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

Enhance WebGPU partial update texture example with random size option in GUI #30456

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

Makio64
Copy link
Contributor

@Makio64 Makio64 commented Feb 5, 2025

Related issue: #30420

Description

Improve the example by adding the "Random Size" option to show how to use copyTextureToTexture when you want to resize your texture.

--

For context : I tried to add this functionality into the core of copyTexture2Texture but it was looking ugly on the WebGPURenderer and I think its better to put this showcase in this example.

@Makio64 Makio64 changed the title Enhance WebGPU texture example with GUI controls for random size and render target support Enhance WebGPU partial update texture example with random size option in GUI Feb 5, 2025
@gkjohnson
Copy link
Collaborator

The approach used here uses more operations than necessary. In order to render to the render target in the first place you're already having to upload the data texture to the GPU which means you can render it directly to the target texture anyway. You can use a full screen quad and renderer.setViewport to render the texture directly at the intended size to the target texture.

There shouldn't be reason to include a new render target or use "copyTextureToTexture".

@Makio64
Copy link
Contributor Author

Makio64 commented Feb 5, 2025

@gkjohnson Sorry I think i'm missing something with your approach.. I think it work only if the final texture is a RenderTarget no ? :

renderer.setViewport( x, y, size, size );
renderer.render( rtQuad, rtCamera, rt ); // <-- we need a RenderTarget here , it will not work with a loaded texture for example ?
renderer.setViewport( 0, 0, window.innerWidth, window.innerHeight );

@gkjohnson
Copy link
Collaborator

gkjohnson commented Feb 5, 2025

Oh I see, now, a normal texture is being targeted. Generally there's no reason why we shouldn't be able to bind a normal texture to a depth-less framebuffer and use it as a render surface for this kind of thing (and it will likely be needed for custom mip map generation in the future, see #29779) but this is something for the future, I suppose.

I tried to add this functionality into the core of copyTexture2Texture but it was looking ugly on the WebGPURenderer and I think its better to put this showcase in this example.

Can you make a PR with what you've tried? Perhaps others can help provide some insight on how this can be done more cleanly. I'd prefer to see a solution built into copyTextureToTexture if this is going to be considered a use case.

Relatedly - can you explain what you're using this for in your application just so I have some more context?

@Makio64
Copy link
Contributor Author

Makio64 commented Feb 5, 2025

It was to draw texts & illustration texture into other texture to create customized "cards", it could have been done by drawing into rt, but i naturally though to copyTextureToTexture as the name of the function make it sounds perfect to do it.

Maybe in the doc the alternative to use rt might be added ?

Another usage I was thinking would be to draw into dynamic textureAtlas, but as you say it could be done using rt.

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