Advertisement
Staggart

COZY 3 debug fog shader

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