Unity Crayon Shader
Fri Mar 11 2022 12:48:44 GMT+0000 (Coordinated Universal Time)
Saved by @BryanJ22
Shader "Crayon Shaders/SimpleCrayonShader" { Properties { [Header(Color Behaviour)] [Space] _Color("Color Tint", Color) = (1,1,1,1) _Brightness("Brightness", Range(0,5)) = 1 _BaseTex("Base Texture", 2D) = "white" {} [Header(Crayon Overlay Behaviour)][Space] _CrayonTex("Crayon Texture", 2D) = "white" {} _CrayonTransparency("Crayon Transparency", Range(0,1)) = 1 [Header(Rim Behaviour)][Space] _RimColor("Rim Color", Color) = (1,1,1,1) _RimPower("Rim Power", Range(0.5, 8.0)) = 5.0 [Header(Distortion Behaviour)][Space] _NoiseTex("Noise Texture", 2D) = "white" {} _Period("Period", Range(0,50)) = 0.4 _Magnitude("Magnitude", Range(0,0.05)) = 0.0007 _Offset("Offset", Range(0,10)) = 0 } SubShader { Tags{ "RenderType" = "Opaque" } LOD 400 CGPROGRAM #pragma surface surf Toon #pragma target 3.0 sampler2D _BaseTex; sampler2D _CrayonTex; sampler2D _RampTex; sampler2D _NoiseTex; half _CrayonTransparency, _Brightness, _RimPower, _Period, _Magnitude, _Offset; fixed4 _Color, _RimColor; half4 LightingToon(SurfaceOutput s, half3 lightDir, half atten) { half NdotL = dot(s.Normal, lightDir); NdotL = tex2D(_RampTex, fixed2(NdotL, 0.5)); fixed4 c; c.rgb = s.Albedo * _LightColor0.rgb * NdotL * atten; c.a = s.Alpha; return c; } half JitterEffect(half x, half m, half M, half period) { half escursion = M - m; half coefficient = 3.1415 * 2.0 / period; half result = (escursion / 2.0 * (1.0 + sin(x * coefficient)) + m); return result; } struct Input { float2 uv_BaseTex; float2 uv_CrayonTex; float2 uv_NoiseTex; float3 viewDir; }; void surf(Input IN, inout SurfaceOutput o) { fixed4 noise = tex2D(_NoiseTex, IN.uv_NoiseTex); half displacement = JitterEffect ( half(_Time[1]) + (noise.xy) * _Offset, half(-_Magnitude), half(_Magnitude), half(_Period) ); half4 base = tex2D(_BaseTex, IN.uv_BaseTex) * _Color * _Brightness; half4 crayon = tex2D(_CrayonTex, IN.uv_CrayonTex + displacement) * _CrayonTransparency; o.Albedo = lerp(base.rgb, crayon.rgb, crayon.a); half rim = 1.0 - saturate(dot(normalize(IN.viewDir), o.Normal)); o.Emission = _RimColor.rgb * pow(rim, _RimPower); } ENDCG } }
Comments