From ea1d75a6f310c90c571c758683daf4187fe654a9 Mon Sep 17 00:00:00 2001 From: nvjingham Date: Wed, 7 Nov 2018 18:37:49 -0800 Subject: Updating Ansel SDK to v1.6 --- .../AnselSDKIntegration/AnselSDKIntegration.cpp | 40 +++++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'samples/AnselSDKIntegration/AnselSDKIntegration.cpp') diff --git a/samples/AnselSDKIntegration/AnselSDKIntegration.cpp b/samples/AnselSDKIntegration/AnselSDKIntegration.cpp index 46876e1..9ef967c 100644 --- a/samples/AnselSDKIntegration/AnselSDKIntegration.cpp +++ b/samples/AnselSDKIntegration/AnselSDKIntegration.cpp @@ -45,6 +45,7 @@ ID3D11VertexShader* g_pVertexShader = nullptr; ID3D11PixelShader* g_pPixelShader = nullptr; ID3D11VertexShader* g_pHudVertexShader = nullptr; ID3D11PixelShader* g_pHudPixelShader = nullptr; +ID3D11PixelShader* g_pHQPixelShader = nullptr; ID3D11InputLayout* g_pVertexLayout = nullptr; ID3D11DepthStencilState *g_pDepthStencilStateDepthDisable = nullptr; ID3D11Buffer* g_pVertexBuffer = nullptr; @@ -62,6 +63,7 @@ float g_Fov = XM_PIDIV4; uint32_t g_FrameWidth = 0u, g_FrameHeight = 0u; float g_ProjectionOffsetX = 0.0f, g_ProjectionOffsetY = 0.0f; float g_LightIntensity = 1.0f; +bool g_HighQuality = false; // Forward declarations HRESULT InitWindow(HINSTANCE hInstance, int nCmdShow); @@ -396,6 +398,20 @@ HRESULT InitDevice() if (FAILED(hr)) return hr; + hr = CompileShaderFromFile(L"Shaders.fx", "PS_HQ", "ps_4_0", &pPSBlob); + if (FAILED(hr)) + { + MessageBox(nullptr, + L"The FX file cannot be compiled. Please run this executable from the directory that contains the FX file.", L"Error", MB_OK); + return hr; + } + + // Create the pixel shader + hr = g_pd3dDevice->CreatePixelShader(pPSBlob->GetBufferPointer(), pPSBlob->GetBufferSize(), nullptr, &g_pHQPixelShader); + pPSBlob->Release(); + if (FAILED(hr)) + return hr; + // Create vertex buffer const SimpleVertex vertices[] = { @@ -564,6 +580,11 @@ HRESULT InitDevice() { // turn disabled effects back on here }; + config.changeQualityCallback = [](bool isHighQuality, void*) + { + // boost or drop quality here depending on requested level + g_HighQuality = isHighQuality; + }; config.isCameraFovSupported = true; config.isCameraOffcenteredProjectionSupported = true; config.isCameraRotationSupported = true; @@ -596,13 +617,14 @@ void CleanupDevice() if (g_pConstantBuffer) g_pConstantBuffer->Release(); if (g_pVertexBuffer) g_pVertexBuffer->Release(); if (g_pIndexBuffer) g_pIndexBuffer->Release(); - if (g_pHudVertexBuffer) g_pVertexBuffer->Release(); - if (g_pHudIndexBuffer) g_pIndexBuffer->Release(); + if (g_pHudVertexBuffer) g_pHudVertexBuffer->Release(); + if (g_pHudIndexBuffer) g_pHudIndexBuffer->Release(); if (g_pVertexLayout) g_pVertexLayout->Release(); if (g_pVertexShader) g_pVertexShader->Release(); if (g_pPixelShader) g_pPixelShader->Release(); - if (g_pHudVertexShader) g_pVertexShader->Release(); - if (g_pHudPixelShader) g_pPixelShader->Release(); + if (g_pHudVertexShader) g_pHudVertexShader->Release(); + if (g_pHudPixelShader) g_pHudPixelShader->Release(); + if (g_pHQPixelShader) g_pHQPixelShader->Release(); if (g_pDepthStencil) g_pDepthStencil->Release(); if (g_pDepthStencilView) g_pDepthStencilView->Release(); if (g_pRenderTargetView) g_pRenderTargetView->Release(); @@ -710,7 +732,15 @@ void Render() g_pImmediateContext->IASetIndexBuffer(g_pIndexBuffer, DXGI_FORMAT_R16_UINT, 0); g_pImmediateContext->VSSetShader(g_pVertexShader, nullptr, 0); g_pImmediateContext->VSSetConstantBuffers(0, 1, &g_pConstantBuffer); - g_pImmediateContext->PSSetShader(g_pPixelShader, nullptr, 0); + if (g_HighQuality) + { + // use HQ pixel shader if enabled + g_pImmediateContext->PSSetShader(g_pHQPixelShader, nullptr, 0); + } + else + { + g_pImmediateContext->PSSetShader(g_pPixelShader, nullptr, 0); + } g_pImmediateContext->PSSetConstantBuffers(0, 1, &g_pConstantBuffer); g_pImmediateContext->DrawIndexed(36, 0, 0); -- cgit v1.2.3