Hi,
I render each object to G-Buffer after that I should render each light in the scene to the lightbuffer, and the result should be blended so the lightbuffer is a blended combination of all lights in the scene correct.
So how do I blend the lightbuffers renderpass? Is this something that i should program in the shaderworld or in the cpu world? And how would a typical very simple lightbuffer look like should that just be a pixel shader?
Also currently my setup works fine for 1 light (:-P) and it goes something like this.
1) Render all object to the G-Buffer one by one, each object has the G-Buffer as there primary shader
2) Render a Quad with the light buffer as a shader and a light as input. If i would start render 1000 lights I cant render
the Quad 1000 times, so I should just run the "light shader" a 10000s without any geometry somehow and then as a third final step render the a Quad and then apply the blend result from the light shader to that quad, how would I do that?
// Lightbuffer
//--------------------------------------------------------------------------------
Texture2D txDiffuse : register(t0);
Texture2D txNormal : register(t1);
Texture2D txDepth : register(t2);
Texture2D txSpecular : register(t3);
//--------------------------------------------------------------------------------
SamplerState samLinear0 : register( s0 );
SamplerState samLinear1 : register( s1 );
SamplerState samLinear2 : register( s2 );
SamplerState samLinear3 : register( s3 );
//--------------------------------------------------------------------------------
cbuffer cbLight : register(b0)
{
float4 lightDirection;
float4 lightColor;
float4 lightRange;
}
//--------------------------------------------------------------------------------
struct PS_INPUT
{
float4 position : SV_POSITION;
float2 texcoord : TEXCOORD0;
};
//--------------------------------------------------------------------------------
float4 main(PS_INPUT input) : SV_Target
{
float4 diffuse = txDiffuse.Sample(samLinear0, input.texcoord);
float4 normal = txNormal.Sample(samLinear1, input.texcoord);
float4 depth = txDepth.Sample(samLinear2, input.texcoord);
float4 specular = txDepth.Sample(samLinear3, input.texcoord);
float irradiance = saturate(dot(normal, -lightDirection));
return lightColor*irradiance*diffuse;
}
// G-BUFFER
Texture2D txDiffuse : register( t0 );
SamplerState samLinear : register( s0 );
cbuffer cbPerObject : register(b0)
{
float4 diffuse;
float4 specular;
bool isTextured;
}
//--------------------------------------------------------------------------------------
struct PS_INPUT
{
float4 position : SV_POSITION;
float2 texcoord : TEXCOORD0;
float4 normal : NORMAL;
};
//--------------------------------------------------------------------------------------
struct PSOutput
{
float4 Color : SV_Target0;
float4 Normal : SV_Target1;
float4 Depth : SV_Target2;
float4 Specular : SV_Target3;
};
//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
PSOutput main(PS_INPUT input)
{
PSOutput output;
output.Color = diffuse*txDiffuse.Sample(samLinear, input.texcoord);
output.Normal = normalize(input.normal);
output.Specular = specular;
output.Depth = input.position.z / input.position.w;
return output;
}
any help is much appreciated.