Bladeren bron

Merge branch 'next' of https://github.com/blackberry-gaming/GamePlay into next-kcunney

Kieran Cunney 13 jaren geleden
bovenliggende
commit
5fe4622324
36 gewijzigde bestanden met toevoegingen van 676 en 542 verwijderingen
  1. 12 0
      gameplay-encoder/src/Base.cpp
  2. 10 0
      gameplay-encoder/src/Base.h
  3. 8 14
      gameplay-encoder/src/TTFFontEncoder.cpp
  4. 12 2
      gameplay-encoder/src/TTFFontEncoder.h
  5. 28 12
      gameplay-encoder/src/main.cpp
  6. 19 20
      gameplay/gameplay.vcxproj
  7. 19 22
      gameplay/gameplay.vcxproj.filters
  8. 69 0
      gameplay/res/shaders/bumped.frag
  9. 0 48
      gameplay/res/shaders/bumped.fsh
  10. 94 0
      gameplay/res/shaders/bumped.vert
  11. 0 72
      gameplay/res/shaders/bumped.vsh
  12. 1 0
      gameplay/res/shaders/colored-unlit.frag
  13. 39 0
      gameplay/res/shaders/colored-unlit.vert
  14. 0 29
      gameplay/res/shaders/colored-unlit.vsh
  15. 70 0
      gameplay/res/shaders/colored.frag
  16. 0 50
      gameplay/res/shaders/colored.fsh
  17. 81 0
      gameplay/res/shaders/colored.vert
  18. 0 51
      gameplay/res/shaders/colored.vsh
  19. 0 9
      gameplay/res/shaders/lib/attributes-skinning.vert
  20. 0 0
      gameplay/res/shaders/lib/attributes.vert
  21. 0 2
      gameplay/res/shaders/lib/lighting-directional.frag
  22. 5 7
      gameplay/res/shaders/lib/lighting-directional.vert
  23. 0 3
      gameplay/res/shaders/lib/lighting-point.frag
  24. 0 5
      gameplay/res/shaders/lib/lighting-point.vert
  25. 2 13
      gameplay/res/shaders/lib/lighting-spot.frag
  26. 0 14
      gameplay/res/shaders/lib/lighting-spot.vert
  27. 4 12
      gameplay/res/shaders/lib/lighting.frag
  28. 0 9
      gameplay/res/shaders/lib/lighting.vsh
  29. 1 1
      gameplay/res/shaders/textured-unlit.frag
  30. 48 0
      gameplay/res/shaders/textured-unlit.vert
  31. 0 40
      gameplay/res/shaders/textured-unlit.vsh
  32. 66 0
      gameplay/res/shaders/textured.frag
  33. 0 45
      gameplay/res/shaders/textured.fsh
  34. 87 0
      gameplay/res/shaders/textured.vert
  35. 0 61
      gameplay/res/shaders/textured.vsh
  36. 1 1
      gameplay/src/Effect.cpp

+ 12 - 0
gameplay-encoder/src/Base.cpp

@@ -11,4 +11,16 @@ void fillArray(float values[], float value, size_t length)
     }
 }
 
+std::string getBaseName(const std::string& filepath)
+{
+    size_t index1 = filepath.find_last_of('\\');
+    size_t index2 = filepath.find_last_of('/');
+    size_t index = (index1 != -1 && index1 > index2 ? index1 : index2);
+    size_t length = filepath.length();
+    std::string filename = filepath.substr(index + 1, length);
+    length = filename.length();
+    std::string output = filename.substr(0, (length-4));
+    return output;
+}
+
 }

+ 10 - 0
gameplay-encoder/src/Base.h

@@ -76,6 +76,16 @@ enum VertexUsage
 
 void fillArray(float values[], float value, size_t length);
 
+/**
+ * Returns the base name of the given path.
+ * Example: "c:/foo/bar/model.dae" returns "model.dae"
+ * 
+ * @param filepath File path.
+ * 
+ * @return Base file name.
+ */
+std::string getBaseName(const std::string& filepath);
+
 #define ISZERO(x) (fabs(x) < 0.000001f)
 
 // Object deletion macro

+ 8 - 14
gameplay-encoder/src/TTFFontEncoder.cpp

@@ -1,6 +1,7 @@
 #include "Base.h"
 #include "TTFFontEncoder.h"
 #include "GPBFile.h"
+#include "StringUtil.h"
 
 namespace gameplay
 {
@@ -33,7 +34,7 @@ static void writeString(FILE* fp, const char* str)
     }
 }
 
-int writeFont(const char* filename, unsigned int fontSize, const char* id, bool fontpreview = false)
+int writeFont(const char* inFilePath, const char* outFilePath, unsigned int fontSize, const char* id, bool fontpreview = false)
 {
     Glyph glyphArray[END_INDEX - START_INDEX];
     
@@ -48,7 +49,7 @@ int writeFont(const char* filename, unsigned int fontSize, const char* id, bool
     
     // Initialize font face.
     FT_Face face;
-    error = FT_New_Face(library, filename, 0, &face);
+    error = FT_New_Face(library, inFilePath, 0, &face);
     if (error)
     {
         fprintf(stderr, "FT_New_Face error: %d \n", error);
@@ -249,15 +250,9 @@ int writeFont(const char* filename, unsigned int fontSize, const char* id, bool
         penX += advance; // Move X to next glyph position
         i++;
     }
-    
-    unsigned int idlen = strlen(id);
 
-    // Write it to the id.gpb file.
-    char* fileName = (char*)malloc(idlen + 4);
-    strcpy(fileName, id);
-    strcat(fileName, ".gpb");
 
-    FILE *gpbFp = fopen(fileName, "wb");
+    FILE *gpbFp = fopen(outFilePath, "wb");
     
     // File header and version.
     char fileHeader[9]     = {'«', 'G', 'P', 'B', '»', '\r', '\n', '\x1A', '\n'};
@@ -303,15 +298,14 @@ int writeFont(const char* filename, unsigned int fontSize, const char* id, bool
     // Close file.
     fclose(gpbFp);
 
-    printf("%s.gpb created successfully! \n", id);
+    printf("%s.gpb created successfully. \n", getBaseName(outFilePath).c_str());
 
     if (fontpreview)
     {
         // Write out font map to an image.
-        strcpy(fileName, id);
-        strcat(fileName, ".pgm");
-
-        FILE *imageFp = fopen(fileName, "wb");
+        std::string pgmFilePath = getFilenameNoExt(outFilePath);
+        pgmFilePath.append(".pgm");
+        FILE *imageFp = fopen(pgmFilePath.c_str(), "wb");
         fprintf(imageFp, "P5 %d %d 255\n", imageWidth, imageHeight);
         fwrite((const char *)imageBuffer, sizeof(unsigned char), imageWidth * imageHeight, imageFp);
         fclose(imageFp);

+ 12 - 2
gameplay-encoder/src/TTFFontEncoder.h

@@ -3,7 +3,6 @@
 
 #define START_INDEX     32
 #define END_INDEX       127
-
 #define GLYPH_PADDING   4
 
 namespace gameplay
@@ -18,6 +17,17 @@ public:
     float uvCoords[4];
 };
 
-int writeFont(const char* filename, unsigned int fontSize, const char* id, bool fontpreview);
+/**
+ * Writes the font gpb file.
+ * 
+ * @param inFilePath Input file path to the tiff file.
+ * @param outFilePath Output file path to write the gpb to.
+ * @param fontSize Size of the font.
+ * @param id ID string of the font in the ref table.
+ * @param fontpreview True if the pgm font preview file should be written. (For debugging)
+ * 
+ * @return 0 if successful, -1 if error.
+ */
+int writeFont(const char* inFilePath, const char* outFilePath, unsigned int fontSize, const char* id, bool fontpreview);
 
 }

+ 28 - 12
gameplay-encoder/src/main.cpp

@@ -7,16 +7,28 @@
 
 using namespace gameplay;
 
-static std::string getFileName(const std::string& filepath)
+/**
+ * Prompts the user for a font size until a valid font size is entered.
+ * 
+ * @return A valid font size.
+ */
+static unsigned int promptUserFontSize()
 {
-    size_t index1 = filepath.find_last_of('\\');
-    size_t index2 = filepath.find_last_of('/');
-    size_t index = (index1 != -1 && index1 > index2 ? index1 : index2);
-    size_t length = filepath.length();
-    std::string filename = filepath.substr(index + 1, length);
-    length = filename.length();
-    std::string output = filename.substr(0, (length-4));
-    return output;
+    static const int lowerBound = 8;
+    static const int upperBound = 500;
+    unsigned int fontSize = 0;
+    char buffer[80];
+    do
+    {
+        printf("Enter font size (between %d and %d):\n", lowerBound, upperBound);
+        std::cin.getline(buffer, 80);
+        int i = atoi(buffer);
+        if (i >= lowerBound && i <= upperBound)
+        {
+            fontSize = (unsigned int)i;
+        }
+    } while (fontSize == 0);
+    return fontSize;
 }
 
 /**
@@ -74,9 +86,13 @@ int main(int argc, const char** argv)
         }
     case EncoderArguments::FILEFORMAT_TTF:
         {
-            std::string realpath(arguments.getFilePath());
-            std::string id = getFileName(realpath);
-            writeFont(realpath.c_str(), arguments.getFontSize(), id.c_str(), arguments.fontPreviewEnabled());
+            unsigned int fontSize = arguments.getFontSize();
+            if (fontSize == 0)
+            {
+                fontSize = promptUserFontSize();
+            }
+            std::string id = getBaseName(arguments.getFilePath());
+            writeFont(arguments.getFilePath().c_str(), arguments.getOutputFilePath().c_str(), fontSize, id.c_str(), arguments.fontPreviewEnabled());
             break;
         }
     case EncoderArguments::FILEFORMAT_GPB:

+ 19 - 20
gameplay/gameplay.vcxproj

@@ -206,26 +206,25 @@
     <None Include="res\logo_powered_black.png" />
     <None Include="res\logo_powered_white.png" />
     <None Include="res\logo_white.png" />
-    <None Include="res\shaders\bumped.fsh" />
-    <None Include="res\shaders\bumped.vsh" />
-    <None Include="res\shaders\colored-unlit.fsh" />
-    <None Include="res\shaders\colored-unlit.vsh" />
-    <None Include="res\shaders\colored.fsh" />
-    <None Include="res\shaders\colored.vsh" />
-    <None Include="res\shaders\lib\attributes-skinning.vsh" />
-    <None Include="res\shaders\lib\attributes.vsh" />
-    <None Include="res\shaders\lib\lighting-directional.fsh" />
-    <None Include="res\shaders\lib\lighting-directional.vsh" />
-    <None Include="res\shaders\lib\lighting-point.fsh" />
-    <None Include="res\shaders\lib\lighting-point.vsh" />
-    <None Include="res\shaders\lib\lighting-spot.fsh" />
-    <None Include="res\shaders\lib\lighting-spot.vsh" />
-    <None Include="res\shaders\lib\lighting.fsh" />
-    <None Include="res\shaders\lib\lighting.vsh" />
-    <None Include="res\shaders\textured-unlit.fsh" />
-    <None Include="res\shaders\textured-unlit.vsh" />
-    <None Include="res\shaders\textured.fsh" />
-    <None Include="res\shaders\textured.vsh" />
+    <None Include="res\shaders\bumped.frag" />
+    <None Include="res\shaders\bumped.vert" />
+    <None Include="res\shaders\colored-unlit.frag" />
+    <None Include="res\shaders\colored-unlit.vert" />
+    <None Include="res\shaders\colored.frag" />
+    <None Include="res\shaders\colored.vert" />
+    <None Include="res\shaders\lib\attributes-skinning.vert" />
+    <None Include="res\shaders\lib\attributes.vert" />
+    <None Include="res\shaders\lib\lighting-directional.frag" />
+    <None Include="res\shaders\lib\lighting-directional.vert" />
+    <None Include="res\shaders\lib\lighting-point.frag" />
+    <None Include="res\shaders\lib\lighting-point.vert" />
+    <None Include="res\shaders\lib\lighting-spot.frag" />
+    <None Include="res\shaders\lib\lighting-spot.vert" />
+    <None Include="res\shaders\lib\lighting.frag" />
+    <None Include="res\shaders\textured-unlit.frag" />
+    <None Include="res\shaders\textured-unlit.vert" />
+    <None Include="res\shaders\textured.frag" />
+    <None Include="res\shaders\textured.vert" />
     <None Include="src\BoundingBox.inl" />
     <None Include="src\BoundingSphere.inl" />
     <None Include="src\Curve.inl" />

+ 19 - 22
gameplay/gameplay.vcxproj.filters

@@ -613,64 +613,61 @@
     <None Include="src\Joystick.inl">
       <Filter>src</Filter>
     </None>
-    <None Include="res\shaders\bumped.fsh">
+    <None Include="res\shaders\textured.vert">
       <Filter>res\shaders</Filter>
     </None>
-    <None Include="res\shaders\bumped.vsh">
+    <None Include="res\shaders\textured.frag">
       <Filter>res\shaders</Filter>
     </None>
-    <None Include="res\shaders\colored.fsh">
+    <None Include="res\shaders\textured-unlit.vert">
       <Filter>res\shaders</Filter>
     </None>
-    <None Include="res\shaders\colored.vsh">
+    <None Include="res\shaders\textured-unlit.frag">
       <Filter>res\shaders</Filter>
     </None>
-    <None Include="res\shaders\colored-unlit.fsh">
+    <None Include="res\shaders\colored.vert">
       <Filter>res\shaders</Filter>
     </None>
-    <None Include="res\shaders\colored-unlit.vsh">
+    <None Include="res\shaders\colored.frag">
       <Filter>res\shaders</Filter>
     </None>
-    <None Include="res\shaders\textured.fsh">
+    <None Include="res\shaders\colored-unlit.vert">
       <Filter>res\shaders</Filter>
     </None>
-    <None Include="res\shaders\textured.vsh">
+    <None Include="res\shaders\colored-unlit.frag">
       <Filter>res\shaders</Filter>
     </None>
-    <None Include="res\shaders\textured-unlit.fsh">
+    <None Include="res\shaders\bumped.vert">
       <Filter>res\shaders</Filter>
     </None>
-    <None Include="res\shaders\textured-unlit.vsh">
+    <None Include="res\shaders\bumped.frag">
       <Filter>res\shaders</Filter>
     </None>
-    <None Include="res\shaders\lib\attributes.vsh">
+    <None Include="res\shaders\lib\lighting.frag">
       <Filter>res\shaders\lib</Filter>
     </None>
-    <None Include="res\shaders\lib\attributes-skinning.vsh">
+    <None Include="res\shaders\lib\lighting-spot.vert">
       <Filter>res\shaders\lib</Filter>
     </None>
-    <None Include="res\shaders\lib\lighting.fsh">
+    <None Include="res\shaders\lib\lighting-spot.frag">
       <Filter>res\shaders\lib</Filter>
     </None>
-    <None Include="res\shaders\lib\lighting.vsh">
+    <None Include="res\shaders\lib\lighting-point.vert">
       <Filter>res\shaders\lib</Filter>
     </None>
-    <None Include="res\shaders\lib\lighting-directional.fsh">
+    <None Include="res\shaders\lib\lighting-point.frag">
       <Filter>res\shaders\lib</Filter>
     </None>
-    <None Include="res\shaders\lib\lighting-directional.vsh">
+    <None Include="res\shaders\lib\lighting-directional.vert">
       <Filter>res\shaders\lib</Filter>
     </None>
-    <None Include="res\shaders\lib\lighting-point.fsh">
+    <None Include="res\shaders\lib\lighting-directional.frag">
       <Filter>res\shaders\lib</Filter>
     </None>
-    <None Include="res\shaders\lib\lighting-point.vsh">
+    <None Include="res\shaders\lib\attributes.vert">
       <Filter>res\shaders\lib</Filter>
     </None>
-    <None Include="res\shaders\lib\lighting-spot.fsh">
-      <Filter>res\shaders\lib</Filter>
-    </None>
-    <None Include="res\shaders\lib\lighting-spot.vsh">
+    <None Include="res\shaders\lib\attributes-skinning.vert">
       <Filter>res\shaders\lib</Filter>
     </None>
   </ItemGroup>

+ 69 - 0
gameplay/res/shaders/bumped.frag

@@ -0,0 +1,69 @@
+#define LIGHTING
+#define BUMPED
+#ifdef OPENGL_ES
+precision highp float;
+#endif
+
+// Inputs
+varying vec3 v_normalVector;					// Normal vector in view space
+varying vec2 v_texCoord;						// Texture Coordinate
+#if defined(SPECULAR)
+varying vec3 v_cameraDirection;                 // Camera direction
+#endif
+#if defined(POINT_LIGHT)
+varying vec3 v_vertexToPointLightDirection;		// Light direction w.r.t current vertex in tangent space.
+varying float v_pointLightAttenuation;			// Attenuation of point light.
+#elif defined(SPOT_LIGHT)
+varying vec3 v_spotLightDirection;				// Direction of spot light in tangent space.
+varying vec3 v_vertexToSpotLightDirection;		// Direction of the spot light w.r.t current vertex in tangent space.
+varying float v_spotLightAttenuation;			// Attenuation of spot light.
+#else
+varying vec3 v_lightDirection;					// Direction of light in tangent space.
+#endif
+#if defined(SPECULAR)
+varying vec3 v_cameraDirection;                 // Camera direction
+#endif
+
+// Uniforms
+uniform sampler2D u_textureDiffuse;        		// Diffuse map texture
+uniform sampler2D u_textureNormal;       		// Normal map texture
+uniform vec3 u_lightDirection;					// Light direction
+uniform vec3 u_lightColor;                      // Light color
+uniform vec3 u_ambientColor;                    // Ambient color
+#if defined(SPECULAR)
+uniform float u_specularExponent;				// Specular exponent.
+#endif
+#if defined(MODULATE_COLOR)
+uniform vec4 u_modulateColor;					// Modulation color
+#endif
+#if defined(MODULATE_ALPHA)
+uniform float u_modulateAlpha;					// Modulation alpha
+#endif
+#include "lib/lighting.frag"
+#if defined(POINT_LIGHT)
+#include "lib/lighting-point.frag"
+#elif defined(SPOT_LIGHT)
+uniform float u_spotLightInnerAngleCos;			// The bright spot [0.0 - 1.0]
+uniform float u_spotLightOuterAngleCos;			// The soft outer part [0.0 - 1.0]
+#include "lib/lighting-spot.frag"
+#else
+#include "lib/lighting-directional.frag"
+#endif
+
+void main()
+{
+    // Fetch diffuse color from texture.
+    _baseColor = texture2D(u_textureDiffuse, v_texCoord);
+
+    // Light the pixel
+    gl_FragColor.a = _baseColor.a;
+    gl_FragColor.rgb = getLitPixel();
+
+	// Global color modulation
+	#if defined(MODULATE_COLOR)
+	gl_FragColor *= u_modulateColor;
+	#endif
+	#if defined(MODULATE_ALPHA)
+    gl_FragColor.a *= u_modulateAlpha;
+    #endif
+}

+ 0 - 48
gameplay/res/shaders/bumped.fsh

@@ -1,48 +0,0 @@
-#define BUMPED
-
-#ifdef OPENGL_ES
-precision highp float;
-#endif
-
-// Uniforms
-uniform sampler2D u_textureDiffuse;        	// Diffuse texture.
-uniform sampler2D u_textureNormal;       	// Normal map texture.
-
-#if defined(MODULATE_COLOR)
-uniform vec4 u_modulateColor;               // Modulation color
-#endif
-#if defined(MODULATE_ALPHA)
-uniform float u_modulateAlpha;              // Modulation alpha
-#endif
-
-// Inputs
-varying vec3 v_normalVector;                // Normal vector in view space.
-varying vec2 v_texCoord;                    // Texture Coordinate.
-
-// Lighting
-#include "lib/lighting.fsh"
-#if defined(POINT_LIGHT)
-#include "lib/lighting-point.fsh"
-#elif defined(SPOT_LIGHT)
-#include "lib/lighting-spot.fsh"
-#else
-#include "lib/lighting-directional.fsh"
-#endif
-
-void main()
-{
-    // Fetch diffuse color from texture.
-    _baseColor = texture2D(u_textureDiffuse, v_texCoord);
-
-    // Light the pixel
-    gl_FragColor.a = _baseColor.a;
-    gl_FragColor.rgb = getLitPixel();
-
-	// Global color modulation
-	#if defined(MODULATE_COLOR)
-	gl_FragColor *= u_modulateColor;
-	#endif
-	#if defined(MODULATE_ALPHA)
-    gl_FragColor.a *= u_modulateAlpha;
-    #endif
-}

+ 94 - 0
gameplay/res/shaders/bumped.vert

@@ -0,0 +1,94 @@
+#define LIGHTING
+#define BUMPED
+
+// Uniforms
+uniform mat4 u_worldViewProjectionMatrix;					// Matrix to transform a position to clip space
+uniform mat4 u_inverseTransposeWorldViewMatrix;				// Matrix to transform a normal to view space
+#if defined(SKINNING)
+uniform vec4 u_matrixPalette[SKINNING_JOINT_COUNT * 3];		// Array of 4x3 matrices as an array of floats
+#endif
+#if defined(SPECULAR)
+uniform mat4 u_worldViewMatrix;								// Matrix to tranform a position to view space
+uniform vec3 u_cameraPosition;                 				// Position of the camera in view space
+#endi
+#if defined(TEXTURE_REPEAT)
+uniform vec2 u_textureRepeat;
+#endif
+#if defined(TEXTURE_OFFSET)
+uniform vec2 u_textureOffset;
+#endif
+#if defined(POINT_LIGHT)
+uniform vec3 u_pointLightPosition;							// Position
+uniform float u_pointLightRangeInverse;						// Inverse of light range
+#elif defined(SPOT_LIGHT)
+uniform vec3 u_spotLightPosition;							// Position
+uniform float u_spotLightRangeInverse;						// Inverse of light range
+uniform vec3 u_spotLightDirection;							// Direction
+#else
+uniform vec3 u_lightDirection;								// Direction
+#endif
+
+// Inputs
+attribute vec4 a_position;									// Vertex Position              (x, y, z, w)
+attribute vec3 a_normal;									// Vertex Normal                (x, y, z)
+attribute vec2 a_texCoord;									// Vertex Texture Coordinate    (u, v)
+attribute vec3 a_tangent;									// Vertex Tangent               (x, y, z)
+attribute vec3 a_binormal;									// Vertex Binormal/Bitangent    (x, y, z)
+
+// Outputs
+varying vec3 v_normalVector;								// Normal vector in view space
+varying vec2 v_texCoord;									// Output Texture Coordinate     (u,v)
+// Lighting
+#if defined(POINT_LIGHT)
+varying vec3 v_vertexToPointLightDirection;					// Direction of point light w.r.t current vertex in tangent space
+varying float v_pointLightAttenuation;						// Attenuation of point light
+#include "lib/lighting-point.vert"
+#elif defined(SPOT_LIGHT)
+varying vec3 v_vertexToSpotLightDirection;					// Direction of the spot light w.r.t current vertex in tangent space
+varying float v_spotLightAttenuation;						// Attenuation of spot light
+varying vec3 v_spotLightDirection;							// Direction of spot light in tangent space
+#include "lib/lighting-spot.vert"
+#else
+uniform vec3 u_lightDirection;								// Direction of light
+#include "lib/lighting-directional.vert"
+#endif
+
+// Vertex Attribute Accessors
+#if defined(SKINNING)
+#include "lib/attributes-skinning.vert"
+#else
+#include "lib/attributes.vert" 
+#endif
+
+void main()
+{
+    // Get the position, normal, tangents and binormals.
+    vec4 position = getPosition();
+    vec3 normal = getNormal();
+    vec3 tangent = getTangent();
+    vec3 binormal = getBinormal();
+    
+    // Transform position to clip space.
+    gl_Position = u_worldViewProjectionMatrix * position;
+
+    // Transform the normal, tangent and binormals to view space.
+    mat3 inverseTransposeWorldViewMatrix = mat3(u_inverseTransposeWorldViewMatrix[0].xyz, u_inverseTransposeWorldViewMatrix[1].xyz, u_inverseTransposeWorldViewMatrix[2].xyz);
+    vec3 normalVector = normalize(inverseTransposeWorldViewMatrix * normal);
+    
+    // Create a transform to convert a vector to tangent space.
+    vec3 tangentVector  = normalize(inverseTransposeWorldViewMatrix * tangent);
+    vec3 binormalVector = normalize(inverseTransposeWorldViewMatrix * binormal);
+    mat3 tangentSpaceTransformMatrix = mat3(tangentVector.x, binormalVector.x, normalVector.x, tangentVector.y, binormalVector.y, normalVector.y, tangentVector.z, binormalVector.z, normalVector.z);
+    
+    // Apply light.
+    applyLight(tangentSpaceTransformMatrix);
+    
+    // Texture transformation.
+    v_texCoord = a_texCoord;
+    #if defined(TEXTURE_REPEAT)
+    v_texCoord *= u_textureRepeat;
+    #endif
+    #if defined(TEXTURE_OFFSET)
+    v_texCoord += u_textureOffset;
+    #endif
+}

+ 0 - 72
gameplay/res/shaders/bumped.vsh

@@ -1,72 +0,0 @@
-#define BUMPED
-
-// Uniforms
-uniform mat4 u_worldViewProjectionMatrix;           // Matrix to transform a position to clip space
-uniform mat4 u_inverseTransposeWorldViewMatrix;     // Matrix to transform a normal to view space
-#if defined(TEXTURE_REPEAT)
-uniform vec2 u_textureRepeat;
-#endif
-#if defined(TEXTURE_OFFSET)
-uniform vec2 u_textureOffset;
-#endif
-
-// Inputs
-attribute vec4 a_position;                          // Vertex Position              (x, y, z, w)
-attribute vec3 a_normal;                            // Vertex Normal                (x, y, z)
-attribute vec2 a_texCoord;                          // Vertex Texture Coordinate    (u, v)
-attribute vec3 a_tangent;                           // Vertex Tangent               (x, y, z)
-attribute vec3 a_binormal;                          // Vertex Binormal/Bitangent    (x, y, z)
-
-// Outputs
-varying vec3 v_normalVector;                        // Normal vector in view space.
-varying vec2 v_texCoord;                            // Output Texture Coordinate     (u,v)
-
-// Lighting
-#include "lib/lighting.vsh"
-#if defined(POINT_LIGHT)
-#include "lib/lighting-point.vsh"
-#elif defined(SPOT_LIGHT)
-#include "lib/lighting-spot.vsh"
-#else
-#include "lib/lighting-directional.vsh"
-#endif
-
-// Attribute Accessors (getPosition(), getNormal(), etc.)
-#if defined(SKINNING)
-#include "lib/attributes-skinning.vsh"
-#else
-#include "lib/attributes.vsh" 
-#endif
-
-void main()
-{
-    // Get the position, normal, tangents and binormals.
-    vec4 position = getPosition();
-    vec3 normal = getNormal();
-    vec3 tangent = getTangent();
-    vec3 binormal = getBinormal();
-    
-    // Transform position to clip space.
-    gl_Position = u_worldViewProjectionMatrix * position;
-
-    // Transform the normal, tangent and binormals to view space.
-    mat3 inverseTransposeWorldViewMatrix = mat3(u_inverseTransposeWorldViewMatrix[0].xyz, u_inverseTransposeWorldViewMatrix[1].xyz, u_inverseTransposeWorldViewMatrix[2].xyz);
-    vec3 normalVector = normalize(inverseTransposeWorldViewMatrix * normal);
-    
-    // Create a transform to convert a vector to tangent space.
-    vec3 tangentVector  = normalize(inverseTransposeWorldViewMatrix * tangent);
-    vec3 binormalVector = normalize(inverseTransposeWorldViewMatrix * binormal);
-    mat3 tangentSpaceTransformMatrix = mat3(tangentVector.x, binormalVector.x, normalVector.x, tangentVector.y, binormalVector.y, normalVector.y, tangentVector.z, binormalVector.z, normalVector.z);
-    
-    // Apply light.
-    applyLight(tangentSpaceTransformMatrix);
-    
-    // Texture transformation.
-    v_texCoord = a_texCoord;
-    #if defined(TEXTURE_REPEAT)
-    v_texCoord *= u_textureRepeat;
-    #endif
-    #if defined(TEXTURE_OFFSET)
-    v_texCoord += u_textureOffset;
-    #endif
-}

+ 1 - 0
gameplay/res/shaders/colored-unlit.fsh → gameplay/res/shaders/colored-unlit.frag

@@ -17,6 +17,7 @@ uniform vec4 u_modulateColor;               // Modulation color
 uniform float u_modulateAlpha;              // Modulation alpha
 #endif
 
+// Fragment program
 void main()
 {
     // Set base diffuse color

+ 39 - 0
gameplay/res/shaders/colored-unlit.vert

@@ -0,0 +1,39 @@
+// Inputs
+attribute vec4 a_position;									// Vertex Position							(x, y, z, w)
+#if defined(SKINNING)
+attribute vec4 a_blendWeights;								// Vertex blend weight, up to 4				(0, 1, 2, 3) 
+attribute vec4 a_blendIndices;								// Vertex blend index int u_matrixPalette	(0, 1, 2, 3)
+#endif
+#if defined(VERTEX_COLOR)
+attribute vec3 a_color;										// Vertex Color								(r, g, b)
+varying vec3 v_color;										// Output Vertex color						(r, g, b)
+#endif
+
+
+// Uniforms
+uniform mat4 u_worldViewProjectionMatrix;					// Matrix to transform a position to clip space.
+#if defined(SKINNING)
+uniform vec4 u_matrixPalette[SKINNING_JOINT_COUNT * 3];		// Array of 4x3 matrices as an array of floats
+#endif
+
+// Attribute accessor
+#if defined(SKINNING)
+#include "lib/attributes-skinning.vert"
+#else
+#include "lib/attributes.vert" 
+#endif
+
+// Vertex Program
+void main()
+{
+    // Get the vertex position
+    vec4 position = getPosition();
+    
+    // Transform position to clip space.a
+    gl_Position = u_worldViewProjectionMatrix *  position;
+    
+     // Pass on vertex color to fragment shader
+    #if defined(VERTEX_COLOR)
+	v_color = a_color;
+    #endif
+}

+ 0 - 29
gameplay/res/shaders/colored-unlit.vsh

@@ -1,29 +0,0 @@
-// Uniforms
-uniform mat4 u_worldViewProjectionMatrix;           // Matrix to transform a position to clip space.
-
-// Inputs
-attribute vec4 a_position;                          // Vertex Position          (x, y, z, w)
-#if defined(VERTEX_COLOR)
-attribute vec3 a_color;                             // Vertex Color             (r, g, b)
-varying vec3 v_color;								// Output Vertex color      (r, g, b)
-#endif
-
-#if defined(SKINNING)
-#include "lib/attributes-skinning.vsh"
-#else
-#include "lib/attributes.vsh" 
-#endif
-
-void main()
-{
-    // Get the vertex position
-    vec4 position = getPosition();
-    
-    // Transform position to clip space.a
-    gl_Position = u_worldViewProjectionMatrix *  position;
-    
-     // Pass on vertex color to fragment shader
-    #if defined(VERTEX_COLOR)
-	v_color = a_color;
-    #endif
-}

+ 70 - 0
gameplay/res/shaders/colored.frag

@@ -0,0 +1,70 @@
+#define LIGHTING
+#ifdef OPENGL_ES
+precision highp float;
+#endif
+
+// Inputs
+varying vec3 v_normalVector;					// Normal vector in view space
+#if defined(VERTEX_COLOR)
+varying vec3 v_color;							// Vertex color
+#endif
+#if defined(POINT_LIGHT)
+varying vec3 v_vertexToPointLightDirection;		// Light direction w.r.t current vertex in tangent space
+varying float v_pointLightAttenuation;			// Attenuation of point light
+#elif defined(SPOT_LIGHT)
+varying vec3 v_spotLightDirection;				// Direction of spot light in tangent space.
+varying vec3 v_vertexToSpotLightDirection;		// Direction of the spot light w.r.t current vertex in tangent space
+varying float v_spotLightAttenuation;			// Attenuation of spot light
+#else
+varying vec3 v_lightDirection;					// Direction of light in tangent space
+#endif
+#if defined(SPECULAR)
+varying vec3 v_cameraDirection;                 // Camera direction
+#endif
+
+// Uniforms
+uniform vec4 u_baseColor;               		// Base color
+uniform vec3 u_lightDirection;					// Light direction
+uniform vec3 u_lightColor;                      // Light color
+uniform vec3 u_ambientColor;                    // Ambient color
+#if defined(SPECULAR)
+uniform float u_specularExponent;				// Specular exponent
+#endif
+#if defined(MODULATE_COLOR)
+uniform vec4 u_modulateColor;					// Modulation color
+#endif
+#if defined(MODULATE_ALPHA)
+uniform float u_modulateAlpha;					// Modulation alpha
+#endif
+#include "lib/lighting.frag"
+#if defined(POINT_LIGHT)
+#include "lib/lighting-point.frag"
+#elif defined(SPOT_LIGHT)
+uniform float u_spotLightInnerAngleCos;			// The bright spot [0.0 - 1.0]
+uniform float u_spotLightOuterAngleCos;			// The soft outer part [0.0 - 1.0]
+#include "lib/lighting-spot.frag"
+#else
+#include "lib/lighting-directional.frag"
+#endif
+
+// Fragment program
+void main()
+{
+    // Set base diffuse color
+    #if defined(VERTEX_COLOR)
+	_baseColor.rgb = v_color;
+	#else
+	_baseColor = u_baseColor;
+	#endif
+
+    // Light the pixel
+    gl_FragColor.a = _baseColor.a;
+    gl_FragColor.rgb = getLitPixel();
+    
+	#if defined(MODULATE_COLOR)
+    gl_FragColor.a *= u_modulateColor;
+    #endif
+	#if defined(MODULATE_ALPHA)
+    gl_FragColor.a *= u_modulateAlpha;
+    #endif
+}

+ 0 - 50
gameplay/res/shaders/colored.fsh

@@ -1,50 +0,0 @@
-#ifdef OPENGL_ES
-precision highp float;
-#endif
-
-// Uniforms
-uniform vec4 u_baseColor;               	// Modulation color
-
-#if defined(MODULATE_COLOR)
-uniform vec4 u_modulateColor;               // Modulation color
-#endif
-#if defined(MODULATE_ALPHA)
-uniform float u_modulateAlpha;              // Modulation alpha
-#endif
-
-// Inputs
-varying vec3 v_normalVector;                // Normal vector in view space
-#if defined(VERTEX_COLOR)
-varying vec3 v_color;						// Vertex color
-#endif
-
-// Lighting
-#include "lib/lighting.fsh"
-#if defined(POINT_LIGHT)
-#include "lib/lighting-point.fsh"
-#elif defined(SPOT_LIGHT)
-#include "lib/lighting-spot.fsh"
-#else
-#include "lib/lighting-directional.fsh"
-#endif
-
-void main()
-{
-    // Set base diffuse color
-    #if defined(VERTEX_COLOR)
-	_baseColor.rgb = v_color;
-	#else
-	_baseColor = u_baseColor;
-	#endif
-
-    // Light the pixel
-    gl_FragColor.a = _baseColor.a;
-    gl_FragColor.rgb = getLitPixel();
-    
-	#if defined(MODULATE_COLOR)
-    gl_FragColor.a *= u_modulateColor;
-    #endif
-	#if defined(MODULATE_ALPHA)
-    gl_FragColor.a *= u_modulateAlpha;
-    #endif
-}

+ 81 - 0
gameplay/res/shaders/colored.vert

@@ -0,0 +1,81 @@
+#define LIGHTING
+
+// Inputs
+attribute vec4 a_position;									// Vertex Position							(x, y, z, w)
+attribute vec3 a_normal;									// Vertex Normal							(x, y, z)
+#if defined(SKINNING)
+attribute vec4 a_blendWeights;								// Vertex blend weight, up to 4				(0, 1, 2, 3) 
+attribute vec4 a_blendIndices;								// Vertex blend index int u_matrixPalette	(0, 1, 2, 3)
+#endif
+#if defined(VERTEX_COLOR)
+attribute vec3 a_color;										// Output Vertex Color
+varying vec3 v_color;										// Output Vertex Color 
+#endif
+
+// Uniforms
+uniform mat4 u_worldViewProjectionMatrix;					// Matrix to transform a position to clip space.
+uniform mat4 u_inverseTransposeWorldViewMatrix;				// Matrix to transform a normal to view space.
+#if defined(SKINNING)
+uniform vec4 u_matrixPalette[SKINNING_JOINT_COUNT * 3];		// Array of 4x3 matrices
+#endif
+#if defined(SPECULAR)
+uniform mat4 u_worldViewMatrix;								// Matrix to tranform a position to view space.
+uniform vec3 u_cameraPosition;                 				// Position of the camera in view space.
+#endif
+#if defined(POINT_LIGHT)
+uniform vec3 u_pointLightPosition;							// Position of light
+uniform float u_pointLightRangeInverse;						// Inverse of light range 
+#elif defined(SPOT_LIGHT)
+uniform vec3 u_spotLightPosition;							// Position of light
+uniform float u_spotLightRangeInverse;						// Inverse of light range.
+#else
+#endif
+
+// Outputs
+varying vec3 v_normalVector;								// Normal vector in view space.
+#if defined(SPECULAR)
+varying vec3 v_cameraDirection;								// Direction the camera is looking at in tangent space.
+#endif
+// Lighting
+#if defined(POINT_LIGHT)
+varying vec3 v_vertexToPointLightDirection;					// Direction of point light w.r.t current vertex in tangent space.
+varying float v_pointLightAttenuation;						// Attenuation of point light.
+#include "lib/lighting-point.vert"
+#elif defined(SPOT_LIGHT)
+varying vec3 v_vertexToSpotLightDirection;					// Direction of the spot light w.r.t current vertex in tangent space.
+varying float v_spotLightAttenuation;						// Attenuation of spot light.
+#include "lib/lighting-spot.vert"
+#else
+uniform vec3 u_lightDirection;								// Direction of light
+#include "lib/lighting-directional.vert"
+#endif
+
+// Vertex attribute accessors
+#if defined(SKINNING)
+#include "lib/attributes-skinning.vert"
+#else
+#include "lib/attributes.vert" 
+#endif
+
+// Vertex program
+void main()
+{
+    // Get the position and normal
+    vec4 position = getPosition();
+    vec3 normal = getNormal();
+
+    // Transform position to clip space.
+    gl_Position = u_worldViewProjectionMatrix * position;
+
+    // Transform normal to view space.
+    mat3 inverseTransposeWorldViewMatrix = mat3(u_inverseTransposeWorldViewMatrix[0].xyz, u_inverseTransposeWorldViewMatrix[1].xyz, u_inverseTransposeWorldViewMatrix[2].xyz);
+    v_normalVector = inverseTransposeWorldViewMatrix * normal;
+
+    // Apply light.
+    applyLight(position);
+    
+    // Pass the vertex color to fragment shader
+    #if defined(VERTEX_COLOR)
+	v_color = a_color;
+    #endif
+}

+ 0 - 51
gameplay/res/shaders/colored.vsh

@@ -1,51 +0,0 @@
-// Uniforms
-uniform mat4 u_worldViewProjectionMatrix;           // Matrix to transform a position to clip space.
-uniform mat4 u_inverseTransposeWorldViewMatrix;     // Matrix to transform a normal to view space.
-
-// Inputs
-attribute vec4 a_position;                          // Vertex Position (x, y, z, w)
-attribute vec3 a_normal;                            // Vertex Normal (x, y, z)
-#if defined(VERTEX_COLOR)
-attribute vec3 a_color;                             // Vertex Color (r, g, b)
-varying vec3 v_color;								// Output Vertex color 
-#endif
-
-// Outputs
-varying vec3 v_normalVector;                        // Normal vector in view space.
-
-#include "lib/lighting.vsh"
-#if defined(POINT_LIGHT)
-#include "lib/lighting-point.vsh"
-#elif defined(SPOT_LIGHT)
-#include "lib/lighting-spot.vsh"
-#else
-#include "lib/lighting-directional.vsh"
-#endif
-
-#if defined(SKINNING)
-#include "lib/attributes-skinning.vsh"
-#else
-#include "lib/attributes.vsh" 
-#endif
-
-void main()
-{
-    // Get the position and normal
-    vec4 position = getPosition();
-    vec3 normal = getNormal();
-
-    // Transform position to clip space.
-    gl_Position = u_worldViewProjectionMatrix * position;
-
-    // Transform normal to view space.
-    mat3 inverseTransposeWorldViewMatrix = mat3(u_inverseTransposeWorldViewMatrix[0].xyz, u_inverseTransposeWorldViewMatrix[1].xyz, u_inverseTransposeWorldViewMatrix[2].xyz);
-    v_normalVector = inverseTransposeWorldViewMatrix * normal;
-
-    // Apply light.
-    applyLight(position);
-    
-    // Pass the vertex color to fragment shader
-    #if defined(VERTEX_COLOR)
-	v_color = a_color;
-    #endif
-}

+ 0 - 9
gameplay/res/shaders/lib/attributes-skinning.vsh → gameplay/res/shaders/lib/attributes-skinning.vert

@@ -1,10 +1,3 @@
-attribute vec4 a_blendWeights;
-attribute vec4 a_blendIndices;
-
-// 32 4x3 matrices as an array of floats
-uniform vec4 u_matrixPalette[SKINNING_JOINT_COUNT * 3];
-
-// Global 
 vec4 _skinnedPosition;
 #if defined(LIGHTING)
 vec3 _skinnedNormal;
@@ -17,7 +10,6 @@ void skinPosition(float blendWeight, int matrixIndex)
     tmp.y = dot(a_position, u_matrixPalette[matrixIndex + 1]);
     tmp.z = dot(a_position, u_matrixPalette[matrixIndex + 2]);
     tmp.w = a_position.w;
-
     _skinnedPosition += blendWeight * tmp;
 }
 
@@ -51,7 +43,6 @@ void skinTangentSpaceVector(vec3 vector, float blendWeight, int matrixIndex)
     tmp.x = dot(vector, u_matrixPalette[matrixIndex].xyz);
     tmp.y = dot(vector, u_matrixPalette[matrixIndex + 1].xyz);
     tmp.z = dot(vector, u_matrixPalette[matrixIndex + 2].xyz);
-	
     _skinnedNormal += blendWeight * tmp;
 }
 

+ 0 - 0
gameplay/res/shaders/lib/attributes.vsh → gameplay/res/shaders/lib/attributes.vert


+ 0 - 2
gameplay/res/shaders/lib/lighting-directional.fsh → gameplay/res/shaders/lib/lighting-directional.frag

@@ -1,5 +1,3 @@
-varying vec3 v_lightDirection;                 // Direction of light in tangent space.
-
 #if defined(BUMPED)
 
 vec3 getLitPixel()

+ 5 - 7
gameplay/res/shaders/lib/lighting-directional.vsh → gameplay/res/shaders/lib/lighting-directional.vert

@@ -1,16 +1,13 @@
 #if defined(BUMPED)
 
-uniform vec3 u_lightDirection;                  // Direction of light
-varying vec3 v_lightDirection;                  // Direction of light in tangent space.
-
 void applyLight(mat3 tangentSpaceTransformMatrix)
 {
     // Transform light direction to tangent space
     v_lightDirection = tangentSpaceTransformMatrix * u_lightDirection;
     
-    // Compute the camera direction for specular lighting
     #if defined(SPECULAR)
-    
+
+    // Compute the camera direction for specular lighting
     vec4 positionWorldSpace = u_worldViewMatrix * a_position;
     v_cameraDirection = u_cameraPosition - positionWorldSpace.xyz;
     
@@ -21,9 +18,10 @@ void applyLight(mat3 tangentSpaceTransformMatrix)
 
 void applyLight(vec4 position)
 {
-    // Compute the camera direction for specular lighting
-    #if defined(SPECULAR)
     
+    #if defined(SPECULAR)
+
+    // Compute the camera direction for specular lighting
     vec4 positionWorldSpace = u_worldViewMatrix * position;
     v_cameraDirection = u_cameraPosition - positionWorldSpace.xyz;
 

+ 0 - 3
gameplay/res/shaders/lib/lighting-point.fsh → gameplay/res/shaders/lib/lighting-point.frag

@@ -1,6 +1,3 @@
-varying vec3 v_vertexToPointLightDirection;   // Light direction w.r.t current vertex in tangent space.
-varying float v_pointLightAttenuation;        // Attenuation of point light.
-
 #if defined(BUMPED)
 
 vec3 getLitPixel()

+ 0 - 5
gameplay/res/shaders/lib/lighting-point.vsh → gameplay/res/shaders/lib/lighting-point.vert

@@ -1,8 +1,3 @@
-uniform vec3 u_pointLightPosition;                  // Position
-uniform float u_pointLightRangeInverse;             // Inverse of light range 
-varying vec3 v_vertexToPointLightDirection;         // Direction of point light w.r.t current vertex in tangent space.
-varying float v_pointLightAttenuation;              // Attenuation of point light.
-
 #if defined(BUMPED)
 
 void applyLight(mat3 tangentSpaceTransformMatrix)

+ 2 - 13
gameplay/res/shaders/lib/lighting-spot.fsh → gameplay/res/shaders/lib/lighting-spot.frag

@@ -1,10 +1,3 @@
-uniform float u_spotLightInnerAngleCos;       // The bright spot [0.0 - 1.0]
-uniform float u_spotLightOuterAngleCos;       // The soft outer part [0.0 - 1.0]
-
-varying vec3 v_spotLightDirection;            // Direction of spot light in tangent space.
-varying vec3 v_vertexToSpotLightDirection;    // Direction of the spot light w.r.t current vertex in tangent space.
-varying float v_spotLightAttenuation;         // Attenuation of spot light.
-
 float lerpstep( float lower, float upper, float s)
 {
     return clamp( ( s - lower ) / ( upper - lower ), 0.0, 1.0 );
@@ -19,13 +12,10 @@ vec3 getLitPixel()
     vec3 spotLightDirection = normalize(v_spotLightDirection);
     vec3 vertexToSpotLightDirection = normalize(v_vertexToSpotLightDirection);
     
-    // "-lightDirection" because light direction points in opposite direction to
-    // to spot direction.
-    // Calculate spot light effect.
+    // "-lightDirection" because light direction points in opposite direction to to spot direction.
     float spotCurrentAngleCos = max(0.0, dot(spotLightDirection, -vertexToSpotLightDirection));
     
-    // Intensity of spot depends on the spot light attenuation and the 
-    // part of the cone vertexToSpotLightDirection points to (inner or outer).
+    // Intensity of spot depends on the spot light attenuation and the part of the cone vertexToSpotLightDirection points to (inner or outer).
     float spotLightAttenuation = clamp(v_spotLightAttenuation, 0.0, 1.0);
     spotLightAttenuation *= lerpstep(u_spotLightOuterAngleCos, u_spotLightInnerAngleCos, spotCurrentAngleCos);
 
@@ -51,7 +41,6 @@ vec3 getLitPixel()
     vec3 vertexToSpotLightDirection = normalize(v_vertexToSpotLightDirection);
 
     // "-lightDirection" is used because light direction points in opposite direction to to spot direction.
-    // Calculate spot light effect.
     float spotCurrentAngleCos = max(0.0, dot(spotLightDirection, -vertexToSpotLightDirection));
     
     // Intensity of spot depends on the spot light attenuation and the 

+ 0 - 14
gameplay/res/shaders/lib/lighting-spot.vsh → gameplay/res/shaders/lib/lighting-spot.vert

@@ -1,13 +1,5 @@
 #if defined(BUMPED)
 
-uniform vec3 u_spotLightPosition;                   // Position
-uniform float u_spotLightRangeInverse;              // Inverse of light range.
-uniform vec3 u_spotLightDirection;                  // Direction
-
-varying vec3 v_spotLightDirection;                  // Direction of spot light in tangent space.
-varying vec3 v_vertexToSpotLightDirection;          // Direction of the spot light w.r.t current vertex in tangent space.
-varying float v_spotLightAttenuation;               // Attenuation of spot light.
-
 void applyLight(mat3 tangentSpaceTransformMatrix)
 {
     vec4 positionWorldViewSpace = u_worldViewMatrix * a_position;
@@ -37,12 +29,6 @@ void applyLight(mat3 tangentSpaceTransformMatrix)
 
 #else
 
-uniform vec3 u_spotLightPosition;                   // Position
-uniform float u_spotLightRangeInverse;              // Inverse of light range.
-
-varying vec3 v_vertexToSpotLightDirection;          // Light direction w.r.t current vertex.
-varying float v_spotLightAttenuation;               // Attenuation of spot light.
-
 void applyLight(vec4 position)
 {
     // World space position.

+ 4 - 12
gameplay/res/shaders/lib/lighting.fsh → gameplay/res/shaders/lib/lighting.frag

@@ -1,18 +1,10 @@
-uniform vec3 u_lightDirection;					// Light direction.
-uniform vec3 u_lightColor;                      // Light color.
-uniform vec3 u_ambientColor;                    // Ambient color.
-
-// Variables
-vec4 _baseColor;                                // Base color.
-vec3 _ambientColor;                             // Ambient Color.
-vec3 _diffuseColor;                             // Diffuse Color.
+vec4 _baseColor;
+vec3 _ambientColor;
+vec3 _diffuseColor;
 
 #if defined(SPECULAR)
 
-vec3 _specularColor;    						// Specular color.
-
-uniform float u_specularExponent;				// Specular exponent.
-varying vec3 v_cameraDirection;                 // Camera direction.
+vec3 _specularColor;
 
 vec3 computeLighting(vec3 normalVector, vec3 lightDirection, float attenuation, vec3 cameraDirection)
 {

+ 0 - 9
gameplay/res/shaders/lib/lighting.vsh

@@ -1,9 +0,0 @@
-#define LIGHTING
-
-#if defined(SPECULAR)
-
-uniform mat4 u_worldViewMatrix;                 // Matrix to tranform a position to view space.
-uniform vec3 u_cameraPosition;                 	// Position of the camera in view space.
-varying vec3 v_cameraDirection;                 // Direction the camera is looking at in tangent space.
-
-#endif

+ 1 - 1
gameplay/res/shaders/textured-unlit.fsh → gameplay/res/shaders/textured-unlit.frag

@@ -7,7 +7,6 @@ uniform sampler2D u_textureDiffuse;     	// Diffuse texture
 #if defined(TEXTURE_LIGHT)
 uniform sampler2D u_textureLight;     		// Lightmap texture
 #endif
-
 #if defined(MODULATE_COLOR)
 uniform vec4 u_modulateColor;               // Modulation color
 #endif
@@ -18,6 +17,7 @@ uniform float u_modulateAlpha;              // Modulation alpha
 // Inputs
 varying vec2 v_texCoord;                	// Texture coordinate(u, v)
 
+// Fragment Program
 void main()
 {
     // Sample the texture for the color

+ 48 - 0
gameplay/res/shaders/textured-unlit.vert

@@ -0,0 +1,48 @@
+// Inputs
+attribute vec4 a_position;									// Vertex Position							(x, y, z, w)
+attribute vec2 a_texCoord;									// Vertex Texture Coordinate				(u, v)
+#if defined(SKINNING)
+attribute vec4 a_blendWeights;								// Vertex blend weight, up to 4				(0, 1, 2, 3) 
+attribute vec4 a_blendIndices;								// Vertex blend index int u_matrixPalette	(0, 1, 2, 3)
+#endif
+
+// Uniforms
+uniform mat4 u_worldViewProjectionMatrix;					// Matrix to transform a position to clip space
+#if defined(SKINNING)
+uniform vec4 u_matrixPalette[SKINNING_JOINT_COUNT * 3];		// Array of 4x3 matrices
+#endif
+#if defined(TEXTURE_REPEAT)
+uniform vec2 u_textureRepeat;								// Texture repeat for tiling
+#endif
+#if defined(TEXTURE_OFFSET)
+uniform vec2 u_textureOffset;								// Texture offset
+#endif
+
+// Outputs
+varying vec2 v_texCoord;									// Texture Coordinate
+
+// Vertex attribute accessors
+#if defined(SKINNING)
+#include "lib/attributes-skinning.vert"
+#else
+#include "lib/attributes.vert" 
+#endif
+
+// Vertex Program
+void main()
+{
+    // Get the vertex position
+    vec4 position = getPosition();
+
+    // Transform position to clip space.
+    gl_Position = u_worldViewProjectionMatrix * position;
+
+    // Texture transformation.
+    v_texCoord = a_texCoord;
+    #if defined(TEXTURE_REPEAT)
+    v_texCoord *= u_textureRepeat;
+    #endif
+    #if defined(TEXTURE_OFFSET)
+    v_texCoord += u_textureOffset;
+    #endif
+}

+ 0 - 40
gameplay/res/shaders/textured-unlit.vsh

@@ -1,40 +0,0 @@
-// Uniforms
-uniform mat4 u_worldViewProjectionMatrix;       // Matrix to transform a position to clip space
-#if defined(TEXTURE_REPEAT)
-uniform vec2 u_textureRepeat;
-#endif
-#if defined(TEXTURE_OFFSET)
-uniform vec2 u_textureOffset;
-#endif
-
-// Inputs
-attribute vec4 a_position;                      // Vertex Position              (x, y, z, w)
-attribute vec2 a_texCoord;                      // Vertex Texture Coordinate    (u, v)
-
-// Outputs
-varying vec2 v_texCoord;                        // Output Texture Coordinate    (u, v)
-
-// Attribute Accessors (getPosition(), getNormal(), etc.)
-#if defined(SKINNING)
-#include "lib/attributes-skinning.vsh"
-#else
-#include "lib/attributes.vsh" 
-#endif
-
-void main()
-{
-    // Get the vertex position
-    vec4 position = getPosition();
-
-    // Transform position to clip space.
-    gl_Position = u_worldViewProjectionMatrix * position;
-
-    // Texture transformation.
-    v_texCoord = a_texCoord;
-    #if defined(TEXTURE_REPEAT)
-    v_texCoord *= u_textureRepeat;
-    #endif
-    #if defined(TEXTURE_OFFSET)
-    v_texCoord += u_textureOffset;
-    #endif
-}

+ 66 - 0
gameplay/res/shaders/textured.frag

@@ -0,0 +1,66 @@
+#define LIGHTING
+
+#ifdef OPENGL_ES
+precision highp float;
+#endif
+
+// Inputs
+varying vec3 v_normalVector;                    // Normal vector in view space
+varying vec2 v_texCoord;                        // Texture coordinate
+#if defined(POINT_LIGHT)
+varying vec3 v_vertexToPointLightDirection;		// Light direction w.r.t current vertex in tangent space.
+varying float v_pointLightAttenuation;			// Attenuation of point light.
+#elif defined(SPOT_LIGHT)
+varying vec3 v_spotLightDirection;				// Direction of spot light in tangent space.
+varying vec3 v_vertexToSpotLightDirection;		// Direction of the spot light w.r.t current vertex in tangent space.
+varying float v_spotLightAttenuation;			// Attenuation of spot light.
+#else
+varying vec3 v_lightDirection;					// Direction of light in tangent space.
+#endif
+#if defined(SPECULAR)
+varying vec3 v_cameraDirection;                 // Camera direction
+#endif
+
+// Uniforms
+uniform sampler2D u_textureDiffuse;             // Diffuse map texture
+uniform vec3 u_lightDirection;					// Light direction
+uniform vec3 u_lightColor;                      // Light color
+uniform vec3 u_ambientColor;                    // Ambient color
+#if defined(SPECULAR)
+uniform float u_specularExponent;				// Specular exponent
+#endif
+#if defined(MODULATE_COLOR)
+uniform vec4 u_modulateColor;               	// Modulation color
+#endif
+#if defined(MODULATE_ALPHA)
+uniform float u_modulateAlpha;              	// Modulation alpha
+#endif
+#include "/lib/lighting.frag"
+#if defined(POINT_LIGHT)
+#include "lib/lighting-point.frag"
+#elif defined(SPOT_LIGHT)
+uniform float u_spotLightInnerAngleCos;			// The bright spot [0.0 - 1.0]
+uniform float u_spotLightOuterAngleCos;			// The soft outer part [0.0 - 1.0]
+#include "lib/lighting-spot.frag"
+#else
+#include "lib/lighting-directional.frag"
+#endif
+
+// Fragment Program
+void main()
+{
+    // Sample the diffuse texture for base color
+    _baseColor = texture2D(u_textureDiffuse, v_texCoord);
+
+    // Light the pixel
+    gl_FragColor.a = _baseColor.a;
+    gl_FragColor.rgb = getLitPixel();
+	
+	// Global color modulation
+	#if defined(MODULATE_COLOR)
+	gl_FragColor *= u_modulateColor;
+	#endif
+	#if defined(MODULATE_ALPHA)
+    gl_FragColor.a *= u_modulateAlpha;
+    #endif
+}

+ 0 - 45
gameplay/res/shaders/textured.fsh

@@ -1,45 +0,0 @@
-#ifdef OPENGL_ES
-precision highp float;
-#endif
-
-// Uniforms
-uniform sampler2D u_textureDiffuse;             // Diffuse texture.
-
-#if defined(MODULATE_COLOR)
-uniform vec4 u_modulateColor;               	// Modulation color
-#endif
-#if defined(MODULATE_ALPHA)
-uniform float u_modulateAlpha;              	// Modulation alpha
-#endif
-
-// Inputs
-varying vec3 v_normalVector;                    // NormalVector in view space.
-varying vec2 v_texCoord;                        // Texture coordinate (u, v).
-
-// Lighting
-#include "lib/lighting.fsh"                     // Functions for lighting
-#if defined(POINT_LIGHT)
-#include "lib/lighting-point.fsh"
-#elif defined(SPOT_LIGHT)
-#include "lib/lighting-spot.fsh"
-#else
-#include "lib/lighting-directional.fsh"
-#endif
-
-void main()
-{
-    // Sample the texture for base color
-    _baseColor = texture2D(u_textureDiffuse, v_texCoord);
-
-    // Light the pixel
-    gl_FragColor.a = _baseColor.a;
-    gl_FragColor.rgb = getLitPixel();
-	
-	// Global color modulation
-	#if defined(MODULATE_COLOR)
-	gl_FragColor *= u_modulateColor;
-	#endif
-	#if defined(MODULATE_ALPHA)
-    gl_FragColor.a *= u_modulateAlpha;
-    #endif
-}

+ 87 - 0
gameplay/res/shaders/textured.vert

@@ -0,0 +1,87 @@
+#define LIGHTING
+
+// Inputs
+attribute vec4 a_position;									// Vertex position							(x, y, z, w)
+attribute vec3 a_normal;									// Vertex normal							(x, y, z)
+attribute vec2 a_texCoord;									// Vertex texture coordinate				(u, v)
+#if defined(SKINNING)
+attribute vec4 a_blendWeights;								// Vertex blend weight, up to 4				(0, 1, 2, 3) 
+attribute vec4 a_blendIndices;								// Vertex blend index int u_matrixPalette	(0, 1, 2, 3)
+#endif
+
+// Uniforms
+uniform mat4 u_worldViewProjectionMatrix;					// Matrix to transform a position to clip space
+uniform mat4 u_inverseTransposeWorldViewMatrix;				// Matrix to transform a normal to view space
+#if defined(SKINNING)
+uniform vec4 u_matrixPalette[SKINNING_JOINT_COUNT * 3];		// Array of 4x3 matrices
+#endif
+#if defined(SPECULAR)
+uniform mat4 u_worldViewMatrix;								// Matrix to tranform a position to view space
+uniform vec3 u_cameraPosition;                 				// Position of the camera in view space
+#endif
+#if defined(TEXTURE_REPEAT)
+uniform vec2 u_textureRepeat;								// Texture repeat for tiling
+#endif
+#if defined(TEXTURE_OFFSET)
+uniform vec2 u_textureOffset;								// Texture offset
+#endif
+#if defined(POINT_LIGHT)
+uniform vec3 u_pointLightPosition;							// Position of light
+uniform float u_pointLightRangeInverse;						// Inverse of light range 
+#elif defined(SPOT_LIGHT)
+uniform vec3 u_spotLightPosition;							// Position of light
+uniform float u_spotLightRangeInverse;						// Inverse of light range
+#else
+#endif
+
+// Outputs
+varying vec3 v_normalVector;								// Normal vector in view space
+varying vec2 v_texCoord;									// Texture coordinate
+#if defined(SPECULAR)
+varying vec3 v_cameraDirection;								// Direction the camera is looking at in tangent space
+#endif
+#if defined(POINT_LIGHT)
+varying vec3 v_vertexToPointLightDirection;					// Direction of point light w.r.t current vertex in tangent space
+varying float v_pointLightAttenuation;						// Attenuation of point light
+#include "lib/lighting-point.vert"
+#elif defined(SPOT_LIGHT)
+varying vec3 v_vertexToSpotLightDirection;					// Direction of the spot light w.r.t current vertex in tangent space
+varying float v_spotLightAttenuation;						// Attenuation of spot light
+#include "lib/lighting-spot.vert"
+#else
+#include "lib/lighting-directional.vert"
+#endif
+
+// Vertex attribute accessors
+#if defined(SKINNING)
+#include "lib/attributes-skinning.vert"
+#else
+#include "lib/attributes.vert" 
+#endif
+
+// Vertex Program
+void main()
+{
+    // Get the position and normal from attribute accessors
+    vec4 position = getPosition();
+    vec3 normal = getNormal();
+
+    // Transform position to clip space.
+    gl_Position = u_worldViewProjectionMatrix * position;
+
+    // Transform normal to view space.
+    mat3 normalMatrix = mat3(u_inverseTransposeWorldViewMatrix[0].xyz, u_inverseTransposeWorldViewMatrix[1].xyz, u_inverseTransposeWorldViewMatrix[2].xyz);
+    v_normalVector = normalMatrix * normal;
+
+    // Apply light.
+    applyLight(position);
+    
+    // Texture transformation
+    v_texCoord = a_texCoord;
+    #if defined(TEXTURE_REPEAT)
+    v_texCoord *= u_textureRepeat;
+    #endif
+    #if defined(TEXTURE_OFFSET)
+    v_texCoord += u_textureOffset;
+    #endif
+}

+ 0 - 61
gameplay/res/shaders/textured.vsh

@@ -1,61 +0,0 @@
-// Uniforms
-uniform mat4 u_worldViewProjectionMatrix;           // Matrix to transform a position to clip space
-uniform mat4 u_inverseTransposeWorldViewMatrix;     // Matrix to transform a normal to view space
-#if defined(TEXTURE_REPEAT)
-uniform vec2 u_textureRepeat;
-#endif
-#if defined(TEXTURE_OFFSET)
-uniform vec2 u_textureOffset;
-#endif
-
-// Inputs
-attribute vec4 a_position;                          // Vertex position                      (x, y, z, w)
-attribute vec3 a_normal;                            // Vertex normal                        (x, y, z)
-attribute vec2 a_texCoord;                          // Vertex texture coordinate            (u, v)
-
-// Outputs
-varying vec3 v_normalVector;                        // Output normal vector in view space   (x, y, z)
-varying vec2 v_texCoord;                            // Output texture coordinate            (u, v)
-
-// Lighting
-#include "lib/lighting.vsh"
-#if defined(POINT_LIGHT)
-#include "lib/lighting-point.vsh"
-#elif defined(SPOT_LIGHT)
-#include "lib/lighting-spot.vsh"
-#else
-#include "lib/lighting-directional.vsh"
-#endif
-
-// Attribute Accessors (getPosition(), getNormal(), etc.)
-#if defined(SKINNING)
-#include "lib/attributes-skinning.vsh"
-#else
-#include "lib/attributes.vsh" 
-#endif
-
-void main()
-{
-    // Get the position and normal
-    vec4 position = getPosition();
-    vec3 normal = getNormal();
-
-    // Transform position to clip space.
-    gl_Position = u_worldViewProjectionMatrix * position;
-
-    // Transform normal to view space.
-    mat3 normalMatrix = mat3(u_inverseTransposeWorldViewMatrix[0].xyz, u_inverseTransposeWorldViewMatrix[1].xyz, u_inverseTransposeWorldViewMatrix[2].xyz);
-    v_normalVector = normalMatrix * normal;
-
-    // Apply light.
-    applyLight(position);
-    
-    // Texture transformation
-    v_texCoord = a_texCoord;
-    #if defined(TEXTURE_REPEAT)
-    v_texCoord *= u_textureRepeat;
-    #endif
-    #if defined(TEXTURE_OFFSET)
-    v_texCoord += u_textureOffset;
-    #endif
-}

+ 1 - 1
gameplay/src/Effect.cpp

@@ -180,13 +180,13 @@ void replaceIncludes(const char* filepath, const char* source, std::string& out)
             if (includedSource == NULL)
             {
                 GP_ERROR("Compile failed for shader '%s' invalid filepath.", filepathStr.c_str());
-                SAFE_DELETE_ARRAY(includedSource);
                 return;
             }
             else
             {
                 // Valid file so lets attempt to see if we need to append anything to it too (recurse...)
                 replaceIncludes(directoryPath.c_str(), includedSource, out);
+                SAFE_DELETE_ARRAY(includedSource);
             }
         }
         else