transparent_object.shader 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. [shaders]
  2. vertex =
  3. uniform highp mat4 u_modelMatrix;
  4. uniform highp mat4 u_viewProjectionMatrix;
  5. uniform highp mat4 u_normalMatrix;
  6. attribute highp vec4 a_vertex;
  7. attribute highp vec4 a_normal;
  8. attribute highp vec2 a_uvs;
  9. varying highp vec3 v_vertex;
  10. varying highp vec3 v_normal;
  11. void main()
  12. {
  13. vec4 world_space_vert = u_modelMatrix * a_vertex;
  14. gl_Position = u_viewProjectionMatrix * world_space_vert;
  15. v_vertex = world_space_vert.xyz;
  16. v_normal = (u_normalMatrix * normalize(a_normal)).xyz;
  17. }
  18. fragment =
  19. uniform mediump vec4 u_ambientColor;
  20. uniform mediump vec4 u_diffuseColor;
  21. uniform highp vec3 u_lightPosition;
  22. uniform mediump float u_opacity;
  23. varying highp vec3 v_vertex;
  24. varying highp vec3 v_normal;
  25. void main()
  26. {
  27. mediump vec4 finalColor = vec4(0.0);
  28. /* Ambient Component */
  29. finalColor += u_ambientColor;
  30. highp vec3 normal = normalize(v_normal);
  31. highp vec3 lightDir = normalize(u_lightPosition - v_vertex);
  32. /* Diffuse Component */
  33. highp float NdotL = clamp(abs(dot(normal, lightDir)), 0.0, 1.0);
  34. finalColor += (NdotL * u_diffuseColor);
  35. gl_FragColor = finalColor;
  36. gl_FragColor.a = u_opacity;
  37. }
  38. vertex41core =
  39. #version 410
  40. uniform highp mat4 u_modelMatrix;
  41. uniform highp mat4 u_viewProjectionMatrix;
  42. uniform highp mat4 u_normalMatrix;
  43. in highp vec4 a_vertex;
  44. in highp vec4 a_normal;
  45. in highp vec2 a_uvs;
  46. out highp vec3 v_vertex;
  47. out highp vec3 v_normal;
  48. void main()
  49. {
  50. vec4 world_space_vert = u_modelMatrix * a_vertex;
  51. gl_Position = u_viewProjectionMatrix * world_space_vert;
  52. v_vertex = world_space_vert.xyz;
  53. v_normal = (u_normalMatrix * normalize(a_normal)).xyz;
  54. }
  55. fragment41core =
  56. #version 410
  57. uniform mediump vec4 u_ambientColor;
  58. uniform mediump vec4 u_diffuseColor;
  59. uniform highp vec3 u_lightPosition;
  60. uniform mediump float u_opacity;
  61. in highp vec3 v_vertex;
  62. in highp vec3 v_normal;
  63. out vec4 frag_color;
  64. void main()
  65. {
  66. mediump vec4 finalColor = vec4(0.0);
  67. /* Ambient Component */
  68. finalColor += u_ambientColor;
  69. highp vec3 normal = normalize(v_normal);
  70. highp vec3 lightDir = normalize(u_lightPosition - v_vertex);
  71. /* Diffuse Component */
  72. highp float NdotL = clamp(abs(dot(normal, lightDir)), 0.0, 1.0);
  73. finalColor += (NdotL * u_diffuseColor);
  74. frag_color = finalColor;
  75. frag_color.a = u_opacity;
  76. }
  77. [defaults]
  78. u_ambientColor = [0.1, 0.1, 0.1, 1.0]
  79. u_diffuseColor = [0.4, 0.4, 0.4, 1.0]
  80. u_opacity = 0.5
  81. [bindings]
  82. u_modelMatrix = model_matrix
  83. u_viewProjectionMatrix = view_projection_matrix
  84. u_normalMatrix = normal_matrix
  85. u_lightPosition = light_0_position
  86. u_diffuseColor = diffuse_color
  87. [attributes]
  88. a_vertex = vertex
  89. a_normal = normal