Search Unity

Bug SamplerState is broken and borderline useless

Discussion in 'Shader Graph' started by hippocoder, May 12, 2020.

  1. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Hi,

    1. can't define SamplerState in material editor blackboard. Doesn't show up
    2. SamplerState is years out of date and doesn't expose any of Unity's new goodies
    3. Can't reason about texture import settings
    4. SamplerState doesn't work on all platforms

    ...

    I cannot make a shader using a custom function node without relying on SamplerState, so the woeful state of that thing is a showstopper for custom function nodes, and I need to use code due to missing regular nodes and even because it's sane to use code...

    Please can you fix up shader graph a bit more aggressively, it's been out for a long long time and I held off using it for years anticipating you'd have enough time to iron out the basics you know?

    I think really, most people aren't trying to use it for much, are my expectations too high?
     
    Noisecrime likes this.
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    More specifically and frustratingly, there's no way to access the existing explicit sampler state a Texture property from within Shader Graph without some heinous hacks (usually involving manually editing generated code). This means you can't enable anisotropic filtering, or generally control the filtering quality via texture importer settings, for any texture not sampled via a built in SampleTexture node. This wouldn't be as horrible if there were existing Sample Texture #D LOD, Bias, and Grad nodes for all texture types, or maybe optional inputs on the base node to override.

    The current implementation is also missing options for per-axis wrap settings, something which the inline sampler state does support.
     
  3. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Is Strumpy Shader Editor coming back?
     
  5. alexandral_unity

    alexandral_unity

    Unity Technologies

    Joined:
    Jun 18, 2018
    Posts:
    163
    Have you filed this request with the public roadmap? The priority of work right now is on a much larger scale than "ironing out the kinks" to be honest, you can see that we're working on an entirely new output format for the graph. When it comes to smaller things like the sampler state support you mention, we prioritize that based on demand. Please put a proposal on that product board link so we can track it better! c:
     
  6. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Thank you for your reply, I've added a suggestion for this feature to be come more workable in the roadmap. I'm aware of the new SG in progress and am in a slack room for that somewhere but I didn't have any idea how far along you are with it, guessing it will be about 1-2 years?

    Grateful for the support, thanks :)
     
  7. alexandral_unity

    alexandral_unity

    Unity Technologies

    Joined:
    Jun 18, 2018
    Posts:
    163
    The new Master Stack is actually on track to be available by 2020.2 this fall, in compatible packages by the beta. It will be continually updated and maintained of course, but the initial feature version is actually quite soon. c:
     
  8. alexandral_unity

    alexandral_unity

    Unity Technologies

    Joined:
    Jun 18, 2018
    Posts:
    163
    Can I ask what version of the package you're using? The Sampler State can be defined on the blackboard so in-graph you can access the same state multiple times, but it is not available in the material inspector at all.

    Also, @bgolus you might already know this, but the explicit sampler state for a texture property can be accessed using a custom function node, you just need to know the reference name of your texture property. It's not an ideal workflow, but it is possible.
     
  9. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Yep. In the conversation that lead to this post I mentioned that option to @hippocoder.

    I was having some issues with explicit samplers in a version of the URP. Some passes were failing to compile, but testing again in 7.1.7 doesn't reproduce it. I don't remember which version I was using when I had the issue and I already deleted the test project I saw the issue in and migrated those assets to a different test project due to some other issues.
    (Upgrading an existing sample project to new versions of SRPs almost always breaks something requiring nuking a project and rebuilding it from scratch.)
     
    alexandral_unity likes this.
  10. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    So, on windows, if you do not use the texture the implicitly declared sampler state is created with, the compiler will strip the sampler. On Metal, it won't get stripped. So often what happens is you have some texture and sampler declaration (lets say _Diffuse, and sampler_Diffuse), and you reuse sampler_Diffuse all over the place. Then, in your shadow pass, the _Diffuse texture does not get sampled, and the compiler strips sampler_Diffuse from the code and reports that it cannot fine "sampler_diffuse" (without capitalization).

    The fix is to do something like:

    finalColor *= saturate(UNITY_SAMPLE_TEX2DARRAY_LOD(_Diffuse, float2(0,0), 11).r + 2);

    such that every pass ends up using the diffuse texture. Ugly, but with pipelining and it sampling the lowest LOD, about the best you can do.

    It would be nice if sampler states were no longer so "DX9" assuming that a texture and sampler are always paired, and can be stripped as one thing.