Advertisement
AQtun

world space texture sampling 2D

Nov 19th, 2024 (edited)
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // uniforms
  2. uniform mat4 inv_proj;
  3. uniform vec2 screen_resolution;
  4. uniform vec2 uv_scale = vec2(1.0, 1.0);
  5.  
  6. // calculate world space
  7. vec2 screen_normalized = (gl_FragCoord.xy / screen_resolution) * 2.0 - 1.0;
  8. vec2 world_space = (inv_proj * vec4(screen_normalized, 0.0, 1.0)).xy;
  9.  
  10. // sample texture
  11. vec3 color = texture(terrain_texture, world_space * uv_scale).rgb;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement