Home Technical Talk
The BRAWL² Tournament Challenge has been announced!

It starts May 12, and ends Sept 12. Let's see what you got!

https://polycount.com/discussion/237047/the-brawl²-tournament

[Unity] Shader, custom lighting function does not work properly with post processed AO

polycounter lvl 9
Offline / Send Message
CarlCraft polycounter lvl 9
I'm quite new to writing shaders but this one problem has made my hair grey way too quickly:

I'm trying to write a foliage shader with good looking backface lighting. The problem I'm having is the post process AO in the project. Whenever I use anything other than the Standard lighting function, the AO behind the object with my foliage shader is rendered in front of it. See below:

Using my original code "#pragma surface surf StandardTranslucent fullforwardshadows". AO from the rocks in the background is rendered on top of the quad.

Changing code to " #pragma surface surf Standard fullforwardshadows". AO stays in the back. The quad still renders its own AO properly (none in this case. Bad example)

I am even invoking the Standard lighting function, but to no avail. My shader code:
  1. Shader "Custom/testFoliageTwoPass" {
  2. Properties {
  3. _Color ("Color", Color) = (1,1,1,1)
  4. _MainTex ("Albedo (RGB)", 2D) = "white" {}
  5.  
  6. _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
  7. }
  8. SubShader {
  9. Tags {
  10. "RenderType"="TransparentCutout"
  11. "Queue"="alphatest"
  12. "IgnoreProjector"="True"
  13. }
  14. LOD 200
  15.  
  16. Cull Off
  17.  
  18. CGPROGRAM
  19. #pragma surface surf StandardTranslucent fullforwardshadows
  20. #pragma target 3.0
  21.  
  22. sampler2D _MainTex;
  23.  
  24. struct Input {
  25. float2 uv_MainTex;
  26. };
  27.  
  28. fixed4 _Color;
  29.  
  30. #include "UnityPBSLighting.cginc"
  31. inline fixed4 LightingStandardTranslucent(SurfaceOutputStandard s, fixed3 viewDir, UnityGI gi)
  32. {
  33. // Original colour
  34. fixed4 pbr = LightingStandard(s, viewDir, gi);
  35.  
  36. return pbr;
  37. }
  38.  
  39. void LightingStandardTranslucent_GI(SurfaceOutputStandard s, UnityGIInput data, inout UnityGI gi)
  40. {
  41. LightingStandard_GI(s, data, gi);
  42. }
  43.  
  44. void surf (Input IN, inout SurfaceOutputStandard o) {
  45. // Albedo comes from a texture tinted by color
  46. fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
  47. o.Albedo = c.rgb;
  48.  
  49. o.Alpha = c.a;
  50. }
  51. ENDCG
  52. }
  53. }

Does anyone have any clue to why the AO from the background is rendered on top of the quad? My suspicion is that it must be a deferred rendering path, but as I said I'm pretty new so I don't really know what that means..! But that's what my trail & erroring have showed. Am I on the right track?

Sign In or Register to comment.