From f9ad6fa902c1167d7622ee7af2617d14b62bee21 Mon Sep 17 00:00:00 2001 From: pryazha Date: Wed, 19 Feb 2025 22:26:48 +0500 Subject: quite a lot of changes that I, of course, are not going to describe;) --- .../2.gamma_correction/gamma_correction.c | 450 ++++++++------------- .../2.gamma_correction/shaders/blinn_phong.frag | 55 +++ .../2.gamma_correction/shaders/blinn_phong.fs | 58 --- .../2.gamma_correction/shaders/blinn_phong.vert | 22 + .../2.gamma_correction/shaders/blinn_phong.vs | 23 -- .../2.gamma_correction/shaders/light.frag | 8 + .../2.gamma_correction/shaders/light.fs | 9 - .../2.gamma_correction/shaders/light.vert | 11 + .../2.gamma_correction/shaders/light.vs | 12 - 9 files changed, 258 insertions(+), 390 deletions(-) create mode 100644 advanced_lighting/2.gamma_correction/shaders/blinn_phong.frag delete mode 100644 advanced_lighting/2.gamma_correction/shaders/blinn_phong.fs create mode 100644 advanced_lighting/2.gamma_correction/shaders/blinn_phong.vert delete mode 100644 advanced_lighting/2.gamma_correction/shaders/blinn_phong.vs create mode 100644 advanced_lighting/2.gamma_correction/shaders/light.frag delete mode 100644 advanced_lighting/2.gamma_correction/shaders/light.fs create mode 100644 advanced_lighting/2.gamma_correction/shaders/light.vert delete mode 100644 advanced_lighting/2.gamma_correction/shaders/light.vs (limited to 'advanced_lighting/2.gamma_correction') diff --git a/advanced_lighting/2.gamma_correction/gamma_correction.c b/advanced_lighting/2.gamma_correction/gamma_correction.c index 68edae7..a027722 100644 --- a/advanced_lighting/2.gamma_correction/gamma_correction.c +++ b/advanced_lighting/2.gamma_correction/gamma_correction.c @@ -1,297 +1,171 @@ -#include "pwyazh.h" - #include "GL/glew.h" #include "GLFW/glfw3.h" +#include "pwyazh.h" #include "pwyazh_GL.h" #include "common.h" -static S32 global_width = 1024, global_height = 768; -static Input global_input; -static V3F camera_dp = (V3F){ 0.0f, 0.0f, 0.0f }; -static V3F light_pos = (V3F){ 0.0f, 0.0f, 0.0f }; -static U32 gamma_correction = 0; - -static V3F light_positions[] = { - (V3F){-3.0f, 0.0f, 0.0f}, - (V3F){-1.0f, 0.0f, 0.0f}, - (V3F){1.0f, 0.0f, 0.0f}, - (V3F){3.0f, 0.0f, 0.0} -}; -static V3F light_colors[] = { - (V3F){0.25f, 0.25f, 0.25f}, - (V3F){0.50f, 0.50f, 0.50f}, - (V3F){0.75f, 0.75f, 0.75f}, - (V3F){1.0f, 1.0f, 1.0} -}; - -void -key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) -{ - switch (action) - { - case GLFW_PRESS: { - switch (key) - { - case GLFW_KEY_D: { - global_input.move_right.state = KeyState_PRESS; - } break; - case GLFW_KEY_W: { - global_input.move_forward.state = KeyState_PRESS; - } break; - case GLFW_KEY_A: { - global_input.move_left.state = KeyState_PRESS; - } break; - case GLFW_KEY_S: { - global_input.move_backward.state = KeyState_PRESS; - } break; - case GLFW_KEY_E: { - global_input.move_up.state = KeyState_PRESS; - } break; - case GLFW_KEY_Q: { - global_input.move_down.state = KeyState_PRESS; - } break; - case GLFW_KEY_SPACE: { - global_input.jump.state = KeyState_PRESS; - } break; - case GLFW_KEY_RIGHT: { - global_input.action_right.state = KeyState_PRESS; - } break; - case GLFW_KEY_UP: { - global_input.action_up.state = KeyState_PRESS; - } break; - case GLFW_KEY_LEFT: { - global_input.action_left.state = KeyState_PRESS; - } break; - case GLFW_KEY_ESCAPE: { - global_input.exit.state = KeyState_PRESS; - } break; - } - } break; - - case GLFW_RELEASE: { - switch (key) - { - case GLFW_KEY_D: { - global_input.move_right.state = KeyState_RELEASE; - } break; - case GLFW_KEY_W: { - global_input.move_forward.state = KeyState_RELEASE; - } break; - case GLFW_KEY_A: { - global_input.move_left.state = KeyState_RELEASE; - } break; - case GLFW_KEY_S: { - global_input.move_backward.state = KeyState_RELEASE; - } break; - case GLFW_KEY_E: { - global_input.move_up.state = KeyState_RELEASE; - } break; - case GLFW_KEY_Q: { - global_input.move_down.state = KeyState_RELEASE; - } break; - case GLFW_KEY_SPACE: { - global_input.jump.state = KeyState_RELEASE; - } break; - case GLFW_KEY_RIGHT: { - global_input.action_right.state = KeyState_RELEASE; - } break; - case GLFW_KEY_UP: { - global_input.action_up.state = KeyState_RELEASE; - } break; - case GLFW_KEY_LEFT: { - global_input.action_left.state = KeyState_RELEASE; - } break; - case GLFW_KEY_ESCAPE: { - global_input.exit.state = KeyState_RELEASE; - } break; - } - } break; - } -} - -void -resize_callback(GLFWwindow* window, int width, int height) -{ - global_width = width; - global_height = height; - glViewport(0, 0, global_width, global_height); -} - -void -error_callback(int error, const char *desc) -{ - fprintf(stderr, "[ERROR] GLFW: %s\n", desc); -} - -void -update(State *state) -{ - V3F camera_dv = get_dv_camera_orbital(&global_input, state->camera.pos, - v3f_zero(), state->dt, 2.0f); - if (key_is_pressed(global_input.action_up)) - camera_dv = v3f_scalef(camera_dv, 3.0f); - camera_dp = v3f_add(camera_dp, camera_dv); - camera_dp = v3f_scalef(camera_dp, 0.7f); - state->camera.pos = v3f_add(state->camera.pos, camera_dp); - - if (key_first_press(global_input.action_right)) - gamma_correction = !gamma_correction; - - F32 time = glfwGetTime(); - for (S32 position_index = 0; - position_index < (S32)ArrayCount(light_positions); - position_index++) - { - F32 radius = position_index*2.0+2.0; - F32 angle = time*position_index*pi_F32/6.0; - F32 x = f32_sin(angle)*radius; - F32 z = f32_cos(angle)*radius; - light_positions[position_index] = v3f(x, light_positions[position_index].y, z); - } - - input_update_last_state(&global_input); -} - -void -render(State *state, U32 *shaders, U32 texture, U32 texture_gamma_corrected, Mesh **meshes) -{ - MAT4 projection, view, model; - U32 shader; - Mesh *mesh; - - glClearColor(0.15f, 0.15f, 0.15f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - projection = perspective(state->camera.fovx, (F32)global_width/(F32)global_height, - state->camera.near, state->camera.far); - view = look_at(state->camera.pos, v3f_zero(), v3f(0.0f, 1.0f, 0.0f)); - model = mat4_identity(); - - U32 mesh_index = 0; - shader = shaders[mesh_index]; - mesh = meshes[mesh_index]; - glUseProgram(shader); - shader_set_mat4fv(shader, "projection", projection); - shader_set_mat4fv(shader, "view", view); - shader_set_mat4fv(shader, "model", model); - if (gamma_correction) - glBindTexture(GL_TEXTURE_2D, texture_gamma_corrected); - else - glBindTexture(GL_TEXTURE_2D, texture); - shader_set_3fv(shader, "light_pos", light_pos); - shader_set_3fv(shader, "view_pos", state->camera.pos); - shader_set_1i(shader, "gamma_correction", gamma_correction); - U32 light_positions_location = glGetUniformLocation(shader, "light_positions"); - glUniform3fv(light_positions_location, 4, (F32 *)&light_positions[0]); - U32 light_colors_location = glGetUniformLocation(shader, "light_colors"); - glUniform3fv(light_colors_location, 4, (F32 *)&light_colors[0]); - mesh_draw(mesh); - mesh_index++; - - shader = shaders[mesh_index]; - mesh = meshes[mesh_index]; - glUseProgram(shader); - shader_set_mat4fv(shader, "projection", projection); - shader_set_mat4fv(shader, "view", view); - for (S32 light_index = 0; - light_index < (S32)ArrayCount(light_positions); - light_index++) - { - model = mat4_make_scale(v3f(0.1f, 0.1f, 0.1f)); - model = mat4_translate(model, light_positions[light_index]); - shader_set_mat4fv(shader, "model", model); - mesh_draw(mesh); - } - glBindTexture(GL_TEXTURE_2D, 0); -} - -int -main(void) +int main(void) { - GLFWwindow *window; - Arena *arena; - State state; - Mesh *meshes[2]; - U32 shaders[2]; - F64 time, last_time; - U32 texture, texture_gamma_corrected; - - glfwSetErrorCallback(error_callback); - - if (glfwInit() == GLFW_FALSE) - return(1); - - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); - glfwWindowHint(GLFW_SAMPLES, 4); - window = glfwCreateWindow(global_width, global_height, "Gamma correction", 0, 0); - if (!window) - goto error; - - glfwSetKeyCallback(window, key_callback); - glfwSetWindowSizeCallback(window, resize_callback); - - glfwMakeContextCurrent(window); - - if (glewInit() != GLEW_OK) - goto error; - - glEnable(GL_DEPTH_TEST); - glEnable(GL_MULTISAMPLE); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - /* NOTE(pryazha): A less controlled method of applying gamma correction */ - /* glEnable(GL_FRAMEBUFFER_SRGB); */ - - /* NOTE(pryazha): init */ - arena = arena_alloc(Megabytes(64)); - - state.camera = (Camera){ v3f(0.0f, 0.0f, 3.0f), 90.0f, 0.1f, 1000.0f }; - - Vertex vertices[] = { - // positions // normals // texcoords - vertex(v3f( 10.0f, -0.5f, 10.0f), v3f(0.0f, 1.0f, 0.0f), v2f(10.0f, 0.0f)), - vertex(v3f(-10.0f, -0.5f, 10.0f), v3f(0.0f, 1.0f, 0.0f), v2f( 0.0f, 0.0f)), - vertex(v3f(-10.0f, -0.5f, -10.0f), v3f(0.0f, 1.0f, 0.0f), v2f( 0.0f, 10.0f)), - - vertex(v3f( 10.0f, -0.5f, 10.0f), v3f(0.0f, 1.0f, 0.0f), v2f(10.0f, 0.0f)), - vertex(v3f(-10.0f, -0.5f, -10.0f), v3f(0.0f, 1.0f, 0.0f), v2f( 0.0f, 10.0f)), - vertex(v3f( 10.0f, -0.5f, -10.0f), v3f(0.0f, 1.0f, 0.0f), v2f(10.0f, 10.0f)) - }; - U32 indices[] = { 0, 1, 2, 3, 4, 5 }; - meshes[0] = mesh_init(arena, vertices, 6, indices, 6); - meshes[1] = mesh_load_obj(arena, "../../data/models/cube.obj"); - - shaders[0] = create_shader_program("shaders/blinn_phong.vs", "shaders/blinn_phong.fs"); - shaders[1] = create_shader_program("shaders/light.vs", "shaders/light.fs"); - - texture = load_texture_gamma("../../data/textures/wood.png", 0); - texture_gamma_corrected = load_texture_gamma("../../data/textures/wood.png", 1); - - last_time = glfwGetTime(); - - while (!glfwWindowShouldClose(window)) - { - glfwPollEvents(); - if (key_first_press(global_input.exit)) - glfwSetWindowShouldClose(window, GLFW_TRUE); - update(&state); - render(&state, shaders, texture, texture_gamma_corrected, meshes); - glfwSwapBuffers(window); - - time = glfwGetTime(); - state.dt = time-last_time; - last_time = time; -#if 0 - fprintf(stdout, "[INFO]: dt: %f\n", state.dt); -#endif - } - - glfwTerminate(); - return(0); - - error: - glfwTerminate(); - return(1); + GLFWwindow *window; + Arena *arena; + State state; + Input input; + F64 time, last_time; + V3F light_pos = (V3F){ 0.0f, 0.0f, 0.0f }; + U32 gamma_correction = 0; + MAT4 proj, view, model; + S32 width, height; + B32 blinn; + + V3F light_positions[] = { + (V3F){-3.0f, 0.0f, 0.0f}, + (V3F){-1.0f, 0.0f, 0.0f}, + (V3F){1.0f, 0.0f, 0.0f}, + (V3F){3.0f, 0.0f, 0.0} + }; + V3F light_colors[] = { + (V3F){0.25f, 0.25f, 0.25f}, + (V3F){0.50f, 0.50f, 0.50f}, + (V3F){0.75f, 0.75f, 0.75f}, + (V3F){1.0f, 1.0f, 1.0} + }; + + glfwSetErrorCallback(error_callback); + + if (glfwInit() == GLFW_FALSE) + return(1); + + width = 1024; + height = 768; + + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); + glfwWindowHint(GLFW_SAMPLES, 4); + window = glfwCreateWindow(width, height, "Gamma correction", 0, 0); + if (!window) + goto error; + + glfwMakeContextCurrent(window); + + if (glewInit() != GLEW_OK) + goto error; + + glEnable(GL_DEPTH_TEST); + glEnable(GL_MULTISAMPLE); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + /* NOTE(pryazha): A less controlled method of applying gamma correction */ + /* glEnable(GL_FRAMEBUFFER_SRGB); */ + + /* NOTE(pryazha): init */ + arena = arena_alloc(Megabytes(64)); + + state.camera = (Camera){ v3f(0.0f, 0.0f, 3.0f), 90.0f, 0.1f, 1000.0f, 0.0f, 0.0f }; + + Vertex vertices[] = { + // positions // normals // texcoords + vertex(v3f( 10.0f, -0.5f, 10.0f), v3f(0.0f, 1.0f, 0.0f), v2f(10.0f, 0.0f)), + vertex(v3f(-10.0f, -0.5f, 10.0f), v3f(0.0f, 1.0f, 0.0f), v2f( 0.0f, 0.0f)), + vertex(v3f(-10.0f, -0.5f, -10.0f), v3f(0.0f, 1.0f, 0.0f), v2f( 0.0f, 10.0f)), + + vertex(v3f( 10.0f, -0.5f, 10.0f), v3f(0.0f, 1.0f, 0.0f), v2f(10.0f, 0.0f)), + vertex(v3f(-10.0f, -0.5f, -10.0f), v3f(0.0f, 1.0f, 0.0f), v2f( 0.0f, 10.0f)), + vertex(v3f( 10.0f, -0.5f, -10.0f), v3f(0.0f, 1.0f, 0.0f), v2f(10.0f, 10.0f)) + }; + U32 indices[] = { 0, 1, 2, 3, 4, 5 }; + Mesh *quad = mesh_init(arena, vertices, 6, indices, 6); + Mesh *cube = mesh_load_obj(arena, "../../data/models/cube.obj"); + + U32 blinn_phong_shader = create_shader_program("shaders/blinn_phong.vert", "shaders/blinn_phong.frag"); + U32 light_shader = create_shader_program("shaders/light.vert", "shaders/light.frag"); + + U32 texture = load_texture_gamma("../../data/textures/wood.png", 0); + U32 texture_gamma_corrected = load_texture_gamma("../../data/textures/wood.png", 1); + + last_time = glfwGetTime(); + + while (!glfwWindowShouldClose(window)) { + glfwPollEvents(); + + /* NOTE(pryazha): Update */ + process_glfw_keyboard(window, &input); + glfwGetFramebufferSize(window, &width, &height); + + V3F target = v3f_zero(); + + if (key_first_press(input.exit)) + glfwSetWindowShouldClose(window, GLFW_TRUE); + + if (key_first_press(input.jump)) + blinn = blinn ? 0 : 1; + + V3F dv = get_dv_camera_orbital(&input, state.camera.pos, + target, state.dt, 3.0f); + state.camera.pos = v3f_add(state.camera.pos, dv); + + if (key_first_press(input.action_right)) + gamma_correction = !gamma_correction; + + for (S32 i = 0; i < (S32)ArrayCount(light_positions); i++) { + F32 radius = i*2.0+2.0; + F32 angle = time*i*pi_F32/6.0; + F32 x = f32_sin(angle)*radius; + F32 z = f32_cos(angle)*radius; + light_positions[i] = v3f(x, light_positions[i].y, z); + } + + input_update_last_state(&input); + + proj = perspective(state.camera.fovx, (F32)width/(F32)height, + state.camera.near, state.camera.far); + view = look_at(state.camera.pos, v3f_zero(), v3f(0.0f, 1.0f, 0.0f)); + model = mat4_identity(); + + /* NOTE(pryazha): Render */ + glViewport(0, 0, width, height); + glClearColor(0.15f, 0.15f, 0.15f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glUseProgram(blinn_phong_shader); + shader_set_mat4fv(blinn_phong_shader, "proj", proj); + shader_set_mat4fv(blinn_phong_shader, "view", view); + shader_set_mat4fv(blinn_phong_shader, "model", model); + if (gamma_correction) + glBindTexture(GL_TEXTURE_2D, texture_gamma_corrected); + else + glBindTexture(GL_TEXTURE_2D, texture); + shader_set_3fv(blinn_phong_shader, "light_pos", light_pos); + shader_set_3fv(blinn_phong_shader, "view_pos", state.camera.pos); + shader_set_1i(blinn_phong_shader, "gamma_correction", gamma_correction); + U32 light_positions_location = glGetUniformLocation(blinn_phong_shader, "light_positions"); + glUniform3fv(light_positions_location, 4, (F32 *)&light_positions[0]); + U32 light_colors_location = glGetUniformLocation(blinn_phong_shader, "light_colors"); + glUniform3fv(light_colors_location, 4, (F32 *)&light_colors[0]); + mesh_draw(quad); + + glUseProgram(light_shader); + shader_set_mat4fv(light_shader, "proj", proj); + shader_set_mat4fv(light_shader, "view", view); + for (S32 i = 0; i < (S32)ArrayCount(light_positions); i++) { + model = mat4_make_scale(v3f(0.1f, 0.1f, 0.1f)); + model = mat4_translate(model, light_positions[i]); + shader_set_mat4fv(light_shader, "model", model); + mesh_draw(cube); + } + glBindTexture(GL_TEXTURE_2D, 0); + + glfwSwapBuffers(window); + + time = glfwGetTime(); + state.dt = time-last_time; + last_time = time; + } + + glfwTerminate(); + return(0); + +error: + glfwTerminate(); + return(1); } diff --git a/advanced_lighting/2.gamma_correction/shaders/blinn_phong.frag b/advanced_lighting/2.gamma_correction/shaders/blinn_phong.frag new file mode 100644 index 0000000..331fc8b --- /dev/null +++ b/advanced_lighting/2.gamma_correction/shaders/blinn_phong.frag @@ -0,0 +1,55 @@ +#version 330 core + +in VS_OUT { + vec3 frag_pos; + vec3 normal; + vec2 tex_coords; +} fs_in; + +out vec4 frag_color; + +uniform sampler2D texture0; +uniform vec3 light_positions[4]; +uniform vec3 light_colors[4]; +uniform vec3 view_pos; +uniform bool gamma_correction; + +vec3 blinn_phong(vec3 light_dir, vec3 view_dir, vec3 normal, + vec3 light_pos, vec3 light_color) +{ + float diff = max(dot(normal, light_dir), 0.0); + vec3 diffuse = diff*light_color; + + vec3 halfway_dir = normalize(light_dir+view_dir); + float spec = pow(max(dot(normal, halfway_dir), 0.0), 16.0); + vec3 specular = spec*light_color; + + float distance = length(light_pos-fs_in.frag_pos); + float attenuation = 1.0/(gamma_correction ? distance*distance : distance); + + return((diffuse+specular)*attenuation); +} + +void main(void) +{ + vec3 view_dir = normalize(view_pos-fs_in.frag_pos); + vec3 normal = normalize(fs_in.normal); + vec3 texture_color = texture(texture0, fs_in.tex_coords).rgb; + + vec3 lighting = vec3(0.0); + for (int i = 0; i < 4; i++) { + vec3 light_pos = light_positions[i]; + vec3 light_color = light_colors[i]; + vec3 light_dir = normalize(light_pos-fs_in.frag_pos); + lighting += blinn_phong(light_dir, view_dir, normal, + light_pos, light_color); + } + + texture_color *= lighting; + + float gamma = 2.2; + if (gamma_correction) + texture_color = pow(texture_color, vec3(1.0/gamma)); + + frag_color = vec4(texture_color, 1.0); +} diff --git a/advanced_lighting/2.gamma_correction/shaders/blinn_phong.fs b/advanced_lighting/2.gamma_correction/shaders/blinn_phong.fs deleted file mode 100644 index 35e701c..0000000 --- a/advanced_lighting/2.gamma_correction/shaders/blinn_phong.fs +++ /dev/null @@ -1,58 +0,0 @@ -#version 330 core - -in VS_OUT { - vec3 frag_pos; - vec3 normal; - vec2 tex_coords; -} fs_in; - -out vec4 frag_color; - -uniform sampler2D texture0; -uniform vec3 light_positions[4]; -uniform vec3 light_colors[4]; -uniform vec3 view_pos; -uniform bool gamma_correction; - -vec3 -blinn_phong(vec3 light_dir, vec3 view_dir, vec3 normal, - vec3 light_pos, vec3 light_color) -{ - float diff = max(dot(normal, light_dir), 0.0); - vec3 diffuse = diff*light_color; - - vec3 halfway_dir = normalize(light_dir+view_dir); - float spec = pow(max(dot(normal, halfway_dir), 0.0), 16.0); - vec3 specular = spec*light_color; - - float distance = length(light_pos-fs_in.frag_pos); - float attenuation = 1.0/(gamma_correction ? distance*distance : distance); - - return((diffuse+specular)*attenuation); -} - -void -main(void) -{ - vec3 view_dir = normalize(view_pos-fs_in.frag_pos); - vec3 normal = normalize(fs_in.normal); - vec3 texture_color = texture(texture0, fs_in.tex_coords).rgb; - - vec3 lighting = vec3(0.0); - for (int i = 0; i < 4; i++) - { - vec3 light_pos = light_positions[i]; - vec3 light_color = light_colors[i]; - vec3 light_dir = normalize(light_pos-fs_in.frag_pos); - lighting += blinn_phong(light_dir, view_dir, normal, - light_pos, light_color); - } - - texture_color *= lighting; - - float gamma = 2.2; - if (gamma_correction) - texture_color = pow(texture_color, vec3(1.0/gamma)); - - frag_color = vec4(texture_color, 1.0); -} diff --git a/advanced_lighting/2.gamma_correction/shaders/blinn_phong.vert b/advanced_lighting/2.gamma_correction/shaders/blinn_phong.vert new file mode 100644 index 0000000..870e7dc --- /dev/null +++ b/advanced_lighting/2.gamma_correction/shaders/blinn_phong.vert @@ -0,0 +1,22 @@ +#version 330 core +layout(location = 0) in vec3 apos; +layout(location = 1) in vec3 anormal; +layout(location = 2) in vec2 atex_coords; + +out VS_OUT { + vec3 frag_pos; + vec3 normal; + vec2 tex_coords; +} vs_out; + +uniform mat4 proj; +uniform mat4 view; +uniform mat4 model; + +void main(void) +{ + vs_out.frag_pos = vec3(model*vec4(apos, 1.0)); + vs_out.normal = mat3(transpose(inverse(model)))*anormal; + vs_out.tex_coords = atex_coords; + gl_Position = proj*view*model*vec4(apos, 1.0); +} diff --git a/advanced_lighting/2.gamma_correction/shaders/blinn_phong.vs b/advanced_lighting/2.gamma_correction/shaders/blinn_phong.vs deleted file mode 100644 index 4d1b792..0000000 --- a/advanced_lighting/2.gamma_correction/shaders/blinn_phong.vs +++ /dev/null @@ -1,23 +0,0 @@ -#version 330 core -layout(location = 0) in vec3 apos; -layout(location = 1) in vec3 anormal; -layout(location = 2) in vec2 atex_coords; - -out VS_OUT { - vec3 frag_pos; - vec3 normal; - vec2 tex_coords; -} vs_out; - -uniform mat4 projection; -uniform mat4 view; -uniform mat4 model; - -void -main(void) -{ - vs_out.frag_pos = vec3(model*vec4(apos, 1.0)); - vs_out.normal = mat3(transpose(inverse(model)))*anormal; - vs_out.tex_coords = atex_coords; - gl_Position = projection*view*model*vec4(apos, 1.0); -} diff --git a/advanced_lighting/2.gamma_correction/shaders/light.frag b/advanced_lighting/2.gamma_correction/shaders/light.frag new file mode 100644 index 0000000..c01da99 --- /dev/null +++ b/advanced_lighting/2.gamma_correction/shaders/light.frag @@ -0,0 +1,8 @@ +#version 330 core + +out vec4 frag_color; + +void main(void) +{ + frag_color = vec4(1.0); +} diff --git a/advanced_lighting/2.gamma_correction/shaders/light.fs b/advanced_lighting/2.gamma_correction/shaders/light.fs deleted file mode 100644 index bd00d82..0000000 --- a/advanced_lighting/2.gamma_correction/shaders/light.fs +++ /dev/null @@ -1,9 +0,0 @@ -#version 330 core - -out vec4 frag_color; - -void -main(void) -{ - frag_color = vec4(1.0); -} diff --git a/advanced_lighting/2.gamma_correction/shaders/light.vert b/advanced_lighting/2.gamma_correction/shaders/light.vert new file mode 100644 index 0000000..a8b1247 --- /dev/null +++ b/advanced_lighting/2.gamma_correction/shaders/light.vert @@ -0,0 +1,11 @@ +#version 330 core +layout(location = 0) in vec3 apos; + +uniform mat4 proj; +uniform mat4 view; +uniform mat4 model; + +void main(void) +{ + gl_Position = proj*view*model*vec4(apos, 1.0); +} diff --git a/advanced_lighting/2.gamma_correction/shaders/light.vs b/advanced_lighting/2.gamma_correction/shaders/light.vs deleted file mode 100644 index ade669b..0000000 --- a/advanced_lighting/2.gamma_correction/shaders/light.vs +++ /dev/null @@ -1,12 +0,0 @@ -#version 330 core -layout(location = 0) in vec3 apos; - -uniform mat4 projection; -uniform mat4 view; -uniform mat4 model; - -void -main(void) -{ - gl_Position = projection*view*model*vec4(apos, 1.0); -} -- cgit v1.2.3