From 366562e5d1beb892c8d205c451e23932d2bec131 Mon Sep 17 00:00:00 2001 From: ulfjorensen Date: Thu, 9 Oct 2008 21:18:59 +0000 Subject: [PATCH] Viewer: - added hacky support for pre-shader graphics cards. Seems to work, but I'll not know for sure until I acutally test it on such a crippled hardware. git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@174 67173fc5-114c-0410-ac8e-9d2fd5bffc1f --- tools/assimp_view/Display.cpp | 4 ++++ tools/assimp_view/Material.cpp | 12 +++++++++++- tools/assimp_view/Shaders.cpp | 2 ++ tools/assimp_view/assimp_view.cpp | 24 ++++++++++++++++++------ 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/tools/assimp_view/Display.cpp b/tools/assimp_view/Display.cpp index 5573ffc9a..041f01233 100644 --- a/tools/assimp_view/Display.cpp +++ b/tools/assimp_view/Display.cpp @@ -1905,6 +1905,10 @@ int CDisplay::RenderNode (aiNode* piNode,const aiMatrix4x4& piMatrix, piEnd->SetVector( "vCameraPos",&apcVec[0]); // setup the best technique + if( g_sCaps.PixelShaderVersion < D3DPS_VERSION(2,0)) + { + g_piDefaultEffect->SetTechnique( "DefaultFXSpecular_FF"); + } else if (g_sCaps.PixelShaderVersion < D3DPS_VERSION(3,0) || g_sOptions.bLowQuality) { if (g_sOptions.b3Lights) diff --git a/tools/assimp_view/Material.cpp b/tools/assimp_view/Material.cpp index a41b8606d..8dc2e2a8f 100644 --- a/tools/assimp_view/Material.cpp +++ b/tools/assimp_view/Material.cpp @@ -1054,7 +1054,13 @@ int CMaterialManager::CreateMaterial( 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(); @@ -1205,6 +1211,10 @@ int CMaterialManager::SetupMaterial ( } // 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) diff --git a/tools/assimp_view/Shaders.cpp b/tools/assimp_view/Shaders.cpp index 8bcbb9955..999d0fcb5 100644 --- a/tools/assimp_view/Shaders.cpp +++ b/tools/assimp_view/Shaders.cpp @@ -714,6 +714,7 @@ std::string g_szMaterialShader = std::string( // 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 < 5; a++) \n" "{ \n" @@ -721,6 +722,7 @@ std::string g_szMaterialShader = std::string( " float specIntensity = pow( dot( -reflDir, viewDir), SPECULAR_STRENGTH) * SPECULARITY; \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" diff --git a/tools/assimp_view/assimp_view.cpp b/tools/assimp_view/assimp_view.cpp index 79415f4c4..7d9f82417 100644 --- a/tools/assimp_view/assimp_view.cpp +++ b/tools/assimp_view/assimp_view.cpp @@ -924,6 +924,13 @@ int CreateDevice (bool p_bMultiSample,bool p_bSuperSample,bool bHW /*= true*/) } g_piDevice->SetFVF(AssetHelper::Vertex::GetFVF()); + // 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, @@ -948,6 +955,10 @@ int CreateDevice (bool p_bMultiSample,bool p_bSuperSample,bool bHW /*= true*/) piBuffer = NULL; } + // 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(), @@ -966,6 +977,10 @@ int CreateDevice (bool p_bMultiSample,bool p_bSuperSample,bool bHW /*= true*/) piBuffer = NULL; } + // 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(), @@ -984,12 +999,9 @@ int CreateDevice (bool p_bMultiSample,bool p_bSuperSample,bool bHW /*= true*/) piBuffer = NULL; } - // 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); - } + // use Fixed Function effect when working with shaderless cards + if( g_sCaps.PixelShaderVersion < D3DPS_VERSION(2,0)) + g_piNormalsEffect->SetTechnique( "RenderNormals_FF"); // create the texture for the HUD CreateHUDTexture();