首先 感謝王巍網站詳細講解:
https://onevcat.com/2013/07/shader-tutorial-1/----------------------------------------
Shader "Shader Forge/Diffuse" {
Properties {
_MinColor ("MinColor", Color) = (1,0,0,1)
_MaxColor ("MaxColor", Color) = (0,1,0.006896496,1)
_Health ("Health", Range(0, 1)) = 0
[HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
}
SubShader {
Tags {
"Queue"="AlphaTest"
"RenderType"="TransparentCutout"
}
Pass {
Name "FORWARD"
Tags {
"LightMode"="ForwardBase"
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#define UNITY_PASS_FORWARDBASE
#include "UnityCG.cginc"
#pragma multi_compile_fwdbase_fullshadows
#pragma exclude_renderers gles3 metal d3d11_9x xbox360 xboxone ps3 ps4 psp2
#pragma target 3.0
uniform float4 _MinColor;
uniform float4 _MaxColor;
uniform float _Health;
struct VertexInput {
float4 vertex : POSITION;
float2 texcoord0 : TEXCOORD0;
};
struct VertexOutput {
float4 pos : SV_POSITION;
float2 uv0 : TEXCOORD0;
};
VertexOutput vert (VertexInput v) {
VertexOutput o = (VertexOutput)0;
o.uv0 = v.texcoord0;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex );
return o;
}
float4 frag(VertexOutput i) : COLOR {
float2 node_7657 = (i.uv0*2.0+-1.0);
float2 node_6660 = node_7657.rg;
float node_9531 = ((atan2(node_6660.g,node_6660.r)/6.28318530718)+0.5);
float node_6063 = length(node_7657);
float node_5128 = floor((0.3+node_6063));
float node_459 = ((1.0 - ceil(((1.0 - node_9531)-_Health)))*node_5128*(1.0 - floor(node_6063)));
clip(node_459 - 0.5);
////// Lighting:
////// Emissive:
float3 node_8440 = lerp(_MinColor.rgb,_MaxColor.rgb,_Health);
float3 emissive = node_8440;
float3 finalColor = emissive;
return fixed4(finalColor,1);
}
ENDCG
}
Pass {
Name "ShadowCaster"
Tags {
"LightMode"="ShadowCaster"
}
Offset 1, 1
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#define UNITY_PASS_SHADOWCASTER
#include "UnityCG.cginc"
#include "Lighting.cginc"
#pragma fragmentoption ARB_precision_hint_fastest
#pragma multi_compile_shadowcaster
#pragma exclude_renderers gles3 metal d3d11_9x xbox360 xboxone ps3 ps4 psp2
#pragma target 3.0
uniform float _Health;
struct VertexInput {
float4 vertex : POSITION;
float2 texcoord0 : TEXCOORD0;
};
struct VertexOutput {
V2F_SHADOW_CASTER;
float2 uv0 : TEXCOORD1;
};
VertexOutput vert (VertexInput v) {
VertexOutput o = (VertexOutput)0;
o.uv0 = v.texcoord0;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex );
TRANSFER_SHADOW_CASTER(o)
return o;
}
float4 frag(VertexOutput i) : COLOR {
float2 node_7657 = (i.uv0*2.0+-1.0);
float2 node_6660 = node_7657.rg;
float node_9531 = ((atan2(node_6660.g,node_6660.r)/6.28318530718)+0.5);
float node_6063 = length(node_7657);
float node_5128 = floor((0.3+node_6063));
float node_459 = ((1.0 - ceil(((1.0 - node_9531)-_Health)))*node_5128*(1.0 - floor(node_6063)));
clip(node_459 - 0.5);
SHADOW_CASTER_FRAGMENT(i)
}
ENDCG
}
}
FallBack "Diffuse"
CustomEditor "ShaderForgeMaterialInspector"
}
------------------------------------------------------
結果圖: