Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Are Sprites not supported by the SRP / Shader Graph?

Discussion in 'Graphics Experimental Previews' started by vProject, Apr 11, 2018.

  1. vProject

    vProject

    Joined:
    Sep 11, 2013
    Posts:
    8
    I have been testing out the built in lightweight pipeline and the shader graph and dont seem to be able to get sprites to play well with the system.

    Putting my shader graph shader on a sprite renderer gives this message:
    "Material does not have a _MainTex texture property"

    Adding a _MainTex property to the graph via the blackboard only adds it as an internal name to the graph, which doesn't help. I have made a script that forces the _maintex keyword on and applies a texture to maintex, but because it isn't linked up in the shadergraph to master output, it doesnt do anything.

    Am I missing something here, Is there a way to get this working? It seems like it should be as simple as naming a blackboard property to _MainTex.
     
    P_Jong and luislodosm like this.
  2. eduilnero

    eduilnero

    Joined:
    May 9, 2013
    Posts:
    15
    Hi, I am very interested on this topic too. I manager to get rid of the warning: "Material does not have a _MainTex texture property" but could not render the sprite properly. Here I show a screenshot of the material applied to a sprite and to a cube next to it (black spots on top of white).
    Is there a way to do this properly or it is still a feature in development? Thank you!
     

    Attached Files:

  3. luislodosm

    luislodosm

    Joined:
    Apr 26, 2016
    Posts:
    26
  4. eduilnero

    eduilnero

    Joined:
    May 9, 2013
    Posts:
    15
    Finally I managed to make it work, although I still need to hack the way to get the _MainTex naming. This is the solution to have a material working with a SpriteRenderer: https://forum.unity.com/threads/feedback-wanted-shader-graph.511960/page-12#post-3462968. And, in order to get the _MainTex what I do is select the shader graph in the explorer, then go to the Inspector in debug mode and change the name there. The problem is that every time you save the shader from the shader graph the naming will be regenerated and you will need to change it again manually. Finally, I had to set SpriteRenderer mode to Tiled or Sliced, Simple didn't work.
     
    disuperguy and St00nsa like this.
  5. vProject

    vProject

    Joined:
    Sep 11, 2013
    Posts:
    8
    Thanks very much for this :) was a huge help. I will try your method ehre and if its doesntr work out well for me ill just wait for them to fix it.
     
  6. luislodosm

    luislodosm

    Joined:
    Apr 26, 2016
    Posts:
    26
    Jamisco likes this.
  7. Grimreaper358

    Grimreaper358

    Joined:
    Apr 8, 2013
    Posts:
    789
    This is already possible since v2.0.x of shader graph, but this is only for Unity 2018 so if you have 2018.1 the newer versions of LWRP/HDRP and shader graph won't show up. Some changes needed to be made C++ side and that happened in 2018.2 so this is why it's not in 2018.1.
     
  8. luislodosm

    luislodosm

    Joined:
    Apr 26, 2016
    Posts:
    26
    Now, Shader Graph allows us to change the reference of the Texture 2D property in order to work with SpriteRenderer component. Unity 2018.2.0f2.

    Captura de pantalla 2018-07-15 a las 21.14.12.png

    Anyone knows how to use the color field in SpriteRenderer with a custom shader? Reference: _Color doesn't work.
     
    Last edited: Jul 15, 2018
    Mr_Rei and Jack31081988 like this.
  9. stalhandske

    stalhandske

    Joined:
    Mar 17, 2014
    Posts:
    24
    Yes, it actually looks like setting the reference to _MainTex works in 2018.2.0f2. I can only get it to work with PBR though. Trying to compile the graph with Unlit gives me the error

    Compilation error in graph at line 63 (on d3d11):
    redefinition of '_MainTex'
    UnityEditor.EditorApplication:Internal_CallUpdateFunctions()


    For getting the color, I tried with both _Color and _RendererColor as these are the two colors in the default Sprite shader. Unfortunately, no luck getting them to work.
     
  10. febucci

    febucci

    Joined:
    Sep 3, 2015
    Posts:
    19

    Yes, at the moment sprites only work with a PBR shader. (_MainTex as you know gives an error on an Unlit Shader)

    Here's a simple Diffuse shader I made for sprites, the Sprite Renderer Color and FlipX/Y work.
    It's also compatible with Sprite Atlases.



    Hope this helps!
     
    OtakuD likes this.
  11. vProject

    vProject

    Joined:
    Sep 11, 2013
    Posts:
    8
    Yeah Unlit doesn't work with _MainTex atm, should see a little performance bump when it does work though.

    And remember on your PBR's plug the texture alpha of the texture to both the master Alpha and master AlphaClipThreshold, it will reduce pixel overdraw. You may need to run it through a multiply node first to fine tune the edges.

    I am really loving the the shader graph so far. I have made a 2d fog that blends the texture with a fog color based on a sprites world y and world z (or layer order). So fog sits low on the ground and gets thicker the further back it goes.

    Everything you see in this scene apart from the water and the pink ball are powered by a single shader. All of the sprites are imported in as white, their color is determined by the shader.


    I even added in a day night cycle that has <1% framerate impact as its just color lerping on a timer.

    Here is the same scene at dawn:


    The background sprites are preblurred and just placeholder for testing. The only PP is fast mdoe bloom from the LWRP.
     
  12. Deleted User

    Deleted User

    Guest

    Any news to this topic? Is there a fix?
     
    Last edited by a moderator: Dec 13, 2018
    Robiwan and P_Jong like this.
  13. Deleted User

    Deleted User

    Guest

  14. hbflyhbfly

    hbflyhbfly

    Joined:
    Oct 21, 2017
    Posts:
    2
    The thing is on unity 2018.2.8,and the shadergrap is 2.0.6 still.:(:(:(
    Anyone know how to fix it ?
     
  15. Wokarol

    Wokarol

    Joined:
    Aug 1, 2017
    Posts:
    34
    Looks like this strange unlit error is still presented
     
  16. ant001

    ant001

    Joined:
    Dec 15, 2010
    Posts:
    116
    2018.3 also has this problem with Unlit Shaders.
     
  17. Deleted User

    Deleted User

    Guest

    Did someone test this issue with 2019?
     
  18. pit-travis

    pit-travis

    Joined:
    Sep 17, 2018
    Posts:
    14
    unlit is still not working with 2019.
     
  19. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    I'm a little confused about what I'm experiencing with respect to using a Shader Graph shader in a screen-space canvas. I've set up the shader pretty much as everyone else has described:

    upload_2019-3-30_21-30-59.png

    I can see the images in the Scene view, but they don't show up in the Game View. The images appear in the game view if I remove the material from them, but as soon as I apply the material they disappear from the game view. Is this just the way things work with HDRP and shader graph shaders in the UI? I'm using 2018.3 and HDRP 4.10.


    upload_2019-3-30_21-30-21.png
     
  20. Siro360

    Siro360

    Joined:
    Oct 14, 2018
    Posts:
    6
    you can use the HDRP/unlit master node if you are using the hdrp. it seems to work there.
     
  21. jayatubi

    jayatubi

    Joined:
    Dec 9, 2013
    Posts:
    143
    Any updates for using _MainTex in a Unlit shader?
     
    Immu likes this.
  22. leshemamit

    leshemamit

    Joined:
    Feb 16, 2018
    Posts:
    3
    Hey, I've recently made a tutorial about using the Shader Graph for a UI Image with Unlit Shader and fixed a number of issues with it.
    hope anyone seeing this thread in the future will find it helpful:

     
  23. jayatubi

    jayatubi

    Joined:
    Dec 9, 2013
    Posts:
    143
    How did you make the unlit work with _MainTex without errors?
     
  24. Pram

    Pram

    Joined:
    Oct 17, 2012
    Posts:
    1
    Thanks for the video leshemamit, I have tried your solution but unlit does not work with _MainTex. I am using Unity 2018.3.7f1.

    Compilation error in graph at line 63 (on d3d11):
    redefinition of '_MainTex'
     
  25. JMackTurbine

    JMackTurbine

    Joined:
    Jan 4, 2019
    Posts:
    1
    @Pram & JayaTubi, Leshemamit is using unity 2019.1 it is fixed there which doesn't help us currently.
     
  26. Wokarol

    Wokarol

    Joined:
    Aug 1, 2017
    Posts:
    34
    I'm alsmost sure it is fixed in 2018.4 too, or something like that
     
  27. jayatubi

    jayatubi

    Joined:
    Dec 9, 2013
    Posts:
    143
    Thanks for updates.

    BTW I would suggest to use the Amplify Shader Editor which could the best shader tool for unity.
     
  28. Marker-jiang

    Marker-jiang

    Joined:
    Nov 6, 2018
    Posts:
    2
    That works perfectly.Thank you.
     
  29. TheElumenati

    TheElumenati

    Joined:
    Jan 22, 2014
    Posts:
    38
    thank you febucci your post helped me.

    Some additional notes if you want HDR colors in the shader....

    The color for sprites is sent to the shader via the vertex color and not a shader parameter.

    This is why you don't use a color parameter you need to pull the color from the vertex.
    One side effect of that is that the color picker on the sprite renderer is restricted to 0-1 (even feeding it hdr colors it clamps the input).

    That being said you can "roll your own" floating-point colors

    * Use the vertex rgb as the mantissa and the vertex alpha as a shared exponent
    HDR.rgb = Vertex.rgb*10^(Vertex.a*100)
    HDR.a = 1

    * use a shader parameter HDR color to multiply the vertex RGB components from 0-1 to a bigger range.

    Dr. Clement Shimizu
     
    Aseemy likes this.
  30. disuperguy

    disuperguy

    Joined:
    Nov 6, 2019
    Posts:
    8
    thank you
     
  31. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    In case it helps anyone else, I ran into this issue today, but only in a build. It was pretty much the same issue: Material doesn't have a texture property '_MainTex'

    TLDR, the issue was that one of my Images didn't have a Sprite assigned to it. Simply assigning a sprite was all it took to fix this.

    It took a while to narrow this down, both because it only occurred in a build, and because the error is simply wrong in its language. Here's the relevant part of the shader that was causing this error:

    upload_2020-8-5_22-16-38.png

    The shader has a _MainTex property. However, I'm assuming that because there was no Sprite assigned to the image, something weird went on internally such that the engine stripped out the _MainTex, resulting in the confusing error message.

    This particular image didn't have a sprite because I really just needed a solid white square. So, in the end, I just assigned a solid white image, and the error went away.