Hi,
I am trying to port an example of the depth peeling, an Order Independent Transparency technique, to the so-called modern OpenGL (3.3+) but since I am a beginner, it is not that easy ^^ Here you can find a working version (the GL2) and the one in progress (the GL3) https://github.com/elect86/modern-jogl-examples/tree/master/modern-jogl-examples/src/depthPeeling I implemented everything that I could, VBOs, VAOs, modelview and projection matrixes as UBOs, ftransform(), etc.. I have problems with the shaders, especially with programs based on multiple vertex and fragment shaders (I have still never encountered them) and also the gl_TexCoord[] variable (that should be deprecated, shouldnt it? Is it ok declaring the UBO only in the VS using the variables included or shall I also declare it in the other VS linked in the same program? |
I am not sure I am understanding the questions but
1. Yes, gl_TexCoord[] is deprecated 2. I see that you have 5 pairs of vertex and fragment shaders. What you probably want to do is create 5 shader programs each one executing one of the shader pairs and then switch among programs to use the one you need at the time. Each shader program (vertex shader) should accept its own uniform variables and they may be different than what the other programs accept. I hope this is somewhat helpful. Maybe I can help you further if I better understand the question. |
This post was updated on .
Ok, lets make a step per time. Starting with the first program, originally it was based on the following VSs and FSs init_VS: vec3 ShadeVertex(); void main(void) { gl_Position = ftransform(); gl_TexCoord[0].xyz = ShadeVertex(); } shade_VS: vec3 ShadeVertex() { float diffuse = abs(normalize(gl_NormalMatrix * gl_Normal).z); return vec3(gl_Vertex.xy, diffuse); } init_FS: vec4 ShadeFragment(); void main(void) { vec4 color = ShadeFragment(); gl_FragColor = vec4(color.rgb * color.a, 1.0 - color.a); } shade_FS: uniform float Alpha; #define COLOR_FREQ 30.0 #define ALPHA_FREQ 30.0 #if 1 vec4 ShadeFragment() { float xWorldPos = gl_TexCoord[0].x; float yWorldPos = gl_TexCoord[0].y; float diffuse = gl_TexCoord[0].z; vec4 color; float i = floor(xWorldPos * COLOR_FREQ); float j = floor(yWorldPos * ALPHA_FREQ); color.rgb = (fmod(i, 2.0) == 0) ? vec3(.4,.85,.0) : vec3(1.0); //color.a = (fmod(j, 2.0) == 0) ? Alpha : 0.2; color.a = Alpha; color.rgb *= diffuse; return color; } #else vec4 ShadeFragment() { vec4 color; color.rgb = vec3(.4,.85,.0); color.a = Alpha; return color; } #endif I partially modified them. Here I introduced custom view and projection matrixes using UBO and declared the position attribute. I dont know what to do with the gl_TexCoord[].. init_VS: layout (location = 0) in vec4 position; layout(std140) uniform mvpMatrixes { mat4 projectionMatrix; mat4 viewMatrix; }; vec3 ShadeVertex(); void main(void) { gl_Position = projectionMatrix * viewMatrix * position; gl_TexCoord[0].xyz = ShadeVertex(); } The shade_VS uses also deprecated values, should I declare my custom normalMatrix and normal attribute there or in the init_VS? Regarding the init_FS, it should be pretty easy, just declaring the output color, substituting the deprecated gl_FragColor vec4 ShadeFragment(); out vec4 outputColor; void main(void) { vec4 color = ShadeFragment(); outputColor = vec4(color.rgb * color.a, 1.0 - color.a); } I dont know instead what to do with the shade_FS, I could modified the #if in order to execute the second branch, that appears to be easier, as follows uniform float Alpha; #define COLOR_FREQ 30.0 #define ALPHA_FREQ 30.0 #if 0 vec4 ShadeFragment() { float xWorldPos = gl_TexCoord[0].x; float yWorldPos = gl_TexCoord[0].y; float diffuse = gl_TexCoord[0].z; vec4 color; float i = floor(xWorldPos * COLOR_FREQ); float j = floor(yWorldPos * ALPHA_FREQ); color.rgb = (fmod(i, 2.0) == 0) ? vec3(.4,.85,.0) : vec3(1.0); //color.a = (fmod(j, 2.0) == 0) ? Alpha : 0.2; color.a = Alpha; color.rgb *= diffuse; return color; } #else vec4 ShadeFragment() { vec4 color; color.rgb = vec3(.4,.85,.0); color.a = Alpha; return color; } #endif |
If I got it properly, gl_TexCoord is nothing else than a variable that is passed from the VS to the FS, isnt it?
Moreover, since it seems that it is used in the first #if-branch inside the shade_FS and I am currently using the second one, I guess I can ignore it for the moment.. |
I cant see any layer behind...
I guess there are some problems with the alpha value.. I tried to debug it and in the private void renderDepthPeeling(GL2 gl2) { confronting between the GL2 and GL3 program version the the first and the last passage (1 and 3) looks correct, so the problem lies in the 2 I modified the for cicle in order to get only a cicle for (int layer = 1; layer < 2; layer++) { and // gl2.glBindFramebuffer(GL2.GL_FRAMEBUFFER, fboId[currentId]); gl2.glBindFramebuffer(GL2.GL_FRAMEBUFFER, 0); In order to see visually the intermediate result Well, in the GL2 I get while in the GL3 My dpPeel program is based on dpPeel_VS #version 330 layout (location = 0) in vec4 position; layout(std140) uniform mvpMatrixes { mat4 projectionMatrix; mat4 cameraMatrix; }; void main(void) { gl_Position = projectionMatrix * cameraMatrix * position; } And dpPeel_FS plus shade_FS #version 330 uniform samplerRect DepthTex; vec4 ShadeFragment(); out vec4 outputColor; void main(void) { // Bit-exact comparison between FP32 z-buffer and fragment depth float frontDepth = texture(DepthTex, gl_FragCoord.xy).r; if (gl_FragCoord.z <= frontDepth) { discard; } // Shade all the fragments behind the z-buffer vec4 color = ShadeFragment(); outputColor = vec4(color.rgb * color.a, color.a); } #version 330 uniform float Alpha; vec4 ShadeFragment() { vec4 color; color.rgb = vec3(.4,.85,.0); color.a = Alpha; return color; } Where am I wrong? You can find all the code here https://github.com/elect86/modern-jogl-examples/tree/master/modern-jogl-examples/src/depthPeeling |
Ok solved, it was a problem at the blending passage and the full screen quad
If I would like to do lighting now, where should I apply it? |
Administrator
|
On 10/14/2013 01:54 PM, elect [via jogamp] wrote:
> Ok solved, it was a problem at the blending passage and the full screen quad Nice! > > If I would like to do lighting now, where should I apply it? Look in GearsES2 for per fragment lighting. ~Sven signature.asc (911 bytes) Download Attachment |
Free forum by Nabble | Edit this page |