Quellcode durchsuchen

- Scripting intefaces
- Texture mipmaping selection

Panagiotis Christopoulos Charitos vor 15 Jahren
Ursprung
Commit
00e93ada22

+ 185 - 182
shaders/IsLpGeneric.glsl

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

+ 4 - 4
src/Main.cpp

@@ -77,7 +77,7 @@ void initPhysics()
 	init.shape = groundShape;
 	init.startTrf = groundTransform;
 
-	new RigidBody(*app->getScene().getPhysics(), init);
+	new RigidBody(app->getScene().getPhysics(), init);
 
 
 	/*{
@@ -210,7 +210,7 @@ void init()
 	PhyCharacter::Initializer init;
 	init.sceneNode = imp;
 	init.startTrf = Transform(Vec3(0, 40, 0), Mat3::getIdentity(), 1.0);
-	character = new PhyCharacter(*app->getScene().getPhysics(), init);
+	character = new PhyCharacter(app->getScene().getPhysics(), init);
 
 	// crate
 	/*crate = new MeshNode;
@@ -304,12 +304,12 @@ void mainLoop()
 		{
 			INFO("Exec script");
 			app->getScriptingEngine().exposeVar("app", app);
-			app->getScriptingEngine().execScript("#from Anki import *\nAnki.app.getScene().setAmbientCol(Anki.Vec3(0.5))");
+			app->getScriptingEngine().execScript(Util::readFile("test.py").c_str());
 		}
 
 		mover->getLocalTransform().getRotation().reorthogonalize();
 
-		app->getScene().getPhysics()->update(crntTime);
+		app->getScene().getPhysics().update(crntTime);
 
 		app->getScene().updateAllControllers();
 		app->getScene().updateAllWorldStuff();

+ 17 - 22
src/Math/Vec2.h

@@ -13,9 +13,8 @@ class Vec2
 {
 	public:
 		// data members
-		float x, y;
-		static const Vec2 zero;
-		static const Vec2 one;
+		float x;
+		float y;
 		// accessors
 		float& operator [](uint i);
 		float  operator [](uint i) const;
@@ -27,35 +26,31 @@ class Vec2
 		explicit Vec2(const Vec3& v3);
 		explicit Vec2(const Vec4& v4);
 		// ops with same type
-		Vec2  operator + (const Vec2& b) const;
+		Vec2 operator +(const Vec2& b) const;
 		Vec2& operator +=(const Vec2& b);
-		Vec2  operator - (const Vec2& b) const;
+		Vec2 operator -(const Vec2& b) const;
 		Vec2& operator -=(const Vec2& b);
-		Vec2  operator * (const Vec2& b) const;
+		Vec2 operator *(const Vec2& b) const;
 		Vec2& operator *=(const Vec2& b);
-		Vec2  operator / (const Vec2& b) const;
+		Vec2 operator /(const Vec2& b) const;
 		Vec2& operator /=(const Vec2& b);
-		Vec2  operator - () const;
+		Vec2 operator -() const;
+		bool operator ==(const Vec2& b) const;
+		bool operator !=(const Vec2& b) const;
 		// ops with float
-		Vec2  operator + (float f) const;
+		Vec2 operator +(float f) const;
 		Vec2& operator +=(float f);
-		Vec2  operator - (float f) const;
+		Vec2 operator -(float f) const;
 		Vec2& operator -=(float f);
-		Vec2  operator * (float f) const;
+		Vec2 operator *(float f) const;
 		Vec2& operator *=(float f);
-		Vec2  operator / (float f) const;
+		Vec2 operator /(float f) const;
 		Vec2& operator /=(float f);
-		// comparision
-		bool operator ==(const Vec2& b) const;
-		bool operator !=(const Vec2& b) const;
 		// other
-		static Vec2 getZero();
-		static Vec2 getOne();
-		float  getLength() const;
-		void   setZero();
-		void   normalize();
-		Vec2   getNormalized() const;
-		float  dot(const Vec2& b) const;
+		float getLength() const;
+		Vec2 getNormalized() const;
+		void normalize();
+		float dot(const Vec2& b) const;
 };
 
 

+ 0 - 18
src/Math/Vec2.inl.h

@@ -199,12 +199,6 @@ inline float Vec2::getLength() const
 	return M::sqrt(x*x + y*y);
 }
 
-// set to zero
-inline void Vec2::setZero()
-{
-	x = y = 0.0;
-}
-
 // normalize
 inline void Vec2::normalize()
 {
@@ -223,18 +217,6 @@ inline float Vec2::dot(const Vec2& b) const
 	return x*b.x + y*b.y;
 }
 
-// getZero
-inline Vec2 Vec2::getZero()
-{
-	return Vec2(0.0);
-}
-
-// getOne
-inline Vec2 Vec2::getOne()
-{
-	return Vec2(1.0);
-}
-
 // print
 inline ostream& operator<<(ostream& s, const Vec2& v)
 {

+ 1 - 1
src/Renderer/Dbg.cpp

@@ -277,7 +277,7 @@ void Renderer::Dbg::run()
 	// Physics
 	glPolygonMode(GL_FRONT, GL_LINE);
 	setModelMat(Mat4::getIdentity());
-	app->getScene().getPhysics()->debugDraw();
+	app->getScene().getPhysics().debugDraw();
 	glPolygonMode(GL_FRONT, GL_FILL);
 }
 

+ 1 - 1
src/Resources/Core/RsrcPtr.h

@@ -50,7 +50,6 @@ class RsrcPtr
 // Inlines                                                                                                             =
 //======================================================================================================================
 
-
 template<typename Type>
 RsrcPtr<Type>::RsrcPtr():
 	p(NULL)
@@ -86,4 +85,5 @@ Type* RsrcPtr<Type>::get() const
 	return p;
 }
 
+
 #endif

+ 2 - 1
src/Resources/LightProps.cpp

@@ -1,4 +1,5 @@
 #include <cstring>
+#include <GL/glew.h>
 #include "LightProps.h"
 #include "Parser.h"
 #include "Texture.h"
@@ -104,7 +105,7 @@ bool LightProps::load(const char* filename)
 				
 			texture.loadRsrc(token->getValue().getString());
 			texture->setRepeat(false);
-			texture->setTexParameter(GL_TEXTURE_MAX_ANISOTROPY_EXT, 0);
+			texture->setAnisotropy(0);
 			texture->setTexParameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 			texture->setTexParameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 		}

+ 32 - 9
src/Resources/Texture.cpp

@@ -52,15 +52,15 @@ bool Texture::load(const char* filename)
 
 	setTexParameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 
-	texParameter(GL_TEXTURE_MAX_ANISOTROPY_EXT, float(anisotropyLevel));
+	setTexParameter(GL_TEXTURE_MAX_ANISOTROPY_EXT, float(anisotropyLevel));
 
 	// leave to GL_REPEAT. There is not real performance hit
 	setRepeat(true);
 
 	// chose formats
-	GLint internalFormat;
-	GLint format;
-	GLint type;
+	int internalFormat;
+	int format;
+	int type;
 	switch(img.getType())
 	{
 		case Image::CT_R:
@@ -89,6 +89,9 @@ bool Texture::load(const char* filename)
 	if(mipmappingEnabled)
 		glGenerateMipmap(target);
 
+
+	setMipmapLevel(3);
+
 	return GL_OK();
 }
 
@@ -96,7 +99,7 @@ bool Texture::load(const char* filename)
 //======================================================================================================================
 // createEmpty2D                                                                                                       =
 //======================================================================================================================
-bool Texture::createEmpty2D(float width_, float height_, int internalFormat, int format_, GLenum type_)
+bool Texture::createEmpty2D(float width_, float height_, int internalFormat, int format_, uint type_)
 {
 	target = GL_TEXTURE_2D;
 	DEBUG_ERR(internalFormat > 0 && internalFormat <= 4); // deprecated internal format
@@ -188,7 +191,7 @@ int Texture::getHeight() const
 //======================================================================================================================
 // setTexParameter [int]                                                                                               =
 //======================================================================================================================
-void Texture::setTexParameter(GLenum paramName, GLint value) const
+void Texture::setTexParameter(uint paramName, int value) const
 {
 	bind(LAST_TEX_UNIT);
 	glTexParameteri(target, paramName, value);
@@ -198,7 +201,7 @@ void Texture::setTexParameter(GLenum paramName, GLint value) const
 //======================================================================================================================
 // setTexParameter [float]                                                                                             =
 //======================================================================================================================
-void Texture::texParameter(GLenum paramName, GLfloat value) const
+void Texture::setTexParameter(uint paramName, float value) const
 {
 	bind(LAST_TEX_UNIT);
 	glTexParameterf(target, paramName, value);
@@ -241,7 +244,7 @@ int Texture::getBaseLevel() const
 //======================================================================================================================
 uint Texture::getActiveTexUnit()
 {
-	GLint unit;
+	int unit;
 	glGetIntegerv(GL_ACTIVE_TEXTURE, &unit);
 	return unit - GL_TEXTURE0;
 }
@@ -252,7 +255,7 @@ uint Texture::getActiveTexUnit()
 //======================================================================================================================
 uint Texture::getBindedTexId(uint unit)
 {
-	GLint id;
+	int id;
 	glActiveTexture(GL_TEXTURE0 + unit);
 	glGetIntegerv(GL_TEXTURE_BINDING_2D, &id);
 	return id;
@@ -269,3 +272,23 @@ int Texture::getMaxLevel() const
 	glGetTexParameteriv(target, GL_TEXTURE_MAX_LEVEL, &level);
 	return level;
 }
+
+
+//======================================================================================================================
+// setAnisotropy                                                                                                       =
+//======================================================================================================================
+void Texture::setAnisotropy(uint level)
+{
+	bind(LAST_TEX_UNIT);
+	setTexParameter(GL_TEXTURE_MAX_ANISOTROPY_EXT, int(level));
+}
+
+
+//======================================================================================================================
+// setMipmapLevel                                                                                                      =
+//======================================================================================================================
+void Texture::setMipmapLevel(uint level)
+{
+	bind(LAST_TEX_UNIT);
+	setTexParameter(GL_TEXTURE_BASE_LEVEL, int(level));
+}

+ 16 - 10
src/Resources/Texture.h

@@ -1,7 +1,6 @@
 #ifndef TEXTURE_H
 #define TEXTURE_H
 
-#include <GL/glew.h>
 #include <limits>
 #include "Common.h"
 #include "Resource.h"
@@ -24,27 +23,34 @@ class Texture: public Resource
 		 Texture();
 		~Texture() {}
 
-		GLuint getGlId() const;
-		int getWidth() const;
-		int getHeight() const;
+		uint getGlId() const;
 
+		/**
+		 * @name Create tex funcs
+		 */
+		/**@{*/
 		bool load(const char* filename);
 		void unload();
-		bool createEmpty2D(float width, float height, int internalFormat, int format, GLenum type_);
+		bool createEmpty2D(float width, float height, int internalFormat, int format, uint type_);
 		bool createEmpty2DMsaa(int samplesNum, int internalFormat, int width_, int height_, bool mimapping);
+		/**@}*/
 
 		void bind(uint texUnit = 0) const;
 		void setRepeat(bool repeat) const;
-		void setTexParameter(GLenum paramName, GLint value) const;
-		void texParameter(GLenum paramName, GLfloat value) const;
+		void setTexParameter(uint paramName, int value) const;
+		void setTexParameter(uint paramName, float value) const;
+		void setAnisotropy(uint level);
+		void setMipmapLevel(uint level);
+		int getWidth() const;
+		int getHeight() const;
 		int getBaseLevel() const;
 		int getMaxLevel() const;
 		static uint getActiveTexUnit();
 		static uint getBindedTexId(uint unit);
 
 	private:
-		GLuint glId; ///< Identification for OGL
-		GLenum target; ///< GL_TEXTURE_2D, GL_TEXTURE_3D... etc
+		uint glId; ///< Identification for OGL
+		uint target; ///< GL_TEXTURE_2D, GL_TEXTURE_3D... etc
 
 		/**
 		 * @name Variables set by the renderer
@@ -61,7 +67,7 @@ class Texture: public Resource
 };
 
 
-inline GLuint Texture::getGlId() const
+inline uint Texture::getGlId() const
 {
 	DEBUG_ERR(!isLoaded());
 	return glId;

+ 1 - 1
src/Scene/ParticleEmitter.cpp

@@ -58,7 +58,7 @@ void ParticleEmitter::init(const char* filename)
 		init.sceneNode = particle;
 		init.group = Physics::CG_PARTICLE;
 		init.mask = Physics::CG_ALL ^ Physics::CG_PARTICLE;
-		RigidBody* body = new RigidBody(*app->getScene().getPhysics(), init);
+		RigidBody* body = new RigidBody(app->getScene().getPhysics(), init);
 
 		body->forceActivationState(DISABLE_SIMULATION);
 

+ 1 - 1
src/Scene/Scene.cpp

@@ -18,7 +18,7 @@ Scene::Scene(Object* parent):
 	ambientCol = Vec3(0.1, 0.05, 0.05)*4;
 	sunPos = Vec3(0.0, 1.0, -1.0) * 50.0;
 
-	phyWorld = new Physics(this);
+	physics = new Physics(this);
 }
 
 

+ 21 - 2
src/Scene/Scene.h

@@ -22,9 +22,9 @@ class ParticleEmitter;
  */
 class Scene: public Object
 {
-	PROPERTY_RW(Vec3, ambientCol, setAmbientCol, getAmbientCol) ///< The global ambient color
+	//PROPERTY_RW(Vec3, ambientCol, setAmbientCol, getAmbientCol) ///< The global ambient color
 	PROPERTY_RW(Vec3, sunPos, setSunPos, getSunPos)
-	PROPERTY_R(Physics*, phyWorld, getPhysics) ///< Connection with bullet
+	//PROPERTY_R(Physics*, phyWorld, getPhysics) ///< Connection with bullet
 
 	public:
 		/**
@@ -55,7 +55,19 @@ class Scene: public Object
 		void updateAllWorldStuff();
 		void updateAllControllers();
 
+		/**
+		 * @name Accessors
+		 */
+		/**@{*/
+		Vec3& getAmbientCol() {return ambientCol;}
+		void setAmbientCol(const Vec3& col) {ambientCol = col;}
+		Physics& getPhysics();
+		/**@}*/
+
 	private:
+		Vec3 ambientCol; ///< The global ambient color
+		Physics* physics; ///< Connection with Bullet wrapper
+
 		/**
 		 * Adds a node in a container
 		 */
@@ -87,4 +99,11 @@ inline void Scene::eraseNode(ContainerType& container, Type* x)
 }
 
 
+inline Physics& Scene::getPhysics()
+{
+	DEBUG_ERR(physics == NULL);
+	return *physics;
+}
+
+
 #endif

+ 38 - 0
src/Scripting/Math/Vec2.bpi.h

@@ -0,0 +1,38 @@
+
+class_<Vec2>("Vec2")
+	.def_readwrite("x", &Vec2::x)
+	.def_readwrite("y", &Vec2::y)
+	// constructors
+	.def(init<>())
+	.def(init<float>())
+	.def(init<float, float>())
+	.def(init<const Vec2&>())
+	.def(init<const Vec3&>())
+	.def(init<const Vec4&>())
+	// ops with same type
+	.def(self + self)
+	.def(self += self)
+	.def(self - self)
+	.def(self -= self)
+	.def(self * self)
+	.def(self *= self)
+	.def(self / self)
+	.def(self /= self)
+	.def(- self)
+	.def(self == self)
+	.def(self != self)
+	// ops with float
+	.def(self + float())
+	.def(self += float())
+	.def(self - float())
+	.def(self -= float())
+	.def(self * float())
+	.def(self *= float())
+	.def(self / float())
+	.def(self /= float())
+	// other
+	.def("getLength", &Vec2::getLength)
+	.def("getNormalized", &Vec2::getNormalized)
+	.def("normalize", &Vec2::normalize)
+	.def("dot", &Vec2::dot)
+;

+ 3 - 1
src/Scripting/Scene/Scene.bpi.h

@@ -1,3 +1,5 @@
 
 class_<Scene, noncopyable>("Scene", no_init)
-	.def("setAmbientCol", &Scene::setAmbientCol);
+	.def("setAmbientCol", &Scene::setAmbientCol)
+	.def("getAmbientCol", &Scene::getAmbientCol, return_value_policy<reference_existing_object>())
+;

+ 5 - 4
src/Util/Input.cpp

@@ -29,8 +29,8 @@ void reset(void)
 	DEBUG_ERR(mouseBtns.size() < 1);
 	memset(&keys[0], 0, keys.size()*sizeof(short));
 	memset(&mouseBtns[0], 0, mouseBtns.size()*sizeof(short));
-	mousePosNdc.setZero();
-	mouseVelocity.setZero();
+	mousePosNdc = Vec2(0.0);
+	mouseVelocity = Vec2(0.0);
 }
 
 
@@ -55,7 +55,7 @@ void handleEvents()
 	}
 
 
-	mouseVelocity.setZero();
+	mouseVelocity = Vec2(0.0);
 
 	SDL_Event event_;
 	while(SDL_PollEvent(&event_))
@@ -92,7 +92,8 @@ void handleEvents()
 				{
 					// the SDL_WarpMouse pushes an event in the event queue. This check is so we wont process the event of the...
 					// ...SDL_WarpMouse function
-					if(mousePosNdc == Vec2::getZero()) break;
+					if(mousePosNdc == Vec2(0.0))
+						break;
 
 					SDL_WarpMouse(app->getWindowWidth()/2, app->getWindowHeight()/2);
 				}