Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

[Solved] Ambient Occlusion showing through Unlit texture

Discussion in 'Editor & General Support' started by Comafly, Jun 14, 2019.

  1. Comafly

    Comafly

    Joined:
    May 30, 2014
    Posts:
    87
    Hi all. I am having an issue where the post-processing ambient occlusion in my scene is showing through my object. The object is a mesh I created in Blender, and has an Unlit Texture shader applied. See below:



    Switching the shader to Standard solves the issue, but I don't want the object to be affected by light sources, so that's not really a solution.

    Would really appreciate any help or ideas!

    Cheers
     
  2. Comafly

    Comafly

    Joined:
    May 30, 2014
    Posts:
    87
    Big thanks to /u/CustomPhase on Reddit:

    I just added in a Shadowcaster pass to my unlit shader and now it works as I'd like. Here is a copy of the shader for anyone who might have this same issue.
     
    BIGTIMEMASTER likes this.
  3. Rugbug_Redfern

    Rugbug_Redfern

    Joined:
    Jun 2, 2017
    Posts:
    20
    Pasting the code here for anyone else in case the link expires:

    Code (CSharp):
    1. Shader "Unlit/UnlitWithShadowcaster"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex ("Texture", 2D) = "white" {}
    6.     }
    7.     SubShader
    8.     {
    9.         Tags { "RenderType"="Opaque" }
    10.         LOD 100
    11.  
    12.         UsePass "Legacy Shaders/VertexLit/SHADOWCASTER"
    13.  
    14.         Pass
    15.         {
    16.             CGPROGRAM
    17.             #pragma vertex vert
    18.             #pragma fragment frag
    19.             // make fog work
    20.             #pragma multi_compile_fog
    21.  
    22.             #include "UnityCG.cginc"
    23.  
    24.             struct appdata
    25.             {
    26.                 float4 vertex : POSITION;
    27.                 float2 uv : TEXCOORD0;
    28.             };
    29.  
    30.             struct v2f
    31.             {
    32.                 float2 uv : TEXCOORD0;
    33.                 UNITY_FOG_COORDS(1)
    34.                 float4 vertex : SV_POSITION;
    35.             };
    36.  
    37.             sampler2D _MainTex;
    38.             float4 _MainTex_ST;
    39.  
    40.             v2f vert (appdata v)
    41.             {
    42.                 v2f o;
    43.                 o.vertex = UnityObjectToClipPos(v.vertex);
    44.                 o.uv = TRANSFORM_TEX(v.uv, _MainTex);
    45.                 UNITY_TRANSFER_FOG(o,o.vertex);
    46.                 return o;
    47.             }
    48.  
    49.             fixed4 frag (v2f i) : SV_Target
    50.             {
    51.                 // sample the texture
    52.                 fixed4 col = tex2D(_MainTex, i.uv);
    53.                 // apply fog
    54.                 UNITY_APPLY_FOG(i.fogCoord, col);
    55.                 return col;
    56.             }
    57.             ENDCG
    58.         }
    59.     }
    60. }
     
    leftshoe18 and thienhaflash like this.