diff --git a/assets/shaders/fbo.frag b/assets/shaders/fbo.frag index 504eec8..2784e90 100644 --- a/assets/shaders/fbo.frag +++ b/assets/shaders/fbo.frag @@ -4,10 +4,17 @@ in vec2 uv; out vec4 frag_color; -uniform sampler2D sampler; +//uniform sampler2D sampler; +uniform sampler2D albedo_map; +uniform sampler2D position_map; +uniform sampler2D normal_map; +uniform sampler2D uv_map; void main() { - frag_color = texture2D(sampler, uv); - //frag_color = vec4(1, 0, 0, 1); + //frag_color = texture2D(sampler, uv); + frag_color = texture(albedo_map, uv); + frag_color = texture(position_map, uv); + frag_color = texture(normal_map, uv); + frag_color = texture(uv_map, uv); } diff --git a/assets/shaders/unshaded.frag b/assets/shaders/unshaded.frag index bc0f0f6..4b8a9a6 100644 --- a/assets/shaders/unshaded.frag +++ b/assets/shaders/unshaded.frag @@ -20,5 +20,4 @@ void main() // gbuffer[1] = vertex.xyz; // gbuffer[2] = normal.xyz; // gbuffer[3] = vec3(uv, 0.0); - //frag_color = vec4(1, 0, 0, 1); } diff --git a/orgfile.org b/orgfile.org index 16229cc..6c5b6de 100644 --- a/orgfile.org +++ b/orgfile.org @@ -70,7 +70,9 @@ All the code in this repository is under GPLv3, see LICENSE for more information ** DONE Materials with textures - State "DONE" from "TODO" [2015-10-15 Thu 21:21] ** TODO Lights! -** TODO Fix problems with texture units +** DONE Fix problems with texture units +- State "DONE" from "TODO" [2016-05-30 Mon 00:57] +** TODO Draw light volumes ** TODO Fix problems with frustrum culling ** TODO 2d drawing routines ** TODO Gui diff --git a/src/game.c b/src/game.c index 5c0bd30..2777813 100644 --- a/src/game.c +++ b/src/game.c @@ -21,6 +21,7 @@ #include "texture.h" #include "material.h" #include "framebuffer.h" +#include "light.h" void run(void); void update(float dt); @@ -44,6 +45,7 @@ void game_init(void) geom_init(); renderer_init(window); transform_init(); + light_init(); camera_init(); material_init(); model_init(); @@ -304,6 +306,7 @@ void game_cleanup(void) model_cleanup(); material_cleanup(); geom_cleanup(); + light_cleanup(); transform_cleanup(); camera_cleanup(); input_cleanup(); diff --git a/src/renderer.c b/src/renderer.c index 3abd9f4..6946137 100644 --- a/src/renderer.c +++ b/src/renderer.c @@ -75,11 +75,11 @@ void renderer_init(GLFWwindow* window) NULL); texture_set_param(def_albedo_tex, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); texture_set_param(def_albedo_tex, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - texture_set_param(def_albedo_tex, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - texture_set_param(def_albedo_tex, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + texture_set_param(def_albedo_tex, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + texture_set_param(def_albedo_tex, GL_TEXTURE_MAG_FILTER, GL_NEAREST); def_position_tex = texture_create("def_position_texture", - TU_DIFFUSE, + TU_SHADOWMAP1, width, height, GL_RGB, GL_RGB16F, @@ -91,7 +91,7 @@ void renderer_init(GLFWwindow* window) texture_set_param(def_position_tex, GL_TEXTURE_MAG_FILTER, GL_LINEAR); def_normal_tex = texture_create("def_normal_texture", - TU_DIFFUSE, + TU_SHADOWMAP2, width, height, GL_RGB, GL_RGB16F, @@ -103,7 +103,7 @@ void renderer_init(GLFWwindow* window) texture_set_param(def_normal_tex, GL_TEXTURE_MAG_FILTER, GL_LINEAR); def_uv_tex = texture_create("def_uv_texture", - TU_DIFFUSE, + TU_SHADOWMAP3, width, height, GL_RGB, GL_RGB16F, @@ -174,34 +174,54 @@ void renderer_draw(void) int width, height; window_get_size(&width, &height); - //glViewport(0, 0, width, height); + glViewport(0, 0, width, height); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); shader_bind(fbo_shader); - struct Camera* primary_camera = camera_get_primary(); - //texture_bind(primary_camera->render_tex); - glViewport(0, height / 2, width / 2, height / 2); + + shader_set_uniform_int(fbo_shader, "albedo_map", (GL_TEXTURE0 + TU_DIFFUSE) - GL_TEXTURE0); texture_bind(def_albedo_tex); - geom_render(quad_geo); - texture_unbind(def_albedo_tex); - glViewport(width / 2, height / 2, width / 2, height / 2); + shader_set_uniform_int(fbo_shader, "position_map", (GL_TEXTURE0 + TU_SHADOWMAP1) - GL_TEXTURE0); texture_bind(def_position_tex); - geom_render(quad_geo); - texture_unbind(def_position_tex); - - glViewport(0, 0, width / 2, height / 2); + + shader_set_uniform_int(fbo_shader, "normal_map", (GL_TEXTURE0 + TU_SHADOWMAP2) - GL_TEXTURE0); texture_bind(def_normal_tex); - geom_render(quad_geo); - texture_unbind(def_normal_tex); - glViewport(width / 2, 0, width / 2, height / 2); - texture_bind(def_depth_tex); + shader_set_uniform_int(fbo_shader, "uv_map", (GL_TEXTURE0 + TU_SHADOWMAP3) - GL_TEXTURE0); + texture_bind(def_uv_tex); + geom_render(quad_geo); - texture_unbind(def_depth_tex); + + //struct Camera* primary_camera = camera_get_primary(); + //texture_bind(primary_camera->render_tex); + /* glViewport(0, height / 2, width / 2, height / 2); */ + /* texture_bind(def_albedo_tex); */ + /* geom_render(quad_geo); */ + /* texture_unbind(def_albedo_tex); */ + + /* glViewport(width / 2, height / 2, width / 2, height / 2); */ + /* texture_bind(def_position_tex); */ + /* geom_render(quad_geo); */ + /* texture_unbind(def_position_tex); */ + + /* glViewport(0, 0, width / 2, height / 2); */ + /* texture_bind(def_normal_tex); */ + /* geom_render(quad_geo); */ + /* texture_unbind(def_normal_tex); */ + + /* glViewport(width / 2, 0, width / 2, height / 2); */ + /* texture_bind(def_depth_tex); */ + /* geom_render(quad_geo); */ + /* texture_unbind(def_depth_tex); */ shader_unbind(); + + texture_unbind(def_albedo_tex); + texture_unbind(def_position_tex); + texture_unbind(def_normal_tex); + texture_unbind(def_uv_tex); } void renderer_cleanup(void)