Force shader graph preview to use shader model 5

I’m using a custom function that contains a call to GatherRed and I’m getting an error that says cannot map expression to ps_4_0 instruction set.
When I use #ifdef SHADERGRAPH_PREVIEW to prevent calling GatherRed in the preview the shader works in the scene but I’m still getting that error in the console.

Is there a way to force the shader graph preview to use shader model 5?

There isn’t a way to force a specific shader model in the preview, but you could provide an alternate method for the preview. For example, with the built-in Gather node, we provide a fallback method that samples the texture 4 times. Not optimal, but it functions. In the worse case, you could just tell the preview to return zero. You’d get a black preview, but it would prevent the error.

I already disabled the preview. My code looks like this:

void MyCustomFunction_float( float3 in_world_position, out float3 base_color, out float alpha, out float3 emission )
{
#ifdef SHADERGRAPH_PREVIEW
    base_color = float3(0, 0, 0);
    alpha = 1;
    emission = float3(0, 0, 0);
#else
    // My custom code here with the Gather function
#endif
}

But I’m still getting the error in the console even though the shader works in the scene view.

Your code looks like it’s set up correctly. I wouldn’t expect that to produce the error. Go ahead and send us a bug on it.

Any follow up or bug report? I’m trying to do the exact same thing, getting the exact error still in 6000.37f1.

I have to manually generate the shader and change the target to 4.5 myself.

Edit: Plugging Unity’s own “Gather” node right into the color output and generating the shader seems to confirm that #target 2.0 is used (alongside with the fallback using 4 x SampleLod).