Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Three.js - What's the most effective way to render a WebGLRenderTarget texture?

Problem

I've gotten to a point in my project where I'm rendering to WebGLRenderTargets and using them as a textures in my main scene. It works, but it seems like I'm having it do a lot more work than it needs to. My generated textures only need to be 64x64, but because I'm using my main renderer (window width by window height) for both, it's unnecessarily rendering the WebGLRenderTargets at a much larger resolution.

I may be wrong, but I believe this increases both the processing required to draw to each RenderTarget and the processing required to then draw that large texture to the mesh.

I've tried using a second renderer, but I seem to get this error when trying to use a WebGLRenderTarget in renderer A after drawing to it from renderer B:

WebGL: INVALID_OPERATION: bindTexture: object not from this context

Example

For reference, you can see my abstracted page here (Warning: Due to the very issue I'm inquiring about, this page may lag for you). I'm running a simplex function on a plane in my secondary scene and chopping it up into sections using camera placement, then applying the segments to tile pieces via WebGLRenderTarget so that they're fluent but individual pieces.

Question

Am I correct in my assumption that using the same renderer size is much less efficient than rendering to a smaller renderer would be? And if so, what do you think the best solution for this would be? Is there currently a way to achieve this optimization?

like image 412
rrowland Avatar asked Oct 06 '12 03:10

rrowland


1 Answers

The size parameters in renderer.setSize() are used by the renderer to set the viewport when rendering to the screen only.

When the renderer renders to an offscreen render target, the size of the texture rendered to is given by the parameters renderTarget.width and renderTarget.height.

So the answer to your question is that it is OK to use the same renderer for both; there is no inefficiency.

like image 94
WestLangley Avatar answered Sep 28 '22 17:09

WestLangley