|
|
|
@ -147,7 +147,7 @@ std::unordered_map<const edge_t*, EdgeData> analyze_edges(const world_t* world) |
|
|
|
const plane_t* planeB = &world->planes[faceB->plane_id]; |
|
|
|
vec3_t normalA = faceA->side ? -planeA->normal : planeA->normal; |
|
|
|
vec3_t normalB = faceB->side ? -planeB->normal : planeB->normal; |
|
|
|
float dot = dotProduct(planeA->normal, planeB->normal); |
|
|
|
float dot = dotProduct(normalA, normalB); |
|
|
|
bool isSmooth = dot >= 0.5f;//&& dot <= 1;
|
|
|
|
iter->second.isSharpEdge = !isSmooth; |
|
|
|
break; |
|
|
|
@ -161,7 +161,7 @@ std::unordered_map<const edge_t*, EdgeData> analyze_edges(const world_t* world) |
|
|
|
return edgeData; |
|
|
|
} |
|
|
|
|
|
|
|
unsigned char compute_faceVertex_light(const world_t* world, const face_t* face, unsigned short vertexIndex, const std::unordered_map<const face_t*, BoundBox> faceBounds, const std::unordered_map<const edge_t*, EdgeData>& edgeData) |
|
|
|
unsigned char compute_faceVertex_light(const world_t* world, const face_t* face, unsigned short vertexIndex, const FaceBounds& faceBounds, const std::unordered_map<const edge_t*, EdgeData>& edgeData) |
|
|
|
{ |
|
|
|
const vertex_t* vertex = &world->vertices[vertexIndex]; |
|
|
|
auto point = vertex->toVec(); |
|
|
|
@ -212,3 +212,40 @@ unsigned char compute_faceVertex_light(const world_t* world, const face_t* face, |
|
|
|
|
|
|
|
return (unsigned char)(light / numSamples); |
|
|
|
} |
|
|
|
|
|
|
|
unsigned char compute_faceVertex_light2(const world_t* world, const face_t* face, unsigned short vertexIndex, const FaceBounds& faceBounds, const VertexFaces& vertexFaces) |
|
|
|
{ |
|
|
|
const vertex_t* vertex = &world->vertices[vertexIndex]; |
|
|
|
auto vertexFaceIter = vertexFaces.find(vertex); |
|
|
|
if (vertexFaceIter == vertexFaces.end()) |
|
|
|
return 0; |
|
|
|
|
|
|
|
auto point = vertex->toVec(); |
|
|
|
|
|
|
|
// Sample this face's lighting contribution
|
|
|
|
unsigned int light = sample_lightmap(world, face, faceBounds.find(face)->second, point) + (0xFF - face->baselight); |
|
|
|
int numSamples = 1; |
|
|
|
|
|
|
|
const plane_t* thisPlane = &world->planes[face->plane_id]; |
|
|
|
vec3_t thisNormal = face->side ? -thisPlane->normal : thisPlane->normal; |
|
|
|
|
|
|
|
// Gather light samples from other faces adjacent to this vertex
|
|
|
|
for (auto faceIter = vertexFaceIter->second.begin(); faceIter != vertexFaceIter->second.end(); ++faceIter) |
|
|
|
{ |
|
|
|
const face_t* otherFace = *faceIter; |
|
|
|
if (otherFace == face) |
|
|
|
continue; |
|
|
|
|
|
|
|
const plane_t* otherPlane = &world->planes[otherFace->plane_id]; |
|
|
|
vec3_t otherNormal = otherFace->side ? -otherPlane->normal : otherPlane->normal; |
|
|
|
|
|
|
|
float dot = dotProduct(thisNormal, otherNormal); |
|
|
|
if (dot < 0.5f) |
|
|
|
continue; // Sharp edge, we don't want light contribution from this face
|
|
|
|
|
|
|
|
light += sample_lightmap(world, otherFace, faceBounds.find(otherFace)->second, point) + (0xFF - otherFace->baselight); |
|
|
|
++numSamples; |
|
|
|
} |
|
|
|
|
|
|
|
return (unsigned char)(light / numSamples); |
|
|
|
} |