Z-buffer problem (?)

This is a discussion on Z-buffer problem (?) within the Game Programming forums, part of the General Programming Boards category; I have implemented Z-buffer algorithm but sometimes I get weird results, ie visibility is not solved correctly. My Z-buffer algorithm ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    12

    Z-buffer problem (?)

    I have implemented Z-buffer algorithm but sometimes I get weird results, ie visibility is not solved correctly. My Z-buffer algorithm works like that:

    -------Step 0:
    Initialize Z-buffer with smallest possible negative numbers
    Initialize frame buffer to background colour

    -------Step 1:

    Projection of all polygons to 2D:

    x_2d = x_3d
    y_2d = y_3d

    (ie projection to xy plane, z coordinates are ommited, more in the remarks section)

    ------Step 2 (for each 2d polygon - ie for each projection)

    Scan conversion of the 2d polygon -> for each pixel of that polygon:

    calculate z-value: z=-(a*x2d + b*x2d + d)/ c
    a, b, c, d are taken from the equation of the plane in which the original 3d polygon lies - and a, b, c are coordinates of the 3d polygon's normal (calculated as P1P2 x P1P3 where P1, P2, P3 are vertices of the 3d polygon)

    compare z-buffer w/ z-value, update z-buffer and frame buffer if z-value > z-buffer[x2d, y2d]

    -------Step 3

    Write frame buffer to screen

    IMPORTANT REMARKS:

    1) I am be unable to project polygons to 2d in a different way than by ommiting z-coordinates because the expression for calculating the z-value in Step 2 wouldn't work in different case, I think

    2) Moreover - from the same reason - I am unable to do any transformations and eg. have [0;0] in the middle of the screen

    WELL, FINALLY, HERE ARE MY QUESTIONS:

    Where (on the internet) can I find a complete, accurate, step-by-step description of the z-buffer algorithm, with all the necessary expression, equations etc. and perhaps some sample code in C/C++/Pascal or VB? Everything I have found do far are vague descriptions with weird pseudo-code, there is not a word about when I work with 3d polygon, when with its 2d projection etc. - only John Carmack could understand that))))

    Is anything described in my implementation wrong?

    Thank you very much

  2. #2
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    Hello,
    this might help:
    http://www.cs.buffalo.edu/faculty/wa.../NewLect21.pdf
    http://thorkildsen.no/faqsys/cates/math.html

    A search on google for "Z-buffer AND visibility AND algorithm AND source code" might be helpful
    Last edited by Carlos; 01-28-2003 at 08:01 AM.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    12
    I've just tried your search phrase in Google and I've found this page:

    http://pages.infinit.net/jstlouis/3d...e_removal.html

    This is exactly what I was looking for!

    Thank you!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with float and argv
    By DonFord81 in forum C Programming
    Replies: 5
    Last Post: 03-04-2009, 01:47 PM
  2. Cout redirection problem
    By MrLucky in forum C++ Programming
    Replies: 6
    Last Post: 06-06-2007, 11:11 AM
  3. clear buffer
    By justins in forum C Programming
    Replies: 5
    Last Post: 05-19-2007, 06:16 AM
  4. buffer contents swapping
    By daluu in forum C++ Programming
    Replies: 7
    Last Post: 10-14-2004, 02:34 PM
  5. memory allocation problem....help..
    By CyC|OpS in forum C Programming
    Replies: 8
    Last Post: 10-18-2002, 09:26 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21