Search Unity

Question DOTS, Handwritten CG shader SRP Batcher

Discussion in 'Graphics for ECS' started by muntes, Jan 18, 2023.

  1. muntes

    muntes

    Joined:
    Nov 24, 2021
    Posts:
    20
    Hi,

    I've ported from an older version of ECS where hybrid still worked on built-in pipeline. Now I run on graphics 1.0.0-pre.15 with URP.

    I'm mainly using this shader:
    Code (CSharp):
    1. Shader "Standard Unlit"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex ("Diffuse", 2D) = "white" {}
    6.         _LightmapTex("Lightmap", 2D) = "white" {}
    7.         _OcclusionTex("Occlusion", 2D) = "white" {}
    8.         _NormalmapTex("Normalmap", 2D) = "bump" {}
    9.         _SpecularmapTex("Specularmap", 2D) = "white" {}
    10.  
    11.         _Cube("Reflection Map", Cube) = "" {}
    12.  
    13.         [PerRendererData] _Color ("Color", Color) = (1,1,1,1)
    14.         [PerRendererData] _LightMapColor("__LightMapColor", Color) = (1, 1, 1, 1)
    15.        
    16.         [PerRendererData] _ShadingRootPosition("__ShadingRootPosition", Vector) = (1.0, 1.0, 1.0)
    17.         [PerRendererData] _ShadingDirection("__ShadingDirection", Vector) = (1.0, 1.0, 1.0)
    18.         [PerRendererData] _ShadingIntensity("__ShadingIntensity", float) = 1000
    19.         [PerRendererData] _MaxShadingColor("__MaxShadingColor", Color) = (1, 1, 1, 1)
    20.         [PerRendererData] _MinShadingColor("__MinShadingColor", Color) = (0.3, 0.3, 0.3, 1)
    21.         _SpecularColor("SpecularColor", Color) = (1, 1, 1, 1)
    22.         _Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
    23.         _TopLightColor("Top Light Color", Color) = (1, 1, 1, 1)
    24.         _CenterLightColor("Center Light Color", Color) = (0.95, 0.95, 0.95, 0.95)
    25.         _BottomLightColor("Bottom Light Color", Color) = (0.5, 0.5, 0.5, 0.5)
    26.  
    27.         _HasReflection("__HasReflection", Range(0,1)) = 0
    28.  
    29.         [HideInInspector] _Mode("__mode", Float) = 0.0
    30.         [HideInInspector] _SrcBlend("__src", Float) = 1.0
    31.         [HideInInspector] _DstBlend("__dst", Float) = 0.0
    32.         [HideInInspector] _ZWrite("__zw", Float) = 1.0
    33.         [HideInInspector][Enum(Off,0,Front,1,Back,2)] _Cull ("__cull", Int) = 2
    34.     }
    35.     SubShader
    36.     {
    37.         Tags{ "LightMode" = "UniversalForward" }
    38.         Blend [_SrcBlend] [_DstBlend]
    39.         ZWrite [_ZWrite]
    40.         Cull [_Cull]
    41.  
    42.         Pass
    43.         {
    44.             CGPROGRAM
    45.             #pragma multi_compile __ _HAS_LIGHTMAP
    46.             #pragma multi_compile __ _HAS_CUTOFF
    47.             #pragma multi_compile __ _HAS_NORMALMAP
    48.             #pragma multi_compile _NO_REFLECTION _REFLECTION_FROM_COLOR _REFLECTION_FROM_MAP
    49.             #pragma multi_compile __ _HAS_SHADING
    50.             #pragma multi_compile __ _HAS_LIGHTMAP_COLOR
    51.             #pragma multi_compile __ _HAS_OCCLUSION
    52.             #pragma multi_compile_instancing
    53.  
    54.             #pragma target 3.0
    55.             #pragma vertex vert
    56.             #pragma fragment frag          
    57.             #include "StandardUnlitShaderCore.cginc"
    58.                        
    59.             ENDCG
    60.         }      
    61.     }
    62.  
    63.     CustomEditor "StandardUnlitShaderGui"
    64. }
    I've managed to get it to work with URP but not with DOTS. Do I have any chance to create something similar with ShaderGraph or manually that would be compatible with UNITY_DOTS_INSTANCING and SRP Batcher?

    Could you guys send me in the right direction regarding the documentation/samples for handwritten shaders compatible with SRP? Thank you all!
     
  2. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    351
  3. muntes

    muntes

    Joined:
    Nov 24, 2021
    Posts:
    20
    Thanks for sharing this.
    I've managed to get it SRP-compatible and DOTS-compatible.
    upload_2023-1-19_14-59-40.png
    upload_2023-1-19_14-55-6.png
    I have the DOTS_INSTANCING_ON, couldn't find more info on this. What exactly means: "Missing DOTS_INSTANCING_ON variant"?
     
  4. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    351
    The error message is saying that it can't find all the required cbuffers in your shader, which would typically happen because you didn't have the keyword.

    However, your shader certainly has the keyword. I'm guessing you are just missing the right #include, so probably you should just add
    Code (CSharp):
    1. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"
     
    muntes likes this.