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

Improve raymarching example v2 #12801

Merged
merged 2 commits into from Dec 5, 2017

Conversation

Projects
None yet
3 participants
@gam0022
Contributor

gam0022 commented Dec 5, 2017

I came up with a way to make it more efficient.

  • Update ProjectionMatrix on change aspect
    • To process aspect ratio by ProjectionMatrix instead of shader
  • Update uniforms only when onWindowResize
    • To avoid calling getInverse every frame

Related Pull Requests:

vec4 ndcRay = vec4( screenPos.xy, 1.0, 1.0 );
// convert ray direction from normalized device coordinate to world coordinate
vec3 ray = ( cameraWorldMatrix * cameraProjectionMatrixInverse * ndcRay ).xyz;

This comment has been minimized.

@WestLangley

WestLangley Dec 5, 2017

Collaborator

Is cameraWorldMatrix updated when the camera moves?

This comment has been minimized.

@gam0022

gam0022 Dec 5, 2017

Contributor

Yes.

material.uniforms.cameraWorldMatrix.value has camera's cameraWorldMatrix "reference".
https://github.com/gam0022/three.js/blob/6d9c22a3bc346f34ad779bada397db6f5c691760/examples/webgl_raymarching_reflect.html#L302

So it seems to work without explicitly updating cameraWorldMatrix when the camera moves.

This comment has been minimized.

@WestLangley

WestLangley Dec 5, 2017

Collaborator

Got it! Thanks.

@mrdoob mrdoob merged commit 23b20c2 into mrdoob:dev Dec 5, 2017

2 checks passed

lgtm analysis: JavaScript No alert changes
Details
lgtm analysis: Python No alert changes
Details
@mrdoob

This comment has been minimized.

Owner

mrdoob commented Dec 5, 2017

Thanks!

@gam0022 gam0022 deleted the gam0022:improve-raymarching-example-v2 branch Dec 5, 2017

@gam0022

This comment has been minimized.

Contributor

gam0022 commented Dec 5, 2017

Thank you for quick merging 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment