question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Shading models using incorrect view direction for orthographic projections.

See original GitHub issue

#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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
sciecodecommented, Oct 5, 2019

I’ve studied a bit more about how orthographic projections are supposed to work.

image

It is a form of parallel projection, in which all the projection lines are orthogonal to the projection plane

The only real difference is that you can assume that lighting rays read by the camera are the ones with exact opposite direction from the camera view direction. You can think of it as if there was a filter, on top of the screen space, blocking any incident rays coming from lateral directions.

With that being said, the lighting calculations should stay exactly the same. Only the view direction calculations need to be adjusted accordingly.


I’ve implemented this behavior on environment reflections / refractions and the result looks correct now.

dev example fix example

( Note that you can rotate the camera and both the environment reflections and the specular component still behaves as you would expect )


I’ve tried looking for how other engines are handling this behavior:

Babylon.js is incorrectly calculating the view directions exactly as we are on dev. example Blender and Cinema4D, however, are behaving exactly as the proposed fix.

I have a partial PR ready, in case you guys want to proceed with this change. There’s just one minor varying collision with vIsPerspective that needs to be solved, but I’ll leave this discussion for this possible PR.

2reactions
WestLangleycommented, Oct 4, 2019

While you are thinking about this, see if you can also study reflections from an environment map.

It is not clear to me how we should be handling lighting with an orthographic camera.

It might be of interest to compare with other engines.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Shades and Shadows in Orthographic Views - andrew.cmu.ed
Viewing shadows as generated by a parallel or central projection gives us a tool to understand and construct them and to model them...
Read more >
Chapter 8 Multiview Drawings
Orthographic projection is used to create this front multiview drawing by projecting details onto a projection plane that is parallel to the view...
Read more >
Perspective Projection: the Wrong Imaging Model
A model based on stereographic projection of the viewing sphere is shown to ... Although neglected in computer vision, wide-angle images are widely...
Read more >
Activity 2.4 Multi-View Sketching Answer Key
Use the minimum number of orthographic projections necessary to fully describe the object shown. Include object lines, hidden lines, and center lines in...
Read more >
First Angle Orthographic Projection - Technology Student
Orthographic Projection is a way of drawing an 3D object from different directions. Usually a front, side and plan view are drawn so...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found