Пример #1
0
void RenderFrameDX10(void)
{
	Vector4 vClearColor(0.0f, 0.0f, 0.0f, 0.0f);

	// 取得主畫面
	ID3D10RenderTargetView *pRenderTargetView = GutGetDX10RenderTargetView();
	ID3D10DepthStencilView *pDepthStencilView = GutGetDX10DepthStencilView(); 

	g_pDevice->ClearRenderTargetView(pRenderTargetView, (float *)&vClearColor);
	g_pDevice->ClearDepthStencilView(pDepthStencilView, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0f, 0);

	g_pDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_LINESTRIP);

	ID3D10EffectTechnique *g_pShader = NULL;

	switch(g_iMode)
	{
	default:
	case 1:
		g_pShader = g_pDrawCurveFX->GetTechniqueByName("SinCurve");
		break;
	case 2:
		{
			g_pShader = g_pDrawCurveFX->GetTechniqueByName("ZCurve");

			Vector4 vNearFar(1.0f, 100.0f, 0.0f, 0.0f);
			Matrix4x4 proj_matrix = GutMatrixPerspectiveRH_DirectX(45.0f, 1.0f, vNearFar[0], vNearFar[1]);
			//Matrix4x4 proj_matrix = GutMatrixOrthoRH_DirectX(10.0f, 10.0f, vNearFar[0], vNearFar[1]);
			//Matrix4x4 proj_matrix = GutMatrixOrthoRH_OpenGL(10.0f, 10.0f, vNearFar[0], vNearFar[1]);
			//Matrix4x4 proj_matrix = GutMatrixPerspectiveRH_OpenGL(45.0f, 1.0f, vNearFar[0], vNearFar[1]);

			ID3D10EffectMatrixVariable *pMatrix = 
				g_pDrawCurveFX->GetVariableByName("proj_matrix")->AsMatrix();
			ID3D10EffectVectorVariable *pNearFarPlane = 
				g_pDrawCurveFX->GetVariableByName("NearFarPlane")->AsVector();

			pMatrix->SetMatrix(&proj_matrix[0][0]);
			pNearFarPlane->SetFloatVector(&vNearFar[0]);

			break;
		}
	}

	g_pShader->GetPassByIndex(0)->Apply(0);
	g_pDevice->Draw(2, 0);

	IDXGISwapChain *pSwapChain = GutGetDX10SwapChain(); 
	pSwapChain->Present(1, 0);
}
Пример #2
0
void CubeMapApp::drawScene()
{
	D3DApp::drawScene();
	
	
	// Restore default states, input layout and primitive topology 
	// because mFont->DrawText changes them.  Note that we can 
	// restore the default states by passing null.
	md3dDevice->OMSetDepthStencilState(0, 0);
	float blendFactor[] = {0.0f, 0.0f, 0.0f, 0.0f};
	md3dDevice->OMSetBlendState(0, blendFactor, 0xffffffff);
	
	md3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	md3dDevice->IASetInputLayout(InputLayout::PosNormalTex);

	// Set per frame constants.
	mfxEyePosVar->SetRawValue(&GetCamera().position(), 0, sizeof(D3DXVECTOR3));
	mfxLightVar->SetRawValue(&mParallelLight, 0, sizeof(Light));
	
	mfxCubeMapVar->SetResource(mEnvMapRV);
	

	D3DXMATRIX view = GetCamera().view();
	D3DXMATRIX proj = GetCamera().proj();

    D3D10_TECHNIQUE_DESC techDesc;
    mTech->GetDesc( &techDesc );

    for(UINT i = 0; i < techDesc.Passes; ++i)
    {
        ID3D10EffectPass* pass = mTech->GetPassByIndex(i);

		//
		// draw center ball
		//
		D3DXMATRIX centerBallWVP = mCenterBallWorld*view*proj;
		mfxWVPVar->SetMatrix((float*)&centerBallWVP);
		mfxWorldVar->SetMatrix((float*)&mCenterBallWorld);
		mfxTexMtxVar->SetMatrix((float*)&mIdentityTexMtx);
		mfxDiffuseMapVar->SetResource(mBallMapRV);
		mfxSpecMapVar->SetResource(mDefaultSpecMapRV);
		mfxCubeMapEnabledVar->SetBool(true);
		mfxReflectMtrlVar->SetFloatVector((float*)&mReflectAll);
		pass->Apply(0);
		mBall.draw();		
    }

	// We specify DT_NOCLIP, so we do not care about width/height of the rect.
	RECT R = {5, 5, 0, 0};
	md3dDevice->RSSetState(0);
	mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, WHITE);

	mSwapChain->Present(0, 0);
}
Пример #3
0
//render frame
void DX10Renderer::RenderFrame()
{

    //rotate light - shouldnt do this each frame but i'm lazy
    //***************************************************************************

    //rotate light position
    /*XMFLOAT3 yaxis(0,1,0), o(0,0,0), u(0,1,0);
    XMMATRIX rotMatrix = XMMatrixRotationAxis( XMLoadFloat3(&yaxis), 0.01f);

    //new rotated light pos
    XMVECTOR olpos = XMLoadFloat3(&lightPos);
    XMVECTOR lpos = XMVector3TransformCoord( olpos , rotMatrix);
    XMStoreFloat3(&lightPos, lpos);

    //get new view matrix
    XMVECTOR fp = XMLoadFloat3( &o  ), up = XMLoadFloat3( &u );
    XMMATRIX vmat = XMMatrixLookAtLH( lpos, fp, up );

    //create new light view proj matrix
    XMMATRIX lpmat = XMLoadFloat4x4(&lightProjMatrix);
    XMMATRIX lvpmat = XMMatrixMultiply(vmat, lpmat);
    XMStoreFloat4x4(&lightViewProjMatrix, lvpmat);*/

    //set per frame variables
    //***************************************************************************

    //effect vars
    ID3D10EffectMatrixVariable* pWorldMatrix = pEffect->GetVariableByName("world")->AsMatrix();
    ID3D10EffectMatrixVariable* pViewProjMatrix = pEffect->GetVariableByName("viewProj")->AsMatrix();
    ID3D10EffectMatrixVariable* pLightViewProjMatrix = pEffect->GetVariableByName("lightViewProj")->AsMatrix();
    ID3D10EffectVectorVariable* pLightPos = pEffect->GetVariableByName("lightPos")->AsVector();

    pLightPos->SetFloatVectorArray( (float*) &lightPos, 0, 3);
    pViewProjMatrix->SetMatrix( (float*) &camera.GetViewProjectionMatrix() );
    pLightViewProjMatrix->SetMatrix( (float*) &lightViewProjMatrix );

    //set topology to triangle list
    pD3DDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

    //create shadow map
    //***************************************************************************

    //set render targets and viewport
    pD3DDevice->OMSetRenderTargets(0, 0, pShadowMapDepthView);
    pD3DDevice->RSSetViewports(1, &shadowMapViewport);
    pD3DDevice->ClearDepthStencilView( pShadowMapDepthView, D3D10_CLEAR_DEPTH, 1.0f, 0 );

    //render scene
    int currMeshID = -1;
    for (unsigned int i=0; i < scene.size(); i++)
    {
        //set appropriate vertex buffers
        if ( currMeshID != scene[i].modelID )
        {
            currMeshID = scene[i].modelID;
            pD3DDevice->IASetVertexBuffers( 0,1, &meshes[currMeshID].pVertexBuffer, &meshes[currMeshID].stride, &meshes[currMeshID].offset );
            pD3DDevice->IASetIndexBuffer( meshes[currMeshID].pIndexBuffer, DXGI_FORMAT_R32_UINT, 0);
        }

        //set instance data and draw
        pWorldMatrix->SetMatrix((float*) &scene[i].world);
        pRenderShadowMapTechnique->GetPassByIndex(0)->Apply( 0 );
        pD3DDevice->DrawIndexed(meshes[scene[i].modelID].numIndices, 0, 0);
    }

    //render final scene
    //***************************************************************************

    //set render targets and viewports
    pD3DDevice->OMSetRenderTargets(1, &pRenderTargetView, pDepthStencilView);
    pD3DDevice->RSSetViewports(1, &viewport);
    pD3DDevice->ClearRenderTargetView( pRenderTargetView, D3DXCOLOR(0.6f,0.6f,0.6f,0) );
    pD3DDevice->ClearDepthStencilView( pDepthStencilView, D3D10_CLEAR_DEPTH, 1.0f, 0 );

    //bind shadow map texture and set shadow map bias
    pEffect->GetVariableByName("shadowMap")->AsShaderResource()->SetResource( pShadowMapSRView );
    pEffect->GetVariableByName("shadowMapBias")->AsScalar()->SetFloat(shadowMapBias);
    int smSize[2] = { shadowMapViewport.Width, shadowMapViewport.Height };
    pEffect->GetVariableByName("shadowMapSize")->AsVector()->SetIntVector(smSize);

    //render scene
    currMeshID = -1;
    for (unsigned int i=0; i < scene.size(); i++)
    {
        //set appropriate vertex buffers
        if ( currMeshID != scene[i].modelID )
        {
            currMeshID = scene[i].modelID;
            pD3DDevice->IASetVertexBuffers( 0,1, &meshes[currMeshID].pVertexBuffer, &meshes[currMeshID].stride, &meshes[currMeshID].offset );
            pD3DDevice->IASetIndexBuffer( meshes[currMeshID].pIndexBuffer, DXGI_FORMAT_R32_UINT, 0);
        }

        //set instance data and draw
        pWorldMatrix->SetMatrix((float*) &scene[i].world);
        pRenderTechnique->GetPassByIndex(0)->Apply( 0 );
        pD3DDevice->DrawIndexed(meshes[scene[i].modelID].numIndices, 0, 0);
    }

    //render shadow map billboard
    //***************************************************************************
    pD3DDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);

    pBillboardTechnique->GetPassByIndex(0)->Apply( 0 );
    pD3DDevice->DrawIndexed(1, 0, 0);

    //unbind shadow map as SRV
    pEffect->GetVariableByName("shadowMap")->AsShaderResource()->SetResource( 0 );
    pBillboardTechnique->GetPassByIndex(0)->Apply( 0 );

    //swap buffers
    pSwapChain->Present(0,0);
}
Пример #4
0
EffectVectorVariable^ EffectVariable::AsVector::get()
{
    ID3D10EffectVectorVariable* returnValue = CastInterface<ID3D10EffectVariable>()->AsVector();
    return (returnValue == NULL || !returnValue->IsValid()) ? nullptr : gcnew EffectVectorVariable(returnValue);
}