Browse Source

Vertex shaders optimization

raysan5 9 years ago
parent
commit
fb6ef2c2f4
41 changed files with 86 additions and 92 deletions
  1. 2 3
      examples/resources/shaders/base.vs
  2. 1 1
      examples/resources/shaders/bloom.fs
  3. 3 3
      examples/resources/shaders/grayscale.fs
  4. 1 1
      examples/resources/shaders/phong.fs
  5. 2 2
      examples/resources/shaders/phong.vs
  6. 4 5
      examples/resources/shaders/shapes_base.vs
  7. 2 2
      examples/resources/shaders/shapes_grayscale.fs
  8. 1 1
      examples/resources/shaders/swirl.fs
  9. 2 3
      shaders/gl330/base.vs
  10. 1 1
      shaders/gl330/bloom.fs
  11. 1 1
      shaders/gl330/blur.fs
  12. 1 1
      shaders/gl330/cross_hatching.fs
  13. 1 1
      shaders/gl330/cross_stitching.fs
  14. 1 1
      shaders/gl330/dream_vision.fs
  15. 1 1
      shaders/gl330/fisheye.fs
  16. 3 3
      shaders/gl330/grayscale.fs
  17. 1 1
      shaders/gl330/phong.fs
  18. 3 4
      shaders/gl330/phong.vs
  19. 1 1
      shaders/gl330/pixel.fs
  20. 1 1
      shaders/gl330/posterization.fs
  21. 1 1
      shaders/gl330/predator.fs
  22. 1 1
      shaders/gl330/scanlines.fs
  23. 1 1
      shaders/gl330/swirl.fs
  24. 2 2
      shaders/gl330/template.fs
  25. 2 3
      shaders/gles100/base.vs
  26. 1 1
      shaders/gles100/bloom.fs
  27. 1 1
      shaders/gles100/blur.fs
  28. 1 1
      shaders/gles100/cross_hatching.fs
  29. 1 1
      shaders/gles100/cross_stitching.fs
  30. 1 1
      shaders/gles100/dream_vision.fs
  31. 1 1
      shaders/gles100/fisheye.fs
  32. 3 3
      shaders/gles100/grayscale.fs
  33. 1 1
      shaders/gles100/pixel.fs
  34. 1 1
      shaders/gles100/posterization.fs
  35. 1 1
      shaders/gles100/predator.fs
  36. 1 1
      shaders/gles100/scanlines.fs
  37. 1 1
      shaders/gles100/swirl.fs
  38. 2 2
      shaders/gles100/template.fs
  39. 2 2
      src/raylib.h
  40. 26 27
      src/rlgl.c
  41. 2 2
      src/rlgl.h

+ 2 - 3
examples/resources/shaders/base.vs

@@ -6,8 +6,7 @@ in vec3 vertexNormal;
 
 
 out vec2 fragTexCoord;
 out vec2 fragTexCoord;
 
 
-uniform mat4 projectionMatrix;
-uniform mat4 modelviewMatrix;
+uniform mat4 mvpMatrix;
 
 
 // NOTE: Add here your custom variables 
 // NOTE: Add here your custom variables 
 
 
@@ -15,5 +14,5 @@ void main()
 {
 {
     fragTexCoord = vertexTexCoord;
     fragTexCoord = vertexTexCoord;
     
     
-    gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0);
+    gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
 }
 }

+ 1 - 1
examples/resources/shaders/bloom.fs

@@ -5,7 +5,7 @@ in vec2 fragTexCoord;
 out vec4 fragColor;
 out vec4 fragColor;
 
 
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // NOTE: Add here your custom variables
 // NOTE: Add here your custom variables
 
 

+ 3 - 3
examples/resources/shaders/grayscale.fs

@@ -5,16 +5,16 @@ in vec2 fragTexCoord;
 out vec4 fragColor;
 out vec4 fragColor;
 
 
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // NOTE: Add here your custom variables
 // NOTE: Add here your custom variables
 
 
 void main()
 void main()
 {
 {
-    vec4 base = texture2D(texture0, fragTexCoord)*tintColor;
+    vec4 base = texture2D(texture0, fragTexCoord)*fragTintColor;
     
     
     // Convert to grayscale using NTSC conversion weights
     // Convert to grayscale using NTSC conversion weights
     float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114));
     float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114));
     
     
-    fragColor = vec4(gray, gray, gray, tintColor.a);
+    fragColor = vec4(gray, gray, gray, fragTintColor.a);
 }
 }

+ 1 - 1
examples/resources/shaders/phong.fs

@@ -6,7 +6,7 @@ in vec3 fragNormal;
 
 
 // Diffuse data
 // Diffuse data
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // Light attributes
 // Light attributes
 uniform vec3 light_ambientColor = vec3(0.6, 0.3, 0);
 uniform vec3 light_ambientColor = vec3(0.6, 0.3, 0);

+ 2 - 2
examples/resources/shaders/phong.vs

@@ -6,8 +6,8 @@ in vec2 vertexTexCoord;
 in vec3 vertexNormal;
 in vec3 vertexNormal;
 
 
 // Projection and model data
 // Projection and model data
-uniform mat4 projectionMatrix;
-uniform mat4 modelviewMatrix;
+uniform mat4 mvpMatrix;
+
 uniform mat4 modelMatrix;
 uniform mat4 modelMatrix;
 
 
 // Attributes to fragment shader
 // Attributes to fragment shader

+ 4 - 5
examples/resources/shaders/shapes_base.vs

@@ -4,16 +4,15 @@ attribute vec3 vertexPosition;
 attribute vec2 vertexTexCoord;
 attribute vec2 vertexTexCoord;
 attribute vec4 vertexColor;
 attribute vec4 vertexColor;
 
 
-uniform mat4 projectionMatrix;
-uniform mat4 modelviewMatrix;
+uniform mat4 mvpMatrix;
 
 
 varying vec2 fragTexCoord;
 varying vec2 fragTexCoord;
-varying vec4 fragColor;
+varying vec4 fragTintColor;
 
 
 void main()
 void main()
 {
 {
     fragTexCoord = vertexTexCoord;
     fragTexCoord = vertexTexCoord;
-    fragColor = vertexColor;
+    fragTintColor = vertexColor;
     
     
-    gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0);
+    gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
 }
 }

+ 2 - 2
examples/resources/shaders/shapes_grayscale.fs

@@ -2,11 +2,11 @@
 
 
 uniform sampler2D texture0;
 uniform sampler2D texture0;
 varying vec2 fragTexCoord;
 varying vec2 fragTexCoord;
-varying vec4 fragColor;
+varying vec4 fragTintColor;
 
 
 void main()
 void main()
 {
 {
-    vec4 base = texture2D(texture0, fragTexCoord)*fragColor;
+    vec4 base = texture2D(texture0, fragTexCoord)*fragTintColor;
 
 
     // Convert to grayscale using NTSC conversion weights
     // Convert to grayscale using NTSC conversion weights
     float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114));
     float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114));

+ 1 - 1
examples/resources/shaders/swirl.fs

@@ -5,7 +5,7 @@ in vec2 fragTexCoord;
 out vec4 fragColor;
 out vec4 fragColor;
 
 
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // NOTE: Add here your custom variables
 // NOTE: Add here your custom variables
 
 

+ 2 - 3
shaders/gl330/base.vs

@@ -6,8 +6,7 @@ in vec3 vertexNormal;
 
 
 out vec2 fragTexCoord;
 out vec2 fragTexCoord;
 
 
-uniform mat4 projectionMatrix;
-uniform mat4 modelviewMatrix;
+uniform mat4 mvpMatrix;
 
 
 // NOTE: Add here your custom variables 
 // NOTE: Add here your custom variables 
 
 
@@ -15,5 +14,5 @@ void main()
 {
 {
     fragTexCoord = vertexTexCoord;
     fragTexCoord = vertexTexCoord;
     
     
-    gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0);
+    gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
 }
 }

+ 1 - 1
shaders/gl330/bloom.fs

@@ -5,7 +5,7 @@ in vec2 fragTexCoord;
 out vec4 fragColor;
 out vec4 fragColor;
 
 
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // NOTE: Add here your custom variables
 // NOTE: Add here your custom variables
 
 

+ 1 - 1
shaders/gl330/blur.fs

@@ -5,7 +5,7 @@ in vec2 fragTexCoord;
 out vec4 fragColor;
 out vec4 fragColor;
 
 
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // NOTE: Add here your custom variables
 // NOTE: Add here your custom variables
 
 

+ 1 - 1
shaders/gl330/cross_hatching.fs

@@ -5,7 +5,7 @@ in vec2 fragTexCoord;
 out vec4 fragColor;
 out vec4 fragColor;
 
 
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // NOTE: Add here your custom variables 
 // NOTE: Add here your custom variables 
 
 

+ 1 - 1
shaders/gl330/cross_stitching.fs

@@ -5,7 +5,7 @@ in vec2 fragTexCoord;
 out vec4 fragColor;
 out vec4 fragColor;
 
 
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // NOTE: Add here your custom variables
 // NOTE: Add here your custom variables
 
 

+ 1 - 1
shaders/gl330/dream_vision.fs

@@ -5,7 +5,7 @@ in vec2 fragTexCoord;
 out vec4 fragColor;
 out vec4 fragColor;
 
 
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // NOTE: Add here your custom variables
 // NOTE: Add here your custom variables
 
 

+ 1 - 1
shaders/gl330/fisheye.fs

@@ -5,7 +5,7 @@ in vec2 fragTexCoord;
 out vec4 fragColor;
 out vec4 fragColor;
 
 
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // NOTE: Add here your custom variables 
 // NOTE: Add here your custom variables 
 
 

+ 3 - 3
shaders/gl330/grayscale.fs

@@ -5,16 +5,16 @@ in vec2 fragTexCoord;
 out vec4 fragColor;
 out vec4 fragColor;
 
 
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // NOTE: Add here your custom variables
 // NOTE: Add here your custom variables
 
 
 void main()
 void main()
 {
 {
-    vec4 base = texture2D(texture0, fragTexCoord)*tintColor;
+    vec4 base = texture2D(texture0, fragTexCoord)*fragTintColor;
     
     
     // Convert to grayscale using NTSC conversion weights
     // Convert to grayscale using NTSC conversion weights
     float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114));
     float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114));
     
     
-    fragColor = vec4(gray, gray, gray, tintColor.a);
+    fragColor = vec4(gray, gray, gray, fragTintColor.a);
 }
 }

+ 1 - 1
shaders/gl330/phong.fs

@@ -6,7 +6,7 @@ in vec3 fragNormal;
 
 
 // Diffuse data
 // Diffuse data
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // Light attributes
 // Light attributes
 uniform vec3 light_ambientColor = vec3(0.6, 0.3, 0);
 uniform vec3 light_ambientColor = vec3(0.6, 0.3, 0);

+ 3 - 4
shaders/gl330/phong.vs

@@ -6,8 +6,7 @@ in vec2 vertexTexCoord;
 in vec3 vertexNormal;
 in vec3 vertexNormal;
 
 
 // Projection and model data
 // Projection and model data
-uniform mat4 projectionMatrix;
-uniform mat4 modelviewMatrix;
+uniform mat4 mvpMatrix;
 uniform mat4 modelMatrix;
 uniform mat4 modelMatrix;
 
 
 // Attributes to fragment shader
 // Attributes to fragment shader
@@ -21,8 +20,8 @@ void main()
     
     
     // Calculate view vector normal from model
     // Calculate view vector normal from model
     mat3 normalMatrix = transpose(inverse(mat3(modelMatrix)));
     mat3 normalMatrix = transpose(inverse(mat3(modelMatrix)));
-    fragNormal = normalize(normalMatrix * vertexNormal);
+    fragNormal = normalize(normalMatrix*vertexNormal);
     
     
     // Calculate final vertex position
     // Calculate final vertex position
-    gl_Position = projectionMatrix * modelviewMatrix * vec4(vertexPosition, 1.0);
+    gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
 }
 }

+ 1 - 1
shaders/gl330/pixel.fs

@@ -5,7 +5,7 @@ in vec2 fragTexCoord;
 out vec4 fragColor;
 out vec4 fragColor;
 
 
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // NOTE: Add here your custom variables 
 // NOTE: Add here your custom variables 
 
 

+ 1 - 1
shaders/gl330/posterization.fs

@@ -5,7 +5,7 @@ in vec2 fragTexCoord;
 out vec4 fragColor;
 out vec4 fragColor;
 
 
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // NOTE: Add here your custom variables
 // NOTE: Add here your custom variables
 
 

+ 1 - 1
shaders/gl330/predator.fs

@@ -5,7 +5,7 @@ in vec2 fragTexCoord;
 out vec4 fragColor;
 out vec4 fragColor;
 
 
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // NOTE: Add here your custom variables
 // NOTE: Add here your custom variables
 
 

+ 1 - 1
shaders/gl330/scanlines.fs

@@ -5,7 +5,7 @@ in vec2 fragTexCoord;
 out vec4 fragColor;
 out vec4 fragColor;
 
 
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // NOTE: Add here your custom variables
 // NOTE: Add here your custom variables
 
 

+ 1 - 1
shaders/gl330/swirl.fs

@@ -5,7 +5,7 @@ in vec2 fragTexCoord;
 out vec4 fragColor;
 out vec4 fragColor;
 
 
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // NOTE: Add here your custom variables
 // NOTE: Add here your custom variables
 
 

+ 2 - 2
shaders/gl330/template.fs

@@ -5,7 +5,7 @@ in vec2 fragTexCoord;
 out vec4 fragColor;
 out vec4 fragColor;
 
 
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // NOTE: Add here your custom variables
 // NOTE: Add here your custom variables
 
 
@@ -15,5 +15,5 @@ void main()
     
     
     // NOTE: Implement here your fragment shader code
     // NOTE: Implement here your fragment shader code
     
     
-    fragColor = texelColor*tintColor;
+    fragColor = texelColor*fragTintColor;
 }
 }

+ 2 - 3
shaders/gles100/base.vs

@@ -6,8 +6,7 @@ attribute vec3 vertexNormal;
 
 
 varying vec2 fragTexCoord;
 varying vec2 fragTexCoord;
 
 
-uniform mat4 projectionMatrix;
-uniform mat4 modelviewMatrix;
+uniform mat4 mvpMatrix;
 
 
 // NOTE: Add here your custom variables 
 // NOTE: Add here your custom variables 
 
 
@@ -17,5 +16,5 @@ void main()
     
     
     fragTexCoord = vertexTexCoord;
     fragTexCoord = vertexTexCoord;
     
     
-    gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0);
+    gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
 }
 }

+ 1 - 1
shaders/gles100/bloom.fs

@@ -5,7 +5,7 @@ precision mediump float;
 varying vec2 fragTexCoord;
 varying vec2 fragTexCoord;
 
 
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // NOTE: Add here your custom variables
 // NOTE: Add here your custom variables
 
 

+ 1 - 1
shaders/gles100/blur.fs

@@ -4,7 +4,7 @@ precision mediump float;
 
 
 varying vec2 fragTexCoord;
 varying vec2 fragTexCoord;
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // NOTE: Add here your custom variables
 // NOTE: Add here your custom variables
 
 

+ 1 - 1
shaders/gles100/cross_hatching.fs

@@ -5,7 +5,7 @@ precision mediump float;
 varying vec2 fragTexCoord;
 varying vec2 fragTexCoord;
 
 
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // NOTE: Add here your custom variables 
 // NOTE: Add here your custom variables 
 
 

+ 1 - 1
shaders/gles100/cross_stitching.fs

@@ -5,7 +5,7 @@ precision mediump float;
 varying vec2 fragTexCoord;
 varying vec2 fragTexCoord;
 
 
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // NOTE: Add here your custom variables
 // NOTE: Add here your custom variables
 
 

+ 1 - 1
shaders/gles100/dream_vision.fs

@@ -5,7 +5,7 @@ precision mediump float;
 varying vec2 fragTexCoord;
 varying vec2 fragTexCoord;
 
 
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // NOTE: Add here your custom variables
 // NOTE: Add here your custom variables
 
 

+ 1 - 1
shaders/gles100/fisheye.fs

@@ -5,7 +5,7 @@ precision mediump float;
 varying vec2 fragTexCoord;
 varying vec2 fragTexCoord;
 
 
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // NOTE: Add here your custom variables 
 // NOTE: Add here your custom variables 
 
 

+ 3 - 3
shaders/gles100/grayscale.fs

@@ -5,16 +5,16 @@ precision mediump float;
 varying vec2 fragTexCoord;
 varying vec2 fragTexCoord;
 
 
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // NOTE: Add here your custom variables
 // NOTE: Add here your custom variables
 
 
 void main()
 void main()
 {
 {
-    vec4 base = texture2D(texture0, fragTexCoord)*tintColor;
+    vec4 base = texture2D(texture0, fragTexCoord)*fragTintColor;
     
     
     // Convert to grayscale using NTSC conversion weights
     // Convert to grayscale using NTSC conversion weights
     float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114));
     float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114));
     
     
-    gl_FragColor = vec4(gray, gray, gray, tintColor.a);
+    gl_FragColor = vec4(gray, gray, gray, fragTintColor.a);
 }
 }

+ 1 - 1
shaders/gles100/pixel.fs

@@ -5,7 +5,7 @@ precision mediump float;
 varying vec2 fragTexCoord;
 varying vec2 fragTexCoord;
 
 
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // NOTE: Add here your custom variables 
 // NOTE: Add here your custom variables 
 
 

+ 1 - 1
shaders/gles100/posterization.fs

@@ -5,7 +5,7 @@ precision mediump float;
 varying vec2 fragTexCoord;
 varying vec2 fragTexCoord;
 
 
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // NOTE: Add here your custom variables
 // NOTE: Add here your custom variables
 
 

+ 1 - 1
shaders/gles100/predator.fs

@@ -5,7 +5,7 @@ precision mediump float;
 varying vec2 fragTexCoord;
 varying vec2 fragTexCoord;
 
 
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // NOTE: Add here your custom variables
 // NOTE: Add here your custom variables
 
 

+ 1 - 1
shaders/gles100/scanlines.fs

@@ -5,7 +5,7 @@ precision mediump float;
 varying vec2 fragTexCoord;
 varying vec2 fragTexCoord;
 
 
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // NOTE: Add here your custom variables
 // NOTE: Add here your custom variables
 
 

+ 1 - 1
shaders/gles100/swirl.fs

@@ -5,7 +5,7 @@ precision mediump float;
 varying vec2 fragTexCoord;
 varying vec2 fragTexCoord;
 
 
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // NOTE: Add here your custom variables
 // NOTE: Add here your custom variables
 
 

+ 2 - 2
shaders/gles100/template.fs

@@ -5,7 +5,7 @@ precision mediump float;
 varying vec2 fragTexCoord;
 varying vec2 fragTexCoord;
 
 
 uniform sampler2D texture0;
 uniform sampler2D texture0;
-uniform vec4 tintColor;
+uniform vec4 fragTintColor;
 
 
 // NOTE: Add here your custom variables
 // NOTE: Add here your custom variables
 
 
@@ -15,5 +15,5 @@ void main()
     
     
     // NOTE: Implement here your fragment shader code
     // NOTE: Implement here your fragment shader code
     
     
-    gl_FragColor = texelColor*tintColor;
+    gl_FragColor = texelColor*fragTintColor;
 }
 }

+ 2 - 2
src/raylib.h

@@ -336,8 +336,8 @@ typedef struct Shader {
     int colorLoc;         // Color attibute location point (vertex shader)
     int colorLoc;         // Color attibute location point (vertex shader)
 
 
     // Uniforms
     // Uniforms
-    int projectionLoc;    // Projection matrix uniform location point (vertex shader)
-    int modelviewLoc;     // ModelView matrix uniform location point (vertex shader)
+    int mvpLoc;           // ModelView-Projection matrix uniform location point (vertex shader)
+    
     int modelLoc;         // Model transformation matrix uniform location point (vertex shader)
     int modelLoc;         // Model transformation matrix uniform location point (vertex shader)
     int viewLoc;          // View transformation matrix uniform location point (vertex shader)
     int viewLoc;          // View transformation matrix uniform location point (vertex shader)
     int tintColorLoc;     // Color uniform location point (fragment shader)
     int tintColorLoc;     // Color uniform location point (fragment shader)

+ 26 - 27
src/rlgl.c

@@ -1295,9 +1295,10 @@ void rlglDraw(void)
     if ((lines.vCounter > 0) || (triangles.vCounter > 0) || (quads.vCounter > 0))
     if ((lines.vCounter > 0) || (triangles.vCounter > 0) || (quads.vCounter > 0))
     {
     {
         glUseProgram(currentShader.id);
         glUseProgram(currentShader.id);
+        
+        Matrix matMVP = MatrixMultiply(modelview, projection);        // Create modelview-projection matrix
 
 
-        glUniformMatrix4fv(currentShader.projectionLoc, 1, false, MatrixToFloat(projection));
-        glUniformMatrix4fv(currentShader.modelviewLoc, 1, false, MatrixToFloat(modelview));
+        glUniformMatrix4fv(currentShader.mvpLoc, 1, false, MatrixToFloat(matMVP));
         glUniform1i(currentShader.mapDiffuseLoc, 0);
         glUniform1i(currentShader.mapDiffuseLoc, 0);
     }
     }
 
 
@@ -1520,14 +1521,14 @@ void rlglDrawModel(Model model, Vector3 position, float rotationAngle, Vector3 r
     Matrix matModelView = MatrixMultiply(matModel, matView);            // Transform to camera-space coordinates
     Matrix matModelView = MatrixMultiply(matModel, matView);            // Transform to camera-space coordinates
 
 
     // Calculate model-view-projection matrix (MVP)
     // Calculate model-view-projection matrix (MVP)
-    //Matrix matMVP = MatrixMultiply(matModelView, matProjection);        // Transform to screen-space coordinates
+    Matrix matMVP = MatrixMultiply(matModelView, matProjection);        // Transform to screen-space coordinates
 
 
     // NOTE: Drawing in OpenGL 3.3+, matrices are passed to shader
     // NOTE: Drawing in OpenGL 3.3+, matrices are passed to shader
     // TODO: Reduce number of matrices passed to shaders, use only matMVP
     // TODO: Reduce number of matrices passed to shaders, use only matMVP
     glUniformMatrix4fv(model.shader.modelLoc, 1, false, MatrixToFloat(matModel));
     glUniformMatrix4fv(model.shader.modelLoc, 1, false, MatrixToFloat(matModel));
     glUniformMatrix4fv(model.shader.viewLoc, 1, false, MatrixToFloat(matView));
     glUniformMatrix4fv(model.shader.viewLoc, 1, false, MatrixToFloat(matView));
-    glUniformMatrix4fv(model.shader.projectionLoc, 1, false, MatrixToFloat(matProjection));
-    glUniformMatrix4fv(model.shader.modelviewLoc, 1, false, MatrixToFloat(matModelView));
+    
+    glUniformMatrix4fv(model.shader.mvpLoc, 1, false, MatrixToFloat(matMVP));
 
 
     // Apply color tinting to model
     // Apply color tinting to model
     // NOTE: Just update one uniform on fragment shader
     // NOTE: Just update one uniform on fragment shader
@@ -2247,13 +2248,13 @@ Shader LoadShader(char *vsFileName, char *fsFileName)
             shader.colorLoc = -1;
             shader.colorLoc = -1;
 
 
             // Get handles to GLSL uniform locations (vertex shader)
             // Get handles to GLSL uniform locations (vertex shader)
-            shader.modelviewLoc  = glGetUniformLocation(shader.id, "modelviewMatrix");
+            shader.mvpLoc  = glGetUniformLocation(shader.id, "mvpMatrix");
+            
             shader.modelLoc  = glGetUniformLocation(shader.id, "modelMatrix");
             shader.modelLoc  = glGetUniformLocation(shader.id, "modelMatrix");
             shader.viewLoc  = glGetUniformLocation(shader.id, "viewMatrix");
             shader.viewLoc  = glGetUniformLocation(shader.id, "viewMatrix");
-            shader.projectionLoc = glGetUniformLocation(shader.id, "projectionMatrix");
 
 
             // Get handles to GLSL uniform locations (fragment shader)
             // Get handles to GLSL uniform locations (fragment shader)
-            shader.tintColorLoc = glGetUniformLocation(shader.id, "tintColor");
+            shader.tintColorLoc = glGetUniformLocation(shader.id, "fragTintColor");
             shader.mapDiffuseLoc = glGetUniformLocation(shader.id, "texture0");
             shader.mapDiffuseLoc = glGetUniformLocation(shader.id, "texture0");
             shader.mapNormalLoc = -1;       // It can be set later
             shader.mapNormalLoc = -1;       // It can be set later
             shader.mapSpecularLoc = -1;     // It can be set later
             shader.mapSpecularLoc = -1;     // It can be set later
@@ -2738,40 +2739,39 @@ static Shader LoadDefaultShader(void)
         "in vec2 vertexTexCoord;            \n"
         "in vec2 vertexTexCoord;            \n"
         "in vec4 vertexColor;               \n"
         "in vec4 vertexColor;               \n"
         "out vec2 fragTexCoord;             \n"
         "out vec2 fragTexCoord;             \n"
-        "out vec4 tintColor;                \n"
+        "out vec4 fragTintColor;                \n"
 #elif defined(GRAPHICS_API_OPENGL_ES2)
 #elif defined(GRAPHICS_API_OPENGL_ES2)
     char vShaderStr[] = "#version 100       \n"
     char vShaderStr[] = "#version 100       \n"
         "attribute vec3 vertexPosition;     \n"
         "attribute vec3 vertexPosition;     \n"
         "attribute vec2 vertexTexCoord;     \n"
         "attribute vec2 vertexTexCoord;     \n"
         "attribute vec4 vertexColor;        \n"
         "attribute vec4 vertexColor;        \n"
         "varying vec2 fragTexCoord;         \n"
         "varying vec2 fragTexCoord;         \n"
-        "varying vec4 tintColor;            \n"
+        "varying vec4 fragTintColor;        \n"
 #endif
 #endif
-        "uniform mat4 projectionMatrix;     \n"
-        "uniform mat4 modelviewMatrix;      \n"
+        "uniform mat4 mvpMatrix;     \n"
         "void main()                        \n"
         "void main()                        \n"
         "{                                  \n"
         "{                                  \n"
         "    fragTexCoord = vertexTexCoord; \n"
         "    fragTexCoord = vertexTexCoord; \n"
-        "    tintColor = vertexColor;       \n"
-        "    gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0); \n"
+        "    fragTintColor = vertexColor;   \n"
+        "    gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); \n"
         "}                                  \n";
         "}                                  \n";
 
 
     // Fragment shader directly defined, no external file required
     // Fragment shader directly defined, no external file required
 #if defined(GRAPHICS_API_OPENGL_33)
 #if defined(GRAPHICS_API_OPENGL_33)
     char fShaderStr[] = "#version 330       \n"
     char fShaderStr[] = "#version 330       \n"
         "in vec2 fragTexCoord;              \n"
         "in vec2 fragTexCoord;              \n"
-        "in vec4 tintColor;                 \n"
+        "in vec4 fragTintColor;                 \n"
 #elif defined(GRAPHICS_API_OPENGL_ES2)
 #elif defined(GRAPHICS_API_OPENGL_ES2)
     char fShaderStr[] = "#version 100       \n"
     char fShaderStr[] = "#version 100       \n"
         "precision mediump float;           \n"     // precision required for OpenGL ES2 (WebGL)
         "precision mediump float;           \n"     // precision required for OpenGL ES2 (WebGL)
         "varying vec2 fragTexCoord;         \n"
         "varying vec2 fragTexCoord;         \n"
-        "varying vec4 tintColor;            \n"
+        "varying vec4 fragTintColor;        \n"
 #endif
 #endif
         "uniform sampler2D texture0;        \n"
         "uniform sampler2D texture0;        \n"
         "void main()                        \n"
         "void main()                        \n"
         "{                                  \n"
         "{                                  \n"
         "    vec4 texelColor = texture2D(texture0, fragTexCoord); \n"   // NOTE: texture2D() is deprecated on OpenGL 3.3 and ES 3.0, use texture() instead
         "    vec4 texelColor = texture2D(texture0, fragTexCoord); \n"   // NOTE: texture2D() is deprecated on OpenGL 3.3 and ES 3.0, use texture() instead
-        "    gl_FragColor = texelColor*tintColor; \n"    
+        "    gl_FragColor = texelColor*fragTintColor; \n"    
         "}                                  \n";
         "}                                  \n";
 
 
     shader.id = LoadShaderProgram(vShaderStr, fShaderStr);
     shader.id = LoadShaderProgram(vShaderStr, fShaderStr);
@@ -2788,10 +2788,10 @@ static Shader LoadDefaultShader(void)
     shader.normalLoc = -1;
     shader.normalLoc = -1;
 
 
     // Get handles to GLSL uniform locations (vertex shader)
     // Get handles to GLSL uniform locations (vertex shader)
-    shader.modelviewLoc = glGetUniformLocation(shader.id, "modelviewMatrix");
+    shader.mvpLoc = glGetUniformLocation(shader.id, "mvpMatrix");
+    
     shader.modelLoc = glGetUniformLocation(shader.id, "modelMatrix");
     shader.modelLoc = glGetUniformLocation(shader.id, "modelMatrix");
     shader.viewLoc = glGetUniformLocation(shader.id, "viewMatrix");
     shader.viewLoc = glGetUniformLocation(shader.id, "viewMatrix");
-    shader.projectionLoc = glGetUniformLocation(shader.id, "projectionMatrix");
 
 
     // Get handles to GLSL uniform locations (fragment shader)
     // Get handles to GLSL uniform locations (fragment shader)
     shader.tintColorLoc = -1;
     shader.tintColorLoc = -1;
@@ -2831,12 +2831,11 @@ static Shader LoadSimpleShader(void)
         "attribute vec3 vertexNormal;       \n"
         "attribute vec3 vertexNormal;       \n"
         "varying vec2 fragTexCoord;         \n"
         "varying vec2 fragTexCoord;         \n"
 #endif
 #endif
-        "uniform mat4 projectionMatrix;     \n"
-        "uniform mat4 modelviewMatrix;      \n"
+        "uniform mat4 mvpMatrix;            \n"
         "void main()                        \n"
         "void main()                        \n"
         "{                                  \n"
         "{                                  \n"
         "    fragTexCoord = vertexTexCoord; \n"
         "    fragTexCoord = vertexTexCoord; \n"
-        "    gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0); \n"
+        "    gl_Position = mvpMatrix*vec4(vertexPosition, 1.0); \n"
         "}                                  \n";
         "}                                  \n";
 
 
     // Fragment shader directly defined, no external file required
     // Fragment shader directly defined, no external file required
@@ -2849,11 +2848,11 @@ static Shader LoadSimpleShader(void)
         "varying vec2 fragTexCoord;         \n"
         "varying vec2 fragTexCoord;         \n"
 #endif
 #endif
         "uniform sampler2D texture0;        \n"
         "uniform sampler2D texture0;        \n"
-        "uniform vec4 tintColor;            \n"
+        "uniform vec4 fragTintColor;        \n"
         "void main()                        \n"
         "void main()                        \n"
         "{                                  \n"
         "{                                  \n"
         "    vec4 texelColor = texture2D(texture0, fragTexCoord); \n"   // NOTE: texture2D() is deprecated on OpenGL 3.3 and ES 3.0, use texture() instead
         "    vec4 texelColor = texture2D(texture0, fragTexCoord); \n"   // NOTE: texture2D() is deprecated on OpenGL 3.3 and ES 3.0, use texture() instead
-        "    gl_FragColor = texelColor*tintColor; \n"
+        "    gl_FragColor = texelColor*fragTintColor; \n"
         "}                                  \n";
         "}                                  \n";
 
 
     shader.id = LoadShaderProgram(vShaderStr, fShaderStr);
     shader.id = LoadShaderProgram(vShaderStr, fShaderStr);
@@ -2870,13 +2869,13 @@ static Shader LoadSimpleShader(void)
     shader.colorLoc = -1;
     shader.colorLoc = -1;
 
 
     // Get handles to GLSL uniform locations (vertex shader)
     // Get handles to GLSL uniform locations (vertex shader)
-    shader.modelviewLoc  = glGetUniformLocation(shader.id, "modelviewMatrix");
+    shader.mvpLoc  = glGetUniformLocation(shader.id, "mvpMatrix");
+    
     shader.modelLoc  = glGetUniformLocation(shader.id, "modelMatrix");
     shader.modelLoc  = glGetUniformLocation(shader.id, "modelMatrix");
     shader.viewLoc  = glGetUniformLocation(shader.id, "viewMatrix");
     shader.viewLoc  = glGetUniformLocation(shader.id, "viewMatrix");
-    shader.projectionLoc = glGetUniformLocation(shader.id, "projectionMatrix");
 
 
     // Get handles to GLSL uniform locations (fragment shader)
     // Get handles to GLSL uniform locations (fragment shader)
-    shader.tintColorLoc = glGetUniformLocation(shader.id, "tintColor");
+    shader.tintColorLoc = glGetUniformLocation(shader.id, "fragTintColor");
     shader.mapDiffuseLoc = glGetUniformLocation(shader.id, "texture0");
     shader.mapDiffuseLoc = glGetUniformLocation(shader.id, "texture0");
     shader.mapNormalLoc = -1;       // It can be set later
     shader.mapNormalLoc = -1;       // It can be set later
     shader.mapSpecularLoc = -1;     // It can be set later
     shader.mapSpecularLoc = -1;     // It can be set later

+ 2 - 2
src/rlgl.h

@@ -159,8 +159,8 @@ typedef enum { OPENGL_11 = 1, OPENGL_33, OPENGL_ES_20 } GlVersion;
         int colorLoc;         // Color attibute location point (vertex shader)
         int colorLoc;         // Color attibute location point (vertex shader)
 
 
         // Uniforms
         // Uniforms
-        int projectionLoc;    // Projection matrix uniform location point (vertex shader)
-        int modelviewLoc;     // ModelView matrix uniform location point (vertex shader)
+        int mvpLoc;           // ModelView-Projection matrix uniform location point (vertex shader)
+    
         int modelLoc;         // Model transformation matrix uniform location point (vertex shader)
         int modelLoc;         // Model transformation matrix uniform location point (vertex shader)
         int viewLoc;          // View transformation matrix uniform location point (vertex shader)
         int viewLoc;          // View transformation matrix uniform location point (vertex shader)
         int tintColorLoc;     // Color uniform location point (fragment shader)
         int tintColorLoc;     // Color uniform location point (fragment shader)