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);
uniform vec2 offset = vec2(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;
}
Tags
screen-space, uv
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

N64 Style Skybox

Surface Embedded Sprites

Related shaders

Local Space Y-Billboard Shader

screen space refraction shader

Screen-Space Edge Detection Outline Shader

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments