Search Unity

Feature Request Expose SamplerState from Texture

Discussion in 'Shader Graph' started by Arycama, Mar 1, 2020.

  1. Arycama

    Arycama

    Joined:
    May 25, 2014
    Posts:
    184
    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.

    Code (CSharp):
    1. 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)
    2. {
    3.     color = SAMPLE_TEXTURE2D_GRAD(tex, texSampler, uv, gradX, gradY);
    4.     r = color.r;
    5.     g = color.g;
    6.     b = color.b;
    7.     a = color.a;
    8. }
     
    ddabble, Serenity, florianBrn and 4 others like this.
  2. huwb

    huwb

    Joined:
    Oct 19, 2013
    Posts:
    24
    Same problem here - looking for a way to pass in the sampler for a user-provided texture into a custom function.
     
    MikeyMyk likes this.
  3. paradoxical-jay

    paradoxical-jay

    Joined:
    Jan 28, 2020
    Posts:
    8
    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.
     
  4. Ziflin

    Ziflin

    Joined:
    Mar 12, 2013
    Posts:
    132
    Same issues here. Has anyone found a solution to this issue? Has anyone found a solution?
     
  5. AlexTuduran

    AlexTuduran

    Joined:
    Nov 26, 2016
    Posts:
    27
    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.
     
  6. MikeyMyk

    MikeyMyk

    Joined:
    Nov 20, 2012
    Posts:
    9
    Just hit this problem too. Would like to specify SamplerState values in a material.
     
  7. Warwlock

    Warwlock

    Joined:
    Aug 17, 2018
    Posts:
    40
    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:
    Capture.PNG
     

    Attached Files: