commit e88c7101e0ae07146c48c314a4723e3190527505
parent c35a0b9e52d0cc84bfedaf75c1c3c9c9348288a7
Author: William Casarin <jb55@jb55.com>
Date: Fri, 9 Nov 2018 15:40:28 -0800
optimized skybox
Diffstat:
4 files changed, 16 insertions(+), 12 deletions(-)
diff --git a/etc/shaders/skybox.v.glsl b/etc/shaders/skybox.v.glsl
@@ -7,6 +7,6 @@ uniform mat4 mvp;
void main() {
tex_coords = position;
- vec4 pos = mvp * vec4(position.xyz, 0.01);
- gl_Position = pos;
+ vec4 pos = mvp * vec4(position.xyz, 1.0);
+ gl_Position = pos.xyww;
}
diff --git a/src/game.c b/src/game.c
@@ -117,14 +117,14 @@ void game_init(struct game *game, int width, int height) {
res->camera.coords.azimuth = -quat_yaw(player->node.orientation) - RAD(90.0);
res->camera.coords.inclination = RAD(60);
- res->camera.coords.radius = 200.0;
+ res->camera.coords.radius = 100.0;
struct entity *tower = new_entity(NULL);
ok = load_model(&tower->model, "tower");
assert(ok);
tower->node.label = "tower";
node_attach(&tower->node, &player->node);
- node_translate(&tower->node, V3(0.0, 40.0, 0.0));
+ node_translate(&tower->node, V3(0.0, 100.0, 0.0));
// END ENTITIES
diff --git a/src/render.c b/src/render.c
@@ -274,12 +274,6 @@ void render (struct game *game, struct render_config *config) {
&game->test_resources.programs[DEFAULT_PROGRAM];
/* mat4_multiply(view_proj, res->skybox.node.mat, mvp); */
- if (!config->is_depth_pass) {
- mat4_inverse(camera, view);
- mat4_remove_translations(view);
- mat4_multiply(projection, view, view_proj);
- render_skybox(&res->skybox, view_proj);
- }
mat4_inverse(camera, view);
mat4_multiply(projection, view, view_proj);
@@ -295,7 +289,7 @@ void render (struct game *game, struct render_config *config) {
mat4_inverse(camera, view);
mat4_multiply(projection, view, view_proj);
- for (u32 i = 0; i < num_entities; ++i) {
+ for (u32 i = 1; i < num_entities; ++i) {
struct entity *entity = &entities[i];
if (config->is_depth_pass && !entity->casts_shadows)
continue;
@@ -354,6 +348,16 @@ void render (struct game *game, struct render_config *config) {
check_gl();
}
+ if (!config->is_depth_pass) {
+ mat4_inverse(camera, view);
+ mat4_remove_translations(view);
+ mat4_multiply(projection, view, view_proj);
+
+ glDepthFunc(GL_LEQUAL);
+ render_skybox(&res->skybox, view_proj);
+ glDepthFunc(GL_LESS);
+ }
+
if (config->draw_ui)
render_ui(&game->ui, view);
diff --git a/src/update.c b/src/update.c
@@ -309,7 +309,7 @@ void orbit_update_from_mouse(struct orbit *camera, struct input *input,
node_recalc(target_node);
vec3_copy(node_world(target_node), target);
- vec3_add(target, V3(0.0, 0.0, 100.0), target);
+ /* vec3_add(target, V3(0.0, 0.0, 100.0), target); */
float mx = 0.0, my = 0.0;
if (input_is_dragging(input, SDL_BUTTON_LEFT) ||