Skip to content

Conversation

@DavidPeicho
Copy link
Contributor

Description

This PR adds the copyTextureToTexture3D() to the class WebGLRenderer.

Why

Just like for 2D textures, it can be useful to update only a small part of a texture on the GPU. When dealing with volumes of consequent size ( > 128 x 128 x 128 for instance), being able to re-upload only what changed gives enormous performance improvement.

Improvements

Right now, the pixelStorei parameters aren't reset:

_gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, width );
_gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, height );
_gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, sourceBox.min.x );
_gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, sourceBox.min.y );
_gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, sourceBox.min.z );

If we plan on adding those on the texture object, then it could make sense to do the pixelStorei of those constants directly in WebGLTextures just like it's done for 2D textures. Otherwise, we can just reset those to the default values after the texSubImage3D call.

@mrdoob
Copy link
Owner

mrdoob commented Feb 16, 2021

@DavidPeicho Could you also add an example in this PR?

@mrdoob mrdoob added this to the r126 milestone Feb 16, 2021
@Mugen87
Copy link
Collaborator

Mugen87 commented Feb 16, 2021

It would also be good to update the documentation page of WebGLRenderer.

@DavidPeicho
Copy link
Contributor Author

Trying to think what good example I could do. I can do a dummy one with colors but that's not fancy.

Just for debugging purposes, on my side I made one updating the "cloud" example with smaller clouds, but that's ugly because it creates discontinuities

@DavidPeicho
Copy link
Contributor Author

Regarding the pixelStore info, do you prefer new params on texture on simply resetting them after the copy call?

@mrdoob
Copy link
Owner

mrdoob commented Feb 16, 2021

Trying to think what good example I could do. I can do a dummy one with colors but that's not fancy.

Don't worry about making it fancy. Once it's working I can try to come up with something 👍

Regarding the pixelStore info, do you prefer new params on texture on simply resetting them after the copy call?

Lets just reset them for now.

@DavidPeicho
Copy link
Contributor Author

DavidPeicho commented Feb 17, 2021

@mrdoob done. Test example is webgl2_materials_texture3d_partialupdate.html.
The test has some random which makes it bad for the E2E tests.

And thanks to the person that wrote the cloud example, this is what I re-used 😄

@mrdoob mrdoob merged commit b5ff213 into mrdoob:dev Feb 17, 2021
@mrdoob
Copy link
Owner

mrdoob commented Feb 17, 2021

Thanks!

@DavidPeicho
Copy link
Contributor Author

Thanks!!! ❤️

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.

3 participants