From d684fc4096e5dff97a6750e027c373c06a085031 Mon Sep 17 00:00:00 2001 From: Ben Doherty Date: Fri, 3 Mar 2023 13:48:36 -0800 Subject: [PATCH] Compute shading_view will full precision (#6611) --- NEW_RELEASE_NOTES.md | 1 + shaders/src/shading_parameters.fs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/NEW_RELEASE_NOTES.md b/NEW_RELEASE_NOTES.md index 79fa6008ea..e535fc5f86 100644 --- a/NEW_RELEASE_NOTES.md +++ b/NEW_RELEASE_NOTES.md @@ -10,3 +10,4 @@ appropriate header in [RELEASE_NOTES.md](./RELEASE_NOTES.md). fog: fixed fog height falloff and computation precision on mobile [⚠️ **Recompile Materials**] materials: new alphaToCoverage property can be used to control alpha to coverage behavior +engine: fix precision issue with `shading_view` in large scenes diff --git a/shaders/src/shading_parameters.fs b/shaders/src/shading_parameters.fs index 0ce5ca0caf..222f7831d9 100644 --- a/shaders/src/shading_parameters.fs +++ b/shaders/src/shading_parameters.fs @@ -36,10 +36,10 @@ void computeShadingParams() { // With perspective camera, the view vector is cast from the fragment pos to the eye position, // With ortho camera, however, the view vector is the same for all fragments: - shading_view = isPerspectiveProjection() ? + highp vec3 sv = isPerspectiveProjection() ? (frameUniforms.cameraPosition - shading_position) : frameUniforms.worldFromViewMatrix[2].xyz; // ortho camera backward dir - shading_view = normalize(shading_view); + shading_view = normalize(sv); // we do this so we avoid doing (matrix multiply), but we burn 4 varyings: // p = clipFromWorldMatrix * shading_position;