File: ex_prim_shader_pixel.hlsl

package info (click to toggle)
allegro5 2%3A5.2.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,820 kB
  • sloc: ansic: 109,795; cpp: 12,976; objc: 4,592; java: 2,845; python: 2,595; javascript: 1,238; sh: 1,008; makefile: 40; xml: 27; pascal: 24
file content (27 lines) | stat: -rw-r--r-- 969 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
float3 light_position;
float4 diffuse_color;
float alpha;

/* Ported from ex_prim_shader_pixel.glsl. See that file for the comments. */

#define AMBIENT_COLOR float4(1, 1, 1, 1)
#define AMBIENT_INTENSITY 0.01
#define SPECULAR_COLOR float4(1, 1, 1, 1)

float4 ps_main(VS_OUTPUT Input) : COLOR0
{
   float3 light_vector = light_position - Input.PixelPosition;
   float3 light_dir = normalize(light_vector);
   float3 normal_vector = normalize(Input.Normal);

   float reflectance = dot(light_dir, normal_vector);
   reflectance = max(reflectance, 0.0f);

   float specular_intensity = dot((2 * reflectance * normal_vector - light_dir), float3(0, 0, 1));
   specular_intensity = max(0, specular_intensity);
   specular_intensity = pow(specular_intensity, alpha);

   float diffuse_intensity = reflectance * 10000.0 / dot(light_vector, light_vector);

   return AMBIENT_COLOR * AMBIENT_INTENSITY + diffuse_color * diffuse_intensity + SPECULAR_COLOR * specular_intensity;
}