_FakePPL.vsh
{
	include generic_vertex.vsh
}

_FakePPL.fsh
{
	uniform sampler2DRect	u_NormalBuffer;
	uniform sampler2DRect	u_SpecularBuffer;
	uniform sampler2DRect	u_DepthBuffer;
	uniform sampler2DRect	u_Deluxe_Buffer;
	uniform sampler2DRect	u_ColorBuffer;
	uniform vec3		u_ViewOrigin;
	uniform mat4		u_UnprojectMatrix;
	uniform float		u_lightMapBrightness;
	uniform float		u_noSpecular;
	out	vec3	fragData;

	include UnPackNormal.inc
	include pbr.inc

	void main(void)
	{
		vec4 specular = texture(u_SpecularBuffer, gl_FragCoord.xy);
		if (specular.a == 1.0)
		{	// no portal surfaces draw
			fragData = vec3(0.0);
			return;
		}

		// reconstruct vertex position in world space
		float depth = texture(u_DepthBuffer, gl_FragCoord.xy).r;
		vec4 P = u_UnprojectMatrix * vec4(gl_FragCoord.xy, depth, 1.0);
		P.xyz /= P.w;

		vec4 nmSample = texture(u_NormalBuffer, gl_FragCoord.xy);
		vec4 sN = texture(u_Deluxe_Buffer, gl_FragCoord.xy);

		// reconstruct normal
		vec3 N = UnPackNormal(nmSample.rg);

		// reconstruct surface normal, uses as light direction
		vec3 L = UnPackNormal(sN.rg);
		
		// reconstruct lightmap
		vec3 lit = vec3(nmSample.b, sN.ba) * u_lightMapBrightness;

		float NL = abs(dot(N, L));

		lit *= NL;

		// compute view direction in world space
		vec3 V = normalize(u_ViewOrigin - P.xyz);

		DoPBR(lit, specular, N, L, V, NL, nmSample.a);
	}
}
