PDA

View Full Version : Z-equal mode??



brett01
04-23-2009, 12:06 AM
I want to know what Z-equal mode is and how to implement it in Opengl.I have seen this in a paper and it is written as "When painting on the object so only the part of the surface whose appearance changes needs to be redrawn. Since painting is usually localized to a small region, this involves redrawing many fewer polygons and can easily be done in realtime.These incremental changes are drawn using z-equal mode into the front-buffer and no buffer swaps are done.."

Z-equal mode is a variation of z-buffering where the screen is updated only if what is being drawn has the same depth as what has been drawn previously. This usually is enough to insure that polygons are only drawn on top of themselves and hence where they are visible

ZbuffeR
04-23-2009, 12:41 AM
glDepthFunc(GL_EQUAL);

but drawing to front buffer only is fragile.

ZbuffeR
04-23-2009, 12:47 AM
Is your paper titled "Direct WYSIWYG Painting and Texturing on 3D Shapes" ?
Beware that it is 20 years old.

brett01
04-23-2009, 01:24 AM
yes the paper is "Direct WYSIWYG Painting and Texturing on 3D Shapes".I also have another doubt please if you have read the paper.

"An easy way to find the brush position that takes advantage of the graphics hardware is to draw object identifiers (id's) into an auxiliary frarnebuffer (sometimes called an object tag buffer or an item buffer). The object id is a integer that uniquely specifies what part of the object is visible at a given screen position.Given the position of the cursor on the screen and an object id buffer, the brush position oti the surface can be found byjust reading the pixel in the object id buffer under the cursor, This id encodes the mesh and the texture coordinates of that mesh's micropolygon. Because the meshes must be divided into large numbers of micropolygons, the object id buffer must have quite a bit of precision. For example, drawing an object with a 512 by 512 texture map, requires at least an 18-bit id buffer."

Please how to simulate this buffer.I am unable to find any info and i dont understand about it.

ZbuffeR
04-23-2009, 02:22 AM
One can use a classic RGBA color buffer for this, it would provide 32bits of precision.

The idea is to disable lighting (and antialiasing if present) and render the texture object normally, but with a different texture : same size, but each texel storing its s,t coordinates.
Once rendered, read the pixel below mouse pointer to retrieve the texture s,t coordinates.

See http://www.opengl.org/resources/faq/technical/selection.htm

brett01
04-23-2009, 10:09 PM
Thank you very much sir for the reply.What i dont understand from the paper is that we are painting for a volume and not to a point right! so we use some function like a sphere and each stroke is composed of a certain radius right??Intersection is for a certain radius and not a point??How it is done by finding closest point??
and object buffer described in the paper contains object space coordinates??you said its something like a color buffer but it contains RGBA values right?

ZbuffeR
04-24-2009, 02:50 AM
As you posted in "OpenGL coding: advanced" I though you were already used to GL and computer graphics, but it now sounds you are just starting.

I did not read the paper, but you have several ways to do the "sphere" brush, a very precise way could be for example readpixels on a wider zone, with both RGBA+depth, reconstruct object space coordinate for each point, and only include those within the sphere centered on middle pixel.

brett01
04-24-2009, 11:47 AM
Another thing is about object id buffer.Does it contain the cordinates of object space(z value)?? How can color buffer can be used for object id buffer??

ZbuffeR
04-25-2009, 12:33 AM
Imagine first the texture A you want to draw on is 256x256, and that we draw a single texel at a time.
Create a second texture B of the same size, having the addition of 2 color gradients :
- horizontal goes from black to full red (so each column has increasing red component value)
- vertical goes from black to full blue (so each line has increasing blue component value)

Then, drawing a frame will be split in 2 parts :
- clear
- draw object with texture A, the real lighting if needed, etc.
- swapbuffers, clear
- draw same object, with texture B this time, same texcoords (this will never be seen on screen)
- readpixels at the cursor position
- the values you get can be mapped directly to position of the texel to be painted. texcoord s = red component, t = blue

Is that ok so far ?

ZbuffeR
04-25-2009, 12:37 AM
Now, for larger textures :
- you have to take advantage of the 32 bits of a RGBA texture, allowing in theory up to 65000*65000 texture.
- decide on a way to pack the S and T bits among the 4 bytes of RGBA texture
- texture B will have to be drawn with GL_NEAREST filtering to prevent interpolation to get in the way.
- once a pixel RGBA value is read, unpack to S and T values

Reading color buffer :
glReadPixels(x, y, width, height, GL_RGBA,GL_UNSIGNED_INT_8_8_8_8,&colordata);

When using readpixels you can choose to read the depth buffer too :
glReadPixels(x, y, width, height,GL_DEPTH_COMPONENT,GL_FLOAT,&zdata);

brett01
04-25-2009, 11:49 PM
Thank you very much sir.Now i understood it.