PDA

View Full Version : Shadows for Skeletal Animations invisible



JonJomate
02-06-2017, 04:27 PM
I have skeletal animations working perfectly fine, however i can't get them to show up in the shadow map.

Regular rendering for static objects works, regular rendering for animated object works, shadow map rendering for static objects works, but rendering shadows for animated objects doesn't. I either skip the skeletal calculations in the fragment shader, and that does work, or i run them and no shadow appears at all. I've triple checked all uniform inputs, viewed the raw shadow map FBO and so on, but i can't figure this out. The code is exactly the same as in the usual non-shadow fragment shader, but for some reason nothing shows up.

Regular entityFragmentShader, this one works perfectly fine



#version 150

const int MAX_JOINTS = 55;//max joints allowed in a skeleton
const int MAX_WEIGHTS = 3;//max number of joints that can affect a vertex

in vec3 in_position;
in vec2 in_textureCoords;
in vec3 in_normal;
in ivec3 in_jointIndices;
in vec3 in_weights;

out vec2 pass_textureCoords;
out vec3 pass_normal;
out vec3 toLightVector[4];
out vec3 toCameraVector;

uniform mat4 jointTransforms[MAX_JOINTS];
uniform mat4 projectionViewMatrix;

uniform mat4 viewMatrix;
uniform mat4 projectionMatrix;
uniform mat4 transformationMatrix;
uniform vec3 lightPosition[4];

uniform float useFakeLighting;
uniform float numberOfRows;
uniform vec2 offset;

uniform vec4 clipPlane;

uniform bool animatedMode;

void main(void) {

vec4 totalLocalPos = vec4(0.0);
vec4 totalNormal = vec4(0.0);

if (animatedMode) {
// Joints
for(int i=0;i<MAX_WEIGHTS;i++) {
if (in_weights[i] > 0) {
vec4 localPosition = transformationMatrix * jointTransforms[in_jointIndices[i]] * vec4(in_position, 1.0);
totalLocalPos += localPosition * in_weights[i];

vec4 worldNormal = jointTransforms[in_jointIndices[i]] * vec4(in_normal, 0.0);
totalNormal += worldNormal * in_weights[i];
}
}
} else {
// Static
totalLocalPos = transformationMatrix * vec4(in_position,1.0);
totalNormal = vec4(in_normal, 0.0);
}


// Fake lighting (Normal pointing upwards)
if (useFakeLighting > 0.5) {
totalNormal = vec4(0.0, 1.0, 0.0, 0.0);
}

// Clipping
gl_ClipDistance[0] = dot(totalLocalPos, clipPlane);

// Lights / Normals
for(int i = 0; i < 4; i++) {
toLightVector[i] = lightPosition[i] - totalLocalPos.xyz;
}
toCameraVector = (inverse(viewMatrix) * vec4(0.0, 0.0, 0.0, 1.0)).xyz - totalLocalPos.xyz;

gl_Position = projectionMatrix * viewMatrix * totalLocalPos;
pass_normal = (transformationMatrix * totalNormal).xyz;
pass_textureCoords = (in_textureCoords / numberOfRows) + offset;
}


And the shadowVertexShader, not working when in animatedMode:



#version 150

const int MAX_JOINTS = 55;
const int MAX_WEIGHTS = 3;


in vec3 in_position;
in vec2 in_textureCoords;
in ivec3 in_jointIndices;
in vec3 in_weights;

out vec2 textureCoords;

uniform mat4 modelViewProjectionMatrix;
uniform mat4 jointTransforms[MAX_JOINTS];
uniform bool animatedMode;

uniform mat4 viewMatrix;
uniform mat4 projectionMatrix;
uniform mat4 transformationMatrix;

void main(void){
if (animatedMode) {

vec4 totalLocalPos = vec4(0.0);
for(int i=0;i<MAX_WEIGHTS;i++) {
if (in_weights[i] > 0) {
vec4 localPosition = transformationMatrix * jointTransforms[in_jointIndices[i]] * vec4(in_position, 1.0);
totalLocalPos += localPosition * in_weights[i];
}
}

gl_Position = projectionMatrix * viewMatrix * totalLocalPos;
} else {
gl_Position = projectionMatrix * viewMatrix * transformationMatrix * vec4(in_position, 1.0);
}

textureCoords = in_textureCoords;

}


Absolutely no shadow on the animated entities shows up. Nothing weird and distorted either. I've checked multiple times that the jointTransforms mat4 array loaded up is correct, glEnableVertexAttribArray is called for all the indices and so on.

Am i missing something obvious? If not, how do i go about solving the problem? Is there a way to examine the values used in the shader calculations? Thanks in advance!

Silence
02-08-2017, 06:13 AM
When you render from the light to create the shadow map, do you render your skeletal objects too ?

JonJomate
02-08-2017, 10:43 AM
Yes, for example, if i load "false" to animatedMode when preparing animated models, the shadows are drawn (just without animations). The problem must be with the calculations or some special mode you have to activate in OpenGL before this type of thing is possible.

Silence
02-08-2017, 11:57 PM
Yes, for example, if i load "false" to animatedMode when preparing animated models, the shadows are drawn (just without animations). The problem must be with the calculations or some special mode you have to activate in OpenGL before this type of thing is possible.

No. Shadow-mapping is an imagery technic, no need to specialize according to any potential kind of objects.
If it works for one object, it should work for all objects provided you have the same workflow for all your kind of objects.
You can try to render your shadow map on screen (or in a file) and see if you see these objects.

However, if your animated objects are very small compared to the scene you render, these shadow might not be visible. This can be fixed by changing the bias in your shadow matrix.