Deferred Shading with Reflections

Screenshot from my upcoming game Pool Shark Pro™ shows the GBuffer (Diffuse, Depth, Normal and Reflection color)

(Click the screenshot to see the whole thing)

Videos here:

YouTube Channel

Reconstructing position from depth

This is my technique for reconstructing position from depth *and* sampling the GBuffer:

Vertex Shader

static const float4x4 gMtexProj = float4x4(
	0.5, 0.0, 0.0, 0.0
,	0.0,-0.5, 0.0, 0.0
,	0.0, 0.0, 1.0, 0.0
,	0.5, 0.5, 0.0, 1.0
);//float4x4

struct VertIn {
	float4 P			: POSITION0;
};//struct

struct VertOut {
	float4 Poutput		: POSITION0;
	float4 P			: TEXCOORD0;
	float4 T			: TEXCOORD1;
};//struct

VertOut VertFn(VertIn Input) {
	
	VertOut Output;

	float4 P		= mul(Input.P	, gMworldViewProj);		// Transform vertex into homogenous clip space
	float4 T		= mul(P			, gMtexProj);			// Transform into projective texture space
	
	Output.Poutput	= P;
	Output.P		= float4(P.xy, abs(P.w), P.w);			// Chuck on to far plane
	Output.T		= T;									// Projective texture coordinate enables non-dependent read

	return Output;

}//function

Pixel Shader

float4x4 gMprojInv; // Inverse Perspective Projection Matrix

float GetDepth(float4 T) {
	return tex2Dproj(gSmpDepth, T).r;
}//function

struct PixIn {
	float4 P			: TEXCOORD0;
	float4 T			: TEXCOORD1;
};//struct

float4 PixFn(PixIn Input) : COLOR0 {

	float	linearUnitZ	= GetDepth(Input.T);
	float4	Ptemp		= mul(Input.P, gMprojInv);
	float3	ViewRay		= Ptemp.xyz / Ptemp.w;
	float3	Pview		= ViewRay * linearUnitZ;

	...

}//function

Non-dependent read
means that the texture units can start sampling before the pixel shaders begin executing.
Actually even before the vertex shader has finished executing.
This means by the time the pixel shader executes … the texture cache already contains the data
so the tex2D() takes no time at all …

You can enable this performance boosting parallelism by sampling using an (unaltered) texture coordinate from a vertex shader.
(AFAIK)

Advertisements