123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- Shader "Custom/wMaillageShader"
- {
- Properties
- {
- _MainTex("Texture", 2D) = "white" {}
- _Color("Color", Color) = (1,1,1,1)
- _Threshold("Threshold", float) = 0.01
-
- _EdgeColor("Edge color", Color) = (1,0,0,1)
-
- _Glossiness("Smoothness", Range(0,1)) = 0.5
- _Metallic("Metallic", Range(0,1)) = 0.0
- }
- SubShader
- {
- Cull Off ZWrite Off ZTest Always
- Tags { "RenderType" = "Opaque" }
- Pass
-
- {
-
- CGPROGRAM
-
- #pragma vertex vert
-
- #pragma fragment frag
-
-
- #include "UnityCG.cginc"
-
- struct appdata
-
- {
-
- float4 vertex : POSITION;
-
- float2 uv : TEXCOORD0;
-
- };
-
- struct v2f
-
- {
-
- float2 uv : TEXCOORD0;
-
- float4 vertex : SV_POSITION;
-
- };
-
- sampler2D _CameraDepthNormalsTexture;
- float4 _MainTex_ST;
-
- v2f vert(appdata v)
-
- {
-
- v2f o;
-
- o.vertex = UnityObjectToClipPos(v.vertex);
-
- o.uv = TRANSFORM_TEX(v.uv, _MainTex);
-
- return o;
-
- }
-
- sampler2D _MainTex;
-
- float4 _MainTex_TexelSize;
-
- float _Threshold;
-
- fixed4 _EdgeColor;
-
- float4 GetPixelValue(in float2 uv) {
-
- half3 normal;
-
- float depth;
-
- DecodeDepthNormal(tex2D(_CameraDepthNormalsTexture, uv), depth, normal);
-
- return fixed4(normal, depth);
-
- }
-
- fixed4 frag(v2f i) : SV_Target
-
- {
-
- fixed4 col = tex2D(_MainTex, i.uv);
-
- fixed4 orValue = GetPixelValue(i.uv);
-
- float2 offsets[8] = {
-
- float2(-1, -1),
-
- float2(-1, 0),
-
- float2(-1, 1),
-
- float2(0, -1),
-
- float2(0, 1),
-
- float2(1, -1),
-
- float2(1, 0),
-
- float2(1, 1)
-
- };
-
- fixed4 sampledValue = fixed4(0,0,0,0);
-
- for (int j = 0; j < 8; j++) {
-
- sampledValue += GetPixelValue(i.uv + offsets[j] * _MainTex_TexelSize.xy);
-
- }
-
- sampledValue /= 8;
-
- return lerp(col, _EdgeColor, step(_Threshold, length(orValue - sampledValue)));
-
- }
-
-
- ENDCG
- }
- }
- }
|