Horde3D
http://horde3d.org/forums/

createTexture2D() and render targets
http://horde3d.org/forums/viewtopic.php?f=2&t=772
Page 1 of 2

Author:  monophon [ 07.06.2009, 12:29 ]
Post subject:  createTexture2D() and render targets

Hi,

I am trying to use a
Code:
Horde3D::createTexture2D("mirrorTex", 0, 1024, 1024, true);

created renderable texture as a render target. How do I set this up in the pipeline definition? I tried:
Code:
<SwitchTarget target="mirrorTex"/>

which fails with:
Quote:
Pipeline resource 'pipelines/mirror.pipeline.xml': Error in stage 'Geometry': Reference to undefined render target in SwitchTarget

From the source code in egPipeline.cpp it seems clear that it does.

My question is: What is the right way to submit such a texture as a valid rendering target for a pipeline stage?

Any help will be greatly appreciated.

Henrik

Author:  marciano [ 07.06.2009, 23:50 ]
Post subject:  Re: createTexture2D() and render targets

You need to bind your renderable texture as output buffer to a camera (CameraNodeParams::OutputTex) and call Horde3D::render with that camera. Inside the pipeline you just bind no render target in order to write to that output buffer. From the docs:

Quote:
SwitchTarget
command for setting the currently active render target to which data is rendered; the command implicitely calls the UnbindBuffers command before the desired render target is activated; child of Stage element {*}
target
name of the render target which was defined in the Setup section or empty string to bind the output buffer assigned to the current camera {required}

Author:  monophon [ 09.06.2009, 08:58 ]
Post subject:  Re: createTexture2D() and render targets

Thanks. That works great.

At least most of the time. Sometimes the textured polygon is just black, no rendered image appears. Restarting the application often helps. Can this be a timing problem? It looks non-deterministic?

Also, how can I enable the depth buffer for my render target? Normaly this seems to be done with the depthBuf attribute on the RenderTarget element.

Henrik

Author:  marciano [ 09.06.2009, 19:46 ]
Post subject:  Re: createTexture2D() and render targets

monophon wrote:
Also, how can I enable the depth buffer for my render target? Normaly this seems to be done with the depthBuf attribute on the RenderTarget element.

At the moment you can't have a depth buffer for renderable textures outside the pipeline. This should be enhanced in the future.

Author:  wakka [ 11.07.2009, 07:32 ]
Post subject:  Re: createTexture2D() and render targets

I have tried to follow the steps you suggested (set OutputTex, render the camera, unbind targets), yet my supposedly-rendered-to-textures come out all black.

I create an empty texture with:
Code:
ResHandle texRes = Horde3D::createTexture2D("NewRenderTexture", 0, 256, 256, true);

This is bound to a camera (the camera uses the forward pipeline that comes with the demos) with:
Code:
Horde3D::setNodeParami(camNode, CameraNodeParams::OutputTex, texRes);

The render-to-texture camera is rendered before the main camera, and finalizeframe is called after the main camera render.

The texture (texRes with name "NewRenderTexture") is referenced in a material file:
Code:
<Material>
  <Shader source="shaders/model.shader" />
  <Sampler name="albedoMap" map="NewRenderTexture" />
</Material>

Yet the geometry drawn with this material comes out all black. If I render the render-to-texture camera after the main camera, Horde3d switches to the debug renderer.

Any ideas?

Author:  marciano [ 11.07.2009, 09:23 ]
Post subject:  Re: createTexture2D() and render targets

You should create the renderable texture before the material using it is loaded (otherwise the texture already has been added by the material and will be non-renderable). If Horde switches to debug view, it could mean that the pipeline used for rendering is not found or not valid. Are there any debug messages in the log?

Author:  wakka [ 12.07.2009, 02:59 ]
Post subject:  Re: createTexture2D() and render targets

Hmm. It seems that I'm seeing the same non-deterministic behavior as monophon.

I created a special pipeline that does nothing but clear buf0 to red. On one computer it never works (the render-to-texture textured boxes which should be red are black). On another computer it works maybe 30% of the time, but using the forward pipeline in RTT never works. On a third computer both the red pipeline and the forward pipeline work in RTT about 80% of the time (although the lack of depth buffer makes the result look quite weird).

The computer on which it never works has the best graphics card of the three (an nvidia gtx260), so I doubt the problem stems from a lack of graphics card capability.

My program is running all the graphics from a single thread, and I'm sure that everything happens in exactly the same order every time.

Author:  marciano [ 12.07.2009, 09:53 ]
Post subject:  Re: createTexture2D() and render targets

Hmm, difficult to say what goes wrong here. If you could provide a minimal sample, I can test it on my machine. You could also try to step into the Horde code with your debugger to see if there are some obvious problems.

Author:  Pyry [ 13.07.2009, 05:00 ]
Post subject:  Re: createTexture2D() and render targets

I'm working with Wakka. I've created a minimal test by modifying the Chicago demo, and attached the added and changed files (just app.cpp and app.h and some additional resources). If you uncompress the zip into the horde3d folder of beta 3, it ought to work.

When it works there should be a blatantly obvious square with RTT working on it right in front of you when you start the chicago demo. To get around the no depth buffer on output textures, it uses a forward pipeline that renders everything to an intermediate buffer first and then copies that to the output target (a texture in this case).

On this computer, it works all the time provided you run outside of debugging mode. If you run in debugging mode, the RTT texture is just black. Additionally, I got an assertion failure once (complaining that there was an opengl error).

Attachments:
File comment: Zip of changes to the chicago demo. Unzip in the Horde3D folder of the beta 3 download.
rtt_test.zip [13.64 KiB]
Downloaded 1368 times

Author:  wakka [ 13.07.2009, 05:14 ]
Post subject:  Re: createTexture2D() and render targets

Ok, using Pyry's patch on this machine (Pentium D w/ GeForce 9800GT running Ubuntu Jaunty), I am getting about a 50% hit rate. That is, 50% of the time, when I start the modded Chicago, I get an RTT square, and 50% of the time I get a completely black square. I've restarted it about 40 times, and I can't see any pattern predicting when it will work.

Author:  marciano [ 19.07.2009, 10:58 ]
Post subject:  Re: createTexture2D() and render targets

Thanks for the repro case. I can see the problem but some quick debugging did not yet reveal what's going wrong.

Author:  marciano [ 26.07.2009, 13:52 ]
Post subject:  Re: createTexture2D() and render targets

The problem is hopefully fixed now in the latest svn version. Could you please confirm that using your application?

Author:  Almahmudrony [ 06.12.2016, 16:46 ]
Post subject:  Re: createTexture2D() and render targets

Hay! Can any one tell me how to implement "Render To Texture" on H3D.................. or any working demo link would be fine.................. :| I mean rendering from a different camera( in this case i called it 2nd camera) into a texture, and i don't want to show that 2nd camera rendered buffer on the screen but into a texture so that i can use it as a texture for a CCTV model...............

Author:  Irdis [ 07.12.2016, 20:44 ]
Post subject:  Re: createTexture2D() and render targets

You should probably use render to texture somewhat like this:
1) Load pipeline (a custom one or a standard) for the second camera
2) Create second camera with this pipeline
3) Create texture and mark it as renderable. h3dCreateTexture( "tex1", width, height, H3DFormats::BGRA8, H3DResFlags::TexRenderable)
4) Set output texture for the second camera. h3dSetNodeParamI( cam2Idx, H3DCamera::OutTexResI, textureIdx)
5) h3dRender with the second camera
6) Apply the texture id to the material of the desired object. h3dSetResParamI( matID, H3DMaterialRes::SamplerElem, 0, H3DMaterialRes::SampTexResI, textureIdx)

I have not tested it, so it may not be fully functional.

Author:  Almahmudrony [ 10.12.2016, 17:42 ]
Post subject:  Re: createTexture2D() and render targets

Thank you Irdis............. its working but still having some problem.... if i use forward pipeline with 2nd camera its rendering the texture with alpha transparent :shock: ........... and if i use deferred pipeline with the 2nd camera its making something crazy, actually its rendering depth buffer only :roll: ....... You can take a look to those screen shot.............

Attachments:
File comment: with forward pipeline
forwordpipeline.jpg
forwordpipeline.jpg [ 142.68 KiB | Viewed 32245 times ]
File comment: with deferred pipeline
deferredpipeline.jpg
deferredpipeline.jpg [ 114.23 KiB | Viewed 32245 times ]

Page 1 of 2 All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/