home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Samples / C++ / Common / DXUTEffectMap.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-09-28  |  24.6 KB  |  544 lines

  1. //-----------------------------------------------------------------------------
  2. // File: DXUTEffectMap.cpp
  3. //
  4. // Desc: Maps the set of standard semantics and annotations to a collection
  5. //       of ID3DXEffect objects. 
  6. //
  7. // Copyright (c) Microsoft Corporation. All rights reserved.
  8. //-----------------------------------------------------------------------------
  9. #include "dxstdafx.h"
  10.  
  11.  
  12.  
  13. //-------------------------------------------------------------------------------------
  14. DXUT_SEMANTIC CDXUTEffectMap::StringToSemantic( const char* cstrSemantic )
  15. {
  16.     char strSemantic[MAX_PATH+1] = {0};
  17.     RemoveTrailingNumber( strSemantic, MAX_PATH, cstrSemantic );
  18.  
  19.     if( StringEquals( strSemantic, "Diffuse" ) )                               return DXUT_Diffuse;
  20.     if( StringEquals( strSemantic, "Specular" ) )                              return DXUT_Specular;
  21.     if( StringEquals( strSemantic, "Ambient" ) )                               return DXUT_Ambient;
  22.     if( StringEquals( strSemantic, "SpecularPower" ) )                         return DXUT_SpecularPower;
  23.     if( StringEquals( strSemantic, "Emissive" ) )                              return DXUT_Emissive;
  24.     if( StringEquals( strSemantic, "Normal" ) )                                return DXUT_Normal;
  25.     if( StringEquals( strSemantic, "Height" ) )                                return DXUT_Height;
  26.     if( StringEquals( strSemantic, "Refraction" ) )                            return DXUT_Refraction;
  27.     if( StringEquals( strSemantic, "Opacity" ) )                               return DXUT_Opacity;
  28.     if( StringEquals( strSemantic, "Environment" ) )                           return DXUT_Environment;
  29.     if( StringEquals( strSemantic, "EnvironmentNormal" ) )                     return DXUT_EnvironmentNormal;
  30.     if( StringEquals( strSemantic, "Fresnel" ) )                               return DXUT_Fresnel;
  31.     
  32.     if( StringEquals( strSemantic, "World" ) )                                 return DXUT_World;
  33.     if( StringEquals( strSemantic, "WorldInverse" ) )                          return DXUT_WorldInverse;
  34.     if( StringEquals( strSemantic, "WorldInverseTranspose" ) )                 return DXUT_WorldInverseTranspose;
  35.     if( StringEquals( strSemantic, "WorldView" ) )                             return DXUT_WorldView;
  36.     if( StringEquals( strSemantic, "WorldViewInverse" ) )                      return DXUT_WorldViewInverse;
  37.     if( StringEquals( strSemantic, "WorldViewInverseTranspose" ) )             return DXUT_WorldViewInverseTranspose;
  38.     if( StringEquals( strSemantic, "WorldViewProjection" ) )                   return DXUT_WorldViewProjection;
  39.     if( StringEquals( strSemantic, "WorldViewProjectionInverse" ) )            return DXUT_WorldViewProjectionInverse;
  40.     if( StringEquals( strSemantic, "WorldViewProjectionInverseTranspose" ) )   return DXUT_WorldViewProjectionInverseTranspose;
  41.     if( StringEquals( strSemantic, "View" ) )                                  return DXUT_View;
  42.     if( StringEquals( strSemantic, "ViewInverse" ) )                           return DXUT_ViewInverse;
  43.     if( StringEquals( strSemantic, "ViewInverseTranspose" ) )                  return DXUT_ViewInverseTranspose;
  44.     if( StringEquals( strSemantic, "ViewProjection" ) )                        return DXUT_ViewProjection;
  45.     if( StringEquals( strSemantic, "ViewProjectionInverse" ) )                 return DXUT_ViewProjectionInverse;
  46.     if( StringEquals( strSemantic, "ViewProjectionInverseTranspose" ) )        return DXUT_ViewProjectionInverseTranspose;
  47.     if( StringEquals( strSemantic, "Projection" ) )                            return DXUT_Projection;
  48.     if( StringEquals( strSemantic, "ProjectionInverse" ) )                     return DXUT_ProjectionInverse;
  49.     if( StringEquals( strSemantic, "ProjectionInverseTranspose" ) )            return DXUT_ProjectionInverseTranspose;
  50.  
  51.     if( StringEquals( strSemantic, "RenderTargetDimensions" ) )                return DXUT_RenderTargetDimensions;
  52.     if( StringEquals( strSemantic, "RenderTargetClipping" ) )                  return DXUT_RenderTargetClipping;
  53.     if( StringEquals( strSemantic, "Time" ) )                                  return DXUT_Time;
  54.     if( StringEquals( strSemantic, "LastTime" ) )                              return DXUT_LastTime;
  55.     if( StringEquals( strSemantic, "ElapsedTime" ) )                           return DXUT_ElapsedTime;
  56.     if( StringEquals( strSemantic, "Position" ) )                              return DXUT_Position;
  57.     if( StringEquals( strSemantic, "Direction" ) )                             return DXUT_Direction;
  58.     if( StringEquals( strSemantic, "BoundingCenter" ) )                        return DXUT_BoundingCenter;
  59.     if( StringEquals( strSemantic, "BoundingSphereSize" ) )                    return DXUT_BoundingSphereSize;
  60.     if( StringEquals( strSemantic, "BoundingSphereMin" ) )                     return DXUT_BoundingSphereMin;
  61.     if( StringEquals( strSemantic, "BoundingSphereMax" ) )                     return DXUT_BoundingSphereMax;
  62.     if( StringEquals( strSemantic, "BoundingBoxSize" ) )                       return DXUT_BoundingBoxSize;
  63.     if( StringEquals( strSemantic, "BoundingBoxMin" ) )                        return DXUT_BoundingBoxMin;
  64.     if( StringEquals( strSemantic, "BoundingBoxMax" ) )                        return DXUT_BoundingBoxMax;
  65.     if( StringEquals( strSemantic, "Attenuation" ) )                           return DXUT_Attenuation;
  66.     if( StringEquals( strSemantic, "RenderColorTarget" ) )                     return DXUT_RenderColorTarget;
  67.     if( StringEquals( strSemantic, "RenderDepthStencilTarget" ) )              return DXUT_RenderDepthStencilTarget;
  68.     if( StringEquals( strSemantic, "UnitsScale" ) )                            return DXUT_UnitsScale;
  69.     if( StringEquals( strSemantic, "StandardsGlobal" ) )                       return DXUT_StandardsGlobal;
  70.         
  71.     return DXUT_UNKNOWN_SEMANTIC;
  72. }
  73.  
  74.  
  75. //-------------------------------------------------------------------------------------
  76. DXUT_SEMANTIC CDXUTEffectMap::StringToSemantic( const WCHAR* strSemantic )
  77. {
  78.     char cstr[MAX_PATH+1] = {0};
  79.     WideCharToMultiByte( CP_ACP, 0, strSemantic, -1, cstr, MAX_PATH, NULL, NULL );
  80.     return StringToSemantic( cstr );
  81. }
  82.  
  83.  
  84. //-------------------------------------------------------------------------------------
  85. DXUT_OBJECT CDXUTEffectMap::StringToObject( const char* cstrObject )
  86. {
  87.     char strObject[MAX_PATH+1] = {0};
  88.     RemoveTrailingNumber( strObject, MAX_PATH, cstrObject );
  89.  
  90.     if( StringEquals( strObject, "Geometry" ) )  return DXUT_Geometry;
  91.     if( StringEquals( strObject, "Light" ) )     return DXUT_Light;
  92.     if( StringEquals( strObject, "Camera" ) )    return DXUT_Camera;
  93.     if( StringEquals( strObject, "Frame" ) )     return DXUT_Frame;
  94.     
  95.     return DXUT_UNKNOWN_OBJECT;
  96. }
  97.  
  98.  
  99. //-------------------------------------------------------------------------------------
  100. DXUT_OBJECT CDXUTEffectMap::StringToObject( const WCHAR* strObject )
  101. {
  102.     char cstr[MAX_PATH+1] = {0};
  103.     WideCharToMultiByte( CP_ACP, 0, strObject, -1, cstr, MAX_PATH, NULL, NULL );
  104.     return StringToObject( cstr );
  105. }
  106.  
  107.  
  108. //-------------------------------------------------------------------------------------
  109. VOID CDXUTEffectMap::Reset()
  110. {
  111.     D3DXMatrixIdentity( &m_matWorld );
  112.     D3DXMatrixIdentity( &m_matView );
  113.     D3DXMatrixIdentity( &m_matProjection );
  114.  
  115.     // Reset all the stored parameter lists
  116.     for( UINT iSemantic = 0; iSemantic < NUM_DXUT_SEMANTICS; iSemantic++ )
  117.     {
  118.         for( UINT iObject = 0; iObject < NUM_DXUT_OBJECTS; iObject++ )
  119.         {
  120.             for( UINT iIndex = 0; iIndex < MAX_INDEX; iIndex++ )
  121.             {
  122.                 CGrowableArray<ParamList>* pBinding = &m_Bindings[ iSemantic ][ iObject ][ iIndex ];
  123.  
  124.                 // Clear nested arrays first
  125.                 for( int iParamList = 0; iParamList < pBinding->GetSize(); iParamList++ )
  126.                 {
  127.                     pBinding->GetAt( iParamList ).Reset();
  128.                 }
  129.                 
  130.                 // Remove all the bound parameter lists
  131.                 pBinding->RemoveAll();
  132.             }
  133.         }
  134.     }
  135. }
  136.  
  137.  
  138. //-------------------------------------------------------------------------------------
  139. HRESULT CDXUTEffectMap::SetStandardParameter( const WCHAR* strSemantic, 
  140.                                          const WCHAR* strObject, 
  141.                                          DWORD dwObjectIndex, 
  142.                                          float* pData, 
  143.                                          DWORD dwDataLen, 
  144.                                          const WCHAR* strType, 
  145.                                          const WCHAR* strUnits, 
  146.                                          const WCHAR* strSpace )
  147. {
  148.     // Map the semantic to the standard set
  149.     DXUT_SEMANTIC eSemantic = StringToSemantic( strSemantic );
  150.     if( eSemantic == DXUT_UNKNOWN_SEMANTIC )
  151.         return E_FAIL;
  152.  
  153.     // Map the object to the standard set
  154.     DXUT_OBJECT eObject = StringToObject( strObject );
  155.     if( eObject == DXUT_UNKNOWN_OBJECT )
  156.         return E_FAIL;  
  157.  
  158.     return SetStandardParameter( eSemantic, eObject, dwObjectIndex, pData, dwDataLen, strType, strUnits, strSpace );
  159. }
  160.  
  161.  
  162. //-------------------------------------------------------------------------------------
  163. HRESULT CDXUTEffectMap::SetStandardParameter( DXUT_SEMANTIC eSemantic, 
  164.                                          DXUT_OBJECT eObject, 
  165.                                          DWORD dwObjectIndex, 
  166.                                          float* pData, 
  167.                                          DWORD dwDataLen, 
  168.                                          const WCHAR* strType, 
  169.                                          const WCHAR* strUnits, 
  170.                                          const WCHAR* strSpace )
  171. {
  172.     HRESULT hr;
  173.  
  174.     // TODO: remove index limits
  175.     if( dwObjectIndex >= MAX_INDEX )
  176.         return E_INVALIDARG;
  177.  
  178.     // TODO: handle unit and space conversions
  179.  
  180.     // Retrieve the interested handles
  181.     CGrowableArray<ParamList>* pBindings = &m_Bindings[ eSemantic ][ eObject ][ dwObjectIndex ];
  182.         
  183.     for( int iList=0; iList < pBindings->GetSize(); iList++ )
  184.     {
  185.         ParamList& paramList = pBindings->GetAt(iList);
  186.  
  187.         for( int iParam=0; iParam < paramList.ahParameters.GetSize(); iParam++ )
  188.         {
  189.             V_RETURN( paramList.pEffect->SetFloatArray( paramList.ahParameters[iParam], pData, dwDataLen ) );
  190.         }
  191.     }
  192.  
  193.     return S_OK;
  194. }
  195.  
  196. void ParamList::Reset() 
  197.     SAFE_RELEASE(pEffect); 
  198.     ahParameters.RemoveAll(); 
  199. }
  200.  
  201.  
  202. //-------------------------------------------------------------------------------------
  203. // Investigates all the parameters, looking at semantics and annotations and placing 
  204. // handles to these parameters within the internal database.
  205. //-------------------------------------------------------------------------------------
  206. HRESULT CDXUTEffectMap::AddEffect( ID3DXEffect* pEffect )
  207. {
  208.     HRESULT hr;
  209.  
  210.     if( pEffect == NULL )
  211.         return E_INVALIDARG;
  212.  
  213.     // Get the number of parameters
  214.     D3DXEFFECT_DESC descEffect;
  215.     V_RETURN( pEffect->GetDesc( &descEffect ) );
  216.     
  217.     // Enumerate the parameters
  218.     for( UINT iParam=0; iParam < descEffect.Parameters; iParam++ )
  219.     {
  220.         // Retrieve param
  221.         D3DXHANDLE hParameter = pEffect->GetParameter( NULL, iParam );
  222.         if( NULL == hParameter )
  223.             return E_FAIL;
  224.  
  225.         // Grab description
  226.         D3DXPARAMETER_DESC desc;
  227.         V_RETURN( pEffect->GetParameterDesc( hParameter, &desc ) );
  228.  
  229.         // If this parameter doesn't have a semantic, skip to the next parameter
  230.         if( desc.Semantic == NULL )
  231.             continue;
  232.  
  233.         // Map the semantic to the standard set
  234.         DXUT_SEMANTIC eSemantic = StringToSemantic( desc.Semantic );
  235.         if( eSemantic == DXUT_UNKNOWN_SEMANTIC )
  236.             continue;
  237.  
  238.         // Get the object annotation
  239.         const char* cstrObject = "Geometry";
  240.         D3DXHANDLE hAnnotation = pEffect->GetAnnotationByName( hParameter, "Object" );
  241.         if( hAnnotation )
  242.         {
  243.             V_RETURN( pEffect->GetString( hAnnotation, &cstrObject ) );
  244.         }
  245.  
  246.         // Map the object to the standard set
  247.         DXUT_OBJECT eObject = StringToObject( cstrObject );
  248.         if( eObject == DXUT_UNKNOWN_OBJECT )
  249.             continue;
  250.  
  251.         // Extract the index from the semantic
  252.         int index = 0;
  253.         const char* strIndex = desc.Semantic + strlen(desc.Semantic)-1;
  254.  
  255.         // If there is a digit at the end of the semantic, locate the beginning of the index
  256.         // and convert to an integer
  257.         if( isdigit( (BYTE) (*strIndex) ) )
  258.         {
  259.             while( isdigit( (BYTE) (*(strIndex-1)) ) )
  260.             {
  261.                 --strIndex;
  262.             }
  263.  
  264.             index = atoi( strIndex );
  265.         }
  266.  
  267.         // Check whether index is out of bounds
  268.         if( index < 0 || index >= MAX_INDEX )
  269.             continue;
  270.  
  271.         // Store the handle
  272.         CGrowableArray<ParamList>* pBindings = &m_Bindings[ eSemantic ][ eObject ][ index ];
  273.         
  274.         bool bBound = false;
  275.         for( int i=0; i < pBindings->GetSize(); i++ )
  276.         {
  277.             if( pBindings->GetAt(i).pEffect == pEffect )
  278.             {
  279.                 // Found the containing effect for this parameter in the list, add the new handle
  280.                 pBindings->GetAt(i).ahParameters.Add( hParameter );
  281.                 bBound = true;
  282.                 break;
  283.             }
  284.         }
  285.  
  286.         if( !bBound )
  287.         {
  288.             // This parameter belongs to a new effect
  289.             ParamList newParamList;
  290.             newParamList.pEffect = pEffect;
  291.             pEffect->AddRef();
  292.             newParamList.ahParameters.Add( hParameter );
  293.             pBindings->Add( newParamList );
  294.         }
  295.        
  296.     }
  297.     
  298.     return S_OK;
  299. }
  300.  
  301.  
  302. //-------------------------------------------------------------------------------------
  303. // Removes all instances of this effect from the binding list
  304. //-------------------------------------------------------------------------------------
  305. HRESULT CDXUTEffectMap::RemoveEffect( ID3DXEffect* pEffect )
  306. {
  307.     if( pEffect == NULL )
  308.         return E_INVALIDARG;
  309.  
  310.     // Search through the list of registered semantics and remove all items
  311.     // assigned to the given effect
  312.     for( UINT iSemantic = 0; iSemantic < NUM_DXUT_SEMANTICS; iSemantic++ )
  313.     {
  314.         for( UINT iObject = 0; iObject < NUM_DXUT_OBJECTS; iObject++ )
  315.         {
  316.             for( UINT iIndex = 0; iIndex < MAX_INDEX; iIndex++ )
  317.             {
  318.                 CGrowableArray<ParamList>* pBinding = &m_Bindings[ iSemantic ][ iObject ][ iIndex ];
  319.  
  320.                 // Clear nested arrays first
  321.                 for( int iParamList = 0; iParamList < pBinding->GetSize(); iParamList++ )
  322.                 {
  323.                     ParamList& rParamList = pBinding->GetAt( iParamList );
  324.  
  325.                     if( rParamList.pEffect == pEffect )
  326.                         rParamList.Reset();
  327.                 }
  328.             }
  329.         }
  330.     }
  331.  
  332.     return S_OK;
  333. }
  334.  
  335.  
  336. //-------------------------------------------------------------------------------------
  337. HRESULT CDXUTEffectMap::SetWorldMatrix( D3DXMATRIXA16* pWorldMatrix, const WCHAR* strUnits )
  338. {
  339.     m_matWorld = *pWorldMatrix;
  340.     return UpdateTransforms( DXUT_World );
  341. }
  342.  
  343.  
  344. //-------------------------------------------------------------------------------------
  345. HRESULT CDXUTEffectMap::SetViewMatrix( D3DXMATRIXA16* pViewMatrix, const WCHAR* strUnits )
  346. {
  347.     m_matView = *pViewMatrix;
  348.     return UpdateTransforms( DXUT_View );
  349. }
  350.  
  351.  
  352. //-------------------------------------------------------------------------------------
  353. HRESULT CDXUTEffectMap::SetProjectionMatrix( D3DXMATRIXA16* pProjectionMatrix )
  354. {
  355.     m_matProjection = *pProjectionMatrix;
  356.     return UpdateTransforms( DXUT_Projection );
  357. }
  358.  
  359.  
  360. //-------------------------------------------------------------------------------------
  361. HRESULT CDXUTEffectMap::UpdateTransforms( DXUT_SEMANTIC eSemantic, const WCHAR* strUnits )
  362. {
  363.     HRESULT hr;
  364.  
  365.     // Determine which transforms are required by the effect
  366.     bool bEffectContains[ NUM_DXUT_SEMANTICS ] = {0};
  367.     for( int iTransform = DXUT_World; iTransform <= DXUT_ProjectionInverseTranspose; iTransform++ )
  368.     {
  369.         bEffectContains[iTransform] = ( m_Bindings[ iTransform ][ DXUT_Geometry ][ 0 ].GetSize() > 0 );
  370.     }
  371.  
  372.     if( eSemantic == DXUT_World )
  373.     {
  374.         // World matrix permutations
  375.         if( bEffectContains[ DXUT_World ] ||
  376.             bEffectContains[ DXUT_WorldInverse ] ||
  377.             bEffectContains[ DXUT_WorldInverseTranspose ] )
  378.         {
  379.             V_RETURN( SetStandardParameter( DXUT_World, DXUT_Geometry, 0, (float*)&m_matWorld, 16, L"", strUnits, L"World" ) );
  380.  
  381.             if( bEffectContains[ DXUT_WorldInverse ] ||
  382.                 bEffectContains[ DXUT_WorldInverseTranspose ] )
  383.             {
  384.                 D3DXMATRIXA16 matWorldInverse;
  385.                 D3DXMatrixInverse( &matWorldInverse, NULL, &m_matWorld );
  386.                 V_RETURN( SetStandardParameter( DXUT_WorldInverse, DXUT_Geometry, 0, (float*)&matWorldInverse, 16, L"", strUnits, L"World" ) );
  387.             
  388.                 if( bEffectContains[ DXUT_WorldInverseTranspose ] )
  389.                 {
  390.                     D3DXMATRIXA16 matWorldInverseTranspose;
  391.                     D3DXMatrixTranspose( &matWorldInverseTranspose, &matWorldInverse );
  392.                     V_RETURN( SetStandardParameter( DXUT_WorldInverseTranspose, DXUT_Geometry, 0, (float*)&matWorldInverseTranspose, 16, L"", strUnits, L"World" ) );
  393.                 }
  394.             }
  395.         }
  396.     }
  397.  
  398.     if( eSemantic == DXUT_World ||
  399.         eSemantic == DXUT_View )
  400.     {
  401.         // WorldView matrix permutations
  402.         if( bEffectContains[ DXUT_WorldView ] ||
  403.             bEffectContains[ DXUT_WorldViewInverse ] ||
  404.             bEffectContains[ DXUT_WorldViewInverseTranspose ] )
  405.         {
  406.             D3DXMATRIXA16 matWorldView;
  407.             D3DXMatrixMultiply( &matWorldView, &m_matWorld, &m_matView );
  408.             V_RETURN( SetStandardParameter( DXUT_WorldView, DXUT_Geometry, 0, (float*)&matWorldView, 16, L"", strUnits, L"World" ) );
  409.         
  410.             if( bEffectContains[ DXUT_WorldViewInverse ] ||
  411.                 bEffectContains[ DXUT_WorldViewInverseTranspose ] )
  412.             {
  413.                 D3DXMATRIXA16 matWorldViewInverse;
  414.                 D3DXMatrixInverse( &matWorldViewInverse, NULL, &matWorldView );    
  415.                 V_RETURN( SetStandardParameter( DXUT_WorldViewInverse, DXUT_Geometry, 0, (float*)&matWorldViewInverse, 16, L"", strUnits, L"World" ) );
  416.             
  417.                 if( bEffectContains[ DXUT_WorldViewInverseTranspose ] )
  418.                 {
  419.                     D3DXMATRIXA16 matWorldViewInverseTranspose;
  420.                     D3DXMatrixTranspose( &matWorldViewInverseTranspose, &matWorldViewInverse );
  421.                     V_RETURN( SetStandardParameter( DXUT_WorldViewInverseTranspose, DXUT_Geometry, 0, (float*)&matWorldViewInverseTranspose, 16, L"", strUnits, L"World" ) );
  422.                 }
  423.             }
  424.         }
  425.     }
  426.  
  427.     if( eSemantic == DXUT_World ||
  428.         eSemantic == DXUT_View ||
  429.         eSemantic == DXUT_Projection )
  430.     {
  431.         // WorldViewProjection matrix permutations
  432.         if( bEffectContains[ DXUT_WorldViewProjection ] ||
  433.             bEffectContains[ DXUT_WorldViewProjectionInverse ] ||
  434.             bEffectContains[ DXUT_WorldViewProjectionInverseTranspose ] )
  435.         {
  436.             D3DXMATRIXA16 matWorldViewProjection;
  437.             D3DXMatrixMultiply( &matWorldViewProjection, &m_matWorld, &m_matView );
  438.             D3DXMatrixMultiply( &matWorldViewProjection, &matWorldViewProjection, &m_matProjection );
  439.  
  440.             V_RETURN( SetStandardParameter( DXUT_WorldViewProjection, DXUT_Geometry, 0, (float*)&matWorldViewProjection, 16, L"", strUnits, L"World" ) );
  441.         
  442.             if( bEffectContains[ DXUT_WorldViewProjectionInverse ] ||
  443.                 bEffectContains[ DXUT_WorldViewProjectionInverseTranspose ] )
  444.             {
  445.                 D3DXMATRIXA16 matWorldViewProjectionInverse;
  446.                 D3DXMatrixInverse( &matWorldViewProjectionInverse, NULL, &matWorldViewProjection );    
  447.                 V_RETURN( SetStandardParameter( DXUT_WorldViewProjectionInverse, DXUT_Geometry, 0, (float*)&matWorldViewProjectionInverse, 16, L"", strUnits, L"World" ) );
  448.             
  449.                 if( bEffectContains[ DXUT_WorldViewProjectionInverseTranspose ] )
  450.                 {
  451.                     D3DXMATRIXA16 matWorldViewProjectionInverseTranspose;
  452.                     D3DXMatrixTranspose( &matWorldViewProjectionInverseTranspose, &matWorldViewProjectionInverse );
  453.                     V_RETURN( SetStandardParameter( DXUT_WorldViewProjectionInverseTranspose, DXUT_Geometry, 0, (float*)&matWorldViewProjectionInverseTranspose, 16, L"", strUnits, L"World" ) );
  454.                 }
  455.             }
  456.         }
  457.     }
  458.  
  459.     if( eSemantic == DXUT_View )
  460.     {
  461.         // View matrix permutations
  462.         if( bEffectContains[ DXUT_View ] ||
  463.             bEffectContains[ DXUT_ViewInverse ] ||
  464.             bEffectContains[ DXUT_ViewInverseTranspose ] )
  465.         {
  466.             V_RETURN( SetStandardParameter( DXUT_View, DXUT_Geometry, 0, (float*)&m_matView, 16, L"", strUnits, L"World" ) );
  467.  
  468.             if( bEffectContains[ DXUT_ViewInverse ] ||
  469.                 bEffectContains[ DXUT_ViewInverseTranspose ] )
  470.             {
  471.                 D3DXMATRIXA16 matViewInverse;
  472.                 D3DXMatrixInverse( &matViewInverse, NULL, &m_matView );
  473.                 V_RETURN( SetStandardParameter( DXUT_ViewInverse, DXUT_Geometry, 0, (float*)&matViewInverse, 16, L"", strUnits, L"World" ) );
  474.             
  475.                 if( bEffectContains[ DXUT_ViewInverseTranspose ] )
  476.                 {
  477.                     D3DXMATRIXA16 matViewInverseTranspose;
  478.                     D3DXMatrixTranspose( &matViewInverseTranspose, &matViewInverse );
  479.                     V_RETURN( SetStandardParameter( DXUT_ViewInverseTranspose, DXUT_Geometry, 0, (float*)&matViewInverseTranspose, 16, L"", strUnits, L"World" ) );
  480.                 }
  481.             }
  482.         }
  483.     }
  484.  
  485.     if( eSemantic == DXUT_View ||
  486.         eSemantic == DXUT_Projection )
  487.     {
  488.         // ViewProjection matrix permutations
  489.         if( bEffectContains[ DXUT_ViewProjection ] ||
  490.             bEffectContains[ DXUT_ViewProjectionInverse ] ||
  491.             bEffectContains[ DXUT_ViewProjectionInverseTranspose ] )
  492.         {
  493.             D3DXMATRIXA16 matViewProjection;
  494.             D3DXMatrixMultiply( &matViewProjection, &m_matView, &m_matProjection );
  495.             V_RETURN( SetStandardParameter( DXUT_ViewProjection, DXUT_Geometry, 0, (float*)&matViewProjection, 16, L"", strUnits, L"World" ) );
  496.         
  497.             if( bEffectContains[ DXUT_ViewProjectionInverse ] ||
  498.                 bEffectContains[ DXUT_ViewProjectionInverseTranspose ] )
  499.             {
  500.                 D3DXMATRIXA16 matViewProjectionInverse;
  501.                 D3DXMatrixInverse( &matViewProjectionInverse, NULL, &matViewProjection );    
  502.                 V_RETURN( SetStandardParameter( DXUT_ViewProjectionInverse, DXUT_Geometry, 0, (float*)&matViewProjectionInverse, 16, L"", strUnits, L"World" ) );
  503.             
  504.                 if( bEffectContains[ DXUT_ViewProjectionInverseTranspose ] )
  505.                 {
  506.                     D3DXMATRIXA16 matViewProjectionInverseTranspose;
  507.                     D3DXMatrixTranspose( &matViewProjectionInverseTranspose, &matViewProjectionInverse );
  508.                     V_RETURN( SetStandardParameter( DXUT_ViewProjectionInverseTranspose, DXUT_Geometry, 0, (float*)&matViewProjectionInverseTranspose, 16, L"", strUnits, L"World" ) );
  509.                 }
  510.             }
  511.         }
  512.     }
  513.  
  514.     if( eSemantic == DXUT_Projection )
  515.     {
  516.         // Projection matrix permutations
  517.         if( bEffectContains[ DXUT_Projection ] ||
  518.             bEffectContains[ DXUT_ProjectionInverse ] ||
  519.             bEffectContains[ DXUT_ProjectionInverseTranspose ] )
  520.         {
  521.             V_RETURN( SetStandardParameter( DXUT_Projection, DXUT_Geometry, 0, (float*)&m_matProjection, 16, L"", strUnits, L"World" ) );
  522.  
  523.             if( bEffectContains[ DXUT_ProjectionInverse ] ||
  524.                 bEffectContains[ DXUT_ProjectionInverseTranspose ] )
  525.             {
  526.                 D3DXMATRIXA16 matProjectionInverse;
  527.                 D3DXMatrixInverse( &matProjectionInverse, NULL, &m_matProjection );
  528.                 V_RETURN( SetStandardParameter( DXUT_ProjectionInverse, DXUT_Geometry, 0, (float*)&matProjectionInverse, 16, L"", strUnits, L"World" ) );
  529.             
  530.                 if( bEffectContains[ DXUT_ProjectionInverseTranspose ] )
  531.                 {
  532.                     D3DXMATRIXA16 matProjectionInverseTranspose;
  533.                     D3DXMatrixTranspose( &matProjectionInverseTranspose, &matProjectionInverse );
  534.                     V_RETURN( SetStandardParameter( DXUT_ProjectionInverseTranspose, DXUT_Geometry, 0, (float*)&matProjectionInverseTranspose, 16, L"", strUnits, L"World" ) );
  535.                 }
  536.             }
  537.         }
  538.     }
  539.  
  540.     return S_OK;
  541. }
  542.  
  543.