Пример #1
0
	void ResizeLightMask(GLuint width, GLuint height)
	{
		Texture::Active(light_tex_unit);
		Texture::Target tex_tgt = Texture::Target::Rectangle;
		light_mask.Bind(tex_tgt);
		Texture::Image2D(
			tex_tgt,
			0,
			PixelDataInternalFormat::Red,
			width, height,
			0,
			PixelDataFormat::Red,
			PixelDataType::UnsignedByte,
			nullptr
		);

		Renderbuffer::Target rbo_tgt = Renderbuffer::Target::Renderbuffer;
		light_rbo.Bind(rbo_tgt);
		Renderbuffer::Storage(
			rbo_tgt,
			PixelDataInternalFormat::DepthComponent,
			width,
			height
		);

	}
Пример #2
0
	void SetupLightMask(void)
	{
		Texture::Active(light_tex_unit);
		Texture::Target tex_tgt = Texture::Target::Rectangle;
		light_mask.Bind(tex_tgt);

		draw_prog.Use();
		UniformSampler(draw_prog, "LightMap").Set(GLuint(light_tex_unit));

		Texture::MinFilter(tex_tgt, TextureMinFilter::Linear);
		Texture::MagFilter(tex_tgt, TextureMagFilter::Linear);
		Texture::WrapS(tex_tgt, TextureWrap::ClampToEdge);
		Texture::WrapT(tex_tgt, TextureWrap::ClampToEdge);

		Framebuffer::Target fbo_tgt = Framebuffer::Target::Draw;
		light_fbo.Bind(fbo_tgt);
		Framebuffer::AttachTexture(fbo_tgt, FramebufferAttachment::Color, light_mask, 0);

		Renderbuffer::Target rbo_tgt = Renderbuffer::Target::Renderbuffer;
		light_rbo.Bind(rbo_tgt);
		Framebuffer::AttachRenderbuffer(fbo_tgt, FramebufferAttachment::Depth, light_rbo);
	}
Пример #3
0
	void RenderShadowMap(GLuint size)
	{
		// matrices
		auto lt_proj= CamMatrixf::PerspectiveX(Degrees(12), 1.0, 85.0, 110.0);
		auto light = CamMatrixf::LookingAt(light_position, Vec3f());
		// setup the texture
		Texture::Active(shadow_tex_unit);

		mask_prog.Use();
		Uniform<Mat4f>(mask_prog, "LightMatrix").Set(lt_proj*light);
		UniformSampler(mask_prog, "ShadowMap").Set(GLuint(shadow_tex_unit));

		draw_prog.Use();
		Uniform<Mat4f>(draw_prog, "LightMatrix").Set(lt_proj*light);
		UniformSampler(draw_prog, "ShadowMap").Set(GLuint(shadow_tex_unit));

		Texture::Target tex_tgt = Texture::Target::_2D;
		shadow_map.Bind(tex_tgt);
		Texture::MinFilter(tex_tgt, TextureMinFilter::Linear);
		Texture::MagFilter(tex_tgt, TextureMagFilter::Linear);
		Texture::WrapS(tex_tgt, TextureWrap::ClampToEdge);
		Texture::WrapT(tex_tgt, TextureWrap::ClampToEdge);
		Texture::CompareMode(tex_tgt, TextureCompareMode::CompareRefToTexture);
		Texture::Image2D(
			tex_tgt,
			0,
			PixelDataInternalFormat::DepthComponent32,
			size, size,
			0,
			PixelDataFormat::DepthComponent,
			PixelDataType::Float,
			nullptr
		);

		// create shadow program
		ShadowProgram shadow_prog(vert_shader);

		// VAO for the meshes in shadow program
		VertexArray vao = meshes.VAOForProgram(shadow_prog);
		vao.Bind();

		// FBO for offscreen rendering of the shadow map
		Framebuffer::Target fbo_tgt = Framebuffer::Target::Draw;
		Framebuffer fbo;
		fbo.Bind(fbo_tgt);
		Framebuffer::AttachTexture(fbo_tgt, FramebufferAttachment::Depth, shadow_map, 0);

		// RBO for offscreen rendering
		Renderbuffer::Target rbo_tgt = Renderbuffer::Target::Renderbuffer;
		Renderbuffer rbo;
		rbo.Bind(rbo_tgt);
		Renderbuffer::Storage(rbo_tgt, PixelDataInternalFormat::RGBA, size, size);
		Framebuffer::AttachRenderbuffer(fbo_tgt, FramebufferAttachment::Color, rbo);

		// setup the matrices
		shadow_prog.projection_matrix.Set(lt_proj);
		shadow_prog.camera_matrix.Set(light);

		// setup and clear the viewport
		gl.Viewport(size, size);
		gl.Clear().DepthBuffer();

		// draw the meshes
		gl.PolygonOffset(1.0, 1.0);
		gl.Enable(Capability::PolygonOffsetFill);
		meshes.Draw();
		gl.Disable(Capability::PolygonOffsetFill);
		gl.Finish();

		// bind the default framebuffer
		DefaultFramebuffer().Bind(Framebuffer::Target::Draw);
	}