Преглед на файлове

fix win32-build for assimp_viewer .

Signed-off-by: Kim Kulling <[email protected]>
Kim Kulling преди 10 години
родител
ревизия
76dd9467b2

+ 1 - 0
.gitignore

@@ -58,3 +58,4 @@ test/gtest/src/gtest-stamp/gtest-gitinfo.txt
 test/gtest/src/gtest-stamp/gtest-gitclone-lastrun.txt
 test/gtest/src/gtest-stamp/gtest-gitclone-lastrun.txt
 Assimp.opensdf
 Assimp.opensdf
 contrib/zlib/CTestTestfile.cmake
 contrib/zlib/CTestTestfile.cmake
+ipch/assimp_viewer-44bbbcd1/assimp_viewerd-ccc45335.ipch

+ 2 - 0
code/StringComparison.h

@@ -51,6 +51,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #define INCLUDED_AI_STRING_WORKERS_H
 #define INCLUDED_AI_STRING_WORKERS_H
 
 
 #include "../include/assimp/ai_assert.h"
 #include "../include/assimp/ai_assert.h"
+#include "StringComparison.h"
+
 #include <string.h>
 #include <string.h>
 #include <stdint.h>
 #include <stdint.h>
 #include <string>
 #include <string>

+ 0 - 1
tools/assimp_view/AnimEvaluator.cpp

@@ -39,7 +39,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ---------------------------------------------------------------------------
 ---------------------------------------------------------------------------
 */
 */
 
 
-#include "stdafx.h"
 #include "assimp_view.h"
 #include "assimp_view.h"
 
 
 using namespace AssimpView;
 using namespace AssimpView;

+ 199 - 190
tools/assimp_view/AssetHelper.h

@@ -43,195 +43,204 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #if (!defined AV_ASSET_HELPER_H_INCLUDED)
 #if (!defined AV_ASSET_HELPER_H_INCLUDED)
 #define AV_ASSET_HELPER_H_INCLUDED
 #define AV_ASSET_HELPER_H_INCLUDED
 
 
-class SceneAnimator;
-
-//-------------------------------------------------------------------------------
-/**	\brief Class to wrap ASSIMP's asset output structures
-*/
-//-------------------------------------------------------------------------------
-class AssetHelper
-	{
-	public:
-		enum 
-		{
-			// the original normal set will be used
-			ORIGINAL = 0x0u,
-
-			// a smoothed normal set will be used
-			SMOOTH = 0x1u,
-
-			// a hard normal set will be used
-			HARD = 0x2u,
-		};
-
-		// default constructor
-		AssetHelper()
-			: iNormalSet(ORIGINAL)
-		{
-			mAnimator = NULL;
-			apcMeshes = NULL;
-			pcScene = NULL;
-		}
-
-		//---------------------------------------------------------------
-		// default vertex data structure
-		// (even if tangents, bitangents or normals aren't
-		// required by the shader they will be committed to the GPU)
-		//---------------------------------------------------------------
-		struct Vertex
-		{
-			aiVector3D vPosition;
-			aiVector3D vNormal;
-
-			D3DCOLOR dColorDiffuse;
-			aiVector3D vTangent;
-			aiVector3D vBitangent;
-			aiVector2D vTextureUV;
-			aiVector2D vTextureUV2;
-			unsigned char mBoneIndices[4];
-			unsigned char mBoneWeights[4]; // last Weight not used, calculated inside the vertex shader
-
-			/** Returns the vertex declaration elements to create a declaration from. */
-			static D3DVERTEXELEMENT9* GetDeclarationElements() 
-			{
-				static D3DVERTEXELEMENT9 decl[] =
-				{
-					{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
-					{ 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
-					{ 0, 24, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
-					{ 0, 28, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },
-					{ 0, 40, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 0 },
-					{ 0, 52, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
-					{ 0, 60, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 },
-					{ 0, 68, D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDINDICES, 0 },
-					{ 0, 72, D3DDECLTYPE_UBYTE4N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 0 },
-					D3DDECL_END()
-				};
-
-				return decl;
-			}
-		};
-
-		//---------------------------------------------------------------
-		// FVF vertex structure used for normals
-		//---------------------------------------------------------------
-		struct LineVertex
-		{
-			aiVector3D vPosition;
-			DWORD dColorDiffuse;
-
-			// retrieves the FVF code of the vertex type
-			static DWORD GetFVF()
-			{
-				return D3DFVF_DIFFUSE | D3DFVF_XYZ;
-			}
-		};
-
-		//---------------------------------------------------------------
-		// Helper class to store GPU related resources created for
-		// a given aiMesh
-		//---------------------------------------------------------------
-		class MeshHelper
-			{
-			public:
-
-				MeshHelper ()
-					: 
-					piVB				(NULL),
-					piIB				(NULL),
-					piVBNormals			(NULL),
-					piEffect			(NULL),
-					bSharedFX           (false),
-					piDiffuseTexture	(NULL),
-					piSpecularTexture	(NULL),
-					piAmbientTexture	(NULL),
-					piEmissiveTexture	(NULL),
-					piNormalTexture		(NULL),
-					piOpacityTexture	(NULL),
-					piShininessTexture	(NULL),
-					piLightmapTexture	(NULL),
-					twosided            (false),
-					pvOriginalNormals	(NULL)
-                {}
-
-				~MeshHelper ()
-					{
-					// NOTE: This is done in DeleteAssetData()
-					// TODO: Make this a proper d'tor
-					}
-
-				// shading mode to use. Either Lambert or otherwise phong
-				// will be used in every case
-				aiShadingMode eShadingMode;
-
-				// vertex buffer
-				IDirect3DVertexBuffer9* piVB;
-
-				// index buffer. For partially transparent meshes
-				// created with dynamic usage to be able to update
-				// the buffer contents quickly
-				IDirect3DIndexBuffer9* piIB;
-
-				// vertex buffer to be used to draw vertex normals
-				// (vertex normals are generated in every case)
-				IDirect3DVertexBuffer9* piVBNormals;
-
-				// shader to be used
-				ID3DXEffect* piEffect;
-				bool bSharedFX;
-
-				// material textures
-				IDirect3DTexture9* piDiffuseTexture;
-				IDirect3DTexture9* piSpecularTexture;
-				IDirect3DTexture9* piAmbientTexture;
-				IDirect3DTexture9* piEmissiveTexture;
-				IDirect3DTexture9* piNormalTexture;
-				IDirect3DTexture9* piOpacityTexture;
-				IDirect3DTexture9* piShininessTexture;
-				IDirect3DTexture9* piLightmapTexture;
-
-				// material colors
-				D3DXVECTOR4 vDiffuseColor;
-				D3DXVECTOR4 vSpecularColor;
-				D3DXVECTOR4 vAmbientColor;
-				D3DXVECTOR4 vEmissiveColor;
-
-				// opacity for the material
-				float fOpacity;
-
-				// shininess for the material
-				float fShininess;
-
-				// strength of the specular highlight
-				float fSpecularStrength;
-
-				// two-sided?
-				bool twosided;
-
-				// Stores a pointer to the original normal set of the asset
-				aiVector3D* pvOriginalNormals;
-			};
-
-		// One instance per aiMesh in the globally loaded asset
-		MeshHelper** apcMeshes;
-
-		// Scene wrapper instance
-		aiScene* pcScene;
-
-		// Animation player to animate the scene if necessary
-		SceneAnimator* mAnimator;
-
-		// Specifies the normal set to be used
-		unsigned int iNormalSet;
-
-		// ------------------------------------------------------------------
-		// set the normal set to be used
-		void SetNormalSet(unsigned int iSet);
-
-		// ------------------------------------------------------------------
-		// flip all normal vectors
-		void FlipNormals();
-		void FlipNormalsInt();
-	};
+#include <d3d9.h>
+#include <d3dx9.h>
+#include <d3dx9mesh.h>
+
+#include <assimp/scene.h>
+
+namespace AssimpView {
+
+    class SceneAnimator;
+
+    //-------------------------------------------------------------------------------
+    /**	\brief Class to wrap ASSIMP's asset output structures
+    */
+    //-------------------------------------------------------------------------------
+    class AssetHelper
+    {
+    public:
+        enum
+        {
+            // the original normal set will be used
+            ORIGINAL = 0x0u,
+
+            // a smoothed normal set will be used
+            SMOOTH = 0x1u,
+
+            // a hard normal set will be used
+            HARD = 0x2u,
+        };
+
+        // default constructor
+        AssetHelper()
+            : iNormalSet( ORIGINAL )
+        {
+            mAnimator = NULL;
+            apcMeshes = NULL;
+            pcScene = NULL;
+        }
+
+        //---------------------------------------------------------------
+        // default vertex data structure
+        // (even if tangents, bitangents or normals aren't
+        // required by the shader they will be committed to the GPU)
+        //---------------------------------------------------------------
+        struct Vertex
+        {
+            aiVector3D vPosition;
+            aiVector3D vNormal;
+
+            D3DCOLOR dColorDiffuse;
+            aiVector3D vTangent;
+            aiVector3D vBitangent;
+            aiVector2D vTextureUV;
+            aiVector2D vTextureUV2;
+            unsigned char mBoneIndices[ 4 ];
+            unsigned char mBoneWeights[ 4 ]; // last Weight not used, calculated inside the vertex shader
+
+            /** Returns the vertex declaration elements to create a declaration from. */
+            static D3DVERTEXELEMENT9* GetDeclarationElements()
+            {
+                static D3DVERTEXELEMENT9 decl[] =
+                {
+                    { 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
+                    { 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
+                    { 0, 24, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
+                    { 0, 28, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },
+                    { 0, 40, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 0 },
+                    { 0, 52, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
+                    { 0, 60, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 },
+                    { 0, 68, D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDINDICES, 0 },
+                    { 0, 72, D3DDECLTYPE_UBYTE4N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 0 },
+                    D3DDECL_END()
+                };
+
+                return decl;
+            }
+        };
+
+        //---------------------------------------------------------------
+        // FVF vertex structure used for normals
+        //---------------------------------------------------------------
+        struct LineVertex
+        {
+            aiVector3D vPosition;
+            DWORD dColorDiffuse;
+
+            // retrieves the FVF code of the vertex type
+            static DWORD GetFVF()
+            {
+                return D3DFVF_DIFFUSE | D3DFVF_XYZ;
+            }
+        };
+
+        //---------------------------------------------------------------
+        // Helper class to store GPU related resources created for
+        // a given aiMesh
+        //---------------------------------------------------------------
+        class MeshHelper
+        {
+        public:
+
+            MeshHelper()
+                :
+                piVB( NULL ),
+                piIB( NULL ),
+                piVBNormals( NULL ),
+                piEffect( NULL ),
+                bSharedFX( false ),
+                piDiffuseTexture( NULL ),
+                piSpecularTexture( NULL ),
+                piAmbientTexture( NULL ),
+                piEmissiveTexture( NULL ),
+                piNormalTexture( NULL ),
+                piOpacityTexture( NULL ),
+                piShininessTexture( NULL ),
+                piLightmapTexture( NULL ),
+                twosided( false ),
+                pvOriginalNormals( NULL )
+            {}
+
+            ~MeshHelper()
+            {
+                // NOTE: This is done in DeleteAssetData()
+                // TODO: Make this a proper d'tor
+            }
+
+            // shading mode to use. Either Lambert or otherwise phong
+            // will be used in every case
+            aiShadingMode eShadingMode;
+
+            // vertex buffer
+            IDirect3DVertexBuffer9* piVB;
+
+            // index buffer. For partially transparent meshes
+            // created with dynamic usage to be able to update
+            // the buffer contents quickly
+            IDirect3DIndexBuffer9* piIB;
+
+            // vertex buffer to be used to draw vertex normals
+            // (vertex normals are generated in every case)
+            IDirect3DVertexBuffer9* piVBNormals;
+
+            // shader to be used
+            ID3DXEffect* piEffect;
+            bool bSharedFX;
+
+            // material textures
+            IDirect3DTexture9* piDiffuseTexture;
+            IDirect3DTexture9* piSpecularTexture;
+            IDirect3DTexture9* piAmbientTexture;
+            IDirect3DTexture9* piEmissiveTexture;
+            IDirect3DTexture9* piNormalTexture;
+            IDirect3DTexture9* piOpacityTexture;
+            IDirect3DTexture9* piShininessTexture;
+            IDirect3DTexture9* piLightmapTexture;
+
+            // material colors
+            D3DXVECTOR4 vDiffuseColor;
+            D3DXVECTOR4 vSpecularColor;
+            D3DXVECTOR4 vAmbientColor;
+            D3DXVECTOR4 vEmissiveColor;
+
+            // opacity for the material
+            float fOpacity;
+
+            // shininess for the material
+            float fShininess;
+
+            // strength of the specular highlight
+            float fSpecularStrength;
+
+            // two-sided?
+            bool twosided;
+
+            // Stores a pointer to the original normal set of the asset
+            aiVector3D* pvOriginalNormals;
+        };
+
+        // One instance per aiMesh in the globally loaded asset
+        MeshHelper** apcMeshes;
+
+        // Scene wrapper instance
+        aiScene* pcScene;
+
+        // Animation player to animate the scene if necessary
+        SceneAnimator* mAnimator;
+
+        // Specifies the normal set to be used
+        unsigned int iNormalSet;
+
+        // ------------------------------------------------------------------
+        // set the normal set to be used
+        void SetNormalSet( unsigned int iSet );
+
+        // ------------------------------------------------------------------
+        // flip all normal vectors
+        void FlipNormals();
+        void FlipNormalsInt();
+    };
+}
 
 
 #endif // !! IG
 #endif // !! IG

+ 1 - 2
tools/assimp_view/Background.cpp

@@ -39,12 +39,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ---------------------------------------------------------------------------
 ---------------------------------------------------------------------------
 */
 */
 
 
-#include "stdafx.h"
 #include "assimp_view.h"
 #include "assimp_view.h"
 
 
-
 namespace AssimpView {
 namespace AssimpView {
 
 
+extern std::string g_szSkyboxShader;
 
 
 // From: U3D build 1256 (src\kernel\graphic\scenegraph\SkyBox.cpp)
 // From: U3D build 1256 (src\kernel\graphic\scenegraph\SkyBox.cpp)
 // ------------------------------------------------------------------------------
 // ------------------------------------------------------------------------------

+ 65 - 65
tools/assimp_view/Background.h

@@ -38,91 +38,91 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ---------------------------------------------------------------------------
 ---------------------------------------------------------------------------
 */
 */
+#pragma once
 
 
-#if (!defined AV_BACKGROUND_H_INCLUDED)
-#define AV_BACKGROUND_H_INCLUDED
+namespace AssimpView
+{
 
 
+    class CBackgroundPainter
+    {
+        CBackgroundPainter()
+            :
+            clrColor( D3DCOLOR_ARGB( 0xFF, 100, 100, 100 ) ),
+            pcTexture( NULL ),
+            piSkyBoxEffect( NULL ),
+            eMode( SIMPLE_COLOR )
+        {}
 
 
-class CBackgroundPainter
-	{
-	CBackgroundPainter()
-		: 
-		clrColor(D3DCOLOR_ARGB(0xFF,100,100,100)),
-		pcTexture(NULL),
-		piSkyBoxEffect(NULL),
-		eMode(SIMPLE_COLOR)
-		{}
+    public:
 
 
-public:
+        // Supported background draw modi
+        enum MODE { SIMPLE_COLOR, TEXTURE_2D, TEXTURE_CUBE };
 
 
-	// Supported background draw modi
-	enum MODE {SIMPLE_COLOR, TEXTURE_2D, TEXTURE_CUBE};
+        // Singleton accessors
+        static CBackgroundPainter s_cInstance;
+        inline static CBackgroundPainter& Instance()
+        {
+            return s_cInstance;
+        }
 
 
-	// Singleton accessors
-	static CBackgroundPainter s_cInstance;
-	inline static CBackgroundPainter& Instance ()
-		{
-		return s_cInstance;
-		}
+        // set the current background color
+        // (this removes any textures loaded)
+        void SetColor( D3DCOLOR p_clrNew );
 
 
-	// set the current background color
-	// (this removes any textures loaded)
-	void SetColor (D3DCOLOR p_clrNew);
+        // Setup a cubemap/a 2d texture as background
+        void SetCubeMapBG( const char* p_szPath );
+        void SetTextureBG( const char* p_szPath );
 
 
-	// Setup a cubemap/a 2d texture as background
-	void SetCubeMapBG (const char* p_szPath);
-	void SetTextureBG (const char* p_szPath);
+        // Called by the render loop
+        void OnPreRender();
+        void OnPostRender();
 
 
-	// Called by the render loop
-	void OnPreRender();
-	void OnPostRender();
+        // Release any native resources associated with the instance
+        void ReleaseNativeResource();
 
 
-	// Release any native resources associated with the instance
-	void ReleaseNativeResource();
+        // Recreate any native resources associated with the instance
+        void RecreateNativeResource();
 
 
-	// Recreate any native resources associated with the instance
-	void RecreateNativeResource();
+        // Rotate the skybox
+        void RotateSB( const aiMatrix4x4* pm );
 
 
-	// Rotate the skybox
-	void RotateSB(const aiMatrix4x4* pm);
+        // Reset the state of the skybox
+        void ResetSB();
 
 
-	// Reset the state of the skybox
-	void ResetSB();
+        inline MODE GetMode() const
+        {
+            return this->eMode;
+        }
 
 
-	inline MODE GetMode() const
-		{
-		return this->eMode;
-		}
+        inline IDirect3DBaseTexture9* GetTexture()
+        {
+            return this->pcTexture;
+        }
 
 
-	inline IDirect3DBaseTexture9* GetTexture()
-		{
-		return this->pcTexture;
-		}
+        inline ID3DXBaseEffect* GetEffect()
+        {
+            return this->piSkyBoxEffect;
+        }
 
 
-	inline ID3DXBaseEffect* GetEffect()
-		{
-		return this->piSkyBoxEffect;
-		}
+    private:
 
 
-private:
+        void RemoveSBDeps();
 
 
-	void RemoveSBDeps();
+        // current background color
+        D3DCOLOR clrColor;
 
 
-	// current background color
-	D3DCOLOR clrColor;
+        // current background texture
+        IDirect3DBaseTexture9* pcTexture;
+        ID3DXEffect* piSkyBoxEffect;
 
 
-	// current background texture
-	IDirect3DBaseTexture9* pcTexture;
-	ID3DXEffect* piSkyBoxEffect;
+        // current background mode
+        MODE eMode;
 
 
-	// current background mode
-	MODE eMode;
+        // path to the texture
+        std::string szPath;
 
 
-	// path to the texture
-	std::string szPath;
+        // transformation matrix for the skybox
+        aiMatrix4x4 mMatrix;
+    };
 
 
-	// transformation matrix for the skybox
-	aiMatrix4x4 mMatrix;
-	};
-
-#endif // !! AV_BACKGROUND_H_INCLUDED
+}

+ 7 - 4
tools/assimp_view/Display.cpp

@@ -38,13 +38,16 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ---------------------------------------------------------------------------
 ---------------------------------------------------------------------------
 */
 */
-
-#include "stdafx.h"
 #include "assimp_view.h"
 #include "assimp_view.h"
-
+#include "AnimEvaluator.h"
+#include "SceneAnimator.h"
 
 
 namespace AssimpView {
 namespace AssimpView {
 
 
+using namespace Assimp;
+
+extern std::string g_szCheckerBackgroundShader;
+
 struct SVertex
 struct SVertex
 {
 {
 	float x,y,z,w,u,v;
 	float x,y,z,w,u,v;
@@ -2240,7 +2243,7 @@ int CDisplay::RenderTextureView()
 		const float ny = (float)sRect.bottom;
 		const float ny = (float)sRect.bottom;
 		const float  x = (float)sDesc.Width;
 		const float  x = (float)sDesc.Width;
 		const float  y = (float)sDesc.Height;
 		const float  y = (float)sDesc.Height;
-		float f = std::min((nx-30) / x,(ny-30) / y) * (m_fTextureZoom/1000.0f);
+		float f = min((nx-30) / x,(ny-30) / y) * (m_fTextureZoom/1000.0f);
 
 
 		float fHalfX = (nx - (f * x)) / 2.0f;
 		float fHalfX = (nx - (f * x)) / 2.0f;
 		float fHalfY = (ny - (f * y)) / 2.0f;
 		float fHalfY = (ny - (f * y)) / 2.0f;

+ 465 - 457
tools/assimp_view/Display.h

@@ -42,6 +42,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #if (!defined AV_DISPLAY_H_INCLUDED)
 #if (!defined AV_DISPLAY_H_INCLUDED)
 #define AV_DISPLAY_H_INCLUDE
 #define AV_DISPLAY_H_INCLUDE
 
 
+#include <windows.h>
+#include <shellapi.h>
+#include <commctrl.h>
+
 // see CDisplay::m_aiImageList
 // see CDisplay::m_aiImageList
 #define AI_VIEW_IMGLIST_NODE			0x0
 #define AI_VIEW_IMGLIST_NODE			0x0
 #define AI_VIEW_IMGLIST_MATERIAL		0x1
 #define AI_VIEW_IMGLIST_MATERIAL		0x1
@@ -49,486 +53,490 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #define AI_VIEW_IMGLIST_TEXTURE_INVALID 0x3
 #define AI_VIEW_IMGLIST_TEXTURE_INVALID 0x3
 #define AI_VIEW_IMGLIST_MODEL			0x4
 #define AI_VIEW_IMGLIST_MODEL			0x4
 
 
-//-------------------------------------------------------------------------------
-/* Corresponds to the "Display" combobox in the UI
-*/
-//-------------------------------------------------------------------------------
-class CDisplay
-	{
-private:
-
-	// helper class
-	struct Info
-	{
-		Info(	D3DXVECTOR4* p1,
-				AssetHelper::MeshHelper* p2,
-				const char* p3)
-				: pclrColor(p1),pMesh(p2),szShaderParam(p3) {}
-
-		D3DXVECTOR4* pclrColor;
-		AssetHelper::MeshHelper* pMesh;
-		const char* szShaderParam;
-	};
-
-// default constructor
-	CDisplay() 
-		:	m_iViewMode(VIEWMODE_FULL), 
-			m_pcCurrentTexture(NULL),
-			m_pcCurrentNode(NULL),
-			m_pcCurrentMaterial(NULL),
-			m_hImageList(NULL),
-			m_hRoot(NULL),
-			m_fTextureZoom(1000.0f)
-	{
-		this->m_aiImageList[0] = 0;
-		this->m_aiImageList[1] = 1;
-		this->m_aiImageList[2] = 2;
-		this->m_aiImageList[3] = 3;
-		this->m_aiImageList[4] = 4;
-
-		this->m_avCheckerColors[0].x = this->m_avCheckerColors[0].y = this->m_avCheckerColors[0].z = 0.4f;
-		this->m_avCheckerColors[1].x = this->m_avCheckerColors[1].y = this->m_avCheckerColors[1].z = 0.6f;
-	}
-
-public:
-
-
-	//------------------------------------------------------------------
-	enum 
-	{
-		// the full model is displayed
-		VIEWMODE_FULL,
-
-		// a material is displayed on a simple spjere as model
-		VIEWMODE_MATERIAL,
-
-		// a texture with an UV set mapped on it is displayed
-		VIEWMODE_TEXTURE,
-
-		// a single node in the scenegraph is displayed
-		VIEWMODE_NODE,
-	};
-
-
-	//------------------------------------------------------------------
-	// represents a texture in the tree view
-	struct TextureInfo
-	{
-		// texture info
-		IDirect3DTexture9** piTexture;
-
-		// Blend factor of the texture
-		float fBlend;
-
-		// blend operation for the texture
-		aiTextureOp eOp;
-
-		// UV index for the texture
-		unsigned int iUV;
-
-		// Associated tree item
-		HTREEITEM hTreeItem;
-
-		// Original path to the texture
-		std::string szPath;
-
-		// index of the corresponding material
-		unsigned int iMatIndex;
-
-		// type of the texture
-		unsigned int iType;
-	};
-
-	//------------------------------------------------------------------
-	// represents a node in the tree view
-	struct NodeInfo
-	{
-		// node object
-		aiNode* psNode;
-
-		// corresponding tree view item
-		HTREEITEM hTreeItem;
-	};
-
-	//------------------------------------------------------------------
-	// represents a mesh in the tree view
-	struct MeshInfo
-	{
-		// the mesh object
-		aiMesh* psMesh;
-
-		// corresponding tree view item
-		HTREEITEM hTreeItem;
-	};
-
-	//------------------------------------------------------------------
-	// represents a material in the tree view
-	struct MaterialInfo
-	{
-		// material index
-		unsigned int iIndex;
-
-		// material object
-		aiMaterial* psMaterial;
-
-		// ID3DXEffect interface
-		ID3DXEffect* piEffect;
-
-		// corresponding tree view item
-		HTREEITEM hTreeItem;
-	};
-
-	//------------------------------------------------------------------
-	// Singleton accessors
-	static CDisplay s_cInstance;
-	inline static CDisplay& Instance ()
-		{
-		return s_cInstance;
-		}
+namespace AssimpView
+{
+
+    //-------------------------------------------------------------------------------
+    /* Corresponds to the "Display" combobox in the UI
+    */
+    //-------------------------------------------------------------------------------
+    class CDisplay
+    {
+    private:
+
+        // helper class
+        struct Info
+        {
+            Info( D3DXVECTOR4* p1,
+                AssetHelper::MeshHelper* p2,
+                const char* p3 )
+                : pclrColor( p1 ), pMesh( p2 ), szShaderParam( p3 ) {}
+
+            D3DXVECTOR4* pclrColor;
+            AssetHelper::MeshHelper* pMesh;
+            const char* szShaderParam;
+        };
+
+        // default constructor
+        CDisplay()
+            : m_iViewMode( VIEWMODE_FULL ),
+            m_pcCurrentTexture( NULL ),
+            m_pcCurrentNode( NULL ),
+            m_pcCurrentMaterial( NULL ),
+            m_hImageList( NULL ),
+            m_hRoot( NULL ),
+            m_fTextureZoom( 1000.0f )
+        {
+            this->m_aiImageList[ 0 ] = 0;
+            this->m_aiImageList[ 1 ] = 1;
+            this->m_aiImageList[ 2 ] = 2;
+            this->m_aiImageList[ 3 ] = 3;
+            this->m_aiImageList[ 4 ] = 4;
+
+            this->m_avCheckerColors[ 0 ].x = this->m_avCheckerColors[ 0 ].y = this->m_avCheckerColors[ 0 ].z = 0.4f;
+            this->m_avCheckerColors[ 1 ].x = this->m_avCheckerColors[ 1 ].y = this->m_avCheckerColors[ 1 ].z = 0.6f;
+        }
+
+    public:
+
+
+        //------------------------------------------------------------------
+        enum
+        {
+            // the full model is displayed
+            VIEWMODE_FULL,
+
+            // a material is displayed on a simple spjere as model
+            VIEWMODE_MATERIAL,
+
+            // a texture with an UV set mapped on it is displayed
+            VIEWMODE_TEXTURE,
+
+            // a single node in the scenegraph is displayed
+            VIEWMODE_NODE,
+        };
+
+
+        //------------------------------------------------------------------
+        // represents a texture in the tree view
+        struct TextureInfo
+        {
+            // texture info
+            IDirect3DTexture9** piTexture;
+
+            // Blend factor of the texture
+            float fBlend;
+
+            // blend operation for the texture
+            aiTextureOp eOp;
+
+            // UV index for the texture
+            unsigned int iUV;
+
+            // Associated tree item
+            HTREEITEM hTreeItem;
+
+            // Original path to the texture
+            std::string szPath;
+
+            // index of the corresponding material
+            unsigned int iMatIndex;
+
+            // type of the texture
+            unsigned int iType;
+        };
+
+        //------------------------------------------------------------------
+        // represents a node in the tree view
+        struct NodeInfo
+        {
+            // node object
+            aiNode* psNode;
+
+            // corresponding tree view item
+            HTREEITEM hTreeItem;
+        };
+
+        //------------------------------------------------------------------
+        // represents a mesh in the tree view
+        struct MeshInfo
+        {
+            // the mesh object
+            aiMesh* psMesh;
+
+            // corresponding tree view item
+            HTREEITEM hTreeItem;
+        };
+
+        //------------------------------------------------------------------
+        // represents a material in the tree view
+        struct MaterialInfo
+        {
+            // material index
+            unsigned int iIndex;
+
+            // material object
+            aiMaterial* psMaterial;
+
+            // ID3DXEffect interface
+            ID3DXEffect* piEffect;
+
+            // corresponding tree view item
+            HTREEITEM hTreeItem;
+        };
+
+        //------------------------------------------------------------------
+        // Singleton accessors
+        static CDisplay s_cInstance;
+        inline static CDisplay& Instance()
+        {
+            return s_cInstance;
+        }
 
 
 
 
-	//------------------------------------------------------------------
-	// Called during the render loop. Renders the scene (including the 
-	// HUD etc) in the current view mode
-	int OnRender();
+        //------------------------------------------------------------------
+        // Called during the render loop. Renders the scene (including the 
+        // HUD etc) in the current view mode
+        int OnRender();
 
 
-	//------------------------------------------------------------------
-	// called when the user selects another item in the "Display" tree 
-	// view the method determines the new view mode and performs all 
-	// required operations
-	// \param p_hTreeItem Selected tree view item
-	int OnSetup(HTREEITEM p_hTreeItem);
+        //------------------------------------------------------------------
+        // called when the user selects another item in the "Display" tree 
+        // view the method determines the new view mode and performs all 
+        // required operations
+        // \param p_hTreeItem Selected tree view item
+        int OnSetup( HTREEITEM p_hTreeItem );
 
 
-	//------------------------------------------------------------------
-	// Variant 1: Render the full scene with the asset
-	int RenderFullScene();
+        //------------------------------------------------------------------
+        // Variant 1: Render the full scene with the asset
+        int RenderFullScene();
 
 
 #if 0
 #if 0
-	//------------------------------------------------------------------
-	// Variant 2: Render only a part of the scene. One node to
-	// be exact
-	int RenderScenePart();
+        //------------------------------------------------------------------
+        // Variant 2: Render only a part of the scene. One node to
+        // be exact
+        int RenderScenePart();
 #endif
 #endif
 
 
-	//------------------------------------------------------------------
-	// Variant 3: Render a large sphere and map a given material on it
-	int RenderMaterialView();
-
-	//------------------------------------------------------------------
-	// Variant 4: Render a flat plane, map a texture on it and
-	// display the UV wire on it
-	int RenderTextureView();
-
-	//------------------------------------------------------------------
-	// Fill the UI combobox with a list of all supported view modi
-	//
-	// The display modes are added in order
-	int FillDisplayList(void);
-
-	//------------------------------------------------------------------
-	// Add a material and all sub textures to the display mode list
-	// hRoot - Handle to the root of the tree view
-	// iIndex - Material index
-	int AddMaterialToDisplayList(HTREEITEM hRoot, 
-		unsigned int iIndex);
-
-	//------------------------------------------------------------------
-	// Add a texture to the display list
-	// pcMat - material containing the texture
-	// hTexture - Handle to the material tree item
-	// szPath - Path to the texture
-	// iUVIndex - UV index to be used for the texture
-	// fBlendFactor - Blend factor to be used for the texture
-	// eTextureOp - texture operation to be used for the texture
-	int AddTextureToDisplayList(unsigned int iType,
-		unsigned int iIndex,
-		const aiString* szPath,
-		HTREEITEM hFX, 
-		unsigned int iUVIndex		= 0,
-		const float fBlendFactor	= 0.0f,
-		aiTextureOp eTextureOp		= aiTextureOp_Multiply,
-		unsigned int iMesh			= 0);
-
-	//------------------------------------------------------------------
-	// Add a node to the display list
-	// Recusrivly adds all subnodes as well
-	// iIndex - Index of the node in the parent's child list
-	// iDepth - Current depth of the node
-	// pcNode - Node object
-	// hRoot - Parent tree view node
-	int AddNodeToDisplayList(
-		unsigned int iIndex, 
-		unsigned int iDepth,
-		aiNode* pcNode,
-		HTREEITEM hRoot);
-
-	//------------------------------------------------------------------
-	// Add a mesh to the display list
-	// iIndex - Index of the mesh in the scene's mesh list
-	// hRoot - Parent tree view node
-	int AddMeshToDisplayList(
-		unsigned int iIndex, 
-		HTREEITEM hRoot);
-
-	//------------------------------------------------------------------
-	// Load the image list for the tree view item
-	int LoadImageList(void);
-
-	//------------------------------------------------------------------
-	// Expand all nodes in the tree 
-	int ExpandTree();
-
-	//------------------------------------------------------------------
-	// Fill the UI combobox with a list of all supported animations
-	// The animations are added in order
-	int FillAnimList(void);
-
-	//------------------------------------------------------------------
-	// Clear the combox box containing the list of animations
-	int ClearAnimList(void);
-
-	//------------------------------------------------------------------
-	// Clear the combox box containing the list of scenegraph items
-	int ClearDisplayList(void);
-
-	//------------------------------------------------------------------
-	// Fill in the default statistics
-	int FillDefaultStatistics(void);
-
-	//------------------------------------------------------------------
-	// Called by LoadAsset()
-	// reset the class instance to the default values
-	int Reset(void);
-
-	//------------------------------------------------------------------
-	// Replace the texture that is current selected with
-	// a new texture
-	int ReplaceCurrentTexture(const char* szPath);
-
-	//------------------------------------------------------------------
-	// Display the context menu (if there) for the specified tree item
-	// hItem Valid tree view item handle
-	int ShowTreeViewContextMenu(HTREEITEM hItem);
-
-	//------------------------------------------------------------------
-	// Event handling for pop-up menus displayed by th tree view
-	int HandleTreeViewPopup(WPARAM wParam,LPARAM lParam);
-
-	//------------------------------------------------------------------
-	// Enable animation-related parts of the UI
-	int EnableAnimTools(BOOL hm) ;
-
-	//------------------------------------------------------------------
-	// setter for m_iViewMode
-	inline void SetViewMode(unsigned int p_iNew)
-	{
-		this->m_iViewMode = p_iNew;
-	}
-
-	//------------------------------------------------------------------
-	// getter for m_iViewMode
-	inline unsigned int GetViewMode()
-	{
-		return m_iViewMode;
-	}
-
-	//------------------------------------------------------------------
-	// change the texture view's zoom factor
-	inline void SetTextureViewZoom(float f)
-	{
-		// FIX: Removed log(), seems to make more problems than it fixes
-		this->m_fTextureZoom += f* 15;
-		if (this->m_fTextureZoom < 0.05f)this->m_fTextureZoom = 0.05f;
-	}
-
-	//------------------------------------------------------------------
-	// change the texture view's offset on the x axis
-	inline void SetTextureViewOffsetX(float f)
-	{
-		this->m_vTextureOffset.x += f;
-	}
-
-	//------------------------------------------------------------------
-	// change the texture view's offset on the y axis
-	inline void SetTextureViewOffsetY(float f)
-	{
-		this->m_vTextureOffset.y += f;
-	}
-
-	//------------------------------------------------------------------
-	// add a new texture to the list
-	inline void AddTexture(const TextureInfo& info)
-	{
-		this->m_asTextures.push_back(info);
-	}
-
-	//------------------------------------------------------------------
-	// add a new node to the list
-	inline void AddNode(const NodeInfo& info)
-	{
-		this->m_asNodes.push_back(info);
-	}
-
-	//------------------------------------------------------------------
-	// add a new mesh to the list
-	inline void AddMesh(const MeshInfo& info)
-	{
-		this->m_asMeshes.push_back(info);
-	}
-
-	//------------------------------------------------------------------
-	// add a new material to the list
-	inline void AddMaterial(const MaterialInfo& info)
-	{
-		this->m_asMaterials.push_back(info);
-	}
-
-	//------------------------------------------------------------------
-	// set the primary color of the checker pattern background
-	inline void SetFirstCheckerColor(D3DXVECTOR4 c)
-	{
-		this->m_avCheckerColors[0] = c;
-	}
-
-	//------------------------------------------------------------------
-	// set the secondary color of the checker pattern background
-	inline void SetSecondCheckerColor(D3DXVECTOR4 c)
-	{
-		this->m_avCheckerColors[1] = c;
-	}
-
-	//------------------------------------------------------------------
-	// get the primary color of the checker pattern background
-	inline const D3DXVECTOR4* GetFirstCheckerColor() const
-	{
-		return &this->m_avCheckerColors[0];
-	}
-
-	//------------------------------------------------------------------
-	// get the secondary color of the checker pattern background
-	inline const D3DXVECTOR4* GetSecondCheckerColor() const
-	{
-		return &this->m_avCheckerColors[1];
-	}
-
-private:
-
-	//------------------------------------------------------------------
-	// Render a screen-filling square using the checker pattern shader
-	int RenderPatternBG();
-
-	//------------------------------------------------------------------
-	// Render a given node in the scenegraph
-	// piNode Node to be rendered
-	// piMatrix Current transformation matrix
-	// bAlpha Render alpha or opaque objects only?
-	int RenderNode (aiNode* piNode,const aiMatrix4x4& piMatrix,
-		bool bAlpha = false);
-
-	//------------------------------------------------------------------
-	// Setup the camera for the stereo view rendering mode
-	int SetupStereoView();
-
-	//------------------------------------------------------------------
-	// Render the second view (for the right eye) in stereo mod
-	// m - World matrix
-	int RenderStereoView(const aiMatrix4x4& m);
-
-	//------------------------------------------------------------------
-	// Handle user input
-	int HandleInput();
-
-	//------------------------------------------------------------------
-	// Handle user input for the texture viewer
-	int HandleInputTextureView();
-
-	//------------------------------------------------------------------
-	// Handle user input if no asset is loaded
-	int HandleInputEmptyScene();
-
-	//------------------------------------------------------------------
-	// Draw the HUD (call only if FPS mode isn't active)
-	int DrawHUD();
-
-	//------------------------------------------------------------------
-	// Used by OnSetup().
-	// Do everything necessary to switch to texture view mode
-	int OnSetupTextureView(TextureInfo* pcNew);
-
-	//------------------------------------------------------------------
-	// Used by OnSetup().
-	// Do everything necessary to switch to material view mode
-	int OnSetupMaterialView(MaterialInfo* pcNew);
-
-	//------------------------------------------------------------------
-	// Used by OnSetup().
-	// Do everything necessary to switch to node view mode
-	int OnSetupNodeView(NodeInfo* pcNew);
-
-	//------------------------------------------------------------------
-	// Used by OnSetup().
-	// Do everything necessary to switch back to normal view mode
-	int OnSetupNormalView();
-
-	//------------------------------------------------------------------
-	// Used by HandleTreeViewPopup().
-	int HandleTreeViewPopup2(WPARAM wParam,LPARAM lParam);
-
-	//------------------------------------------------------------------
-	// Render skeleton
-	int RenderSkeleton (aiNode* piNode,const aiMatrix4x4& piMatrix, 
-		const aiMatrix4x4& parent);
-
-	
+        //------------------------------------------------------------------
+        // Variant 3: Render a large sphere and map a given material on it
+        int RenderMaterialView();
+
+        //------------------------------------------------------------------
+        // Variant 4: Render a flat plane, map a texture on it and
+        // display the UV wire on it
+        int RenderTextureView();
+
+        //------------------------------------------------------------------
+        // Fill the UI combobox with a list of all supported view modi
+        //
+        // The display modes are added in order
+        int FillDisplayList( void );
+
+        //------------------------------------------------------------------
+        // Add a material and all sub textures to the display mode list
+        // hRoot - Handle to the root of the tree view
+        // iIndex - Material index
+        int AddMaterialToDisplayList( HTREEITEM hRoot,
+            unsigned int iIndex );
+
+        //------------------------------------------------------------------
+        // Add a texture to the display list
+        // pcMat - material containing the texture
+        // hTexture - Handle to the material tree item
+        // szPath - Path to the texture
+        // iUVIndex - UV index to be used for the texture
+        // fBlendFactor - Blend factor to be used for the texture
+        // eTextureOp - texture operation to be used for the texture
+        int AddTextureToDisplayList( unsigned int iType,
+            unsigned int iIndex,
+            const aiString* szPath,
+            HTREEITEM hFX,
+            unsigned int iUVIndex = 0,
+            const float fBlendFactor = 0.0f,
+            aiTextureOp eTextureOp = aiTextureOp_Multiply,
+            unsigned int iMesh = 0 );
+
+        //------------------------------------------------------------------
+        // Add a node to the display list
+        // Recusrivly adds all subnodes as well
+        // iIndex - Index of the node in the parent's child list
+        // iDepth - Current depth of the node
+        // pcNode - Node object
+        // hRoot - Parent tree view node
+        int AddNodeToDisplayList(
+            unsigned int iIndex,
+            unsigned int iDepth,
+            aiNode* pcNode,
+            HTREEITEM hRoot );
+
+        //------------------------------------------------------------------
+        // Add a mesh to the display list
+        // iIndex - Index of the mesh in the scene's mesh list
+        // hRoot - Parent tree view node
+        int AddMeshToDisplayList(
+            unsigned int iIndex,
+            HTREEITEM hRoot );
+
+        //------------------------------------------------------------------
+        // Load the image list for the tree view item
+        int LoadImageList( void );
+
+        //------------------------------------------------------------------
+        // Expand all nodes in the tree 
+        int ExpandTree();
+
+        //------------------------------------------------------------------
+        // Fill the UI combobox with a list of all supported animations
+        // The animations are added in order
+        int FillAnimList( void );
+
+        //------------------------------------------------------------------
+        // Clear the combox box containing the list of animations
+        int ClearAnimList( void );
+
+        //------------------------------------------------------------------
+        // Clear the combox box containing the list of scenegraph items
+        int ClearDisplayList( void );
+
+        //------------------------------------------------------------------
+        // Fill in the default statistics
+        int FillDefaultStatistics( void );
+
+        //------------------------------------------------------------------
+        // Called by LoadAsset()
+        // reset the class instance to the default values
+        int Reset( void );
+
+        //------------------------------------------------------------------
+        // Replace the texture that is current selected with
+        // a new texture
+        int ReplaceCurrentTexture( const char* szPath );
+
+        //------------------------------------------------------------------
+        // Display the context menu (if there) for the specified tree item
+        // hItem Valid tree view item handle
+        int ShowTreeViewContextMenu( HTREEITEM hItem );
+
+        //------------------------------------------------------------------
+        // Event handling for pop-up menus displayed by th tree view
+        int HandleTreeViewPopup( WPARAM wParam, LPARAM lParam );
+
+        //------------------------------------------------------------------
+        // Enable animation-related parts of the UI
+        int EnableAnimTools( BOOL hm );
+
+        //------------------------------------------------------------------
+        // setter for m_iViewMode
+        inline void SetViewMode( unsigned int p_iNew )
+        {
+            this->m_iViewMode = p_iNew;
+        }
+
+        //------------------------------------------------------------------
+        // getter for m_iViewMode
+        inline unsigned int GetViewMode()
+        {
+            return m_iViewMode;
+        }
+
+        //------------------------------------------------------------------
+        // change the texture view's zoom factor
+        inline void SetTextureViewZoom( float f )
+        {
+            // FIX: Removed log(), seems to make more problems than it fixes
+            this->m_fTextureZoom += f * 15;
+            if( this->m_fTextureZoom < 0.05f )this->m_fTextureZoom = 0.05f;
+        }
+
+        //------------------------------------------------------------------
+        // change the texture view's offset on the x axis
+        inline void SetTextureViewOffsetX( float f )
+        {
+            this->m_vTextureOffset.x += f;
+        }
+
+        //------------------------------------------------------------------
+        // change the texture view's offset on the y axis
+        inline void SetTextureViewOffsetY( float f )
+        {
+            this->m_vTextureOffset.y += f;
+        }
+
+        //------------------------------------------------------------------
+        // add a new texture to the list
+        inline void AddTexture( const TextureInfo& info )
+        {
+            this->m_asTextures.push_back( info );
+        }
+
+        //------------------------------------------------------------------
+        // add a new node to the list
+        inline void AddNode( const NodeInfo& info )
+        {
+            this->m_asNodes.push_back( info );
+        }
+
+        //------------------------------------------------------------------
+        // add a new mesh to the list
+        inline void AddMesh( const MeshInfo& info )
+        {
+            this->m_asMeshes.push_back( info );
+        }
+
+        //------------------------------------------------------------------
+        // add a new material to the list
+        inline void AddMaterial( const MaterialInfo& info )
+        {
+            this->m_asMaterials.push_back( info );
+        }
+
+        //------------------------------------------------------------------
+        // set the primary color of the checker pattern background
+        inline void SetFirstCheckerColor( D3DXVECTOR4 c )
+        {
+            this->m_avCheckerColors[ 0 ] = c;
+        }
+
+        //------------------------------------------------------------------
+        // set the secondary color of the checker pattern background
+        inline void SetSecondCheckerColor( D3DXVECTOR4 c )
+        {
+            this->m_avCheckerColors[ 1 ] = c;
+        }
+
+        //------------------------------------------------------------------
+        // get the primary color of the checker pattern background
+        inline const D3DXVECTOR4* GetFirstCheckerColor() const
+        {
+            return &this->m_avCheckerColors[ 0 ];
+        }
+
+        //------------------------------------------------------------------
+        // get the secondary color of the checker pattern background
+        inline const D3DXVECTOR4* GetSecondCheckerColor() const
+        {
+            return &this->m_avCheckerColors[ 1 ];
+        }
+
+    private:
+
+        //------------------------------------------------------------------
+        // Render a screen-filling square using the checker pattern shader
+        int RenderPatternBG();
+
+        //------------------------------------------------------------------
+        // Render a given node in the scenegraph
+        // piNode Node to be rendered
+        // piMatrix Current transformation matrix
+        // bAlpha Render alpha or opaque objects only?
+        int RenderNode( aiNode* piNode, const aiMatrix4x4& piMatrix,
+            bool bAlpha = false );
+
+        //------------------------------------------------------------------
+        // Setup the camera for the stereo view rendering mode
+        int SetupStereoView();
+
+        //------------------------------------------------------------------
+        // Render the second view (for the right eye) in stereo mod
+        // m - World matrix
+        int RenderStereoView( const aiMatrix4x4& m );
+
+        //------------------------------------------------------------------
+        // Handle user input
+        int HandleInput();
+
+        //------------------------------------------------------------------
+        // Handle user input for the texture viewer
+        int HandleInputTextureView();
+
+        //------------------------------------------------------------------
+        // Handle user input if no asset is loaded
+        int HandleInputEmptyScene();
+
+        //------------------------------------------------------------------
+        // Draw the HUD (call only if FPS mode isn't active)
+        int DrawHUD();
+
+        //------------------------------------------------------------------
+        // Used by OnSetup().
+        // Do everything necessary to switch to texture view mode
+        int OnSetupTextureView( TextureInfo* pcNew );
+
+        //------------------------------------------------------------------
+        // Used by OnSetup().
+        // Do everything necessary to switch to material view mode
+        int OnSetupMaterialView( MaterialInfo* pcNew );
+
+        //------------------------------------------------------------------
+        // Used by OnSetup().
+        // Do everything necessary to switch to node view mode
+        int OnSetupNodeView( NodeInfo* pcNew );
+
+        //------------------------------------------------------------------
+        // Used by OnSetup().
+        // Do everything necessary to switch back to normal view mode
+        int OnSetupNormalView();
+
+        //------------------------------------------------------------------
+        // Used by HandleTreeViewPopup().
+        int HandleTreeViewPopup2( WPARAM wParam, LPARAM lParam );
+
+        //------------------------------------------------------------------
+        // Render skeleton
+        int RenderSkeleton( aiNode* piNode, const aiMatrix4x4& piMatrix,
+            const aiMatrix4x4& parent );
+
+
 
 
-private:
+    private:
 
 
-	// view mode
-	unsigned int m_iViewMode;
+        // view mode
+        unsigned int m_iViewMode;
 
 
-	// List of all textures in the display CB
-	std::vector<TextureInfo> m_asTextures;
+        // List of all textures in the display CB
+        std::vector<TextureInfo> m_asTextures;
 
 
-	// current texture or NULL if no texture is active
-	TextureInfo* m_pcCurrentTexture;
+        // current texture or NULL if no texture is active
+        TextureInfo* m_pcCurrentTexture;
 
 
-	// List of all node in the display CB
-	std::vector<NodeInfo> m_asNodes;
+        // List of all node in the display CB
+        std::vector<NodeInfo> m_asNodes;
 
 
-	// List of all node in the display CB
-	std::vector<MeshInfo> m_asMeshes;
+        // List of all node in the display CB
+        std::vector<MeshInfo> m_asMeshes;
 
 
-	// current Node or NULL if no Node is active
-	NodeInfo* m_pcCurrentNode;
+        // current Node or NULL if no Node is active
+        NodeInfo* m_pcCurrentNode;
 
 
-	// List of all materials in the display CB
-	std::vector<MaterialInfo> m_asMaterials;
+        // List of all materials in the display CB
+        std::vector<MaterialInfo> m_asMaterials;
 
 
-	// current material or NULL if no material is active
-	MaterialInfo* m_pcCurrentMaterial;
+        // current material or NULL if no material is active
+        MaterialInfo* m_pcCurrentMaterial;
 
 
-	// indices into the image list of the "display" tree view control
-	unsigned int m_aiImageList[5]; /* = {0,1,2,3,4};*/
+        // indices into the image list of the "display" tree view control
+        unsigned int m_aiImageList[ 5 ]; /* = {0,1,2,3,4};*/
 
 
-	// Image list
-	HIMAGELIST m_hImageList;
+        // Image list
+        HIMAGELIST m_hImageList;
 
 
-	// Root node of the tree, "Model"
-	HTREEITEM m_hRoot;
+        // Root node of the tree, "Model"
+        HTREEITEM m_hRoot;
 
 
-	// Current zoom factor of the texture viewer
-	float m_fTextureZoom;
+        // Current zoom factor of the texture viewer
+        float m_fTextureZoom;
 
 
-	// Current offset (in pixels) of the texture viewer
-	aiVector2D m_vTextureOffset;
+        // Current offset (in pixels) of the texture viewer
+        aiVector2D m_vTextureOffset;
 
 
-	// Colors used to draw the checker pattern (for the
-	// texture viewer as background )
-	D3DXVECTOR4 m_avCheckerColors[2];
+        // Colors used to draw the checker pattern (for the
+        // texture viewer as background )
+        D3DXVECTOR4 m_avCheckerColors[ 2 ];
 
 
-	// View projection matrix
-	aiMatrix4x4 mViewProjection;
-	aiVector3D vPos;
-	};
+        // View projection matrix
+        aiMatrix4x4 mViewProjection;
+        aiVector3D vPos;
+    };
 
 
+}
 #endif // AV_DISPLAY_H_INCLUDE
 #endif // AV_DISPLAY_H_INCLUDE

+ 0 - 2
tools/assimp_view/HelpDialog.cpp

@@ -39,14 +39,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ---------------------------------------------------------------------------
 ---------------------------------------------------------------------------
 */
 */
 
 
-#include "stdafx.h"
 #include "assimp_view.h"
 #include "assimp_view.h"
 
 
 #include "richedit.h"
 #include "richedit.h"
 
 
 namespace AssimpView {
 namespace AssimpView {
 
 
-
 //-------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------
 // Message procedure for the help dialog
 // Message procedure for the help dialog
 //-------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------

+ 0 - 2
tools/assimp_view/Input.cpp

@@ -39,10 +39,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ---------------------------------------------------------------------------
 ---------------------------------------------------------------------------
 */
 */
 
 
-#include "stdafx.h"
 #include "assimp_view.h"
 #include "assimp_view.h"
 
 
-
 namespace AssimpView {
 namespace AssimpView {
 
 
 //-------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------

+ 1 - 4
tools/assimp_view/LogDisplay.cpp

@@ -39,14 +39,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ---------------------------------------------------------------------------
 ---------------------------------------------------------------------------
 */
 */
 
 
-#include "stdafx.h"
 #include "assimp_view.h"
 #include "assimp_view.h"
 
 
-
 namespace AssimpView {
 namespace AssimpView {
 
 
-
-/* extern */ CLogDisplay CLogDisplay::s_cInstance;
+CLogDisplay CLogDisplay::s_cInstance;
 
 
 //-------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------
 void CLogDisplay::AddEntry(const std::string& szText,
 void CLogDisplay::AddEntry(const std::string& szText,

+ 45 - 42
tools/assimp_view/LogDisplay.h

@@ -38,59 +38,62 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ---------------------------------------------------------------------------
 ---------------------------------------------------------------------------
 */
 */
+#pragma once
 
 
-#if (!defined AV_LOG_DISPLAY_H_INCLUDED)
-#define AV_LOG_DISPLAY_H_INCLUDE
+#include <list>
 
 
-//-------------------------------------------------------------------------------
-/**	\brief Class to display log strings in the upper right corner of the view
-*/
-//-------------------------------------------------------------------------------
-class CLogDisplay
-	{
-private:
+namespace AssimpView
+{
+
+    //-------------------------------------------------------------------------------
+    /**	\brief Class to display log strings in the upper right corner of the view
+    */
+    //-------------------------------------------------------------------------------
+    class CLogDisplay
+    {
+    private:
 
 
-	CLogDisplay()  {}
+        CLogDisplay()  {}
 
 
-public:
+    public:
 
 
-	// data structure for an entry in the log queue
-	struct SEntry
-		{
-		SEntry ()
-			:
-			clrColor(D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0x00)), dwStartTicks(0)
-				{}
+        // data structure for an entry in the log queue
+        struct SEntry
+        {
+            SEntry()
+                :
+                clrColor( D3DCOLOR_ARGB( 0xFF, 0xFF, 0xFF, 0x00 ) ), dwStartTicks( 0 )
+            {}
 
 
-		std::string szText;
-		D3DCOLOR clrColor;
-		DWORD dwStartTicks;
-		};
+            std::string szText;
+            D3DCOLOR clrColor;
+            DWORD dwStartTicks;
+        };
 
 
-	// Singleton accessors
-	static CLogDisplay s_cInstance;
-	inline static CLogDisplay& Instance ()
-		{
-		return s_cInstance;
-		}
+        // Singleton accessors
+        static CLogDisplay s_cInstance;
+        inline static CLogDisplay& Instance()
+        {
+            return s_cInstance;
+        }
 
 
-	// Add an entry to the log queue
-	void AddEntry(const std::string& szText,
-		const D3DCOLOR clrColor = D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0x00));
+        // Add an entry to the log queue
+        void AddEntry( const std::string& szText,
+            const D3DCOLOR clrColor = D3DCOLOR_ARGB( 0xFF, 0xFF, 0xFF, 0x00 ) );
 
 
-	// Release any native resources associated with the instance
-	void ReleaseNativeResource();
+        // Release any native resources associated with the instance
+        void ReleaseNativeResource();
 
 
-	// Recreate any native resources associated with the instance
-	void RecreateNativeResource();
+        // Recreate any native resources associated with the instance
+        void RecreateNativeResource();
 
 
-	// Called during the render loop
-	void OnRender();
+        // Called during the render loop
+        void OnRender();
 
 
-private:
+    private:
 
 
-	std::list<SEntry> asEntries;
-	ID3DXFont* piFont;
-	};
+        std::list<SEntry> asEntries;
+        ID3DXFont* piFont;
+    };
 
 
-#endif // AV_LOG_DISPLAY_H_INCLUDE
+}

+ 2 - 2
tools/assimp_view/LogWindow.cpp

@@ -39,13 +39,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ---------------------------------------------------------------------------
 ---------------------------------------------------------------------------
 */
 */
 
 
-#include "stdafx.h"
 #include "assimp_view.h"
 #include "assimp_view.h"
 #include "richedit.h"
 #include "richedit.h"
 
 
 namespace AssimpView {
 namespace AssimpView {
 
 
-/* extern */ CLogWindow CLogWindow::s_cInstance;
+CLogWindow CLogWindow::s_cInstance;
+
 extern HKEY g_hRegistry;
 extern HKEY g_hRegistry;
 
 
 // header for the RTF log file
 // header for the RTF log file

+ 65 - 60
tools/assimp_view/LogWindow.h

@@ -42,87 +42,92 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #if (!defined AV_LOG_WINDOW_H_INCLUDED)
 #if (!defined AV_LOG_WINDOW_H_INCLUDED)
 #define AV_LOG_WINDOW_H_INCLUDE
 #define AV_LOG_WINDOW_H_INCLUDE
 
 
-
-//-------------------------------------------------------------------------------
-/**	\brief Subclass of Assimp::LogStream used to add all log messages to the
- *         log window.
-*/
-//-------------------------------------------------------------------------------
-class CMyLogStream : public Assimp::LogStream
+namespace AssimpView
 {
 {
-public:
-	/**	@brief	Implementation of the abstract method	*/
-	void write(const char* message);
-};
 
 
 
 
-//-------------------------------------------------------------------------------
-/**	\brief Class to display log strings in a separate window
-*/
-//-------------------------------------------------------------------------------
-class CLogWindow
-	{
-private:
+    //-------------------------------------------------------------------------------
+    /**	\brief Subclass of Assimp::LogStream used to add all log messages to the
+     *         log window.
+     */
+    //-------------------------------------------------------------------------------
+    class CMyLogStream : public Assimp::LogStream
+    {
+    public:
+        /**	@brief	Implementation of the abstract method	*/
+        void write( const char* message );
+    };
+
+
+    //-------------------------------------------------------------------------------
+    /**	\brief Class to display log strings in a separate window
+    */
+    //-------------------------------------------------------------------------------
+    class CLogWindow
+    {
+    private:
+
+        friend class CMyLogStream;
+        friend INT_PTR CALLBACK LogDialogProc( HWND hwndDlg, UINT uMsg,
+            WPARAM wParam, LPARAM lParam );
 
 
-	friend class CMyLogStream;
-	friend INT_PTR CALLBACK LogDialogProc(HWND hwndDlg,UINT uMsg,
-		WPARAM wParam,LPARAM lParam);
+        CLogWindow() : hwnd( NULL ), bIsVisible( false ), bUpdate( true ) {}
 
 
-	CLogWindow() : hwnd(NULL),  bIsVisible(false), bUpdate(true) {}
+    public:
 
 
-public:
 
 
+        // Singleton accessors
+        static CLogWindow s_cInstance;
+        inline static CLogWindow& Instance()
+        {
+            return s_cInstance;
+        }
 
 
-	// Singleton accessors
-	static CLogWindow s_cInstance;
-	inline static CLogWindow& Instance ()
-		{
-		return s_cInstance;
-		}
+        // initializes the log window
+        void Init();
 
 
-	// initializes the log window
-	void Init ();
+        // Shows the log window
+        void Show();
 
 
-	// Shows the log window
-	void Show();
+        // Clears the log window
+        void Clear();
 
 
-	// Clears the log window
-	void Clear();
+        // Save the log window to an user-defined file
+        void Save();
 
 
-	// Save the log window to an user-defined file
-	void Save();
+        // write a line to the log window
+        void WriteLine( const char* message );
 
 
-	// write a line to the log window
-	void WriteLine(const char* message);
+        // Set the bUpdate member
+        inline void SetAutoUpdate( bool b )
+        {
+            this->bUpdate = b;
+        }
 
 
-	// Set the bUpdate member
-	inline void SetAutoUpdate(bool b)
-	{
-		this->bUpdate = b;
-	}
+        // updates the log file
+        void Update();
 
 
-	// updates the log file
-	void Update();
+    private:
 
 
-private:
+        // Window handle
+        HWND hwnd;
 
 
-	// Window handle
-	HWND hwnd;
+        // current text of the window (contains RTF tags)
+        std::string szText;
+        std::string szPlainText;
 
 
-	// current text of the window (contains RTF tags)
-	std::string szText;
-	std::string szPlainText;
+        // is the log window currently visible?
+        bool bIsVisible;
 
 
-	// is the log window currently visible?
-	bool bIsVisible;
+        // Specified whether each new log message updates the log automatically
+        bool bUpdate;
 
 
-	// Specified whether each new log message updates the log automatically
-	bool bUpdate;
 
 
+    public:
+        // associated log stream
+        CMyLogStream* pcStream;
+    };
 
 
-public:
-	// associated log stream
-	CMyLogStream* pcStream;
-	};
+}
 
 
 #endif // AV_LOG_DISPLA
 #endif // AV_LOG_DISPLA

+ 1392 - 1301
tools/assimp_view/Material.cpp

@@ -38,15 +38,106 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ---------------------------------------------------------------------------
 ---------------------------------------------------------------------------
 */
 */
-
-#include "stdafx.h"
 #include "assimp_view.h"
 #include "assimp_view.h"
 
 
+#include "MaterialManager.h"
+#include "AssetHelper.h"
+
+#include <assimp/cimport.h>
+#include <assimp/Importer.hpp>
+#include <assimp/ai_assert.h>
+#include <assimp/cfileio.h>
+#include <assimp/postprocess.h>
+#include <assimp/scene.h>
+#include <assimp/IOSystem.hpp>
+#include <assimp/IOStream.hpp>
+#include <assimp/LogStream.hpp>
+#include <assimp/DefaultLogger.hpp>
+#include <../code/StringComparison.h>
+
+#include <vector>
+#include <algorithm>
 
 
 namespace AssimpView {
 namespace AssimpView {
+    
+using namespace Assimp;
+
+extern std::string g_szMaterialShader;
+extern HINSTANCE g_hInstance				/*= NULL*/;
+extern HWND g_hDlg							/*= NULL*/;
+extern IDirect3D9* g_piD3D					/*= NULL*/;
+extern IDirect3DDevice9* g_piDevice			/*= NULL*/;
+extern IDirect3DVertexDeclaration9* gDefaultVertexDecl /*= NULL*/;
+extern double g_fFPS						/*= 0.0f*/;
+extern char g_szFileName[ MAX_PATH ];
+extern ID3DXEffect* g_piDefaultEffect		/*= NULL*/;
+extern ID3DXEffect* g_piNormalsEffect		/*= NULL*/;
+extern ID3DXEffect* g_piPassThroughEffect	/*= NULL*/;
+extern ID3DXEffect* g_piPatternEffect		/*= NULL*/;
+extern bool g_bMousePressed					/*= false*/;
+extern bool g_bMousePressedR				/*= false*/;
+extern bool g_bMousePressedM				/*= false*/;
+extern bool g_bMousePressedBoth				/*= false*/;
+extern float g_fElpasedTime					/*= 0.0f*/;
+extern D3DCAPS9 g_sCaps;
+extern bool g_bLoadingFinished				/*= false*/;
+extern HANDLE g_hThreadHandle				/*= NULL*/;
+extern float g_fWheelPos					/*= -10.0f*/;
+extern bool g_bLoadingCanceled				/*= false*/;
+extern IDirect3DTexture9* g_pcTexture		/*= NULL*/;
+
+extern aiMatrix4x4 g_mWorld;
+extern aiMatrix4x4 g_mWorldRotate;
+extern aiVector3D g_vRotateSpeed			/*= aiVector3D(0.5f,0.5f,0.5f)*/;
+
+extern aiVector3D g_avLightDirs[ 1 ] /* =
+                                        {	aiVector3D(-0.5f,0.6f,0.2f) ,
+                                        aiVector3D(-0.5f,0.5f,0.5f)} */;
+
+
+extern POINT g_mousePos						/*= {0,0};*/;
+extern POINT g_LastmousePos					/*= {0,0}*/;
+extern bool g_bFPSView						/*= false*/;
+extern bool g_bInvert						/*= false*/;
+extern EClickPos g_eClick;
+extern unsigned int g_iCurrentColor			/*= 0*/;
+
+// NOTE: The light intensity is separated from the color, it can
+// directly be manipulated using the middle mouse button.
+// When the user chooses a color from the palette the intensity
+// is reset to 1.0
+// index[2] is the ambient color
+extern float g_fLightIntensity				/*=0.0f*/;
+extern D3DCOLOR g_avLightColors[ 3 ];
+
+extern RenderOptions g_sOptions;
+extern Camera g_sCamera;
+extern AssetHelper *g_pcAsset				/*= NULL*/;
+
+
+//
+// Contains the mask image for the HUD 
+// (used to determine the position of a click)
+//
+// The size of the image is identical to the size of the main 
+// HUD texture
+//
+extern unsigned char* g_szImageMask			/*= NULL*/;
+
+
+extern float g_fACMR /*= 3.0f*/;
+extern IDirect3DQuery9* g_piQuery;
+
+extern bool g_bPlay						/*= false*/;
+
+extern double g_dCurrent;
+extern float g_smoothAngle /*= 80.f*/;
+
+extern unsigned int ppsteps, ppstepsdefault;
+extern bool nopointslines;
 
 
 
 
-/*static */ CMaterialManager CMaterialManager::s_cInstance;
+CMaterialManager CMaterialManager::s_cInstance;
 
 
 //-------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------
 // D3DX callback function to fill a texture with a checkers pattern
 // D3DX callback function to fill a texture with a checkers pattern
@@ -54,1350 +145,1350 @@ namespace AssimpView {
 // This pattern is used to mark textures which could not be loaded
 // This pattern is used to mark textures which could not be loaded
 //-------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------
 VOID WINAPI FillFunc(D3DXVECTOR4* pOut, 
 VOID WINAPI FillFunc(D3DXVECTOR4* pOut, 
-					 CONST D3DXVECTOR2* pTexCoord, 
-					 CONST D3DXVECTOR2* pTexelSize, 
-					 LPVOID pData)
+                     CONST D3DXVECTOR2* pTexCoord, 
+                     CONST D3DXVECTOR2* pTexelSize, 
+                     LPVOID pData)
 {
 {
-	UNREFERENCED_PARAMETER(pData);
-	UNREFERENCED_PARAMETER(pTexelSize);
-
-	// generate a nice checker pattern (yellow/black)
-	// size of a square: 32 * 32 px
-	unsigned int iX = (unsigned int)(pTexCoord->x * 256.0f);
-	unsigned int iY = (unsigned int)(pTexCoord->y * 256.0f);
-
-	bool bBlack = false;
-	if ((iX / 32) % 2 == 0)
-	{
-		if ((iY / 32) % 2 == 0)bBlack = true;
-	}
-	else 
-	{
-		if ((iY / 32) % 2 != 0)bBlack = true;
-	}
-	pOut->w = 1.0f;
-	if (bBlack)
-	{
-		pOut->x = pOut->y = pOut->z = 0.0f;
-	}
-	else
-	{
-		pOut->x = pOut->y = 1.0f;
-		pOut->z = 0.0f;
-	}
-	return;
+    UNREFERENCED_PARAMETER(pData);
+    UNREFERENCED_PARAMETER(pTexelSize);
+
+    // generate a nice checker pattern (yellow/black)
+    // size of a square: 32 * 32 px
+    unsigned int iX = (unsigned int)(pTexCoord->x * 256.0f);
+    unsigned int iY = (unsigned int)(pTexCoord->y * 256.0f);
+
+    bool bBlack = false;
+    if ((iX / 32) % 2 == 0)
+    {
+        if ((iY / 32) % 2 == 0)bBlack = true;
+    }
+    else 
+    {
+        if ((iY / 32) % 2 != 0)bBlack = true;
+    }
+    pOut->w = 1.0f;
+    if (bBlack)
+    {
+        pOut->x = pOut->y = pOut->z = 0.0f;
+    }
+    else
+    {
+        pOut->x = pOut->y = 1.0f;
+        pOut->z = 0.0f;
+    }
+    return;
 }
 }
 
 
 //-------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------
 int CMaterialManager::UpdateSpecularMaterials()
 int CMaterialManager::UpdateSpecularMaterials()
-	{
-	if (g_pcAsset && g_pcAsset->pcScene)
-		{
-		for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i)
-			{
-			if (aiShadingMode_Phong == g_pcAsset->apcMeshes[i]->eShadingMode)
-				{
-				this->DeleteMaterial(g_pcAsset->apcMeshes[i]);
-				this->CreateMaterial(g_pcAsset->apcMeshes[i],g_pcAsset->pcScene->mMeshes[i]);
-				}
-			}
-		}
-	return 1;
-	}
+    {
+    if (g_pcAsset && g_pcAsset->pcScene)
+        {
+        for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i)
+            {
+            if (aiShadingMode_Phong == g_pcAsset->apcMeshes[i]->eShadingMode)
+                {
+                this->DeleteMaterial(g_pcAsset->apcMeshes[i]);
+                this->CreateMaterial(g_pcAsset->apcMeshes[i],g_pcAsset->pcScene->mMeshes[i]);
+                }
+            }
+        }
+    return 1;
+    }
 //-------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------
 int CMaterialManager::SetDefaultTexture(IDirect3DTexture9** p_ppiOut)
 int CMaterialManager::SetDefaultTexture(IDirect3DTexture9** p_ppiOut)
 {
 {
-	if  (sDefaultTexture) {
-		sDefaultTexture->AddRef();
-		*p_ppiOut = sDefaultTexture;
-		return 1;
-	}
-	if(FAILED(g_piDevice->CreateTexture(
-		256,
-		256,
-		0,
-		0,
-		D3DFMT_A8R8G8B8,
-		D3DPOOL_MANAGED,
-		p_ppiOut,
-		NULL)))
-	{
-		CLogDisplay::Instance().AddEntry("[ERROR] Unable to create default texture",
-			D3DCOLOR_ARGB(0xFF,0xFF,0,0));
-
-		*p_ppiOut = NULL;
-		return 0;
-	}
-	D3DXFillTexture(*p_ppiOut,&FillFunc,NULL);
-	sDefaultTexture = *p_ppiOut;
-	sDefaultTexture->AddRef();
-
-	// {9785DA94-1D96-426b-B3CB-BADC36347F5E}
-	static const GUID guidPrivateData = 
-		{ 0x9785da94, 0x1d96, 0x426b, 
-		{ 0xb3, 0xcb, 0xba, 0xdc, 0x36, 0x34, 0x7f, 0x5e } };
-
-	uint32_t iData = 0xFFFFFFFF;
-	(*p_ppiOut)->SetPrivateData(guidPrivateData,&iData,4,0);
-	return 1;
+    if  (sDefaultTexture) {
+        sDefaultTexture->AddRef();
+        *p_ppiOut = sDefaultTexture;
+        return 1;
+    }
+    if(FAILED(g_piDevice->CreateTexture(
+        256,
+        256,
+        0,
+        0,
+        D3DFMT_A8R8G8B8,
+        D3DPOOL_MANAGED,
+        p_ppiOut,
+        NULL)))
+    {
+        CLogDisplay::Instance().AddEntry("[ERROR] Unable to create default texture",
+            D3DCOLOR_ARGB(0xFF,0xFF,0,0));
+
+        *p_ppiOut = NULL;
+        return 0;
+    }
+    D3DXFillTexture(*p_ppiOut,&FillFunc,NULL);
+    sDefaultTexture = *p_ppiOut;
+    sDefaultTexture->AddRef();
+
+    // {9785DA94-1D96-426b-B3CB-BADC36347F5E}
+    static const GUID guidPrivateData = 
+        { 0x9785da94, 0x1d96, 0x426b, 
+        { 0xb3, 0xcb, 0xba, 0xdc, 0x36, 0x34, 0x7f, 0x5e } };
+
+    uint32_t iData = 0xFFFFFFFF;
+    (*p_ppiOut)->SetPrivateData(guidPrivateData,&iData,4,0);
+    return 1;
 }
 }
 //-------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------
 bool CMaterialManager::TryLongerPath(char* szTemp,aiString* p_szString)
 bool CMaterialManager::TryLongerPath(char* szTemp,aiString* p_szString)
 {
 {
-	char szTempB[MAX_PATH];
-	strcpy(szTempB,szTemp);
-
-	// go to the beginning of the file name
-	char* szFile = strrchr(szTempB,'\\');
-	if (!szFile)szFile = strrchr(szTempB,'/');
-
-	char* szFile2 = szTemp + (szFile - szTempB)+1;
-	szFile++;
-	char* szExt = strrchr(szFile,'.');
-	if (!szExt)return false;
-	szExt++;
-	*szFile = 0;
-
-	strcat(szTempB,"*.*");
-	const unsigned int iSize = (const unsigned int) ( szExt - 1 - szFile );
-
-	HANDLE          h;
-	WIN32_FIND_DATA info;
-
-	// build a list of files
-	h = FindFirstFile(szTempB, &info);
-	if (h != INVALID_HANDLE_VALUE)
-	{
-		do
-		{
-			if (!(strcmp(info.cFileName, ".") == 0 || strcmp(info.cFileName, "..") == 0))
-			{
-				char* szExtFound = strrchr(info.cFileName, '.');
-				if (szExtFound)
-				{
-					++szExtFound;
-					if (0 == ASSIMP_stricmp(szExtFound,szExt))
-					{
-						const unsigned int iSizeFound = (const unsigned int) ( 
-							szExtFound - 1 - info.cFileName);
-
-						for (unsigned int i = 0; i < iSizeFound;++i)
-							info.cFileName[i] = (CHAR)tolower(info.cFileName[i]);
-
-						if (0 == memcmp(info.cFileName,szFile2, std::min(iSizeFound,iSize)))
-						{
-							// we have it. Build the full path ...
-							char* sz = strrchr(szTempB,'*');
-							*(sz-2) = 0x0;
-
-							strcat(szTempB,info.cFileName);
-
-							// copy the result string back to the aiString
-							const size_t iLen = strlen(szTempB);
-							size_t iLen2 = iLen+1;
-							iLen2 = iLen2 > MAXLEN ? MAXLEN : iLen2;
-							memcpy(p_szString->data,szTempB,iLen2);
-							p_szString->length = iLen;
-							return true;
-						}
-					}
-					// check whether the 8.3 DOS name is matching
-					if (0 == ASSIMP_stricmp(info.cAlternateFileName,p_szString->data))
-					{
-						strcat(szTempB,info.cAlternateFileName);
-
-						// copy the result string back to the aiString
-						const size_t iLen = strlen(szTempB);
-						size_t iLen2 = iLen+1;
-						iLen2 = iLen2 > MAXLEN ? MAXLEN : iLen2;
-						memcpy(p_szString->data,szTempB,iLen2);
-						p_szString->length = iLen;
-						return true;
-					}
-				}
-			}
-		} 
-		while (FindNextFile(h, &info));
-
-		FindClose(h);
-	}
-	return false;
+    char szTempB[MAX_PATH];
+    strcpy(szTempB,szTemp);
+
+    // go to the beginning of the file name
+    char* szFile = strrchr(szTempB,'\\');
+    if (!szFile)szFile = strrchr(szTempB,'/');
+
+    char* szFile2 = szTemp + (szFile - szTempB)+1;
+    szFile++;
+    char* szExt = strrchr(szFile,'.');
+    if (!szExt)return false;
+    szExt++;
+    *szFile = 0;
+
+    strcat(szTempB,"*.*");
+    const unsigned int iSize = (const unsigned int) ( szExt - 1 - szFile );
+
+    HANDLE          h;
+    WIN32_FIND_DATA info;
+
+    // build a list of files
+    h = FindFirstFile(szTempB, &info);
+    if (h != INVALID_HANDLE_VALUE)
+    {
+        do
+        {
+            if (!(strcmp(info.cFileName, ".") == 0 || strcmp(info.cFileName, "..") == 0))
+            {
+                char* szExtFound = strrchr(info.cFileName, '.');
+                if (szExtFound)
+                {
+                    ++szExtFound;
+                    if (0 == ASSIMP_stricmp(szExtFound,szExt))
+                    {
+                        const unsigned int iSizeFound = (const unsigned int) ( 
+                            szExtFound - 1 - info.cFileName);
+
+                        for (unsigned int i = 0; i < iSizeFound;++i)
+                            info.cFileName[i] = (CHAR)tolower(info.cFileName[i]);
+
+                        if (0 == memcmp(info.cFileName,szFile2, min(iSizeFound,iSize)))
+                        {
+                            // we have it. Build the full path ...
+                            char* sz = strrchr(szTempB,'*');
+                            *(sz-2) = 0x0;
+
+                            strcat(szTempB,info.cFileName);
+
+                            // copy the result string back to the aiString
+                            const size_t iLen = strlen(szTempB);
+                            size_t iLen2 = iLen+1;
+                            iLen2 = iLen2 > MAXLEN ? MAXLEN : iLen2;
+                            memcpy(p_szString->data,szTempB,iLen2);
+                            p_szString->length = iLen;
+                            return true;
+                        }
+                    }
+                    // check whether the 8.3 DOS name is matching
+                    if (0 == ASSIMP_stricmp(info.cAlternateFileName,p_szString->data))
+                    {
+                        strcat(szTempB,info.cAlternateFileName);
+
+                        // copy the result string back to the aiString
+                        const size_t iLen = strlen(szTempB);
+                        size_t iLen2 = iLen+1;
+                        iLen2 = iLen2 > MAXLEN ? MAXLEN : iLen2;
+                        memcpy(p_szString->data,szTempB,iLen2);
+                        p_szString->length = iLen;
+                        return true;
+                    }
+                }
+            }
+        } 
+        while (FindNextFile(h, &info));
+
+        FindClose(h);
+    }
+    return false;
 }
 }
 //-------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------
 int CMaterialManager::FindValidPath(aiString* p_szString)
 int CMaterialManager::FindValidPath(aiString* p_szString)
 {
 {
-	ai_assert(NULL != p_szString);
-	aiString pcpy = *p_szString;
-	if ('*' ==  p_szString->data[0])	{
-		// '*' as first character indicates an embedded file
-		return 5;
-	}
-
-	// first check whether we can directly load the file
-	FILE* pFile = fopen(p_szString->data,"rb");
-	if (pFile)fclose(pFile);
-	else
-	{
-		// check whether we can use the directory of  the asset as relative base
-		char szTemp[MAX_PATH*2], tmp2[MAX_PATH*2];
-		strcpy(szTemp, g_szFileName);
-		strcpy(tmp2,szTemp);
-
-		char* szData = p_szString->data;
-		if (*szData == '\\' || *szData == '/')++szData;
-
-		char* szEnd = strrchr(szTemp,'\\');
-		if (!szEnd)
-		{
-			szEnd = strrchr(szTemp,'/');
-			if (!szEnd)szEnd = szTemp;
-		}
-		szEnd++;
-		*szEnd = 0;
-		strcat(szEnd,szData);
-
-
-		pFile = fopen(szTemp,"rb");
-		if (!pFile)
-		{
-			// convert the string to lower case
-			for (unsigned int i = 0;;++i)
-			{
-				if ('\0' == szTemp[i])break;
-				szTemp[i] = (char)tolower(szTemp[i]);
-			}
-
-			if(TryLongerPath(szTemp,p_szString))return 1;
-			*szEnd = 0;
-
-			// search common sub directories
-			strcat(szEnd,"tex\\");
-			strcat(szEnd,szData);
-
-			pFile = fopen(szTemp,"rb");
-			if (!pFile)
-			{
-				if(TryLongerPath(szTemp,p_szString))return 1;
-
-				*szEnd = 0;
-
-				strcat(szEnd,"textures\\");
-				strcat(szEnd,szData);
-
-				pFile = fopen(szTemp,"rb");
-				if (!pFile)
-				{
-					if(TryLongerPath(szTemp, p_szString))return 1;
-				}
-
-				// patch by mark sibly to look for textures files in the asset's base directory.
-				const char *path=pcpy.data; 
-				const char *p=strrchr( path,'/' ); 
-				if( !p ) p=strrchr( path,'\\' ); 
-				if( p ){ 
-					char *q=strrchr( tmp2,'/' ); 
-					if( !q ) q=strrchr( tmp2,'\\' ); 
-					if( q ){ 
-						strcpy( q+1,p+1 ); 
-						if((pFile=fopen( tmp2,"r" ))){ 
-							fclose( pFile ); 
-							strcpy(p_szString->data,tmp2);
-							p_szString->length = strlen(tmp2);
-							return 1;
-						} 
-					} 
-				}
-				return 0;
-			}
-		}
-		fclose(pFile);
-
-		// copy the result string back to the aiString
-		const size_t iLen = strlen(szTemp);
-		size_t iLen2 = iLen+1;
-		iLen2 = iLen2 > MAXLEN ? MAXLEN : iLen2;
-		memcpy(p_szString->data,szTemp,iLen2);
-		p_szString->length = iLen;
-
-	}
-	return 1;
+    ai_assert(NULL != p_szString);
+    aiString pcpy = *p_szString;
+    if ('*' ==  p_szString->data[0])	{
+        // '*' as first character indicates an embedded file
+        return 5;
+    }
+
+    // first check whether we can directly load the file
+    FILE* pFile = fopen(p_szString->data,"rb");
+    if (pFile)fclose(pFile);
+    else
+    {
+        // check whether we can use the directory of  the asset as relative base
+        char szTemp[MAX_PATH*2], tmp2[MAX_PATH*2];
+        strcpy(szTemp, g_szFileName);
+        strcpy(tmp2,szTemp);
+
+        char* szData = p_szString->data;
+        if (*szData == '\\' || *szData == '/')++szData;
+
+        char* szEnd = strrchr(szTemp,'\\');
+        if (!szEnd)
+        {
+            szEnd = strrchr(szTemp,'/');
+            if (!szEnd)szEnd = szTemp;
+        }
+        szEnd++;
+        *szEnd = 0;
+        strcat(szEnd,szData);
+
+
+        pFile = fopen(szTemp,"rb");
+        if (!pFile)
+        {
+            // convert the string to lower case
+            for (unsigned int i = 0;;++i)
+            {
+                if ('\0' == szTemp[i])break;
+                szTemp[i] = (char)tolower(szTemp[i]);
+            }
+
+            if(TryLongerPath(szTemp,p_szString))return 1;
+            *szEnd = 0;
+
+            // search common sub directories
+            strcat(szEnd,"tex\\");
+            strcat(szEnd,szData);
+
+            pFile = fopen(szTemp,"rb");
+            if (!pFile)
+            {
+                if(TryLongerPath(szTemp,p_szString))return 1;
+
+                *szEnd = 0;
+
+                strcat(szEnd,"textures\\");
+                strcat(szEnd,szData);
+
+                pFile = fopen(szTemp,"rb");
+                if (!pFile)
+                {
+                    if(TryLongerPath(szTemp, p_szString))return 1;
+                }
+
+                // patch by mark sibly to look for textures files in the asset's base directory.
+                const char *path=pcpy.data; 
+                const char *p=strrchr( path,'/' ); 
+                if( !p ) p=strrchr( path,'\\' ); 
+                if( p ){ 
+                    char *q=strrchr( tmp2,'/' ); 
+                    if( !q ) q=strrchr( tmp2,'\\' ); 
+                    if( q ){ 
+                        strcpy( q+1,p+1 ); 
+                        if((pFile=fopen( tmp2,"r" ))){ 
+                            fclose( pFile ); 
+                            strcpy(p_szString->data,tmp2);
+                            p_szString->length = strlen(tmp2);
+                            return 1;
+                        } 
+                    } 
+                }
+                return 0;
+            }
+        }
+        fclose(pFile);
+
+        // copy the result string back to the aiString
+        const size_t iLen = strlen(szTemp);
+        size_t iLen2 = iLen+1;
+        iLen2 = iLen2 > MAXLEN ? MAXLEN : iLen2;
+        memcpy(p_szString->data,szTemp,iLen2);
+        p_szString->length = iLen;
+
+    }
+    return 1;
 }
 }
 //-------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------
 int CMaterialManager::LoadTexture(IDirect3DTexture9** p_ppiOut,aiString* szPath)
 int CMaterialManager::LoadTexture(IDirect3DTexture9** p_ppiOut,aiString* szPath)
 {
 {
-	ai_assert(NULL != p_ppiOut);
-	ai_assert(NULL != szPath);
-
-	*p_ppiOut = NULL;
-
-	const std::string s = szPath->data;
-	TextureCache::iterator ff;
-	if ((ff = sCachedTextures.find(s)) != sCachedTextures.end()) {
-		*p_ppiOut = (*ff).second;
-		(*p_ppiOut)->AddRef();
-		return 1;
-	}
-
-	// first get a valid path to the texture
-	if( 5 == FindValidPath(szPath))
-	{
-		// embedded file. Find its index
-		unsigned int iIndex = atoi(szPath->data+1);
-		if (iIndex < g_pcAsset->pcScene->mNumTextures)
-		{
-			if (0 == g_pcAsset->pcScene->mTextures[iIndex]->mHeight)
-			{
-				// it is an embedded file ... don't need the file format hint,
-				// simply let D3DX load the file
-				D3DXIMAGE_INFO info;
-				if (FAILED(D3DXCreateTextureFromFileInMemoryEx(g_piDevice,
-					g_pcAsset->pcScene->mTextures[iIndex]->pcData,
-					g_pcAsset->pcScene->mTextures[iIndex]->mWidth,
-					D3DX_DEFAULT,
-					D3DX_DEFAULT,
-					1,
-					D3DUSAGE_AUTOGENMIPMAP,
-					D3DFMT_UNKNOWN,
-					D3DPOOL_MANAGED,
-					D3DX_DEFAULT,
-					D3DX_DEFAULT,
-					0,
-					&info,
-					NULL,
-					p_ppiOut)))
-				{
-					std::string sz = "[ERROR] Unable to load embedded texture (#1): ";
-					sz.append(szPath->data);
-					CLogDisplay::Instance().AddEntry(sz,D3DCOLOR_ARGB(0xFF,0xFF,0x0,0x0));
-
-					this->SetDefaultTexture(p_ppiOut);
-					return 1;
-				}
-			}
-			else
-			{
-				// fill a new texture ...
-				if(FAILED(g_piDevice->CreateTexture(
-					g_pcAsset->pcScene->mTextures[iIndex]->mWidth,
-					g_pcAsset->pcScene->mTextures[iIndex]->mHeight,
-					0,D3DUSAGE_AUTOGENMIPMAP,D3DFMT_A8R8G8B8,D3DPOOL_MANAGED,p_ppiOut,NULL)))
-				{
-					std::string sz = "[ERROR] Unable to load embedded texture (#2): ";
-					sz.append(szPath->data);
-					CLogDisplay::Instance().AddEntry(sz,D3DCOLOR_ARGB(0xFF,0xFF,0x0,0x0));
-
-					this->SetDefaultTexture(p_ppiOut);
-					return 1;
-				}
-
-				// now copy the data to it ... (assume non pow2 to be supported)
-				D3DLOCKED_RECT sLock;
-				(*p_ppiOut)->LockRect(0,&sLock,NULL,0);
-
-				const aiTexel* pcData = g_pcAsset->pcScene->mTextures[iIndex]->pcData;
-
-				for (unsigned int y = 0; y < g_pcAsset->pcScene->mTextures[iIndex]->mHeight;++y)
-				{
-					memcpy(sLock.pBits,pcData,g_pcAsset->pcScene->mTextures[iIndex]->
-						mWidth *sizeof(aiTexel));
-					sLock.pBits = (char*)sLock.pBits + sLock.Pitch;
-					pcData += g_pcAsset->pcScene->mTextures[iIndex]->mWidth;
-				}
-				(*p_ppiOut)->UnlockRect(0);
-				(*p_ppiOut)->GenerateMipSubLevels();
-			}
-			sCachedTextures[s] = *p_ppiOut;
-			(*p_ppiOut)->AddRef();
-			return 1;
-		}
-		else
-		{
-			std::string sz = "[ERROR] Invalid index for embedded texture: ";
-			sz.append(szPath->data);
-			CLogDisplay::Instance().AddEntry(sz,D3DCOLOR_ARGB(0xFF,0xFF,0x0,0x0));
-
-			SetDefaultTexture(p_ppiOut);
-			return 1;
-		}
-	}
-
-	// then call D3DX to load the texture
-	if (FAILED(D3DXCreateTextureFromFileEx(
-		g_piDevice,
-		szPath->data,
-		D3DX_DEFAULT,
-		D3DX_DEFAULT,
-		0,
-		0,
-		D3DFMT_A8R8G8B8,
-		D3DPOOL_MANAGED,
-		D3DX_DEFAULT,
-		D3DX_DEFAULT,
-		0,
-		NULL,
-		NULL,
-		p_ppiOut)))
-	{
-		// error ... use the default texture instead
-		std::string sz = "[ERROR] Unable to load texture: ";
-		sz.append(szPath->data);
-		CLogDisplay::Instance().AddEntry(sz,D3DCOLOR_ARGB(0xFF,0xFF,0x0,0x0));
-
-		this->SetDefaultTexture(p_ppiOut);
-	}
-	sCachedTextures[s] = *p_ppiOut;
-	(*p_ppiOut)->AddRef();
-
-	return 1;
+    ai_assert(NULL != p_ppiOut);
+    ai_assert(NULL != szPath);
+
+    *p_ppiOut = NULL;
+
+    const std::string s = szPath->data;
+    TextureCache::iterator ff;
+    if ((ff = sCachedTextures.find(s)) != sCachedTextures.end()) {
+        *p_ppiOut = (*ff).second;
+        (*p_ppiOut)->AddRef();
+        return 1;
+    }
+
+    // first get a valid path to the texture
+    if( 5 == FindValidPath(szPath))
+    {
+        // embedded file. Find its index
+        unsigned int iIndex = atoi(szPath->data+1);
+        if (iIndex < g_pcAsset->pcScene->mNumTextures)
+        {
+            if (0 == g_pcAsset->pcScene->mTextures[iIndex]->mHeight)
+            {
+                // it is an embedded file ... don't need the file format hint,
+                // simply let D3DX load the file
+                D3DXIMAGE_INFO info;
+                if (FAILED(D3DXCreateTextureFromFileInMemoryEx(g_piDevice,
+                    g_pcAsset->pcScene->mTextures[iIndex]->pcData,
+                    g_pcAsset->pcScene->mTextures[iIndex]->mWidth,
+                    D3DX_DEFAULT,
+                    D3DX_DEFAULT,
+                    1,
+                    D3DUSAGE_AUTOGENMIPMAP,
+                    D3DFMT_UNKNOWN,
+                    D3DPOOL_MANAGED,
+                    D3DX_DEFAULT,
+                    D3DX_DEFAULT,
+                    0,
+                    &info,
+                    NULL,
+                    p_ppiOut)))
+                {
+                    std::string sz = "[ERROR] Unable to load embedded texture (#1): ";
+                    sz.append(szPath->data);
+                    CLogDisplay::Instance().AddEntry(sz,D3DCOLOR_ARGB(0xFF,0xFF,0x0,0x0));
+
+                    this->SetDefaultTexture(p_ppiOut);
+                    return 1;
+                }
+            }
+            else
+            {
+                // fill a new texture ...
+                if(FAILED(g_piDevice->CreateTexture(
+                    g_pcAsset->pcScene->mTextures[iIndex]->mWidth,
+                    g_pcAsset->pcScene->mTextures[iIndex]->mHeight,
+                    0,D3DUSAGE_AUTOGENMIPMAP,D3DFMT_A8R8G8B8,D3DPOOL_MANAGED,p_ppiOut,NULL)))
+                {
+                    std::string sz = "[ERROR] Unable to load embedded texture (#2): ";
+                    sz.append(szPath->data);
+                    CLogDisplay::Instance().AddEntry(sz,D3DCOLOR_ARGB(0xFF,0xFF,0x0,0x0));
+
+                    this->SetDefaultTexture(p_ppiOut);
+                    return 1;
+                }
+
+                // now copy the data to it ... (assume non pow2 to be supported)
+                D3DLOCKED_RECT sLock;
+                (*p_ppiOut)->LockRect(0,&sLock,NULL,0);
+
+                const aiTexel* pcData = g_pcAsset->pcScene->mTextures[iIndex]->pcData;
+
+                for (unsigned int y = 0; y < g_pcAsset->pcScene->mTextures[iIndex]->mHeight;++y)
+                {
+                    memcpy(sLock.pBits,pcData,g_pcAsset->pcScene->mTextures[iIndex]->
+                        mWidth *sizeof(aiTexel));
+                    sLock.pBits = (char*)sLock.pBits + sLock.Pitch;
+                    pcData += g_pcAsset->pcScene->mTextures[iIndex]->mWidth;
+                }
+                (*p_ppiOut)->UnlockRect(0);
+                (*p_ppiOut)->GenerateMipSubLevels();
+            }
+            sCachedTextures[s] = *p_ppiOut;
+            (*p_ppiOut)->AddRef();
+            return 1;
+        }
+        else
+        {
+            std::string sz = "[ERROR] Invalid index for embedded texture: ";
+            sz.append(szPath->data);
+            CLogDisplay::Instance().AddEntry(sz,D3DCOLOR_ARGB(0xFF,0xFF,0x0,0x0));
+
+            SetDefaultTexture(p_ppiOut);
+            return 1;
+        }
+    }
+
+    // then call D3DX to load the texture
+    if (FAILED(D3DXCreateTextureFromFileEx(
+        g_piDevice,
+        szPath->data,
+        D3DX_DEFAULT,
+        D3DX_DEFAULT,
+        0,
+        0,
+        D3DFMT_A8R8G8B8,
+        D3DPOOL_MANAGED,
+        D3DX_DEFAULT,
+        D3DX_DEFAULT,
+        0,
+        NULL,
+        NULL,
+        p_ppiOut)))
+    {
+        // error ... use the default texture instead
+        std::string sz = "[ERROR] Unable to load texture: ";
+        sz.append(szPath->data);
+        CLogDisplay::Instance().AddEntry(sz,D3DCOLOR_ARGB(0xFF,0xFF,0x0,0x0));
+
+        this->SetDefaultTexture(p_ppiOut);
+    }
+    sCachedTextures[s] = *p_ppiOut;
+    (*p_ppiOut)->AddRef();
+
+    return 1;
 }
 }
 //-------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------
 void CMaterialManager::DeleteMaterial(AssetHelper::MeshHelper* pcIn)
 void CMaterialManager::DeleteMaterial(AssetHelper::MeshHelper* pcIn)
 {
 {
-	if (!pcIn || !pcIn->piEffect)return;
-	pcIn->piEffect->Release();
-
-	// release all textures associated with the material
-	if (pcIn->piDiffuseTexture)
-	{
-		pcIn->piDiffuseTexture->Release();
-		pcIn->piDiffuseTexture = NULL;
-	}
-	if (pcIn->piSpecularTexture)
-	{
-		pcIn->piSpecularTexture->Release();
-		pcIn->piSpecularTexture = NULL;
-	}
-	if (pcIn->piEmissiveTexture)
-	{
-		pcIn->piEmissiveTexture->Release();
-		pcIn->piEmissiveTexture = NULL;
-	}
-	if (pcIn->piAmbientTexture)
-	{
-		pcIn->piAmbientTexture->Release();
-		pcIn->piAmbientTexture = NULL;
-	}
-	if (pcIn->piOpacityTexture)
-	{
-		pcIn->piOpacityTexture->Release();
-		pcIn->piOpacityTexture = NULL;
-	}
-	if (pcIn->piNormalTexture)
-	{
-		pcIn->piNormalTexture->Release();
-		pcIn->piNormalTexture = NULL;
-	}
-	if (pcIn->piShininessTexture)
-	{
-		pcIn->piShininessTexture->Release();
-		pcIn->piShininessTexture = NULL;
-	}
-	if (pcIn->piLightmapTexture)
-	{
-		pcIn->piLightmapTexture->Release();
-		pcIn->piLightmapTexture = NULL;
-	}
-	pcIn->piEffect = NULL;
+    if (!pcIn || !pcIn->piEffect)return;
+    pcIn->piEffect->Release();
+
+    // release all textures associated with the material
+    if (pcIn->piDiffuseTexture)
+    {
+        pcIn->piDiffuseTexture->Release();
+        pcIn->piDiffuseTexture = NULL;
+    }
+    if (pcIn->piSpecularTexture)
+    {
+        pcIn->piSpecularTexture->Release();
+        pcIn->piSpecularTexture = NULL;
+    }
+    if (pcIn->piEmissiveTexture)
+    {
+        pcIn->piEmissiveTexture->Release();
+        pcIn->piEmissiveTexture = NULL;
+    }
+    if (pcIn->piAmbientTexture)
+    {
+        pcIn->piAmbientTexture->Release();
+        pcIn->piAmbientTexture = NULL;
+    }
+    if (pcIn->piOpacityTexture)
+    {
+        pcIn->piOpacityTexture->Release();
+        pcIn->piOpacityTexture = NULL;
+    }
+    if (pcIn->piNormalTexture)
+    {
+        pcIn->piNormalTexture->Release();
+        pcIn->piNormalTexture = NULL;
+    }
+    if (pcIn->piShininessTexture)
+    {
+        pcIn->piShininessTexture->Release();
+        pcIn->piShininessTexture = NULL;
+    }
+    if (pcIn->piLightmapTexture)
+    {
+        pcIn->piLightmapTexture->Release();
+        pcIn->piLightmapTexture = NULL;
+    }
+    pcIn->piEffect = NULL;
 }
 }
 //-------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------
 void CMaterialManager::HMtoNMIfNecessary(
 void CMaterialManager::HMtoNMIfNecessary(
-	IDirect3DTexture9* piTexture,
-	IDirect3DTexture9** piTextureOut,
-	bool bWasOriginallyHM)
+    IDirect3DTexture9* piTexture,
+    IDirect3DTexture9** piTextureOut,
+    bool bWasOriginallyHM)
 {
 {
-	ai_assert(NULL != piTexture);
-	ai_assert(NULL != piTextureOut);
-
-	bool bMustConvert = false;
-	uintptr_t iElement = 3;
-
-	*piTextureOut = piTexture;
-
-	// Lock the input texture and try to determine its type.
-	// Criterias:
-	// - If r,g,b channel are identical it MUST be a height map
-	// - If one of the rgb channels is used and the others are empty it
-	//   must be a height map, too.
-	// - If the average color of the whole image is something inside the
-	//   purple range we can be sure it is a normal map
-	//
-	// - Otherwise we assume it is a normal map
-	// To increase performance we take not every pixel
-
-	D3DLOCKED_RECT sRect;
-	D3DSURFACE_DESC sDesc;
-	piTexture->GetLevelDesc(0,&sDesc);
-	if (FAILED(piTexture->LockRect(0,&sRect,NULL,D3DLOCK_READONLY)))
-	{
-		return;
-	}
-	const int iPitchDiff = (int)sRect.Pitch - (int)(sDesc.Width * 4);
-
-	struct SColor
-	{
-		union
-		{
-			struct {unsigned char b,g,r,a;};
-			char _array[4];
-		};
-	};
-	const SColor* pcData = (const SColor*)sRect.pBits;
-
-	union
-	{
-		const SColor* pcPointer;
-		const unsigned char* pcCharPointer;
-	};
-	pcPointer = pcData;
-
-	// 1. If r,g,b channel are identical it MUST be a height map
-	bool bIsEqual = true;
-	for (unsigned int y = 0; y <  sDesc.Height;++y)
-	{
-		for (unsigned int x = 0; x <  sDesc.Width;++x)
-		{
-			if (pcPointer->b != pcPointer->r || pcPointer->b != pcPointer->g)
-			{
-				bIsEqual = false;
-				break;
-			}
-			pcPointer++;
-		}
-		pcCharPointer += iPitchDiff;
-	}
-	if (bIsEqual)bMustConvert = true;
-	else
-	{
-		// 2. If one of the rgb channels is used and the others are empty it
-		//    must be a height map, too.
-		pcPointer = pcData;
-		while (*pcCharPointer == 0)pcCharPointer++;
-
-		iElement = (uintptr_t)(pcCharPointer - (unsigned char*)pcData) % 4;
-		unsigned int aiIndex[3] = {0,1,2};
-		if (3 != iElement)aiIndex[iElement] = 3;
-
-		pcPointer = pcData;
-
-		bIsEqual = true;
-		if (3 != iElement)
-		{
-			for (unsigned int y = 0; y <  sDesc.Height;++y)
-			{
-				for (unsigned int x = 0; x <  sDesc.Width;++x)
-				{
-					for (unsigned int ii = 0; ii < 3;++ii)
-					{
-						// don't take the alpha channel into account.
-						// if the texture was stored n RGB888 format D3DX has
-						// converted it to ARGB8888 format with a fixed alpha channel
-						if (aiIndex[ii] != 3 && pcPointer->_array[aiIndex[ii]] != 0)
-						{
-							bIsEqual = false;
-							break;
-						}
-					}
-					pcPointer++;
-				}
-				pcCharPointer += iPitchDiff;
-			}
-			if (bIsEqual)bMustConvert = true;
-			else
-			{
-				// If the average color of the whole image is something inside the
-				// purple range we can be sure it is a normal map
-
-				// (calculate the average color line per line to prevent overflows!)
-				pcPointer = pcData;
-				aiColor3D clrColor;
-				for (unsigned int y = 0; y <  sDesc.Height;++y)
-				{
-					aiColor3D clrColorLine;
-					for (unsigned int x = 0; x <  sDesc.Width;++x)
-					{
-						clrColorLine.r += pcPointer->r;
-						clrColorLine.g += pcPointer->g;
-						clrColorLine.b += pcPointer->b;
-						pcPointer++;
-					}
-					clrColor.r += clrColorLine.r /= (float)sDesc.Width;
-					clrColor.g += clrColorLine.g /= (float)sDesc.Width;
-					clrColor.b += clrColorLine.b /= (float)sDesc.Width;
-					pcCharPointer += iPitchDiff;
-				}
-				clrColor.r /= (float)sDesc.Height;
-				clrColor.g /= (float)sDesc.Height;
-				clrColor.b /= (float)sDesc.Height;
-
-				if (!(clrColor.b > 215 && 
-					clrColor.r > 100 && clrColor.r < 140 && 
-					clrColor.g > 100 && clrColor.g < 140))
-				{
-					// Unable to detect. Believe the original value obtained from the loader
-					if (bWasOriginallyHM)
-					{
-						bMustConvert = true;
-					}
-				}
-			}
-		}
-	}
-
-	piTexture->UnlockRect(0);
-
-	// if the input data is assumed to be a height map we'll
-	// need to convert it NOW
-	if (bMustConvert)
-	{
-		D3DSURFACE_DESC sDesc;
-		piTexture->GetLevelDesc(0, &sDesc);
-
-		IDirect3DTexture9* piTempTexture;
-		if(FAILED(g_piDevice->CreateTexture(
-			sDesc.Width,
-			sDesc.Height,
-			piTexture->GetLevelCount(),
-			sDesc.Usage,
-			sDesc.Format,
-			sDesc.Pool, &piTempTexture, NULL)))
-		{
-			CLogDisplay::Instance().AddEntry(
-				"[ERROR] Unable to create normal map texture",
-				D3DCOLOR_ARGB(0xFF,0xFF,0x0,0x0));
-			return;
-		}
-
-		DWORD dwFlags;
-		if (3 == iElement)dwFlags = D3DX_CHANNEL_LUMINANCE;
-		else if (2 == iElement)dwFlags = D3DX_CHANNEL_RED;
-		else if (1 == iElement)dwFlags = D3DX_CHANNEL_GREEN;
-		else /*if (0 == iElement)*/dwFlags = D3DX_CHANNEL_BLUE;
-
-		if(FAILED(D3DXComputeNormalMap(piTempTexture,
-			piTexture,NULL,0,dwFlags,1.0f)))
-		{
-			CLogDisplay::Instance().AddEntry(
-				"[ERROR] Unable to compute normal map from height map",
-				D3DCOLOR_ARGB(0xFF,0xFF,0x0,0x0));
-
-			piTempTexture->Release();
-			return;
-		}
-		*piTextureOut = piTempTexture;
-		piTexture->Release();
-	}
+    ai_assert(NULL != piTexture);
+    ai_assert(NULL != piTextureOut);
+
+    bool bMustConvert = false;
+    uintptr_t iElement = 3;
+
+    *piTextureOut = piTexture;
+
+    // Lock the input texture and try to determine its type.
+    // Criterias:
+    // - If r,g,b channel are identical it MUST be a height map
+    // - If one of the rgb channels is used and the others are empty it
+    //   must be a height map, too.
+    // - If the average color of the whole image is something inside the
+    //   purple range we can be sure it is a normal map
+    //
+    // - Otherwise we assume it is a normal map
+    // To increase performance we take not every pixel
+
+    D3DLOCKED_RECT sRect;
+    D3DSURFACE_DESC sDesc;
+    piTexture->GetLevelDesc(0,&sDesc);
+    if (FAILED(piTexture->LockRect(0,&sRect,NULL,D3DLOCK_READONLY)))
+    {
+        return;
+    }
+    const int iPitchDiff = (int)sRect.Pitch - (int)(sDesc.Width * 4);
+
+    struct SColor
+    {
+        union
+        {
+            struct {unsigned char b,g,r,a;};
+            char _array[4];
+        };
+    };
+    const SColor* pcData = (const SColor*)sRect.pBits;
+
+    union
+    {
+        const SColor* pcPointer;
+        const unsigned char* pcCharPointer;
+    };
+    pcPointer = pcData;
+
+    // 1. If r,g,b channel are identical it MUST be a height map
+    bool bIsEqual = true;
+    for (unsigned int y = 0; y <  sDesc.Height;++y)
+    {
+        for (unsigned int x = 0; x <  sDesc.Width;++x)
+        {
+            if (pcPointer->b != pcPointer->r || pcPointer->b != pcPointer->g)
+            {
+                bIsEqual = false;
+                break;
+            }
+            pcPointer++;
+        }
+        pcCharPointer += iPitchDiff;
+    }
+    if (bIsEqual)bMustConvert = true;
+    else
+    {
+        // 2. If one of the rgb channels is used and the others are empty it
+        //    must be a height map, too.
+        pcPointer = pcData;
+        while (*pcCharPointer == 0)pcCharPointer++;
+
+        iElement = (uintptr_t)(pcCharPointer - (unsigned char*)pcData) % 4;
+        unsigned int aiIndex[3] = {0,1,2};
+        if (3 != iElement)aiIndex[iElement] = 3;
+
+        pcPointer = pcData;
+
+        bIsEqual = true;
+        if (3 != iElement)
+        {
+            for (unsigned int y = 0; y <  sDesc.Height;++y)
+            {
+                for (unsigned int x = 0; x <  sDesc.Width;++x)
+                {
+                    for (unsigned int ii = 0; ii < 3;++ii)
+                    {
+                        // don't take the alpha channel into account.
+                        // if the texture was stored n RGB888 format D3DX has
+                        // converted it to ARGB8888 format with a fixed alpha channel
+                        if (aiIndex[ii] != 3 && pcPointer->_array[aiIndex[ii]] != 0)
+                        {
+                            bIsEqual = false;
+                            break;
+                        }
+                    }
+                    pcPointer++;
+                }
+                pcCharPointer += iPitchDiff;
+            }
+            if (bIsEqual)bMustConvert = true;
+            else
+            {
+                // If the average color of the whole image is something inside the
+                // purple range we can be sure it is a normal map
+
+                // (calculate the average color line per line to prevent overflows!)
+                pcPointer = pcData;
+                aiColor3D clrColor;
+                for (unsigned int y = 0; y <  sDesc.Height;++y)
+                {
+                    aiColor3D clrColorLine;
+                    for (unsigned int x = 0; x <  sDesc.Width;++x)
+                    {
+                        clrColorLine.r += pcPointer->r;
+                        clrColorLine.g += pcPointer->g;
+                        clrColorLine.b += pcPointer->b;
+                        pcPointer++;
+                    }
+                    clrColor.r += clrColorLine.r /= (float)sDesc.Width;
+                    clrColor.g += clrColorLine.g /= (float)sDesc.Width;
+                    clrColor.b += clrColorLine.b /= (float)sDesc.Width;
+                    pcCharPointer += iPitchDiff;
+                }
+                clrColor.r /= (float)sDesc.Height;
+                clrColor.g /= (float)sDesc.Height;
+                clrColor.b /= (float)sDesc.Height;
+
+                if (!(clrColor.b > 215 && 
+                    clrColor.r > 100 && clrColor.r < 140 && 
+                    clrColor.g > 100 && clrColor.g < 140))
+                {
+                    // Unable to detect. Believe the original value obtained from the loader
+                    if (bWasOriginallyHM)
+                    {
+                        bMustConvert = true;
+                    }
+                }
+            }
+        }
+    }
+
+    piTexture->UnlockRect(0);
+
+    // if the input data is assumed to be a height map we'll
+    // need to convert it NOW
+    if (bMustConvert)
+    {
+        D3DSURFACE_DESC sDesc;
+        piTexture->GetLevelDesc(0, &sDesc);
+
+        IDirect3DTexture9* piTempTexture;
+        if(FAILED(g_piDevice->CreateTexture(
+            sDesc.Width,
+            sDesc.Height,
+            piTexture->GetLevelCount(),
+            sDesc.Usage,
+            sDesc.Format,
+            sDesc.Pool, &piTempTexture, NULL)))
+        {
+            CLogDisplay::Instance().AddEntry(
+                "[ERROR] Unable to create normal map texture",
+                D3DCOLOR_ARGB(0xFF,0xFF,0x0,0x0));
+            return;
+        }
+
+        DWORD dwFlags;
+        if (3 == iElement)dwFlags = D3DX_CHANNEL_LUMINANCE;
+        else if (2 == iElement)dwFlags = D3DX_CHANNEL_RED;
+        else if (1 == iElement)dwFlags = D3DX_CHANNEL_GREEN;
+        else /*if (0 == iElement)*/dwFlags = D3DX_CHANNEL_BLUE;
+
+        if(FAILED(D3DXComputeNormalMap(piTempTexture,
+            piTexture,NULL,0,dwFlags,1.0f)))
+        {
+            CLogDisplay::Instance().AddEntry(
+                "[ERROR] Unable to compute normal map from height map",
+                D3DCOLOR_ARGB(0xFF,0xFF,0x0,0x0));
+
+            piTempTexture->Release();
+            return;
+        }
+        *piTextureOut = piTempTexture;
+        piTexture->Release();
+    }
 }
 }
 //-------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------
 bool CMaterialManager::HasAlphaPixels(IDirect3DTexture9* piTexture)
 bool CMaterialManager::HasAlphaPixels(IDirect3DTexture9* piTexture)
 {
 {
-	ai_assert(NULL != piTexture);
-
-	D3DLOCKED_RECT sRect;
-	D3DSURFACE_DESC sDesc;
-	piTexture->GetLevelDesc(0,&sDesc);
-	if (FAILED(piTexture->LockRect(0,&sRect,NULL,D3DLOCK_READONLY)))
-	{
-		return false;
-	}
-	const int iPitchDiff = (int)sRect.Pitch - (int)(sDesc.Width * 4);
-
-	struct SColor
-	{
-		unsigned char b,g,r,a;;
-	};
-	const SColor* pcData = (const SColor*)sRect.pBits;
-
-	union
-	{
-		const SColor* pcPointer;
-		const unsigned char* pcCharPointer;
-	};
-	pcPointer = pcData;
-	for (unsigned int y = 0; y <  sDesc.Height;++y)
-	{
-		for (unsigned int x = 0; x <  sDesc.Width;++x)
-		{
-			if (pcPointer->a != 0xFF)
-			{
-				piTexture->UnlockRect(0);
-				return true;
-			}
-			pcPointer++;
-		}
-		pcCharPointer += iPitchDiff;
-	}
-	piTexture->UnlockRect(0);
-	return false;
+    ai_assert(NULL != piTexture);
+
+    D3DLOCKED_RECT sRect;
+    D3DSURFACE_DESC sDesc;
+    piTexture->GetLevelDesc(0,&sDesc);
+    if (FAILED(piTexture->LockRect(0,&sRect,NULL,D3DLOCK_READONLY)))
+    {
+        return false;
+    }
+    const int iPitchDiff = (int)sRect.Pitch - (int)(sDesc.Width * 4);
+
+    struct SColor
+    {
+        unsigned char b,g,r,a;;
+    };
+    const SColor* pcData = (const SColor*)sRect.pBits;
+
+    union
+    {
+        const SColor* pcPointer;
+        const unsigned char* pcCharPointer;
+    };
+    pcPointer = pcData;
+    for (unsigned int y = 0; y <  sDesc.Height;++y)
+    {
+        for (unsigned int x = 0; x <  sDesc.Width;++x)
+        {
+            if (pcPointer->a != 0xFF)
+            {
+                piTexture->UnlockRect(0);
+                return true;
+            }
+            pcPointer++;
+        }
+        pcCharPointer += iPitchDiff;
+    }
+    piTexture->UnlockRect(0);
+    return false;
 }
 }
 //-------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------
 int CMaterialManager::CreateMaterial(
 int CMaterialManager::CreateMaterial(
-	AssetHelper::MeshHelper* pcMesh,const aiMesh* pcSource)
+    AssetHelper::MeshHelper* pcMesh,const aiMesh* pcSource)
 {
 {
-	ai_assert(NULL != pcMesh);
-	ai_assert(NULL != pcSource);
-
-	ID3DXBuffer* piBuffer;
-
-	D3DXMACRO sMacro[64];
-
-	// extract all properties from the ASSIMP material structure
-	const aiMaterial* pcMat = g_pcAsset->pcScene->mMaterials[pcSource->mMaterialIndex];
-
-	//
-	// DIFFUSE COLOR --------------------------------------------------
-	//
-	if(AI_SUCCESS != aiGetMaterialColor(pcMat,AI_MATKEY_COLOR_DIFFUSE,
-		(aiColor4D*)&pcMesh->vDiffuseColor))
-	{
-		pcMesh->vDiffuseColor.x = 1.0f;
-		pcMesh->vDiffuseColor.y = 1.0f;
-		pcMesh->vDiffuseColor.z = 1.0f;
-		pcMesh->vDiffuseColor.w = 1.0f;
-	}
-	//
-	// SPECULAR COLOR --------------------------------------------------
-	//
-	if(AI_SUCCESS != aiGetMaterialColor(pcMat,AI_MATKEY_COLOR_SPECULAR,
-		(aiColor4D*)&pcMesh->vSpecularColor))
-	{
-		pcMesh->vSpecularColor.x = 1.0f;
-		pcMesh->vSpecularColor.y = 1.0f;
-		pcMesh->vSpecularColor.z = 1.0f;
-		pcMesh->vSpecularColor.w = 1.0f;
-	}
-	//
-	// AMBIENT COLOR --------------------------------------------------
-	//
-	if(AI_SUCCESS != aiGetMaterialColor(pcMat,AI_MATKEY_COLOR_AMBIENT,
-		(aiColor4D*)&pcMesh->vAmbientColor))
-	{
-		pcMesh->vAmbientColor.x = 0.0f;
-		pcMesh->vAmbientColor.y = 0.0f;
-		pcMesh->vAmbientColor.z = 0.0f;
-		pcMesh->vAmbientColor.w = 1.0f;
-	}
-	//
-	// EMISSIVE COLOR -------------------------------------------------
-	//
-	if(AI_SUCCESS != aiGetMaterialColor(pcMat,AI_MATKEY_COLOR_EMISSIVE,
-		(aiColor4D*)&pcMesh->vEmissiveColor))
-	{
-		pcMesh->vEmissiveColor.x = 0.0f;
-		pcMesh->vEmissiveColor.y = 0.0f;
-		pcMesh->vEmissiveColor.z = 0.0f;
-		pcMesh->vEmissiveColor.w = 1.0f;
-	}
-
-	//
-	// Opacity --------------------------------------------------------
-	//
-	if(AI_SUCCESS != aiGetMaterialFloat(pcMat,AI_MATKEY_OPACITY,&pcMesh->fOpacity))
-	{
-		pcMesh->fOpacity = 1.0f;
-	}
-
-	//
-	// Shading Model --------------------------------------------------
-	//
-	bool bDefault = false;
-	if(AI_SUCCESS != aiGetMaterialInteger(pcMat,AI_MATKEY_SHADING_MODEL,(int*)&pcMesh->eShadingMode ))
-	{
-		bDefault = true;
-		pcMesh->eShadingMode = aiShadingMode_Gouraud;
-	}
-
-
-	//
-	// Shininess ------------------------------------------------------
-	//
-	if(AI_SUCCESS != aiGetMaterialFloat(pcMat,AI_MATKEY_SHININESS,&pcMesh->fShininess))
-	{
-		// assume 15 as default shininess
-		pcMesh->fShininess = 15.0f;
-	}
-	else if (bDefault)pcMesh->eShadingMode  = aiShadingMode_Phong;
-
-
-	//
-	// Shininess strength ------------------------------------------------------
-	//
-	if(AI_SUCCESS != aiGetMaterialFloat(pcMat,AI_MATKEY_SHININESS_STRENGTH,&pcMesh->fSpecularStrength))
-	{
-		// assume 1.0 as default shininess strength
-		pcMesh->fSpecularStrength = 1.0f;
-	}
-
-	aiString szPath;
-
-	aiTextureMapMode mapU(aiTextureMapMode_Wrap),mapV(aiTextureMapMode_Wrap);
-
-	bool bib =false;
-	if (pcSource->mTextureCoords[0])
-	{
-
-		//
-		// DIFFUSE TEXTURE ------------------------------------------------
-		//
-		if(AI_SUCCESS == aiGetMaterialString(pcMat,AI_MATKEY_TEXTURE_DIFFUSE(0),&szPath))
-		{
-			LoadTexture(&pcMesh->piDiffuseTexture,&szPath);
-
-			aiGetMaterialInteger(pcMat,AI_MATKEY_MAPPINGMODE_U_DIFFUSE(0),(int*)&mapU);
-			aiGetMaterialInteger(pcMat,AI_MATKEY_MAPPINGMODE_V_DIFFUSE(0),(int*)&mapV);
-		}
-
-		//
-		// SPECULAR TEXTURE ------------------------------------------------
-		//
-		if(AI_SUCCESS == aiGetMaterialString(pcMat,AI_MATKEY_TEXTURE_SPECULAR(0),&szPath))
-		{
-			LoadTexture(&pcMesh->piSpecularTexture,&szPath);
-		}
-
-		//
-		// OPACITY TEXTURE ------------------------------------------------
-		//
-		if(AI_SUCCESS == aiGetMaterialString(pcMat,AI_MATKEY_TEXTURE_OPACITY(0),&szPath))
-		{
-			LoadTexture(&pcMesh->piOpacityTexture,&szPath);
-		}
-		else
-		{
-			int flags = 0;
-			aiGetMaterialInteger(pcMat,AI_MATKEY_TEXFLAGS_DIFFUSE(0),&flags);
-
-			// try to find out whether the diffuse texture has any
-			// non-opaque pixels. If we find a few, use it as opacity texture
-			if (pcMesh->piDiffuseTexture && !(flags & aiTextureFlags_IgnoreAlpha) && HasAlphaPixels(pcMesh->piDiffuseTexture))
-			{
-				int iVal;
-
-				// NOTE: This special value is set by the tree view if the user
-				// manually removes the alpha texture from the view ...
-				if (AI_SUCCESS != aiGetMaterialInteger(pcMat,"no_a_from_d",0,0,&iVal))
-				{
-					pcMesh->piOpacityTexture = pcMesh->piDiffuseTexture;
-					pcMesh->piOpacityTexture->AddRef();
-				}
-			}
-		}
-
-		//
-		// AMBIENT TEXTURE ------------------------------------------------
-		//
-		if(AI_SUCCESS == aiGetMaterialString(pcMat,AI_MATKEY_TEXTURE_AMBIENT(0),&szPath))
-		{
-			LoadTexture(&pcMesh->piAmbientTexture,&szPath);
-		}
-
-		//
-		// EMISSIVE TEXTURE ------------------------------------------------
-		//
-		if(AI_SUCCESS == aiGetMaterialString(pcMat,AI_MATKEY_TEXTURE_EMISSIVE(0),&szPath))
-		{
-			LoadTexture(&pcMesh->piEmissiveTexture,&szPath);
-		}
-
-		//
-		// Shininess TEXTURE ------------------------------------------------
-		//
-		if(AI_SUCCESS == aiGetMaterialString(pcMat,AI_MATKEY_TEXTURE_SHININESS(0),&szPath))
-		{
-			LoadTexture(&pcMesh->piShininessTexture,&szPath);
-		}
-
-		//
-		// Lightmap TEXTURE ------------------------------------------------
-		//
-		if(AI_SUCCESS == aiGetMaterialString(pcMat,AI_MATKEY_TEXTURE_LIGHTMAP(0),&szPath))
-		{
-			LoadTexture(&pcMesh->piLightmapTexture,&szPath);
-		}
-
-
-		//
-		// NORMAL/HEIGHT MAP ------------------------------------------------
-		//
-		bool bHM = false;
-		if(AI_SUCCESS == aiGetMaterialString(pcMat,AI_MATKEY_TEXTURE_NORMALS(0),&szPath))
-		{
-			LoadTexture(&pcMesh->piNormalTexture,&szPath);
-		}
-		else
-		{
-			if(AI_SUCCESS == aiGetMaterialString(pcMat,AI_MATKEY_TEXTURE_HEIGHT(0),&szPath))
-			{
-				LoadTexture(&pcMesh->piNormalTexture,&szPath);
-			}
-			else bib = true;
-			bHM = true;
-		}
-
-		// normal/height maps are sometimes mixed up. Try to detect the type
-		// of the texture automatically
-		if (pcMesh->piNormalTexture)
-		{
-			HMtoNMIfNecessary(pcMesh->piNormalTexture, &pcMesh->piNormalTexture,bHM);
-		}
-	}
-
-	// check whether a global background texture is contained
-	// in this material. Some loaders set this value ...
-	if(AI_SUCCESS == aiGetMaterialString(pcMat,AI_MATKEY_GLOBAL_BACKGROUND_IMAGE,&szPath))
-	{
-		CBackgroundPainter::Instance().SetTextureBG(szPath.data);
-	}
-
-	// BUGFIX: If the shininess is 0.0f disable phong lighting
-	// This is a workaround for some meshes in the DX SDK (e.g. tiny.x)
-	// FIX: Added this check to the x-loader, but the line remains to
-	// catch other loader doing the same ...
-	if (0.0f == pcMesh->fShininess){
-		pcMesh->eShadingMode = aiShadingMode_Gouraud;
-	}
-
-	int two_sided = 0;
-	aiGetMaterialInteger(pcMat,AI_MATKEY_TWOSIDED,&two_sided);
-	pcMesh->twosided = (two_sided != 0);
-
-	// check whether we have already a material using the same
-	// shader. This will decrease loading time rapidly ...
-	for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i)
-	{
-		if (g_pcAsset->pcScene->mMeshes[i] == pcSource)
-		{
-			break;
-		}
-		AssetHelper::MeshHelper* pc = g_pcAsset->apcMeshes[i];
-
-		if  ((pcMesh->piDiffuseTexture != NULL ? true : false) != 
-			(pc->piDiffuseTexture != NULL ? true : false))
-			continue;
-		if  ((pcMesh->piSpecularTexture != NULL ? true : false) != 
-			(pc->piSpecularTexture != NULL ? true : false))
-			continue;
-		if  ((pcMesh->piAmbientTexture != NULL ? true : false) != 
-			(pc->piAmbientTexture != NULL ? true : false))
-			continue;
-		if  ((pcMesh->piEmissiveTexture != NULL ? true : false) != 
-			(pc->piEmissiveTexture != NULL ? true : false))
-			continue;
-		if  ((pcMesh->piNormalTexture != NULL ? true : false) != 
-			(pc->piNormalTexture != NULL ? true : false))
-			continue;
-		if  ((pcMesh->piOpacityTexture != NULL ? true : false) != 
-			(pc->piOpacityTexture != NULL ? true : false))
-			continue;
-		if  ((pcMesh->piShininessTexture != NULL ? true : false) != 
-			(pc->piShininessTexture != NULL ? true : false))
-			continue;
-		if  ((pcMesh->piLightmapTexture != NULL ? true : false) != 
-			(pc->piLightmapTexture != NULL ? true : false))
-			continue;
-		if ((pcMesh->eShadingMode != aiShadingMode_Gouraud ? true : false) != 
-			(pc->eShadingMode != aiShadingMode_Gouraud ? true : false))
-			continue;
-
-		if ((pcMesh->fOpacity != 1.0f ? true : false) != (pc->fOpacity != 1.0f ? true : false))
-			continue;
-
-		if (pcSource->HasBones() != g_pcAsset->pcScene->mMeshes[i]->HasBones())
-			continue;
-
-		// we can reuse this material
-		if (pc->piEffect)
-		{
-			pcMesh->piEffect = pc->piEffect;
-			pc->bSharedFX = pcMesh->bSharedFX = true;
-			pcMesh->piEffect->AddRef();
-			return 2;
-		}
-	}
-	m_iShaderCount++;
-
-	// build macros for the HLSL compiler
-	unsigned int iCurrent = 0;
-	if (pcMesh->piDiffuseTexture)
-	{
-		sMacro[iCurrent].Name = "AV_DIFFUSE_TEXTURE";
-		sMacro[iCurrent].Definition = "1";
-		++iCurrent;
-
-		if (mapU == aiTextureMapMode_Wrap)
-			sMacro[iCurrent].Name = "AV_WRAPU";
-		else if (mapU == aiTextureMapMode_Mirror)
-			sMacro[iCurrent].Name = "AV_MIRRORU";
-		else // if (mapU == aiTextureMapMode_Clamp)
-			sMacro[iCurrent].Name = "AV_CLAMPU";
-
-		sMacro[iCurrent].Definition = "1";
-		++iCurrent;
-
-
-		if (mapV == aiTextureMapMode_Wrap)
-			sMacro[iCurrent].Name = "AV_WRAPV";
-		else if (mapV == aiTextureMapMode_Mirror)
-			sMacro[iCurrent].Name = "AV_MIRRORV";
-		else // if (mapV == aiTextureMapMode_Clamp)
-			sMacro[iCurrent].Name = "AV_CLAMPV";
-
-		sMacro[iCurrent].Definition = "1";
-		++iCurrent;
-	}
-	if (pcMesh->piSpecularTexture)
-	{
-		sMacro[iCurrent].Name = "AV_SPECULAR_TEXTURE";
-		sMacro[iCurrent].Definition = "1";
-		++iCurrent;
-	}
-	if (pcMesh->piAmbientTexture)
-	{
-		sMacro[iCurrent].Name = "AV_AMBIENT_TEXTURE";
-		sMacro[iCurrent].Definition = "1";
-		++iCurrent;
-	}
-	if (pcMesh->piEmissiveTexture)
-	{
-		sMacro[iCurrent].Name = "AV_EMISSIVE_TEXTURE";
-		sMacro[iCurrent].Definition = "1";
-		++iCurrent;
-	}
-	char buff[32];
-	if (pcMesh->piLightmapTexture)
-	{
-		sMacro[iCurrent].Name = "AV_LIGHTMAP_TEXTURE";
-		sMacro[iCurrent].Definition = "1";
-		++iCurrent;
-
-		int idx;
-		if(AI_SUCCESS == aiGetMaterialInteger(pcMat,AI_MATKEY_UVWSRC_LIGHTMAP(0),&idx) && idx >= 1 && pcSource->mTextureCoords[idx])	{
-			sMacro[iCurrent].Name = "AV_TWO_UV";
-			sMacro[iCurrent].Definition = "1";
-			++iCurrent;
-
-			sMacro[iCurrent].Definition = "IN.TexCoord1";
-		}
-		else sMacro[iCurrent].Definition = "IN.TexCoord0";
-		sMacro[iCurrent].Name = "AV_LIGHTMAP_TEXTURE_UV_COORD";
-
-		++iCurrent;float f= 1.f;
-		aiGetMaterialFloat(pcMat,AI_MATKEY_TEXBLEND_LIGHTMAP(0),&f);
-		sprintf(buff,"%f",f);
-
-		sMacro[iCurrent].Name = "LM_STRENGTH";
-		sMacro[iCurrent].Definition = buff;
-		++iCurrent;
-	}
-	if (pcMesh->piNormalTexture && !bib)
-	{
-		sMacro[iCurrent].Name = "AV_NORMAL_TEXTURE";
-		sMacro[iCurrent].Definition = "1";
-		++iCurrent;
-	}
-	if (pcMesh->piOpacityTexture)
-	{
-		sMacro[iCurrent].Name = "AV_OPACITY_TEXTURE";
-		sMacro[iCurrent].Definition = "1";
-		++iCurrent;
-
-		if (pcMesh->piOpacityTexture == pcMesh->piDiffuseTexture)
-		{
-			sMacro[iCurrent].Name = "AV_OPACITY_TEXTURE_REGISTER_MASK";
-			sMacro[iCurrent].Definition = "a";
-			++iCurrent;
-		}
-		else
-		{
-			sMacro[iCurrent].Name = "AV_OPACITY_TEXTURE_REGISTER_MASK";
-			sMacro[iCurrent].Definition = "r";
-			++iCurrent;
-		}
-	}
-
-	if (pcMesh->eShadingMode  != aiShadingMode_Gouraud  && !g_sOptions.bNoSpecular)
-	{
-		sMacro[iCurrent].Name = "AV_SPECULAR_COMPONENT";
-		sMacro[iCurrent].Definition = "1";
-		++iCurrent;
-
-		if (pcMesh->piShininessTexture)
-		{
-			sMacro[iCurrent].Name = "AV_SHININESS_TEXTURE";
-			sMacro[iCurrent].Definition = "1";
-			++iCurrent;
-		}
-	}
-	if (1.0f != pcMesh->fOpacity)
-	{
-		sMacro[iCurrent].Name = "AV_OPACITY";
-		sMacro[iCurrent].Definition = "1";
-		++iCurrent;
-	}
-
-	if( pcSource->HasBones())
-	{
-		sMacro[iCurrent].Name = "AV_SKINNING";
-		sMacro[iCurrent].Definition = "1";
-		++iCurrent;
-	}
-
-	// If a cubemap is active, we'll need to lookup it for calculating
-	// a physically correct reflection
-	if (CBackgroundPainter::TEXTURE_CUBE == CBackgroundPainter::Instance().GetMode())
-	{
-		sMacro[iCurrent].Name = "AV_SKYBOX_LOOKUP";
-		sMacro[iCurrent].Definition = "1";
-		++iCurrent;
-	}
-	sMacro[iCurrent].Name = NULL;
-	sMacro[iCurrent].Definition = NULL;
-
-	// compile the shader
-	if(FAILED( D3DXCreateEffect(g_piDevice,
-		g_szMaterialShader.c_str(),(UINT)g_szMaterialShader.length(),
-		(const D3DXMACRO*)sMacro,NULL,0,NULL,&pcMesh->piEffect,&piBuffer)))
-	{
-		// failed to compile the shader
-		if( piBuffer) 
-		{
-			MessageBox(g_hDlg,(LPCSTR)piBuffer->GetBufferPointer(),"HLSL",MB_OK);
-			piBuffer->Release();
-		}
-		// use the default material instead
-		if (g_piDefaultEffect)
-		{
-			pcMesh->piEffect = g_piDefaultEffect;
-			g_piDefaultEffect->AddRef();
-		}
-
-		// get the name of the material and use it in the log message
-		if(AI_SUCCESS == aiGetMaterialString(pcMat,AI_MATKEY_NAME,&szPath) &&
-			'\0' != szPath.data[0])
-		{
-			std::string sz = "[ERROR] Unable to load material: ";
-			sz.append(szPath.data);
-			CLogDisplay::Instance().AddEntry(sz);
-		}
-		else
-		{
-			CLogDisplay::Instance().AddEntry("Unable to load material: UNNAMED");
-		}
-		return 0;
-	} else
-	{
-		// use Fixed Function effect when working with shaderless cards
-		if( g_sCaps.PixelShaderVersion < D3DPS_VERSION(2,0))
-			pcMesh->piEffect->SetTechnique( "MaterialFX_FF");
-	}
-
-	if( piBuffer) piBuffer->Release();
-
-
-	// now commit all constants to the shader
-	//
-	// This is not necessary for shared shader. Shader constants for
-	// shared shaders are automatically recommited before the shader
-	// is being used for a particular mesh
-
-	if (1.0f != pcMesh->fOpacity)
-		pcMesh->piEffect->SetFloat("TRANSPARENCY",pcMesh->fOpacity);
-	if (pcMesh->eShadingMode  != aiShadingMode_Gouraud && !g_sOptions.bNoSpecular)
-	{
-		pcMesh->piEffect->SetFloat("SPECULARITY",pcMesh->fShininess);
-		pcMesh->piEffect->SetFloat("SPECULAR_STRENGTH",pcMesh->fSpecularStrength);
-	}
-
-	pcMesh->piEffect->SetVector("DIFFUSE_COLOR",&pcMesh->vDiffuseColor);
-	pcMesh->piEffect->SetVector("SPECULAR_COLOR",&pcMesh->vSpecularColor);
-	pcMesh->piEffect->SetVector("AMBIENT_COLOR",&pcMesh->vAmbientColor);
-	pcMesh->piEffect->SetVector("EMISSIVE_COLOR",&pcMesh->vEmissiveColor);
-
-	if (pcMesh->piDiffuseTexture)
-		pcMesh->piEffect->SetTexture("DIFFUSE_TEXTURE",pcMesh->piDiffuseTexture);
-	if (pcMesh->piOpacityTexture)
-		pcMesh->piEffect->SetTexture("OPACITY_TEXTURE",pcMesh->piOpacityTexture);
-	if (pcMesh->piSpecularTexture)
-		pcMesh->piEffect->SetTexture("SPECULAR_TEXTURE",pcMesh->piSpecularTexture);
-	if (pcMesh->piAmbientTexture)
-		pcMesh->piEffect->SetTexture("AMBIENT_TEXTURE",pcMesh->piAmbientTexture);
-	if (pcMesh->piEmissiveTexture)
-		pcMesh->piEffect->SetTexture("EMISSIVE_TEXTURE",pcMesh->piEmissiveTexture);
-	if (pcMesh->piNormalTexture)
-		pcMesh->piEffect->SetTexture("NORMAL_TEXTURE",pcMesh->piNormalTexture);
-	if (pcMesh->piShininessTexture)
-		pcMesh->piEffect->SetTexture("SHININESS_TEXTURE",pcMesh->piShininessTexture);
-	if (pcMesh->piLightmapTexture)
-		pcMesh->piEffect->SetTexture("LIGHTMAP_TEXTURE",pcMesh->piLightmapTexture);
-
-	if (CBackgroundPainter::TEXTURE_CUBE == CBackgroundPainter::Instance().GetMode()){
-		pcMesh->piEffect->SetTexture("lw_tex_envmap",CBackgroundPainter::Instance().GetTexture());
-	}
-
-	return 1;
+    ai_assert(NULL != pcMesh);
+    ai_assert(NULL != pcSource);
+
+    ID3DXBuffer* piBuffer;
+
+    D3DXMACRO sMacro[64];
+
+    // extract all properties from the ASSIMP material structure
+    const aiMaterial* pcMat = g_pcAsset->pcScene->mMaterials[pcSource->mMaterialIndex];
+
+    //
+    // DIFFUSE COLOR --------------------------------------------------
+    //
+    if(AI_SUCCESS != aiGetMaterialColor(pcMat,AI_MATKEY_COLOR_DIFFUSE,
+        (aiColor4D*)&pcMesh->vDiffuseColor))
+    {
+        pcMesh->vDiffuseColor.x = 1.0f;
+        pcMesh->vDiffuseColor.y = 1.0f;
+        pcMesh->vDiffuseColor.z = 1.0f;
+        pcMesh->vDiffuseColor.w = 1.0f;
+    }
+    //
+    // SPECULAR COLOR --------------------------------------------------
+    //
+    if(AI_SUCCESS != aiGetMaterialColor(pcMat,AI_MATKEY_COLOR_SPECULAR,
+        (aiColor4D*)&pcMesh->vSpecularColor))
+    {
+        pcMesh->vSpecularColor.x = 1.0f;
+        pcMesh->vSpecularColor.y = 1.0f;
+        pcMesh->vSpecularColor.z = 1.0f;
+        pcMesh->vSpecularColor.w = 1.0f;
+    }
+    //
+    // AMBIENT COLOR --------------------------------------------------
+    //
+    if(AI_SUCCESS != aiGetMaterialColor(pcMat,AI_MATKEY_COLOR_AMBIENT,
+        (aiColor4D*)&pcMesh->vAmbientColor))
+    {
+        pcMesh->vAmbientColor.x = 0.0f;
+        pcMesh->vAmbientColor.y = 0.0f;
+        pcMesh->vAmbientColor.z = 0.0f;
+        pcMesh->vAmbientColor.w = 1.0f;
+    }
+    //
+    // EMISSIVE COLOR -------------------------------------------------
+    //
+    if(AI_SUCCESS != aiGetMaterialColor(pcMat,AI_MATKEY_COLOR_EMISSIVE,
+        (aiColor4D*)&pcMesh->vEmissiveColor))
+    {
+        pcMesh->vEmissiveColor.x = 0.0f;
+        pcMesh->vEmissiveColor.y = 0.0f;
+        pcMesh->vEmissiveColor.z = 0.0f;
+        pcMesh->vEmissiveColor.w = 1.0f;
+    }
+
+    //
+    // Opacity --------------------------------------------------------
+    //
+    if(AI_SUCCESS != aiGetMaterialFloat(pcMat,AI_MATKEY_OPACITY,&pcMesh->fOpacity))
+    {
+        pcMesh->fOpacity = 1.0f;
+    }
+
+    //
+    // Shading Model --------------------------------------------------
+    //
+    bool bDefault = false;
+    if(AI_SUCCESS != aiGetMaterialInteger(pcMat,AI_MATKEY_SHADING_MODEL,(int*)&pcMesh->eShadingMode ))
+    {
+        bDefault = true;
+        pcMesh->eShadingMode = aiShadingMode_Gouraud;
+    }
+
+
+    //
+    // Shininess ------------------------------------------------------
+    //
+    if(AI_SUCCESS != aiGetMaterialFloat(pcMat,AI_MATKEY_SHININESS,&pcMesh->fShininess))
+    {
+        // assume 15 as default shininess
+        pcMesh->fShininess = 15.0f;
+    }
+    else if (bDefault)pcMesh->eShadingMode  = aiShadingMode_Phong;
+
+
+    //
+    // Shininess strength ------------------------------------------------------
+    //
+    if(AI_SUCCESS != aiGetMaterialFloat(pcMat,AI_MATKEY_SHININESS_STRENGTH,&pcMesh->fSpecularStrength))
+    {
+        // assume 1.0 as default shininess strength
+        pcMesh->fSpecularStrength = 1.0f;
+    }
+
+    aiString szPath;
+
+    aiTextureMapMode mapU(aiTextureMapMode_Wrap),mapV(aiTextureMapMode_Wrap);
+
+    bool bib =false;
+    if (pcSource->mTextureCoords[0])
+    {
+
+        //
+        // DIFFUSE TEXTURE ------------------------------------------------
+        //
+        if(AI_SUCCESS == aiGetMaterialString(pcMat,AI_MATKEY_TEXTURE_DIFFUSE(0),&szPath))
+        {
+            LoadTexture(&pcMesh->piDiffuseTexture,&szPath);
+
+            aiGetMaterialInteger(pcMat,AI_MATKEY_MAPPINGMODE_U_DIFFUSE(0),(int*)&mapU);
+            aiGetMaterialInteger(pcMat,AI_MATKEY_MAPPINGMODE_V_DIFFUSE(0),(int*)&mapV);
+        }
+
+        //
+        // SPECULAR TEXTURE ------------------------------------------------
+        //
+        if(AI_SUCCESS == aiGetMaterialString(pcMat,AI_MATKEY_TEXTURE_SPECULAR(0),&szPath))
+        {
+            LoadTexture(&pcMesh->piSpecularTexture,&szPath);
+        }
+
+        //
+        // OPACITY TEXTURE ------------------------------------------------
+        //
+        if(AI_SUCCESS == aiGetMaterialString(pcMat,AI_MATKEY_TEXTURE_OPACITY(0),&szPath))
+        {
+            LoadTexture(&pcMesh->piOpacityTexture,&szPath);
+        }
+        else
+        {
+            int flags = 0;
+            aiGetMaterialInteger(pcMat,AI_MATKEY_TEXFLAGS_DIFFUSE(0),&flags);
+
+            // try to find out whether the diffuse texture has any
+            // non-opaque pixels. If we find a few, use it as opacity texture
+            if (pcMesh->piDiffuseTexture && !(flags & aiTextureFlags_IgnoreAlpha) && HasAlphaPixels(pcMesh->piDiffuseTexture))
+            {
+                int iVal;
+
+                // NOTE: This special value is set by the tree view if the user
+                // manually removes the alpha texture from the view ...
+                if (AI_SUCCESS != aiGetMaterialInteger(pcMat,"no_a_from_d",0,0,&iVal))
+                {
+                    pcMesh->piOpacityTexture = pcMesh->piDiffuseTexture;
+                    pcMesh->piOpacityTexture->AddRef();
+                }
+            }
+        }
+
+        //
+        // AMBIENT TEXTURE ------------------------------------------------
+        //
+        if(AI_SUCCESS == aiGetMaterialString(pcMat,AI_MATKEY_TEXTURE_AMBIENT(0),&szPath))
+        {
+            LoadTexture(&pcMesh->piAmbientTexture,&szPath);
+        }
+
+        //
+        // EMISSIVE TEXTURE ------------------------------------------------
+        //
+        if(AI_SUCCESS == aiGetMaterialString(pcMat,AI_MATKEY_TEXTURE_EMISSIVE(0),&szPath))
+        {
+            LoadTexture(&pcMesh->piEmissiveTexture,&szPath);
+        }
+
+        //
+        // Shininess TEXTURE ------------------------------------------------
+        //
+        if(AI_SUCCESS == aiGetMaterialString(pcMat,AI_MATKEY_TEXTURE_SHININESS(0),&szPath))
+        {
+            LoadTexture(&pcMesh->piShininessTexture,&szPath);
+        }
+
+        //
+        // Lightmap TEXTURE ------------------------------------------------
+        //
+        if(AI_SUCCESS == aiGetMaterialString(pcMat,AI_MATKEY_TEXTURE_LIGHTMAP(0),&szPath))
+        {
+            LoadTexture(&pcMesh->piLightmapTexture,&szPath);
+        }
+
+
+        //
+        // NORMAL/HEIGHT MAP ------------------------------------------------
+        //
+        bool bHM = false;
+        if(AI_SUCCESS == aiGetMaterialString(pcMat,AI_MATKEY_TEXTURE_NORMALS(0),&szPath))
+        {
+            LoadTexture(&pcMesh->piNormalTexture,&szPath);
+        }
+        else
+        {
+            if(AI_SUCCESS == aiGetMaterialString(pcMat,AI_MATKEY_TEXTURE_HEIGHT(0),&szPath))
+            {
+                LoadTexture(&pcMesh->piNormalTexture,&szPath);
+            }
+            else bib = true;
+            bHM = true;
+        }
+
+        // normal/height maps are sometimes mixed up. Try to detect the type
+        // of the texture automatically
+        if (pcMesh->piNormalTexture)
+        {
+            HMtoNMIfNecessary(pcMesh->piNormalTexture, &pcMesh->piNormalTexture,bHM);
+        }
+    }
+
+    // check whether a global background texture is contained
+    // in this material. Some loaders set this value ...
+    if(AI_SUCCESS == aiGetMaterialString(pcMat,AI_MATKEY_GLOBAL_BACKGROUND_IMAGE,&szPath))
+    {
+        CBackgroundPainter::Instance().SetTextureBG(szPath.data);
+    }
+
+    // BUGFIX: If the shininess is 0.0f disable phong lighting
+    // This is a workaround for some meshes in the DX SDK (e.g. tiny.x)
+    // FIX: Added this check to the x-loader, but the line remains to
+    // catch other loader doing the same ...
+    if (0.0f == pcMesh->fShininess){
+        pcMesh->eShadingMode = aiShadingMode_Gouraud;
+    }
+
+    int two_sided = 0;
+    aiGetMaterialInteger(pcMat,AI_MATKEY_TWOSIDED,&two_sided);
+    pcMesh->twosided = (two_sided != 0);
+
+    // check whether we have already a material using the same
+    // shader. This will decrease loading time rapidly ...
+    for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i)
+    {
+        if (g_pcAsset->pcScene->mMeshes[i] == pcSource)
+        {
+            break;
+        }
+        AssetHelper::MeshHelper* pc = g_pcAsset->apcMeshes[i];
+
+        if  ((pcMesh->piDiffuseTexture != NULL ? true : false) != 
+            (pc->piDiffuseTexture != NULL ? true : false))
+            continue;
+        if  ((pcMesh->piSpecularTexture != NULL ? true : false) != 
+            (pc->piSpecularTexture != NULL ? true : false))
+            continue;
+        if  ((pcMesh->piAmbientTexture != NULL ? true : false) != 
+            (pc->piAmbientTexture != NULL ? true : false))
+            continue;
+        if  ((pcMesh->piEmissiveTexture != NULL ? true : false) != 
+            (pc->piEmissiveTexture != NULL ? true : false))
+            continue;
+        if  ((pcMesh->piNormalTexture != NULL ? true : false) != 
+            (pc->piNormalTexture != NULL ? true : false))
+            continue;
+        if  ((pcMesh->piOpacityTexture != NULL ? true : false) != 
+            (pc->piOpacityTexture != NULL ? true : false))
+            continue;
+        if  ((pcMesh->piShininessTexture != NULL ? true : false) != 
+            (pc->piShininessTexture != NULL ? true : false))
+            continue;
+        if  ((pcMesh->piLightmapTexture != NULL ? true : false) != 
+            (pc->piLightmapTexture != NULL ? true : false))
+            continue;
+        if ((pcMesh->eShadingMode != aiShadingMode_Gouraud ? true : false) != 
+            (pc->eShadingMode != aiShadingMode_Gouraud ? true : false))
+            continue;
+
+        if ((pcMesh->fOpacity != 1.0f ? true : false) != (pc->fOpacity != 1.0f ? true : false))
+            continue;
+
+        if (pcSource->HasBones() != g_pcAsset->pcScene->mMeshes[i]->HasBones())
+            continue;
+
+        // we can reuse this material
+        if (pc->piEffect)
+        {
+            pcMesh->piEffect = pc->piEffect;
+            pc->bSharedFX = pcMesh->bSharedFX = true;
+            pcMesh->piEffect->AddRef();
+            return 2;
+        }
+    }
+    m_iShaderCount++;
+
+    // build macros for the HLSL compiler
+    unsigned int iCurrent = 0;
+    if (pcMesh->piDiffuseTexture)
+    {
+        sMacro[iCurrent].Name = "AV_DIFFUSE_TEXTURE";
+        sMacro[iCurrent].Definition = "1";
+        ++iCurrent;
+
+        if (mapU == aiTextureMapMode_Wrap)
+            sMacro[iCurrent].Name = "AV_WRAPU";
+        else if (mapU == aiTextureMapMode_Mirror)
+            sMacro[iCurrent].Name = "AV_MIRRORU";
+        else // if (mapU == aiTextureMapMode_Clamp)
+            sMacro[iCurrent].Name = "AV_CLAMPU";
+
+        sMacro[iCurrent].Definition = "1";
+        ++iCurrent;
+
+
+        if (mapV == aiTextureMapMode_Wrap)
+            sMacro[iCurrent].Name = "AV_WRAPV";
+        else if (mapV == aiTextureMapMode_Mirror)
+            sMacro[iCurrent].Name = "AV_MIRRORV";
+        else // if (mapV == aiTextureMapMode_Clamp)
+            sMacro[iCurrent].Name = "AV_CLAMPV";
+
+        sMacro[iCurrent].Definition = "1";
+        ++iCurrent;
+    }
+    if (pcMesh->piSpecularTexture)
+    {
+        sMacro[iCurrent].Name = "AV_SPECULAR_TEXTURE";
+        sMacro[iCurrent].Definition = "1";
+        ++iCurrent;
+    }
+    if (pcMesh->piAmbientTexture)
+    {
+        sMacro[iCurrent].Name = "AV_AMBIENT_TEXTURE";
+        sMacro[iCurrent].Definition = "1";
+        ++iCurrent;
+    }
+    if (pcMesh->piEmissiveTexture)
+    {
+        sMacro[iCurrent].Name = "AV_EMISSIVE_TEXTURE";
+        sMacro[iCurrent].Definition = "1";
+        ++iCurrent;
+    }
+    char buff[32];
+    if (pcMesh->piLightmapTexture)
+    {
+        sMacro[iCurrent].Name = "AV_LIGHTMAP_TEXTURE";
+        sMacro[iCurrent].Definition = "1";
+        ++iCurrent;
+
+        int idx;
+        if(AI_SUCCESS == aiGetMaterialInteger(pcMat,AI_MATKEY_UVWSRC_LIGHTMAP(0),&idx) && idx >= 1 && pcSource->mTextureCoords[idx])	{
+            sMacro[iCurrent].Name = "AV_TWO_UV";
+            sMacro[iCurrent].Definition = "1";
+            ++iCurrent;
+
+            sMacro[iCurrent].Definition = "IN.TexCoord1";
+        }
+        else sMacro[iCurrent].Definition = "IN.TexCoord0";
+        sMacro[iCurrent].Name = "AV_LIGHTMAP_TEXTURE_UV_COORD";
+
+        ++iCurrent;float f= 1.f;
+        aiGetMaterialFloat(pcMat,AI_MATKEY_TEXBLEND_LIGHTMAP(0),&f);
+        sprintf(buff,"%f",f);
+
+        sMacro[iCurrent].Name = "LM_STRENGTH";
+        sMacro[iCurrent].Definition = buff;
+        ++iCurrent;
+    }
+    if (pcMesh->piNormalTexture && !bib)
+    {
+        sMacro[iCurrent].Name = "AV_NORMAL_TEXTURE";
+        sMacro[iCurrent].Definition = "1";
+        ++iCurrent;
+    }
+    if (pcMesh->piOpacityTexture)
+    {
+        sMacro[iCurrent].Name = "AV_OPACITY_TEXTURE";
+        sMacro[iCurrent].Definition = "1";
+        ++iCurrent;
+
+        if (pcMesh->piOpacityTexture == pcMesh->piDiffuseTexture)
+        {
+            sMacro[iCurrent].Name = "AV_OPACITY_TEXTURE_REGISTER_MASK";
+            sMacro[iCurrent].Definition = "a";
+            ++iCurrent;
+        }
+        else
+        {
+            sMacro[iCurrent].Name = "AV_OPACITY_TEXTURE_REGISTER_MASK";
+            sMacro[iCurrent].Definition = "r";
+            ++iCurrent;
+        }
+    }
+
+    if (pcMesh->eShadingMode  != aiShadingMode_Gouraud  && !g_sOptions.bNoSpecular)
+    {
+        sMacro[iCurrent].Name = "AV_SPECULAR_COMPONENT";
+        sMacro[iCurrent].Definition = "1";
+        ++iCurrent;
+
+        if (pcMesh->piShininessTexture)
+        {
+            sMacro[iCurrent].Name = "AV_SHININESS_TEXTURE";
+            sMacro[iCurrent].Definition = "1";
+            ++iCurrent;
+        }
+    }
+    if (1.0f != pcMesh->fOpacity)
+    {
+        sMacro[iCurrent].Name = "AV_OPACITY";
+        sMacro[iCurrent].Definition = "1";
+        ++iCurrent;
+    }
+
+    if( pcSource->HasBones())
+    {
+        sMacro[iCurrent].Name = "AV_SKINNING";
+        sMacro[iCurrent].Definition = "1";
+        ++iCurrent;
+    }
+
+    // If a cubemap is active, we'll need to lookup it for calculating
+    // a physically correct reflection
+    if (CBackgroundPainter::TEXTURE_CUBE == CBackgroundPainter::Instance().GetMode())
+    {
+        sMacro[iCurrent].Name = "AV_SKYBOX_LOOKUP";
+        sMacro[iCurrent].Definition = "1";
+        ++iCurrent;
+    }
+    sMacro[iCurrent].Name = NULL;
+    sMacro[iCurrent].Definition = NULL;
+
+    // compile the shader
+    if(FAILED( D3DXCreateEffect(g_piDevice,
+        g_szMaterialShader.c_str(),(UINT)g_szMaterialShader.length(),
+        (const D3DXMACRO*)sMacro,NULL,0,NULL,&pcMesh->piEffect,&piBuffer)))
+    {
+        // failed to compile the shader
+        if( piBuffer) 
+        {
+            MessageBox(g_hDlg,(LPCSTR)piBuffer->GetBufferPointer(),"HLSL",MB_OK);
+            piBuffer->Release();
+        }
+        // use the default material instead
+        if (g_piDefaultEffect)
+        {
+            pcMesh->piEffect = g_piDefaultEffect;
+            g_piDefaultEffect->AddRef();
+        }
+
+        // get the name of the material and use it in the log message
+        if(AI_SUCCESS == aiGetMaterialString(pcMat,AI_MATKEY_NAME,&szPath) &&
+            '\0' != szPath.data[0])
+        {
+            std::string sz = "[ERROR] Unable to load material: ";
+            sz.append(szPath.data);
+            CLogDisplay::Instance().AddEntry(sz);
+        }
+        else
+        {
+            CLogDisplay::Instance().AddEntry("Unable to load material: UNNAMED");
+        }
+        return 0;
+    } else
+    {
+        // use Fixed Function effect when working with shaderless cards
+        if( g_sCaps.PixelShaderVersion < D3DPS_VERSION(2,0))
+            pcMesh->piEffect->SetTechnique( "MaterialFX_FF");
+    }
+
+    if( piBuffer) piBuffer->Release();
+
+
+    // now commit all constants to the shader
+    //
+    // This is not necessary for shared shader. Shader constants for
+    // shared shaders are automatically recommited before the shader
+    // is being used for a particular mesh
+
+    if (1.0f != pcMesh->fOpacity)
+        pcMesh->piEffect->SetFloat("TRANSPARENCY",pcMesh->fOpacity);
+    if (pcMesh->eShadingMode  != aiShadingMode_Gouraud && !g_sOptions.bNoSpecular)
+    {
+        pcMesh->piEffect->SetFloat("SPECULARITY",pcMesh->fShininess);
+        pcMesh->piEffect->SetFloat("SPECULAR_STRENGTH",pcMesh->fSpecularStrength);
+    }
+
+    pcMesh->piEffect->SetVector("DIFFUSE_COLOR",&pcMesh->vDiffuseColor);
+    pcMesh->piEffect->SetVector("SPECULAR_COLOR",&pcMesh->vSpecularColor);
+    pcMesh->piEffect->SetVector("AMBIENT_COLOR",&pcMesh->vAmbientColor);
+    pcMesh->piEffect->SetVector("EMISSIVE_COLOR",&pcMesh->vEmissiveColor);
+
+    if (pcMesh->piDiffuseTexture)
+        pcMesh->piEffect->SetTexture("DIFFUSE_TEXTURE",pcMesh->piDiffuseTexture);
+    if (pcMesh->piOpacityTexture)
+        pcMesh->piEffect->SetTexture("OPACITY_TEXTURE",pcMesh->piOpacityTexture);
+    if (pcMesh->piSpecularTexture)
+        pcMesh->piEffect->SetTexture("SPECULAR_TEXTURE",pcMesh->piSpecularTexture);
+    if (pcMesh->piAmbientTexture)
+        pcMesh->piEffect->SetTexture("AMBIENT_TEXTURE",pcMesh->piAmbientTexture);
+    if (pcMesh->piEmissiveTexture)
+        pcMesh->piEffect->SetTexture("EMISSIVE_TEXTURE",pcMesh->piEmissiveTexture);
+    if (pcMesh->piNormalTexture)
+        pcMesh->piEffect->SetTexture("NORMAL_TEXTURE",pcMesh->piNormalTexture);
+    if (pcMesh->piShininessTexture)
+        pcMesh->piEffect->SetTexture("SHININESS_TEXTURE",pcMesh->piShininessTexture);
+    if (pcMesh->piLightmapTexture)
+        pcMesh->piEffect->SetTexture("LIGHTMAP_TEXTURE",pcMesh->piLightmapTexture);
+
+    if (CBackgroundPainter::TEXTURE_CUBE == CBackgroundPainter::Instance().GetMode()){
+        pcMesh->piEffect->SetTexture("lw_tex_envmap",CBackgroundPainter::Instance().GetTexture());
+    }
+
+    return 1;
 }
 }
 //-------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------
 int CMaterialManager::SetupMaterial (
 int CMaterialManager::SetupMaterial (
-	AssetHelper::MeshHelper* pcMesh,
-	const aiMatrix4x4& pcProj,
-	const aiMatrix4x4& aiMe,
-	const aiMatrix4x4& pcCam,
-	const aiVector3D& vPos)
+    AssetHelper::MeshHelper* pcMesh,
+    const aiMatrix4x4& pcProj,
+    const aiMatrix4x4& aiMe,
+    const aiMatrix4x4& pcCam,
+    const aiVector3D& vPos)
 {
 {
-	ai_assert(NULL != pcMesh);
-	if (!pcMesh->piEffect)return 0;
-
-	ID3DXEffect* piEnd = pcMesh->piEffect;
-
-	piEnd->SetMatrix("WorldViewProjection",
-		(const D3DXMATRIX*)&pcProj);
-
-	piEnd->SetMatrix("World",(const D3DXMATRIX*)&aiMe);
-	piEnd->SetMatrix("WorldInverseTranspose",
-		(const D3DXMATRIX*)&pcCam);
-
-	D3DXVECTOR4 apcVec[5];
-	memset(apcVec,0,sizeof(apcVec));
-	apcVec[0].x = g_avLightDirs[0].x;
-	apcVec[0].y = g_avLightDirs[0].y;
-	apcVec[0].z = g_avLightDirs[0].z;
-	apcVec[0].w = 0.0f;
-	apcVec[1].x = g_avLightDirs[0].x * -1.0f;
-	apcVec[1].y = g_avLightDirs[0].y * -1.0f;
-	apcVec[1].z = g_avLightDirs[0].z * -1.0f;
-	apcVec[1].w = 0.0f;
-	D3DXVec4Normalize(&apcVec[0],&apcVec[0]);
-	D3DXVec4Normalize(&apcVec[1],&apcVec[1]);
-	piEnd->SetVectorArray("afLightDir",apcVec,5);
-
-	apcVec[0].x = ((g_avLightColors[0] >> 16)	& 0xFF) / 255.0f;
-	apcVec[0].y = ((g_avLightColors[0] >> 8)	& 0xFF) / 255.0f;
-	apcVec[0].z = ((g_avLightColors[0])			& 0xFF) / 255.0f;
-	apcVec[0].w = 1.0f;
-
-	if( g_sOptions.b3Lights)
-	{
-		apcVec[1].x = ((g_avLightColors[1] >> 16) & 0xFF) / 255.0f;
-		apcVec[1].y = ((g_avLightColors[1] >> 8) & 0xFF) / 255.0f;
-		apcVec[1].z = ((g_avLightColors[1]) & 0xFF) / 255.0f;
-		apcVec[1].w = 0.0f;
-	} else
-	{
-		apcVec[1].x = 0.0f;
-		apcVec[1].y = 0.0f;
-		apcVec[1].z = 0.0f;
-		apcVec[1].w = 0.0f;
-	}
-
-	apcVec[0] *= g_fLightIntensity;
-	apcVec[1] *= g_fLightIntensity;
-	piEnd->SetVectorArray("afLightColor",apcVec,5);
-
-	apcVec[0].x = ((g_avLightColors[2] >> 16)	& 0xFF) / 255.0f;
-	apcVec[0].y = ((g_avLightColors[2] >> 8)	& 0xFF) / 255.0f;
-	apcVec[0].z = ((g_avLightColors[2])			& 0xFF) / 255.0f;
-	apcVec[0].w = 1.0f;
-
-	apcVec[1].x = ((g_avLightColors[2] >> 16)	& 0xFF) / 255.0f;
-	apcVec[1].y = ((g_avLightColors[2] >> 8)	& 0xFF) / 255.0f;
-	apcVec[1].z = ((g_avLightColors[2])			& 0xFF) / 255.0f;
-	apcVec[1].w = 0.0f;
-
-	// FIX: light intensity doesn't apply to ambient color
-	//apcVec[0] *= g_fLightIntensity;
-	//apcVec[1] *= g_fLightIntensity;
-	piEnd->SetVectorArray("afLightColorAmbient",apcVec,5);
-
-
-	apcVec[0].x = vPos.x;
-	apcVec[0].y = vPos.y;
-	apcVec[0].z = vPos.z;
-	piEnd->SetVector( "vCameraPos",&apcVec[0]);
-
-	// if the effect instance is shared by multiple materials we need to
-	// recommit its whole state once per frame ...
-	if (pcMesh->bSharedFX)
-	{
-		// now commit all constants to the shader
-		if (1.0f != pcMesh->fOpacity)
-			pcMesh->piEffect->SetFloat("TRANSPARENCY",pcMesh->fOpacity);
-		if (pcMesh->eShadingMode  != aiShadingMode_Gouraud)
-		{
-			pcMesh->piEffect->SetFloat("SPECULARITY",pcMesh->fShininess);
-			pcMesh->piEffect->SetFloat("SPECULAR_STRENGTH",pcMesh->fSpecularStrength);
-		}
-
-		pcMesh->piEffect->SetVector("DIFFUSE_COLOR",&pcMesh->vDiffuseColor);
-		pcMesh->piEffect->SetVector("SPECULAR_COLOR",&pcMesh->vSpecularColor);
-		pcMesh->piEffect->SetVector("AMBIENT_COLOR",&pcMesh->vAmbientColor);
-		pcMesh->piEffect->SetVector("EMISSIVE_COLOR",&pcMesh->vEmissiveColor);
-
-		if (pcMesh->piOpacityTexture)
-			pcMesh->piEffect->SetTexture("OPACITY_TEXTURE",pcMesh->piOpacityTexture);
-		if (pcMesh->piDiffuseTexture)
-			pcMesh->piEffect->SetTexture("DIFFUSE_TEXTURE",pcMesh->piDiffuseTexture);
-		if (pcMesh->piSpecularTexture)
-			pcMesh->piEffect->SetTexture("SPECULAR_TEXTURE",pcMesh->piSpecularTexture);
-		if (pcMesh->piAmbientTexture)
-			pcMesh->piEffect->SetTexture("AMBIENT_TEXTURE",pcMesh->piAmbientTexture);
-		if (pcMesh->piEmissiveTexture)
-			pcMesh->piEffect->SetTexture("EMISSIVE_TEXTURE",pcMesh->piEmissiveTexture);
-		if (pcMesh->piNormalTexture)
-			pcMesh->piEffect->SetTexture("NORMAL_TEXTURE",pcMesh->piNormalTexture);
-		if (pcMesh->piShininessTexture)
-			pcMesh->piEffect->SetTexture("SHININESS_TEXTURE",pcMesh->piShininessTexture);
-		if (pcMesh->piLightmapTexture)
-			pcMesh->piEffect->SetTexture("LIGHTMAP_TEXTURE",pcMesh->piLightmapTexture);
-
-		if (CBackgroundPainter::TEXTURE_CUBE == CBackgroundPainter::Instance().GetMode())
-		{
-			piEnd->SetTexture("lw_tex_envmap",CBackgroundPainter::Instance().GetTexture());
-		}
-	}
-
-	// disable culling, if necessary
-	if (pcMesh->twosided && g_sOptions.bCulling) {
-		g_piDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);
-	}
-
-	// setup the correct shader technique to be used for drawing
-	if( g_sCaps.PixelShaderVersion < D3DPS_VERSION(2,0))
-	{
-		g_piDefaultEffect->SetTechnique( "MaterialFXSpecular_FF");
-	} else
-	if (g_sCaps.PixelShaderVersion < D3DPS_VERSION(3,0) || g_sOptions.bLowQuality)
-	{
-		if (g_sOptions.b3Lights)
-			piEnd->SetTechnique("MaterialFXSpecular_PS20_D2");
-		else piEnd->SetTechnique("MaterialFXSpecular_PS20_D1");
-	}
-	else
-	{
-		if (g_sOptions.b3Lights)
-			piEnd->SetTechnique("MaterialFXSpecular_D2");
-		else piEnd->SetTechnique("MaterialFXSpecular_D1");
-	}
-
-	// activate the effect
-	UINT dwPasses = 0;
-	piEnd->Begin(&dwPasses,0);
-	piEnd->BeginPass(0);
-	return 1;
+    ai_assert(NULL != pcMesh);
+    if (!pcMesh->piEffect)return 0;
+
+    ID3DXEffect* piEnd = pcMesh->piEffect;
+
+    piEnd->SetMatrix("WorldViewProjection",
+        (const D3DXMATRIX*)&pcProj);
+
+    piEnd->SetMatrix("World",(const D3DXMATRIX*)&aiMe);
+    piEnd->SetMatrix("WorldInverseTranspose",
+        (const D3DXMATRIX*)&pcCam);
+
+    D3DXVECTOR4 apcVec[5];
+    memset(apcVec,0,sizeof(apcVec));
+    apcVec[0].x = g_avLightDirs[0].x;
+    apcVec[0].y = g_avLightDirs[0].y;
+    apcVec[0].z = g_avLightDirs[0].z;
+    apcVec[0].w = 0.0f;
+    apcVec[1].x = g_avLightDirs[0].x * -1.0f;
+    apcVec[1].y = g_avLightDirs[0].y * -1.0f;
+    apcVec[1].z = g_avLightDirs[0].z * -1.0f;
+    apcVec[1].w = 0.0f;
+    D3DXVec4Normalize(&apcVec[0],&apcVec[0]);
+    D3DXVec4Normalize(&apcVec[1],&apcVec[1]);
+    piEnd->SetVectorArray("afLightDir",apcVec,5);
+
+    apcVec[0].x = ((g_avLightColors[0] >> 16)	& 0xFF) / 255.0f;
+    apcVec[0].y = ((g_avLightColors[0] >> 8)	& 0xFF) / 255.0f;
+    apcVec[0].z = ((g_avLightColors[0])			& 0xFF) / 255.0f;
+    apcVec[0].w = 1.0f;
+
+    if( g_sOptions.b3Lights)
+    {
+        apcVec[1].x = ((g_avLightColors[1] >> 16) & 0xFF) / 255.0f;
+        apcVec[1].y = ((g_avLightColors[1] >> 8) & 0xFF) / 255.0f;
+        apcVec[1].z = ((g_avLightColors[1]) & 0xFF) / 255.0f;
+        apcVec[1].w = 0.0f;
+    } else
+    {
+        apcVec[1].x = 0.0f;
+        apcVec[1].y = 0.0f;
+        apcVec[1].z = 0.0f;
+        apcVec[1].w = 0.0f;
+    }
+
+    apcVec[0] *= g_fLightIntensity;
+    apcVec[1] *= g_fLightIntensity;
+    piEnd->SetVectorArray("afLightColor",apcVec,5);
+
+    apcVec[0].x = ((g_avLightColors[2] >> 16)	& 0xFF) / 255.0f;
+    apcVec[0].y = ((g_avLightColors[2] >> 8)	& 0xFF) / 255.0f;
+    apcVec[0].z = ((g_avLightColors[2])			& 0xFF) / 255.0f;
+    apcVec[0].w = 1.0f;
+
+    apcVec[1].x = ((g_avLightColors[2] >> 16)	& 0xFF) / 255.0f;
+    apcVec[1].y = ((g_avLightColors[2] >> 8)	& 0xFF) / 255.0f;
+    apcVec[1].z = ((g_avLightColors[2])			& 0xFF) / 255.0f;
+    apcVec[1].w = 0.0f;
+
+    // FIX: light intensity doesn't apply to ambient color
+    //apcVec[0] *= g_fLightIntensity;
+    //apcVec[1] *= g_fLightIntensity;
+    piEnd->SetVectorArray("afLightColorAmbient",apcVec,5);
+
+
+    apcVec[0].x = vPos.x;
+    apcVec[0].y = vPos.y;
+    apcVec[0].z = vPos.z;
+    piEnd->SetVector( "vCameraPos",&apcVec[0]);
+
+    // if the effect instance is shared by multiple materials we need to
+    // recommit its whole state once per frame ...
+    if (pcMesh->bSharedFX)
+    {
+        // now commit all constants to the shader
+        if (1.0f != pcMesh->fOpacity)
+            pcMesh->piEffect->SetFloat("TRANSPARENCY",pcMesh->fOpacity);
+        if (pcMesh->eShadingMode  != aiShadingMode_Gouraud)
+        {
+            pcMesh->piEffect->SetFloat("SPECULARITY",pcMesh->fShininess);
+            pcMesh->piEffect->SetFloat("SPECULAR_STRENGTH",pcMesh->fSpecularStrength);
+        }
+
+        pcMesh->piEffect->SetVector("DIFFUSE_COLOR",&pcMesh->vDiffuseColor);
+        pcMesh->piEffect->SetVector("SPECULAR_COLOR",&pcMesh->vSpecularColor);
+        pcMesh->piEffect->SetVector("AMBIENT_COLOR",&pcMesh->vAmbientColor);
+        pcMesh->piEffect->SetVector("EMISSIVE_COLOR",&pcMesh->vEmissiveColor);
+
+        if (pcMesh->piOpacityTexture)
+            pcMesh->piEffect->SetTexture("OPACITY_TEXTURE",pcMesh->piOpacityTexture);
+        if (pcMesh->piDiffuseTexture)
+            pcMesh->piEffect->SetTexture("DIFFUSE_TEXTURE",pcMesh->piDiffuseTexture);
+        if (pcMesh->piSpecularTexture)
+            pcMesh->piEffect->SetTexture("SPECULAR_TEXTURE",pcMesh->piSpecularTexture);
+        if (pcMesh->piAmbientTexture)
+            pcMesh->piEffect->SetTexture("AMBIENT_TEXTURE",pcMesh->piAmbientTexture);
+        if (pcMesh->piEmissiveTexture)
+            pcMesh->piEffect->SetTexture("EMISSIVE_TEXTURE",pcMesh->piEmissiveTexture);
+        if (pcMesh->piNormalTexture)
+            pcMesh->piEffect->SetTexture("NORMAL_TEXTURE",pcMesh->piNormalTexture);
+        if (pcMesh->piShininessTexture)
+            pcMesh->piEffect->SetTexture("SHININESS_TEXTURE",pcMesh->piShininessTexture);
+        if (pcMesh->piLightmapTexture)
+            pcMesh->piEffect->SetTexture("LIGHTMAP_TEXTURE",pcMesh->piLightmapTexture);
+
+        if (CBackgroundPainter::TEXTURE_CUBE == CBackgroundPainter::Instance().GetMode())
+        {
+            piEnd->SetTexture("lw_tex_envmap",CBackgroundPainter::Instance().GetTexture());
+        }
+    }
+
+    // disable culling, if necessary
+    if (pcMesh->twosided && g_sOptions.bCulling) {
+        g_piDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);
+    }
+
+    // setup the correct shader technique to be used for drawing
+    if( g_sCaps.PixelShaderVersion < D3DPS_VERSION(2,0))
+    {
+        g_piDefaultEffect->SetTechnique( "MaterialFXSpecular_FF");
+    } else
+    if (g_sCaps.PixelShaderVersion < D3DPS_VERSION(3,0) || g_sOptions.bLowQuality)
+    {
+        if (g_sOptions.b3Lights)
+            piEnd->SetTechnique("MaterialFXSpecular_PS20_D2");
+        else piEnd->SetTechnique("MaterialFXSpecular_PS20_D1");
+    }
+    else
+    {
+        if (g_sOptions.b3Lights)
+            piEnd->SetTechnique("MaterialFXSpecular_D2");
+        else piEnd->SetTechnique("MaterialFXSpecular_D1");
+    }
+
+    // activate the effect
+    UINT dwPasses = 0;
+    piEnd->Begin(&dwPasses,0);
+    piEnd->BeginPass(0);
+    return 1;
 }
 }
 //-------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------
 int CMaterialManager::EndMaterial (AssetHelper::MeshHelper* pcMesh)
 int CMaterialManager::EndMaterial (AssetHelper::MeshHelper* pcMesh)
 {
 {
-	ai_assert(NULL != pcMesh);
-	if (!pcMesh->piEffect)return 0;
+    ai_assert(NULL != pcMesh);
+    if (!pcMesh->piEffect)return 0;
 
 
-	// end the effect
-	pcMesh->piEffect->EndPass();
-	pcMesh->piEffect->End();
+    // end the effect
+    pcMesh->piEffect->EndPass();
+    pcMesh->piEffect->End();
 
 
-	// reenable culling if necessary
-	if (pcMesh->twosided && g_sOptions.bCulling) {
-		g_piDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_CCW);
-	}		
+    // reenable culling if necessary
+    if (pcMesh->twosided && g_sOptions.bCulling) {
+        g_piDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_CCW);
+    }		
 
 
-	return 1;
+    return 1;
 }
 }
 }; // end namespace AssimpView
 }; // end namespace AssimpView

+ 165 - 159
tools/assimp_view/MaterialManager.h

@@ -39,164 +39,170 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ---------------------------------------------------------------------------
 ---------------------------------------------------------------------------
 */
 */
 
 
-#if (!defined AV_MATERIAL_H_INCLUDED)
-#define AV_MATERIAL_H_INCLUDE
+#pragma once
 
 
-//-------------------------------------------------------------------------------
-/* Helper class to create, access and destroy materials
-*/
-//-------------------------------------------------------------------------------
-class CMaterialManager
+#include <map>
+
+#include "AssetHelper.h"
+
+namespace AssimpView
 {
 {
-private:
-
-	friend class CDisplay;
-
-	// default constructor
-	CMaterialManager() 
-		:	m_iShaderCount (0), sDefaultTexture() {}
-
-	~CMaterialManager() {
-		if (sDefaultTexture) {
-			sDefaultTexture->Release();
-		}
-		Reset();
-	}
-
-public:
-
-	//------------------------------------------------------------------
-	// Singleton accessors
-	static CMaterialManager s_cInstance;
-	inline static CMaterialManager& Instance ()
-		{
-		return s_cInstance;
-		}
-
-	//------------------------------------------------------------------
-	// Delete all resources of a given material
-	//
-	// Must be called before CreateMaterial() to prevent memory leaking
-	void DeleteMaterial(AssetHelper::MeshHelper* pcIn);
-	
-	//------------------------------------------------------------------
-	// Create the material for a mesh.
-	//
-	// The function checks whether an identical shader is already in use.
-	// A shader is considered to be identical if it has the same input 
-	// signature and takes the same number of texture channels.
-	int CreateMaterial(AssetHelper::MeshHelper* pcMesh,
-		const aiMesh* pcSource);
-
-	//------------------------------------------------------------------
-	// Setup the material for a given mesh
-	// pcMesh Mesh to be rendered
-	// pcProj Projection matrix
-	// aiMe Current world matrix
-	// pcCam Camera matrix
-	// vPos Position of the camera
-	// TODO: Extract camera position from matrix ...
-	//
-	int SetupMaterial (AssetHelper::MeshHelper* pcMesh,
-		const aiMatrix4x4& pcProj,
-		const aiMatrix4x4& aiMe,
-		const aiMatrix4x4& pcCam,
-		const aiVector3D& vPos);
-
-	//------------------------------------------------------------------
-	// End the material for a given mesh
-	// Called after mesh rendering is complete
-	// pcMesh Mesh object
-	int EndMaterial (AssetHelper::MeshHelper* pcMesh);
-
-	//------------------------------------------------------------------
-	// Recreate all specular materials depending on the current 
-	// specularity settings
-	//
-	// Diffuse-only materials are ignored.
-	// Must be called after specular highlights have been toggled
-	int UpdateSpecularMaterials();
-
-	//------------------------------------------------------------------
-	// find a valid path to a texture file
-	//
-	// Handle 8.3 syntax correctly, search the environment of the
-	// executable and the asset for a texture with a name very similar 
-	// to a given one
-	int FindValidPath(aiString* p_szString);
-
-	//------------------------------------------------------------------
-	// Load a texture into memory and create a native D3D texture resource
-	//
-	// The function tries to find a valid path for a texture
-	int LoadTexture(IDirect3DTexture9** p_ppiOut,aiString* szPath);
-
-
-	//------------------------------------------------------------------
-	// Getter for m_iShaderCount
-	//
-	inline unsigned int GetShaderCount()
-	{
-		return this->m_iShaderCount;
-	}
-
-	//------------------------------------------------------------------
-	// Reset the state of the class
-	// Called whenever a new asset is loaded
-	inline void Reset()
-	{
-		this->m_iShaderCount = 0;
-		for (TextureCache::iterator it = sCachedTextures.begin(); it != sCachedTextures.end(); ++it) {
-			(*it).second->Release();
-		}
-		sCachedTextures.clear();
-	}
-
-private:
-
-	//------------------------------------------------------------------
-	// find a valid path to a texture file
-	//
-	// Handle 8.3 syntax correctly, search the environment of the
-	// executable and the asset for a texture with a name very similar 
-	// to a given one
-	bool TryLongerPath(char* szTemp,aiString* p_szString);
-
-	//------------------------------------------------------------------
-	// Setup the default texture for a texture channel
-	//
-	// Generates a default checker pattern for a texture
-	int SetDefaultTexture(IDirect3DTexture9** p_ppiOut);
-
-	//------------------------------------------------------------------
-	// Convert a height map to a normal map if necessary
-	//
-	// The function tries to detect the type of a texture automatically.
-	// However, this wont work in every case.
-	void HMtoNMIfNecessary(IDirect3DTexture9* piTexture,
-		IDirect3DTexture9** piTextureOut,
-		bool bWasOriginallyHM = true);
-
-	//------------------------------------------------------------------
-	// Search for non-opaque pixels in a texture
-	//
-	// A pixel is considered to be non-opaque if its alpha value is
-	// less than 255
-	//------------------------------------------------------------------
-	bool HasAlphaPixels(IDirect3DTexture9* piTexture);
-
-private:
-
-	//
-	// Specifies the number of different shaders generated for
-	// the current asset. This number is incremented by CreateMaterial()
-	// each time a shader isn't found in cache and needs to be created
-	//
-	unsigned int m_iShaderCount;
-	IDirect3DTexture9* sDefaultTexture;
-
-	typedef std::map<std::string,IDirect3DTexture9*> TextureCache;
-	TextureCache sCachedTextures;
-};
-
-#endif //!! include guard
+
+    //-------------------------------------------------------------------------------
+    /* Helper class to create, access and destroy materials
+    */
+    //-------------------------------------------------------------------------------
+    class CMaterialManager
+    {
+    private:
+
+        friend class CDisplay;
+
+        // default constructor
+        CMaterialManager()
+            : m_iShaderCount( 0 ), sDefaultTexture() {}
+
+        ~CMaterialManager() {
+            if( sDefaultTexture ) {
+                sDefaultTexture->Release();
+            }
+            Reset();
+        }
+
+    public:
+
+        //------------------------------------------------------------------
+        // Singleton accessors
+        static CMaterialManager s_cInstance;
+        inline static CMaterialManager& Instance()
+        {
+            return s_cInstance;
+        }
+
+        //------------------------------------------------------------------
+        // Delete all resources of a given material
+        //
+        // Must be called before CreateMaterial() to prevent memory leaking
+        void DeleteMaterial( AssetHelper::MeshHelper* pcIn );
+
+        //------------------------------------------------------------------
+        // Create the material for a mesh.
+        //
+        // The function checks whether an identical shader is already in use.
+        // A shader is considered to be identical if it has the same input 
+        // signature and takes the same number of texture channels.
+        int CreateMaterial( AssetHelper::MeshHelper* pcMesh,
+            const aiMesh* pcSource );
+
+        //------------------------------------------------------------------
+        // Setup the material for a given mesh
+        // pcMesh Mesh to be rendered
+        // pcProj Projection matrix
+        // aiMe Current world matrix
+        // pcCam Camera matrix
+        // vPos Position of the camera
+        // TODO: Extract camera position from matrix ...
+        //
+        int SetupMaterial( AssetHelper::MeshHelper* pcMesh,
+            const aiMatrix4x4& pcProj,
+            const aiMatrix4x4& aiMe,
+            const aiMatrix4x4& pcCam,
+            const aiVector3D& vPos );
+
+        //------------------------------------------------------------------
+        // End the material for a given mesh
+        // Called after mesh rendering is complete
+        // pcMesh Mesh object
+        int EndMaterial( AssetHelper::MeshHelper* pcMesh );
+
+        //------------------------------------------------------------------
+        // Recreate all specular materials depending on the current 
+        // specularity settings
+        //
+        // Diffuse-only materials are ignored.
+        // Must be called after specular highlights have been toggled
+        int UpdateSpecularMaterials();
+
+        //------------------------------------------------------------------
+        // find a valid path to a texture file
+        //
+        // Handle 8.3 syntax correctly, search the environment of the
+        // executable and the asset for a texture with a name very similar 
+        // to a given one
+        int FindValidPath( aiString* p_szString );
+
+        //------------------------------------------------------------------
+        // Load a texture into memory and create a native D3D texture resource
+        //
+        // The function tries to find a valid path for a texture
+        int LoadTexture( IDirect3DTexture9** p_ppiOut, aiString* szPath );
+
+
+        //------------------------------------------------------------------
+        // Getter for m_iShaderCount
+        //
+        inline unsigned int GetShaderCount()
+        {
+            return this->m_iShaderCount;
+        }
+
+        //------------------------------------------------------------------
+        // Reset the state of the class
+        // Called whenever a new asset is loaded
+        inline void Reset()
+        {
+            this->m_iShaderCount = 0;
+            for( TextureCache::iterator it = sCachedTextures.begin(); it != sCachedTextures.end(); ++it ) {
+                ( *it ).second->Release();
+            }
+            sCachedTextures.clear();
+        }
+
+    private:
+
+        //------------------------------------------------------------------
+        // find a valid path to a texture file
+        //
+        // Handle 8.3 syntax correctly, search the environment of the
+        // executable and the asset for a texture with a name very similar 
+        // to a given one
+        bool TryLongerPath( char* szTemp, aiString* p_szString );
+
+        //------------------------------------------------------------------
+        // Setup the default texture for a texture channel
+        //
+        // Generates a default checker pattern for a texture
+        int SetDefaultTexture( IDirect3DTexture9** p_ppiOut );
+
+        //------------------------------------------------------------------
+        // Convert a height map to a normal map if necessary
+        //
+        // The function tries to detect the type of a texture automatically.
+        // However, this wont work in every case.
+        void HMtoNMIfNecessary( IDirect3DTexture9* piTexture,
+            IDirect3DTexture9** piTextureOut,
+            bool bWasOriginallyHM = true );
+
+        //------------------------------------------------------------------
+        // Search for non-opaque pixels in a texture
+        //
+        // A pixel is considered to be non-opaque if its alpha value is
+        // less than 255
+        //------------------------------------------------------------------
+        bool HasAlphaPixels( IDirect3DTexture9* piTexture );
+
+    private:
+
+        //
+        // Specifies the number of different shaders generated for
+        // the current asset. This number is incremented by CreateMaterial()
+        // each time a shader isn't found in cache and needs to be created
+        //
+        unsigned int m_iShaderCount;
+        IDirect3DTexture9* sDefaultTexture;
+
+        typedef std::map<std::string, IDirect3DTexture9*> TextureCache;
+        TextureCache sCachedTextures;
+    };
+
+}

+ 0 - 2
tools/assimp_view/MeshRenderer.cpp

@@ -39,7 +39,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ---------------------------------------------------------------------------
 ---------------------------------------------------------------------------
 */
 */
 
 
-#include "stdafx.h"
 #include "assimp_view.h"
 #include "assimp_view.h"
 
 
 #include <map>
 #include <map>
@@ -47,7 +46,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 
 namespace AssimpView {
 namespace AssimpView {
 
 
-
 CMeshRenderer CMeshRenderer::s_cInstance;
 CMeshRenderer CMeshRenderer::s_cInstance;
 
 
 //-------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------

+ 40 - 38
tools/assimp_view/MeshRenderer.h

@@ -42,56 +42,58 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #if (!defined AV_MESH_RENDERER_H_INCLUDED)
 #if (!defined AV_MESH_RENDERER_H_INCLUDED)
 #define AV_MESH_RENDERER_H_INCLUDED
 #define AV_MESH_RENDERER_H_INCLUDED
 
 
+namespace AssimpView {
 
 
 
 
-//-------------------------------------------------------------------------------
-/* Helper class tp render meshes
-*/
-//-------------------------------------------------------------------------------
-class CMeshRenderer
-{
-private:
+    //-------------------------------------------------------------------------------
+    /* Helper class tp render meshes
+    */
+    //-------------------------------------------------------------------------------
+    class CMeshRenderer
+    {
+    private:
+
+        // default constructor
+        CMeshRenderer()
 
 
-	// default constructor
-	CMeshRenderer() 
+        {
+            // no other members to initialize
+        }
 
 
-	{
-		// no other members to initialize
-	}
+    public:
 
 
-public:
+        //------------------------------------------------------------------
+        // Singleton accessors
+        static CMeshRenderer s_cInstance;
+        inline static CMeshRenderer& Instance()
+        {
+            return s_cInstance;
+        }
 
 
-	//------------------------------------------------------------------
-	// Singleton accessors
-	static CMeshRenderer s_cInstance;
-	inline static CMeshRenderer& Instance ()
-	{
-		return s_cInstance;
-	}
 
 
+        //------------------------------------------------------------------
+        // Draw a mesh in the global mesh list using the current pipeline state
+        // iIndex Index of the mesh to be drawn
+        //
+        // The function draws all faces in order, regardless of their distance
+        int DrawUnsorted( unsigned int iIndex );
 
 
-	//------------------------------------------------------------------
-	// Draw a mesh in the global mesh list using the current pipeline state
-	// iIndex Index of the mesh to be drawn
-	//
-	// The function draws all faces in order, regardless of their distance
-	int DrawUnsorted(unsigned int iIndex);
+        //------------------------------------------------------------------
+        // Draw a mesh in the global mesh list using the current pipeline state
+        // iIndex Index of the mesh to be drawn
+        //
+        // The method sorts all vertices by their distance (back to front)
+        //
+        // mWorld World matrix for the node
+        int DrawSorted( unsigned int iIndex,
+            const aiMatrix4x4& mWorld );
 
 
-	//------------------------------------------------------------------
-	// Draw a mesh in the global mesh list using the current pipeline state
-	// iIndex Index of the mesh to be drawn
-	//
-	// The method sorts all vertices by their distance (back to front)
-	//
-	// mWorld World matrix for the node
-	int DrawSorted(unsigned int iIndex,
-		const aiMatrix4x4& mWorld);
 
 
 
 
+    private:
 
 
-private:
 
 
-	
-};
+    };
 
 
+}
 #endif //!! include guard
 #endif //!! include guard

+ 7 - 3
tools/assimp_view/MessageProc.cpp

@@ -39,12 +39,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ---------------------------------------------------------------------------
 ---------------------------------------------------------------------------
 */
 */
 
 
-#include "stdafx.h"
 #include "assimp_view.h"
 #include "assimp_view.h"
+#include <assimp/Exporter.hpp>
+#include <algorithm>
+
 #include <windowsx.h>
 #include <windowsx.h>
 
 
 namespace AssimpView {
 namespace AssimpView {
 
 
+using namespace Assimp;
+
 // Static array to keep custom color values
 // Static array to keep custom color values
 COLORREF g_aclCustomColors[16] = {0};
 COLORREF g_aclCustomColors[16] = {0};
 
 
@@ -1044,9 +1048,9 @@ void DoExport(size_t formatId)
 		ai_assert(strlen(szFileName) <= MAX_PATH);
 		ai_assert(strlen(szFileName) <= MAX_PATH);
 
 
 		// invent a nice default file name 
 		// invent a nice default file name 
-		char* sz = std::max(strrchr(szFileName,'\\'),strrchr(szFileName,'/'));
+		char* sz = max(strrchr(szFileName,'\\'),strrchr(szFileName,'/'));
 		if (sz) {
 		if (sz) {
-			strncpy(sz,std::max(strrchr(g_szFileName,'\\'),strrchr(g_szFileName,'/')),MAX_PATH);
+			strncpy(sz,max(strrchr(g_szFileName,'\\'),strrchr(g_szFileName,'/')),MAX_PATH);
 		}
 		}
 	}
 	}
 	else {
 	else {

+ 1 - 1
tools/assimp_view/Normals.cpp

@@ -40,7 +40,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 */
 
 
 
 
-#include "stdafx.h"
 #include "assimp_view.h"
 #include "assimp_view.h"
 
 
 // note: these are no longer part of the public API, but they are 
 // note: these are no longer part of the public API, but they are 
@@ -53,6 +52,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 
 namespace AssimpView {
 namespace AssimpView {
 
 
+using namespace Assimp;
 
 
 bool g_bWasFlipped = false;
 bool g_bWasFlipped = false;
 float g_smoothAngle = 80.f;
 float g_smoothAngle = 80.f;

+ 0 - 1
tools/assimp_view/SceneAnimator.cpp

@@ -43,7 +43,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *  @brief Implementation of the utility class SceneAnimator
  *  @brief Implementation of the utility class SceneAnimator
  */
  */
 
 
-#include "stdafx.h"
 #include "assimp_view.h"
 #include "assimp_view.h"
 
 
 using namespace AssimpView;
 using namespace AssimpView;

+ 1295 - 1299
tools/assimp_view/Shaders.cpp

@@ -38,1377 +38,1373 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ---------------------------------------------------------------------------
 ---------------------------------------------------------------------------
 */
 */
-
-#include "stdafx.h"
 #include "assimp_view.h"
 #include "assimp_view.h"
 
 
-
-namespace AssimpView 
-{
+namespace AssimpView  {
 
 
 // ------------------------------------------------------------------------------------------------
 // ------------------------------------------------------------------------------------------------
 std::string g_szNormalsShader = std::string(
 std::string g_szNormalsShader = std::string(
 
 
-	// World * View * Projection matrix\n"
-	// NOTE: Assume that the material uses a WorldViewProjection matrix\n"
-	"float4x4 WorldViewProjection	: WORLDVIEWPROJECTION;\n"
-	"float4 OUTPUT_COLOR;\n"
-	
-	// Vertex shader input structure
-	"struct VS_INPUT\n"
-	"{\n"
-		"// Position\n"
-		"float3 Position : POSITION;\n"
-	"};\n"
-
-	// Vertex shader output structure for pixel shader usage
-	"struct VS_OUTPUT\n"
+    // World * View * Projection matrix\n"
+    // NOTE: Assume that the material uses a WorldViewProjection matrix\n"
+    "float4x4 WorldViewProjection	: WORLDVIEWPROJECTION;\n"
+    "float4 OUTPUT_COLOR;\n"
+    
+    // Vertex shader input structure
+    "struct VS_INPUT\n"
+    "{\n"
+        "// Position\n"
+        "float3 Position : POSITION;\n"
+    "};\n"
+
+    // Vertex shader output structure for pixel shader usage
+    "struct VS_OUTPUT\n"
   "{\n"
   "{\n"
-		"float4 Position : POSITION;\n"
-	"};\n"
+        "float4 Position : POSITION;\n"
+    "};\n"
 
 
-	// Vertex shader output structure for FixedFunction usage
-	"struct VS_OUTPUT_FF\n"
-	"{\n"
-		"float4 Position : POSITION;\n"
+    // Vertex shader output structure for FixedFunction usage
+    "struct VS_OUTPUT_FF\n"
+    "{\n"
+        "float4 Position : POSITION;\n"
     "float4 Color : COLOR;\n"
     "float4 Color : COLOR;\n"
-	"};\n"
+    "};\n"
 
 
-	// Vertex shader for rendering normals using pixel shader
-	"VS_OUTPUT RenderNormalsVS(VS_INPUT IN)\n"
-	"{\n"
-		"// Initialize the output structure with zero\n"
-		"VS_OUTPUT Out = (VS_OUTPUT)0;\n"
+    // Vertex shader for rendering normals using pixel shader
+    "VS_OUTPUT RenderNormalsVS(VS_INPUT IN)\n"
+    "{\n"
+        "// Initialize the output structure with zero\n"
+        "VS_OUTPUT Out = (VS_OUTPUT)0;\n"
 
 
-		"// Multiply with the WorldViewProjection matrix\n"
-		"Out.Position = mul(float4(IN.Position,1.0f),WorldViewProjection);\n"
+        "// Multiply with the WorldViewProjection matrix\n"
+        "Out.Position = mul(float4(IN.Position,1.0f),WorldViewProjection);\n"
 
 
-		"return Out;\n"
-	"}\n"
+        "return Out;\n"
+    "}\n"
 
 
-	// Vertex shader for rendering normals using fixed function pipeline
-	"VS_OUTPUT_FF RenderNormalsVS_FF(VS_INPUT IN)\n"
+    // Vertex shader for rendering normals using fixed function pipeline
+    "VS_OUTPUT_FF RenderNormalsVS_FF(VS_INPUT IN)\n"
   "{\n"
   "{\n"
-		"VS_OUTPUT_FF Out;\n"
-		"Out.Position = mul(float4(IN.Position,1.0f),WorldViewProjection);\n"
+        "VS_OUTPUT_FF Out;\n"
+        "Out.Position = mul(float4(IN.Position,1.0f),WorldViewProjection);\n"
     "Out.Color = OUTPUT_COLOR;\n"
     "Out.Color = OUTPUT_COLOR;\n"
-		"return Out;\n"
-	"}\n"
-
-	// Pixel shader
-	"float4 RenderNormalsPS() : COLOR\n"
-	"{\n"
-		"return OUTPUT_COLOR;\n"
-	"}\n"
-
-	// Technique for the normal rendering effect (ps_2_0)
-	"technique RenderNormals\n"
-	"{\n"
-		"pass p0\n"
-		"{\n"
-		"CullMode=none;\n"
-		"PixelShader = compile ps_2_0 RenderNormalsPS();\n"
-		"VertexShader = compile vs_2_0 RenderNormalsVS();\n"
-		"}\n"
-	"};\n"
-
-	// Technique for the normal rendering effect (fixed function)
-	"technique RenderNormals_FF\n"
-	"{\n"
-		"pass p0\n"
-		"{\n"
-		  "CullMode=none;\n"
-		  "VertexShader = compile vs_2_0 RenderNormalsVS_FF();\n"
+        "return Out;\n"
+    "}\n"
+
+    // Pixel shader
+    "float4 RenderNormalsPS() : COLOR\n"
+    "{\n"
+        "return OUTPUT_COLOR;\n"
+    "}\n"
+
+    // Technique for the normal rendering effect (ps_2_0)
+    "technique RenderNormals\n"
+    "{\n"
+        "pass p0\n"
+        "{\n"
+        "CullMode=none;\n"
+        "PixelShader = compile ps_2_0 RenderNormalsPS();\n"
+        "VertexShader = compile vs_2_0 RenderNormalsVS();\n"
+        "}\n"
+    "};\n"
+
+    // Technique for the normal rendering effect (fixed function)
+    "technique RenderNormals_FF\n"
+    "{\n"
+        "pass p0\n"
+        "{\n"
+          "CullMode=none;\n"
+          "VertexShader = compile vs_2_0 RenderNormalsVS_FF();\n"
       "ColorOp[0] = SelectArg1;\n"
       "ColorOp[0] = SelectArg1;\n"
       "ColorArg0[0] = Diffuse;\n"
       "ColorArg0[0] = Diffuse;\n"
       "AlphaOp[0] = SelectArg1;\n"
       "AlphaOp[0] = SelectArg1;\n"
       "AlphaArg0[0] = Diffuse;\n"
       "AlphaArg0[0] = Diffuse;\n"
-		"}\n"
-	"};\n"
-	);
+        "}\n"
+    "};\n"
+    );
 
 
 // ------------------------------------------------------------------------------------------------
 // ------------------------------------------------------------------------------------------------
 std::string g_szSkyboxShader = std::string(
 std::string g_szSkyboxShader = std::string(
 
 
-	// Sampler and texture for the skybox
-	"textureCUBE lw_tex_envmap;\n"
-	"samplerCUBE EnvironmentMapSampler = sampler_state\n"
-	"{\n"
-	  "Texture = (lw_tex_envmap);\n"
-	  "AddressU = CLAMP;\n"
-	  "AddressV = CLAMP;\n"
-	  "AddressW = CLAMP;\n"
-
-	  "MAGFILTER = linear;\n"
-	  "MINFILTER = linear;\n"
-	"};\n"
-
-	// World * View * Projection matrix\n"
-	// NOTE: Assume that the material uses a WorldViewProjection matrix\n"
-	"float4x4 WorldViewProjection	: WORLDVIEWPROJECTION;\n"
-	
-	// Vertex shader input structure
-	"struct VS_INPUT\n"
-	"{\n"
-		"float3 Position : POSITION;\n"
-		"float3 Texture0 : TEXCOORD0;\n"
-	"};\n"
-
-	// Vertex shader output structure
-	"struct VS_OUTPUT\n"
-	"{\n"
-		"float4 Position : POSITION;\n"
-		"float3 Texture0 : TEXCOORD0;\n"
-	"};\n"
-
-	// Vertex shader
-	"VS_OUTPUT RenderSkyBoxVS(VS_INPUT IN)\n"
-	"{\n"
-		"VS_OUTPUT Out;\n"
-
-		// Multiply with the WorldViewProjection matrix
-		"Out.Position = mul(float4(IN.Position,1.0f),WorldViewProjection);\n"
-
-		// Set z to w to ensure z becomes 1.0 after the division through w occurs
-		"Out.Position.z = Out.Position.w;\n"
-	
-		// Simply pass through texture coordinates
-		"Out.Texture0 = IN.Texture0;\n"
-
-		"return Out;\n"
-	"}\n"
-
-	// Pixel shader
-	"float4 RenderSkyBoxPS(float3 Texture0 : TEXCOORD0) : COLOR\n"
-	"{\n"
-		// Lookup the skybox texture
-		"return texCUBE(EnvironmentMapSampler,Texture0) ;\n"
-	"}\n"
-
-	// Technique for the skybox shader (ps_2_0)
-	"technique RenderSkyBox\n"
-	"{\n"
-		"pass p0\n"
-		"{\n"
-		  "ZWriteEnable = FALSE;\n"
-		  "FogEnable = FALSE;\n"
-		  "CullMode = NONE;\n"
-
-		  "PixelShader = compile ps_2_0 RenderSkyBoxPS();\n"
-		  "VertexShader = compile vs_2_0 RenderSkyBoxVS();\n"
-		"}\n"
-	"};\n"
+    // Sampler and texture for the skybox
+    "textureCUBE lw_tex_envmap;\n"
+    "samplerCUBE EnvironmentMapSampler = sampler_state\n"
+    "{\n"
+      "Texture = (lw_tex_envmap);\n"
+      "AddressU = CLAMP;\n"
+      "AddressV = CLAMP;\n"
+      "AddressW = CLAMP;\n"
+
+      "MAGFILTER = linear;\n"
+      "MINFILTER = linear;\n"
+    "};\n"
+
+    // World * View * Projection matrix\n"
+    // NOTE: Assume that the material uses a WorldViewProjection matrix\n"
+    "float4x4 WorldViewProjection	: WORLDVIEWPROJECTION;\n"
+    
+    // Vertex shader input structure
+    "struct VS_INPUT\n"
+    "{\n"
+        "float3 Position : POSITION;\n"
+        "float3 Texture0 : TEXCOORD0;\n"
+    "};\n"
+
+    // Vertex shader output structure
+    "struct VS_OUTPUT\n"
+    "{\n"
+        "float4 Position : POSITION;\n"
+        "float3 Texture0 : TEXCOORD0;\n"
+    "};\n"
+
+    // Vertex shader
+    "VS_OUTPUT RenderSkyBoxVS(VS_INPUT IN)\n"
+    "{\n"
+        "VS_OUTPUT Out;\n"
+
+        // Multiply with the WorldViewProjection matrix
+        "Out.Position = mul(float4(IN.Position,1.0f),WorldViewProjection);\n"
+
+        // Set z to w to ensure z becomes 1.0 after the division through w occurs
+        "Out.Position.z = Out.Position.w;\n"
+    
+        // Simply pass through texture coordinates
+        "Out.Texture0 = IN.Texture0;\n"
+
+        "return Out;\n"
+    "}\n"
+
+    // Pixel shader
+    "float4 RenderSkyBoxPS(float3 Texture0 : TEXCOORD0) : COLOR\n"
+    "{\n"
+        // Lookup the skybox texture
+        "return texCUBE(EnvironmentMapSampler,Texture0) ;\n"
+    "}\n"
+
+    // Technique for the skybox shader (ps_2_0)
+    "technique RenderSkyBox\n"
+    "{\n"
+        "pass p0\n"
+        "{\n"
+          "ZWriteEnable = FALSE;\n"
+          "FogEnable = FALSE;\n"
+          "CullMode = NONE;\n"
+
+          "PixelShader = compile ps_2_0 RenderSkyBoxPS();\n"
+          "VertexShader = compile vs_2_0 RenderSkyBoxVS();\n"
+        "}\n"
+    "};\n"
 
 
   // -------------- same for static background image -----------------
   // -------------- same for static background image -----------------
-	"texture TEXTURE_2D;\n"
-	"sampler TEXTURE_SAMPLER = sampler_state\n"
-	"{\n"
-		"Texture = (TEXTURE_2D);\n"
-	"};\n"
-
-	"struct VS_OUTPUT2\n"
-	"{\n"
-		"float4 Position : POSITION;\n"
-		"float2 TexCoord0 : TEXCOORD0;\n"
-	"};\n"
-
-	"VS_OUTPUT2 RenderImageVS(float4 INPosition : POSITION, float2 INTexCoord0 : TEXCOORD0 )\n"
-	"{\n"
-		"VS_OUTPUT2 Out;\n"
-
-		"Out.Position.xy = INPosition.xy;\n"
-		"Out.Position.z = Out.Position.w = 1.0f;\n"
-		"Out.TexCoord0 = INTexCoord0;\n"
-
-		"return Out;\n"
-	"}\n"
-
-	"float4 RenderImagePS(float2 IN : TEXCOORD0) : COLOR\n"
-	"{\n"
-		"return tex2D(TEXTURE_SAMPLER,IN);\n"
-	"}\n"
-
-	// Technique for the background image shader (ps_2_0)
-	"technique RenderImage2D\n"
-	"{\n"
-		"pass p0\n"
-		"{\n"
-			"ZWriteEnable = FALSE;\n"
-			"FogEnable = FALSE;\n"
-			"CullMode = NONE;\n"
-	
-			"PixelShader = compile ps_2_0 RenderImagePS();\n"
-			"VertexShader = compile vs_2_0 RenderImageVS();\n"
-		"}\n"
-	"};\n"
-	);
+    "texture TEXTURE_2D;\n"
+    "sampler TEXTURE_SAMPLER = sampler_state\n"
+    "{\n"
+        "Texture = (TEXTURE_2D);\n"
+    "};\n"
+
+    "struct VS_OUTPUT2\n"
+    "{\n"
+        "float4 Position : POSITION;\n"
+        "float2 TexCoord0 : TEXCOORD0;\n"
+    "};\n"
+
+    "VS_OUTPUT2 RenderImageVS(float4 INPosition : POSITION, float2 INTexCoord0 : TEXCOORD0 )\n"
+    "{\n"
+        "VS_OUTPUT2 Out;\n"
+
+        "Out.Position.xy = INPosition.xy;\n"
+        "Out.Position.z = Out.Position.w = 1.0f;\n"
+        "Out.TexCoord0 = INTexCoord0;\n"
+
+        "return Out;\n"
+    "}\n"
+
+    "float4 RenderImagePS(float2 IN : TEXCOORD0) : COLOR\n"
+    "{\n"
+        "return tex2D(TEXTURE_SAMPLER,IN);\n"
+    "}\n"
+
+    // Technique for the background image shader (ps_2_0)
+    "technique RenderImage2D\n"
+    "{\n"
+        "pass p0\n"
+        "{\n"
+            "ZWriteEnable = FALSE;\n"
+            "FogEnable = FALSE;\n"
+            "CullMode = NONE;\n"
+    
+            "PixelShader = compile ps_2_0 RenderImagePS();\n"
+            "VertexShader = compile vs_2_0 RenderImageVS();\n"
+        "}\n"
+    "};\n"
+    );
 
 
 std::string g_szDefaultShader = std::string(
 std::string g_szDefaultShader = std::string(
 
 
-	// World * View * Projection matrix
-	// NOTE: Assume that the material uses a WorldViewProjection matrix
-	"float4x4 WorldViewProjection	: WORLDVIEWPROJECTION;\n"
-	"float4x4 World					: WORLD;\n"
-	"float4x3 WorldInverseTranspose	: WORLDINVERSETRANSPOSE;\n"
+    // World * View * Projection matrix
+    // NOTE: Assume that the material uses a WorldViewProjection matrix
+    "float4x4 WorldViewProjection	: WORLDVIEWPROJECTION;\n"
+    "float4x4 World					: WORLD;\n"
+    "float4x3 WorldInverseTranspose	: WORLDINVERSETRANSPOSE;\n"
 
 
-	// light colors
-	"float3 afLightColor[5];\n"
-	// light direction
-	"float3 afLightDir[5];\n"
+    // light colors
+    "float3 afLightColor[5];\n"
+    // light direction
+    "float3 afLightDir[5];\n"
 
 
-	// position of the camera in worldspace\n"
-	"float3 vCameraPos : CAMERAPOSITION;\n"
+    // position of the camera in worldspace\n"
+    "float3 vCameraPos : CAMERAPOSITION;\n"
 
 
-	// Bone matrices
+    // Bone matrices
 //	"#ifdef AV_SKINNING \n"
 //	"#ifdef AV_SKINNING \n"
-	"float4x3 gBoneMatrix[60]; \n"
+    "float4x3 gBoneMatrix[60]; \n"
 //	"#endif // AV_SKINNING \n"
 //	"#endif // AV_SKINNING \n"
 
 
-	// Vertex shader input structure
-	"struct VS_INPUT\n"
-	"{\n"
-		"float3 Position : POSITION;\n"
-		"float3 Normal : NORMAL;\n"
+    // Vertex shader input structure
+    "struct VS_INPUT\n"
+    "{\n"
+        "float3 Position : POSITION;\n"
+        "float3 Normal : NORMAL;\n"
 //		"#ifdef AV_SKINNING \n"
 //		"#ifdef AV_SKINNING \n"
-			"float4 BlendIndices : BLENDINDICES;\n"
-			"float4 BlendWeights : BLENDWEIGHT;\n"
+            "float4 BlendIndices : BLENDINDICES;\n"
+            "float4 BlendWeights : BLENDWEIGHT;\n"
 //		"#endif // AV_SKINNING \n"
 //		"#endif // AV_SKINNING \n"
-	"};\n"
-
-	// Vertex shader output structure for pixel shader usage
-	"struct VS_OUTPUT\n"
-	"{\n"
-		"float4 Position : POSITION;\n"
-		"float3 ViewDir : TEXCOORD0;\n"
-		"float3 Normal : TEXCOORD1;\n"
-	"};\n"
-
-	// Vertex shader output structure for fixed function
-	"struct VS_OUTPUT_FF\n"
-	"{\n"
-		"float4 Position : POSITION;\n"
-		"float4 Color : COLOR;\n"
-	"};\n"
-
-	// Vertex shader for pixel shader usage
-	"VS_OUTPUT DefaultVShader(VS_INPUT IN)\n"
-	"{\n"
-		"VS_OUTPUT Out;\n"
+    "};\n"
+
+    // Vertex shader output structure for pixel shader usage
+    "struct VS_OUTPUT\n"
+    "{\n"
+        "float4 Position : POSITION;\n"
+        "float3 ViewDir : TEXCOORD0;\n"
+        "float3 Normal : TEXCOORD1;\n"
+    "};\n"
+
+    // Vertex shader output structure for fixed function
+    "struct VS_OUTPUT_FF\n"
+    "{\n"
+        "float4 Position : POSITION;\n"
+        "float4 Color : COLOR;\n"
+    "};\n"
+
+    // Vertex shader for pixel shader usage
+    "VS_OUTPUT DefaultVShader(VS_INPUT IN)\n"
+    "{\n"
+        "VS_OUTPUT Out;\n"
 
 
 //		"#ifdef AV_SKINNING \n"
 //		"#ifdef AV_SKINNING \n"
-		"float4 weights = IN.BlendWeights; \n"
-		"weights.w = 1.0f - dot( weights.xyz, float3( 1, 1, 1)); \n"
-		"float4 localPos = float4( IN.Position, 1.0f); \n"
-		"float3 objPos = mul( localPos, gBoneMatrix[IN.BlendIndices.x]) * weights.x; \n"
-		"objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.y]) * weights.y; \n"
-		"objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.z]) * weights.z; \n"
-		"objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.w]) * weights.w; \n"
+        "float4 weights = IN.BlendWeights; \n"
+        "weights.w = 1.0f - dot( weights.xyz, float3( 1, 1, 1)); \n"
+        "float4 localPos = float4( IN.Position, 1.0f); \n"
+        "float3 objPos = mul( localPos, gBoneMatrix[IN.BlendIndices.x]) * weights.x; \n"
+        "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.y]) * weights.y; \n"
+        "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.z]) * weights.z; \n"
+        "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.w]) * weights.w; \n"
 //		"#else \n"
 //		"#else \n"
 //		"float3 objPos = IN.Position; \n"
 //		"float3 objPos = IN.Position; \n"
 //		"#endif // AV_SKINNING \n"
 //		"#endif // AV_SKINNING \n"
 
 
-		// Multiply with the WorldViewProjection matrix
-		"Out.Position = mul( float4( objPos, 1.0f), WorldViewProjection);\n"
-		"float3 WorldPos = mul( float4( objPos, 1.0f), World);\n"
-		"Out.ViewDir = vCameraPos - WorldPos;\n"
-		"Out.Normal = mul(IN.Normal,WorldInverseTranspose);\n"
+        // Multiply with the WorldViewProjection matrix
+        "Out.Position = mul( float4( objPos, 1.0f), WorldViewProjection);\n"
+        "float3 WorldPos = mul( float4( objPos, 1.0f), World);\n"
+        "Out.ViewDir = vCameraPos - WorldPos;\n"
+        "Out.Normal = mul(IN.Normal,WorldInverseTranspose);\n"
 
 
-		"return Out;\n"
-	"}\n"
+        "return Out;\n"
+    "}\n"
 
 
-	// Vertex shader for fixed function pipeline
-	"VS_OUTPUT_FF DefaultVShader_FF(VS_INPUT IN)\n"
-	"{\n"
-		"VS_OUTPUT_FF Out;\n"
+    // Vertex shader for fixed function pipeline
+    "VS_OUTPUT_FF DefaultVShader_FF(VS_INPUT IN)\n"
+    "{\n"
+        "VS_OUTPUT_FF Out;\n"
 
 
 //		"#ifdef AV_SKINNING \n"
 //		"#ifdef AV_SKINNING \n"
-		"float4 weights = IN.BlendWeights; \n"
-		"weights.w = 1.0f - dot( weights.xyz, float3( 1, 1, 1)); \n"
-		"float4 localPos = float4( IN.Position, 1.0f); \n"
-		"float3 objPos = mul( localPos, gBoneMatrix[IN.BlendIndices.x]) * weights.x; \n"
-		"objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.y]) * weights.y; \n"
-		"objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.z]) * weights.z; \n"
-		"objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.w]) * weights.w; \n"
+        "float4 weights = IN.BlendWeights; \n"
+        "weights.w = 1.0f - dot( weights.xyz, float3( 1, 1, 1)); \n"
+        "float4 localPos = float4( IN.Position, 1.0f); \n"
+        "float3 objPos = mul( localPos, gBoneMatrix[IN.BlendIndices.x]) * weights.x; \n"
+        "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.y]) * weights.y; \n"
+        "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.z]) * weights.z; \n"
+        "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.w]) * weights.w; \n"
 //		"#else \n"
 //		"#else \n"
 //		"float3 objPos = IN.Position; \n"
 //		"float3 objPos = IN.Position; \n"
 //		"#endif // AV_SKINNING \n"
 //		"#endif // AV_SKINNING \n"
 
 
-		// Multiply with the WorldViewProjection matrix
-		"Out.Position = mul( float4( objPos, 1.0f), WorldViewProjection);\n"
-
-		"float3 worldNormal = normalize( mul( IN.Normal, (float3x3) WorldInverseTranspose)); \n"
-
-		// per-vertex lighting. We simply assume light colors of unused lights to be black
-		"Out.Color = float4( 0.2f, 0.2f, 0.2f, 1.0f); \n"
-		"for( int a = 0; a < 2; a++)\n"
-		"  Out.Color.rgb += saturate( dot( afLightDir[a], worldNormal)) * afLightColor[a].rgb; \n"
-			"return Out;\n"
-	"}\n"
-
-	// Pixel shader for one light
-	"float4 DefaultPShaderSpecular_D1(VS_OUTPUT IN) : COLOR\n"
-	"{\n"
-		"float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
-
-		"float3 Normal = normalize(IN.Normal);\n"
-		"float3 ViewDir = normalize(IN.ViewDir);\n"
-
-		"{\n"
-			"float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;\n"
-			"float3 Reflect = reflect (Normal,afLightDir[0]);\n"
-			"float fHalfLambert = L1*L1;\n"
-			"OUT.rgb += afLightColor[0] * (fHalfLambert +\n"
-				"saturate(fHalfLambert * 4.0f) * pow(dot(Reflect,ViewDir),9));\n"
-		"}\n"
-		"return OUT;\n"
-	"}\n"
-
-	// Pixel shader for two lights
-	"float4 DefaultPShaderSpecular_D2(VS_OUTPUT IN) : COLOR\n"
-	"{\n"
-		"float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
-
-		"float3 Normal = normalize(IN.Normal);\n"
-		"float3 ViewDir = normalize(IN.ViewDir);\n"
-
-		"{\n"
-			"float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;\n"
-			"float3 Reflect = reflect (ViewDir,Normal);\n"
-			"float fHalfLambert = L1*L1;\n"
-			"OUT.rgb += afLightColor[0] * (fHalfLambert +\n"
-			"saturate(fHalfLambert * 4.0f) * pow(dot(Reflect,afLightDir[0]),9));\n"
-		"}\n"
-		"{\n"
-			"float L1 = dot(Normal,afLightDir[1]) * 0.5f + 0.5f;\n"
-			"float3 Reflect = reflect (ViewDir,Normal);\n"
-			"float fHalfLambert = L1*L1;\n"
-			"OUT.rgb += afLightColor[1] * (fHalfLambert +\n"
-			"saturate(fHalfLambert * 4.0f) * pow(dot(Reflect,afLightDir[1]),9));\n"
-		"}\n"
-		"return OUT;\n"
-	"}\n"
-	// ----------------------------------------------------------------------------
-	"float4 DefaultPShaderSpecular_PS20_D1(VS_OUTPUT IN) : COLOR\n"
-	"{\n"
-		"float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
-
-		"float3 Normal = normalize(IN.Normal);\n"
-		"float3 ViewDir = normalize(IN.ViewDir);\n"
-
-		"{\n"
-			"float L1 = dot(Normal,afLightDir[0]);\n"
-			"float3 Reflect = reflect (Normal,afLightDir[0]);\n"
-			"OUT.rgb += afLightColor[0] * ((L1) +\n"
-			"pow(dot(Reflect,ViewDir),9));\n"
-		"}\n"
-
-		"return OUT;\n"
-	"}\n"
-	// ----------------------------------------------------------------------------
-	"float4 DefaultPShaderSpecular_PS20_D2(VS_OUTPUT IN) : COLOR\n"
-	"{\n"
-		"float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
-
-		"float3 Normal = normalize(IN.Normal);\n"
-		"float3 ViewDir = normalize(IN.ViewDir);\n"
-
-		"{\n"
-			"float L1 = dot(Normal,afLightDir[0]);\n"
-			"float3 Reflect = reflect (Normal,afLightDir[0]);\n"
-			"OUT.rgb += afLightColor[0] * ((L1) +\n"
-			"pow(dot(Reflect,ViewDir),9));\n"
-		"}\n"
-		"{\n"
-			"float L1 = dot(Normal,afLightDir[1]);\n"
-			"float3 Reflect = reflect (Normal,afLightDir[1]);\n"
-			"OUT.rgb += afLightColor[1] * ((L1) +\n"
-			"pow(dot(Reflect,ViewDir),9));\n"
-		"}\n"
-		"return OUT;\n"
-	"}\n"
-
-
-	// Technique for the default effect
-	"technique DefaultFXSpecular_D1\n"
-	"{\n"
-		"pass p0\n"
-		"{\n"
-			"CullMode=none;\n"
-			"PixelShader = compile ps_3_0 DefaultPShaderSpecular_D1();\n"
-			"VertexShader = compile vs_3_0 DefaultVShader();\n"
-		"}\n"
-	"};\n"
-	"technique DefaultFXSpecular_D2\n"
-	"{\n"
-		"pass p0\n"
-		"{\n"
-			"CullMode=none;\n"
-			"PixelShader = compile ps_3_0 DefaultPShaderSpecular_D2();\n"
-			"VertexShader = compile vs_3_0 DefaultVShader();\n"
-		"}\n"
-	"};\n"
-
-	// Technique for the default effect (ps_2_0)
-	"technique DefaultFXSpecular_PS20_D1\n"
-	"{\n"
-		"pass p0\n"
-  	"{\n"
-		  "CullMode=none;\n"
-		  "PixelShader = compile ps_2_0 DefaultPShaderSpecular_PS20_D1();\n"
-		  "VertexShader = compile vs_2_0 DefaultVShader();\n"
-		"}\n"
-	"};\n"
-	"technique DefaultFXSpecular_PS20_D2\n"
-	"{\n"
-		"pass p0\n"
-		"{\n"
-		  "CullMode=none;\n"
-		  "PixelShader = compile ps_2_0 DefaultPShaderSpecular_PS20_D2();\n"
-		  "VertexShader = compile vs_2_0 DefaultVShader();\n"
-		"}\n"
-	"};\n"
-
-	// Technique for the default effect using the fixed function pixel pipeline
-	"technique DefaultFXSpecular_FF\n"
-	"{\n"
-		"pass p0\n"
-		"{\n"
-			"CullMode=none;\n"
-			"VertexShader = compile vs_2_0 DefaultVShader_FF();\n"
-			"ColorOp[0] = SelectArg1;\n"
-			"ColorArg0[0] = Diffuse;\n"
-			"AlphaOp[0] = SelectArg1;\n"
-			"AlphaArg0[0] = Diffuse;\n"
-		"}\n"
-	"};\n"
+        // Multiply with the WorldViewProjection matrix
+        "Out.Position = mul( float4( objPos, 1.0f), WorldViewProjection);\n"
+
+        "float3 worldNormal = normalize( mul( IN.Normal, (float3x3) WorldInverseTranspose)); \n"
+
+        // per-vertex lighting. We simply assume light colors of unused lights to be black
+        "Out.Color = float4( 0.2f, 0.2f, 0.2f, 1.0f); \n"
+        "for( int a = 0; a < 2; a++)\n"
+        "  Out.Color.rgb += saturate( dot( afLightDir[a], worldNormal)) * afLightColor[a].rgb; \n"
+            "return Out;\n"
+    "}\n"
+
+    // Pixel shader for one light
+    "float4 DefaultPShaderSpecular_D1(VS_OUTPUT IN) : COLOR\n"
+    "{\n"
+        "float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
+
+        "float3 Normal = normalize(IN.Normal);\n"
+        "float3 ViewDir = normalize(IN.ViewDir);\n"
+
+        "{\n"
+            "float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;\n"
+            "float3 Reflect = reflect (Normal,afLightDir[0]);\n"
+            "float fHalfLambert = L1*L1;\n"
+            "OUT.rgb += afLightColor[0] * (fHalfLambert +\n"
+                "saturate(fHalfLambert * 4.0f) * pow(dot(Reflect,ViewDir),9));\n"
+        "}\n"
+        "return OUT;\n"
+    "}\n"
+
+    // Pixel shader for two lights
+    "float4 DefaultPShaderSpecular_D2(VS_OUTPUT IN) : COLOR\n"
+    "{\n"
+        "float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
+
+        "float3 Normal = normalize(IN.Normal);\n"
+        "float3 ViewDir = normalize(IN.ViewDir);\n"
+
+        "{\n"
+            "float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;\n"
+            "float3 Reflect = reflect (ViewDir,Normal);\n"
+            "float fHalfLambert = L1*L1;\n"
+            "OUT.rgb += afLightColor[0] * (fHalfLambert +\n"
+            "saturate(fHalfLambert * 4.0f) * pow(dot(Reflect,afLightDir[0]),9));\n"
+        "}\n"
+        "{\n"
+            "float L1 = dot(Normal,afLightDir[1]) * 0.5f + 0.5f;\n"
+            "float3 Reflect = reflect (ViewDir,Normal);\n"
+            "float fHalfLambert = L1*L1;\n"
+            "OUT.rgb += afLightColor[1] * (fHalfLambert +\n"
+            "saturate(fHalfLambert * 4.0f) * pow(dot(Reflect,afLightDir[1]),9));\n"
+        "}\n"
+        "return OUT;\n"
+    "}\n"
+    // ----------------------------------------------------------------------------
+    "float4 DefaultPShaderSpecular_PS20_D1(VS_OUTPUT IN) : COLOR\n"
+    "{\n"
+        "float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
+
+        "float3 Normal = normalize(IN.Normal);\n"
+        "float3 ViewDir = normalize(IN.ViewDir);\n"
+
+        "{\n"
+            "float L1 = dot(Normal,afLightDir[0]);\n"
+            "float3 Reflect = reflect (Normal,afLightDir[0]);\n"
+            "OUT.rgb += afLightColor[0] * ((L1) +\n"
+            "pow(dot(Reflect,ViewDir),9));\n"
+        "}\n"
+
+        "return OUT;\n"
+    "}\n"
+    // ----------------------------------------------------------------------------
+    "float4 DefaultPShaderSpecular_PS20_D2(VS_OUTPUT IN) : COLOR\n"
+    "{\n"
+        "float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
+
+        "float3 Normal = normalize(IN.Normal);\n"
+        "float3 ViewDir = normalize(IN.ViewDir);\n"
+
+        "{\n"
+            "float L1 = dot(Normal,afLightDir[0]);\n"
+            "float3 Reflect = reflect (Normal,afLightDir[0]);\n"
+            "OUT.rgb += afLightColor[0] * ((L1) +\n"
+            "pow(dot(Reflect,ViewDir),9));\n"
+        "}\n"
+        "{\n"
+            "float L1 = dot(Normal,afLightDir[1]);\n"
+            "float3 Reflect = reflect (Normal,afLightDir[1]);\n"
+            "OUT.rgb += afLightColor[1] * ((L1) +\n"
+            "pow(dot(Reflect,ViewDir),9));\n"
+        "}\n"
+        "return OUT;\n"
+    "}\n"
+
+
+    // Technique for the default effect
+    "technique DefaultFXSpecular_D1\n"
+    "{\n"
+        "pass p0\n"
+        "{\n"
+            "CullMode=none;\n"
+            "PixelShader = compile ps_3_0 DefaultPShaderSpecular_D1();\n"
+            "VertexShader = compile vs_3_0 DefaultVShader();\n"
+        "}\n"
+    "};\n"
+    "technique DefaultFXSpecular_D2\n"
+    "{\n"
+        "pass p0\n"
+        "{\n"
+            "CullMode=none;\n"
+            "PixelShader = compile ps_3_0 DefaultPShaderSpecular_D2();\n"
+            "VertexShader = compile vs_3_0 DefaultVShader();\n"
+        "}\n"
+    "};\n"
+
+    // Technique for the default effect (ps_2_0)
+    "technique DefaultFXSpecular_PS20_D1\n"
+    "{\n"
+        "pass p0\n"
+    "{\n"
+          "CullMode=none;\n"
+          "PixelShader = compile ps_2_0 DefaultPShaderSpecular_PS20_D1();\n"
+          "VertexShader = compile vs_2_0 DefaultVShader();\n"
+        "}\n"
+    "};\n"
+    "technique DefaultFXSpecular_PS20_D2\n"
+    "{\n"
+        "pass p0\n"
+        "{\n"
+          "CullMode=none;\n"
+          "PixelShader = compile ps_2_0 DefaultPShaderSpecular_PS20_D2();\n"
+          "VertexShader = compile vs_2_0 DefaultVShader();\n"
+        "}\n"
+    "};\n"
+
+    // Technique for the default effect using the fixed function pixel pipeline
+    "technique DefaultFXSpecular_FF\n"
+    "{\n"
+        "pass p0\n"
+        "{\n"
+            "CullMode=none;\n"
+            "VertexShader = compile vs_2_0 DefaultVShader_FF();\n"
+            "ColorOp[0] = SelectArg1;\n"
+            "ColorArg0[0] = Diffuse;\n"
+            "AlphaOp[0] = SelectArg1;\n"
+            "AlphaArg0[0] = Diffuse;\n"
+        "}\n"
+    "};\n"
   );
   );
 
 
 
 
 std::string g_szMaterialShader = std::string(
 std::string g_szMaterialShader = std::string(
 
 
-	// World * View * Projection matrix
+    // World * View * Projection matrix
   // NOTE: Assume that the material uses a WorldViewProjection matrix
   // NOTE: Assume that the material uses a WorldViewProjection matrix
-	"float4x4 WorldViewProjection	: WORLDVIEWPROJECTION;\n"
-	"float4x4 World					: WORLD;\n"
-	"float4x3 WorldInverseTranspose	: WORLDINVERSETRANSPOSE;\n"
-
-	"#ifndef AV_DISABLESSS\n"
-	"float4x3 ViewProj;\n"
-	"float4x3 InvViewProj;\n"
-	"#endif\n"
-
-	"float4 DIFFUSE_COLOR;\n"
-	"float4 SPECULAR_COLOR;\n"
-	"float4 AMBIENT_COLOR;\n"
-	"float4 EMISSIVE_COLOR;\n"
-
-	"#ifdef AV_SPECULAR_COMPONENT\n"
-	"float SPECULARITY;\n"
-	"float SPECULAR_STRENGTH;\n"
-	"#endif\n"
-	"#ifdef AV_OPACITY\n"
-	"float TRANSPARENCY;\n"
-	"#endif\n"
-
-	// light colors (diffuse and specular)
-	"float4 afLightColor[5];\n"
-	"float4 afLightColorAmbient[5];\n"
-
-	// light direction
-	"float3 afLightDir[5];\n"
-
-	// position of the camera in worldspace
-	"float3 vCameraPos : CAMERAPOSITION;\n"
-
-	// Bone matrices
-	"#ifdef AV_SKINNING \n"
-	"float4x3 gBoneMatrix[60]; \n"
-	"#endif // AV_SKINNING \n"
-
-	"#ifdef AV_DIFFUSE_TEXTURE\n"
-		"texture DIFFUSE_TEXTURE;\n"
-		"sampler DIFFUSE_SAMPLER\n"
-		"{\n"
-		  "Texture = <DIFFUSE_TEXTURE>;\n"
-		  "#ifdef AV_WRAPU\n"
-		  "AddressU = WRAP;\n"
-		  "#endif\n"
-		  "#ifdef AV_MIRRORU\n"
-		  "AddressU = MIRROR;\n"
-		  "#endif\n"
-		  "#ifdef AV_CLAMPU\n"
-		  "AddressU = CLAMP;\n"
-		  "#endif\n"
-		  "#ifdef AV_WRAPV\n"
-		  "AddressV = WRAP;\n"
-		  "#endif\n"
-		  "#ifdef AV_MIRRORV\n"
-		  "AddressV = MIRROR;\n"
-		  "#endif\n"
-		  "#ifdef AV_CLAMPV\n"
-		  "AddressV = CLAMP;\n"
-		  "#endif\n"
-		"};\n"
-	"#endif // AV_DIFFUSE_TEXTUR\n"
-
-	"#ifdef AV_DIFFUSE_TEXTURE2\n"
-		"texture DIFFUSE_TEXTURE2;\n"
-		"sampler DIFFUSE_SAMPLER2\n"
-		"{\n"
-		  "Texture = <DIFFUSE_TEXTURE2>;\n"
-		"};\n"
-	"#endif // AV_DIFFUSE_TEXTUR2\n"
-
-	"#ifdef AV_SPECULAR_TEXTURE\n"
-		"texture SPECULAR_TEXTURE;\n"
-		"sampler SPECULAR_SAMPLER\n"
-		"{\n"
-		  "Texture = <SPECULAR_TEXTURE>;\n"
-		"};\n"
-	"#endif // AV_SPECULAR_TEXTUR\n"
-
-	"#ifdef AV_AMBIENT_TEXTURE\n"
-		"texture AMBIENT_TEXTURE;\n"
-		"sampler AMBIENT_SAMPLER\n"
-		"{\n"
-		  "Texture = <AMBIENT_TEXTURE>;\n"
-		"};\n"
-	"#endif // AV_AMBIENT_TEXTUR\n"
-
-	"#ifdef AV_LIGHTMAP_TEXTURE\n"
-		"texture LIGHTMAP_TEXTURE;\n"
-		"sampler LIGHTMAP_SAMPLER\n"
-		"{\n"
-		  "Texture = <LIGHTMAP_TEXTURE>;\n"
-		"};\n"
-	"#endif // AV_LIGHTMAP_TEXTURE\n"
-
-	"#ifdef AV_OPACITY_TEXTURE\n"
-		"texture OPACITY_TEXTURE;\n"
-		"sampler OPACITY_SAMPLER\n"
-		"{\n"
-		  "Texture = <OPACITY_TEXTURE>;\n"
-		"};\n"
-	"#endif // AV_OPACITY_TEXTURE\n"
-
-	"#ifdef AV_EMISSIVE_TEXTURE\n"
-		"texture EMISSIVE_TEXTURE;\n"
-		"sampler EMISSIVE_SAMPLER\n"
-		"{\n"
-		  "Texture = <EMISSIVE_TEXTURE>;\n"
-		"};\n"
-	"#endif // AV_EMISSIVE_TEXTUR\n"
-
-	"#ifdef AV_NORMAL_TEXTURE\n"
-		"texture NORMAL_TEXTURE;\n"
-		"sampler NORMAL_SAMPLER\n"
-		"{\n"
-		  "Texture = <NORMAL_TEXTURE>;\n"
-		"};\n"
-	"#endif // AV_NORMAL_TEXTURE\n"
-
-	"#ifdef AV_SKYBOX_LOOKUP\n"
-		"textureCUBE lw_tex_envmap;\n"
-		"samplerCUBE EnvironmentMapSampler = sampler_state\n"
-		"{\n"
-		  "Texture = (lw_tex_envmap);\n"
-		  "AddressU = CLAMP;\n"
-		  "AddressV = CLAMP;\n"
-		  "AddressW = CLAMP;\n"
-
-		  "MAGFILTER = linear;\n"
-		  "MINFILTER = linear;\n"
-		"};\n"
-	"#endif // AV_SKYBOX_LOOKUP\n"
-
-	// Vertex shader input structure
-	"struct VS_INPUT\n"
-	"{\n"
-		"float3 Position : POSITION;\n"
-		"float3 Normal : NORMAL;\n"
-		"float4 Color : COLOR0;\n"
-		"float3 Tangent   : TANGENT;\n"
-		"float3 Bitangent : BINORMAL;\n"
-		"float2 TexCoord0 : TEXCOORD0;\n"
-		"#ifdef AV_TWO_UV \n"
-		"float2 TexCoord1 : TEXCOORD1;\n"
-		"#endif \n"
-		  "#ifdef AV_SKINNING \n"
-			"float4 BlendIndices : BLENDINDICES;\n"
-			"float4 BlendWeights : BLENDWEIGHT;\n"
-		 "#endif // AV_SKINNING \n"
-	"};\n"
-
-	// Vertex shader output structure for pixel shader usage
-	"struct VS_OUTPUT\n"
-	"{\n"
-		"float4 Position : POSITION;\n"
-		"float3 ViewDir : TEXCOORD0;\n"
-
-		"float4 Color : COLOR0;\n"
-
-		"#ifndef AV_NORMAL_TEXTURE\n"
-		"float3 Normal  : TEXCOORD1;\n"
-		"#endif\n"
-
-		"float2 TexCoord0 : TEXCOORD2;\n"
-		"#ifdef AV_TWO_UV \n"
-		"float2 TexCoord1 : TEXCOORD3;\n"
-		"#endif \n"
-
-		"#ifdef AV_NORMAL_TEXTURE\n"
-		"float3 Light0 : TEXCOORD3;\n"
-		"float3 Light1 : TEXCOORD4;\n"
-		"#endif\n"
-	"};\n"
-
-	// Vertex shader output structure for fixed function pixel pipeline
-	"struct VS_OUTPUT_FF\n"
-	"{\n"
-		"float4 Position : POSITION;\n"
-		"float4 DiffuseColor : COLOR0;\n"
-		"float4 SpecularColor : COLOR1;\n"
-		"float2 TexCoord0 : TEXCOORD0;\n"
-	"};\n"
-
-
-	// Selective SuperSampling in screenspace for reflection lookups
-	"#define GetSSSCubeMap(_refl) (texCUBElod(EnvironmentMapSampler,float4(_refl,0.0f)).rgb) \n"
-
-
-	// Vertex shader for pixel shader usage and one light
-	"VS_OUTPUT MaterialVShader_D1(VS_INPUT IN)\n"
-	"{\n"
-		"VS_OUTPUT Out = (VS_OUTPUT)0;\n"
-
-		"#ifdef AV_SKINNING \n"
-		"float4 weights = IN.BlendWeights; \n"
-		"weights.w = 1.0f - dot( weights.xyz, float3( 1, 1, 1)); \n"
-		"float4 localPos = float4( IN.Position, 1.0f); \n"
-		"float3 objPos = mul( localPos, gBoneMatrix[IN.BlendIndices.x]) * weights.x; \n"
-		"objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.y]) * weights.y; \n"
-		"objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.z]) * weights.z; \n"
-		"objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.w]) * weights.w; \n"
-		"#else \n"
-		"float3 objPos = IN.Position; \n"
-		"#endif // AV_SKINNING \n"
-
-		// Multiply with the WorldViewProjection matrix
-		"Out.Position = mul( float4( objPos, 1.0f), WorldViewProjection);\n"
-		"float3 WorldPos = mul( float4( objPos, 1.0f), World);\n"
-		"Out.TexCoord0 = IN.TexCoord0;\n"
-		"#ifdef AV_TWO_UV \n"
-		"Out.TexCoord1 = IN.TexCoord1;\n"
-		"#endif\n"
-		"Out.Color = IN.Color;\n"
-
-		"#ifndef AV_NORMAL_TEXTURE\n"
-		"Out.ViewDir = vCameraPos - WorldPos;\n"
-		"Out.Normal = mul(IN.Normal,WorldInverseTranspose);\n"
-		"#endif\n"
-		
-		"#ifdef AV_NORMAL_TEXTURE\n"
-		"float3x3 TBNMatrix = float3x3(IN.Tangent, IN.Bitangent, IN.Normal);\n"
-		"float3x3 WTTS      = mul(TBNMatrix, (float3x3)WorldInverseTranspose);\n"
-		"Out.Light0         = normalize(mul(WTTS, afLightDir[0] ));\n"
-		"Out.ViewDir = normalize(mul(WTTS, (vCameraPos - WorldPos)));\n"
-		"#endif\n"
-		"return Out;\n"
-	"}\n"
-
-	// Vertex shader for pixel shader usage and two lights
-	"VS_OUTPUT MaterialVShader_D2(VS_INPUT IN)\n"
-	"{\n"
-		"VS_OUTPUT Out = (VS_OUTPUT)0;\n"
-
-		"#ifdef AV_SKINNING \n"
-		"float4 weights = IN.BlendWeights; \n"
-		"weights.w = 1.0f - dot( weights.xyz, float3( 1, 1, 1)); \n"
-		"float4 localPos = float4( IN.Position, 1.0f); \n"
-		"float3 objPos = mul( localPos, gBoneMatrix[IN.BlendIndices.x]) * weights.x; \n"
-		"objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.y]) * weights.y; \n"
-		"objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.z]) * weights.z; \n"
-		"objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.w]) * weights.w; \n"
-		"#else \n"
-		"float3 objPos = IN.Position; \n"
-		"#endif // AV_SKINNING \n"
-
-		// Multiply with the WorldViewProjection matrix
-		"Out.Position = mul( float4( objPos, 1.0f), WorldViewProjection);\n"
-		"float3 WorldPos = mul( float4( objPos, 1.0f), World);\n"
-		"Out.TexCoord0 = IN.TexCoord0;\n"
-		"#ifdef AV_TWO_UV \n"
-		"Out.TexCoord1 = IN.TexCoord1;\n"
-		"#endif\n"
-		"Out.Color = IN.Color;\n"
-
-		"#ifndef AV_NORMAL_TEXTURE\n"
-		"Out.ViewDir = vCameraPos - WorldPos;\n"
-		"Out.Normal = mul(IN.Normal,WorldInverseTranspose);\n"
-		"#endif\n"
-
-		"#ifdef AV_NORMAL_TEXTURE\n"
-		"float3x3 TBNMatrix = float3x3(IN.Tangent, IN.Bitangent, IN.Normal);\n"
-		"float3x3 WTTS      = mul(TBNMatrix, (float3x3)WorldInverseTranspose);\n"
-		"Out.Light0         = normalize(mul(WTTS, afLightDir[0] ));\n"
-		"Out.Light1         = normalize(mul(WTTS, afLightDir[1] ));\n"
-		"Out.ViewDir = normalize(mul(WTTS, (vCameraPos - WorldPos)));\n"
-		"#endif\n"
-		"return Out;\n"
-	"}\n"
-
-	// Vertex shader for zero to five lights using the fixed function pixel pipeline
-	"VS_OUTPUT_FF MaterialVShader_FF(VS_INPUT IN)\n"
-	"{\n"
-		"VS_OUTPUT_FF Out = (VS_OUTPUT_FF)0;\n"
-
-		"#ifdef AV_SKINNING \n"
-		"float4 weights = IN.BlendWeights; \n"
-		"weights.w = 1.0f - dot( weights.xyz, float3( 1, 1, 1)); \n"
-		"float4 localPos = float4( IN.Position, 1.0f); \n"
-		"float3 objPos = mul( localPos, gBoneMatrix[IN.BlendIndices.x]) * weights.x; \n"
-		"objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.y]) * weights.y; \n"
-		"objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.z]) * weights.z; \n"
-		"objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.w]) * weights.w; \n"
-		"#else \n"
-		"float3 objPos = IN.Position; \n"
-		"#endif // AV_SKINNING \n"
-
-		// Multiply with the WorldViewProjection matrix
-		"Out.Position = mul( float4( objPos, 1.0f), WorldViewProjection);\n"
-		"float3 worldPos = mul( float4( objPos, 1.0f), World);\n"
-		"float3 worldNormal = normalize( mul( IN.Normal, (float3x3) WorldInverseTranspose)); \n"
-		"Out.TexCoord0 = IN.TexCoord0;\n"
-
-		// calculate per-vertex diffuse lighting including ambient part
-		"float4 diffuseColor = float4( 0.0f, 0.0f, 0.0f, 1.0f); \n"
-		"for( int a = 0; a < 2; a++) \n"
-		"  diffuseColor.rgb += saturate( dot( afLightDir[a], worldNormal)) * afLightColor[a].rgb; \n"
-		// factor in material properties and a bit of ambient lighting
-		"Out.DiffuseColor = diffuseColor * DIFFUSE_COLOR + float4( 0.2f, 0.2f, 0.2f, 1.0f) * AMBIENT_COLOR; ; \n"
-
-		// and specular including emissive part
-		"float4 specularColor = float4( 0.0f, 0.0f, 0.0f, 1.0f); \n"
-		"#ifdef AV_SPECULAR_COMPONENT\n"
-		"float3 viewDir = normalize( worldPos - vCameraPos); \n"
-		"for( int a = 0; a < 2; a++) \n"
-		"{ \n"
-		"  float3 reflDir = reflect( afLightDir[a], worldNormal); \n"
-		"  float specIntensity = pow( saturate( dot( reflDir, viewDir)), SPECULARITY) * SPECULAR_STRENGTH; \n"
-		"  specularColor.rgb += afLightColor[a] * specIntensity; \n"
-		"} \n"
-		"#endif // AV_SPECULAR_COMPONENT\n"
-		// factor in material properties and the emissive part
-		"Out.SpecularColor = specularColor * SPECULAR_COLOR + EMISSIVE_COLOR; \n"
-
-		"return Out;\n"
-	"}\n"
-
-
-	// Pixel shader - one light
-	"float4 MaterialPShaderSpecular_D1(VS_OUTPUT IN) : COLOR\n"
-	"{\n"
-		"float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
-
-		"#ifdef AV_NORMAL_TEXTURE\n"
-		"float3 IN_Light0 = normalize(IN.Light0);\n"
-		"float3 Normal  =  normalize(2.0f * tex2D(NORMAL_SAMPLER, IN.TexCoord0).rgb - 1.0f);\n"
-		"#else\n"
-		"float3 Normal = normalize(IN.Normal);\n"
-		"#endif \n"
-		"float3 ViewDir = normalize(IN.ViewDir);\n"
-		"#ifdef AV_SPECULAR_COMPONENT\n"
-			"float3 Reflect = normalize(reflect (-ViewDir,Normal));\n"
-		"#endif // !AV_SPECULAR_COMPONENT\n"
-
-		"{\n"
-		"#ifdef AV_NORMAL_TEXTURE\n"
-			"float L1 =  dot(Normal,IN_Light0) * 0.5f + 0.5f;\n"
-			"#define AV_LIGHT_0 IN_Light0\n"
-			// would need to convert the reflection vector into world space ....
-			// simply let it ...
-		"#else\n"
-			"float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;\n"
-			"#define AV_LIGHT_0 afLightDir[0]\n"
-		"#endif\n"
-		"#ifdef AV_DIFFUSE_TEXTURE2\n"
-			"float fHalfLambert = 1.f;\n"
-		"#else\n"
-			"float fHalfLambert = L1*L1;\n"
-		"#endif \n"
-		"#ifdef AV_DIFFUSE_TEXTURE\n"
-			"OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * fHalfLambert * IN.Color.rgb +\n"
-		"#else\n"
-			"OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * fHalfLambert * IN.Color.rgb +\n"
-		"#endif // !AV_DIFFUSE_TEXTURE\n"
-
-		
-		"#ifdef AV_SPECULAR_COMPONENT\n"
-			"#ifndef AV_SKYBOX_LOOKUP\n"
-				"#ifdef AV_SPECULAR_TEXTURE\n"
-					"SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
-				"#else\n"
-					"SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
-				"#endif // !AV_SPECULAR_TEXTURE\n"
-			"#else\n"
-				"#ifdef AV_SPECULAR_TEXTURE\n"
-					"SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * GetSSSCubeMap(Reflect) * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
-				"#else\n"
-					"SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * GetSSSCubeMap(Reflect) * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
-				"#endif // !AV_SPECULAR_TEXTURE\n"
-			"#endif // !AV_SKYBOX_LOOKUP\n"
-		"#endif // !AV_SPECULAR_COMPONENT\n"
-
-		"#ifdef AV_AMBIENT_TEXTURE\n"
-			"AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb +\n"
-		"#else\n"
-			"AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb + \n"
-		"#endif // !AV_AMBIENT_TEXTURE\n"
-     		"#ifdef AV_EMISSIVE_TEXTURE\n"
-			"EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;\n"
-		"#else \n"
-			"EMISSIVE_COLOR.rgb;\n"
-		"#endif // !AV_EMISSIVE_TEXTURE\n"
-		"}\n"
-		"#ifdef AV_OPACITY\n"
-		"OUT.a = TRANSPARENCY;\n"
-		"#endif\n"
-		"#ifdef AV_LIGHTMAP_TEXTURE\n"
-		"OUT.rgb *= tex2D(LIGHTMAP_SAMPLER,AV_LIGHTMAP_TEXTURE_UV_COORD).rgb*LM_STRENGTH;\n"
-		"#endif\n"
-		"#ifdef AV_OPACITY_TEXTURE\n"
-		"OUT.a *= tex2D(OPACITY_SAMPLER,IN.TexCoord0). AV_OPACITY_TEXTURE_REGISTER_MASK;\n"
-		"#endif\n"
-		"return OUT;\n"
-
-		"#undef AV_LIGHT_0\n"
-	"}\n"
-
-	// Pixel shader - two lights
-	"float4 MaterialPShaderSpecular_D2(VS_OUTPUT IN) : COLOR\n"
-	"{\n"
-		"float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
-
-		"#ifdef AV_NORMAL_TEXTURE\n"
-		"float3 IN_Light0 = normalize(IN.Light0);\n"
-		"float3 IN_Light1 = normalize(IN.Light1);\n"
-		"float3 Normal  =  normalize(2.0f * tex2D(NORMAL_SAMPLER, IN.TexCoord0).rgb - 1.0f);\n"
-		"#else\n"
-		"float3 Normal = normalize(IN.Normal);\n"
-		"#endif \n"
-		"float3 ViewDir = normalize(IN.ViewDir);\n"
-		"#ifdef AV_SPECULAR_COMPONENT\n"
-			"float3 Reflect = -normalize(reflect (ViewDir,Normal));\n"
-		"#endif // !AV_SPECULAR_COMPONENT\n"
-
-		"{\n"
-		
-		"#ifdef AV_NORMAL_TEXTURE\n"
-			"float L1 = dot(Normal,IN_Light0) * 0.5f + 0.5f;\n"
-			"#define AV_LIGHT_0 IN_Light0\n"
-		"#else\n"
-			"float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;\n"
-			"#define AV_LIGHT_0 afLightDir[0]\n"
-		"#endif\n"
-			"float fHalfLambert = L1*L1;\n"
-			
-		"#ifdef AV_DIFFUSE_TEXTURE\n"
-			"OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * fHalfLambert  * IN.Color.rgb +\n"
-		"#else\n"
-			"OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * fHalfLambert  * IN.Color.rgb +\n"
-		"#endif // !AV_DIFFUSE_TEXTURE\n"
-
-		"#ifdef AV_SPECULAR_COMPONENT\n"
-			"#ifndef AV_SKYBOX_LOOKUP\n"
-				"#ifdef AV_SPECULAR_TEXTURE\n"
-					"SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
-				"#else\n"
-					"SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
-				"#endif // !AV_SPECULAR_TEXTURE\n"
-			"#else\n"
-				"#ifdef AV_SPECULAR_TEXTURE\n"
-					"SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * GetSSSCubeMap(Reflect) * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
-				"#else\n"
-					"SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * GetSSSCubeMap(Reflect) * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
-				"#endif // !AV_SPECULAR_TEXTURE\n"
-			"#endif // !AV_SKYBOX_LOOKUP\n"
-		"#endif // !AV_SPECULAR_COMPONENT\n"
-		"#ifdef AV_AMBIENT_TEXTURE\n"
-			"AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb + \n"
-		"#else\n"
-			"AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb + \n"
-		"#endif // !AV_AMBIENT_TEXTURE\n"
-		"#ifdef AV_EMISSIVE_TEXTURE\n"
-			"EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;\n"
-		"#else \n"
-			"EMISSIVE_COLOR.rgb;\n"
-		"#endif // !AV_EMISSIVE_TEXTURE\n"
-		"}\n"
-		"{\n"
-		"#ifdef AV_NORMAL_TEXTURE\n"
-			"float L1 = dot(Normal,IN_Light1) * 0.5f + 0.5f;\n"
-			"#define AV_LIGHT_1 IN_Light1\n"
-		"#else\n"
-			"float L1 = dot(Normal,afLightDir[1]) * 0.5f + 0.5f;\n"
-			"#define AV_LIGHT_1 afLightDir[1]\n"
-		"#endif\n"
-			"float fHalfLambert = L1*L1;\n"
-		"#ifdef AV_DIFFUSE_TEXTURE\n"
-			"OUT.rgb += afLightColor[1].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * fHalfLambert  * IN.Color.rgb +\n"
-		"#else\n"
-			"OUT.rgb += afLightColor[1].rgb * DIFFUSE_COLOR.rgb * fHalfLambert   * IN.Color.rgb +\n"
-		"#endif // !AV_DIFFUSE_TEXTURE\n"
-
-		"#ifdef AV_SPECULAR_COMPONENT\n"
-			"#ifndef AV_SKYBOX_LOOKUP\n"
-				"#ifdef AV_SPECULAR_TEXTURE\n"
-					"SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[1].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_1),SPECULARITY)) + \n"
-				"#else\n"
-					"SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[1].rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_1),SPECULARITY)) + \n"
-				"#endif // !AV_SPECULAR_TEXTURE\n"
-			"#else\n"
-				"#ifdef AV_SPECULAR_TEXTURE\n"
-					"SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[1].rgb * GetSSSCubeMap(Reflect) * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_1),SPECULARITY)) + \n"
-				"#else\n"
-					"SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[1].rgb * GetSSSCubeMap(Reflect) * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_1),SPECULARITY)) + \n"
-				"#endif // !AV_SPECULAR_TEXTURE\n"
-			"#endif // !AV_SKYBOX_LOOKUP\n"
-		"#endif // !AV_SPECULAR_COMPONENT\n"
-		"#ifdef AV_AMBIENT_TEXTURE\n"
-			"AMBIENT_COLOR.rgb * afLightColorAmbient[1].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb + \n"
-		"#else\n"
-			"AMBIENT_COLOR.rgb * afLightColorAmbient[1].rgb + \n"
-		"#endif // !AV_AMBIENT_TEXTURE\n"
-		"#ifdef AV_EMISSIVE_TEXTURE\n"
-			"EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;\n"
-		"#else \n"
-			"EMISSIVE_COLOR.rgb;\n"
-		"#endif // !AV_EMISSIVE_TEXTURE\n"
-		"}\n"
-		"#ifdef AV_OPACITY\n"
-		"OUT.a = TRANSPARENCY;\n"
-		"#endif\n"
-		"#ifdef AV_LIGHTMAP_TEXTURE\n"
-		"OUT.rgb *= tex2D(LIGHTMAP_SAMPLER,AV_LIGHTMAP_TEXTURE_UV_COORD).rgb*LM_STRENGTH;\n"
-		"#endif\n"
-		"#ifdef AV_OPACITY_TEXTURE\n"
-		"OUT.a *= tex2D(OPACITY_SAMPLER,IN.TexCoord0). AV_OPACITY_TEXTURE_REGISTER_MASK;\n"
-		"#endif\n"
-		"return OUT;\n"
-
-		"#undef AV_LIGHT_0\n"
-		"#undef AV_LIGHT_1\n"
-	"}\n"
-
-	// Same pixel shader again, one light
-	"float4 MaterialPShaderSpecular_PS20_D1(VS_OUTPUT IN) : COLOR\n"
-	"{\n"
-		"float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
-
-		"#ifdef AV_NORMAL_TEXTURE\n"
-		"float3 IN_Light0 = normalize(IN.Light0);\n"
-		"float3 Normal  =  normalize(2.0f * tex2D(NORMAL_SAMPLER, IN.TexCoord0).rgb - 1.0f);\n"
-		"#else\n"
-		"float3 Normal = normalize(IN.Normal);\n"
-		"#endif \n"
-		"float3 ViewDir = normalize(IN.ViewDir);\n"
-
-		"{\n"
-		"#ifdef AV_NORMAL_TEXTURE\n"
-		"float L1 = dot(Normal,IN_Light0) * 0.5f + 0.5f;\n"
-		"float3 Reflect = reflect (Normal,IN_Light0);\n"
-		"#else\n"
-		"float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;\n"
-		"float3 Reflect = reflect (Normal,afLightDir[0]);\n"
-		"#endif\n"
-		"#ifdef AV_DIFFUSE_TEXTURE\n"
-			"OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * L1 +\n"
-		"#else\n"
-			"OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * L1 +\n"
-		"#endif // !AV_DIFFUSE_TEXTURE\n"
-
-		"#ifdef AV_SPECULAR_COMPONENT\n"
-		"#ifdef AV_SPECULAR_TEXTURE\n"
-			"SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) + \n"
-		"#else\n"
-			"SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) + \n"
-		"#endif // !AV_SPECULAR_TEXTURE\n"
-		"#endif // !AV_SPECULAR_COMPONENT\n"
-		"#ifdef AV_AMBIENT_TEXTURE\n"
-			"AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb +\n"
-		"#else\n"
-			"AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb +\n"
-		"#endif // !AV_AMBIENT_TEXTURE\n"
-		"#ifdef AV_EMISSIVE_TEXTURE\n"
-			"EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;\n"
-		"#else \n"
-			"EMISSIVE_COLOR.rgb;\n"
-		"#endif // !AV_EMISSIVE_TEXTURE\n"
-		"}\n"
-
-		"#ifdef AV_OPACITY\n"
-		"OUT.a = TRANSPARENCY;\n"
-		"#endif\n"
-		"#ifdef AV_OPACITY_TEXTURE\n"
-		"OUT.a *= tex2D(OPACITY_SAMPLER,IN.TexCoord0). AV_OPACITY_TEXTURE_REGISTER_MASK;\n"
-		"#endif\n"
-		"return OUT;\n"
-	"}\n"
-
-	// Same pixel shader again, two lights
-	"float4 MaterialPShaderSpecular_PS20_D2(VS_OUTPUT IN) : COLOR\n"
-	"{\n"
-		"float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
-
-		"#ifdef AV_NORMAL_TEXTURE\n"
-		"float3 IN_Light0 = normalize(IN.Light0);\n"
-		"float3 IN_Light1 = normalize(IN.Light1);\n"
-		"float3 Normal  =  normalize(2.0f * tex2D(NORMAL_SAMPLER, IN.TexCoord0) - 1.0f);\n"
-		"#else\n"
-		"float3 Normal = normalize(IN.Normal);\n"
-		"#endif \n"
-		"float3 ViewDir = normalize(IN.ViewDir);\n"
-
-		"{\n"
-		"#ifdef AV_NORMAL_TEXTURE\n"
-		"float L1 = dot(Normal,IN_Light0) * 0.5f + 0.5f;\n"
-		"float3 Reflect = reflect (Normal,IN_Light0);\n"
-		"#else\n"
-		"float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;\n"
-		"float3 Reflect = reflect (Normal,afLightDir[0]);\n"
-		"#endif\n"
-		"#ifdef AV_DIFFUSE_TEXTURE\n"
-			"OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * L1 +\n"
-		"#else\n"
-			"OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * L1 +\n"
-		"#endif // !AV_DIFFUSE_TEXTURE\n"
-
-		"#ifdef AV_SPECULAR_COMPONENT\n"
-		"#ifdef AV_SPECULAR_TEXTURE\n"
-			"SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) + \n"
-		"#else\n"
-			"SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) + \n"
-		"#endif // !AV_SPECULAR_TEXTURE\n"
-		"#endif // !AV_SPECULAR_COMPONENT\n"
-		"#ifdef AV_AMBIENT_TEXTURE\n"
-			"AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb +\n"
-		"#else\n"
-			"AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb +\n"
-		"#endif // !AV_AMBIENT_TEXTURE\n"
-		"#ifdef AV_EMISSIVE_TEXTURE\n"
-			"EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;\n"
-		"#else \n"
-			"EMISSIVE_COLOR.rgb;\n"
-		"#endif // !AV_EMISSIVE_TEXTURE\n"
-		"}\n"
-		"{\n"
-		"#ifdef AV_NORMAL_TEXTURE\n"
-		"float L1 = dot(Normal,IN_Light1) * 0.5f + 0.5f;\n"
-		"float3 Reflect = reflect (Normal,IN_Light1);\n"
-		"#else\n"
-		"float L1 = dot(Normal,afLightDir[1]) * 0.5f + 0.5f;\n"
-		"float3 Reflect = reflect (Normal,afLightDir[1]);\n"
-		"#endif\n"
-		"#ifdef AV_DIFFUSE_TEXTURE\n"
-			"OUT.rgb += afLightColor[1].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * L1 +\n"
-		"#else\n"
-			"OUT.rgb += afLightColor[1].rgb * DIFFUSE_COLOR.rgb * L1 +\n"
-		"#endif // !AV_DIFFUSE_TEXTURE\n"
-
-		"#ifdef AV_SPECULAR_COMPONENT\n"
-		"#ifdef AV_SPECULAR_TEXTURE\n"
-			"SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[1].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) + \n"
-		"#else\n"
-			"SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[1].rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) + \n"
-		"#endif // !AV_SPECULAR_TEXTURE\n"
-		"#endif // !AV_SPECULAR_COMPONENT\n"
-		"#ifdef AV_AMBIENT_TEXTURE\n"
-			"AMBIENT_COLOR.rgb * afLightColorAmbient[1].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb +\n"
-		"#else\n"
-			"AMBIENT_COLOR.rgb * afLightColorAmbient[1].rgb + \n"
-		"#endif // !AV_AMBIENT_TEXTURE\n"
-		"#ifdef AV_EMISSIVE_TEXTURE\n"
-			"EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;\n"
-		"#else \n"
-			"EMISSIVE_COLOR.rgb;\n"
-		"#endif // !AV_EMISSIVE_TEXTURE\n"
-		"}\n"
-
-		"#ifdef AV_OPACITY\n"
-		"OUT.a = TRANSPARENCY;\n"
-		"#endif\n"
-		"#ifdef AV_OPACITY_TEXTURE\n"
-		"OUT.a *= tex2D(OPACITY_SAMPLER,IN.TexCoord0). AV_OPACITY_TEXTURE_REGISTER_MASK;\n"
-		"#endif\n"
-		"return OUT;\n"
-	"}\n"
-
-
-	// Technique for the material effect
-	"technique MaterialFXSpecular_D1\n"
-	"{\n"
-		"pass p0\n"
-		"{\n"
-			"#ifdef AV_OPACITY_TEXTURE\n"
-			"AlphaBlendEnable=TRUE;"
-			"SrcBlend = srcalpha;\n"
-			"DestBlend = invsrcalpha;\n"
-			"#else\n"
-			"#ifdef AV_OPACITY\n"
-			"AlphaBlendEnable=TRUE;"
-			"SrcBlend = srcalpha;\n"
-			"DestBlend = invsrcalpha;\n"
-			"#endif \n"
-			"#endif\n"
-
-			"PixelShader = compile ps_3_0 MaterialPShaderSpecular_D1();\n"
-			"VertexShader = compile vs_3_0 MaterialVShader_D1();\n"
-		"}\n"
-	"};\n"
-	"technique MaterialFXSpecular_D2\n"
-	"{\n"
-		"pass p0\n"
-		"{\n"
-			"#ifdef AV_OPACITY_TEXTURE\n"
-			"AlphaBlendEnable=TRUE;"
-			"SrcBlend = srcalpha;\n"
-			"DestBlend = invsrcalpha;\n"
-			"#else\n"
-			"#ifdef AV_OPACITY\n"
-			"AlphaBlendEnable=TRUE;"
-			"SrcBlend = srcalpha;\n"
-			"DestBlend = invsrcalpha;\n"
-			"#endif \n"
-			"#endif\n"
-
-			"PixelShader = compile ps_3_0 MaterialPShaderSpecular_D2();\n"
-			"VertexShader = compile vs_3_0 MaterialVShader_D2();\n"
-		"}\n"
-	"};\n"
-
-	// Technique for the material effect (ps_2_0)
-	"technique MaterialFXSpecular_PS20_D1\n"
-	"{\n"
-		"pass p0\n"
-  	"{\n"
-		  "#ifdef AV_OPACITY_TEXTURE\n"
-		  "AlphaBlendEnable=TRUE;"
-		  "SrcBlend = srcalpha;\n"
-		  "DestBlend = invsrcalpha;\n"
-		  "#else\n"
-		  "#ifdef AV_OPACITY\n"
-		  "AlphaBlendEnable=TRUE;"
-		  "SrcBlend = srcalpha;\n"
-		  "DestBlend = invsrcalpha;\n"
-		  "#endif \n"
-		  "#endif\n"
-
-		  "PixelShader = compile ps_2_0 MaterialPShaderSpecular_PS20_D1();\n"
-		  "VertexShader = compile vs_2_0 MaterialVShader_D1();\n"
-		"}\n"
-	"};\n"
-
-	"technique MaterialFXSpecular_PS20_D2\n"
-	"{\n"
-		"pass p0\n"
-	  "{\n"
-		  "//CullMode=none;\n"
-
-		  "#ifdef AV_OPACITY_TEXTURE\n"
-		  "AlphaBlendEnable=TRUE;"
-		  "SrcBlend = srcalpha;\n"
-		  "DestBlend = invsrcalpha;\n"
-		  "#else\n"
-		  "#ifdef AV_OPACITY\n"
-		  "AlphaBlendEnable=TRUE;"
-		  "SrcBlend = srcalpha;\n"
-		  "DestBlend = invsrcalpha;\n"
-		  "#endif \n"
-		  "#endif\n"
-
-		  "PixelShader = compile ps_2_0 MaterialPShaderSpecular_PS20_D2();\n"
-		  "VertexShader = compile vs_2_0 MaterialVShader_D2();\n"
-		"}\n"
-	"};\n"
-
-	// Technique for the material effect using fixed function pixel pipeline
-	"technique MaterialFX_FF\n"
-	"{\n"
-		"pass p0\n"
-		"{\n"
-			"//CullMode=none;\n"
-			"SpecularEnable = true; \n"
-			"VertexShader = compile vs_2_0 MaterialVShader_FF();\n"
-			"ColorOp[0] = Modulate;\n"
-			"ColorArg0[0] = Texture;\n"
-			"ColorArg1[0] = Diffuse;\n"
-			"AlphaOp[0] = Modulate;\n"
-			"AlphaArg0[0] = Texture;\n"
-			"AlphaArg1[0] = Diffuse;\n"
-		"}\n"
-	"};\n"
-	);
+    "float4x4 WorldViewProjection	: WORLDVIEWPROJECTION;\n"
+    "float4x4 World					: WORLD;\n"
+    "float4x3 WorldInverseTranspose	: WORLDINVERSETRANSPOSE;\n"
+
+    "#ifndef AV_DISABLESSS\n"
+    "float4x3 ViewProj;\n"
+    "float4x3 InvViewProj;\n"
+    "#endif\n"
+
+    "float4 DIFFUSE_COLOR;\n"
+    "float4 SPECULAR_COLOR;\n"
+    "float4 AMBIENT_COLOR;\n"
+    "float4 EMISSIVE_COLOR;\n"
+
+    "#ifdef AV_SPECULAR_COMPONENT\n"
+    "float SPECULARITY;\n"
+    "float SPECULAR_STRENGTH;\n"
+    "#endif\n"
+    "#ifdef AV_OPACITY\n"
+    "float TRANSPARENCY;\n"
+    "#endif\n"
+
+    // light colors (diffuse and specular)
+    "float4 afLightColor[5];\n"
+    "float4 afLightColorAmbient[5];\n"
+
+    // light direction
+    "float3 afLightDir[5];\n"
+
+    // position of the camera in worldspace
+    "float3 vCameraPos : CAMERAPOSITION;\n"
+
+    // Bone matrices
+    "#ifdef AV_SKINNING \n"
+    "float4x3 gBoneMatrix[60]; \n"
+    "#endif // AV_SKINNING \n"
+
+    "#ifdef AV_DIFFUSE_TEXTURE\n"
+        "texture DIFFUSE_TEXTURE;\n"
+        "sampler DIFFUSE_SAMPLER\n"
+        "{\n"
+          "Texture = <DIFFUSE_TEXTURE>;\n"
+          "#ifdef AV_WRAPU\n"
+          "AddressU = WRAP;\n"
+          "#endif\n"
+          "#ifdef AV_MIRRORU\n"
+          "AddressU = MIRROR;\n"
+          "#endif\n"
+          "#ifdef AV_CLAMPU\n"
+          "AddressU = CLAMP;\n"
+          "#endif\n"
+          "#ifdef AV_WRAPV\n"
+          "AddressV = WRAP;\n"
+          "#endif\n"
+          "#ifdef AV_MIRRORV\n"
+          "AddressV = MIRROR;\n"
+          "#endif\n"
+          "#ifdef AV_CLAMPV\n"
+          "AddressV = CLAMP;\n"
+          "#endif\n"
+        "};\n"
+    "#endif // AV_DIFFUSE_TEXTUR\n"
+
+    "#ifdef AV_DIFFUSE_TEXTURE2\n"
+        "texture DIFFUSE_TEXTURE2;\n"
+        "sampler DIFFUSE_SAMPLER2\n"
+        "{\n"
+          "Texture = <DIFFUSE_TEXTURE2>;\n"
+        "};\n"
+    "#endif // AV_DIFFUSE_TEXTUR2\n"
+
+    "#ifdef AV_SPECULAR_TEXTURE\n"
+        "texture SPECULAR_TEXTURE;\n"
+        "sampler SPECULAR_SAMPLER\n"
+        "{\n"
+          "Texture = <SPECULAR_TEXTURE>;\n"
+        "};\n"
+    "#endif // AV_SPECULAR_TEXTUR\n"
+
+    "#ifdef AV_AMBIENT_TEXTURE\n"
+        "texture AMBIENT_TEXTURE;\n"
+        "sampler AMBIENT_SAMPLER\n"
+        "{\n"
+          "Texture = <AMBIENT_TEXTURE>;\n"
+        "};\n"
+    "#endif // AV_AMBIENT_TEXTUR\n"
+
+    "#ifdef AV_LIGHTMAP_TEXTURE\n"
+        "texture LIGHTMAP_TEXTURE;\n"
+        "sampler LIGHTMAP_SAMPLER\n"
+        "{\n"
+          "Texture = <LIGHTMAP_TEXTURE>;\n"
+        "};\n"
+    "#endif // AV_LIGHTMAP_TEXTURE\n"
+
+    "#ifdef AV_OPACITY_TEXTURE\n"
+        "texture OPACITY_TEXTURE;\n"
+        "sampler OPACITY_SAMPLER\n"
+        "{\n"
+          "Texture = <OPACITY_TEXTURE>;\n"
+        "};\n"
+    "#endif // AV_OPACITY_TEXTURE\n"
+
+    "#ifdef AV_EMISSIVE_TEXTURE\n"
+        "texture EMISSIVE_TEXTURE;\n"
+        "sampler EMISSIVE_SAMPLER\n"
+        "{\n"
+          "Texture = <EMISSIVE_TEXTURE>;\n"
+        "};\n"
+    "#endif // AV_EMISSIVE_TEXTUR\n"
+
+    "#ifdef AV_NORMAL_TEXTURE\n"
+        "texture NORMAL_TEXTURE;\n"
+        "sampler NORMAL_SAMPLER\n"
+        "{\n"
+          "Texture = <NORMAL_TEXTURE>;\n"
+        "};\n"
+    "#endif // AV_NORMAL_TEXTURE\n"
+
+    "#ifdef AV_SKYBOX_LOOKUP\n"
+        "textureCUBE lw_tex_envmap;\n"
+        "samplerCUBE EnvironmentMapSampler = sampler_state\n"
+        "{\n"
+          "Texture = (lw_tex_envmap);\n"
+          "AddressU = CLAMP;\n"
+          "AddressV = CLAMP;\n"
+          "AddressW = CLAMP;\n"
+
+          "MAGFILTER = linear;\n"
+          "MINFILTER = linear;\n"
+        "};\n"
+    "#endif // AV_SKYBOX_LOOKUP\n"
+
+    // Vertex shader input structure
+    "struct VS_INPUT\n"
+    "{\n"
+        "float3 Position : POSITION;\n"
+        "float3 Normal : NORMAL;\n"
+        "float4 Color : COLOR0;\n"
+        "float3 Tangent   : TANGENT;\n"
+        "float3 Bitangent : BINORMAL;\n"
+        "float2 TexCoord0 : TEXCOORD0;\n"
+        "#ifdef AV_TWO_UV \n"
+        "float2 TexCoord1 : TEXCOORD1;\n"
+        "#endif \n"
+          "#ifdef AV_SKINNING \n"
+            "float4 BlendIndices : BLENDINDICES;\n"
+            "float4 BlendWeights : BLENDWEIGHT;\n"
+         "#endif // AV_SKINNING \n"
+    "};\n"
+
+    // Vertex shader output structure for pixel shader usage
+    "struct VS_OUTPUT\n"
+    "{\n"
+        "float4 Position : POSITION;\n"
+        "float3 ViewDir : TEXCOORD0;\n"
+
+        "float4 Color : COLOR0;\n"
+
+        "#ifndef AV_NORMAL_TEXTURE\n"
+        "float3 Normal  : TEXCOORD1;\n"
+        "#endif\n"
+
+        "float2 TexCoord0 : TEXCOORD2;\n"
+        "#ifdef AV_TWO_UV \n"
+        "float2 TexCoord1 : TEXCOORD3;\n"
+        "#endif \n"
+
+        "#ifdef AV_NORMAL_TEXTURE\n"
+        "float3 Light0 : TEXCOORD3;\n"
+        "float3 Light1 : TEXCOORD4;\n"
+        "#endif\n"
+    "};\n"
+
+    // Vertex shader output structure for fixed function pixel pipeline
+    "struct VS_OUTPUT_FF\n"
+    "{\n"
+        "float4 Position : POSITION;\n"
+        "float4 DiffuseColor : COLOR0;\n"
+        "float4 SpecularColor : COLOR1;\n"
+        "float2 TexCoord0 : TEXCOORD0;\n"
+    "};\n"
+
+
+    // Selective SuperSampling in screenspace for reflection lookups
+    "#define GetSSSCubeMap(_refl) (texCUBElod(EnvironmentMapSampler,float4(_refl,0.0f)).rgb) \n"
+
+
+    // Vertex shader for pixel shader usage and one light
+    "VS_OUTPUT MaterialVShader_D1(VS_INPUT IN)\n"
+    "{\n"
+        "VS_OUTPUT Out = (VS_OUTPUT)0;\n"
+
+        "#ifdef AV_SKINNING \n"
+        "float4 weights = IN.BlendWeights; \n"
+        "weights.w = 1.0f - dot( weights.xyz, float3( 1, 1, 1)); \n"
+        "float4 localPos = float4( IN.Position, 1.0f); \n"
+        "float3 objPos = mul( localPos, gBoneMatrix[IN.BlendIndices.x]) * weights.x; \n"
+        "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.y]) * weights.y; \n"
+        "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.z]) * weights.z; \n"
+        "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.w]) * weights.w; \n"
+        "#else \n"
+        "float3 objPos = IN.Position; \n"
+        "#endif // AV_SKINNING \n"
+
+        // Multiply with the WorldViewProjection matrix
+        "Out.Position = mul( float4( objPos, 1.0f), WorldViewProjection);\n"
+        "float3 WorldPos = mul( float4( objPos, 1.0f), World);\n"
+        "Out.TexCoord0 = IN.TexCoord0;\n"
+        "#ifdef AV_TWO_UV \n"
+        "Out.TexCoord1 = IN.TexCoord1;\n"
+        "#endif\n"
+        "Out.Color = IN.Color;\n"
+
+        "#ifndef AV_NORMAL_TEXTURE\n"
+        "Out.ViewDir = vCameraPos - WorldPos;\n"
+        "Out.Normal = mul(IN.Normal,WorldInverseTranspose);\n"
+        "#endif\n"
+        
+        "#ifdef AV_NORMAL_TEXTURE\n"
+        "float3x3 TBNMatrix = float3x3(IN.Tangent, IN.Bitangent, IN.Normal);\n"
+        "float3x3 WTTS      = mul(TBNMatrix, (float3x3)WorldInverseTranspose);\n"
+        "Out.Light0         = normalize(mul(WTTS, afLightDir[0] ));\n"
+        "Out.ViewDir = normalize(mul(WTTS, (vCameraPos - WorldPos)));\n"
+        "#endif\n"
+        "return Out;\n"
+    "}\n"
+
+    // Vertex shader for pixel shader usage and two lights
+    "VS_OUTPUT MaterialVShader_D2(VS_INPUT IN)\n"
+    "{\n"
+        "VS_OUTPUT Out = (VS_OUTPUT)0;\n"
+
+        "#ifdef AV_SKINNING \n"
+        "float4 weights = IN.BlendWeights; \n"
+        "weights.w = 1.0f - dot( weights.xyz, float3( 1, 1, 1)); \n"
+        "float4 localPos = float4( IN.Position, 1.0f); \n"
+        "float3 objPos = mul( localPos, gBoneMatrix[IN.BlendIndices.x]) * weights.x; \n"
+        "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.y]) * weights.y; \n"
+        "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.z]) * weights.z; \n"
+        "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.w]) * weights.w; \n"
+        "#else \n"
+        "float3 objPos = IN.Position; \n"
+        "#endif // AV_SKINNING \n"
+
+        // Multiply with the WorldViewProjection matrix
+        "Out.Position = mul( float4( objPos, 1.0f), WorldViewProjection);\n"
+        "float3 WorldPos = mul( float4( objPos, 1.0f), World);\n"
+        "Out.TexCoord0 = IN.TexCoord0;\n"
+        "#ifdef AV_TWO_UV \n"
+        "Out.TexCoord1 = IN.TexCoord1;\n"
+        "#endif\n"
+        "Out.Color = IN.Color;\n"
+
+        "#ifndef AV_NORMAL_TEXTURE\n"
+        "Out.ViewDir = vCameraPos - WorldPos;\n"
+        "Out.Normal = mul(IN.Normal,WorldInverseTranspose);\n"
+        "#endif\n"
+
+        "#ifdef AV_NORMAL_TEXTURE\n"
+        "float3x3 TBNMatrix = float3x3(IN.Tangent, IN.Bitangent, IN.Normal);\n"
+        "float3x3 WTTS      = mul(TBNMatrix, (float3x3)WorldInverseTranspose);\n"
+        "Out.Light0         = normalize(mul(WTTS, afLightDir[0] ));\n"
+        "Out.Light1         = normalize(mul(WTTS, afLightDir[1] ));\n"
+        "Out.ViewDir = normalize(mul(WTTS, (vCameraPos - WorldPos)));\n"
+        "#endif\n"
+        "return Out;\n"
+    "}\n"
+
+    // Vertex shader for zero to five lights using the fixed function pixel pipeline
+    "VS_OUTPUT_FF MaterialVShader_FF(VS_INPUT IN)\n"
+    "{\n"
+        "VS_OUTPUT_FF Out = (VS_OUTPUT_FF)0;\n"
+
+        "#ifdef AV_SKINNING \n"
+        "float4 weights = IN.BlendWeights; \n"
+        "weights.w = 1.0f - dot( weights.xyz, float3( 1, 1, 1)); \n"
+        "float4 localPos = float4( IN.Position, 1.0f); \n"
+        "float3 objPos = mul( localPos, gBoneMatrix[IN.BlendIndices.x]) * weights.x; \n"
+        "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.y]) * weights.y; \n"
+        "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.z]) * weights.z; \n"
+        "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.w]) * weights.w; \n"
+        "#else \n"
+        "float3 objPos = IN.Position; \n"
+        "#endif // AV_SKINNING \n"
+
+        // Multiply with the WorldViewProjection matrix
+        "Out.Position = mul( float4( objPos, 1.0f), WorldViewProjection);\n"
+        "float3 worldPos = mul( float4( objPos, 1.0f), World);\n"
+        "float3 worldNormal = normalize( mul( IN.Normal, (float3x3) WorldInverseTranspose)); \n"
+        "Out.TexCoord0 = IN.TexCoord0;\n"
+
+        // calculate per-vertex diffuse lighting including ambient part
+        "float4 diffuseColor = float4( 0.0f, 0.0f, 0.0f, 1.0f); \n"
+        "for( int a = 0; a < 2; a++) \n"
+        "  diffuseColor.rgb += saturate( dot( afLightDir[a], worldNormal)) * afLightColor[a].rgb; \n"
+        // factor in material properties and a bit of ambient lighting
+        "Out.DiffuseColor = diffuseColor * DIFFUSE_COLOR + float4( 0.2f, 0.2f, 0.2f, 1.0f) * AMBIENT_COLOR; ; \n"
+
+        // and specular including emissive part
+        "float4 specularColor = float4( 0.0f, 0.0f, 0.0f, 1.0f); \n"
+        "#ifdef AV_SPECULAR_COMPONENT\n"
+        "float3 viewDir = normalize( worldPos - vCameraPos); \n"
+        "for( int a = 0; a < 2; a++) \n"
+        "{ \n"
+        "  float3 reflDir = reflect( afLightDir[a], worldNormal); \n"
+        "  float specIntensity = pow( saturate( dot( reflDir, viewDir)), SPECULARITY) * SPECULAR_STRENGTH; \n"
+        "  specularColor.rgb += afLightColor[a] * specIntensity; \n"
+        "} \n"
+        "#endif // AV_SPECULAR_COMPONENT\n"
+        // factor in material properties and the emissive part
+        "Out.SpecularColor = specularColor * SPECULAR_COLOR + EMISSIVE_COLOR; \n"
+
+        "return Out;\n"
+    "}\n"
+
+
+    // Pixel shader - one light
+    "float4 MaterialPShaderSpecular_D1(VS_OUTPUT IN) : COLOR\n"
+    "{\n"
+        "float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
+
+        "#ifdef AV_NORMAL_TEXTURE\n"
+        "float3 IN_Light0 = normalize(IN.Light0);\n"
+        "float3 Normal  =  normalize(2.0f * tex2D(NORMAL_SAMPLER, IN.TexCoord0).rgb - 1.0f);\n"
+        "#else\n"
+        "float3 Normal = normalize(IN.Normal);\n"
+        "#endif \n"
+        "float3 ViewDir = normalize(IN.ViewDir);\n"
+        "#ifdef AV_SPECULAR_COMPONENT\n"
+            "float3 Reflect = normalize(reflect (-ViewDir,Normal));\n"
+        "#endif // !AV_SPECULAR_COMPONENT\n"
+
+        "{\n"
+        "#ifdef AV_NORMAL_TEXTURE\n"
+            "float L1 =  dot(Normal,IN_Light0) * 0.5f + 0.5f;\n"
+            "#define AV_LIGHT_0 IN_Light0\n"
+            // would need to convert the reflection vector into world space ....
+            // simply let it ...
+        "#else\n"
+            "float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;\n"
+            "#define AV_LIGHT_0 afLightDir[0]\n"
+        "#endif\n"
+        "#ifdef AV_DIFFUSE_TEXTURE2\n"
+            "float fHalfLambert = 1.f;\n"
+        "#else\n"
+            "float fHalfLambert = L1*L1;\n"
+        "#endif \n"
+        "#ifdef AV_DIFFUSE_TEXTURE\n"
+            "OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * fHalfLambert * IN.Color.rgb +\n"
+        "#else\n"
+            "OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * fHalfLambert * IN.Color.rgb +\n"
+        "#endif // !AV_DIFFUSE_TEXTURE\n"
+
+        
+        "#ifdef AV_SPECULAR_COMPONENT\n"
+            "#ifndef AV_SKYBOX_LOOKUP\n"
+                "#ifdef AV_SPECULAR_TEXTURE\n"
+                    "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
+                "#else\n"
+                    "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
+                "#endif // !AV_SPECULAR_TEXTURE\n"
+            "#else\n"
+                "#ifdef AV_SPECULAR_TEXTURE\n"
+                    "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * GetSSSCubeMap(Reflect) * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
+                "#else\n"
+                    "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * GetSSSCubeMap(Reflect) * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
+                "#endif // !AV_SPECULAR_TEXTURE\n"
+            "#endif // !AV_SKYBOX_LOOKUP\n"
+        "#endif // !AV_SPECULAR_COMPONENT\n"
+
+        "#ifdef AV_AMBIENT_TEXTURE\n"
+            "AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb +\n"
+        "#else\n"
+            "AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb + \n"
+        "#endif // !AV_AMBIENT_TEXTURE\n"
+            "#ifdef AV_EMISSIVE_TEXTURE\n"
+            "EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;\n"
+        "#else \n"
+            "EMISSIVE_COLOR.rgb;\n"
+        "#endif // !AV_EMISSIVE_TEXTURE\n"
+        "}\n"
+        "#ifdef AV_OPACITY\n"
+        "OUT.a = TRANSPARENCY;\n"
+        "#endif\n"
+        "#ifdef AV_LIGHTMAP_TEXTURE\n"
+        "OUT.rgb *= tex2D(LIGHTMAP_SAMPLER,AV_LIGHTMAP_TEXTURE_UV_COORD).rgb*LM_STRENGTH;\n"
+        "#endif\n"
+        "#ifdef AV_OPACITY_TEXTURE\n"
+        "OUT.a *= tex2D(OPACITY_SAMPLER,IN.TexCoord0). AV_OPACITY_TEXTURE_REGISTER_MASK;\n"
+        "#endif\n"
+        "return OUT;\n"
+
+        "#undef AV_LIGHT_0\n"
+    "}\n"
+
+    // Pixel shader - two lights
+    "float4 MaterialPShaderSpecular_D2(VS_OUTPUT IN) : COLOR\n"
+    "{\n"
+        "float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
+
+        "#ifdef AV_NORMAL_TEXTURE\n"
+        "float3 IN_Light0 = normalize(IN.Light0);\n"
+        "float3 IN_Light1 = normalize(IN.Light1);\n"
+        "float3 Normal  =  normalize(2.0f * tex2D(NORMAL_SAMPLER, IN.TexCoord0).rgb - 1.0f);\n"
+        "#else\n"
+        "float3 Normal = normalize(IN.Normal);\n"
+        "#endif \n"
+        "float3 ViewDir = normalize(IN.ViewDir);\n"
+        "#ifdef AV_SPECULAR_COMPONENT\n"
+            "float3 Reflect = -normalize(reflect (ViewDir,Normal));\n"
+        "#endif // !AV_SPECULAR_COMPONENT\n"
+
+        "{\n"
+        
+        "#ifdef AV_NORMAL_TEXTURE\n"
+            "float L1 = dot(Normal,IN_Light0) * 0.5f + 0.5f;\n"
+            "#define AV_LIGHT_0 IN_Light0\n"
+        "#else\n"
+            "float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;\n"
+            "#define AV_LIGHT_0 afLightDir[0]\n"
+        "#endif\n"
+            "float fHalfLambert = L1*L1;\n"
+            
+        "#ifdef AV_DIFFUSE_TEXTURE\n"
+            "OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * fHalfLambert  * IN.Color.rgb +\n"
+        "#else\n"
+            "OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * fHalfLambert  * IN.Color.rgb +\n"
+        "#endif // !AV_DIFFUSE_TEXTURE\n"
+
+        "#ifdef AV_SPECULAR_COMPONENT\n"
+            "#ifndef AV_SKYBOX_LOOKUP\n"
+                "#ifdef AV_SPECULAR_TEXTURE\n"
+                    "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
+                "#else\n"
+                    "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
+                "#endif // !AV_SPECULAR_TEXTURE\n"
+            "#else\n"
+                "#ifdef AV_SPECULAR_TEXTURE\n"
+                    "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * GetSSSCubeMap(Reflect) * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
+                "#else\n"
+                    "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * GetSSSCubeMap(Reflect) * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
+                "#endif // !AV_SPECULAR_TEXTURE\n"
+            "#endif // !AV_SKYBOX_LOOKUP\n"
+        "#endif // !AV_SPECULAR_COMPONENT\n"
+        "#ifdef AV_AMBIENT_TEXTURE\n"
+            "AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb + \n"
+        "#else\n"
+            "AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb + \n"
+        "#endif // !AV_AMBIENT_TEXTURE\n"
+        "#ifdef AV_EMISSIVE_TEXTURE\n"
+            "EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;\n"
+        "#else \n"
+            "EMISSIVE_COLOR.rgb;\n"
+        "#endif // !AV_EMISSIVE_TEXTURE\n"
+        "}\n"
+        "{\n"
+        "#ifdef AV_NORMAL_TEXTURE\n"
+            "float L1 = dot(Normal,IN_Light1) * 0.5f + 0.5f;\n"
+            "#define AV_LIGHT_1 IN_Light1\n"
+        "#else\n"
+            "float L1 = dot(Normal,afLightDir[1]) * 0.5f + 0.5f;\n"
+            "#define AV_LIGHT_1 afLightDir[1]\n"
+        "#endif\n"
+            "float fHalfLambert = L1*L1;\n"
+        "#ifdef AV_DIFFUSE_TEXTURE\n"
+            "OUT.rgb += afLightColor[1].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * fHalfLambert  * IN.Color.rgb +\n"
+        "#else\n"
+            "OUT.rgb += afLightColor[1].rgb * DIFFUSE_COLOR.rgb * fHalfLambert   * IN.Color.rgb +\n"
+        "#endif // !AV_DIFFUSE_TEXTURE\n"
+
+        "#ifdef AV_SPECULAR_COMPONENT\n"
+            "#ifndef AV_SKYBOX_LOOKUP\n"
+                "#ifdef AV_SPECULAR_TEXTURE\n"
+                    "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[1].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_1),SPECULARITY)) + \n"
+                "#else\n"
+                    "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[1].rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_1),SPECULARITY)) + \n"
+                "#endif // !AV_SPECULAR_TEXTURE\n"
+            "#else\n"
+                "#ifdef AV_SPECULAR_TEXTURE\n"
+                    "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[1].rgb * GetSSSCubeMap(Reflect) * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_1),SPECULARITY)) + \n"
+                "#else\n"
+                    "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[1].rgb * GetSSSCubeMap(Reflect) * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_1),SPECULARITY)) + \n"
+                "#endif // !AV_SPECULAR_TEXTURE\n"
+            "#endif // !AV_SKYBOX_LOOKUP\n"
+        "#endif // !AV_SPECULAR_COMPONENT\n"
+        "#ifdef AV_AMBIENT_TEXTURE\n"
+            "AMBIENT_COLOR.rgb * afLightColorAmbient[1].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb + \n"
+        "#else\n"
+            "AMBIENT_COLOR.rgb * afLightColorAmbient[1].rgb + \n"
+        "#endif // !AV_AMBIENT_TEXTURE\n"
+        "#ifdef AV_EMISSIVE_TEXTURE\n"
+            "EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;\n"
+        "#else \n"
+            "EMISSIVE_COLOR.rgb;\n"
+        "#endif // !AV_EMISSIVE_TEXTURE\n"
+        "}\n"
+        "#ifdef AV_OPACITY\n"
+        "OUT.a = TRANSPARENCY;\n"
+        "#endif\n"
+        "#ifdef AV_LIGHTMAP_TEXTURE\n"
+        "OUT.rgb *= tex2D(LIGHTMAP_SAMPLER,AV_LIGHTMAP_TEXTURE_UV_COORD).rgb*LM_STRENGTH;\n"
+        "#endif\n"
+        "#ifdef AV_OPACITY_TEXTURE\n"
+        "OUT.a *= tex2D(OPACITY_SAMPLER,IN.TexCoord0). AV_OPACITY_TEXTURE_REGISTER_MASK;\n"
+        "#endif\n"
+        "return OUT;\n"
+
+        "#undef AV_LIGHT_0\n"
+        "#undef AV_LIGHT_1\n"
+    "}\n"
+
+    // Same pixel shader again, one light
+    "float4 MaterialPShaderSpecular_PS20_D1(VS_OUTPUT IN) : COLOR\n"
+    "{\n"
+        "float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
+
+        "#ifdef AV_NORMAL_TEXTURE\n"
+        "float3 IN_Light0 = normalize(IN.Light0);\n"
+        "float3 Normal  =  normalize(2.0f * tex2D(NORMAL_SAMPLER, IN.TexCoord0).rgb - 1.0f);\n"
+        "#else\n"
+        "float3 Normal = normalize(IN.Normal);\n"
+        "#endif \n"
+        "float3 ViewDir = normalize(IN.ViewDir);\n"
+
+        "{\n"
+        "#ifdef AV_NORMAL_TEXTURE\n"
+        "float L1 = dot(Normal,IN_Light0) * 0.5f + 0.5f;\n"
+        "float3 Reflect = reflect (Normal,IN_Light0);\n"
+        "#else\n"
+        "float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;\n"
+        "float3 Reflect = reflect (Normal,afLightDir[0]);\n"
+        "#endif\n"
+        "#ifdef AV_DIFFUSE_TEXTURE\n"
+            "OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * L1 +\n"
+        "#else\n"
+            "OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * L1 +\n"
+        "#endif // !AV_DIFFUSE_TEXTURE\n"
+
+        "#ifdef AV_SPECULAR_COMPONENT\n"
+        "#ifdef AV_SPECULAR_TEXTURE\n"
+            "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) + \n"
+        "#else\n"
+            "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) + \n"
+        "#endif // !AV_SPECULAR_TEXTURE\n"
+        "#endif // !AV_SPECULAR_COMPONENT\n"
+        "#ifdef AV_AMBIENT_TEXTURE\n"
+            "AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb +\n"
+        "#else\n"
+            "AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb +\n"
+        "#endif // !AV_AMBIENT_TEXTURE\n"
+        "#ifdef AV_EMISSIVE_TEXTURE\n"
+            "EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;\n"
+        "#else \n"
+            "EMISSIVE_COLOR.rgb;\n"
+        "#endif // !AV_EMISSIVE_TEXTURE\n"
+        "}\n"
+
+        "#ifdef AV_OPACITY\n"
+        "OUT.a = TRANSPARENCY;\n"
+        "#endif\n"
+        "#ifdef AV_OPACITY_TEXTURE\n"
+        "OUT.a *= tex2D(OPACITY_SAMPLER,IN.TexCoord0). AV_OPACITY_TEXTURE_REGISTER_MASK;\n"
+        "#endif\n"
+        "return OUT;\n"
+    "}\n"
+
+    // Same pixel shader again, two lights
+    "float4 MaterialPShaderSpecular_PS20_D2(VS_OUTPUT IN) : COLOR\n"
+    "{\n"
+        "float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
+
+        "#ifdef AV_NORMAL_TEXTURE\n"
+        "float3 IN_Light0 = normalize(IN.Light0);\n"
+        "float3 IN_Light1 = normalize(IN.Light1);\n"
+        "float3 Normal  =  normalize(2.0f * tex2D(NORMAL_SAMPLER, IN.TexCoord0) - 1.0f);\n"
+        "#else\n"
+        "float3 Normal = normalize(IN.Normal);\n"
+        "#endif \n"
+        "float3 ViewDir = normalize(IN.ViewDir);\n"
+
+        "{\n"
+        "#ifdef AV_NORMAL_TEXTURE\n"
+        "float L1 = dot(Normal,IN_Light0) * 0.5f + 0.5f;\n"
+        "float3 Reflect = reflect (Normal,IN_Light0);\n"
+        "#else\n"
+        "float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;\n"
+        "float3 Reflect = reflect (Normal,afLightDir[0]);\n"
+        "#endif\n"
+        "#ifdef AV_DIFFUSE_TEXTURE\n"
+            "OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * L1 +\n"
+        "#else\n"
+            "OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * L1 +\n"
+        "#endif // !AV_DIFFUSE_TEXTURE\n"
+
+        "#ifdef AV_SPECULAR_COMPONENT\n"
+        "#ifdef AV_SPECULAR_TEXTURE\n"
+            "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) + \n"
+        "#else\n"
+            "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) + \n"
+        "#endif // !AV_SPECULAR_TEXTURE\n"
+        "#endif // !AV_SPECULAR_COMPONENT\n"
+        "#ifdef AV_AMBIENT_TEXTURE\n"
+            "AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb +\n"
+        "#else\n"
+            "AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb +\n"
+        "#endif // !AV_AMBIENT_TEXTURE\n"
+        "#ifdef AV_EMISSIVE_TEXTURE\n"
+            "EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;\n"
+        "#else \n"
+            "EMISSIVE_COLOR.rgb;\n"
+        "#endif // !AV_EMISSIVE_TEXTURE\n"
+        "}\n"
+        "{\n"
+        "#ifdef AV_NORMAL_TEXTURE\n"
+        "float L1 = dot(Normal,IN_Light1) * 0.5f + 0.5f;\n"
+        "float3 Reflect = reflect (Normal,IN_Light1);\n"
+        "#else\n"
+        "float L1 = dot(Normal,afLightDir[1]) * 0.5f + 0.5f;\n"
+        "float3 Reflect = reflect (Normal,afLightDir[1]);\n"
+        "#endif\n"
+        "#ifdef AV_DIFFUSE_TEXTURE\n"
+            "OUT.rgb += afLightColor[1].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * L1 +\n"
+        "#else\n"
+            "OUT.rgb += afLightColor[1].rgb * DIFFUSE_COLOR.rgb * L1 +\n"
+        "#endif // !AV_DIFFUSE_TEXTURE\n"
+
+        "#ifdef AV_SPECULAR_COMPONENT\n"
+        "#ifdef AV_SPECULAR_TEXTURE\n"
+            "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[1].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) + \n"
+        "#else\n"
+            "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[1].rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) + \n"
+        "#endif // !AV_SPECULAR_TEXTURE\n"
+        "#endif // !AV_SPECULAR_COMPONENT\n"
+        "#ifdef AV_AMBIENT_TEXTURE\n"
+            "AMBIENT_COLOR.rgb * afLightColorAmbient[1].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb +\n"
+        "#else\n"
+            "AMBIENT_COLOR.rgb * afLightColorAmbient[1].rgb + \n"
+        "#endif // !AV_AMBIENT_TEXTURE\n"
+        "#ifdef AV_EMISSIVE_TEXTURE\n"
+            "EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;\n"
+        "#else \n"
+            "EMISSIVE_COLOR.rgb;\n"
+        "#endif // !AV_EMISSIVE_TEXTURE\n"
+        "}\n"
+
+        "#ifdef AV_OPACITY\n"
+        "OUT.a = TRANSPARENCY;\n"
+        "#endif\n"
+        "#ifdef AV_OPACITY_TEXTURE\n"
+        "OUT.a *= tex2D(OPACITY_SAMPLER,IN.TexCoord0). AV_OPACITY_TEXTURE_REGISTER_MASK;\n"
+        "#endif\n"
+        "return OUT;\n"
+    "}\n"
+
+
+    // Technique for the material effect
+    "technique MaterialFXSpecular_D1\n"
+    "{\n"
+        "pass p0\n"
+        "{\n"
+            "#ifdef AV_OPACITY_TEXTURE\n"
+            "AlphaBlendEnable=TRUE;"
+            "SrcBlend = srcalpha;\n"
+            "DestBlend = invsrcalpha;\n"
+            "#else\n"
+            "#ifdef AV_OPACITY\n"
+            "AlphaBlendEnable=TRUE;"
+            "SrcBlend = srcalpha;\n"
+            "DestBlend = invsrcalpha;\n"
+            "#endif \n"
+            "#endif\n"
+
+            "PixelShader = compile ps_3_0 MaterialPShaderSpecular_D1();\n"
+            "VertexShader = compile vs_3_0 MaterialVShader_D1();\n"
+        "}\n"
+    "};\n"
+    "technique MaterialFXSpecular_D2\n"
+    "{\n"
+        "pass p0\n"
+        "{\n"
+            "#ifdef AV_OPACITY_TEXTURE\n"
+            "AlphaBlendEnable=TRUE;"
+            "SrcBlend = srcalpha;\n"
+            "DestBlend = invsrcalpha;\n"
+            "#else\n"
+            "#ifdef AV_OPACITY\n"
+            "AlphaBlendEnable=TRUE;"
+            "SrcBlend = srcalpha;\n"
+            "DestBlend = invsrcalpha;\n"
+            "#endif \n"
+            "#endif\n"
+
+            "PixelShader = compile ps_3_0 MaterialPShaderSpecular_D2();\n"
+            "VertexShader = compile vs_3_0 MaterialVShader_D2();\n"
+        "}\n"
+    "};\n"
+
+    // Technique for the material effect (ps_2_0)
+    "technique MaterialFXSpecular_PS20_D1\n"
+    "{\n"
+        "pass p0\n"
+    "{\n"
+          "#ifdef AV_OPACITY_TEXTURE\n"
+          "AlphaBlendEnable=TRUE;"
+          "SrcBlend = srcalpha;\n"
+          "DestBlend = invsrcalpha;\n"
+          "#else\n"
+          "#ifdef AV_OPACITY\n"
+          "AlphaBlendEnable=TRUE;"
+          "SrcBlend = srcalpha;\n"
+          "DestBlend = invsrcalpha;\n"
+          "#endif \n"
+          "#endif\n"
+
+          "PixelShader = compile ps_2_0 MaterialPShaderSpecular_PS20_D1();\n"
+          "VertexShader = compile vs_2_0 MaterialVShader_D1();\n"
+        "}\n"
+    "};\n"
+
+    "technique MaterialFXSpecular_PS20_D2\n"
+    "{\n"
+        "pass p0\n"
+      "{\n"
+          "//CullMode=none;\n"
+
+          "#ifdef AV_OPACITY_TEXTURE\n"
+          "AlphaBlendEnable=TRUE;"
+          "SrcBlend = srcalpha;\n"
+          "DestBlend = invsrcalpha;\n"
+          "#else\n"
+          "#ifdef AV_OPACITY\n"
+          "AlphaBlendEnable=TRUE;"
+          "SrcBlend = srcalpha;\n"
+          "DestBlend = invsrcalpha;\n"
+          "#endif \n"
+          "#endif\n"
+
+          "PixelShader = compile ps_2_0 MaterialPShaderSpecular_PS20_D2();\n"
+          "VertexShader = compile vs_2_0 MaterialVShader_D2();\n"
+        "}\n"
+    "};\n"
+
+    // Technique for the material effect using fixed function pixel pipeline
+    "technique MaterialFX_FF\n"
+    "{\n"
+        "pass p0\n"
+        "{\n"
+            "//CullMode=none;\n"
+            "SpecularEnable = true; \n"
+            "VertexShader = compile vs_2_0 MaterialVShader_FF();\n"
+            "ColorOp[0] = Modulate;\n"
+            "ColorArg0[0] = Texture;\n"
+            "ColorArg1[0] = Diffuse;\n"
+            "AlphaOp[0] = Modulate;\n"
+            "AlphaArg0[0] = Texture;\n"
+            "AlphaArg1[0] = Diffuse;\n"
+        "}\n"
+    "};\n"
+    );
 
 
 std::string g_szPassThroughShader = std::string(
 std::string g_szPassThroughShader = std::string(
-		"texture TEXTURE_2D;\n"
-		"sampler TEXTURE_SAMPLER = sampler_state\n"
-		"{\n"
-			"Texture = (TEXTURE_2D);\n"
-			"MinFilter = POINT;\n"
-			"MagFilter = POINT;\n"
-		"};\n"
+        "texture TEXTURE_2D;\n"
+        "sampler TEXTURE_SAMPLER = sampler_state\n"
+        "{\n"
+            "Texture = (TEXTURE_2D);\n"
+            "MinFilter = POINT;\n"
+            "MagFilter = POINT;\n"
+        "};\n"
 
 
     // Vertex Shader output for pixel shader usage
     // Vertex Shader output for pixel shader usage
-		"struct VS_OUTPUT\n"
-		"{\n"
-			"float4 Position : POSITION;\n"
-			"float2 TexCoord0 : TEXCOORD0;\n"
-		"};\n"
+        "struct VS_OUTPUT\n"
+        "{\n"
+            "float4 Position : POSITION;\n"
+            "float2 TexCoord0 : TEXCOORD0;\n"
+        "};\n"
 
 
     // vertex shader for pixel shader usage
     // vertex shader for pixel shader usage
-		"VS_OUTPUT DefaultVShader(float4 INPosition : POSITION, float2 INTexCoord0 : TEXCOORD0 )\n"
-		"{\n"
-			"VS_OUTPUT Out;\n"
-
-			"Out.Position = INPosition;\n"
-			"Out.TexCoord0 = INTexCoord0;\n"
-
-			"return Out;\n"
-		"}\n"
-
-		// simply lookup a texture
-		"float4 PassThrough_PS(float2 IN : TEXCOORD0) : COLOR\n"
-		"{\n"
- 		"  return tex2D(TEXTURE_SAMPLER,IN);\n"
-		"}\n"
-
-		// visualize the alpha channel (in black) -> use a
-		"float4 PassThroughAlphaA_PS(float2 IN : TEXCOORD0) : COLOR\n"
-		"{\n"
-		"  return float4(0.0f,0.0f,0.0f,tex2D(TEXTURE_SAMPLER,IN).a);\n"
-		"}\n"
-
-		// visualize the alpha channel (in black) -> use r
-		"float4 PassThroughAlphaR_PS(float2 IN : TEXCOORD0) : COLOR\n"
-		"{\n"
-		"  return float4(0.0f,0.0f,0.0f,tex2D(TEXTURE_SAMPLER,IN).r);\n"
-		"}\n"
-
-		// Simple pass-through technique
-		"technique PassThrough\n"
-		"{\n"
-			"pass p0\n"
-			"{\n"
-				"FillMode=Solid;\n"
-				"ZEnable = FALSE;\n"
-				"CullMode = none;\n"
-				"AlphaBlendEnable = TRUE;\n"
-				"SrcBlend =srcalpha;\n"
-				"DestBlend =invsrcalpha;\n"
-				"PixelShader = compile ps_2_0 PassThrough_PS();\n"
-				"VertexShader = compile vs_2_0 DefaultVShader();\n"
-			"}\n"
-		"};\n"
-
-		// Pass-through technique which visualizes the texture's alpha channel
-		"technique PassThroughAlphaFromA\n"
-		"{\n"
-			"pass p0\n"
-			"{\n"
-				"FillMode=Solid;\n"
-				"ZEnable = FALSE;\n"
-				"CullMode = none;\n"
-				"AlphaBlendEnable = TRUE;\n"
-				"SrcBlend =srcalpha;\n"
-				"DestBlend =invsrcalpha;\n"
-				"PixelShader = compile ps_2_0 PassThroughAlphaA_PS();\n"
-				"VertexShader = compile vs_2_0 DefaultVShader();\n"
-			"}\n"
-		"};\n"
-
-		// Pass-through technique which visualizes the texture's red channel
-		"technique PassThroughAlphaFromR\n"
-		"{\n"
-			"pass p0\n"
-			"{\n"
-				"FillMode=Solid;\n"
-				"ZEnable = FALSE;\n"
-				"CullMode = none;\n"
-				"AlphaBlendEnable = TRUE;\n"
-				"SrcBlend =srcalpha;\n"
-				"DestBlend =invsrcalpha;\n"
-				"PixelShader = compile ps_2_0 PassThroughAlphaR_PS();\n"
-				"VertexShader = compile vs_2_0 DefaultVShader();\n"
-			"}\n"
-		"};\n"
-
-		// technique for fixed function pixel pipeline
-		"technique PassThrough_FF\n"
-		"{\n"
-			"pass p0\n"
-			"{\n"
-				"ZEnable = FALSE;\n"
-				"CullMode = none;\n"
-				"AlphaBlendEnable = TRUE;\n"
-				"SrcBlend =srcalpha;\n"
-				"DestBlend =invsrcalpha;\n"
-				"VertexShader = compile vs_2_0 DefaultVShader();\n"
+        "VS_OUTPUT DefaultVShader(float4 INPosition : POSITION, float2 INTexCoord0 : TEXCOORD0 )\n"
+        "{\n"
+            "VS_OUTPUT Out;\n"
+
+            "Out.Position = INPosition;\n"
+            "Out.TexCoord0 = INTexCoord0;\n"
+
+            "return Out;\n"
+        "}\n"
+
+        // simply lookup a texture
+        "float4 PassThrough_PS(float2 IN : TEXCOORD0) : COLOR\n"
+        "{\n"
+        "  return tex2D(TEXTURE_SAMPLER,IN);\n"
+        "}\n"
+
+        // visualize the alpha channel (in black) -> use a
+        "float4 PassThroughAlphaA_PS(float2 IN : TEXCOORD0) : COLOR\n"
+        "{\n"
+        "  return float4(0.0f,0.0f,0.0f,tex2D(TEXTURE_SAMPLER,IN).a);\n"
+        "}\n"
+
+        // visualize the alpha channel (in black) -> use r
+        "float4 PassThroughAlphaR_PS(float2 IN : TEXCOORD0) : COLOR\n"
+        "{\n"
+        "  return float4(0.0f,0.0f,0.0f,tex2D(TEXTURE_SAMPLER,IN).r);\n"
+        "}\n"
+
+        // Simple pass-through technique
+        "technique PassThrough\n"
+        "{\n"
+            "pass p0\n"
+            "{\n"
+                "FillMode=Solid;\n"
+                "ZEnable = FALSE;\n"
+                "CullMode = none;\n"
+                "AlphaBlendEnable = TRUE;\n"
+                "SrcBlend =srcalpha;\n"
+                "DestBlend =invsrcalpha;\n"
+                "PixelShader = compile ps_2_0 PassThrough_PS();\n"
+                "VertexShader = compile vs_2_0 DefaultVShader();\n"
+            "}\n"
+        "};\n"
+
+        // Pass-through technique which visualizes the texture's alpha channel
+        "technique PassThroughAlphaFromA\n"
+        "{\n"
+            "pass p0\n"
+            "{\n"
+                "FillMode=Solid;\n"
+                "ZEnable = FALSE;\n"
+                "CullMode = none;\n"
+                "AlphaBlendEnable = TRUE;\n"
+                "SrcBlend =srcalpha;\n"
+                "DestBlend =invsrcalpha;\n"
+                "PixelShader = compile ps_2_0 PassThroughAlphaA_PS();\n"
+                "VertexShader = compile vs_2_0 DefaultVShader();\n"
+            "}\n"
+        "};\n"
+
+        // Pass-through technique which visualizes the texture's red channel
+        "technique PassThroughAlphaFromR\n"
+        "{\n"
+            "pass p0\n"
+            "{\n"
+                "FillMode=Solid;\n"
+                "ZEnable = FALSE;\n"
+                "CullMode = none;\n"
+                "AlphaBlendEnable = TRUE;\n"
+                "SrcBlend =srcalpha;\n"
+                "DestBlend =invsrcalpha;\n"
+                "PixelShader = compile ps_2_0 PassThroughAlphaR_PS();\n"
+                "VertexShader = compile vs_2_0 DefaultVShader();\n"
+            "}\n"
+        "};\n"
+
+        // technique for fixed function pixel pipeline
+        "technique PassThrough_FF\n"
+        "{\n"
+            "pass p0\n"
+            "{\n"
+                "ZEnable = FALSE;\n"
+                "CullMode = none;\n"
+                "AlphaBlendEnable = TRUE;\n"
+                "SrcBlend =srcalpha;\n"
+                "DestBlend =invsrcalpha;\n"
+                "VertexShader = compile vs_2_0 DefaultVShader();\n"
         "ColorOp[0] = SelectArg1;\n"
         "ColorOp[0] = SelectArg1;\n"
         "ColorArg0[0] = Texture;\n"
         "ColorArg0[0] = Texture;\n"
         "AlphaOp[0] = SelectArg1;\n"
         "AlphaOp[0] = SelectArg1;\n"
         "AlphaArg0[0] = Texture;\n"
         "AlphaArg0[0] = Texture;\n"
-			"}\n"
-		"};\n"
+            "}\n"
+        "};\n"
     );
     );
 
 
 std::string g_szCheckerBackgroundShader = std::string(
 std::string g_szCheckerBackgroundShader = std::string(
 
 
-		// the two colors used to draw the checker pattern
-		"float3 COLOR_ONE = float3(0.4f,0.4f,0.4f);\n"
-		"float3 COLOR_TWO = float3(0.6f,0.6f,0.6f);\n"
+        // the two colors used to draw the checker pattern
+        "float3 COLOR_ONE = float3(0.4f,0.4f,0.4f);\n"
+        "float3 COLOR_TWO = float3(0.6f,0.6f,0.6f);\n"
 
 
-		// size of a square in both x and y direction
-		"float SQUARE_SIZE = 10.0f;\n"
+        // size of a square in both x and y direction
+        "float SQUARE_SIZE = 10.0f;\n"
 
 
     // vertex shader output structure
     // vertex shader output structure
-		"struct VS_OUTPUT\n"
-		"{\n"
-			"float4 Position : POSITION;\n"	
-		"};\n"
+        "struct VS_OUTPUT\n"
+        "{\n"
+            "float4 Position : POSITION;\n"	
+        "};\n"
 
 
     // vertex shader 
     // vertex shader 
-		"VS_OUTPUT DefaultVShader(float4 INPosition : POSITION, float2 INTexCoord0 : TEXCOORD0 )\n"
-		"{\n"
-			"VS_OUTPUT Out;\n"
-
-			"Out.Position = INPosition;\n"
-			"return Out;\n"
-		"}\n"
-
-		// pixel shader
-		"float4 MakePattern_PS(float2 IN : VPOS) : COLOR\n"
-		"{\n"
-		  "float2 fDiv = IN / SQUARE_SIZE;\n"
-		  "float3 fColor = COLOR_ONE;\n"
-		  "if (0 == round(fmod(round(fDiv.x),2)))\n"
-		  "{\n"
-		  "  if (0 == round(fmod(round(fDiv.y),2))) fColor = COLOR_TWO;\n"
-		  "}\n"
-		  "else if (0 != round(fmod(round(fDiv.y),2)))fColor = COLOR_TWO;\n"
-		  "return float4(fColor,1.0f);"
-		"}\n"
-	
-		// technique to generate a pattern
-		"technique MakePattern\n"
-		"{\n"
-		  "pass p0\n"
-		  "{\n"
-		    "FillMode=Solid;\n"
-		    "ZEnable = FALSE;\n"
-		    "CullMode = none;\n"
-		    "PixelShader = compile ps_3_0 MakePattern_PS();\n"
-		    "VertexShader = compile vs_3_0 DefaultVShader();\n"
-		  "}\n"
-		"};\n"
-		);
-	};
+        "VS_OUTPUT DefaultVShader(float4 INPosition : POSITION, float2 INTexCoord0 : TEXCOORD0 )\n"
+        "{\n"
+            "VS_OUTPUT Out;\n"
+
+            "Out.Position = INPosition;\n"
+            "return Out;\n"
+        "}\n"
+
+        // pixel shader
+        "float4 MakePattern_PS(float2 IN : VPOS) : COLOR\n"
+        "{\n"
+          "float2 fDiv = IN / SQUARE_SIZE;\n"
+          "float3 fColor = COLOR_ONE;\n"
+          "if (0 == round(fmod(round(fDiv.x),2)))\n"
+          "{\n"
+          "  if (0 == round(fmod(round(fDiv.y),2))) fColor = COLOR_TWO;\n"
+          "}\n"
+          "else if (0 != round(fmod(round(fDiv.y),2)))fColor = COLOR_TWO;\n"
+          "return float4(fColor,1.0f);"
+        "}\n"
+    
+        // technique to generate a pattern
+        "technique MakePattern\n"
+        "{\n"
+          "pass p0\n"
+          "{\n"
+            "FillMode=Solid;\n"
+            "ZEnable = FALSE;\n"
+            "CullMode = none;\n"
+            "PixelShader = compile ps_3_0 MakePattern_PS();\n"
+            "VertexShader = compile vs_3_0 DefaultVShader();\n"
+          "}\n"
+        "};\n"
+        );
+    };

Файловите разлики са ограничени, защото са твърде много
+ 523 - 522
tools/assimp_view/assimp_view.cpp


+ 34 - 33
tools/assimp_view/assimp_view.h

@@ -47,6 +47,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 // include resource definitions
 // include resource definitions
 #include "resource.h"
 #include "resource.h"
 
 
+#include <assert.h>
+#include <stdlib.h>
+#include <malloc.h>
+#include <memory.h>
+#include <tchar.h>
+#include <stdio.h>
+#include <time.h>
+
 // Include ASSIMP headers (XXX: do we really need all of them?)
 // Include ASSIMP headers (XXX: do we really need all of them?)
 #include <assimp/cimport.h>
 #include <assimp/cimport.h>
 #include <assimp/Importer.hpp>
 #include <assimp/Importer.hpp>
@@ -59,29 +67,23 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include <assimp/LogStream.hpp>
 #include <assimp/LogStream.hpp>
 #include <assimp/DefaultLogger.hpp>
 #include <assimp/DefaultLogger.hpp>
 
 
-#include "../../code/AssimpPCH.h" /* HACK */
  
  
 #include "../../code/MaterialSystem.h"   // aiMaterial class
 #include "../../code/MaterialSystem.h"   // aiMaterial class
 #include "../../code/StringComparison.h" // ASSIMP_stricmp and ASSIMP_strincmp
 #include "../../code/StringComparison.h" // ASSIMP_stricmp and ASSIMP_strincmp
 
 
 // in order for std::min and std::max to behave properly
 // in order for std::min and std::max to behave properly
-#ifdef min 
+/*#ifdef min 
 #undef min
 #undef min
 #endif // min
 #endif // min
 #ifdef max 
 #ifdef max 
 #undef max
 #undef max
-#endif // min
+#endif // min*/
 
 
 #include <time.h>
 #include <time.h>
 
 
 // default movement speed 
 // default movement speed 
 #define MOVE_SPEED 3.f
 #define MOVE_SPEED 3.f
 
 
-using namespace Assimp;
-
-namespace AssimpView 
-{
-
 #include "AssetHelper.h"
 #include "AssetHelper.h"
 #include "Camera.h"
 #include "Camera.h"
 #include "RenderOptions.h"
 #include "RenderOptions.h"
@@ -93,7 +95,6 @@ namespace AssimpView
 #include "MeshRenderer.h"
 #include "MeshRenderer.h"
 #include "MaterialManager.h"
 #include "MaterialManager.h"
 
 
-} // end of namespace AssimpView - for a while
 
 
 // outside of namespace, to help Intellisense and solve boost::metatype_stuff_miracle
 // outside of namespace, to help Intellisense and solve boost::metatype_stuff_miracle
 #include "AnimEvaluator.h"
 #include "AnimEvaluator.h"
@@ -105,30 +106,30 @@ namespace AssimpView
 //-------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------
 // Function prototypes
 // Function prototypes
 //-------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------
-	int InitD3D(void);
-	int ShutdownD3D(void);
-	int CreateDevice (bool p_bMultiSample,bool p_bSuperSample, bool bHW = true);
-	int CreateDevice (void);
-	int ShutdownDevice(void);
-	int GetProjectionMatrix (aiMatrix4x4& p_mOut);
-	int LoadAsset(void);
-	int CreateAssetData(void);
-	int DeleteAssetData(bool bNoMaterials = false);
-	int ScaleAsset(void);
-	int DeleteAsset(void);
-	int SetupFPSView();
+int InitD3D(void);
+int ShutdownD3D(void);
+int CreateDevice (bool p_bMultiSample,bool p_bSuperSample, bool bHW = true);
+int CreateDevice (void);
+int ShutdownDevice(void);
+int GetProjectionMatrix (aiMatrix4x4& p_mOut);
+int LoadAsset(void);
+int CreateAssetData(void);
+int DeleteAssetData(bool bNoMaterials = false);
+int ScaleAsset(void);
+int DeleteAsset(void);
+int SetupFPSView();
 	
 	
-	aiVector3D GetCameraMatrix (aiMatrix4x4& p_mOut);
-	int CreateMaterial(AssetHelper::MeshHelper* pcMesh,const aiMesh* pcSource);
+aiVector3D GetCameraMatrix (aiMatrix4x4& p_mOut);
+int CreateMaterial(AssetHelper::MeshHelper* pcMesh,const aiMesh* pcSource);
 
 
-	void HandleMouseInputFPS( void );
-	void HandleMouseInputLightRotate( void );
-	void HandleMouseInputLocal( void );
-	void HandleKeyboardInputFPS( void );
-	void HandleMouseInputLightIntensityAndColor( void );
-	void HandleMouseInputSkyBox( void );
-	void HandleKeyboardInputTextureView( void );
-	void HandleMouseInputTextureView( void );
+void HandleMouseInputFPS( void );
+void HandleMouseInputLightRotate( void );
+void HandleMouseInputLocal( void );
+void HandleKeyboardInputFPS( void );
+void HandleMouseInputLightIntensityAndColor( void );
+void HandleMouseInputSkyBox( void );
+void HandleKeyboardInputTextureView( void );
+void HandleMouseInputTextureView( void );
 
 
 
 
 //-------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------
@@ -160,7 +161,7 @@ INT_PTR CALLBACK AboutMessageProc(HWND hwndDlg,UINT uMsg,
 
 
 //-------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------
 // 
 // 
-// Dialog prcoedure for the help dialog
+// Dialog procedure for the help dialog
 //
 //
 //-------------------------------------------------------------------------------
 //-------------------------------------------------------------------------------
 INT_PTR CALLBACK HelpDialogProc(HWND hwndDlg,UINT uMsg,
 INT_PTR CALLBACK HelpDialogProc(HWND hwndDlg,UINT uMsg,
@@ -182,7 +183,7 @@ type clamp(intype in)
 {
 {
 	// for unsigned types only ...
 	// for unsigned types only ...
 	intype mask = (0x1u << (sizeof(type)*8))-1;
 	intype mask = (0x1u << (sizeof(type)*8))-1;
-	return (type)std::max((intype)0,std::min(in,mask));
+	return (type)max((intype)0,min(in,mask));
 }
 }
 
 
 
 

Някои файлове не бяха показани, защото твърде много файлове са промени