1 | |
---|
2 | -- GLSL.Vert -- |
---|
3 | #version 120 |
---|
4 | |
---|
5 | attribute vec3 in_Vertex; |
---|
6 | attribute vec3 in_Normal; |
---|
7 | attribute vec4 in_Color; |
---|
8 | uniform mat4 in_ModelView; |
---|
9 | uniform mat4 in_Proj; |
---|
10 | uniform mat3 in_NormalMat; |
---|
11 | uniform float in_Damage; |
---|
12 | varying vec4 pass_Color; |
---|
13 | |
---|
14 | void main(void) |
---|
15 | { |
---|
16 | /* Material properties */ |
---|
17 | vec3 specular_reflect = vec3(0.8, 0.75, 0.4); |
---|
18 | float specular_power = 60.0; |
---|
19 | |
---|
20 | /* World properties */ |
---|
21 | float ambient_mul = 0.5; |
---|
22 | vec3 light_dir = normalize(vec3(0.3, 0.3, 0.7)); |
---|
23 | vec3 ambient_color = vec3(0.25, 0.2, 0.35); |
---|
24 | vec3 diffuse_color = vec3(1.0, 1.0, 0.6); |
---|
25 | vec3 specular_color = vec3(1.0, 1.0, 0.6); |
---|
26 | |
---|
27 | vec3 tnorm = normalize(in_NormalMat * in_Normal); |
---|
28 | vec4 eye = in_ModelView * vec4(in_Vertex, 1.0); |
---|
29 | |
---|
30 | vec3 s = light_dir; /* normalize(eye - lightpos); */ |
---|
31 | vec3 v = normalize(-eye.xyz); |
---|
32 | vec3 r = reflect(-s, tnorm); |
---|
33 | |
---|
34 | vec3 ambient = ambient_color; |
---|
35 | float sdotn = max(dot(s, tnorm), 0.0); |
---|
36 | vec3 diffuse = diffuse_color * sdotn; |
---|
37 | vec3 specular = vec3(0.0, 0.0, 0.0); |
---|
38 | if (sdotn > 0.0) |
---|
39 | specular = specular_color * specular_reflect |
---|
40 | * pow(max(dot(r, v), 0.0), specular_power); |
---|
41 | vec3 light = ambient + diffuse + specular; |
---|
42 | |
---|
43 | vec4 real_color = in_Damage * vec4(1.2, 1.2, 1.2, 1.0) |
---|
44 | + (1.0 - in_Damage) * in_Color; |
---|
45 | pass_Color = real_color * vec4(light, 1.0); |
---|
46 | gl_Position = in_Proj * eye; |
---|
47 | } |
---|
48 | |
---|
49 | -- GLSL.Frag -- |
---|
50 | #version 120 |
---|
51 | |
---|
52 | //precision highp float; |
---|
53 | varying vec4 pass_Color; |
---|
54 | |
---|
55 | void main(void) { |
---|
56 | gl_FragColor = pass_Color; |
---|
57 | } |
---|
58 | |
---|
59 | -- HLSL.Vert -- |
---|
60 | |
---|
61 | void main(float3 in_Vertex : POSITION, |
---|
62 | float3 in_Normal : NORMAL, |
---|
63 | float4 in_Color : COLOR, |
---|
64 | uniform float4x4 in_ModelView, |
---|
65 | uniform float4x4 in_Proj, |
---|
66 | uniform float3x3 in_NormalMat, |
---|
67 | uniform float in_Damage, |
---|
68 | out float4 out_Position : POSITION, |
---|
69 | out float4 pass_Color : COLOR) |
---|
70 | { |
---|
71 | float3 specular_reflect = float3(0.8, 0.75, 0.4); |
---|
72 | float specular_power = 60.0; |
---|
73 | float ambient_mul = 0.5; |
---|
74 | float3 light_dir = normalize(float3(0.3, 0.3, 0.7)); |
---|
75 | float3 ambient_color = float3(0.25, 0.2, 0.35); |
---|
76 | float3 diffuse_color = float3(1.0, 1.0, 0.6); |
---|
77 | float3 specular_color = float3(1.0, 1.0, 0.6); |
---|
78 | float3 tnorm = normalize(mul(in_NormalMat, in_Normal)); |
---|
79 | float4 eye = mul(in_ModelView, float4(in_Vertex, 1.0)); |
---|
80 | float3 s = light_dir; |
---|
81 | float3 v = normalize(-eye.xyz); |
---|
82 | float3 r = reflect(-s, tnorm); |
---|
83 | float3 ambient = ambient_color; |
---|
84 | float sdotn = max(dot(s, tnorm), 0.0); |
---|
85 | float3 diffuse = diffuse_color * sdotn; |
---|
86 | float3 specular = float3(0.0, 0.0, 0.0); |
---|
87 | if (sdotn > 0.0) |
---|
88 | specular = specular_color * specular_reflect |
---|
89 | * pow(max(dot(r, v), 0.0), specular_power); |
---|
90 | float3 light = ambient + diffuse + specular; |
---|
91 | #ifdef _XBOX |
---|
92 | float4 real_color = in_Color.abgr; |
---|
93 | #else |
---|
94 | float4 real_color = in_Color; |
---|
95 | #endif |
---|
96 | real_color = in_Damage * float4(1.2, 1.2, 1.2, 1.0) |
---|
97 | + (1.0 - in_Damage) * real_color; |
---|
98 | pass_Color = real_color * float4(light, 1.0); |
---|
99 | out_Position = mul(in_Proj, eye); |
---|
100 | } |
---|
101 | |
---|
102 | -- HLSL.Frag -- |
---|
103 | |
---|
104 | void main(float4 pass_Color : COLOR, |
---|
105 | out float4 out_FragColor : COLOR) |
---|
106 | { |
---|
107 | out_FragColor = pass_Color; |
---|
108 | } |
---|
109 | |
---|