move light code from SimplePixelShader to Lights
This commit is contained in:
parent
80e0790a63
commit
f0ab528f13
2 changed files with 31 additions and 31 deletions
31
Lights.hlsli
31
Lights.hlsli
|
@ -22,4 +22,35 @@ struct Light
|
||||||
float3 Padding;
|
float3 Padding;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Gets the specular value for any light
|
||||||
|
float calculateSpecular(float3 normal, float3 direction, float3 view, float roughness)
|
||||||
|
{
|
||||||
|
return getSpecular(
|
||||||
|
view,
|
||||||
|
getReflection(direction, normal),
|
||||||
|
getSpecularExponent(roughness, MAX_SPECULAR_EXPONENT)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gets the RGB value of a pixel with a directional light
|
||||||
|
float3 calculateDirectionalLight(Light light, float3 normal, float3 view, float roughness, float3 surfaceColor, float specularValue)
|
||||||
|
{
|
||||||
|
float3 lightDirection = normalize(light.Direction);
|
||||||
|
float diffuse = getDiffuse(normal, -lightDirection);
|
||||||
|
float specular = calculateSpecular(normal, lightDirection, view, roughness) * specularValue;
|
||||||
|
|
||||||
|
return (diffuse * surfaceColor + specular) * light.Intensity * light.Color;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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, float specularValue)
|
||||||
|
{
|
||||||
|
float3 lightDirection = normalize(light.Position - worldPosition);
|
||||||
|
float attenuation = getAttenuation(light.Position, worldPosition, light.Range);
|
||||||
|
float diffuse = getDiffuse(normal, lightDirection);
|
||||||
|
float specular = calculateSpecular(normal, lightDirection, view, roughness) * specularValue;
|
||||||
|
|
||||||
|
return (diffuse * surfaceColor + specular) * attenuation * light.Intensity * light.Color;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -26,37 +26,6 @@ Texture2D Specular : register(t1);
|
||||||
Texture2D Emissive : register(t2);
|
Texture2D Emissive : register(t2);
|
||||||
SamplerState BasicSampler : register(s0);
|
SamplerState BasicSampler : register(s0);
|
||||||
|
|
||||||
// Gets the specular value for any light
|
|
||||||
float calculateSpecular(float3 normal, float3 direction, float3 view, float roughness)
|
|
||||||
{
|
|
||||||
return getSpecular(
|
|
||||||
view,
|
|
||||||
getReflection(direction, normal),
|
|
||||||
getSpecularExponent(roughness, MAX_SPECULAR_EXPONENT)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gets the RGB value of a pixel with a directional light
|
|
||||||
float3 calculateDirectionalLight(Light light, float3 normal, float3 view, float roughness, float3 surfaceColor, float specularValue)
|
|
||||||
{
|
|
||||||
float3 lightDirection = normalize(light.Direction);
|
|
||||||
float diffuse = getDiffuse(normal, -lightDirection);
|
|
||||||
float specular = calculateSpecular(normal, lightDirection, view, roughness) * specularValue;
|
|
||||||
|
|
||||||
return (diffuse * surfaceColor + specular) * light.Intensity * light.Color;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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, float specularValue)
|
|
||||||
{
|
|
||||||
float3 lightDirection = normalize(light.Position - worldPosition);
|
|
||||||
float attenuation = getAttenuation(light.Position, worldPosition, light.Range);
|
|
||||||
float diffuse = getDiffuse(normal, lightDirection);
|
|
||||||
float specular = calculateSpecular(normal, lightDirection, view, roughness) * specularValue;
|
|
||||||
|
|
||||||
return (diffuse * surfaceColor + specular) * attenuation * light.Intensity * light.Color;
|
|
||||||
}
|
|
||||||
|
|
||||||
// shader entry point
|
// shader entry point
|
||||||
float4 main(VertexToPixel input) : SV_TARGET
|
float4 main(VertexToPixel input) : SV_TARGET
|
||||||
{
|
{
|
||||||
|
|
Reference in a new issue