diff --git a/shaders/src/getters.fs b/shaders/src/getters.fs index 6b675348c6..e7fc029568 100644 --- a/shaders/src/getters.fs +++ b/shaders/src/getters.fs @@ -54,6 +54,10 @@ vec3 getWorldViewVector() { return shading_view; } +bool isPerspectiveProjection() { + return frameUniforms.clipFromViewMatrix[2].w != 0.0; +} + /** @public-api */ vec3 getWorldNormalVector() { return shading_normal; diff --git a/shaders/src/shading_parameters.fs b/shaders/src/shading_parameters.fs index 34fc249683..0ce5ca0caf 100644 --- a/shaders/src/shading_parameters.fs +++ b/shaders/src/shading_parameters.fs @@ -33,7 +33,13 @@ void computeShadingParams() { #endif shading_position = vertex_worldPosition.xyz; - shading_view = normalize(frameUniforms.cameraPosition - shading_position); + + // 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() ? + (frameUniforms.cameraPosition - shading_position) : + frameUniforms.worldFromViewMatrix[2].xyz; // ortho camera backward dir + shading_view = normalize(shading_view); // we do this so we avoid doing (matrix multiply), but we burn 4 varyings: // p = clipFromWorldMatrix * shading_position;