How to render a grey scale image of the Z-buffer
How to render a grey scale image of the Z-buffer
What is the most effective way to render the Z-buffer to a texture?
Re: How to render a grey scale image of the Z-buffer
Using shaders. i don't know if there is any other way. You calculate the position of the vertices in the vertex shader, then, you can pass the normalized Z value to the pixel shader, and you can draw it either to the alpha channel of the current render target or to a diferent render target using MRT
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Re: How to render a grey scale image of the Z-buffer
Yes, that´s one way, probably the fastest way as the code runs on the GPU. Also directly readying the memory, but perhaps Irrlicht´s developers know the best way to do it with Irrlicht 1.8? Maybe some inbuilt facility?
Re: How to render a grey scale image of the Z-buffer
I think I have seen somewhere in 1.8 a function called createDepthMap but dunno if it works or even if it is public. Otherwise shaders.
Using trunk with mingw/gcc 4.6, Windows 7 64 bits driver opengl
Re: How to render a grey scale image of the Z-buffer
Thanks for that, will look that one up.
The aim is to show a 2D image of the depth buffer in grey scale on an area of the screen.
Would it be possible to draw the depth buffer into the GUI area?
The aim is to show a 2D image of the depth buffer in grey scale on an area of the screen.
Would it be possible to draw the depth buffer into the GUI area?
Re: How to render a grey scale image of the Z-buffer
Use draw2DImage and you can draw it wherever you want.
Re: How to render a grey scale image of the Z-buffer
How would that work? You´d need the z-buffer in an IMage, but how?
Re: How to render a grey scale image of the Z-buffer
driver->draw2DImage(ITexture *tex, recti srcrect, recti destrec);
It's in the examples. Demo.cpp?
It's in the examples. Demo.cpp?
Re: How to render a grey scale image of the Z-buffer
yes, but how do you propose to access the Z-buffer, which is an array of floats?
Re: How to render a grey scale image of the Z-buffer
Ah, sorry. As Mel said, you use a vertex shader to save the depth values in a varying, and a pixel shader to write the depth values to the render target. Then you just draw the render target. (Divide the depth values by the far value to get a number between 0 and 1.) I had forgotten the details.
Re: How to render a grey scale image of the Z-buffer
Other, more creative way, is to render the scene in 2 passes, one for the normal render to one rendertarget, and the other with the objects in black, with a white fog that started in the near value of the camera, and ended in the far value drawn into another rendertarget. It is not as efficient as using shaders and/or MRT, but for instance, is more compatible, shadow mapping is done like this, so it is an affordable way too... at the cost of a 2 passes process
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Re: How to render a grey scale image of the Z-buffer
interesting idea, but if speed is an important, not so good.
shaders would be faster, but if a shader cannot access more than the z-buffer for its own object, then it would be necessary to re-render every object using a special z-buffer shader; very inefficient.
there are methods in opengl to copy the z-buffer to a texture, but how is that supported in IRRLICHT?
OpenGL mehtod: "Copying the depth buffer to a texture is pretty simple in opengl. If you have created a new texture that you haven't called glTexImage* on, you can use glCopyTexImage2D. This will copy pixels from the framebuffer to the texture. To copy depth pixels, you use a GL_DEPTH_COMPONENT format. I'd suggest GL_DEPTH_COMPONENT24."
shaders would be faster, but if a shader cannot access more than the z-buffer for its own object, then it would be necessary to re-render every object using a special z-buffer shader; very inefficient.
there are methods in opengl to copy the z-buffer to a texture, but how is that supported in IRRLICHT?
OpenGL mehtod: "Copying the depth buffer to a texture is pretty simple in opengl. If you have created a new texture that you haven't called glTexImage* on, you can use glCopyTexImage2D. This will copy pixels from the framebuffer to the texture. To copy depth pixels, you use a GL_DEPTH_COMPONENT format. I'd suggest GL_DEPTH_COMPONENT24."
Code: Select all
int shadowMapWidth = 512;
int shadowMapHeight = 512;
glGenTextures(1, &m_depthTexture);
glBindTexture(GL_TEXTURE_2D, m_depthTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, shadowMapWidth, shadowMapHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 512,512);
Re: How to render a grey scale image of the Z-buffer
If the backbuffer is 1920 x 1080, can opengl (irrlicht) copy it to a texture of the same resolution? Keep reading about powers of 2 and some flag to change to any resolution, wondered if anyone knows if it works okay and fast? I`ve done it with the D3D driver, now for opengl...
Last edited by robmar on Tue Apr 30, 2013 4:30 pm, edited 1 time in total.
Re: How to render a grey scale image of the Z-buffer
http://irrlicht.sourceforge.net/forum/v ... =9&t=48621
I did it here simply by dividing the screen depth by 1024
I did it here simply by dividing the screen depth by 1024
Re: How to render a grey scale image of the Z-buffer
sorry, my question was a bit off-topic. I´m trying to find a fast way to bltcopy from the framebuffer, with the opengl driver, to a texture overlay. Can´t find the function to do a copy from the frame buffer to a texture...