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.
 
 
 

165 rivejä
4.2 KiB

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