Skip to content

Commit

Permalink
Fix problems while resizing window
Browse files Browse the repository at this point in the history
  • Loading branch information
shuhuai committed Jul 29, 2015
1 parent ac576f0 commit 4f875a8
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion BasicPS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ output.albedo= float3(1.0f, 0.0f, 0.0f);
output.normal= float4(pIn.normal, 1.0f);


output.specgloss = float4(0.5,0.5,0.5,0.5);
output.specgloss = float4(0.5,0.5,0.5,0.6);

return output;
}
15 changes: 10 additions & 5 deletions CameraManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ void GCamera::InitProjMatrix(const float angle, const float client_width, const
mClientHeight = client_height;
mNearest = near_plane;
mFarthest = far_plane;
XMStoreFloat4x4(&mProj, XMMatrixPerspectiveFovLH(angle, client_width / client_height,
float ration = client_width / client_height;

XMStoreFloat4x4(&mProj, XMMatrixPerspectiveFovLH(angle,ration ,
near_plane, far_plane));


Expand Down Expand Up @@ -315,9 +317,12 @@ void GCamera::InitOrthoMatrix(const float clientWidth, const float clientHeight,

void GCamera::OnResize(uint32_t new_width, uint32_t new_height)
{
mClientWidth = new_width;
mClientHeight = new_height;
InitProjMatrix(mAngle, static_cast<float>(new_width), static_cast<float>(new_height), mNearest, mFarthest);
InitOrthoMatrix(static_cast<float>(new_width), static_cast<float>(new_height), 0.0f, mFarthest);
if (new_width != 0 && new_width != 0)
{
mClientWidth = new_width;
mClientHeight = new_height;
InitProjMatrix(mAngle, static_cast<float>(new_width), static_cast<float>(new_height), mNearest, mFarthest);
InitOrthoMatrix(static_cast<float>(new_width), static_cast<float>(new_height), 0.0f, mFarthest);
}
}

2 changes: 1 addition & 1 deletion DeferredRender.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class DeferredRender
ComPtr<ID3D12Resource> mLightCB;
ComPtr<ID3D12Resource> mDsTexture;

float mClearColor[4] = { 0.2f,0.5f,0.7f,1.0f };
float mClearColor[4] = { 0.0,0.0f,0.0f,1.0f };
float mClearDepth = 1.0f;
const static int numRTV = 3;
ComPtr<ID3D12Resource> mRtvTexture[numRTV];
Expand Down
17 changes: 10 additions & 7 deletions DirectxApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class directxProcess :public windowsApp
CameraData mCamData;
LightData mLightData;
GCamera mCamera;

bool mInit = false;
SphereRenderer mSphereRenderer;

std::shared_ptr<D3dDeviceManager> GetDeviceResources()
Expand Down Expand Up @@ -60,7 +60,7 @@ class directxProcess :public windowsApp
mCamData.InvPV = mCamera.InvScreenProjView();
mCamData.CamPos = mCamera.Position();

mLightData.pos = XMFLOAT3(0, 7, -10);
mLightData.pos = XMFLOAT3(0, 7, -15);

mDeferredTech.Init();
mDeferredTech.UpdateConstantBuffer(mCamData, mLightData);
Expand All @@ -74,7 +74,7 @@ class directxProcess :public windowsApp
g_d3dObjects->WaitForGPU();
}
PIXEndEvent(commandQueue);

mInit = true;
}
void Render()
{
Expand All @@ -88,7 +88,7 @@ class directxProcess :public windowsApp

AddResourceBarrier(mCommandList.Get(), g_d3dObjects->GetRenderTarget(), D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET);

float clearColor[4]={ 0.2f,0.5f,0.7f,0.0f };
float clearColor[4]={ 0.0f,0.0f,0.0f,0.0f };
mCommandList->ClearRenderTargetView(g_d3dObjects->GetRenderTargetView(), clearColor,0,nullptr);
D3D12_RECT rect = { 0, 0, mWidth, mHeight };

Expand Down Expand Up @@ -139,9 +139,12 @@ class directxProcess :public windowsApp
mWidth = width;
mHeight = height;
GetDeviceResources()->SetWindows(mHwnd,width,height);
mCamera.OnResize(mWidth, mHeight);
int x = 0;
x++;
if (mInit)
{
mCamera.OnResize(mWidth, mHeight);
mDeferredTech.InitWindowSizeDependentResources();
}

}

void KeyDown(UINT key)
Expand Down
2 changes: 1 addition & 1 deletion DirectxHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void D3dDeviceManager::CreateWindowSizeDependentResources()
);
}




// Create a render target view of the swap chain back buffer.
Expand Down
3 changes: 2 additions & 1 deletion LightPassPS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ float4 specGloss = gSpecularGlossTexture[pIn.position.xy].xyzw;
float3 col=GGXBRDF(normalize(gLightPos.xyz- vPositionWS.xyz), gLightPos, albedo ,normal,
normalize(gCamPos - vPositionWS), specGloss.xyz, specGloss.w);
float d = length(gLightPos.xyz - vPositionWS.xyz);
col = col*(1.0f / (1.0f + 0.01f*d + 0.001f*d));
col = col*(1.0f / (1.0f + 0.1f*d + 0.01f*d));

return float4(col,1.0f);


Expand Down
Binary file modified Shaders/BasicPS.cso
Binary file not shown.
Binary file modified Shaders/BasicVS.cso
Binary file not shown.
Binary file modified Shaders/LightPassPS.cso
Binary file not shown.
Binary file modified Shaders/ScreenQuadVS.cso
Binary file not shown.

0 comments on commit 4f875a8

Please sign in to comment.