| 1 |
float3 light_position; |
| 2 |
float4 diffuse_color; |
| 3 |
float alpha; |
| 4 |
|
| 5 |
/* Ported from ex_prim_shader_pixel.glsl. See that file for the comments. */ |
| 6 |
|
| 7 |
#define AMBIENT_COLOR float4(1, 1, 1, 1) |
| 8 |
#define AMBIENT_INTENSITY 0.01 |
| 9 |
#define SPECULAR_COLOR float4(1, 1, 1, 1) |
| 10 |
|
| 11 |
float4 ps_main(VS_OUTPUT Input) : COLOR0 |
| 12 |
{ |
| 13 |
float3 light_vector = light_position - Input.PixelPosition; |
| 14 |
float3 light_dir = normalize(light_vector); |
| 15 |
float3 normal_vector = normalize(Input.Normal); |
| 16 |
|
| 17 |
float reflectance = dot(light_dir, normal_vector); |
| 18 |
reflectance = max(reflectance, 0.0f); |
| 19 |
|
| 20 |
float specular_intensity = dot((2 * reflectance * normal_vector - light_dir), float3(0, 0, 1)); |
| 21 |
specular_intensity = max(0, specular_intensity); |
| 22 |
specular_intensity = pow(specular_intensity, alpha); |
| 23 |
|
| 24 |
float diffuse_intensity = reflectance * 10000.0 / dot(light_vector, light_vector); |
| 25 |
|
| 26 |
return AMBIENT_COLOR * AMBIENT_INTENSITY + diffuse_color * diffuse_intensity + SPECULAR_COLOR * specular_intensity; |
| 27 |
} |