Advertisement
Staggart

COZY Weather fog debug shader

Mar 15th, 2022
2,637
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Debug/COZY Fog"
  2. {
  3.     SubShader
  4.     {
  5.         Tags { "RenderPipeline" = "UniversalPipeline" "RenderType" = "Transparent" "Queue" = "Transparent" }
  6.         Blend SrcAlpha OneMinusSrcAlpha, One OneMinusSrcAlpha
  7.         ZTest LEqual
  8.         ZWrite Off
  9.        
  10.         Stencil { Ref 221 Comp Always Pass Replace }
  11.        
  12.         Pass
  13.         {
  14.             Name "ForwardLit"
  15.             Tags { "LightMode" = "UniversalForward" }
  16.            
  17.             HLSLPROGRAM
  18.             #pragma target 3.0
  19.             #pragma vertex vert
  20.             #pragma fragment frag
  21.             #pragma multi_compile_fog
  22.  
  23.             #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  24.             #include "Assets/Distant Lands/Cozy Weather/Contents/Materials/Shaders/Includes/StylizedFogIncludes.cginc"
  25.  
  26.             struct appdata
  27.             {
  28.                 float4 vertex : POSITION;
  29.                 UNITY_VERTEX_INPUT_INSTANCE_ID
  30.             };
  31.  
  32.             struct v2f
  33.             {
  34.                 float4 pos     : SV_POSITION;
  35.                 float3 positionWS  : TEXCOORD1;
  36.                 float fogFactor : TEXCOORD2;
  37.                
  38.                 UNITY_VERTEX_INPUT_INSTANCE_ID
  39.                 UNITY_VERTEX_OUTPUT_STEREO
  40.             };
  41.  
  42.             v2f vert(appdata v)
  43.             {
  44.                 v2f o;
  45.  
  46.                 UNITY_SETUP_INSTANCE_ID(v);
  47.                 UNITY_TRANSFER_INSTANCE_ID(v, o);
  48.                 UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  49.  
  50.                 o.pos = TransformObjectToHClip(v.vertex.xyz);
  51.                 o.positionWS = TransformObjectToWorld(v.vertex.xyz);
  52.                 o.fogFactor = ComputeFogFactor(o.pos.z);
  53.                
  54.                 return o;
  55.             }
  56.  
  57.             half4 frag(v2f i) : SV_Target
  58.             {
  59.                 UNITY_SETUP_INSTANCE_ID(i);
  60.                 UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
  61.  
  62.                 float3 color = 0;
  63.  
  64.                 float3 foggedColor = BlendStylizedFog(i.positionWS, float4(color.rgb, 1.0)).rgb;
  65.  
  66.                 //Default Unity fog
  67.                 //foggedColor = MixFog(color.rgb, i.fogFactor);
  68.                
  69.                 return float4(foggedColor.rgb,1);
  70.  
  71.             }
  72.             ENDHLSL
  73.         }
  74.  
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement