-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,4 +102,3 @@ Shader "Unlit/MyShader" | |
} | ||
} | ||
``` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# UI Shader | ||
|
||
1. 基础纹理采样 | ||
|
||
2. 支持组件中的调色功能 | ||
|
||
3. 遮罩支持 | ||
|
||
4. 去色功能(扫光等) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// UI去色 | ||
Shader "Unlit/UIGray" | ||
{ | ||
Properties | ||
{ | ||
// UI 必须用内置的一些变量,关联贴图,对应 Source Image | ||
// PerRendererData 配合 GetPropertyBlock/SetPropertyBlock 使用,用于统一修改全部用到该Shader的材质,此处设置后在面板中参数置灰,因为已经对应 Source Image | ||
[PerRendererData]_MainTex("MainTex", 2D) = "white"{} | ||
} | ||
SubShader | ||
{ | ||
Tags{"Queue" = "Transparent"} | ||
// 固定使用此 Blend | ||
Blend SrcAlpha OneMinusSrcAlpha | ||
|
||
Pass | ||
{ | ||
CGPROGRAM | ||
#pragma vertex vert | ||
#pragma fragment frag | ||
#include "UnityCG.cginc" | ||
|
||
struct appdata | ||
{ | ||
float4 vertex : POSITION; | ||
float2 uv: TEXCOORD; | ||
}; | ||
|
||
struct v2f | ||
{ | ||
float4 pos: SV_POSITION; | ||
float2 uv: TEXCOORD; | ||
}; | ||
|
||
sampler2D _MainTex; | ||
|
||
v2f vert (appdata v) | ||
{ | ||
v2f o; | ||
o.pos = UnityObjectToClipPos(v.vertex); | ||
o.uv = v.uv; | ||
return o; | ||
} | ||
|
||
fixed4 frag (v2f i): SV_TARGET | ||
{ | ||
fixed4 mainTex = tex2D(_MainTex, i.uv); | ||
return mainTex; | ||
} | ||
ENDCG | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
%YAML 1.1 | ||
%TAG !u! tag:unity3d.com,2011: | ||
--- !u!21 &2100000 | ||
Material: | ||
serializedVersion: 8 | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_Name: 21 | ||
m_Shader: {fileID: 4800000, guid: 19d7c7f31213e471dab3caa866029574, type: 3} | ||
m_Parent: {fileID: 0} | ||
m_ModifiedSerializedProperties: 0 | ||
m_ValidKeywords: [] | ||
m_InvalidKeywords: [] | ||
m_LightmapFlags: 4 | ||
m_EnableInstancingVariants: 0 | ||
m_DoubleSidedGI: 0 | ||
m_CustomRenderQueue: -1 | ||
stringTagMap: {} | ||
disabledShaderPasses: [] | ||
m_LockedProperties: | ||
m_SavedProperties: | ||
serializedVersion: 3 | ||
m_TexEnvs: [] | ||
m_Ints: [] | ||
m_Floats: [] | ||
m_Colors: [] | ||
m_BuildTextureStacks: [] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// 模版缓冲区、模版测试 | ||
// 模版测试是基于模版缓冲区和自身区域值进行对比,如UI中的遮罩 | ||
// 需要在mask节点上添加mask组件,指定为遮罩 | ||
// 模版测试公式: | ||
// (Ref & ReadMask) Comp (StencilBufferValue & ReadMask) | ||
// Ref 为Shader中自定义的值,StencilBufferValue 为模版缓冲区中的值 | ||
|
||
Shader "Unlit/Stencil" | ||
{ | ||
Properties | ||
{ | ||
[PerRendererData]_MainTex("MainTex", 2D) = "white"{} | ||
// 模版测试参数 | ||
_Ref("Stencil Ref", int) = 0 | ||
[Enum(UnityEngine.Rendering.CompareFunction)]_StencilComp("Stencil Comp", int) = 0 | ||
[Enum(UnityEngine.Rendering.StencilOp)]_StencilOp("Stencil OP", int) = 0 | ||
} | ||
SubShader | ||
{ | ||
Tags{"Queue" = "Transparent"} | ||
Blend SrcAlpha OneMinusSrcAlpha | ||
|
||
// 模版测试 | ||
Stencil { | ||
Ref [_Ref] // 0 1 | ||
// ReadMask | ||
// WriteMask | ||
Comp [_StencilComp] // Equal | ||
Pass [_StencilOp] // Keep | ||
// Fail | ||
// ZFail | ||
} | ||
|
||
Pass | ||
{ | ||
CGPROGRAM | ||
#pragma vertex vert | ||
#pragma fragment frag | ||
#include "UnityCG.cginc" | ||
|
||
struct appdata | ||
{ | ||
float4 vertex : POSITION; | ||
float2 uv: TEXCOORD; | ||
}; | ||
|
||
struct v2f | ||
{ | ||
float4 pos: SV_POSITION; | ||
float2 uv: TEXCOORD; | ||
}; | ||
|
||
sampler2D _MainTex; | ||
|
||
v2f vert (appdata v) | ||
{ | ||
v2f o; | ||
o.pos = UnityObjectToClipPos(v.vertex); | ||
o.uv = v.uv; | ||
return o; | ||
} | ||
|
||
fixed4 frag (v2f i): SV_TARGET | ||
{ | ||
fixed4 mainTex = tex2D(_MainTex, i.uv); | ||
return mainTex; | ||
} | ||
ENDCG | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
%YAML 1.1 | ||
%TAG !u! tag:unity3d.com,2011: | ||
--- !u!21 &2100000 | ||
Material: | ||
serializedVersion: 8 | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_Name: 22 | ||
m_Shader: {fileID: 4800000, guid: dd6fe0fd438924b38adf87c7f63005dd, type: 3} | ||
m_Parent: {fileID: 0} | ||
m_ModifiedSerializedProperties: 0 | ||
m_ValidKeywords: [] | ||
m_InvalidKeywords: [] | ||
m_LightmapFlags: 4 | ||
m_EnableInstancingVariants: 0 | ||
m_DoubleSidedGI: 0 | ||
m_CustomRenderQueue: -1 | ||
stringTagMap: {} | ||
disabledShaderPasses: [] | ||
m_LockedProperties: | ||
m_SavedProperties: | ||
serializedVersion: 3 | ||
m_TexEnvs: | ||
- _MainTex: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
m_Ints: [] | ||
m_Floats: | ||
- _Ref: 1 | ||
- _StencilComp: 3 | ||
- _StencilOp: 0 | ||
m_Colors: [] | ||
m_BuildTextureStacks: [] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// 颜色遮罩,对颜色缓冲区的值过滤 | ||
|
||
Shader "Unlit/ColorMask" | ||
{ | ||
Properties | ||
{ | ||
[PerRendererData]_MainTex("MainTex", 2D) = "white"{} | ||
_Ref("Stencil Ref", int) = 0 | ||
[Enum(UnityEngine.Rendering.CompareFunction)]_StencilComp("Stencil Comp", int) = 0 | ||
[Enum(UnityEngine.Rendering.StencilOp)]_StencilOp("Stencil OP", int) = 0 | ||
} | ||
SubShader | ||
{ | ||
Tags{"Queue" = "Transparent"} | ||
Blend SrcAlpha OneMinusSrcAlpha | ||
|
||
// ColorMask | ||
// ColorMask 0 // 什么都不显示 | ||
// ColorMask RGBA // RGBA的任意组合 | ||
ColorMask R // RGBA的任意组合 | ||
|
||
Stencil { | ||
Ref [_Ref] | ||
Comp [_StencilComp] | ||
Pass [_StencilOp] | ||
} | ||
|
||
Pass | ||
{ | ||
CGPROGRAM | ||
#pragma vertex vert | ||
#pragma fragment frag | ||
#include "UnityCG.cginc" | ||
|
||
struct appdata | ||
{ | ||
float4 vertex : POSITION; | ||
float2 uv: TEXCOORD; | ||
}; | ||
|
||
struct v2f | ||
{ | ||
float4 pos: SV_POSITION; | ||
float2 uv: TEXCOORD; | ||
}; | ||
|
||
sampler2D _MainTex; | ||
|
||
v2f vert (appdata v) | ||
{ | ||
v2f o; | ||
o.pos = UnityObjectToClipPos(v.vertex); | ||
o.uv = v.uv; | ||
return o; | ||
} | ||
|
||
fixed4 frag (v2f i): SV_TARGET | ||
{ | ||
fixed4 mainTex = tex2D(_MainTex, i.uv); | ||
return mainTex; | ||
} | ||
ENDCG | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
%YAML 1.1 | ||
%TAG !u! tag:unity3d.com,2011: | ||
--- !u!21 &2100000 | ||
Material: | ||
serializedVersion: 8 | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_Name: 23 | ||
m_Shader: {fileID: 4800000, guid: 4e27097398a824e609070fdcc0307df4, type: 3} | ||
m_Parent: {fileID: 0} | ||
m_ModifiedSerializedProperties: 0 | ||
m_ValidKeywords: [] | ||
m_InvalidKeywords: [] | ||
m_LightmapFlags: 4 | ||
m_EnableInstancingVariants: 0 | ||
m_DoubleSidedGI: 0 | ||
m_CustomRenderQueue: -1 | ||
stringTagMap: {} | ||
disabledShaderPasses: [] | ||
m_LockedProperties: | ||
m_SavedProperties: | ||
serializedVersion: 3 | ||
m_TexEnvs: | ||
- _MainTex: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
m_Ints: [] | ||
m_Floats: | ||
- _Ref: 0 | ||
- _StencilComp: 0 | ||
- _StencilOp: 0 | ||
m_Colors: [] | ||
m_BuildTextureStacks: [] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.