make corrections to light calculations

This commit is contained in:
lightling 2022-03-27 16:07:07 -04:00
parent 3a92403510
commit 29b3605cba
Signed by: lightling
GPG key ID: 016F11E0AA296B67
3 changed files with 16 additions and 15 deletions

View file

@ -123,36 +123,36 @@ void Game::LoadTextures()
void Game::LoadLighting()
{
ambient = XMFLOAT3(0.5f, 0.5f, 0.5f);
ambient = XMFLOAT3(0.1f, 0.1f, 0.25f);
Light directionalLight0 = {};
directionalLight0.Type = LIGHT_TYPE_DIRECTIONAL;
directionalLight0.Direction = XMFLOAT3(1, 0, 0);
directionalLight0.Direction = XMFLOAT3(1, 0.5f, 0.5f);
directionalLight0.Color = XMFLOAT3(1, 1, 1);
directionalLight0.Intensity = 0.5f;
directionalLight0.Intensity = 1.0f;
Light directionalLight1 = {};
directionalLight1.Type = LIGHT_TYPE_DIRECTIONAL;
directionalLight1.Direction = XMFLOAT3(0, -1, 0);
directionalLight1.Direction = XMFLOAT3(-0.25f, -1, 0.75f);
directionalLight1.Color = XMFLOAT3(1, 1, 1);
directionalLight1.Intensity = 0.5f;
directionalLight1.Intensity = 1.0f;
Light directionalLight2 = {};
directionalLight2.Type = LIGHT_TYPE_DIRECTIONAL;
directionalLight2.Direction = XMFLOAT3(-1, 1, -0.5f);
directionalLight2.Color = XMFLOAT3(1, 1, 1);
directionalLight2.Intensity = 0.5f;
directionalLight2.Intensity = 1.0f;
Light pointLight0 = {};
pointLight0.Type = LIGHT_TYPE_POINT;
pointLight0.Position = XMFLOAT3(-2, -2, 0);
pointLight0.Position = XMFLOAT3(-1.5f, 0, 0);
pointLight0.Color = XMFLOAT3(1, 1, 1);
pointLight0.Intensity = 0.5f;
pointLight0.Intensity = 1.0f;
pointLight0.Range = 10;
Light pointLight1 = {};
pointLight1.Type = LIGHT_TYPE_POINT;
pointLight1.Position = XMFLOAT3(2, 2, 0);
pointLight1.Position = XMFLOAT3(1.5f, 0, 0);
pointLight1.Color = XMFLOAT3(1, 1, 1);
pointLight1.Intensity = 0.5f;
pointLight1.Range = 10;

View file

@ -10,7 +10,7 @@ float3 getView(float3 cameraPosition, float3 pixelWorldPosition)
// gets reflection vector, needed per light
float3 getReflection(float3 direction, float3 normal)
{
return reflect(direction, normal);
return reflect(-direction, normal);
}
// gets specular exponent: (1-roughness) * max

View file

@ -40,9 +40,9 @@ float3 calculateDirectionalLight(Light light, float3 normal, float3 view, float
// Gets the RGB value of a pixel with a point light
float3 calculatePointLight(Light light, float3 normal, float3 view, float3 worldPosition, float roughness, float3 surfaceColor)
{
float3 lightDirection = normalize(worldPosition - light.Position);
float3 lightDirection = normalize(light.Position - worldPosition);
float attenuation = getAttenuation(light.Position, worldPosition, light.Range);
float diffuse = getDiffuse(normal, -lightDirection);
float diffuse = getDiffuse(normal, lightDirection);
float specular = calculateSpecular(normal, lightDirection, view, roughness);
return (diffuse * surfaceColor + specular) * attenuation * light.Intensity * light.Color;
@ -58,7 +58,8 @@ float4 main(VertexToPixel input) : SV_TARGET
float3 view = getView(cameraPosition, input.worldPosition);
float4 albedo = Albedo.Sample(BasicSampler, input.uv).rgba;
float3 light = ambient * albedo.rgb * tint;
float3 surface = albedo.rgb * tint;
float3 light = ambient * surface;
// loop through lights
for (int i = 0; i < LIGHT_COUNT; i++)
@ -66,10 +67,10 @@ float4 main(VertexToPixel input) : SV_TARGET
switch (lights[i].Type)
{
case LIGHT_TYPE_DIRECTIONAL:
light += calculateDirectionalLight(lights[i], input.normal, view, roughness, tint);
light += calculateDirectionalLight(lights[i], input.normal, view, roughness, surface);
break;
case LIGHT_TYPE_POINT:
light += calculatePointLight(lights[i], input.normal, view, input.worldPosition, roughness, tint);
light += calculatePointLight(lights[i], input.normal, view, input.worldPosition, roughness, surface);
break;
}
}