HRESULT TestApplication1::OnCreateDevice(ID3D10Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc,
	void* pUserContext)
{
	HRESULT hr;

	D3DXVECTOR3 vCenter(0.25767413f, -28.503521f, 111.00689f);
	FLOAT fObjectRadius = 378.15607f;

	D3DXMatrixTranslation(&_mCenterMesh, -vCenter.x, -vCenter.y, -vCenter.z);
	D3DXMATRIXA16 m;
	D3DXMatrixRotationY(&m, D3DX_PI);
	_mCenterMesh *= m;
	D3DXMatrixRotationX(&m, D3DX_PI / 2.0f);
	_mCenterMesh *= m;
	
	// Create our vertex input layout
	_shaderutil.SetShaderName(L"Shader\\SpecularMapping_2.fx", "SpecularMapping");
	_shaderutil.ShaderSetting(*pd3dDevice);
	// Load the mesh
	V_RETURN(_Mesh.Create(pd3dDevice, L"Model\\Sphere.sdkmesh", true));

	// Setup the camera's view parameters
	D3DXVECTOR3 vecEye(0.0f, 0.0f, -15.0f);
	D3DXVECTOR3 vecAt(0.0f, 0.0f, -0.0f);
	_camera.SetViewParams(&vecEye, &vecAt);
	_camera.SetRadius(fObjectRadius * 3.0f, fObjectRadius * 0.5f, fObjectRadius * 10.0f);

	return S_OK;
}
void CTextureContentView::SetDocument(CContentStudioDoc* pDoc)
{
    m_pDoc = pDoc;

    m_renderer.Clear();

    // Handle first init?

    // FirstPersonCamera
    D3DXVECTOR3 vMin = D3DXVECTOR3( -1000.0f, -1000.0f, -1000.0f );
    D3DXVECTOR3 vMax = D3DXVECTOR3( 1000.0f, 1000.0f, 1000.0f );
    D3DXVECTOR3 vecEye( 2.0f, 0.0f, 0.0f );
    D3DXVECTOR3 vecAt( 0.0f,0.0f,0.0f );
    m_FirstPersonCamera.SetViewParams( &vecEye, &vecAt );
    m_FirstPersonCamera.SetRotateButtons(TRUE, FALSE, FALSE);
    m_FirstPersonCamera.SetScalers( 0.01f, 1 );
    m_FirstPersonCamera.SetDrag( true );
    m_FirstPersonCamera.SetEnableYAxisMovement( true );
    m_FirstPersonCamera.SetClipToBoundary( TRUE, &vMin, &vMax );
    m_FirstPersonCamera.FrameMove( 0 );
}
//--------------------------------------------------------------------------------------
// When the user changes scene, recreate these components as they are scene 
// dependent.
//--------------------------------------------------------------------------------------
HRESULT CreateD3DComponents(ID3D11Device* pd3dDevice)
{
    HRESULT hr;

    ID3D11DeviceContext* pd3dImmediateContext = DXUTGetD3D11DeviceContext();
    V_RETURN(g_DialogResourceManager.OnD3D11CreateDevice(pd3dDevice, pd3dImmediateContext));
    V_RETURN(g_D3DSettingsDlg.OnD3D11CreateDevice(pd3dDevice));
    g_pTxtHelper = new CDXUTTextHelper(pd3dDevice, pd3dImmediateContext, &g_DialogResourceManager, 15);

    XMFLOAT3 vecEye(100.0f, 5.0f, 5.0f);
    XMFLOAT3 vecAt(0.0f, 0.0f, 0.0f);
    XMFLOAT3 vMin = XMFLOAT3(-1000.0f, -1000.0f, -1000.0f);
    XMFLOAT3 vMax = XMFLOAT3(1000.0f, 1000.0f, 1000.0f);

    g_ViewerCamera.SetViewParams(XMLoadFloat3(&vecEye), XMLoadFloat3(&vecAt));
    g_ViewerCamera.SetRotateButtons(TRUE, FALSE, FALSE);
    g_ViewerCamera.SetScalers(0.01f, 10.0f);
    g_ViewerCamera.SetDrag(true);
    g_ViewerCamera.SetEnableYAxisMovement(true);
    g_ViewerCamera.SetClipToBoundary(TRUE, &vMin, &vMax);
    g_ViewerCamera.FrameMove(0);

    vecEye = XMFLOAT3(-320.0f, 300.0f, -220.3f);
    vecAt = XMFLOAT3(0.0f, 0.0f, 0.0f);
    XMFLOAT3 eyenorm = Normalize(vecEye);

    g_LightCamera.SetViewParams(XMLoadFloat3(&vecEye), XMLoadFloat3(&vecAt));
    g_LightCamera.SetRotateButtons(TRUE, FALSE, FALSE);
    g_LightCamera.SetScalers(0.01f, 50.0f);
    g_LightCamera.SetDrag(true);
    g_LightCamera.SetEnableYAxisMovement(true);
    g_LightCamera.SetClipToBoundary(TRUE, &vMin, &vMax);
    g_LightCamera.SetProjParams(XM_PI / 4, 1.0f, 0.1f, 1000.0f);
    g_LightCamera.FrameMove(0);

    g_VarianceShadow.Init(pd3dDevice, pd3dImmediateContext,
        g_pSelectedMesh, &g_ViewerCamera, &g_LightCamera, &g_CascadeConfig);

    return S_OK;
}
示例#4
0
//--------------------------------------------------------------------------------------
// Create any D3D10 resources that aren't dependant on the back buffer
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D10CreateDevice( ID3D10Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc,
                                      void* pUserContext )
{
    HRESULT hr;

    V_RETURN( g_DialogResourceManager.OnD3D10CreateDevice( pd3dDevice ) );
    V_RETURN( g_D3DSettingsDlg.OnD3D10CreateDevice( pd3dDevice ) );
    V_RETURN( D3DX10CreateFont( pd3dDevice, 15, 0, FW_BOLD, 1, FALSE, DEFAULT_CHARSET,
                                OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
                                L"Arial", &g_pFont10 ) );
    V_RETURN( D3DX10CreateSprite( pd3dDevice, MAX_SPRITES, &g_pSprite10 ) );

    V_RETURN( CDXUTDirectionWidget::StaticOnD3D10CreateDevice( pd3dDevice ) );

    // Read the D3DX effect file
    WCHAR str[MAX_PATH];
    DWORD dwShaderFlags = D3D10_SHADER_ENABLE_BACKWARDS_COMPATIBILITY;
#if defined( DEBUG ) || defined( _DEBUG )
    // Set the D3D10_SHADER_DEBUG flag to embed debug information in the shaders.
    // Setting this flag improves the shader debugging experience, but still allows 
    // the shaders to be optimized and to run exactly the way they will run in 
    // the release configuration of this program.
    dwShaderFlags |= D3D10_SHADER_DEBUG;
    #endif
    V_RETURN( DXUTFindDXSDKMediaFileCch( str, MAX_PATH, L"Exercise03.fx" ) );
    V_RETURN( D3DX10CreateEffectFromFile( str, NULL, NULL, "fx_4_0", dwShaderFlags, 0, pd3dDevice, NULL,
                                          NULL, &g_pEffect10, NULL, NULL ) );

    // Obtain the technique handles
    g_pRenderTextured = g_pEffect10->GetTechniqueByName( "RenderTextured" );
    g_pRenderPiece = g_pEffect10->GetTechniqueByName( "RenderPiece" );

    // Obtain the parameter handles
    g_pmWorldViewProj = g_pEffect10->GetVariableByName( "g_mWorldViewProj" )->AsMatrix();
    g_pmWorldView = g_pEffect10->GetVariableByName( "g_mWorldView" )->AsMatrix();
    g_pmWorld = g_pEffect10->GetVariableByName( "g_mWorld" )->AsMatrix();
    g_pmProj = g_pEffect10->GetVariableByName( "g_mProj" )->AsMatrix();
    g_pViewSpaceLightDir = g_pEffect10->GetVariableByName( "g_ViewSpaceLightDir" )->AsVector();
    g_pDiffuseTex = g_pEffect10->GetVariableByName( "g_txDiffuse" )->AsShaderResource();

    // Define our vertex data layout
    const D3D10_INPUT_ELEMENT_DESC layout[] =
    {
        { "POS", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
        { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 },
        { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0 },
    };
    UINT numElements = sizeof( layout ) / sizeof( layout[0] );
    D3D10_PASS_DESC PassDesc;
    g_pRenderPiece->GetPassByIndex( 0 )->GetDesc( &PassDesc );
    V_RETURN( pd3dDevice->CreateInputLayout( layout, numElements, PassDesc.pIAInputSignature,
                                             PassDesc.IAInputSignatureSize, &g_pVertexLayout ) );

    // Load our IB and VB with mesh data
    V_RETURN( LoadMesh( pd3dDevice ) );

    // Setup the camera's view parameters
    D3DXVECTOR3 vecEye( 0.0f, 0.0f, -8.0f );
    D3DXVECTOR3 vecAt( 0.0f,0.0f,0.0f );
    g_Camera.SetViewParams( &vecEye, &vecAt );

    return S_OK;
}
示例#5
0
//--------------------------------------------------------------------------------------
// Create any D3D10 resources that aren't dependant on the back buffer
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D10CreateDevice( ID3D10Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc,
                                      void* pUserContext )
{
    HRESULT hr;

    V_RETURN( g_DialogResourceManager.OnD3D10CreateDevice( pd3dDevice ) );
    V_RETURN( g_D3DSettingsDlg.OnD3D10CreateDevice( pd3dDevice ) );
    V_RETURN( D3DX10CreateFont( pd3dDevice, 15, 0, FW_BOLD, 1, FALSE, DEFAULT_CHARSET,
                                OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
                                L"Arial", &g_pFont10 ) );
    V_RETURN( D3DX10CreateSprite( pd3dDevice, MAX_SPRITES, &g_pSprite10 ) );

    V_RETURN( CDXUTDirectionWidget::StaticOnD3D10CreateDevice( pd3dDevice ) );

    // Read the D3DX effect file
    WCHAR str[MAX_PATH];
    DWORD dwShaderFlags = D3D10_SHADER_ENABLE_BACKWARDS_COMPATIBILITY;
#if defined( DEBUG ) || defined( _DEBUG )
    // Set the D3D10_SHADER_DEBUG flag to embed debug information in the shaders.
    // Setting this flag improves the shader debugging experience, but still allows 
    // the shaders to be optimized and to run exactly the way they will run in 
    // the release configuration of this program.
    dwShaderFlags |= D3D10_SHADER_DEBUG;
    #endif
    V_RETURN( DXUTFindDXSDKMediaFileCch( str, MAX_PATH, L"Exercise06.fx" ) );
    V_RETURN( D3DX10CreateEffectFromFile( str, NULL, NULL, "fx_4_0", dwShaderFlags, 0, pd3dDevice, NULL,
                                          NULL, &g_pEffect10, NULL, NULL ) );

    // Obtain the technique handles
    g_pRenderTextured = g_pEffect10->GetTechniqueByName( "RenderTextured" );
    g_pGrowBranches = g_pEffect10->GetTechniqueByName( "GrowBranches" );

    // Obtain the parameter handles
    g_pmWorldViewProj = g_pEffect10->GetVariableByName( "g_mWorldViewProj" )->AsMatrix();
    g_pmWorld = g_pEffect10->GetVariableByName( "g_mWorld" )->AsMatrix();
    g_pmWorldView = g_pEffect10->GetVariableByName( "g_mWorldView" )->AsMatrix();
    g_pViewSpaceLightDir = g_pEffect10->GetVariableByName( "g_ViewSpaceLightDir" )->AsVector();
    g_pLengthModifier = g_pEffect10->GetVariableByName( "LengthModifier" )->AsScalar();
    g_pSpreadModifier = g_pEffect10->GetVariableByName( "SpreadModifier" )->AsScalar();
    g_pShrinkModifier = g_pEffect10->GetVariableByName( "ShrinkModifier" )->AsScalar();
    g_pExtinctionRate = g_pEffect10->GetVariableByName( "ExtinctionRate" )->AsScalar();
    g_pDiffuseTex = g_pEffect10->GetVariableByName( "g_txDiffuse" )->AsShaderResource();
    g_pRandomBuf = g_pEffect10->GetVariableByName( "g_RandomBuffer" )->AsShaderResource();

    // Define our vertex data layout
    const D3D10_INPUT_ELEMENT_DESC layout[] =
    {
        { "POS", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
        { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 },
        { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0 },
        { "GROWAMT", 0, DXGI_FORMAT_R32_FLOAT, 0, 32, D3D10_INPUT_PER_VERTEX_DATA, 0 },
    };
    D3D10_PASS_DESC PassDesc;
    UINT numElements = sizeof( layout ) / sizeof( D3D10_INPUT_ELEMENT_DESC );
    g_pRenderTextured->GetPassByIndex( 0 )->GetDesc( &PassDesc );
    V_RETURN( pd3dDevice->CreateInputLayout( layout, numElements, PassDesc.pIAInputSignature,
                                             PassDesc.IAInputSignatureSize, &g_pVertexLayout ) );

    // Load our IB and VB with mesh data
    V_RETURN( LoadMesh( pd3dDevice ) );

    // Create our StreamTo and DrawFrom buffers
    const UINT MaxVertices = 300000;
    D3D10_BUFFER_DESC bd;
    bd.Usage = D3D10_USAGE_DEFAULT;
    bd.ByteWidth = MaxVertices * g_VertStride;
    bd.BindFlags = D3D10_BIND_VERTEX_BUFFER | D3D10_BIND_STREAM_OUTPUT;
    bd.CPUAccessFlags = 0;
    bd.MiscFlags = 0;
    V_RETURN( pd3dDevice->CreateBuffer( &bd, NULL, &g_pStreamTo ) );
    V_RETURN( pd3dDevice->CreateBuffer( &bd, NULL, &g_pDrawFrom ) );

    // Setup the camera's view parameters
    D3DXVECTOR3 vecEye( 0.0f, 0.0f, -15.0f );
    D3DXVECTOR3 vecAt( 0.0f,0.0f,0.0f );
    g_Camera.SetViewParams( &vecEye, &vecAt );

    g_pLengthModifier->SetFloat( g_LengthModifier );
    g_pSpreadModifier->SetFloat( g_SpreadModifier );
    g_pShrinkModifier->SetFloat( g_ShrinkModifier );
    g_pExtinctionRate->SetFloat( g_ExtinctionRate );


    //-----------------------------------------------------------------------------------------
    // o/__   <-- Create a buffer full of random vectors.  These will be indexed by our
    // |  (\      tree generation algorithm to give the tree a more natural look.
    //-----------------------------------------------------------------------------------------
    int iNumRandValues = 1024;
    srand( 200 );
    //create the data
    D3D10_SUBRESOURCE_DATA InitData;
    InitData.pSysMem = new float[iNumRandValues * 4];
    if( !InitData.pSysMem )
        return E_OUTOFMEMORY;
    for( int i = 0; i < iNumRandValues * 3; i++ )
    {
        ( ( float* )InitData.pSysMem )[i] = float( ( rand() % 10000 ) - 5000 ) / 5000.0f;
    }

    D3D10_BUFFER_DESC bufferDesc;
    bufferDesc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
    bufferDesc.ByteWidth = 1024 * 4 * sizeof( float );
    bufferDesc.CPUAccessFlags = 0;
    bufferDesc.MiscFlags = 0;
    bufferDesc.Usage = D3D10_USAGE_DEFAULT;
    V_RETURN( pd3dDevice->CreateBuffer( &bufferDesc, &InitData, &g_pRandomBuffer ) );
    D3D10_SHADER_RESOURCE_VIEW_DESC SRVDesc;
    ZeroMemory( &SRVDesc, sizeof( SRVDesc ) );
    SRVDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
    SRVDesc.ViewDimension = D3D10_SRV_DIMENSION_BUFFER;
    SRVDesc.Buffer.ElementOffset = 0;
    SRVDesc.Buffer.ElementWidth = 1024;
    V_RETURN( pd3dDevice->CreateShaderResourceView( g_pRandomBuffer, &SRVDesc, &g_pRandomBufferRV ) );

    SAFE_DELETE_ARRAY( InitData.pSysMem );

    return S_OK;
}
//------------------------------------------------------------------------
int CGraphicsLayer::CreateShader()
{

	 HRESULT r=0;

	 DWORD ShaderFlags=D3D10_SHADER_ENABLE_STRICTNESS;

	 ID3D10Blob *pErrors = 0;

	// Compile shaders
	 ID3D10Blob* pBlobVS = NULL;
	 ID3D10Blob* pBlobHS = NULL;
	 ID3D10Blob* pBlobDS = NULL;
	 ID3D10Blob* pBlobPS = NULL;

	 
	 ID3D10Blob* pBlobGS = NULL;
	 ID3D10Blob* pBlobGSFur = NULL;

	
	 if(CompileShaderFromFile( L"D3D11SimpleFx.hlsl", "SmoothVS",	   "vs_5_0", &pBlobVS )!=S_OK){return 1;}
	 if(CompileShaderFromFile( L"D3D11SimpleFx.hlsl", "SmoothHS",	   "hs_5_0", &pBlobHS )!=S_OK){return 1;}
	 if(CompileShaderFromFile( L"D3D11SimpleFx.hlsl", "SmoothDS",	   "ds_5_0", &pBlobDS )!=S_OK){return 1;}
	 if(CompileShaderFromFile( L"D3D11SimpleFx.hlsl", "SmoothGS",	   "gs_5_0", &pBlobGS )!=S_OK){return 1;}
	 if(CompileShaderFromFile( L"D3D11SimpleFx.hlsl", "FurGS",	       "gs_5_0", &pBlobGSFur )!=S_OK){return 1;}
	 if(CompileShaderFromFile( L"D3D11SimpleFx.hlsl", "SmoothPS",	   "ps_5_0", &pBlobPS )!=S_OK){return 1;}
	
	 
	 if(m_pDevice->CreateVertexShader( pBlobVS->GetBufferPointer(), pBlobVS->GetBufferSize(), NULL, &m_pVSGouraud )!=S_OK){return 1;}
	 if(m_pDevice->CreateHullShader(  pBlobHS->GetBufferPointer(), pBlobHS->GetBufferSize(), NULL, &m_pHSSmooth )!=S_OK){return 1;}
	 if(m_pDevice->CreateDomainShader(  pBlobDS->GetBufferPointer(), pBlobDS->GetBufferSize(), NULL, &m_pDSSmooth )!=S_OK){return 1;}
	 if(m_pDevice->CreateGeometryShader(  pBlobGS->GetBufferPointer(), pBlobGS->GetBufferSize(), NULL, &m_pGSSmooth )!=S_OK){return 1;}
	 if(m_pDevice->CreatePixelShader(  pBlobPS->GetBufferPointer(), pBlobPS->GetBufferSize(), NULL, &m_pPSGouraud )!=S_OK){return 1;}
	 if(m_pDevice->CreateGeometryShader(  pBlobGSFur->GetBufferPointer(), pBlobGSFur->GetBufferSize(), NULL, &m_pGSFur )!=S_OK){return 1;} 


	D3D11_INPUT_ELEMENT_DESC defaultLayout[] =
	{
		{"POSITION",0,DXGI_FORMAT_R32G32B32_FLOAT   ,0,							  0,D3D11_INPUT_PER_VERTEX_DATA,0},
	};

	if(m_pDevice->CreateInputLayout( defaultLayout, ARRAYSIZE( defaultLayout ), pBlobVS->GetBufferPointer(),
		pBlobVS->GetBufferSize(), &m_pVertexLayout )!=S_OK){return 1;}
	
	m_pDeviceContext->IASetInputLayout(m_pVertexLayout);

	if(CreateConstantsBuffer()!=S_OK){return 1;}



	D3DXMATRIX mtxWorld;
    D3DXMatrixIdentity(&mtxWorld);
	SetWorldMtx(mtxWorld);

	D3DXMATRIX mtxView;
	D3DXVECTOR3 vecEye(3.0f, 3.0f, 3.5f);
    D3DXVECTOR3 vecAt(0.0f, 0.0f, 0.0f);
    D3DXVECTOR3 vecUp(0.0f, 1.0f, 0.0f);
    D3DXMatrixLookAtLH(&mtxView, &vecEye, &vecAt, &vecUp);
	SetViewMtx(mtxView);

	

    D3DXMatrixPerspectiveFovLH(&m_mProj, (float)D3DX_PI * 0.5f, 
		m_rcScreenRect.right/(float)m_rcScreenRect.bottom, 0.1f, 50.0f);

  

	UpdateMatrices();

}