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

Examples: Added webgl2_volume_instancing example. #19992

Merged
merged 1 commit into from
Aug 2, 2020
Merged

Examples: Added webgl2_volume_instancing example. #19992

merged 1 commit into from
Aug 2, 2020

Conversation

mrdoob
Copy link
Owner

@mrdoob mrdoob commented Aug 2, 2020

Screen Shot 2020-08-02 at 11 15 48 PM

@mrdoob mrdoob added this to the r120 milestone Aug 2, 2020
@mrdoob mrdoob merged commit 1efcd88 into dev Aug 2, 2020
@mrdoob mrdoob deleted the volume branch August 2, 2020 21:30
void main() {
vec4 worldPosition = modelViewMatrix * instanceMatrix * vec4( position, 1.0 );

vOrigin = vec3( inverse( instanceMatrix * modelMatrix ) * vec4( cameraPos, 1.0 ) ).xyz;
Copy link
Collaborator

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.

Copy link
Owner Author

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

Copy link
Collaborator

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?

Copy link
Owner Author

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 );
Copy link
Collaborator

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.

Copy link
Owner Author

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.

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.

2 participants