void ShadowMapRenderer::SetupFramebuffers(const unsigned &w,
        const unsigned &h)
{
    using namespace oglplus;
    static Context gl;
    // save size
    shadowMapSize = glm::uvec2(w, h);
    // setup shadow framebuffer
    shadowFramebuffer.Bind(FramebufferTarget::Draw);
    // create render buffer for depth testing
    depthRender.Bind(RenderbufferTarget::Renderbuffer);
    depthRender.Storage(RenderbufferTarget::Renderbuffer,
                        PixelDataInternalFormat::DepthComponent24, w, h);
    // create variance shadow mapping texture, z and z * z
    gl.Bound(TextureTarget::_2D, shadowMap)
    .Image2D(0, PixelDataInternalFormat::RGBA32F, w, h, 0,
             PixelDataFormat::RGBA, PixelDataType::Float, nullptr);
    Filtering(filtering);
    Anisotropy(8);
    shadowFramebuffer.AttachColorTexture(FramebufferTarget::Draw, 0, shadowMap, 0);
    shadowFramebuffer.AttachRenderbuffer(FramebufferTarget::Draw,
                                         FramebufferAttachment::Depth,
                                         depthRender);
    gl.DrawBuffer(FramebufferColorAttachment::_0);

    // check if success building frame buffer
    if (!Framebuffer::IsComplete(FramebufferTarget::Draw))
    {
        auto status = Framebuffer::Status(FramebufferTarget::Draw);
        Framebuffer::HandleIncompleteError(FramebufferTarget::Draw, status);
    }

    Framebuffer::Bind(Framebuffer::Target::Draw, FramebufferName(0));
    // setup shadow blur framebuffer
    blurFramebuffer.Bind(FramebufferTarget::Draw);
    // create variance shadow mapping texture, z and z * z
    gl.Bound(TextureTarget::_2D, blurShadow)
    .Image2D(0, PixelDataInternalFormat::RGBA32F, w, h, 0,
             PixelDataFormat::RGBA, PixelDataType::Float, nullptr)
    .MinFilter(TextureMinFilter::Linear).MagFilter(TextureMagFilter::Linear)
    .WrapS(TextureWrap::ClampToEdge).WrapT(TextureWrap::ClampToEdge).Anisotropy(8);
    blurFramebuffer.AttachColorTexture(FramebufferTarget::Draw, 0, blurShadow, 0);
    gl.DrawBuffer(FramebufferColorAttachment::_0);

    // check if success building frame buffer
    if (!Framebuffer::IsComplete(FramebufferTarget::Draw))
    {
        auto status = Framebuffer::Status(FramebufferTarget::Draw);
        Framebuffer::HandleIncompleteError(FramebufferTarget::Draw, status);
    }

    Framebuffer::Bind(Framebuffer::Target::Draw, FramebufferName(0));
}
Ejemplo n.º 2
0
	void Render(double time)
	{
		flow.Update(time);

		Framebuffer::BindDefault(Framebuffer::Target::Draw);
		gl.DrawBuffer(ColorBuffer::BackLeft);
		gl.Viewport(width, height);
		gl.Clear().ColorBuffer().DepthBuffer();

		screen_prog.Use();
		screen.Use();
		screen.Draw();
	}
Ejemplo n.º 3
0
	void Render(double time)
	{
		ripples.Update();

		DefaultFramebuffer::Bind(Framebuffer::Target::Draw);
		gl.DrawBuffer(ColorBuffer::BackLeft);
		gl.Viewport(width, height);
		gl.Clear().ColorBuffer().DepthBuffer();

		auto camera = CamMatrixf::Orbiting(
			Vec3f(),
			6.0 + SineWave(time / 31.0),
			FullCircles(time / 17.0),
			Degrees(50 + SineWave(time / 21.0) * 35)
		);

		water_prog.Use();
		water_prog.camera_matrix.Set(camera);
		water_prog.camera_position.Set(camera.Position());

		water.Draw();
	}
Ejemplo n.º 4
0
	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);
	}