diff options
| author | Jason Maskell <[email protected]> | 2016-05-19 15:51:45 +0200 |
|---|---|---|
| committer | Jason Maskell <[email protected]> | 2016-05-19 15:51:45 +0200 |
| commit | b352eb55361a8b92f7cef224db990c00318afeff (patch) | |
| tree | aee2120d1772898cd240ba059f46437b25216119 | |
| parent | Lots more conversion work done, not quite compiling yet. Paranoia commit. (diff) | |
| download | waveworks_archive-b352eb55361a8b92f7cef224db990c00318afeff.tar.xz waveworks_archive-b352eb55361a8b92f7cef224db990c00318afeff.zip | |
Sample now compiles cleanly, doesn't run yet due to media path issues.
| -rw-r--r-- | sample/d3d11/distance_field.cpp | 13 | ||||
| -rw-r--r-- | sample/d3d11/distance_field.h | 8 | ||||
| -rw-r--r-- | sample/d3d11/ocean_surface.cpp | 6 | ||||
| -rw-r--r-- | sample/d3d11/sample_d3d11.cpp | 37 | ||||
| -rw-r--r-- | sample/d3d11/terrain.cpp | 5 |
5 files changed, 38 insertions, 31 deletions
diff --git a/sample/d3d11/distance_field.cpp b/sample/d3d11/distance_field.cpp index 3ad7ad7..61e335b 100644 --- a/sample/d3d11/distance_field.cpp +++ b/sample/d3d11/distance_field.cpp @@ -39,7 +39,7 @@ const unsigned int kTopDownDataResolution = 256; DistanceField::DistanceField( CTerrain* const pTerrainRenderer ) : m_pTerrainRenderer( pTerrainRenderer ) - , m_viewDirectionWS( 0, -1, 0 ) + , m_viewDirectionWS( 0, -1, 0, 0 ) , m_pTopDownDataSRV( NULL ) , m_pTopDownDataRTV( NULL ) , m_pTopDownDataTexture( NULL ) @@ -150,14 +150,15 @@ void DistanceField::renderTopDownData( ID3D11DeviceContext* pDC, const XMVECTOR pDC->ClearRenderTargetView( m_pTopDownDataRTV, ClearColor ); pDC->OMSetRenderTargetsAndUnorderedAccessViews( 1, &m_pTopDownDataRTV, NULL, 0, 0, NULL, NULL ); - m_topDownViewPositionWS = XMVectorSet( XMVectorGetX(eyePositionWS), kHeightAboveSeaLevel, XMVectorGetZ(eyePositionWS), 0 ); + m_topDownViewPositionWS = XMFLOAT4( XMVectorGetX(eyePositionWS), kHeightAboveSeaLevel, XMVectorGetZ(eyePositionWS), 0 ); const float kOrthoSize = 700; - m_viewToProjectionMatrix = XMMatrixOrthographicLH( kOrthoSize, kOrthoSize, 0.3f, kHeightAboveSeaLevel + kMinHeightBelowSeaLevel ); + XMStoreFloat4x4(&m_viewToProjectionMatrix, XMMatrixOrthographicLH(kOrthoSize, kOrthoSize, 0.3f, kHeightAboveSeaLevel + kMinHeightBelowSeaLevel)); + const XMVECTOR up = XMVectorSet( 0, 0, 1, 0 ); - m_worldToViewMatrix = XMMatrixLookAtLH( m_topDownViewPositionWS, eyePositionWS, up); + XMStoreFloat4x4(&m_worldToViewMatrix, XMMatrixLookAtLH(XMLoadFloat4(&m_topDownViewPositionWS), eyePositionWS, up)); - m_pTerrainRenderer->RenderTerrainToHeightField( pDC, m_worldToViewMatrix, m_viewToProjectionMatrix, m_topDownViewPositionWS, m_viewDirectionWS ); + m_pTerrainRenderer->RenderTerrainToHeightField( pDC, XMLoadFloat4x4(&m_worldToViewMatrix), XMLoadFloat4x4(&m_viewToProjectionMatrix), XMLoadFloat4(&m_topDownViewPositionWS), XMLoadFloat4(&m_viewDirectionWS) ); pDC->RSSetViewports(NumViewports, &vp); pDC->OMSetRenderTargetsAndUnorderedAccessViews( 1, &pRenderTarget, pDepthBuffer, 0, 0, NULL, NULL ); @@ -287,5 +288,5 @@ float DistanceField::FindNearestPixel( float* pTextureData, const int cx, const void DistanceField::GetWorldToTopDownTextureMatrix( XMMATRIX worldToTopDownMatrix ) { - worldToTopDownMatrix = m_worldToViewMatrix * m_viewToProjectionMatrix; + worldToTopDownMatrix = XMLoadFloat4x4(&m_worldToViewMatrix) * XMLoadFloat4x4(&m_viewToProjectionMatrix); }
\ No newline at end of file diff --git a/sample/d3d11/distance_field.h b/sample/d3d11/distance_field.h index 7f566e7..5b2e3a2 100644 --- a/sample/d3d11/distance_field.h +++ b/sample/d3d11/distance_field.h @@ -64,10 +64,10 @@ private: ID3D11Texture2D* m_pStagingTexture; // ---------------------------------- Top down camera data ------------------------------------ - XMVECTOR m_topDownViewPositionWS; - XMVECTOR m_viewDirectionWS; - XMMATRIX m_worldToViewMatrix; - XMMATRIX m_viewToProjectionMatrix; + XMFLOAT4 m_topDownViewPositionWS; + XMFLOAT4 m_viewDirectionWS; + XMFLOAT4X4 m_worldToViewMatrix; + XMFLOAT4X4 m_viewToProjectionMatrix; bool m_shouldGenerateDataTexture; diff --git a/sample/d3d11/ocean_surface.cpp b/sample/d3d11/ocean_surface.cpp index ed88415..4bd0dc6 100644 --- a/sample/d3d11/ocean_surface.cpp +++ b/sample/d3d11/ocean_surface.cpp @@ -298,7 +298,11 @@ void OceanSurface::renderShaded( ID3D11DeviceContext* pDC, // Apply data tex SRV XMMATRIX topDownMatrix; pDistanceFieldModule->GetWorldToTopDownTextureMatrix( topDownMatrix ); - m_pOceanFX->GetVariableByName("g_WorldToTopDownTextureMatrix")->AsMatrix()->SetMatrix( &topDownMatrix._11 ); + + XMFLOAT4X4 tdmStore; + XMStoreFloat4x4(&tdmStore, topDownMatrix); + + m_pOceanFX->GetVariableByName("g_WorldToTopDownTextureMatrix")->AsMatrix()->SetMatrix( (FLOAT*)&tdmStore ); m_pOceanFX->GetVariableByName("g_GerstnerSteepness")->AsScalar()->SetFloat( steepness ); m_pOceanFX->GetVariableByName("g_BaseGerstnerAmplitude")->AsScalar()->SetFloat( amplitude ); diff --git a/sample/d3d11/sample_d3d11.cpp b/sample/d3d11/sample_d3d11.cpp index 5e750f7..ff5a1f2 100644 --- a/sample/d3d11/sample_d3d11.cpp +++ b/sample/d3d11/sample_d3d11.cpp @@ -41,6 +41,7 @@ #include <windows.h> // for QueryPerformanceFrequency/QueryPerformanceCounter #include "DDSTextureLoader.h" #include "D3DX11Effect.h" +#include "D3D9types.h" //#define DEBUG_VS // Uncomment this line to debug vertex shaders //#define DEBUG_PS // Uncomment this line to debug pixel shaders @@ -1164,7 +1165,7 @@ bool intersectRayWithOcean(XMVECTOR& Result, XMVECTOR Position, XMVECTOR Directi const int max_num_binary_steps = 16; // we limit ourselves on #of binary search steps const float t_threshold = 0.05f; // we stop successive tracing when we don't progress more than 5 cm each step const float refinement_threshold_sqr = 0.1f*0.1f; // we stop refinement step when we don't progress more than 10cm while doing refinement of current water altitude - const float t_multiplier = 1.8f/(fabs(Direction.y) + 1.0f); // we increase step length at steep angles to speed up the tracing, + const float t_multiplier = 1.8f/(fabs(XMVectorGetY(Direction)) + 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 XMVECTOR PositionBSStart; // Vectors used at binary search step @@ -1174,12 +1175,12 @@ bool intersectRayWithOcean(XMVECTOR& Result, XMVECTOR Position, XMVECTOR Directi Direction = XMVector3Normalize(Direction); // checking if ray is outside of ocean surface volume - if((Position.y >= max_displacement + sea_level) && (Direction.y >=0)) return false; + if((XMVectorGetY(Position) >= max_displacement + sea_level) && (XMVectorGetY(Direction) >=0)) return false; // getting to the top edge of volume where we can start - if(Position.y > max_displacement + sea_level) + if(XMVectorGetY(Position) > max_displacement + sea_level) { - t = -(Position.y - max_displacement - sea_level) / Direction.y; + t = -(XMVectorGetY(Position) - max_displacement - sea_level) / XMVectorGetY(Direction); Position += t*Direction; } @@ -1198,15 +1199,15 @@ bool intersectRayWithOcean(XMVECTOR& Result, XMVECTOR Position, XMVECTOR Directi // moving back sample points by the displacements read initially, // to get a guess on which undisturbed water surface point moved to the actual sample point // due to x,y motion of water surface, assuming the x,y disturbances are locally constant - test_point.x = Position.x - displacements.x; - test_point.y = Position.z - displacements.y; + test_point.x = XMVectorGetX(Position) - displacements.x; + test_point.y = XMVectorGetZ(Position) - displacements.y; GFSDK_WaveWorks_Simulation_GetDisplacements( hSim, &test_point, &displacements, 1 ); if(refinement_threshold_sqr > (old_test_point.x - test_point.x)*(old_test_point.x - test_point.x) + (old_test_point.y - test_point.y)*(old_test_point.y - test_point.y)) break; old_test_point.x = test_point.x; old_test_point.y = test_point.y; } // getting t to travel along the ray - t = t_multiplier * (Position.y - displacements.z - sea_level); + t = t_multiplier * (XMVectorGetY(Position) - displacements.z - sea_level); // traveling along the ray Position += t*Direction; @@ -1219,20 +1220,18 @@ bool intersectRayWithOcean(XMVECTOR& Result, XMVECTOR Position, XMVECTOR Directi // exited the loop, checking if intersection is found if(t < t_threshold) { - Result.x = Position.x; - Result.y = Position.y; - Result.z = Position.z; + Result = Position; return true; } // if we're looking down and we did not hit water surface, doing binary search to make sure we hit water surface, // but there is risk of shooting through wave tips if we are tracing at extremely steep angles - if(Direction.y < 0) + if(XMVectorGetY(Direction) < 0) { PositionBSStart = Position; // getting to the bottom edge of volume where we can start - t = -(Position.y + max_displacement - sea_level) / Direction.y; + t = -(XMVectorGetY(Position) + max_displacement - sea_level) / XMVectorGetY(Direction); PositionBSEnd = Position + t*Direction; for(int i = 0; i < max_num_binary_steps; i++) @@ -1242,14 +1241,14 @@ bool intersectRayWithOcean(XMVECTOR& Result, XMVECTOR Position, XMVECTOR Directi old_test_point.y = 0; for(int k = 0; k < 4; k++) { - test_point.x = Position.x - displacements.x; - test_point.y = Position.z - displacements.y; + test_point.x = XMVectorGetX(Position) - displacements.x; + test_point.y = XMVectorGetZ(Position) - displacements.y; GFSDK_WaveWorks_Simulation_GetDisplacements( hSim, &test_point, &displacements, 1 ); if(refinement_threshold_sqr > (old_test_point.x - test_point.x)*(old_test_point.x - test_point.x) + (old_test_point.y - test_point.y)*(old_test_point.y - test_point.y)) break; old_test_point.x = test_point.x; old_test_point.y = test_point.y; } - if(Position.y - displacements.z - sea_level > 0) + if(XMVectorGetY(Position) - displacements.z - sea_level > 0) { PositionBSStart = Position; } @@ -1257,10 +1256,10 @@ bool intersectRayWithOcean(XMVECTOR& Result, XMVECTOR Position, XMVECTOR Directi { PositionBSEnd = Position; } - } - Result.x = Position.x; - Result.y = Position.y; - Result.z = Position.z; + } + + Result = Position; + return true; } return false; diff --git a/sample/d3d11/terrain.cpp b/sample/d3d11/terrain.cpp index d8ce061..d52059b 100644 --- a/sample/d3d11/terrain.cpp +++ b/sample/d3d11/terrain.cpp @@ -677,7 +677,7 @@ void CTerrain::CreateTerrain() temp_layerdef_map_texture_pixels[(j*terrain_layerdef_map_texture_size+i)*4+3]=0; } - mv=bilinear_interpolation(x-ix,z-iz,normal[ix][iz].y,normal[ix+1][iz].y,normal[ix+1][iz+1][1],normal[ix][iz+1].y); + mv=bilinear_interpolation(x-ix,z-iz,normal[ix][iz].y,normal[ix+1][iz].y,normal[ix+1][iz+1].y,normal[ix][iz+1].y); if((mv<terrain_slope_grass_start)&&(rm>terrain_height_sand_end)) { @@ -958,6 +958,8 @@ HRESULT CTerrain::LoadTextures() V_RETURN(DXUTFindDXSDKMediaFileCch(path, MAX_PATH, TEXT("foam.dds"))); V_RETURN(DirectX::CreateDDSTextureFromFile(pDevice, static_cast<const wchar_t *>(path), &pD3D11Resource, &foam_diffuse_textureSRV)); SAFE_RELEASE(pD3D11Resource); + + return S_OK; } @@ -1455,6 +1457,7 @@ void CTerrain::SetupRefractionView(CFirstPersonCamera *cam) pEffect->GetVariableByName("g_HalfSpaceCullSign")->AsScalar()->SetFloat(-1.0f); pEffect->GetVariableByName("g_HalfSpaceCullPosition")->AsScalar()->SetFloat(terrain_minheight); } + void CTerrain::SetupLightView(CFirstPersonCamera *cam) { |