Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ShaderChunks: Fix orthographic view direction #17767

Merged
merged 3 commits into from
Oct 28, 2019

Conversation

sciecode
Copy link
Contributor

Fixes #17379.

Based on #17662.

Adds isOrthographicuniform only for light/view dependant built-in materials.
Correctly handles view direction for orthographic projection, specular lighting and environment maps.

@sciecode
Copy link
Contributor Author

@WestLangley
Copy link
Collaborator

Can you please add this to the two examples:

geometry = new THREE.IcosahedronBufferGeometry( 128, 0 );

@sciecode
Copy link
Contributor Author

sciecode commented Oct 18, 2019

@mrdoob
Copy link
Owner

mrdoob commented Oct 21, 2019

@WestLangley Looks good?

@mrdoob mrdoob added this to the r110 milestone Oct 21, 2019
@WestLangley
Copy link
Collaborator

@WestLangley Looks goos?

As @sciecode and I discussed offline, this change has weird side effects in environment reflections. I am not sure I would support this PR.

@sciecode
Copy link
Contributor Author

sciecode commented Oct 22, 2019

this change has weird side effects in environment reflections.

Yes. In reality neither the dev model nor the PR model are truly correct or incorrect. Both are approximating some aspect of orthographic projection correctly, but not entirely.

This ambiguous way of handling orthographic projections is noticeable across multiple engines:

Unity and BabylonJS are using perspective view direction model for light and reflections.
Blender is using orthographic view direction for light and reflections.

It is a subjective choice. Personally, I don't like having the fresnel component completely detached from the mesh as we have on dev; but I, equally, dislike the flat reflections on this PR. So, I'm afraid we gonna need a judgement call.

PS: Cinema4D is the only example I could find using a mixed approach. Orthographic view direction for lighting and perspective view direction for reflections. I like this approach, but it isn't very popular or considered standard.

@mrdoob
Copy link
Owner

mrdoob commented Oct 24, 2019

@WestLangley As discussed offline, the reflections in orthographic projection looks good to me after this PR. Are you happy with the implementation in this PR?

Comment on lines 6 to 16
vec3 cameraToFrag;

if ( isOrthographic ) {

cameraToFrag = normalize( vec3( -viewMatrix[0][2], -viewMatrix[1][2], -viewMatrix[2][2] ) );

} else {

cameraToFrag = normalize( vWorldPosition - cameraPosition );

}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not tested, but may work.

vec3 cameraToFrag = ( isOrthographic ) ? normalize( - viewMatrix[ 2 ].xyz ) : normalize( vWorldPosition - cameraPosition );

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, doesn't work. matrix[i] is a column selector. Unfortunately, I don't think there is a row selector on GLSL.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right. You are selecting the row, not the column.

Only the white space needs to be corrected: - viewMatrix[ 0 ][ 2 ]

@WestLangley
Copy link
Collaborator

Are you happy with the implementation in this PR?

When @sciecode has fully-tested it, we can give it a try.

@sciecode
Copy link
Contributor Author

When @sciecode has fully-tested it, we can give it a try.

I'll just make sure I haven't missed any cases where I need to input isOrthographic and we should be good to go.

@sciecode
Copy link
Contributor Author

PR is ready to merge.
Both built-in materials and examples appear to be fully covered.

Should I make a follow up PR adjusting example shaders to work correctly with orthographic projection as well?

@WestLangley
Copy link
Collaborator

Should I make a follow up PR adjusting example shaders to work correctly with orthographic projection as well?

@mrdoob will have to answer that, and @sunag will have to be alerted to these changes.

@mrdoob
Copy link
Owner

mrdoob commented Oct 25, 2019

Should I make a follow up PR adjusting example shaders to work correctly with orthographic projection as well?

That would be great yeah!

@EliasHasle
Copy link
Contributor

Does any conclusions of this discussion transfer to distance-based fog? The proposal in #17592 assumes (like @supereggbert's and several older ones) that this is independent of camera type, i.e. that the distance is considered from eye to fragment. An alternative for orthographic camera could be to take distance along pixel normals, i.e. depth-based fog... Also mentioned in #17592 (comment)

I think that to answer the question, one needs to consider the use cases. If map top views are the main application of ortho in scenes with fog, then it makes sense that the fog density is independent of screen position (depth-based, not distance-based). But I barely cannot think of an example where I wouldn't disable fog for map views...

@sciecode
Copy link
Contributor Author

sciecode commented Oct 28, 2019

Does any conclusions of this discussion transfer to distance-based fog?

I can't think of a reason why anyone would want to use rangeFog on a orthographic projection.
But if you were to adapt it, it would be as simple as you noted. Only, using isOrthographic now.

@mrdoob @WestLangley I believe every stylistic changes were covered, any chance we could get this merged before r110?

edit: I didn't explicitly set this PR to close #17662, but it's fair to say we can close when we merge.

@mrdoob
Copy link
Owner

mrdoob commented Oct 28, 2019

Looks good to me!

@mrdoob mrdoob merged commit a5584f2 into mrdoob:dev Oct 28, 2019
@mrdoob
Copy link
Owner

mrdoob commented Oct 28, 2019

Thanks!

@EliasHasle
Copy link
Contributor

@mrdoob Is your 👍 to @sciecode's comment also to using depth-based fog on orthographic projection?

@mrdoob
Copy link
Owner

mrdoob commented Oct 28, 2019

@EliasHasle Noes, I haven't studied that case yet. Probably worth its own issue?

@EliasHasle
Copy link
Contributor

I guess it is natural to discuss it in #17592 .

@sciecode sciecode deleted the dev-ortho-light branch October 31, 2019 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Physical and Standard Material shading problem with orthographic camera
4 participants