本文整理汇总了C++中D3D11GraphicsEngine::GetGBuffer1方法的典型用法代码示例。如果您正苦于以下问题:C++ D3D11GraphicsEngine::GetGBuffer1方法的具体用法?C++ D3D11GraphicsEngine::GetGBuffer1怎么用?C++ D3D11GraphicsEngine::GetGBuffer1使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类D3D11GraphicsEngine
的用法示例。
在下文中一共展示了D3D11GraphicsEngine::GetGBuffer1方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
/** Draws this effect to the given buffer */
XRESULT D3D11PFX_GodRays::Render(RenderToTextureBuffer* fxbuffer)
{
D3D11GraphicsEngine* engine = (D3D11GraphicsEngine *)Engine::GraphicsEngine;
D3DXVECTOR3 sunPosition = *Engine::GAPI->GetSky()->GetAtmosphereCB().AC_LightPos.toD3DXVECTOR3();
sunPosition *= Engine::GAPI->GetSky()->GetAtmosphereCB().AC_OuterRadius;
sunPosition += Engine::GAPI->GetCameraPosition(); // Maybe use cameraposition from sky?
D3DXMATRIX& view = Engine::GAPI->GetRendererState()->TransformState.TransformView;
D3DXMATRIX& proj = Engine::GAPI->GetProjectionMatrix();
D3DXMATRIX viewProj = proj * view;
D3DXMatrixTranspose(&viewProj, &viewProj);
D3DXMatrixTranspose(&view, &view);
D3DXVECTOR3 sunViewPosition;
D3DXVec3TransformCoord(&sunViewPosition, &sunPosition, &view); // This is for checking if the light is behind the camera
D3DXVec3TransformCoord(&sunPosition, &sunPosition, &viewProj);
if(sunViewPosition.z < 0.0f)
return XR_SUCCESS; // Don't render the godrays when the sun is behind the camera
GodRayZoomConstantBuffer gcb;
gcb.GR_Weight = 1.0f;
gcb.GR_Decay = Engine::GAPI->GetRendererState()->RendererSettings.GodRayDecay;
gcb.GR_Weight = Engine::GAPI->GetRendererState()->RendererSettings.GodRayWeight;
gcb.GR_Density = Engine::GAPI->GetRendererState()->RendererSettings.GodRayDensity;
gcb.GR_Center.x = sunPosition.x/2.0f +0.5f;
gcb.GR_Center.y = sunPosition.y/-2.0f +0.5f;
gcb.GR_ColorMod = Engine::GAPI->GetRendererState()->RendererSettings.GodRayColorMod;
if(abs(gcb.GR_Center.x - 0.5f) > 0.5f)
gcb.GR_Weight *= std::max(0.0f, 1.0f - (abs(gcb.GR_Center.x - 0.5f) - 0.5f) / 0.5f);
if(abs(gcb.GR_Center.y - 0.5f) > 0.5f)
gcb.GR_Weight *= std::max(0.0f, 1.0f - (abs(gcb.GR_Center.y - 0.5f) - 0.5f) / 0.5f);
ID3D11RenderTargetView* oldRTV=NULL;
ID3D11DepthStencilView* oldDSV=NULL;
engine->GetContext()->OMGetRenderTargets(1, &oldRTV, &oldDSV);
D3D11VShader* vs = engine->GetShaderManager()->GetVShader("VS_PFX");
D3D11PShader* maskPS = engine->GetShaderManager()->GetPShader("PS_PFX_GodRayMask");
D3D11PShader* zoomPS = engine->GetShaderManager()->GetPShader("PS_PFX_GodRayZoom");
maskPS->Apply();
vs->Apply();
// Draw downscaled mask
engine->GetContext()->OMSetRenderTargets(1, FxRenderer->GetTempBufferDS4_1()->GetRenderTargetViewPtr(), NULL);
engine->GetHDRBackBuffer()->BindToPixelShader(engine->GetContext(), 0);
engine->GetGBuffer1()->BindToPixelShader(engine->GetContext(), 1);
D3D11_VIEWPORT vp;
vp.TopLeftX = 0.0f;
vp.TopLeftY = 0.0f;
vp.MinDepth = 0.0f;
vp.MaxDepth = 1.0f;
vp.Width = (float)FxRenderer->GetTempBufferDS4_1()->GetSizeX();
vp.Height = (float)FxRenderer->GetTempBufferDS4_1()->GetSizeY();
engine->GetContext()->RSSetViewports(1, &vp);
FxRenderer->DrawFullScreenQuad();
// Zoom
zoomPS->Apply();
zoomPS->GetConstantBuffer()[0]->UpdateBuffer(&gcb);
zoomPS->GetConstantBuffer()[0]->BindToPixelShader(0);
FxRenderer->CopyTextureToRTV(FxRenderer->GetTempBufferDS4_1()->GetShaderResView(), FxRenderer->GetTempBufferDS4_2()->GetRenderTargetView(), INT2(0,0), true);
// Upscale and blend
Engine::GAPI->GetRendererState()->BlendState.SetAdditiveBlending();
Engine::GAPI->GetRendererState()->BlendState.SetDirty();
FxRenderer->CopyTextureToRTV(FxRenderer->GetTempBufferDS4_2()->GetShaderResView(), oldRTV, INT2(engine->GetResolution().x, engine->GetResolution().y));
vp.Width = (float)engine->GetResolution().x;
vp.Height = (float)engine->GetResolution().y;
engine->GetContext()->RSSetViewports(1, &vp);
engine->GetContext()->OMSetRenderTargets(1, &oldRTV, oldDSV);
if(oldRTV)oldRTV->Release();
if(oldDSV)oldDSV->Release();
return XR_SUCCESS;
}