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