polyadvent

A game engine from scratch in C
git clone git://jb55.com/polyadvent
Log | Files | Refs | README

commit 5d8a70c618224e7a09869bcfff3da465e791987b
parent 35865d59734ee3d1d36b12d20aef92da41497319
Author: William Casarin <jb55@jb55.com>
Date:   Sat,  3 Nov 2018 23:04:54 -0700

calculate shadowmap ortho camera from bounding boxes

Diffstat:
MMakefile | 2+-
Msrc/game.c | 16++--------------
Msrc/update.c | 11+++++++++++
3 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/Makefile b/Makefile @@ -2,7 +2,7 @@ NAME ?= polyadvent BIN ?= $(NAME) PREFIX ?= /usr/local DEFS= -DGLFW_INCLUDE_NONE -DDEBUG -CFLAGS = $(DEFS) -ggdb -O -I src -Wall -Werror -Wextra -std=c99 \ +CFLAGS = $(DEFS) -ggdb -Ofast -I src -Wall -Werror -Wextra -std=c99 \ -Wno-unused-function \ -Wno-unused-parameter \ -Wno-unused-variable \ diff --git a/src/game.c b/src/game.c @@ -40,7 +40,7 @@ void game_init(struct game *game, int width, int height) { mat4 *light_dir = res->light_dir; int ok = 0; - const double size = 1000; + const double size = 10000; terrain->settings = (struct perlin_settings){ .depth = 1, @@ -54,18 +54,6 @@ void game_init(struct game *game, int width, int height) { .scale = 1.0 }; - static const int shadowmap_scale = 10.0; - - // default ortho screenspace projection - mat4_ortho(-shadowmap_scale, // left - shadowmap_scale, // right - -shadowmap_scale, // bottom - shadowmap_scale, // top - -10000.0, // near - 10000.0, // far - res->proj_ortho - ); - create_ui(&game->ui, width, height, &res->programs[UI_PROGRAM]); check_gl(); @@ -118,7 +106,7 @@ void game_init(struct game *game, int width, int height) { terrain->entity.casts_shadows = 0; // player init - ok = load_model(&player->model, "ico-sphere"); + ok = load_model(&player->model, "tower"); assert(ok); player->model.shading = SHADING_VERT_COLOR; player->node.label = "player"; diff --git a/src/update.c b/src/update.c @@ -220,6 +220,17 @@ void resize_fbos(struct game *game, int width, int height) { delete_fbo(&res->shadow_buffer); } + const float factor = 8.0; + float left = res->player.model.geom.min[0] * factor; + float right = res->player.model.geom.max[0] * factor; + float bottom = res->player.model.geom.min[1] * factor; + float top = res->player.model.geom.max[1] * factor; + const float near = -10000.0; + const float far = 10000.0; + + // default ortho screenspace projection + mat4_ortho(left, right, bottom, top, near, far, res->proj_ortho); + create_fbo(&res->shadow_buffer, width, height); /* fbo_attach_renderbuffer(&res->shadow_buffer, GL_DEPTH24_STENCIL8, */ /* GL_DEPTH_STENCIL_ATTACHMENT); */