ソースを参照

Lighting in screenspace

Ivan Safrin 10 年 前
コミット
1aa20ab8a3

BIN
assets/default/default.pak


+ 2 - 3
assets/default/default/DefaultShader.vert

@@ -26,11 +26,10 @@ void main()
 	mat4 modelViewMatrix = viewMatrix * modelMatrix;
 	vec4 p = modelViewMatrix  * position;
 
-	mat3 rotN = mat3_emu(modelMatrix);
+	mat3 rotN = mat3_emu(modelViewMatrix);
 	varNormal = normalize(rotN * normal);
 
-
-	varPosition = modelMatrix  * position;
+	varPosition = modelViewMatrix  * position;
 	gl_Position = projectionMatrix * p;
 
 	texCoordVar = texCoord;

+ 5 - 3
src/core/PolyScene.cpp

@@ -261,7 +261,9 @@ void Scene::Render(Camera *targetCamera, RenderBuffer *targetFramebuffer) {
 		direction.Normalize();
 		
 		direction = light->getConcatenatedMatrix().rotateVector(direction);
-		
+        direction = drawBuffer->viewMatrix.rotateVector(direction);
+        
+        
 		Texture *shadowMapTexture = NULL;
 		if(light->areShadowsEnabled()) {
 			if(light->getType() == SceneLight::SPOT_LIGHT) {
@@ -279,9 +281,9 @@ void Scene::Render(Camera *targetCamera, RenderBuffer *targetFramebuffer) {
 		
 		position = light->getPosition();
 		if(light->getParentEntity() != NULL) {
-			position = light->getParentEntity()->getConcatenatedMatrix() * position;			
+			position = light->getParentEntity()->getConcatenatedMatrix() * position;
 		}
-        
+        position = drawBuffer->viewMatrix * position;
         
         drawBuffer->lights.push_back(light->getLightInfo());
         drawBuffer->lights[drawBuffer->lights.size()-1].position = position;