Expose SamplerState from Texture

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;
}
7 Likes

Same problem here - looking for a way to pass in the sampler for a user-provided texture into a custom function.

1 Like

Same. In my case I want to use anisotropic sampler inside a custom function, but A) shader graph sampler state node provides no control over anisotropy, so I can’t wire an appropriate sampler state node into the function, and B) there appears to be no way to access the anisotropic sampler state already associated with the texture input.

Same issues here. Has anyone found a solution to this issue? Has anyone found a solution?

Yes please. To make things worse, the boolean or enum nodes don’t support SamplerState as a transported type in case you need to chose based on preprocessors definition. Also, the SS cannot be plugged into a Branch node, so we’re basically stuck with NO way to either:

  • Fetch the SS from texture.
  • Switch between multiple SSs either at run-time or compile-time.

Just hit this problem too. Would like to specify SamplerState values in a material.

I know it has been too long but there is a solution with new subgraph:

Usage:
Use float values for SamplerState:
For Filter: 0 = Linear, 1 = Point, 2 = Trilinear
For Warp: 0 = Repeat, 1 = Clamp, 2 = Mirror, 3 = Mirror Once

Also, you should connect UV Node to uv port of node to show texture.

Example usage:

7629637–949516–ExposedSamplerState.unitypackage (5 KB)