1
0
mirror of https://github.com/ncblakely/GiantsTools synced 2024-11-23 14:45:37 +01:00
GiantsTools/Shaders/fxh/Lighting.fxh

91 lines
1.9 KiB
HLSL
Raw Normal View History

2020-12-01 02:40:33 +01:00
#include "Constants.fxh"
2020-11-03 10:46:00 +01:00
struct Material
{
float4 Diffuse;
float4 Ambient;
float4 Specular;
float4 Emissive;
float Power;
};
struct Lighting
{
float4 Diffuse : COLOR0;
float4 Specular : COLOR1;
};
2020-12-01 02:40:33 +01:00
struct DirectionalLightInfo
{
int Count;
int SunIndex;
float4 Ambient;
float4 Diffuse[MAX_DIRECTIONAL_LIGHTS];
float4 Specular[MAX_DIRECTIONAL_LIGHTS];
float4 Direction[MAX_DIRECTIONAL_LIGHTS];
};
struct PointLightInfo
{
int Count;
float4 Position[MAX_POINT_LIGHTS];
float4 Diffuse[MAX_POINT_LIGHTS];
float Range[MAX_POINT_LIGHTS];
};
struct TextureBlendStage
{
int colorOp;
int colorArg1;
int colorArg2;
int alphaOp;
int alphaArg1;
int alphaArg2;
2020-12-01 02:40:33 +01:00
};
struct BlendStageInfo
{
int Count;
TextureBlendStage BlendStages[MAX_BLEND_STAGES];
};
struct ColorMixMode
{
int BumpMappingEnabled;
int EnvironmentMappingEnabled;
};
float4 CalculateDirectionalDiffuse(float3 N, float3 L, float4 diffuseColor)
{
float NDotL = dot(N, L);
float4 finalColor = 0;
if (NDotL > 0.0f)
{
finalColor = max(0, NDotL * diffuseColor);
}
return finalColor;
}
float4 CalculateDirectionalSpecular(float3 worldPos, float3 cameraPosition, float3 N, float3 L, float4 specularColor, float specularPower)
{
float4 finalColor = 0;
if (specularPower)
{
float3 toEye = normalize(cameraPosition - worldPos);
float3 halfway = normalize(toEye + L);
float NDotH = saturate(dot(halfway, N));
finalColor = max(0, pow(NDotH, specularPower) * specularColor);
}
return finalColor;
}
inline float4 CalculatePointDiffuse(float3 worldPos, float3 N, float3 L, float range, float4 diffuseColor)
{
float diffuseLighting = saturate(dot(N, L));
diffuseLighting *= (range / dot(worldPos, worldPos));
return diffuseLighting * diffuseColor;
}