Nice tutorial! It is very helpful and its not covered many places. Although I find it annoying to transcript the code from the video so if anyone is lazy here it is: shader_type canvas_item; varying flat vec2 vertexPos[2]; uniform vec2 globalMousePos; void vertex() { vertexPos[0] = (MODEL_MATRIX * vec4(VERTEX, 0.0, 1.0)).xy; } void fragment() { // Place fragment code here. float isWithinY = step(vertexPos[0].y, globalMousePos.y) * step(globalMousePos.y, vertexPos[0].y + 64.); float isWithinX = step(vertexPos[0].x, globalMousePos.x) * step(globalMousePos.x, vertexPos[0].x + 64.); float isWithin = isWithinY * isWithinX; vec4 textureColor = texture(TEXTURE, UV); COLOR = mix(textureColor, vec4(0.7,0.,0.,1.0), 0.7* isWithin) ; }
Really useful, thanks! I'm using this for a game! A lil tip for future Godot 4 devs using the TileMapLayers - one can use a separate TileMapLayer for highlighting. Pretty much what you did for Godot 3. I had to hit my head on the wall for a bit before landing on that solution π΅βπ«
Sick video I think maybe you could have dwelled on basic things (like how a vec4 can encode color via rgba). Itβs not explicitly related to the main aim of the video, but since the shader in the video is relatively simple, it could double as a good intro to shaders as a whole if you explained basic concepts more thoroughly. Still really cool, though, and good explanation over-all. - co-developer :)
I should have made the shader editor bigger :p Hope you guys enjoy Going to be posting more game dev stuff here or on maybe a new channel. Subscribe for that if you are interested.
how come when i rotate my tile it no longer works the same
This was so helpful. Thanks. But I realized that if you have some rotated tiles (when you paint them on tilemap menu), then this shader only selects that tile with an offset of the mouseposition. The offset changes depending on the rotation. Do you have any idea why that is happening?
Very helpful tutoial! only the thing is i'm working with an isometric tileset and the position is slightly off. in my tilemap scipt i'm using the local mouse position, not the global one. Do you know how that would be possible within a shader?
Great video! But there is something weird happening in my project, checking if it is within x works great but within y does weird things, it highlights halves of cells in two rows instead of one full row of cells, do you have an idea why that is happening? The only difference I see in my project is the fact, that my cells are not squares but rectangles, I hoped that adding my cell size in places where you add 64 would work, but maybe this is the problem? Though, when I change the size to 64X64 it doesn't work either. Sorry for my english, but it's not my first language and I still have problem writing using it.
Does this work for hexagonal grids?
@Infini-Creation