` //////////// djafer //////// mat4 ajustwMatrix (float theta) { return mat4( vec4(cos(theta), sin(theta), 0.0, 0.0), vec4(-sin(theta), cos(theta), 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0) ); } mat4 rotate_x(float theta) { return mat4( vec4(1.0, 0.0, 0.0, 0.0), vec4(0.0, cos(theta), sin(theta), 0.0), vec4(0.0, -sin(theta), cos(theta), 0.0), vec4(0.0, 0.0 , 0.0 , 1.0) ); } mat4 rotate_y(float theta) { return mat4( vec4(cos(theta), 0.0, sin(theta), 0.0), vec4(0.0, 1.0, 0.0 , 0.0), vec4(-sin(theta), 0.0, cos(theta), 0.0), vec4(0.0, 0.0, 0.0, 1.0) ); } mat4 rotate_z(float theta) { return mat4( vec4(cos(theta), sin(theta), 0.0, 0.0), vec4(-sin(theta), cos(theta), 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0) ); } //uniforms uniform mat4 uNormalMatrix; uniform mat4 uModelViewMatrix; uniform mat4 uProjectionMatrix; //ambient lights // uniform vec3 uAmbientColor; uniform vec3 uAmbientLightingColor; //directional lights uniform vec3 uLightingDirection; uniform vec3 uDirectionalLightingColor ; //uDirectionalColor; ///// point lights uniform vec3 uPointLightingLocation; uniform vec3 uPointLightingColor; //switch lights on/off uniform bool uUseLighting; ///// //attribute // attribute vec4 aVertexPosition; attribute vec3 aVertexPosition; attribute vec3 aVertexNormal; attribute vec2 aTextureCoord; attribute vec3 aVertexColor ; //varying //varying vec2 vTextureCoord; varying highp vec2 vTextureCoord; varying highp vec3 vLighting; varying highp vec3 vLightWeighting; varying highp vec4 vColor; // varying vec3 vTransformedNormal; // ? varying vec4 vTransformedNormal; // ? varying vec4 vPosition; // ? ////////// end ///////////// void main(void) { vec4 mvPosition = uModelViewMatrix * vec4(aVertexPosition, 1.0); // gl_Position = uProjectionMatrix * mvPosition; vPosition = uModelViewMatrix * vec4(aVertexPosition, 1.0); gl_Position = uProjectionMatrix * uModelViewMatrix * vec4(aVertexPosition, 1.0); // Apply textures and colors vTextureCoord = aTextureCoord; vColor = vec4(aVertexColor, 1.0); // Apply lighting effect // vTransformedNormal = uNormalMatrix * aVertexNormal; vTransformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0); if (!uUseLighting) { // vLightWeighting = vec3(0.5, 0.0, 0.0); } else { //directional lights highp vec4 directionalTransformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0); float directionDirectionalLightWeighting = max(dot(directionalTransformedNormal.xyz, uLightingDirection), 0.0); highp vec3 directionalLightWeighting = uDirectionalLightingColor * directionDirectionalLightWeighting; /// point lights highp vec3 pointLightDirection = normalize(uPointLightingLocation - mvPosition.xyz); highp vec4 pointTransformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0); float directionPointLightWeighting = max(dot(pointTransformedNormal.xyz, pointLightDirection), 0.0); highp vec3 pointLightWeighting = uPointLightingColor * directionPointLightWeighting; vLightWeighting = uAmbientLightingColor + pointLightWeighting + directionalLightWeighting ; } }`