From 31cb526f57cfd023e397873551ab62b20ef125d9 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 21 Feb 2021 23:33:32 +0200 Subject: [PATCH] Update the desertpillars demo --- demos/desertpillars.cpp | 60 ++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/demos/desertpillars.cpp b/demos/desertpillars.cpp index 758f5eb1..242a9e73 100644 --- a/demos/desertpillars.cpp +++ b/demos/desertpillars.cpp @@ -19,8 +19,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -97,13 +97,15 @@ private: Msp::Graphics::Window window; Msp::Graphics::GLContext gl_context; Msp::Input::Keyboard keyboard; + GL::Resources resources; GL::Program skybox_shprog; GL::Technique skybox_tech; GL::TextureCube skybox_tex; + GL::Sampler linear_clamped_sampler; ObjectData skybox_data; - GL::Program shadow_shprog; + const GL::Program &shadow_shprog; GL::Program ground_shprog; GL::ProgramData ground_shdata; @@ -111,6 +113,8 @@ private: GL::Texture2D tiles_normalmap; GL::Texture2D sand_texture; GL::Texture2D sand_normalmap; + GL::Sampler linear_sampler; + GL::Sampler mipmap_sampler; GL::Technique ground_tech; ObjectData ground_data; @@ -229,7 +233,7 @@ const char DesertPillars::ground_src[] = "{\n" " return mix(texture(texture1, texcoord.xy*3.0), texture(texture2, texcoord.xy), ground_type);\n" "}\n" - "vec4 get_normal_sample()\n" + "vec4 get_fragment_normal()\n" "{\n" " return mix(texture(normalmap1, texcoord.xy*3.0).rgb, texture(normalmap2, texcoord.xy).rgb, ground_type);\n" "}\n"; @@ -286,14 +290,15 @@ DesertPillars::DesertPillars(int argc, char **argv): gl_context(window), keyboard(window), skybox_shprog(skybox_src), - shadow_shprog("occluder.glsl"), + shadow_shprog(resources.get("_occluder.glsl.shader")), ground_shprog(ground_src), cube_shprog(cube_src), cube_shadow_shprog(string(cube_src)+cube_shadow_src_tail), view(window, gl_context), pipeline(view), - shadow_scene(2048, scene, light), - bloom(window.get_width(), window.get_height()), + shadow_scene(resources, 2048, scene, light), + bloom(resources, window.get_width(), window.get_height()), + colorcurve(resources), env_pipeline(512, 512), camera_angle(0), camera_stopped(false), @@ -379,15 +384,15 @@ void DesertPillars::create_pipeline() void DesertPillars::create_skybox() { - skybox_tex.storage(GL::SRGB, 128); - skybox_tex.set_min_filter(GL::LINEAR); - skybox_tex.set_wrap(GL::CLAMP_TO_EDGE); + skybox_tex.storage(GL::SRGB8, 128, 1); + linear_clamped_sampler.set_min_filter(GL::LINEAR); + linear_clamped_sampler.set_wrap(GL::CLAMP_TO_EDGE); for(unsigned i=0; i<6; ++i) create_skybox_face(skybox_tex, skybox_tex.enumerate_faces(i)); GL::RenderPass &pass = skybox_tech.add_pass(0); pass.set_shader_program(&skybox_shprog, 0); - pass.set_texture(0, &skybox_tex); + pass.set_texture(0, &skybox_tex, &linear_clamped_sampler); // The shader will use the vertex coordinates to initialize texture coordinates as well skybox_data.mesh = new GL::Mesh(GL::VERTEX3); @@ -421,7 +426,7 @@ void DesertPillars::create_skybox_face(GL::TextureCube &texture, GL::TextureCube pixels[i+2] = 160; } } - texture.image(face, 0, GL::RGB, GL::UNSIGNED_BYTE, pixels); + texture.image(face, 0, pixels); delete[] pixels; } @@ -429,10 +434,9 @@ void DesertPillars::create_tiles_texture() { unsigned width = 256; unsigned height = 256; - tiles_texture.storage(GL::RGB, width, height); - tiles_texture.set_min_filter(GL::LINEAR); - tiles_normalmap.storage(GL::RGB, width, height); - tiles_normalmap.set_min_filter(GL::LINEAR); + tiles_texture.storage(GL::RGB8, width, height, 1); + tiles_normalmap.storage(GL::RGB8, width, height, 1); + linear_sampler.set_min_filter(GL::LINEAR); GL::Mesh tiles((GL::VERTEX3, GL::NORMAL3, GL::COLOR4_UBYTE)); @@ -447,6 +451,7 @@ void DesertPillars::create_tiles_texture() 4, 4, 3, 3, 4, 1, 3, 2, 2, 3, 2, 2, 3, 3, 3, 2 }; + { GL::MeshBuilder bld(tiles); // Create a dark background @@ -483,6 +488,7 @@ void DesertPillars::create_tiles_texture() bld.vertex(coords[i*4+order[32+l*2]], coords[j*4+order[32+l*2+1]], bevel); bld.end(); } + } GL::Program shprog(texture_src); @@ -501,14 +507,12 @@ void DesertPillars::create_sand_texture() unsigned width = 512; unsigned height = 512; - sand_texture.storage(GL::SRGB, width/16, height/16); - sand_texture.set_min_filter(GL::LINEAR_MIPMAP_LINEAR); - sand_texture.set_max_anisotropy(4); + sand_texture.storage(GL::SRGB8, width/16, height/16); sand_texture.set_auto_generate_mipmap(true); - sand_normalmap.storage(GL::RGB, width, height); - sand_normalmap.set_min_filter(GL::LINEAR_MIPMAP_LINEAR); - sand_normalmap.set_max_anisotropy(4); + sand_normalmap.storage(GL::RGB8, width, height); sand_normalmap.set_auto_generate_mipmap(true); + mipmap_sampler.set_min_filter(GL::LINEAR_MIPMAP_LINEAR); + mipmap_sampler.set_max_anisotropy(4); unsigned char *pixels = new unsigned char[width*height*3]; unsigned char *bump = new unsigned char[width*height]; @@ -522,10 +526,10 @@ void DesertPillars::create_sand_texture() pixels[i+2] = 160; bump[x+y*width] = rand(); } - sand_texture.image(0, GL::RGB, GL::UNSIGNED_BYTE, pixels); + sand_texture.image(0, pixels); gaussian_blur(bump, width, height); create_normalmap(bump, pixels, width, height, 4); - sand_normalmap.image(0, GL::RGB, GL::UNSIGNED_BYTE, pixels); + sand_normalmap.image(0, pixels); delete[] pixels; delete[] bump; } @@ -597,10 +601,10 @@ void DesertPillars::create_ground() GL::RenderPass *pass = &ground_tech.add_pass(0); pass->set_shader_program(&ground_shprog, &ground_shdata); - pass->set_texture(0, &tiles_texture); - pass->set_texture(1, &tiles_normalmap); - pass->set_texture(2, &sand_texture); - pass->set_texture(3, &sand_normalmap); + pass->set_texture(0, &tiles_texture, &linear_sampler); + pass->set_texture(1, &tiles_normalmap, &linear_sampler); + pass->set_texture(2, &sand_texture, &mipmap_sampler); + pass->set_texture(3, &sand_normalmap, &mipmap_sampler); /* No shadow pass here; the ground only receives shadows, but doesn't cast them. */ @@ -770,7 +774,7 @@ void DesertPillars::create_cube() cube_data.object = new GL::Object(cube_data.mesh, &cube_tech); cube = new Cube(*cube_data.object); - env_cube = new GL::EnvironmentMap(512, *cube, env_pipeline); + env_cube = new GL::EnvironmentMap(resources, 512, *cube, env_pipeline); scene.add(*env_cube); } -- 2.45.2