summaryrefslogtreecommitdiff
path: root/common/shaders
diff options
context:
space:
mode:
Diffstat (limited to 'common/shaders')
-rw-r--r--common/shaders/math/common_utils.wgsl10
1 files changed, 10 insertions, 0 deletions
diff --git a/common/shaders/math/common_utils.wgsl b/common/shaders/math/common_utils.wgsl
index 7131216..49aaead 100644
--- a/common/shaders/math/common_utils.wgsl
+++ b/common/shaders/math/common_utils.wgsl
@@ -34,3 +34,13 @@ fn grid_pattern(uv: vec2<f32>) -> f32 {
// NOTE: calc_sdf_normal_bumped() removed - too specialized, depends on get_dist()
// from scene_query snippets. Keep bump mapping code inline in shaders that use it.
+
+// Calculates normalized screen coordinates from fragment position and resolution.
+// Input `p` is the fragment's @builtin(position), `resolution` is the screen resolution.
+// Returns a vec2<f32> in NDC space, with X adjusted for aspect ratio.
+fn getScreenCoord(p: vec4<f32>, resolution: vec2<f32>) -> vec2<f32> {
+ let q = p.xy / resolution;
+ var coord = -1.0 + 2.0 * q;
+ coord.x *= resolution.x / resolution.y;
+ return coord;
+}