commit 6bb630423da678fd7db9ce13b170d8a5253c6107
parent 37ae4c6c6e23f596e31e92ea49734871fbc13042
Author: William Casarin <jb55@jb55.com>
Date: Thu, 8 Nov 2018 18:28:50 -0800
skybox working
Diffstat:
10 files changed, 39 insertions(+), 58 deletions(-)
diff --git a/data/textures/cubemaps/ame_siege/siege_dn_flip.tga b/data/textures/cubemaps/ame_siege/siege_dn_flip.tga
Binary files differ.
diff --git a/data/textures/cubemaps/ame_siege/siege_ft_flip.tga b/data/textures/cubemaps/ame_siege/siege_ft_flip.tga
Binary files differ.
diff --git a/data/textures/cubemaps/ame_siege/siege_lf_flip.tga b/data/textures/cubemaps/ame_siege/siege_lf_flip.tga
Binary files differ.
diff --git a/data/textures/cubemaps/ame_siege/siege_rt_flip.tga b/data/textures/cubemaps/ame_siege/siege_rt_flip.tga
Binary files differ.
diff --git a/data/textures/cubemaps/ame_siege/siege_up_flip.tga b/data/textures/cubemaps/ame_siege/siege_up_flip.tga
Binary files differ.
diff --git a/etc/shaders/skybox.v.glsl b/etc/shaders/skybox.v.glsl
@@ -1,12 +1,13 @@
#include profile
in vec3 position;
+in vec3 tex_coord;
out vec3 tex_coords;
uniform mat4 mvp;
void main() {
tex_coords = position;
- vec4 pos = mvp * vec4(position.xyz, 0.00018);
- gl_Position = pos.xyzw;
+ vec4 pos = mvp * vec4(position.xyz, 0.01);
+ gl_Position = pos;
}
diff --git a/src/geometry.c b/src/geometry.c
@@ -70,7 +70,7 @@ void render_geometry(struct geometry *geom, struct attributes *attrs,
}
else {
/* printf("nverts %d\n", geom->num_verts); */
- glDrawArrays(type, 0, geom->num_verts / 3);
+ glDrawArrays(type, 0, geom->num_verts);
check_gl();
}
}
diff --git a/src/render.c b/src/render.c
@@ -281,6 +281,11 @@ void render (struct game *game, struct render_config *config) {
glCullFace(GL_BACK);
}
+ mat4_inverse(camera, view);
+ mat4_remove_translations(view);
+ mat4_multiply(projection, view, view_proj);
+ /* mat4_multiply(view_proj, res->skybox.node.mat, mvp); */
+ render_skybox(&res->skybox, view_proj);
mat4_inverse(camera, view);
mat4_multiply(projection, view, view_proj);
@@ -347,12 +352,6 @@ void render (struct game *game, struct render_config *config) {
if (config->draw_ui)
render_ui(&game->ui, view);
- mat4_inverse(camera, view);
- mat4_remove_translations(view);
- mat4_multiply(projection, view, view_proj);
- /* mat4_multiply(view_proj, res->skybox.node.mat, mvp); */
- render_skybox(&res->skybox, view_proj);
-
//player
// y tho
diff --git a/src/skybox.c b/src/skybox.c
@@ -3,51 +3,25 @@
#include "util.h"
#include "texture.h"
-static float skybox_vertices[] = {
- // positions
- -1.0f, 1.0f, -1.0f,
- -1.0f, -1.0f, -1.0f,
- 0.0f, -1.0f, -1.0f,
- 0.0f, -1.0f, -1.0f,
- 0.0f, 1.0f, -1.0f,
- 1.0f, 1.0f, -1.0f,
-
- 1.0f, -1.0f, 1.0f,
- 1.0f, -1.0f, -1.0f,
- 1.0f, 1.0f, -1.0f,
- 1.0f, 1.0f, -1.0f,
- 1.0f, 1.0f, 1.0f,
- 1.0f, -1.0f, 1.0f,
-
- 0.0f, -1.0f, -1.0f,
- 0.0f, -1.0f, 1.0f,
- 0.0f, 1.0f, 1.0f,
- 0.0f, 1.0f, 1.0f,
- 0.0f, 1.0f, -1.0f,
- 0.0f, -1.0f, -1.0f,
-
- 1.0f, -1.0f, 1.0f,
- 1.0f, 1.0f, 1.0f,
- 0.0f, 1.0f, 1.0f,
- 0.0f, 1.0f, 1.0f,
- 0.0f, -1.0f, 1.0f,
- 1.0f, -1.0f, 1.0f,
-
- 1.0f, 1.0f, -1.0f,
- 0.0f, 1.0f, -1.0f,
- 0.0f, 1.0f, 1.0f,
- 0.0f, 1.0f, 1.0f,
- 1.0f, 1.0f, 1.0f,
- 1.0f, 1.0f, -1.0f,
-
- 1.0f, -1.0f, -1.0f,
- 1.0f, -1.0f, 1.0f,
- 0.0f, -1.0f, -1.0f,
- 0.0f, -1.0f, -1.0f,
- 1.0f, -1.0f, 1.0f,
- 0.0f, -1.0f, 1.0f
+static GLfloat skybox_vertices[] = {
+ 1.0, 1.0, 1.0, -1.0, 1.0, 1.0, -1.0,-1.0, 1.0, 1.0,-1.0, 1.0, // v0-v1-v2-v3 front
+ 1.0, 1.0,-1.0, 1.0, 1.0, 1.0, 1.0,-1.0, 1.0, 1.0,-1.0,-1.0, // v5-v0-v3-v4 right
+ -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,-1.0, -1.0, 1.0,-1.0, // v1-v0-v5-v6 top
+ -1.0, 1.0, 1.0, -1.0, 1.0,-1.0, -1.0,-1.0,-1.0, -1.0,-1.0, 1.0, // v1-v6-v7-v2 left
+ 1.0,-1.0, 1.0, -1.0,-1.0, 1.0, -1.0,-1.0,-1.0, 1.0,-1.0,-1.0, // v3-v2-v7-v4 bottom
+ -1.0, 1.0,-1.0, 1.0, 1.0,-1.0, 1.0,-1.0,-1.0, -1.0,-1.0,-1.0 // v4-v7-v6-v5 back
};
+static u32 skybox_indices[] = {
+ 0, 1, 2, 0, 2, 3, // top (+z)
+ 4, 5, 6, 4, 6, 7, // right (+x)
+ 8, 9,10, 8, 10,11, // front (+y)
+ 12,13,14, 12,14,15, // left (-x)
+ 16,17,18, 16,18,19, // back (-y)
+ 20,21,22, 20,22,23 // bottom (-z)
+};
+
+
void create_skybox(struct skybox *skybox, struct gpu_program *program) {
struct shader vertex, frag;
struct shader *shaders[] = {&vertex, &frag};
@@ -57,18 +31,22 @@ void create_skybox(struct skybox *skybox, struct gpu_program *program) {
init_model(&skybox->model);
skybox->program = program;
+
skybox->model.geom.vertices = skybox_vertices;
+ skybox->model.geom.indices = skybox_indices;
+
skybox->model.geom.num_verts = ARRAY_SIZE(skybox_vertices);
+ skybox->model.geom.num_indices = ARRAY_SIZE(skybox_indices);
make_buffer_geometry(&skybox->model.geom);
static const char *faces[6] = {
- CUBEMAP("ame_siege/siege_rt.tga"),
- CUBEMAP("ame_siege/siege_lf.tga"),
- CUBEMAP("ame_siege/siege_up.tga"),
- CUBEMAP("ame_siege/siege_dn.tga"),
- CUBEMAP("ame_siege/siege_ft.tga"),
+ CUBEMAP("ame_siege/siege_rt_flip.tga"),
+ CUBEMAP("ame_siege/siege_lf_flip.tga"),
+ CUBEMAP("ame_siege/siege_ft_flip.tga"),
CUBEMAP("ame_siege/siege_bk.tga"),
+ CUBEMAP("ame_siege/siege_up_flip.tga"),
+ CUBEMAP("ame_siege/siege_dn_flip.tga"),
};
skybox->model.texture = create_cubemap(faces);
@@ -86,6 +64,9 @@ void create_skybox(struct skybox *skybox, struct gpu_program *program) {
skybox->attrs.position = (gpu_addr)
glGetAttribLocation(skybox->program->handle, "position");
+
+ skybox->attrs.tex_coord = (gpu_addr)
+ glGetAttribLocation(skybox->program->handle, "tex_coord");
}
diff --git a/src/window.c b/src/window.c
@@ -11,7 +11,7 @@ void
handle_resize(struct game *game, int width, int height) {
/* printf("resizing %d %d\n", width, height); */
glViewport( 0, 0, width, height );
- mat4_perspective(75 /* fov */, (float)width / height, 50.0, 10000.0,
+ mat4_perspective(75 /* fov */, (float)width / height, 10.0, 10000.0,
game->test_resources.proj_persp);
resize_fbos(get_entity(&game->test_resources.player_id),