Created
October 7, 2018 09:44
-
-
Save HarukaKajita/b8b15068a8290d30bab7f68fdeb62c2e to your computer and use it in GitHub Desktop.
Environmental Transporterの改悪シェーダーMaterialBreakerの完成版
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Shader "Unlit/Gouge2" | |
| { | |
| Properties | |
| { | |
| _Color ("Color", Color) = (1,0,0) | |
| _NoiseScale ("Noise Scale", float) = 100 | |
| } | |
| SubShader | |
| { | |
| Tags { "RenderType"="Transparent" "Queue"="Transparent+300" } | |
| LOD 100 | |
| Pass{ | |
| ZWrite off | |
| Cull off | |
| ColorMask 0 | |
| Stencil{ | |
| Ref 255 | |
| Comp Always | |
| Pass Replace | |
| } | |
| } | |
| //マテリアル破壊パス | |
| Pass | |
| { | |
| Tags { "RenderType"="Transparent" "Queue"="Transparent+900" } | |
| ZTest Greater | |
| Stencil{ | |
| Ref 255 | |
| Comp Equal | |
| } | |
| Blend SrcAlpha OneMinusSrcAlpha | |
| Cull Front | |
| CGPROGRAM | |
| #pragma vertex vert | |
| #pragma fragment frag | |
| #pragma multi_compile_fog | |
| #include "UnityCG.cginc" | |
| struct appdata | |
| { | |
| float4 vertex : POSITION; | |
| float2 uv : TEXCOORD0; | |
| float3 normal : NORMAL; | |
| }; | |
| struct v2f | |
| { | |
| float2 uv : TEXCOORD0; | |
| UNITY_FOG_COORDS(1) | |
| float4 vertex : SV_POSITION; | |
| float3 normal : NORMAL; | |
| float3 lightDir : TEXCOORD2; | |
| float3 wPos : TEXCOORD3; | |
| }; | |
| float3 _Color; | |
| float _NoiseScale; | |
| fixed2 random2(fixed2 st){ | |
| st = fixed2( dot(st,fixed2(127.1,311.7)), | |
| dot(st,fixed2(269.5,183.3)) ); | |
| return -1.0 + 2.0*frac(sin(st)*43758.5453123); | |
| } | |
| float perlinNoise(fixed2 st){ | |
| fixed2 p = floor(st); | |
| fixed2 f = frac(st); | |
| fixed2 u = f*f*(3.0-2.0*f); | |
| float v00 = random2(p+fixed2(0,0)); | |
| float v10 = random2(p+fixed2(1,0)); | |
| float v01 = random2(p+fixed2(0,1)); | |
| float v11 = random2(p+fixed2(1,1)); | |
| return lerp( lerp( dot( v00, f - fixed2(0,0) ), dot( v10, f - fixed2(1,0) ), u.x ), | |
| lerp( dot( v01, f - fixed2(0,1) ), dot( v11, f - fixed2(1,1) ), u.x ), | |
| u.y)+0.5f; | |
| } | |
| v2f vert (appdata v) | |
| { | |
| v2f o; | |
| o.vertex = UnityObjectToClipPos(v.vertex); | |
| o.uv = v.uv; | |
| o.normal = UnityObjectToWorldNormal(v.normal); | |
| o.lightDir = normalize(UnityWorldSpaceLightDir(v.vertex)); | |
| o.wPos = mul(unity_ObjectToWorld, v.vertex); | |
| UNITY_TRANSFER_FOG(o,o.vertex); | |
| return o; | |
| } | |
| fixed4 frag (v2f i) : SV_Target | |
| { | |
| float scale = _NoiseScale; | |
| fixed4 col; | |
| col.rgb = fixed3(perlinNoise(i.wPos.xy*scale),perlinNoise(i.wPos.yz*scale),perlinNoise(i.wPos.zx*scale)); | |
| col.rgb = fixed3(1,0,1); | |
| col.a = 1; | |
| //col.rgb *= max(0.4, dot(i.lightDir, i.normal*-1)); | |
| UNITY_APPLY_FOG(i.fogCoord, col); | |
| return col; | |
| } | |
| ENDCG | |
| } | |
| //リムライトパス | |
| Pass | |
| { | |
| Tags { "RenderType"="Transparent" "Queue"="Transparent" } | |
| Blend SrcAlpha OneMinusSrcAlpha | |
| Stencil{ | |
| Ref 255 | |
| Pass Replace | |
| } | |
| Cull front //内側からも見えるようにするため | |
| ZTest LEqual | |
| CGPROGRAM | |
| #pragma vertex vert | |
| #pragma fragment frag | |
| // make fog work | |
| #pragma multi_compile_fog | |
| #include "UnityCG.cginc" | |
| struct appdata | |
| { | |
| float4 vertex : POSITION; | |
| float2 uv : TEXCOORD0; | |
| float3 normal : NORMAL; | |
| }; | |
| struct v2f | |
| { | |
| float2 uv : TEXCOORD0; | |
| UNITY_FOG_COORDS(1) | |
| float4 vertex : SV_POSITION; | |
| float3 wPos : TEXCOORD2; | |
| float3 normal : TEXCOORD3; | |
| }; | |
| float3 _Color; | |
| fixed2 random2(fixed2 st){ | |
| st = fixed2( dot(st,fixed2(127.1,311.7)), | |
| dot(st,fixed2(269.5,183.3)) ); | |
| return -1.0 + 2.0*frac(sin(st)*43758.5453123); | |
| } | |
| float perlinNoise(fixed2 st){ | |
| fixed2 p = floor(st); | |
| fixed2 f = frac(st); | |
| fixed2 u = f*f*(3.0-2.0*f); | |
| float v00 = random2(p+fixed2(0,0)); | |
| float v10 = random2(p+fixed2(1,0)); | |
| float v01 = random2(p+fixed2(0,1)); | |
| float v11 = random2(p+fixed2(1,1)); | |
| return lerp( lerp( dot( v00, f - fixed2(0,0) ), dot( v10, f - fixed2(1,0) ), u.x ), | |
| lerp( dot( v01, f - fixed2(0,1) ), dot( v11, f - fixed2(1,1) ), u.x ), | |
| u.y)+0.5f; | |
| } | |
| v2f vert (appdata v) | |
| { | |
| v2f o; | |
| o.vertex = UnityObjectToClipPos(v.vertex); | |
| o.uv = v.uv; | |
| o.wPos = mul(unity_ObjectToWorld, v.vertex); | |
| o.normal = UnityObjectToWorldNormal(v.vertex); | |
| UNITY_TRANSFER_FOG(o,o.vertex); | |
| return o; | |
| } | |
| fixed4 frag (v2f i) : SV_Target | |
| { | |
| fixed4 col; | |
| float3 normal = normalize(i.normal); | |
| float3 viewDir = normalize(UnityWorldSpaceViewDir(i.wPos)); | |
| col.xyz = _Color * (1 - saturate(dot(normal*-1, viewDir)));//リムライト | |
| col.a = (1 - saturate((dot(normal*-1, viewDir))));//リムライトの透明度 | |
| col.a *= perlinNoise(i.uv * 100); | |
| col.a = pow(col.a, 2);//リムライトの太さ | |
| col.a += 0.1;//最低限の透明度を確保 | |
| UNITY_APPLY_FOG(i.fogCoord, col); | |
| return col; | |
| } | |
| ENDCG | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment