Lighting Functions - sinisterchipmunk/jax GitHub Wiki
Import: //= require "shaders/functions/lights"
shared uniform bool LIGHT_ENABLED
Defines a uniform boolean which is true when the light is enabled, false otherwise.
shared uniform int LIGHT_TYPE
This is an integer value equal to one of the following JavaScript-level constants: Jax.POINT_LIGHT; Jax.DIRECTIONAL_LIGHT; Jax.SPOT_LIGHT
shared uniform vec3 LIGHT_POSITION
The position of this light, in world space.
shared uniform vec3 LIGHT_DIRECTION
The normalized direction this light is pointing, in world space.
shared uniform vec4 LIGHT_AMBIENT, LIGHT_DIFFUSE, LIGHT_SPECULAR
The ambient, diffuse and specular components of the light.
shared uniform float LIGHT_ATTENUATION_CONSTANT, LIGHT_ATTENUATION_LINEAR,
LIGHT_ATTENUATION_QUADRATIC
The constant, linear and quadratic attenuation components of the light.
shared uniform float LIGHT_SPOT_EXPONENT, LIGHT_SPOT_COS_CUTOFF
The spot exponent and cosine of the spot angle cutoff.
float calcAttenuation(in vec3 ecPosition3, out vec3 lightDirection)
Calculates the attenuation factor for this light, based on the eye-coordinate position of the vertex (ecPosition3
). The out vector lightDirection
stores the calculated direction from the light's position to the vertex position, in eye space.
void DirectionalLight(in vec3 normal, inout vec4 ambient,
inout vec4 diffuse, inout vec4 specular)
Calculates lighting effects for directional light based on the specified vertex normal normal
. Stores ambient, diffuse and specular color components in their respective inout vectors. The color components of the light will be added to the color vectors.
Attenuation factor is never calculated for directional light, since by definition its attenuation factor must be constant because its relative position is infinite.
void PointLightWithAttenuation(in vec3 ecPosition3, in vec3 normal,
inout vec4 ambient, inout vec4 diffuse,
inout vec4 specular)
Calculates lighting effects for omnidirectional light based on the position of the vertex in eye coordinates (ecPosition3
) and its normal. Stores ambient, diffuse and specular color components in their respective inout vectors. The color components of the light will be added to the color vectors.
This function should be used when LIGHT_ATTENUATION_CONSTANT is not equal to 1, or if the other attenuation factors are nonzero.
void PointLightWithoutAttenuation(in vec3 ecPosition3, in vec3 normal,
inout vec4 ambient, inout vec4 diffuse,
inout vec4 specular)
Calculates lighting effects for omnidirectional light based on the position of the vertex in eye coordinates (ecPosition3
) and its normal. Stores ambient, diffuse and specular color components in their respective inout vectors. The color components of the light will be added to the color vectors.
For better performance, this function should be used when LIGHT_ATTENUATION_CONSTANT is equal to 1 and the other attenuation factors are equal to 0. (Using the PointLightWithAttenuation
function will produce the same result under these conditions, but will be slower.)
void SpotLight(in vec3 ecPosition3, in vec3 normal, inout vec4 ambient,
inout vec4 diffuse, inout vec4 specular)
Calculates lighting effects for a spot light based on the position of the vertex in eye coordinates (ecPosition3
) and its normal. Stores ambient, diffuse and specular components in their respective inout vectors. The color components of the light will be added to the color vectors.
Attenuation is always calculated for spot lights.