I’m trying to make a Re-usable Texture2DGrad node, so that I can pass in custom derivatives for certain effects.
However I can’t figure out a way to use the SamplerState from an existing texture, I can only use a custom SamplerState which is limited to either Point, Bilinear or Trilinear.
This is an issue because in vert/frag shaders, you can declare SamplerState sampler_TextureName;
and it will inherit the properties of the texture, including wrap, filtermode and anisotropy. This way, when Anisotropic Textures are enabled through QualitySettings, your custom shaders which use SampleGrad/Tex2DGrad will also use anisotropic filtering automatically.
My custom function looks like this currently. It requires manually passing in a SamplerState in ShaderGraph, but as far as I can tell there’s no way to get the SamplerState from a texture, so it’s always going to be either bilinear or trilinear, with no anisotropic filtering.
A pretty simple fix would just be a way to get the SamplerState from a texture in ShaderGraph, not sure how I would do this though.
void SampleTexture2DGrad_float(TEXTURE2D(tex), SAMPLER(texSampler), float2 uv, float2 gradX, float2 gradY, out float4 color, out float r, out float g, out float b, out float a)
{
color = SAMPLE_TEXTURE2D_GRAD(tex, texSampler, uv, gradX, gradY);
r = color.r;
g = color.g;
b = color.b;
a = color.a;
}