From 99e502fab69c29239be8437383ee3fc99306ebc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9?= <noe.artru@polytechnique.org> Date: Tue, 16 May 2023 12:36:37 +0200 Subject: [PATCH] Transitioning skybox --- .../skybox_drawable/skybox_drawable.cpp | 14 +++++++++++--- .../skybox_drawable/skybox_drawable.hpp | 3 ++- projet-code/scenes_inf443/base/src/scene.cpp | 6 +++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/projet-code/cgp/library/cgp/graphics/drawable/special_drawable/skybox_drawable/skybox_drawable.cpp b/projet-code/cgp/library/cgp/graphics/drawable/special_drawable/skybox_drawable/skybox_drawable.cpp index 708ddea..6279065 100644 --- a/projet-code/cgp/library/cgp/graphics/drawable/special_drawable/skybox_drawable/skybox_drawable.cpp +++ b/projet-code/cgp/library/cgp/graphics/drawable/special_drawable/skybox_drawable/skybox_drawable.cpp @@ -14,14 +14,16 @@ namespace cgp { layout(location=0) out vec4 FragColor; uniform samplerCube image_skybox; + uniform samplerCube image_skybox2; + uniform float skyTime; void main() { // Apply a symetry on x to preserve the orientation of the image // (left handed convention system on skybox) vec3 p = fragment.position * vec3(1.0, 1.0, -1.0); - - FragColor = texture(image_skybox, p); + + FragColor = skyTime*texture(image_skybox, p) + (1-skyTime)*texture(image_skybox2, p); } )"; @@ -85,7 +87,7 @@ namespace cgp { } - void draw(skybox_drawable const& drawable, environment_generic_structure const& environment) + void draw(skybox_drawable const& drawable, float t, environment_generic_structure const& environment) { opengl_check; // Initial clean check @@ -100,6 +102,7 @@ namespace cgp { assert_cgp(drawable.shader.id != 0, "Try to draw skybox_drawable without shader "); assert_cgp(!glIsShader(drawable.shader.id), "Try to draw skybox_drawable with incorrect shader "); assert_cgp(drawable.texture.id != 0, "Try to draw skybox_drawable without texture "); + assert_cgp(drawable.texture2.id != 0, "There is no second texture"); // Set the current shader // ********************************** // @@ -119,6 +122,11 @@ namespace cgp { glActiveTexture(GL_TEXTURE0); opengl_check; drawable.texture.bind(); opengl_uniform(drawable.shader, "image_skybox", 0); opengl_check; + glActiveTexture(GL_TEXTURE1); opengl_check; + drawable.texture2.bind(); + opengl_uniform(drawable.shader, "image_skybox2", 1); opengl_check; + + opengl_uniform(drawable.shader, "skyTime", (float) cos(t/10)); // Draw call // ********************************** // diff --git a/projet-code/cgp/library/cgp/graphics/drawable/special_drawable/skybox_drawable/skybox_drawable.hpp b/projet-code/cgp/library/cgp/graphics/drawable/special_drawable/skybox_drawable/skybox_drawable.hpp index 1d6a79b..0484731 100644 --- a/projet-code/cgp/library/cgp/graphics/drawable/special_drawable/skybox_drawable/skybox_drawable.hpp +++ b/projet-code/cgp/library/cgp/graphics/drawable/special_drawable/skybox_drawable/skybox_drawable.hpp @@ -16,6 +16,7 @@ namespace cgp { // Texture image opengl_texture_image_structure texture; + opengl_texture_image_structure texture2; // Per-vertex data opengl_vbo_structure vbo_position; @@ -44,7 +45,7 @@ namespace cgp { // draw(skybox, environment); // glDepthMask(GL_TRUE); // re-activate depth-buffer write // ... other drawing calls comes after - void draw(skybox_drawable const& drawable, environment_generic_structure const& environment = environment_generic_structure()); + void draw(skybox_drawable const& drawable, float t, environment_generic_structure const& environment = environment_generic_structure()); } diff --git a/projet-code/scenes_inf443/base/src/scene.cpp b/projet-code/scenes_inf443/base/src/scene.cpp index f159a34..15d72e8 100644 --- a/projet-code/scenes_inf443/base/src/scene.cpp +++ b/projet-code/scenes_inf443/base/src/scene.cpp @@ -35,9 +35,13 @@ void scene_structure::initialize() image_structure image_skybox_template = image_load_file("assets/skybox2.jpg"); std::vector<image_structure> image_grid = image_split_grid(image_skybox_template, 4, 3); + image_structure image_skybox_template2 = image_load_file("assets/skyboxNight.jpeg"); + std::vector<image_structure> image_grid2 = image_split_grid(image_skybox_template2, 4, 3); + skybox.initialize_data_on_gpu(); //x neg, x pos, y neg, y pos, z neg, z pos skybox.texture.initialize_cubemap_on_gpu(image_grid[7].rotate_90_degrees_counterclockwise(), image_grid[1].rotate_90_degrees_clockwise(), image_grid[4].rotate_90_degrees_clockwise().rotate_90_degrees_clockwise(), image_grid[10], image_grid[3], image_grid[5].rotate_90_degrees_clockwise().rotate_90_degrees_clockwise()); + skybox.texture2.initialize_cubemap_on_gpu(image_grid2[7].rotate_90_degrees_counterclockwise(), image_grid2[1].rotate_90_degrees_clockwise(), image_grid2[4].rotate_90_degrees_clockwise().rotate_90_degrees_clockwise(), image_grid2[10], image_grid2[3], image_grid2[5].rotate_90_degrees_clockwise().rotate_90_degrees_clockwise()); @@ -140,7 +144,7 @@ void scene_structure::display_frame() // Must be called before drawing the other shapes and without writing in the Depth Buffer glDepthMask(GL_FALSE); // disable depth-buffer writing - draw(skybox, environment); + draw(skybox, timer.t, environment); glDepthMask(GL_TRUE); // re-activate depth-buffer write //Walking on ground -- GitLab