Search Unity

Feature Request Shader Model 5.0 functions don't work

Discussion in 'Shader Graph' started by Arycama, Feb 23, 2020.

  1. Arycama

    Arycama

    Joined:
    May 25, 2014
    Posts:
    185
    I'd like to port a shader which uses some DX11 functions, such as GatherRed, GatherGreen, CalculateLevelOfDetail, and RWTexture2D.

    Example code is below (I'm using a File for the custom function):

    Code (CSharp):
    1. void GatherRed_float(Texture2D Texture, float2 UV, SamplerState Sampler, out float4 Out)
    2. {
    3.     Out = Texture.GatherRed(Sampler, UV);
    4. }

    However using a custom node gives me the following error. I assume this is because the instructions require shader model 4. I'm guessing ShaderGraph defaults to #pragma target 4.0.

    Is there a way to make this work with ShaderGraph? Eg forcing the Shader or custom node to require a higher shader model than 4? 4 seems like a pretty low target considering the modern platforms that HDRP targets, so I really hope this is possible or at least planned for the near future, as it prevents a lot of advanced techniques from being implemented in ShaderGRaph.

    upload_2020-2-23_12-19-3.png
     
    Last edited: Feb 23, 2020
  2. Arycama

    Arycama

    Joined:
    May 25, 2014
    Posts:
    185
    Weirdly enough, the compiled shader code for a HDRP shader does have #pragma target 4.5 specified, which should be able to support the instructions. (If I make a custom shader with the same target and instructions, it compiles fine)

    So it seems like ShaderGraph just won't accept custom functions that require #pragma target 4.5, even though that's what the final shader is compiled to?

    This is a bit strange, and also hard to find any documentation on.
     
  3. alexandral_unity

    alexandral_unity

    Unity Technologies

    Joined:
    Jun 18, 2018
    Posts:
    163
    The _preview_ shader doesn't map to 4.5 if I'm remembering properly. You need to wrap your code in an ifdef for SHADERGRAPH_PREVIEW and output a hard coded value for the preview boxes, and then it should work in scene and not give you errors.
     
    Nobuu-Nakata likes this.