How to feed a sampler2D to a Custom Function

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!

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:

SAMPLE_TEXTURE2D(texture, samplerState, uv);