void Technique::updateShaderParameters(const RenderContext& context) { m_viewportResolution->setValue(context.viewportResolution); ProjectionPtr projection = context.camera->getProjection(); m_farClipDistance->setValue(projection->getFarClipDistance()); m_maxClipSpaceDepth->setValue(projection->getMaxClipSpaceDepth()); glm::mat4 viewProj = context.camera->getViewProjectionMatrix(); m_viewProjectionMatrix->setValue(viewProj); m_modelViewProjectionMatrix->setValue(viewProj * context.sceneNode->getTransform()); glm::mat4 invModelMatrix = glm::inverse(context.sceneNode->getTransform()); m_invModelMatrix->setValue(invModelMatrix); { // camera glm::vec4 v = invModelMatrix * glm::vec4(context.camera->getPosition(), 1); glm::vec3 pos(v.x, v.y, v.z); m_cameraPosition_modelSpace->setValue(pos); m_cameraDirection_modelSpace->setValue(glm::normalize(pos)); m_cameraForwardDirection_modelSpace->setValue(glm::mat3(invModelMatrix) * context.camera->getDirection()); } if (context.light) { glm::vec3 dir = glm::inverse(context.sceneNode->getOrientation()) * context.light->getDirection(); m_lightDirection_modelSpace->setValue(-dir); // light direction in shader is direction to light const ShadowProjector* projector = context.light->getShadowProjector(); if (projector) { static glm::mat4 biasMatrix( 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0 ); glm::mat4 shadowModelViewProj = projector->getCamera()->getViewProjectionMatrix() * context.sceneNode->getTransform(); m_shadowModelViewProjectionMatrix->setValue(biasMatrix * shadowModelViewProj); m_shadowMaxClipSpaceDepth->setValue(projector->getCamera()->getProjection()->getMaxClipSpaceDepth()); m_invShadowViewProjectionMatrix->setValue(glm::inverse(biasMatrix * projector->getCamera()->getViewProjectionMatrix())); } } else { m_lightDirection_modelSpace->setValue(vec3Zero()); } }
void Prop::init() { vec3Zero(&velocity); }