本文整理汇总了C++中CDXUTSDKMesh::Render方法的典型用法代码示例。如果您正苦于以下问题:C++ CDXUTSDKMesh::Render方法的具体用法?C++ CDXUTSDKMesh::Render怎么用?C++ CDXUTSDKMesh::Render使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDXUTSDKMesh
的用法示例。
在下文中一共展示了CDXUTSDKMesh::Render方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RenderGBuffer
void App::RenderGBuffer(ID3D11DeviceContext* d3dDeviceContext,
CDXUTSDKMesh& mesh_opaque,
CDXUTSDKMesh& mesh_alpha,
const CFirstPersonCamera* viewerCamera,
const D3D11_VIEWPORT* viewport,
const UIConstants* ui)
{
// Clear GBuffer
// NOTE: We actually only need to clear the depth buffer here since we replace unwritten (i.e. far plane) samples
// with the skybox. We use the depth buffer to reconstruct position and only in-frustum positions are shaded.
// NOTE: Complementary Z buffer: clear to 0 (far)!
d3dDeviceContext->ClearDepthStencilView(mDepthBuffer->GetDepthStencil(), D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
d3dDeviceContext->IASetInputLayout(mMeshVertexLayout);
d3dDeviceContext->VSSetConstantBuffers(0, 1, &mPerFrameConstants);
d3dDeviceContext->VSSetShader(mGeometryVS->GetShader(), 0, 0);
d3dDeviceContext->GSSetShader(0, 0, 0);
d3dDeviceContext->RSSetViewports(1, viewport);
d3dDeviceContext->PSSetConstantBuffers(0, 1, &mPerFrameConstants);
d3dDeviceContext->PSSetSamplers(0, 1, &mDiffuseSampler);
// Diffuse texture set per-material by DXUT mesh routines
// Set up render GBuffer render targets
d3dDeviceContext->OMSetDepthStencilState(mDepthState, 0);
d3dDeviceContext->OMSetRenderTargets(static_cast<UINT>(mGBufferRTV.size()), &mGBufferRTV.front(), mDepthBuffer->GetDepthStencil());
d3dDeviceContext->OMSetBlendState(mGeometryBlendState, 0, 0xFFFFFFFF);
// Render opaque geometry
if (mesh_opaque.IsLoaded()) {
d3dDeviceContext->RSSetState(mRasterizerState);
d3dDeviceContext->PSSetShader(mGBufferPS->GetShader(), 0, 0);
mesh_opaque.Render(d3dDeviceContext, 0);
}
// Render alpha tested geometry
if (mesh_alpha.IsLoaded()) {
d3dDeviceContext->RSSetState(mDoubleSidedRasterizerState);
d3dDeviceContext->PSSetShader(mGBufferAlphaTestPS->GetShader(), 0, 0);
mesh_alpha.Render(d3dDeviceContext, 0);
}
// Cleanup (aka make the runtime happy)
d3dDeviceContext->OMSetRenderTargets(0, 0, 0);
}
示例2: RenderSky
//--------------------------------------------------------------------------------------
// RenderSky
//--------------------------------------------------------------------------------------
void RenderSky( ID3D10Device* pd3dDevice )
{
D3DXMATRIX mWorld;
D3DXVECTOR3 vEye;
D3DXVECTOR3 vDir;
D3DXMATRIX mCamWorld;
D3DXMATRIX mView;
D3DXMATRIX mProj;
D3DXMatrixRotationY( &mWorld, -D3DX_PI / 2.5f );
GetCameraData( &mCamWorld, &mView, &mProj, &vEye, &vDir );
mView._41 = mView._42 = mView._43 = 0.0f;
D3DXMATRIX mWVP = mWorld * mCamWorld * mView * mProj;
g_pmWorldViewProj->SetMatrix( ( float* )&mWVP );
g_pmWorld->SetMatrix( ( float* )&mWorld );
pd3dDevice->IASetInputLayout( g_pBasicDecl10 );
g_SkyMesh.Render( pd3dDevice, g_pRenderSky, g_ptxDiffuse );
}
示例3: V
//--------------------------------------------------------------------------------------
// Render the scene using the D3D9 device
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D9FrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
HRESULT hr = S_OK;
// If the settings dialog is being shown, then render it instead of rendering the app's scene
if( g_SettingsDlg.IsActive() )
{
g_SettingsDlg.OnRender( fElapsedTime );
return;
}
D3DXMATRIX mWorld = *g_Camera.GetWorldMatrix();
D3DXMATRIX mView = *g_Camera.GetViewMatrix();
D3DXMATRIX mProj = *g_Camera.GetProjMatrix();
D3DXMATRIX mWorldViewProjection = mWorld * mView * mProj;
// Clear the render target and the zbuffer
V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB( 0, 160, 160, 250 ), 1.0f, 0 ) );
// Render the scene
if( SUCCEEDED( pd3dDevice->BeginScene() ) )
{
g_pEffect9->SetMatrix( g_hmWorld, &mWorld );
g_pEffect9->SetMatrix( g_hmWorldViewProjection, &mWorldViewProjection );
g_pEffect9->SetTexture( g_htxDiffuse, g_pTexture9 );
pd3dDevice->SetVertexDeclaration( g_pDecl9 );
g_Mesh.Render( pd3dDevice, g_pEffect9, g_hRenderScene );
DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" ); // These events are to help PIX identify what the code is doing
RenderText();
V( g_HUD.OnRender( fElapsedTime ) );
V( g_SampleUI.OnRender( fElapsedTime ) );
DXUT_EndPerfEvent();
V( pd3dDevice->EndScene() );
}
}
示例4: vLightGrndClr
//--------------------------------------------------------------------------------------
// Render the scene using the D3D11 device
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, double fTime,
float fElapsedTime, void* pUserContext )
{
HRESULT hr;
// If the settings dialog is being shown, then render it instead of rendering the app's scene
if( g_D3DSettingsDlg.IsActive() )
{
g_D3DSettingsDlg.OnRender( fElapsedTime );
return;
}
// Clear the render target and depth stencil
auto pRTV = DXUTGetD3D11RenderTargetView();
pd3dImmediateContext->ClearRenderTargetView( pRTV, Colors::MidnightBlue );
auto pDSV = DXUTGetD3D11DepthStencilView();
pd3dImmediateContext->ClearDepthStencilView( pDSV, D3D11_CLEAR_DEPTH, 1.0, 0 );
// Get the projection & view matrix from the camera class
XMMATRIX mWorld = g_Camera.GetWorldMatrix();
XMMATRIX mProj = g_Camera.GetProjMatrix();
XMMATRIX mView = g_Camera.GetViewMatrix();
// Get the light direction
XMVECTOR vLightDir = g_LightControl.GetLightDirection();
// Render the light arrow so the user can visually see the light dir
V( g_LightControl.OnRender( Colors::Yellow, mView, mProj, g_Camera.GetEyePt() ) );
// Ambient Light
static const XMVECTORF32 s_vLightColorA = { 0.1f, 0.1f, 0.1f, 1.0f };
g_pAmbientLightColor->SetFloatVector( s_vLightColorA );
g_pAmbientLightEnable->SetBool(true);
// Hemi Ambient Light
static const XMVECTORF32 s_vLightColorH1 = { 0.3f, 0.3f, 0.4f, 1.0f };
g_pHemiAmbientLightColor->SetFloatVector( s_vLightColorH1 );
g_pHemiAmbientLightEnable->SetBool(true);
XMFLOAT4 vLightGrndClr( 0.05f, 0.05f, 0.05f, 1.f );
g_pHemiAmbientLightGroundColor->SetFloatVector( reinterpret_cast<float*>( &vLightGrndClr ) );
XMFLOAT4 vVec(0.0f, 1.0f, 0.0f, 1.0f);
g_pHemiAmbientLightDirUp->SetFloatVector( reinterpret_cast<float*>( &vVec ) );
// Directional Light
g_pDirectionalLightColor->SetFloatVector( Colors::White );
g_pDirectionalLightEnable->SetBool(true);
XMFLOAT4 tmp;
XMStoreFloat4( &tmp, vLightDir );
tmp.w = 1.f;
g_pDirectionalLightDir->SetFloatVector( reinterpret_cast<float*>( &tmp ) );
// Environment Light - color comes from the texture
g_pEnvironmentLightColor->SetFloatVector( Colors::Black );
g_pEnvironmentLightEnable->SetBool(true);
// Setup the Eye based on the DXUT camera
XMVECTOR vEyePt = g_Camera.GetEyePt();
XMVECTOR vDir = g_Camera.GetLookAtPt() - vEyePt;
XMStoreFloat4( &tmp, vDir );
tmp.w = 1.f;
g_pEyeDir->SetFloatVector( reinterpret_cast<float*>( &tmp ) );
//Get the mesh
//IA setup
pd3dImmediateContext->IASetInputLayout( g_pVertexLayout11 );
UINT Strides[1];
UINT Offsets[1];
ID3D11Buffer* pVB[1];
pVB[0] = g_Mesh11.GetVB11( 0, 0 );
Strides[0] = ( UINT )g_Mesh11.GetVertexStride( 0, 0 );
Offsets[0] = 0;
pd3dImmediateContext->IASetVertexBuffers( 0, 1, pVB, Strides, Offsets );
pd3dImmediateContext->IASetIndexBuffer( g_Mesh11.GetIB11( 0 ), g_Mesh11.GetIBFormat11( 0 ), 0 );
// Set the per object constant data
XMMATRIX mWorldViewProjection = mWorld * mView * mProj;
// VS Per object
XMFLOAT4X4 tmp4x4;
XMStoreFloat4x4( &tmp4x4, mWorldViewProjection );
g_pWorldViewProjection->SetMatrix( reinterpret_cast<float*>( &tmp4x4 ) );
XMStoreFloat4x4( &tmp4x4, mWorld );
g_pWorld->SetMatrix( reinterpret_cast<float*>( &tmp4x4 ) );
// Setup the Shader Linkage based on the user settings for Lighting
ID3DX11EffectClassInstanceVariable* pLightClassVar;
// Ambient Lighting First - Constant or Hemi?
if ( g_bHemiAmbientLighting )
{
pLightClassVar = g_pHemiAmbientLightClass;
}
else
{
//.........这里部分代码省略.........
示例5: if
//--------------------------------------------------------------------------------------
// render callback
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D11FrameRender( ID3D11Device* pd3dDevice,
ID3D11DeviceContext* pd3dImmediateContext,
double fTime,
float fElapsedTime, void* pUserContext )
{
static int s_iCounter = 0;
// If the settings dialog is being shown, then render it instead of rendering the app's scene
if( g_D3DSettingsDlg.IsActive() )
{
g_D3DSettingsDlg.OnRender( fElapsedTime );
return;
}
if( g_pScenePS == NULL && s_iCounter == 0 )
{
s_iCounter = 4;
}
if( s_iCounter > 0 )
s_iCounter --;
if( s_iCounter == 1 && g_pScenePS == NULL )
{
HRESULT hr = S_OK;
// Create the shaders
ID3DBlob* pBlob = NULL;
// VS
hr = CompileShaderFromFile( L"ContactHardeningShadows11.hlsl", "VS_RenderScene", "vs_5_0", &pBlob );
hr = pd3dDevice->CreateVertexShader( pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, &g_pSceneVS );
DXUT_SetDebugName( g_pSceneVS, "VS_RenderScene" );
// Define our scene vertex data layout
const D3D11_INPUT_ELEMENT_DESC SceneLayout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "TEXTURE", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};
hr = pd3dDevice->CreateInputLayout( SceneLayout, ARRAYSIZE( SceneLayout ), pBlob->GetBufferPointer(),
pBlob->GetBufferSize(), &g_pSceneVertexLayout );
SAFE_RELEASE( pBlob );
DXUT_SetDebugName( g_pSceneVertexLayout, "SceneLayout" );
hr = CompileShaderFromFile( L"ContactHardeningShadows11.hlsl", "VS_RenderSceneSM", "vs_5_0", &pBlob );
hr = pd3dDevice->CreateVertexShader( pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, &g_pSM_VS );
SAFE_RELEASE( pBlob );
DXUT_SetDebugName( g_pSM_VS, "VS_RenderSceneSM" );
// PS
hr = CompileShaderFromFile( L"ContactHardeningShadows11.hlsl", "PS_RenderScene", "ps_5_0", &pBlob );
hr = pd3dDevice->CreatePixelShader( pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, &g_pScenePS );
SAFE_RELEASE( pBlob );
DXUT_SetDebugName( g_pScenePS, "PS_RenderScene" );
s_iCounter = 0;
}
else if( g_pScenePS != NULL )
{
ID3D11RenderTargetView* pRTV[2] = { NULL,NULL };
ID3D11ShaderResourceView* pSRV[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
// Array of our samplers
ID3D11SamplerState* ppSamplerStates[3] = { g_pSamplePoint, g_pSampleLinear, g_pSamplePointCmp };
pd3dImmediateContext->PSSetSamplers( 0, 3, ppSamplerStates );
// Store off original render target, this is the back buffer of the swap chain
ID3D11RenderTargetView* pOrigRTV = DXUTGetD3D11RenderTargetView();
ID3D11DepthStencilView* pOrigDSV = DXUTGetD3D11DepthStencilView();
// Clear the render target
float ClearColor[4] = { 0.0f, 0.25f, 0.25f, 0.55f };
pd3dImmediateContext->ClearRenderTargetView( DXUTGetD3D11RenderTargetView(),
ClearColor );
pd3dImmediateContext->ClearDepthStencilView( DXUTGetD3D11DepthStencilView(),
D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL,
1.0, 0 );
// Get the projection & view matrix from the camera class
D3DXMATRIXA16 mWorld;
D3DXMATRIXA16 mView;
D3DXMATRIXA16 mProj;
D3DXMATRIXA16 mViewProjLight;
D3DXMATRIXA16 mWorldViewProjection;
D3DXVECTOR3 vLightDir;
// disable color writes
pd3dImmediateContext->OMSetBlendState(g_pBlendStateColorWritesOff, 0, 0xffffffff);
RenderShadowMap( pd3dDevice, pd3dImmediateContext, mViewProjLight, vLightDir );
// enable color writes
pd3dImmediateContext->OMSetBlendState(g_pBlendStateNoBlend, 0, 0xffffffff);
mView = *g_Camera.GetViewMatrix();
//.........这里部分代码省略.........
示例6: RenderShadowMap
//--------------------------------------------------------------------------------------
// Renders the depth only shadow map
//--------------------------------------------------------------------------------------
void RenderShadowMap( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext,
D3DXMATRIXA16& mViewProjLight, D3DXVECTOR3& vLightDir )
{
D3D11_RECT oldrects[1];
D3D11_VIEWPORT oldvp[2];
UINT num = 1;
pd3dImmediateContext->RSGetScissorRects( &num, oldrects );
num = 1;
pd3dImmediateContext->RSGetViewports( &num, oldvp );
oldvp[ 1 ] = oldvp[ 0 ];
D3D11_RECT rects[1] = { { 0, UINT(g_fShadowMapWidth), 0, UINT(g_fShadowMapHeight) } };
pd3dImmediateContext->RSSetScissorRects( 1, rects );
D3D11_VIEWPORT vp[1] = { { 0, 0, g_fShadowMapWidth, g_fShadowMapHeight, 0.0f, 1.0f } };
pd3dImmediateContext->RSSetViewports( 1, vp );
// Set our scene render target & keep original depth buffer
ID3D11RenderTargetView* pRTVs[2] = {0,0};
pd3dImmediateContext->OMSetRenderTargets( 2, pRTVs, g_pDepthStencilTextureDSV );
// Clear the render target
pd3dImmediateContext->ClearDepthStencilView( g_pDepthStencilTextureDSV,
D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL,
1.0, 0 );
// Get the projection & view matrix from the camera class
D3DXMATRIXA16 mWorld;
D3DXMATRIXA16 mView;
D3DXMATRIXA16 mProj;
D3DXVECTOR3 up(0,1,0);
D3DXVECTOR4 vLight( 0.0f,0.0f,0.0f, 1.0f );
D3DXVECTOR4 vLightLookAt4d( 0.0f,-0.5f,1.0f, 0.0f );
vLightLookAt4d = vLight + vLightLookAt4d;
D3DXVec4Transform( &vLight, &vLight, g_LCamera.GetWorldMatrix() );
D3DXVec4Transform( &vLightLookAt4d, &vLightLookAt4d, g_LCamera.GetWorldMatrix() );
D3DXMatrixOrthoOffCenterLH( &mProj, -8.5, 9, -15, 11, -20, 20 );
D3DXVECTOR3 vLight3d( vLight.x, vLight.y, vLight.z );
D3DXVECTOR3 vLightLookAt3d( vLightLookAt4d.x, vLightLookAt4d.y, vLightLookAt4d.z );
vLightDir = vLightLookAt3d - vLight3d;
D3DXMatrixLookAtLH( &mView, &vLight3d, &vLightLookAt3d, &up);
mViewProjLight = mView * mProj;
// Setup the constant buffer for the scene vertex shader
D3D11_MAPPED_SUBRESOURCE MappedResource;
pd3dImmediateContext->Map( g_pcbConstants, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource );
CB_CONSTANTS* pConstants = ( CB_CONSTANTS* )MappedResource.pData;
D3DXMatrixTranspose( &pConstants->f4x4WorldViewProjection, &mViewProjLight );
D3DXMatrixTranspose( &pConstants->f4x4WorldViewProjLight, &mViewProjLight );
pConstants->vShadowMapDimensions = D3DXVECTOR4(g_fShadowMapWidth,
g_fShadowMapHeight,
1.0f/g_fShadowMapWidth,
1.0f/g_fShadowMapHeight);
pd3dImmediateContext->Unmap( g_pcbConstants, 0 );
pd3dImmediateContext->VSSetConstantBuffers( g_iCONSTANTSCBBind, 1, &g_pcbConstants );
pd3dImmediateContext->PSSetConstantBuffers( g_iCONSTANTSCBBind, 1, &g_pcbConstants );
// Set the shaders
pd3dImmediateContext->VSSetShader( g_pSM_VS, NULL, 0 );
pd3dImmediateContext->PSSetShader( NULL, NULL, 0 );
// Set the vertex buffer format
pd3dImmediateContext->IASetInputLayout( g_pSceneVertexLayout );
// Render the scene
g_Poles.Render( pd3dImmediateContext, 0 );
// reset the old viewport etc.
pd3dImmediateContext->RSSetScissorRects( 1, oldrects );
pd3dImmediateContext->RSSetViewports( 1, oldvp );
}