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 = vec4(1.0, 1.0, 1.0, in_Color.w);//; |
---|
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 | uniform mat4 in_Inv_View; |
---|
40 | |
---|
41 | uniform vec4 u_Lights[8 * 2]; |
---|
42 | |
---|
43 | varying vec4 pass_Vertex; /* View space */ |
---|
44 | varying vec3 pass_TNormal; |
---|
45 | varying vec4 pass_Color; |
---|
46 | |
---|
47 | void main(void) |
---|
48 | { |
---|
49 | /* Material properties */ |
---|
50 | vec3 specular_reflect = vec3(0.8, 0.75, 0.4); |
---|
51 | float specular_power = 60.0; |
---|
52 | |
---|
53 | /* World properties */ |
---|
54 | vec3 ambient = vec3(0.1, 0.1, 0.1); |
---|
55 | vec3 specular = vec3(0.0, 0.0, 0.0); |
---|
56 | vec3 diffuse = vec3(0.0, 0.0, 0.0); |
---|
57 | |
---|
58 | /* Light precalculations */ |
---|
59 | vec3 v = normalize(-pass_Vertex.xyz); |
---|
60 | |
---|
61 | /* Apply lighting */ |
---|
62 | for (int i = 0; i < 8; i++) |
---|
63 | { |
---|
64 | vec4 pos = u_Lights[i * 2]; |
---|
65 | vec4 color = u_Lights[i * 2 + 1]; |
---|
66 | vec3 s, r; |
---|
67 | |
---|
68 | if (pos.w > 0.0) |
---|
69 | { |
---|
70 | /* Point light -- no attenuation yet */ |
---|
71 | s = normalize((in_View * pos).xyz - pass_Vertex.xyz); |
---|
72 | r = reflect(-s, pass_TNormal); |
---|
73 | } |
---|
74 | else |
---|
75 | { |
---|
76 | /* Directional light */ |
---|
77 | s = normalize(-pos.xyz); |
---|
78 | r = reflect(s, pass_TNormal); |
---|
79 | } |
---|
80 | |
---|
81 | float sdotn = max(dot(s, pass_TNormal), 0.0); |
---|
82 | diffuse += color.xyz * sdotn; |
---|
83 | if (sdotn > 0.0) |
---|
84 | specular += color.xyz * specular_reflect |
---|
85 | * pow(max(dot(r, v), 0.0), specular_power); |
---|
86 | } |
---|
87 | |
---|
88 | vec3 light = ambient + diffuse + specular; |
---|
89 | |
---|
90 | //vec4 real_color = mix(pass_Color, vec4(1.0, 1.0, 1.0, 1.0), 1.0); |
---|
91 | gl_FragColor = pass_Color * vec4(light, 1.0); |
---|
92 | } |
---|
93 | |
---|
94 | [vert.hlsl] |
---|
95 | |
---|
96 | void main(float3 in_Vertex : POSITION, |
---|
97 | float3 in_Normal : NORMAL, |
---|
98 | float4 in_Color : COLOR, |
---|
99 | uniform float4x4 in_ModelView, |
---|
100 | uniform float4x4 in_Model, |
---|
101 | uniform float4x4 in_Proj, |
---|
102 | uniform float3x3 in_NormalMat, |
---|
103 | out float4 pass_Vertex : TEXCOORD0, |
---|
104 | out float3 pass_TNormal : TEXCOORD1, |
---|
105 | out float4 pass_Color : COLOR, |
---|
106 | out float4 out_Position : POSITION) |
---|
107 | { |
---|
108 | float4 eye = mul(in_ModelView, float4(in_Vertex, 1.0)); |
---|
109 | float3 tnorm = normalize(mul(in_NormalMat, in_Normal)); |
---|
110 | |
---|
111 | pass_Vertex = eye; |
---|
112 | pass_TNormal = tnorm; |
---|
113 | #ifdef _XBOX |
---|
114 | pass_Color = in_Color.abgr; |
---|
115 | #else |
---|
116 | pass_Color = in_Color; |
---|
117 | #endif |
---|
118 | |
---|
119 | out_Position = mul(in_Proj, eye); |
---|
120 | } |
---|
121 | |
---|
122 | [frag.hlsl] |
---|
123 | |
---|
124 | void main(float4 pass_Vertex : TEXCOORD0, |
---|
125 | float3 pass_TNormal : TEXCOORD1, |
---|
126 | float4 pass_Color : COLOR, |
---|
127 | uniform float in_Damage, |
---|
128 | out float4 out_FragColor : COLOR) |
---|
129 | { |
---|
130 | float3 in_LightDir = float3(0.3, 0.3, 0.7); |
---|
131 | |
---|
132 | /* Material properties */ |
---|
133 | float3 specular_reflect = float3(0.8, 0.75, 0.4); |
---|
134 | float specular_power = 60.0; |
---|
135 | |
---|
136 | /* World properties */ |
---|
137 | float ambient_mul = 0.5; |
---|
138 | float3 ambient_color = float3(0.25, 0.2, 0.35); |
---|
139 | float3 diffuse_color = float3(1.0, 1.0, 0.6); |
---|
140 | float3 specular_color = float3(1.0, 1.0, 0.6); |
---|
141 | |
---|
142 | float3 s = normalize(in_LightDir); /* normalize(pass_Vertex - lightpos); */ |
---|
143 | float3 v = normalize(-pass_Vertex.xyz); |
---|
144 | float3 r = reflect(-s, pass_TNormal); |
---|
145 | |
---|
146 | float3 ambient = ambient_color; |
---|
147 | float sdotn = max(dot(s, pass_TNormal), 0.0); |
---|
148 | float3 diffuse = diffuse_color * sdotn; |
---|
149 | float3 specular = float3(0.0, 0.0, 0.0); |
---|
150 | if (sdotn > 0.0) |
---|
151 | specular = specular_color * specular_reflect |
---|
152 | * pow(max(dot(r, v), 0.0), specular_power); |
---|
153 | float3 light = ambient + diffuse + specular; |
---|
154 | |
---|
155 | float4 real_color = in_Damage * float4(1.2, 1.2, 1.2, 1.0) |
---|
156 | + (1.0 - in_Damage) * pass_Color; |
---|
157 | out_FragColor = real_color * float4(light, 1.0); |
---|
158 | } |
---|
159 | |
---|