Ortho shading fixes (#6453)

This commit is contained in:
Koncz Levente
2023-01-27 18:36:56 +01:00
committed by GitHub
parent 2a049d1324
commit 73880428dc
2 changed files with 11 additions and 1 deletions

View File

@@ -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;

View File

@@ -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;