Hello everyone! ![]()
![]()
I have a really annoying problem ![]()
I wanted to made dropped shadows in the game
. During my searching I have know that it calls “Shadow Mapping” ![]()
I spend a lot of time on implementation this, and everything that I got is:
I want to ask you to help me to implement dropping shadows to the game ![]()
Here’s the source code of this project
xolatgames/Dima-wants-crisps: Just a simple game where Dima can stands 🧍♂️, jumps, and walks 🏃♂️ - Codeberg.org
You don’t need to touch all of that
. Let me to explain you where’s the all that you needed ![]()
There’s the script that makes framebuffers for depth-testing ![]()
+o objects/info/packs +o info/refs.
There’s the place where locates the shaders those uses for depth-testing ![]()
Tree copies for relevant files (see gitattributes(5)). E.g.
They calls depth_shader.vert and depth_shader.frag
Also, there are the shaders those uses when the calculation shadows is finished, for rendering the level. And those uses the rendered framebuffer for they can take a decision, does here should be an obscuring place ![]()
They calls diffuse.vert and diffuse.frag
Also, there’s the C++ script for rendering level by itself
Time, reducing the time zone ("author-tz"); similarly for.
But it’s not all that I wanted to tell you!
I also have not so much good experiment with the current version of the source code.
So, listen!
There’s game.cpp script
[--delta-base-offset] [--non-empty] [--local] [--incremental] [--window=<n>] [--depth=<n>] [--revs [--unpacked .
When I add glUseProgram(depth_shader_program); to the 185th line for it seems so there:
...
case Stage::LEVEL: {
...
level.RenderDepthBuffer(depth_shader_program);
glViewport(0, 0, buffer_scale.x, buffer_scale.y);
glm::mat4 vp = level.GetCameraMatrix();
sky.Draw(vp);
glUseProgram(depth_shader_program);
level.Draw();
} break;
...
Then comment all the lines between 156th line and 163th line, except 160th line, and uncomment 166th line in level.cpp script for this part of this script seems so:
...
void Level::Draw() {
/* shadow_map.BindTextureMap(diffuse_program);
glUseProgram(diffuse_program); */
UpdateVPMatrix();
/* UpdateLightSpaceMatrix();
RenderScene(); */
// Uncomment this, if you want to see the depth map texture
shadow_map.DrawPreview(twod_program);
gui.Draw();
}
...
My game start looks so:
So, I have the one question
, and also want for you pay attention on these lines in level.cpp (between the 257th and 269th lines)
:
...
void Level::UpdateLightSpaceMatrix() {
glm::mat4 dir_light_m = dir_light.GetMatrix();
light_space_matrix_id = glGetUniformLocation(diffuse_program, "lightSpaceMatrix");
glUniformMatrix4fv(light_space_matrix_id, 1, GL_FALSE, glm::value_ptr(dir_light_m));
}
void Level::UpdateVPMatrix() {
// A little trick for viewing the direction light projection ;P
// glm::mat4 camera_vp = dir_light.GetMatrix();
glm::mat4 camera_vp = GetCameraMatrix();
vp_id = glGetUniformLocation(diffuse_program, "vp");
glUniformMatrix4fv(vp_id, 1, GL_FALSE, glm::value_ptr(camera_vp));
}
...
And also pay attention on these lines (between 144th and 153th lines) in level.cpp where shadow_map.cpp start its working
:
...
void Level::RenderDepthBuffer(GLuint depth_shader_program) {
glUseProgram(depth_shader_program);
UpdateLightSpaceMatrix();
shadow_map.StartMapping();
RenderScene();
shadow_map.EndMapping();
}
...
There’s the place where the framebuffer renders everything that it needed for calculation the depth map ![]()
And if we touch something in these lines at this moment:
...
void Level::Draw() {
/* shadow_map.BindTextureMap(diffuse_program);
glUseProgram(diffuse_program); */
UpdateVPMatrix();
/* UpdateLightSpaceMatrix();
RenderScene(); */
// Uncomment this, if you want to see the depth map texture
shadow_map.DrawPreview(twod_program);
gui.Draw();
}
...
For example, even UpdateVPMatrix();, everything may stop its working
. And then we got a black screen ![]()
So, my question is: Does the framebuffer just must to hold everything that it rendered between shadow_map.StartMapping(); and shadow_map.EndMapping();, and just be untouchable after that?
If it so… Why when I commend UpdateVPMatrix(); everything stop its working? ![]()
But, also, everything stop its working when I switches to glUseProgram(diffuse_program); at this time:
...
void Level::Draw() {
// shadow_map.BindTextureMap(diffuse_program);
glUseProgram(diffuse_program); // Uncommention of this at this time also breaks everything
UpdateVPMatrix();
/* UpdateLightSpaceMatrix();
RenderScene(); */
// Uncomment this, if you want to see the depth map texture
shadow_map.DrawPreview(twod_program);
gui.Draw();
}
...
So, please help me to fix the shadows in my game ![]()
![]()
Thanks to everyone for your attention! ![]()


