void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); auto cameraMatrix = CamMatrixf::Orbiting( Vec3f(0.0f, 3.0f, 0.0f), 8.0f, FullCircles(time / 12.0), Degrees(SineWave(time / 20.0) * 80) ); plane.Bind(); plane_prog.Use(); Uniform<Mat4f>(plane_prog, "CameraMatrix").Set(cameraMatrix); gl.DrawArrays(PrimitiveType::TriangleStrip, 0, 4); gl.Enable(Capability::Blend); volume.Bind(); volume_prog.Use(); Uniform<Mat4f>(volume_prog, "CameraMatrix").Set(cameraMatrix); Uniform<Vec3f>(volume_prog, "ViewX").Set( cameraMatrix.Row(0).xyz() ); Uniform<Vec3f>(volume_prog, "ViewY").Set( cameraMatrix.Row(1).xyz() ); Uniform<Vec3f>(volume_prog, "ViewZ").Set( cameraMatrix.Row(2).xyz() ); gl.DrawArraysInstanced( PrimitiveType::Points, 0, 1, samples ); gl.Disable(Capability::Blend); }
void Render(double time) { gl.Clear().ColorBuffer().DepthBuffer(); auto lightPos = light_path.Position(time * 0.05); auto cameraMatrix = CamMatrixf::Orbiting( Vec3f(), 4.5f, Degrees(0), Degrees(SineWave(time / 20.0) * 80) ); light.Bind(); light_prog.Use(); Uniform<Vec3f>(light_prog, "LightPos").Set(lightPos); Uniform<Mat4f>(light_prog, "CameraMatrix").Set(cameraMatrix); sphere_instr.Draw(sphere_indices); clouds.Bind(); cloud_prog.Use(); Uniform<Vec3f>(cloud_prog, "LightPos").Set(lightPos); Uniform<Mat4f>(cloud_prog, "CameraMatrix").Set(cameraMatrix); Uniform<Vec4f>(cloud_prog, "ViewX").Set(cameraMatrix.Row(0)); Uniform<Vec4f>(cloud_prog, "ViewY").Set(cameraMatrix.Row(1)); Uniform<Vec4f>(cloud_prog, "ViewZ").Set(cameraMatrix.Row(2)); for(std::size_t i=0, n=positions.size(); i!=n; ++i) { cloud_tex[i].Bind(Texture::Target::_3D); gl.DrawArraysInstanced( PrimitiveType::Points, i, 1, samples ); } }
void Render(double time) { // // the camera matrix Mat4f camera = CamMatrixf::Orbiting( Vec3f(), 6.5 + SineWave(time / 16.0) * 1.5, FullCircles(time / 12.0), Degrees(SineWave(time / 30.0) * 90) ); // // the model matrix Mat4f model = ModelMatrixf::RotationA( Vec3f(1.0f, 1.0f, 1.0f), FullCircles(time / 10.0) ); // the light position Vec3f lightPos(0.0f, SineWave(time / 7.0) * 0.5, 0.0f); // SetProgramUniform(shape_prog, "LightPos", lightPos); SetProgramUniform(depth_prog, "LightPos", lightPos); SetProgramUniform(light_prog, "LightPos", lightPos); // SetProgramUniform(shape_prog, "CameraMatrix", camera); SetProgramUniform(light_prog, "CameraMatrix", camera); SetProgramUniform(shape_prog, "ModelMatrix", model); SetProgramUniform(depth_prog, "ModelMatrix", model); // render the shadow map depth_fbo.Bind(Framebuffer::Target::Draw); gl.DrawBuffer(ColorBuffer::None); gl.Viewport(tex_side, tex_side); gl.Clear().DepthBuffer(); depth_prog.Use(); shape.Bind(); shape_instr.Draw(shape_indices); // render the output frame Framebuffer::BindDefault(Framebuffer::Target::Draw); gl.DrawBuffer(ColorBuffer::Back); gl.Viewport(width, height); gl.Clear().ColorBuffer().DepthBuffer(); shape_prog.Use(); shape.Bind(); shape_instr.Draw(shape_indices); gl.Enable(Capability::Blend); light_prog.Use(); SetUniform(light_prog, "ViewX", camera.Row(0).xyz()); SetUniform(light_prog, "ViewY", camera.Row(1).xyz()); SetUniform(light_prog, "ViewZ", camera.Row(2).xyz()); light.Bind(); gl.DrawArraysInstanced( PrimitiveType::Points, 0, 1, sample_count ); gl.Disable(Capability::Blend); }