commit 3ef42fb903ead800a694ce6135f538a7bfff81c8
parent 534606327d29470da8f36a285081e6dcad721f8c
Author: William Casarin <jb55@jb55.com>
Date: Mon, 29 Oct 2018 17:05:45 -0700
add is_depth_pass to render config
Diffstat:
3 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/src/main.c b/src/main.c
@@ -48,13 +48,15 @@ int main(void)
struct render_config fbo_render_config = {
.draw_ui = 0,
+ .is_depth_pass = 1,
.camera = game.test_resources.sun_camera.mat,
.projection = game.test_resources.proj_ortho,
.depth_mvp = depth_mvp
};
struct render_config default_config = {
- .draw_ui = 1,
+ .draw_ui = 0,
+ .is_depth_pass = 0,
.camera = game.test_resources.camera.mat,
.projection = game.test_resources.proj_persp,
.depth_mvp = depth_mvp
diff --git a/src/render.c b/src/render.c
@@ -53,6 +53,13 @@ static const GLushort cube_indices[] = {
20,21,22, 20,22,23
};
+static const float bias_matrix[] = {
+ 0.5, 0.0, 0.0, 0.0,
+ 0.0, 0.5, 0.0, 0.0,
+ 0.0, 0.0, 0.5, 0.0,
+ 0.5, 0.5, 0.5, 1.0
+};
+
void
init_gl(struct resources *resources, int width, int height) {
struct shader vertex, terrain_vertex, fragment, fragment_smooth;
@@ -187,13 +194,12 @@ void render (struct game *game, struct render_config *config) {
, &game->test_resources.player
};
- int is_shadow = config->draw_ui == 0;
int terrain_program = game->test_resources.programs[TERRAIN_PROGRAM].handle;
int default_program = game->test_resources.programs[DEFAULT_PROGRAM].handle;
for (size_t i = 0; i < ARRAY_SIZE(entities); ++i) {
struct entity *entity = entities[i];
- if (is_shadow && !entity->casts_shadows)
+ if (config->is_depth_pass && !entity->casts_shadows)
continue;
// TODO this is a bit wonky, refactor this
if (i == 0)
@@ -205,17 +211,8 @@ void render (struct game *game, struct render_config *config) {
mat4_inverse(camera, view);
mat4_multiply(projection, view, view_proj);
- // TODO: use something other than draw_ui to detect shadow map fbo phase
- if (is_shadow) {
- static const float bias_matrix[] = {
- 0.5, 0.0, 0.0, 0.0,
- 0.0, 0.5, 0.0, 0.0,
- 0.0, 0.0, 0.5, 0.0,
- 0.5, 0.5, 0.5, 1.0
- };
-
+ if (config->is_depth_pass) {
mat4_multiply(bias_matrix, view_proj, config->depth_mvp);
- /* mat4_copy(view_proj, config->depth_mvp); */
}
else {
glUniformMatrix4fv(res->uniforms.depth_mvp, 1, 0, config->depth_mvp);
diff --git a/src/render.h b/src/render.h
@@ -7,6 +7,7 @@ struct game;
struct render_config {
int draw_ui;
+ int is_depth_pass;
float *camera;
float *projection;
float *depth_mvp;