Advertisement
adamsleepy_

Triplanar Shader for Godot

May 12th, 2025
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. shader_type spatial;
  2.  
  3. uniform sampler2D texture_x: source_color, repeat_enable;
  4. uniform sampler2D texture_y: source_color, repeat_enable;
  5. uniform sampler2D texture_z: source_color, repeat_enable;
  6.  
  7. uniform float UV_Scale = 0.5;
  8.  
  9. uniform vec4 albedo_modulate : source_color = vec4(1.0, 1.0, 1.0, 1.0);
  10. uniform float modulate_intensity : hint_range(0.0, 1.0);
  11.  
  12. void fragment() {
  13.     vec4 vertex = INV_VIEW_MATRIX * vec4(VERTEX, 1.0);
  14.     vec3 normal = normalize((INV_VIEW_MATRIX * vec4(NORMAL, 0.0)).xyz);
  15.     vec3 adjusted_normal = pow(abs(normal), vec3(8.0));
  16.     vec3 weights = adjusted_normal / (adjusted_normal.x + adjusted_normal.y + adjusted_normal.z) * 3.0;
  17.  
  18.     vec2 uv_x = vertex.zy * UV_Scale;
  19.     vec2 uv_y = vertex.xz * UV_Scale;
  20.     vec2 uv_z = vertex.xy * UV_Scale;
  21.  
  22.     float use_y_up = float(normal.y > 0.0);
  23.  
  24.     vec3 color_x = texture(texture_x, uv_x).rgb * weights.x;
  25.     vec3 color_y_up = texture(texture_y, uv_y).rgb * weights.y;
  26.     vec3 color_y_down = texture(texture_x, uv_y).rgb * weights.y;
  27.     vec3 color_z = texture(texture_z, uv_z).rgb * weights.z;
  28.  
  29.     ALBEDO = (color_x + mix(color_y_down, color_y_up, use_y_up) + color_z) / 3.0 * albedo_modulate.rgb + (albedo_modulate.rgb * vec3(modulate_intensity,modulate_intensity,modulate_intensity));
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement