Quantcast
Channel: Questions in topic: "post processing"
Viewing all articles
Browse latest Browse all 713

Why doesn't this shader work when using it with as a custom effect on the post processing stack

$
0
0
During game mode, the effect doesn't do anything and while in edit mode, the game preview flickers between black and the normal camera view. Any help would be greatly appreciated. Shader code Shader "Custom/FirewatchFog" { Properties { _MainTex("Texture", 2D) = "white" {} _FogAmount("Fog amount", float) = 1 _ColorRamp("Color ramp", 2D) = "white" {} _FogIntensity("Fog intensity", float) = 1 } SubShader { // No culling or depth Cull Off ZWrite Off ZTest Always Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; }; struct v2f { float2 uv : TEXCOORD0; float4 vertex : SV_POSITION; float4 scrPos : TEXCOORD1; }; v2f vert(appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.uv = v.uv; o.scrPos = ComputeScreenPos(o.vertex); return o; } sampler2D _MainTex; sampler2D _CameraDepthTexture; sampler2D _ColorRamp; float _FogAmount; float _FogIntensity; fixed4 frag(v2f i) : SV_Target { fixed4 orCol = tex2D(_MainTex, i.uv); float depthValue = Linear01Depth(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.scrPos))); float depthValueMul = depthValue * _FogAmount; fixed4 fogCol = tex2D(_ColorRamp, (float2(depthValueMul, 0))); return (depthValue < 1) ? lerp(orCol, fogCol, fogCol.a * _FogIntensity) : orCol; } ENDCG } } } Code to add the effect to the post processing stack using UnityEngine; using System.Collections; using UnityEngine.Rendering.PostProcessing; using System; [Serializable] [PostProcess(typeof(RampFogRenderer), PostProcessEvent.AfterStack, "Custom/FirewatchFog")] public sealed class RampFog : PostProcessEffectSettings { [Range(0,5), Tooltip("Fog intensity.")] public FloatParameter intensity = new FloatParameter { value = 0.5f }; [Range(0, 5), Tooltip("Fog amount.")] public FloatParameter amount = new FloatParameter { value = 0.5f }; public TextureParameter albedo = new TextureParameter(); public TextureParameter rampTexture = new TextureParameter(); } public sealed class RampFogRenderer : PostProcessEffectRenderer { public override void Render(PostProcessRenderContext context) { var sheet = context.propertySheets.Get(Shader.Find("Custom/FirewatchFog")); sheet.properties.SetFloat("_FogIntensity", settings.intensity); sheet.properties.SetFloat("_FogAmount", settings.amount); sheet.properties.SetTexture("_ColorRamp", settings.rampTexture); sheet.properties.SetTexture("_MainTex", settings.albedo); context.command.BlitFullscreenTriangle(context.source, context.destination, sheet, 0); } }

Viewing all articles
Browse latest Browse all 713

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>