Are Sprites not supported by the SRP / Shader Graph?

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.

2 Likes

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!

Unity said that they are working on it. Feedback Wanted: Shader Graph page-12

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: Feedback Wanted: Shader Graph 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.

2 Likes

Thanks very much for this :slight_smile: 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.

In the next update, we will be able to change the texture name for using with sprite renderer. ShaderGraph/CHANGELOG.md at master · Unity-Technologies/ShaderGraph · GitHub

1 Like

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.

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.

3564830--287298--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.

2 Likes

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

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.

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!

1 Like

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.

Any news to this topic? Is there a fix?

2 Likes

BUMP?!?

The thing is on unity 2018.2.8,and the shadergrap is 2.0.6 still.:(:(:frowning:
Anyone know how to fix it ?

Looks like this strange unlit error is still presented

2018.3 also has this problem with Unlit Shaders.

Did someone test this issue with 2019?

unlit is still not working with 2019.

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:

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.

you can use the HDRP/unlit master node if you are using the hdrp. it seems to work there.