|
|
@@ -69,11 +69,11 @@ vec3 getFragPosVSpace()
|
|
|
discard;
|
|
|
}
|
|
|
|
|
|
- vec3 _fragPosVspace_;
|
|
|
- vec3 _vposn_ = normalize(vPosition);
|
|
|
- _fragPosVspace_.z = -planes.y / (planes.x + _depth_);
|
|
|
- _fragPosVspace_.xy = _vposn_.xy * (_fragPosVspace_.z / _vposn_.z);
|
|
|
- return _fragPosVspace_;
|
|
|
+ vec3 fragPosVspace;
|
|
|
+ vec3 vposn = normalize(vPosition);
|
|
|
+ fragPosVspace.z = -planes.y / (planes.x + _depth_);
|
|
|
+ fragPosVspace.xy = vposn.xy * (fragPosVspace.z / vposn.z);
|
|
|
+ return fragPosVspace;
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -81,10 +81,10 @@ vec3 getFragPosVSpace()
|
|
|
// getAttenuation =
|
|
|
//======================================================================================================================
|
|
|
/// @return The attenuation factor given the distance from the frag to the light source
|
|
|
-float getAttenuation(in float _fragLightDist_)
|
|
|
+float getAttenuation(in float fragLightDist)
|
|
|
{
|
|
|
- return clamp(1.0 - sqrt(_fragLightDist_) / lightRadius, 0.0, 1.0);
|
|
|
- //return 1.0 - _fragLightDist_ * _inv_light_radius;
|
|
|
+ return clamp(1.0 - sqrt(fragLightDist) / lightRadius, 0.0, 1.0);
|
|
|
+ //return 1.0 - fragLightDist * _inv_light_radius;
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -94,31 +94,31 @@ float getAttenuation(in float _fragLightDist_)
|
|
|
#if defined(SPOT_LIGHT_ENABLED) && defined(SHADOW_ENABLED)
|
|
|
|
|
|
/// @return The blurred shadow
|
|
|
-float pcfLow(in vec3 _shadowUv_)
|
|
|
+float pcfLow(in vec3 shadowUv)
|
|
|
{
|
|
|
- const float _mapScale_ = 1.0 / SHADOWMAP_SIZE;
|
|
|
- const int _kernelSize_ = 8;
|
|
|
- const vec2 _kernel_[_kernelSize_] = vec2[]
|
|
|
+ const float MAP_SCALE = 1.0 / SHADOWMAP_SIZE;
|
|
|
+ const int KERNEL_SIZE = 8;
|
|
|
+ const vec2 KERNEL[KERNEL_SIZE] = vec2[]
|
|
|
(
|
|
|
- vec2(_mapScale_, _mapScale_),
|
|
|
- vec2(_mapScale_, -_mapScale_),
|
|
|
- vec2(-_mapScale_, _mapScale_),
|
|
|
- vec2(-_mapScale_, -_mapScale_),
|
|
|
- vec2(0.0, _mapScale_),
|
|
|
- vec2(0.0, -_mapScale_),
|
|
|
- vec2(_mapScale_, 0.0),
|
|
|
- vec2(-_mapScale_, 0.0)
|
|
|
+ vec2(MAP_SCALE, MAP_SCALE),
|
|
|
+ vec2(MAP_SCALE, -MAP_SCALE),
|
|
|
+ vec2(-MAP_SCALE, MAP_SCALE),
|
|
|
+ vec2(-MAP_SCALE, -MAP_SCALE),
|
|
|
+ vec2(0.0, MAP_SCALE),
|
|
|
+ vec2(0.0, -MAP_SCALE),
|
|
|
+ vec2(MAP_SCALE, 0.0),
|
|
|
+ vec2(-MAP_SCALE, 0.0)
|
|
|
);
|
|
|
|
|
|
- float _shadowCol_ = shadow2D(shadowMap, _shadowUv_).r;
|
|
|
- for(int i=0; i<_kernelSize_; i++)
|
|
|
+ float shadowCol = shadow2D(shadowMap, shadowUv).r;
|
|
|
+ for(int i=0; i<KERNEL_SIZE; i++)
|
|
|
{
|
|
|
- vec3 _uvCoord_ = vec3(_shadowUv_.xy + _kernel_[i], _shadowUv_.z);
|
|
|
- _shadowCol_ += shadow2D(shadowMap, _uvCoord_).r;
|
|
|
+ vec3 uv = vec3(shadowUv.xy + KERNEL[i], shadowUv.z);
|
|
|
+ shadowCol += shadow2D(shadowMap, uv).r;
|
|
|
}
|
|
|
|
|
|
- _shadowCol_ *= (1.0 / 9.0);
|
|
|
- return _shadowCol_;
|
|
|
+ shadowCol *= (1.0 / 9.0);
|
|
|
+ return shadowCol;
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
@@ -128,48 +128,48 @@ float pcfLow(in vec3 _shadowUv_)
|
|
|
// doPhong =
|
|
|
//======================================================================================================================
|
|
|
/// Performs phong lighting using the MS FAIs and a few other things
|
|
|
-/// @param _fragPosVspace_ The fragment position in view space
|
|
|
-/// @param _fragLightDist_ Output needed for the attenuation calculation
|
|
|
+/// @param fragPosVspace The fragment position in view space
|
|
|
+/// @param fragLightDist Output needed for the attenuation calculation
|
|
|
/// @return The final color
|
|
|
-vec3 doPhong(in vec3 _fragPosVspace_, out float _fragLightDist_)
|
|
|
+vec3 doPhong(in vec3 fragPosVspace, out float fragLightDist)
|
|
|
{
|
|
|
// get the vector from the frag to the light
|
|
|
- vec3 _frag2LightVec_ = lightPos - _fragPosVspace_;
|
|
|
+ vec3 frag2LightVec = lightPos - fragPosVspace;
|
|
|
|
|
|
- // Instead of using normalize(_frag2LightVec_) we brake the operation because we want _fragLightDist_ for the calc of
|
|
|
+ // Instead of using normalize(frag2LightVec) we brake the operation because we want fragLightDist for the calc of
|
|
|
// the attenuation
|
|
|
- _fragLightDist_ = dot(_frag2LightVec_, _frag2LightVec_);
|
|
|
- vec3 _lightDir_ = _frag2LightVec_ * inversesqrt(_fragLightDist_);
|
|
|
+ fragLightDist = dot(frag2LightVec, frag2LightVec);
|
|
|
+ vec3 lightDir = frag2LightVec * inversesqrt(fragLightDist);
|
|
|
|
|
|
// Read the normal
|
|
|
- vec3 _normal_ = unpackNormal(texture2D(msNormalFai, vTexCoords).rg);
|
|
|
+ vec3 normal = unpackNormal(texture2D(msNormalFai, vTexCoords).rg);
|
|
|
|
|
|
// Lambert term
|
|
|
- float _lambertTerm_ = dot(_normal_, _lightDir_);
|
|
|
+ float lambertTerm = dot(normal, lightDir);
|
|
|
|
|
|
- if(_lambertTerm_ < 0.0)
|
|
|
+ if(lambertTerm < 0.0)
|
|
|
{
|
|
|
discard;
|
|
|
}
|
|
|
- //_lambertTerm_ = max(0.0, _lambertTerm_);
|
|
|
+ //lambertTerm = max(0.0, lambertTerm);
|
|
|
|
|
|
// Diffuce
|
|
|
- vec3 _diffuse_ = texture2D(msDiffuseFai, vTexCoords).rgb;
|
|
|
- _diffuse_ *= lightDiffuseCol;
|
|
|
- vec3 _color_ = _diffuse_ * _lambertTerm_;
|
|
|
+ vec3 diffuse = texture2D(msDiffuseFai, vTexCoords).rgb;
|
|
|
+ diffuse *= lightDiffuseCol;
|
|
|
+ vec3 color = diffuse * lambertTerm;
|
|
|
|
|
|
// Specular
|
|
|
- vec4 _specularMix_ = texture2D(msSpecularFai, vTexCoords); // the MS specular FAI has the color and the shininess
|
|
|
- vec3 _specular_ = _specularMix_.xyz;
|
|
|
- float _shininess_ = _specularMix_.w;
|
|
|
-
|
|
|
- vec3 _eyeVec_ = normalize(-_fragPosVspace_);
|
|
|
- vec3 _h_ = normalize(_lightDir_ + _eyeVec_);
|
|
|
- float _specIntensity_ = pow(max(0.0, dot(_normal_, _h_)), _shininess_);
|
|
|
- _color_ += _specular_ * lightSpecularCol * (_specIntensity_ * _lambertTerm_);
|
|
|
+ vec4 specularMix = texture2D(msSpecularFai, vTexCoords); // the MS specular FAI has the color and the shininess
|
|
|
+ vec3 specular = specularMix.xyz;
|
|
|
+ float shininess = specularMix.w;
|
|
|
+
|
|
|
+ vec3 _eyeVec_ = normalize(-fragPosVspace);
|
|
|
+ vec3 h = normalize(lightDir + _eyeVec_);
|
|
|
+ float specIntensity = pow(max(0.0, dot(normal, h)), shininess);
|
|
|
+ color += specular * lightSpecularCol * (specIntensity * lambertTerm);
|
|
|
|
|
|
// end
|
|
|
- return _color_;
|
|
|
+ return color;
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -185,50 +185,50 @@ void main()
|
|
|
// Point light
|
|
|
//
|
|
|
#if defined(POINT_LIGHT_ENABLED)
|
|
|
- // The func doPhong calculates the frag to light distance (_fragLightDist_) and be cause we need that distance
|
|
|
+ // The func doPhong calculates the frag to light distance (fragLightDist) and be cause we need that distance
|
|
|
// latter for other calculations we export it
|
|
|
- float _fragLightDist_;
|
|
|
- vec3 _color_ = doPhong(fragPosVspace, _fragLightDist_);
|
|
|
- fColor = _color_ * getAttenuation(_fragLightDist_);
|
|
|
+ float fragLightDist;
|
|
|
+ vec3 color = doPhong(fragPosVspace, fragLightDist);
|
|
|
+ fColor = color * getAttenuation(fragLightDist);
|
|
|
|
|
|
//
|
|
|
// Spot light
|
|
|
//
|
|
|
#elif defined(SPOT_LIGHT_ENABLED)
|
|
|
- vec4 _vTexCoords2_ = texProjectionMat * vec4(fragPosVspace, 1.0);
|
|
|
- vec3 _vTexCoords3_ = _vTexCoords2_.xyz / _vTexCoords2_.w;
|
|
|
-
|
|
|
- if(_vTexCoords2_.w > 0.0 &&
|
|
|
- _vTexCoords3_.x > 0.0 &&
|
|
|
- _vTexCoords3_.x < 1.0 &&
|
|
|
- _vTexCoords3_.y > 0.0 &&
|
|
|
- _vTexCoords3_.y < 1.0 &&
|
|
|
- _vTexCoords2_.w < lightRadius)
|
|
|
+ vec4 vTexCoords2 = texProjectionMat * vec4(fragPosVspace, 1.0);
|
|
|
+ vec3 vTexCoords3 = vTexCoords2.xyz / vTexCoords2.w;
|
|
|
+
|
|
|
+ if(vTexCoords2.w > 0.0 &&
|
|
|
+ vTexCoords3.x > 0.0 &&
|
|
|
+ vTexCoords3.x < 1.0 &&
|
|
|
+ vTexCoords3.y > 0.0 &&
|
|
|
+ vTexCoords3.y < 1.0 &&
|
|
|
+ vTexCoords2.w < lightRadius)
|
|
|
{
|
|
|
// Get shadow
|
|
|
#if defined(SHADOW_ENABLED)
|
|
|
#if defined(PCF_ENABLED)
|
|
|
- float _shadowCol_ = pcfLow(_vTexCoords3_);
|
|
|
+ float shadowCol = pcfLow(vTexCoords3);
|
|
|
#else
|
|
|
- float _shadowCol_ = shadow2D(shadowMap, _vTexCoords3_).r;
|
|
|
+ float shadowCol = shadow2D(shadowMap, vTexCoords3).r;
|
|
|
#endif
|
|
|
|
|
|
- if(_shadowCol_ == 0.0)
|
|
|
+ if(shadowCol == 0.0)
|
|
|
{
|
|
|
discard;
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
- float _fragLightDist_;
|
|
|
- vec3 _color_ = doPhong(fragPosVspace, _fragLightDist_);
|
|
|
+ float fragLightDist;
|
|
|
+ vec3 color = doPhong(fragPosVspace, fragLightDist);
|
|
|
|
|
|
- vec3 _lightTexCol_ = texture2DProj(lightTex, _vTexCoords2_.xyz).rgb;
|
|
|
- float _att_ = getAttenuation(_fragLightDist_);
|
|
|
+ vec3 lightTexCol = texture2DProj(lightTex, vTexCoords2.xyz).rgb;
|
|
|
+ float att = getAttenuation(fragLightDist);
|
|
|
|
|
|
#if defined(SHADOW_ENABLED)
|
|
|
- fColor = _lightTexCol_ * _color_ * (_shadowCol_ * _att_);
|
|
|
+ fColor = lightTexCol * color * (shadowCol * att);
|
|
|
#else
|
|
|
- fColor = _lightTexCol_ * _color_ * _att_;
|
|
|
+ fColor = lightTexCol * color * att;
|
|
|
#endif
|
|
|
}
|
|
|
else
|