So I am trying to make a color remap shader, to easily re-color my game with pre-defined color palettes. This graph modifies 1 texture2D, but when i display that in my game, the sprite atlas that tileset also uses distorts it entirely. I believe this is a uv issue? But I don’t know how to make the shader graph understand the atlas specific UVs. Heres an image of the shadergraph, and atlas
^this image is my shader graph, and the atlas on the right. I have tried subbing in other UVs, as well as attempting the solution on this post:
discussion post
This is from the post, maybe I set it up wrong but it doesn’t do much.
The left side is my game view (destroyed tileset).
Any ideas on what I’m doing wrong?
Hey I’m the same guy who replied in the thread you linked haha. I don’t see anything about injecting the sprite rect UVs in your shader graph as described in the linked thread. You said you tried that right? Is that logic meant to be in your shader graph screenshot?
Actually after looking at the graph more this seems to be just a simple color replace, which should not break when using a sprite atlas and should not need any sprite rect UV injecting.
Is this the full graph? Cause for example I see a yellow line hidden in the top right so not sure if anything else is happening there.
And what output are you expecting vs what output are you getting?
In general you should name the main texture property that you sample from exactly “MainTex” (instead of “Texture” in your case), as Unity will automatically set that depending on what sprite is assigned to the renderer. But as long as you assigned the “Texture” property correctly that should not have broken it still.
hey man! I posted this like minutes before running to work, the screenshot was from yesterday, the only change I made was implementing the update min and max sprite size (added to a script), adding those Vector2s to the shader graph, feeding those + a UV node into a Inverse loop node.
Just got back from work, heres the current version. On the right is the material itself, and the scene view is whats currently being displayed. When I disconnect, I’m left with the distortion shown previously. I can only attach one picture for some reason.
& This is my implementation of the code required:
void Start()
{
Vector2 minRaw = new Vector2(tilesheet.textureRect.xMin, tilesheet.textureRect.yMin);
Debug.LogWarning("minRaw: "+ minRaw);
Vector2 maxRaw = new Vector2(tilesheet.textureRect.xMax, tilesheet.textureRect.yMax);
Debug.LogWarning("maxRaw: "+ minRaw);
min = new Vector2(minRaw.x / tilesheet.texture.width, minRaw.y / tilesheet.texture.height);
max = new Vector2(maxRaw.x / tilesheet.texture.width, maxRaw.y / tilesheet.texture.height);
tileset.SetVector("_RecMin", min);
tileset.SetVector("_RecMax", max);
}
tilesheet is a Sprite with the same png.
The debugs both print (4.00, 4.00), the png itself is 256x256, each tile is 16x16.
I am so lost xD
Thank you for the help btw, you were super quick to respond.
So like I said in my second comment, this is unlikely to be a UV issue. You should not need to work with the sprite rect properties at all, that will only break it even more, so you can go ahead and revert all of that.
(Btw the debugs are only printing the same output because you’re printing “minRaw” twice, but that’s besides the point)
So we need to see what else is going wrong. Ideally I’d need a rough explanation or diagram of what the output is meant to be versus what it currently is. Ie is it just the colors that are wrong? Or are the shapes also totally wrong? Etc.
Have you tried renaming the “Texture” property to “MainTex” first of all?
Also is this material being used on a tilemap renderer, a sprite renderer, or something else?
Gotchu. Yes I realized the debug issue pretty quickly after posting that haha. I’m a little frustrated as I’m only able to post 1 image.
From Left to right: my shader graph, it filters through 2 sets of rgb colors, replacing them with ScriptableObjects filled with colors, so I can sub them out like color palettes. The Main preview is the final product. The scene view is what it looks like in game (The shader is working correctly at the moment because I have emptied the sprite atlas’s packaged image. On The right is the RGB tileset I used to make the level, before the material is applied.
I would keep it like this, but I have a TON of tile map grids in my game (I duplicate some for a 3D effect), I’d like to keep all the sprites packed in an atlas for optimization. I’m also left with weird lines between the tiles? You can see one example in the image, but I have that same tile map selected so it has an orange outline on it as well.
Thank you for the replies, I am unsure whether I’m allowed to add an itch.io link to the page for the game while in dev, but if you would like to play it to see the final product I can reply with a link!
*note, I took out the UV code & portion of the graph, I fixed the debugs, but it would completely cover the whole tiles in my ShaderGraphs “GrassB” Color, I have no clue as to why.
Ok that is still peculiar.
Like I mentioned in the previous comment, have you tried renaming the shader texture property to exactly “MainTex”? How are you setting the texture property right now?
Also the material is being used on a tilemap renderer I assume, right?
Regarding the orange lines, setting a padding value of something above 0 in the sprite atlas inspector will probably fix that.
Btw make sure to reply to this comment directly when replying to make sure I get a notification.
Hey, I completely missed the main texture part of your message! (idk how
).
I just made a build to my phone to test but I think that worked! I’m gonna test more when I’m home from work. Thanks for all the help!
Glad to hear that, you’re welcome!
When you have a shader property called exactly MainTex, Unity will automatically take care of assigning the correct texture when a new sprite is assigned to a renderer. Otherwise if it has any other name, you’ll have to make sure of that yourself via code. So generally you should always use MainTex when you want to sample based on the main sprite to keep things simple.