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!

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!