Index: /GTP/trunk/App/Demos/Illum/Ogre/Media/PMDemo/PRMDemo.material
===================================================================
--- /GTP/trunk/App/Demos/Illum/Ogre/Media/PMDemo/PRMDemo.material	(revision 2337)
+++ /GTP/trunk/App/Demos/Illum/Ogre/Media/PMDemo/PRMDemo.material	(revision 2404)
@@ -7,21 +7,11 @@
 	IllumTechniques
 	{
-	   	RenderTechnique PathMap
+	
+	  	RenderTechnique PathMap
 	 	{
-	    
-	  	}
-		RenderTechnique DepthShadowReceiver
-	  	{
-	    	max_light_count 2
-			vertex_program_name GTP/Basic/LightCPos_VS
-			fragment_program_name GTP/Basic/SM/Dist_VSM_PS
-			set_light_view true
-			set_light_farplane true
-			light_viewproj_param_name LightViewProj
-			light_view_param_name LightView
-			light_farplane_param_name lightFarPlane
-			world_view_proj_param_name WorldViewProj
-			world_param_name World
-	  	}
+	    		pass_blending one one
+	 	}
+	 
+		
 	}
 	vertex_program_ref GTP/Basic/ShadedTex_VS
@@ -31,10 +21,15 @@
 		param_named_auto WorldInv inverse_world_matrix
 	}
-	fragment_program_ref GTP/Basic/Shaded/TexturedOneLight_PS
+	fragment_program_ref GTP/Basic/Shaded/TexturedTwoLights_PS
 	{
-		param_named_auto lightPos light_position 0
-		param_named_auto lightDir light_direction 0
-		param_named_auto lightColor light_diffuse_colour 0
-		param_named_auto lightPower light_power 0
+		param_named_auto lightPos1 light_position 0
+		param_named_auto lightDir1 light_direction 0
+		param_named_auto lightColor1 light_diffuse_colour 0
+		param_named_auto lightPower1 light_power 0
+		
+		param_named_auto lightPos2 light_position 1
+		param_named_auto lightDir2 light_direction 1
+		param_named_auto lightColor2 light_diffuse_colour 1
+		param_named_auto lightPower2 light_power 1
 	}
    	texture_unit color
@@ -116,2 +111,37 @@
   }
 }
+
+
+
+RenderTechnique DepthShadowReceiver
+	 {
+	 		pass_blending one zero
+	    	max_light_count 1
+			vertex_program_name GTP/Basic/LightCPos_VS
+			//fragment_program_name GTP/Basic/SM/Dist_VSM_PS
+			fragment_program_name GTP/Basic/SM/Dist_PS
+			set_light_view true
+			set_light_farplane true
+			light_viewproj_param_name LightViewProj
+			light_view_param_name LightView
+			light_farplane_param_name lightFarPlane
+			world_view_proj_param_name WorldViewProj
+			world_param_name World
+	 }
+	 
+	 
+	  	RenderTechnique DepthShadowReceiver
+	 {
+	 		pass_blending zero src_colour
+	    	max_light_count 1
+			vertex_program_name GTP/Basic/LightCPos_VS
+			//fragment_program_name GTP/Basic/SM/Dist_VSM_PS
+			fragment_program_name GTP/Basic/SM/Dist_PS
+			set_light_view true
+			set_light_farplane true
+			light_viewproj_param_name LightViewProj
+			light_view_param_name LightView
+			light_farplane_param_name lightFarPlane
+			world_view_proj_param_name WorldViewProj
+			world_param_name World
+	 }
Index: /GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPEnvMap/GTPEnvMap.hlsl
===================================================================
--- /GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPEnvMap/GTPEnvMap.hlsl	(revision 2266)
+++ /GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPEnvMap/GTPEnvMap.hlsl	(revision 2404)
@@ -128,5 +128,5 @@
 	RR = R;	
 	RR = Hit(cubePos, R, DistanceMap);
-	Color = readCubeMap(CubeMap, RR);
+	Color = readCubeMap(CubeMap, R);
 	//Color = readDistanceCubeMap(DistanceMap, cubePos)/300.0;
 	//return Color;
Index: /GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/difflab.material
===================================================================
--- /GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/difflab.material	(revision 2293)
+++ /GTP/trunk/App/Demos/Illum/Ogre/Media/materials/scripts/difflab.material	(revision 2404)
@@ -130,4 +130,5 @@
 					world_view_proj_param_name WorldViewProj
 					world_param_name World
+					nearest_from_camera false
 			 }					
 		    }	
@@ -167,4 +168,5 @@
 					world_view_proj_param_name WorldViewProj
 					world_param_name World
+					nearest_from_camera false
 			}					
 		}	
@@ -210,4 +212,5 @@
 					world_view_proj_param_name WorldViewProj
 					world_param_name World
+					nearest_from_camera false
 			 }					
 		    }	
@@ -267,4 +270,5 @@
 					world_view_proj_param_name WorldViewProj
 					world_param_name World
+					nearest_from_camera false
 			}					
 		}	
@@ -310,4 +314,5 @@
 					world_view_proj_param_name WorldViewProj
 					world_param_name World
+					nearest_from_camera false
 			}					
 		}	
@@ -371,4 +376,5 @@
 					world_view_proj_param_name WorldViewProj
 					world_param_name World
+					nearest_from_camera false
 			}					
 		}	
Index: /GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPBasic/GTPShadowMap_PS.hlsl
===================================================================
--- /GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPBasic/GTPShadowMap_PS.hlsl	(revision 2337)
+++ /GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPBasic/GTPShadowMap_PS.hlsl	(revision 2404)
@@ -15,5 +15,5 @@
 #define DEPTH_BIAS_VSM  0.001
 #define DEPTH_EPSILON   0.05
-#define DIST_BIAS       0.0005
+#define DIST_BIAS       0.005
 #define DIST_BIAS_VSM   0.0005
 #define DIST_EPSILON    0.001
@@ -76,10 +76,10 @@
 					 uniform sampler2D shadowMap) : COLOR
 {
-  float4 light = shadowColor;  
+  float4 light = 0;//shadowColor;  
   if( IN.LightVPos.z > 0.0)
   {	
     float4 pos = (IN.LightVPos / IN.LightVPos.w);
   	float d = length(pos.xy);
-    light = saturate((1.0 - d)/0.05);		
+    //light = saturate((1.0 - d)/0.05);		
     if(d <= 1.0)
     {
@@ -90,4 +90,6 @@
 		light = max(dist < storedDist + DIST_BIAS, shadowColor);    
 		light = dist < storedDist + DIST_BIAS;
+		//if(dist < storedDist + DIST_BIAS)
+		//light = 1;
     }
   }
Index: /GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPBasic/GTPBasic.program
===================================================================
--- /GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPBasic/GTPBasic.program	(revision 2337)
+++ /GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPBasic/GTPBasic.program	(revision 2404)
@@ -216,3 +216,10 @@
    target ps_2_0
 }
+
+fragment_program GTP/Basic/Shaded/TexturedTwoLights_PS hlsl
+{
+   source GTPBasicShading.hlsl
+   entry_point TexturedShadedTwoLights_PS
+   target ps_2_0
+}
    
Index: /GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPBasic/GTPBasicShading.hlsl
===================================================================
--- /GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPBasic/GTPBasicShading.hlsl	(revision 2266)
+++ /GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPBasic/GTPBasicShading.hlsl	(revision 2404)
@@ -27,7 +27,57 @@
 	float cosb = max(dot(IN.wNormal.xyz, diff), 0);
 	
-	color.rgb = pow(cosa, 9) * cosb / dist2 * lightPower;
+	color.rgb = pow(cosa, 9) * cosb / dist2 * lightPower * lightColor;
 	//color.rgb *= lightPower;
 	//return 0;
 	return color * tex2D(colorTex, IN.texCoord);
 }
+
+
+float4 TexturedShadedTwoLights_PS(ShadedTex_OUT IN,
+						uniform float3 lightPos1,
+						uniform float3 lightDir1,
+						uniform float3 lightColor1,						
+						uniform float  lightPower1,
+						uniform float3 lightPos2,
+						uniform float3 lightDir2,
+						uniform float3 lightColor2,						
+						uniform float  lightPower2,						
+						uniform sampler2D colorTex : register(s0)):COLOR0
+{
+	float4 color = 0;
+	IN.wNormal.xyz = normalize(IN.wNormal.xyz);
+	
+	{
+	float3 lightDir = normalize(lightDir1);
+	
+	float3 diff = lightPos1 - IN.wPos;
+	float dist2 = dot(diff, diff);
+	if(dist2 < SAMPLECUTDIST2)
+		dist2 = SAMPLECUTDIST2;	
+	diff = normalize(diff);
+	float cosa = max(dot(lightDir1, -diff), 0);
+	float cosb = max(dot(IN.wNormal.xyz, diff), 0);
+	
+	//color.rgb += pow(cosa, 9) * cosb / dist2 * lightPower1 * lightColor1;
+	color.rgb += cosb / dist2 * lightPower1 * lightColor1;
+	
+	}
+	
+	{
+	float3  lightDir = normalize(lightDir2);
+	
+	float3 diff = lightPos2 - IN.wPos;
+	float dist2 = dot(diff, diff);
+	if(dist2 < SAMPLECUTDIST2)
+		dist2 = SAMPLECUTDIST2;	
+	diff = normalize(diff);
+	float cosa = max(dot(lightDir2, -diff), 0);
+	float cosb = max(dot(IN.wNormal.xyz, diff), 0);
+	
+	color.rgb += pow(cosa, 9) * cosb / dist2 * lightPower2 * lightColor2;	
+	}	
+	
+	//color.rgb *= lightPower;
+	//return 0;
+	return color * tex2D(colorTex, IN.texCoord);
+}
Index: /GTP/trunk/App/Demos/Illum/Ogre/Media/MORIA/MoriaHallBase.hlsl
===================================================================
--- /GTP/trunk/App/Demos/Illum/Ogre/Media/MORIA/MoriaHallBase.hlsl	(revision 2398)
+++ /GTP/trunk/App/Demos/Illum/Ogre/Media/MORIA/MoriaHallBase.hlsl	(revision 2404)
@@ -3,9 +3,4 @@
 #define MAX_LIGHT 2
 #define MAX_CAU_CASTER 2
-#define SPOT_ANGLE 2.093
-#define SPOT_FALLOFF 1
-#define SHADOW_COLOR float4(0.3,0.3,0.3,1.0)
-#define SHADOW_BIAS_POINT 0.0001
-#define SHADOW_EPSILON_POINT 0.0001
 
 #include "illum.hlsl"
Index: /GTP/trunk/App/Demos/Illum/Ogre/Media/MORIA/trollvs.cg
===================================================================
--- /GTP/trunk/App/Demos/Illum/Ogre/Media/MORIA/trollvs.cg	(revision 2386)
+++ /GTP/trunk/App/Demos/Illum/Ogre/Media/MORIA/trollvs.cg	(revision 2404)
@@ -5,13 +5,14 @@
 	float2 uv       : TEXCOORD0,
 	float3 tangent  : TANGENT,
-	float  blendIdx : BLENDINDICES,
+	float4  blendIdx : BLENDINDICES,
+	float4 blendWgt : BLENDWEIGHT,
 	out float4 oPosition : POSITION,
 	out float2 oUv       : TEXCOORD0,
-	out float3 oTangent: TEXCOORD1,
-	out float3 oBinormal: TEXCOORD2,
+	//out float3 oTangent: TEXCOORD1,
+	//out float3 oBinormal: TEXCOORD2,
 	out float3 oNormal   : TEXCOORD3,
 	out float3 V: TEXCOORD4,
 	out float3 L: TEXCOORD5,
-	uniform float3x4   worldMatrix3x4Array[67],
+	uniform float3x4   worldMatrix3x4Array[69],
 	uniform float4x4 viewProjectionMatrix,
 	uniform float4   lightPos,
@@ -19,13 +20,16 @@
 {
 	// transform by indexed matrix
-	float4 blendPos = float4(mul(worldMatrix3x4Array[blendIdx], position).xyz, 1.0);
+	float4 blendPos = float4(0,0,0,1);
+	blendPos.xyz += mul(worldMatrix3x4Array[blendIdx[0]], position).xyz * blendWgt[0];
+	blendPos.xyz += mul(worldMatrix3x4Array[blendIdx[1]], position).xyz * blendWgt[1];
+	
 	// view / projection
 	oPosition = mul(viewProjectionMatrix, blendPos);
 	// transform normal
-	oNormal = mul((float3x3)worldMatrix3x4Array[blendIdx], normal);
-	oTangent = mul((float3x3)worldMatrix3x4Array[blendIdx], tangent);
+	//oNormal = mul((float3x3)worldMatrix3x4Array[blendIdx], normal);
+	//oTangent = mul((float3x3)worldMatrix3x4Array[blendIdx], tangent);
 	oNormal = normalize(oNormal);
-	oTangent = normalize(oTangent);
-	oBinormal = cross(oTangent, oNormal);
+//	oTangent = normalize(oTangent);
+//	oBinormal = cross(oTangent, oNormal);
 	// Lighting - support point and directional
 	L =  lightPos.xyz - blendPos.xyz * lightPos.w;
@@ -38,5 +42,6 @@
 void trollSkinning_SMGen_One_Weight_vp(
 	float4 position : POSITION,
-	float  blendIdx : BLENDINDICES,
+	float4  blendIdx : BLENDINDICES,
+	float4 blendWgt : BLENDWEIGHT,	
 	out float4 oPosition : POSITION,
 	out float3 cPos:TEXCOORD0,	
@@ -48,5 +53,8 @@
 {
 	// transform by indexed matrix
-	float4 blendPos = float4(mul(worldMatrix3x4Array[blendIdx], position).xyz, 1.0);
+	float4 blendPos = float4(0,0,0,1);
+	blendPos.xyz += mul(worldMatrix3x4Array[blendIdx[0]], position).xyz * blendWgt[0];
+	blendPos.xyz += mul(worldMatrix3x4Array[blendIdx[1]], position).xyz * blendWgt[1];
+	
 	// view / projection
 	cPos = mul(viewMatrix, blendPos).xyz;
Index: /GTP/trunk/App/Demos/Illum/Ogre/Media/MORIA/illum.hlsl
===================================================================
--- /GTP/trunk/App/Demos/Illum/Ogre/Media/MORIA/illum.hlsl	(revision 2398)
+++ /GTP/trunk/App/Demos/Illum/Ogre/Media/MORIA/illum.hlsl	(revision 2404)
@@ -1,2 +1,7 @@
+#define SPOT_ANGLE 2.093
+#define SPOT_FALLOFF 1
+#define SHADOW_COLOR float4(0.3,0.3,0.3,1.0)
+#define SHADOW_BIAS_POINT 0.0001
+#define SHADOW_EPSILON_POINT 0.0001
 
 float4 Illumination(float3 N, float3 L, float3 V, float4 lightColor, float4 lightRange, float4 diffuseColor, float specularity, float4 specularColor)
Index: /GTP/trunk/App/Demos/Illum/Ogre/Media/MORIA/FPSarm.material
===================================================================
--- /GTP/trunk/App/Demos/Illum/Ogre/Media/MORIA/FPSarm.material	(revision 2398)
+++ /GTP/trunk/App/Demos/Illum/Ogre/Media/MORIA/FPSarm.material	(revision 2404)
@@ -24,2 +24,118 @@
 	}
 }
+
+vertex_program GTP/MoriaDemo/Sword_VS hlsl
+{
+   source sword.hlsl
+   entry_point Sword_VS
+   target vs_2_0
+}
+
+fragment_program GTP/MoriaDemo/Sword_Metal_PS hlsl
+{
+   source sword.hlsl
+   entry_point Sword_Metal_PS
+   target ps_3_0
+}
+fragment_program GTP/MoriaDemo/Sword_Handle_PS hlsl
+{
+   source sword.hlsl
+   entry_point Sword_Handle_PS
+   target ps_3_0
+}
+
+material swordHandle
+{
+	technique
+	{
+		pass
+		{
+			IllumTechniques
+			{
+			//	RenderTechnique DepthShadowReceiver
+			//	{
+			//		max_light_count 1
+			//		set_light_viewproj false
+			//		set_light_view true
+			//		set_light_farplane true
+			//		light_view_param_name LightView
+			//		light_farplane_param_name lightFarPlane
+			//		new_passes false
+			//		start_tex_id 1
+			//	}			  	
+		  	}
+		  	cull_hardware none
+			vertex_program_ref GTP/MoriaDemo/Sword_VS
+   			{
+   			  param_named_auto WorldViewProj worldviewproj_matrix  
+   			  param_named_auto World world_matrix
+   			  param_named_auto WorldI inverse_world_matrix
+   			  param_named_auto wCamPos camera_position
+   			}
+  			fragment_program_ref GTP/MoriaDemo/Sword_Handle_PS
+  			{ 
+	  		  param_named_auto wLightPos1 light_position 0
+   			 // param_named_auto wLightPos2 light_position 1   			  
+	  		  param_named_auto lightRange1 light_attenuation 0
+  			 // param_named_auto lightRange2 light_attenuation 1
+   			  param_named_auto lightPower1 light_power 0
+   			 // param_named_auto lightPower2 light_power 1
+   			  param_named_auto lightColor1 light_diffuse_colour 0
+   			 // param_named_auto lightColor2 light_diffuse_colour 1
+   			  param_named specularity float 100
+   			  param_named specularColor float4 0.05 0.05 0.05 0.05   			  
+   			}
+			texture_unit
+			{
+				texture swordColor.dds
+			}			
+			texture_unit
+			{
+			}
+			texture_unit
+			{
+			}
+		}
+	}
+}
+
+material swordMetal
+{
+   technique maintechnique
+   {   
+      pass mainpass
+      { 
+		 IllumTechniques
+		 {
+			RenderTechnique ColorCubeMap
+			{
+				update_interval		1
+				update_all_face false
+				distance_calc false					
+				face_angle_calc false
+			}				
+		 }      
+	     vertex_program_ref GTP/Basic/ShadedTex_VS
+     	 {       
+            param_named_auto WorldViewProj worldviewproj_matrix 
+    	    param_named_auto World world_matrix
+    	    param_named_auto WorldInv inverse_world_matrix
+     	 } 
+	     fragment_program_ref GTP/MoriaDemo/Sword_Metal_PS
+     	 { 
+		    param_named_auto wCamPos camera_position            
+	     }		
+	     //Cube map for reflections and refractions	
+	     texture_unit
+	     {
+	    
+	     }
+	     texture_unit
+	     {
+	   		texture swordColor.dds
+	     }
+	  }
+   }
+}
+
+
Index: /GTP/trunk/App/Demos/Illum/Ogre/Media/MORIA/sword.hlsl
===================================================================
--- /GTP/trunk/App/Demos/Illum/Ogre/Media/MORIA/sword.hlsl	(revision 2404)
+++ /GTP/trunk/App/Demos/Illum/Ogre/Media/MORIA/sword.hlsl	(revision 2404)
@@ -0,0 +1,135 @@
+#include "illum.hlsl"
+
+float4 readCubeMap(samplerCUBE cm, float3 coord)		
+{
+	float4 color = texCUBE( cm, float3(coord.xy, - coord.z) );
+	color.a = 1;
+	return color;
+}
+
+struct Sword_VS_OUT
+{
+ float4 hPos : POSITION;
+ float2 texCoord : TEXCOORD0;
+ float3 wView		  : TEXCOORD2;
+ float3 wTangent 	  : TEXCOORD3;
+ float3 wBinormal 	  : TEXCOORD4;
+ float3 wNormal 		  : TEXCOORD5;
+ float3 wPos    : TEXCOORD1;  
+};
+
+uniform float4x4 WorldViewProj;
+uniform float4x4 World;
+uniform float4x4 WorldI;
+
+uniform float3 wCamPos;
+
+uniform float4 wLightPos1;
+uniform float4 wLightPos2;
+uniform float4 lightRange1;
+uniform float4 lightRange2;
+uniform float lightPower1;
+uniform float lightPower2;
+uniform float4 lightColor1;
+uniform float4 lightColor2;
+						
+uniform float4x4 LightView1;
+uniform float4x4 LightView2;
+uniform float lightFarPlane1;
+uniform float lightFarPlane2;
+
+uniform float specularity;
+uniform float4 specularColor;
+
+
+Sword_VS_OUT Sword_VS(float4 position :POSITION,
+										float3 normal :NORMAL,
+										float2 texCoord : TEXCOORD0,
+										float3 tangent   : TEXCOORD1)
+{
+	Sword_VS_OUT OUT = (Sword_VS_OUT) 0;
+	
+	OUT.texCoord = texCoord;
+			
+	OUT.hPos = mul(WorldViewProj, position);
+	OUT.wPos = mul(World, position).xyz;
+	
+	OUT.wView = wCamPos - OUT.wPos;
+	
+	OUT.wTangent = normalize(mul(float4(tangent, 1),WorldI)).xyz;
+	OUT.wNormal = normalize(mul(float4(normal, 1),WorldI)).xyz;		
+	OUT.wBinormal = cross(OUT.wTangent, OUT.wNormal).xyz;		
+		
+	return OUT;
+}
+
+struct ShadedTex_OUT
+{
+ float4 vPos : POSITION;
+ float4 texCoord : TEXCOORD0;
+ float4 wNormal : TEXCOORD1;
+ float4 wPos    : TEXCOORD2;  
+};
+
+float4 Sword_Metal_PS(  ShadedTex_OUT IN,
+						uniform samplerCUBE CubeMap : register(s0),
+						uniform sampler2D colorTexture : register(s1),
+						uniform float3 lastCenter):COLOR0
+{	
+	if(!tex2D(colorTexture, IN.texCoord).a)
+		discard;
+	
+	float3 F0 = tex2D(colorTexture, IN.texCoord).rgb;
+		
+	float4 Color;
+	float3 N = normalize(IN.wNormal.xyz);
+	float3 RR;	
+	float3 V = normalize(IN.wPos.xyz - wCamPos);
+	float3 R = reflect( V, N);
+		
+	Color = readCubeMap(CubeMap, R);
+	
+	float ctheta_in = dot(N, R);
+	float ctheta_out = dot(N, -V);
+
+	float3 F = 0;
+	
+	float3 H = normalize(R - V);	// felezõvektor
+	float cbeta  = dot(H,R);		
+	F = F0 + (1 - F0) * pow(1 - cbeta, 5);
+	
+		
+	return Color * float4(F,1);		
+}
+
+float4 Sword_Handle_PS(  Sword_VS_OUT IN,
+									uniform sampler2D colorTexture : register(s0),
+									uniform sampler2D bumpTexture : register(s1),
+									uniform samplerCUBE ShadowMap1Point : register(s2),
+									uniform samplerCUBE ShadowMap2Point : register(s3),
+									uniform float3 cameraPos,
+									uniform float3 lastCenter):COLOR0
+{		
+	float4 Color = 0;
+	float3 N = IN.wNormal;//NormalMap(IN.wTangent, IN.wBinormal, IN.wNormal, IN.texCoord, bumpTexture);
+	float3 V = normalize(IN.wView);
+		
+	float3 L;
+	float4 col;
+	float3 lightCPos;
+	float shadow;
+
+	float4 diffuseColor = tex2D(colorTexture, IN.texCoord);
+	
+//if(dot(lightColor1, lightColor1) != 0)
+//{
+	L = wLightPos1.xyz - IN.wPos * wLightPos1.w;
+	//illumination
+	col = Illumination(N, L, V, lightColor1 * lightPower1, lightRange1, diffuseColor, specularity, specularColor);
+	//shadowing	
+	lightCPos = mul(LightView1, float4(IN.wPos, 1)).xyz;
+	shadow = shadowPoint(ShadowMap1Point, lightCPos, lightFarPlane1);
+	Color += col;// * shadow;
+	
+	return Color;	
+}
