Re: [osg-users] Z-buffer transparency / Alpha
hybr wrote: Hi, If u didn't solved that yet - try 2 things: 1st: when doing prerender - on root stateset set GL_DEPTH_TEST to ON|OVERRIDE and DEPTH attrib to LESS and turn it ON|OVERRIDE(seems like depth write turned off for transparent objects by default, which is right thing in general :D ) 2nd: when doing prerender - render depth with a shader and set there gl_FragColor.a = 1.0; Cheers, Sergey Hi, Thank you for digging :). Good observation, GL_DEPTH_TEST influences the z-buffer (of course you would say...). Actually, when accessing a depth texture in a shader in GLSL 1.2 if DEPTH_TEST is ON it has to be passed as a sampler(2D/Rect)Shadow else as a sampler(2D/Rect). This may help someone someday. Actually, I had just forgot to check my texture units (I thought I had, but I had just begun and not finished) and wrote z-buffer on a unit used transparent faces use. I didn't want to push it on the top of the topics, but I have to reply to any help. Cheers, Max -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=16921#16921 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Z-buffer transparency / Alpha
Hi, If u didn't solved that yet - try 2 things: 1st: when doing prerender - on root stateset set GL_DEPTH_TEST to ON|OVERRIDE and DEPTH attrib to LESS and turn it ON|OVERRIDE(seems like depth write turned off for transparent objects by default, which is right thing in general :D ) 2nd: when doing prerender - render depth with a shader and set there gl_FragColor.a = 1.0; Cheers, Sergey -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=16739#16739 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Z-buffer transparency / Alpha
Hi, I discovered something I find really strange. I exported my scene from .ive to .osg. I opened it with a text editor and I replaced all GL_BLEND ON statements by GL_BLEND OFF. When I load my project with this .osg here's what the camera see (placed at the projective camera place): [Image: http://img7.hostingpics.net/pics/270676Dot_OSG_GL_BLEND_OFF.png ] (http://www.hostingpics.net/viewer.php?id=270676Dot_OSG_GL_BLEND_OFF.png) And if I open the .ive file and execute: Code: _root_stateset-setMode(GL_BLEND, StateAttribute::OFF | StateAttribute::OVERRIDE); [Image: http://img7.hostingpics.net/pics/690702Z_buffer_pourri.png ] (http://www.hostingpics.net/viewer.php?id=690702Z_buffer_pourri.png) I am very surprised it doesn't give the sam results. What's happening ? Is there a bug? Thank you! Cheers, Maxime -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=16129#16129 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Z-buffer transparency / Alpha
Hi, look in the .osg file if some of the statesets do not maybe have StateAttribute::PROTECTED. jp Maxime BOUCHER wrote: Hi, I discovered something I find really strange. I exported my scene from .ive to .osg. I opened it with a text editor and I replaced all GL_BLEND ON statements by GL_BLEND OFF. When I load my project with this .osg here's what the camera see (placed at the projective camera place): [Image: http://img7.hostingpics.net/pics/270676Dot_OSG_GL_BLEND_OFF.png ] (http://www.hostingpics.net/viewer.php?id=270676Dot_OSG_GL_BLEND_OFF.png) And if I open the .ive file and execute: Code: _root_stateset-setMode(GL_BLEND, StateAttribute::OFF | StateAttribute::OVERRIDE); [Image: http://img7.hostingpics.net/pics/690702Z_buffer_pourri.png ] (http://www.hostingpics.net/viewer.php?id=690702Z_buffer_pourri.png) I am very surprised it doesn't give the sam results. What's happening ? Is there a bug? Thank you! Cheers, Maxime -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=16129#16129 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org -- This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html. This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. MailScanner thanks Transtec Computers for their support. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Z-buffer transparency / Alpha
Hello there again, Thanks J.P for answering, but no, there is no protected stateattribute. Max wrote: Hi, I discovered something I find really strange. I exported my scene from .ive to .osg. I opened it with a text editor and I replaced all GL_BLEND ON statements by GL_BLEND OFF. When I load my project with this .osg here's what the camera see (placed at the projective camera place): [Image: http://img7.hostingpics.net/pics/270676Dot_OSG_GL_BLEND_OFF.png ] (http://www.hostingpics.net/viewer.php?id=270676Dot_OSG_GL_BLEND_OFF.png) And if I open the .ive file and execute: Code: _root_stateset-setMode(GL_BLEND, StateAttribute::OFF | StateAttribute::OVERRIDE); [Image: http://img7.hostingpics.net/pics/690702Z_buffer_pourri.png ] (http://www.hostingpics.net/viewer.php?id=690702Z_buffer_pourri.png) I am very surprised it doesn't give the sam results. What's happening ? Is there a bug? Thank you! Cheers, Maxime I made another test. I converted the .ive to .osg and I made no change to the file. I executed the same code on both and for the .osg I had the same results than the manual modif I told in the previous post. This means, for the same code (and called _root_stateset-setMode(GL_BLEND, StateAttribute::OFF | StateAttribute::OVERRIDE);), the same model, one in .ive, the other in .osg the results are differents. Well, am I doing something wrong, or is there a bug? Thank you Cheers, Max -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=16135#16135 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Z-buffer transparency / Alpha
J.P. Delport wrote: Hi, Maxime BOUCHER wrote: Hello there again, Thanks J.P for answering, but no, there is no protected stateattribute. I made another test. I converted the .ive to .osg and I made no change to the file. I executed the same code on both and for the .osg I had the same results than the manual modif I told in the previous post. This means, for the same code (and called _root_stateset-setMode(GL_BLEND, StateAttribute::OFF | StateAttribute::OVERRIDE);), the same model, one in .ive, the other in .osg the results are differents. Well, am I doing something wrong, or is there a bug? What happens when you convert the .osg back to .ive and use that .ive? Maybe the optimiser in osgconv is messing with the original .ive? You could also manually try to write out the osg graph after loading the .ive and compare it to the output of osgconv. jp Thank you Cheers, Max -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=16135#16135 ___ osg-users mailing list http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org -- This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html. This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. MailScanner thanks Transtec Computers for their support. ___ osg-users mailing list http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org -- Post generated by Mail2Forum Hello, Alright, I did osgconv .ive to .osg and immediately .osg to .ive, and now it seems blending is always deactivated. I mean, whether I call: _root_stateset-setMode(GL_BLEND, StateAttribute::OFF | StateAttribute::OVERRIDE); _root_stateset-setMode(GL_BLEND, StateAttribute:: ON | StateAttribute::OVERRIDE); or nothing I always visualize this: [Image: http://img7.hostingpics.net/pics/270676Dot_OSG_GL_BLEND_OFF.png ] (http://www.hostingpics.net/viewer.php?id=270676Dot_OSG_GL_BLEND_OFF.png) Thus: -I completely lost, what is happening? I am wondering if this hasn't to deal with more than just blending. - Do you know what can happen in the depth buffer so that even with blending turned off, transparent faces are not filled with a distance? - I 've read a topic about using multiple viewer and uncomplete drawings. In this post Robert adviced to call stopThreading() on the currently not rendering viewer. I tried that, but of course, since I post, it didn't solve the problem. Thank you for your help and reading, Cheers, Max -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=16145#16145 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Z-buffer transparency / Alpha
Alright, I found the problem. During the conversion, textures are lost, then when the shader reads a texture it finds nothing. - Do you know how can I test it? I mean, if the texture slot (the specified unit) is empty, I would like to fill the fragment with the object color. Too bad my textures are compressed .rgb, thus I can't export them in .osg as explained here (http://forum.openscenegraph.org/viewtopic.php?t=3337postdays=0postorder=ascstart=0). Finally, the problem came only from me (as usual would say some), sorry for the wrong alert. However, I'm still in big troubles with the Z-buffer, your help would be welcomed. Thank you! Cheers, Maxime -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=16148#16148 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Z-buffer transparency / Alpha
Hi, Maxime BOUCHER wrote: Alright, I found the problem. During the conversion, textures are lost, then when the shader reads a texture it finds nothing. - Do you know how can I test it? I mean, if the texture slot (the specified unit) is empty, I would like to fill the fragment with the object color. sorry I don't know if it's possible. Too bad my textures are compressed .rgb, thus I can't export them in .osg as explained here (http://forum.openscenegraph.org/viewtopic.php?t=3337postdays=0postorder=ascstart=0). Do you not have the original textures? How did you get to the .ive? In that thread it seemed there was a solution - you have to convince osgconv to use another extension/format for the textures. Finally, the problem came only from me (as usual would say some), sorry for the wrong alert. However, I'm still in big troubles with the Z-buffer, your help would be welcomed. I don't have any more ideas. From the last image you posted it just seems that you are somehow not writing to the depth buffer for some geometry or fragments. You will have to check the statesets for disabling of depth write. jp Thank you! Cheers, Maxime -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=16148#16148 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org -- This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html. This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. MailScanner thanks Transtec Computers for their support. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Z-buffer transparency / Alpha
Hi, Ulrich Hertlein wrote: Hi Maxime, On 7/08/09 12:02 PM, Maxime BOUCHER wrote: Ulrich Hertlein wrote: Hi Maxime, I'm extremely irritated by what you write and maybe I'm not the only one. I am very sorry, please apologize. Maybe could you tell me why so that I won't do it again. No need to apologize. (I meant 'irritated' as 'confused', not annoyed or angry, just in case that's how you understood it; English can be fuzzy... :-} Well, thank you, I misunderstood you, but I also know I'm quite a noob compared to most of you, and I understand my noob's questions can be irritating. Ulrich Hertlein wrote: You have to keep in mind that the people on the mailing list have absolutely no idea what you're trying to achieve and what the problem is. You alone have that information so it helps to give as much detail as possible when posting a question. What are you trying to accomplish and how do you approach it? What is your shader doing? What I do: It is a projective texture mapping. I put a prerending viewer in the scene given its orientation and position. I attach to its DEPTH_BUFFER a depth image. I do a frame() on the prerender to fill the depth image. A color image is declared to check the prerender orientation if needed. Code: _root_stateset = _root-getOrCreateStateSet(); _depth = new Image(); _color = new Image(); _depth-allocateImage(_imWidthHeight-x(), _imWidthHeight-y(), 1, GL_DEPTH_COMPONENT, GL_FLOAT); _color-allocateImage(_imWidthHeight-x(), _imWidthHeight-y(), 1, GL_RGBA, GL_UNSIGNED_BYTE); _prerender-getCamera()-attach(Camera::DEPTH_BUFFER, _depth.get(), 0, 0); _prerender-getCamera()-attach(Camera::COLOR_BUFFER, _color.get(), 0, 0); _texdepth = new Texture2D(_depth.get()); _root_stateset-setTextureAttribute(_depth_unit, _texdepth.get()); _texcolor = new Texture2D(_color.get()); _root_stateset-setTextureAttribute(_color_unit, _texcolor.get()); _tex = new Texture2D(_img.get()); _root_stateset-setTextureAttribute(_tex_unit, _tex.get()); Then I attach to the root node a shader and run the rendering viewer. The shader computes the projection of each fragment in the image space of the projective camera (i.e. the prerender). If the fragment is out of bound then I texture it with it's original texture. If the fragment distance from the projective camera is different from the one stored in the Z-buffer then I texture it with its original texture too. Else, I texture the fragment with its corresponding set of pixels (interpolation done by hardware) in the image to project. It is quite clear in the code (and I don't post it in order to be debugged, just to be clearer). Vertex shader: Code: varying vec4 coord; void main() { coord = gl_Vertex; gl_TexCoord[0] = gl_MultiTexCoord0; gl_Position = ftransform(); } Fragment shader: Code: uniform sampler2D tex; //uniform sampler2D depthtex; uniform sampler2DShadow depthtex; uniform sampler2D originaltexture; uniform sampler2D colortex; uniform mat4 WorldToCam; uniform mat4 CamToImage; uniform mat4 correction; uniform vec3 camposition; uniform float znear; uniform float zfar; uniform float uptozbits; uniform float imagewidth; uniform float imageheight; varying vec4 coord; varying float intensity; void normalizeW( inout vec4 vec ) { vec = vec / vec.w; return; } void normalizeZ( inout vec4 vec ) { vec = vec / vec.z; return; } float zbuffer_precision(float Z) //*** Used to compute the error of Z buffer { float b = znear * zfar / (znear-zfar); float res = ( b / ( (b/Z) - 1.0/uptozbits ) ) - Z; return abs(res); } void main() { vec4 camspace = WorldToCam * coord; normalizeW(camspace); if (camspace.z 0.0) { gl_FragColor = texture2D(originaltexture, gl_TexCoord[0].st); return; } float Z = -camspace.z; vec4 imspace = CamToImage * correction * camspace; normalizeZ(imspace); if ( imspace.x 0.0 | imspace.x imagewidth | imspace.y 0.0 | imspace.y imageheight ) { gl_FragColor = texture2D(originaltexture, gl_TexCoord[0].st); return; } //float uncorrected_z = texture2D( depthtex, vec2(imspace.x/imagewidth, 1-imspace.y/imageheight) ); float uncorrected_z = shadow2D( depthtex, vec3(imspace.x/imagewidth, 1-imspace.y/imageheight, 1.0) ).r; float corrected_z = znear*zfar / (zfar - uncorrected_z*(zfar-znear)); if (uncorrected_z 0.0 | uncorrected_z 1.0) //*** Error case { gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); return; } if(false) //*** Used to display a kind of real distance { gl_FragColor = vec4(Z/15, Z/15, Z/15, 1.0); return; } if(true) //*** Used to display distance stored in the Z-buffer { vec4 color = vec4(uncorrected_z, uncorrected_z, uncorrected_z, 1.0); gl_FragColor = color; return; } if (false) //*** Used to display the color image attached to the color_buffer { gl_FragColor = texture2D( colortex, vec2(imspace.x/imagewidth, 1-imspace.y/imageheight) ); return; } float delta = zbuffer_precision(Z); float corrected_delta = znear*zfar / (zfar -
Re: [osg-users] Z-buffer transparency / Alpha
Hi Maxime, On 6/08/09 4:41 PM, Maxime BOUCHER wrote: I know Z-buffer isn't very in fond of transparency, and actually, when I capture it on a model having transparent faces it stores strange things (a kind of luminance image of some textures on parts corresponding to these transparents faces). Thus, I tried to deactivate it, but I didn't find how. I tried all this stuff: ... But, if one of it (ALPHA_TEST), stopped the transparency, my Z-buffer has always kept being corrupted. Then, my question is, how can I really deactivate the transparency? Of course, if you have good ideas to have transparency and a working Z-buffer, I would be very pleased :). I'm extremely irritated by what you write and maybe I'm not the only one. Why do you suspect that the Z-buffer is influenced by alpha blending? So you're reading back the depth buffer and it's not what you expect? Could you post a screenshot? /ulrich ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Z-buffer transparency / Alpha
Hi Ulrich, Ulrich Hertlein wrote: Hi Maxime, I'm extremely irritated by what you write and maybe I'm not the only one. I am very sorry, please apologize. Maybe could you tell me why so that I won't do it again. Ulrich Hertlein wrote: Why do you suspect that the Z-buffer is influenced by alpha blending? Because problems only appear with models having alpha blending. Ulrich Hertlein wrote: So you're reading back the depth buffer and it's not what you expect? Could you post a screenshot? /ulrich You're right, it would be clearer. Here is the camera view (with a green mask): [Image: http://img7.hostingpics.net/pics/144972Z_buffer_colorimage.png ] (http://www.hostingpics.net/viewer.php?id=144972Z_buffer_colorimage.png) here the distance of fragments to the camera computed in shader: [Image: http://img7.hostingpics.net/pics/850811Z_buffer_shader.png ] (http://www.hostingpics.net/viewer.php?id=850811Z_buffer_shader.png) and the Z-buffer image: [Image: http://img7.hostingpics.net/pics/690702Z_buffer_pourri.png ] (http://www.hostingpics.net/viewer.php?id=690702Z_buffer_pourri.png) Problems are only located on surfaces having transparency. And to be complete: - The Z image is computed from another viewer than the rendering one (I allocate an image and attach it to prerendering cam's Z-buffer then execute one frame() ). - The images are sampler2D in the shader, thus I retrieve pixels from them and put it in gl_FragColor to be able to display. Thanks a lot for help, and once again I'm very sorry for being so irritating, please accept my apologies. Cheers, Max -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=15942#15942 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Z-buffer transparency / Alpha
Hi Maxime, On 7/08/09 12:02 PM, Maxime BOUCHER wrote: Ulrich Hertlein wrote: Hi Maxime, I'm extremely irritated by what you write and maybe I'm not the only one. I am very sorry, please apologize. Maybe could you tell me why so that I won't do it again. No need to apologize. (I meant 'irritated' as 'confused', not annoyed or angry, just in case that's how you understood it; English can be fuzzy... :-} You have to keep in mind that the people on the mailing list have absolutely no idea what you're trying to achieve and what the problem is. You alone have that information so it helps to give as much detail as possible when posting a question. What are you trying to accomplish and how do you approach it? What is your shader doing? Here is the camera view (with a green mask): [Image: http://img7.hostingpics.net/pics/144972Z_buffer_colorimage.png ] here the distance of fragments to the camera computed in shader: [Image: http://img7.hostingpics.net/pics/850811Z_buffer_shader.png ] and the Z-buffer image: [Image: http://img7.hostingpics.net/pics/690702Z_buffer_pourri.png ] Okay, the issue is with the last image, the parts that look like they're from a previous frame? And these are areas that are covered by transparent geometry in the original image? Cheers, /ulrich ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Z-buffer transparency / Alpha
Hi, I know Z-buffer isn't very in fond of transparency, and actually, when I capture it on a model having transparent faces it stores strange things (a kind of luminance image of some textures on parts corresponding to these transparents faces). Thus, I tried to deactivate it, but I didn't find how. I tried all this stuff: Code: _root_stateset-setMode(GL_BLEND, StateAttribute::OFF | StateAttribute::OVERRIDE); _root_stateset-setMode(GL_ALPHA_TEST, StateAttribute::OFF | StateAttribute::OVERRIDE); _root_stateset-setMode(GL_ALPHA_TEST_FUNC, StateAttribute::OFF | StateAttribute::OVERRIDE); _root_stateset-setMode(GL_ALPHA_TEST_REF, StateAttribute::OFF | StateAttribute::OVERRIDE); _root_stateset-setMode(GL_LUMINANCE_ALPHA, StateAttribute::OFF | StateAttribute::OVERRIDE); _root_stateset-setMode(GL_LUMINANCE, StateAttribute::OFF | StateAttribute::OVERRIDE); _root_stateset-setMode(GL_ALPHA, StateAttribute::OFF | StateAttribute::OVERRIDE); But, if one of it (ALPHA_TEST), stopped the transparency, my Z-buffer has always kept being corrupted. Then, my question is, how can I really deactivate the transparency? Of course, if you have good ideas to have transparency and a working Z-buffer, I would be very pleased :). Thank you! Cheers, Maxime -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=15922#15922 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org