Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

shinymvtexture.lolfx 4.2 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 mat4 u_view;
  31. uniform mat4 u_inv_view;
  32. uniform mat4 u_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((u_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 u_modelview,
  83. uniform float4x4 u_projection,
  84. uniform float3x3 u_normalmat,
  85. out float4 pass_Vertex : TEXCOORD0,
  86. out float3 pass_TNormal : TEXCOORD1,
  87. out float4 pass_Color : COLOR,
  88. out float4 out_Position : POSITION)
  89. {
  90. float4 eye = mul(u_modelview, float4(in_Vertex, 1.0));
  91. float3 tnorm = normalize(mul(u_normalmat, in_Normal));
  92. pass_Vertex = eye;
  93. pass_TNormal = tnorm;
  94. #ifdef _XBOX
  95. pass_Color = in_Color.abgr;
  96. #else
  97. pass_Color = in_Color;
  98. #endif
  99. out_Position = mul(u_projection, eye);
  100. }
  101. [frag.hlsl]
  102. void main(float4 pass_Vertex : TEXCOORD0,
  103. float3 pass_TNormal : TEXCOORD1,
  104. float4 pass_Color : COLOR,
  105. uniform float in_Damage,
  106. out float4 out_FragColor : COLOR)
  107. {
  108. float3 in_LightDir = float3(0.3, 0.3, 0.7);
  109. /* Material properties */
  110. float3 specular_reflect = float3(0.8, 0.75, 0.4);
  111. float specular_power = 60.0;
  112. /* World properties */
  113. float ambient_mul = 0.5;
  114. float3 ambient_color = float3(0.25, 0.2, 0.35);
  115. float3 diffuse_color = float3(1.0, 1.0, 0.6);
  116. float3 specular_color = float3(1.0, 1.0, 0.6);
  117. float3 s = normalize(in_LightDir); /* normalize(pass_Vertex - lightpos); */
  118. float3 v = normalize(-pass_Vertex.xyz);
  119. float3 r = reflect(-s, pass_TNormal);
  120. float3 ambient = ambient_color;
  121. float sdotn = max(dot(s, pass_TNormal), 0.0);
  122. float3 diffuse = diffuse_color * sdotn;
  123. float3 specular = float3(0.0, 0.0, 0.0);
  124. if (sdotn > 0.0)
  125. specular = specular_color * specular_reflect
  126. * pow(max(dot(r, v), 0.0), specular_power);
  127. float3 light = ambient + diffuse + specular;
  128. float4 real_color = in_Damage * float4(1.2, 1.2, 1.2, 1.0)
  129. + (1.0 - in_Damage) * pass_Color;
  130. out_FragColor = real_color * float4(light, 1.0);
  131. }