Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 16 Jun 2009
Offline Last Active Mar 13 2013 09:30 AM

Topics I've Started

SRGB with FBO problem

08 February 2013 - 08:42 AM



I was trying to write linear color values to FBO with glEnable(GL_FRAMEBUFFER_SRGB) enabled, but conversion from linear -> SRGB space seems not working.

My test program was doing something like this:


1. Load some test texture with GL_SRGB8 format

2. Initialize FBO with texture with GL_SRGB8_ALPHA8 format

3. Bind that FBO


5. render test texture to FBO

  -> now FBO should contain very the same color values as input test texture (conversion SRGB -> linear of test texture during sampling, and then conversion linear -> SRGB during write to FBO).


7. Unbind FBO and render FBO texture to back buffer.


I was expecting, that output color will be the same as input texture, but result is darker, that means, that conversion is not working. Strange is, that rendering that test GL_SRGB8 texture directly to the back buffer (no FBO) when GL_FRAMEBUFFER_SRGB was enabled is working (output is very the same as input texture).


I was trying to initialize FBO just as GL_RGBA8 format, but results were still dark.


So, I want to ask, shoud SRGB conversion work even for FBO buffers? (as I was reading the spec of that extension, it should work). Or is it just some driver bug? (I'm using AMD card), or did I overlook something?



depth stencil framebuffer problem

15 April 2010 - 08:57 PM

Hello, I have setup FBO depth stencil texture, and everything works fine, but problem is, when I try to bind that depth texture, and later bind that FBO again, then contents of stencil buffer is damaged (it looks, that it is rewriten by some depth values). My code looks somehow like this: Generation of FBO: glGenFramebuffersEXT(1, &m_gl_framebuffer); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_gl_framebuffer); glGenTextures(1,&depthTextureID); glBindTexture(GL_TEXTURE_2D,depthTextureID); glTexImage2D (GL_TEXTURE_2D,0,GL_DEPTH24_STENCIL8_EXT,800,600,0,GL_DEPTH_STENCIL_EXT,GL_UNSIGNED_INT_24_8_EXT, NULL); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, depthTextureID, 0); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_2D, depthTextureID, 0); test for rewrite: glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_gl_framebuffer); glClearDepth(0.500000); glClearStencil(1); glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0); //Binding of texture - if commented, then stencil is ok! glActiveTextureARB(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,depthTextureID); glActiveTextureARB(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,0); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,m_gl_framebuffer); //<--- here stencil buffer is damaged! glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0); If I dont bind that texture, then everything is OK :( Did anyone encounter this problem too? Thanks for help.

Reading bound depth stencil resource

31 March 2010 - 06:46 PM

Hello, I needed to use depth stencil resource in the shader, but at the same time I need to bound this resource as the render target. But because this is impossible to do in DX10, I had to overcome this problem somehow. First solution is to use DX9 approach - this means create another resource, and during depth fill bind that resource and store depth info into it. This has the disadvantage, that resource must be cleared with the regular depth stencil buffer. So, next I was trying to create another resource again, but when finishing depth rendering, use CopyResource to copy this depth-stencil buffer into it. So now instead of clearing the buffer there is a copy. I did some tests and it seems, that for depth buffer without stencil this copy is faster. BUT, for depth buffer with stencil I cannot find any suitable format for destination, for which this CopyResource would be possible to do. Could anyone help? Is this copy even possible? In DX10 help is mentioned, that depth-stencil resources cannot be used as a destination. But I'm using it as source, so this should be OK. Thanks.

FBO Configuration

21 December 2009 - 12:54 AM

Hello, I was trying to setup FBO configuration that would draw color normaly to the back buffer, and depth values to the texture, but didn't find out how. Is such configuration even possible? I needed it for following rendering: 1. Do scene draw with Z-pass only (this would fill that depth texture) 2. Do some calculations using that depth texture (some kind of shadow mapping) 3. Render scene to the back buffer and use that depth texture for depth tests. This configuration is possible to do in DX9, but I failed to set it up on OGL. Can anybody help? Thanks.

Shadow mapping question

16 June 2009 - 11:08 AM

Hello, I was trying to get into shadow mapping. Theory behind seemed to me easy - that is, render scene from light POV and save depth, then render scene from camera POV and using depths compare of camera and light check if pixel is in the shadow. I found some demo/tutorials that works, but I still didn't get details. First I used code like this: set light modelview and projection matrix, render scene, and save depth and texture matrices like this: bias * projection * modelview. then set camera modelview and projection matrix and render scene again, but this time use shader program that looks like this: VS: ... ShadowCoord = gl_TextureMatrix * gl_Vertex; ... FS: uniform sampler2DShadow ShadowMap; ... float shadow = shadow2DProj(ShadowMap, shadowCoord).w; //see if we are in shadow. .. this worked, but I still didn't fully understand what is behind that shadow2DProj instruction. So I made some investigation and according to specifications I replaced code with this: VS is the same FS: uniform sampler2D ShadowMap; ... vec4 swCoords = shadowCoord / shadowCoord.q; float depth1 = texture2D(ShadowMap, swCoords.st).r; float depth2 = swCoords.p; float shadow; if (depth1 >= depth2) shadow = 1.0; else shadow = 0.0; .. It still worked, BUT in fact I still dont understand it:( It should work like comparing of depth from light and camera, but I still dont see it in it! Because as I understand the code it means: * ShadowCoords in vertex shader is vertex transformed by light matrices into screen coordinates (without w division) - think, that this is called homogeneous coordinates * next, in fragment shader we divide it by W component and we get coordinates as the vertex appears in the screen (in 0 - 1 range) IS IT CORRECT? * by using those coordinates we go to the ShadowMap (texture that represents scene depth from point of wiew) to get depth1 - this is probably light depth * depth2 is just swCoords.p * then comparison is made. But, I dont understand those two depths they both seems to me related only to the light, but not the scene, because that swCoords are realated only to the light! Please, where did I go wrong? Thanks.