コード例 #1
0
void ShadowDemo::DrawScene()
{
	Matrix worldMatrix;
	Matrix viewMatrix;
	Matrix projectionMatrix;
	viewMatrix = g_objTrackballCameraController.View();
	projectionMatrix = g_objTrackballCameraController.Proj();
	SwapChainPtr->Begin();
	RenderSceneToTexture();
	Render(worldMatrix, viewMatrix, projectionMatrix);
	SwapChainPtr->Flip();
}
コード例 #2
0
//===============================================================================================================================
void BlurredEnvironment::Render()
{
	if( Quickwire() )
	{
		m_pCube->SetWireframe( true );
		m_pNoBlurCube->SetWireframe( true );
		m_D3DSystem->TurnOnWireframe();
	}

	m_D3DSystem->TurnOnZBuffer();
	
	// Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing.
	ZShadeSandboxMesh::MeshRenderParameters mrp;
	mrp.camera = m_CameraSystem;
	m_pCube->Render(mrp);
	//m_pNoBlurCube->Render(mCamera, TriangleList, false, true);

	/*if (m_VertextProcessEnable)
	{
		ID3D11ShaderResourceView* pInputSRV = mD3DSystem->GetColorRenderTarget()->GetSRV();
		DepthStencilBuffer* pDepth = mD3DSystem->GetDepthStencilBuffer();
		ID3D11RenderTargetView* pOutputRTV = mD3DSystem->GetBackBufferRTV();

		m_pSimplePP->Render(pInputSRV, pOutputRTV);

		Reset the backbuffer and viewports after Vertext processing and turn the z buffer back on
		mD3DSystem->SetBackBufferRenderTarget(m_VertextProcessEnable);
		mD3DSystem->ResetViewport();
		mD3DSystem->TurnOnZBuffer();
	}*/

	RenderSceneToTexture();
	DownSampleTexture();
	RenderHorizontalBlurToTexture();
	RenderVerticalBlurToTexture();
	UpSampleTexture();
	Render2DTextureScene();
}
コード例 #3
0
bool GraphicsClass::Render()
{
    D3DXMATRIX worldMatrix, viewMatrix, projectionMatrix, translateMatrix;
    float posX, posY, posZ;


    // First render the scene to a texture.
    RenderSceneToTexture();

    // Next render the shadowed scene in black and white.
    RenderBlackAndWhiteShadows();

    // Then down sample the black and white scene texture.
    DownSampleTexture();

    // Perform a horizontal blur on the down sampled texture.
    RenderHorizontalBlurToTexture();

    // Now perform a vertical blur on the texture.
    RenderVerticalBlurToTexture();

    // Finally up sample the final blurred render to texture that can now be used in the soft shadow shader.
    UpSampleTexture();

    // Clear the buffers to begin the scene.
    m_D3D->BeginScene(0.0f, 0.0f, 0.0f, 1.0f);

    // Generate the view matrix based on the camera's position.
    m_Camera->Render();

    // Get the world, view, and projection matrices from the camera and d3d objects.
    m_D3D->GetWorldMatrix(worldMatrix);
    m_Camera->GetViewMatrix(viewMatrix);
    m_D3D->GetProjectionMatrix(projectionMatrix);

    // Setup the translation matrix for the cube model.
    m_CubeModel->GetPosition(posX, posY, posZ);
    D3DXMatrixTranslation(&worldMatrix, posX, posY, posZ);

    // Render the cube model using the soft shadow shader.
    m_CubeModel->Render(m_D3D->GetDevice());
    m_SoftShadowShader->Render(m_D3D->GetDevice(), m_CubeModel->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_CubeModel->GetTexture(),
                               m_UpSampleTexure->GetShaderResourceView(), m_Light->GetPosition(), m_Light->GetAmbientColor(), m_Light->GetDiffuseColor());

    // Reset the world matrix.
    m_D3D->GetWorldMatrix(worldMatrix);

    // Setup the translation matrix for the sphere model.
    m_SphereModel->GetPosition(posX, posY, posZ);
    D3DXMatrixTranslation(&worldMatrix, posX, posY, posZ);

    // Render the sphere model using the soft shadow shader.
    m_SphereModel->Render(m_D3D->GetDevice());
    m_SoftShadowShader->Render(m_D3D->GetDevice(), m_SphereModel->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_SphereModel->GetTexture(),
                               m_UpSampleTexure->GetShaderResourceView(), m_Light->GetPosition(), m_Light->GetAmbientColor(), m_Light->GetDiffuseColor());

    // Reset the world matrix.
    m_D3D->GetWorldMatrix(worldMatrix);

    // Setup the translation matrix for the ground model.
    m_GroundModel->GetPosition(posX, posY, posZ);
    D3DXMatrixTranslation(&worldMatrix, posX, posY, posZ);

    // Render the ground model using the soft shadow shader.
    m_GroundModel->Render(m_D3D->GetDevice());
    m_SoftShadowShader->Render(m_D3D->GetDevice(), m_GroundModel->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_GroundModel->GetTexture(),
                               m_UpSampleTexure->GetShaderResourceView(), m_Light->GetPosition(), m_Light->GetAmbientColor(), m_Light->GetDiffuseColor());

    // Present the rendered scene to the screen.
    m_D3D->EndScene();

    return true;
}
コード例 #4
0
bool GraphicsClass::Render()
{
    D3DXMATRIX worldMatrix, viewMatrix, projectionMatrix, translateMatrix;
    D3DXMATRIX lightViewMatrix, lightProjectionMatrix;
    bool result;
    float posX, posY, posZ;


    // First render the scene to a texture.
    result = RenderSceneToTexture();
    if(!result)
    {
        return false;
    }

    // Clear the buffers to begin the scene.
    m_D3D->BeginScene(0.0f, 0.0f, 0.0f, 1.0f);

    // Generate the view matrix based on the camera's position.
    m_Camera->Render();

    // Generate the light view matrix based on the light's position.
    m_Light->GenerateViewMatrix();

    // Get the world, view, and projection matrices from the camera and d3d objects.
    m_Camera->GetViewMatrix(viewMatrix);
    m_D3D->GetWorldMatrix(worldMatrix);
    m_D3D->GetProjectionMatrix(projectionMatrix);

    // Get the light's view and projection matrices from the light object.
    m_Light->GetViewMatrix(lightViewMatrix);
    m_Light->GetProjectionMatrix(lightProjectionMatrix);

    // Setup the translation matrix for the cube model.
    m_CubeModel->GetPosition(posX, posY, posZ);
    D3DXMatrixTranslation(&worldMatrix, posX, posY, posZ);

    // Put the cube model vertex and index buffers on the graphics pipeline to prepare them for drawing.
    m_CubeModel->Render(m_D3D->GetDevice());

    // Render the model using the shadow shader.
    m_ShadowShader->Render(m_D3D->GetDevice(), m_CubeModel->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, lightViewMatrix,
                           lightProjectionMatrix, m_CubeModel->GetTexture(), m_RenderTexture->GetShaderResourceView(), m_Light->GetPosition(),
                           m_Light->GetAmbientColor(), m_Light->GetDiffuseColor());

    // Reset the world matrix.
    m_D3D->GetWorldMatrix(worldMatrix);

    // Setup the translation matrix for the sphere model.
    m_SphereModel->GetPosition(posX, posY, posZ);
    D3DXMatrixTranslation(&worldMatrix, posX, posY, posZ);

    // Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing.
    m_SphereModel->Render(m_D3D->GetDevice());
    m_ShadowShader->Render(m_D3D->GetDevice(), m_SphereModel->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
                           lightViewMatrix, lightProjectionMatrix, m_SphereModel->GetTexture(), m_RenderTexture->GetShaderResourceView(),
                           m_Light->GetPosition(), m_Light->GetAmbientColor(), m_Light->GetDiffuseColor());

    // Reset the world matrix.
    m_D3D->GetWorldMatrix(worldMatrix);

    // Setup the translation matrix for the ground model.
    m_GroundModel->GetPosition(posX, posY, posZ);
    D3DXMatrixTranslation(&worldMatrix, posX, posY, posZ);

    // Render the ground model using the shadow shader.
    m_GroundModel->Render(m_D3D->GetDevice());
    m_ShadowShader->Render(m_D3D->GetDevice(), m_GroundModel->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
                           lightViewMatrix, lightProjectionMatrix, m_GroundModel->GetTexture(), m_RenderTexture->GetShaderResourceView(),
                           m_Light->GetPosition(), m_Light->GetAmbientColor(), m_Light->GetDiffuseColor());

    // Present the rendered scene to the screen.
    m_D3D->EndScene();

    return true;
}
コード例 #5
0
bool GraphicsManager::RenderPostProcessing(Camera* cam)
{
	bool result;

	// First render the scene to a render texture.
	result = RenderSceneToTexture(cam);
	if(!result)
	{
		return false;
	}

	//// Next down sample the render texture to a smaller sized texture.
	//result = DownSampleTexture(cam, m_RenderTexture);
	//if(!result)
	//{
	//	return false;
	//}

	//Render glow map
	result = CreateGlowMap(cam, m_RenderTexture, D3DXVECTOR4(0.33f, 0.33f, 0.33f, 0.0f));
	if(!result)
	{
		return false;
	}

	for (int pass = 0; pass < 1; pass++)
	{
		//// Perform a convolution pass.
		//result = ApplyConvolutionTexture(cam, m_RenderTexture, D3DXVECTOR4(0.0f, -1.0f, 0.0f, 0.0f), D3DXVECTOR4(-1.0f, 5.0f, -1.0f, 0.0f), D3DXVECTOR4(0.0f, -1.0f, 0.0f, 0.0f));
		//if(!result)
		//{
		//	return false;
		//}

		// Horizontal blur the down sampled texture.
		result = BlurTextureHorizontally(cam, m_GlowMapTexture);
		if(!result)
		{
			return false;
		}

		// Vertical blur the horizontal blur texture.
		result = BlurTextureVertically(cam, m_HorizontalBlurTexture);
		if(!result)
		{
			return false;
		}
	}

	// Up sample the final blurred render texture to screen size again.
	result = UpSampleTexture(cam, m_VerticalBlurTexture);
	if(!result)
	{
		return false;
	}

	RenderTestToTexture(cam, m_MiniMapTexture);
	result = ApplyConvolutionTexture(cam, m_MiniMapTexture, m_convolutionRow1, m_convolutionRow2, m_convolutionRow3);
	if(!result)
	{
			return false;
	}

	//Perform glow on texture
	result = GlowTexture(cam, m_RenderTexture, 1.1f);
	if(!result)
	{
		return false;
	}

	// Render the blurred up sampled render texture to the screen.
	result = Render2DTextureScene(cam, m_GlowTexture);
	if(!result)
	{
		return false;
	}
	
	return true;
}