[osg-users] Offscreen rendering of large scenes
Brad Colbert
bcolbert at rscusa.com
Fri Dec 20 15:54:06 PST 2019
Oh darn! I had a good reply to this :) Congrat's on the find!
On Thursday, December 12, 2019 at 12:51:02 AM UTC-8, Philipp Wagner wrote:
>
> Sorry, the issue has been that the camera automatically adjusted the near
> and far plane when rendering the individual parts.
> Problem solved.
>
> Grettings,
> Phil
>
> Am Dienstag, 10. Dezember 2019 16:42:23 UTC+1 schrieb Philipp Wagner:
>>
>> Hi,
>>
>> I want to perform an offscreen rendering of a scene that is too large to
>> fit into the GPU memory at once (lots of big textures).
>> My idea was to render parts of the scene each in its own frame, and
>> disable the clearing of the depth and color buffer.
>> This does work for the color buffer, but the depth buffer seems to be
>> cleared after each frame, which leads to incorrect results (The later parts
>> are drawn over the previous ones, even though they are behind the other
>> parts).
>>
>> The algorithm:
>> 1. Create camera/context/...
>> 2. Clear the buffers (i.e. Render an empty scene with a clear mask of
>> (GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT)
>> 3. Disable buffer clearing
>> 4. Render each part in its own frame
>> a. Add part to the scene
>> b. Render
>> c. Remove part from the scene
>> 5. Read back color buffer
>>
>>
>> osg::ref_ptr<::osg::Camera> camera = new osg::Camera();
>>
>> //Here we set the camera orientation/projection matrix
>>
>> camera->setClearColor(...);
>> camera->setGraphicsContext(context);
>>
>> osg::ref_ptr<osg::Image> img = new osg::Image;
>> img->allocateImage(textureWidth, textureHeight, 1, GL_RGBA,
>> GL_UNSIGNED_BYTE);
>> camera->attach(osg::Camera::COLOR_BUFFER0, img, numSamples);
>> camera->attach(osg::Camera::DEPTH_BUFFER, GL_DEPTH_COMPONENT32);
>> camera->setRenderOrder(osg::Camera::PRE_RENDER);
>>
>> camera->setRenderTargetImplementation(osg::Camera::RenderTargetImplementation::FRAME_BUFFER_OBJECT);
>> camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF);
>> camera->setProjectionResizePolicy(osg::Camera::FIXED);
>> camera->setViewport(0, 0, img->s(), img->t());
>> viewer->addSlave(camera);
>>
>> camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
>> viewer->frame();
>> camera->setClearMask(0);
>> for (auto& item : parts)
>> {
>> //Here we create and add the item to the scene...
>> viewer->frame();
>> //Here we remove item from the scene and delete it
>> }
>>
>> Thanks in advance
>> Phil
>>
>
--
You received this message because you are subscribed to the Google Groups "OpenSceneGraph Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osg-users+unsubscribe at googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/osg-users/0ac99069-ec02-4af0-9f17-77743dcc871b%40googlegroups.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20191220/8ff8d3ed/attachment.html>
More information about the osg-users
mailing list