Hi guys,
right now I'm facing a problem with lighting in Uber Shading, my Shader file looks as following:
cbuffer ConstantObjectBuffer
{
float4x4 final;
float4x4 rotation;
float4 ambientcol;
}
cbuffer ConstantFrameBuffer
{
float4 lightvec;
float4 lightcol;
}
cbuffer UberData
{
int _diffuse;
int _texture;
int _directionall;
int _bumpmap;
}
cbuffer ConstantMatrixBuffer
{
float4 world;
float4 view;
float4 projection;
}
Texture2D txt;
Texture2D txt2;
SamplerState ss;
struct VOut
{
float4 position : SV_POSITION;
float2 texcoord : TEXCOORD; // texture coordinates
float4 normal : NORMAL;
float4 color : COLOR;
};
VOut VShader(float4 position : POSITION, float4 normal : NORMAL, float2 texcoord : TEXCOORD)
{
VOut output;
output.position = mul(final, position);
output.color = float4(0, 0, 0, 1);
// set the ambient light
if (_diffuse == 1)
{
output.color = ambientcol;
}
if (_texture == 1)
{
output.texcoord = texcoord;
}
if (_directionall == 1)
{
float4 norm = normalize(mul(rotation, normal));
float diffusebrightness = saturate(dot(norm, lightvec));
output.color += lightcol * diffusebrightness;
float4 light = normalize(lightvec);
float4 eye = float4(1.0, 1.0, 1.0, 0.0);
float4 vhalf = normalize(light + eye);
float4 specularMaterial = float4(1, 1, 1, 1.0);
float specular = dot(normal, vhalf);
output.color += specular*specularMaterial;
}
return output;
}
float4 PShader(VOut input) : SV_TARGET
{
float4 color = input.color;
if (_texture == 1)
{
color *= txt.Sample(ss, input.texcoord);
}
return color;
}
As you can see I have a section of lighting, and this Shader file is used once per mesh. But the problem is what if I have more than one light? Maybe 3? As hlsl cannot declare dynamic arrays, is the only option to have limited lights?
I am aware of this deffered rendering, just not how it works, though I can't say I have put a lot of research effort into that, but would that fit here?
Thank You