Local Screen Space UV

Screen space UV coordinates which stay attached to an object’s center as in this post: https://www.artstation.com/artwork/48zd5l

FOV calculation per Glitshy

Shader code
shader_type spatial;
render_mode unshaded;

uniform sampler2D image : source_color;
uniform vec2 tiling = vec2(1.0, 1.0);
uniform vec2 offset = vec2(0.0, 0.0);

varying vec4 node_position_clip;

void vertex() {
	 node_position_clip = (PROJECTION_MATRIX * vec4(NODE_POSITION_VIEW, 1.0));
}

void fragment() {
	vec2 local_uv = (SCREEN_UV * 2.0 - 1.0) * node_position_clip.w - node_position_clip.xy;
	
	// Adjust for aspect ratio and FOV
	local_uv.x *= VIEWPORT_SIZE.x / VIEWPORT_SIZE.y;
	local_uv *= -1.0 / PROJECTION_MATRIX[1][1];
	
	ALBEDO = texture(image, local_uv * tiling + 0.5 + offset).rgb;
}
Live Preview
Tags
screen-space, uv, vfx
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from tentabrobpy

Related shaders

guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Monkshovv
Monkshovv
6 months ago

Thank you so much