trying to ge the shadow to render correctly

This commit is contained in:
Sam Gateau 2015-02-23 13:12:29 -08:00
parent e9360a77f2
commit 687c76a6f8
4 changed files with 19 additions and 7 deletions

View file

@ -2564,7 +2564,9 @@ void Application::updateShadowMap() {
glm::ortho(minima.x, maxima.x, minima.y, maxima.y, -maxima.z, -minima.z) * glm::mat4_cast(inverseRotation));
// update the shadow view frustum
_shadowViewFrustum.setPosition(rotation * ((minima + maxima) * 0.5f));
// glm::vec3 shadowFrustumCenter = glm::vec3((minima.x + maxima.x) * 0.5f, (minima.y + maxima.y) * 0.5f, (minima.z + maxima.z) * 0.5f);
glm::vec3 shadowFrustumCenter = rotation * ((minima + maxima) * 0.5f);
_shadowViewFrustum.setPosition(shadowFrustumCenter);
_shadowViewFrustum.setOrientation(rotation);
_shadowViewFrustum.setOrthographic(true);
_shadowViewFrustum.setWidth(maxima.x - minima.x);
@ -2594,8 +2596,10 @@ void Application::updateShadowMap() {
// this is what is used for rendering the Entities and avatars
Transform viewTransform;
viewTransform.setRotation(rotation);
// viewTransform.postTranslate(shadowFrustumCenter);
setViewTransform(viewTransform);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.1f, 4.0f); // magic numbers courtesy http://www.eecs.berkeley.edu/~ravir/6160/papers/shadowmaps.ppt

View file

@ -577,6 +577,10 @@ void ViewFrustum::computeOffAxisFrustum(float& left, float& right, float& bottom
// compute our dimensions the usual way
float hheight = _nearClip * tanf(_fieldOfView * 0.5f * RADIANS_PER_DEGREE);
float hwidth = _aspectRatio * hheight;
if (isOrthographic()) {
hheight = getHeight();
hwidth = getWidth();
}
// get our frustum corners in view space
glm::mat4 eyeMatrix = glm::mat4_cast(glm::inverse(_eyeOffsetOrientation)) * glm::translate(-_eyeOffsetPosition);
@ -868,18 +872,18 @@ float ViewFrustum::distanceToCamera(const glm::vec3& point) const {
void ViewFrustum::evalProjectionMatrix(glm::mat4& proj) const {
if (isOrthographic()) {
float left, right, bottom, top, near, far;
glm::vec4 clip0, clip1;
computeOffAxisFrustum(left, right, bottom, top, near, far, clip0, clip1);
glm::vec3 frustumCenter = glm::inverse( _orientation) * _position;
proj = glm::ortho(left, right, bottom, top);
proj = glm::ortho(-0.5f * getWidth(), +0.5f * getWidth(), -0.5f * getWidth(), +0.5f * getWidth());
proj = glm::ortho(frustumCenter.x -0.5f * getWidth(),
frustumCenter.x +0.5f * getWidth(),
frustumCenter.y -0.5f * getHeight(),
frustumCenter.y +0.5f * getHeight(),
-getFarClip(), -getNearClip());
} else {
float left, right, bottom, top, near, far;
glm::vec4 clip0, clip1;
computeOffAxisFrustum(left, right, bottom, top, near, far, clip0, clip1);
proj = glm::perspective(glm::radians(getFieldOfView()), getAspectRatio(), getNearClip(), getFarClip());
// proj = glm::perspective(getFieldOfView() * 0.5f, getAspectRatio(), getNearClip(), getFarClip());
}
}

View file

@ -31,6 +31,8 @@ uniform vec3 shadowDistances;
// the inverse of the size of the shadow map
uniform float shadowScale;
uniform mat4 shadowMatrices[4];
vec2 samples[8] = vec2[8](
vec2(-2.0, -2.0),
vec2(2.0, -2.0),

View file

@ -46,4 +46,6 @@ void main(void) {
gl_FragColor = vec4(color, frag.normalVal.a);
}
gl_FragColor = vec4(vec3(shadowAttenuation), 1.0);
}