# the precision issue in 16 bit Z-Buffer

Printable View

Show 40 post(s) from this thread on one page
Page 2 of 2 First 12
• 09-16-2012, 07:40 PM
kamimail
Hi, Everyone,
Thanks for all replies!
mhagain, according to the specification in WebGL 1.0, the size of default depth buffer is 16 bit integer.:)
I have struggled this problem throught this weekend.due to the limitations in WebGL,Nether Lineard Depth Buffer nor Logarithmic Depth Buffer is appropraite to be applied in my situation.
maybe ,the only way is to adjust the projection plane dynamicly.
• 09-16-2012, 08:49 PM
michagl
I developed some stuff for WebGL a little while back and now that you mention it the depth dept. did seem really cramped, but I figured I just did not know what I was doing. Anyway I calculated the near/far planes because I needed accuracy for doing things like filling in back faces and shadows.

I never explicitly set the depth buffer anywhere as I recall (since you don't seem to have to specify that with OpenGL??) so it may well be 16bit if so.

You might look into passing creation parameters. It may different for every browser. But there are some things you can control that way. Let us know how it goes please.

EDITED: http://www.swordofmoonlight.net/canvas.php?shadow=1
• 09-17-2012, 01:44 AM
kRogue
I think what he means is that tweak the projection matrix so the rows that produce x and y and w are as usual, but tweak the row that makes the z-coordinate to act orthogonal and tweak your shader to do the right thing too:

C code
Code :

```mat4 /*or whatever you use for 4x4matrices */ proj;   proj=createProjectionMatrix(args); /* tweak row that produces the z-coordinate: */ proj.row(3).element(0)=0.0f; proj.row(3).element(1)=0.0f; proj.row(3).element(2)= 2.0f/(far-near); proj.row(3).element(3)=-1 -2.0f*near/(far-near);```

GLSL
Code :

```mat4 projection; vec3 eye_coordinates;   gl_Position.xyzw=projection*eye_coordinates; gl_Position.z*=gl_Position.w; //essentially kill the perspective divide on the z-coordinate.```

Though this will drop the z-fighting far away, up close the z-fighting is going to become an issue...
Show 40 post(s) from this thread on one page
Page 2 of 2 First 12