45 lines
1.4 KiB
HLSL
45 lines
1.4 KiB
HLSL
Texture2D MainTexture;
|
|
SamplerState MainSampler;
|
|
|
|
cbuffer LightBuffer // has to be always 16 byte aligned
|
|
{
|
|
float3 LightVector;
|
|
float LightIntensity;
|
|
float4 DiffuseColor;
|
|
float4 SpecularColor;
|
|
float3 CameraPosition;
|
|
float Phong;
|
|
};
|
|
|
|
struct PixelInput
|
|
{
|
|
float4 position : SV_POSITION;
|
|
float3 positionWorld : POSITION1;
|
|
float3 normal : NORMAL;
|
|
float2 uv : TEXCOORD;
|
|
};
|
|
|
|
float4 main(PixelInput INPUT) : SV_TARGET
|
|
{
|
|
float4 texColor = MainTexture.Sample(MainSampler, INPUT.uv);
|
|
float4 ambientColor = float4(0.2f, 0.2f, 0.2f, 1.0f);
|
|
float4 diffuseColor = DiffuseColor;
|
|
float4 specularColor = SpecularColor;
|
|
float4 emissionColor = float4(0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
float3 lightVector = normalize(-LightVector);
|
|
float3 normalVector = normalize(INPUT.normal);
|
|
|
|
// diffuse color
|
|
float diffuse = dot(lightVector, normalVector); // diffuse intensity
|
|
diffuseColor *= diffuse * LightIntensity;
|
|
|
|
// specular color
|
|
float3 reflectVector = normalize(reflect(-lightVector, normalVector));
|
|
//float3 reflectVector = 2 * normalVector * diffuse - lightVector;
|
|
float3 viewVector = normalize(CameraPosition - INPUT.positionWorld);
|
|
float specular = pow(max(dot(reflectVector, viewVector), 0), Phong);
|
|
specularColor *= specular * LightIntensity;
|
|
|
|
return saturate(saturate(texColor * saturate(ambientColor + diffuseColor) + specularColor) + emissionColor);
|
|
} |