void Reshape(GLuint vp_width, GLuint vp_height) { width = vp_width; height = vp_height; gl.Viewport(width, height); Texture::Image2D( Texture::Target::Rectangle, 0, PixelDataInternalFormat::DepthComponent, width, height, 0, PixelDataFormat::DepthComponent, PixelDataType::Float, nullptr ); auto projection = CamMatrixf::PerspectiveX( Degrees(60), double(width)/height, 1, 10000 ); draw_prog.Use(); draw_prog.projection_matrix.Set(projection); depth_prog.Use(); depth_prog.projection_matrix.Set(projection); }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); CamMatrixf camera = CamMatrixf::Orbiting( Vec3f(), 4.5f + float(SineWave(time / 25.0)), FullCircles(time / 30.0), Degrees(SineWave(time / 19.0) * 20) ); light_prog.camera_matrix.Set(camera); flare_prog.camera_matrix.Set(camera); shape_prog.camera_matrix.Set(camera); shape_prog.camera_position.Set(camera.Position()); shape_prog.model_matrix.Set( ModelMatrixf::RotationX(FullCircles(time / 30.0)) ); shape_prog.Use(); shape.Draw(); NoProgram().Use(); lights.Bind(); light_prog.Use(); for(GLuint l=0; l!=n_flares; ++l) { queries[l].Begin(Query::Target::SamplesPassed); gl.DrawArrays(PrimitiveType::Points, l, 1); queries[l].End(Query::Target::SamplesPassed); } gl.Enable(Capability::Blend); gl.Disable(Capability::DepthTest); flare_prog.Use(); for(GLuint l=0; l!=n_flares; ++l) { GLint samples = 0; queries[l].WaitForResult(samples); if(samples != 0) { flare_prog.samples = samples; gl.DrawArrays(PrimitiveType::Points, l, 1); } } gl.Enable(Capability::DepthTest); gl.Disable(Capability::Blend); }
void Render(double time) { gl.ClearDepth(0.0f); gl.Clear().DepthBuffer(); auto camera = CamMatrixf::Orbiting( objects.BoundingSphere().Center(), objects.BoundingSphere().Radius()*2.8, FullCircles(time / 19.0), Degrees(SineWave(time / 17.0) * 90) ); depth_prog.Use(); gl.DepthFunc(CompareFn::Greater); gl.CullFace(Face::Front); depth_prog.camera_matrix.Set(camera); depth_prog.model_matrix.Set(Mat4f()); objects.Draw(); Texture::CopyImage2D( Texture::Target::Rectangle, 0, PixelDataInternalFormat::DepthComponent, 0, 0, width, height, 0 ); gl.ClearDepth(1.0f); gl.Clear().ColorBuffer().DepthBuffer(); draw_prog.Use(); gl.DepthFunc(CompareFn::Less); gl.CullFace(Face::Back); draw_prog.camera_matrix.Set(camera); draw_prog.model_matrix.Set(Mat4f()); objects.Draw(); }
void Render(double time) { GLfloat bs_rad = shape.BoundingSphere().Radius()*1.2f; auto light = CamMatrixf::Orbiting( shape.BoundingSphere().Center(), shape.BoundingSphere().Radius()*10.0, FullCircles(time / 23.0), Degrees(35 + SineWave(time / 31.0) * 50) ); GLfloat lgt_tgt_dist = Distance( shape.BoundingSphere().Center(), light.Position() ); auto lgt_proj = CamMatrixf::PerspectiveX( ArcSin(bs_rad/lgt_tgt_dist)*2, 1.0f, lgt_tgt_dist-bs_rad, lgt_tgt_dist+bs_rad ); auto camera = CamMatrixf::Orbiting( shape.BoundingSphere().Center(), shape.BoundingSphere().Radius()*2.8, FullCircles(time / 17.0), Degrees(SineWave(time / 19.0) * 80) ); GLfloat cam_tgt_dist = Distance( shape.BoundingSphere().Center(), camera.Position() ); auto cam_proj = CamMatrixf::PerspectiveX( ArcSin(bs_rad/cam_tgt_dist)*2, double(width)/height, cam_tgt_dist-bs_rad, cam_tgt_dist+bs_rad ); auto model = ModelMatrixf::RotationZ(Degrees(SineWave(time / 21.0)*25))* ModelMatrixf::Translation(0.0f,-bs_rad*0.25f, 0.0f); depth_vao.Bind(); depth_prog.Use(); depth_prog.camera_matrix.Set(lgt_proj*light); depth_prog.model_matrix.Set(model); depth_buffer.SetupViewport(); depth_buffer.Bind(); gl.ClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.ClearDepth(1.0f); gl.Clear().ColorBuffer().DepthBuffer(); gl.Enable(Capability::PolygonOffsetFill); shape.Draw(); // draw_vao.Bind(); draw_prog.Use(); draw_prog.camera_matrix.Set(cam_proj*camera); draw_prog.light_matrix.Set(lgt_proj*light); draw_prog.model_matrix.Set(model); draw_prog.camera_position.Set(camera.Position()); draw_prog.light_position.Set(light.Position()); DefaultFramebuffer::Bind(Framebuffer::Target::Draw); gl.Viewport(width, height); gl.ClearColor(0.2f, 0.2f, 0.2f, 0.0f); gl.ClearDepth(1.0f); gl.Clear().ColorBuffer().DepthBuffer(); gl.Disable(Capability::PolygonOffsetFill); shape.Draw(); }