2
0
Эх сурвалжийг харах

Fixed shader library for bumped shaders.

seanpaultaylor 13 жил өмнө
parent
commit
eb9ff34ad4

+ 4 - 1
gameplay/res/shaders/bumped.fsh

@@ -1,3 +1,5 @@
+#define BUMPED
+
 #ifdef OPENGL_ES
 precision highp float;
 #endif
@@ -14,6 +16,7 @@ uniform float u_modulateAlpha;              // Modulation alpha
 #endif
 
 // Inputs
+varying vec3 v_normalVector;                // Normal vector in view space.
 varying vec2 v_texCoord;                    // Texture Coordinate.
 
 // Lighting
@@ -29,7 +32,7 @@ varying vec2 v_texCoord;                    // Texture Coordinate.
 void main()
 {
     // Fetch diffuse color from texture.
-    _baseColor = texture2D(u_diffuseTexture, v_texCoord);
+    _baseColor = texture2D(u_textureDiffuse, v_texCoord);
 
     // Light the pixel
     gl_FragColor.a = _baseColor.a;

+ 3 - 1
gameplay/res/shaders/bumped.vsh

@@ -1,3 +1,5 @@
+#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
@@ -16,6 +18,7 @@ attribute vec3 a_tangent;                           // Vertex Tangent
 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
@@ -29,7 +32,6 @@ varying vec2 v_texCoord;                            // Output Texture Coordinate
 #endif
 
 // Attribute Accessors (getPosition(), getNormal(), etc.)
-#define BUMPED
 #if defined(SKINNING)
 #include "lib/attributes-skinning.vsh"
 #else

+ 1 - 1
gameplay/res/shaders/lib/lighting-directional.vsh

@@ -11,7 +11,7 @@ void applyLight(mat3 tangentSpaceTransformMatrix)
     // Compute the camera direction for specular lighting
     #if defined(SPECULAR)
     
-    vec4 positionWorldSpace = u_worldViewMatrix * position;
+    vec4 positionWorldSpace = u_worldViewMatrix * a_position;
     v_cameraDirection = u_cameraPosition - positionWorldSpace.xyz;
     
     #endif

+ 2 - 2
gameplay/res/shaders/lib/lighting-point.fsh

@@ -29,10 +29,10 @@ vec3 getLitPixel()
 {
     // Normalize the vectors.
     vec3 normalVector = normalize(v_normalVector);    
-    vec3 vertexToPointLightDirection = normalize(v_vertexToPointLightDirection.xyz);
+    vec3 vertexToPointLightDirection = normalize(v_vertexToPointLightDirection);
     
     // Fetch point light attenuation.
-    float pointLightAttenuation = v_vertexToPointLightDirection.w;
+    float pointLightAttenuation = v_pointLightAttenuation;
     
     #if defined (SPECULAR)
     

+ 3 - 7
gameplay/res/shaders/lib/lighting-point.vsh

@@ -1,10 +1,10 @@
-#if defined(BUMPED)
-
 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)
 {
     vec4 positionWorldViewSpace = u_worldViewMatrix * a_position;
@@ -31,10 +31,6 @@ void applyLight(mat3 tangentSpaceTransformMatrix)
 
 #else
 
-uniform vec3 u_pointLightPosition;                  // Position
-uniform float u_pointLightRange;                    // Inverse of light range.
-varying vec4 v_vertexToPointLightDirection;         // Light direction w.r.t current vertex.
-
 void applyLight(vec4 position)
 {
     // World space position.
@@ -47,7 +43,7 @@ void applyLight(vec4 position)
     vertexToPointLightDirection.xyz = lightDirection;
    
     // Attenuation
-    vertexToPointLightDirection.w = 1.0 - dot(lightDirection * u_pointLightRangeInverse, lightDirection * u_pointLightRangeInverse);
+    v_pointLightAttenuation = 1.0 - dot(lightDirection * u_pointLightRangeInverse, lightDirection * u_pointLightRangeInverse);
 
     // Output light direction.
     v_vertexToPointLightDirection =  vertexToPointLightDirection;

+ 1 - 0
gameplay/res/shaders/lib/lighting.fsh

@@ -10,6 +10,7 @@ vec3 _diffuseColor;                             // Diffuse Color.
 #if defined(SPECULAR)
 
 vec3 _specularColor;    						// Specular color.
+
 uniform float u_specularExponent;				// Specular exponent.
 varying vec3 v_cameraDirection;                 // Camera direction.
 

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

@@ -1,7 +1,5 @@
 #define LIGHTING
 
-uniform vec3 u_lightDirection;					// Light direction.
-
 #if defined(SPECULAR)
 
 uniform mat4 u_worldViewMatrix;                 // Matrix to tranform a position to view space.