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