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