Search Unity

Question How to feed a sampler2D to a Custom Function

Discussion in 'Shader Graph' started by eco_bach, Mar 20, 2021.

  1. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Trying to feed a sampler2D into my Custom Function pixel shader but there is no 'sampler2D' type for input.

    My .hlsl custom function pixel shader is using a tex2D method which expects a sampler2D as the first argument.

    If I use Vector4 as an Input Type in my Custom Function instead I get the error
    'cannot implicitly convert from 'float4' to 'sampler2D'

    Frustrating!

    sampler2D.JPG
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Hi,

    You can use SAMPLE_TEXTURE2D or SAMPLE_TEXTURE2D_LOD to sample a texture. I think you need to pass in the texture and the sampler state as an input parameter.

    Then to sample the texture in your custom function:
    Code (CSharp):
    1. SAMPLE_TEXTURE2D(texture, samplerState, uv);