From 8e24055dcc76b08804cdc46a7b61ad41d7eb0008 Mon Sep 17 00:00:00 2001 From: Gajanan Date: Sun, 1 Dec 2024 14:36:26 +0530 Subject: [PATCH 1/2] Fixed Matrix Multiplication Shaders --- packages/engine/Source/Shaders/SkyAtmosphereVS.glsl | 3 ++- packages/engine/Specs/Scene/MultifrustumSpec.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/engine/Source/Shaders/SkyAtmosphereVS.glsl b/packages/engine/Source/Shaders/SkyAtmosphereVS.glsl index 8ed97f1a0979..0696ecff084d 100644 --- a/packages/engine/Source/Shaders/SkyAtmosphereVS.glsl +++ b/packages/engine/Source/Shaders/SkyAtmosphereVS.glsl @@ -27,5 +27,6 @@ void main(void) #endif v_outerPositionWC = positionWC.xyz; - gl_Position = czm_modelViewProjection * position; + vec4 positionEC = czm_modelView * position; + gl_Position = czm_projection * positionEC; } diff --git a/packages/engine/Specs/Scene/MultifrustumSpec.js b/packages/engine/Specs/Scene/MultifrustumSpec.js index f981a3de2845..7bce4075976c 100644 --- a/packages/engine/Specs/Scene/MultifrustumSpec.js +++ b/packages/engine/Specs/Scene/MultifrustumSpec.js @@ -237,7 +237,7 @@ describe( vs += "in vec4 position;"; vs += "void main()"; vs += "{"; - vs += " gl_Position = czm_modelViewProjection * position;"; + vs += " vec4 positionEC = czm_modelView * positiong; l_Position = czm_projection * positionEC;"; vs += closestFrustum ? " gl_Position.z = clamp(gl_Position.z, gl_DepthRange.near, gl_DepthRange.far);" : ""; From 8196a22dd962e0cab1a84b2da1ddfc46c721c5c4 Mon Sep 17 00:00:00 2001 From: Gajanan Date: Tue, 10 Dec 2024 15:52:17 +0530 Subject: [PATCH 2/2] Fixed all --- .../Shaders/Builtin/Functions/modelToWindowCoordinates.glsl | 3 ++- packages/engine/Source/Shaders/DepthPlaneVS.glsl | 4 ++-- packages/engine/Source/Shaders/EllipsoidVS.glsl | 4 ++-- packages/engine/Source/Shaders/GlobeVS.glsl | 3 ++- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/engine/Source/Shaders/Builtin/Functions/modelToWindowCoordinates.glsl b/packages/engine/Source/Shaders/Builtin/Functions/modelToWindowCoordinates.glsl index 0244f84d4a43..f6af20d7bac8 100644 --- a/packages/engine/Source/Shaders/Builtin/Functions/modelToWindowCoordinates.glsl +++ b/packages/engine/Source/Shaders/Builtin/Functions/modelToWindowCoordinates.glsl @@ -30,7 +30,8 @@ */ vec4 czm_modelToWindowCoordinates(vec4 position) { - vec4 q = czm_modelViewProjection * position; // clip coordinates + vec4 positionEC = czm_modelView * position; + q = czm_projection * positionEC; q.xyz /= q.w; // normalized device coordinates q.xyz = (czm_viewportTransformation * vec4(q.xyz, 1.0)).xyz; // window coordinates return q; diff --git a/packages/engine/Source/Shaders/DepthPlaneVS.glsl b/packages/engine/Source/Shaders/DepthPlaneVS.glsl index b5204ec2f53d..01898473b9ba 100644 --- a/packages/engine/Source/Shaders/DepthPlaneVS.glsl +++ b/packages/engine/Source/Shaders/DepthPlaneVS.glsl @@ -5,7 +5,7 @@ out vec4 positionEC; void main() { positionEC = czm_modelView * position; - gl_Position = czm_modelViewProjection * position; - + vec4 positionEC = czm_modelView * position; + gl_Position = czm_projection * positionEC; czm_vertexLogDepth(); } diff --git a/packages/engine/Source/Shaders/EllipsoidVS.glsl b/packages/engine/Source/Shaders/EllipsoidVS.glsl index 118b0e721cfb..5ef44bd4cb14 100644 --- a/packages/engine/Source/Shaders/EllipsoidVS.glsl +++ b/packages/engine/Source/Shaders/EllipsoidVS.glsl @@ -13,8 +13,8 @@ void main() vec4 p = vec4(u_radii * position, 1.0); v_positionEC = (czm_modelView * p).xyz; // position in eye coordinates - gl_Position = czm_modelViewProjection * p; // position in clip coordinates - + vec4 positionEC = czm_modelView * position; + gl_Position = czm_projection * positionEC; // With multi-frustum, when the ellipsoid primitive is positioned on the intersection of two frustums // and close to terrain, the terrain (writes depth) in the closest frustum can overwrite part of the // ellipsoid (does not write depth) that was rendered in the farther frustum. diff --git a/packages/engine/Source/Shaders/GlobeVS.glsl b/packages/engine/Source/Shaders/GlobeVS.glsl index 13fd7946027f..358fcfeeb8df 100644 --- a/packages/engine/Source/Shaders/GlobeVS.glsl +++ b/packages/engine/Source/Shaders/GlobeVS.glsl @@ -114,7 +114,8 @@ vec4 getPositionMorphingMode(vec3 position, float height, vec2 textureCoordinate float yPositionFraction = get2DYPositionFraction(textureCoordinates); vec4 position2DWC = vec4(height, mix(u_tileRectangle.st, u_tileRectangle.pq, vec2(textureCoordinates.x, yPositionFraction)), 1.0); vec4 morphPosition = czm_columbusViewMorph(position2DWC, vec4(position3DWC, 1.0), czm_morphTime); - return czm_modelViewProjection * morphPosition; + vec4 positionEC = czm_modelView * position; + return czm_projection * positionEC; } #ifdef QUANTIZATION_BITS12