Will try and keep this short for once:
In my map editor I wanted to add light mapping, but it seemed rather complex so first I wanted to try out an idea i had for vertex shadowing using raycasting and flipping vertex normals. However I cant make it work, it seems to darken some random parts of my map object in squares and thats about it.
code for shadow mapper and my invert function (which i use to ivnert a normal value):
float InvertFloat(float fFloat, float fRange) {
//number range is always 0~fRange
return fRange - fFloat;
}
void cMap::VertexShadowCompile(int nObj) {
register int nLimb, nV, nL; //limb, vertex, light
int nVc; //vertex count
float fNx, fNy, fNz; //normal x, y, z
float fNxo, fNyo, fNzo; //old normal x, y, z
float fOx, fOy, fOz; //object x, y, z
float fDist; //distance to intersection
float fDistBetween; //distance between vertex and light
bool bShadowed; //has this vertex been shadowed by another light yet
fOx = dbObjectPositionX(nObj);
fOy = dbObjectPositionY(nObj);
fOz = dbObjectPositionZ(nObj);
dbPerformCheckListForObjectLimbs(nObj);
//for each limb
for (nLimb = 1; nLimb <= dbChecklistQuantity(); nLimb++) {
dbLockVertexDataForLimb(nObj, nLimb);
nVc = dbGetVertexDataVertexCount();
//for each vertex
for (nV = 0; nV < nVc; nV++) {
fNxo = dbGetVertexDataNormalsX(nV);
fNyo = dbGetVertexDataNormalsY(nV);
fNzo = dbGetVertexDataNormalsZ(nV);
fNx = fNxo;
fNy = fNyo;
fNz = fNzo;
bShadowed = false;
//for each light
for (nL = 0; nL < nRealEntityCount; nL++) { //not optimal, better to put lights in seperate array
//
if (aEntityInfo[nL].nEntityType == E_LIGHT) { //
//get distance between light and vertex
fDistBetween = Get3dDistance(aEntityInfo[nL].fEntityX, aEntityInfo[nL].fEntityY, aEntityInfo[nL].fEntityZ, fOx + dbGetVertexDataPositionX(nV), fOy + dbGetVertexDataPositionY(nV), fOz + dbGetVertexDataPositionZ(nV));
//cast FROM light TO vertex world coordinate (object + vertex position)
fDist = dbIntersectObject(nObj, aEntityInfo[nL].fEntityX, aEntityInfo[nL].fEntityY, aEntityInfo[nL].fEntityZ, fOx + dbGetVertexDataPositionX(nV), fOy + dbGetVertexDataPositionY(nV), fOz + dbGetVertexDataPositionZ(nV));
if (fDist < fDistBetween) {
//this vert is in the shadow of this light
if (!bShadowed) { //hasnt been shadowed before
fNx = InvertFloat(fNxo, 1.0f);
fNy = InvertFloat(fNyo, 1.0f);
fNz = InvertFloat(fNzo, 1.0f);
bShadowed = true;
} else {
//nvm
}
} else {
//this vert is being lit by this light
if (bShadowed) {
fNx -= 0.05f;
fNy -= 0.05f;
fNz -= 0.05f;
if (fNx < 0.0f) fNx = 0.0f;
if (fNy < 0.0f) fNy = 0.0f;
if (fNz < 0.0f) fNz = 0.0f;
}
}
}
}
if (!bShadowed) {
if (fNx != fNxo) {
fNx = fNxo;
fNy = fNyo;
fNz = fNzo;
}
}
dbSetVertexDataNormals(nV, fNx, fNy, fNz);
}
dbUnlockVertexData();
}
}
Having never read anything about vertex shadowing in this manner I made up the algorithm myself, so it may be flawed. But I am bothered by the fact that when stepping through in the debugger that dbGetVertexDataNormalsY(nV) often seems to return: -3.09086e-008
That cant be good >.>; Any thoughts on this routine and whats wrong?