Is it possible to render in layers in Irrlicht?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Noiecity
Posts: 336
Joined: Wed Aug 23, 2023 7:22 pm
Contact:

Is it possible to render in layers in Irrlicht?

Post by Noiecity »

I'm thinking of imitating the floor reflection by creating two layers, one to render the objects on top of the floor, and then rotating the image vertically, using the rotated render image for the second layer of the refletion2_layer material texture. I think it would look just like this image:

Image

This is because reflection2_layer remains centered on the camera even if the object moves, but I haven't tested it yet, so it's just a theory for now.

Now, this would mean being able to render objects first, with transparency, but I don't think this is possible, except that I think it is if the background is black and we convert the black to transparent, like in the Irrlicht examples where it uses particles. However, I don't want it to be black because I use black for shadows.
Irrlicht is love, Irrlicht is life, long live to Irrlicht
CuteAlien
Admin
Posts: 9942
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Is it possible to render in layers in Irrlicht?

Post by CuteAlien »

What do you need the transparency for? To make the floor transparent when rendering from below? Basically - just hide that node in that shot (if you have backfrace culling enabled the floor won't show up anyway when rendered from below). A bit harder is that this kinda need some fade-out effect for the reflection. I usually do that with shaders. Thought I suppose maybe enabling fog in the shot from below could also work.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Noiecity
Posts: 336
Joined: Wed Aug 23, 2023 7:22 pm
Contact:

Re: Is it possible to render in layers in Irrlicht?

Post by Noiecity »

CuteAlien wrote: Fri Feb 13, 2026 9:39 pm What do you need the transparency for? To make the floor transparent when rendering from below? Basically - just hide that node in that shot (if you have backfrace culling enabled the floor won't show up anyway when rendered from below). A bit harder is that this kinda need some fade-out effect for the reflection. I usually do that with shaders. Thought I suppose maybe enabling fog in the shot from below could also work.
Transparency is used to avoid rendering the floor, i.e. if the scene has a cube and a floor, it would render the cube first, but now as I write this, I realise that it would have problems rendering the shadow on the floor... the other solution is to have a semi-transparent surface and duplicate the 3D models in reverse, but then I have the shadow problem again... So the only real solution is to use shaders and solve the performance issues with a low-resolution render... This is the approach I will probably end up using, but I want to see the possibilities so I can compare them.
Irrlicht is love, Irrlicht is life, long live to Irrlicht
CuteAlien
Admin
Posts: 9942
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Is it possible to render in layers in Irrlicht?

Post by CuteAlien »

But can't you can avoid rendering the floor by simply hiding it? If you need to render twice -hide in first render - then set it visible again in second render.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Noiecity
Posts: 336
Joined: Wed Aug 23, 2023 7:22 pm
Contact:

Re: Is it possible to render in layers in Irrlicht?

Post by Noiecity »

CuteAlien wrote: Fri Feb 13, 2026 10:57 pm But can't you can avoid rendering the floor by simply hiding it? If you need to render twice -hide in first render - then set it visible again in second render.
Yes, but the render saves the background of the scene, so you would see one image completely on top of another without leaving any visibility to the floor. I haven't yet tried to see if there is a way to render without any background, that is, with transparency, while maintaining visibility. For now, I'm unrolling the xeffects shaders, which is a big bottleneck on my computer (there are compilers that do this automatically, but I don't know how or when).
Irrlicht is love, Irrlicht is life, long live to Irrlicht
Noiecity
Posts: 336
Joined: Wed Aug 23, 2023 7:22 pm
Contact:

Re: Is it possible to render in layers in Irrlicht?

Post by Noiecity »

CuteAlien wrote: Fri Feb 13, 2026 10:57 pm But can't you can avoid rendering the floor by simply hiding it? If you need to render twice -hide in first render - then set it visible again in second render.
No, I was wrong, it actually runs at almost double the fps without the unrolls.
Irrlicht is love, Irrlicht is life, long live to Irrlicht
Noiecity
Posts: 336
Joined: Wed Aug 23, 2023 7:22 pm
Contact:

Re: Is it possible to render in layers in Irrlicht?

Post by Noiecity »

CuteAlien wrote: Fri Feb 13, 2026 10:57 pm But can't you can avoid rendering the floor by simply hiding it? If you need to render twice -hide in first render - then set it visible again in second render.
If I wanted to copy the vertex colors from one model to another, with them being exactly the same, except that one has dynamic lighting disabled, it would be possible to replicate the reflection effect. However, is it possible to do this? In other words, can I copy the ground shading buffer from one model to another, considering that only the vertex is colored?
Irrlicht is love, Irrlicht is life, long live to Irrlicht
Noiecity
Posts: 336
Joined: Wed Aug 23, 2023 7:22 pm
Contact:

Re: Is it possible to render in layers in Irrlicht?

Post by Noiecity »

The other option is to use the CPU. Transferring a low-resolution image from the CPU to the GPU, I choose a background color that is difficult to achieve on stage, such as some type of pink, and I make the pink transparent, so I can easily mix it using the CPU, is usually quite fast, less than 1 FPS according to ChatGPT. This may not be true, but I'll take it. With the CPU, I can use SSE2 to perform multiple vectorized calculations, and instead of using floating point, I would use q8.8 fixed point, so I can vectorize multiple mathematical calculations in 128 bits... I also add a bloom filter and increase the brightness, contrast, and saturation, finally displaying it with a trilinear filter. In my mind, it looks beautiful, and probably in practice as well...
Like that: https://m.youtube.com/watch?v=wgtMW38vsUs

In a 128x128 render, this is almost free
Irrlicht is love, Irrlicht is life, long live to Irrlicht
CuteAlien
Admin
Posts: 9942
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Is it possible to render in layers in Irrlicht?

Post by CuteAlien »

Not yet getting which step you are struggling with, I'm probably missing something. Is it about floor having 2 texture (it's own + reflection) and how to combine those?

The way to do such mirrors is something like:
1. Set the camera to the reflection vector of you real camera

Code: Select all

const core::vector3df camPos = activeCam->getPosition();
reflectionCamera->setPosition(core::vector3df(camPos.X, -camPos.Y, camPos.Z));
core::vector3df target = activeCam->getTarget() - camPos;
target.normalize(); // not sure if that one is really needed
target.Y *= -1.0f;
reflectionCamera->setTarget(reflectionCamera->getPosition() + target);
			
if(activeCam->getUpVector().Y > 0.0f)
	reflectionCamera->setUpVector(core::vector3df(0.0f, 1.0f, 0.0f));
else
	reflectionCamera->setUpVector(core::vector3df(0.0f, -1.0f, 0.0f));
2. Disable nodes you don't want in the reflection
3. Render reflection to render target texture
And maybe this is the step where you'll run into problems?
In my current project we use some fade-out there in shaders, like:

Code: Select all

float fadeFac = clamp(distToFloor / 25.0, 0.0, 1.0);
gl_FragColor = mix(gl_FragColor, vec4(1.0, 1.0, 1.0, 1.0), fadeFac);
Not sure how to replace this without shaders, my guess was that maybe using black or white fog could work? You have to figure out if there is some way to combine a fade-out with the real floor texture later.
4. Enable all your nodes again
5. Put the render target texture as second texture on your floor. Figure out which material/flags to use to combine those so you see floor and reflection. If you white out the fog earlier you can maybe just multiply them - there's some fixed function materials for that I think - the lightmap stuff should do it, thought it means reflection makes your floor darker, there's probably better options. I tend to use shaders for this step again, so would have to experiment myself how to do that with fixed function materials.
6. Render your real scene with original camera
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Noiecity
Posts: 336
Joined: Wed Aug 23, 2023 7:22 pm
Contact:

Re: Is it possible to render in layers in Irrlicht?

Post by Noiecity »

CuteAlien wrote: Sat Feb 14, 2026 11:06 am Not yet getting which step you are struggling with, I'm probably missing something. Is it about floor having 2 texture (it's own + reflection) and how to combine those?

The way to do such mirrors is something like:
1. Set the camera to the reflection vector of you real camera

Code: Select all

const core::vector3df camPos = activeCam->getPosition();
reflectionCamera->setPosition(core::vector3df(camPos.X, -camPos.Y, camPos.Z));
core::vector3df target = activeCam->getTarget() - camPos;
target.normalize(); // not sure if that one is really needed
target.Y *= -1.0f;
reflectionCamera->setTarget(reflectionCamera->getPosition() + target);
			
if(activeCam->getUpVector().Y > 0.0f)
	reflectionCamera->setUpVector(core::vector3df(0.0f, 1.0f, 0.0f));
else
	reflectionCamera->setUpVector(core::vector3df(0.0f, -1.0f, 0.0f));
2. Disable nodes you don't want in the reflection
3. Render reflection to render target texture
And maybe this is the step where you'll run into problems?
In my current project we use some fade-out there in shaders, like:

Code: Select all

float fadeFac = clamp(distToFloor / 25.0, 0.0, 1.0);
gl_FragColor = mix(gl_FragColor, vec4(1.0, 1.0, 1.0, 1.0), fadeFac);
Not sure how to replace this without shaders, my guess was that maybe using black or white fog could work? You have to figure out if there is some way to combine a fade-out with the real floor texture later.
4. Enable all your nodes again
5. Put the render target texture as second texture on your floor. Figure out which material/flags to use to combine those so you see floor and reflection. If you white out the fog earlier you can maybe just multiply them - there's some fixed function materials for that I think - the lightmap stuff should do it, thought it means reflection makes your floor darker, there's probably better options. I tend to use shaders for this step again, so would have to experiment myself how to do that with fixed function materials.
6. Render your real scene with original camera
I think the problem I was seeing was caused by using Mesa on Linux to translate the instructions from the GPU to the CPU. I'm going to switch to Windows XP to see what's really going on (I have dual boot). Thanks anyway, I'll use your code as a reference for testing.
Irrlicht is love, Irrlicht is life, long live to Irrlicht
Post Reply