|
|
@@ -72,159 +72,12 @@ void Renderer::clearLights() {
|
|
|
lights.clear();
|
|
|
areaLights.clear();
|
|
|
spotLights.clear();
|
|
|
-// shadowMapTextures.clear();
|
|
|
}
|
|
|
-/*
|
|
|
-void Renderer::addShadowMap(Texture *texture) {
|
|
|
- shadowMapTextures.push_back(texture);
|
|
|
-}
|
|
|
-*/
|
|
|
+
|
|
|
void Renderer::setExposureLevel(Number level) {
|
|
|
exposureLevel = level;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-bool Renderer::test2DCoordinateInPolygon(Number x, Number y, Polycode::Polygon *poly, const Matrix4 &matrix, bool ortho, bool testBackfacing, bool billboardMode, bool reverseDirection, Matrix4 *adjustMatrix) {
|
|
|
-
|
|
|
- Vector3 dirVec;
|
|
|
- Vector3 origin;
|
|
|
-
|
|
|
- if(ortho) {
|
|
|
- origin = Vector3(((x/(Number)xRes)*orthoSizeX) - (orthoSizeX*0.5), (((yRes-y)/(Number)yRes)*orthoSizeY) - (orthoSizeY*0.5), 0.0);
|
|
|
- origin = cameraMatrix * origin;
|
|
|
-
|
|
|
- dirVec = Vector3(0.0, 0.0, -1.0);
|
|
|
- dirVec = cameraMatrix.rotateVector(dirVec);
|
|
|
- } else {
|
|
|
- dirVec = projectRayFrom2DCoordinate(x, y);
|
|
|
- origin = cameraMatrix.getPosition();
|
|
|
- }
|
|
|
-
|
|
|
- Vector3 hitPoint;
|
|
|
-
|
|
|
- Matrix4 fullMatrix = matrix;
|
|
|
-
|
|
|
- if(billboardMode) {
|
|
|
- Matrix4 camInverse = cameraMatrix.Inverse();
|
|
|
- fullMatrix = fullMatrix * camInverse;
|
|
|
-
|
|
|
- fullMatrix.m[0][0] = 1;
|
|
|
- fullMatrix.m[0][1] = 0;
|
|
|
- fullMatrix.m[0][2] = 0;
|
|
|
-
|
|
|
- fullMatrix.m[1][0] = 0;
|
|
|
- fullMatrix.m[1][1] = 1;
|
|
|
- fullMatrix.m[1][2] = 0;
|
|
|
-
|
|
|
- fullMatrix.m[2][0] = 0;
|
|
|
- fullMatrix.m[2][1] = 0;
|
|
|
- fullMatrix.m[2][2] = 1;
|
|
|
-
|
|
|
- origin = camInverse * origin;
|
|
|
- dirVec = camInverse.rotateVector(dirVec);
|
|
|
- }
|
|
|
-
|
|
|
- if(adjustMatrix) {
|
|
|
- fullMatrix = (*adjustMatrix) * fullMatrix;
|
|
|
- }
|
|
|
-
|
|
|
- bool retStatus = false;
|
|
|
-
|
|
|
-
|
|
|
- if(poly->getVertexCount() == 3) {
|
|
|
-
|
|
|
- if(reverseDirection) {
|
|
|
- retStatus = rayTriangleIntersect(origin, dirVec, fullMatrix * (*poly->getVertex(2)), fullMatrix * (*poly->getVertex(1)), fullMatrix * (*poly->getVertex(0)), &hitPoint);
|
|
|
- if(testBackfacing && !retStatus) {
|
|
|
- retStatus = rayTriangleIntersect(origin, dirVec, fullMatrix * (*poly->getVertex(0)), fullMatrix * (*poly->getVertex(1)), fullMatrix * (*poly->getVertex(2)), &hitPoint);
|
|
|
-
|
|
|
- }
|
|
|
- } else {
|
|
|
- retStatus = rayTriangleIntersect(origin, dirVec, fullMatrix * (*poly->getVertex(0)), fullMatrix * (*poly->getVertex(1)), fullMatrix * (*poly->getVertex(2)), &hitPoint);
|
|
|
- if(testBackfacing && !retStatus) {
|
|
|
- retStatus = rayTriangleIntersect(origin, dirVec, fullMatrix * (*poly->getVertex(2)), fullMatrix * (*poly->getVertex(1)), fullMatrix * (*poly->getVertex(0)), &hitPoint);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- } else if(poly->getVertexCount() == 4) {
|
|
|
-
|
|
|
- if(reverseDirection) {
|
|
|
-
|
|
|
- retStatus = (rayTriangleIntersect(origin, dirVec, fullMatrix * (*poly->getVertex(0)), fullMatrix * (*poly->getVertex(1)), fullMatrix * (*poly->getVertex(2)), &hitPoint) ||
|
|
|
- rayTriangleIntersect(origin, dirVec, fullMatrix * (*poly->getVertex(2)), fullMatrix * (*poly->getVertex(3)), fullMatrix * (*poly->getVertex(0)), &hitPoint));
|
|
|
- if(testBackfacing && !retStatus) {
|
|
|
- retStatus = (rayTriangleIntersect(origin, dirVec, fullMatrix * (*poly->getVertex(2)), fullMatrix * (*poly->getVertex(1)), fullMatrix * (*poly->getVertex(0)), &hitPoint) ||
|
|
|
- rayTriangleIntersect(origin, dirVec, fullMatrix * (*poly->getVertex(0)), fullMatrix * (*poly->getVertex(3)), fullMatrix * (*poly->getVertex(2)), &hitPoint));
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- retStatus = (rayTriangleIntersect(origin, dirVec, fullMatrix * (*poly->getVertex(2)), fullMatrix * (*poly->getVertex(1)), fullMatrix * (*poly->getVertex(0)), &hitPoint) ||
|
|
|
- rayTriangleIntersect(origin, dirVec, fullMatrix * (*poly->getVertex(0)), fullMatrix * (*poly->getVertex(3)), fullMatrix * (*poly->getVertex(2)), &hitPoint));
|
|
|
- if(testBackfacing && !retStatus) {
|
|
|
- retStatus = (rayTriangleIntersect(origin, dirVec, fullMatrix * (*poly->getVertex(0)), fullMatrix * (*poly->getVertex(1)), fullMatrix * (*poly->getVertex(2)), &hitPoint) ||
|
|
|
- rayTriangleIntersect(origin, dirVec, fullMatrix * (*poly->getVertex(2)), fullMatrix * (*poly->getVertex(3)), fullMatrix * (*poly->getVertex(0)), &hitPoint));
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- } else {
|
|
|
- retStatus = false;
|
|
|
- }
|
|
|
-
|
|
|
- return retStatus;
|
|
|
-}
|
|
|
-
|
|
|
-bool Renderer::rayTriangleIntersect(Vector3 ray_origin, Vector3 ray_direction, Vector3 vert0, Vector3 vert1, Vector3 vert2, Vector3 *hitPoint)
|
|
|
-{
|
|
|
-
|
|
|
-// printf("TESTING RAY\nORIGIN: %f,%f,%f\nDIR: %f,%f,%f\nVERT0: %f,%f,%f\nnVERT1: %f,%f,%f\nnVERT2: %f,%f,%f\n", ray_origin.x, ray_origin.y, ray_origin.z, ray_direction.x, ray_direction.y, ray_direction.z, vert0.x, vert0.y, vert0.z, vert1.x, vert1.y, vert1.z, vert2.x, vert2.y, vert2.z);
|
|
|
-
|
|
|
-
|
|
|
- Number t,u,v;
|
|
|
- t = 0; u = 0; v = 0;
|
|
|
-
|
|
|
- Vector3 edge1 = vert1 - vert0;
|
|
|
- Vector3 edge2 = vert2 - vert0;
|
|
|
-
|
|
|
- Vector3 tvec, pvec, qvec;
|
|
|
- Number det, inv_det;
|
|
|
-
|
|
|
-
|
|
|
- pvec = ray_direction.crossProduct(edge2);
|
|
|
- det = edge1.dot(pvec);
|
|
|
-
|
|
|
- if (det > -0.00001f)
|
|
|
- return false;
|
|
|
-
|
|
|
- inv_det = 1.0f / det;
|
|
|
-
|
|
|
- tvec = ray_origin - vert0;
|
|
|
-
|
|
|
- u = tvec.dot(pvec) * inv_det;
|
|
|
- if (u < -0.001f || u > 1.001f)
|
|
|
- return false;
|
|
|
-
|
|
|
- qvec = tvec.crossProduct(edge1);
|
|
|
-
|
|
|
- v = ray_direction.dot(qvec) * inv_det;
|
|
|
- if (v < -0.001f || u + v > 1.001f)
|
|
|
- return false;
|
|
|
-
|
|
|
- t = edge2.dot(qvec) * inv_det;
|
|
|
-
|
|
|
- if (t <= 0)
|
|
|
- return false;
|
|
|
-
|
|
|
- hitPoint->x = ray_origin.x+t*ray_direction.x;
|
|
|
- hitPoint->y = ray_origin.y+t*ray_direction.y;
|
|
|
- hitPoint->z = ray_origin.z+t*ray_direction.z;
|
|
|
-
|
|
|
- return true;
|
|
|
-}
|
|
|
-
|
|
|
void Renderer::addShaderModule(PolycodeShaderModule *module) {
|
|
|
shaderModules.push_back(module);
|
|
|
}
|