//////////////////////////////////////////////////////////////////////////////// // SoftShadowsRenderer::updateLightCamera() //////////////////////////////////////////////////////////////////////////////// void SoftShadowsRenderer::updateLightCamera(const nv::matrix4f &view) { // Assuming that the bbox of mesh1 contains everything nv::vec3f center = m_knightMesh->getWorldCenter(); nv::vec3f extents = m_knightMesh->getExtents(); nv::vec3f box[2]; box[0] = center - extents; box[1] = center + extents; nv::vec3f bbox[2]; transformBoundingBox(bbox, box, view); float frustumWidth = std::max(fabs(bbox[0][0]), fabs(bbox[1][0])) * 2.0f; float frustumHeight = std::max(fabs(bbox[0][1]), fabs(bbox[1][1])) * 2.0f; float zNear = -bbox[1][2]; float zFar = LIGHT_ZFAR; nv::matrix4f proj; perspectiveFrustum(proj, frustumWidth, frustumHeight, zNear, zFar); m_lightViewProj = proj * view; nv::matrix4f clip2Tex; clip2Tex.set_scale(nv::vec3f(0.5f, 0.5f, 0.5f)); clip2Tex.set_translate(nv::vec3f(0.5f, 0.5f, 0.5f)); nv::matrix4f viewProjClip2Tex = clip2Tex * m_lightViewProj; nv::matrix4f inverseView = nv::inverse(view); nv::vec3f lightCenterWorld = transformCoord(inverseView, nv::vec3f(0.0f, 0.0f, 0.0f)); if (m_shadowMapShader) { m_shadowMapShader->enable(); m_shadowMapShader->setViewProjMatrix(m_lightViewProj); m_shadowMapShader->disable(); CHECK_GL_ERROR(); } if (m_visTexShader) { m_visTexShader->enable(); m_visTexShader->setLightZNear(zNear); m_visTexShader->setLightZFar(zFar); m_visTexShader->disable(); CHECK_GL_ERROR(); } if (m_pcssShader) { m_pcssShader->enable(); m_pcssShader->setLightViewMatrix(view); m_pcssShader->setLightViewProjClip2TexMatrix(viewProjClip2Tex); m_pcssShader->setLightZNear(zNear); m_pcssShader->setLightZFar(zFar); m_pcssShader->setLightPosition(lightCenterWorld); m_pcssShader->disable(); CHECK_GL_ERROR(); } updateLightSize(frustumWidth, frustumHeight); CHECK_GL_ERROR(); }
Instance::Instance(Keyframed<Vector> t, Keyframed<double> rx, Keyframed<double> ry, Keyframed<double> rz, Keyframed<Vector> s, std::shared_ptr<Shape> i):Shape(std::make_shared<NullMaterial>(),BoundingBox()),t(t),rx(rx),ry(ry),rz(rz),s(s),i(i),memo() { transformBoundingBox(); }