📄 mvolumerender.cpp
字号:
if(MainViewport.Width <= MainViewport.Height)
{
MainViewport.Height = (DWORD)scaleFactor*MainViewport.Height/MainViewport.Width;
MainViewport.Width = (DWORD)scaleFactor;
}
else
{
MainViewport.Width = (DWORD)scaleFactor*MainViewport.Width/MainViewport.Height;
MainViewport.Height = (DWORD)scaleFactor;
}
D3DXMatrixOrthoLH( &matOrtho, (float)MainViewport.Width, (float)MainViewport.Height, -15, 20 );
*/
// render target 厚啦捞 沥荤阿屈栏肺 绊沥登绢 乐栏骨肺..
D3DXMatrixOrthoLH( &matOrtho, (float)scaleFactor, (float)scaleFactor, 0, 30 );
//------ Set VertexShader view projection matrix constants !!------------------------
D3DXMatrixMultiply( &viewProjection, &matView, &matOrtho ); // viewProjection 汲沥.
m_pEffect->SetMatrix( "viewProjMatrix", &viewProjection );
}
//-----------------------------------------------------------------------------
// Name: CAppForm::FrameMove()
// Desc: Called once per frame, the call is the entry point for animating
// the scene.
//-----------------------------------------------------------------------------
HRESULT CAppForm::FrameMove()
{
// TODO: update world
// Update user input state
UpdateInput( &m_UserInput );
// Update the world state according to user input
if( m_UserInput.bRotateLeft && !m_UserInput.bRotateRight )
m_texCoordRotY -= m_fElapsedTime;
else if( m_UserInput.bRotateRight && !m_UserInput.bRotateLeft )
m_texCoordRotY += m_fElapsedTime;
if( m_UserInput.bRotateUp && !m_UserInput.bRotateDown )
m_texCoordRotX -= m_fElapsedTime;
else if( m_UserInput.bRotateDown && !m_UserInput.bRotateUp )
m_texCoordRotX += m_fElapsedTime;
D3DXMATRIX matRotY;
D3DXMATRIX matRotX;
D3DXMATRIX rotation;
D3DXMATRIX trans;
D3DXMATRIX result;
D3DXMatrixTranslation(&trans, 0.5, 0.5, 0.5);
D3DXMatrixRotationX(&matRotX, -m_texCoordRotX );
D3DXMatrixRotationZ(&matRotY, m_texCoordRotY );
//------------------ Texture coordinate transformation -----------------------------------
// --> 谅钎函券苞 楷魂鉴辑 馆措~ (trans 茄 饶 Y rotation & X rotation)
rotation = matRotX * matRotY;
result = rotation * trans; // texture coord. bias 父怒 歹秦霖 饶 雀傈.
m_pEffect->SetMatrix( "textureTransMatrix", &result );
//------ set light & view vector ----------------------------------
D3DXVECTOR3 litTrans;
D3DXVec3TransformNormal(&litTrans, &light, &rotation);
D3DXVECTOR4 lightDirection = D3DXVECTOR4( litTrans.x, litTrans.y, litTrans.z, 0.0f );
m_pEffect->SetVector( "lightVec", &lightDirection ); // light vector
// D3DXVECTOR3 viewTrans;
// D3DXVec3TransformNormal(&viewTrans, &view, &rotation);
// D3DXVECTOR4 viewDirection = D3DXVECTOR4( viewTrans.x, viewTrans.y, viewTrans.z, 0.0f );
// m_pEffect->SetVector( "viewVec", &viewDirection ); // view vector
//------------------ clip plane using fixed function pixel pipeline (only 6 plane) -------------
D3DXVECTOR3 rotClipPoint[6];
D3DXPLANE plane;
// Set the custom clip planes rotation
// Texture coordinate transformation 苞 阿档蔼 馆措, 雀傈青纺 利侩鉴辑 馆措. (角力 谅钎蔼狼 函券捞骨肺)
// 雀傈..
rotation = matRotY * matRotX;
// fixed function clip 狼 版快, clip coordi. 俊辑 clipping 捞 老绢唱骨肺 viewProjection 蚌窍咯 clip coordi. 栏肺 函券窍咯 霖促.
result = rotation * viewProjection;
// set pass0 vertex shader trans matrix-------------------------------------------
m_pEffect->SetMatrix( "objectTransMatrix", &result );
// MPR_TEST
// MPR 檬扁拳 青纺 matCustomMPR 蚌秦淋. (OnLButtonDown 曼炼)
matFinalMPRVertex = matCustomMPR * result;
m_pEffect->SetMatrix( "customMPRMatrix", &matFinalMPRVertex );
matFinalMPRTex = matCustomMPRTex * trans;
// m_pEffect->SetMatrix( "customMPRTex", &matFinalMPRTex );
// used in EmptySkipVShader
// object face normal, tranformed
D3DXVECTOR3 transObjNormalZ;
D3DXVECTOR3 transObjNormalX;
D3DXVECTOR3 transObjNormalY;
// transfrom object face normals
D3DXVec3TransformNormal(&transObjNormalZ, &objFaceNormalZ, &result);
D3DXVec3TransformNormal(&transObjNormalX, &objFaceNormalX, &result);
D3DXVec3TransformNormal(&transObjNormalY, &objFaceNormalY, &result);
isFrontFaceZ = D3DXVec3Dot(&transObjNormalZ, &view);
isFrontFaceX = D3DXVec3Dot(&transObjNormalX, &view);
isFrontFaceY = D3DXVec3Dot(&transObjNormalY, &view);
for(int k=0; k<6; k++)
{
D3DXVec3TransformCoord(&rotClipPoint[k], &clipPoint[k], &result);
}
//
D3DXPlaneFromPoints( &m_ClipPlaneCoeff[0], &rotClipPoint[1], &rotClipPoint[0], &rotClipPoint[2]);
D3DXPlaneFromPoints( &m_ClipPlaneCoeff[1], &rotClipPoint[4], &rotClipPoint[3], &rotClipPoint[5]);
//
m_pd3dDevice->SetClipPlane( 0, m_ClipPlaneCoeff[0]); // left
m_pd3dDevice->SetClipPlane( 1, m_ClipPlaneCoeff[1]); // right
m_pd3dDevice->SetClipPlane( 2, *D3DXPlaneFromPoints( &plane, &rotClipPoint[4], &rotClipPoint[5], &rotClipPoint[2])); // top
m_pd3dDevice->SetClipPlane( 3, *D3DXPlaneFromPoints( &plane, &rotClipPoint[3], &rotClipPoint[0], &rotClipPoint[1])); // bottom
m_pd3dDevice->SetClipPlane( 4, *D3DXPlaneFromPoints( &plane, &rotClipPoint[0], &rotClipPoint[3], &rotClipPoint[4])); // back
m_pd3dDevice->SetClipPlane( 5, *D3DXPlaneFromPoints( &plane, &rotClipPoint[1], &rotClipPoint[2], &rotClipPoint[5])); // front face
//----------------- clip plane using Vertex Shader -------------------------------------
// fixed function pipeline clip苞绰 崔府 viewProjection matrix 蚌窍瘤 臼澜!! ( vertex shader 俊辑狼 vertex v0 绰 酒流 world coordi. 俊 粮犁窍骨肺.. )
m_clipPlaneRotation = rotation; // matRotY * matRotX
SetTwoVSClipPlane(vsClipplaneCoord0, vsClipplaneCoord1); // set two vertex shader clip plane
//added by taeki -- 辑宏杭俘 access俊 包茄 函荐甫 持绢初绰促.
D3DXVECTOR4 sizeOfSubvolume = D3DXVECTOR4(m_intSubvolumeSizeX, m_intSubvolumeSizeY, m_intSubvolumeSizeZ, 0);
D3DXVECTOR4 redunRealSlot = D3DXVECTOR4(m_intRealSubvolumeSlotX, m_intRealSubvolumeSlotY, m_intRealSubvolumeSlotZ, 0);
D3DXVECTOR4 volumeSize = D3DXVECTOR4(m_intVolumeX, m_intVolumeY, m_intVolumeZ, 0);
D3DXVECTOR4 virtualSubvolumeSize = D3DXVECTOR4(m_intVirtualMemorySlotX, m_intVirtualMemorySlotY, m_intVirtualMemorySlotZ, 0);
D3DXVECTOR4 forOptimize = D3DXVECTOR4(m_intSubvolumeSizeX*m_intVirtualMemorySlotX, m_intSubvolumeSizeY*m_intVirtualMemorySlotY, m_intSubvolumeSizeZ*m_intVirtualMemorySlotZ, m_intVirtualMemorySlotX*m_intVirtualMemorySlotY*m_intVirtualMemorySlotZ);
m_pEffect->SetVector( "sizeOfSubvolume", &sizeOfSubvolume ); // 辑宏杭俘狼 农扁
m_pEffect->SetVector( "redunRealSlot", &redunRealSlot ); // 吝汗等 角力 杭俘狼 辑宏杭俘 肮荐
m_pEffect->SetVector( "volumeSize", &volumeSize ); // 杭俘狼 农扁
m_pEffect->SetVector( "virtualSubvolumeSize", &virtualSubvolumeSize ); // 啊惑 辑宏杭俘狼 肮荐
m_pEffect->SetVector( "forOptimize", &forOptimize ); // 郴何 拌魂阑 临捞扁 困茄 惑荐
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: UpdateInput()
// Desc: Update the user input. Called once per frame
//-----------------------------------------------------------------------------
void CAppForm::UpdateInput( UserInput* pUserInput )
{
pUserInput->bRotateUp = ( m_bActive && (GetAsyncKeyState( VK_UP ) & 0x8000) == 0x8000 );
pUserInput->bRotateDown = ( m_bActive && (GetAsyncKeyState( VK_DOWN ) & 0x8000) == 0x8000 );
pUserInput->bRotateLeft = ( m_bActive && (GetAsyncKeyState( VK_LEFT ) & 0x8000) == 0x8000 );
pUserInput->bRotateRight = ( m_bActive && (GetAsyncKeyState( VK_RIGHT ) & 0x8000) == 0x8000 );
}
//-----------------------------------------------------------------------------
// Name: CAppForm::Render()
// Desc: Called once per frame, the call is the entry point for 3d
// rendering. This function sets up render states, clears the
// viewport, and renders the scene.
//-----------------------------------------------------------------------------
HRESULT CAppForm::Render()
{
// Begin the scene
// if( SUCCEEDED( m_pd3dDevice->BeginScene() ) )
{
//--------------- TODO: render world ----------------------
// save old render target (frame buffer)
m_pd3dDevice->GetRenderTarget(0, &m_pOldRenderTarget);
LPDIRECT3DSURFACE9 pInterResult;
m_pIntermediateTexture->GetSurfaceLevel(0, &pInterResult);
m_pd3dDevice->SetRenderTarget(0, pInterResult);
// clear render target texture
m_pd3dDevice->Clear( 0L, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
0x00000000, 0.0f, 0L );
//---- 1. Draw the quad, with the volume texture to Render target ----
m_pd3dDevice->BeginScene();
m_pEffect->SetTechnique("MVRenderTechnique"); // set technique
UINT numPasses;
m_pEffect->Begin( &numPasses, 0 ); // Effect Begin()
//-------------- Start PASS0 -------------------
if(m_renderingPass == RENDERALLPASS || m_renderingPass == RENDERSHOWDEPTH)
{
//------------ 0. Pass0 : empty space skip -----------------------------------
m_pd3dDevice->Clear( 0L, NULL, D3DCLEAR_ZBUFFER, 0x00000000, 100.0f, 0L ); // clear depth to 1.0f
m_pd3dDevice->SetVertexDeclaration( m_pObjOrderProxyVertexDecl );
m_pd3dDevice->SetStreamSource( 0, m_pObjectOrderProxy, 0, sizeof(OBJECTORDERPROXY) );
// sampler register fixed in Effect file
m_pd3dDevice->SetTexture( 0, m_pVolumeTexture );
m_pd3dDevice->SetTexture( 1, m_pGradientTexture );
m_pd3dDevice->SetTexture( 2, m_pPreIntegratedTexture );
m_pd3dDevice->SetTexture( 3, m_pIntermediateTexture );
m_pd3dDevice->SetTexture( 4, m_pVolumeTexMM );
if(m_renderingPass == RENDERSHOWDEPTH) {
m_pEffect->Pass(4); // ShowDepthPass
}
else {
m_pEffect->Pass(0); // EmptySkipPass
}
// object face normal (in object space) set for z axis
m_pEffect->SetVector( "faceNormal", &objFaceNormal4DZ );
m_pEffect->SetFloat( "isFrontFace", isFrontFaceZ );
// ----------- for z axis ----------------------
for(int m=0; m < OBJECTSLICENUM ; m = m+1)
{
m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, m*4, 2);
}
// object face normal (in object space) set for x axis
m_pEffect->SetVector( "faceNormal", &objFaceNormal4DX );
m_pEffect->SetFloat( "isFrontFace", isFrontFaceX );
// ----------- for x axis ----------------------
for( m=OBJECTSLICENUM; m < 2*OBJECTSLICENUM ; m = m+1)
{
m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, m*4, 2);
}
// object face normal (in object space) set for y axis
m_pEffect->SetVector( "faceNormal", &objFaceNormal4DY );
m_pEffect->SetFloat( "isFrontFace", isFrontFaceY );
// ----------- for y axis ----------------------
for(m=2*OBJECTSLICENUM; m < 3*OBJECTSLICENUM ; m = m+1)
{
m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, m*4, 2);
}
m_pd3dDevice->EndScene(); // end scene
}//------------ End PASS0 --------------------
for(int i=0; i<SLICENUMBER; i++)
{
m_pd3dDevice->BeginScene(); // begin/end scene per Passes
//------------- Start PASS1 -----------------
if(m_renderingPass == RENDERALLPASS || m_renderingPass == RENDERPASS1)
{
//------------- 1. Pass1 : Main Pass -----------------------------------------
m_pd3dDevice->SetVertexDeclaration( m_pImagOrderProxyVertexDecl );
m_pd3dDevice->SetStreamSource( 0, m_pVB, 0, sizeof(VOLUMEVERTEX) );
m_pd3dDevice->SetTexture( 0, m_pVolumeTexture );
m_pd3dDevice->SetTexture( 1, m_pGradientTexture );
m_pd3dDevice->SetTexture( 2, m_pPreIntegratedTexture );
m_pd3dDevice->SetTexture( 3, NULL );
m_pd3dDevice->SetTexture( 4, NULL );
m_pd3dDevice->SetTexture( 7, NULL );
m_pEffect->Pass(1); // VolumeRenderPass
m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, i*4, 2);
}//------------- End PASS1 ---------------------
//------------- Start PASS2 -----------------
if(m_renderingPass == RENDERALLPASS)
{
if(i%8 == 0) { // per 8 slice
//--------------- 2. Pass2 : Early Ray termination --------------
m_pd3dDevice->SetTexture( 0, NULL );
m_pd3dDevice->SetTexture( 1, NULL );
m_pd3dDevice->SetTexture( 2, NULL );
m_pd3dDevice->SetTexture( 3, m_pIntermediateTexture ); // renderTarget texture
m_pd3dDevice->SetTexture( 4, NULL );
m_pd3dDevice->SetTexture( 7, NULL );
m_pEffect->Pass(2); // EarlyRayPass
m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, i*4, 2);
}
}//------------- End PASS2 ---------------------
m_pd3dDevice->EndScene(); // end scene
}
// MPR_TEST
//------------ Curved MPR plane 阑 DVR 俊 般媚辑 弊妨霖促. --------------------
m_pd3dDevice->BeginScene();
{
m_pd3dDevice->SetVertexDeclaration( m_pObjOrderProxyVertexDecl );
m_pd3dDevice->SetStreamSource( 0, m_pMPRGeometryVB, 0, sizeof(OBJECTORDERPROXY) );
m_pd3dDevice->SetTexture( 0, m_pVolumeTexture );
if(m_mprCtrlPntNum >= 2) {
m_pEffect->Pass(7); // CustomMPR Pass
// 贾府靛肺 弊府绊 弊 困俊 客捞绢 橇饭烙栏肺..
m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2*(m_mprCtrlPntNum-1) );
m_pEffect->Pass(8); // CustomMPR wireframe Pass
m_pd3dDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_WIREFRAME);// WIREFRAME MODE
m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2*(m_mprCtrlPntNum-1) );
m_pd3dDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID); // RESTORE FILLMODE
}
}
m_pd3dDevice->EndScene(); // end scene
m_pEffect->End(); // Effect End() before render target change
//---------- RenderTarget 阑 m_pMPRRenderTarget 肺 汲沥.
pInterResult->Release();
LPDIRECT3DSURFACE9 pMPRInterResult;
m_pMPRRenderTarget->GetSurfaceLevel(0, &pMPRInterResult);
m_pd3dDevice->SetRenderTarget(0, pMPRInterResult);
// clear render target texture
m_pd3dDevice->Clear( 0L, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
0x00000000, 0.0f, 0L );
// MPR_TEST
///////////////////////////////// Pass 9 /////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
//---- MPR Plane 旗辑 MPR 咆胶媚 谅钎
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -