Skip to content

Instantly share code, notes, and snippets.

@partybusiness
Created May 25, 2025 16:53
Show Gist options
  • Save partybusiness/9d8d639c44bbc72ba27e1017b89efe58 to your computer and use it in GitHub Desktop.
Save partybusiness/9d8d639c44bbc72ba27e1017b89efe58 to your computer and use it in GitHub Desktop.
Godot shader that samples texture from world pos oriented with surface normal
shader_type spatial;
// if you have a mesh with big flat surfaces this might work better than a triplanar shader
// applied to a curved surfact this will look distorted
uniform sampler2D main_texture:source_color, repeat_enable;
uniform float scale = 1.0;
varying vec3 world_pos;
varying vec3 world_tangent;
varying vec3 world_binormal;
void vertex() {
world_pos = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz;
world_tangent = MODEL_NORMAL_MATRIX * TANGENT;
world_binormal = MODEL_NORMAL_MATRIX * BINORMAL;
}
void fragment() {
vec2 face_uv = vec2(dot(world_pos, world_tangent), dot(world_binormal, world_pos)) / scale;
ALBEDO = texture(main_texture, face_uv).rgb;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment