Added directional lights and removed some unused code

dev
Shariq Shah 9 years ago
parent 08a7b96ace
commit c9cdfb5fff
  1. 40
      assets/shaders/blinn_phong.frag
  2. BIN
      assets/textures/white.tga
  3. 77
      src/game.c
  4. 4
      src/light.c
  5. 52
      src/model.c
  6. 215
      src/renderer.c

@ -3,6 +3,7 @@
struct Light struct Light
{ {
vec3 position; vec3 position;
vec3 direction;
float outer_angle; float outer_angle;
float inner_angle; float inner_angle;
float falloff; float falloff;
@ -64,6 +65,34 @@ vec4 calc_point_light(in Light point_light)
} }
} }
vec4 calc_dir_light(in Light dir_light)
{
vec4 diffuse_comp = vec4(0.0);
vec4 specular_comp = vec4(0.0);
vec3 normalized_normal = normalize(normal);
float cos_ang_incidence = dot(normalized_normal, -dir_light.direction);
cos_ang_incidence = clamp(cos_ang_incidence, 0, 1);
float shadow_factor = 1.0;
if(cos_ang_incidence > 0)
{
diffuse_comp = dir_light.color * diffuse * cos_ang_incidence;
vec3 vertex_to_eye = normalize(camera_pos - vertex);
vec3 light_reflect = normalize(reflect(dir_light.direction, normalized_normal));
float specular_factor = max(0.0, dot(vertex_to_eye, light_reflect));
specular_factor = pow(specular_factor, specular_strength);
specular_comp = dir_light.color * specular * specular_factor;
// if(light.castShadow == 1)
// {
// shadow_factor = calcShadowFactor(vertLightSpace.xyz);
// }
}
//return (dir_light.intensity * (diffuse_comp + specular_comp)) * shadow_factor;
return (dir_light.intensity * (diffuse_comp + specular_comp));
}
void main() void main()
{ {
vec4 albedo_color = diffuse_color * texture(diffuse_texture, uv); vec4 albedo_color = diffuse_color * texture(diffuse_texture, uv);
@ -73,15 +102,12 @@ void main()
{ {
if(i == total_active_lights) break; if(i == total_active_lights) break;
// if(lights[i].type == LT_POINT) if(lights[i].type == LT_POINT)
light_contribution += calc_point_light(lights[i]); light_contribution += calc_point_light(lights[i]);
else if(lights[i].type == LT_DIR)
light_contribution += calc_dir_light(lights[i]);
} }
frag_color = (albedo_color * vec4(0.1, 0.1, 0.1, 1.0)) + frag_color = (albedo_color * vec4(0.1, 0.1, 0.1, 1.0)) +
(albedo_color * light_contribution); (albedo_color * light_contribution);
//frag_color = lights[0].color;
//frag_color = vec4(lights[0].intensity, 0.0, 0.0, 1.0);
//frag_color = vec4(lights[0].position, 1.0);
//frag_color = vec4(camera_pos, 1.0);
//frag_color = vec4(total_active_lights);
} }

Binary file not shown.

@ -1,6 +1,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stddef.h> #include <stddef.h>
#include <time.h>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include "game.h" #include "game.h"
@ -93,10 +94,10 @@ void scene_setup(void)
vec4_fill(&color, 1.f, 1.f, 1.f, 1.f); vec4_fill(&color, 1.f, 1.f, 1.f, 1.f);
transform_set_position(viewer_tran, &viewer_pos); transform_set_position(viewer_tran, &viewer_pos);
int render_width, render_height; int render_width, render_height;
render_width = 800; render_width = 1024;
render_height = 600; render_height = 768;
struct Camera* camera = entity_component_add(player, C_CAMERA, render_width, render_height); struct Camera* camera = entity_component_add(player, C_CAMERA, render_width, render_height);
//camera_attach_fbo(camera, render_width, render_height, 1, 1); camera_attach_fbo(camera, render_width, render_height, 1, 1);
vec4_fill(&camera->clear_color, 0.3f, 0.6f, 0.9f, 1.0f); vec4_fill(&camera->clear_color, 0.3f, 0.6f, 0.9f, 1.0f);
camera_set_primary_viewer(camera); camera_set_primary_viewer(camera);
@ -107,37 +108,50 @@ void scene_setup(void)
struct Model* box_model = entity_component_add(new_ent, C_MODEL, "default.pamesh", "Blinn_Phong"); struct Model* box_model = entity_component_add(new_ent, C_MODEL, "default.pamesh", "Blinn_Phong");
model_set_material_param(box_model, "diffuse_color", &color); model_set_material_param(box_model, "diffuse_color", &color);
struct Transform* model_tran = entity_component_get(new_ent, C_TRANSFORM); struct Transform* model_tran = entity_component_get(new_ent, C_TRANSFORM);
vec3 scale = {1, 1, 2}; vec3 scale = {1, 1, 1};
transform_scale(model_tran, &scale); transform_scale(model_tran, &scale);
struct Entity* suz = scene_add_as_child("Suzanne", NULL, new_ent->node); int parent_node = new_ent->node;
struct Model* suz_model = entity_component_add(suz, C_MODEL, "suzanne.pamesh", "Blinn_Phong"); int num_suz = 100;
model_set_material_param(suz_model, "diffuse_color", &color); srand(time(NULL));
struct Transform* s_tran = entity_component_get(suz, C_TRANSFORM); for(int i = 0; i < num_suz; i++)
vec3 s_pos = {3, 0, 0}; {
transform_translate(s_tran, &s_pos, TS_WORLD); int x = rand() % num_suz;
int y = rand() % num_suz;
int z = rand() % num_suz;
x++; y++; z++;
struct Entity* suz = scene_add_as_child("Suzanne", NULL, parent_node);
struct Model* suz_model = entity_component_add(suz, C_MODEL, "suzanne.pamesh", "Blinn_Phong");
model_set_material_param(suz_model, "diffuse_color", &color);
struct Transform* s_tran = entity_component_get(suz, C_TRANSFORM);
vec3 s_pos = {x, 5, z};
transform_translate(s_tran, &s_pos, TS_WORLD);
}
struct Entity* ground = scene_add_new("Ground", NULL); struct Entity* ground = scene_add_new("Ground", NULL);
struct Model* ground_model = entity_component_add(ground, C_MODEL, "default.pamesh", "Blinn_Phong"); struct Model* ground_model = entity_component_add(ground, C_MODEL, "plane.pamesh", "Blinn_Phong");
model_set_material_param(ground_model, "diffuse_color", &color); model_set_material_param(ground_model, "diffuse_color", &color);
int white_tex = texture_create_from_file("white.tga", TU_DIFFUSE);
model_set_material_param(ground_model, "diffuse_texture", &white_tex);
struct Transform* ground_tran = entity_component_get(ground, C_TRANSFORM); struct Transform* ground_tran = entity_component_get(ground, C_TRANSFORM);
vec3 pos = {0, -3, -3}; vec3 pos = {0, -15, 0};
vec3 scale_ground = {200.f, 0.2f, 200.f}; vec3 scale_ground = {200.f, 200.f, 200.f};
transform_set_position(ground_tran, &pos); transform_set_position(ground_tran, &pos);
transform_scale(ground_tran, &scale_ground); transform_scale(ground_tran, &scale_ground);
struct Entity* screen = scene_add_new("Screen", NULL); /* struct Entity* screen = scene_add_new("Screen", NULL); */
struct Model* screen_model = entity_component_add(screen, C_MODEL, NULL, NULL); /* struct Model* screen_model = entity_component_add(screen, C_MODEL, NULL, NULL); */
screen_model->geometry_index = geom_find("Quad"); /* screen_model->geometry_index = geom_find("Quad"); */
struct Entity* screen_camera = scene_add_as_child("Screen_Camera", NULL, screen->node); /* struct Entity* screen_camera = scene_add_as_child("Screen_Camera", NULL, screen->node); */
struct Transform* screen_camera_tran = entity_component_get(screen_camera, C_TRANSFORM); /* struct Transform* screen_camera_tran = entity_component_get(screen_camera, C_TRANSFORM); */
transform_rotate(screen_camera_tran, &UNIT_Y, 180.f, TS_WORLD); /* transform_rotate(screen_camera_tran, &UNIT_Y, 180.f, TS_WORLD); */
struct Camera* cam = entity_component_add(screen_camera, C_CAMERA, 1024, 1024); /* struct Camera* cam = entity_component_add(screen_camera, C_CAMERA, 50, 50); */
camera_attach_fbo(cam, 1024, 1024, 1, 1); /* camera_attach_fbo(cam, 50, 50, 1, 1); */
model_set_material_param(screen_model, "diffuse_color", &color); /* model_set_material_param(screen_model, "diffuse_color", &color); */
model_set_material_param(screen_model, "diffuse_texture", &cam->render_tex); /* model_set_material_param(screen_model, "diffuse_texture", &cam->render_tex); */
const int MAX_LIGHTS = 10; const int MAX_LIGHTS = 5;
for(int i = 0; i < MAX_LIGHTS; i++) for(int i = 0; i < MAX_LIGHTS; i++)
{ {
int x = rand() % MAX_LIGHTS; int x = rand() % MAX_LIGHTS;
@ -145,11 +159,16 @@ void scene_setup(void)
x++; z++; x++; z++;
struct Entity* light_ent = scene_add_new("Light_Ent", NULL); struct Entity* light_ent = scene_add_new("Light_Ent", NULL);
struct Transform* light_tran = entity_component_get(light_ent, C_TRANSFORM); struct Transform* light_tran = entity_component_get(light_ent, C_TRANSFORM);
vec3 lt_pos = {x * 2, 3, z * 2}; vec3 lt_pos = {x * 10, 3, z * 10};
transform_set_position(light_tran, &lt_pos); transform_set_position(light_tran, &lt_pos);
struct Light* light_comp = entity_component_add(light_ent, C_LIGHT, LT_POINT); struct Light* light_comp = entity_component_add(light_ent, C_LIGHT, LT_POINT);
vec4_fill(&light_comp->color, 1.f / (float)x, 1, 1.f / (float)z, 1); vec4_fill(&light_comp->color, 1.f / (float)x, 1.f / ((rand() % 10) + 1.f), 1.f / (float)z, 1);
light_comp->intensity = 0.2f;
} }
struct Entity* sun = scene_add_new("Sun", NULL);
struct Light* sun_light = entity_component_add(sun, C_LIGHT, LT_DIR);
sun_light->intensity = 0.8f;
} }
void debug(float dt) void debug(float dt)
@ -246,7 +265,7 @@ void debug(float dt)
if(input_key_state_get(GLFW_KEY_SPACE, GLFW_PRESS)) if(input_key_state_get(GLFW_KEY_SPACE, GLFW_PRESS))
{ {
struct Entity* model = scene_find("Screen"); struct Entity* model = scene_find("Model_Entity");
struct Transform* mod_tran = entity_component_get(model, C_TRANSFORM); struct Transform* mod_tran = entity_component_get(model, C_TRANSFORM);
vec3 x_axis = {1, 0, 0}; vec3 x_axis = {1, 0, 0};
transform_rotate(mod_tran, &x_axis, 25.f * dt, TS_WORLD); transform_rotate(mod_tran, &x_axis, 25.f * dt, TS_WORLD);
@ -254,7 +273,7 @@ void debug(float dt)
if(input_key_state_get(GLFW_KEY_M, GLFW_PRESS)) if(input_key_state_get(GLFW_KEY_M, GLFW_PRESS))
{ {
struct Entity* model = scene_find("Screen"); struct Entity* model = scene_find("Model_Entity");
struct Transform* mod_tran = entity_component_get(model, C_TRANSFORM); struct Transform* mod_tran = entity_component_get(model, C_TRANSFORM);
//vec3 y_axis = {0, 0, 1}; //vec3 y_axis = {0, 0, 1};
//transform_rotate(mod_tran, &y_axis, 25.f * dt, TS_LOCAL); //transform_rotate(mod_tran, &y_axis, 25.f * dt, TS_LOCAL);
@ -264,7 +283,7 @@ void debug(float dt)
if(input_key_state_get(GLFW_KEY_N, GLFW_PRESS)) if(input_key_state_get(GLFW_KEY_N, GLFW_PRESS))
{ {
struct Entity* model = scene_find("Screen"); struct Entity* model = scene_find("Model_Entity");
struct Transform* mod_tran = entity_component_get(model, C_TRANSFORM); struct Transform* mod_tran = entity_component_get(model, C_TRANSFORM);
/* vec3 y_axis = {0, 0, 1}; */ /* vec3 y_axis = {0, 0, 1}; */
/* transform_rotate(mod_tran, &y_axis, 25.f * dt, TS_WORLD); */ /* transform_rotate(mod_tran, &y_axis, 25.f * dt, TS_WORLD); */

@ -69,11 +69,11 @@ int light_create(int node, int light_type)
new_light->depth_bias = 0.0005f; new_light->depth_bias = 0.0005f;
new_light->type = light_type; new_light->type = light_type;
new_light->pcf_enabled = 0; new_light->pcf_enabled = 0;
new_light->intensity = 0.5f; new_light->intensity = 1.f;
new_light->falloff = 1.5f; new_light->falloff = 1.5f;
new_light->outer_angle = TO_RADIANS(30.f); new_light->outer_angle = TO_RADIANS(30.f);
new_light->inner_angle = TO_RADIANS(20.f); new_light->inner_angle = TO_RADIANS(20.f);
new_light->radius = 30; new_light->radius = 20;
return index; return index;
} }

@ -173,27 +173,44 @@ void model_render_all(struct Camera* camera)
struct Transform* transform = entity_component_get(light_entity, C_TRANSFORM); struct Transform* transform = entity_component_get(light_entity, C_TRANSFORM);
vec3 light_pos = {0, 0, 0}; vec3 light_pos = {0, 0, 0};
transform_get_absolute_pos(transform, &light_pos); transform_get_absolute_pos(transform, &light_pos);
if(light->type != LT_POINT)
{
snprintf(uniform_name, max_name_len, "lights[%d].direction", i);
transform_get_absolute_lookat(transform, &light_pos);
vec3_norm(&light_pos, &light_pos);
shader_set_uniform_vec3(material->shader, uniform_name, &light_pos);
memset(uniform_name, '\0', max_name_len);
}
if(light->type != LT_DIR)
{
snprintf(uniform_name, max_name_len, "lights[%d].position", i);
shader_set_uniform_vec3(material->shader, uniform_name, &light_pos);
memset(uniform_name, '\0', max_name_len);
snprintf(uniform_name, max_name_len, "lights[%d].outer_angle", i);
shader_set_uniform_float(material->shader, uniform_name, light->outer_angle);
memset(uniform_name, '\0', max_name_len);
snprintf(uniform_name, max_name_len, "lights[%d].position", i); snprintf(uniform_name, max_name_len, "lights[%d].inner_angle", i);
shader_set_uniform_vec3(material->shader, uniform_name, &light_pos); shader_set_uniform_float(material->shader, uniform_name, light->inner_angle);
memset(uniform_name, '\0', max_name_len); memset(uniform_name, '\0', max_name_len);
snprintf(uniform_name, max_name_len, "lights[%d].falloff", i);
shader_set_uniform_float(material->shader, uniform_name, light->falloff);
memset(uniform_name, '\0', max_name_len);
snprintf(uniform_name, max_name_len, "lights[%d].radius", i);
shader_set_uniform_int(material->shader, uniform_name, light->radius);
memset(uniform_name, '\0', max_name_len);
}
snprintf(uniform_name, max_name_len, "lights[%d].color", i); snprintf(uniform_name, max_name_len, "lights[%d].color", i);
shader_set_uniform_vec4(material->shader, uniform_name, &light->color); shader_set_uniform_vec4(material->shader, uniform_name, &light->color);
memset(uniform_name, '\0', max_name_len); memset(uniform_name, '\0', max_name_len);
snprintf(uniform_name, max_name_len, "lights[%d].outer_angle", i);
shader_set_uniform_float(material->shader, uniform_name, light->outer_angle);
memset(uniform_name, '\0', max_name_len);
snprintf(uniform_name, max_name_len, "lights[%d].inner_angle", i);
shader_set_uniform_float(material->shader, uniform_name, light->inner_angle);
memset(uniform_name, '\0', max_name_len);
snprintf(uniform_name, max_name_len, "lights[%d].falloff", i);
shader_set_uniform_float(material->shader, uniform_name, light->falloff);
memset(uniform_name, '\0', max_name_len);
snprintf(uniform_name, max_name_len, "lights[%d].intensity", i); snprintf(uniform_name, max_name_len, "lights[%d].intensity", i);
shader_set_uniform_float(material->shader, uniform_name, light->intensity); shader_set_uniform_float(material->shader, uniform_name, light->intensity);
memset(uniform_name, '\0', max_name_len); memset(uniform_name, '\0', max_name_len);
@ -201,10 +218,6 @@ void model_render_all(struct Camera* camera)
snprintf(uniform_name, max_name_len, "lights[%d].type", i); snprintf(uniform_name, max_name_len, "lights[%d].type", i);
shader_set_uniform_int(material->shader, uniform_name, light->type); shader_set_uniform_int(material->shader, uniform_name, light->type);
memset(uniform_name, '\0', max_name_len); memset(uniform_name, '\0', max_name_len);
snprintf(uniform_name, max_name_len, "lights[%d].radius", i);
shader_set_uniform_int(material->shader, uniform_name, light->radius);
memset(uniform_name, '\0', max_name_len);
} }
shader_set_uniform_int(material->shader, "total_active_lights", valid_light_count); shader_set_uniform_int(material->shader, "total_active_lights", valid_light_count);
@ -268,7 +281,6 @@ int model_set_material_param(struct Model* model, const char* name, void* value)
mat4_assign((mat4*)param->value, (mat4*)value); mat4_assign((mat4*)param->value, (mat4*)value);
break; break;
case UT_TEX: case UT_TEX:
log_message("Tex Val : %d", *((int*)value));
*((int*)param->value) = *((int*)value); *((int*)param->value) = *((int*)value);
break; break;
default: default:

@ -17,15 +17,9 @@
#include "transform.h" #include "transform.h"
static int def_fbo = -1; static int def_fbo = -1;
static int light_fbo = -1;
static int light_tex = -1;
static int def_albedo_tex = -1; static int def_albedo_tex = -1;
static int def_position_tex = -1;
static int def_normal_tex = -1;
static int def_uv_tex = -1;
static int def_depth_tex = -1; static int def_depth_tex = -1;
static int quad_geo = -1; static int quad_geo = -1;
static int fbo_shader = -1;
static int composition_shader = -1; static int composition_shader = -1;
void on_framebuffer_size_change(GLFWwindow* window, int width, int height); void on_framebuffer_size_change(GLFWwindow* window, int width, int height);
@ -69,7 +63,6 @@ void renderer_init(GLFWwindow* window)
array_free(normals); array_free(normals);
array_free(indices); array_free(indices);
/* Textues for default fbo */
int width = -1, height = -1; int width = -1, height = -1;
window_get_size(&width, &height); window_get_size(&width, &height);
def_albedo_tex = texture_create("def_albedo_texture", def_albedo_tex = texture_create("def_albedo_texture",
@ -81,44 +74,8 @@ void renderer_init(GLFWwindow* window)
NULL); NULL);
texture_set_param(def_albedo_tex, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 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_WRAP_T, GL_CLAMP_TO_EDGE);
texture_set_param(def_albedo_tex, GL_TEXTURE_MIN_FILTER, GL_NEAREST); texture_set_param(def_albedo_tex, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
texture_set_param(def_albedo_tex, GL_TEXTURE_MAG_FILTER, GL_NEAREST); texture_set_param(def_albedo_tex, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
def_position_tex = texture_create("def_position_texture",
TU_SHADOWMAP1,
width, height,
GL_RGB,
GL_RGB16F,
GL_FLOAT,
NULL);
texture_set_param(def_position_tex, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
texture_set_param(def_position_tex, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
texture_set_param(def_position_tex, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
texture_set_param(def_position_tex, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
def_normal_tex = texture_create("def_normal_texture",
TU_SHADOWMAP2,
width, height,
GL_RGB,
GL_RGB16F,
GL_FLOAT,
NULL);
texture_set_param(def_normal_tex, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
texture_set_param(def_normal_tex, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
texture_set_param(def_normal_tex, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
texture_set_param(def_normal_tex, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
def_uv_tex = texture_create("def_uv_texture",
TU_SHADOWMAP3,
width, height,
GL_RGB,
GL_RGB16F,
GL_FLOAT,
NULL);
texture_set_param(def_uv_tex, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
texture_set_param(def_uv_tex, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
texture_set_param(def_uv_tex, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
texture_set_param(def_uv_tex, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
def_depth_tex = texture_create("def_depth_texture", def_depth_tex = texture_create("def_depth_texture",
TU_SHADOWMAP4, TU_SHADOWMAP4,
@ -136,28 +93,8 @@ void renderer_init(GLFWwindow* window)
def_fbo = framebuffer_create(width, height, 1, 1); def_fbo = framebuffer_create(width, height, 1, 1);
framebuffer_set_texture(def_fbo, def_albedo_tex, GL_COLOR_ATTACHMENT0); framebuffer_set_texture(def_fbo, def_albedo_tex, GL_COLOR_ATTACHMENT0);
/* framebuffer_set_texture(def_fbo, def_position_tex, GL_COLOR_ATTACHMENT0 + 1); */
/* framebuffer_set_texture(def_fbo, def_normal_tex, GL_COLOR_ATTACHMENT0 + 2); */
/* framebuffer_set_texture(def_fbo, def_uv_tex, GL_COLOR_ATTACHMENT0 + 3); */
framebuffer_set_texture(def_fbo, def_depth_tex, GL_DEPTH_ATTACHMENT); framebuffer_set_texture(def_fbo, def_depth_tex, GL_DEPTH_ATTACHMENT);
light_tex = texture_create("light_tex",
TU_SHADOWMAP1,
width, height,
GL_RGB,
GL_RGB16F,
GL_FLOAT,
NULL);
texture_set_param(light_tex, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
texture_set_param(light_tex, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
texture_set_param(light_tex, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
texture_set_param(light_tex, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
light_fbo = framebuffer_create(width, height, 0, 1);
framebuffer_set_texture(light_fbo, light_tex, GL_COLOR_ATTACHMENT0);
composition_shader = shader_create("fbo.vert", "fbo.frag"); composition_shader = shader_create("fbo.vert", "fbo.frag");
//fbo_shader = shader_create("deferred_light.vert", "deferred_light.frag");
} }
void renderer_draw(void) void renderer_draw(void)
@ -173,11 +110,6 @@ void renderer_draw(void)
framebuffer_bind(fbo); framebuffer_bind(fbo);
{ {
glViewport(0, 0, framebuffer_get_width(fbo), framebuffer_get_height(fbo)); glViewport(0, 0, framebuffer_get_width(fbo), framebuffer_get_height(fbo));
/* GLenum draw_buffers[] = {GL_COLOR_ATTACHMENT0, */
/* GL_COLOR_ATTACHMENT1, */
/* GL_COLOR_ATTACHMENT2, */
/* GL_COLOR_ATTACHMENT3}; */
/* glDrawBuffers(4, &draw_buffers[0]); */
glDrawBuffer(GL_COLOR_ATTACHMENT0); glDrawBuffer(GL_COLOR_ATTACHMENT0);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL); glDepthFunc(GL_LEQUAL);
@ -198,147 +130,12 @@ void renderer_draw(void)
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
shader_bind(composition_shader); shader_bind(composition_shader);
struct Camera* active_camera = camera_get_primary();
//shader_set_uniform_int(composition_shader, "albedo_map", (GL_TEXTURE0 + TU_DIFFUSE) - GL_TEXTURE0); int final_render_tex = active_camera->render_tex == -1 ? def_albedo_tex : active_camera->render_tex;
texture_bind(def_albedo_tex); texture_bind(final_render_tex);
geom_render(quad_geo); geom_render(quad_geo);
shader_unbind(); shader_unbind();
texture_unbind(final_render_tex);
texture_unbind(def_albedo_tex);
/* int width, height; */
/* window_get_size(&width, &height); */
/* struct Camera* active_camera = camera_get_primary(); */
/* struct Entity* camera_entity = entity_get(active_camera->node); */
/* struct Transform* camera_tran = entity_component_get(camera_entity, C_TRANSFORM); */
/* framebuffer_bind(light_fbo); */
/* { */
/* glViewport(0, 0, width, height); */
/* glClearColor(0.f, 0.f, 0.f, 1.0f); */
/* glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); */
/* //glEnable(GL_BLEND); */
/* //glEnable(GL_DEPTH_TEST ); */
/* /\* glDisable(GL_DEPTH_TEST ); *\/ */
/* /\* glEnable(GL_CULL_FACE ); *\/ */
/* /\* glCullFace(GL_BACK); *\/ */
/* /\* glDepthFunc(GL_LEQUAL); *\/ */
/* /\* glBlendEquation(GL_FUNC_ADD); *\/ */
/* /\* glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); *\/ */
/* /\* uint gbuffer_fbo_handle = 0; *\/ */
/* /\* gbuffer_fbo_handle = framebuffer_get_gl_handle(def_fbo); *\/ */
/* /\* glBindFramebuffer(GL_READ_FRAMEBUFFER, gbuffer_fbo_handle); *\/ */
/* /\* glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); *\/ */
/* /\* glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_DEPTH_BUFFER_BIT, GL_NEAREST); *\/ */
/* /\* glBindFramebuffer(GL_FRAMEBUFFER, 0); *\/ */
/* shader_bind(fbo_shader); */
/* vec3 camera_pos = {0, 0, 0}; */
/* transform_get_absolute_pos(camera_tran, &camera_pos); */
/* shader_set_uniform_vec3(fbo_shader, "camera_pos", &camera_pos); */
/* shader_set_uniform_int(fbo_shader, "albedo_map", (GL_TEXTURE0 + TU_DIFFUSE) - GL_TEXTURE0); */
/* texture_bind(def_albedo_tex); */
/* shader_set_uniform_int(fbo_shader, "position_map", (GL_TEXTURE0 + TU_SHADOWMAP1) - GL_TEXTURE0); */
/* texture_bind(def_position_tex); */
/* shader_set_uniform_int(fbo_shader, "normal_map", (GL_TEXTURE0 + TU_SHADOWMAP2) - GL_TEXTURE0); */
/* texture_bind(def_normal_tex); */
/* /\* shader_set_uniform_int(fbo_shader, "depth_map", (GL_TEXTURE0 + TU_SHADOWMAP4) - GL_TEXTURE0); *\/ */
/* /\* texture_bind(def_depth_tex); *\/ */
/* /\* shader_set_uniform_int(fbo_shader, "uv_map", (GL_TEXTURE0 + TU_SHADOWMAP3) - GL_TEXTURE0); *\/ */
/* /\* texture_bind(def_uv_tex); *\/ */
/* struct Light* active_lights = light_get_all(); */
/* int sphere_geo = geom_find("sphere.pamesh"); */
/* mat4 mvp; */
/* struct Transform sphere_tran; */
/* vec2 screen_size = {width, height}; */
/* shader_set_uniform_vec2(fbo_shader, "screen_size", &screen_size); */
/* for(int i = 0; i < array_len(active_lights); i++) */
/* { */
/* if(i == 0) */
/* glBlendFunc(GL_ZERO, GL_ONE); */
/* else */
/* glBlendFunc(GL_ONE, GL_ONE); */
/* /\* Set light uniform *\/ */
/* struct Light* light = light_get(i); /\* TODO: Remove this and do it properly *\/ */
/* struct Entity* light_entity = entity_get(light->node); */
/* struct Transform* transform = entity_component_get(light_entity, C_TRANSFORM); */
/* vec3 light_pos = {0, 0, 0}; */
/* transform_get_absolute_pos(transform, &light_pos); */
/* shader_set_uniform_vec3(fbo_shader, "light.position", &light_pos); */
/* shader_set_uniform_vec4(fbo_shader, "light.color", &light->color); */
/* shader_set_uniform_float(fbo_shader, "light.outer_angle", light->outer_angle); */
/* shader_set_uniform_float(fbo_shader, "light.inner_angle", light->inner_angle); */
/* shader_set_uniform_float(fbo_shader, "light.falloff", light->falloff); */
/* shader_set_uniform_float(fbo_shader, "light.intensity", light->intensity); */
/* shader_set_uniform_int(fbo_shader, "light.type", light->type); */
/* shader_set_uniform_int(fbo_shader, "light.radius", light->radius); */
/* /\* vec2 planes = {active_camera->nearz, active_camera->farz}; *\/ */
/* /\* //vec2 planes = {active_camera->farz, active_camera->nearz}; *\/ */
/* /\* shader_set_uniform_vec2(fbo_shader, "planes", &planes); *\/ */
/* mat4_identity(&mvp); */
/* transform_set_position(&sphere_tran, &light_pos); */
/* vec3 light_scale = {light->radius, light->radius, light->radius}; */
/* transform_scale(&sphere_tran, &light_scale); */
/* mat4_mul(&mvp, &active_camera->view_proj_mat, &sphere_tran.trans_mat); */
/* shader_set_uniform_mat4(fbo_shader, "mvp", &mvp); */
/* /\* mat4 inv_proj_mat; *\/ */
/* /\* mat4_identity(&inv_proj_mat); *\/ */
/* /\* mat4_inverse(&inv_proj_mat, &active_camera->view_proj_mat); *\/ */
/* /\* shader_set_uniform_mat4(fbo_shader, "inv_proj_mat", &inv_proj_mat); *\/ */
/* geom_render(quad_geo); */
/* //geom_render(sphere_geo); */
/* } */
/* //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); */
/* glDisable(GL_BLEND); */
/* } */
/* framebuffer_unbind(); */
} }
void renderer_cleanup(void) void renderer_cleanup(void)

Loading…
Cancel
Save