#ShaderGraph custom function node errors

1 messages · Page 1 of 1 (latest)

willow trout
#

Hello, i am creating a simple sub graph to have the ability to use the SampleGrad function in shader graph. However i can't figure out how to correctly write the function so there are no errors.

In the Name texbox i have put the following:

CustomSampleGrad

In the Body textbox i have put the following:

float4 CustomSampleGrad(Texture2D tex, SamplerState samp, float2 uv, float2 ddx, float2 ddy)
{
    return tex.SampleGrad(samp, uv, ddx, ddy);
}

I get a syntax error however saying unexpected token '(' at line 174.
I am not sure how i should write my function node correctly.

#

I think i found it

#

I do not need to add the function body just the code inside it. and output it into the output variable

#

The correct code is below

result = tex.SampleGrad(samp, uv, ddx, ddy);
spice jetty
#

Yeah when using String mode you don't want the function name/params, the graph generates that for you. (Would also cause a few errors in File mode as the format needs to be very specific, the docs explain more)

You might also want to know you can get SampleGrad in graph without needing a custom function, by changing the Mip Sampling Mode under the Node Settings on the Sample Texture 2D node

willow trout
#

One small question maybe how do i get the sampler state from a texture?

spice jetty
#

Yeah, quite a hidden feature

spice jetty
#

Actually not sure if you can get it in graph, but leaving the port blank uses the sampler state from texture by default

willow trout