Panoramic Mapping

SphericalUV  – it’s a Shader Algorithm that converts the 3D direction vector (usually from a reflection or view vector) into UV coordinates compatible with equirectangular (latitude-longitude) 360° textures.

 

It allows you to map panoramic environment textures (HDRIs or standard 360° images) onto reflective surfaces or skydomes, creating the illusion of spherical reflection or immersive surroundings.

Shader code
shader_type spatial;
render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_lambert, specular_schlick_ggx;

uniform sampler2D PanoramicTexture;

void fragment() {
	// Направление взгляда в мировом пространстве отражается от нормали
	vec3 view_dir = VIEW;
	vec3 normal = NORMAL;
	vec3 reflect_dir = reflect(view_dir, normal);

	// Вычисление долготы (longitude) и широты (latitude)
	float longitude = atan(reflect_dir.x, reflect_dir.z); // [-PI, PI]
	float latitude = acos(clamp(reflect_dir.y, -1.0, 1.0)); // [0, PI]

	// Нормализация в UV-координаты
	longitude = (longitude + 3.14159265359) / (2.0 * 3.14159265359); // [0..1]
	latitude = latitude / 3.14159265359; // [0..1]

	vec2 uv = vec2(longitude, latitude);

	// Семплируем панорамную текстуру
	vec4 tex_color = texture(PanoramicTexture, uv);
	ALBEDO = tex_color.rgb;
}
Tags
360, 360 Equirectangular, 360TextureMapper, environment, Latittude, Longitude, Map, mapping, Panoramic, reflection, spherical
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 Riko

Color Blind

UV Simple Rotation

Normal Reconstruct – Z

Related shaders

Parallax Mapping

Uniplanar mapping with dithered blending

“Omniplanar” Mapping

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments