-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
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
Examples: Added webgl2_volume_instancing example. #19992
Conversation
mrdoob
commented
Aug 2, 2020
void main() { | ||
vec4 worldPosition = modelViewMatrix * instanceMatrix * vec4( position, 1.0 ); | ||
|
||
vOrigin = vec3( inverse( instanceMatrix * modelMatrix ) * vec4( cameraPos, 1.0 ) ).xyz; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you are computing here. Inverting a matrix may be avoidable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not, sure... I don't have a 100% understanding of the code yet. It was done by @spite.
The technique es pretty much the same as in this article:
https://medium.com/@babylonjs/path-tracing-with-babylonjs-part-1-solids-e48be7c2ba9c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vOrigin
is the camera position in the local space of the instance, so the code looks correct.
Tricks to avoid an inverse can be found here, but they may not apply in this case. Maybe the fragment shader could be implemented in a different coordinate frame?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could pass the inverted camera position, but in this example we're also dealing with instanceMatrix
which wouldn't work.
Changing the fragment shader is indeed an option but, it doesn't seem like that matrix inversion is the bottle neck. The bottleneck is the 3d texture size and the raymarching code.
|
||
for ( let i = 0; i < mesh.count; i ++ ) { | ||
|
||
transform.position.random().subScalar( 0.5 ).multiplyScalar( 150 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be a bit heavy. Consider reducing the count by a factor of 10 and scaling position by 50, instead. Looks about the same visually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I was trying to see how much my device was able to handle. I'll reduce it.