No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

226 líneas
6.3 KiB

  1. [vert.glsl]
  2. #version 120
  3. attribute vec3 in_Vertex;
  4. attribute vec3 in_Normal;
  5. attribute vec4 in_Color;
  6. attribute vec2 in_Index;
  7. attribute vec2 in_Weight;
  8. uniform mat4 in_ModelView;
  9. uniform mat4 in_View;
  10. uniform mat4 in_Proj;
  11. uniform mat3 in_NormalMat;
  12. //10is not a fix idea, should be more.
  13. uniform mat4 in_BoneList[10];
  14. varying vec4 pass_Vertex; /* View space */
  15. varying vec3 pass_TNormal;
  16. varying vec4 pass_Color;
  17. void main(void)
  18. {
  19. vec4 vertex = in_ModelView * vec4(in_Vertex, 1.0);
  20. vec3 tnorm = normalize(in_NormalMat * in_Normal);
  21. pass_Vertex = vertex;
  22. pass_TNormal = tnorm;
  23. pass_Color = in_Color;
  24. gl_Position = in_Proj * vertex;
  25. }
  26. [frag.glsl]
  27. #version 120
  28. #if defined GL_ES
  29. precision highp float;
  30. #endif
  31. uniform float in_Damage;
  32. uniform mat4 in_View;
  33. uniform mat4 in_Inv_View;
  34. uniform vec4 u_Lights[8 * 2];
  35. varying vec4 pass_Vertex; /* View space */
  36. varying vec3 pass_TNormal;
  37. varying vec4 pass_Color;
  38. #if 0
  39. //Cube Light
  40. //Cos(45) = 0.70710678118
  41. //1.0 - Cos(45) = 0.29289321881
  42. const float cos_45 = 0.70710678118;
  43. const float inv_cos_45 = 0.29289321881;
  44. vec4 in_Light3_Pos = vec4(-10.0, 20.0, 0.0, 1.0);
  45. vec3 in_Light3_Size_Inner = vec3(12.0, 12.0, 12.0);
  46. vec3 in_Light3_Size_Outer = vec3(10.0, 10.0, 10.0);
  47. vec3 in_Light3_diffuse = vec3(0.4, 1.0, 0.4);
  48. #endif
  49. void main(void)
  50. {
  51. /* Material properties */
  52. vec3 specular_reflect = vec3(0.8, 0.75, 0.4);
  53. float specular_power = 60.0;
  54. /* World properties */
  55. vec3 ambient = vec3(0.7, 0.7, 0.7);
  56. vec3 specular = vec3(0.0, 0.0, 0.0);
  57. vec3 diffuse = vec3(0.0, 0.0, 0.0);
  58. /* Light precalculations */
  59. vec3 v = normalize(-pass_Vertex.xyz);
  60. /* Apply lighting */
  61. for (int i = 0; i < 8; i++)
  62. {
  63. vec4 pos = u_Lights[i * 2];
  64. vec4 color = u_Lights[i * 2 + 1];
  65. vec3 s, r;
  66. if (pos.w > 0.0)
  67. {
  68. /* Point light -- no attenuation yet */
  69. s = normalize((in_View * pos).xyz - pass_Vertex.xyz);
  70. r = reflect(-s, pass_TNormal);
  71. }
  72. else
  73. {
  74. /* Directional light */
  75. s = normalize(-pos.xyz);
  76. r = reflect(s, pass_TNormal);
  77. }
  78. float sdotn = max(dot(s, pass_TNormal), 0.0);
  79. diffuse += color.xyz * sdotn;
  80. if (sdotn > 0.0)
  81. specular += color.xyz * specular_reflect
  82. * pow(max(dot(r, v), 0.0), specular_power);
  83. }
  84. #if 0
  85. //Light calculation for cube light
  86. //const float cos_45 = 0.70710678118;
  87. //const float inv_cos_45 = 0.29289321881;
  88. vec3 local_vertex = (in_Inv_View * pass_Vertex).xyz - (in_Light3_Pos).xyz;
  89. vec3 proj_vertex = clamp(local_vertex.xyz, -in_Light3_Size_Inner, in_Light3_Size_Inner);
  90. vec3 proj_local_dir = local_vertex - proj_vertex;
  91. vec3 inner_dir = proj_vertex / in_Light3_Size_Inner;
  92. inner_dir.x = (inner_dir.x == 1.0)?(1.0):(0.0);
  93. inner_dir.y = (inner_dir.y == 1.0)?(1.0):(0.0);
  94. inner_dir.z = (inner_dir.z == 1.0)?(1.0):(0.0);
  95. //inside the cube
  96. if (length(proj_local_dir) == 0.0)
  97. {
  98. sdotn = 1.0;
  99. light_radius_mod = 1.0;
  100. }
  101. //spec calculation
  102. else
  103. {
  104. //Distance calculation
  105. vec3 proj_local_light = proj_local_dir / in_Light3_Size_Outer;
  106. light_radius_mod = max(0.0, 1.0 - length(proj_local_light));
  107. //cube orientation
  108. sdotn = max(0.0, dot(normalize(proj_local_dir), normalize(inner_dir)));
  109. //if (length(inner_dir) > 1.0)
  110. // sdotn = 0.0;
  111. //else
  112. //{
  113. // //vec3 proj_local_light = max(vec3(0.0,0.0,0.0), vec3(1.0,1.0,1.0) - abs(proj_local_dir / in_Light3_Size_Outer));
  114. //}
  115. /*
  116. proj_local_dir = normalize((in_View * vec4(proj_vertex + in_Light3_Pos.xyz,1.0)).xyz - pass_Vertex.xyz);
  117. sdotn = max(dot(proj_local_dir, pass_TNormal), 0.0);
  118. r = reflect(-proj_local_dir, pass_TNormal);
  119. if (sdotn > 0.0 && light_radius_mod > 0.0)
  120. specular += specular_color * min(specular_reflect, light_radius_mod)
  121. * pow(max(dot(r, v), 0.0), specular_power);
  122. */
  123. }
  124. //diffuse calculation
  125. diffuse += in_Light3_diffuse * sdotn; //min(sdotn, light_radius_mod);
  126. //----------
  127. #endif
  128. vec3 light = ambient + diffuse + specular;
  129. vec4 real_color = mix(pass_Color, vec4(1.2, 1.2, 1.2, 1.0), in_Damage);
  130. gl_FragColor = real_color * vec4(light, 1.0);
  131. }
  132. [vert.hlsl]
  133. void main(float3 in_Vertex : POSITION,
  134. float3 in_Normal : NORMAL,
  135. float4 in_Color : COLOR,
  136. uniform float4x4 in_ModelView,
  137. uniform float4x4 in_Model,
  138. uniform float4x4 in_Proj,
  139. uniform float3x3 in_NormalMat,
  140. out float4 pass_Vertex : TEXCOORD0,
  141. out float3 pass_TNormal : TEXCOORD1,
  142. out float4 pass_Color : COLOR,
  143. out float4 out_Position : POSITION)
  144. {
  145. float4 eye = mul(in_ModelView, float4(in_Vertex, 1.0));
  146. float3 tnorm = normalize(mul(in_NormalMat, in_Normal));
  147. pass_Vertex = eye;
  148. pass_TNormal = tnorm;
  149. #ifdef _XBOX
  150. pass_Color = in_Color.abgr;
  151. #else
  152. pass_Color = in_Color;
  153. #endif
  154. out_Position = mul(in_Proj, eye);
  155. }
  156. [frag.hlsl]
  157. void main(float4 pass_Vertex : TEXCOORD0,
  158. float3 pass_TNormal : TEXCOORD1,
  159. float4 pass_Color : COLOR,
  160. uniform float in_Damage,
  161. out float4 out_FragColor : COLOR)
  162. {
  163. float3 in_LightDir = float3(0.3, 0.3, 0.7);
  164. /* Material properties */
  165. float3 specular_reflect = float3(0.8, 0.75, 0.4);
  166. float specular_power = 60.0;
  167. /* World properties */
  168. float ambient_mul = 0.5;
  169. float3 ambient_color = float3(0.25, 0.2, 0.35);
  170. float3 diffuse_color = float3(1.0, 1.0, 0.6);
  171. float3 specular_color = float3(1.0, 1.0, 0.6);
  172. float3 s = normalize(in_LightDir); /* normalize(pass_Vertex - lightpos); */
  173. float3 v = normalize(-pass_Vertex.xyz);
  174. float3 r = reflect(-s, pass_TNormal);
  175. float3 ambient = ambient_color;
  176. float sdotn = max(dot(s, pass_TNormal), 0.0);
  177. float3 diffuse = diffuse_color * sdotn;
  178. float3 specular = float3(0.0, 0.0, 0.0);
  179. if (sdotn > 0.0)
  180. specular = specular_color * specular_reflect
  181. * pow(max(dot(r, v), 0.0), specular_power);
  182. float3 light = ambient + diffuse + specular;
  183. float4 real_color = in_Damage * float4(1.2, 1.2, 1.2, 1.0)
  184. + (1.0 - in_Damage) * pass_Color;
  185. out_FragColor = real_color * float4(light, 1.0);
  186. }