本文整理汇总了C++中CGutModel_DX10类的典型用法代码示例。如果您正苦于以下问题:C++ CGutModel_DX10类的具体用法?C++ CGutModel_DX10怎么用?C++ CGutModel_DX10使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CGutModel_DX10类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RenderFrameDX10
void RenderFrameDX10(void)
{
Vector4 vClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// frame buffer
ID3D10RenderTargetView *pRenderTargetView = GutGetDX10RenderTargetView();
// depth/stencil buffer
ID3D10DepthStencilView *pDepthStencilView = GutGetDX10DepthStencilView();
// front/back buffer
IDXGISwapChain *pSwapChain = GutGetDX10SwapChain();
// 清除顏色
g_pDevice->ClearRenderTargetView(pRenderTargetView, (float *)&vClearColor);
// 清除Depth/Stencil buffer
g_pDevice->ClearDepthStencilView(pDepthStencilView, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0);
// 取得轉換矩陣
Matrix4x4 view_matrix = g_Control.GetViewMatrix();
Matrix4x4 world_matrix = g_Control.GetObjectMatrix();
Matrix4x4 ident_matrix = Matrix4x4::IdentityMatrix();
CGutModel_DX10::SetProjectionMatrix(g_proj_matrix);
CGutModel_DX10::SetViewMatrix(view_matrix);
// 畫出茶具組
{
g_pDevice->OMSetDepthStencilState(NULL, 1);
CGutModel_DX10::SetWorldMatrix(world_matrix);
CGutModel_DX10::UpdateMatrix();
g_Model_DX10.Render();
}
// stencil pass, 在stencil buffer里標出光源照射到的像素
{
g_pDevice->OMSetDepthStencilState(g_pZStencil_Mask, 1);
CGutModel_DX10::SetWorldMatrix(ident_matrix);
CGutModel_DX10::UpdateMatrix();
CGutModel_DX10::SetMaterialOverwrite(&g_material_stencilpass);
g_SpotLightModel_DX10.Render();
}
// 畫出被光線照射到的區域
{
g_pDevice->OMSetDepthStencilState(g_pZStencil_Test, 1);
CGutModel_DX10::SetMaterialOverwrite(&g_material_spotlightpass);
g_SpotLightModel_DX10.Render();
}
// 畫出光柱圓錐
{
g_pDevice->OMSetDepthStencilState(NULL, 1);
CGutModel_DX10::SetMaterialOverwrite(NULL);
g_SpotLightModel_DX10.Render();
}
// 等待硬體掃結束, 然後才更新畫面.
pSwapChain->Present(1, 0);
}
示例2: RenderModelDX10
void RenderModelDX10(bool mirror, Vector4 *pPlane)
{
ID3D10Device *pDevice = GutGetGraphicsDeviceDX10();
Matrix4x4 view_matrix;
Matrix4x4 proj_matrix;
Matrix4x4 world_matrix = g_Control.GetObjectMatrix();
if ( mirror )
{
Vector4 vEye = g_Control.GetCameraPosition();
Vector4 vUp = g_Control.m_vUp;
Vector4 vLookAt = g_Control.m_vLookAt;
Vector4 mirror_eye = MirrorPoint(vEye, *pPlane);
Vector4 mirror_lookat = MirrorPoint(vLookAt, *pPlane);
Vector4 mirror_up = MirrorPoint(vUp, *pPlane);
view_matrix = GutMatrixLookAtRH(mirror_eye, mirror_lookat, mirror_up);
g_mirror_view_matrix = view_matrix;
}
else
{
view_matrix = g_Control.GetViewMatrix();
}
// `CGutModel_DX10中有提供一些模擬Fixed Piepline的函式`
CGutModel_DX10::SetProjectionMatrix(g_proj_matrix);
CGutModel_DX10::SetViewMatrix(view_matrix);
CGutModel_DX10::SetWorldMatrix(world_matrix);
CGutModel_DX10::UpdateMatrix();
g_Model_DX10.Render();
}
示例3: RenderFrameDX10
void RenderFrameDX10(void)
{
Matrix4x4 view_matrix = g_Control.GetViewMatrix();
Matrix4x4 world_matrix = g_Control.GetObjectMatrix();
Vector4 vClearColor(0.0f, 0.0f, 0.0f, 0.0f);
UINT stride = sizeof(Vertex_VT);
UINT offset = 0;
ID3D10RenderTargetView *pRenderTargetView = GutGetDX10RenderTargetView();
ID3D10DepthStencilView *pDepthStencilView = GutGetDX10DepthStencilView();
g_pDevice->OMSetRenderTargets(1, &g_pRTView[FULLSIZE], pDepthStencilView);
g_pDevice->ClearRenderTargetView(g_pRTView[FULLSIZE], &vClearColor[0]);
g_pDevice->ClearDepthStencilView(pDepthStencilView, D3D10_CLEAR_DEPTH|D3D10_CLEAR_STENCIL, 1.0f, 0);
SetViewport(FULLSIZE);
CGutModel_DX10::SetViewMatrix(view_matrix);
CGutModel_DX10::SetWorldMatrix(world_matrix);
CGutModel_DX10::SetProjectionMatrix(g_proj_matrix);
CGutModel_DX10::UpdateMatrix();
g_Model_DX10.Render();
ConvertToLuminance();
Average();
AdaptiveLuminance();
AutoExposure();
if ( g_iMode & 0x01 )
{
g_pDevice->OMSetRenderTargets(1, &pRenderTargetView, pDepthStencilView);
SetViewport(FULLSIZE);
float x = -1.0f;
float y = -1.0f;
float w = 0.2f;
float h = 0.2f;
DrawImage(g_pSRView[LUMINANCE_CURRENT], x, y, w, h);
x+=w;
DrawImage(g_pSRView[LUMINANCE_PREVIOUS], x, y, w, h);
x+=w;
}
// 等待硬體掃結束, 然後才更新畫面
IDXGISwapChain *pSwapChain = GutGetDX10SwapChain();
pSwapChain->Present(1, 0);
}
示例4: InitResourceDX10
bool InitResourceDX10(void)
{
g_pDevice = GutGetGraphicsDeviceDX10();
ID3D10Blob *pVSCode = NULL;
for ( int i=0; i<NUM_FRAMEBUFFERS; i++ )
{
g_pTextures[i] = NULL;
g_pSRView[i] = NULL;
g_pRTView[i] = NULL;
}
// 載入Shader
{
g_pPostFX = GutLoadFXShaderDX10("../../shaders/Posteffect_dx10.fx");
if ( NULL==g_pPostFX )
return false;
g_pExposureFX = GutLoadFXShaderDX10("../../shaders/Exposure_dx10.fx");
if ( NULL==g_pExposureFX )
return false;
}
// 設定Vertex資料格式
{
ID3D10EffectTechnique *pShader = g_pExposureFX->GetTechniqueByName("AutoExposure");
D3D10_INPUT_ELEMENT_DESC layout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 }
};
D3D10_PASS_DESC PassDesc;
pShader->GetPassByIndex(0)->GetDesc(&PassDesc);
if ( D3D_OK != g_pDevice->CreateInputLayout( layout, 2, PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, &g_pVertexLayout ) )
return false;
SAFE_RELEASE(pVSCode);
}
if ( !ReInitResourceDX10() )
return false;
CGutModel_DX10::LoadDefaultShader("../../shaders/gmodel_dx10.hlsl");
g_Model_DX10.ConvertToDX10Model(&g_Model);
g_pVertexBuffer = GutCreateVertexBuffer_DX10(sizeof(Vertex_VT)*4, g_FullScreenQuad);
return true;
}
示例5: InitResourceDX10
bool InitResourceDX10(void)
{
g_pDevice = GutGetGraphicsDeviceDX10();
// 載入Shader
{
g_pRefractionFX = GutLoadFXShaderDX10("../../shaders/Refraction_dx10.fx");
if ( NULL==g_pRefractionFX )
return false;
ID3D10EffectTechnique *pShader = g_pRefractionFX->GetTechniqueByName("Refraction");
const sVertexDecl *pVertexDecl = g_Model.GetVertexFormat();
D3D10_PASS_DESC PassDesc;
pShader->GetPassByIndex(0)->GetDesc(&PassDesc);
g_pRefractionLayout = GutCreateInputLayoutDX10(pVertexDecl, PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize);
}
g_pPostFX = GutLoadFXShaderDX10("../../shaders/Posteffect_dx10.fx");
if ( NULL==g_pPostFX )
return false;
{
g_pVertexBuffer = GutCreateVertexBuffer_DX10(sizeof(Vertex_VT)*4, g_FullScreenQuad);
D3D10_INPUT_ELEMENT_DESC layout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 }
};
ID3D10EffectTechnique *pShader = g_pPostFX->GetTechniqueByName("DrawIcon");
D3D10_PASS_DESC PassDesc;
pShader->GetPassByIndex(0)->GetDesc(&PassDesc);
if ( D3D_OK != g_pDevice->CreateInputLayout( layout, 2, PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, &g_pVertexLayout ) )
return false;
}
if ( !ReInitResourceDX10() )
return false;
CGutModel_DX10::LoadDefaultShader("../../shaders/gmodel_dx10.hlsl");
g_Model_DX10.ConvertToDX10Model(&g_Model);
g_pTexture = GutLoadTexture_DX10("../../textures/lena.dds");
return true;
}
示例6: InitResourceDX10
bool InitResourceDX10(void)
{
g_pDevice = GutGetGraphicsDeviceDX10();
ID3D10Blob *pVSCode = NULL;
// 計算投影矩陣
g_proj_matrix = GutMatrixPerspectiveRH_DirectX(g_fFovW, 1.0f, g_fNear, g_fFar);
if ( !CGutModel_DX10::LoadDefaultShader("../../shaders/gmodel_dx10.hlsl") )
return false;
g_Model_DX10.ConvertToDX10Model(&g_Model);
return true;
}
示例7: InitResourceDX10
bool InitResourceDX10(void)
{
g_pDevice = GutGetGraphicsDeviceDX10();
ID3D10Blob *pVSCode = NULL;
{
// 載入Vertex Shader
g_pVertexShader = GutLoadVertexShaderDX10_HLSL("../../shaders/color_dx10.hlsl", "VS", "vs_4_0", &pVSCode);
if ( NULL==g_pVertexShader )
return false;
// 載入Pixel Shader
g_pPixelShader = GutLoadPixelShaderDX10_HLSL("../../shaders/color_dx10.hlsl", "PS", "ps_4_0");
if ( NULL==g_pPixelShader )
return false;
}
CGutModel_DX10::LoadDefaultShader("../../shaders/gmodel_dx10.hlsl");
CGutModel::SetTexturePath("../../textures/");
g_Model_DX10.ConvertToDX10Model(&g_Model);
// 設定Vertex資料格式
{
D3D10_INPUT_ELEMENT_DESC layout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
};
if ( D3D_OK != g_pDevice->CreateInputLayout( layout, sizeof(layout)/sizeof(D3D10_INPUT_ELEMENT_DESC), pVSCode->GetBufferPointer(), pVSCode->GetBufferSize(), &g_pVertexLayout ) )
return false;
SAFE_RELEASE(pVSCode);
}
// 配置Shader讀取參數的記憶體空間
{
D3D10_BUFFER_DESC cbDesc;
ZeroMemory(&cbDesc, sizeof(cbDesc));
cbDesc.ByteWidth = sizeof(ShaderConstant);
cbDesc.Usage = D3D10_USAGE_DYNAMIC;
cbDesc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
cbDesc.MiscFlags = 0;
if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, NULL, &g_pConstantBuffer ) )
return false;
}
// 配置Vertex Buffer
{
D3D10_BUFFER_DESC cbDesc;
ZeroMemory(&cbDesc, sizeof(cbDesc));
cbDesc.ByteWidth = sizeof(Vertex_V) * 4;
cbDesc.Usage = D3D10_USAGE_DYNAMIC ;
cbDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
cbDesc.MiscFlags = 0;
D3D10_SUBRESOURCE_DATA subDesc;
ZeroMemory(&subDesc, sizeof(subDesc));
subDesc.pSysMem = g_Quad;
if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, &subDesc, &g_pVertexBuffer ) )
return false;
}
// rasterizer state物件
{
D3D10_RASTERIZER_DESC desc;
GutSetDX10DefaultRasterizerDesc(desc);
desc.CullMode = D3D10_CULL_NONE;
desc.FrontCounterClockwise = true;
if ( D3D_OK != g_pDevice->CreateRasterizerState(&desc, &g_pRasterizerNoCull) )
return false;
desc.CullMode = D3D10_CULL_BACK;
desc.FrontCounterClockwise = true;
if ( D3D_OK != g_pDevice->CreateRasterizerState(&desc, &g_pRasterizerCull) )
return false;
CGutModel_DX10::SetRasterizeState(g_pRasterizerCull, g_pRasterizerNoCull);
g_pDevice->RSSetState(g_pRasterizerNoCull);
}
// depth stencil object
{
D3D10_DEPTH_STENCIL_DESC desc;
GutSetDX10DefaultDepthStencilDesc(desc);
desc.StencilEnable = TRUE;
desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_INCR;
desc.BackFace = desc.FrontFace;
//.........这里部分代码省略.........
示例8: RenderFrameDX10
void RenderFrameDX10(void)
{
Vector4 vClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// frame buffer
ID3D10RenderTargetView *pRenderTargetView = GutGetDX10RenderTargetView();
// depth/stencil buffer
ID3D10DepthStencilView *pDepthStencilView = GutGetDX10DepthStencilView();
// front/back buffer
IDXGISwapChain *pSwapChain = GutGetDX10SwapChain();
Matrix4x4 ident_matrix; ident_matrix.Identity();
Matrix4x4 view_matrix = g_Control.GetViewMatrix();
Matrix4x4 world_matrix = g_Control.GetObjectMatrix();
Matrix4x4 world_view_proj_matrix = world_matrix * view_matrix * g_proj_matrix;
// 清除顏色
g_pDevice->ClearRenderTargetView(pRenderTargetView, (float *)&vClearColor);
// 清除Depth/Stencil buffer
g_pDevice->ClearDepthStencilView(pDepthStencilView, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0);
// 畫出茶壼, 并更新 Stencil Buffer.
{
g_pDevice->OMSetDepthStencilState(g_pZStencil_Incr, 0);
CGutModel_DX10::SetProjectionMatrix(g_proj_matrix);
CGutModel_DX10::SetViewMatrix(view_matrix);
CGutModel_DX10::SetWorldMatrix(world_matrix);
CGutModel_DX10::UpdateMatrix();
g_Model_DX10.Render();
}
// 套用 Shader
{
UINT stride = sizeof(Vertex_V);
UINT offset = 0;
// 設定Shader
g_pDevice->VSSetShader(g_pVertexShader);
g_pDevice->PSSetShader(g_pPixelShader);
// 設定Shader讀取參數的記憶體位罝
g_pDevice->VSSetConstantBuffers(0, 1, &g_pConstantBuffer);
g_pDevice->PSSetConstantBuffers(0, 1, &g_pConstantBuffer);
// 設定vertex資料格式
g_pDevice->IASetInputLayout(g_pVertexLayout);
// 設定Vertex Buffer
g_pDevice->IASetVertexBuffers(0, 1, &g_pVertexBuffer, &stride, &offset);
// 設定三角形頂點索引值資料排列是triangle strip
g_pDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
}
ShaderConstant *pConstData = NULL;
// 用綠色標示出只更新1次的像素
{
// 設定shader參數
g_pConstantBuffer->Map( D3D10_MAP_WRITE_DISCARD, NULL, (void **) &pConstData );
pConstData->m_wvp_matrix = ident_matrix;
pConstData->m_color.Set(0,1,0,1);
g_pConstantBuffer->Unmap();
// 畫出看板
g_pDevice->OMSetDepthStencilState(g_pZStencil_Test, 1);
g_pDevice->Draw(4, 0);
}
// 用藍色標示出更新2次的像素
{
// 設定shader參數
g_pConstantBuffer->Map( D3D10_MAP_WRITE_DISCARD, NULL, (void **) &pConstData );
pConstData->m_wvp_matrix = ident_matrix;
pConstData->m_color.Set(0,0,1,1);
g_pConstantBuffer->Unmap();
// 畫出看板
g_pDevice->OMSetDepthStencilState(g_pZStencil_Test, 2);
g_pDevice->Draw(4, 0);
}
// 用紅色標示出更新3次的像素
{
// 設定shader參數
g_pConstantBuffer->Map( D3D10_MAP_WRITE_DISCARD, NULL, (void **) &pConstData );
pConstData->m_wvp_matrix = ident_matrix;
pConstData->m_color.Set(1,0,0,1);
g_pConstantBuffer->Unmap();
// 畫出看板
g_pDevice->OMSetDepthStencilState(g_pZStencil_Test, 3);
g_pDevice->Draw(4, 0);
}
// 用白色標示出更新超過3次的像素
{
// 設定shader參數
g_pConstantBuffer->Map( D3D10_MAP_WRITE_DISCARD, NULL, (void **) &pConstData );
pConstData->m_wvp_matrix = ident_matrix;
pConstData->m_color.Set(1,1,1,1);
g_pConstantBuffer->Unmap();
// 畫出看板
g_pDevice->OMSetDepthStencilState(g_pZStencil_Less, 3);
g_pDevice->Draw(4, 0);
}
// 等待硬體掃結束, 然後才更新畫面.
pSwapChain->Present(1, 0);
//.........这里部分代码省略.........
示例9: InitResourceDX10
bool InitResourceDX10(void)
{
g_pDevice = GutGetGraphicsDeviceDX10();
ID3D10Blob *pVSCode = NULL;
// 載入Vertex Shader
g_pVertexShader = GutLoadVertexShaderDX10_HLSL("../../shaders/texture_dx10.hlsl", "VS", "vs_4_0", &pVSCode);
if ( NULL==g_pVertexShader )
return false;
// 載入Pixel Shader
g_pPixelShader = GutLoadPixelShaderDX10_HLSL("../../shaders/texture_dx10.hlsl", "PS", "ps_4_0");
if ( NULL==g_pPixelShader )
return false;
CGutModel_DX10::LoadDefaultShader("../../shaders/gmodel_dx10.hlsl");
CGutModel::SetTexturePath("../../textures/");
g_Model_DX10.ConvertToDX10Model(&g_Model);
// 設定Vertex資料格式
D3D10_INPUT_ELEMENT_DESC layout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0 }
};
if ( D3D_OK != g_pDevice->CreateInputLayout( layout, sizeof(layout)/sizeof(D3D10_INPUT_ELEMENT_DESC),
pVSCode->GetBufferPointer(), pVSCode->GetBufferSize(), &g_pVertexLayout ) )
return false;
SAFE_RELEASE(pVSCode);
D3D10_BUFFER_DESC cbDesc;
ZeroMemory(&cbDesc, sizeof(cbDesc));
// 配置Vertex Buffer
{
cbDesc.ByteWidth = sizeof(Vertex_VT) * 4;
cbDesc.Usage = D3D10_USAGE_DYNAMIC ;
cbDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
cbDesc.MiscFlags = 0;
D3D10_SUBRESOURCE_DATA subDesc;
ZeroMemory(&subDesc, sizeof(subDesc));
subDesc.pSysMem = g_Quad;
if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, &subDesc, &g_pVertexBuffer ) )
return false;
}
// 配置Vertex Shader 常數記憶體
{
cbDesc.ByteWidth = sizeof(Matrix4x4);
cbDesc.Usage = D3D10_USAGE_DYNAMIC;
cbDesc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
cbDesc.MiscFlags = 0;
if ( D3D_OK != g_pDevice->CreateBuffer( &cbDesc, NULL, &g_pVSConstBuffer ) )
return false;
}
// 配置RGBA動態貼圖
{
D3D10_TEXTURE2D_DESC dstex;
dstex.Width = 512;
dstex.Height = 512;
dstex.MipLevels = 1;
dstex.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
dstex.SampleDesc.Count = 1;
dstex.SampleDesc.Quality = 0;
dstex.Usage = D3D10_USAGE_DEFAULT;
dstex.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
dstex.CPUAccessFlags = 0;
dstex.MiscFlags = 0;
dstex.ArraySize = 1;
g_pDevice->CreateTexture2D( &dstex, NULL, &g_pTexture );
D3D10_SHADER_RESOURCE_VIEW_DESC SRVDesc;
ZeroMemory( &SRVDesc, sizeof(SRVDesc) );
SRVDesc.Format = dstex.Format;
SRVDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
SRVDesc.Texture2D.MipLevels = 1;
// for shader
g_pDevice->CreateShaderResourceView(g_pTexture, &SRVDesc, &g_pTextureView);
D3D10_RENDER_TARGET_VIEW_DESC DescRT;
DescRT.Format = dstex.Format;
DescRT.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
DescRT.Texture2D.MipSlice = 0;
// for rendertarget
g_pDevice->CreateRenderTargetView(g_pTexture, &DescRT, &g_pRGBAView);
}
// 配置DepthStencil動態貼圖
{
D3D10_TEXTURE2D_DESC desc;
ZeroMemory( &desc, sizeof(desc) );
//.........这里部分代码省略.........
示例10: InitResourceDX10
bool InitResourceDX10(void)
{
g_pDevice = GutGetGraphicsDeviceDX10();
CGutModel_DX10::LoadDefaultShader("../../shaders/gmodel_dx10.hlsl");
CGutModel::SetTexturePath("../../textures/");
g_Model_DX10.ConvertToDX10Model(&g_Model);
g_SpotLightModel_DX10.ConvertToDX10Model(&g_SpotLightModel);
// depth stencil object
{
D3D10_DEPTH_STENCIL_DESC desc;
GutSetDX10DefaultDepthStencilDesc(desc);
desc.StencilEnable = TRUE;
desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ZERO;
desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_INCR;
desc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
desc.BackFace.StencilPassOp = D3D10_STENCIL_OP_DECR;
g_pDevice->CreateDepthStencilState(&desc, &g_pZStencil_Mask);
desc.FrontFace.StencilFunc = D3D10_COMPARISON_EQUAL;
desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
desc.BackFace = desc.FrontFace;
g_pDevice->CreateDepthStencilState(&desc, &g_pZStencil_Test);
}
// disable rgba output
{
D3D10_BLEND_DESC desc;
GutSetDX10DefaultBlendDesc(desc);
desc.RenderTargetWriteMask[0] = 0;
g_pDevice->CreateBlendState(&desc, &g_pBlendState_ColorWriteOff);
}
// material overwrite
{
g_material_stencilpass.m_bCullFace = false;
g_material_stencilpass.m_pBlendState = g_pBlendState_ColorWriteOff;
g_material_stencilpass.m_vDiffuse.Set(0.1f);
g_material_spotlightpass.m_bCullFace = true;
g_material_spotlightpass.m_pBlendState = CGutModel_DX10::s_pBlend_Add;
g_material_spotlightpass.m_vDiffuse.Set(0.3f);
}
// sampler state / texture filter
{
D3D10_SAMPLER_DESC sampler_desc;
ZeroMemory(&sampler_desc, sizeof(sampler_desc));
sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_LINEAR;
sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_WRAP;
sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_WRAP;
sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_WRAP;
g_pDevice->CreateSamplerState(&sampler_desc, &g_pSamplerState);
for ( int i=0; i<4; i++ )
{
g_pDevice->PSSetSamplers(i, 1, &g_pSamplerState);
}
}
// 投影矩陣
g_proj_matrix = GutMatrixPerspectiveRH_DirectX(g_fFOV, 1.0f, 0.1f, 100.0f);
return true;
}
示例11: RenderFrameDX10
void RenderFrameDX10(void)
{
Vector4 vClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// 取得呼叫GutCreateGraphicsDeviceDX10時所產生的D3D10物件
ID3D10RenderTargetView *pRenderTargetView = GutGetDX10RenderTargetView(); //frame buffer
ID3D10DepthStencilView *pDepthStencilView = GutGetDX10DepthStencilView(); //depth/stencil buffer
IDXGISwapChain *pSwapChain = GutGetDX10SwapChain(); // front/back buffer
g_pDevice->ClearRenderTargetView(pRenderTargetView, &vClearColor[0]);
g_pDevice->ClearDepthStencilView(pDepthStencilView, D3D10_CLEAR_DEPTH|D3D10_CLEAR_STENCIL, 1.0f, 0);
Matrix4x4 camera_matrix = g_Control.GetCameraMatrix();
Matrix4x4 view_matrix = g_Control.GetViewMatrix();
Matrix4x4 world_matrix = g_Control.GetObjectMatrix();
g_Model_DX10.SetLight(0, g_Lights[0]);
g_Model_DX10.SetLight(1, g_Lights[1]);
g_Model_DX10.EnableLighting(true);
g_Model_DX10.SetProjectionMatrix(g_proj_matrix);
g_Model_DX10.SetWorldMatrix(world_matrix);
g_Model_DX10.SetViewMatrix(view_matrix);
g_Model_DX10.SetInvViewMatrix(camera_matrix);
g_Model_DX10.UpdateMatrix();
g_Model_DX10.Render();
// 等待硬體掃結束, 然後才更新畫面
pSwapChain->Present(1, 0);
}
示例12: RenderFrameDX10
void RenderFrameDX10(void)
{
Vector4 vClearColor(0.0f);
Vector4 vObjectColor(0.0f, 1.0f, 0.0f);
ID3D10RenderTargetView *pRenderTargetView = GutGetDX10RenderTargetView(); //frame buffer
ID3D10DepthStencilView *pDepthStencilView = GutGetDX10DepthStencilView(); //depth/stencil buffer
g_pDevice->ClearRenderTargetView(pRenderTargetView, &vClearColor[0]);
g_pDevice->ClearDepthStencilView(pDepthStencilView, D3D10_CLEAR_DEPTH|D3D10_CLEAR_STENCIL, 1.0f, 0);
// background image
DrawImage(g_pTexture);
// refraction
Matrix4x4 view_matrix = g_Control.GetViewMatrix();
Matrix4x4 world_matrix = g_Control.GetObjectMatrix();
Matrix4x4 wvp_matrix = world_matrix * view_matrix * g_proj_matrix;
Matrix4x4 wv_matrix = world_matrix * view_matrix;
ID3D10EffectTechnique *pShader = g_pRefractionFX->GetTechniqueByName("Refraction");
ID3D10EffectShaderResourceVariable *texture_param = g_pRefractionFX->GetVariableByName("BackgroundImage")->AsShaderResource();
ID3D10EffectMatrixVariable *wvpmatrix_param = g_pRefractionFX->GetVariableByName("wvp_matrix")->AsMatrix();
ID3D10EffectMatrixVariable *wvmatrix_param = g_pRefractionFX->GetVariableByName("wv_matrix")->AsMatrix();
ID3D10EffectVectorVariable *color_param = g_pRefractionFX->GetVariableByName("object_color")->AsVector();
texture_param->SetResource(g_pTexture);
wvpmatrix_param->SetMatrix( (float *)&wvp_matrix );
wvmatrix_param->SetMatrix( (float *)&wv_matrix );
color_param->SetFloatVector( (float *)&vObjectColor );
pShader->GetPassByIndex(0)->Apply(0);
g_pDevice->IASetInputLayout(g_pRefractionLayout);
g_Model_DX10.Render(SUBMIT_CULLFACE);
// 等待硬體掃結束, 然後才更新畫面
IDXGISwapChain *pSwapChain = GutGetDX10SwapChain();
pSwapChain->Present(1, 0);
}
示例13: ReleaseResourceDX10
bool ReleaseResourceDX10(void)
{
g_Model_DX10.Release();
return true;
}