Search Unity

Custom tessellation shader not working with GI

Discussion in 'Shaders' started by Warrior1424, Apr 16, 2018.

  1. Warrior1424

    Warrior1424

    Joined:
    Sep 30, 2010
    Posts:
    984
    (tested this in 2017.3.0, 2017.4.1, and 2018b13)

    So I have this tessellation shader.
    For some reason, it won't generate the Albedo pass for the lightmapper, meaning that it never renders bounced light. If I swap to the standard shader, it does.

    I made a tessellation shader in Shader Forge and it handled everything just fine, but Shader Forge doesn't generate surface shaders and consequently doesn't work with mixed lighting so I figured I'd just do my shader by code.

    Messing with the height and edge length can make parts of the Albedo pass show up, and sometimes even fully cover the surface, but the rules for this are inconsistent and either way not really a solution.

    Here is what I mean by parts of it showing up (by the way, that isn't the mesh tessellating at this distance, just the base model which is high poly)


    The same thing happens with Unity's Tessellation Shader (which is where I got the tessellation part of my code from), which makes me worried.

    Here is the code:
    Code (CSharp):
    1. Shader "Custom/TessellationBump" {
    2.     Properties {
    3.         _MainTex ("Albedo (RGB), Height (A)", 2D) = "white" {}
    4.         _BumpMap("Normalmap", 2D) = "bump" {}
    5.         _Parallax("Height", Range(0.0, 1.0)) = 0.5
    6.         _EdgeLength("Edge length", Range(3,50)) = 10
    7.     }
    8.     SubShader {
    9.         Tags { "RenderType"="Opaque" }
    10.         LOD 200
    11.  
    12.         CGPROGRAM
    13.         #pragma surface surf Standard fullforwardshadows vertex:disp tessellate:tessEdge
    14.  
    15.         #pragma target 3.0
    16.  
    17. #include "Tessellation.cginc"
    18.  
    19.         struct appdata {
    20.         float4 vertex : POSITION;
    21.         float4 tangent : TANGENT;
    22.         float3 normal : NORMAL;
    23.         float2 texcoord : TEXCOORD0;
    24.         float2 texcoord1 : TEXCOORD1;
    25.         float2 texcoord2 : TEXCOORD2;
    26.     };
    27.  
    28.     float _EdgeLength;
    29.     float _Parallax;
    30.  
    31.     float4 tessEdge(appdata v0, appdata v1, appdata v2)
    32.     {
    33.         return UnityEdgeLengthBasedTessCull(v0.vertex, v1.vertex, v2.vertex, _EdgeLength, _Parallax * 1.5f);
    34.     }
    35.  
    36.     sampler2D _MainTex;
    37.  
    38.     void disp(inout appdata v)
    39.     {
    40.         float d = tex2Dlod(_MainTex, float4(v.texcoord.xy,0,0)).a * _Parallax;
    41.         v.vertex.xyz += v.normal * d;
    42.     }
    43.  
    44.      
    45.     sampler2D _BumpMap;
    46.  
    47.         struct Input {
    48.             float2 uv_MainTex;
    49.             float2 uv_BumpMap;
    50.         };
    51.  
    52.         void surf (Input IN, inout SurfaceOutputStandard o) {
    53.  
    54.             fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
    55.             o.Albedo = c.rgb;
    56.  
    57.             o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
    58.  
    59.             o.Metallic = 0;
    60.             o.Smoothness = 0;
    61.         }
    62.         ENDCG
    63.     }
    64.     FallBack "Diffuse"
    65. }
    66.  

    EDIT:
    So not really a solution as much as it is a workaround for now:
    Instead of using
    UnityEdgeLengthBasedTessCull

    I'm now using
    UnityDistanceBasedTess
     
    Last edited: Apr 16, 2018