XNA Creators Club Online
Page 1 of 1 (2 items)
Sort Posts: Previous Next

Backface Culling Problem

Last post 05/11/2009 2:21 AM by OuchGames. 1 replies.
  • 05/11/2009 12:43 AM

    Backface Culling Problem

    Hello there, I'm trying to create a terrain. I have the vertices stored in a vertex buffer, and I'm trying to fill an array with the indices. I understand the indices should be ordered so that the vertices are drawn clockwise so they aren't to be culled... Here is my method for filling the index array:

                private int[] GetIndices(int sizex, int sizey) 
                { 
     
                    int current_index = 0; 
                    int current_quad = 0; 
     
                    int topLeft, topRight, bottomLeft, bottomRight; 
     
                    int[] indices; 
     
                    indices = new int[(sizex - 1) * (sizey - 1) * 6]; 
     
                   for (int y = 0; y < sizey - 1; y++) 
                    { 
                        for (int x = 0; x < sizex - 1; x++) 
     
                        { 
                            topLeft = current_quad; 
                            topRight = current_quad + 1; 
                            bottomLeft = current_quad + sizex; 
                            bottomRight = current_quad + sizex + 1; 
     
                            indices[current_index++] = topLeft; 
                            indices[current_index++] = topRight; 
                            indices[current_index++] = bottomLeft; 
     
                            indices[current_index++] = topRight; 
                            indices[current_index++] = bottomRight; 
                            indices[current_index++] = bottomLeft; 
     
                            current_quad++; 
                        } 
                    } 
     
                    return indices; 
                } 

    It works great when the camera is positioned above the terrain looking down on it (like you normally would be). However when you move the camera below it, instead of all of the primitives being culled as they should... the outline box and some lines are left. Here's a screenshot of the camera above and below the terrain:

    Terrain Image

    Does anyone have an idea of why everything isn't being culled when looking from underneath?

    Thanks!

  • 05/11/2009 2:21 AM In reply to

    Re: Backface Culling Problem

    Answer
    Reply Quote
    You have to watch the case when the quad wraps around from right to left. On a 4x4 grid, the last quad on the first row has indices (2, 3, 6, 7) and the next quad should have (4, 5, 8, 9). In your case it instead has (3, 4, 7, 8), making a degenerate quad and that odd looking image you get. Sorry I don't have a picture but try drawing it if it's unclear.
    Buy Tank-tastic! here
Page 1 of 1 (2 items) Previous Next