-
- [vert.glsl]
- #version 130
-
- in vec3 in_position;
- in vec3 in_Normal;
- in vec4 in_color;
-
- uniform mat4 u_modelview;
- uniform mat4 u_view;
- uniform mat4 u_projection;
- uniform mat3 u_normalmat;
- uniform float u_damage;
-
- out vec4 pass_vertex; /* View space */
- out vec3 pass_tnormal;
- out vec4 pass_color;
-
- void main(void)
- {
- vec4 vertex = vec4(in_position + (in_Normal * u_damage), 1.0);
- float dam_perc = u_damage / (0.1 * 40);
- vec3 vGravity = vec3(0.0, -0.981, 0.0) * 2.0;
- float k = pow(dam_perc, 3);
- vertex = u_modelview * vertex + u_view * vec4(vGravity * k, 1.0);
- vec3 tnorm = normalize(u_normalmat * in_Normal);
-
- pass_vertex = vertex;
- pass_tnormal = tnorm;
- pass_color = in_color;
-
- gl_Position = u_projection * vertex;
- }
-
- [frag.glsl]
- #version 130
-
- #if defined GL_ES
- precision highp float;
- #endif
-
- in vec4 pass_vertex; /* View space */
- in vec3 pass_tnormal;
- in vec4 pass_color;
-
- uniform mat4 u_view;
- uniform mat4 u_inv_view;
- uniform mat4 u_inv_modelview;
- uniform float u_damage;
-
- //Light list
- uniform vec4 u_lights[8 * 2];
-
- void main(void)
- {
- /* Material properties */
- vec3 specular_reflect = vec3(0.8, 0.75, 0.4);
- float specular_power = 60.0;
-
- /* World properties */
- vec3 ambient = vec3(0.7, 0.7, 0.7);
- vec3 specular = vec3(0.0, 0.0, 0.0);
- vec3 diffuse = vec3(0.0, 0.0, 0.0);
-
- /* Light precalculations */
- vec3 v = normalize(-pass_vertex.xyz);
-
- /* Apply lighting */
- for (int i = 0; i < 8; i++)
- {
- vec4 pos = u_lights[i * 2];
- vec4 color = u_lights[i * 2 + 1];
- vec3 s, r;
-
- if (pos.w > 0.0)
- {
- /* Point light -- no attenuation yet */
- s = normalize((u_view * pos).xyz - pass_vertex.xyz);
- r = reflect(-s, pass_tnormal);
- }
- else
- {
- /* Directional light */
- s = normalize(-pos.xyz);
- r = reflect(s, pass_tnormal);
- }
-
- float sdotn = max(dot(s, pass_tnormal), 0.0);
- diffuse += color.xyz * sdotn;
- if (sdotn > 0.0)
- specular += color.xyz * specular_reflect
- * pow(max(dot(r, v), 0.0), specular_power);
- }
-
- vec3 light = ambient + diffuse + specular;
-
- vec4 world_vertex = u_inv_modelview * pass_vertex;
- vec4 world_normal = u_inv_modelview * vec4(pass_tnormal, 1.0);
-
- float dam_perc = u_damage / (0.1 * 40);
- float PI = 3.14159265358979323846264;
- dam_perc = (sin(PI * (dam_perc - 0.5)) * 0.5 + 0.5);
- dam_perc *= dam_perc;
- dam_perc = 1.0 - dam_perc;
- float mod = 2.0;
- float transp = dam_perc;
- /*
- abs(sin(world_vertex.x * mod) * dam_perc * 0.5 + 0.5) *
- abs(sin(world_vertex.y * mod) * dam_perc * 0.5 + 0.5) *
- abs(sin(world_vertex.z * mod) * dam_perc * 0.5 + 0.5)
- */
-
- //vec4 real_color = mix(pass_color, vec4(1.2, 1.2, 1.2, 1.0), u_damage);
- // - u_damage
- gl_FragColor = pass_color * vec4(light, (u_damage == 0)?(1.0):(transp));
- }
-
|