Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

ImageEffect GlobalFog doesn't work on my customized vert/frag shaders

Discussion in 'Shaders' started by snoop_huang, Jun 30, 2015.

  1. snoop_huang

    snoop_huang

    Joined:
    Jul 11, 2014
    Posts:
    4
    I wat trying GlobalFog from StandardAssets.ImageEffect but it didn't work on my customized vert/frag shaders. Some other built-in shaders like Unlit/Color and Unlit/Texture also didn't work.

    I modified GlobalFog.shader to check if the depthTexture is doing its job and it results in all white with customized shader.

    Scene


    Depth w/ built-in Standard shader


    Depth w/ customized shader


    I know here's another option for fog, I was just trying another way around.

    Here's the custom shader.

    Adding #pragma multi_compile_fog and marcos like UNITY_APPLY_FOG didn't change anything in this case. I must missed something ...

    Code (CSharp):
    1.  
    2. Shader "Custom/Opaque/NoLit" {
    3.     Properties {
    4.         _MainTex ("Diffuse (RGB)", 2D) = "white" {}
    5.         _ColorEnhance ("Color", Color) = (0,0,0,1)
    6.     }
    7.     SubShader {
    8.         Pass{
    9.             Tags { "Queue"="Geometry" "LightMode" = "ForwardBase" "RenderType"="Opaque"}
    10.             Blend Off
    11.             LOD 80
    12.            
    13.             CGPROGRAM      
    14.             #pragma vertex vs
    15.             #pragma fragment fs      
    16.             #pragma multi_compile_fwdbase
    17.             #pragma skip_variants SHADOWS_SCREEN SHADOWS_NATIVE DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE VERTEXLIGHT_ON  
    18.             #include "UnityCG.cginc"
    19.             #pragma target 3.0
    20.  
    21.             sampler2D _MainTex;
    22.             half4 _MainTex_ST;
    23.             fixed4 _ColorEnhance;
    24.            
    25.             struct VSInput {
    26.                 float4 pos         : POSITION0;
    27.                 half4 uv_MainTex: TEXCOORD0;
    28.             };
    29.            
    30.             struct FSInput {
    31.                 float4 pos   : SV_POSITION;
    32.                 half2 uv_MainTex: TEXCOORD0;
    33.             };
    34.            
    35.             FSInput vs(VSInput input)
    36.             {
    37.                 FSInput output;
    38.                 output.pos = mul(UNITY_MATRIX_MVP, input.pos);
    39.                 output.uv_MainTex = TRANSFORM_TEX(input.uv_MainTex, _MainTex);
    40.                
    41.                 return output;
    42.             }
    43.            
    44.             fixed4 fs(FSInput input) : COLOR
    45.             {
    46.                 return tex2D(_MainTex, input.uv_MainTex) + _ColorEnhance;
    47.             }          
    48.             ENDCG
    49.         }
    50.     }
    51.     FallBack "Unlit/Texture"
    52. }
     
  2. snoop_huang

    snoop_huang

    Joined:
    Jul 11, 2014
    Posts:
    4
    I found out that when I change my fallback shader to Standard or any other shader that make GlobalFog works can make my custom shader work too!

    I totally have no idea what's going on here O_O