I tried to use an additional alpha for sprites from a secondary texture, but the SpriteRenderer uses an alpha from the main texture. My shader on the MeshRenderer works as it should. I want to understand if it is possible to force the SpriteRenderer to use alpha from another source other than _MainTex. I use URP
For clarity, I have a main sprite (crocodile) and an additional sprite (outline). Here’s what it looks like on MeshRenderer:
That’s literally what I’m doing. And as you can see in the screenshots above, it works as it should on MeshRenderer using a Quad mesh. But SpriteRenderer apparently ignores alpha values that go beyond the alpha of the main texture.
This is what a shader graph looks like. It’s a bit more complicated than just two textures. But the bottom line is that if you specify any value in the alpha that goes beyond the alpha of the main texture, it will be ignored. In other words, it’s as if SpriteRenderer has additional alpha processing after the shader and multiplies the alpha of the main texture with the alpha from the shader.
i see, I think that you should make a final check, for example change the alpha of the secondary texture to something very different than the main tex, if the alpha remains equal to the main tex then at least you will have confirmation that the main tex alpha is hijacking the shader, and can move further from there
What might be happening is your sprite’s vertices are too close to the dino(tightness – outline tolerance), which prevents the fragment shader being executed on the outline pixels.
Also it is rather hard reading a low resolution screenshot. All you should do from what I see is sample the outline, add the outline’s alpha to main texture’s alpha and attach it to fragment’s alpha
It turned out to solve the problem and it consisted in the fact that SpriteRenderer really cuts the alpha according to the sprite shape, which is automatically generated when converting the texture to a sprite.
I found two solutions to this problem.
Use Custom Physics Shape and Custom Outline (to be honest, I still did not understand which one uses SpriteRenderer)
Use Extrude Edges in texture import settings
I had problems with the first option due to the strange behavior of SpriteRenderer when using default and custom sprite shaders. If you add a Custom Physics Shape or Custom Outline to a sprite, then the standard sprite shaders do not react to them in any way and display the standard shape of the sprite. At the same time, my shader changes the shape of the sprite.
But if you clear the Custom Physics Shape and Custom Outline and sort of return the standard sprite settings, my shader does not react to these changes in any way and continues to display the latest custom sprite shape. I’ve tried everything, it seems, to try to bring back the standard sprite shape settings, but it didn’t help. As a result, the only solution to this was to reimport the sprite (not by using the Reimport button in the context menu, but by reuploading the file to the assets folder).
As a result, I rejected the first option due to its unreliability and inconveniences in the setup. But using the second option, you can also face a problem, because in fact it has restrictions on the thickness of the outline. The maximum value is only 32 and if I need to add a sparite with a very thick outline, then it can also be cut off by the shape of the main sprite as before. I don’t think that I will encounter this specifically in my case, but still it doesn’t look like the right way to solve this problem.
This is how it looks with Extrude Edges 32 and the standard sprite shape