|
|
@@ -2,13 +2,14 @@
|
|
|
|
|
|
void applyLight(mat3 tangentSpaceTransformMatrix)
|
|
|
{
|
|
|
- vec4 positionWorldViewSpace = u_worldViewMatrix * a_position;
|
|
|
+ //vec4 positionWorldSpace = u_worldMatrix * a_position;
|
|
|
+ vec4 positionWorldViewSpace = u_worldViewMatrix * a_position;
|
|
|
|
|
|
// Transform spot light direction to tangent space.
|
|
|
v_spotLightDirection = tangentSpaceTransformMatrix * u_spotLightDirection;
|
|
|
|
|
|
// Compute the light direction with light position and the vertex position.
|
|
|
- vec3 lightDirection = u_spotLightPosition - positionWorldViewSpace.xyz;
|
|
|
+ vec3 lightDirection = u_spotLightPosition - positionWorldViewSpace.xyz;
|
|
|
|
|
|
// Transform current light direction to tangent space.
|
|
|
lightDirection = tangentSpaceTransformMatrix * lightDirection;
|
|
|
@@ -22,7 +23,7 @@ void applyLight(mat3 tangentSpaceTransformMatrix)
|
|
|
#if defined(SPECULAR)
|
|
|
|
|
|
// Compute camera direction and transform it to tangent space.
|
|
|
- v_cameraDirection = tangentSpaceTransformMatrix * (u_cameraPosition - positionWorldViewSpace.xyz);
|
|
|
+ v_cameraDirection = tangentSpaceTransformMatrix * (u_cameraPosition - positionWorldViewSpace.xyz);
|
|
|
|
|
|
#endif
|
|
|
}
|
|
|
@@ -31,24 +32,21 @@ void applyLight(mat3 tangentSpaceTransformMatrix)
|
|
|
|
|
|
void applyLight(vec4 position)
|
|
|
{
|
|
|
- // World space position.
|
|
|
- vec4 positionWorldViewSpace = u_worldViewMatrix * position;
|
|
|
+ // World view space position.
|
|
|
+ vec4 positionWorldViewSpace = u_worldViewMatrix * position;
|
|
|
|
|
|
// Compute the light direction with light position and the vertex position.
|
|
|
- vec3 lightDirection = u_spotLightPosition - positionWorldViewSpace.xyz;
|
|
|
-
|
|
|
- // Attenuation
|
|
|
- v_spotLightAttenuation = 1.0 - dot(lightDirection * u_spotLightRangeInverse, lightDirection * u_spotLightRangeInverse);
|
|
|
-
|
|
|
- // Output light direction.
|
|
|
- v_vertexToSpotLightDirection = lightDirection;
|
|
|
-
|
|
|
- #if defined(SPECULAR)
|
|
|
+ v_vertexToSpotLightDirection = u_spotLightPosition - positionWorldViewSpace.xyz;
|
|
|
|
|
|
+ // Attenuation
|
|
|
+ v_spotLightAttenuation = 1.0 - dot(v_vertexToSpotLightDirection * u_spotLightRangeInverse, v_vertexToSpotLightDirection * u_spotLightRangeInverse);
|
|
|
+
|
|
|
// Compute camera direction and transform it to tangent space.
|
|
|
- v_cameraDirection = tangentSpaceTransformMatrix * (u_cameraPosition - positionWorldViewSpace.xyz);
|
|
|
-
|
|
|
- #endif
|
|
|
+ #if defined(SPECULAR)
|
|
|
+
|
|
|
+ v_cameraDirection = u_cameraPosition - positionWorldViewSpace.xyz;
|
|
|
+
|
|
|
+ #endif
|
|
|
}
|
|
|
|
|
|
#endif
|