Search Unity

Question [SOLVED] SampleTexture2DLOD alternative for GLES2.0 ?

Discussion in 'Shader Graph' started by _watcher_, Apr 25, 2020.

  1. _watcher_

    _watcher_

    Joined:
    Nov 7, 2014
    Posts:
    261
    Hi!

    I've encountered a brick wall in my shadergraph development.

    I'm trying to only use GLES2.0-friendly shaders.
    I need to connect a TilingAndOffset Node into SampleTexture2D's UV Input, which doesn't let me to connect (cant be used for vertex-stage sampling). So instead of SampleTexture2D i use SampleTexture2DLOD, which then does allow me to connect the out/in. However when the shader compiles, it gives me an error 'cannot map expression to vs_5_0 in: GLES20'. When i export for GLES3.0+, the shader still works, however in GLES2.0 it doesn't (the errors hit and i get pink texture).

    Does the SampleTexture2DLOD really require GLES3.0+? Or should i report bug?

    U2019.3.0f3
    ShaderGraph 7.1.8

    Any suggestion on how to circumvent this issue using ShaderGraph? What im trying to achieve is to 'animate' the movement of the tiled texture (the one with the white cricles), then use that as a vertex displacement for the MainTex Diffuse texture (btw i cant use Voronoi, its too slow).

    TL;DR:
    1) Using SampleTexture2DLOD requires GLES 3.0+ and shader breaks on GLES2.0-only devices.
    2) There is also a caching bug, making ShaderGraph's inspector [Compile and show code] button unusable.
    Both above cases were tested and are present on different versions on Unity and ShaderGraph up to U2020.1b and ShaderGraph 8.1.

     
    Last edited: Apr 25, 2020
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Hi @_watcher_ ,
    If you just need tiling, did you try with an UV node and some simple multiplication to get tiling? It would produce just the same result as your tiling node. However I don't know if it would affect your compatibility issue, but try it.
     
    _watcher_ likes this.
  3. _watcher_

    _watcher_

    Joined:
    Nov 7, 2014
    Posts:
    261
    Hi and thank you for the great suggestion! I was excited to try it, as i am using UV Nodes elsewhere and those graphs work fine with GLES2.0.

    However, the Shader Graph(SG) behaves super strangely when i use it..

    The errors 'cannot map expression to GLES20' always show (on the shader). This would suggest using UV node was unsuccessful.

    Situation like this can occur often:

    > Add UV Node and connect it to SampleTexture2DLOD but dont connect it to Master Node (so it doesnt cause trouble)
    > Save graph
    > publish to device
    >>> RESULT: pink texture
    > without touching anything, publish again to device
    >>> RESULT: everything works (no pink texture) - how is this possible when shader errors still show when selecting shader?

    Weird right? All that assuming the nodes are not even connected to Master!
    Again, shader Inspector constantly shows there are errors.
    If targeting GLES3.0+, this situation never occurs, everything seems to work all the time, as the errors seem to only be 2.0 related. Perhaps not enough testing was done on 2.0 specifically to detect/fix such issues.

    This looks like some cache problem and also im not even sure when the 'refresh' happens, as 'Save Asset' on graph doesnt seem to properly refresh (publish to device can still show error state, or not)

    I should really just learn HLSG/CG and avoid using this component until things like this are ironed out, makes me feel im not in control, weird behavior. And the above is just one of them.

    Further testing made me realize that it would be hard for anyone to help with my problem as it seems to be SG related. Maybe ill test with SG8.1 in U2020.1. If its fixed in there, ill post here later.

    UPDATE: I did my 2020.1 tests on ShaderGraph 8.1. The problems i outlined seemed to persist in 8.1, and some of those are directly related to this issue (which was supposed to be fixed in 8.0). Basically, once you hit 'Compile and show code' in shader inspector, all hell breaks loose. With 0 errors and 0 warnings, when i hit that button, i get 3 fatal errors and about 20 warnings, that persist (seems cached), even once the shadergraph shader is updated/saved asset. Even more so, once i select another shader graph asset, and then select the first asset, some of the errors from the former seem to show in the latter? Strange behavior!

    UPDATE2: This was a bug. Confirmed by Unity team. Now being worked on (issue tracker link).
     
    Last edited: Apr 30, 2020
  4. ChrisTchou

    ChrisTchou

    Unity Technologies

    Joined:
    Apr 26, 2017
    Posts:
    74
    Hello! I'm working on the bug above!

    However the bug only covers the compilation failures of the ShaderGraph generated shader. The caching/publishing issues are a separate problem; you may want to file those as a separate bug if you can reproduce them reliably.

    For the compilation failures, we can make the graph compile on GLES2, but we can't make it 'work' on older devices, as the hardware just doesn't support it. We want to make it easy to provide a fallback case for GLES2 though, so you can at least control how it should behave when it is on those devices.
     
  5. alexanderameye

    alexanderameye

    Joined:
    Nov 27, 2013
    Posts:
    1,383