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.
 
 
 

155 lines
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 u_modelview;
  8. uniform mat4 u_view;
  9. uniform mat4 u_projection;
  10. uniform mat3 u_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 = u_modelview * vec4(in_Position, 1.0);
  18. vec3 tnorm = normalize(u_normalmat * in_Normal);
  19. pass_Vertex = vertex;
  20. pass_TNormal = tnorm;
  21. pass_Color = in_Color;
  22. pass_TexCoord = in_TexCoord;
  23. gl_Position = u_projection * vertex;
  24. }
  25. [frag.glsl]
  26. #version 120
  27. #if defined GL_ES
  28. precision highp float;
  29. #endif
  30. uniform float in_Damage;
  31. uniform mat4 u_view;
  32. uniform mat4 u_inv_view;
  33. uniform vec4 u_lights[8 * 2];
  34. varying vec4 pass_Vertex; /* View space */
  35. varying vec3 pass_TNormal;
  36. varying vec4 pass_Color;
  37. varying vec2 pass_TexCoord;
  38. void main(void)
  39. {
  40. float mode = 0.0;
  41. if (mode == 0.0)
  42. {
  43. gl_FragColor = vec4(mod(pass_TexCoord.x, 1.0),
  44. 0.1,
  45. mod(pass_TexCoord.y, 1.0), 1.0);
  46. }
  47. else
  48. {
  49. float col = ((mod(mode, 2.0) == 1.0)?(mod(pass_TexCoord.x, 1.0)):(mod(pass_TexCoord.y, 1.0)));
  50. if (mode == 1.0 || mode == 2.0)
  51. {
  52. if (col > 1.0/3.0) gl_FragColor.r = 0.0;
  53. else gl_FragColor.r = min(col, 1.0/3.0);
  54. if (col > 2.0/3.0) gl_FragColor.g = 0.0;
  55. else gl_FragColor.g = min(max(col, 1.0/3.0) - 1.0/3.0, 1.0/3.0);
  56. gl_FragColor.b = min(max(col, 2.0/3.0) - 2.0/3.0, 1.0/3.0);
  57. }
  58. else if (mode == 3.0 || mode == 4.0)
  59. {
  60. if (col > 0.5) gl_FragColor.r = 0.0;
  61. else gl_FragColor.r = min(col, 0.5);
  62. gl_FragColor.g = min(max(col, 0.5) - 0.5, 0.5);
  63. gl_FragColor.b = 0.1;
  64. }
  65. else if (mode == 5.0 || mode == 6.0)
  66. {
  67. gl_FragColor.r = col;
  68. gl_FragColor.g = 0.1;
  69. gl_FragColor.b = 0.1;
  70. }
  71. }
  72. gl_FragColor.a = 1.0;
  73. gl_FragColor *=
  74. //= pass_Color *
  75. length(normalize(pass_TexCoord)) *
  76. length(normalize(pass_Color.xyz)) *
  77. length(normalize(pass_TNormal));
  78. }
  79. [vert.hlsl]
  80. void main(float3 in_Vertex : POSITION,
  81. float3 in_Normal : NORMAL,
  82. float4 in_Color : COLOR,
  83. uniform float4x4 u_modelview,
  84. uniform float4x4 u_projection,
  85. uniform float3x3 u_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(u_modelview, float4(in_Vertex, 1.0));
  92. float3 tnorm = normalize(mul(u_normalmat, in_Normal));
  93. pass_Vertex = eye;
  94. pass_TNormal = tnorm;
  95. pass_Color = in_Color;
  96. out_Position = mul(u_projection, eye);
  97. }
  98. [frag.hlsl]
  99. void main(float4 pass_Vertex : TEXCOORD0,
  100. float3 pass_TNormal : TEXCOORD1,
  101. float4 pass_Color : COLOR,
  102. uniform float in_Damage,
  103. out float4 out_FragColor : COLOR)
  104. {
  105. float3 in_LightDir = float3(0.3, 0.3, 0.7);
  106. /* Material properties */
  107. float3 specular_reflect = float3(0.8, 0.75, 0.4);
  108. float specular_power = 60.0;
  109. /* World properties */
  110. float ambient_mul = 0.5;
  111. float3 ambient_color = float3(0.25, 0.2, 0.35);
  112. float3 diffuse_color = float3(1.0, 1.0, 0.6);
  113. float3 specular_color = float3(1.0, 1.0, 0.6);
  114. float3 s = normalize(in_LightDir); /* normalize(pass_Vertex - lightpos); */
  115. float3 v = normalize(-pass_Vertex.xyz);
  116. float3 r = reflect(-s, pass_TNormal);
  117. float3 ambient = ambient_color;
  118. float sdotn = max(dot(s, pass_TNormal), 0.0);
  119. float3 diffuse = diffuse_color * sdotn;
  120. float3 specular = float3(0.0, 0.0, 0.0);
  121. if (sdotn > 0.0)
  122. specular = specular_color * specular_reflect
  123. * pow(max(dot(r, v), 0.0), specular_power);
  124. float3 light = ambient + diffuse + specular;
  125. float4 real_color = in_Damage * float4(1.2, 1.2, 1.2, 1.0)
  126. + (1.0 - in_Damage) * pass_Color;
  127. out_FragColor = real_color * float4(light, 1.0);
  128. }