Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //When applied to an object, it will appear to blend into the fog. Compare the result by toggling fog off/on
- Shader "Debug/COZY 3 Fog"
- {
- Properties
- {
- [HDR] _BaseColor("Color", Color) = (0, 0, 0, 1)
- [Toggle] _Enable("Enable Fog", Float) = 1
- }
- SubShader
- {
- Tags { "RenderPipeline" = "UniversalPipeline" "RenderType" = "Transparent" "Queue" = "Transparent" }
- Blend SrcAlpha OneMinusSrcAlpha, One OneMinusSrcAlpha
- //ZTest LEqual
- ZWrite Off
- Stencil { Ref 221 Comp Always Pass Replace }
- Pass
- {
- Name "ForwardLit"
- Tags { "LightMode" = "UniversalForward" }
- HLSLPROGRAM
- #pragma target 3.0
- #pragma vertex vert
- #pragma fragment frag
- #pragma multi_compile_fog
- #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
- #include "Packages/com.distantlands.cozy.core/Runtime/Shaders/Includes/StylizedFogIncludes.cginc"
- struct appdata
- {
- float4 vertex : POSITION;
- UNITY_VERTEX_INPUT_INSTANCE_ID
- };
- struct v2f
- {
- float4 pos : SV_POSITION;
- float3 positionWS : TEXCOORD1;
- float fogFactor : TEXCOORD2;
- UNITY_VERTEX_INPUT_INSTANCE_ID
- UNITY_VERTEX_OUTPUT_STEREO
- };
- bool _Enable;
- float4 _BaseColor;
- v2f vert(appdata v)
- {
- v2f o;
- UNITY_SETUP_INSTANCE_ID(v);
- UNITY_TRANSFER_INSTANCE_ID(v, o);
- UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
- o.pos = TransformObjectToHClip(v.vertex.xyz);
- o.positionWS = TransformObjectToWorld(v.vertex.xyz);
- o.fogFactor = ComputeFogFactor(o.pos.z);
- return o;
- }
- half4 frag(v2f i) : SV_Target
- {
- UNITY_SETUP_INSTANCE_ID(i);
- UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
- float3 color = _BaseColor.rgb;
- if(_Enable == false) return float4(color.rgb, 1.0);
- //Cozy's fog application function. Base color goes in, fogged color comes out
- float3 foggedColor = BlendStylizedFog(i.positionWS, float4(color.rgb, 1.0)).rgb;
- //Default Unity fog
- //foggedColor = MixFog(color.rgb, i.fogFactor);
- return float4(foggedColor.rgb, 1.0);
- }
- ENDHLSL
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement