Quellcode durchsuchen

Initial import, shaders

Panagiotis Christopoulos Charitos vor 16 Jahren
Ursprung
Commit
3a0c4de897
100 geänderte Dateien mit 3196 neuen und 0 gelöschten Zeilen
  1. 13 0
      shaders/bs_bp_volfog.frag
  2. 8 0
      shaders/bs_bp_volfog.shdr
  3. 4 0
      shaders/bs_bp_volfog.vert
  4. 4 0
      shaders/dbg.frag
  5. 3 0
      shaders/dbg.shdr
  6. 5 0
      shaders/dbg.vert
  7. 7 0
      shaders/dp.shdr
  8. 12 0
      shaders/dp_generic.frag
  9. 20 0
      shaders/dp_generic.vert
  10. 13 0
      shaders/dp_grass.shdr
  11. 25 0
      shaders/dp_hw_skinning.shdr
  12. 10 0
      shaders/final.frag
  13. 8 0
      shaders/final.shdr
  14. 26 0
      shaders/hw_skinning.glsl
  15. 9 0
      shaders/is_ambient_pass.frag
  16. 13 0
      shaders/is_ambient_pass.shdr
  17. 262 0
      shaders/is_lp_generic.frag
  18. 12 0
      shaders/is_lp_generic.vert
  19. 28 0
      shaders/is_lp_point.shdr
  20. 29 0
      shaders/is_lp_spot.shdr
  21. 30 0
      shaders/is_lp_spot_shad.shdr
  22. 11 0
      shaders/linear_depth.glsl
  23. 7 0
      shaders/ms_mp format: dnspgk
  24. 8 0
      shaders/ms_mp_********.shdr
  25. 9 0
      shaders/ms_mp_d*******.shdr
  26. 11 0
      shaders/ms_mp_d****g***.shdr
  27. 10 0
      shaders/ms_mp_dn******.shdr
  28. 15 0
      shaders/ms_mp_dn***e**.shdr
  29. 11 0
      shaders/ms_mp_dn**g***.shdr
  30. 11 0
      shaders/ms_mp_dn*p****.shdr
  31. 10 0
      shaders/ms_mp_dns*****.shdr
  32. 21 0
      shaders/ms_mp_dnsk.shdr
  33. 15 0
      shaders/ms_mp_dnsp****.shdr
  34. 14 0
      shaders/ms_mp_dnspg***.shdr
  35. 157 0
      shaders/ms_mp_generic.frag
  36. 100 0
      shaders/ms_mp_generic.vert
  37. 36 0
      shaders/ms_mp_skybox.frag
  38. 14 0
      shaders/ms_mp_skybox.shdr
  39. 8 0
      shaders/ms_mp_skybox.vert
  40. 50 0
      shaders/old/dfrd_post.frag
  41. 16 0
      shaders/old/dfrd_post.shdr
  42. 10 0
      shaders/old/dfrd_post.vert
  43. 18 0
      shaders/old/glass.frag
  44. 3 0
      shaders/old/glass.shader
  45. 13 0
      shaders/old/glass.vert
  46. 10 0
      shaders/old/grass.frag
  47. 2 0
      shaders/old/grass.shdr
  48. 7 0
      shaders/old/grass.vert
  49. 10 0
      shaders/old/lp_generic(with distance falloff).vert
  50. 57 0
      shaders/old/ms_mp_generic.vert
  51. 35 0
      shaders/old/ms_mp_skybox.frag
  52. 7 0
      shaders/old/multitxtr.frag
  53. 6 0
      shaders/old/multitxtr.vert
  54. 58 0
      shaders/old/norm3l.frag
  55. 37 0
      shaders/old/norm3l.vert
  56. 24 0
      shaders/old/normal_mapping.frag
  57. 27 0
      shaders/old/normal_mapping.vert
  58. 42 0
      shaders/old/parallax.frag
  59. 2 0
      shaders/old/parallax.shdr
  60. 53 0
      shaders/old/parallax.vert
  61. 75 0
      shaders/old/spec3l.frag
  62. 9 0
      shaders/old/spec3l.vert
  63. 71 0
      shaders/old/specular.frag
  64. 9 0
      shaders/old/specular.vert
  65. 79 0
      shaders/old/specular3lights.frag
  66. 10 0
      shaders/old/specular3lights.vert
  67. 21 0
      shaders/old/test1.frag
  68. 15 0
      shaders/old/test1.shdr
  69. 12 0
      shaders/old/test1.vert
  70. 45 0
      shaders/old/test_normalmaping.frag
  71. 12 0
      shaders/old/test_normalmaping.shdr
  72. 41 0
      shaders/old/test_normalmaping.vert
  73. 64 0
      shaders/old/test_shadowmap.frag
  74. 5 0
      shaders/old/test_shadowmap.shader
  75. 13 0
      shaders/old/test_shadowmap.vert
  76. 23 0
      shaders/old/toon.frag
  77. 13 0
      shaders/old/toon.vert
  78. 15 0
      shaders/old/toon2.frag
  79. 30 0
      shaders/old/toon3.frag
  80. 74 0
      shaders/old/txtr_project.frag
  81. 14 0
      shaders/old/txtr_project.shdr
  82. 33 0
      shaders/old/txtr_project.vert
  83. 34 0
      shaders/pack.glsl
  84. 7 0
      shaders/paraboloid.frag
  85. 22 0
      shaders/paraboloid.vert
  86. 245 0
      shaders/photoshop_filters.glsl
  87. 207 0
      shaders/pps.frag
  88. 12 0
      shaders/pps.shdr
  89. 13 0
      shaders/pps_bloom_final.shdr
  90. 72 0
      shaders/pps_bloom_generic.frag
  91. 13 0
      shaders/pps_bloom_vblur.shdr
  92. 48 0
      shaders/pps_lscatt.frag
  93. 18 0
      shaders/pps_lscatt.shdr
  94. 238 0
      shaders/pps_ssao.frag
  95. 21 0
      shaders/pps_ssao.shdr
  96. 18 0
      shaders/simple.vert
  97. 27 0
      shaders/simple_texturing.frag
  98. 2 0
      shaders/simple_texturing.shdr
  99. 9 0
      shaders/simple_texturing.vert
  100. 11 0
      shaders/txt.frag

+ 13 - 0
shaders/bs_bp_volfog.frag

@@ -0,0 +1,13 @@
+//
+uniform sampler2D ms_depth_fai;
+
+void main()
+{
+	vec2 tex_coords_ = gl_FragCoord.xy*vec2( 1.0/R_W, 1.0/R_H );
+	
+	float depth_exp_ = texture2D( ms_depth_fai, tex_coords_ ).r;
+	if( depth_exp_ == 1 ) discard;
+	
+	float depth_ = LinearizeDepth( depth_exp_, 0.1, 10.0 );
+	gl_FragColor = vec4( depth_ );
+}

+ 8 - 0
shaders/bs_bp_volfog.shdr

@@ -0,0 +1,8 @@
+//
+VERTEX_SHADER "shaders/bs_bp_volfog.vert"
+FRAGMENT_SHADER "shaders/bs_bp_volfog.frag"
+
+FRAGMENT_SHADER_INCLUDES
+{
+	"shaders/linear_depth.glsl"
+}

+ 4 - 0
shaders/bs_bp_volfog.vert

@@ -0,0 +1,4 @@
+void main()
+{
+	gl_Position = ftransform();
+}

+ 4 - 0
shaders/dbg.frag

@@ -0,0 +1,4 @@
+void main()
+{
+	gl_FragData[0].rgb = gl_Color.rgb;
+}

+ 3 - 0
shaders/dbg.shdr

@@ -0,0 +1,3 @@
+VERTEX_SHADER "shaders/dbg.vert"
+FRAGMENT_SHADER "shaders/dbg.frag"
+

+ 5 - 0
shaders/dbg.vert

@@ -0,0 +1,5 @@
+void main()
+{
+	gl_Position = ftransform();
+	gl_FrontColor = gl_Color;
+}

+ 7 - 0
shaders/dp.shdr

@@ -0,0 +1,7 @@
+VERTEX_SHADER "shaders/dp_generic.vert"
+FRAGMENT_SHADER "shaders/dp_generic.frag"
+
+PREPROCESSOR_DEFINES
+{
+}
+

+ 12 - 0
shaders/dp_generic.frag

@@ -0,0 +1,12 @@
+uniform sampler2D diffuse_map;
+varying vec2 txtr_coords;
+
+
+
+void main()
+{
+	#if defined( _GRASS_LIKE_ )
+		vec4 _diff = texture2D( diffuse_map, txtr_coords );
+		if( _diff.a == 0.0 ) discard;
+	#endif
+}

+ 20 - 0
shaders/dp_generic.vert

@@ -0,0 +1,20 @@
+varying vec2 txtr_coords;
+
+void main()
+{
+	#if defined( _GRASS_LIKE_ )
+		txtr_coords = gl_MultiTexCoord0.xy;
+	#endif
+
+	#if defined( _HW_SKINNING_ )
+		mat3 _rot;
+		vec3 _tsl;
+
+		HWSkinning( _rot, _tsl );
+		
+		vec3 pos_lspace = ( _rot * gl_Vertex.xyz) + _tsl;
+		gl_Position =  gl_ModelViewProjectionMatrix * vec4(pos_lspace, 1.0);
+	#else
+	  gl_Position = ftransform();
+	#endif
+}

+ 13 - 0
shaders/dp_grass.shdr

@@ -0,0 +1,13 @@
+VERTEX_SHADER "shaders/dp_generic.vert"
+FRAGMENT_SHADER "shaders/dp_generic.frag"
+
+PREPROCESSOR_DEFINES
+{
+	"#define _GRASS_LIKE_"
+}
+
+UNIFORMS
+{
+	diffuse_map = 0
+}
+

+ 25 - 0
shaders/dp_hw_skinning.shdr

@@ -0,0 +1,25 @@
+VERTEX_SHADER "shaders/dp_generic.vert"
+FRAGMENT_SHADER "shaders/dp_generic.frag"
+
+PREPROCESSOR_DEFINES
+{
+	"#define _HW_SKINNING_"
+}
+
+VERTEX_SHADER_INCLUDES
+{
+	"shaders/hw_skinning.glsl"
+}
+
+UNIFORMS
+{
+	skinning_rotations = 0
+	skinning_translations = 1
+}
+
+ATTRIBUTES
+{
+	vert_weight_bones_num = 0
+	vert_weight_bone_ids = 1
+	vert_weight_weights = 2
+}

+ 10 - 0
shaders/final.frag

@@ -0,0 +1,10 @@
+uniform sampler2D raster_image;
+varying vec2 tex_coords;
+
+void main()
+{
+	//if( gl_FragCoord.x > 0.5 ) discard;
+
+	gl_FragColor.rgb = texture2D( raster_image, tex_coords ).rgb;
+	//gl_FragColor.rgb = gl_FragCoord.xyz;
+}

+ 8 - 0
shaders/final.shdr

@@ -0,0 +1,8 @@
+VERTEX_SHADER "shaders/simple.vert"
+FRAGMENT_SHADER "shaders/final.frag"
+
+UNIFORMS
+{
+	raster_image = 0
+}
+

+ 26 - 0
shaders/hw_skinning.glsl

@@ -0,0 +1,26 @@
+
+// hardware skinning data
+attribute float vert_weight_bones_num;
+attribute vec4  vert_weight_bone_ids;
+attribute vec4  vert_weight_weights;
+
+const int MAX_BONES_PER_MESH = 60;
+
+uniform mat3 skinning_rotations[ MAX_BONES_PER_MESH ];
+uniform vec3 skinning_translations[ MAX_BONES_PER_MESH ];
+
+
+void HWSkinning( out mat3 _rot, out vec3 _tsl )
+{
+	_rot = mat3( 0.0 );
+	_tsl = vec3( 0.0 );
+
+	for( int i=0; i<int(vert_weight_bones_num); i++ )
+	{
+		int bone_id = int( vert_weight_bone_ids[i] );
+		float weight = vert_weight_weights[i];
+
+		_rot += skinning_rotations[bone_id] * weight;
+		_tsl += skinning_translations[bone_id] * weight;
+	}
+}

+ 9 - 0
shaders/is_ambient_pass.frag

@@ -0,0 +1,9 @@
+uniform sampler2D ms_diffuse_fai;
+uniform vec3 ambient_color;
+varying vec2 tex_coords;
+
+
+void main()
+{
+	gl_FragData[0].rgb = texture2D( ms_diffuse_fai, tex_coords ).rgb * ambient_color;
+}

+ 13 - 0
shaders/is_ambient_pass.shdr

@@ -0,0 +1,13 @@
+VERTEX_SHADER "shaders/simple.vert"
+FRAGMENT_SHADER "shaders/is_ambient_pass.frag"
+
+PREPROCESSOR_DEFINES
+{
+}
+
+UNIFORMS
+{
+	ambient_color = 0
+	ms_diffuse_fai = 1
+}
+

+ 262 - 0
shaders/is_lp_generic.frag

@@ -0,0 +1,262 @@
+uniform sampler2D ms_normal_fai, ms_diffuse_fai, ms_specular_fai, ms_depth_fai;
+uniform sampler2D light_tex;
+uniform sampler2DShadow shadow_map;
+uniform vec2 planes; // for the calculation of frag pos in view space
+
+varying vec2 tex_coords;
+varying vec3 vpos; // for the calculation of frag pos in view space
+
+
+/*
+=======================================================================================================================================
+FragPosVSpace                                                                                                                         =
+return frag pos in view space                                                                                                         =
+=======================================================================================================================================
+*/
+vec3 FragPosVSpace()
+{
+	float _depth = texture2D( ms_depth_fai, tex_coords ).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;
+}
+
+
+/*
+=======================================================================================================================================
+Attenuation                                                                                                                           =
+return the attenuation factor fiven the distance from the frag to the light source                                                    =
+=======================================================================================================================================
+*/
+float Attenuation( in float _frag_light_dist )
+{
+	float _inv_light_radius = gl_LightSource[0].position.w;
+	return clamp(1.0 - _inv_light_radius * sqrt(_frag_light_dist), 0.0, 1.0);
+	//return 1.0 - _frag_light_dist * _inv_light_radius;
+}
+
+
+/*
+=======================================================================================================================================
+PCF                                                                                                                                   =
+it returns a blured shadow                                                                                                            =
+=======================================================================================================================================
+*/
+#if defined(_SPOT_LIGHT_) && defined( _SHADOW_ )
+
+float PCF_Off( in vec3 _shadow_uv )
+{
+	return shadow2D(shadow_map, _shadow_uv ).r;
+}
+
+
+float PCF_Low( in vec3 _shadow_uv )
+{
+	float _shadow_col = shadow2D(shadow_map, _shadow_uv ).r;
+	const float _map_scale = 1.0 / SHADOWMAP_SIZE;
+
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3( _map_scale,  _map_scale, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3( _map_scale, -_map_scale, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3( _map_scale,         0.0, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(-_map_scale,  _map_scale, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(-_map_scale, -_map_scale, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(-_map_scale,         0.0, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(        0.0,  _map_scale, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(        0.0, -_map_scale, 0.0)).r;
+	_shadow_col *= 1.0/9.0;
+
+	return _shadow_col;
+}
+
+
+float PCF_Medium( in vec3 _shadow_uv )
+{
+	float _shadow_col = shadow2D(shadow_map, _shadow_uv ).r;
+	float _map_scale = 1.0 / SHADOWMAP_SIZE;
+
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3( _map_scale,  _map_scale, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3( _map_scale, -_map_scale, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3( _map_scale,         0.0, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(-_map_scale,  _map_scale, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(-_map_scale, -_map_scale, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(-_map_scale,         0.0, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(        0.0,  _map_scale, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(        0.0, -_map_scale, 0.0)).r;
+
+	_map_scale *= 2.0;
+
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3( _map_scale,  _map_scale, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3( _map_scale, -_map_scale, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3( _map_scale,         0.0, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(-_map_scale,  _map_scale, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(-_map_scale, -_map_scale, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(-_map_scale,         0.0, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(        0.0,  _map_scale, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(        0.0, -_map_scale, 0.0)).r;
+
+	_shadow_col *= 0.058823529; // aka: _shadow_col /= 17.0;
+	return _shadow_col;
+}
+
+
+float PCF_High( in vec3 _shadow_uv )
+{
+	float _shadow_col = shadow2D(shadow_map, _shadow_uv ).r;
+	float _map_scale = 1.0 / SHADOWMAP_SIZE;
+
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3( _map_scale,  _map_scale, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3( _map_scale, -_map_scale, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3( _map_scale,  	     0.0, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(-_map_scale,  _map_scale, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(-_map_scale, -_map_scale, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(-_map_scale,  	     0.0, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(        0.0,  _map_scale, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(        0.0, -_map_scale, 0.0)).r;
+
+
+	float _map_scale_2 = 2.0 * _map_scale;
+
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(_map_scale_2, _map_scale_2, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(_map_scale, _map_scale_2, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(0.0, _map_scale_2, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(-_map_scale, _map_scale_2, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(-_map_scale_2, _map_scale_2, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(-_map_scale_2, _map_scale, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(-_map_scale_2, 0.0, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(-_map_scale_2, -_map_scale, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(-_map_scale_2, -_map_scale_2, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(-_map_scale, -_map_scale_2, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(0.0, -_map_scale_2, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(_map_scale, -_map_scale_2, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(_map_scale_2, -_map_scale_2, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(_map_scale_2, -_map_scale, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _shadow_uv.xyz + vec3(_map_scale_2, 0.0, 0.0)).r;
+	_shadow_col += shadow2D(shadow_map, _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 _light_pos_eyespace = gl_LightSource[0].position.xyz;
+	vec3 _light_frag_vec = _light_pos_eyespace - _frag_pos_vspace;
+
+	_frag_light_dist = dot( _light_frag_vec, _light_frag_vec ); // instead of using normalize(_frag_light_dist) we brake the operation...
+	vec3 _light_dir = _light_frag_vec * inversesqrt(_frag_light_dist); // ...because we want frag_light_dist for the calc of the attenuation
+
+	// read the normal
+	//vec3 _normal = texture2D( ms_normal_fai, tex_coords ).rgb;
+	vec3 _normal = UnpackNormal( texture2D( ms_normal_fai, tex_coords ).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( ms_diffuse_fai, tex_coords ).rgb;
+	_diffuse = (_diffuse * gl_LightSource[0].diffuse.rgb);
+	vec3 _color = _diffuse * _lambert_term;
+
+	// specular lighting
+	vec4 _specular_mix = texture2D( ms_specular_fai, tex_coords );
+	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);
+	_color += _specular * vec3(gl_LightSource[0].specular) * (_spec_intensity * _lambert_term);
+
+	return _color;
+}
+
+
+
+/*
+=======================================================================================================================================
+main                                                                                                                                  =
+=======================================================================================================================================
+*/
+void main()
+{
+	// get frag pos in view space
+	vec3 _frag_pos_vspace = FragPosVSpace();
+
+	//===================================================================================================================================
+	// POINT LIGHT                                                                                                                      =
+	//===================================================================================================================================
+	#if defined(_POINT_LIGHT_)
+		// 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 );
+		gl_FragData[0] = vec4( _color * Attenuation(_frag_light_dist), 1.0 );
+
+	//===================================================================================================================================
+	// SPOT LIGHT                                                                                                                       =
+	//===================================================================================================================================
+	#elif defined(_SPOT_LIGHT_)
+		vec4 _tex_coord2 = gl_TextureMatrix[0] * vec4(_frag_pos_vspace, 1.0);
+		vec3 _tex_coords3 = _tex_coord2.xyz / _tex_coord2.w;
+
+		if
+		(
+			_tex_coord2.w > 0.0 &&
+			_tex_coords3.x > 0.0 &&
+			_tex_coords3.x < 1.0 &&
+			_tex_coords3.y > 0.0 &&
+			_tex_coords3.y < 1.0 &&
+			_tex_coord2.w < 1.0/gl_LightSource[0].position.w
+		)
+		{
+			#if defined( _SHADOW_ )
+				#if defined( _SHADOW_MAPPING_PCF_ )
+					float _shadow_color = PCF_Low( _tex_coords3 );
+				#else
+					float _shadow_color = PCF_Off( _tex_coords3 );
+				#endif
+
+				if( _shadow_color == 0.0 ) discard;
+			#endif // shadow
+
+			float _frag_light_dist;
+			vec3 _color = Phong( _frag_pos_vspace, _frag_light_dist );
+
+			vec3 _texel = texture2DProj( light_tex, _tex_coord2.xyz ).rgb;
+			float _att = Attenuation(_frag_light_dist);
+
+			#if defined( _SHADOW_ )
+				gl_FragData[0] = vec4(_texel * _color * (_shadow_color * _att), 1.0);
+			#else
+				gl_FragData[0] = vec4( _color * _texel * _att, 1.0 );
+			#endif
+			//gl_FragData[0] = vec4( 1.0, 0.0, 1.0, 1.0 );
+		}
+		else
+		{
+			discard;
+		}
+	#endif // spot light
+
+	/*#if defined(_SPOT_LIGHT_)
+	gl_FragData[0] = vec4( UnpackNormal(texture2D( ms_normal_fai, tex_coords ).rg), 1.0 );
+	//gl_FragData[0] = vec4( texture2D( ms_depth_fai, tex_coords ).rg), 1.0 );
+	#endif*/
+}

+ 12 - 0
shaders/is_lp_generic.vert

@@ -0,0 +1,12 @@
+attribute vec3 view_vector;
+varying vec2 tex_coords;
+varying vec3 vpos;
+
+void main()
+{
+	vpos = view_vector;
+	vec2 vert_pos = gl_Vertex.xy; // the vert coords are {1.0,1.0}, {0.0,1.0}, {0.0,0.0}, {1.0,0.0}
+	tex_coords = vert_pos;
+	vec2 vert_pos_ndc = vert_pos*2.0 - 1.0;
+	gl_Position = vec4( vert_pos_ndc, 0.0, 1.0 );
+}

+ 28 - 0
shaders/is_lp_point.shdr

@@ -0,0 +1,28 @@
+VERTEX_SHADER "shaders/is_lp_generic.vert"
+FRAGMENT_SHADER "shaders/is_lp_generic.frag"
+
+PREPROCESSOR_DEFINES
+{
+	"#define _POINT_LIGHT_"
+}
+
+FRAGMENT_SHADER_INCLUDES
+{
+	"shaders/pack.glsl"
+}
+
+UNIFORMS
+{
+	// put the uniform vars with this order ONLY (or prepere to make changes in the cpp)
+	ms_normal_fai = 0
+	ms_diffuse_fai = 1
+	ms_specular_fai = 2
+	ms_depth_fai = 3
+	planes = 4
+}
+
+ATTRIBUTES
+{
+	view_vector = 0
+}
+

+ 29 - 0
shaders/is_lp_spot.shdr

@@ -0,0 +1,29 @@
+VERTEX_SHADER "shaders/is_lp_generic.vert"
+FRAGMENT_SHADER "shaders/is_lp_generic.frag"
+
+PREPROCESSOR_DEFINES
+{
+	"#define _SPOT_LIGHT_"
+}
+
+FRAGMENT_SHADER_INCLUDES
+{
+	"shaders/pack.glsl"
+}
+
+UNIFORMS
+{
+	// put the uniform vars with this order ONLY (or prepere to make changes in the cpp)
+	ms_normal_fai = 0
+	ms_diffuse_fai = 1
+	ms_specular_fai = 2
+	ms_depth_fai = 3
+	planes = 4
+	light_tex = 5
+}
+
+ATTRIBUTES
+{
+	view_vector = 0
+}
+

+ 30 - 0
shaders/is_lp_spot_shad.shdr

@@ -0,0 +1,30 @@
+VERTEX_SHADER "shaders/is_lp_generic.vert"
+FRAGMENT_SHADER "shaders/is_lp_generic.frag"
+
+PREPROCESSOR_DEFINES
+{
+	"#define _SPOT_LIGHT_"
+	"#define _SHADOW_"
+}
+
+FRAGMENT_SHADER_INCLUDES
+{
+	"shaders/pack.glsl"
+}
+
+UNIFORMS
+{
+	// put the uniform vars with this order ONLY (or prepere to make changes in the cpp)
+	ms_normal_fai = 0
+	ms_diffuse_fai = 1
+	ms_specular_fai = 2
+	ms_depth_fai = 3
+	planes = 4
+	light_tex = 5
+	shadow_map = 6
+}
+
+ATTRIBUTES
+{
+	view_vector = 0
+}

+ 11 - 0
shaders/linear_depth.glsl

@@ -0,0 +1,11 @@
+// convert to linear depth
+
+float LinearizeDepth( in float depth_, in float znear_, in float zfar_ )
+{
+	return (2.0 * znear_) / (zfar_ + znear_ - depth_ * (zfar_ - znear_));
+}
+
+float ReadFromTexAndLinearizeDepth( in sampler2D depth_map_, in vec2 tex_coord_, in float znear_, in float zfar_ )
+{
+	return LinearizeDepth( texture2D( depth_map_, tex_coord_ ).r, znear_, zfar_ );
+}

+ 7 - 0
shaders/ms_mp format: dnspgk

@@ -0,0 +1,7 @@
+dnspgk aka
+
+diffuse mapping
+normal mapping
+specular mapping
+grass like
+hardware skinning

+ 8 - 0
shaders/ms_mp_********.shdr

@@ -0,0 +1,8 @@
+VERTEX_SHADER "shaders/ms_mp_generic.vert"
+FRAGMENT_SHADER "shaders/ms_mp_generic.frag"
+
+PREPROCESSOR_DEFINES
+{
+}
+
+

+ 9 - 0
shaders/ms_mp_d*******.shdr

@@ -0,0 +1,9 @@
+VERTEX_SHADER "shaders/ms_mp_generic.vert"
+FRAGMENT_SHADER "shaders/ms_mp_generic.frag"
+
+PREPROCESSOR_DEFINES
+{
+	"#define _HAS_DIFFUSE_MAP_"
+}
+
+

+ 11 - 0
shaders/ms_mp_d****g***.shdr

@@ -0,0 +1,11 @@
+VERTEX_SHADER "shaders/ms_mp_generic.vert"
+FRAGMENT_SHADER "shaders/ms_mp_generic.frag"
+
+PREPROCESSOR_DEFINES
+{
+	"#define _HAS_DIFFUSE_MAP_"
+	//"#define _HAS_NORMAL_MAP_"
+	"#define _GRASS_LIKE_"
+}
+
+

+ 10 - 0
shaders/ms_mp_dn******.shdr

@@ -0,0 +1,10 @@
+VERTEX_SHADER "shaders/ms_mp_generic.vert"
+FRAGMENT_SHADER "shaders/ms_mp_generic.frag"
+
+PREPROCESSOR_DEFINES
+{
+	"#define _HAS_DIFFUSE_MAP_"
+	"#define _HAS_NORMAL_MAP_"
+}
+
+

+ 15 - 0
shaders/ms_mp_dn***e**.shdr

@@ -0,0 +1,15 @@
+VERTEX_SHADER "shaders/ms_mp_generic.vert"
+FRAGMENT_SHADER "shaders/ms_mp_generic.frag"
+
+PREPROCESSOR_DEFINES
+{
+	"#define _HAS_DIFFUSE_MAP_"
+	"#define _HAS_NORMAL_MAP_"
+	"#define _ENVIRONMENT_MAPPING_"
+}
+
+FRAGMENT_SHADER_INCLUDES
+{
+	"shaders/pack.glsl"
+}
+

+ 11 - 0
shaders/ms_mp_dn**g***.shdr

@@ -0,0 +1,11 @@
+VERTEX_SHADER "shaders/ms_mp_generic.vert"
+FRAGMENT_SHADER "shaders/ms_mp_generic.frag"
+
+PREPROCESSOR_DEFINES
+{
+	"#define _HAS_DIFFUSE_MAP_"
+	"#define _HAS_NORMAL_MAP_"
+	"#define _GRASS_LIKE_"
+}
+
+

+ 11 - 0
shaders/ms_mp_dn*p****.shdr

@@ -0,0 +1,11 @@
+VERTEX_SHADER "shaders/ms_mp_generic.vert"
+FRAGMENT_SHADER "shaders/ms_mp_generic.frag"
+
+PREPROCESSOR_DEFINES
+{
+	"#define _HAS_DIFFUSE_MAP_"
+	"#define _HAS_NORMAL_MAP_"
+	"#define _PARALLAX_MAPPING_"
+}
+
+

+ 10 - 0
shaders/ms_mp_dns*****.shdr

@@ -0,0 +1,10 @@
+VERTEX_SHADER "shaders/ms_mp_generic.vert"
+FRAGMENT_SHADER "shaders/ms_mp_generic.frag"
+
+PREPROCESSOR_DEFINES
+{
+	"#define _HAS_DIFFUSE_MAP_"
+	"#define _HAS_NORMAL_MAP_"
+	"#define _HAS_SPECULAR_MAP_"
+}
+

+ 21 - 0
shaders/ms_mp_dnsk.shdr

@@ -0,0 +1,21 @@
+VERTEX_SHADER "shaders/ms_mp_generic.vert"
+FRAGMENT_SHADER "shaders/ms_mp_generic.frag"
+
+PREPROCESSOR_DEFINES
+{
+	"#define _HAS_DIFFUSE_MAP_"
+	"#define _HAS_NORMAL_MAP_"
+	"#define _HAS_SPECULAR_MAP_"
+	"#define _HARDWARE_SKINNING_"
+}
+
+FRAGMENT_SHADER_INCLUDES
+{
+	"shaders/pack.glsl"
+}
+
+VERTEX_SHADER_INCLUDES
+{
+	"shaders/hw_skinning.glsl"
+}
+

+ 15 - 0
shaders/ms_mp_dnsp****.shdr

@@ -0,0 +1,15 @@
+VERTEX_SHADER "shaders/ms_mp_generic.vert"
+FRAGMENT_SHADER "shaders/ms_mp_generic.frag"
+
+PREPROCESSOR_DEFINES
+{
+	"#define _HAS_DIFFUSE_MAP_"
+	"#define _HAS_NORMAL_MAP_"
+	"#define _HAS_SPECULAR_MAP_"
+	"#define _PARALLAX_MAPPING_"
+}
+
+UNIFORM_VARS
+{
+}
+

+ 14 - 0
shaders/ms_mp_dnspg***.shdr

@@ -0,0 +1,14 @@
+VERTEX_SHADER "shaders/ms_mp_generic.vert"
+FRAGMENT_SHADER "shaders/ms_mp_generic.frag"
+
+PREPROCESSOR_DEFINES
+{
+	"#define _HAS_DIFFUSE_MAP_"
+	"#define _HAS_NORMAL_MAP_"
+	"#define _HAS_HEIGHT_MAP_"
+}
+
+UNIFORM_VARS
+{
+}
+

+ 157 - 0
shaders/ms_mp_generic.frag

@@ -0,0 +1,157 @@
+/**
+Note: The process of calculating the diffuse color for the diffuse MSFAI is divided into two parts. The first happens before the
+normal calculation and the other just after it. In the first part we read the texture (or the gl_Color) and we set the _diff_color.
+In case of grass we discard. In the second part we calculate a SEM color and we combine it with the _diff_color. We cannot put
+the second part before normal calculation because SEM needs the _new_normal. Also we cannot put the first part after normal
+calculation because in case of grass we will waste calculations for the normal. For that two reasons we split the diffuse
+calculations in two parts
+*/
+
+/*
+=======================================================================================================================================
+VARS                                                                                                                                  =
+=======================================================================================================================================
+*/
+varying vec3 normal;
+
+#if defined( _HAS_DIFFUSE_MAP_ )
+	uniform sampler2D diffuse_map;
+#endif
+
+#if defined( _HAS_NORMAL_MAP_ )
+	uniform sampler2D normal_map;
+	varying vec3 tangent_v2f;
+	varying float w_v2f;
+#endif
+
+#if defined( _HAS_SPECULAR_MAP_ )
+	uniform sampler2D specular_map;
+#endif
+
+#if defined( _HAS_DIFFUSE_MAP_ ) || defined( _HAS_NORMAL_MAP_ ) || defined( _HAS_SPECULAR_MAP_ ) || defined( _PARALLAX_MAPPING_ )
+	varying vec2 tex_coords_v2f;
+#endif
+
+#if defined( _PARALLAX_MAPPING_ )
+	uniform sampler2D height_map;
+	varying vec3 eye;
+#endif
+
+
+#if defined( _ENVIRONMENT_MAPPING_ )
+	uniform sampler2D environment_map;
+	varying vec3 vert_pos_eye_space_v2f;
+#endif
+
+
+/*
+=======================================================================================================================================
+main                                                                                                                                  =
+=======================================================================================================================================
+*/
+void main()
+{
+	//===================================================================================================================================
+	// Paralax Mapping Calculations                                                                                                     =
+	// The code below reads the height map, makes some calculations and returns a new tex_coords                                        =
+	//===================================================================================================================================
+	#if defined( _PARALLAX_MAPPING_ )
+		const float _scale = 0.04;
+		const float _bias = scale * 0.4;
+
+		vec3 _norm_eye = normalize( eye );
+
+		float _h = texture2D( height_map, tex_coords_v2f ).r;
+		float _height = _scale * _h - _bias;
+
+		vec2 _super_tex_coords_v2f = _height * _norm_eye.xy + tex_coords_v2f;
+	#else
+		#define _super_tex_coords tex_coords_v2f
+	#endif
+
+
+	//===================================================================================================================================
+	// Diffuse Calculations (Part I)                                                                                                    =
+	// Get the color from the diffuse map and discard if grass                                                                          =
+	//===================================================================================================================================
+	vec3 _diff_color;
+	#if defined( _HAS_DIFFUSE_MAP_ )
+
+		#if defined( _GRASS_LIKE_ )
+			vec4 _diff_color4 = texture2D( diffuse_map, _super_tex_coords );
+			if( _diff_color4.a == 0.0 ) discard;
+			_diff_color = _diff_color4.rgb;
+		#else
+			_diff_color = texture2D( diffuse_map, _super_tex_coords ).rgb;
+		#endif
+
+		_diff_color *= gl_FrontMaterial.diffuse.rgb;
+	#else
+		_diff_color = gl_FrontMaterial.diffuse.rgb;
+	#endif
+
+
+	//===================================================================================================================================
+	// Normal Calculations                                                                                                              =
+	// Either use a normap map and make some calculations or use the vertex normal                                                      =
+	//===================================================================================================================================
+	#if defined( _HAS_NORMAL_MAP_ )
+		vec3 _n = normalize( normal );
+		vec3 _t = normalize( tangent_v2f );
+		vec3 _b = cross(_n, _t) * w_v2f;
+
+		mat3 _tbn_mat = mat3(_t,_b,_n);
+
+		vec3 _n_at_tangentspace = ( texture2D( normal_map, _super_tex_coords ).rgb - 0.5 ) * 2.0;
+
+		vec3 _new_normal = normalize( _tbn_mat * _n_at_tangentspace );
+	#else
+		vec3 _new_normal = normalize(normal);
+	#endif
+
+
+	//===================================================================================================================================
+	// Diffuse Calculations (Part II)                                                                                                   =
+	// If SEM is enabled make some calculations and combine colors of SEM and the _diff_color                                           =
+	//===================================================================================================================================
+
+	// if SEM enabled make some aditional calculations using the vert_pos_eye_space_v2f, environment_map and the _new_normal
+	#if defined( _ENVIRONMENT_MAPPING_ )
+		vec3 _u = normalize( vert_pos_eye_space_v2f );
+		vec3 _r = reflect( _u, _new_normal ); // In case of normal mapping I could play with vertex's normal but this gives better...
+		                                      // ...results and its allready computed
+		_r.z += 1.0;
+		float _m = 2.0 * length(_r);
+		vec2 _sem_tex_coords = _r.xy/_m + 0.5;
+
+		vec3 _sem_col = texture2D( environment_map, _sem_tex_coords ).rgb;
+		_diff_color = _diff_color + _sem_col; // blend existing color with the SEM texture map
+	#endif
+
+
+	//===================================================================================================================================
+	// Specular Calculations                                                                                                            =
+	//===================================================================================================================================
+
+	// has specular map
+	#if defined( _HAS_SPECULAR_MAP_ )
+		vec4 _specular = vec4(texture2D( specular_map, _super_tex_coords ).rgb * gl_FrontMaterial.specular.rgb, gl_FrontMaterial.shininess);
+	// no specular map
+	#else
+		vec4 _specular = vec4(gl_FrontMaterial.specular.rgb, gl_FrontMaterial.shininess);
+	#endif
+
+
+	//===================================================================================================================================
+	// Final Stage. Write all data                                                                                                      =
+	//===================================================================================================================================
+	//gl_FragData[0].rgb = _new_normal;
+	gl_FragData[0].rg = PackNormal( _new_normal );
+	gl_FragData[1].rgb = _diff_color;
+	gl_FragData[2] = _specular;
+
+	/*#if defined( _HARDWARE_SKINNING_ )
+		gl_FragData[1] = gl_Color;
+	#endif*/
+}
+

+ 100 - 0
shaders/ms_mp_generic.vert

@@ -0,0 +1,100 @@
+/**
+This a generic shader to fill the deferred shading buffers. You can always build your own if you dont need to write in all the
+buffers.
+*/
+varying vec3 normal;
+
+
+#if defined( _HAS_DIFFUSE_MAP_ ) || defined( _HAS_NORMAL_MAP_ ) || defined( _HAS_SPECULAR_MAP_ )
+	#define NEEDS_TEX_MAPPING 1
+#else
+	#define NEEDS_TEX_MAPPING 0
+#endif
+
+
+#if defined( _HAS_NORMAL_MAP_ ) || defined( _PARALLAX_MAPPING_ )
+	#define NEEDS_TANGENT 1
+#else
+	#define NEEDS_TANGENT 0
+#endif
+
+
+varying vec2 tex_coords_v2f;
+uniform vec2 tex_coords;
+
+attribute vec4 tangent;
+varying vec3 tangent_v2f;
+varying float w_v2f;
+
+varying vec3 eye_v2f; ///< In tangent space
+varying vec3 vert_pos_eye_space_v2f;
+
+
+
+//=====================================================================================================================================
+// main                                                                                                                               =
+//=====================================================================================================================================
+void main()
+{
+	// calculate the vert pos, normal and tangent
+
+	// if we have hardware skinning then:
+	#if defined( _HARDWARE_SKINNING_ )
+		mat3 _rot;
+		vec3 _tsl;
+
+		HWSkinning( _rot, _tsl );
+
+		normal = gl_NormalMatrix * ( _rot * gl_Normal );
+
+		#if NEEDS_TANGENT
+			tangent_v2f = gl_NormalMatrix * ( _rot * vec3(tangent) );
+		#endif
+
+		vec3 pos_lspace = ( _rot * gl_Vertex.xyz) + _tsl;
+		gl_Position =  gl_ModelViewProjectionMatrix * vec4(pos_lspace, 1.0);
+
+	// if DONT have hardware skinning
+	#else
+		normal = gl_NormalMatrix * gl_Normal;
+
+		#if NEEDS_TANGENT
+			tangent_v2f = gl_NormalMatrix * vec3(tangent);
+		#endif
+
+		gl_Position = ftransform();
+	#endif
+
+
+	// calculate the rest
+
+	#if NEEDS_TEX_MAPPING
+		tex_coords_v2f = gl_MultiTexCoord0.xy;
+	#endif
+
+
+	#if NEEDS_TANGENT
+		w_v2f = tangent.w;
+	#endif
+
+
+	#if defined( _ENVIRONMENT_MAPPING_ )
+		vert_pos_eye_space_v2f = vec3( gl_ModelViewMatrix * gl_Vertex );
+	#endif
+
+
+	#if defined( _PARALLAX_MAPPING_ )
+		vec3 t = gl_NormalMatrix * tangent.xyz;
+		vec3 n = normal;
+		vec3 b = cross( n, t ) /* tangent.w*/;
+
+		vec3 eye_pos = gl_Position.xyz - gl_ModelViewMatrixInverse[3].xyz;
+		eye_pos = eye_pos - ( gl_ModelViewMatrixInverse * gl_Vertex ).xyz;
+
+		mat3 tbn_mat = mat3( t, b, n );
+		eye = tbn_mat * eye_pos;
+		//eye.y = -eye.y;
+		//eye.x = -eye.x;
+	#endif
+}
+

+ 36 - 0
shaders/ms_mp_skybox.frag

@@ -0,0 +1,36 @@
+uniform sampler2D colormap;
+uniform sampler2D noisemap;
+uniform float timer;
+uniform vec3 scene_ambient_color;
+varying vec2 txtr_coords;
+
+#define PI 3.14159265358979323846
+
+
+void main()
+{
+	vec3 _noise_vec;
+	vec2 displacement;
+	float scaled_timer;
+
+	displacement = txtr_coords;
+
+	scaled_timer = timer*0.4;
+
+	displacement.x -= scaled_timer;
+	displacement.y -= scaled_timer;
+
+	_noise_vec = normalize( texture2D(noisemap, displacement).xyz );
+	_noise_vec = (_noise_vec * 2.0 - 1.0);
+
+	// edge_factor is a value that varies from 1.0 to 0.0 and then again to 1.0. Its zero in the edge of the skybox quad
+	// and white in the middle of the quad. We use it in order to reduse the distortion at the edges because of artefacts
+	float _edge_factor = sin( txtr_coords.s * PI ) * sin( txtr_coords.t * PI );
+
+	const float _strength_factor = 0.015;
+
+	_noise_vec = _noise_vec * _strength_factor * _edge_factor;
+
+	gl_FragData[1].rgb = texture2D(colormap, txtr_coords + _noise_vec.xy).rgb * scene_ambient_color; // write to the diffuse buffer
+}
+

+ 14 - 0
shaders/ms_mp_skybox.shdr

@@ -0,0 +1,14 @@
+VERTEX_SHADER "shaders/ms_mp_skybox.vert"
+FRAGMENT_SHADER "shaders/ms_mp_skybox.frag"
+
+PREPROCESSOR_DEFINES
+{
+}
+
+UNIFORMS
+{
+	colormap = 0
+	noisemap = 1
+	timer = 2
+}
+

+ 8 - 0
shaders/ms_mp_skybox.vert

@@ -0,0 +1,8 @@
+varying vec2 txtr_coords;
+
+void main()
+{
+	txtr_coords = gl_MultiTexCoord0.xy;
+	gl_Position = ftransform();
+}
+

+ 50 - 0
shaders/old/dfrd_post.frag

@@ -0,0 +1,50 @@
+#pragma optimize(off)
+
+uniform sampler2D normal_buf, diffuse_buf, specular_buf;
+uniform sampler2D depth_buf;
+uniform vec2 planes;
+uniform vec3 light_pos_eyespace;
+varying vec3 vpos1;
+
+vec3 Color2Normal( in vec3 _col )
+{
+	vec3 _normal;
+	_normal.x = _col.r - 0.5;
+	_normal.y = _col.g - 0.5;
+	_normal.z = _col.b - 0.5;
+	_normal = _normal * 2.0;
+	return _normal;
+}
+
+void main()
+{
+	vec3 _normal   = Color2Normal( texture2D( normal_buf, gl_TexCoord[0].st ).rgb );
+	vec4 _diffuse  = texture2D( diffuse_buf, gl_TexCoord[0].st );
+	vec4 _specular = texture2D( specular_buf, gl_TexCoord[0].st );
+	float _depth   = texture2D( depth_buf, gl_TexCoord[0].st ).r;
+
+
+  vec3 view = normalize(vpos1);
+
+	vec3 _pos;
+	_pos.z = -planes.y/(planes.x+_depth);
+	_pos.xy = view.xy/view.z*_pos.z;
+
+
+	vec3 _light_dir = /*normalize*/( light_pos_eyespace - _pos );
+
+	float invRadius = 1.0 / 4.0;
+
+	float distSqr = dot( _light_dir, _light_dir );
+	float att = clamp(1.0 - invRadius * sqrt(distSqr), 0.0, 1.0);
+	vec3 L = _light_dir * inversesqrt(distSqr);
+
+
+	float _lambert_term = dot( _normal, L );
+	_diffuse = _diffuse * gl_LightSource[0].diffuse;
+	vec4 _color = _diffuse * _lambert_term;
+
+	gl_FragColor = _color * att;
+	//gl_FragColor = vec4(_diffuse) ;
+}
+

+ 16 - 0
shaders/old/dfrd_post.shdr

@@ -0,0 +1,16 @@
+VERTEX_SHADER "shaders/dfrd_post.vert"
+FRAGMENT_SHADER "shaders/dfrd_post.frag"
+
+PREPROCESSOR_DEFINES
+{
+}
+
+UNIFORM_VARS
+{
+	"depth_buf"
+	"normal_buf"
+	"diffuse_buf"
+	"specular_buf"
+	"light_pos_eyespace"
+}
+

+ 10 - 0
shaders/old/dfrd_post.vert

@@ -0,0 +1,10 @@
+attribute vec3 vpos;
+varying vec3 vpos1;
+
+void main()
+{
+	vpos1 = vpos;
+	gl_TexCoord[0] = gl_MultiTexCoord0;
+  gl_Position = ftransform();
+}
+

+ 18 - 0
shaders/old/glass.frag

@@ -0,0 +1,18 @@
+// vertex to fragment shader io
+varying vec3 normal_v;
+varying vec3 vert_pos_modelview_v;
+
+uniform vec3 color;
+
+// globals
+const float edgefalloff = 6.0;
+
+// entry point
+void main()
+{
+    float opac = dot( normalize(-normal_v), normalize(-vert_pos_modelview_v) );
+    opac = abs(opac);
+    opac = 1.0-pow(opac, edgefalloff);
+
+    gl_FragColor =  vec4( opac * color, opac );
+}

+ 3 - 0
shaders/old/glass.shader

@@ -0,0 +1,3 @@
+VERT_SHADER shaders/glass.vert
+FRAG_SHADER shaders/glass.frag
+PREPROCESSOR_DEFINES_NUM 0

+ 13 - 0
shaders/old/glass.vert

@@ -0,0 +1,13 @@
+// Application to vertex shader
+varying vec3 normal_v;
+varying vec3 vert_pos_modelview_v;
+
+void main()
+{
+	vert_pos_modelview_v = (gl_ModelViewMatrix * gl_Vertex).xyz;
+
+	normal_v  = gl_NormalMatrix * gl_Normal;
+
+	gl_FrontColor = gl_Color;
+	gl_Position = ftransform();
+}

+ 10 - 0
shaders/old/grass.frag

@@ -0,0 +1,10 @@
+uniform sampler2D t0;
+
+void main()
+{
+	vec4 tex_col = texture2D( t0, gl_TexCoord[0].st );
+	
+	if( tex_col.a == 0.0 ) discard;
+	
+	gl_FragColor = tex_col;
+}

+ 2 - 0
shaders/old/grass.shdr

@@ -0,0 +1,2 @@
+VERTEX_SHADER "shaders/grass.vert"
+FRAGMENT_SHADER "shaders/grass.frag"

+ 7 - 0
shaders/old/grass.vert

@@ -0,0 +1,7 @@
+void main(void)
+{
+	gl_TexCoord[0] = gl_MultiTexCoord0;
+	gl_Position = ftransform();
+}
+
+

+ 10 - 0
shaders/old/lp_generic(with distance falloff).vert

@@ -0,0 +1,10 @@
+attribute vec3 view_vector;
+varying vec3 vpos;
+varying vec2 txtr_coord;
+
+void main()
+{
+	vpos = view_vector;
+	txtr_coord = gl_MultiTexCoord0.xy;
+  gl_Position = ftransform();
+}

+ 57 - 0
shaders/old/ms_mp_generic.vert

@@ -0,0 +1,57 @@
+/*
+This a generic shader to fill the deferred shading buffers. You can always build your own if you dont need to write in all the
+buffers.
+*/
+varying vec3 normal;
+
+#if defined( _HAS_DIFFUSE_MAP_ ) || defined( _HAS_NORMAL_MAP_ ) || defined( _HAS_SPECULAR_MAP_ )
+varying vec2 tex_coords;
+#endif
+
+
+#if defined( _HAS_NORMAL_MAP_ ) || defined( _PARALLAX_MAPPING_ )
+attribute vec4 tangent;
+#endif
+
+#if defined( _HAS_NORMAL_MAP_ )
+varying vec3 tangent_v;
+varying float w;
+#endif
+
+#if defined( _PARALLAX_MAPPING_ )
+varying vec3 eye; // in tangent space
+#endif
+
+
+void main()
+{
+	normal = gl_NormalMatrix * gl_Normal;
+	gl_Position = ftransform();
+
+#if defined( _HAS_DIFFUSE_MAP_ ) || defined( _HAS_NORMAL_MAP_ ) || defined( _HAS_SPECULAR_MAP_ )
+	tex_coords = gl_MultiTexCoord0.xy;
+#else
+	gl_FrontColor = gl_Color;
+#endif
+
+#if defined( _HAS_NORMAL_MAP_ )
+	tangent_v = gl_NormalMatrix * vec3(tangent);
+	w = tangent.w;
+#endif
+
+
+#if defined( _PARALLAX_MAPPING_ )
+	vec3 t = gl_NormalMatrix * tangent.xyz;
+	vec3 n = normal;
+	vec3 b = cross( n, t ) /* tangent.w*/;
+
+	vec3 eye_pos = gl_Position.xyz - gl_ModelViewMatrixInverse[3].xyz;
+	eye_pos = eye_pos - ( gl_ModelViewMatrixInverse * gl_Vertex ).xyz;
+
+	mat3 tbn_mat = mat3( t, b, n );
+	eye = tbn_mat * eye_pos;
+	//eye.y = -eye.y;
+	//eye.x = -eye.x;
+#endif
+}
+

+ 35 - 0
shaders/old/ms_mp_skybox.frag

@@ -0,0 +1,35 @@
+uniform sampler2D colormap;
+uniform sampler2D noisemap;
+uniform float timer;
+varying vec2 txtr_coords;
+
+#define PI 3.14159265358979323846
+
+
+void main()
+{
+	vec3 _noise_vec;
+	vec2 displacement;
+	float scaled_timer;
+
+	displacement = txtr_coords;
+
+	scaled_timer = timer*0.4;
+
+	displacement.x -= scaled_timer;
+	displacement.y -= scaled_timer;
+
+	_noise_vec = normalize( texture2D(noisemap, displacement).xyz );
+	_noise_vec = (_noise_vec * 2.0 - 1.0);
+
+	// edge_factor is a value that varies from 1.0 to 0.0 and then again to 1.0. Its zero in the edge of the skybox quad
+	// and white in the middle of the quad. We use it in order to reduse the distortion at the edges because of artefacts
+	float _edge_factor = sin( txtr_coords.s * PI ) * sin( txtr_coords.t * PI );
+
+	const float _strength_factor = 0.015;
+
+	_noise_vec = _noise_vec * _strength_factor * _edge_factor;
+
+	gl_FragData[1] = texture2D(colormap, txtr_coords + _noise_vec.xy); // write to the diffuse buffer
+}
+

+ 7 - 0
shaders/old/multitxtr.frag

@@ -0,0 +1,7 @@
+uniform sampler2D t0, t1;
+
+
+void main()
+{
+	gl_FragColor = texture2D( t0, gl_TexCoord[0].st) * texture2D( t1, gl_TexCoord[0].st);
+}

+ 6 - 0
shaders/old/multitxtr.vert

@@ -0,0 +1,6 @@
+void main(void)
+{
+	gl_TexCoord[0] = gl_MultiTexCoord0;
+	gl_Position = ftransform();
+}
+

+ 58 - 0
shaders/old/norm3l.frag

@@ -0,0 +1,58 @@
+uniform sampler2D color_map;
+uniform sampler2D normal_map;
+uniform sampler2D specular_map;
+
+varying vec3 light_dirs[3];
+uniform int light_ids[3];
+varying vec3 vert_modelview;
+
+varying vec4 _tangent;
+
+void main()
+{
+	vec3 n = normalize( texture2D(normal_map, gl_TexCoord[0].st).xyz * 2.0 - 1.0 );
+	vec3 t = normalize( _tangent.xyz );
+
+	vec4 diffuse, ambient, specular;
+	diffuse = ambient = specular = vec4(0.0, 0.0, 0.0, 0.0);
+
+	for( int i=0; i<3; i++ )
+	{
+		if( light_ids[i] == -1 ) break;
+		int light_id = light_ids[i];
+
+		vec3 b = cross( n, t );
+		mat3 rotate = mat3( t, b, n );
+		//mat3 rotate = mat3(t.x, b.x, n.x, t.y, b.y, n.y, t.z, b.z, n.z);
+
+		vec3 light_dir = gl_LightSource[light_id].position.xyz - vert_modelview;
+		light_dir = rotate * light_dir;
+		light_dir = normalize( light_dir );
+
+
+
+		float ndotl = dot( n, light_dir );
+
+		ambient += gl_FrontLightProduct[light_id].ambient;
+
+		if( ndotl > 0.0 )
+		{
+			//diffuse += gl_FrontLightProduct[light_id].diffuse * ndotl;
+
+
+			vec3 eye = -vert_modelview;
+			eye = normalize(rotate * eye);
+
+			vec3 r = reflect( -light_dir, n );
+			float power = pow( max(0.0, dot(r, eye)),  gl_FrontMaterial.shininess );
+
+//			vec4 spec_texel = texture2D(specular_map, gl_TexCoord[0].st);
+//			float shininess = clamp( (spec_texel.r + spec_texel.b + spec_texel.g), 0.0, 1.0);
+//			specular += gl_LightSource[i].specular * (shininess * power);
+			specular += gl_FrontLightProduct[light_id].specular * (power);
+		}
+	}
+
+	vec4 col_tex = texture2D(color_map, gl_TexCoord[0].st);
+	gl_FragColor = (ambient + diffuse + specular) ;
+}

+ 37 - 0
shaders/old/norm3l.vert

@@ -0,0 +1,37 @@
+attribute vec4 tangent;
+uniform int light_ids[3];
+varying vec3 light_dirs[3];
+varying vec3 vert_modelview;
+varying vec3 eye;
+varying vec4 _tangent;
+
+
+void main()
+{
+	gl_Position = ftransform();
+	gl_TexCoord[0] = gl_MultiTexCoord0;
+	vert_modelview = vec3(gl_ModelViewMatrix * gl_Vertex);
+
+
+	_tangent = tangent;
+
+
+	/*vec3 n = normalize( gl_NormalMatrix * gl_Normal );
+	vec3 t = normalize( gl_NormalMatrix * tangent.xyz );
+	//vec3 b = cross(n, t) * -tangent.w;             put this if you want defuse on the un-lighen area of a model
+	vec3 b = cross(n, t);
+
+	mat3 rotate = mat3(t.x, b.x, n.x,
+	                   t.y, b.y, n.y,
+	                   t.z, b.z, n.z);
+	//mat3 rotate = mat3( t, b, n );
+
+	for( int i=0; i<3; i++ )
+	{
+		int light_id = light_ids[i];
+		if( light_id == -1 ) break;
+		vec3 temp = gl_LightSource[light_id].position.xyz - vert_modelview;
+		light_dirs[i] = normalize( rotate * temp );
+		eye = rotate * -vert_modelview;
+	}*/
+}

+ 24 - 0
shaders/old/normal_mapping.frag

@@ -0,0 +1,24 @@
+uniform sampler2D color_map;
+uniform sampler2D normal_map;
+
+varying vec3 lightDir;
+varying vec3 halfVector;
+
+void main()
+{
+	vec3 n = normalize(texture2D(normal_map, gl_TexCoord[0].st).xyz * 2.0 - 1.0);
+	vec3 l = normalize(lightDir);
+	vec3 h = normalize(halfVector);
+
+	float nDotL = max(0.0, dot(n, l));
+	float nDotH = max(0.0, dot(n, h));
+	float power = (nDotL == 0.0) ? 0.0 : pow(nDotH, gl_FrontMaterial.shininess);
+
+	vec4 ambient = gl_FrontLightProduct[0].ambient;
+	vec4 diffuse = gl_FrontLightProduct[0].diffuse * nDotL;
+	vec4 specular = gl_FrontLightProduct[0].specular * power;
+	vec4 color = gl_FrontLightModelProduct.sceneColor + ambient + diffuse;// + specular;
+
+	gl_FragColor = color * texture2D(color_map, gl_TexCoord[0].st);
+	//gl_FragColor = gl_Color;
+}

+ 27 - 0
shaders/old/normal_mapping.vert

@@ -0,0 +1,27 @@
+varying vec3 lightDir;
+varying vec3 halfVector;
+attribute vec3 tangent;
+
+void main()
+{
+    gl_Position = ftransform();
+    gl_TexCoord[0] = gl_MultiTexCoord0;
+
+    vec3 n = normalize(gl_NormalMatrix * gl_Normal);
+    vec3 t = normalize(gl_NormalMatrix * tangent);
+    vec3 b = cross(n, t) /* gl_MultiTexCoord1.w*/;
+
+    mat3 tbnMatrix = mat3(t.x, b.x, n.x,
+                          t.y, b.y, n.y,
+                          t.z, b.z, n.z);
+
+		vec3 vert_modelview = vec3(gl_ModelViewMatrix * gl_Vertex);
+
+    lightDir = gl_LightSource[0].position.xyz - vert_modelview;
+    lightDir = tbnMatrix * lightDir;
+
+    halfVector = gl_LightSource[0].halfVector.xyz;
+    halfVector = tbnMatrix * halfVector;
+
+    gl_FrontColor = vec4( tangent, 1.0 );
+}

+ 42 - 0
shaders/old/parallax.frag

@@ -0,0 +1,42 @@
+varying vec2 UVtextureCoordinate;
+varying vec3 tanEyeVec;
+
+varying vec3 lightDir;
+
+uniform sampler2D texture;
+uniform sampler2D heightMap;
+uniform sampler2D normalMap;
+
+
+void main (void)
+{
+	float scale = 0.04;
+	float bias = scale * 0.4;
+
+   vec3 normalizedEyeVector = normalize( tanEyeVec );
+
+   float h = texture2D( heightMap, UVtextureCoordinate ).r;
+   float height = -scale * h + bias;
+   vec2 nextTextureCoordinate = height * normalizedEyeVector.xy + UVtextureCoordinate;
+
+
+
+
+	vec3 n = normalize(texture2D(normalMap, nextTextureCoordinate).xyz * 2.0 - 1.0);
+	vec3 l = normalize(lightDir);
+
+	float nDotL = max(0.0, dot(n, l));
+
+	vec4 diffuse = texture2D(texture, nextTextureCoordinate);
+
+	gl_FragColor = diffuse * nDotL;
+	//gl_FragColor = texture2D(diffuse_map, gl_TexCoord[0].st);
+	//gl_FragColor = vec4(tangent_v * 0.5 + 0.5, 1.0);
+
+
+
+
+   //gl_FragColor = texture2D( texture, nextTextureCoordinate );
+
+
+}

+ 2 - 0
shaders/old/parallax.shdr

@@ -0,0 +1,2 @@
+VERTEX_SHADER "shaders/old/parallax.vert"
+FRAGMENT_SHADER "shaders/old/parallax.frag"

+ 53 - 0
shaders/old/parallax.vert

@@ -0,0 +1,53 @@
+uniform vec3 lightPos;
+uniform mat4 model;
+
+varying vec2 UVtextureCoordinate;
+varying vec3 tanEyeVec;
+varying vec4 vcol;
+varying vec3 lightDir;
+
+vec3 TBN(in vec3 v)
+{
+	vec3 tangent 	= vec3(1.0,0.0,0.0);
+	vec3 normal		= normalize(gl_Normal);
+	vec3 binormal = cross(normal,tangent);
+
+	vec3 tvec;
+	tvec.x = dot(tangent,v);
+	tvec.y = dot(binormal,v);
+	tvec.z = dot(normal,v);
+	return tvec;
+}
+
+void main(void)
+{
+	gl_Position = ftransform();
+
+	gl_TexCoord[0] = gl_MultiTexCoord0;
+	UVtextureCoordinate = gl_TexCoord[0].xy;
+
+	// Get view position in view coordinates
+	vec3 eyePosition_ = gl_Position.xyz - gl_ModelViewMatrixInverse[3].xyz;
+
+	vec3 eyeVec = eyePosition_ - ( gl_ModelViewMatrixInverse * gl_Vertex ).xyz;;
+
+
+
+	vec3 tangent 	= gl_NormalMatrix * vec3(1.0,0.0,0.0);
+	vec3 normal		= normalize(gl_NormalMatrix * gl_Normal);
+	vec3 binormal = cross(normal, tangent);
+
+	mat3 tangentBinormalNormalMatrix = mat3( tangent, binormal, normal );
+
+	tanEyeVec = tangentBinormalNormalMatrix * eyeVec;
+
+
+
+
+	lightDir = lightPos - ( gl_ModelViewMatrix * gl_Vertex ).xyz;
+	vec3 v;
+	v.x = dot (lightDir, tangent);
+	v.y = dot (lightDir, binormal);
+	v.z = dot (lightDir, normal);
+	lightDir = normalize (v);
+}

+ 75 - 0
shaders/old/spec3l.frag

@@ -0,0 +1,75 @@
+/*
+TEXTBOOK LIGHTING MODEL
+
+A = Am * Al
+A is the final ambitent color, Am is the material's ambient and Al is the light's
+
+D = Dm * Dl * dot( normal, light_dir )
+D stands for diffuse color, Dm for material's diffuse and Dl for light's
+
+S = Sm * Sl * si     ** this shader uses a slightly different method **
+S is specular color and Sm, Sl as above.
+si is the specular intensity and its equal to: si = pow( dot(normal, h), material_shininess )
+h is h = normalize( light_dir + eye )
+
+C = A * D * S
+C is the final color vector
+
+
+OTHER METHOD FOR SPEC LIGHTING:
+The "ndotl > 0.0" check removes some unwanted specular calculations but it doesnt produces color under some conditions. This problem happens when:
+1) the angle of the vert's normal and light is grater than than 90degr and
+2) the material_shininess is small (close to 8.0)
+So we mul the si with dot(normal, light) to correct this. The result is not so correct but it looks close to the standard one and it
+allows us to use the the "ndotl > 0.0" check without the incorrect results. So:
+S = Sm * Sl * ( si * dot(normal, light) );
+
+*/
+
+uniform sampler2D color_map;
+uniform int light_ids[3];
+varying vec3 normal, vert_pos;
+
+void main()
+{
+	vec3 n = normalize( normal );
+
+	vec4 ctex = texture2D( color_map, gl_TexCoord[0].st );
+
+	vec4 color = vec4(0.0);
+
+
+	vec3 eye = normalize(-vert_pos.xyz);
+
+	for( int i=0; i<1; i++ )
+	{
+		if( light_ids[i] == -1 ) break;
+		int light_id = light_ids[i];
+
+		vec3 light_dir = normalize( gl_LightSource[light_id].position.xyz - vert_pos );
+
+
+		color += gl_FrontLightProduct[light_id].ambient;
+
+
+		float ndotl = dot( n, light_dir );
+
+		if( ndotl > 0.0 )
+		{
+			// diffuse
+			color += gl_FrontLightProduct[light_id].diffuse * ndotl;
+
+			// specular
+
+			vec3 r = reflect( -light_dir, n );
+			float power = pow(max(0.0, dot(r, eye)), gl_FrontMaterial.shininess);
+			/*vec3 h = normalize(light_dir + eye);
+			float power = pow(max(0.0, dot(n, h)), shininess);*/
+			color += gl_FrontLightProduct[light_id].specular * (power * ndotl);
+		}
+
+	}
+
+  gl_FragColor = (color) * ctex;
+  //gl_FragColor = vec4( light_ids.x, light_ids.y, light_ids.z, 1 );
+}

+ 9 - 0
shaders/old/spec3l.vert

@@ -0,0 +1,9 @@
+varying vec3 normal, vert_pos;
+
+void main()
+{
+	normal = gl_NormalMatrix * gl_Normal;
+  vert_pos = (gl_ModelViewMatrix * gl_Vertex).xyz; // vert pos in world space
+  gl_TexCoord[0] = gl_MultiTexCoord0;
+  gl_Position = ftransform();
+}

+ 71 - 0
shaders/old/specular.frag

@@ -0,0 +1,71 @@
+/*
+TEXTBOOK LIGHTING MODEL
+
+A = Am * Al
+A is the final ambitent color, Am is the material's ambient and Al is the light's
+
+D = Dm * Dl * dot( normal, light_dir )
+D stands for diffuse color, Dm for material's diffuse and Dl for light's
+
+S = Sm * Sl * si     ** this shader uses a slightly different method **
+S is specular color and Sm, Sl as above.
+si is the specular intensity and its equal to: si = pow( dot(normal, h), material_shininess )
+h is h = normalize( light_dir + eye )
+
+C = A * D * S
+C is the final color vector
+
+*/
+
+uniform sampler2D tex0, tex1;
+varying vec3 normal, vert_pos;
+
+void main()
+{
+  float shininess = gl_FrontMaterial.shininess;
+	vec3 n = normalize( normal );
+
+
+  vec3 light_dir = normalize( gl_LightSource[0].position.xyz - vert_pos );
+
+
+	float ndotl = dot( n, light_dir );
+
+	vec4 diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
+	vec4 ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
+	vec4 specular = gl_FrontMaterial.specular * gl_LightSource[0].specular;
+
+	vec4 color = ambient + ( diffuse * max(0.0, ndotl) );
+
+
+	// add some specular lighting IF necessary
+  if( ndotl > 0.0 )
+  {
+  	/*
+  	TEXTBOOK METHOD:
+  	the textbook way to calc spec color is as explained on the top:
+  	S = Sm * Sl * si;
+
+  	MY METHOD:
+  	The "ndotl > 0.0" check removes some unwanted specular calculations but it doesnt produces color under some conditions. This problem happens when:
+		1) the angle of the vert's normal and light is grater than than 90degr and
+		2) the material_shininess is small (close to 8.0)
+  	So we mul the si with dot(normal, light) to correct this. The result is not so correct but it looks close to the standard one and it
+  	allows us to use the the "ndotl > 0.0" check without the incorrect results. So:
+  	S = Sm * Sl * ( si * dot(normal, light) );
+  	*/
+
+		vec3 eye = -vert_pos.xyz;
+		eye = normalize(eye);
+
+		vec3 h = normalize( light_dir + eye );
+		float spec_intensity = pow(max(0.0, dot(n, h)), shininess);
+		color += specular * (spec_intensity * ndotl);
+  }
+
+	vec4 texel0 = texture2D( tex0, gl_TexCoord[0].st );
+	vec4 texel1 = texture2D( tex1, gl_TexCoord[0].st );
+	vec4 texel = texel0 * texel1;
+
+  gl_FragColor = color ;
+}

+ 9 - 0
shaders/old/specular.vert

@@ -0,0 +1,9 @@
+varying vec3 normal, vert_pos;
+
+void main()
+{
+	normal = gl_NormalMatrix * gl_Normal;
+  vert_pos = (gl_ModelViewMatrix * gl_Vertex).xyz; // vert pos in world space
+  gl_TexCoord[0] = gl_MultiTexCoord0;
+  gl_Position = ftransform();
+}

+ 79 - 0
shaders/old/specular3lights.frag

@@ -0,0 +1,79 @@
+/*
+TEXTBOOK LIGHTING MODEL
+
+A = Am * Al
+A is the final ambitent color, Am is the material's ambient and Al is the light's
+
+D = Dm * Dl * dot( normal, light_dir )
+D stands for diffuse color, Dm for material's diffuse and Dl for light's
+
+S = Sm * Sl * si     ** this shader uses a slightly different method **
+S is specular color and Sm, Sl as above.
+si is the specular intensity and its equal to: si = pow( dot(normal, h), material_shininess )
+h is h = normalize( light_dir + eye )
+
+C = A * D * S
+C is the final color vector
+
+*/
+
+uniform sampler2D color_map, normal_map;
+uniform int lights[3];
+varying vec3 normal, vert_pos;
+
+void main()
+{
+  float shininess = gl_FrontMaterial.shininess;
+	vec3 n = normalize( normal );
+
+	vec4 diffuse, ambient, specular;
+	diffuse = ambient = specular = vec4(0.0, 0.0, 0.0, 0.0);
+
+	vec3 light_dir;
+	float ndotl;
+
+	for( int i=0; i<3; i++ )
+	{
+		if( lights[i] == -1 ) continue;
+
+		light_dir = normalize( gl_LightSource[i].position.xyz - vert_pos );
+
+		ndotl = dot( n, light_dir );
+
+
+		ambient += gl_FrontLightProduct[i].ambient;
+		diffuse += gl_FrontLightProduct[i].diffuse * max(0.0, ndotl);
+
+
+		// add some specular lighting IF necessary
+		if( ndotl > 0.0 )
+		{
+			/*
+			TEXTBOOK METHOD:
+			the textbook way to calc spec color is as explained on the top:
+			S = Sm * Sl * si;
+
+			MY METHOD:
+			The "ndotl > 0.0" check removes some unwanted specular calculations but it doesnt produces color under some conditions. This problem happens when:
+			1) the angle of the vert's normal and light is grater than than 90degr and
+			2) the material_shininess is small (close to 8.0)
+			So we mul the si with dot(normal, light) to correct this. The result is not so correct but it looks close to the standard one and it
+			allows us to use the the "ndotl > 0.0" check without the incorrect results. So:
+			S = Sm * Sl * ( si * dot(normal, light) );
+			*/
+
+			vec3 eye = -vert_pos.xyz;
+			eye = normalize(eye);
+
+			vec3 h = normalize( light_dir + eye );
+			float power = pow(max(0.0, dot(n, h)), shininess);
+			specular += gl_FrontLightProduct[i].specular * (power * ndotl);
+		}
+	}
+
+	vec4 color_texel = texture2D( color_map, gl_TexCoord[0].st );
+	vec4 normal_texel = texture2D( normal_map, gl_TexCoord[0].st );
+	vec4 texel = color_texel;
+
+  gl_FragColor = (ambient + diffuse + specular) * texel;
+}

+ 10 - 0
shaders/old/specular3lights.vert

@@ -0,0 +1,10 @@
+varying vec3 normal, vert_pos;
+
+void main()
+{
+	normal = gl_NormalMatrix * gl_Normal;
+  vert_pos = (gl_ModelViewMatrix * gl_Vertex).xyz; // vert pos in world space
+  gl_TexCoord[0] = gl_MultiTexCoord0;
+  gl_Position = ftransform();
+  //gl_FrontColor = gl_Color;
+}

+ 21 - 0
shaders/old/test1.frag

@@ -0,0 +1,21 @@
+varying vec3 txtr_coord;
+uniform sampler2D normal_buf;
+
+vec3 Color2Vec( in vec3 _col )
+{
+	vec3 _vec3 = _col;
+	_col.x -= 0.5;
+	_col.y -= 0.5;
+	_col.z -= 0.5;
+	_vec3 = _vec3 * 2.0;
+	return _vec3;
+}
+
+
+void main()
+{
+	vec4 _normal = texture2DProj( normal_buf, txtr_coord );
+
+	gl_FragColor = _normal * gl_Color;
+}
+

+ 15 - 0
shaders/old/test1.shdr

@@ -0,0 +1,15 @@
+VERTEX_SHADER "shaders/test1.vert"
+FRAGMENT_SHADER "shaders/test1.frag"
+
+PREPROCESSOR_DEFINES
+{
+}
+
+UNIFORM_VARS
+{
+	"normal_buf"
+	/*"diffuse_buf"
+	"specular_buf"
+	"pos_buf"*/
+}
+

+ 12 - 0
shaders/old/test1.vert

@@ -0,0 +1,12 @@
+varying vec3 txtr_coord;
+
+void main()
+{
+	vec4 _vert_pos_eye_space = gl_ModelViewMatrix * gl_Vertex;
+	txtr_coord = vec3(gl_TextureMatrix[0] * _vert_pos_eye_space);
+
+	gl_FrontColor = gl_Color;
+
+  gl_Position = ftransform();
+}
+

+ 45 - 0
shaders/old/test_normalmaping.frag

@@ -0,0 +1,45 @@
+uniform sampler2D diffuse_map;
+uniform sampler2D normal_map;
+
+//varying vec3 lightDir;
+
+varying vec3 normal, tangent_v, frag_pos_vspace;
+varying float w;
+
+void main()
+{
+	vec3 _l = normalize( gl_LightSource[0].position.xyz - frag_pos_vspace );
+
+	vec3 _n = normalize( normal );
+	vec3 _t = normalize( tangent_v );
+	vec3 _b = cross( _n, _t ) * w;
+
+	vec3 _N = normalize(texture2D(normal_map, gl_TexCoord[0].st).xyz * 2.0 - 1.0);
+
+	vec3 v;
+	v.x = dot(_N, _t);
+	v.y = dot(_N, _b);
+	v.z = dot(_N, _n);
+
+	//_n = v;
+
+	mat3 tbnMatrix = mat3(_t, _b, _n);
+	_n = tbnMatrix * _N;
+
+	gl_FragColor = texture2D(diffuse_map, gl_TexCoord[0].st) * max(0.0, dot(_n, _l));
+	//gl_FragColor = vec4(w);
+
+
+/// The proper way
+//	vec3 n = normalize(texture2D(normal_map, gl_TexCoord[0].st).xyz * 2.0 - 1.0);
+//	vec3 l = normalize(lightDir);
+//
+//	float nDotL = max(0.0, dot(n, l));
+//
+//	vec4 diffuse = texture2D(diffuse_map, gl_TexCoord[0].st) * nDotL;
+//	vec4 color = diffuse;
+//
+//	gl_FragColor = color;
+//	//gl_FragColor = texture2D(diffuse_map, gl_TexCoord[0].st);
+//	//gl_FragColor = vec4(tangent_v * 0.5 + 0.5, 1.0);
+}

+ 12 - 0
shaders/old/test_normalmaping.shdr

@@ -0,0 +1,12 @@
+VERTEX_SHADER "shaders/old/test_normalmaping.vert"
+FRAGMENT_SHADER "shaders/old/test_normalmaping.frag"
+
+PREPROCESSOR_DEFINES
+{
+}
+
+UNIFORM_VARS
+{
+
+}
+

+ 41 - 0
shaders/old/test_normalmaping.vert

@@ -0,0 +1,41 @@
+varying vec3 lightDir;
+attribute vec4 tangent;
+
+varying vec3 normal, tangent_v, frag_pos_vspace;
+varying float w;
+
+void main()
+{
+	gl_Position = ftransform();
+	gl_TexCoord[0] = gl_MultiTexCoord0;
+
+	frag_pos_vspace = vec3( gl_ModelViewMatrix * gl_Vertex );
+
+	normal = normalize(gl_NormalMatrix * gl_Normal);
+	tangent_v = normalize( gl_NormalMatrix * vec3(tangent) );
+	w =  tangent.w;
+
+//	vec3 n = normalize(gl_NormalMatrix * gl_Normal);
+//	vec3 t = normalize(gl_NormalMatrix * vec3(tangent));
+//	vec3 b = cross(n, t) * tangent.w;
+//
+//	vec3 vert_modelview = vec3(gl_ModelViewMatrix * gl_Vertex);
+//	lightDir = gl_LightSource[0].position.xyz - vert_modelview;
+//
+////	mat3 tbnMatrix = mat3(t.x, b.x, n.x,
+////												t.y, b.y, n.y,
+////												t.z, b.z, n.z);
+//
+//
+////	mat3 tbnMatrix = mat3(t.x, t.y, t.z,
+////												b.x, b.y, b.z,
+////												n.x, n.y, n.z);
+//
+//	vec3 v;
+//	v.x = dot (lightDir, t);
+//	v.y = dot (lightDir, b);
+//	v.z = dot (lightDir, n);
+//	lightDir = normalize (v);
+//
+//	//lightDir = tbnMatrix * lightDir;
+}

+ 64 - 0
shaders/old/test_shadowmap.frag

@@ -0,0 +1,64 @@
+uniform sampler2DShadow s0;
+varying vec4 txtr_coord;
+
+void main ()
+{
+	const float kTransparency = 0.5;
+	const float smap_size = _SHADOW_MAP_QUALITY_;
+	vec4 color = gl_Color;
+
+	vec3 shadowUV = txtr_coord.xyz / txtr_coord.w; // ToDo: na do mipos kai xrimopoiiso anti gia vec3 gia to shadowUV enan aplo float. Mallon exei to idio xroma gia r kai g kai b ontas gray scale
+
+	vec4 shadowColor = shadow2D(s0, shadowUV);
+
+#if defined( _PCF_1_PASSES_ )
+	float mapScale = 1.0 / smap_size;
+
+	shadowColor += shadow2D(s0, shadowUV.xyz + vec3( mapScale,  mapScale, 0));
+	shadowColor += shadow2D(s0, shadowUV.xyz + vec3( mapScale, -mapScale, 0));
+	shadowColor += shadow2D(s0, shadowUV.xyz + vec3( mapScale,  	  0, 0));
+	shadowColor += shadow2D(s0, shadowUV.xyz + vec3(-mapScale,  mapScale, 0));
+	shadowColor += shadow2D(s0, shadowUV.xyz + vec3(-mapScale, -mapScale, 0));
+	shadowColor += shadow2D(s0, shadowUV.xyz + vec3(-mapScale,  	  0, 0));
+	shadowColor += shadow2D(s0, shadowUV.xyz + vec3(        0,  mapScale, 0));
+	shadowColor += shadow2D(s0, shadowUV.xyz + vec3(        0, -mapScale, 0));
+	shadowColor /= 9.0;
+#elif defined( _PCF_2_PASSES_ )
+	float mapScale = 1.0 / smap_size;
+
+	shadowColor += shadow2D(s0, shadowUV.xyz + vec3( mapScale,  mapScale, 0));
+	shadowColor += shadow2D(s0, shadowUV.xyz + vec3( mapScale, -mapScale, 0));
+	shadowColor += shadow2D(s0, shadowUV.xyz + vec3( mapScale,  	  0, 0));
+	shadowColor += shadow2D(s0, shadowUV.xyz + vec3(-mapScale,  mapScale, 0));
+	shadowColor += shadow2D(s0, shadowUV.xyz + vec3(-mapScale, -mapScale, 0));
+	shadowColor += shadow2D(s0, shadowUV.xyz + vec3(-mapScale,  	  0, 0));
+	shadowColor += shadow2D(s0, shadowUV.xyz + vec3(        0,  mapScale, 0));
+	shadowColor += shadow2D(s0, shadowUV.xyz + vec3(        0, -mapScale, 0));
+
+	mapScale = 2.0 / smap_size;
+	shadowColor += shadow2D(s0, shadowUV.xyz + vec3( mapScale,  mapScale, 0));
+	shadowColor += shadow2D(s0, shadowUV.xyz + vec3( mapScale, -mapScale, 0));
+	shadowColor += shadow2D(s0, shadowUV.xyz + vec3( mapScale,  	  0, 0));
+	shadowColor += shadow2D(s0, shadowUV.xyz + vec3(-mapScale,  mapScale, 0));
+	shadowColor += shadow2D(s0, shadowUV.xyz + vec3(-mapScale, -mapScale, 0));
+	shadowColor += shadow2D(s0, shadowUV.xyz + vec3(-mapScale,  	  0, 0));
+	shadowColor += shadow2D(s0, shadowUV.xyz + vec3(        0,  mapScale, 0));
+	shadowColor += shadow2D(s0, shadowUV.xyz + vec3(        0, -mapScale, 0));
+
+	shadowColor /= 18.0;
+
+#endif
+
+
+	shadowColor += kTransparency;
+	shadowColor = clamp(shadowColor, 0.0, 1.0);
+
+	if( shadowUV.x >= 0.0 && shadowUV.y >= 0.0 && shadowUV.x <= 1.0 && shadowUV.y <= 1.0 && txtr_coord.w > 0.0 && txtr_coord.w < 10.0  )
+	{
+		gl_FragColor = color * shadowColor;
+	}
+	else
+	{
+		gl_FragColor = color * vec4(kTransparency);
+	}
+}

+ 5 - 0
shaders/old/test_shadowmap.shader

@@ -0,0 +1,5 @@
+VERT_SHADER shaders/test.vert
+FRAG_SHADER shaders/test.frag
+PREPROCESSOR_DEFINES_NUM 2
+	#define _SHADOW_MAP_QUALITY_ 512.0
+	#define _PCF_1_PASSES_

+ 13 - 0
shaders/old/test_shadowmap.vert

@@ -0,0 +1,13 @@
+varying vec4 txtr_coord;
+
+void main()
+{
+	vec4 realPos = gl_ModelViewMatrix * gl_Vertex;
+  
+	txtr_coord = gl_TextureMatrix[0] * realPos;
+	gl_FrontColor = gl_Color;
+
+	gl_Position = ftransform();
+}
+
+

+ 23 - 0
shaders/old/toon.frag

@@ -0,0 +1,23 @@
+// simple toon fragment shader
+// www.lighthouse3d.com
+
+varying vec3 normal, lightDir;
+
+void main()
+{
+	float intensity;
+	vec4 color;
+
+	intensity = max( dot(lightDir,normalize(normal)), 0.0 ); 
+
+	if (intensity > 0.98)
+		color = vec4(0.8,0.8,0.8,1.0);
+	else if (intensity > 0.5)
+		color = vec4(0.4,0.4,0.8,1.0);	
+	else if (intensity > 0.25)
+		color = vec4(0.2,0.2,0.4,1.0);
+	else
+		color = vec4(0.1,0.1,0.1,1.0);		
+		
+	gl_FragColor = color;
+}

+ 13 - 0
shaders/old/toon.vert

@@ -0,0 +1,13 @@
+// simple toon vertex shader
+// www.lighthouse3d.com
+
+
+varying vec3 normal, lightDir;
+
+void main()
+{	
+	lightDir = normalize( vec3(gl_LightSource[1].position) );
+	normal = normalize( gl_NormalMatrix * gl_Normal );
+		
+	gl_Position = ftransform();
+}

+ 15 - 0
shaders/old/toon2.frag

@@ -0,0 +1,15 @@
+vec4 toonify(in float intensity) {
+
+	vec4 color;
+
+	if (intensity > 0.98)
+		color = vec4(0.8,0.8,0.8,1.0);
+	else if (intensity > 0.5)
+		color = vec4(0.4,0.4,0.8,1.0);	
+	else if (intensity > 0.25)
+		color = vec4(0.2,0.2,0.4,1.0);
+	else
+		color = vec4(0.1,0.1,0.1,1.0);		
+
+	return(color);
+}

+ 30 - 0
shaders/old/toon3.frag

@@ -0,0 +1,30 @@
+// simple toon fragment shader
+// www.lighthouse3d.com
+
+uniform float specIntensity;
+uniform vec4 specColor;
+uniform float t[2];
+uniform vec4 colors[3];
+
+varying vec3 normal, lightDir;
+
+void main()
+{
+	float intensity;
+	vec3 n;
+	vec4 color;
+
+	n = normalize(normal);
+	intensity = max(dot(lightDir,n),0.0); 
+
+	if (intensity > specIntensity)
+		color = specColor;
+	else if (intensity > t[0])
+		color = colors[0];	
+	else if (intensity > t[1])
+		color = colors[1];
+	else
+		color = colors[2];		
+
+	gl_FragColor = color;
+}

+ 74 - 0
shaders/old/txtr_project.frag

@@ -0,0 +1,74 @@
+/**
+TEXTBOOK LIGHTING MODEL
+
+A = Am * Al
+A is the final ambitent color, Am is the material's ambient and Al is the light's
+
+D = Dm * Dl * dot( normal, light_dir )
+D stands for diffuse color, Dm for material's diffuse and Dl for light's
+
+S = Sm * Sl * si     ** this shader uses a slightly different method **
+S is specular color and Sm, Sl as above.
+si is the specular intensity and its equal to: si = pow( dot(normal, h), material_shininess )
+h is h = normalize( light_dir + eye )
+
+C = A * D * S
+C is the final color vector
+
+*/
+
+
+
+void Phong( in int _light_id, in vec3 _light_dir, in vec3 _eye_vec, in vec3 _normal, out vec4 _color, out float _lambert_term )
+{
+	vec4 _ambient = gl_FrontMaterial.ambient * gl_LightSource[_light_id].ambient;
+	_color = _ambient;
+
+	_lambert_term = dot( _normal, _light_dir );
+
+	if( _lambert_term < 0.0 ) return; // dont calculate specular or diffuse
+
+	vec4 _diffuse = gl_FrontMaterial.diffuse * gl_LightSource[_light_id].diffuse;
+	_color += _diffuse * _lambert_term;
+
+	/// TEXTBOOK METHOD:
+	/// the textbook way to calc spec color is as explained on the top:
+	/// S = Sm * Sl * si;
+	/// MY METHOD:
+	/// The "ndotl > 0.0" check removes some unwanted specular calculations but it doesnt produces color under some conditions. This problem happens when:
+	/// 1) the angle of the vert's normal and light is grater than than 90degr and
+	/// 2) the material_shininess is small (close to 8.0)
+	/// So we mul the si with dot(normal, light) to correct this. The result is not so correct but it looks close to the standard one and it
+	/// allows us to use the the "ndotl > 0.0" check without the incorrect results. So:
+	/// S = Sm * Sl * ( si * dot(normal, light) );
+
+	float _shininess = gl_FrontMaterial.shininess;
+
+	vec3 _h = normalize( _light_dir + _eye_vec );
+	float _spec_intensity = pow(max(0.0, dot(_normal, _h)), _shininess);
+	_color += gl_FrontMaterial.specular * gl_LightSource[_light_id].specular * (_spec_intensity * _lambert_term);
+}
+
+varying vec3 normal, vert_light_vec, eye_vec;
+varying vec4 txtr_coord;
+uniform sampler2D t0;
+
+void main()
+{
+	vec3 _n = normalize( normal );
+  vec3 _light_dir = normalize( vert_light_vec );
+  vec3 _eye_vec = normalize( eye_vec );
+	vec4 _color;
+	float _lambert_term;
+	Phong( 0, _light_dir, _eye_vec, _n, _color, _lambert_term );
+
+	if( txtr_coord.q > 0.0 )
+	{
+		vec4 _texel = texture2DProj( t0, txtr_coord.xyz );
+		vec4 _texel_with_lambert = _texel * _lambert_term;
+		gl_FragColor = _color * _texel_with_lambert;
+	}
+	else
+		gl_FragColor = vec4(0.0);
+}
+

+ 14 - 0
shaders/old/txtr_project.shdr

@@ -0,0 +1,14 @@
+VERTEX_SHADER "shaders/test.vert"
+FRAGMENT_SHADER "shaders/test.frag"
+
+PREPROCESSOR_DEFINES
+{
+	"#define _SHADOW_MAP_QUALITY_ 512.0"
+	"#define _PCF_1_PASSES_"
+}
+
+UNIFORM_VARS
+{
+	"t0"
+}
+

+ 33 - 0
shaders/old/txtr_project.vert

@@ -0,0 +1,33 @@
+//varying vec3 normal, vert_pos;
+//varying vec4 txtr_coord;
+//
+//void main()
+//{
+//	normal = gl_NormalMatrix * gl_Normal;
+//	vert_pos = vec3(gl_ModelViewMatrix * gl_Vertex); // vert pos in world space
+//	txtr_coord = gl_TextureMatrix[0] * vec4(vert_pos, 0.0);
+//
+//  //gl_TexCoord[0] = gl_MultiTexCoord0;
+//  gl_Position = ftransform();
+//}
+
+
+varying vec3 normal, vert_light_vec, eye_vec;
+varying vec4 txtr_coord;
+
+void main()
+{
+	/// standard stuff
+	//gl_TexCoord[0] = gl_MultiTexCoord0;
+  gl_Position = ftransform();
+
+	/// varying vars
+	normal = gl_NormalMatrix * gl_Normal;
+
+	vec4 _vert_pos_eye_space = gl_ModelViewMatrix * gl_Vertex;
+	vert_light_vec = gl_LightSource[0].position.xyz - _vert_pos_eye_space.xyz;
+	eye_vec = -_vert_pos_eye_space.xyz; // the actual eye_vec is normalized but there is no need to normalize in vert shader
+
+	txtr_coord = gl_TextureMatrix[0] * _vert_pos_eye_space;
+}
+

+ 34 - 0
shaders/pack.glsl

@@ -0,0 +1,34 @@
+vec2 PackNormal( in vec3 _normal )
+{
+    /*original code:
+    const float _scale = 1.7777;
+    vec2 _enc = _normal.xy / (_normal.z+1.0);
+    _enc /= _scale;
+    _enc = _enc*0.5 + 0.5;
+    return _enc;*/
+
+    const float _scale = 1.7777;
+    float scalar1 = (_normal.z+1.0)*(_scale*2.0);
+    return _normal.xy / scalar1 + 0.5;
+}
+
+
+vec3 UnpackNormal( in vec2 _enc )
+{
+	/*original code:
+	float _scale = 1.7777;
+	vec3 _nn = vec3( _enc*vec2(2.0*_scale, 2.0*_scale) + vec2(-_scale, -_scale), 1.0 );
+	float _g = 2.0 / dot(_nn.xyz, _nn.xyz);
+	vec3 _normal;
+	_normal.xy = _g * _nn.xy;
+	_normal.z = _g - 1.0;
+	return _normal;*/
+
+	const float _scale = 1.7777;
+	vec2 _nn = _enc*(2.0*_scale) - _scale;
+	float _g = 2.0 / (dot(_nn.xy, _nn.xy) + 1.0);
+	vec3 _normal;
+	_normal.xy = _g * _nn.xy;
+	_normal.z = _g - 1.0;
+	return _normal;
+}

+ 7 - 0
shaders/paraboloid.frag

@@ -0,0 +1,7 @@
+varying vec2 tex_coords;
+uniform sampler2D diff_map;
+
+void main()
+{
+	gl_FragColor = texture2D( diff_map, tex_coords );
+}

+ 22 - 0
shaders/paraboloid.vert

@@ -0,0 +1,22 @@
+varying vec2 tex_coords;
+uniform mat4 matrix;
+
+void main()
+{
+	tex_coords = gl_MultiTexCoord0.xy;
+
+	vec4 pos = gl_ModelViewProjectionMatrix * gl_Vertex;
+	//pos = pos / pos.w;
+
+	float L = length( pos.xyz );
+	pos = pos / L;
+
+	pos.z = pos.z + 1;
+	pos.x = pos.x / pos.z;
+	pos.y = pos.y / pos.z;
+
+	pos.z = (L - 0.1)/(200.0-0.1);
+	pos.w = 1.0;
+
+	gl_Position = pos;
+}

+ 245 - 0
shaders/photoshop_filters.glsl

@@ -0,0 +1,245 @@
+/*
+** Photoshop & misc math
+** Blending modes, RGB/HSL/Contrast/Desaturate, levels control
+**
+** Romain Dura | Romz
+** Blog: http://blog.mouaif.org
+** Post: http://blog.mouaif.org/?p=94
+*/
+
+
+/*
+** Desaturation
+*/
+
+vec4 Desaturate(vec3 color, float Desaturation)
+{
+	vec3 grayXfer = vec3(0.3, 0.59, 0.11);
+	vec3 gray = vec3(dot(grayXfer, color));
+	return vec4(mix(color, gray, Desaturation), 1.0);
+}
+
+
+/*
+** Hue, saturation, luminance
+*/
+
+vec3 RGBToHSL(vec3 color)
+{
+	vec3 hsl; // init to 0 to avoid warnings ? (and reverse if + remove first part)
+
+	float fmin = min(min(color.r, color.g), color.b);    //Min. value of RGB
+	float fmax = max(max(color.r, color.g), color.b);    //Max. value of RGB
+	float delta = fmax - fmin;             //Delta RGB value
+
+	hsl.z = (fmax + fmin) / 2.0; // Luminance
+
+	if (delta == 0.0)		//This is a gray, no chroma...
+	{
+		hsl.x = 0.0;	// Hue
+		hsl.y = 0.0;	// Saturation
+	}
+	else                                    //Chromatic data...
+	{
+		if (hsl.z < 0.5)
+			hsl.y = delta / (fmax + fmin); // Saturation
+		else
+			hsl.y = delta / (2.0 - fmax - fmin); // Saturation
+
+		float deltaR = (((fmax - color.r) / 6.0) + (delta / 2.0)) / delta;
+		float deltaG = (((fmax - color.g) / 6.0) + (delta / 2.0)) / delta;
+		float deltaB = (((fmax - color.b) / 6.0) + (delta / 2.0)) / delta;
+
+		if (color.r == fmax )
+			hsl.x = deltaB - deltaG; // Hue
+		else if (color.g == fmax)
+			hsl.x = (1.0 / 3.0) + deltaR - deltaB; // Hue
+		else if (color.b == fmax)
+			hsl.x = (2.0 / 3.0) + deltaG - deltaR; // Hue
+
+		if (hsl.x < 0.0)
+			hsl.x += 1.0; // Hue
+		else if (hsl.x > 1.0)
+			hsl.x -= 1.0; // Hue
+	}
+
+	return hsl;
+}
+
+float HueToRGB(float f1, float f2, float hue)
+{
+	if (hue < 0.0)
+		hue += 1.0;
+	else if (hue > 1.0)
+		hue -= 1.0;
+	float res;
+	if ((6.0 * hue) < 1.0)
+		res = f1 + (f2 - f1) * 6.0 * hue;
+	else if ((2.0 * hue) < 1.0)
+		res = f2;
+	else if ((3.0 * hue) < 2.0)
+		res = f1 + (f2 - f1) * ((2.0 / 3.0) - hue) * 6.0;
+	else
+		res = f1;
+	return res;
+}
+
+vec3 HSLToRGB(vec3 hsl)
+{
+	vec3 rgb;
+
+	if (hsl.y == 0.0)
+		rgb = vec3(hsl.z); // Luminance
+	else
+	{
+		float f2;
+
+		if (hsl.z < 0.5)
+			f2 = hsl.z * (1.0 + hsl.y);
+		else
+			f2 = (hsl.z + hsl.y) - (hsl.y * hsl.z);
+
+		float f1 = 2.0 * hsl.z - f2;
+
+		rgb.r = HueToRGB(f1, f2, hsl.x + (1.0/3.0));
+		rgb.g = HueToRGB(f1, f2, hsl.x);
+		rgb.b= HueToRGB(f1, f2, hsl.x - (1.0/3.0));
+	}
+
+	return rgb;
+}
+
+
+/*
+** Contrast, saturation, brightness
+** Code of this function is from TGM's shader pack
+** http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=21057
+*/
+
+// For all settings: 1.0 = 100% 0.5=50% 1.5 = 150%
+vec3 ContrastSaturationBrightness(vec3 color, float brt, float sat, float con)
+{
+	// Increase or decrease theese values to adjust r, g and b color channels seperately
+	const float AvgLumR = 0.5;
+	const float AvgLumG = 0.5;
+	const float AvgLumB = 0.5;
+
+	const vec3 LumCoeff = vec3(0.2125, 0.7154, 0.0721);
+
+	vec3 AvgLumin = vec3(AvgLumR, AvgLumG, AvgLumB);
+	vec3 brtColor = color * brt;
+	vec3 intensity = vec3(dot(brtColor, LumCoeff));
+	vec3 satColor = mix(intensity, brtColor, sat);
+	vec3 conColor = mix(AvgLumin, satColor, con);
+	return conColor;
+}
+
+
+/*
+** Float blending modes
+** Adapted from here: http://www.nathanm.com/photoshop-blending-math/
+** But I modified the HardMix (wrong condition), Overlay, SoftLight, ColorDodge, ColorBurn, VividLight, PinLight (inverted layers) ones to have correct results
+*/
+
+#define BlendLinearDodgef 			BlendAddf
+#define BlendLinearBurnf 			BlendSubstractf
+#define BlendAddf(base, blend) 		min(base + blend, 1.0)
+#define BlendSubstractf(base, blend) 	max(base + blend - 1.0, 0.0)
+#define BlendLightenf(base, blend) 		max(blend, base)
+#define BlendDarkenf(base, blend) 		min(blend, base)
+#define BlendLinearLightf(base, blend) 	(blend < 0.5 ? BlendLinearBurnf(base, (2.0 * blend)) : BlendLinearDodgef(base, (2.0 * (blend - 0.5))))
+#define BlendScreenf(base, blend) 		(1.0 - ((1.0 - base) * (1.0 - blend)))
+#define BlendOverlayf(base, blend) 	(base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend)))
+#define BlendSoftLightf(base, blend) 	((blend < 0.5) ? (2.0 * base * blend + base * base * (1.0 - 2.0 * blend)) : (sqrt(base) * (2.0 * blend - 1.0) + 2.0 * base * (1.0 - blend)))
+#define BlendColorDodgef(base, blend) 	((blend == 1.0) ? blend : min(base / (1.0 - blend), 1.0))
+#define BlendColorBurnf(base, blend) 	((blend == 0.0) ? blend : max((1.0 - ((1.0 - base) / blend)), 0.0))
+#define BlendVividLightf(base, blend) 	((blend < 0.5) ? BlendColorBurnf(base, (2.0 * blend)) : BlendColorDodgef(base, (2.0 * (blend - 0.5))))
+#define BlendPinLightf(base, blend) 	((blend < 0.5) ? BlendDarkenf(base, (2.0 * blend)) : BlendLightenf(base, (2.0 *(blend - 0.5))))
+#define BlendHardMixf(base, blend) 	((BlendVividLightf(base, blend) < 0.5) ? 0.0 : 1.0)
+#define BlendReflectf(base, blend) 		((blend == 1.0) ? blend : min(base * base / (1.0 - blend), 1.0))
+
+
+/*
+** Vector3 blending modes
+*/
+
+// Component wise blending
+#define Blend(base, blend, funcf) 		vec3(funcf(base.r, blend.r), funcf(base.g, blend.g), funcf(base.b, blend.b))
+
+#define BlendNormal(base, blend) 		(blend)
+#define BlendLighten				BlendLightenf
+#define BlendDarken				BlendDarkenf
+#define BlendMultiply(base, blend) 		(base * blend)
+#define BlendAverage(base, blend) 		((base + blend) / 2.0)
+#define BlendAdd(base, blend) 		min(base + blend, vec3(1.0))
+#define BlendSubstract(base, blend) 	max(base + blend - vec3(1.0), vec3(0.0))
+#define BlendDifference(base, blend) 	abs(base - blend)
+#define BlendNegation(base, blend) 	(vec3(1.0) - abs(vec3(1.0) - base - blend))
+#define BlendExclusion(base, blend) 	(base + blend - 2.0 * base * blend)
+#define BlendScreen(base, blend) 		Blend(base, blend, BlendScreenf)
+#define BlendOverlay(base, blend) 		Blend(base, blend, BlendOverlayf)
+#define BlendSoftLight(base, blend) 	Blend(base, blend, BlendSoftLightf)
+#define BlendHardLight(base, blend) 	BlendOverlay(blend, base)
+#define BlendColorDodge(base, blend) 	Blend(base, blend, BlendColorDodgef)
+#define BlendColorBurn(base, blend) 	Blend(base, blend, BlendColorBurnf)
+#define BlendLinearDodge			BlendAdd
+#define BlendLinearBurn			BlendSubstract
+// Linear Light is another contrast-increasing mode
+// If the blend color is darker than midgray, Linear Light darkens the image by decreasing the brightness. If the blend color is lighter than midgray, the result is a brighter image due to increased brightness.
+#define BlendLinearLight(base, blend) 	Blend(base, blend, BlendLinearLightf)
+#define BlendVividLight(base, blend) 	Blend(base, blend, BlendVividLightf)
+#define BlendPinLight(base, blend) 		Blend(base, blend, BlendPinLightf)
+#define BlendHardMix(base, blend) 		Blend(base, blend, BlendHardMixf)
+#define BlendReflect(base, blend) 		Blend(base, blend, BlendReflectf)
+#define BlendGlow(base, blend) 		BlendReflect(blend, base)
+#define BlendPhoenix(base, blend) 		(min(base, blend) - max(base, blend) + vec3(1.0))
+#define BlendOpacity(base, blend, F, O) 	(F(base, blend) * O + blend * (1.0 - O))
+
+
+// Hue Blend mode creates the result color by combining the luminance and saturation of the base color with the hue of the blend color.
+vec3 BlendHue(vec3 base, vec3 blend)
+{
+	vec3 baseHSL = RGBToHSL(base);
+	return HSLToRGB(vec3(RGBToHSL(blend).r, baseHSL.g, baseHSL.b));
+}
+
+// Saturation Blend mode creates the result color by combining the luminance and hue of the base color with the saturation of the blend color.
+vec3 BlendSaturation(vec3 base, vec3 blend)
+{
+	vec3 baseHSL = RGBToHSL(base);
+	return HSLToRGB(vec3(baseHSL.r, RGBToHSL(blend).g, baseHSL.b));
+}
+
+// Color Mode keeps the brightness of the base color and applies both the hue and saturation of the blend color.
+vec3 BlendColor(vec3 base, vec3 blend)
+{
+	vec3 blendHSL = RGBToHSL(blend);
+	return HSLToRGB(vec3(blendHSL.r, blendHSL.g, RGBToHSL(base).b));
+}
+
+// Luminosity Blend mode creates the result color by combining the hue and saturation of the base color with the luminance of the blend color.
+vec3 BlendLuminosity(vec3 base, vec3 blend)
+{
+	vec3 baseHSL = RGBToHSL(base);
+	return HSLToRGB(vec3(baseHSL.r, baseHSL.g, RGBToHSL(blend).b));
+}
+
+
+/*
+** Gamma correction
+** Details: http://blog.mouaif.org/2009/01/22/photoshop-gamma-correction-shader/
+*/
+
+#define GammaCorrection(color, gamma)								pow(color, 1.0 / gamma)
+
+/*
+** Levels control (input (+gamma), output)
+** Details: http://blog.mouaif.org/2009/01/28/levels-control-shader/
+*/
+
+#define LevelsControlInputRange(color, minInput, maxInput)				min(max(color - vec3(minInput), vec3(0.0)) / (vec3(maxInput) - vec3(minInput)), vec3(1.0))
+#define LevelsControlInput(color, minInput, gamma, maxInput)				GammaCorrection(LevelsControlInputRange(color, minInput, maxInput), gamma)
+#define LevelsControlOutputRange(color, minOutput, maxOutput) 			mix(vec3(minOutput), vec3(maxOutput), color)
+#define LevelsControl(color, minInput, gamma, maxInput, minOutput, maxOutput) 	LevelsControlOutputRange(LevelsControlInput(color, minInput, gamma, maxInput), minOutput, maxOutput)
+
+

+ 207 - 0
shaders/pps.frag

@@ -0,0 +1,207 @@
+//
+uniform sampler2D is_fai;
+varying vec2 tex_coords;
+
+#if defined(_SSAO_)
+uniform sampler2D pps_ssao_fai;
+#endif
+
+#if defined(_EDGEAA_)
+uniform sampler2D ms_normal_fai;
+uniform vec2 camerarange;
+#endif
+
+#if defined(_BLOOM_)
+uniform sampler2D pps_boom_fai;
+#endif
+
+#if defined(_LSCATT_)
+	uniform sampler2D pps_lscatt_fai;
+#endif
+
+
+/*
+=======================================================================================================================================
+GrayScale                                                                                                                             =
+=======================================================================================================================================
+*/
+vec3 GrayScale( in vec3 _col )
+{
+	float _grey = (_col.r + _col.g + _col.b) * 0.333333333; // aka: / 3.0
+	return vec3(_grey);
+}
+
+
+/*
+=======================================================================================================================================
+Saturation                                                                                                                            =
+=======================================================================================================================================
+*/
+vec3 Saturation( in vec3 _col, in float _satur_factor )
+{
+	const vec3 lumCoeff = vec3 ( 0.2125, 0.7154, 0.0721);
+
+	vec3 intensity = vec3( dot(_col, lumCoeff) );
+	return mix( intensity, _col, _satur_factor );
+}
+
+
+/*
+=======================================================================================================================================
+EdgeAA                                                                                                                                =
+=======================================================================================================================================
+*/
+#if defined(_EDGEAA_)
+
+//float LinearizeDepth( in float _depth )
+//{
+//	return (2.0 * camerarange.x) / (camerarange.y + camerarange.x - _depth * (camerarange.y - camerarange.x));
+//}
+//
+//float ReadLinearDepth( in vec2 coord )
+//{
+//	return LinearizeDepth( texture2D( depth_map, coord ).r );
+//}
+
+vec3 EdgeAA()
+{
+	vec2 kernel[8];
+	kernel[0] = vec2(-1,1);
+	kernel[1] = vec2(1,-1);
+	kernel[2] = vec2(-1,-1);
+	kernel[3] = vec2(1,1);
+	kernel[4] = vec2(-1,0);
+	kernel[5] = vec2(1,0);
+	kernel[6] = vec2(0,-1);
+	kernel[7] = vec2(0,1);
+
+	vec2 pixelsize = vec2( 1.0/(R_W*R_Q), 1.0/(R_H*R_Q) );
+	const float weight = 1.0;
+
+	vec3 tex = texture2D( ms_normal_fai, tex_coords ).rgb;
+	float factor = -0.5;
+
+	for( int i=0; i<4; i++ )
+	{
+		vec3 t = texture2D( ms_normal_fai, tex_coords + kernel[i]*pixelsize ).rgb;
+		t -= tex;
+		factor += dot(t, t);
+	}
+
+	factor = min(1.0, factor) * weight;
+
+	//return vec3(factor);
+	//if( factor < 0.01 ) return texture2D( is_fai, tex_coords ).rgb;
+
+	vec3 color = vec3(0.0);
+
+	for( int i=0; i<8; i++ )
+	{
+		color += texture2D( is_fai, tex_coords + kernel[i]*pixelsize*factor ).rgb;
+	}
+
+	color += 2.0 * texture2D( is_fai, tex_coords ).rgb;
+
+	return color*(1.0/9.0);
+
+//	const float aob = 1.0; // area of blur
+//
+//	vec2 kernel[8];
+//	kernel[0] = vec2(-aob,aob);
+//	kernel[1] = vec2(aob,-aob);
+//	kernel[2] = vec2(-aob,-aob);
+//	kernel[3] = vec2(aob,aob);
+//	kernel[4] = vec2(-aob,0);
+//	kernel[5] = vec2(aob,0);
+//	kernel[6] = vec2(0,-aob);
+//	kernel[7] = vec2(0,aob);
+//
+//	vec2 pixelsize = vec2( 1.0/R_W, 1.0/R_H );
+//
+//	float d = ReadLinearDepth( tex_coords );
+//	float factor = 0.0;
+//
+//	const float weight = 8.0;
+//
+//	for( int i=0; i<4; i++ )
+//	{
+//		float ds = ReadLinearDepth( tex_coords + kernel[i]*pixelsize );
+//
+//		factor += abs(d - ds);
+//	}
+//
+//	factor = (factor / 4)*weight;
+//
+//	//return vec3(factor);
+//
+//	/*if( factor < 0.001 )
+//	{
+//		return texture2D( is_fai, tex_coords ).rgb;
+//	}*/
+//
+//	vec3 color = vec3(0.0);
+//
+//	for( int i=0; i<8; i++ )
+//	{
+//		color += texture2D( is_fai, tex_coords + kernel[i]*pixelsize*factor ).rgb;
+//	}
+//
+//	color += 2.0 * texture2D( is_fai, tex_coords ).rgb;
+//
+//	return color*(1.0/10.0);
+}
+#endif
+
+
+/*
+=======================================================================================================================================
+main                                                                                                                                  =
+=======================================================================================================================================
+*/
+void main (void)
+{
+	vec3 color;
+
+	#if defined(_EDGEAA_)
+		color = EdgeAA();
+	#else
+		color = texture2D( is_fai, tex_coords ).rgb;
+	#endif
+
+	/*const float gamma = 0.7;
+	color.r = pow(color.r, 1.0 / gamma);
+	color.g = pow(color.g, 1.0 / gamma);
+	color.b = pow(color.b, 1.0 / gamma);*/
+
+	#if defined(_SSAO_)
+		float ssao_factor = texture2D( pps_ssao_fai, tex_coords ).a;
+		color *= ssao_factor;
+	#endif
+
+	#if defined(_LSCATT_)
+		vec3 lscatt = texture2D( pps_lscatt_fai, tex_coords ).rgb;
+		color += lscatt;
+	#endif
+
+	#if defined(_BLOOM_)
+		//float bloom_factor = texture2D( pps_boom_fai, tex_coords ).r; // ORIGINAL BLOOM CODE
+		vec3 bloom = texture2D( pps_boom_fai, tex_coords ).rgb;
+		color += bloom;
+	#endif
+
+	color = BlendHardLight( vec3(0.6, 0.62, 0.4), color );
+
+	gl_FragData[0].rgb = color;
+
+	//gl_FragColor = vec4( color, 1.0 );
+	//gl_FragColor = vec4( GrayScale(gl_FragColor.rgb), 1.0 );
+	//gl_FragData[0] = vec4( ssao_factor );
+	//gl_FragData[0] = vec4( lscatt, 1.0 );
+	//gl_FragData[0] = vec4( bloom_factor );
+	//gl_FragColor = vec4( EdgeAA(), 1.0 );
+	//gl_FragColor = texture2D( pps_boom_fai, tex_coords );
+	//gl_FragColor = texture2D( is_fai, tex_coords );
+	//gl_FragData[0].rgb = UnpackNormal( texture2D( ms_normal_fai, tex_coords ).rg );
+	//gl_FragData[0] = vec4( bloom*2, 1.0 );
+}
+

+ 12 - 0
shaders/pps.shdr

@@ -0,0 +1,12 @@
+VERTEX_SHADER "shaders/simple.vert"
+FRAGMENT_SHADER "shaders/pps.frag"
+
+PREPROCESSOR_DEFINES
+{
+}
+
+FRAGMENT_SHADER_INCLUDES
+{
+	"shaders/photoshop_filters.glsl"
+}
+

+ 13 - 0
shaders/pps_bloom_final.shdr

@@ -0,0 +1,13 @@
+VERTEX_SHADER "shaders/simple.vert"
+FRAGMENT_SHADER "shaders/pps_bloom_generic.frag"
+
+PREPROCESSOR_DEFINES
+{
+	"#define _BLOOM_FINAL_"
+}
+
+UNIFORMS
+{
+	bloom_final_fai = 0
+}
+

+ 72 - 0
shaders/pps_bloom_generic.frag

@@ -0,0 +1,72 @@
+// the first pass is for horizontal blur and the second for vertical
+
+varying vec2 tex_coords;
+
+#if defined( _BLOOM_VBLUR_ )
+	uniform sampler2D is_fai;
+#elif defined ( _BLOOM_FINAL_ )
+	uniform sampler2D bloom_final_fai;
+#else
+	#error "something is wrong"
+#endif
+
+
+
+/*
+=======================================================================================================================================
+main                                                                                                                                  =
+=======================================================================================================================================
+*/
+void main (void)
+{
+	const float super_offset = 1.;
+	#if defined( _BLOOM_VBLUR_ )
+		const float offset = 1.0 / (R_W*R_Q*BLOOM_RENDERING_QUALITY) * super_offset; // 1 / width_of_the_IS_FAI     !!!!!!!!!!!!!!!!!!!!!!!
+	#else
+		const float offset = 1.0 / (R_H*R_Q*BLOOM_RENDERING_QUALITY) * super_offset; // 1 / height_of_the_BLOOM_FAI
+	#endif
+
+	const int kernel_size = 7;
+	float kernel[kernel_size];
+	kernel[0] = -3.0 * offset;
+	kernel[1] = -2.0 * offset;
+	kernel[2] = -1.0 * offset;
+	kernel[3] = 0.0 * offset;
+	kernel[4] = 1.0 * offset;
+	kernel[5] = 2.0 * offset;
+	kernel[6] = 3.0 * offset;
+	/*kernel[7] = -4.0 * offset;
+	kernel[8] = 4.0 * offset;
+	kernel[9] = -5.0 * offset;
+	kernel[10] = 5.0 * offset;*/
+
+	//float bloom_factor = 0.0; // ORIGINAL BLOOM CODE
+	vec3 bloom = vec3(0.0);
+
+	for( int i=0; i<kernel_size; i++ )
+	{
+		#if defined( _BLOOM_VBLUR_ )
+			vec3 color = texture2D( is_fai, tex_coords + vec2(kernel[i], 0.0) ).rgb;
+
+			float Y = dot(vec3(0.30, 0.59, 0.11), color);
+			const float exposure = 4.0;
+			const float brightMax = 4.0;
+			float YD = exposure * (exposure/brightMax + 1.0) / (exposure + 1.0) * Y;
+			color *= YD;
+
+			bloom += color;
+			//vec3 color = texture2D( is_fai, tex_coords + vec2(kernel[i], 0.0) ).rgb; // ORIGINAL BLOOM CODE
+			//bloom_factor += dot(tex,tex); // ORIGINAL BLOOM CODE
+		#else
+			vec3 color = texture2D( bloom_final_fai, tex_coords + vec2(0.0, kernel[i]) ).rgb;
+			bloom += color;
+
+			//float factor = texture2D( bloom_final_fai, tex_coords + vec2(0.0, kernel[i]) ).r; // ORIGINAL BLOOM CODE
+			//bloom_factor += factor; // ORIGINAL BLOOM CODE
+		#endif
+	}
+
+	gl_FragColor.rgb = bloom * (1.0/kernel_size);
+	//gl_FragColor.r = bloom_factor * (1.0/7.0); // ORIGINAL BLOOM CODE
+}
+

+ 13 - 0
shaders/pps_bloom_vblur.shdr

@@ -0,0 +1,13 @@
+VERTEX_SHADER "shaders/simple.vert"
+FRAGMENT_SHADER "shaders/pps_bloom_generic.frag"
+
+PREPROCESSOR_DEFINES
+{
+	"#define _BLOOM_VBLUR_"
+}
+
+UNIFORMS
+{
+	is_fai = 0
+}
+

+ 48 - 0
shaders/pps_lscatt.frag

@@ -0,0 +1,48 @@
+//
+
+const int SAMPLES_NUM = 100;
+
+float exposure = 2.0;
+float decay = 0.8;
+float density = 1.0;
+float weight = 0.3;
+vec2 light_pos_screen_space = vec2(0.5, 0.5);
+
+uniform sampler2D ms_depth_fai;
+uniform sampler2D is_fai;
+
+varying vec2 tex_coords;
+
+
+
+void main()
+{
+	vec2 delta_tex_coord = tex_coords - light_pos_screen_space;
+	vec2 tex_coords2 = tex_coords;
+	delta_tex_coord *= 1.0 / float(SAMPLES_NUM) * density;
+	float illumination_decay = 1.0;
+
+	gl_FragData[0].rgb = vec3(0.0);
+
+	for( int i=0; i<SAMPLES_NUM; i++ )
+	{
+		tex_coords2 -= delta_tex_coord;
+
+		float depth = texture2D( ms_depth_fai, tex_coords2 ).r;
+		if( depth != 1.0 ) // if the fragment is not part of the skybox dont bother continuing
+		{
+			illumination_decay *= decay;
+			continue;
+		}
+
+		vec3 sample = texture2D( is_fai, tex_coords2 ).rgb;			
+		sample *= illumination_decay * weight;
+		gl_FragData[0].rgb += sample;
+		illumination_decay *= decay;
+	}
+
+	gl_FragData[0].rgb *= exposure;
+	
+	//gl_FragData[0].rgb = texture2D( is_fai, tex_coords ).rgb;
+	//gl_FragData[0].rgb = vec3(1, 1, 0);
+}

+ 18 - 0
shaders/pps_lscatt.shdr

@@ -0,0 +1,18 @@
+//
+VERTEX_SHADER "shaders/simple.vert"
+FRAGMENT_SHADER "shaders/pps_lscatt.frag"
+
+PREPROCESSOR_DEFINES
+{
+}
+
+FRAGMENT_SHADER_INCLUDES
+{
+}
+
+UNIFORM_VARS
+{
+	ms_depth_fai = 0
+	is_fai = 1
+}
+

+ 238 - 0
shaders/pps_ssao.frag

@@ -0,0 +1,238 @@
+//varying vec2 tex_coords;
+//uniform vec2 camerarange;  // = vec2( znear, zfar )
+//uniform sampler2D ms_depth_fai;
+//uniform sampler2D noise_map;
+//
+//
+////float SSAOComponent( in float _ldepth, in float _sdepth, in float _ao_multiplier )
+////{
+////	const float _ao_cap = 1.0;
+////	const float _depth_tolerance = 0.0001;
+////	float ao0 = min( _ao_cap, max(0.0,_ldepth-_sdepth-_depth_tolerance) * _ao_multiplier );
+////
+////	float zd = max(_ldepth-_sdepth,0.0)*50.0;
+////	float gauss = pow(2.7182,-2.0*zd*zd);
+////	float ao1 = (zd*gauss*2.0);
+////
+////	return ao1 * 1.5 + ao0 * 0.8;
+////}
+////
+////
+////float SSAO()
+////{
+////	float _ldepth = ReadLinearDepth(tex_coords);
+////	float _sdepth;
+////
+////	float pw = 1.0 / screensize.x;
+////	float ph = 1.0 / screensize.y;
+////	const float p_factor = 2.0;
+////
+////	float al_mul = 200.0;
+////	const float ao_mul_factor = 0.6; // default 0.5
+////
+////	float ao = 0.0;
+////
+////	_sdepth = ReadLinearDepth( vec2(tex_coords.x+pw,tex_coords.y+ph) );
+////	ao += SSAOComponent(_ldepth, _sdepth, al_mul);
+////
+////	_sdepth = ReadLinearDepth( vec2(tex_coords.x-pw,tex_coords.y+ph) );
+////	ao += SSAOComponent(_ldepth, _sdepth, al_mul);
+////
+////	_sdepth = ReadLinearDepth( vec2(tex_coords.x+pw,tex_coords.y-ph) );
+////	ao += SSAOComponent(_ldepth, _sdepth, al_mul);
+////
+////	_sdepth = ReadLinearDepth( vec2(tex_coords.x-pw,tex_coords.y-ph) );
+////	ao += SSAOComponent(_ldepth, _sdepth, al_mul);
+////
+////	pw*=p_factor;
+////	ph*=p_factor;
+////	al_mul *= ao_mul_factor;
+////
+////	_sdepth = ReadLinearDepth( vec2(tex_coords.x+pw,tex_coords.y+ph));
+////	ao += SSAOComponent(_ldepth, _sdepth, al_mul);
+////
+////	_sdepth = ReadLinearDepth( vec2(tex_coords.x-pw,tex_coords.y+ph));
+////	ao += SSAOComponent(_ldepth, _sdepth, al_mul);
+////
+////	_sdepth = ReadLinearDepth( vec2(tex_coords.x+pw,tex_coords.y-ph));
+////	ao += SSAOComponent(_ldepth, _sdepth, al_mul);
+////
+////	_sdepth = ReadLinearDepth( vec2(tex_coords.x-pw,tex_coords.y-ph));
+////	ao += SSAOComponent(_ldepth, _sdepth, al_mul);
+////
+////	pw*=p_factor;
+////	ph*=p_factor;
+////	al_mul *= ao_mul_factor;
+////
+////	_sdepth = ReadLinearDepth( vec2(tex_coords.x+pw,tex_coords.y+ph));
+////	ao += SSAOComponent(_ldepth, _sdepth, al_mul);
+////
+////	_sdepth = ReadLinearDepth( vec2(tex_coords.x-pw,tex_coords.y+ph));
+////	ao += SSAOComponent(_ldepth, _sdepth, al_mul);
+////
+////	_sdepth = ReadLinearDepth( vec2(tex_coords.x+pw,tex_coords.y-ph));
+////	ao += SSAOComponent(_ldepth, _sdepth, al_mul);
+////
+////	_sdepth = ReadLinearDepth( vec2(tex_coords.x-pw,tex_coords.y-ph));
+////	ao += SSAOComponent(_ldepth, _sdepth, al_mul);
+////
+////	pw*=p_factor;
+////	ph*=p_factor;
+////	al_mul *= ao_mul_factor;
+////
+////	_sdepth = ReadLinearDepth( vec2(tex_coords.x+pw,tex_coords.y+ph));
+////	ao += SSAOComponent(_ldepth, _sdepth, al_mul);
+////
+////	_sdepth = ReadLinearDepth( vec2(tex_coords.x-pw,tex_coords.y+ph));
+////	ao += SSAOComponent(_ldepth, _sdepth, al_mul);
+////
+////	_sdepth = ReadLinearDepth( vec2(tex_coords.x+pw,tex_coords.y-ph));
+////	ao += SSAOComponent(_ldepth, _sdepth, al_mul);
+////
+////	_sdepth = ReadLinearDepth( vec2(tex_coords.x-pw,tex_coords.y-ph));
+////	ao += SSAOComponent(_ldepth, _sdepth, al_mul);
+////
+////	ao *= 0.0625; // aka: ao/=16.0;
+////
+////	return 1.0-ao;
+////}
+//
+//float SSAO()
+//{
+//	float prof = ReadFromTexAndLinearizeDepth( ms_depth_fai, tex_coords, camerarange.x, camerarange.y );
+//	if( prof == 0.0 || prof == 1.0 ) return 1.0; // check for skybox
+//
+//	vec2 kernel[8];
+//	kernel[0] = vec2(-1,1);
+//	kernel[1] = vec2(0,1);
+//	kernel[2] = vec2(1,1);
+//	kernel[3] = vec2(1,0);
+//	kernel[4] = vec2(1,-1);
+//	kernel[5] = vec2(0,-1);
+//	kernel[6] = vec2(-1,-1);
+//	kernel[7] = vec2(-1,0);
+//	kernel[7] = vec2(0,0);
+////	kernel[8] = vec2(2,0);
+////	kernel[9] = vec2(2,2);
+////	kernel[10] = vec2(0,2);
+////	kernel[11] = vec2(-2,2);
+////	kernel[12] = vec2(-2,0);
+////	kernel[13] = vec2(-2,-2);
+////	kernel[14] = vec2(0,-2);
+////	kernel[15] = vec2(2,-2);
+//
+//	float sum = 0.0;
+//
+//	vec2 fres = vec2(160, 160);//tiling of the random texture across screen.
+//	vec3 random = texture2D( noise_map, tex_coords*fres.xy ).rgb;
+//	//return texture2D( noise_map, tex_coords ).r;
+//	//return random.r;
+//	random = random - .5; //we obtain the difference (color-gray) so that there are negative values also.
+//	//random = normalize( random );
+//	//return random.r;
+//
+//	//calculate sampling rates:
+//	const float radx = (1.0/(R_W*R_Q));
+//	const float rady = (1.0/(R_H*R_Q));
+//
+//	for( int i=0; i<9; i++ )
+//	{
+//		vec2 point = vec2( kernel[i].x*radx, kernel[i].y*rady )+random.xy*0.09;
+//		vec2 sp = tex_coords+point/prof; //divide by the depth value so that the sampling area gets smaller with depth.
+//
+//		float prof2 = ReadFromTexAndLinearizeDepth( ms_depth_fai, sp, camerarange.x, camerarange.y );
+//
+//		float zd = max(prof-prof2,0.0)*50; //depth difference*50
+//		float gauss = pow(2.7182,-2*zd*zd); //gaussian falloff
+//
+//		float factor0 = zd*gauss*2;
+//		float factor1 = (prof-prof2)*3;
+//
+//		sum += (factor0 + factor1)*0.5;
+//		//sum += factor1;
+//	}
+//
+//	float ssao_factor = (1.0-sum/9.0);
+//	return pow(ssao_factor,5.0); //white-occlusion
+//}
+//
+//
+///*
+//=======================================================================================================================================
+//main                                                                                                                                  =
+//=======================================================================================================================================
+//*/
+//void main (void)
+//{
+//	gl_FragColor.a = SSAO();
+//}
+
+
+
+uniform sampler2D noise_map;
+uniform sampler2D ms_normal_fai;
+uniform sampler2D ms_depth_fai;
+uniform vec2 camerarange;  // = vec2( znear, zfar )
+varying vec2 tex_coords;
+const float totStrength = 1.0;
+const float strength = 0.07;
+const float offset = 18.0;
+const float falloff = 0.000002;
+const float rad = 0.006;
+const int SAMPLES = 16; // 10 is good
+const float invSamples = 1.0/float(SAMPLES);
+
+void main(void)
+{
+	// these are the random vectors inside a unit sphere
+	vec3 pSphere[16] = vec3[](vec3(0.53812504, 0.18565957, -0.43192),vec3(0.13790712, 0.24864247, 0.44301823),vec3(0.33715037, 0.56794053, -0.005789503),vec3(-0.6999805, -0.04511441, -0.0019965635),vec3(0.06896307, -0.15983082, -0.85477847),vec3(0.056099437, 0.006954967, -0.1843352),vec3(-0.014653638, 0.14027752, 0.0762037),vec3(0.010019933, -0.1924225, -0.034443386),vec3(-0.35775623, -0.5301969, -0.43581226),vec3(-0.3169221, 0.106360726, 0.015860917),vec3(0.010350345, -0.58698344, 0.0046293875),vec3(-0.08972908, -0.49408212, 0.3287904),vec3(0.7119986, -0.0154690035, -0.09183723),vec3(-0.053382345, 0.059675813, -0.5411899),vec3(0.035267662, -0.063188605, 0.54602677),vec3(-0.47761092, 0.2847911, -0.0271716));
+	//const vec3 pSphere[8] = vec3[](vec3(0.24710192, 0.6445882, 0.033550154),vec3(0.00991752, -0.21947019, 0.7196721),vec3(0.25109035, -0.1787317, -0.011580509),vec3(-0.08781511, 0.44514698, 0.56647956),vec3(-0.011737816, -0.0643377, 0.16030222),vec3(0.035941467, 0.04990871, -0.46533614),vec3(-0.058801126, 0.7347013, -0.25399926),vec3(-0.24799341, -0.022052078, -0.13399573));
+	//const vec3 pSphere[12] = vec3[](vec3(-0.13657719, 0.30651027, 0.16118456),vec3(-0.14714938, 0.33245975, -0.113095455),vec3(0.030659059, 0.27887347, -0.7332209),vec3(0.009913514, -0.89884496, 0.07381549),vec3(0.040318526, 0.40091, 0.6847858),vec3(0.22311053, -0.3039437, -0.19340435),vec3(0.36235332, 0.21894878, -0.05407306),vec3(-0.15198798, -0.38409665, -0.46785462),vec3(-0.013492276, -0.5345803, 0.11307949),vec3(-0.4972847, 0.037064247, -0.4381323),vec3(-0.024175806, -0.008928787, 0.17719103),vec3(0.694014, -0.122672155, 0.33098832));
+	//const vec3 pSphere[10] = vec3[](vec3(-0.010735935, 0.01647018, 0.0062425877),vec3(-0.06533369, 0.3647007, -0.13746321),vec3(-0.6539235, -0.016726388, -0.53000957),vec3(0.40958285, 0.0052428036, -0.5591124),vec3(-0.1465366, 0.09899267, 0.15571679),vec3(-0.44122112, -0.5458797, 0.04912532),vec3(0.03755566, -0.10961345, -0.33040273),vec3(0.019100213, 0.29652783, 0.066237666),vec3(0.8765323, 0.011236004, 0.28265962),vec3(0.29264435, -0.40794238, 0.15964167));
+	// grab a normal for reflecting the sample rays later on
+	vec3 fres = normalize((texture2D(noise_map,tex_coords*offset).xyz*2.0) - vec3(1.0));
+
+	vec4 currentPixelSample = texture2D(ms_normal_fai,tex_coords);
+
+	float currentPixelDepth = ReadFromTexAndLinearizeDepth( ms_depth_fai, tex_coords, camerarange.x, camerarange.y );
+
+	// current fragment coords in screen space
+	vec3 ep = vec3( tex_coords.xy, currentPixelDepth );
+	// get the normal of current fragment
+	vec3 norm = UnpackNormal(currentPixelSample.xy);
+
+	float bl = 0.0;
+	// adjust for the depth ( not shure if this is good..)
+	float radD = rad/currentPixelDepth;
+
+	vec3 ray, se, occNorm;
+	float occluderDepth, depthDifference, normDiff;
+
+	for( int i=0; i<SAMPLES; ++i )
+	{
+		// get a vector (randomized inside of a sphere with radius 1.0) from a texture and reflect it
+		ray = radD*reflect(pSphere[i],fres);
+
+		// if the ray is outside the hemisphere then change direction
+		se = ep + sign(dot(ray,norm) )*ray;
+
+		// get the depth of the occluder fragment
+		vec4 occluderFragment = texture2D(ms_normal_fai,se.xy);
+
+		// get the normal of the occluder fragment
+		occNorm = UnpackNormal(occluderFragment.xy);
+
+		// if depthDifference is negative = occluder is behind current fragment
+		depthDifference = currentPixelDepth - ReadFromTexAndLinearizeDepth( ms_depth_fai, se.xy, camerarange.x, camerarange.y );;
+
+		// calculate the difference between the normals as a weight
+
+		normDiff = (1.0-dot(occNorm,norm));
+		// the falloff equation, starts at falloff and is kind of 1/x^2 falling
+		bl += step(falloff,depthDifference)*normDiff*(1.0-smoothstep(falloff,strength,depthDifference));
+	}
+
+	// output the result
+	float ao = 1.0-totStrength*bl*invSamples;
+	gl_FragColor.a = ao;
+}

+ 21 - 0
shaders/pps_ssao.shdr

@@ -0,0 +1,21 @@
+//
+VERTEX_SHADER "shaders/simple.vert"
+FRAGMENT_SHADER "shaders/pps_ssao.frag"
+
+PREPROCESSOR_DEFINES
+{
+}
+
+FRAGMENT_SHADER_INCLUDES
+{
+	"shaders/linear_depth.glsl"
+	"shaders/pack.glsl"
+}
+
+UNIFORMS
+{
+	camerarange = 0
+	ms_depth_fai = 1
+	noise_map = 2
+}
+

+ 18 - 0
shaders/simple.vert

@@ -0,0 +1,18 @@
+/** 
+ * Simple vertex shader for IS and PPS stages. It is used for rendering a quad in the 
+ * screen. Notice that it does not use ftransform(). We dont need it because we can
+ * get the Normalized Display Coordinates ([-1,1]) simply by looking in the vertex
+ * position. The vertex positions of the quad are from 0.0 to 1.0 for both axis.
+ */
+
+varying vec2 tex_coords;
+
+void main()
+{
+	vec2 vert_pos = gl_Vertex.xy; // the vert coords are {1.0,1.0}, {0.0,1.0}, {0.0,0.0}, {1.0,0.0}
+	tex_coords = vert_pos;
+	vec2 vert_pos_ndc = vert_pos*2.0 - 1.0;
+	gl_Position = vec4( vert_pos_ndc, 0.0, 1.0 );
+}
+
+

+ 27 - 0
shaders/simple_texturing.frag

@@ -0,0 +1,27 @@
+uniform sampler2D diffuse_map, noise_map;
+varying vec2 tex_coords;
+varying vec3 normal;
+
+vec3 DecodeNormal( in vec2 _enc )
+{
+	float _scale = 1.7777;
+	vec3 _nn = vec3( _enc*vec2(2.0*_scale, 2.0*_scale) + vec2(-_scale, -_scale), 1.0 );
+	float _g = 2.0 / dot(_nn.xyz, _nn.xyz);
+	vec3 _normal;
+	_normal.xy = _g * _nn.xy;
+	_normal.z = _g - 1.0;
+	return _normal;
+}
+
+void main()
+{
+	/*vec3 _noise = DecodeNormal( texture2D( noise_map, gl_FragCoord.xy*vec2( 1.0/R_W, 1.0/R_H ) ).rg ).rgb;
+	_noise = _noise * 2 - 1;
+	_noise *= 7.0;*/
+	vec4 _texel = texture2D( diffuse_map, (gl_FragCoord.xy+(normal.xy*2))*vec2( 1.0/R_W, 1.0/R_H ) );
+
+
+	//vec4 _texel = texture2D( diffuse_map, tex_coords );
+
+	gl_FragColor = _texel;
+}

+ 2 - 0
shaders/simple_texturing.shdr

@@ -0,0 +1,2 @@
+VERTEX_SHADER "shaders/simple_texturing.vert"
+FRAGMENT_SHADER "shaders/simple_texturing.frag"

+ 9 - 0
shaders/simple_texturing.vert

@@ -0,0 +1,9 @@
+varying vec2 tex_coords;
+varying vec3 normal;
+
+void main()
+{
+	tex_coords = gl_MultiTexCoord0.xy;
+	normal = gl_NormalMatrix * gl_Normal;
+	gl_Position = ftransform();
+}

+ 11 - 0
shaders/txt.frag

@@ -0,0 +1,11 @@
+uniform sampler2D font_map;
+varying vec2 tex_coords;
+
+void main()
+{
+	vec2 tex_col = texture2D( font_map, tex_coords ).ra; // get only one value and the alpha
+
+	if( tex_col.y == 0.0 ) discard;
+
+	gl_FragColor = vec4(tex_col.x) * gl_Color;
+}

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden.