inline GlTexture load_cubemap() { GlTexture tex; glBindTexture(GL_TEXTURE_CUBE_MAP, tex.get_gl_handle()); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, 0); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); int size; glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGB, 2048, 2048, 0, GL_RGB, GL_UNSIGNED_BYTE, load_image_data("assets/images/cubemap/positive_x.jpg", size).data()); glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGB, 2048, 2048, 0, GL_RGB, GL_UNSIGNED_BYTE, load_image_data("assets/images/cubemap/negative_x.jpg", size).data()); glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGB, 2048, 2048, 0, GL_RGB, GL_UNSIGNED_BYTE, load_image_data("assets/images/cubemap/positive_y.jpg", size).data()); glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGB, 2048, 2048, 0, GL_RGB, GL_UNSIGNED_BYTE, load_image_data("assets/images/cubemap/negative_y.jpg", size).data()); glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGB, 2048, 2048, 0, GL_RGB, GL_UNSIGNED_BYTE, load_image_data("assets/images/cubemap/positive_z.jpg", size).data()); glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGB, 2048, 2048, 0, GL_RGB, GL_UNSIGNED_BYTE, load_image_data("assets/images/cubemap/negative_z.jpg", size).data()); glBindTexture(GL_TEXTURE_CUBE_MAP, 0); return tex; }
ExperimentalApp() : GLFWApp(1280, 720, "Shadow App") { glfwSwapInterval(0); gen = std::mt19937(rd()); igm.reset(new gui::ImGuiManager(window)); gui::make_dark_theme(); int width, height; glfwGetWindowSize(window, &width, &height); glViewport(0, 0, width, height); cameraController.set_camera(&camera); camera.farClip = 55.f; camera.look_at({0, 0, +15}, {0, 0, 0}); // Debugging views uiSurface.bounds = {0, 0, (float) width, (float) height}; uiSurface.add_child( {{0.0000f, +10},{0, +10},{0.1667f, -10},{0.133f, +10}}); uiSurface.add_child( {{0.1667f, +10},{0, +10},{0.3334f, -10},{0.133f, +10}}); uiSurface.add_child( {{0.3334f, +10},{0, +10},{0.5009f, -10},{0.133f, +10}}); uiSurface.add_child( {{0.5000f, +10},{0, +10},{0.6668f, -10},{0.133f, +10}}); uiSurface.add_child( {{0.6668f, +10},{0, +10},{0.8335f, -10},{0.133f, +10}}); uiSurface.add_child( {{0.8335f, +10},{0, +10},{1.0000f, -10},{0.133f, +10}}); uiSurface.layout(); fullscreen_post_quad = make_fullscreen_quad(); sceneShader = make_watched_shader(shaderMonitor, "assets/shaders/shadow/scene_vert.glsl", "assets/shaders/shadow/scene_frag.glsl"); shadowmapShader = make_watched_shader(shaderMonitor, "assets/shaders/shadow/shadowmap_vert.glsl", "assets/shaders/shadow/shadowmap_frag.glsl"); pointLightShader = make_watched_shader(shaderMonitor, "assets/shaders/shadow/point_light_vert.glsl", "assets/shaders/shadow/point_light_frag.glsl"); gaussianBlurShader = make_watched_shader(shaderMonitor, "assets/shaders/gaussian_blur_vert.glsl", "assets/shaders/gaussian_blur_frag.glsl"); skydome.recompute(2, 10.f, 1.15f); auto lightDir = skydome.get_light_direction(); sunLight = std::make_shared<DirectionalLight>(lightDir, float3(.50f, .75f, .825f), 64.f); // todo spotLightB shadowDepthTexture.load_data(shadowmapResolution, shadowmapResolution, GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); shadowFramebuffer.attach(GL_DEPTH_ATTACHMENT, shadowDepthTexture); if (!shadowFramebuffer.check_complete()) throw std::runtime_error("incomplete shadow framebuffer"); shadowBlurTexture.load_data(shadowmapResolution, shadowmapResolution, GL_R32F, GL_RGBA, GL_FLOAT, nullptr); shadowBlurFramebuffer.attach(GL_COLOR_ATTACHMENT0, shadowBlurTexture); if (!shadowBlurFramebuffer.check_complete()) throw std::runtime_error("incomplete blur framebuffer"); auto spotLightA = std::make_shared<SpotLight>(float3(0.f, 10.f, 0.f), float3(0.f, -1.f, 0.f), float3(0.766f, 0.766f, 0.005f), 30.0f, float3(1.0f, 0.0f, 0.0001f)); spotLights.push_back(spotLightA); // Single spotlight fbo for (int i = 0; i < 1; ++i) { auto buffer = std::make_shared<SpotLightFramebuffer>(); buffer->create(shadowmapResolution); spotLightFramebuffers.push_back(buffer); } // Point light init { pointLight.reset(new PointLight(float3(0.f, 0.f, 0.f), float3(0, 1, 1), float3(1.0f, 0.05f, 0.0002f))); pointLightFramebuffer.reset(new PointLightFramebuffer()); pointLightFramebuffer->create(float2(shadowmapResolution)); pointLightSphere = std::make_shared<Renderable>(make_sphere(0.5f)); sceneObjects.push_back(pointLightSphere); } viewA.reset(new GLTextureView(shadowDepthTexture.get_gl_handle())); viewB.reset(new GLTextureView(shadowBlurTexture.get_gl_handle())); viewC.reset(new GLTextureView(spotLightFramebuffers[0]->shadowDepthTexture.get_gl_handle())); viewD.reset(new GLTextureView(pointLightFramebuffer->depthBuffer.get_gl_handle())); auto lucy = load_geometry_from_ply("assets/models/stanford/lucy.ply"); rescale_geometry(lucy, 8.0f); auto lucyBounds = lucy.compute_bounds(); auto statue = std::make_shared<Renderable>(lucy); statue->pose.position = {0, 0, 0}; //sceneObjects.push_back(statue); auto hollowCube = load_geometry_from_ply("assets/models/geometry/CubeHollowOpen.ply"); for (auto & v : hollowCube.vertices) v *= 0.20f; auto hCube = std::make_shared<Renderable>(hollowCube); hCube->pose.position = float3(0, 0, 0); hCube->pose.orientation = make_rotation_quat_around_x(ANVIL_PI / 2); //sceneObjects.push_back(hCube); auto curvedMesh = make_curved_plane(2, 1, 8, 8); sceneObjects.push_back(std::make_shared<Renderable>(curvedMesh)); //floor = std::make_shared<Renderable>(make_plane(32.f, 32.f, 64, 64), false); //floor->pose.orientation = make_rotation_quat_axis_angle({1, 0, 0}, -ANVIL_PI / 2); //floor->pose.position = {0, lucyBounds.min().y, 0}; //sceneObjects.push_back(floor); gl_check_error(__FILE__, __LINE__); }