25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

184 satır
5.0 KiB

  1. [vert.glsl]
  2. #version 120
  3. attribute vec3 in_Vertex;
  4. attribute vec3 in_Normal;
  5. attribute vec4 in_Color;
  6. uniform mat4 in_ModelView;
  7. uniform mat4 in_View;
  8. uniform mat4 in_Proj;
  9. uniform mat3 in_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_Vertex + (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 = in_ModelView * vertex + in_View * vec4(vGravity * k, 1.0);
  21. vec3 tnorm = normalize(in_NormalMat * in_Normal);
  22. pass_Vertex = vertex;
  23. pass_TNormal = tnorm;
  24. pass_Color = in_Color;
  25. gl_Position = in_Proj * vertex;
  26. }
  27. [frag.glsl]
  28. #version 120
  29. #if defined GL_ES
  30. precision highp float;
  31. #endif
  32. uniform mat4 in_View;
  33. uniform mat4 in_Inv_View;
  34. uniform mat4 in_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((in_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 = in_Inv_ModelView * pass_Vertex;
  78. vec4 world_normal = in_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 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. pass_Vertex = eye;
  111. pass_TNormal = tnorm;
  112. #ifdef _XBOX
  113. pass_Color = in_Color.abgr;
  114. #else
  115. pass_Color = in_Color;
  116. #endif
  117. out_Position = mul(in_Proj, eye);
  118. }
  119. [frag.hlsl]
  120. void main(float4 pass_Vertex : TEXCOORD0,
  121. float3 pass_TNormal : TEXCOORD1,
  122. float4 pass_Color : COLOR,
  123. uniform float in_Damage,
  124. out float4 out_FragColor : COLOR)
  125. {
  126. float3 in_LightDir = float3(0.3, 0.3, 0.7);
  127. /* Material properties */
  128. float3 specular_reflect = float3(0.8, 0.75, 0.4);
  129. float specular_power = 60.0;
  130. /* World properties */
  131. float ambient_mul = 0.5;
  132. float3 ambient_color = float3(0.25, 0.2, 0.35);
  133. float3 diffuse_color = float3(1.0, 1.0, 0.6);
  134. float3 specular_color = float3(1.0, 1.0, 0.6);
  135. float3 s = normalize(in_LightDir); /* normalize(pass_Vertex - lightpos); */
  136. float3 v = normalize(-pass_Vertex.xyz);
  137. float3 r = reflect(-s, pass_TNormal);
  138. float3 ambient = ambient_color;
  139. float sdotn = max(dot(s, pass_TNormal), 0.0);
  140. float3 diffuse = diffuse_color * sdotn;
  141. float3 specular = float3(0.0, 0.0, 0.0);
  142. if (sdotn > 0.0)
  143. specular = specular_color * specular_reflect
  144. * pow(max(dot(r, v), 0.0), specular_power);
  145. float3 light = ambient + diffuse + specular;
  146. float4 real_color = in_Damage * float4(1.2, 1.2, 1.2, 1.0)
  147. + (1.0 - in_Damage) * pass_Color;
  148. out_FragColor = real_color * float4(light, 1.0);
  149. }