Tessellation Shader has stopped working

Hi
In my game I was trying to add a tessellation there. When I opened an example project it was working perfectly. When I added tessellation shader to my game, whole material got pink and even after pasting object from example to my game it was pink as well. After adding another shader, tessellation suddenly seemed to work for a while, but after some changes in shader files everything went pink again.

Here is the console output:

What can I do to make it working? In the player settings in Unity I’m using DirectX11 and 12, there is no difference on both. Other shaders are working.

The shader from below is added to the graphic settings to always included shaders.

Normal shader:

Tessellation:

post the code or itll be hard to help

This comes from Standard Assets, so there is no need to show code because it should work and everybody can see it from Unity, but I will if you wish.

Shader "Tessellation/Bumped Specular (displacement)" {
Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
    _Shininess ("Shininess", Range (0.03, 1)) = 0.078125
    _Parallax ("Height", Range (0.0, 1.0)) = 0.5
    _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
    _BumpMap ("Normalmap", 2D) = "bump" {}
    _ParallaxMap ("Heightmap (A)", 2D) = "black" {}

    _EdgeLength ("Edge length", Range(3,50)) = 10
}
SubShader {
    Tags { "RenderType"="Opaque" }
    LOD 800
  
CGPROGRAM
#pragma surface surf BlinnPhong addshadow vertex:disp tessellate:tessEdge
#include "Tessellation.cginc"

struct appdata {
    float4 vertex : POSITION;
    float4 tangent : TANGENT;
    float3 normal : NORMAL;
    float2 texcoord : TEXCOORD0;
    float2 texcoord1 : TEXCOORD1;
    float2 texcoord2 : TEXCOORD2;
};

float _EdgeLength;
float _Parallax;

float4 tessEdge (appdata v0, appdata v1, appdata v2)
{
    return UnityEdgeLengthBasedTessCull (v0.vertex, v1.vertex, v2.vertex, _EdgeLength, _Parallax * 1.5f);
}

sampler2D _ParallaxMap;

void disp (inout appdata v)
{
    float d = tex2Dlod(_ParallaxMap, float4(v.texcoord.xy,0,0)).a * _Parallax;
    v.vertex.xyz += v.normal * d;
}

sampler2D _MainTex;
sampler2D _BumpMap;
fixed4 _Color;
half _Shininess;

struct Input {
    float2 uv_MainTex;
    float2 uv_BumpMap;
};

void surf (Input IN, inout SurfaceOutput o) {
    fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
    o.Albedo = tex.rgb * _Color.rgb;
    o.Gloss = tex.a;
    o.Alpha = tex.a * _Color.a;
    o.Specular = _Shininess;
    o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
}
ENDCG
}

FallBack "Bumped Specular"
}

Bump… ( ͡° ʖ̯ ͡°)

Does anybody know what does that error mean when setting material to tessellation?

It happens with any tessellation shader from store or standard assets. And why other projects seem to be working but on mine tessellation just suddenly stopped working?

Im not sure what this is, but it seems to have problems with stuff related to GPU instancing. Also seeing as the error is on line 167 which is beyond what you have posted, I am guessing the error is in another script? Post that file and itll be easier to track it down.

As far as I can see from this code, you are not actually setting any properties as instanced, so the instancing must be in the tesselation cginc you have.

Tessellation and gpu instancing is not supported together I believe

Why?

1 Like

Not sure, this is what I was told and it seems to be true, turning on gpu instancing breaks tessellation. Is this a bug ?

I cant find the article, maybe it was specific to distance based tessellation

Well, I would expect those two things to work together :slight_smile:

I will try dig up where I found that info, could have been on the Unity blog

And how did you fixed it?

Feel free to see the bug I logged about this in 2018.3’s terrain instancing. When the displacement function is called, the instance id has not been set yet, so the compiler complains about an uninitialized structure.
Bug 1111579

This tread looks old but I’m having the same issue. I’m making a tessellation shader in Amplify and when I turn on Instancing it breaks.

This is broken and Unity has resolved the bug as won’t fix… So it’s instancing or tessellation, or write a vertex/fragment shader instead.

2 Likes

I got tesselation and GPU instancing working together. However, the shader is written for URP:

Shader "Custom/InstancedTesselation"
{
    Properties
    {
        _Color("Color", Color) = (1, 1, 1, 1)
        _Tesselation("Tesselation", Range(0, 32)) = 1
    }
        SubShader
    {
        Pass
        {
            //Tags {"LightMode" = "ForwardBase"}
            HLSLPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma hull hull
            #pragma domain domain
            #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
            #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
            #pragma multi_compile _ _SHADOWS_SOFT
            #pragma multi_compile_instancing
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"

            float random(float2 st) {
            return frac(sin(dot(st.xy, float2(12.9898,78.233))) * 43758.5453123);
            }

            struct appdata
            {
                float4 vertex : POSITION;
                float3 normal : NORMAL;
                UNITY_VERTEX_INPUT_INSTANCE_ID
            };

            struct t2f
            {
                float4 pos : SV_POSITION;
                float3 posWS : TEXCOORD0;
                float3 normal : NORMAL;
                UNITY_VERTEX_INPUT_INSTANCE_ID
            };

            struct v2d
            {
                float4 vertex : SV_POSITION;
                float3 normal : NORMAL;
                UNITY_VERTEX_INPUT_INSTANCE_ID
            };

            struct TessellationFactors
            {
                float edge[3] : SV_TessFactor;
                float inside : SV_InsideTessFactor;
            };

            v2d vert(appdata v)
            {
                v2d output;
                UNITY_SETUP_INSTANCE_ID(v);
                UNITY_TRANSFER_INSTANCE_ID(v, output);
                output.vertex = v.vertex;
                output.normal = v.normal;
                return output;
            }

            t2f tessVert(appdata v)
            {
                t2f output;
                UNITY_SETUP_INSTANCE_ID(v); //Insert
                UNITY_TRANSFER_INSTANCE_ID(v, output);
                VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz + random(v.vertex.xz));
                output.pos = vertexInput.positionCS;
                output.posWS = vertexInput.positionWS;
                output.normal = v.normal;
                return output;
            }

            float _Tesselation;

            TessellationFactors patchConstantFunction(InputPatch<v2d, 3> patch)
            {
                UNITY_SETUP_INSTANCE_ID(patch[0]);
                VertexPositionInputs vertexInput1 = GetVertexPositionInputs(patch[0].vertex.xyz);
                VertexPositionInputs vertexInput2 = GetVertexPositionInputs(patch[1].vertex.xyz);
                VertexPositionInputs vertexInput3 = GetVertexPositionInputs(patch[2].vertex.xyz);
                TessellationFactors f;
                f.edge[0] = _Tesselation;
                f.edge[1] = _Tesselation;
                f.edge[2] = _Tesselation;
                f.inside = _Tesselation;
                return f;
            }

            [patchconstantfunc("patchConstantFunction")]
            [domain("tri")]
            [partitioning("integer")]
            [outputtopology("triangle_cw")]
            [outputcontrolpoints(3)]
            v2d hull(InputPatch<v2d, 3> patch, uint id : SV_OutputControlPointID)
            {
                return patch[id];
            }

            [domain("tri")]
            t2f domain(TessellationFactors factors, OutputPatch<v2d, 3> patch, float3 barycentricCoordinates : SV_DomainLocation)
            {
                v2d v;
                #define MY_DOMAIN_PROGRAM_INTERPOLATE(fieldName) v.fieldName = patch[0].fieldName * barycentricCoordinates.x + patch[1].fieldName * barycentricCoordinates.y + patch[2].fieldName * barycentricCoordinates.z;
                MY_DOMAIN_PROGRAM_INTERPOLATE(vertex)
                MY_DOMAIN_PROGRAM_INTERPOLATE(normal)
                UNITY_TRANSFER_INSTANCE_ID(patch[0], v);
                return tessVert(v);
            }


            float4 _Color;

            float4 frag(t2f i) : SV_Target
            {
                UNITY_SETUP_INSTANCE_ID(i);

                half3 viewDirectionWS = SafeNormalize(GetCameraPositionWS() - i.posWS.xyz);

                BRDFData brdfData;
                float alpha = 1;
                InitializeBRDFData(_Color.xyz, 0, 0, 0, alpha, brdfData);


                //lighting
                half3 bakedGI = SampleSH(i.normal);
                VertexPositionInputs vertexInput = GetVertexPositionInputs(i.posWS.xyz);
                Light mainLight = GetMainLight(TransformWorldToShadowCoord(i.posWS.xyz));
                half3 col = GlobalIllumination(brdfData, bakedGI, 1, i.normal, viewDirectionWS);
                col += LightingPhysicallyBased(brdfData, mainLight, i.normal, viewDirectionWS);

                return float4(col, 1);
            }
        ENDHLSL
    }
    UsePass "Universal Render Pipeline/Lit/ShadowCaster"
    UsePass "Universal Render Pipeline/Lit/DepthOnly"
    }
        Fallback "Diffuse"
}

francois85 probably got the information that instancing and tesselation is incompatible from here:
[ Tessellation](http:// Tessellation)

2 Likes