From 76dd9467b292bcc1aad0fe678df6b3bd587eadde Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 17 Apr 2015 20:02:55 +0200 Subject: [PATCH] fix win32-build for assimp_viewer . Signed-off-by: Kim Kulling --- .gitignore | 1 + code/StringComparison.h | 2 + tools/assimp_view/AnimEvaluator.cpp | 1 - tools/assimp_view/AssetHelper.h | 327 ++-- tools/assimp_view/Background.cpp | 3 +- tools/assimp_view/Background.h | 130 +- tools/assimp_view/Display.cpp | 11 +- tools/assimp_view/Display.h | 774 +++++---- tools/assimp_view/HelpDialog.cpp | 2 - tools/assimp_view/Input.cpp | 2 - tools/assimp_view/LogDisplay.cpp | 5 +- tools/assimp_view/LogDisplay.h | 87 +- tools/assimp_view/LogWindow.cpp | 4 +- tools/assimp_view/LogWindow.h | 149 +- tools/assimp_view/Material.cpp | 2409 +++++++++++++------------- tools/assimp_view/MaterialManager.h | 278 +-- tools/assimp_view/MeshRenderer.cpp | 2 - tools/assimp_view/MeshRenderer.h | 78 +- tools/assimp_view/MessageProc.cpp | 10 +- tools/assimp_view/Normals.cpp | 2 +- tools/assimp_view/SceneAnimator.cpp | 1 - tools/assimp_view/Shaders.cpp | 2492 +++++++++++++-------------- tools/assimp_view/assimp_view.cpp | 1599 ++++++++--------- tools/assimp_view/assimp_view.h | 67 +- 24 files changed, 4278 insertions(+), 4158 deletions(-) diff --git a/.gitignore b/.gitignore index 74acea82f..833e56ef1 100644 --- a/.gitignore +++ b/.gitignore @@ -58,3 +58,4 @@ test/gtest/src/gtest-stamp/gtest-gitinfo.txt test/gtest/src/gtest-stamp/gtest-gitclone-lastrun.txt Assimp.opensdf contrib/zlib/CTestTestfile.cmake +ipch/assimp_viewer-44bbbcd1/assimp_viewerd-ccc45335.ipch diff --git a/code/StringComparison.h b/code/StringComparison.h index 1f0ab1d9b..f5dd83092 100644 --- a/code/StringComparison.h +++ b/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 #include "../include/assimp/ai_assert.h" +#include "StringComparison.h" + #include #include #include diff --git a/tools/assimp_view/AnimEvaluator.cpp b/tools/assimp_view/AnimEvaluator.cpp index 7145b3d31..0f9bdf611 100644 --- a/tools/assimp_view/AnimEvaluator.cpp +++ b/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" using namespace AssimpView; diff --git a/tools/assimp_view/AssetHelper.h b/tools/assimp_view/AssetHelper.h index 837cf3aab..94a453ece 100644 --- a/tools/assimp_view/AssetHelper.h +++ b/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) #define AV_ASSET_HELPER_H_INCLUDED -class SceneAnimator; +#include +#include +#include -//------------------------------------------------------------------------------- -/** \brief Class to wrap ASSIMP's asset output structures -*/ -//------------------------------------------------------------------------------- -class AssetHelper - { - public: - enum - { - // the original normal set will be used - ORIGINAL = 0x0u, +#include - // a smoothed normal set will be used - SMOOTH = 0x1u, +namespace AssimpView { - // a hard normal set will be used - HARD = 0x2u, - }; + class SceneAnimator; - // default constructor - AssetHelper() - : iNormalSet(ORIGINAL) - { - mAnimator = NULL; - apcMeshes = NULL; - pcScene = NULL; - } + //------------------------------------------------------------------------------- + /** \brief Class to wrap ASSIMP's asset output structures + */ + //------------------------------------------------------------------------------- + class AssetHelper + { + public: + enum + { + // the original normal set will be used + ORIGINAL = 0x0u, - //--------------------------------------------------------------- - // 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; + // a smoothed normal set will be used + SMOOTH = 0x1u, - 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 + // a hard normal set will be used + HARD = 0x2u, + }; - /** 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() - }; + // default constructor + AssetHelper() + : iNormalSet( ORIGINAL ) + { + mAnimator = NULL; + apcMeshes = NULL; + pcScene = NULL; + } - return decl; - } - }; + //--------------------------------------------------------------- + // 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; - //--------------------------------------------------------------- - // FVF vertex structure used for normals - //--------------------------------------------------------------- - struct LineVertex - { - aiVector3D vPosition; - DWORD dColorDiffuse; + 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 - // retrieves the FVF code of the vertex type - static DWORD GetFVF() - { - return D3DFVF_DIFFUSE | D3DFVF_XYZ; - } - }; + /** 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() + }; - //--------------------------------------------------------------- - // Helper class to store GPU related resources created for - // a given aiMesh - //--------------------------------------------------------------- - class MeshHelper - { - public: + return decl; + } + }; - 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) - {} + //--------------------------------------------------------------- + // FVF vertex structure used for normals + //--------------------------------------------------------------- + struct LineVertex + { + aiVector3D vPosition; + DWORD dColorDiffuse; - ~MeshHelper () - { - // NOTE: This is done in DeleteAssetData() - // TODO: Make this a proper d'tor - } + // retrieves the FVF code of the vertex type + static DWORD GetFVF() + { + return D3DFVF_DIFFUSE | D3DFVF_XYZ; + } + }; - // shading mode to use. Either Lambert or otherwise phong - // will be used in every case - aiShadingMode eShadingMode; + //--------------------------------------------------------------- + // Helper class to store GPU related resources created for + // a given aiMesh + //--------------------------------------------------------------- + class MeshHelper + { + public: - // vertex buffer - IDirect3DVertexBuffer9* piVB; + 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 ) + {} - // index buffer. For partially transparent meshes - // created with dynamic usage to be able to update - // the buffer contents quickly - IDirect3DIndexBuffer9* piIB; + ~MeshHelper() + { + // NOTE: This is done in DeleteAssetData() + // TODO: Make this a proper d'tor + } - // vertex buffer to be used to draw vertex normals - // (vertex normals are generated in every case) - IDirect3DVertexBuffer9* piVBNormals; + // shading mode to use. Either Lambert or otherwise phong + // will be used in every case + aiShadingMode eShadingMode; - // shader to be used - ID3DXEffect* piEffect; - bool bSharedFX; + // vertex buffer + IDirect3DVertexBuffer9* piVB; - // material textures - IDirect3DTexture9* piDiffuseTexture; - IDirect3DTexture9* piSpecularTexture; - IDirect3DTexture9* piAmbientTexture; - IDirect3DTexture9* piEmissiveTexture; - IDirect3DTexture9* piNormalTexture; - IDirect3DTexture9* piOpacityTexture; - IDirect3DTexture9* piShininessTexture; - IDirect3DTexture9* piLightmapTexture; + // index buffer. For partially transparent meshes + // created with dynamic usage to be able to update + // the buffer contents quickly + IDirect3DIndexBuffer9* piIB; - // material colors - D3DXVECTOR4 vDiffuseColor; - D3DXVECTOR4 vSpecularColor; - D3DXVECTOR4 vAmbientColor; - D3DXVECTOR4 vEmissiveColor; + // vertex buffer to be used to draw vertex normals + // (vertex normals are generated in every case) + IDirect3DVertexBuffer9* piVBNormals; - // opacity for the material - float fOpacity; + // shader to be used + ID3DXEffect* piEffect; + bool bSharedFX; - // shininess for the material - float fShininess; + // material textures + IDirect3DTexture9* piDiffuseTexture; + IDirect3DTexture9* piSpecularTexture; + IDirect3DTexture9* piAmbientTexture; + IDirect3DTexture9* piEmissiveTexture; + IDirect3DTexture9* piNormalTexture; + IDirect3DTexture9* piOpacityTexture; + IDirect3DTexture9* piShininessTexture; + IDirect3DTexture9* piLightmapTexture; - // strength of the specular highlight - float fSpecularStrength; + // material colors + D3DXVECTOR4 vDiffuseColor; + D3DXVECTOR4 vSpecularColor; + D3DXVECTOR4 vAmbientColor; + D3DXVECTOR4 vEmissiveColor; - // two-sided? - bool twosided; + // opacity for the material + float fOpacity; - // Stores a pointer to the original normal set of the asset - aiVector3D* pvOriginalNormals; - }; + // shininess for the material + float fShininess; - // One instance per aiMesh in the globally loaded asset - MeshHelper** apcMeshes; + // strength of the specular highlight + float fSpecularStrength; - // Scene wrapper instance - aiScene* pcScene; + // two-sided? + bool twosided; - // Animation player to animate the scene if necessary - SceneAnimator* mAnimator; + // Stores a pointer to the original normal set of the asset + aiVector3D* pvOriginalNormals; + }; - // Specifies the normal set to be used - unsigned int iNormalSet; + // One instance per aiMesh in the globally loaded asset + MeshHelper** apcMeshes; - // ------------------------------------------------------------------ - // set the normal set to be used - void SetNormalSet(unsigned int iSet); + // Scene wrapper instance + aiScene* pcScene; - // ------------------------------------------------------------------ - // flip all normal vectors - void FlipNormals(); - void FlipNormalsInt(); - }; + // 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 diff --git a/tools/assimp_view/Background.cpp b/tools/assimp_view/Background.cpp index 94141f641..b0f01b02c 100644 --- a/tools/assimp_view/Background.cpp +++ b/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" - namespace AssimpView { +extern std::string g_szSkyboxShader; // From: U3D build 1256 (src\kernel\graphic\scenegraph\SkyBox.cpp) // ------------------------------------------------------------------------------ diff --git a/tools/assimp_view/Background.h b/tools/assimp_view/Background.h index 9908babf3..1d073cf8d 100644 --- a/tools/assimp_view/Background.h +++ b/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. --------------------------------------------------------------------------- */ +#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 \ No newline at end of file +} diff --git a/tools/assimp_view/Display.cpp b/tools/assimp_view/Display.cpp index 9927fbe58..37c22962b 100644 --- a/tools/assimp_view/Display.cpp +++ b/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. --------------------------------------------------------------------------- */ - -#include "stdafx.h" #include "assimp_view.h" - +#include "AnimEvaluator.h" +#include "SceneAnimator.h" namespace AssimpView { +using namespace Assimp; + +extern std::string g_szCheckerBackgroundShader; + struct SVertex { float x,y,z,w,u,v; @@ -2240,7 +2243,7 @@ int CDisplay::RenderTextureView() const float ny = (float)sRect.bottom; const float x = (float)sDesc.Width; 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 fHalfY = (ny - (f * y)) / 2.0f; diff --git a/tools/assimp_view/Display.h b/tools/assimp_view/Display.h index c31b3aa7c..5b282bbdf 100644 --- a/tools/assimp_view/Display.h +++ b/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) #define AV_DISPLAY_H_INCLUDE +#include +#include +#include + // see CDisplay::m_aiImageList #define AI_VIEW_IMGLIST_NODE 0x0 #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_MODEL 0x4 -//------------------------------------------------------------------------------- -/* Corresponds to the "Display" combobox in the UI -*/ -//------------------------------------------------------------------------------- -class CDisplay - { -private: +namespace AssimpView +{ - // helper class - struct Info - { - Info( D3DXVECTOR4* p1, - AssetHelper::MeshHelper* p2, - const char* p3) - : pclrColor(p1),pMesh(p2),szShaderParam(p3) {} + //------------------------------------------------------------------------------- + /* Corresponds to the "Display" combobox in the UI + */ + //------------------------------------------------------------------------------- + class CDisplay + { + private: - D3DXVECTOR4* pclrColor; - AssetHelper::MeshHelper* pMesh; - const char* szShaderParam; - }; + // helper class + struct Info + { + Info( D3DXVECTOR4* p1, + AssetHelper::MeshHelper* p2, + const char* p3 ) + : pclrColor( p1 ), pMesh( p2 ), szShaderParam( p3 ) {} -// 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; + D3DXVECTOR4* pclrColor; + AssetHelper::MeshHelper* pMesh; + const char* szShaderParam; + }; - 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; - } + // 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; -public: + 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, + //------------------------------------------------------------------ + enum + { + // the full model is displayed + VIEWMODE_FULL, - // a material is displayed on a simple spjere as model - VIEWMODE_MATERIAL, + // 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 texture with an UV set mapped on it is displayed + VIEWMODE_TEXTURE, - // a single node in the scenegraph is displayed - VIEWMODE_NODE, - }; + // a single node in the scenegraph is displayed + VIEWMODE_NODE, + }; - //------------------------------------------------------------------ - // represents a texture in the tree view - struct TextureInfo - { - // texture info - IDirect3DTexture9** piTexture; + //------------------------------------------------------------------ + // represents a texture in the tree view + struct TextureInfo + { + // texture info + IDirect3DTexture9** piTexture; - // Blend factor of the texture - float fBlend; + // Blend factor of the texture + float fBlend; - // blend operation for the texture - aiTextureOp eOp; + // blend operation for the texture + aiTextureOp eOp; - // UV index for the texture - unsigned int iUV; + // UV index for the texture + unsigned int iUV; - // Associated tree item - HTREEITEM hTreeItem; + // Associated tree item + HTREEITEM hTreeItem; - // Original path to the texture - std::string szPath; + // Original path to the texture + std::string szPath; - // index of the corresponding material - unsigned int iMatIndex; + // index of the corresponding material + unsigned int iMatIndex; - // type of the texture - unsigned int iType; - }; + // type of the texture + unsigned int iType; + }; - //------------------------------------------------------------------ - // represents a node in the tree view - struct NodeInfo - { - // node object - aiNode* psNode; + //------------------------------------------------------------------ + // represents a node in the tree view + struct NodeInfo + { + // node object + aiNode* psNode; - // corresponding tree view item - HTREEITEM hTreeItem; - }; + // corresponding tree view item + HTREEITEM hTreeItem; + }; - //------------------------------------------------------------------ - // represents a mesh in the tree view - struct MeshInfo - { - // the mesh object - aiMesh* psMesh; + //------------------------------------------------------------------ + // represents a mesh in the tree view + struct MeshInfo + { + // the mesh object + aiMesh* psMesh; - // corresponding tree view item - HTREEITEM hTreeItem; - }; + // corresponding tree view item + HTREEITEM hTreeItem; + }; - //------------------------------------------------------------------ - // represents a material in the tree view - struct MaterialInfo - { - // material index - unsigned int iIndex; + //------------------------------------------------------------------ + // represents a material in the tree view + struct MaterialInfo + { + // material index + unsigned int iIndex; - // material object - aiMaterial* psMaterial; + // material object + aiMaterial* psMaterial; - // ID3DXEffect interface - ID3DXEffect* piEffect; + // ID3DXEffect interface + ID3DXEffect* piEffect; - // corresponding tree view item - HTREEITEM hTreeItem; - }; + // corresponding tree view item + HTREEITEM hTreeItem; + }; - //------------------------------------------------------------------ - // Singleton accessors - static CDisplay s_cInstance; - inline static CDisplay& Instance () - { - return s_cInstance; - } + //------------------------------------------------------------------ + // 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 - //------------------------------------------------------------------ - // 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 - //------------------------------------------------------------------ - // Variant 3: Render a large sphere and map a given material on it - int RenderMaterialView(); + //------------------------------------------------------------------ + // 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(); + //------------------------------------------------------------------ + // 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); + //------------------------------------------------------------------ + // 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 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 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 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); + //------------------------------------------------------------------ + // 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); + //------------------------------------------------------------------ + // Load the image list for the tree view item + int LoadImageList( void ); - //------------------------------------------------------------------ - // Expand all nodes in the tree - int ExpandTree(); + //------------------------------------------------------------------ + // 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); + //------------------------------------------------------------------ + // 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 animations + int ClearAnimList( void ); - //------------------------------------------------------------------ - // Clear the combox box containing the list of scenegraph items - int ClearDisplayList(void); + //------------------------------------------------------------------ + // Clear the combox box containing the list of scenegraph items + int ClearDisplayList( void ); - //------------------------------------------------------------------ - // Fill in the default statistics - int FillDefaultStatistics(void); + //------------------------------------------------------------------ + // Fill in the default statistics + int FillDefaultStatistics( void ); - //------------------------------------------------------------------ - // Called by LoadAsset() - // reset the class instance to the default values - int Reset(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); + //------------------------------------------------------------------ + // 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); + //------------------------------------------------------------------ + // 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); + //------------------------------------------------------------------ + // 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) ; + //------------------------------------------------------------------ + // 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; - } + //------------------------------------------------------------------ + // 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; - } + //------------------------------------------------------------------ + // 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 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 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; - } + //------------------------------------------------------------------ + // 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 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 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 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); - } + //------------------------------------------------------------------ + // 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 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; - } + //------------------------------------------------------------------ + // 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 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]; - } + //------------------------------------------------------------------ + // get the secondary color of the checker pattern background + inline const D3DXVECTOR4* GetSecondCheckerColor() const + { + return &this->m_avCheckerColors[ 1 ]; + } -private: + private: - //------------------------------------------------------------------ - // Render a screen-filling square using the checker pattern shader - int RenderPatternBG(); + //------------------------------------------------------------------ + // 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); + //------------------------------------------------------------------ + // 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(); + //------------------------------------------------------------------ + // 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); + //------------------------------------------------------------------ + // 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 + int HandleInput(); - //------------------------------------------------------------------ - // Handle user input for the texture viewer - int HandleInputTextureView(); + //------------------------------------------------------------------ + // Handle user input for the texture viewer + int HandleInputTextureView(); - //------------------------------------------------------------------ - // Handle user input if no asset is loaded - int HandleInputEmptyScene(); + //------------------------------------------------------------------ + // Handle user input if no asset is loaded + int HandleInputEmptyScene(); - //------------------------------------------------------------------ - // Draw the HUD (call only if FPS mode isn't active) - int DrawHUD(); + //------------------------------------------------------------------ + // 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 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 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 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 OnSetup(). + // Do everything necessary to switch back to normal view mode + int OnSetupNormalView(); - //------------------------------------------------------------------ - // Used by HandleTreeViewPopup(). - int HandleTreeViewPopup2(WPARAM wParam,LPARAM lParam); + //------------------------------------------------------------------ + // Used by HandleTreeViewPopup(). + int HandleTreeViewPopup2( WPARAM wParam, LPARAM lParam ); - //------------------------------------------------------------------ - // Render skeleton - int RenderSkeleton (aiNode* piNode,const aiMatrix4x4& piMatrix, - const aiMatrix4x4& parent); + //------------------------------------------------------------------ + // Render skeleton + int RenderSkeleton( aiNode* piNode, const aiMatrix4x4& piMatrix, + const aiMatrix4x4& parent ); - -private: - // view mode - unsigned int m_iViewMode; + private: - // List of all textures in the display CB - std::vector m_asTextures; + // view mode + unsigned int m_iViewMode; - // current texture or NULL if no texture is active - TextureInfo* m_pcCurrentTexture; + // List of all textures in the display CB + std::vector m_asTextures; - // List of all node in the display CB - std::vector m_asNodes; + // current texture or NULL if no texture is active + TextureInfo* m_pcCurrentTexture; - // List of all node in the display CB - std::vector m_asMeshes; + // List of all node in the display CB + std::vector m_asNodes; - // current Node or NULL if no Node is active - NodeInfo* m_pcCurrentNode; + // List of all node in the display CB + std::vector m_asMeshes; - // List of all materials in the display CB - std::vector m_asMaterials; + // current Node or NULL if no Node is active + NodeInfo* m_pcCurrentNode; - // current material or NULL if no material is active - MaterialInfo* m_pcCurrentMaterial; + // List of all materials in the display CB + std::vector m_asMaterials; - // indices into the image list of the "display" tree view control - unsigned int m_aiImageList[5]; /* = {0,1,2,3,4};*/ + // current material or NULL if no material is active + MaterialInfo* m_pcCurrentMaterial; - // Image list - HIMAGELIST m_hImageList; + // indices into the image list of the "display" tree view control + unsigned int m_aiImageList[ 5 ]; /* = {0,1,2,3,4};*/ - // Root node of the tree, "Model" - HTREEITEM m_hRoot; + // Image list + HIMAGELIST m_hImageList; - // Current zoom factor of the texture viewer - float m_fTextureZoom; + // Root node of the tree, "Model" + HTREEITEM m_hRoot; - // Current offset (in pixels) of the texture viewer - aiVector2D m_vTextureOffset; + // Current zoom factor of the texture viewer + float m_fTextureZoom; - // Colors used to draw the checker pattern (for the - // texture viewer as background ) - D3DXVECTOR4 m_avCheckerColors[2]; + // Current offset (in pixels) of the texture viewer + aiVector2D m_vTextureOffset; - // View projection matrix - aiMatrix4x4 mViewProjection; - aiVector3D vPos; - }; + // Colors used to draw the checker pattern (for the + // texture viewer as background ) + D3DXVECTOR4 m_avCheckerColors[ 2 ]; + // View projection matrix + aiMatrix4x4 mViewProjection; + aiVector3D vPos; + }; + +} #endif // AV_DISPLAY_H_INCLUDE \ No newline at end of file diff --git a/tools/assimp_view/HelpDialog.cpp b/tools/assimp_view/HelpDialog.cpp index 3fb09f0c1..6d3458662 100644 --- a/tools/assimp_view/HelpDialog.cpp +++ b/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 "richedit.h" namespace AssimpView { - //------------------------------------------------------------------------------- // Message procedure for the help dialog //------------------------------------------------------------------------------- diff --git a/tools/assimp_view/Input.cpp b/tools/assimp_view/Input.cpp index 113890a05..994f76535 100644 --- a/tools/assimp_view/Input.cpp +++ b/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" - namespace AssimpView { //------------------------------------------------------------------------------- diff --git a/tools/assimp_view/LogDisplay.cpp b/tools/assimp_view/LogDisplay.cpp index 4b320a144..762c263ba 100644 --- a/tools/assimp_view/LogDisplay.cpp +++ b/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" - namespace AssimpView { - -/* extern */ CLogDisplay CLogDisplay::s_cInstance; +CLogDisplay CLogDisplay::s_cInstance; //------------------------------------------------------------------------------- void CLogDisplay::AddEntry(const std::string& szText, diff --git a/tools/assimp_view/LogDisplay.h b/tools/assimp_view/LogDisplay.h index ac609a7d2..dc6724cf8 100644 --- a/tools/assimp_view/LogDisplay.h +++ b/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. --------------------------------------------------------------------------- */ +#pragma once -#if (!defined AV_LOG_DISPLAY_H_INCLUDED) -#define AV_LOG_DISPLAY_H_INCLUDE +#include -//------------------------------------------------------------------------------- -/** \brief Class to display log strings in the upper right corner of the view -*/ -//------------------------------------------------------------------------------- -class CLogDisplay - { -private: +namespace AssimpView +{ - CLogDisplay() {} + //------------------------------------------------------------------------------- + /** \brief Class to display log strings in the upper right corner of the view + */ + //------------------------------------------------------------------------------- + class CLogDisplay + { + private: -public: + CLogDisplay() {} - // data structure for an entry in the log queue - struct SEntry - { - SEntry () - : - clrColor(D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0x00)), dwStartTicks(0) - {} + public: - std::string szText; - D3DCOLOR clrColor; - DWORD dwStartTicks; - }; + // data structure for an entry in the log queue + struct SEntry + { + SEntry() + : + clrColor( D3DCOLOR_ARGB( 0xFF, 0xFF, 0xFF, 0x00 ) ), dwStartTicks( 0 ) + {} - // Singleton accessors - static CLogDisplay s_cInstance; - inline static CLogDisplay& Instance () - { - return s_cInstance; - } + std::string szText; + D3DCOLOR clrColor; + DWORD dwStartTicks; + }; - // Add an entry to the log queue - void AddEntry(const std::string& szText, - const D3DCOLOR clrColor = D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0x00)); + // Singleton accessors + static CLogDisplay s_cInstance; + inline static CLogDisplay& Instance() + { + return s_cInstance; + } - // Release any native resources associated with the instance - void ReleaseNativeResource(); + // Add an entry to the log queue + void AddEntry( const std::string& szText, + const D3DCOLOR clrColor = D3DCOLOR_ARGB( 0xFF, 0xFF, 0xFF, 0x00 ) ); - // Recreate any native resources associated with the instance - void RecreateNativeResource(); + // Release any native resources associated with the instance + void ReleaseNativeResource(); - // Called during the render loop - void OnRender(); + // Recreate any native resources associated with the instance + void RecreateNativeResource(); -private: + // Called during the render loop + void OnRender(); - std::list asEntries; - ID3DXFont* piFont; - }; + private: -#endif // AV_LOG_DISPLAY_H_INCLUDE \ No newline at end of file + std::list asEntries; + ID3DXFont* piFont; + }; + +} diff --git a/tools/assimp_view/LogWindow.cpp b/tools/assimp_view/LogWindow.cpp index 7fd4a6179..1a53a972e 100644 --- a/tools/assimp_view/LogWindow.cpp +++ b/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 "richedit.h" namespace AssimpView { -/* extern */ CLogWindow CLogWindow::s_cInstance; +CLogWindow CLogWindow::s_cInstance; + extern HKEY g_hRegistry; // header for the RTF log file diff --git a/tools/assimp_view/LogWindow.h b/tools/assimp_view/LogWindow.h index cc786e484..49862cdee 100644 --- a/tools/assimp_view/LogWindow.h +++ b/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) #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: - - friend class CMyLogStream; - friend INT_PTR CALLBACK LogDialogProc(HWND hwndDlg,UINT uMsg, - WPARAM wParam,LPARAM lParam); - - CLogWindow() : hwnd(NULL), bIsVisible(false), bUpdate(true) {} - -public: + //------------------------------------------------------------------------------- + /** \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 ); + }; - // Singleton accessors - static CLogWindow s_cInstance; - inline static CLogWindow& Instance () - { - return s_cInstance; - } + //------------------------------------------------------------------------------- + /** \brief Class to display log strings in a separate window + */ + //------------------------------------------------------------------------------- + class CLogWindow + { + private: - // initializes the log window - void Init (); + friend class CMyLogStream; + friend INT_PTR CALLBACK LogDialogProc( HWND hwndDlg, UINT uMsg, + WPARAM wParam, LPARAM lParam ); - // Shows the log window - void Show(); + CLogWindow() : hwnd( NULL ), bIsVisible( false ), bUpdate( true ) {} - // Clears the log window - void Clear(); - - // Save the log window to an user-defined file - void Save(); - - // write a line to the log window - void WriteLine(const char* message); - - // Set the bUpdate member - inline void SetAutoUpdate(bool b) - { - this->bUpdate = b; - } - - // updates the log file - void Update(); - -private: - - // Window handle - HWND hwnd; - - // current text of the window (contains RTF tags) - std::string szText; - std::string szPlainText; - - // is the log window currently visible? - bool bIsVisible; - - // Specified whether each new log message updates the log automatically - bool bUpdate; + public: -public: - // associated log stream - CMyLogStream* pcStream; - }; + // Singleton accessors + static CLogWindow s_cInstance; + inline static CLogWindow& Instance() + { + return s_cInstance; + } + + // initializes the log window + void Init(); + + // Shows the log window + void Show(); + + // Clears the log window + void Clear(); + + // Save the log window to an user-defined file + void Save(); + + // write a line to the log window + void WriteLine( const char* message ); + + // Set the bUpdate member + inline void SetAutoUpdate( bool b ) + { + this->bUpdate = b; + } + + // updates the log file + void Update(); + + private: + + // Window handle + HWND hwnd; + + // current text of the window (contains RTF tags) + std::string szText; + std::string szPlainText; + + // is the log window currently visible? + bool bIsVisible; + + // Specified whether each new log message updates the log automatically + bool bUpdate; + + + public: + // associated log stream + CMyLogStream* pcStream; + }; + +} #endif // AV_LOG_DISPLA \ No newline at end of file diff --git a/tools/assimp_view/Material.cpp b/tools/assimp_view/Material.cpp index 6f9aac341..d9646320b 100644 --- a/tools/assimp_view/Material.cpp +++ b/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. --------------------------------------------------------------------------- */ - -#include "stdafx.h" #include "assimp_view.h" +#include "MaterialManager.h" +#include "AssetHelper.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include <../code/StringComparison.h> + +#include +#include 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)} */; -/*static */ CMaterialManager CMaterialManager::s_cInstance; +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; + + +CMaterialManager CMaterialManager::s_cInstance; //------------------------------------------------------------------------------- // 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 //------------------------------------------------------------------------------- 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); + 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); + // 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; + 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() - { - 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) { - 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)); + 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(); + *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 } }; + // {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; + uint32_t iData = 0xFFFFFFFF; + (*p_ppiOut)->SetPrivateData(guidPrivateData,&iData,4,0); + return 1; } //------------------------------------------------------------------------------- bool CMaterialManager::TryLongerPath(char* szTemp,aiString* p_szString) { - char szTempB[MAX_PATH]; - strcpy(szTempB,szTemp); + char szTempB[MAX_PATH]; + strcpy(szTempB,szTemp); - // go to the beginning of the file name - char* szFile = strrchr(szTempB,'\\'); - if (!szFile)szFile = strrchr(szTempB,'/'); + // 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; + 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 ); + strcat(szTempB,"*.*"); + const unsigned int iSize = (const unsigned int) ( szExt - 1 - szFile ); - HANDLE h; - WIN32_FIND_DATA info; + 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); + // 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]); + 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; + 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); + 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; + } + } + // 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)); + // 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; + FindClose(h); + } + return false; } //------------------------------------------------------------------------------- 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; - } + 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); + // 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* 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); + 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]); - } + 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; + if(TryLongerPath(szTemp,p_szString))return 1; + *szEnd = 0; - // search common sub directories - strcat(szEnd,"tex\\"); - strcat(szEnd,szData); + // search common sub directories + strcat(szEnd,"tex\\"); + strcat(szEnd,szData); - pFile = fopen(szTemp,"rb"); - if (!pFile) - { - if(TryLongerPath(szTemp,p_szString))return 1; + pFile = fopen(szTemp,"rb"); + if (!pFile) + { + if(TryLongerPath(szTemp,p_szString))return 1; - *szEnd = 0; + *szEnd = 0; - strcat(szEnd,"textures\\"); - strcat(szEnd,szData); + strcat(szEnd,"textures\\"); + strcat(szEnd,szData); - pFile = fopen(szTemp,"rb"); - if (!pFile) - { - if(TryLongerPath(szTemp, p_szString))return 1; - } + 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); + // 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; + // 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; + } + return 1; } //------------------------------------------------------------------------------- int CMaterialManager::LoadTexture(IDirect3DTexture9** p_ppiOut,aiString* szPath) { - ai_assert(NULL != p_ppiOut); - ai_assert(NULL != szPath); + ai_assert(NULL != p_ppiOut); + ai_assert(NULL != szPath); - *p_ppiOut = NULL; + *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; - } + 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)); + // 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; + } + } + 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; - } + 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); + // 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; + 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)); + 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; - } - } + 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)); + // 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(); + this->SetDefaultTexture(p_ppiOut); + } + sCachedTextures[s] = *p_ppiOut; + (*p_ppiOut)->AddRef(); - return 1; + return 1; } //------------------------------------------------------------------------------- void CMaterialManager::DeleteMaterial(AssetHelper::MeshHelper* pcIn) { - if (!pcIn || !pcIn->piEffect)return; - pcIn->piEffect->Release(); + 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; + // 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( - IDirect3DTexture9* piTexture, - IDirect3DTexture9** piTextureOut, - bool bWasOriginallyHM) + IDirect3DTexture9* piTexture, + IDirect3DTexture9** piTextureOut, + bool bWasOriginallyHM) { - ai_assert(NULL != piTexture); - ai_assert(NULL != piTextureOut); + ai_assert(NULL != piTexture); + ai_assert(NULL != piTextureOut); - bool bMustConvert = false; - uintptr_t iElement = 3; + bool bMustConvert = false; + uintptr_t iElement = 3; - *piTextureOut = piTexture; + *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 + // 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); + 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; + 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; + 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++; + // 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; + iElement = (uintptr_t)(pcCharPointer - (unsigned char*)pcData) % 4; + unsigned int aiIndex[3] = {0,1,2}; + if (3 != iElement)aiIndex[iElement] = 3; - pcPointer = pcData; + 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 + 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; + // (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; - } - } - } - } - } + 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); + 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); + // 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; - } + 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; + 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)); + 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(); - } + piTempTexture->Release(); + return; + } + *piTextureOut = piTempTexture; + piTexture->Release(); + } } //------------------------------------------------------------------------------- bool CMaterialManager::HasAlphaPixels(IDirect3DTexture9* piTexture) { - ai_assert(NULL != 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); + 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; + 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; + 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( - AssetHelper::MeshHelper* pcMesh,const aiMesh* pcSource) + AssetHelper::MeshHelper* pcMesh,const aiMesh* pcSource) { - ai_assert(NULL != pcMesh); - ai_assert(NULL != pcSource); + ai_assert(NULL != pcMesh); + ai_assert(NULL != pcSource); - ID3DXBuffer* piBuffer; + ID3DXBuffer* piBuffer; - D3DXMACRO sMacro[64]; + D3DXMACRO sMacro[64]; - // extract all properties from the ASSIMP material structure - const aiMaterial* pcMat = g_pcAsset->pcScene->mMaterials[pcSource->mMaterialIndex]; + // 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; - } + // + // 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; - } + // + // 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; - } + // + // 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 ------------------------------------------------------ + // + 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; - } + // + // 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; + aiString szPath; - aiTextureMapMode mapU(aiTextureMapMode_Wrap),mapV(aiTextureMapMode_Wrap); + aiTextureMapMode mapU(aiTextureMapMode_Wrap),mapV(aiTextureMapMode_Wrap); - bool bib =false; - if (pcSource->mTextureCoords[0]) - { + bool bib =false; + if (pcSource->mTextureCoords[0]) + { - // - // DIFFUSE TEXTURE ------------------------------------------------ - // - if(AI_SUCCESS == aiGetMaterialString(pcMat,AI_MATKEY_TEXTURE_DIFFUSE(0),&szPath)) - { - LoadTexture(&pcMesh->piDiffuseTexture,&szPath); + // + // 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); - } + 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); - } + // + // 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); + // + // 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; + // 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(); - } - } - } + // 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); - } + // + // 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); - } + // + // 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); - } + // + // 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); - } + // + // 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 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); - } - } + // 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); - } + // 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; - } + // 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); + 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]; + // 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->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 ((pcMesh->fOpacity != 1.0f ? true : false) != (pc->fOpacity != 1.0f ? true : false)) + continue; - if (pcSource->HasBones() != g_pcAsset->pcScene->mMeshes[i]->HasBones()) - 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++; + // 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; + // 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"; + 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; + 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"; + 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; + 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; + 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"; + 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); + ++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; + 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->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->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 (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( 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; + // 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(); - } + // 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"); - } + // 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(); + 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 + // 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); - } + 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); + 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 (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()); - } + if (CBackgroundPainter::TEXTURE_CUBE == CBackgroundPainter::Instance().GetMode()){ + pcMesh->piEffect->SetTexture("lw_tex_envmap",CBackgroundPainter::Instance().GetTexture()); + } - return 1; + return 1; } //------------------------------------------------------------------------------- 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; + ai_assert(NULL != pcMesh); + if (!pcMesh->piEffect)return 0; - ID3DXEffect* piEnd = pcMesh->piEffect; + ID3DXEffect* piEnd = pcMesh->piEffect; - piEnd->SetMatrix("WorldViewProjection", - (const D3DXMATRIX*)&pcProj); + piEnd->SetMatrix("WorldViewProjection", + (const D3DXMATRIX*)&pcProj); - piEnd->SetMatrix("World",(const D3DXMATRIX*)&aiMe); - piEnd->SetMatrix("WorldInverseTranspose", - (const D3DXMATRIX*)&pcCam); + 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); + 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; + 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; - } + 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] *= 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[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; + 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); + // 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]); + 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); - } + // 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); + 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 (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()); - } - } + 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); - } + // 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"); - } + // 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; + // activate the effect + UINT dwPasses = 0; + piEnd->Begin(&dwPasses,0); + piEnd->BeginPass(0); + return 1; } //------------------------------------------------------------------------------- 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 diff --git a/tools/assimp_view/MaterialManager.h b/tools/assimp_view/MaterialManager.h index 804f452c0..069d6dc2b 100644 --- a/tools/assimp_view/MaterialManager.h +++ b/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 + +#include "AssetHelper.h" + +namespace AssimpView { -private: - friend class CDisplay; + //------------------------------------------------------------------------------- + /* Helper class to create, access and destroy materials + */ + //------------------------------------------------------------------------------- + class CMaterialManager + { + private: - // default constructor - CMaterialManager() - : m_iShaderCount (0), sDefaultTexture() {} + friend class CDisplay; - ~CMaterialManager() { - if (sDefaultTexture) { - sDefaultTexture->Release(); - } - Reset(); - } + // default constructor + CMaterialManager() + : m_iShaderCount( 0 ), sDefaultTexture() {} -public: + ~CMaterialManager() { + if( sDefaultTexture ) { + sDefaultTexture->Release(); + } + Reset(); + } - //------------------------------------------------------------------ - // Singleton accessors - static CMaterialManager s_cInstance; - inline static CMaterialManager& Instance () - { - return s_cInstance; - } + public: - //------------------------------------------------------------------ - // 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); + //------------------------------------------------------------------ + // Singleton accessors + static CMaterialManager s_cInstance; + inline static CMaterialManager& Instance() + { + return s_cInstance; + } - //------------------------------------------------------------------ - // 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); + //------------------------------------------------------------------ + // Delete all resources of a given material + // + // Must be called before CreateMaterial() to prevent memory leaking + void DeleteMaterial( AssetHelper::MeshHelper* pcIn ); - //------------------------------------------------------------------ - // End the material for a given mesh - // Called after mesh rendering is complete - // pcMesh Mesh object - int EndMaterial (AssetHelper::MeshHelper* pcMesh); + //------------------------------------------------------------------ + // 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 ); - //------------------------------------------------------------------ - // 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(); + //------------------------------------------------------------------ + // 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 ); - //------------------------------------------------------------------ - // 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); + //------------------------------------------------------------------ + // End the material for a given mesh + // Called after mesh rendering is complete + // pcMesh Mesh object + int EndMaterial( AssetHelper::MeshHelper* pcMesh ); - //------------------------------------------------------------------ - // 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); + //------------------------------------------------------------------ + // 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; - } + //------------------------------------------------------------------ + // 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(); - } + //------------------------------------------------------------------ + // 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: + 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); + //------------------------------------------------------------------ + // 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); + //------------------------------------------------------------------ + // 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); + //------------------------------------------------------------------ + // 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); + //------------------------------------------------------------------ + // 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: + 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; + // + // 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 TextureCache; - TextureCache sCachedTextures; -}; + typedef std::map TextureCache; + TextureCache sCachedTextures; + }; -#endif //!! include guard +} diff --git a/tools/assimp_view/MeshRenderer.cpp b/tools/assimp_view/MeshRenderer.cpp index d17bd2f8d..f2c3a0bc6 100644 --- a/tools/assimp_view/MeshRenderer.cpp +++ b/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 @@ -47,7 +46,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace AssimpView { - CMeshRenderer CMeshRenderer::s_cInstance; //------------------------------------------------------------------------------- diff --git a/tools/assimp_view/MeshRenderer.h b/tools/assimp_view/MeshRenderer.h index 98d9ef39d..2e9df0616 100644 --- a/tools/assimp_view/MeshRenderer.h +++ b/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) #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 \ No newline at end of file diff --git a/tools/assimp_view/MessageProc.cpp b/tools/assimp_view/MessageProc.cpp index 0b95a8ec6..ecffa40a6 100644 --- a/tools/assimp_view/MessageProc.cpp +++ b/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 +#include + #include namespace AssimpView { +using namespace Assimp; + // Static array to keep custom color values COLORREF g_aclCustomColors[16] = {0}; @@ -1044,9 +1048,9 @@ void DoExport(size_t formatId) ai_assert(strlen(szFileName) <= MAX_PATH); // invent a nice default file name - char* sz = std::max(strrchr(szFileName,'\\'),strrchr(szFileName,'/')); + char* sz = max(strrchr(szFileName,'\\'),strrchr(szFileName,'/')); 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 { diff --git a/tools/assimp_view/Normals.cpp b/tools/assimp_view/Normals.cpp index 9f4bea6fe..4ea067357 100644 --- a/tools/assimp_view/Normals.cpp +++ b/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" // 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 { +using namespace Assimp; bool g_bWasFlipped = false; float g_smoothAngle = 80.f; diff --git a/tools/assimp_view/SceneAnimator.cpp b/tools/assimp_view/SceneAnimator.cpp index 0df269d35..7eed88724 100644 --- a/tools/assimp_view/SceneAnimator.cpp +++ b/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 */ -#include "stdafx.h" #include "assimp_view.h" using namespace AssimpView; diff --git a/tools/assimp_view/Shaders.cpp b/tools/assimp_view/Shaders.cpp index ce030a7ec..7fb0bd4c2 100644 --- a/tools/assimp_view/Shaders.cpp +++ b/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. --------------------------------------------------------------------------- */ - -#include "stdafx.h" #include "assimp_view.h" - -namespace AssimpView -{ +namespace AssimpView { // ------------------------------------------------------------------------------------------------ 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" + // 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" + // Vertex shader output structure for pixel shader usage + "struct VS_OUTPUT\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" - "};\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" - "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" - "return Out;\n" - "}\n" + "return Out;\n" + "}\n" - // Pixel shader - "float4 RenderNormalsPS() : COLOR\n" - "{\n" - "return OUTPUT_COLOR;\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 (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" + // 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" "ColorArg0[0] = Diffuse;\n" "AlphaOp[0] = SelectArg1;\n" "AlphaArg0[0] = Diffuse;\n" - "}\n" - "};\n" - ); + "}\n" + "};\n" + ); // ------------------------------------------------------------------------------------------------ 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" + // 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" + "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" + // 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 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" + // 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" + // 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" + // 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" + "return Out;\n" + "}\n" - // Pixel shader - "float4 RenderSkyBoxPS(float3 Texture0 : TEXCOORD0) : COLOR\n" - "{\n" - // Lookup the skybox texture - "return texCUBE(EnvironmentMapSampler,Texture0) ;\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" + // 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" + "PixelShader = compile ps_2_0 RenderSkyBoxPS();\n" + "VertexShader = compile vs_2_0 RenderSkyBoxVS();\n" + "}\n" + "};\n" // -------------- same for static background image ----------------- - "texture TEXTURE_2D;\n" - "sampler TEXTURE_SAMPLER = sampler_state\n" - "{\n" - "Texture = (TEXTURE_2D);\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" + "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" + "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" + "Out.Position.xy = INPosition.xy;\n" + "Out.Position.z = Out.Position.w = 1.0f;\n" + "Out.TexCoord0 = INTexCoord0;\n" - "return Out;\n" - "}\n" + "return Out;\n" + "}\n" - "float4 RenderImagePS(float2 IN : TEXCOORD0) : COLOR\n" - "{\n" - "return tex2D(TEXTURE_SAMPLER,IN);\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" - ); + // 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( - // 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" - "float4x3 gBoneMatrix[60]; \n" + "float4x3 gBoneMatrix[60]; \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" - "float4 BlendIndices : BLENDINDICES;\n" - "float4 BlendWeights : BLENDWEIGHT;\n" + "float4 BlendIndices : BLENDINDICES;\n" + "float4 BlendWeights : BLENDWEIGHT;\n" // "#endif // AV_SKINNING \n" - "};\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 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 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" + // Vertex shader for pixel shader usage + "VS_OUTPUT DefaultVShader(VS_INPUT IN)\n" + "{\n" + "VS_OUTPUT Out;\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" // "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.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" - "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" // "float3 objPos = IN.Position; \n" // "#endif // AV_SKINNING \n" - // Multiply with the WorldViewProjection matrix - "Out.Position = mul( float4( objPos, 1.0f), WorldViewProjection);\n" + // Multiply with the WorldViewProjection matrix + "Out.Position = mul( float4( objPos, 1.0f), WorldViewProjection);\n" - "float3 worldNormal = normalize( mul( IN.Normal, (float3x3) WorldInverseTranspose)); \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" + // 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" + // 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" + "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" + "{\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" + // 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" + "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" + "{\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" + "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[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" + "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" + "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" + "{\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 + "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 (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" + // 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( - // World * View * Projection matrix + // 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" - - "#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 = ;\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 = ;\n" - "};\n" - "#endif // AV_DIFFUSE_TEXTUR2\n" - - "#ifdef AV_SPECULAR_TEXTURE\n" - "texture SPECULAR_TEXTURE;\n" - "sampler SPECULAR_SAMPLER\n" - "{\n" - "Texture = ;\n" - "};\n" - "#endif // AV_SPECULAR_TEXTUR\n" - - "#ifdef AV_AMBIENT_TEXTURE\n" - "texture AMBIENT_TEXTURE;\n" - "sampler AMBIENT_SAMPLER\n" - "{\n" - "Texture = ;\n" - "};\n" - "#endif // AV_AMBIENT_TEXTUR\n" - - "#ifdef AV_LIGHTMAP_TEXTURE\n" - "texture LIGHTMAP_TEXTURE;\n" - "sampler LIGHTMAP_SAMPLER\n" - "{\n" - "Texture = ;\n" - "};\n" - "#endif // AV_LIGHTMAP_TEXTURE\n" - - "#ifdef AV_OPACITY_TEXTURE\n" - "texture OPACITY_TEXTURE;\n" - "sampler OPACITY_SAMPLER\n" - "{\n" - "Texture = ;\n" - "};\n" - "#endif // AV_OPACITY_TEXTURE\n" - - "#ifdef AV_EMISSIVE_TEXTURE\n" - "texture EMISSIVE_TEXTURE;\n" - "sampler EMISSIVE_SAMPLER\n" - "{\n" - "Texture = ;\n" - "};\n" - "#endif // AV_EMISSIVE_TEXTUR\n" - - "#ifdef AV_NORMAL_TEXTURE\n" - "texture NORMAL_TEXTURE;\n" - "sampler NORMAL_SAMPLER\n" - "{\n" - "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 = ;\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 = ;\n" + "};\n" + "#endif // AV_DIFFUSE_TEXTUR2\n" + + "#ifdef AV_SPECULAR_TEXTURE\n" + "texture SPECULAR_TEXTURE;\n" + "sampler SPECULAR_SAMPLER\n" + "{\n" + "Texture = ;\n" + "};\n" + "#endif // AV_SPECULAR_TEXTUR\n" + + "#ifdef AV_AMBIENT_TEXTURE\n" + "texture AMBIENT_TEXTURE;\n" + "sampler AMBIENT_SAMPLER\n" + "{\n" + "Texture = ;\n" + "};\n" + "#endif // AV_AMBIENT_TEXTUR\n" + + "#ifdef AV_LIGHTMAP_TEXTURE\n" + "texture LIGHTMAP_TEXTURE;\n" + "sampler LIGHTMAP_SAMPLER\n" + "{\n" + "Texture = ;\n" + "};\n" + "#endif // AV_LIGHTMAP_TEXTURE\n" + + "#ifdef AV_OPACITY_TEXTURE\n" + "texture OPACITY_TEXTURE;\n" + "sampler OPACITY_SAMPLER\n" + "{\n" + "Texture = ;\n" + "};\n" + "#endif // AV_OPACITY_TEXTURE\n" + + "#ifdef AV_EMISSIVE_TEXTURE\n" + "texture EMISSIVE_TEXTURE;\n" + "sampler EMISSIVE_SAMPLER\n" + "{\n" + "Texture = ;\n" + "};\n" + "#endif // AV_EMISSIVE_TEXTUR\n" + + "#ifdef AV_NORMAL_TEXTURE\n" + "texture NORMAL_TEXTURE;\n" + "sampler NORMAL_SAMPLER\n" + "{\n" + "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( - "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 - "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 - "VS_OUTPUT DefaultVShader(float4 INPosition : POSITION, float2 INTexCoord0 : TEXCOORD0 )\n" - "{\n" - "VS_OUTPUT Out;\n" + "VS_OUTPUT DefaultVShader(float4 INPosition : POSITION, float2 INTexCoord0 : TEXCOORD0 )\n" + "{\n" + "VS_OUTPUT Out;\n" - "Out.Position = INPosition;\n" - "Out.TexCoord0 = INTexCoord0;\n" + "Out.Position = INPosition;\n" + "Out.TexCoord0 = INTexCoord0;\n" - "return Out;\n" - "}\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" + // 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 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" + // 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" + // 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 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" + // 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" + // 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" "ColorArg0[0] = Texture;\n" "AlphaOp[0] = SelectArg1;\n" "AlphaArg0[0] = Texture;\n" - "}\n" - "};\n" + "}\n" + "};\n" ); 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 - "struct VS_OUTPUT\n" - "{\n" - "float4 Position : POSITION;\n" - "};\n" + "struct VS_OUTPUT\n" + "{\n" + "float4 Position : POSITION;\n" + "};\n" // vertex shader - "VS_OUTPUT DefaultVShader(float4 INPosition : POSITION, float2 INTexCoord0 : TEXCOORD0 )\n" - "{\n" - "VS_OUTPUT Out;\n" + "VS_OUTPUT DefaultVShader(float4 INPosition : POSITION, float2 INTexCoord0 : TEXCOORD0 )\n" + "{\n" + "VS_OUTPUT Out;\n" - "Out.Position = INPosition;\n" - "return Out;\n" - "}\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" - ); - }; \ No newline at end of file + // 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" + ); + }; \ No newline at end of file diff --git a/tools/assimp_view/assimp_view.cpp b/tools/assimp_view/assimp_view.cpp index f3c261e92..e88a7035e 100644 --- a/tools/assimp_view/assimp_view.cpp +++ b/tools/assimp_view/assimp_view.cpp @@ -40,16 +40,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "stdafx.h" #include "assimp_view.h" #include + using namespace std; namespace AssimpView { +extern std::string g_szNormalsShader; +extern std::string g_szDefaultShader; +extern std::string g_szPassThroughShader; -//------------------------------------------------------------------------------- -// evil globals //------------------------------------------------------------------------------- HINSTANCE g_hInstance = NULL; HWND g_hDlg = NULL; @@ -78,19 +79,19 @@ double g_dCurrent = 0.; // default pp steps unsigned int ppsteps = aiProcess_CalcTangentSpace | // calculate tangents and bitangents if possible - aiProcess_JoinIdenticalVertices | // join identical vertices/ optimize indexing - aiProcess_ValidateDataStructure | // perform a full validation of the loader's output - aiProcess_ImproveCacheLocality | // improve the cache locality of the output vertices - aiProcess_RemoveRedundantMaterials | // remove redundant materials - aiProcess_FindDegenerates | // remove degenerated polygons from the import - aiProcess_FindInvalidData | // detect invalid model data, such as invalid normal vectors - aiProcess_GenUVCoords | // convert spherical, cylindrical, box and planar mapping to proper UVs - aiProcess_TransformUVCoords | // preprocess UV transformations (scaling, translation ...) - aiProcess_FindInstances | // search for instanced meshes and remove them by references to one master - aiProcess_LimitBoneWeights | // limit bone weights to 4 per vertex - aiProcess_OptimizeMeshes | // join small meshes, if possible; - aiProcess_SplitByBoneCount | // split meshes with too many bones. Necessary for our (limited) hardware skinning shader - 0; + aiProcess_JoinIdenticalVertices | // join identical vertices/ optimize indexing + aiProcess_ValidateDataStructure | // perform a full validation of the loader's output + aiProcess_ImproveCacheLocality | // improve the cache locality of the output vertices + aiProcess_RemoveRedundantMaterials | // remove redundant materials + aiProcess_FindDegenerates | // remove degenerated polygons from the import + aiProcess_FindInvalidData | // detect invalid model data, such as invalid normal vectors + aiProcess_GenUVCoords | // convert spherical, cylindrical, box and planar mapping to proper UVs + aiProcess_TransformUVCoords | // preprocess UV transformations (scaling, translation ...) + aiProcess_FindInstances | // search for instanced meshes and remove them by references to one master + aiProcess_LimitBoneWeights | // limit bone weights to 4 per vertex + aiProcess_OptimizeMeshes | // join small meshes, if possible; + aiProcess_SplitByBoneCount | // split meshes with too many bones. Necessary for our (limited) hardware skinning shader + 0; unsigned int ppstepsdefault = ppsteps; @@ -108,9 +109,9 @@ aiVector3D g_avLightDirs[1] = D3DCOLOR g_avLightColors[3] = { - D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0xFF), - D3DCOLOR_ARGB(0xFF,0xFF,0x00,0x00), - D3DCOLOR_ARGB(0xFF,0x05,0x05,0x05), + D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0xFF), + D3DCOLOR_ARGB(0xFF,0xFF,0x00,0x00), + D3DCOLOR_ARGB(0xFF,0x05,0x05,0x05), }; POINT g_mousePos; @@ -143,53 +144,53 @@ float g_fLoadTime = 0.0f; //------------------------------------------------------------------------------- DWORD WINAPI LoadThreadProc(LPVOID lpParameter) { - UNREFERENCED_PARAMETER(lpParameter); + UNREFERENCED_PARAMETER(lpParameter); - // get current time - double fCur = (double)timeGetTime(); + // get current time + double fCur = (double)timeGetTime(); - aiPropertyStore* props = aiCreatePropertyStore(); - aiSetImportPropertyInteger(props,AI_CONFIG_IMPORT_TER_MAKE_UVS,1); - aiSetImportPropertyFloat(props,AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE,g_smoothAngle); - aiSetImportPropertyInteger(props,AI_CONFIG_PP_SBP_REMOVE,nopointslines ? aiPrimitiveType_LINE | aiPrimitiveType_POINT : 0 ); + aiPropertyStore* props = aiCreatePropertyStore(); + aiSetImportPropertyInteger(props,AI_CONFIG_IMPORT_TER_MAKE_UVS,1); + aiSetImportPropertyFloat(props,AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE,g_smoothAngle); + aiSetImportPropertyInteger(props,AI_CONFIG_PP_SBP_REMOVE,nopointslines ? aiPrimitiveType_LINE | aiPrimitiveType_POINT : 0 ); - aiSetImportPropertyInteger(props,AI_CONFIG_GLOB_MEASURE_TIME,1); - //aiSetImportPropertyInteger(props,AI_CONFIG_PP_PTV_KEEP_HIERARCHY,1); + aiSetImportPropertyInteger(props,AI_CONFIG_GLOB_MEASURE_TIME,1); + //aiSetImportPropertyInteger(props,AI_CONFIG_PP_PTV_KEEP_HIERARCHY,1); - // Call ASSIMPs C-API to load the file - g_pcAsset->pcScene = (aiScene*)aiImportFileExWithProperties(g_szFileName, + // Call ASSIMPs C-API to load the file + g_pcAsset->pcScene = (aiScene*)aiImportFileExWithProperties(g_szFileName, - ppsteps | /* configurable pp steps */ - aiProcess_GenSmoothNormals | // generate smooth normal vectors if not existing - aiProcess_SplitLargeMeshes | // split large, unrenderable meshes into submeshes - aiProcess_Triangulate | // triangulate polygons with more than 3 edges - aiProcess_ConvertToLeftHanded | // convert everything to D3D left handed space - aiProcess_SortByPType | // make 'clean' meshes which consist of a single typ of primitives - 0, - NULL, - props); + ppsteps | /* configurable pp steps */ + aiProcess_GenSmoothNormals | // generate smooth normal vectors if not existing + aiProcess_SplitLargeMeshes | // split large, unrenderable meshes into submeshes + aiProcess_Triangulate | // triangulate polygons with more than 3 edges + aiProcess_ConvertToLeftHanded | // convert everything to D3D left handed space + aiProcess_SortByPType | // make 'clean' meshes which consist of a single typ of primitives + 0, + NULL, + props); - aiReleasePropertyStore(props); + aiReleasePropertyStore(props); - // get the end time of zje operation, calculate delta t - double fEnd = (double)timeGetTime(); - g_fLoadTime = (float)((fEnd - fCur) / 1000); + // get the end time of zje operation, calculate delta t + double fEnd = (double)timeGetTime(); + g_fLoadTime = (float)((fEnd - fCur) / 1000); // char szTemp[128]; - g_bLoadingFinished = true; + g_bLoadingFinished = true; - // check whether the loading process has failed ... - if (NULL == g_pcAsset->pcScene) - { - CLogDisplay::Instance().AddEntry("[ERROR] Unable to load this asset:", - D3DCOLOR_ARGB(0xFF,0xFF,0,0)); + // check whether the loading process has failed ... + if (NULL == g_pcAsset->pcScene) + { + CLogDisplay::Instance().AddEntry("[ERROR] Unable to load this asset:", + D3DCOLOR_ARGB(0xFF,0xFF,0,0)); - // print ASSIMPs error string to the log display - CLogDisplay::Instance().AddEntry(aiGetErrorString(), - D3DCOLOR_ARGB(0xFF,0xFF,0,0)); - return 1; - } + // print ASSIMPs error string to the log display + CLogDisplay::Instance().AddEntry(aiGetErrorString(), + D3DCOLOR_ARGB(0xFF,0xFF,0,0)); + return 1; + } - return 0; + return 0; } //------------------------------------------------------------------------------- @@ -198,102 +199,102 @@ DWORD WINAPI LoadThreadProc(LPVOID lpParameter) //------------------------------------------------------------------------------- int LoadAsset(void) { - // set the world and world rotation matrices to the identuty - g_mWorldRotate = aiMatrix4x4(); - g_mWorld = aiMatrix4x4(); + // set the world and world rotation matrices to the identuty + g_mWorldRotate = aiMatrix4x4(); + g_mWorld = aiMatrix4x4(); // char szTemp[MAX_PATH+64]; // sprintf(szTemp,"Starting to load %s",g_szFileName); - CLogWindow::Instance().WriteLine( - "----------------------------------------------------------------------------"); + CLogWindow::Instance().WriteLine( + "----------------------------------------------------------------------------"); // CLogWindow::Instance().WriteLine(szTemp); // CLogWindow::Instance().WriteLine( // "----------------------------------------------------------------------------"); - CLogWindow::Instance().SetAutoUpdate(false); + CLogWindow::Instance().SetAutoUpdate(false); - // create a helper thread to load the asset - DWORD dwID; - g_bLoadingCanceled = false; - g_pcAsset = new AssetHelper(); - g_hThreadHandle = CreateThread(NULL,0,&LoadThreadProc,NULL,0,&dwID); + // create a helper thread to load the asset + DWORD dwID; + g_bLoadingCanceled = false; + g_pcAsset = new AssetHelper(); + g_hThreadHandle = CreateThread(NULL,0,&LoadThreadProc,NULL,0,&dwID); - if (!g_hThreadHandle) - { - CLogDisplay::Instance().AddEntry( - "[ERROR] Unable to create helper thread for loading", - D3DCOLOR_ARGB(0xFF,0xFF,0,0)); - return 0; - } + if (!g_hThreadHandle) + { + CLogDisplay::Instance().AddEntry( + "[ERROR] Unable to create helper thread for loading", + D3DCOLOR_ARGB(0xFF,0xFF,0,0)); + return 0; + } - // show the progress bar dialog - DialogBox(g_hInstance,MAKEINTRESOURCE(IDD_LOADDIALOG), - g_hDlg,&ProgressMessageProc); + // show the progress bar dialog + DialogBox(g_hInstance,MAKEINTRESOURCE(IDD_LOADDIALOG), + g_hDlg,&ProgressMessageProc); - // update the log window - CLogWindow::Instance().SetAutoUpdate(true); - CLogWindow::Instance().Update(); + // update the log window + CLogWindow::Instance().SetAutoUpdate(true); + CLogWindow::Instance().Update(); - // now we should have loaded the asset. Check this ... - g_bLoadingFinished = false; - if (!g_pcAsset || !g_pcAsset->pcScene) - { - if (g_pcAsset) - { - delete g_pcAsset; - g_pcAsset = NULL; - } - return 0; - } + // now we should have loaded the asset. Check this ... + g_bLoadingFinished = false; + if (!g_pcAsset || !g_pcAsset->pcScene) + { + if (g_pcAsset) + { + delete g_pcAsset; + g_pcAsset = NULL; + } + return 0; + } - // allocate a new MeshHelper array and build a new instance - // for each mesh in the original asset - g_pcAsset->apcMeshes = new AssetHelper::MeshHelper*[g_pcAsset->pcScene->mNumMeshes](); - for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i) - g_pcAsset->apcMeshes[i] = new AssetHelper::MeshHelper(); + // allocate a new MeshHelper array and build a new instance + // for each mesh in the original asset + g_pcAsset->apcMeshes = new AssetHelper::MeshHelper*[g_pcAsset->pcScene->mNumMeshes](); + for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i) + g_pcAsset->apcMeshes[i] = new AssetHelper::MeshHelper(); - // create animator - g_pcAsset->mAnimator = new SceneAnimator( g_pcAsset->pcScene); + // create animator + g_pcAsset->mAnimator = new SceneAnimator( g_pcAsset->pcScene); - // build a new caption string for the viewer - char szOut[MAX_PATH + 10]; - sprintf(szOut,AI_VIEW_CAPTION_BASE " [%s]",g_szFileName); - SetWindowText(g_hDlg,szOut); + // build a new caption string for the viewer + char szOut[MAX_PATH + 10]; + sprintf(szOut,AI_VIEW_CAPTION_BASE " [%s]",g_szFileName); + SetWindowText(g_hDlg,szOut); - // scale the asset vertices to fit into the viewer window - ScaleAsset(); + // scale the asset vertices to fit into the viewer window + ScaleAsset(); - // reset the camera view to the default position - g_sCamera.vPos = aiVector3D(0.0f,0.0f,-10.0f); - g_sCamera.vLookAt = aiVector3D(0.0f,0.0f,1.0f); - g_sCamera.vUp = aiVector3D(0.0f,1.0f,0.0f); - g_sCamera.vRight = aiVector3D(0.0f,1.0f,0.0f); + // reset the camera view to the default position + g_sCamera.vPos = aiVector3D(0.0f,0.0f,-10.0f); + g_sCamera.vLookAt = aiVector3D(0.0f,0.0f,1.0f); + g_sCamera.vUp = aiVector3D(0.0f,1.0f,0.0f); + g_sCamera.vRight = aiVector3D(0.0f,1.0f,0.0f); - // build native D3D vertex/index buffers, textures, materials - if( 1 != CreateAssetData()) - return 0; + // build native D3D vertex/index buffers, textures, materials + if( 1 != CreateAssetData()) + return 0; - if (!g_pcAsset->pcScene->HasAnimations()) { - EnableWindow(GetDlgItem(g_hDlg,IDC_PLAY),FALSE); - EnableWindow(GetDlgItem(g_hDlg,IDC_SLIDERANIM),FALSE); - } - else { - EnableWindow(GetDlgItem(g_hDlg,IDC_PLAY),TRUE); - EnableWindow(GetDlgItem(g_hDlg,IDC_SLIDERANIM),TRUE); - } + if (!g_pcAsset->pcScene->HasAnimations()) { + EnableWindow(GetDlgItem(g_hDlg,IDC_PLAY),FALSE); + EnableWindow(GetDlgItem(g_hDlg,IDC_SLIDERANIM),FALSE); + } + else { + EnableWindow(GetDlgItem(g_hDlg,IDC_PLAY),TRUE); + EnableWindow(GetDlgItem(g_hDlg,IDC_SLIDERANIM),TRUE); + } - CLogDisplay::Instance().AddEntry("[OK] The asset has been loaded successfully"); - CDisplay::Instance().FillDisplayList(); - CDisplay::Instance().FillAnimList(); + CLogDisplay::Instance().AddEntry("[OK] The asset has been loaded successfully"); + CDisplay::Instance().FillDisplayList(); + CDisplay::Instance().FillAnimList(); - CDisplay::Instance().FillDefaultStatistics(); - - // render the scene once - CDisplay::Instance().OnRender(); + CDisplay::Instance().FillDefaultStatistics(); + + // render the scene once + CDisplay::Instance().OnRender(); - g_pcAsset->iNormalSet = AssetHelper::ORIGINAL; - g_bWasFlipped = false; - return 1; + g_pcAsset->iNormalSet = AssetHelper::ORIGINAL; + g_bWasFlipped = false; + return 1; } @@ -303,33 +304,33 @@ int LoadAsset(void) //------------------------------------------------------------------------------- int DeleteAsset(void) { - if (!g_pcAsset)return 0; + if (!g_pcAsset)return 0; - // don't anymore know why this was necessary ... - CDisplay::Instance().OnRender(); + // don't anymore know why this was necessary ... + CDisplay::Instance().OnRender(); - // delete everything - DeleteAssetData(); - for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i) - { - delete g_pcAsset->apcMeshes[i]; - } - aiReleaseImport(g_pcAsset->pcScene); - delete[] g_pcAsset->apcMeshes; - delete g_pcAsset->mAnimator; - delete g_pcAsset; - g_pcAsset = NULL; + // delete everything + DeleteAssetData(); + for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i) + { + delete g_pcAsset->apcMeshes[i]; + } + aiReleaseImport(g_pcAsset->pcScene); + delete[] g_pcAsset->apcMeshes; + delete g_pcAsset->mAnimator; + delete g_pcAsset; + g_pcAsset = NULL; - // reset the caption of the viewer window - SetWindowText(g_hDlg,AI_VIEW_CAPTION_BASE); + // reset the caption of the viewer window + SetWindowText(g_hDlg,AI_VIEW_CAPTION_BASE); - // clear UI - CDisplay::Instance().ClearAnimList(); - CDisplay::Instance().ClearDisplayList(); + // clear UI + CDisplay::Instance().ClearAnimList(); + CDisplay::Instance().ClearDisplayList(); - CMaterialManager::Instance().Reset(); - UpdateWindow(g_hDlg); - return 1; + CMaterialManager::Instance().Reset(); + UpdateWindow(g_hDlg); + return 1; } @@ -341,39 +342,39 @@ int DeleteAsset(void) // piMatrix Transformation matrix of the graph at this position //------------------------------------------------------------------------------- int CalculateBounds(aiNode* piNode, aiVector3D* p_avOut, - const aiMatrix4x4& piMatrix) + const aiMatrix4x4& piMatrix) { - ai_assert(NULL != piNode); - ai_assert(NULL != p_avOut); + ai_assert(NULL != piNode); + ai_assert(NULL != p_avOut); - aiMatrix4x4 mTemp = piNode->mTransformation; - mTemp.Transpose(); - aiMatrix4x4 aiMe = mTemp * piMatrix; + aiMatrix4x4 mTemp = piNode->mTransformation; + mTemp.Transpose(); + aiMatrix4x4 aiMe = mTemp * piMatrix; - for (unsigned int i = 0; i < piNode->mNumMeshes;++i) - { - for( unsigned int a = 0; a < g_pcAsset->pcScene->mMeshes[ - piNode->mMeshes[i]]->mNumVertices;++a) - { - aiVector3D pc =g_pcAsset->pcScene->mMeshes[piNode->mMeshes[i]]->mVertices[a]; + for (unsigned int i = 0; i < piNode->mNumMeshes;++i) + { + for( unsigned int a = 0; a < g_pcAsset->pcScene->mMeshes[ + piNode->mMeshes[i]]->mNumVertices;++a) + { + aiVector3D pc =g_pcAsset->pcScene->mMeshes[piNode->mMeshes[i]]->mVertices[a]; - aiVector3D pc1; - D3DXVec3TransformCoord((D3DXVECTOR3*)&pc1,(D3DXVECTOR3*)&pc, - (D3DXMATRIX*)&aiMe); + aiVector3D pc1; + D3DXVec3TransformCoord((D3DXVECTOR3*)&pc1,(D3DXVECTOR3*)&pc, + (D3DXMATRIX*)&aiMe); - p_avOut[0].x = std::min( p_avOut[0].x, pc1.x); - p_avOut[0].y = std::min( p_avOut[0].y, pc1.y); - p_avOut[0].z = std::min( p_avOut[0].z, pc1.z); - p_avOut[1].x = std::max( p_avOut[1].x, pc1.x); - p_avOut[1].y = std::max( p_avOut[1].y, pc1.y); - p_avOut[1].z = std::max( p_avOut[1].z, pc1.z); - } - } - for (unsigned int i = 0; i < piNode->mNumChildren;++i) - { - CalculateBounds( piNode->mChildren[i], p_avOut, aiMe ); - } - return 1; + p_avOut[0].x = min( p_avOut[0].x, pc1.x); + p_avOut[0].y = min( p_avOut[0].y, pc1.y); + p_avOut[0].z = min( p_avOut[0].z, pc1.z); + p_avOut[1].x = max( p_avOut[1].x, pc1.x); + p_avOut[1].y = max( p_avOut[1].y, pc1.y); + p_avOut[1].z = max( p_avOut[1].z, pc1.z); + } + } + for (unsigned int i = 0; i < piNode->mNumChildren;++i) + { + CalculateBounds( piNode->mChildren[i], p_avOut, aiMe ); + } + return 1; } //------------------------------------------------------------------------------- // Scale the asset that it fits perfectly into the viewer window @@ -382,30 +383,30 @@ int CalculateBounds(aiNode* piNode, aiVector3D* p_avOut, //------------------------------------------------------------------------------- int ScaleAsset(void) { - aiVector3D aiVecs[2] = {aiVector3D( 1e10f, 1e10f, 1e10f), - aiVector3D( -1e10f, -1e10f, -1e10f) }; + aiVector3D aiVecs[2] = {aiVector3D( 1e10f, 1e10f, 1e10f), + aiVector3D( -1e10f, -1e10f, -1e10f) }; - if (g_pcAsset->pcScene->mRootNode) - { - aiMatrix4x4 m; - CalculateBounds(g_pcAsset->pcScene->mRootNode,aiVecs,m); - } + if (g_pcAsset->pcScene->mRootNode) + { + aiMatrix4x4 m; + CalculateBounds(g_pcAsset->pcScene->mRootNode,aiVecs,m); + } - aiVector3D vDelta = aiVecs[1]-aiVecs[0]; - aiVector3D vHalf = aiVecs[0] + (vDelta / 2.0f); - float fScale = 10.0f / vDelta.Length(); + aiVector3D vDelta = aiVecs[1]-aiVecs[0]; + aiVector3D vHalf = aiVecs[0] + (vDelta / 2.0f); + float fScale = 10.0f / vDelta.Length(); - g_mWorld = aiMatrix4x4( - 1.0f,0.0f,0.0f,0.0f, - 0.0f,1.0f,0.0f,0.0f, - 0.0f,0.0f,1.0f,0.0f, - -vHalf.x,-vHalf.y,-vHalf.z,1.0f) * - aiMatrix4x4( - fScale,0.0f,0.0f,0.0f, - 0.0f,fScale,0.0f,0.0f, - 0.0f,0.0f,fScale,0.0f, - 0.0f,0.0f,0.0f,1.0f); - return 1; + g_mWorld = aiMatrix4x4( + 1.0f,0.0f,0.0f,0.0f, + 0.0f,1.0f,0.0f,0.0f, + 0.0f,0.0f,1.0f,0.0f, + -vHalf.x,-vHalf.y,-vHalf.z,1.0f) * + aiMatrix4x4( + fScale,0.0f,0.0f,0.0f, + 0.0f,fScale,0.0f,0.0f, + 0.0f,0.0f,fScale,0.0f, + 0.0f,0.0f,0.0f,1.0f); + return 1; } //------------------------------------------------------------------------------- @@ -416,48 +417,48 @@ int ScaleAsset(void) //------------------------------------------------------------------------------- int GenerateNormalsAsLineList(AssetHelper::MeshHelper* pcMesh,const aiMesh* pcSource) { - ai_assert(NULL != pcMesh); - ai_assert(NULL != pcSource); + ai_assert(NULL != pcMesh); + ai_assert(NULL != pcSource); - if (!pcSource->mNormals)return 0; + if (!pcSource->mNormals)return 0; - // create vertex buffer - if(FAILED( g_piDevice->CreateVertexBuffer(sizeof(AssetHelper::LineVertex) * - pcSource->mNumVertices * 2, - D3DUSAGE_WRITEONLY, - AssetHelper::LineVertex::GetFVF(), - D3DPOOL_DEFAULT, &pcMesh->piVBNormals,NULL))) - { - CLogDisplay::Instance().AddEntry("Failed to create vertex buffer for the normal list", - D3DCOLOR_ARGB(0xFF,0xFF,0,0)); - return 2; - } + // create vertex buffer + if(FAILED( g_piDevice->CreateVertexBuffer(sizeof(AssetHelper::LineVertex) * + pcSource->mNumVertices * 2, + D3DUSAGE_WRITEONLY, + AssetHelper::LineVertex::GetFVF(), + D3DPOOL_DEFAULT, &pcMesh->piVBNormals,NULL))) + { + CLogDisplay::Instance().AddEntry("Failed to create vertex buffer for the normal list", + D3DCOLOR_ARGB(0xFF,0xFF,0,0)); + return 2; + } - // now fill the vertex buffer with data - AssetHelper::LineVertex* pbData2; - pcMesh->piVBNormals->Lock(0,0,(void**)&pbData2,0); - for (unsigned int x = 0; x < pcSource->mNumVertices;++x) - { - pbData2->vPosition = pcSource->mVertices[x]; + // now fill the vertex buffer with data + AssetHelper::LineVertex* pbData2; + pcMesh->piVBNormals->Lock(0,0,(void**)&pbData2,0); + for (unsigned int x = 0; x < pcSource->mNumVertices;++x) + { + pbData2->vPosition = pcSource->mVertices[x]; - ++pbData2; + ++pbData2; - aiVector3D vNormal = pcSource->mNormals[x]; - vNormal.Normalize(); + aiVector3D vNormal = pcSource->mNormals[x]; + vNormal.Normalize(); - // scalo with the inverse of the world scaling to make sure - // the normals have equal length in each case - // TODO: Check whether this works in every case, I don't think so - vNormal.x /= g_mWorld.a1*4; - vNormal.y /= g_mWorld.b2*4; - vNormal.z /= g_mWorld.c3*4; + // scalo with the inverse of the world scaling to make sure + // the normals have equal length in each case + // TODO: Check whether this works in every case, I don't think so + vNormal.x /= g_mWorld.a1*4; + vNormal.y /= g_mWorld.b2*4; + vNormal.z /= g_mWorld.c3*4; - pbData2->vPosition = pcSource->mVertices[x] + vNormal; + pbData2->vPosition = pcSource->mVertices[x] + vNormal; - ++pbData2; - } - pcMesh->piVBNormals->Unlock(); - return 1; + ++pbData2; + } + pcMesh->piVBNormals->Unlock(); + return 1; } //------------------------------------------------------------------------------- @@ -466,184 +467,184 @@ int GenerateNormalsAsLineList(AssetHelper::MeshHelper* pcMesh,const aiMesh* pcSo //------------------------------------------------------------------------------- int CreateAssetData() { - if (!g_pcAsset)return 0; + if (!g_pcAsset)return 0; - // reset all subsystems - CMaterialManager::Instance().Reset(); - CDisplay::Instance().Reset(); + // reset all subsystems + CMaterialManager::Instance().Reset(); + CDisplay::Instance().Reset(); - for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i) - { - const aiMesh* mesh = g_pcAsset->pcScene->mMeshes[i]; + for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i) + { + const aiMesh* mesh = g_pcAsset->pcScene->mMeshes[i]; - // create the material for the mesh - if (!g_pcAsset->apcMeshes[i]->piEffect) { - CMaterialManager::Instance().CreateMaterial( - g_pcAsset->apcMeshes[i],mesh); - } + // create the material for the mesh + if (!g_pcAsset->apcMeshes[i]->piEffect) { + CMaterialManager::Instance().CreateMaterial( + g_pcAsset->apcMeshes[i],mesh); + } - // create vertex buffer - if(FAILED( g_piDevice->CreateVertexBuffer(sizeof(AssetHelper::Vertex) * - mesh->mNumVertices, - D3DUSAGE_WRITEONLY, - 0, - D3DPOOL_DEFAULT, &g_pcAsset->apcMeshes[i]->piVB,NULL))) { - MessageBox(g_hDlg,"Failed to create vertex buffer", - "ASSIMP Viewer Utility",MB_OK); - return 2; - } + // create vertex buffer + if(FAILED( g_piDevice->CreateVertexBuffer(sizeof(AssetHelper::Vertex) * + mesh->mNumVertices, + D3DUSAGE_WRITEONLY, + 0, + D3DPOOL_DEFAULT, &g_pcAsset->apcMeshes[i]->piVB,NULL))) { + MessageBox(g_hDlg,"Failed to create vertex buffer", + "ASSIMP Viewer Utility",MB_OK); + return 2; + } - DWORD dwUsage = 0; - if (g_pcAsset->apcMeshes[i]->piOpacityTexture || 1.0f != g_pcAsset->apcMeshes[i]->fOpacity) - dwUsage |= D3DUSAGE_DYNAMIC; + DWORD dwUsage = 0; + if (g_pcAsset->apcMeshes[i]->piOpacityTexture || 1.0f != g_pcAsset->apcMeshes[i]->fOpacity) + dwUsage |= D3DUSAGE_DYNAMIC; - unsigned int nidx; - switch (mesh->mPrimitiveTypes) { - case aiPrimitiveType_POINT: - nidx = 1;break; - case aiPrimitiveType_LINE: - nidx = 2;break; - case aiPrimitiveType_TRIANGLE: - nidx = 3;break; - default: ai_assert(false); - }; + unsigned int nidx; + switch (mesh->mPrimitiveTypes) { + case aiPrimitiveType_POINT: + nidx = 1;break; + case aiPrimitiveType_LINE: + nidx = 2;break; + case aiPrimitiveType_TRIANGLE: + nidx = 3;break; + default: ai_assert(false); + }; - // check whether we can use 16 bit indices - if (mesh->mNumFaces * 3 >= 65536) { - // create 32 bit index buffer - if(FAILED( g_piDevice->CreateIndexBuffer( 4 * - mesh->mNumFaces * nidx, - D3DUSAGE_WRITEONLY | dwUsage, - D3DFMT_INDEX32, - D3DPOOL_DEFAULT, - &g_pcAsset->apcMeshes[i]->piIB, - NULL))) - { - MessageBox(g_hDlg,"Failed to create 32 Bit index buffer", - "ASSIMP Viewer Utility",MB_OK); - return 2; - } + // check whether we can use 16 bit indices + if (mesh->mNumFaces * 3 >= 65536) { + // create 32 bit index buffer + if(FAILED( g_piDevice->CreateIndexBuffer( 4 * + mesh->mNumFaces * nidx, + D3DUSAGE_WRITEONLY | dwUsage, + D3DFMT_INDEX32, + D3DPOOL_DEFAULT, + &g_pcAsset->apcMeshes[i]->piIB, + NULL))) + { + MessageBox(g_hDlg,"Failed to create 32 Bit index buffer", + "ASSIMP Viewer Utility",MB_OK); + return 2; + } - // now fill the index buffer - unsigned int* pbData; - g_pcAsset->apcMeshes[i]->piIB->Lock(0,0,(void**)&pbData,0); - for (unsigned int x = 0; x < mesh->mNumFaces;++x) - { - for (unsigned int a = 0; a < nidx;++a) - { - *pbData++ = mesh->mFaces[x].mIndices[a]; - } - } - } - else { - // create 16 bit index buffer - if(FAILED( g_piDevice->CreateIndexBuffer( 2 * - mesh->mNumFaces * nidx, - D3DUSAGE_WRITEONLY | dwUsage, - D3DFMT_INDEX16, - D3DPOOL_DEFAULT, - &g_pcAsset->apcMeshes[i]->piIB, - NULL))) - { - MessageBox(g_hDlg,"Failed to create 16 Bit index buffer", - "ASSIMP Viewer Utility",MB_OK); - return 2; - } + // now fill the index buffer + unsigned int* pbData; + g_pcAsset->apcMeshes[i]->piIB->Lock(0,0,(void**)&pbData,0); + for (unsigned int x = 0; x < mesh->mNumFaces;++x) + { + for (unsigned int a = 0; a < nidx;++a) + { + *pbData++ = mesh->mFaces[x].mIndices[a]; + } + } + } + else { + // create 16 bit index buffer + if(FAILED( g_piDevice->CreateIndexBuffer( 2 * + mesh->mNumFaces * nidx, + D3DUSAGE_WRITEONLY | dwUsage, + D3DFMT_INDEX16, + D3DPOOL_DEFAULT, + &g_pcAsset->apcMeshes[i]->piIB, + NULL))) + { + MessageBox(g_hDlg,"Failed to create 16 Bit index buffer", + "ASSIMP Viewer Utility",MB_OK); + return 2; + } - // now fill the index buffer - uint16_t* pbData; - g_pcAsset->apcMeshes[i]->piIB->Lock(0,0,(void**)&pbData,0); - for (unsigned int x = 0; x < mesh->mNumFaces;++x) - { - for (unsigned int a = 0; a < nidx;++a) - { - *pbData++ = (uint16_t)mesh->mFaces[x].mIndices[a]; - } - } - } - g_pcAsset->apcMeshes[i]->piIB->Unlock(); + // now fill the index buffer + uint16_t* pbData; + g_pcAsset->apcMeshes[i]->piIB->Lock(0,0,(void**)&pbData,0); + for (unsigned int x = 0; x < mesh->mNumFaces;++x) + { + for (unsigned int a = 0; a < nidx;++a) + { + *pbData++ = (uint16_t)mesh->mFaces[x].mIndices[a]; + } + } + } + g_pcAsset->apcMeshes[i]->piIB->Unlock(); - // collect weights on all vertices. Quick and careless - std::vector > weightsPerVertex( mesh->mNumVertices); - for( unsigned int a = 0; a < mesh->mNumBones; a++) { - const aiBone* bone = mesh->mBones[a]; - for( unsigned int b = 0; b < bone->mNumWeights; b++) - weightsPerVertex[bone->mWeights[b].mVertexId].push_back( aiVertexWeight( a, bone->mWeights[b].mWeight)); - } + // collect weights on all vertices. Quick and careless + std::vector > weightsPerVertex( mesh->mNumVertices); + for( unsigned int a = 0; a < mesh->mNumBones; a++) { + const aiBone* bone = mesh->mBones[a]; + for( unsigned int b = 0; b < bone->mNumWeights; b++) + weightsPerVertex[bone->mWeights[b].mVertexId].push_back( aiVertexWeight( a, bone->mWeights[b].mWeight)); + } - // now fill the vertex buffer - AssetHelper::Vertex* pbData2; - g_pcAsset->apcMeshes[i]->piVB->Lock(0,0,(void**)&pbData2,0); - for (unsigned int x = 0; x < mesh->mNumVertices;++x) - { - pbData2->vPosition = mesh->mVertices[x]; + // now fill the vertex buffer + AssetHelper::Vertex* pbData2; + g_pcAsset->apcMeshes[i]->piVB->Lock(0,0,(void**)&pbData2,0); + for (unsigned int x = 0; x < mesh->mNumVertices;++x) + { + pbData2->vPosition = mesh->mVertices[x]; - if (NULL == mesh->mNormals) - pbData2->vNormal = aiVector3D(0.0f,0.0f,0.0f); - else pbData2->vNormal = mesh->mNormals[x]; + if (NULL == mesh->mNormals) + pbData2->vNormal = aiVector3D(0.0f,0.0f,0.0f); + else pbData2->vNormal = mesh->mNormals[x]; - if (NULL == mesh->mTangents) { - pbData2->vTangent = aiVector3D(0.0f,0.0f,0.0f); - pbData2->vBitangent = aiVector3D(0.0f,0.0f,0.0f); - } - else { - pbData2->vTangent = mesh->mTangents[x]; - pbData2->vBitangent = mesh->mBitangents[x]; - } + if (NULL == mesh->mTangents) { + pbData2->vTangent = aiVector3D(0.0f,0.0f,0.0f); + pbData2->vBitangent = aiVector3D(0.0f,0.0f,0.0f); + } + else { + pbData2->vTangent = mesh->mTangents[x]; + pbData2->vBitangent = mesh->mBitangents[x]; + } - if (mesh->HasVertexColors( 0)) { - pbData2->dColorDiffuse = D3DCOLOR_ARGB( - ((unsigned char)std::max( std::min( mesh->mColors[0][x].a * 255.0f, 255.0f),0.0f)), - ((unsigned char)std::max( std::min( mesh->mColors[0][x].r * 255.0f, 255.0f),0.0f)), - ((unsigned char)std::max( std::min( mesh->mColors[0][x].g * 255.0f, 255.0f),0.0f)), - ((unsigned char)std::max( std::min( mesh->mColors[0][x].b * 255.0f, 255.0f),0.0f))); - } - else pbData2->dColorDiffuse = D3DCOLOR_ARGB(0xFF,0xff,0xff,0xff); + if (mesh->HasVertexColors( 0)) { + pbData2->dColorDiffuse = D3DCOLOR_ARGB( + ((unsigned char)max( min( mesh->mColors[0][x].a * 255.0f, 255.0f),0.0f)), + ((unsigned char)max( min( mesh->mColors[0][x].r * 255.0f, 255.0f),0.0f)), + ((unsigned char)max( min( mesh->mColors[0][x].g * 255.0f, 255.0f),0.0f)), + ((unsigned char)max( min( mesh->mColors[0][x].b * 255.0f, 255.0f),0.0f))); + } + else pbData2->dColorDiffuse = D3DCOLOR_ARGB(0xFF,0xff,0xff,0xff); - // ignore a third texture coordinate component - if (mesh->HasTextureCoords( 0)) { - pbData2->vTextureUV = aiVector2D( - mesh->mTextureCoords[0][x].x, - mesh->mTextureCoords[0][x].y); - } - else pbData2->vTextureUV = aiVector2D(0.5f,0.5f); + // ignore a third texture coordinate component + if (mesh->HasTextureCoords( 0)) { + pbData2->vTextureUV = aiVector2D( + mesh->mTextureCoords[0][x].x, + mesh->mTextureCoords[0][x].y); + } + else pbData2->vTextureUV = aiVector2D(0.5f,0.5f); - if (mesh->HasTextureCoords( 1)) { - pbData2->vTextureUV2 = aiVector2D( - mesh->mTextureCoords[1][x].x, - mesh->mTextureCoords[1][x].y); - } - else pbData2->vTextureUV2 = aiVector2D(0.5f,0.5f); + if (mesh->HasTextureCoords( 1)) { + pbData2->vTextureUV2 = aiVector2D( + mesh->mTextureCoords[1][x].x, + mesh->mTextureCoords[1][x].y); + } + else pbData2->vTextureUV2 = aiVector2D(0.5f,0.5f); - // Bone indices and weights - if( mesh->HasBones()) { - unsigned char boneIndices[4] = { 0, 0, 0, 0 }; - unsigned char boneWeights[4] = { 0, 0, 0, 0 }; - ai_assert( weightsPerVertex[x].size() <= 4); - for( unsigned int a = 0; a < weightsPerVertex[x].size(); a++) - { - boneIndices[a] = weightsPerVertex[x][a].mVertexId; - boneWeights[a] = (unsigned char) (weightsPerVertex[x][a].mWeight * 255.0f); - } + // Bone indices and weights + if( mesh->HasBones()) { + unsigned char boneIndices[4] = { 0, 0, 0, 0 }; + unsigned char boneWeights[4] = { 0, 0, 0, 0 }; + ai_assert( weightsPerVertex[x].size() <= 4); + for( unsigned int a = 0; a < weightsPerVertex[x].size(); a++) + { + boneIndices[a] = weightsPerVertex[x][a].mVertexId; + boneWeights[a] = (unsigned char) (weightsPerVertex[x][a].mWeight * 255.0f); + } - memcpy( pbData2->mBoneIndices, boneIndices, sizeof( boneIndices)); - memcpy( pbData2->mBoneWeights, boneWeights, sizeof( boneWeights)); - } else - { - memset( pbData2->mBoneIndices, 0, sizeof( pbData2->mBoneIndices)); - memset( pbData2->mBoneWeights, 0, sizeof( pbData2->mBoneWeights)); - } + memcpy( pbData2->mBoneIndices, boneIndices, sizeof( boneIndices)); + memcpy( pbData2->mBoneWeights, boneWeights, sizeof( boneWeights)); + } else + { + memset( pbData2->mBoneIndices, 0, sizeof( pbData2->mBoneIndices)); + memset( pbData2->mBoneWeights, 0, sizeof( pbData2->mBoneWeights)); + } - ++pbData2; - } - g_pcAsset->apcMeshes[i]->piVB->Unlock(); + ++pbData2; + } + g_pcAsset->apcMeshes[i]->piVB->Unlock(); - // now generate the second vertex buffer, holding all normals - if (!g_pcAsset->apcMeshes[i]->piVBNormals) { - GenerateNormalsAsLineList(g_pcAsset->apcMeshes[i],mesh); - } - } - return 1; + // now generate the second vertex buffer, holding all normals + if (!g_pcAsset->apcMeshes[i]->piVBNormals) { + GenerateNormalsAsLineList(g_pcAsset->apcMeshes[i],mesh); + } + } + return 1; } //------------------------------------------------------------------------------- @@ -652,80 +653,80 @@ int CreateAssetData() //------------------------------------------------------------------------------- int DeleteAssetData(bool bNoMaterials) { - if (!g_pcAsset)return 0; + if (!g_pcAsset)return 0; - // TODO: Move this to a proper destructor - for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i) - { - if(g_pcAsset->apcMeshes[i]->piVB) - { - g_pcAsset->apcMeshes[i]->piVB->Release(); - g_pcAsset->apcMeshes[i]->piVB = NULL; - } - if(g_pcAsset->apcMeshes[i]->piVBNormals) - { - g_pcAsset->apcMeshes[i]->piVBNormals->Release(); - g_pcAsset->apcMeshes[i]->piVBNormals = NULL; - } - if(g_pcAsset->apcMeshes[i]->piIB) - { - g_pcAsset->apcMeshes[i]->piIB->Release(); - g_pcAsset->apcMeshes[i]->piIB = NULL; - } + // TODO: Move this to a proper destructor + for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i) + { + if(g_pcAsset->apcMeshes[i]->piVB) + { + g_pcAsset->apcMeshes[i]->piVB->Release(); + g_pcAsset->apcMeshes[i]->piVB = NULL; + } + if(g_pcAsset->apcMeshes[i]->piVBNormals) + { + g_pcAsset->apcMeshes[i]->piVBNormals->Release(); + g_pcAsset->apcMeshes[i]->piVBNormals = NULL; + } + if(g_pcAsset->apcMeshes[i]->piIB) + { + g_pcAsset->apcMeshes[i]->piIB->Release(); + g_pcAsset->apcMeshes[i]->piIB = NULL; + } - // TODO ... unfixed memory leak - // delete storage eventually allocated to hold a copy - // of the original vertex normals - //if (g_pcAsset->apcMeshes[i]->pvOriginalNormals) - //{ - // delete[] g_pcAsset->apcMeshes[i]->pvOriginalNormals; - //} + // TODO ... unfixed memory leak + // delete storage eventually allocated to hold a copy + // of the original vertex normals + //if (g_pcAsset->apcMeshes[i]->pvOriginalNormals) + //{ + // delete[] g_pcAsset->apcMeshes[i]->pvOriginalNormals; + //} - if (!bNoMaterials) - { - if(g_pcAsset->apcMeshes[i]->piEffect) - { - g_pcAsset->apcMeshes[i]->piEffect->Release(); - g_pcAsset->apcMeshes[i]->piEffect = NULL; - } - if(g_pcAsset->apcMeshes[i]->piDiffuseTexture) - { - g_pcAsset->apcMeshes[i]->piDiffuseTexture->Release(); - g_pcAsset->apcMeshes[i]->piDiffuseTexture = NULL; - } - if(g_pcAsset->apcMeshes[i]->piNormalTexture) - { - g_pcAsset->apcMeshes[i]->piNormalTexture->Release(); - g_pcAsset->apcMeshes[i]->piNormalTexture = NULL; - } - if(g_pcAsset->apcMeshes[i]->piSpecularTexture) - { - g_pcAsset->apcMeshes[i]->piSpecularTexture->Release(); - g_pcAsset->apcMeshes[i]->piSpecularTexture = NULL; - } - if(g_pcAsset->apcMeshes[i]->piAmbientTexture) - { - g_pcAsset->apcMeshes[i]->piAmbientTexture->Release(); - g_pcAsset->apcMeshes[i]->piAmbientTexture = NULL; - } - if(g_pcAsset->apcMeshes[i]->piEmissiveTexture) - { - g_pcAsset->apcMeshes[i]->piEmissiveTexture->Release(); - g_pcAsset->apcMeshes[i]->piEmissiveTexture = NULL; - } - if(g_pcAsset->apcMeshes[i]->piOpacityTexture) - { - g_pcAsset->apcMeshes[i]->piOpacityTexture->Release(); - g_pcAsset->apcMeshes[i]->piOpacityTexture = NULL; - } - if(g_pcAsset->apcMeshes[i]->piShininessTexture) - { - g_pcAsset->apcMeshes[i]->piShininessTexture->Release(); - g_pcAsset->apcMeshes[i]->piShininessTexture = NULL; - } - } - } - return 1; + if (!bNoMaterials) + { + if(g_pcAsset->apcMeshes[i]->piEffect) + { + g_pcAsset->apcMeshes[i]->piEffect->Release(); + g_pcAsset->apcMeshes[i]->piEffect = NULL; + } + if(g_pcAsset->apcMeshes[i]->piDiffuseTexture) + { + g_pcAsset->apcMeshes[i]->piDiffuseTexture->Release(); + g_pcAsset->apcMeshes[i]->piDiffuseTexture = NULL; + } + if(g_pcAsset->apcMeshes[i]->piNormalTexture) + { + g_pcAsset->apcMeshes[i]->piNormalTexture->Release(); + g_pcAsset->apcMeshes[i]->piNormalTexture = NULL; + } + if(g_pcAsset->apcMeshes[i]->piSpecularTexture) + { + g_pcAsset->apcMeshes[i]->piSpecularTexture->Release(); + g_pcAsset->apcMeshes[i]->piSpecularTexture = NULL; + } + if(g_pcAsset->apcMeshes[i]->piAmbientTexture) + { + g_pcAsset->apcMeshes[i]->piAmbientTexture->Release(); + g_pcAsset->apcMeshes[i]->piAmbientTexture = NULL; + } + if(g_pcAsset->apcMeshes[i]->piEmissiveTexture) + { + g_pcAsset->apcMeshes[i]->piEmissiveTexture->Release(); + g_pcAsset->apcMeshes[i]->piEmissiveTexture = NULL; + } + if(g_pcAsset->apcMeshes[i]->piOpacityTexture) + { + g_pcAsset->apcMeshes[i]->piOpacityTexture->Release(); + g_pcAsset->apcMeshes[i]->piOpacityTexture = NULL; + } + if(g_pcAsset->apcMeshes[i]->piShininessTexture) + { + g_pcAsset->apcMeshes[i]->piShininessTexture->Release(); + g_pcAsset->apcMeshes[i]->piShininessTexture = NULL; + } + } + } + return 1; } @@ -735,22 +736,22 @@ int DeleteAssetData(bool bNoMaterials) //------------------------------------------------------------------------------- int SetupFPSView() { - if (!g_bFPSView) - { - g_sCamera.vPos = aiVector3D(0.0f,0.0f,g_fWheelPos); - g_sCamera.vLookAt = aiVector3D(0.0f,0.0f,1.0f); - g_sCamera.vUp = aiVector3D(0.0f,1.0f,0.0f); - g_sCamera.vRight = aiVector3D(0.0f,1.0f,0.0f); - } - else - { - g_fWheelPos = g_sCamera.vPos.z; - g_sCamera.vPos = aiVector3D(0.0f,0.0f,-10.0f); - g_sCamera.vLookAt = aiVector3D(0.0f,0.0f,1.0f); - g_sCamera.vUp = aiVector3D(0.0f,1.0f,0.0f); - g_sCamera.vRight = aiVector3D(0.0f,1.0f,0.0f); - } - return 1; + if (!g_bFPSView) + { + g_sCamera.vPos = aiVector3D(0.0f,0.0f,g_fWheelPos); + g_sCamera.vLookAt = aiVector3D(0.0f,0.0f,1.0f); + g_sCamera.vUp = aiVector3D(0.0f,1.0f,0.0f); + g_sCamera.vRight = aiVector3D(0.0f,1.0f,0.0f); + } + else + { + g_fWheelPos = g_sCamera.vPos.z; + g_sCamera.vPos = aiVector3D(0.0f,0.0f,-10.0f); + g_sCamera.vLookAt = aiVector3D(0.0f,0.0f,1.0f); + g_sCamera.vUp = aiVector3D(0.0f,1.0f,0.0f); + g_sCamera.vRight = aiVector3D(0.0f,1.0f,0.0f); + } + return 1; } //------------------------------------------------------------------------------- @@ -759,12 +760,12 @@ int SetupFPSView() //------------------------------------------------------------------------------- int InitD3D(void) { - if (NULL == g_piD3D) - { - g_piD3D = Direct3DCreate9(D3D_SDK_VERSION); - if (NULL == g_piD3D)return 0; - } - return 1; + if (NULL == g_piD3D) + { + g_piD3D = Direct3DCreate9(D3D_SDK_VERSION); + if (NULL == g_piD3D)return 0; + } + return 1; } @@ -774,13 +775,13 @@ int InitD3D(void) //------------------------------------------------------------------------------- int ShutdownD3D(void) { - ShutdownDevice(); - if (NULL != g_piD3D) - { - g_piD3D->Release(); - g_piD3D = NULL; - } - return 1; + ShutdownDevice(); + if (NULL != g_piD3D) + { + g_piD3D->Release(); + g_piD3D = NULL; + } + return 1; } @@ -790,55 +791,55 @@ int ShutdownD3D(void) //------------------------------------------------------------------------------- int ShutdownDevice(void) { - // release other subsystems - CBackgroundPainter::Instance().ReleaseNativeResource(); - CLogDisplay::Instance().ReleaseNativeResource(); + // release other subsystems + CBackgroundPainter::Instance().ReleaseNativeResource(); + CLogDisplay::Instance().ReleaseNativeResource(); - // release global shaders that have been allocazed - if (NULL != g_piDefaultEffect) - { - g_piDefaultEffect->Release(); - g_piDefaultEffect = NULL; - } - if (NULL != g_piNormalsEffect) - { - g_piNormalsEffect->Release(); - g_piNormalsEffect = NULL; - } - if (NULL != g_piPassThroughEffect) - { - g_piPassThroughEffect->Release(); - g_piPassThroughEffect = NULL; - } - if (NULL != g_piPatternEffect) - { - g_piPatternEffect->Release(); - g_piPatternEffect = NULL; - } - if (NULL != g_pcTexture) - { - g_pcTexture->Release(); - g_pcTexture = NULL; - } + // release global shaders that have been allocazed + if (NULL != g_piDefaultEffect) + { + g_piDefaultEffect->Release(); + g_piDefaultEffect = NULL; + } + if (NULL != g_piNormalsEffect) + { + g_piNormalsEffect->Release(); + g_piNormalsEffect = NULL; + } + if (NULL != g_piPassThroughEffect) + { + g_piPassThroughEffect->Release(); + g_piPassThroughEffect = NULL; + } + if (NULL != g_piPatternEffect) + { + g_piPatternEffect->Release(); + g_piPatternEffect = NULL; + } + if (NULL != g_pcTexture) + { + g_pcTexture->Release(); + g_pcTexture = NULL; + } - if( NULL != gDefaultVertexDecl) - { - gDefaultVertexDecl->Release(); - gDefaultVertexDecl = NULL; - } + if( NULL != gDefaultVertexDecl) + { + gDefaultVertexDecl->Release(); + gDefaultVertexDecl = NULL; + } - // delete the main D3D device object - if (NULL != g_piDevice) - { - g_piDevice->Release(); - g_piDevice = NULL; - } + // delete the main D3D device object + if (NULL != g_piDevice) + { + g_piDevice->Release(); + g_piDevice = NULL; + } - // deleted the one channel image allocated to hold the HUD mask - delete[] g_szImageMask; - g_szImageMask = NULL; + // deleted the one channel image allocated to hold the HUD mask + delete[] g_szImageMask; + g_szImageMask = NULL; - return 1; + return 1; } @@ -846,269 +847,269 @@ int ShutdownDevice(void) //------------------------------------------------------------------------------- int CreateHUDTexture() { - // lock the memory resource ourselves - HRSRC res = FindResource(NULL,MAKEINTRESOURCE(IDR_HUD),RT_RCDATA); - HGLOBAL hg = LoadResource(NULL,res); - void* pData = LockResource(hg); + // lock the memory resource ourselves + HRSRC res = FindResource(NULL,MAKEINTRESOURCE(IDR_HUD),RT_RCDATA); + HGLOBAL hg = LoadResource(NULL,res); + void* pData = LockResource(hg); - if(FAILED(D3DXCreateTextureFromFileInMemoryEx(g_piDevice, - pData,SizeofResource(NULL,res), - D3DX_DEFAULT_NONPOW2, - D3DX_DEFAULT_NONPOW2, - 1, - 0, - D3DFMT_A8R8G8B8, - D3DPOOL_MANAGED, - D3DX_DEFAULT, - D3DX_DEFAULT, - 0, - NULL, - NULL, - &g_pcTexture))) - { - CLogDisplay::Instance().AddEntry("[ERROR] Unable to load HUD texture", - D3DCOLOR_ARGB(0xFF,0xFF,0,0)); + if(FAILED(D3DXCreateTextureFromFileInMemoryEx(g_piDevice, + pData,SizeofResource(NULL,res), + D3DX_DEFAULT_NONPOW2, + D3DX_DEFAULT_NONPOW2, + 1, + 0, + D3DFMT_A8R8G8B8, + D3DPOOL_MANAGED, + D3DX_DEFAULT, + D3DX_DEFAULT, + 0, + NULL, + NULL, + &g_pcTexture))) + { + CLogDisplay::Instance().AddEntry("[ERROR] Unable to load HUD texture", + D3DCOLOR_ARGB(0xFF,0xFF,0,0)); - g_pcTexture = NULL; - g_szImageMask = NULL; + g_pcTexture = NULL; + g_szImageMask = NULL; - FreeResource(hg); - return 0; - } + FreeResource(hg); + return 0; + } - FreeResource(hg); + FreeResource(hg); - D3DSURFACE_DESC sDesc; - g_pcTexture->GetLevelDesc(0,&sDesc); + D3DSURFACE_DESC sDesc; + g_pcTexture->GetLevelDesc(0,&sDesc); - // lock the memory resource ourselves - res = FindResource(NULL,MAKEINTRESOURCE(IDR_HUDMASK),RT_RCDATA); - hg = LoadResource(NULL,res); - pData = LockResource(hg); + // lock the memory resource ourselves + res = FindResource(NULL,MAKEINTRESOURCE(IDR_HUDMASK),RT_RCDATA); + hg = LoadResource(NULL,res); + pData = LockResource(hg); - IDirect3DTexture9* pcTex; - if(FAILED(D3DXCreateTextureFromFileInMemoryEx(g_piDevice, - pData,SizeofResource(NULL,res), - sDesc.Width, - sDesc.Height, - 1, - 0, - D3DFMT_L8, - D3DPOOL_MANAGED, // unnecessary - D3DX_DEFAULT, - D3DX_DEFAULT, - 0, - NULL, - NULL, - &pcTex))) - { - CLogDisplay::Instance().AddEntry("[ERROR] Unable to load HUD mask texture", - D3DCOLOR_ARGB(0xFF,0xFF,0,0)); - g_szImageMask = NULL; + IDirect3DTexture9* pcTex; + if(FAILED(D3DXCreateTextureFromFileInMemoryEx(g_piDevice, + pData,SizeofResource(NULL,res), + sDesc.Width, + sDesc.Height, + 1, + 0, + D3DFMT_L8, + D3DPOOL_MANAGED, // unnecessary + D3DX_DEFAULT, + D3DX_DEFAULT, + 0, + NULL, + NULL, + &pcTex))) + { + CLogDisplay::Instance().AddEntry("[ERROR] Unable to load HUD mask texture", + D3DCOLOR_ARGB(0xFF,0xFF,0,0)); + g_szImageMask = NULL; - FreeResource(hg); - return 0; - } + FreeResource(hg); + return 0; + } - FreeResource(hg); + FreeResource(hg); - // lock the texture and copy it to get a pointer - D3DLOCKED_RECT sRect; - pcTex->LockRect(0,&sRect,NULL,D3DLOCK_READONLY); + // lock the texture and copy it to get a pointer + D3DLOCKED_RECT sRect; + pcTex->LockRect(0,&sRect,NULL,D3DLOCK_READONLY); - unsigned char* szOut = new unsigned char[sDesc.Width * sDesc.Height]; - unsigned char* _szOut = szOut; + unsigned char* szOut = new unsigned char[sDesc.Width * sDesc.Height]; + unsigned char* _szOut = szOut; - unsigned char* szCur = (unsigned char*) sRect.pBits; - for (unsigned int y = 0; y < sDesc.Height;++y) - { - memcpy(_szOut,szCur,sDesc.Width); + unsigned char* szCur = (unsigned char*) sRect.pBits; + for (unsigned int y = 0; y < sDesc.Height;++y) + { + memcpy(_szOut,szCur,sDesc.Width); - szCur += sRect.Pitch; - _szOut += sDesc.Width; - } - pcTex->UnlockRect(0); - pcTex->Release(); + szCur += sRect.Pitch; + _szOut += sDesc.Width; + } + pcTex->UnlockRect(0); + pcTex->Release(); - g_szImageMask = szOut; - return 1; + g_szImageMask = szOut; + return 1; } //------------------------------------------------------------------------------- //------------------------------------------------------------------------------- int CreateDevice (bool p_bMultiSample,bool p_bSuperSample,bool bHW /*= true*/) { - D3DDEVTYPE eType = bHW ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF; + D3DDEVTYPE eType = bHW ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF; - // get the client rectangle of the window. - RECT sRect; - GetWindowRect(GetDlgItem(g_hDlg,IDC_RT),&sRect); - sRect.right -= sRect.left; - sRect.bottom -= sRect.top; + // get the client rectangle of the window. + RECT sRect; + GetWindowRect(GetDlgItem(g_hDlg,IDC_RT),&sRect); + sRect.right -= sRect.left; + sRect.bottom -= sRect.top; - D3DPRESENT_PARAMETERS sParams; - memset(&sParams,0,sizeof(D3DPRESENT_PARAMETERS)); + D3DPRESENT_PARAMETERS sParams; + memset(&sParams,0,sizeof(D3DPRESENT_PARAMETERS)); - // get the current display mode - D3DDISPLAYMODE sMode; - g_piD3D->GetAdapterDisplayMode(0,&sMode); + // get the current display mode + D3DDISPLAYMODE sMode; + g_piD3D->GetAdapterDisplayMode(0,&sMode); - // fill the presentation parameter structure - sParams.Windowed = TRUE; - sParams.hDeviceWindow = GetDlgItem( g_hDlg, IDC_RT ); - sParams.EnableAutoDepthStencil = TRUE; - sParams.PresentationInterval = D3DPRESENT_INTERVAL_ONE; - sParams.BackBufferWidth = (UINT)sRect.right; - sParams.BackBufferHeight = (UINT)sRect.bottom; - sParams.SwapEffect = D3DSWAPEFFECT_DISCARD; - sParams.BackBufferCount = 1; + // fill the presentation parameter structure + sParams.Windowed = TRUE; + sParams.hDeviceWindow = GetDlgItem( g_hDlg, IDC_RT ); + sParams.EnableAutoDepthStencil = TRUE; + sParams.PresentationInterval = D3DPRESENT_INTERVAL_ONE; + sParams.BackBufferWidth = (UINT)sRect.right; + sParams.BackBufferHeight = (UINT)sRect.bottom; + sParams.SwapEffect = D3DSWAPEFFECT_DISCARD; + sParams.BackBufferCount = 1; - // check whether we can use a D32 depth buffer format - if (SUCCEEDED ( g_piD3D->CheckDepthStencilMatch(0,eType, - D3DFMT_X8R8G8B8,D3DFMT_X8R8G8B8,D3DFMT_D32))) - { - sParams.AutoDepthStencilFormat = D3DFMT_D32; - } - else sParams.AutoDepthStencilFormat = D3DFMT_D24X8; + // check whether we can use a D32 depth buffer format + if (SUCCEEDED ( g_piD3D->CheckDepthStencilMatch(0,eType, + D3DFMT_X8R8G8B8,D3DFMT_X8R8G8B8,D3DFMT_D32))) + { + sParams.AutoDepthStencilFormat = D3DFMT_D32; + } + else sParams.AutoDepthStencilFormat = D3DFMT_D24X8; - // find the highest multisample type available on this device - D3DMULTISAMPLE_TYPE sMS = D3DMULTISAMPLE_2_SAMPLES; - D3DMULTISAMPLE_TYPE sMSOut = D3DMULTISAMPLE_NONE; - DWORD dwQuality = 0; - if (p_bMultiSample) - { - while ((D3DMULTISAMPLE_TYPE)(D3DMULTISAMPLE_16_SAMPLES + 1) != - (sMS = (D3DMULTISAMPLE_TYPE)(sMS + 1))) - { - if(SUCCEEDED( g_piD3D->CheckDeviceMultiSampleType(0,eType, - sMode.Format,TRUE,sMS,&dwQuality))) - { - sMSOut = sMS; - } - } - if (0 != dwQuality)dwQuality -= 1; + // find the highest multisample type available on this device + D3DMULTISAMPLE_TYPE sMS = D3DMULTISAMPLE_2_SAMPLES; + D3DMULTISAMPLE_TYPE sMSOut = D3DMULTISAMPLE_NONE; + DWORD dwQuality = 0; + if (p_bMultiSample) + { + while ((D3DMULTISAMPLE_TYPE)(D3DMULTISAMPLE_16_SAMPLES + 1) != + (sMS = (D3DMULTISAMPLE_TYPE)(sMS + 1))) + { + if(SUCCEEDED( g_piD3D->CheckDeviceMultiSampleType(0,eType, + sMode.Format,TRUE,sMS,&dwQuality))) + { + sMSOut = sMS; + } + } + if (0 != dwQuality)dwQuality -= 1; - sParams.MultiSampleQuality = dwQuality; - sParams.MultiSampleType = sMSOut; - } + sParams.MultiSampleQuality = dwQuality; + sParams.MultiSampleType = sMSOut; + } - // preget the device capabilities. If the hardware vertex shader is too old, we prefer software vertex processing - g_piD3D->GetDeviceCaps( 0, D3DDEVTYPE_HAL, &g_sCaps); - DWORD creationFlags = D3DCREATE_MULTITHREADED; - if( g_sCaps.VertexShaderVersion >= D3DVS_VERSION( 2, 0)) - creationFlags |= D3DCREATE_HARDWARE_VERTEXPROCESSING; - else - creationFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING; + // preget the device capabilities. If the hardware vertex shader is too old, we prefer software vertex processing + g_piD3D->GetDeviceCaps( 0, D3DDEVTYPE_HAL, &g_sCaps); + DWORD creationFlags = D3DCREATE_MULTITHREADED; + if( g_sCaps.VertexShaderVersion >= D3DVS_VERSION( 2, 0)) + creationFlags |= D3DCREATE_HARDWARE_VERTEXPROCESSING; + else + creationFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING; - // create the D3D9 device object. with software-vertexprocessing if VS2.0 isn`t supported in hardware - if(FAILED(g_piD3D->CreateDevice(0,eType, g_hDlg, creationFlags ,&sParams,&g_piDevice))) - { - // if hardware fails use software rendering instead - if (bHW)return CreateDevice(p_bMultiSample,p_bSuperSample,false); - return 0; - } + // create the D3D9 device object. with software-vertexprocessing if VS2.0 isn`t supported in hardware + if(FAILED(g_piD3D->CreateDevice(0,eType, g_hDlg, creationFlags ,&sParams,&g_piDevice))) + { + // if hardware fails use software rendering instead + if (bHW)return CreateDevice(p_bMultiSample,p_bSuperSample,false); + return 0; + } - // create a vertex declaration to match the vertex - D3DVERTEXELEMENT9* vdecl = AssetHelper::Vertex::GetDeclarationElements(); - if( FAILED( g_piDevice->CreateVertexDeclaration( vdecl, &gDefaultVertexDecl))) - { - MessageBox( g_hDlg, "Failed to create vertex declaration", "Init", MB_OK); - return 0; - } - g_piDevice->SetVertexDeclaration( gDefaultVertexDecl); + // create a vertex declaration to match the vertex + D3DVERTEXELEMENT9* vdecl = AssetHelper::Vertex::GetDeclarationElements(); + if( FAILED( g_piDevice->CreateVertexDeclaration( vdecl, &gDefaultVertexDecl))) + { + MessageBox( g_hDlg, "Failed to create vertex declaration", "Init", MB_OK); + return 0; + } + g_piDevice->SetVertexDeclaration( gDefaultVertexDecl); - // get the capabilities of the device object - g_piDevice->GetDeviceCaps(&g_sCaps); - if(g_sCaps.PixelShaderVersion < D3DPS_VERSION(3,0)) - { - EnableWindow(GetDlgItem(g_hDlg,IDC_LOWQUALITY),FALSE); - } + // get the capabilities of the device object + g_piDevice->GetDeviceCaps(&g_sCaps); + if(g_sCaps.PixelShaderVersion < D3DPS_VERSION(3,0)) + { + EnableWindow(GetDlgItem(g_hDlg,IDC_LOWQUALITY),FALSE); + } - // compile the default material shader (gray gouraud/phong) - ID3DXBuffer* piBuffer = NULL; - if(FAILED( D3DXCreateEffect(g_piDevice, - g_szDefaultShader.c_str(), - (UINT)g_szDefaultShader.length(), - NULL, - NULL, - AI_SHADER_COMPILE_FLAGS, - NULL, - &g_piDefaultEffect,&piBuffer))) - { - if( piBuffer) - { - MessageBox(g_hDlg,(LPCSTR)piBuffer->GetBufferPointer(),"HLSL",MB_OK); - piBuffer->Release(); - } - return 0; - } - if( piBuffer) - { - piBuffer->Release(); - piBuffer = NULL; - } + // compile the default material shader (gray gouraud/phong) + ID3DXBuffer* piBuffer = NULL; + if(FAILED( D3DXCreateEffect(g_piDevice, + g_szDefaultShader.c_str(), + (UINT)g_szDefaultShader.length(), + NULL, + NULL, + AI_SHADER_COMPILE_FLAGS, + NULL, + &g_piDefaultEffect,&piBuffer))) + { + if( piBuffer) + { + MessageBox(g_hDlg,(LPCSTR)piBuffer->GetBufferPointer(),"HLSL",MB_OK); + piBuffer->Release(); + } + return 0; + } + if( piBuffer) + { + piBuffer->Release(); + piBuffer = NULL; + } - // use Fixed Function effect when working with shaderless cards - if( g_sCaps.PixelShaderVersion < D3DPS_VERSION(2,0)) - g_piDefaultEffect->SetTechnique( "DefaultFXSpecular_FF"); + // use Fixed Function effect when working with shaderless cards + if( g_sCaps.PixelShaderVersion < D3DPS_VERSION(2,0)) + g_piDefaultEffect->SetTechnique( "DefaultFXSpecular_FF"); - // create the shader used to draw the HUD - if(FAILED( D3DXCreateEffect(g_piDevice, - g_szPassThroughShader.c_str(),(UINT)g_szPassThroughShader.length(), - NULL,NULL,AI_SHADER_COMPILE_FLAGS,NULL,&g_piPassThroughEffect,&piBuffer))) - { - if( piBuffer) - { - MessageBox(g_hDlg,(LPCSTR)piBuffer->GetBufferPointer(),"HLSL",MB_OK); - piBuffer->Release(); - } - return 0; - } - if( piBuffer) - { - piBuffer->Release(); - piBuffer = NULL; - } + // create the shader used to draw the HUD + if(FAILED( D3DXCreateEffect(g_piDevice, + g_szPassThroughShader.c_str(),(UINT)g_szPassThroughShader.length(), + NULL,NULL,AI_SHADER_COMPILE_FLAGS,NULL,&g_piPassThroughEffect,&piBuffer))) + { + if( piBuffer) + { + MessageBox(g_hDlg,(LPCSTR)piBuffer->GetBufferPointer(),"HLSL",MB_OK); + piBuffer->Release(); + } + return 0; + } + if( piBuffer) + { + piBuffer->Release(); + piBuffer = NULL; + } - // use Fixed Function effect when working with shaderless cards - if( g_sCaps.PixelShaderVersion < D3DPS_VERSION(2,0)) - g_piPassThroughEffect->SetTechnique( "PassThrough_FF"); + // use Fixed Function effect when working with shaderless cards + if( g_sCaps.PixelShaderVersion < D3DPS_VERSION(2,0)) + g_piPassThroughEffect->SetTechnique( "PassThrough_FF"); - // create the shader used to visualize normal vectors - if(FAILED( D3DXCreateEffect(g_piDevice, - g_szNormalsShader.c_str(),(UINT)g_szNormalsShader.length(), - NULL,NULL,AI_SHADER_COMPILE_FLAGS,NULL,&g_piNormalsEffect, &piBuffer))) - { - if( piBuffer) - { - MessageBox(g_hDlg,(LPCSTR)piBuffer->GetBufferPointer(),"HLSL",MB_OK); - piBuffer->Release(); - } - return 0; - } - if( piBuffer) - { - piBuffer->Release(); - piBuffer = NULL; - } + // create the shader used to visualize normal vectors + if(FAILED( D3DXCreateEffect(g_piDevice, + g_szNormalsShader.c_str(),(UINT)g_szNormalsShader.length(), + NULL,NULL,AI_SHADER_COMPILE_FLAGS,NULL,&g_piNormalsEffect, &piBuffer))) + { + if( piBuffer) + { + MessageBox(g_hDlg,(LPCSTR)piBuffer->GetBufferPointer(),"HLSL",MB_OK); + piBuffer->Release(); + } + return 0; + } + if( piBuffer) + { + piBuffer->Release(); + piBuffer = NULL; + } - //MessageBox( g_hDlg, "Failed to create vertex declaration", "Init", MB_OK); + //MessageBox( g_hDlg, "Failed to create vertex declaration", "Init", MB_OK); - // use Fixed Function effect when working with shaderless cards - if( g_sCaps.PixelShaderVersion < D3DPS_VERSION(2,0)) - g_piNormalsEffect->SetTechnique( "RenderNormals_FF"); + // use Fixed Function effect when working with shaderless cards + if( g_sCaps.PixelShaderVersion < D3DPS_VERSION(2,0)) + g_piNormalsEffect->SetTechnique( "RenderNormals_FF"); - g_piDevice->SetRenderState(D3DRS_DITHERENABLE,TRUE); + g_piDevice->SetRenderState(D3DRS_DITHERENABLE,TRUE); - // create the texture for the HUD - CreateHUDTexture(); - CBackgroundPainter::Instance().RecreateNativeResource(); - CLogDisplay::Instance().RecreateNativeResource(); + // create the texture for the HUD + CreateHUDTexture(); + CBackgroundPainter::Instance().RecreateNativeResource(); + CLogDisplay::Instance().RecreateNativeResource(); - g_piPassThroughEffect->SetTexture("TEXTURE_2D",g_pcTexture); - return 1; + g_piPassThroughEffect->SetTexture("TEXTURE_2D",g_pcTexture); + return 1; } @@ -1116,8 +1117,8 @@ int CreateDevice (bool p_bMultiSample,bool p_bSuperSample,bool bHW /*= true*/) //------------------------------------------------------------------------------- int CreateDevice (void) { - return CreateDevice(g_sOptions.bMultiSample, - g_sOptions.bSuperSample); + return CreateDevice(g_sOptions.bMultiSample, + g_sOptions.bSuperSample); } @@ -1125,25 +1126,25 @@ int CreateDevice (void) //------------------------------------------------------------------------------- int GetProjectionMatrix (aiMatrix4x4& p_mOut) { - const float fFarPlane = 100.0f; - const float fNearPlane = 0.1f; - const float fFOV = (float)(45.0 * 0.0174532925); + const float fFarPlane = 100.0f; + const float fNearPlane = 0.1f; + const float fFOV = (float)(45.0 * 0.0174532925); - const float s = 1.0f / tanf(fFOV * 0.5f); - const float Q = fFarPlane / (fFarPlane - fNearPlane); + const float s = 1.0f / tanf(fFOV * 0.5f); + const float Q = fFarPlane / (fFarPlane - fNearPlane); - RECT sRect; - GetWindowRect(GetDlgItem(g_hDlg,IDC_RT),&sRect); - sRect.right -= sRect.left; - sRect.bottom -= sRect.top; - const float fAspect = (float)sRect.right / (float)sRect.bottom; + RECT sRect; + GetWindowRect(GetDlgItem(g_hDlg,IDC_RT),&sRect); + sRect.right -= sRect.left; + sRect.bottom -= sRect.top; + const float fAspect = (float)sRect.right / (float)sRect.bottom; - p_mOut = aiMatrix4x4( - s / fAspect, 0.0f, 0.0f, 0.0f, - 0.0f, s, 0.0f, 0.0f, - 0.0f, 0.0f, Q, 1.0f, - 0.0f, 0.0f, -Q * fNearPlane, 0.0f); - return 1; + p_mOut = aiMatrix4x4( + s / fAspect, 0.0f, 0.0f, 0.0f, + 0.0f, s, 0.0f, 0.0f, + 0.0f, 0.0f, Q, 1.0f, + 0.0f, 0.0f, -Q * fNearPlane, 0.0f); + return 1; } @@ -1151,38 +1152,38 @@ int GetProjectionMatrix (aiMatrix4x4& p_mOut) //------------------------------------------------------------------------------- aiVector3D GetCameraMatrix (aiMatrix4x4& p_mOut) { - D3DXMATRIX view; - D3DXMatrixIdentity( &view ); + D3DXMATRIX view; + D3DXMatrixIdentity( &view ); - D3DXVec3Normalize( (D3DXVECTOR3*)&g_sCamera.vLookAt, (D3DXVECTOR3*)&g_sCamera.vLookAt ); - D3DXVec3Cross( (D3DXVECTOR3*)&g_sCamera.vRight, (D3DXVECTOR3*)&g_sCamera.vUp, (D3DXVECTOR3*)&g_sCamera.vLookAt ); - D3DXVec3Normalize( (D3DXVECTOR3*)&g_sCamera.vRight, (D3DXVECTOR3*)&g_sCamera.vRight ); - D3DXVec3Cross( (D3DXVECTOR3*)&g_sCamera.vUp, (D3DXVECTOR3*)&g_sCamera.vLookAt, (D3DXVECTOR3*)&g_sCamera.vRight ); - D3DXVec3Normalize( (D3DXVECTOR3*)&g_sCamera.vUp, (D3DXVECTOR3*)&g_sCamera.vUp ); + D3DXVec3Normalize( (D3DXVECTOR3*)&g_sCamera.vLookAt, (D3DXVECTOR3*)&g_sCamera.vLookAt ); + D3DXVec3Cross( (D3DXVECTOR3*)&g_sCamera.vRight, (D3DXVECTOR3*)&g_sCamera.vUp, (D3DXVECTOR3*)&g_sCamera.vLookAt ); + D3DXVec3Normalize( (D3DXVECTOR3*)&g_sCamera.vRight, (D3DXVECTOR3*)&g_sCamera.vRight ); + D3DXVec3Cross( (D3DXVECTOR3*)&g_sCamera.vUp, (D3DXVECTOR3*)&g_sCamera.vLookAt, (D3DXVECTOR3*)&g_sCamera.vRight ); + D3DXVec3Normalize( (D3DXVECTOR3*)&g_sCamera.vUp, (D3DXVECTOR3*)&g_sCamera.vUp ); - view._11 = g_sCamera.vRight.x; - view._12 = g_sCamera.vUp.x; - view._13 = g_sCamera.vLookAt.x; - view._14 = 0.0f; + view._11 = g_sCamera.vRight.x; + view._12 = g_sCamera.vUp.x; + view._13 = g_sCamera.vLookAt.x; + view._14 = 0.0f; - view._21 = g_sCamera.vRight.y; - view._22 = g_sCamera.vUp.y; - view._23 = g_sCamera.vLookAt.y; - view._24 = 0.0f; + view._21 = g_sCamera.vRight.y; + view._22 = g_sCamera.vUp.y; + view._23 = g_sCamera.vLookAt.y; + view._24 = 0.0f; - view._31 = g_sCamera.vRight.z; - view._32 = g_sCamera.vUp.z; - view._33 = g_sCamera.vLookAt.z; - view._34 = 0.0f; + view._31 = g_sCamera.vRight.z; + view._32 = g_sCamera.vUp.z; + view._33 = g_sCamera.vLookAt.z; + view._34 = 0.0f; - view._41 = -D3DXVec3Dot( (D3DXVECTOR3*)&g_sCamera.vPos, (D3DXVECTOR3*)&g_sCamera.vRight ); - view._42 = -D3DXVec3Dot( (D3DXVECTOR3*)&g_sCamera.vPos, (D3DXVECTOR3*)&g_sCamera.vUp ); - view._43 = -D3DXVec3Dot( (D3DXVECTOR3*)&g_sCamera.vPos, (D3DXVECTOR3*)&g_sCamera.vLookAt ); - view._44 = 1.0f; + view._41 = -D3DXVec3Dot( (D3DXVECTOR3*)&g_sCamera.vPos, (D3DXVECTOR3*)&g_sCamera.vRight ); + view._42 = -D3DXVec3Dot( (D3DXVECTOR3*)&g_sCamera.vPos, (D3DXVECTOR3*)&g_sCamera.vUp ); + view._43 = -D3DXVec3Dot( (D3DXVECTOR3*)&g_sCamera.vPos, (D3DXVECTOR3*)&g_sCamera.vLookAt ); + view._44 = 1.0f; - memcpy(&p_mOut,&view,sizeof(aiMatrix4x4)); + memcpy(&p_mOut,&view,sizeof(aiMatrix4x4)); - return g_sCamera.vPos; + return g_sCamera.vPos; } } diff --git a/tools/assimp_view/assimp_view.h b/tools/assimp_view/assimp_view.h index dcd65de15..7ae21aed4 100644 --- a/tools/assimp_view/assimp_view.h +++ b/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.h" +#include +#include +#include +#include +#include +#include +#include + // Include ASSIMP headers (XXX: do we really need all of them?) #include #include @@ -59,29 +67,23 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include "../../code/AssimpPCH.h" /* HACK */ #include "../../code/MaterialSystem.h" // aiMaterial class #include "../../code/StringComparison.h" // ASSIMP_stricmp and ASSIMP_strincmp // in order for std::min and std::max to behave properly -#ifdef min +/*#ifdef min #undef min #endif // min #ifdef max #undef max -#endif // min +#endif // min*/ #include // default movement speed #define MOVE_SPEED 3.f -using namespace Assimp; - -namespace AssimpView -{ - #include "AssetHelper.h" #include "Camera.h" #include "RenderOptions.h" @@ -93,7 +95,6 @@ namespace AssimpView #include "MeshRenderer.h" #include "MaterialManager.h" -} // end of namespace AssimpView - for a while // outside of namespace, to help Intellisense and solve boost::metatype_stuff_miracle #include "AnimEvaluator.h" @@ -105,30 +106,30 @@ namespace AssimpView //------------------------------------------------------------------------------- // 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, @@ -182,7 +183,7 @@ type clamp(intype in) { // for unsigned types only ... 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)); }