Hi group,
For creating a shadow map I've set up a depth render buffer object, using
this code:
GLuint frameBuffer = 0;
GLuint renderBuffer = 0;
glGenFramebuffersEXT(1, &frameBuffer);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frameBuffer);
// Render depth values to a buffer.
glGenRenderbuffersEXT(1, &renderBuffer);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, renderBuffer);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24,
width, height);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, renderBuffer);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
// Check validity of the frame buffer and go back to traditional
rendering if something failed.
GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
canUseFBOs = false;
This works fine so far but now I want to get the depth values into a memory
buffer to make it a nice look looking, smooth shadow (blurring it,
adjusting alpha values and such). Later I want to take the result and use
this as texture for a simple quad. The problem I have is the glReadPixels
call, which throws an access violation in the ATI driver. It looks so:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
render(1);
void* buffer = malloc(3 * width * height);
glReadBuffer(GL_DEPTH_ATTACHMENT_EXT);
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, buffer);
What is it that I'm doing wrong here? It doesn't really look complicated to
read the pixels. I have already done this with the color attachment (to
save to a file), but reading the depth values causes trouble.
Thank you,
Mike
--
www.soft-gems.net
|
|
0
|
|
|
|
Reply
|
Mike
|
12/13/2005 10:50:04 AM |
|
Mike Lischke wrote:
> Hi group,
>
> For creating a shadow map I've set up a depth render buffer object, using
> this code:
>
> GLuint frameBuffer = 0;
> GLuint renderBuffer = 0;
>
> glGenFramebuffersEXT(1, &frameBuffer);
> glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frameBuffer);
>
> // Render depth values to a buffer.
> glGenRenderbuffersEXT(1, &renderBuffer);
> glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, renderBuffer);
> glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24,
> width, height);
> glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
> GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, renderBuffer);
>
> glDrawBuffer(GL_NONE);
> glReadBuffer(GL_NONE);
>
> // Check validity of the frame buffer and go back to traditional
> rendering if something failed.
> GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
> if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
> canUseFBOs = false;
>
> This works fine so far but now I want to get the depth values into a memory
> buffer to make it a nice look looking, smooth shadow (blurring it,
> adjusting alpha values and such). Later I want to take the result and use
> this as texture for a simple quad. The problem I have is the glReadPixels
> call, which throws an access violation in the ATI driver. It looks so:
>
> glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
>
> render(1);
>
> void* buffer = malloc(3 * width * height);
> glReadBuffer(GL_DEPTH_ATTACHMENT_EXT);
> glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, buffer);
>
> What is it that I'm doing wrong here? It doesn't really look complicated to
> read the pixels. I have already done this with the color attachment (to
> save to a file), but reading the depth values causes trouble.
>
> Thank you,
>
> Mike
> --
> www.soft-gems.net
Hi,
The reason for the access violation is that your buffer is too small.
The format argument to glReadPixels should be GL_DEPTH_COMPONENT
and the type argument should be GL_FLOAT, giving
void *buffer = malloc(sizeof(GLfloat) * width * height);
glReadPixels(0, 0, width, height, GL_DEPTH_COMPONENT, GL_FLOAT,
buffer);
Presumably sizeof(GLfloat) >= 4 and so that was the reason for the
access violation.
All the best,
Nicholas
|
|
0
|
|
|
|
Reply
|
Nicholas
|
12/13/2005 2:03:16 PM
|
|
Mike Lischke <newsgroups@soft-gems.net> wrote:
> This works fine so far but now I want to get the depth values into a
> memory buffer to make it a nice look looking, smooth shadow (blurring
> it, adjusting alpha values and such). Later I want to take the result
> and use this as texture for a simple quad. The problem I have is the
If you are using shadow mapping, be aware of the fact that blurring
the depthmap will not blur the shadow. Read up on "Percentage Closer
Filtering" (short PCF) .. there is a pretty old paper (mid 80s I think)
about it out there written by William Reeves et al.
Alternatively, there was an article on either gamedev or devmaster,
which described one (not too fast) technique for rendering soft shadows.
hth
--
jb
(reply address in rot13, unscramble first)
|
|
0
|
|
|
|
Reply
|
Jakob
|
12/13/2005 3:05:55 PM
|
|
Nicholas Nash wrote
>The reason for the access violation is that your buffer is too small.
>The format argument to glReadPixels should be GL_DEPTH_COMPONENT
>and the type argument should be GL_FLOAT, giving
Exactly that was it, thank you.
Mike
--
www.soft-gems.net
|
|
0
|
|
|
|
Reply
|
Mike
|
12/13/2005 4:33:35 PM
|
|
Jakob Bieling wrote
>If you are using shadow mapping, be aware of the fact that blurring the
>depthmap will not blur the shadow.
Hmm, I'd think it would. If I create an image with smooth shadow and use
this as texture I have of course this shadow there too. What I'm after is
not a complete and correct dynamic scene shadowing, but rather good looking
but cheap drop shadows underneath my 2D objects. So mostly the shape is
important and stored in a texture for quick rendering, everything else is
done only when the shape changes. I have no idea how that works out with
many objects (can be 2000+, each with an own shadow)
>Read up on "Percentage Closer
>Filtering" (short PCF) .. there is a pretty old paper (mid 80s I think)
>about it out there written by William Reeves et al.
Interesting stuff. Found some pdfs (from ATI and Max-Planck-Institut f�r
Infomatik in Saarbr�cken). However, I'm afraid this will too expensive (in
terms of render time), but since I never have tried that I can't say for
sure.
> Alternatively, there was an article on either gamedev or devmaster,
>which described one (not too fast) technique for rendering soft shadows.
Do you know a sample implementation?
Thanks for your help, Jacob.
Mike
--
www.soft-gems.net
|
|
0
|
|
|
|
Reply
|
Mike
|
12/13/2005 4:44:20 PM
|
|
Mike Lischke <newsgroups@soft-gems.net> wrote:
> Jakob Bieling wrote
>> If you are using shadow mapping, be aware of the fact that blurring
>> the depthmap will not blur the shadow.
> Hmm, I'd think it would. If I create an image with smooth shadow and
> use this as texture I have of course this shadow there too. What I'm
> after is not a complete and correct dynamic scene shadowing, but
> rather good looking but cheap drop shadows underneath my 2D objects.
Does not sound like commonly known shadow mapping technique. In this
case your approach should work, if I understood you correctly :)
>> Read up on "Percentage Closer
>> Filtering" (short PCF) .. there is a pretty old paper (mid 80s I
>> think) about it out there written by William Reeves et al.
> Interesting stuff. Found some pdfs (from ATI and Max-Planck-Institut
> f�r Infomatik in Saarbr�cken). However, I'm afraid this will too
> expensive (in terms of render time), but since I never have tried
> that I can't say for sure.
It is expensive. And since you are not using the shadow mapping
technique, where depth-value comparisons are involved, it is probably
not of much use for you either.
>> Alternatively, there was an article on either gamedev or devmaster,
>> which described one (not too fast) technique for rendering soft
>> shadows.
> Do you know a sample implementation?
I think the article has code accompanying it. But it is using
DirectX. Modifying this for OpenGL would be some work, but surely is not
impossible.
hth
--
jb
(reply address in rot13, unscramble first)
|
|
0
|
|
|
|
Reply
|
Jakob
|
12/13/2005 5:22:07 PM
|
|
|
5 Replies
336 Views
(page loaded in 0.083 seconds)
Similiar Articles: FBO: depth render buffer objects - comp.graphics.api.opengl ...Hi group, For creating a shadow map I've set up a depth render buffer object, using this code: GLuint frameBuffer = 0; GLuint renderBuff... renderbuffer objects - comp.graphics.api.openglHi! I am reading about renderbuffer objects (as a part of the fbo extension) and know that they can be used to save the depth buffer. I just wonder how to render this ... Render to depth texture - comp.graphics.api.openglFBO: depth render buffer objects - comp.graphics.api.opengl ... Render to depth texture - comp.graphics.api.opengl Depth-map Shadows: Shadows in a Frame Buffer Object ... Write Depth Map to Depth buffer - comp.graphics.api.opengl ...FBO: depth render buffer objects - comp.graphics.api.opengl ... Hi group, For creating a shadow map I've set up a depth render buffer object, using ... still struggling with FBOs and depth texture (for shadow map ...After rendering to the depth buffer, I ... back to 2D textures and object ... struggling with FBOs and depth ... create a shadow map). > to render into my ... FBOs and depth ... Stencil shadowing and transparent objects. - comp.graphics.api ...FBO: depth render buffer objects - comp.graphics.api.opengl ... Hi group, For creating a shadow map I've set up a depth render buffer object, using this code ... Reading rendered image into memory - comp.graphics.api.opengl ...FBO: depth render buffer objects - comp.graphics.api.opengl ..... so far but now I want to get the depth values into a memory ... If I create an image with smooth shadow ... Color depth #3 - comp.unix.solarisFBO: depth render buffer objects - comp.graphics.api.opengl ... It looks so: glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); render(1); void* buffer = malloc(3 * width ... Getting an image object from a JPanel that is not visible - comp ...renderbuffer objects - comp.graphics.api.opengl How to get a graphics.datatip object - comp.soft-sys.matlab ... FBO: depth render buffer ... glEnable(GL_CULL_FACE ... so ... Drawing bitmap with glOrtho at a specific depth - comp.graphics ...> > In perspective projection the depth buffer values map like 1/z, while in ... you just need to be clear on who "owns" a particular ... FBO: depth render buffer objects ... FBO: depth render buffer objects - comp.graphics.api.opengl ...Hi group, For creating a shadow map I've set up a depth render buffer object, using this code: GLuint frameBuffer = 0; GLuint renderBuff... FBO: depth render buffer objects - opengl - Mofeel Groupsopengl, FBO: depth render buffer objects . comp.graphics.api.opengl - The OpenGL 3D application programming interface. 7/23/2012 4:15:14 PM
|