Skip to content

Instantly share code, notes, and snippets.

@partybusiness
Last active December 18, 2024 01:43
Show Gist options
  • Save partybusiness/bdcc89213f1aade8684219c65a5a7548 to your computer and use it in GitHub Desktop.
Save partybusiness/bdcc89213f1aade8684219c65a5a7548 to your computer and use it in GitHub Desktop.
shader_type sky;
uniform sampler2D skyTexture:source_color;
void sky() {
COLOR = textureLod(skyTexture, SKY_COORDS, 0.0).rgb;
}
shader_type spatial;
render_mode unshaded;
uniform sampler2D skyTexture:source_color;
vec2 view_dir_to_equirectangular(vec3 view_dir) {
float y = 0.5 - (atan(view_dir.y, length(view_dir.xz)) / 3.14159);
//float y = 0.5-view_dir.y*0.5;
float x = -atan(view_dir.x, view_dir.z) / (3.14159 * 2.0) + 0.5;
return vec2(x, y);
}
varying vec3 world_position;
void vertex()
{
world_position = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz;
}
void fragment() {
vec3 view_dir = normalize(world_position - CAMERA_POSITION_WORLD);
vec2 sky_coords = view_dir_to_equirectangular(view_dir);
ALBEDO = textureLod(skyTexture, sky_coords, 0.0).rgb;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment