Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: the precision issue in 16 bit Z-Buffer

  1. #11
    Junior Member Newbie
    Join Date
    Nov 2009
    Location
    beijing
    Posts
    11
    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.

  2. #12
    Member Regular Contributor
    Join Date
    Jan 2005
    Location
    USA
    Posts
    411
    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
    God have mercy on the soul that wanted hard decimal points and pure ctor conversion in GLSL.

  3. #13
    Advanced Member Frequent Contributor
    Join Date
    Apr 2009
    Posts
    600
    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...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •