Skip to content

Shading models using incorrect view direction for orthographic projections. #17662

@sciecode

Description

@sciecode

#17379 exposed a problem with the current orthographic behavior of light. However it was quickly dismissed as a help question, but I don't think this is the case.

It was thought to be a problem with physical and standard models, but I believe the real issue at hand is the incorrect calculation of the view direction for orthographic cameras.

Currently the view direction is being calculated as follows vViewPosition = - mvPosition.xyz;
However this is not a correct model for an orthographic view. This is supposed to be fixed as the camera direction, disregarding the object position.

This is causing multiple unexpected behaviours. Given a fixed orthographic camera and a scene being lit by a directional light, the specular light component shouldn't move if the object moves. This is not what's happening on Dev - dev example

image

From the image, you can see the fresnel component is being incorrectly placed on the object. As previously noted, the specular component is also incorrectly moving when it shouldn't be.


In order to fix this behavior, I just replaced the vViewPosition calculation for every shading model with the following:
vViewPosition = isPerspectiveMatrix( projectionMatrix ) ? - mvPosition.xyz : vec3( 0, 0, 1 );

This is the example of what should be actually happening - fix example

image

Would appreciate if other contributors, that are more familiar with orthographic projection, could confirm this is indeed the correct way of handling the issue at hand.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions