diff options
| author | Jason Maskell <[email protected]> | 2016-05-19 14:56:31 +0200 |
|---|---|---|
| committer | Jason Maskell <[email protected]> | 2016-05-19 14:56:31 +0200 |
| commit | f7023576ff2f5be202e9c8536d38daeb966fa975 (patch) | |
| tree | e0df3dd4bfbab02626785d618f1147f78e803ec2 /sample | |
| parent | D3D11 test is compiling and running with a rendering error (ocean is grey and... (diff) | |
| download | waveworks_archive-f7023576ff2f5be202e9c8536d38daeb966fa975.tar.xz waveworks_archive-f7023576ff2f5be202e9c8536d38daeb966fa975.zip | |
Lots more conversion work done, not quite compiling yet. Paranoia commit.
Diffstat (limited to 'sample')
| -rw-r--r-- | sample/d3d11/distance_field.cpp | 19 | ||||
| -rw-r--r-- | sample/d3d11/distance_field.h | 6 | ||||
| -rw-r--r-- | sample/d3d11/ocean_surface.cpp | 22 | ||||
| -rw-r--r-- | sample/d3d11/ocean_surface.h | 26 | ||||
| -rw-r--r-- | sample/d3d11/sample_d3d11.cpp | 73 | ||||
| -rw-r--r-- | sample/d3d11/terrain.cpp | 244 |
6 files changed, 219 insertions, 171 deletions
diff --git a/sample/d3d11/distance_field.cpp b/sample/d3d11/distance_field.cpp index ad132ec..3ad7ad7 100644 --- a/sample/d3d11/distance_field.cpp +++ b/sample/d3d11/distance_field.cpp @@ -35,8 +35,6 @@ #pragma warning(disable:4127) -extern HRESULT LoadFile(LPCTSTR FileName, ID3DXBuffer** ppBuffer); - const unsigned int kTopDownDataResolution = 256; DistanceField::DistanceField( CTerrain* const pTerrainRenderer ) @@ -119,13 +117,13 @@ void DistanceField::GenerateDataTexture( ID3D11DeviceContext* pDC ) { if( !m_shouldGenerateDataTexture ) return; - renderTopDownData( pDC, D3DXVECTOR3( 250, 0, 250 ) ); + renderTopDownData( pDC, XMVectorSet( 250, 0, 250, 0 ) ); generateDistanceField( pDC ); m_shouldGenerateDataTexture = false; } -void DistanceField::renderTopDownData( ID3D11DeviceContext* pDC, const D3DXVECTOR3& eyePositionWS ) +void DistanceField::renderTopDownData( ID3D11DeviceContext* pDC, const XMVECTOR eyePositionWS ) { const float kHeightAboveSeaLevel = 300; const float kMinHeightBelowSeaLevel = 20; @@ -147,16 +145,17 @@ void DistanceField::renderTopDownData( ID3D11DeviceContext* pDC, const D3DXVECTO viewport.Height = kTopDownDataResolution; viewport.Width = kTopDownDataResolution; + float ClearColor[4] = { 0.0f, -kMinHeightBelowSeaLevel, 0.0f, 0.0f }; pDC->RSSetViewports(1, &viewport); - pDC->ClearRenderTargetView( m_pTopDownDataRTV, D3DXCOLOR( 0.0f, -kMinHeightBelowSeaLevel, 0.0f, 0.0f ) ); + pDC->ClearRenderTargetView( m_pTopDownDataRTV, ClearColor ); pDC->OMSetRenderTargetsAndUnorderedAccessViews( 1, &m_pTopDownDataRTV, NULL, 0, 0, NULL, NULL ); - m_topDownViewPositionWS = D3DXVECTOR3( eyePositionWS.x, kHeightAboveSeaLevel, eyePositionWS.z ); + m_topDownViewPositionWS = XMVectorSet( XMVectorGetX(eyePositionWS), kHeightAboveSeaLevel, XMVectorGetZ(eyePositionWS), 0 ); const float kOrthoSize = 700; - D3DXMatrixOrthoLH( &m_viewToProjectionMatrix, kOrthoSize, kOrthoSize, 0.3f, kHeightAboveSeaLevel + kMinHeightBelowSeaLevel ); - const D3DXVECTOR3 up = D3DXVECTOR3( 0, 0, 1 ); - D3DXMatrixLookAtLH( &m_worldToViewMatrix, &m_topDownViewPositionWS, &eyePositionWS, &up); + m_viewToProjectionMatrix = XMMatrixOrthographicLH( kOrthoSize, kOrthoSize, 0.3f, kHeightAboveSeaLevel + kMinHeightBelowSeaLevel ); + const XMVECTOR up = XMVectorSet( 0, 0, 1, 0 ); + m_worldToViewMatrix = XMMatrixLookAtLH( m_topDownViewPositionWS, eyePositionWS, up); m_pTerrainRenderer->RenderTerrainToHeightField( pDC, m_worldToViewMatrix, m_viewToProjectionMatrix, m_topDownViewPositionWS, m_viewDirectionWS ); @@ -286,7 +285,7 @@ float DistanceField::FindNearestPixel( float* pTextureData, const int cx, const return originPositive ? -minDistance/kMaxDistance : minDistance/kMaxDistance; } -void DistanceField::GetWorldToTopDownTextureMatrix( D3DXMATRIX& worldToTopDownMatrix ) +void DistanceField::GetWorldToTopDownTextureMatrix( XMMATRIX worldToTopDownMatrix ) { worldToTopDownMatrix = m_worldToViewMatrix * m_viewToProjectionMatrix; }
\ No newline at end of file diff --git a/sample/d3d11/distance_field.h b/sample/d3d11/distance_field.h index bbc217d..7f566e7 100644 --- a/sample/d3d11/distance_field.h +++ b/sample/d3d11/distance_field.h @@ -43,7 +43,7 @@ struct DistanceField // --------------------------------- Accessors ----------------------------------- ID3D11ShaderResourceView* GetDataTextureSRV() const { return m_pTopDownDataSRV; } - void GetWorldToTopDownTextureMatrix( XMMATRIX& worldToTopDownMatrix ); + void GetWorldToTopDownTextureMatrix( XMMATRIX worldToTopDownMatrix ); // --------------------------------- Rendering routines ----------------------------------- void GenerateDataTexture(ID3D11DeviceContext* pDC ); @@ -71,8 +71,8 @@ private: bool m_shouldGenerateDataTexture; - void renderTopDownData(ID3D11DeviceContext* pDC, const XMVECTOR& eyePositionWS); - void generateDistanceField( ID3D11DeviceContext* pDC ); + void renderTopDownData(ID3D11DeviceContext* pDC, const XMVECTOR eyePositionWS); + void generateDistanceField(ID3D11DeviceContext* pDC); bool checkPixel( float* pTextureData, const int cx, const int cy, const int dx, const int dy) const; float FindNearestPixel( float* pTextureData, const int cx, const int cy, float&, float&); }; diff --git a/sample/d3d11/ocean_surface.cpp b/sample/d3d11/ocean_surface.cpp index 8483d8c..ed88415 100644 --- a/sample/d3d11/ocean_surface.cpp +++ b/sample/d3d11/ocean_surface.cpp @@ -34,7 +34,6 @@ #pragma warning(disable:4127) -extern HRESULT LoadFile(LPCTSTR FileName, ID3DXBuffer** ppBuffer); OceanSurface::OceanSurface() { @@ -149,13 +148,14 @@ HRESULT OceanSurface::init() if(NULL == m_pOceanFX) { - ID3DXBuffer* pEffectBuffer = NULL; + ID3DBlob* pEffectBuffer = NULL; TCHAR path[MAX_PATH]; - DXUTFindDXSDKMediaFileCch(path, MAX_PATH, TEXT("..\\Media\\ocean_surface_d3d11.fxo")); - V_RETURN(LoadFile(path, &pEffectBuffer)); - V_RETURN(D3DX11CreateEffectFromMemory(pEffectBuffer->GetBufferPointer(), pEffectBuffer->GetBufferSize(), 0, m_pd3dDevice, &m_pOceanFX)); - pEffectBuffer->Release(); + + V_RETURN(DXUTFindDXSDKMediaFileCch(path, MAX_PATH, TEXT("ocean_surface_d3d11.fxo"))); + V_RETURN(D3DX11CreateEffectFromFile(path, 0, m_pd3dDevice, &m_pOceanFX));// pEffectBuffer->GetBufferPointer(), pEffectBuffer->GetBufferSize(), 0, pd3dDevice, &g_pEffect)); + SAFE_RELEASE(pEffectBuffer); + // Hook up the shader mappings m_pRenderSurfaceTechnique = m_pOceanFX->GetTechniqueByName("RenderOceanSurfTech"); @@ -246,7 +246,7 @@ HRESULT OceanSurface::init() -1, 1, 0, 0, 0, 1,-1, 0}; D3D11_BUFFER_DESC vBufferDesc; - vBufferDesc.ByteWidth = 5 * sizeof(D3DXVECTOR4); + vBufferDesc.ByteWidth = 5 * sizeof(XMFLOAT4); vBufferDesc.Usage = D3D11_USAGE_DEFAULT; vBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; vBufferDesc.CPUAccessFlags = 0; @@ -276,11 +276,11 @@ HRESULT OceanSurface::init() void OceanSurface::renderShaded( ID3D11DeviceContext* pDC, - const D3DXMATRIX& matView, - const D3DXMATRIX& matProj, + const XMMATRIX matView, + const XMMATRIX matProj, GFSDK_WaveWorks_SimulationHandle hSim, GFSDK_WaveWorks_SavestateHandle hSavestate, - const D3DXVECTOR2& windDir, + const XMFLOAT2 windDir, const float steepness, const float amplitude, const float wavelength, @@ -296,7 +296,7 @@ void OceanSurface::renderShaded( ID3D11DeviceContext* pDC, if( pDistanceFieldModule != NULL) { // Apply data tex SRV - D3DXMATRIX topDownMatrix; + XMMATRIX topDownMatrix; pDistanceFieldModule->GetWorldToTopDownTextureMatrix( topDownMatrix ); m_pOceanFX->GetVariableByName("g_WorldToTopDownTextureMatrix")->AsMatrix()->SetMatrix( &topDownMatrix._11 ); diff --git a/sample/d3d11/ocean_surface.h b/sample/d3d11/ocean_surface.h index ab16964..5910970 100644 --- a/sample/d3d11/ocean_surface.h +++ b/sample/d3d11/ocean_surface.h @@ -63,19 +63,19 @@ public: // --------------------------------- Rendering routines ----------------------------------- // Rendering - void renderShaded( ID3D11DeviceContext* pDC, - const XMMATRIX& matView, - const XMMATRIX& matProj, - GFSDK_WaveWorks_SimulationHandle hSim, - GFSDK_WaveWorks_SavestateHandle hSavestate, - const XMFLOAT2& windDir, - const float steepness, - const float amplitude, - const float wavelength, - const float speed, - const float parallelness, - const float totalTime - ); + void renderShaded( ID3D11DeviceContext* pDC, + const XMMATRIX matView, + const XMMATRIX matProj, + GFSDK_WaveWorks_SimulationHandle hSim, + GFSDK_WaveWorks_SavestateHandle hSavestate, + const XMFLOAT2 windDir, + const float steepness, + const float amplitude, + const float wavelength, + const float speed, + const float parallelness, + const float totalTime); + void getQuadTreeStats(GFSDK_WaveWorks_Quadtree_Stats& stats); // --------------------------------- Surface geometry ----------------------------------- diff --git a/sample/d3d11/sample_d3d11.cpp b/sample/d3d11/sample_d3d11.cpp index 5e5b896..5e750f7 100644 --- a/sample/d3d11/sample_d3d11.cpp +++ b/sample/d3d11/sample_d3d11.cpp @@ -39,6 +39,8 @@ #include "GFSDK_WaveWorks_D3D_Util.h" #include "terrain.h" #include <windows.h> // for QueryPerformanceFrequency/QueryPerformanceCounter +#include "DDSTextureLoader.h" +#include "D3DX11Effect.h" //#define DEBUG_VS // Uncomment this line to debug vertex shaders //#define DEBUG_PS // Uncomment this line to debug pixel shaders @@ -46,7 +48,7 @@ // Disable warning "conditional expression is constant" #pragma warning(disable:4127) -extern HRESULT LoadFile(LPCTSTR FileName, ID3DXBuffer** ppBuffer); +extern HRESULT LoadFile(LPCTSTR FileName, ID3DBlob** ppBuffer); //-------------------------------------------------------------------------------------- // Global variables @@ -84,7 +86,7 @@ GFSDK_WaveWorks_Quadtree_Params g_ocean_quadtree_param; GFSDK_WaveWorks_Quadtree_Stats g_ocean_quadtree_stats; GFSDK_WaveWorks_Simulation_DetailLevel g_max_detail_level = GFSDK_WaveWorks_Simulation_DetailLevel_Normal; -D3DXVECTOR2 g_WindDir = D3DXVECTOR2(0.8f, 0.6f); +XMFLOAT2 g_WindDir = XMFLOAT2(0.8f, 0.6f); bool g_Wireframe = false; bool g_SimulateWater = true; bool g_ForceKick = false; @@ -123,9 +125,9 @@ enum { NumMarkersXY = 10, NumMarkers = NumMarkersXY*NumMarkersXY }; gfsdk_float2 g_readback_marker_coords[NumMarkers]; gfsdk_float4 g_readback_marker_positions[NumMarkers]; -D3DXVECTOR3 g_raycast_origins[NumMarkers]; -D3DXVECTOR3 g_raycast_directions[NumMarkers]; -D3DXVECTOR3 g_raycast_hitpoints[NumMarkers]; +XMVECTOR g_raycast_origins[NumMarkers]; +XMVECTOR g_raycast_directions[NumMarkers]; +XMVECTOR g_raycast_hitpoints[NumMarkers]; bool g_raycast_hittestresults[NumMarkers]; static LARGE_INTEGER g_IntersectRaysPerfCounter, g_IntersectRaysPerfCounterOld, g_IntersectRaysPerfFrequency; float g_IntersectRaysTime; @@ -159,7 +161,6 @@ const FLOAT kMaxWindSpeedBeaufort = 4.0f; //-------------------------------------------------------------------------------------- // Forward declarations //-------------------------------------------------------------------------------------- -bool CALLBACK IsD3D9DeviceAcceptable( D3DCAPS9* pCaps, D3DFORMAT AdapterFormat, D3DFORMAT BackBufferFormat, bool bWindowed, void* pUserContext ); bool CALLBACK IsD3D11DeviceAcceptable( const CD3D11EnumAdapterInfo *AdapterInfo, UINT Output, const CD3D11EnumDeviceInfo *DeviceInfo, DXGI_FORMAT BackBufferFormat, bool bWindowed, void* pUserContext ); bool CALLBACK ModifyDeviceSettings( DXUTDeviceSettings* pDeviceSettings, void* pUserContext ); HRESULT CALLBACK OnD3D11CreateDevice( ID3D11Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ); @@ -215,7 +216,6 @@ INT WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR cmdline, int ) DXUTSetCallbackKeyboard( KeyboardProc ); DXUTSetCallbackFrameMove( OnFrameMove ); - DXUTSetCallbackD3D9DeviceAcceptable( IsD3D9DeviceAcceptable ); DXUTSetCallbackD3D11DeviceAcceptable( IsD3D11DeviceAcceptable ); DXUTSetCallbackD3D11DeviceCreated( OnD3D11CreateDevice ); DXUTSetCallbackD3D11SwapChainResized( OnD3D11ResizedSwapChain ); @@ -365,16 +365,6 @@ void AddGUISet() iY += 20; } -//-------------------------------------------------------------------------------------- -// Called during device initialization, this code checks the device for some -// minimum set of capabilities, and rejects those that don't pass by returning E_FAIL. -//-------------------------------------------------------------------------------------- -bool CALLBACK IsD3D9DeviceAcceptable( D3DCAPS9* pCaps, D3DFORMAT AdapterFormat, - D3DFORMAT BackBufferFormat, bool bWindowed, void* pUserContext ) -{ - return false; -} - bool CALLBACK IsD3D11DeviceAcceptable(const CD3D11EnumAdapterInfo *AdapterInfo, UINT Output, const CD3D11EnumDeviceInfo *DeviceInfo, DXGI_FORMAT BackBufferFormat, bool bWindowed, void* pUserContext ) { @@ -465,7 +455,7 @@ HRESULT CALLBACK OnD3D11CreateDevice( ID3D11Device* pd3dDevice, const DXGI_SURFA } float aspectRatio = (float)pBackBufferSurfaceDesc->Width / (float)pBackBufferSurfaceDesc->Height; - g_Camera.SetProjParams(camera_fov * D3DX_PI / 360.0f, aspectRatio, scene_z_near, scene_z_far); + g_Camera.SetProjParams(camera_fov * XMVectorGetY(DirectX::g_XMPi) / 360.0f, aspectRatio, scene_z_near, scene_z_far); // Ocean sim GFSDK_WaveWorks_InitD3D11(pd3dDevice,NULL,GFSDK_WAVEWORKS_API_GUID); @@ -486,16 +476,14 @@ HRESULT CALLBACK OnD3D11CreateDevice( ID3D11Device* pd3dDevice, const DXGI_SURFA g_pLogoTextureVariable = g_pOceanSurf->m_pOceanFX->GetVariableByName("g_LogoTexture")->AsShaderResource(); ID3D11Resource* pD3D11Resource = NULL; - DXUTFindDXSDKMediaFileCch(path, MAX_PATH, TEXT("..\\media\\nvidia_logo.dds")); - V_RETURN(D3DX11CreateTextureFromFile(pd3dDevice, path, NULL, NULL, &pD3D11Resource, NULL)); - V_RETURN(pd3dDevice->CreateShaderResourceView(pD3D11Resource, NULL, &g_pLogoTex)); + V_RETURN(DXUTFindDXSDKMediaFileCch(path, MAX_PATH, TEXT("nvidia_logo.dds"))); + V_RETURN(DirectX::CreateDDSTextureFromFile(pd3dDevice, static_cast<const wchar_t *>(path), NULL, &g_pLogoTex)); SAFE_RELEASE(pD3D11Resource); // Terrain and sky fx - ID3DXBuffer* pEffectBuffer = NULL; - DXUTFindDXSDKMediaFileCch(path, MAX_PATH, TEXT("..\\Media\\sample_d3d11.fxo")); - V_RETURN(LoadFile(path, &pEffectBuffer)); - V_RETURN(D3DX11CreateEffectFromMemory(pEffectBuffer->GetBufferPointer(), pEffectBuffer->GetBufferSize(), 0, pd3dDevice, &g_pEffect)); + ID3DBlob* pEffectBuffer = NULL; + V_RETURN(DXUTFindDXSDKMediaFileCch(path, MAX_PATH, TEXT("sample_d3d11.fxo"))); + V_RETURN(D3DX11CreateEffectFromFile(path, 0, pd3dDevice, &g_pEffect));// pEffectBuffer->GetBufferPointer(), pEffectBuffer->GetBufferSize(), 0, pd3dDevice, &g_pEffect)); SAFE_RELEASE(pEffectBuffer); // Initialize shoreline interaction. @@ -531,7 +519,7 @@ HRESULT CALLBACK OnD3D11ResizedSwapChain( ID3D11Device* pd3dDevice, IDXGISwapCha V_RETURN( g_SettingsDlg.OnD3D11ResizedSwapChain(pd3dDevice,pBackBufferSurfaceDesc) ); float aspectRatio = (float)pBackBufferSurfaceDesc->Width / (float)pBackBufferSurfaceDesc->Height; - g_Camera.SetProjParams(camera_fov * D3DX_PI / 360.0f, aspectRatio, scene_z_near, scene_z_far); + g_Camera.SetProjParams(camera_fov * XMVectorGetY(DirectX::g_XMPi) / 360.0f, aspectRatio, scene_z_near, scene_z_far); // UI g_HUD.SetLocation(pBackBufferSurfaceDesc->Width-240, 8); @@ -701,16 +689,16 @@ void CALLBACK OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* g_FrameTime = fElapsedTime; - D3DXVECTOR2 ScreenSizeInv(1.0f / (g_Terrain.BackbufferWidth*main_buffer_size_multiplier), 1.0f / (g_Terrain.BackbufferHeight*main_buffer_size_multiplier)); + XMFLOAT2 ScreenSizeInv(1.0f / (g_Terrain.BackbufferWidth*main_buffer_size_multiplier), 1.0f / (g_Terrain.BackbufferHeight*main_buffer_size_multiplier)); ID3DX11Effect* oceanFX = g_pOceanSurf->m_pOceanFX; oceanFX->GetVariableByName("g_ZNear")->AsScalar()->SetFloat(scene_z_near); oceanFX->GetVariableByName("g_ZFar")->AsScalar()->SetFloat(scene_z_far); - D3DXVECTOR3 light_pos = D3DXVECTOR3(140000.0f,65000.0f,40000.0f); - g_pEffect->GetVariableByName("g_LightPosition")->AsVector()->SetFloatVector(light_pos); - g_pEffect->GetVariableByName("g_ScreenSizeInv")->AsVector()->SetFloatVector(ScreenSizeInv); - oceanFX->GetVariableByName("g_ScreenSizeInv")->AsVector()->SetFloatVector(ScreenSizeInv); + XMFLOAT3 light_pos = XMFLOAT3(140000.0f,65000.0f,40000.0f); + g_pEffect->GetVariableByName("g_LightPosition")->AsVector()->SetFloatVector((FLOAT*)&light_pos); + g_pEffect->GetVariableByName("g_ScreenSizeInv")->AsVector()->SetFloatVector((FLOAT*)&ScreenSizeInv); + oceanFX->GetVariableByName("g_ScreenSizeInv")->AsVector()->SetFloatVector((FLOAT*)&ScreenSizeInv); g_pEffect->GetVariableByName("g_DynamicTessFactor")->AsScalar()->SetFloat(g_ocean_quadtree_param.tessellation_lod * 0.25f + 0.1f); g_pOceanSurf->m_pOceanFX->GetVariableByName("g_enableShoreEffects")->AsScalar()->SetFloat(g_enableShoreEffects? 1.0f:0.0f); @@ -766,7 +754,7 @@ void RenderText( double fTime ) // Output statistics g_pTxtHelper->Begin(); g_pTxtHelper->SetInsertionPos( 2, 0 ); - g_pTxtHelper->SetForegroundColor( D3DXCOLOR( 0.9f, 0.9f, 0.9f, 1.0f ) ); + g_pTxtHelper->SetForegroundColor( XMFLOAT4( 0.9f, 0.9f, 0.9f, 1.0f ) ); swprintf_s(buffer, buffer_len, L"Lib build: %S\n", GFSDK_WaveWorks_GetBuildString()); g_pTxtHelper->DrawTextLine(buffer); @@ -776,7 +764,7 @@ void RenderText( double fTime ) if(g_QueryStats) { - g_pTxtHelper->SetForegroundColor( D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f ) ); + g_pTxtHelper->SetForegroundColor( XMFLOAT4( 1.0f, 1.0f, 1.0f, 1.0f ) ); g_pTxtHelper->DrawTextLine(L"----------"); wsprintf(buffer, L"Quad patches drawn : %d\n", g_ocean_quadtree_stats.num_patches_drawn); g_pTxtHelper->DrawTextLine(buffer); @@ -1162,7 +1150,7 @@ void UpdateReadbackPositions() // Returns true and sets Result to intersection point if intersection is found, or returns false and does not update Result // NB: The function does trace the water surface from above or from inside the water volume, but can be easily changed to trace from below water volume // NB: y axiz is up -bool intersectRayWithOcean(D3DXVECTOR3& Result, D3DXVECTOR3 Position, D3DXVECTOR3 Direction, GFSDK_WaveWorks_SimulationHandle hSim, float sea_level) +bool intersectRayWithOcean(XMVECTOR& Result, XMVECTOR Position, XMVECTOR Direction, GFSDK_WaveWorks_SimulationHandle hSim, float sea_level) { gfsdk_float2 test_point; // x,z coordinates of current test point gfsdk_float2 old_test_point; // x,z coordinates of current test point @@ -1179,11 +1167,11 @@ bool intersectRayWithOcean(D3DXVECTOR3& Result, D3DXVECTOR3 Position, D3DXVECTOR const float t_multiplier = 1.8f/(fabs(Direction.y) + 1.0f); // we increase step length at steep angles to speed up the tracing, // but less than 2 to make sure the process converges // and to add some safety to minimize chance of overshooting - D3DXVECTOR3 PositionBSStart; // Vectors used at binary search step - D3DXVECTOR3 PositionBSEnd; + XMVECTOR PositionBSStart; // Vectors used at binary search step + XMVECTOR PositionBSEnd; // normalizing direction - D3DXVec3Normalize(&Direction, &Direction); + Direction = XMVector3Normalize(Direction); // checking if ray is outside of ocean surface volume if((Position.y >= max_displacement + sea_level) && (Direction.y >=0)) return false; @@ -1285,13 +1273,10 @@ void UpdateRaycastPositions() for(int y = 0; y != NumMarkersXY; ++y) { int i = x + y*NumMarkersXY; - g_raycast_origins[i].x = 0; - g_raycast_origins[i].y = 10; - g_raycast_origins[i].z = terrain_gridpoints*terrain_geometry_scale; - g_raycast_directions[i].x = 5.0f*float(x - NumMarkersXY/2.0f); - g_raycast_directions[i].y = -10.0f; - g_raycast_directions[i].z = 5.0f*float(y - NumMarkersXY/2.0f); - D3DXVec3Normalize(&g_raycast_directions[i], &g_raycast_directions[i]); + g_raycast_origins[i] = XMVectorSet(0, 10, terrain_gridpoints*terrain_geometry_scale, 0); + g_raycast_directions[i] = XMVectorSet(5.0f*float(x - NumMarkersXY / 2.0f), -10.0f, 5.0f*float(y - NumMarkersXY / 2.0f), 0); + + g_raycast_directions[i] = XMVector3Normalize(g_raycast_directions[i]); } } g_IntersectRaysTime = 0.f; diff --git a/sample/d3d11/terrain.cpp b/sample/d3d11/terrain.cpp index 5e10537..d8ce061 100644 --- a/sample/d3d11/terrain.cpp +++ b/sample/d3d11/terrain.cpp @@ -53,7 +53,7 @@ extern float g_BaseGerstnerWavelength; extern float g_BaseGerstnerSpeed; extern float g_GerstnerParallelity; extern float g_ShoreTime; -extern XMFLOAT3 g_WindDir; +extern XMFLOAT2 g_WindDir; extern bool g_Wireframe; enum { NumMarkersXY = 10, NumMarkers = NumMarkersXY*NumMarkersXY }; @@ -61,9 +61,9 @@ enum { NumMarkersXY = 10, NumMarkers = NumMarkersXY*NumMarkersXY }; extern gfsdk_float2 g_readback_marker_coords[NumMarkers]; extern gfsdk_float4 g_readback_marker_positions[NumMarkers]; -extern XMFLOAT3 g_raycast_origins[NumMarkers]; -extern XMFLOAT3 g_raycast_directions[NumMarkers]; -extern XMFLOAT3 g_raycast_hitpoints[NumMarkers]; +extern XMVECTOR g_raycast_origins[NumMarkers]; +extern XMVECTOR g_raycast_directions[NumMarkers]; +extern XMVECTOR g_raycast_hitpoints[NumMarkers]; int gp_wrap( int a) { @@ -975,14 +975,23 @@ void CTerrain::RenderTerrainToHeightField(ID3D11DeviceContext* const pContext, c pEffect->GetVariableByName("g_HeightFieldSize")->AsScalar()->SetFloat(terrain_gridpoints*terrain_geometry_scale); XMMATRIX worldToProjectionMatrix = worldToViewMatrix * viewToProjectionMatrix; - XMMATRIX projectionToWorldMatrix = XMMatrixInverse(&XMVectorSet(0, 0, 0, 0), worldToProjectionMatrix); + XMMATRIX projectionToWorldMatrix = XMMatrixInverse(NULL, worldToProjectionMatrix); // D3DXMatrixInverse(&projectionToWorldMatrix, NULL, &worldToProjectionMatrix); - pEffect->GetVariableByName("g_ModelViewMatrix")->AsMatrix()->SetMatrix( worldToViewMatrix ); - pEffect->GetVariableByName("g_ModelViewProjectionMatrix")->AsMatrix()->SetMatrix( worldToProjectionMatrix ); - pEffect->GetVariableByName("g_ModelViewProjectionMatrixInv")->AsMatrix()->SetMatrix( projectionToWorldMatrix ); - pEffect->GetVariableByName("g_CameraPosition")->AsVector()->SetFloatVector( eyePositionWS ); - pEffect->GetVariableByName("g_CameraDirection")->AsVector()->SetFloatVector( viewDirectionWS ); + XMFLOAT4X4 wvMat, wtpMat, ptwMat; + XMFLOAT3 epWS, vdWS; + + XMStoreFloat4x4(&wvMat, worldToViewMatrix); + XMStoreFloat4x4(&wtpMat, worldToProjectionMatrix); + XMStoreFloat4x4(&ptwMat, projectionToWorldMatrix); + XMStoreFloat3(&epWS, eyePositionWS); + XMStoreFloat3(&vdWS, viewDirectionWS); + + pEffect->GetVariableByName("g_ModelViewMatrix")->AsMatrix()->SetMatrix( (FLOAT*) &wvMat ); + pEffect->GetVariableByName("g_ModelViewProjectionMatrix")->AsMatrix()->SetMatrix((FLOAT*)&wtpMat); + pEffect->GetVariableByName("g_ModelViewProjectionMatrixInv")->AsMatrix()->SetMatrix((FLOAT*)&ptwMat); + pEffect->GetVariableByName("g_CameraPosition")->AsVector()->SetFloatVector((FLOAT*)&epWS); + pEffect->GetVariableByName("g_CameraDirection")->AsVector()->SetFloatVector((FLOAT*)&vdWS); pEffect->GetVariableByName("g_HalfSpaceCullSign")->AsScalar()->SetFloat(1.0); pEffect->GetVariableByName("g_HalfSpaceCullPosition")->AsScalar()->SetFloat(terrain_minheight*20); @@ -1142,9 +1151,14 @@ void CTerrain::Render(CFirstPersonCamera *cam) pEffect->GetVariableByName("g_ApplyFog")->AsScalar()->SetFloat(1.0f); pEffect->GetVariableByName("g_FoamIntensityTexture")->AsShaderResource()->SetResource(foam_intensity_textureSRV); pEffect->GetVariableByName("g_FoamDiffuseTexture")->AsShaderResource()->SetResource(foam_diffuse_textureSRV); - D3DXMATRIX topDownMatrix; + + XMMATRIX topDownMatrix; g_pOceanSurf->pDistanceFieldModule->GetWorldToTopDownTextureMatrix( topDownMatrix ); - pEffect->GetVariableByName("g_WorldToTopDownTextureMatrix" )->AsMatrix()->SetMatrix(&topDownMatrix._11); + + XMFLOAT4X4 tdMat; + XMStoreFloat4x4(&tdMat, topDownMatrix); + + pEffect->GetVariableByName("g_WorldToTopDownTextureMatrix")->AsMatrix()->SetMatrix((FLOAT*)&tdMat); pEffect->GetVariableByName("g_Time" )->AsScalar()->SetFloat( g_ShoreTime ); pEffect->GetVariableByName("g_DataTexture" )->AsShaderResource()->SetResource( g_pOceanSurf->pDistanceFieldModule->GetDataTextureSRV() ); pEffect->GetVariableByName("g_GerstnerSteepness")->AsScalar()->SetFloat( g_GerstnerSteepness ); @@ -1242,17 +1256,25 @@ void CTerrain::Render(CFirstPersonCamera *cam) oceanFX->GetVariableByName("g_FoamIntensityTexture")->AsShaderResource()->SetResource(foam_intensity_textureSRV); oceanFX->GetVariableByName("g_FoamDiffuseTexture")->AsShaderResource()->SetResource(foam_diffuse_textureSRV); - const D3DXMATRIX matView = D3DXMATRIX(1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1) * *cam->GetViewMatrix(); - const D3DXMATRIX matProj = *cam->GetProjMatrix(); - D3DXVECTOR3 cameraPosition = *cam->GetEyePt(); - D3DXVECTOR3 lightPosition = D3DXVECTOR3(14000.0f,6500.0f,4000.0f); + XMMATRIX matView = XMMatrixSet(1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1) * cam->GetViewMatrix(); + XMMATRIX matProj = cam->GetProjMatrix(); + XMMATRIX matMVP = matView * matProj; + XMVECTOR cameraPosition = cam->GetEyePt(); + XMVECTOR lightPosition = XMVectorSet(14000.0f, 6500.0f, 4000.0f, 0); - oceanFX->GetVariableByName("g_ModelViewMatrix")->AsMatrix()->SetMatrix(matView); - oceanFX->GetVariableByName("g_ModelViewProjectionMatrix")->AsMatrix()->SetMatrix(matView*matProj); - oceanFX->GetVariableByName("g_CameraPosition")->AsVector()->SetFloatVector(cameraPosition); - oceanFX->GetVariableByName("g_LightPosition")->AsVector()->SetFloatVector(lightPosition); +// const D3DXMATRIX matView = D3DXMATRIX(1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1) * *cam->GetViewMatrix(); +// const D3DXMATRIX matProj = *cam->GetProjMatrix(); +// D3DXVECTOR3 cameraPosition = *cam->GetEyePt(); +// D3DXVECTOR3 lightPosition = D3DXVECTOR3(14000.0f,6500.0f,4000.0f); +// + oceanFX->GetVariableByName("g_ModelViewMatrix")->AsMatrix()->SetMatrix((FLOAT*)&matView); + oceanFX->GetVariableByName("g_ModelViewProjectionMatrix")->AsMatrix()->SetMatrix((FLOAT*)&matMVP); + oceanFX->GetVariableByName("g_CameraPosition")->AsVector()->SetFloatVector((FLOAT*)&cameraPosition); + oceanFX->GetVariableByName("g_LightPosition")->AsVector()->SetFloatVector((FLOAT*)&lightPosition); oceanFX->GetVariableByName("g_Wireframe")->AsScalar()->SetFloat(g_Wireframe ? 1.0f : 0.0f); - oceanFX->GetVariableByName("g_WinSize")->AsVector()->SetFloatVector(D3DXVECTOR4(main_Viewport.Width,main_Viewport.Height,0,0)); + + XMFLOAT4 winSize = XMFLOAT4(main_Viewport.Width, main_Viewport.Height, 0, 0); + oceanFX->GetVariableByName("g_WinSize")->AsVector()->SetFloatVector((FLOAT*)&winSize); g_pOceanSurf->renderShaded(pContext, matView,matProj,g_hOceanSimulation, g_hOceanSavestate, g_WindDir, g_GerstnerSteepness, g_BaseGerstnerAmplitude, g_BaseGerstnerWavelength, g_BaseGerstnerSpeed, g_GerstnerParallelity, g_ShoreTime); g_pOceanSurf->getQuadTreeStats(g_ocean_quadtree_stats); @@ -1272,14 +1294,17 @@ void CTerrain::Render(CFirstPersonCamera *cam) // drawing readback markers to main buffer const UINT vbOffset = 0; - const UINT vertexStride = sizeof(D3DXVECTOR4); + const UINT vertexStride = sizeof(XMFLOAT4); + XMFLOAT4 contactPos; + pContext->IASetInputLayout(g_pOceanSurf->m_pRayContactLayout); pContext->IASetVertexBuffers(0, 1, &g_pOceanSurf->m_pContactVB, &vertexStride, &vbOffset); pContext->IASetIndexBuffer(g_pOceanSurf->m_pContactIB, DXGI_FORMAT_R16_UINT, 0); pContext->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST); for( int i = 0; i < NumMarkers; i++) { - g_pOceanSurf->m_pOceanFX->GetVariableByName("g_ContactPosition")->AsVector()->SetFloatVector(D3DXVECTOR4(g_readback_marker_positions[i].x,g_readback_marker_positions[i].y,g_readback_marker_positions[i].z,0)); + contactPos = XMFLOAT4(g_readback_marker_positions[i].x, g_readback_marker_positions[i].y, g_readback_marker_positions[i].z, 0); + g_pOceanSurf->m_pOceanFX->GetVariableByName("g_ContactPosition")->AsVector()->SetFloatVector((FLOAT*)&contactPos); g_pOceanSurf->m_pRenderRayContactTechnique->GetPassByIndex(0)->Apply(0, pContext); pContext->DrawIndexed(12, 0, 0); } @@ -1290,18 +1315,29 @@ void CTerrain::Render(CFirstPersonCamera *cam) pContext->IASetVertexBuffers(0, 1, &g_pOceanSurf->m_pContactVB, &vertexStride, &vbOffset); pContext->IASetIndexBuffer(g_pOceanSurf->m_pContactIB, DXGI_FORMAT_R16_UINT, 0); pContext->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + for( int i = 0; i < NumMarkers; i++) { - g_pOceanSurf->m_pOceanFX->GetVariableByName("g_ContactPosition")->AsVector()->SetFloatVector(D3DXVECTOR4(g_raycast_hitpoints[i].x, g_raycast_hitpoints[i].z, g_raycast_hitpoints[i].y, 0.0f)); + XMStoreFloat4(&contactPos, g_raycast_hitpoints[i]); + + g_pOceanSurf->m_pOceanFX->GetVariableByName("g_ContactPosition")->AsVector()->SetFloatVector((FLOAT*)&contactPos); g_pOceanSurf->m_pRenderRayContactTechnique->GetPassByIndex(0)->Apply(0, pContext); pContext->DrawIndexed(12, 0, 0); } + + XMFLOAT4 origPos, rayDirection; + // drawing rays to main buffer pContext->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_LINESTRIP); for( int i = 0; i < NumMarkers; i++) { - g_pOceanSurf->m_pOceanFX->GetVariableByName("g_OriginPosition")->AsVector()->SetFloatVector(g_raycast_origins[i]); - g_pOceanSurf->m_pOceanFX->GetVariableByName("g_RayDirection")->AsVector()->SetFloatVector(g_raycast_directions[i]*100.0f); + XMStoreFloat4(&origPos, g_raycast_origins[i]); + g_pOceanSurf->m_pOceanFX->GetVariableByName("g_OriginPosition")->AsVector()->SetFloatVector((FLOAT*)&origPos); + + XMVECTOR vecRayDir = g_raycast_directions[i] * 100.0f; + XMStoreFloat4(&rayDirection, vecRayDir); + + g_pOceanSurf->m_pOceanFX->GetVariableByName("g_RayDirection")->AsVector()->SetFloatVector((FLOAT*) &rayDirection); g_pOceanSurf->m_pRenderRayContactTechnique->GetPassByIndex(1)->Apply(0, pContext); pContext->DrawIndexed(2, 0, 0); } @@ -1362,41 +1398,53 @@ void CTerrain::SetupReflectionView(CFirstPersonCamera *cam) float aspectRatio = BackbufferWidth / BackbufferHeight; - D3DXVECTOR3 EyePoint; - D3DXVECTOR3 LookAtPoint; + XMVECTOR EyePoint; + XMVECTOR LookAtPoint; - EyePoint =*cam->GetEyePt(); - LookAtPoint =*cam->GetLookAtPt(); - EyePoint.y=-1.0f*EyePoint.y+1.0f; - LookAtPoint.y=-1.0f*LookAtPoint.y+1.0f; + EyePoint = cam->GetEyePt(); + LookAtPoint = cam->GetLookAtPt(); + XMVectorSetY(EyePoint, -1.0f*XMVectorGetY(EyePoint) + 1.0f); + XMVectorSetY(LookAtPoint, -1.0f*XMVectorGetY(LookAtPoint) + 1.0f); - D3DXMATRIX mView; - D3DXMATRIX mProj; - D3DXMATRIX mViewProj; - D3DXMATRIX mViewProjInv; - D3DXMATRIX mWorld; - mView = *cam->GetViewMatrix(); - mWorld = *cam->GetWorldMatrix(); + XMMATRIX mView = cam->GetViewMatrix(); + XMMATRIX mProj; + XMMATRIX mViewProj; + XMMATRIX mViewProjInv; - mWorld._42=-mWorld._42-1.0f; + XMMATRIX mWorld = cam->GetWorldMatrix(); + XMFLOAT4X4 mWorldTweak; + XMStoreFloat4x4(&mWorldTweak, mWorld); + + mWorldTweak._42 = -mWorldTweak._42 - 1.0f; - mWorld._21*=-1.0f; - mWorld._23*=-1.0f; + mWorldTweak._21 *= -1.0f; + mWorldTweak._23 *= -1.0f; + + mWorldTweak._32 *= -1.0f; - mWorld._32*=-1.0f; + mWorld = XMLoadFloat4x4(&mWorldTweak); - D3DXMatrixInverse(&mView, NULL, &mWorld); - D3DXMatrixPerspectiveFovLH(&mProj,camera_fov * D3DX_PI / 360.0f,aspectRatio,scene_z_near,scene_z_far); - mViewProj=mView*mProj; - D3DXMatrixInverse(&mViewProjInv, NULL, &mViewProj); + mView = XMMatrixInverse(NULL, mWorld); + mProj = XMMatrixPerspectiveFovLH(camera_fov * XMVectorGetY(DirectX::g_XMPi) / 360.0f, aspectRatio, scene_z_near, scene_z_far); + mViewProj = mView * mProj; + mViewProjInv = XMMatrixInverse(NULL, mViewProj); + + XMFLOAT4X4 mvpStore; + XMFLOAT4 epStore; + + XMStoreFloat4x4(&mvpStore, mViewProj); + XMStoreFloat4(&epStore, EyePoint); - pEffect->GetVariableByName("g_ModelViewProjectionMatrix")->AsMatrix()->SetMatrix(mViewProj); - pEffect->GetVariableByName("g_CameraPosition")->AsVector()->SetFloatVector(EyePoint); - D3DXVECTOR3 direction = LookAtPoint - EyePoint; - D3DXVECTOR3 normalized_direction = *D3DXVec3Normalize(&normalized_direction,&direction); - pEffect->GetVariableByName("g_CameraDirection")->AsVector()->SetFloatVector(normalized_direction); + pEffect->GetVariableByName("g_ModelViewProjectionMatrix")->AsMatrix()->SetMatrix((FLOAT*)&mvpStore); + pEffect->GetVariableByName("g_CameraPosition")->AsVector()->SetFloatVector((FLOAT*)&epStore); + + XMVECTOR normalized_direction = XMVector3Normalize(LookAtPoint - EyePoint); + XMFLOAT4 ndStore; + XMStoreFloat4(&ndStore, normalized_direction); + + pEffect->GetVariableByName("g_CameraDirection")->AsVector()->SetFloatVector((FLOAT*) &ndStore); pEffect->GetVariableByName("g_HalfSpaceCullSign")->AsScalar()->SetFloat(1.0f); pEffect->GetVariableByName("g_HalfSpaceCullPosition")->AsScalar()->SetFloat(0); @@ -1410,31 +1458,40 @@ void CTerrain::SetupRefractionView(CFirstPersonCamera *cam) void CTerrain::SetupLightView(CFirstPersonCamera *cam) { - D3DXVECTOR3 EyePoint= D3DXVECTOR3(14000.0f,6500.0f,4000.0f); - D3DXVECTOR3 LookAtPoint = D3DXVECTOR3(terrain_far_range/2.0f,0.0f,terrain_far_range/2.0f); - D3DXVECTOR3 lookUp = D3DXVECTOR3(0,1,0); - D3DXVECTOR3 cameraPosition = *cam->GetEyePt(); + XMVECTOR EyePoint = XMVectorSet(14000.0f,6500.0f,4000.0f, 0); + XMVECTOR LookAtPoint = XMVectorSet(terrain_far_range / 2.0f, 0.0f, terrain_far_range / 2.0f, 0); + XMVECTOR lookUp = XMVectorSet(0, 1, 0, 0); + XMVECTOR cameraPosition = cam->GetEyePt(); float nr, fr; - nr=sqrt(EyePoint.x*EyePoint.x+EyePoint.y*EyePoint.y+EyePoint.z*EyePoint.z)-terrain_far_range*1.0f; - fr=sqrt(EyePoint.x*EyePoint.x+EyePoint.y*EyePoint.y+EyePoint.z*EyePoint.z)+terrain_far_range*1.0f; + nr=sqrt(XMVectorGetX(EyePoint)*XMVectorGetX(EyePoint)+XMVectorGetY(EyePoint)*XMVectorGetY(EyePoint)+XMVectorGetZ(EyePoint)*XMVectorGetZ(EyePoint))-terrain_far_range*1.0f; + fr=sqrt(XMVectorGetX(EyePoint)*XMVectorGetX(EyePoint)+XMVectorGetY(EyePoint)*XMVectorGetY(EyePoint)+XMVectorGetZ(EyePoint)*XMVectorGetZ(EyePoint))+terrain_far_range*1.0f; + + XMMATRIX mView = XMMatrixLookAtLH(EyePoint, LookAtPoint, lookUp); // *D3DXMatrixLookAtLH(&mView, &EyePoint, &LookAtPoint, &lookUp); + XMMATRIX mProjMatrix = XMMatrixOrthographicLH(terrain_far_range*1.5, terrain_far_range, nr, fr); //*D3DXMatrixOrthoLH(&mProjMatrix, terrain_far_range*1.5, terrain_far_range, nr, fr); + XMMATRIX mViewProj = mView * mProjMatrix; + XMMATRIX mViewProjInv; - D3DXMATRIX mView = *D3DXMatrixLookAtLH(&mView,&EyePoint,&LookAtPoint,&lookUp); - D3DXMATRIX mProjMatrix = *D3DXMatrixOrthoLH(&mProjMatrix,terrain_far_range*1.5,terrain_far_range,nr,fr); - D3DXMATRIX mViewProj = mView * mProjMatrix; - D3DXMATRIX mViewProjInv; - D3DXMatrixInverse(&mViewProjInv, NULL, &mViewProj); + mViewProjInv = XMMatrixInverse(NULL, mViewProj); + + XMFLOAT4X4 vpStore, vpiStore; + XMStoreFloat4x4(&vpStore, mViewProj); + XMStoreFloat4x4(&vpiStore, mViewProjInv); + XMFLOAT4 camStore, ndStore; + XMStoreFloat4(&camStore, cameraPosition); ID3DX11Effect* oceanFX = g_pOceanSurf->m_pOceanFX; - oceanFX->GetVariableByName("g_LightModelViewProjectionMatrix")->AsMatrix()->SetMatrix(mViewProj); + oceanFX->GetVariableByName("g_LightModelViewProjectionMatrix")->AsMatrix()->SetMatrix((FLOAT*)&vpStore); + + pEffect->GetVariableByName("g_ModelViewProjectionMatrix")->AsMatrix()->SetMatrix((FLOAT*)&vpStore); + pEffect->GetVariableByName("g_LightModelViewProjectionMatrix")->AsMatrix()->SetMatrix((FLOAT*)&vpStore); + pEffect->GetVariableByName("g_LightModelViewProjectionMatrixInv")->AsMatrix()->SetMatrix((FLOAT*)&vpiStore); + pEffect->GetVariableByName("g_CameraPosition")->AsVector()->SetFloatVector((FLOAT*)&camStore); - pEffect->GetVariableByName("g_ModelViewProjectionMatrix")->AsMatrix()->SetMatrix(mViewProj); - pEffect->GetVariableByName("g_LightModelViewProjectionMatrix")->AsMatrix()->SetMatrix(mViewProj); - pEffect->GetVariableByName("g_LightModelViewProjectionMatrixInv")->AsMatrix()->SetMatrix(mViewProjInv); - pEffect->GetVariableByName("g_CameraPosition")->AsVector()->SetFloatVector(cameraPosition); - D3DXVECTOR3 direction = *cam->GetLookAtPt() - *cam->GetEyePt(); - D3DXVECTOR3 normalized_direction = *D3DXVec3Normalize(&normalized_direction,&direction); - pEffect->GetVariableByName("g_CameraDirection")->AsVector()->SetFloatVector(normalized_direction); + XMVECTOR normalized_direction = XMVector3Normalize(cam->GetLookAtPt() - cam->GetEyePt()); + XMStoreFloat4(&ndStore, normalized_direction); + + pEffect->GetVariableByName("g_CameraDirection")->AsVector()->SetFloatVector((FLOAT*)&ndStore); pEffect->GetVariableByName("g_HalfSpaceCullSign")->AsScalar()->SetFloat(1.0); pEffect->GetVariableByName("g_HalfSpaceCullPosition")->AsScalar()->SetFloat(terrain_minheight*2); @@ -1443,25 +1500,32 @@ void CTerrain::SetupLightView(CFirstPersonCamera *cam) void CTerrain::SetupNormalView(CFirstPersonCamera *cam) { - D3DXVECTOR3 EyePoint; - D3DXVECTOR3 LookAtPoint; - - EyePoint =*cam->GetEyePt(); - LookAtPoint =*cam->GetLookAtPt(); - D3DXMATRIX mView = *cam->GetViewMatrix(); - D3DXMATRIX mProjMatrix = *cam->GetProjMatrix(); - D3DXMATRIX mViewProj = mView * mProjMatrix; - D3DXMATRIX mViewProjInv; - D3DXMatrixInverse(&mViewProjInv, NULL, &mViewProj); - D3DXVECTOR3 cameraPosition = *cam->GetEyePt(); - - pEffect->GetVariableByName("g_ModelViewMatrix")->AsMatrix()->SetMatrix(mView); - pEffect->GetVariableByName("g_ModelViewProjectionMatrix")->AsMatrix()->SetMatrix(mViewProj); - pEffect->GetVariableByName("g_ModelViewProjectionMatrixInv")->AsMatrix()->SetMatrix(mViewProjInv); - pEffect->GetVariableByName("g_CameraPosition")->AsVector()->SetFloatVector(cameraPosition); - D3DXVECTOR3 direction = LookAtPoint - EyePoint; - D3DXVECTOR3 normalized_direction = *D3DXVec3Normalize(&normalized_direction,&direction); - pEffect->GetVariableByName("g_CameraDirection")->AsVector()->SetFloatVector(normalized_direction); + XMVECTOR EyePoint = cam->GetEyePt(); + XMVECTOR LookAtPoint = cam->GetLookAtPt(); + + XMMATRIX mView = cam->GetViewMatrix(); + XMMATRIX mProjMatrix = cam->GetProjMatrix(); + XMMATRIX mViewProj = mView * mProjMatrix; + XMMATRIX mViewProjInv = XMMatrixInverse(NULL, mViewProj); + XMVECTOR cameraPosition = cam->GetEyePt(); + + XMFLOAT4X4 vStore, vpStore, vpiStore; + XMStoreFloat4x4(&vStore, mView); + XMStoreFloat4x4(&vpStore, mViewProj); + XMStoreFloat4x4(&vpiStore, mViewProjInv); + + XMFLOAT4 cpStore, ndStore; + XMStoreFloat4(&cpStore, cameraPosition); + + + pEffect->GetVariableByName("g_ModelViewMatrix")->AsMatrix()->SetMatrix((FLOAT*)&vStore); + pEffect->GetVariableByName("g_ModelViewProjectionMatrix")->AsMatrix()->SetMatrix((FLOAT*)&vpStore); + pEffect->GetVariableByName("g_ModelViewProjectionMatrixInv")->AsMatrix()->SetMatrix((FLOAT*)&vpiStore); + pEffect->GetVariableByName("g_CameraPosition")->AsVector()->SetFloatVector((FLOAT*)&cpStore); + + XMVECTOR normalized_direction = XMVector3Normalize(LookAtPoint - EyePoint); + XMStoreFloat4(&ndStore, normalized_direction); + pEffect->GetVariableByName("g_CameraDirection")->AsVector()->SetFloatVector((FLOAT*)&ndStore); pEffect->GetVariableByName("g_HalfSpaceCullSign")->AsScalar()->SetFloat(1.0); pEffect->GetVariableByName("g_HalfSpaceCullPosition")->AsScalar()->SetFloat(terrain_minheight*20); |