Hello everyone,
So I have been trying to learn HLSL and I think I got the hang of it. I found this awesome tutorial that show how to implement deferred lighting. and I think I understand it. However there is just one thing that I would like to know. How can I change the light shape from point light to cone shape like light?
Here is a video of my implementation of deferred lighting.
">
and here is the code
struct Light
{
float2 position;
float4 color;
float power;
};
texture colortexture;
int numberOfLights;
Light lights[4];
float ambient;
float4 ambientColor;
float screenWidth;
float screenHeight;
sampler ColorMap = sampler_state
{
Texture = <colortexture>;
};
float4 CalculateLight(Light light, float4 base, float3 pixelPosition)
{
float2 direction = light.position - pixelPosition;
float distance = 1 / length(light.position - pixelPosition) * light.power;
float amount = max(dot(base, normalize(distance)), 0);
return base * distance * light.color * ambient;
}
float4 Deferredlight(float2 texCoords : TEXCOORD0) : COLOR
{
float4 base = tex2D(ColorMap, texCoords);
float3 pixelPosition = float3(screenWidth * texCoords.x, screenHeight * texCoords.y, 0);
float4 finalColor = (base * ambientColor * ambient);
for(int i=0; numberOfLights; i++)
{
finalColor += CalculateLight(lights, base, pixelPosition);
}
return finalColor;
}
technique Deferred
{
pass Pass1
{
PixelShader = compile ps_2_0 Deferredlight();
}
}