• Create Account

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

No replies to this topic

### #1StakFallT  Members   -  Reputation: 308

Like
0Likes
Like

Posted 29 June 2014 - 01:19 PM

Hoping someone here can help me. I've gotten further with implementing shadow volumes based on John Carmack's Doom 3 work. Yes I know about shadow mapping -- basically, to be implemented; one thing at a time...

Here's the paper I'm working off of:

http://fabiensanglard.net/doom3_documentation/37730-293752.pdf

Obviously, I've modified it quite a bit. I've even changed much of it from the C-style to C++ style; something I'm not overly happy about doing (Usually from what I've seen C stuff runs much faster than C++ style code...)... Anyhow to tame the beast a bit, it had to be done; problems with indexing dynamic pointer-style arrays with pointer arithmetic were occurring (Not idea if pointer arithmetic even works on non-guaranteed contiguous memory allocations), way way too many parameters were being passed around from function to function, and when one function might yield 2 more calls deep, tracking the proper pointer-type passings became miserable -- especially since technically I was passing a pointer to a pointer-style dynamic-array (as opposed to something like a vector or map).

Anyhow, I think I narrowed the problem down to the creation of the silhouette. I'm using a simple basic textured cube (2 triangles per face) I exported out of Maya using an exporter I wrote. The cube renders ok, but I'm not seeing the silhouette when I tell the engine to render it. At best I'm able to see a single line shooting way out from one of the cube's points. Even if the windings were correct, even if the created triangle were not closed, I should still see the lines. and I'm not. Here's the function I'm using for generating the silhouette (once the edges have been found and stored that is). Note: Duplicate edges are not stored when the edge list is being generated. Also, the code below is the product of multiple multiple attempts at different methods to try to achieve some kind of indication of vertices being generated properly so not all variables may be being used. Vertex list is the linear form of each face's vertices expanded into the list -- duplicate vertices should be expected.

 unsigned int CreateSilTriangles(cShadowVolume *ShadowVolume, const cMeshVert *VertexList)
{
unsigned int SilIndex = 0;
int i = 0; //Get count of Number of silhouette indices needed...
unsigned int SilIndices = 0;
for (SilIndex = 0, i = ShadowVolume->nEdges - 1; i > -1; i--, SilIndex++)
{
///edge of the model (In other words, it's an "outside" edge or another way of putting
//it -- it's an edge that contributes to the model's silhouette.
//if (f1 != f2)
if ( (f1 > f2) || (f1 < f2) )
SilIndices += 6;
for (SilIndex = 0, i = ShadowVolume->nEdges - 1; i > -1; i--, SilIndex++)
{
//Due to a subtle math-logic issue, the bytes were changed to floats. On a perfectly smooth sphere
//where the geodesics of the surface of a sphere gradually wrap around towards the back -- mathematically,
//this could probably be expressed as, the degree of the surface is expressed as an extremely smooth gradient.
//The problem with this is depending on where the points of a triangle line up, the center of that triangle might
//be on the "tipping" point of facing/not-facing, while the rear-most point of a triangle_1 may be on the
//opposite site of the facing-stradle mark so this -may- create issues in determining facings. Thus when the
//difference between the triangle_1 face and triangle_2 face occur, the math -may- not work out to a
//desirable effect. So a float is used to determine how far off triangle_1 and triangle_2 are from each other,
//and in the future a sensitivity level could be used to allow a triangle to be part of the
//silhouette -- allowing for finer control just as cullbits does.
///edge of the model (In other words, it's an "outside" edge or another way of putting
//it -- it's an edge that contributes to the model's silhouette.
//if (f1 != f2)
if ( (f1 > f2) || (f1 < f2) )
{
unsigned int v2 = ShadowVolume->Edges[SilIndex].v2;   unsigned int V1 = v1;
unsigned int V2 = v2;   unsigned int V1_1 = v1 + 1;
unsigned int V2_1 = v2 + 1;   cVector3 Vec1 = VertexList[ShadowVolume->Edges[SilIndex].v1].Coords;
cVector3 Vec3 = VertexList[ShadowVolume->Edges[SilIndex].v1].Coords; Vec3 = Vec3 * 500.0f;
cVector3 Vec4 = VertexList[ShadowVolume->Edges[SilIndex].v2].Coords; Vec4 = Vec4 * 500.0f;   //"To properly determine the regions in space that are in shadow the vertices
//of the shadow volume triangles must consistently wind counterclockwise so
//that the triangle normals point out of the shadow volume. As such the
//triangle winding orders have to be set based on which of the two triangles
//faces the light source." -- http://fabiensanglard.net/doom3_documentation/37730-293752.pdf
//if (f1)
if (f1 > 0.0f)
{
/** /
si[0] = v1;
si[1] = v2 + 1;
si[2] = v2;
si[3] = v1;
si[4] = v1 + 1;
si[5] = v2 + 1;
/**/
/**/
ShadowVolume->pSilIndices[si_Index + 1] = v2 + 1;
ShadowVolume->pSilIndices[si_Index + 4] = v1 + 1;
ShadowVolume->pSilIndices[si_Index + 5] = v2 + 1;
/**/    /**/
ShadowVolume->pVertices[si_Index + 1] = Vec2 * 500;
ShadowVolume->pVertices[si_Index + 4] = Vec1 * 500;
ShadowVolume->pVertices[si_Index + 5] = Vec2 * 500;
/**/
/** /
/**/
} else
{
/** /
si[0] = v1;
si[1] = v2;
si[2] = v2 + 1;
si[3] = v1 + 1;
si[4] = v1;
si[5] = v2 + 1;
/**/
/**/
ShadowVolume->pSilIndices[si_Index + 2] = v2 + 1;
ShadowVolume->pSilIndices[si_Index + 3] = v1 + 1;
ShadowVolume->pSilIndices[si_Index + 5] = v2 + 1;
/**/    /**/
ShadowVolume->pVertices[si_Index + 2] = Vec2 * 500;
ShadowVolume->pVertices[si_Index + 3] = Vec1 * 500;
ShadowVolume->pVertices[si_Index + 5] = Vec2 * 500;
/**/
/** /
/**/
};
si_Index += 6;
};
};

return si_Index;
}; // End of unsigned int CreateSilTriangles(cShadowVolume *ShadowVolume, const cMeshVert *VertexList)

I know there's a winding problem, but even if I disable culling I still don't see the lines being generated (much less the triangles). So even without the culling being an issue, I'm not even sure the generation method is correct.

Here's part of the generated log by my engine:

[Sun Jun 29 14:05:09 2014] Model's shadow volume-vertex list:

[Sun Jun 29 14:05:09 2014] (0) X: -0.5 Y: 0.5 Z: 0.5 Vertex Index: 35

[Sun Jun 29 14:05:09 2014] (1) X: -0.5 Y: 0.5 Z: 0.5 Vertex Index: 3

[Sun Jun 29 14:05:09 2014] (2) X: 0.5 Y: -0.5 Z: 0.5 Vertex Index: 4

[Sun Jun 29 14:05:09 2014] (3) X: 3.02486104e-034 Y: 0 Z: 0 Vertex Index: 36

[Sun Jun 29 14:05:09 2014] (4) X: -0.5 Y: 0.5 Z: 0.5 Vertex Index: 35

[Sun Jun 29 14:05:09 2014] (5) X: 0.5 Y: -0.5 Z: 0.5 Vertex Index: 4


(and yes I know about the vertex 36 index not being present in the list just below. Like I said though, not even seeing the lines generated from the other 5 points.)

EDIT1 (Begin):

Correction being made. The output log that shows what vertices are being pushed into the vertex buffer is wrong. It was logging based on

ShadowVolume->pVertices[VertIndex].x, y, and z. Here's the corrected output:

[Sun Jun 29 16:52:51 2014] Model's shadow volume-vertex list:
[Sun Jun 29 16:52:51 2014] (0) X: -0.5 Y: 0.5 Z: -0.5
[Sun Jun 29 16:52:51 2014] (1) X: -250 Y: 250 Z: -250
[Sun Jun 29 16:52:51 2014] (2) X: -0.5 Y: 0.5 Z: -0.5
[Sun Jun 29 16:52:51 2014] (3) X: -0.5 Y: 0.5 Z: -0.5
[Sun Jun 29 16:52:51 2014] (4) X: -250 Y: 250 Z: -250
[Sun Jun 29 16:52:51 2014] (5) X: -250 Y: 250 Z: -250

EDIT1 (End)

Here is part of the model file: NOTE: Vertex list is a raw vertex list -- that is, each face's points are expanded into their vertices and placed into this list for each face. Thus, duplicate vertices should be present.

*MESH_VERTEX: 0:-0.5,-0.5,0.5

*MESH_VERTEX: 1:0.5,-0.5,0.5

*MESH_VERTEX: 2:-0.5,0.5,0.5

*MESH_VERTEX: 3:-0.5,0.5,0.5

*MESH_VERTEX: 4:0.5,-0.5,0.5

*MESH_VERTEX: 5:0.5,0.5,0.5

*MESH_VERTEX: 6:-0.5,0.5,0.5

*MESH_VERTEX: 7:0.5,0.5,0.5

*MESH_VERTEX: 8:-0.5,0.5,-0.5

*MESH_VERTEX: 9:-0.5,0.5,-0.5

*MESH_VERTEX: 10:0.5,0.5,0.5

*MESH_VERTEX: 11:0.5,0.5,-0.5

*MESH_VERTEX: 12:-0.5,0.5,-0.5

*MESH_VERTEX: 13:0.5,0.5,-0.5

*MESH_VERTEX: 14:-0.5,-0.5,-0.5

*MESH_VERTEX: 15:-0.5,-0.5,-0.5

*MESH_VERTEX: 16:0.5,0.5,-0.5

*MESH_VERTEX: 17:0.5,-0.5,-0.5

*MESH_VERTEX: 18:-0.5,-0.5,-0.5

*MESH_VERTEX: 19:0.5,-0.5,-0.5

*MESH_VERTEX: 20:-0.5,-0.5,0.5

*MESH_VERTEX: 21:-0.5,-0.5,0.5

*MESH_VERTEX: 22:0.5,-0.5,-0.5

*MESH_VERTEX: 23:0.5,-0.5,0.5

*MESH_VERTEX: 24:0.5,-0.5,0.5

*MESH_VERTEX: 25:0.5,-0.5,-0.5

*MESH_VERTEX: 26:0.5,0.5,0.5

*MESH_VERTEX: 27:0.5,0.5,0.5

*MESH_VERTEX: 28:0.5,-0.5,-0.5

*MESH_VERTEX: 29:0.5,0.5,-0.5

*MESH_VERTEX: 30:-0.5,-0.5,-0.5

*MESH_VERTEX: 31:-0.5,-0.5,0.5

*MESH_VERTEX: 32:-0.5,0.5,-0.5

*MESH_VERTEX: 33:-0.5,0.5,-0.5

*MESH_VERTEX: 34:-0.5,-0.5,0.5

*MESH_VERTEX: 35:-0.5,0.5,0.5


-- StakFallT

UPDATE 1: Ok so I figured out a large portion of the problem was because my edge generation/detection function was not logically sound. I reworked it a bit and this is what I have so far:

unsigned int Generate_ShadowVolume_EdgeArray(cShadowVolume *ShadowVolume, const cMeshVert *VertPosTable, cMeshFace **linearFaces_IN, const unsigned int NumLinearFaces)
{
bool Continue_OuterLoop = true;
//if (nLinearFaces < 1)
// Continue_OuterLoop = false;
int TableIndex = 0;
int TableIndex2 = 1;
std::map<int, cEdge> Temp_Edges;
std::map<int, bool> Edge_Is_Duplicate;
unsigned int Face1 = 0;
unsigned int Face2 = 1;
unsigned int Edge_Index = 0;

//First, build the edge table -- check for redundant edges after.
while (Continue_OuterLoop == true)
{
//Loop through all Faces
bool Continue_InnerLoop = true;
while (Continue_InnerLoop == true)
{
//Loop through all Faces
unsigned int p1_1 = linearFaces_IN[Face1]->Points[0].vertIDX;
unsigned int p1_2 = linearFaces_IN[Face1]->Points[1].vertIDX;
unsigned int p1_3 = linearFaces_IN[Face1]->Points[2].vertIDX;
cVector3 p1_1_Vec3 = VertPosTable[p1_1].Coords;
cVector3 p1_2_Vec3 = VertPosTable[p1_2].Coords;
cVector3 p1_3_Vec3 = VertPosTable[p1_3].Coords;
unsigned int p2_1 = linearFaces_IN[Face2]->Points[0].vertIDX;
unsigned int p2_2 = linearFaces_IN[Face2]->Points[1].vertIDX;
unsigned int p2_3 = linearFaces_IN[Face2]->Points[2].vertIDX;
cVector3 p2_1_Vec3 = VertPosTable[p2_1].Coords;
cVector3 p2_2_Vec3 = VertPosTable[p2_2].Coords;
cVector3 p2_3_Vec3 = VertPosTable[p2_3].Coords;
unsigned int v1;
unsigned int v2;
bool Common_Edge_Found = false;
if ( (p1_1_Vec3 == p2_1_Vec3) && (p1_2_Vec3 == p2_2_Vec3) )
{
v1 = p1_1;
v2 = p1_2;
Common_Edge_Found = true;
} else if ( (p1_2_Vec3 == p2_1_Vec3) && (p1_1_Vec3 == p2_2_Vec3) )
{
v1 = p1_2;
v2 = p1_1;
Common_Edge_Found = true;
} else if ( (p1_2_Vec3 == p2_2_Vec3) && (p1_3_Vec3 == p2_3_Vec3) )
{
v1 = p1_2;
v2 = p1_3;
Common_Edge_Found = true;
} else if ( (p1_3_Vec3 == p2_2_Vec3) && (p1_2_Vec3 == p2_3_Vec3) )
{
v1 = p1_3;
v2 = p1_2;
Common_Edge_Found = true;
} else if ( (p1_3_Vec3 == p2_3_Vec3) && (p1_1_Vec3 == p2_1_Vec3) )
{
v1 = p1_3;
v2 = p1_1;
Common_Edge_Found = true;
} else if ( (p1_1_Vec3 == p2_3_Vec3) && (p1_3_Vec3 == p2_1_Vec3) )
{
v1 = p1_1;
v2 = p1_3;
Common_Edge_Found = true;
};
if (Common_Edge_Found == true)
{
Temp_Edges[Edge_Index].FaceA = linearFaces_IN[Face1];
Temp_Edges[Edge_Index].FaceB = linearFaces_IN[Face2];
Temp_Edges[Edge_Index].p1  = Face1;
Temp_Edges[Edge_Index].p2  = Face2;
Temp_Edges[Edge_Index].v1  = v1;
Temp_Edges[Edge_Index].v2  = v2;
Edge_Index += 1;
Continue_InnerLoop = false;
} else
{
Face2 += 1;
if (Face2 >= NumLinearFaces)
Continue_InnerLoop = false;
else
{
if (Face2 == Face1)
{
Face2 += 1;
if (Face2 >= NumLinearFaces)
{
Continue_OuterLoop = false;
Continue_InnerLoop = false;
};
};
};
};
}; //while (Continue_InnerLoop == true)
Face1 += 1;
if (Face1 >= NumLinearFaces)
Continue_OuterLoop = false;
else
{
Face2 = Face1 + 1;
if (Face2 >= NumLinearFaces)
{
Continue_OuterLoop = false;
Continue_InnerLoop = false;
};
};
}; //while (Continue_OuterLoop == true)

//Initialize Duplicate Flags Array
for (int i = 0; i < Temp_Edges.size(); i++)
Edge_Is_Duplicate[i] = false;
//Now check for duplicate edge entries and mark them accordingly...
bool Continue_DuplicateCheck = true;
int RunningIndex = 0; //Unaffected by conditionals
int Edge1 = 0;
int Edge2 = 1;
int p1_1, p1_2 = -1;
int p2_1, p2_2 = -1;

Continue_OuterLoop = true;
while (Continue_OuterLoop == true)
{
//Run through all the edges.
p1_1 = Temp_Edges[Edge1].p1;
p1_2 = Temp_Edges[Edge1].p2;
bool Continue_InnerLoop = true;
while (Continue_InnerLoop == true)
{
//Check if this edge is a duplicate.
p2_1 = Temp_Edges[Edge2].p1;
p2_2 = Temp_Edges[Edge2].p2;
if ( (((p1_1 == p2_1) || (p1_1 == p2_2)) &&
((p1_2 == p2_2) || (p1_2 == p2_1))) ||
((p1_1 == p2_1) && (p1_2 == p2_2)) )
Edge_Is_Duplicate[Edge2] = true;
Edge2 += 1;
if (Edge2 >= Temp_Edges.size())
Continue_InnerLoop = false;
else
{
if (Edge2 == Edge1)
{
Edge2 += 1;
if (Edge2 >= Temp_Edges.size())
{
Continue_OuterLoop = false;
Continue_InnerLoop = false;
};
};
};
};
Edge1 += 1;
if (Edge1 >= Temp_Edges.size())
Continue_OuterLoop = false;
else
{
Edge2 = Edge1 + 1;
if (Edge2 >= Temp_Edges.size())
{
Continue_OuterLoop = false;
Continue_InnerLoop = false;
};
};
}; // while (Continue_OuterLoop == true)
//Get a count of how many edge slots will actually be needed.
unsigned int nUnique_Edges = 0;
unsigned int Tmp_Edge_Index = 0;
bool ContinueLoop = true;
while (ContinueLoop == true)
{
if (Edge_Is_Duplicate[Tmp_Edge_Index] == false)
nUnique_Edges += 1;
Tmp_Edge_Index += 1;
if (Tmp_Edge_Index >= Temp_Edges.size())
ContinueLoop = false;
};

Edge_Index = 0;
Tmp_Edge_Index = 0;
ContinueLoop = true;
while (ContinueLoop == true)
{
if (Edge_Is_Duplicate[Tmp_Edge_Index] == false)
{
Edge_Index += 1;
Tmp_Edge_Index += 1;
if (Tmp_Edge_Index >= Temp_Edges.size())
ContinueLoop = false;
} else
{
Tmp_Edge_Index += 1;
if (Tmp_Edge_Index >= Temp_Edges.size())
ContinueLoop = false;
};
};
//Edge_Index is not -1'd because Edge_Index starts at 0 and only increments after an edge has been added.
};


problem is, it's the shadow volume is still off. Here's a couple of screenshots.

For reference, here's the raw vert positions being pushed into the vertex buffer:

[Sun Jun 29 19:27:58 2014] Model's shadow volume-vertex list:
[Sun Jun 29 19:27:58 2014] (0) X: 0.5 Y: -0.5 Z: 0.5
[Sun Jun 29 19:27:58 2014] (1) X: -0.5 Y: 0.5 Z: 0.5
[Sun Jun 29 19:27:58 2014] (2) X: -1 Y: 1 Z: 1
[Sun Jun 29 19:27:58 2014] (3) X: 1 Y: -1 Z: 1
[Sun Jun 29 19:27:58 2014] (4) X: 0.5 Y: -0.5 Z: 0.5
[Sun Jun 29 19:27:58 2014] (5) X: -1 Y: 1 Z: 1
[Sun Jun 29 19:27:58 2014] (6) X: 0.5 Y: 0.5 Z: 0.5
[Sun Jun 29 19:27:58 2014] (7) X: -0.5 Y: 0.5 Z: -0.5
[Sun Jun 29 19:27:58 2014] (8) X: -1 Y: 1 Z: -1
[Sun Jun 29 19:27:58 2014] (9) X: 1 Y: 1 Z: 1
[Sun Jun 29 19:27:58 2014] (10) X: 0.5 Y: 0.5 Z: 0.5
[Sun Jun 29 19:27:58 2014] (11) X: -1 Y: 1 Z: -1
[Sun Jun 29 19:27:58 2014] (12) X: 0.5 Y: 0.5 Z: -0.5
[Sun Jun 29 19:27:58 2014] (13) X: -1 Y: -1 Z: -1
[Sun Jun 29 19:27:58 2014] (14) X: -0.5 Y: -0.5 Z: -0.5
[Sun Jun 29 19:27:58 2014] (15) X: 0.5 Y: 0.5 Z: -0.5
[Sun Jun 29 19:27:58 2014] (16) X: 1 Y: 1 Z: -1
[Sun Jun 29 19:27:58 2014] (17) X: -1 Y: -1 Z: -1
[Sun Jun 29 19:27:58 2014] (18) X: 0.5 Y: 0.5 Z: -0.5
[Sun Jun 29 19:27:58 2014] (19) X: 0.5 Y: -0.5 Z: -0.5
[Sun Jun 29 19:27:58 2014] (20) X: 1 Y: -1 Z: -1
[Sun Jun 29 19:27:58 2014] (21) X: 1 Y: 1 Z: -1
[Sun Jun 29 19:27:58 2014] (22) X: 0.5 Y: 0.5 Z: -0.5
[Sun Jun 29 19:27:58 2014] (23) X: 1 Y: -1 Z: -1
[Sun Jun 29 19:27:58 2014] (24) X: 0.5 Y: -0.5 Z: -0.5
[Sun Jun 29 19:27:58 2014] (25) X: -1 Y: -1 Z: 1
[Sun Jun 29 19:27:58 2014] (26) X: -0.5 Y: -0.5 Z: 0.5
[Sun Jun 29 19:27:58 2014] (27) X: 0.5 Y: -0.5 Z: -0.5
[Sun Jun 29 19:27:58 2014] (28) X: 1 Y: -1 Z: -1
[Sun Jun 29 19:27:58 2014] (29) X: -1 Y: -1 Z: 1
[Sun Jun 29 19:27:58 2014] (30) X: 0.5 Y: -0.5 Z: 0.5
[Sun Jun 29 19:27:58 2014] (31) X: 0.5 Y: -0.5 Z: -0.5
[Sun Jun 29 19:27:58 2014] (32) X: 1 Y: -1 Z: -1
[Sun Jun 29 19:27:58 2014] (33) X: 1 Y: -1 Z: 1
[Sun Jun 29 19:27:58 2014] (34) X: 0.5 Y: -0.5 Z: 0.5
[Sun Jun 29 19:27:58 2014] (35) X: 1 Y: -1 Z: -1
[Sun Jun 29 19:27:58 2014] (36) X: 0.5 Y: -0.5 Z: -0.5
[Sun Jun 29 19:27:58 2014] (37) X: 1 Y: 1 Z: 1
[Sun Jun 29 19:27:58 2014] (38) X: 0.5 Y: 0.5 Z: 0.5
[Sun Jun 29 19:27:58 2014] (39) X: 0.5 Y: -0.5 Z: -0.5
[Sun Jun 29 19:27:58 2014] (40) X: 1 Y: -1 Z: -1
[Sun Jun 29 19:27:58 2014] (41) X: 1 Y: 1 Z: 1
[Sun Jun 29 19:27:58 2014] (42) X: -0.5 Y: -0.5 Z: 0.5
[Sun Jun 29 19:27:58 2014] (43) X: -0.5 Y: 0.5 Z: -0.5
[Sun Jun 29 19:27:58 2014] (44) X: -1 Y: 1 Z: -1
[Sun Jun 29 19:27:58 2014] (45) X: -1 Y: -1 Z: 1
[Sun Jun 29 19:27:58 2014] (46) X: -0.5 Y: -0.5 Z: 0.5
[Sun Jun 29 19:27:58 2014] (47) X: -1 Y: 1 Z: -1


I'm thinking it's got something to do with the silhouette generation which was posted above, only I made the change of instead of the vectors being multiplied by 500, I brought it down to 2.0f.

Edited by StakFallT, 29 June 2014 - 05:52 PM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS