transparent_object.shader 3.0 KB

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