Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Carnivorous · Aug 15, 2018 at 10:19 AM · shadershaderspost processingpost-process-effect

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

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<RampFog>
 {
     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);
     }
 }


Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RShields · Aug 15, 2018 at 12:33 PM 0
Share

You're using stack 2.0? Are you following this guide? https://github.com/Unity-Technologies/PostProcessing/wiki/Quick-start

avatar image Carnivorous RShields · Aug 15, 2018 at 01:34 PM 0
Share

I'm using this as a reference: https://github.com/Unity-Technologies/PostProcessing/wiki/Writing-Custom-Effects

And I'm using the PostProcessing stack from the package manager, version for it is 2.0.10

Also I should add that the shader itself works fine when using it the legacy way, from a image effect script, as instructed in this post: https://forum.unity.com/threads/how-to-use-shaders-in-custom-post-effects.322009/

avatar image RShields Carnivorous · Aug 15, 2018 at 02:02 PM 1
Share

Stack 2.0 follows new rules, so guides for previous versions may not work as intended. Try the new guide.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by WubiCookie · May 20, 2019 at 01:37 PM

Hi! I had this problem too and I just solved it, so here's the answer:
When using the BlitFullscreenTriangle method, the input vertex positions are in clip space, so o.vertex = UnityObjectToClipPos(v.vertex); is invalid. You must do

o.vertex = float4(v.vertex.xy, 0.0, 1.0);

Also, there is no input texture coordinates, you must compute them from the positions:
o.texcoord = (v.vertex.xy + 1.0) * 0.5;
#if UNITY_UV_STARTS_AT_TOP
    o.texcoord = o.texcoord * float2(1.0, -1.0) + float2(0.0, 1.0);
#endif

@Carnivorous I hope I'm not too late :D

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

150 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Curved Screen Post Processing Effect 1 Answer

HLSL Post Process Shader Fixing UV/Texcoord 1 Answer

Can you process a color with postprocessing stack's color grading? 2 Answers

How to change color of material from shader graf per script,How to change color of material from shader graf 1 Answer

Fake Volumetrics via custom bloom 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges