You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

183 lines
5.0 KiB

  1. [vert.glsl]
  2. #version 120
  3. attribute vec3 in_Position;
  4. attribute vec3 in_Normal;
  5. attribute vec4 in_Color;
  6. uniform mat4 u_modelview;
  7. uniform mat4 u_view;
  8. uniform mat4 u_projection;
  9. uniform mat3 u_normalmat;
  10. uniform float in_Damage;
  11. varying vec4 pass_Vertex; /* View space */
  12. varying vec3 pass_TNormal;
  13. varying vec4 pass_Color;
  14. void main(void)
  15. {
  16. vec4 vertex = vec4(in_Position + (in_Normal * in_Damage), 1.0);
  17. float dam_perc = in_Damage / (0.1 * 40);
  18. vec3 vGravity = vec3(0.0, -0.981, 0.0) * 2.0;
  19. float k = pow(dam_perc, 3);
  20. vertex = u_modelview * vertex + u_view * vec4(vGravity * k, 1.0);
  21. vec3 tnorm = normalize(u_normalmat * in_Normal);
  22. pass_Vertex = vertex;
  23. pass_TNormal = tnorm;
  24. pass_Color = in_Color;
  25. gl_Position = u_projection * vertex;
  26. }
  27. [frag.glsl]
  28. #version 120
  29. #if defined GL_ES
  30. precision highp float;
  31. #endif
  32. uniform mat4 u_view;
  33. uniform mat4 u_inv_view;
  34. uniform mat4 u_inv_modelview;
  35. uniform float in_Damage;
  36. //Light list
  37. uniform vec4 u_lights[8 * 2];
  38. varying vec4 pass_Vertex; /* View space */
  39. varying vec3 pass_TNormal;
  40. varying vec4 pass_Color;
  41. void main(void)
  42. {
  43. /* Material properties */
  44. vec3 specular_reflect = vec3(0.8, 0.75, 0.4);
  45. float specular_power = 60.0;
  46. /* World properties */
  47. vec3 ambient = vec3(0.7, 0.7, 0.7);
  48. vec3 specular = vec3(0.0, 0.0, 0.0);
  49. vec3 diffuse = vec3(0.0, 0.0, 0.0);
  50. /* Light precalculations */
  51. vec3 v = normalize(-pass_Vertex.xyz);
  52. /* Apply lighting */
  53. for (int i = 0; i < 8; i++)
  54. {
  55. vec4 pos = u_lights[i * 2];
  56. vec4 color = u_lights[i * 2 + 1];
  57. vec3 s, r;
  58. if (pos.w > 0.0)
  59. {
  60. /* Point light -- no attenuation yet */
  61. s = normalize((u_view * pos).xyz - pass_Vertex.xyz);
  62. r = reflect(-s, pass_TNormal);
  63. }
  64. else
  65. {
  66. /* Directional light */
  67. s = normalize(-pos.xyz);
  68. r = reflect(s, pass_TNormal);
  69. }
  70. float sdotn = max(dot(s, pass_TNormal), 0.0);
  71. diffuse += color.xyz * sdotn;
  72. if (sdotn > 0.0)
  73. specular += color.xyz * specular_reflect
  74. * pow(max(dot(r, v), 0.0), specular_power);
  75. }
  76. vec3 light = ambient + diffuse + specular;
  77. vec4 world_vertex = u_inv_modelview * pass_Vertex;
  78. vec4 world_normal = u_inv_modelview * vec4(pass_TNormal, 1.0);
  79. float dam_perc = in_Damage / (0.1 * 40);
  80. float PI = 3.14159265358979323846264;
  81. dam_perc = (sin(PI * (dam_perc - 0.5)) * 0.5 + 0.5);
  82. dam_perc *= dam_perc;
  83. dam_perc = 1.0 - dam_perc;
  84. float mod = 2.0;
  85. float transp = dam_perc;
  86. /*
  87. abs(sin(world_vertex.x * mod) * dam_perc * 0.5 + 0.5) *
  88. abs(sin(world_vertex.y * mod) * dam_perc * 0.5 + 0.5) *
  89. abs(sin(world_vertex.z * mod) * dam_perc * 0.5 + 0.5)
  90. */
  91. //vec4 real_color = mix(pass_Color, vec4(1.2, 1.2, 1.2, 1.0), in_Damage);
  92. // - in_Damage
  93. gl_FragColor = pass_Color * vec4(light, (in_Damage == 0)?(1.0):(transp));
  94. }
  95. [vert.hlsl]
  96. void main(float3 in_Vertex : POSITION,
  97. float3 in_Normal : NORMAL,
  98. float4 in_Color : COLOR,
  99. uniform float4x4 u_modelview,
  100. uniform float4x4 u_projection,
  101. uniform float3x3 u_normalmat,
  102. out float4 pass_Vertex : TEXCOORD0,
  103. out float3 pass_TNormal : TEXCOORD1,
  104. out float4 pass_Color : COLOR,
  105. out float4 out_Position : POSITION)
  106. {
  107. float4 eye = mul(u_modelview, float4(in_Vertex, 1.0));
  108. float3 tnorm = normalize(mul(u_normalmat, in_Normal));
  109. pass_Vertex = eye;
  110. pass_TNormal = tnorm;
  111. #ifdef _XBOX
  112. pass_Color = in_Color.abgr;
  113. #else
  114. pass_Color = in_Color;
  115. #endif
  116. out_Position = mul(u_projection, eye);
  117. }
  118. [frag.hlsl]
  119. void main(float4 pass_Vertex : TEXCOORD0,
  120. float3 pass_TNormal : TEXCOORD1,
  121. float4 pass_Color : COLOR,
  122. uniform float in_Damage,
  123. out float4 out_FragColor : COLOR)
  124. {
  125. float3 in_LightDir = float3(0.3, 0.3, 0.7);
  126. /* Material properties */
  127. float3 specular_reflect = float3(0.8, 0.75, 0.4);
  128. float specular_power = 60.0;
  129. /* World properties */
  130. float ambient_mul = 0.5;
  131. float3 ambient_color = float3(0.25, 0.2, 0.35);
  132. float3 diffuse_color = float3(1.0, 1.0, 0.6);
  133. float3 specular_color = float3(1.0, 1.0, 0.6);
  134. float3 s = normalize(in_LightDir); /* normalize(pass_Vertex - lightpos); */
  135. float3 v = normalize(-pass_Vertex.xyz);
  136. float3 r = reflect(-s, pass_TNormal);
  137. float3 ambient = ambient_color;
  138. float sdotn = max(dot(s, pass_TNormal), 0.0);
  139. float3 diffuse = diffuse_color * sdotn;
  140. float3 specular = float3(0.0, 0.0, 0.0);
  141. if (sdotn > 0.0)
  142. specular = specular_color * specular_reflect
  143. * pow(max(dot(r, v), 0.0), specular_power);
  144. float3 light = ambient + diffuse + specular;
  145. float4 real_color = in_Damage * float4(1.2, 1.2, 1.2, 1.0)
  146. + (1.0 - in_Damage) * pass_Color;
  147. out_FragColor = real_color * float4(light, 1.0);
  148. }