[Scummvm-git-logs] scummvm master -> a3c99a3e1b89054cbbf36cbd7d82d02dd57d9a43

aquadran aquadran at gmail.com
Tue Oct 19 19:19:20 UTC 2021


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
a3c99a3e1b STARK: Move lights pre-calculation to top of lights setup


Commit: a3c99a3e1b89054cbbf36cbd7d82d02dd57d9a43
    https://github.com/scummvm/scummvm/commit/a3c99a3e1b89054cbbf36cbd7d82d02dd57d9a43
Author: Paweł Kołodziejski (aquadran at gmail.com)
Date: 2021-10-19T21:18:33+02:00

Commit Message:
STARK: Move lights pre-calculation to top of lights setup

Changed paths:
    engines/stark/gfx/openglactor.cpp
    engines/stark/gfx/openglprop.cpp
    engines/stark/gfx/renderentry.h
    engines/stark/resources/location.cpp


diff --git a/engines/stark/gfx/openglactor.cpp b/engines/stark/gfx/openglactor.cpp
index 9eec6a2afc..9002aab9f6 100644
--- a/engines/stark/gfx/openglactor.cpp
+++ b/engines/stark/gfx/openglactor.cpp
@@ -47,8 +47,6 @@ OpenGLActorRenderer::~OpenGLActorRenderer() {
 }
 
 void OpenGLActorRenderer::render(const Math::Vector3d &position, float direction, const LightEntryArray &lights) {
-	static const uint maxLights = 10;
-
 	if (_modelIsDirty) {
 		clearVertices();
 		uploadVertices();
@@ -103,24 +101,6 @@ void OpenGLActorRenderer::render(const Math::Vector3d &position, float direction
 		lightDirection = getShadowLightDirection(lights, position, modelInverse.getRotation());
 	}
 
-	Math::Vector4d worldPosition[maxLights];
-	Math::Vector4d lightEyePosition[maxLights];
-	Math::Vector3d lightEyeDirection[maxLights];
-	if (_gfx->computeLightsEnabled()) {
-		for (uint li = 0; li < lights.size() - 1; li++) {
-			const LightEntry *l = lights[li + 1];
-
-			worldPosition[li].x() = l->position.x();
-			worldPosition[li].y() = l->position.y();
-			worldPosition[li].z() = l->position.z();
-			worldPosition[li].w() = 1.0f;
-
-			lightEyePosition[li] = view * worldPosition[li];
-			lightEyeDirection[li] = view.getRotation() * l->direction;
-			lightEyeDirection[li].normalize();
-		}
-	}
-
 	glEnable(GL_TEXTURE_2D);
 
 	Common::Array<Face *> faces = _model->getFaces();
@@ -214,6 +194,8 @@ void OpenGLActorRenderer::render(const Math::Vector3d &position, float direction
 			}
 
 			if (_gfx->computeLightsEnabled()) {
+				static const uint maxLights = 10;
+
 				assert(lights.size() >= 1);
 				assert(lights.size() <= maxLights);
 
@@ -227,7 +209,7 @@ void OpenGLActorRenderer::render(const Math::Vector3d &position, float direction
 
 					switch (l->type) {
 						case LightEntry::kPoint: {
-							Math::Vector3d vertexToLight = lightEyePosition[li].getXYZ() - modelEyePosition.getXYZ();
+							Math::Vector3d vertexToLight = l->eyePosition.getXYZ() - modelEyePosition.getXYZ();
 
 							float dist = vertexToLight.length();
 							vertexToLight.normalize();
@@ -237,12 +219,12 @@ void OpenGLActorRenderer::render(const Math::Vector3d &position, float direction
 							break;
 						}
 						case LightEntry::kDirectional: {
-							float incidence = MAX(0.0f, Math::Vector3d::dotProduct(modelEyeNormal, -lightEyeDirection[li]));
+							float incidence = MAX(0.0f, Math::Vector3d::dotProduct(modelEyeNormal, -l->eyeDirection));
 							lightColor += (l->color * incidence);
 							break;
 						}
 						case LightEntry::kSpot: {
-							Math::Vector3d vertexToLight = lightEyePosition[li].getXYZ() - modelEyePosition.getXYZ();
+							Math::Vector3d vertexToLight = l->eyePosition.getXYZ() - modelEyePosition.getXYZ();
 
 							float dist = vertexToLight.length();
 							float attn = CLIP((l->falloffFar - dist) / MAX(0.001f, l->falloffFar - l->falloffNear), 0.0f, 1.0f);
@@ -250,7 +232,7 @@ void OpenGLActorRenderer::render(const Math::Vector3d &position, float direction
 							vertexToLight.normalize();
 							float incidence = MAX(0.0f, modelEyeNormal.dotProduct(vertexToLight));
 
-							float cosAngle = MAX(0.0f, vertexToLight.dotProduct(-lightEyeDirection[li]));
+							float cosAngle = MAX(0.0f, vertexToLight.dotProduct(-l->eyeDirection));
 							float cone = CLIP((cosAngle - l->innerConeAngle.getCosine()) / MAX(0.001f, l->outerConeAngle.getCosine() - l->innerConeAngle.getCosine()), 0.0f, 1.0f);
 
 							lightColor += l->color * attn * incidence * cone;
diff --git a/engines/stark/gfx/openglprop.cpp b/engines/stark/gfx/openglprop.cpp
index 74dc556a2f..fd579a358f 100644
--- a/engines/stark/gfx/openglprop.cpp
+++ b/engines/stark/gfx/openglprop.cpp
@@ -44,8 +44,6 @@ OpenGLPropRenderer::~OpenGLPropRenderer() {
 }
 
 void OpenGLPropRenderer::render(const Math::Vector3d &position, float direction, const LightEntryArray &lights) {
-	static const uint maxLights = 10;
-
 	if (_modelIsDirty) {
 		clearVertices();
 		uploadVertices();
@@ -79,24 +77,6 @@ void OpenGLPropRenderer::render(const Math::Vector3d &position, float direction,
 		normalMatrix.invertAffineOrthonormal();
 	}
 
-	Math::Vector4d worldPosition[maxLights];
-	Math::Vector4d lightEyePosition[maxLights];
-	Math::Vector3d lightEyeDirection[maxLights];
-	if (_gfx->computeLightsEnabled()) {
-		for (uint li = 0; li < lights.size() - 1; li++) {
-			const LightEntry *l = lights[li + 1];
-
-			worldPosition[li].x() = l->position.x();
-			worldPosition[li].y() = l->position.y();
-			worldPosition[li].z() = l->position.z();
-			worldPosition[li].w() = 1.0f;
-
-			lightEyePosition[li] = view * worldPosition[li];
-			lightEyeDirection[li] = view.getRotation() * l->direction;
-			lightEyeDirection[li].normalize();
-		}
-	}
-
 	const Common::Array<Face> &faces = _model->getFaces();
 	const Common::Array<Material> &materials = _model->getMaterials();
 
@@ -143,6 +123,8 @@ void OpenGLPropRenderer::render(const Math::Vector3d &position, float direction,
 				Math::Vector3d modelEyeNormal = normalMatrix.getRotation() *  Math::Vector3d(vertex.nx, vertex.ny, vertex.nz);
 				modelEyeNormal.normalize();
 
+				static const uint maxLights = 10;
+
 				assert(lights.size() >= 1);
 				assert(lights.size() <= maxLights);
 
@@ -156,7 +138,7 @@ void OpenGLPropRenderer::render(const Math::Vector3d &position, float direction,
 
 					switch (l->type) {
 						case LightEntry::kPoint: {
-							Math::Vector3d vertexToLight = lightEyePosition[li].getXYZ() - modelEyePosition.getXYZ();
+							Math::Vector3d vertexToLight = l->eyePosition.getXYZ() - modelEyePosition.getXYZ();
 
 							float dist = vertexToLight.length();
 							vertexToLight.normalize();
@@ -166,12 +148,12 @@ void OpenGLPropRenderer::render(const Math::Vector3d &position, float direction,
 							break;
 						}
 						case LightEntry::kDirectional: {
-							float incidence = MAX(0.0f, Math::Vector3d::dotProduct(modelEyeNormal, -lightEyeDirection[li]));
+							float incidence = MAX(0.0f, Math::Vector3d::dotProduct(modelEyeNormal, -l->eyeDirection));
 							lightColor += (l->color * incidence);
 							break;
 						}
 						case LightEntry::kSpot: {
-							Math::Vector3d vertexToLight = lightEyePosition[li].getXYZ() - modelEyePosition.getXYZ();
+							Math::Vector3d vertexToLight = l->eyePosition.getXYZ() - modelEyePosition.getXYZ();
 
 							float dist = vertexToLight.length();
 							float attn = CLIP((l->falloffFar - dist) / MAX(0.001f, l->falloffFar - l->falloffNear), 0.0f, 1.0f);
@@ -179,7 +161,7 @@ void OpenGLPropRenderer::render(const Math::Vector3d &position, float direction,
 							vertexToLight.normalize();
 							float incidence = MAX(0.0f, modelEyeNormal.dotProduct(vertexToLight));
 
-							float cosAngle = MAX(0.0f, vertexToLight.dotProduct(-lightEyeDirection[li]));
+							float cosAngle = MAX(0.0f, vertexToLight.dotProduct(-l->eyeDirection));
 							float cone = CLIP((cosAngle - l->innerConeAngle.getCosine()) / MAX(0.001f, l->outerConeAngle.getCosine() - l->innerConeAngle.getCosine()), 0.0f, 1.0f);
 
 							lightColor += l->color * attn * incidence * cone;
diff --git a/engines/stark/gfx/renderentry.h b/engines/stark/gfx/renderentry.h
index a400209760..c5f5593f64 100644
--- a/engines/stark/gfx/renderentry.h
+++ b/engines/stark/gfx/renderentry.h
@@ -58,6 +58,9 @@ struct LightEntry {
 	Math::Angle outerConeAngle;
 	float falloffNear;
 	float falloffFar;
+	Math::Vector4d worldPosition;
+	Math::Vector4d eyePosition;
+	Math::Vector3d eyeDirection;
 };
 
 typedef Common::Array<LightEntry *> LightEntryArray;
diff --git a/engines/stark/resources/location.cpp b/engines/stark/resources/location.cpp
index f6f489f7b6..17b6fc274a 100644
--- a/engines/stark/resources/location.cpp
+++ b/engines/stark/resources/location.cpp
@@ -214,6 +214,14 @@ Gfx::LightEntryArray Location::listLightEntries() {
 				if (light->type == Gfx::LightEntry::kAmbient) {
 					ambient = light;
 				} else {
+					Math::Matrix4 view = StarkScene->getViewMatrix();
+					light->worldPosition.x() = light->position.x();
+					light->worldPosition.y() = light->position.y();
+					light->worldPosition.z() = light->position.z();
+					light->worldPosition.w() = 1.0f;
+					light->eyePosition = view * light->worldPosition;
+					light->eyeDirection = view.getRotation() * light->direction;
+					light->eyeDirection.normalize();
 					others.push_back(light);
 				}
 			}




More information about the Scummvm-git-logs mailing list