|
|
@@ -1,3 +1,4 @@
|
|
|
+//
|
|
|
#pragma anki vertShaderBegins
|
|
|
|
|
|
#pragma anki attribute viewVector 1
|
|
|
@@ -36,9 +37,9 @@ uniform mat4 texProjectionMat;
|
|
|
varying vec2 texCoords;
|
|
|
varying vec3 vpos; // for the calculation of frag pos in view space
|
|
|
|
|
|
-
|
|
|
-//======================================================================================================================
|
|
|
-// getFragPosVSpace =
|
|
|
+
|
|
|
+//======================================================================================================================
|
|
|
+// getFragPosVSpace =
|
|
|
//======================================================================================================================
|
|
|
|
|
|
/**
|
|
|
@@ -46,222 +47,224 @@ varying vec3 vpos; // for the calculation of frag pos in view space
|
|
|
*/
|
|
|
vec3 getFragPosVSpace()
|
|
|
{
|
|
|
- float _depth = texture2D( msDepthFai, texCoords ).r;
|
|
|
-
|
|
|
- if( _depth == 1.0 ) discard;
|
|
|
-
|
|
|
- vec3 _frag_pos_vspace;
|
|
|
- vec3 _vposn = normalize(vpos);
|
|
|
- _frag_pos_vspace.z = -planes.y/(planes.x+_depth);
|
|
|
- _frag_pos_vspace.xy = _vposn.xy/_vposn.z*_frag_pos_vspace.z;
|
|
|
- return _frag_pos_vspace;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-//======================================================================================================================
|
|
|
-// getAttenuation =
|
|
|
-//======================================================================================================================
|
|
|
+ float _depth = texture2D( msDepthFai, texCoords ).r;
|
|
|
+
|
|
|
+ if( _depth == 1.0 ) discard;
|
|
|
+
|
|
|
+ vec3 _frag_pos_vspace;
|
|
|
+ vec3 _vposn = normalize(vpos);
|
|
|
+ _frag_pos_vspace.z = -planes.y/(planes.x+_depth);
|
|
|
+ _frag_pos_vspace.xy = _vposn.xy/_vposn.z*_frag_pos_vspace.z;
|
|
|
+ return _frag_pos_vspace;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+//======================================================================================================================
|
|
|
+// getAttenuation =
|
|
|
+//======================================================================================================================
|
|
|
|
|
|
/**
|
|
|
* @return The attenuation factor fiven the distance from the frag to the light
|
|
|
* source
|
|
|
- */
|
|
|
-float getAttenuation( in float _frag_light_dist )
|
|
|
-{
|
|
|
- return clamp(1.0 - lightInvRadius * sqrt(_frag_light_dist), 0.0, 1.0);
|
|
|
- //return 1.0 - _frag_light_dist * _inv_light_radius;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-//======================================================================================================================
|
|
|
-// Pcf =
|
|
|
+ */
|
|
|
+float getAttenuation( in float _frag_light_dist )
|
|
|
+{
|
|
|
+ return clamp(1.0 - lightInvRadius * sqrt(_frag_light_dist), 0.0, 1.0);
|
|
|
+ //return 1.0 - _frag_light_dist * _inv_light_radius;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
//======================================================================================================================
|
|
|
-
|
|
|
+// Pcf =
|
|
|
+//======================================================================================================================
|
|
|
+
|
|
|
#if defined(SPOT_LIGHT_ENABLED) && defined( SHADOW_ENABLED )
|
|
|
|
|
|
/**
|
|
|
* @return The blurred shadow
|
|
|
*/
|
|
|
-float pcfOff( in vec3 _shadow_uv )
|
|
|
-{
|
|
|
- return shadow2D(shadowMap, _shadow_uv ).r;
|
|
|
+float pcfOff( in vec3 _shadow_uv )
|
|
|
+{
|
|
|
+ return shadow2D(shadowMap, _shadow_uv ).r;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+float pcfLow( in vec3 _shadow_uv )
|
|
|
+{
|
|
|
+ float _shadow_col = shadow2D(shadowMap, _shadow_uv ).r;
|
|
|
+ const float _map_scale = 1.0 / SHADOWMAP_SIZE;
|
|
|
+
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( _map_scale, _map_scale, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( _map_scale, -_map_scale, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( _map_scale, 0.0, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale, _map_scale, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale, -_map_scale, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale, 0.0, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( 0.0, _map_scale, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( 0.0, -_map_scale, 0.0)).r;
|
|
|
+ _shadow_col *= 1.0/9.0;
|
|
|
+
|
|
|
+ return _shadow_col;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+float pcfMedium( in vec3 _shadow_uv )
|
|
|
+{
|
|
|
+ float _shadow_col = shadow2D(shadowMap, _shadow_uv ).r;
|
|
|
+ float _map_scale = 1.0 / SHADOWMAP_SIZE;
|
|
|
+
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( _map_scale, _map_scale, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( _map_scale, -_map_scale, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( _map_scale, 0.0, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale, _map_scale, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale, -_map_scale, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale, 0.0, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( 0.0, _map_scale, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( 0.0, -_map_scale, 0.0)).r;
|
|
|
+
|
|
|
+ _map_scale *= 2.0;
|
|
|
+
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( _map_scale, _map_scale, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( _map_scale, -_map_scale, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( _map_scale, 0.0, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale, _map_scale, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale, -_map_scale, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale, 0.0, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( 0.0, _map_scale, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( 0.0, -_map_scale, 0.0)).r;
|
|
|
+
|
|
|
+ _shadow_col *= 0.058823529; // aka: _shadow_col /= 17.0;
|
|
|
+ return _shadow_col;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-float pcfLow( in vec3 _shadow_uv )
|
|
|
-{
|
|
|
- float _shadow_col = shadow2D(shadowMap, _shadow_uv ).r;
|
|
|
- const float _map_scale = 1.0 / SHADOWMAP_SIZE;
|
|
|
-
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( _map_scale, _map_scale, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( _map_scale, -_map_scale, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( _map_scale, 0.0, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale, _map_scale, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale, -_map_scale, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale, 0.0, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( 0.0, _map_scale, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( 0.0, -_map_scale, 0.0)).r;
|
|
|
- _shadow_col *= 1.0/9.0;
|
|
|
-
|
|
|
- return _shadow_col;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-float pcfMedium( in vec3 _shadow_uv )
|
|
|
-{
|
|
|
- float _shadow_col = shadow2D(shadowMap, _shadow_uv ).r;
|
|
|
- float _map_scale = 1.0 / SHADOWMAP_SIZE;
|
|
|
-
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( _map_scale, _map_scale, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( _map_scale, -_map_scale, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( _map_scale, 0.0, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale, _map_scale, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale, -_map_scale, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale, 0.0, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( 0.0, _map_scale, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( 0.0, -_map_scale, 0.0)).r;
|
|
|
-
|
|
|
- _map_scale *= 2.0;
|
|
|
-
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( _map_scale, _map_scale, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( _map_scale, -_map_scale, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( _map_scale, 0.0, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale, _map_scale, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale, -_map_scale, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale, 0.0, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( 0.0, _map_scale, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( 0.0, -_map_scale, 0.0)).r;
|
|
|
-
|
|
|
- _shadow_col *= 0.058823529; // aka: _shadow_col /= 17.0;
|
|
|
- return _shadow_col;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-float pcfHigh( in vec3 _shadow_uv )
|
|
|
-{
|
|
|
- float _shadow_col = shadow2D(shadowMap, _shadow_uv ).r;
|
|
|
- float _map_scale = 1.0 / SHADOWMAP_SIZE;
|
|
|
-
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( _map_scale, _map_scale, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( _map_scale, -_map_scale, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( _map_scale, 0.0, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale, _map_scale, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale, -_map_scale, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale, 0.0, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( 0.0, _map_scale, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( 0.0, -_map_scale, 0.0)).r;
|
|
|
-
|
|
|
-
|
|
|
- float _map_scale_2 = 2.0 * _map_scale;
|
|
|
-
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(_map_scale_2, _map_scale_2, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(_map_scale, _map_scale_2, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(0.0, _map_scale_2, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale, _map_scale_2, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale_2, _map_scale_2, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale_2, _map_scale, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale_2, 0.0, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale_2, -_map_scale, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale_2, -_map_scale_2, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale, -_map_scale_2, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(0.0, -_map_scale_2, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(_map_scale, -_map_scale_2, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(_map_scale_2, -_map_scale_2, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(_map_scale_2, -_map_scale, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(_map_scale_2, 0.0, 0.0)).r;
|
|
|
- _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(_map_scale_2, _map_scale, 0.0)).r;
|
|
|
-
|
|
|
- _shadow_col /= 25.0;
|
|
|
- return _shadow_col;
|
|
|
-}
|
|
|
-#endif
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-//======================================================================================================================
|
|
|
-// phong =
|
|
|
+
|
|
|
+
|
|
|
+float pcfHigh( in vec3 _shadow_uv )
|
|
|
+{
|
|
|
+ float _shadow_col = shadow2D(shadowMap, _shadow_uv ).r;
|
|
|
+ float _map_scale = 1.0 / SHADOWMAP_SIZE;
|
|
|
+
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( _map_scale, _map_scale, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( _map_scale, -_map_scale, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( _map_scale, 0.0, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale, _map_scale, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale, -_map_scale, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale, 0.0, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( 0.0, _map_scale, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3( 0.0, -_map_scale, 0.0)).r;
|
|
|
+
|
|
|
+
|
|
|
+ float _map_scale_2 = 2.0 * _map_scale;
|
|
|
+
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(_map_scale_2, _map_scale_2, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(_map_scale, _map_scale_2, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(0.0, _map_scale_2, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale, _map_scale_2, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale_2, _map_scale_2, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale_2, _map_scale, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale_2, 0.0, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale_2, -_map_scale, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale_2, -_map_scale_2, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(-_map_scale, -_map_scale_2, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(0.0, -_map_scale_2, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(_map_scale, -_map_scale_2, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(_map_scale_2, -_map_scale_2, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(_map_scale_2, -_map_scale, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(_map_scale_2, 0.0, 0.0)).r;
|
|
|
+ _shadow_col += shadow2D(shadowMap, _shadow_uv.xyz + vec3(_map_scale_2, _map_scale, 0.0)).r;
|
|
|
+
|
|
|
+ _shadow_col /= 25.0;
|
|
|
+ return _shadow_col;
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+//======================================================================================================================
|
|
|
+// phong =
|
|
|
//======================================================================================================================
|
|
|
vec3 phong( in vec3 _frag_pos_vspace, out float _frag_light_dist )
|
|
|
{
|
|
|
- // get the lambert term
|
|
|
- vec3 _lightPos_eyespace = lightPos;
|
|
|
- vec3 _light_frag_vec = _lightPos_eyespace - _frag_pos_vspace;
|
|
|
+ // get the lambert term
|
|
|
+ vec3 _lightPos_eyespace = lightPos;
|
|
|
+ vec3 _light_frag_vec = _lightPos_eyespace - _frag_pos_vspace;
|
|
|
|
|
|
/*
|
|
|
* Instead of using normalize(_frag_light_dist) we brake the operation because we want frag_light_dist for the calc of
|
|
|
* the attenuation
|
|
|
- */
|
|
|
- _frag_light_dist = dot( _light_frag_vec, _light_frag_vec );
|
|
|
- vec3 _light_dir = _light_frag_vec * inversesqrt(_frag_light_dist);
|
|
|
-
|
|
|
+ */
|
|
|
+ _frag_light_dist = dot( _light_frag_vec, _light_frag_vec );
|
|
|
+ vec3 _light_dir = _light_frag_vec * inversesqrt(_frag_light_dist);
|
|
|
+
|
|
|
// read the normal
|
|
|
//vec3 _normal = texture2D( msNormalFai, texCoords ).rgb;
|
|
|
- vec3 _normal = UnpackNormal( texture2D( msNormalFai, texCoords ).rg );
|
|
|
-
|
|
|
- // the lambert term
|
|
|
- float _lambert_term = dot( _normal, _light_dir );
|
|
|
-
|
|
|
+ vec3 _normal = UnpackNormal( texture2D( msNormalFai, texCoords ).rg );
|
|
|
+
|
|
|
+ // the lambert term
|
|
|
+ float _lambert_term = dot( _normal, _light_dir );
|
|
|
+
|
|
|
if( _lambert_term < 0.0 ) discard;
|
|
|
- //_lambert_term = max( 0.0, _lambert_term );
|
|
|
-
|
|
|
- // diffuce lighting
|
|
|
- vec3 _diffuse = texture2D( msDiffuseFai, texCoords ).rgb;
|
|
|
- _diffuse = (_diffuse * lightDiffuseCol);
|
|
|
- vec3 _color = _diffuse * _lambert_term;
|
|
|
-
|
|
|
- // specular lighting
|
|
|
- vec4 _specular_mix = texture2D( msSpecularFai, texCoords );
|
|
|
+ //_lambert_term = max( 0.0, _lambert_term );
|
|
|
+
|
|
|
+ // diffuce lighting
|
|
|
+ vec3 _diffuse = texture2D( msDiffuseFai, texCoords ).rgb;
|
|
|
+ _diffuse = (_diffuse * lightDiffuseCol);
|
|
|
+ vec3 _color = _diffuse * _lambert_term;
|
|
|
+
|
|
|
+ // specular lighting
|
|
|
+ vec4 _specular_mix = texture2D( msSpecularFai, texCoords );
|
|
|
vec3 _specular = _specular_mix.xyz;
|
|
|
float _shininess = _specular_mix.w;
|
|
|
-
|
|
|
- vec3 _eye_vec = normalize( -_frag_pos_vspace );
|
|
|
- vec3 _h = normalize( _light_dir + _eye_vec );
|
|
|
- float _spec_intensity = pow(max(0.0, dot(_normal, _h)), _shininess);
|
|
|
+
|
|
|
+ vec3 _eye_vec = normalize( -_frag_pos_vspace );
|
|
|
+ vec3 _h = normalize( _light_dir + _eye_vec );
|
|
|
+ float _spec_intensity = pow(max(0.0, dot(_normal, _h)), _shininess);
|
|
|
_color += _specular * lightSpecularCol * (_spec_intensity * _lambert_term);
|
|
|
|
|
|
return _color;
|
|
|
}
|
|
|
|
|
|
-uniform sampler2D tex;
|
|
|
+uniform sampler2D tex;
|
|
|
|
|
|
-
|
|
|
-//======================================================================================================================
|
|
|
-// main =
|
|
|
-//======================================================================================================================
|
|
|
-void main()
|
|
|
+
|
|
|
+//======================================================================================================================
|
|
|
+// main =
|
|
|
+//======================================================================================================================
|
|
|
+void main()
|
|
|
{
|
|
|
- // get frag pos in view space
|
|
|
- vec3 _frag_pos_vspace = getFragPosVSpace();
|
|
|
+ // get frag pos in view space
|
|
|
+ vec3 _frag_pos_vspace = getFragPosVSpace();
|
|
|
|
|
|
//
|
|
|
// Point light
|
|
|
- //
|
|
|
+ //
|
|
|
#if defined(POINT_LIGHT_ENABLED)
|
|
|
// The func phong calculates the frag to light distance (_frag_light_dist) and be cause we need that distance
|
|
|
// latter for other calculations we export it
|
|
|
float _frag_light_dist;
|
|
|
- vec3 _color = phong( _frag_pos_vspace, _frag_light_dist );
|
|
|
+ vec3 _color = phong( _frag_pos_vspace, _frag_light_dist );
|
|
|
gl_FragData[0] = vec4( _color * getAttenuation(_frag_light_dist), 1.0 );
|
|
|
|
|
|
- //gl_FragData[0] = gl_FragData[0] - gl_FragData[0] + texture2D( msNormalFai, texCoords );
|
|
|
+ //gl_FragData[0] = gl_FragData[0] - gl_FragData[0] + texture2D( msNormalFai, texCoords );
|
|
|
|
|
|
|
|
|
//
|
|
|
// Spot light
|
|
|
- //
|
|
|
- #elif defined(SPOT_LIGHT_ENABLED)
|
|
|
- vec4 _tex_coord2 = texProjectionMat * vec4(_frag_pos_vspace, 1.0);
|
|
|
+ //
|
|
|
+ #elif defined(SPOT_LIGHT_ENABLED)
|
|
|
+ vec4 _tex_coord2 = texProjectionMat * vec4(_frag_pos_vspace, 1.0);
|
|
|
vec3 _texCoords3 = _tex_coord2.xyz / _tex_coord2.w;
|
|
|
-
|
|
|
- if
|
|
|
- (
|
|
|
- _tex_coord2.w > 0.0 &&
|
|
|
- _texCoords3.x > 0.0 &&
|
|
|
- _texCoords3.x < 1.0 &&
|
|
|
- _texCoords3.y > 0.0 &&
|
|
|
+
|
|
|
+ const float theshold = 0.01;
|
|
|
+
|
|
|
+ if
|
|
|
+ (
|
|
|
+ _tex_coord2.w > 0.0 &&
|
|
|
+ _texCoords3.x > 0.0 + theshold &&
|
|
|
+ _texCoords3.x < 1.0 - theshold &&
|
|
|
+ _texCoords3.y > 0.0 &&
|
|
|
_texCoords3.y < 1.0 &&
|
|
|
- _tex_coord2.w < 1.0/lightInvRadius
|
|
|
- )
|
|
|
+ _tex_coord2.w < 1.0/lightInvRadius
|
|
|
+ )
|
|
|
{
|
|
|
#if defined( SHADOW_ENABLED )
|
|
|
#if defined( PCF_ENABLED )
|
|
|
@@ -276,18 +279,18 @@ void main()
|
|
|
|
|
|
float _frag_light_dist;
|
|
|
vec3 _color = phong( _frag_pos_vspace, _frag_light_dist );
|
|
|
-
|
|
|
- vec3 _texel = texture2DProj( lightTex, _tex_coord2.xyz ).rgb;
|
|
|
+
|
|
|
+ vec3 _texel = texture2DProj( lightTex, _tex_coord2.xyz ).rgb;
|
|
|
float _att = getAttenuation(_frag_light_dist);
|
|
|
|
|
|
#if defined( SHADOW_ENABLED )
|
|
|
gl_FragData[0] = vec4(_texel * _color * (_shadow_color * _att), 1.0);
|
|
|
#else
|
|
|
gl_FragData[0] = vec4( _color * _texel * _att, 1.0 );
|
|
|
- #endif
|
|
|
- }
|
|
|
+ #endif
|
|
|
+ }
|
|
|
else
|
|
|
- {
|
|
|
+ {
|
|
|
discard;
|
|
|
}
|
|
|
#endif // spot light
|
|
|
@@ -299,8 +302,8 @@ void main()
|
|
|
#endif*/
|
|
|
|
|
|
//gl_FragData[0] = gl_FragData[0] - gl_FragData[0] + vec4( 1, 0, 1, 1 );
|
|
|
- /*#if defined(SPOT_LIGHT_ENABLED)
|
|
|
+ /*#if defined(SPOT_LIGHT_ENABLED)
|
|
|
gl_FragData[0] = gl_FragData[0] - gl_FragData[0] + vec4( texture2D( msDepthFai, texCoords ).r );
|
|
|
//gl_FragData[0] = vec4( texture2D( msDepthFai, texCoords ).rg), 1.0 );
|
|
|
- #endif*/
|
|
|
-}
|
|
|
+ #endif*/
|
|
|
+}
|