// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' Shader "Test/Material Property Drawer Example" {
Properties {
[Header(Material Property Drawer Example)] [Space(20)] _TintColor("TintColor", Color) = (1,1,1,1) _MainTex ("Texture", 2D) = "white" {} [NoScaleOffset]_SecondTex ("Additional Texture", 2D) = "white" {}
[Space(30)] //Toggle shader feature. it can use only multiply properties. [Toggle] _Invert ("Invert Color", Float) = 0
//Toggle Keyword Enum [Toggle(ENABLE_Gray)] _Gray("GrayScale", Float) = 0
[Space(30)] // All following properties are valid for both SrcFactor & DstFactor in the Blend command. //Source refers to the calculated color, Destination is the color already on the screen. //The blend factors are ignored if BlendOp is using logical operations. [Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend ("Src Blend", Float) = 1 [Enum(UnityEngine.Rendering.BlendMode)] _DstBlend ("Dst Blend", Float) = 1 [Enum(Off, 0, On, 1)] _ZWrite ("ZWrite", Float) = 0 [Enum(UnityEngine.Rendering.CompareFunction)] _ZTest ("ZTest", Float) = 0 [Enum(UnityEngine.Rendering.CullMode)] _Cull ("Cull Mode", Float) = 1 // This is used with "#pragma multi_compile" in shaders, to enable or disable parts of shader code. // Each name will enable "property name" + underscore + "enum name", uppercased, shader keyword. [Space(30)] [KeywordEnum(None, Add, Multiply)] _Overlay ("Overlay mode", Float) = 0 // _Shininess ("Shininess", Range (0.01, 1)) = 0.08 } // PowerSlider show non-linear curve slide [Space(30)] [PowerSlider(3.0)] _Shininess ("Shininess", Range (0.01, 1)) = 0.08 } SubShader {
Tags { "Queue"="Transparent" "RenderType"="Transparent" }
Blend [_SrcBlend] [_DstBlend] ZWrite [_ZWrite] ZTest [_ZTest] Cull [_Cull]
Pass { CGPROGRAM
#pragma shader_feature _INVERT_ON #pragma shader_feature ENABLE_Gray #pragma multi_compile _OVERLAY_NONE _OVERLAY_ADD _OVERLAY_MULTIPLY #pragma vertex vert #pragma fragment frag
//make fogwork #pragma multi_compile_fog #include "UnityCG.cginc"
sampler2D _MainTex; float4 _MainTex_ST; sampler2D _SecondTex; float4 _SecondTex_ST; fixed4 _TintColor; float _Shininess;
struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; };
struct v2f { float4 uv : TEXCOORD0; float4 vertex : SV_POSITION; UNITY_FOG_COORDS(1) }; v2f vert (appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); // mul( UNITY_MATRIX_VP, _Object2World); // mul( UNITY_MATRIX_MVP, v.vertex ) ;
o.uv.xy = TRANSFORM_TEX(v.uv, _MainTex); o.uv.zw = TRANSFORM_TEX(v.uv, _SecondTex); UNITY_TRANSFER_FOG(o,o.vertex); return o; } fixed4 frag (v2f i) : SV_Target { fixed4 col = tex2D(_MainTex, i.uv.xy) * _TintColor; #if _INVERT_ON col = 1 - col; #endif #if ENABLE_Gray col = (col.r + col.g + col.b)/3; #endif
fixed4 secCol = tex2D(_SecondTex, i.uv.zw); #if _OVERLAY_ADD col += secCol;
#elif _OVERLAY_MULTIPLY col *= secCol; #endif UNITY_APPLY_FOG(i.fogCoord, col); col *= _Shininess; return col; } ENDCG } } }
|