Skip to content
Snippets Groups Projects
Commit 99e502fa authored by Noé's avatar Noé
Browse files

Transitioning skybox

parent 0b93d2dd
No related branches found
No related tags found
No related merge requests found
......@@ -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
// ********************************** //
......
......@@ -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());
}
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment