PDA

View Full Version : order independent transparency



yalmar
07-05-2007, 02:20 PM
hello all,

i need to implement a GLSL version for the ARB_fragment_program of the nvidia oit_3x example:

"!!ARBfp1.0\n"
"OPTION ARB_fragment_program_shadow;\n"
"PARAM offset = program.env[0];\n"
"TEMP R0;\n"
"MOV R0, fragment.position;\n"
"ADD R0.x, R0.x, - offset;\n"
"TEX R0.x, R0, texture[0], SHADOWRECT;\n"
"ADD R0.x, R0.x, -0.5;\n"
"KIL R0.x;\n"
"MOV result.color, fragment.color;\n"
"END\n";I try a GLSL code, but it doesn't work, it does only show black blots.
see my GLSL code:

uniform sampler2DRectShadow shadow;
uniform int offset;
void main(){
vec3 r0 = gl_FragCoord.xyz;
r0.x = r0.x - float(offset);
float tmp = shadow2DRect(shadow, r0).x;
if (tmp < 0.5)
discard;
gl_FragColor = gl_Color;
}In the C++ code I changed only the part:

glEnable(GL_FRAGMENT_PROGRAM_ARB);

if(peel)
peel_shader.bind();
//fp_peel.bind();
else
no_peel_shader.bind();
//fp_nopeel.bind();
where no_peel_shader is

void main(){
gl_FragColor = gl_Color;
} I assumed that the other parts of the c++ code are correcly initialized, texture_rectangles for example. I believe don't need modify anything, isn't it?

thanks for your attention,

Komat
07-05-2007, 04:48 PM
Do you set the value of the offset uniform correctly?

yalmar
07-05-2007, 06:25 PM
Yes, i do it in the same way that ARB_fragment_program parameters.

brtnrdr
07-05-2007, 08:58 PM
The offset parameter isn't necessary as OpenGL samples from the center of texels (unlike Direct3D).

I downloaded the depth peeling 2 demo from nvida (it was the only one I could find) and their ARB fragment program is:

char _fp_peel[] =
"!!ARBfp1.0\n"
"OPTION ARB_fragment_program_shadow;\n"
"TEMP R0;\n"
"TEX R0.x, fragment.position, texture[0], SHADOWRECT;\n"
"ADD R0.x, R0.x, -0.5;\n"
"KIL R0.x;\n"
"MOV result.color, fragment.color;\n"
"END\n";This would translate to GLSL as:

void main()
{
vec4 tmp = textureRect(rt, gl_FragPos.xy);
// or use shadowRect or whatever texture function will do the depth compare for you
if(tmp.x - 0.5 < 0.0)
{
discard;
}
gl_FragColor = gl_Color;
}your code was very close, but offsetting the texture lookup is a bug.

But, you might want to make sure that your shader is actually compiling and linking (by checking the infolog) because it also might sound like your hardware isn't supporting something in the application (like the shader or rendertargets, etc.).

Hope this helps some.

Humus
07-06-2007, 06:40 AM
Originally posted by yalmar:
Yes, i do it in the same way that ARB_fragment_program parameters. You're using glUniform*() calls, right? Not glProgramEnvParameter*ARB()?

yalmar
07-06-2007, 08:31 AM
Of course, for using offset in GLSL i used glUniform.
I implemented the glsl version for the layerz_3x demo, and it works fine, but in the oit_3x demo I no yet tested. I believe that works too.

overlay
07-06-2007, 10:07 AM
Take a look at the implementation in VTK:

http://www.vtk.org/Wiki/VTK/Depth_Peeling

in VTK/Rendering/vtkOpenGLRenderer.cxx, there is the following code:

uniform sampler2DRectShadow shadowTex;
uniform sampler2DRectShadow opaqueShadowTex;
uniform float offsetX;
uniform float offsetY;
uniform int useTexture;
uniform sampler2D texture;
void main()
{
vec4 r0=gl_FragCoord;
r0.x=r0.x-offsetX;
r0.y=r0.y-offsetY;
float r1=shadow2DRect(opaqueShadowTex,r0.xyz).x;
r1=r1-0.5;
if(r1<0.0)
{
discard;
}
r0.x=shadow2DRect(shadowTex,r0.xyz).x;
r0.x=r0.x-0.5;
if(r0.x<0.0)
{
discard;
}
if(useTexture==1)
{ gl_FragColor=gl_Color*texture2D(texture,gl_TexCoor d[0].xy);
}
else
{
gl_FragColor=gl_Color;
}
}

yalmar
07-10-2007, 07:36 AM
VTK Rendering? I tested it, but ... I think isn't a good implementation of OIT, and in 8XXX series' NVIDIA GPUs doesn't work fine.

Someone has an implementation like as "Multi-layer depth peeling via fragment sort"?