From 8de80295ea54da44d75005c8892510dce8edaf19 Mon Sep 17 00:00:00 2001 From: turanszkij Date: Sun, 7 Aug 2016 01:18:50 +0200 Subject: [PATCH] light update fix --- WickedEngine/wiLoader.cpp | 24 ++++++++++-------------- WickedEngine/wiRenderer.cpp | 17 ++++++++--------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/WickedEngine/wiLoader.cpp b/WickedEngine/wiLoader.cpp index 43bfc4484..454b8729f 100644 --- a/WickedEngine/wiLoader.cpp +++ b/WickedEngine/wiLoader.cpp @@ -3901,15 +3901,13 @@ void Light::UpdateLight() else if (type == Light::SPOT) { if (shadow) { - if (!shadowCam_spotLight.empty()) - { - shadowCam_spotLight[0].Update(XMLoadFloat4x4(&world)); - shadowCam_spotLight[0].Create_Perspective(XM_PIDIV2); - } - else + if (shadowCam_spotLight.empty()) { shadowCam_spotLight.push_back(SHCAM(XMFLOAT4(0, 0, 0, 1), 0.1f, 1000.0f, enerDis.z)); } + shadowCam_spotLight[0].Update(XMLoadFloat4x4(&world)); + shadowCam_spotLight[0].farplane = enerDis.y; + shadowCam_spotLight[0].Create_Perspective(enerDis.z); } bounds.createFromHalfWidth(translation, XMFLOAT3(enerDis.y, enerDis.y, enerDis.y)); @@ -3917,14 +3915,7 @@ void Light::UpdateLight() else if (type == Light::POINT) { if (shadow) { - if (!shadowCam_pointLight.empty()) - { - for (unsigned int i = 0; i < shadowCam_pointLight.size(); ++i) { - shadowCam_pointLight[i].Update(XMLoadFloat3(&translation)); - shadowCam_pointLight[i].Create_Perspective(XM_PIDIV2); - } - } - else + if (shadowCam_pointLight.empty()) { shadowCam_pointLight.push_back(SHCAM(XMFLOAT4(0.5f, -0.5f, -0.5f, -0.5f), 0.1f, 1000.0f, XM_PIDIV2)); //+x shadowCam_pointLight.push_back(SHCAM(XMFLOAT4(0.5f, 0.5f, 0.5f, -0.5f), 0.1f, 1000.0f, XM_PIDIV2)); //-x @@ -3935,6 +3926,11 @@ void Light::UpdateLight() shadowCam_pointLight.push_back(SHCAM(XMFLOAT4(0.707f, 0, 0, -0.707f), 0.1f, 1000.0f, XM_PIDIV2)); //+z shadowCam_pointLight.push_back(SHCAM(XMFLOAT4(0, 0.707f, 0.707f, 0), 0.1f, 1000.0f, XM_PIDIV2)); //-z } + for (unsigned int i = 0; i < shadowCam_pointLight.size(); ++i) { + shadowCam_pointLight[i].Update(XMLoadFloat3(&translation)); + shadowCam_spotLight[i].farplane = enerDis.y; + shadowCam_pointLight[i].Create_Perspective(XM_PIDIV2); + } } bounds.createFromHalfWidth(translation, XMFLOAT3(enerDis.y, enerDis.y, enerDis.y)); diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 5c78f6d83..57496f9cb 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -2331,13 +2331,16 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID) switch (l->type) { case Light::SPOT: - orderedSpotLights.insert(l); + if(!l->shadowCam_spotLight.empty()) + orderedSpotLights.insert(l); break; case Light::POINT: - orderedPointLights.insert(l); + if (!l->shadowCam_pointLight.empty()) + orderedPointLights.insert(l); break; default: - dirLights.insert(l); + if (!l->shadowCam_dirLight.empty()) + dirLights.insert(l); break; } } @@ -2460,14 +2463,10 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID) Light::shadowMaps_spotLight[i].Set(threadID); Frustum frustum; - XMFLOAT4X4 proj, view; - XMStoreFloat4x4(&proj, XMLoadFloat4x4(&l->shadowCam_spotLight[0].Projection)); - XMStoreFloat4x4(&view, XMLoadFloat4x4(&l->shadowCam_spotLight[0].View)); - frustum.ConstructFrustum(wiRenderer::getCamera()->zFarP, proj, view); + frustum.ConstructFrustum(wiRenderer::getCamera()->zFarP, l->shadowCam_spotLight[0].Projection, l->shadowCam_spotLight[0].View); if (spTree) wiSPTree::getVisible(spTree->root, frustum, culledObjects); - int index = 0; #pragma region BLOAT { if (!culledObjects.empty()) { @@ -2489,7 +2488,7 @@ void wiRenderer::DrawForShadowMap(GRAPHICSTHREAD threadID) //MAPPED_SUBRESOURCE mappedResource; ShadowCB cb; - cb.mVP = l->shadowCam_spotLight[index].getVP(); + cb.mVP = l->shadowCam_spotLight[0].getVP(); GetDevice()->UpdateBuffer(constantBuffers[CBTYPE_SHADOW], &cb, threadID);