I've spent some time looking at shadows within AppGameKit, and specifically at trying to create custom spot and point light shadows, and the facility for multiple shadows.
I have been folowing these tow guides, which take the same approach but with different code:
https://learnopengl.com/Advanced-Lighting/Shadows/Shadow-Mapping
http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-16-shadow-mapping/
I cannot get it to work however. I have generated the depth image (not ortho, but that doesn't work), which the screen show shows attached (image.png - why is the embed button gone now????) - the shader is currently set to cast from the highlighted spotlight down to the ground and the depth image is displayed as a sprite.
I have recreated both veresions of the code in a T2 plugin so I can use the GLW extensions, and they do seem to be calculating correctly. When I get to the shader, it doesn't map the shadow but instead just adds to the lights in the scene. The second screen shot (image 2) shows what happens when the code from the first link is implimented. I do wonder if part of the problem is the scale of my world - I cannot use the ortho camera or the 3D is all scrambled - the spaceship is actually thousands of units wide.
Anyone have any ideas?
The C code is as follows:
int off = 0;
float near_plane = 1.0f, far_plane = 7.5f;
glm::mat4 lightProjection = glm::ortho<float>(-10.0f, 10.0f, -10.0f, 10.0f, -10.0f, 20.0f);
//glm::mat4 lightProjection = glm::ortho<float>(-10.0f, 10.0f, -10.0f, 10.0f, near_plane, far_plane);
//glm::mat4 lightView = glm::lookAt(glm::vec3(-2.0f, 4.0f, -1.0f),
glm::mat4 lightView = glm::lookAt(glm::vec3(17809212.0f, -11445.0f, 17875868.0f),
glm::vec3(17809212.0f, -11445.0f, 17875868.0f),
glm::vec3(0.0f, 1.0f, 0.0f));
glm::mat4 lightSpaceMatrix = lightProjection * lightView;
//glm::vec3 lightInvDir = glm::vec3(0.5f, 2, 2);
//glm::mat4 depthProjectionMatrix = glm::ortho<float>(-10.0f, 10.0f, -10.0f, 10.0f, -10.0f, 20.0f);
//glm::mat4 depthViewMatrix = glm::lookAt(lightInvDir, glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));
//glm::mat4 depthModelMatrix = glm::mat4(1.0);
//glm::mat4 depthMVP = depthProjectionMatrix * depthViewMatrix * depthModelMatrix;
//agk::Message(agk::Str(lightSpaceMatrix[0][0]));
for (int b = 0; b < 4; b++) {
for (int a = 0; a < 4; a++) {
agk::SetMemblockFloat(mem_blk_num, off, lightSpaceMatrix[b][a]);
//agk::SetMemblockFloat(mem_blk_num, off, depthMVP[b][a]);
off = off + 25;
}
}
The shader code is as follows (PS):
float ShadowCalculation(vec4 fragPosLightSpace)
{
// perform perspective divide
vec3 projCoords = fragPosLightSpace.xyz / fragPosLightSpace.w;
// transform to [0,1] range
projCoords = projCoords * 0.5 + 0.5;
// get closest depth value from light's perspective (using [0,1] range fragPosLight as coords)
float closestDepth = texture(texture6, projCoords.xy).r;
// get depth of current fragment from light's perspective
float currentDepth = projCoords.z;
// check whether current frag pos is in shadow
float shadow = currentDepth > closestDepth ? 1.0 : 0.0;
return shadow;
}
I can change the texturing on the objects to slot 6 and the depth image appears on them, so I know that texture is being applied to the objects, so I think it;s the conversion of the depth image coords back to 3D space that are at fault, but I cannot get this to work any way.