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