Created
May 25, 2025 16:53
-
-
Save partybusiness/9d8d639c44bbc72ba27e1017b89efe58 to your computer and use it in GitHub Desktop.
Godot shader that samples texture from world pos oriented with surface normal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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