I'm making an isometric voxel game. I'd like to make it so that if a character is obscured by a roof that is exactly 3 blocks above the player, then the roof is moved over 2 blocks so that you can see the player and still and interact with whatever is on the roof.
I've got this shader code which kind of does what I want except that it deforms the roof:
void vertex() {
vec3 _pixel_world_pos = (WORLD_MATRIX * vec4(VERTEX, 1.0)).xyz;
if (_looking_up) {
// If the pixel is part of a roof aka exactly 2 blocks above the player
if ( _pixel_world_pos.y > _player_position.y + 2.0) {
// Move the vertex over 2 blocks in world space
_pixel_world_pos.z += 2.0;
// Convert back object space
VERTEX = (inverse(WORLD_MATRIX) * vec4(_pixel_world_pos, 1.0)).xyz;
}
}
}
Before (The white thing is the character):
After:

I'd like the blocks to still be blocks and not be stretched out.
Any idea why that could be happening?
Thanks!