Created
August 1, 2020 08:53
-
-
Save mrtrizer/eb52d061397637f34b89fe92e39b6f25 to your computer and use it in GitHub Desktop.
Fog.shader
This file contains 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 "Custom/Fog" | |
{ | |
Properties | |
{ | |
_Color ("Color", Color) = (1,1,1,1) | |
_MainTex ("Texture", 2D) = "white" {} | |
_NoiseTex ("NoiseTexture", 2D) = "white" {} | |
} | |
SubShader | |
{ | |
Tags { "Queue"="Transparent" "RenderType"="Transparent" } | |
LOD 100 | |
Pass | |
{ | |
ColorMask RGBA | |
ZWrite On | |
ZTest Always | |
Blend SrcAlpha OneMinusSrcAlpha | |
CGPROGRAM | |
#pragma vertex vert alpha | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
struct appdata | |
{ | |
float4 vertex : POSITION; | |
float2 uv : TEXCOORD0; | |
}; | |
struct v2f | |
{ | |
float2 uv : TEXCOORD0; | |
float4 vertex : SV_POSITION; | |
}; | |
sampler2D _MainTex; | |
sampler2D _NoiseTex; | |
float4 _MainTex_ST; | |
fixed4 _Color; | |
v2f vert (appdata v) | |
{ | |
v2f o; | |
o.vertex = UnityObjectToClipPos(v.vertex); | |
o.uv = TRANSFORM_TEX(v.uv, _MainTex); | |
return o; | |
} | |
fixed4 frag (v2f i) : SV_Target | |
{ | |
fixed4 outColor = _Color; | |
// sample the texture | |
fixed4 c = tex2D(_MainTex, i.uv + fixed2(0.002, -0.004)); | |
fixed4 c1 = tex2D(_MainTex, i.uv + fixed2(0.004, 0.007)); | |
fixed4 c2 = tex2D(_MainTex, i.uv + fixed2(-0.006, 0.005)); | |
fixed4 c3 = tex2D(_MainTex, i.uv + fixed2(-0.004, -0.004)); | |
fixed4 c4 = tex2D(_MainTex, i.uv + fixed2(-0.003, -0.006)); | |
fixed4 noise = tex2D(_NoiseTex, i.uv * 4 + fixed2(0.02,0.02) * _Time / 2) + 0.05; | |
float noiseK = (noise.r * 5 + noise.g + noise.b) / 7; | |
float result = noiseK - (c.r + c.g + c1.r + c1.g + c2.r + c2.g + c3.r + c3.g + c4.r + c4.g) / 10; | |
outColor.a = result > 0.5 ? clamp(result * 1.15, 0.7, 1) : result > 0.15 ? result * 1.3 : 0; | |
return outColor; | |
} | |
ENDCG | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment