Godot Version
4.8
Question
Hello!
I’d like to display as an overlay a portion of a second texture on my sprites, it’s a world space decal of sorts that the game paints during play. Any idea how I could get the UVs into the shader? Since the sprite UV doesn’t go from 0->1 across U and V I can’t mix between two float2 parameters based on that. Or can I get hold of the quad’s UV before it’s transformed to the sprite’s frame data? I suppose I could transform the verts to world space and use that info…
Other idea is just to use a second sprite which will of course work but somehow I worry about that in terms of efficiency, and I’d have to faff about trying to get the size and alpha channel from the underlying sprite.
Thanks!
Why not just have a second sprite on your node that has a higher layer priority and just toggle it on and off as needed.
Yeah that’s my last resort. Be nice if all the geo didn’t need a second pass / set of nodes. there’s a big old bunch of small sprites that make up the level geometry. probably fine though.
Oh another reason I can’t really use layers is I’m y-sorting all my sprites and so other things that should be in front of the decal would then appear behind them.
OK, using the world position of the vertices works fine for me.
If I wanted 0->1 UV from the sprite verts I could use a shader parameter and input the sprite UVs from script (guess I’d have to calculate them myself from h_frames, v_frames and the frame index, not sure calculated UVs are accessible from the sprite2d class) and then remap the sprite UV to 0-1 using those. I don’t need to but maybe someone else will one day.
Pretty sure there are local overides (relative) for Z ordering though, so you should be able to work around that.