Exemple #1
0
void Heightfield::SetupPipeline()
{
    // load and compile the two shaders
	ID3D10Blob *VS, *PS;
    D3DX11CompileFromFile("shaders.hlsl", 0, 0, "VShader", "vs_5_0", 0, 0, 0, &VS, 0, 0);
    D3DX11CompileFromFile("shaders.hlsl", 0, 0, "PShader", "ps_5_0", 0, 0, 0, &PS, 0, 0);

    // encapsulate both shaders into shader objects
    mDev->CreateVertexShader(VS->GetBufferPointer(), VS->GetBufferSize(), NULL, &mVS);
    

    mDev->CreatePixelShader(PS->GetBufferPointer(), PS->GetBufferSize(), NULL, &mPS);
    
    
    // create the input layout object
    D3D11_INPUT_ELEMENT_DESC ied[] =
    {
        {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
        {"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
        {"TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
        {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 36, D3D11_INPUT_PER_VERTEX_DATA, 0}
    };

    mDev->CreateInputLayout(ied, 4, VS->GetBufferPointer(), VS->GetBufferSize(), &mLayout);
   
}
// this function loads and prepares the shaders
void FRenderD3D11::InitPipeline()
{
	// load and compile the two shaders
	ID3D10Blob *VertexShader, *PixelShader;
	D3DX11CompileFromFile(TEXT("..\\..\\Resource\\Shader\\shader.shader"), 0, 0, "VShader", "vs_4_0", 0, 0, 0, &VertexShader, 0, 0);
	D3DX11CompileFromFile(TEXT("..\\..\\Resource\\Shader\\shader.shader"), 0, 0, "PShader", "ps_4_0", 0, 0, 0, &PixelShader, 0, 0);

	// encapsulate both shaders into shader objects
	m_pDevice->CreateVertexShader(VertexShader->GetBufferPointer(), VertexShader->GetBufferSize(), NULL, &m_pVertexShader);
	m_pDevice->CreatePixelShader(PixelShader->GetBufferPointer(), PixelShader->GetBufferSize(), NULL, &m_pPixelShader);

	// set the shader objects
	m_pDeviceContext->VSSetShader(m_pVertexShader, 0, 0);
	m_pDeviceContext->PSSetShader(m_pPixelShader, 0, 0);

	// create the input layout object
	D3D11_INPUT_ELEMENT_DESC ied[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	};

	m_pDevice->CreateInputLayout(ied, _countof(ied), VertexShader->GetBufferPointer(), VertexShader->GetBufferSize(), &m_pLayout);
	m_pDeviceContext->IASetInputLayout(m_pLayout);
}
Exemple #3
0
void BlendApp::BuildShaders()
{
	HR(D3DX11CompileFromFile(L"Blend.hlsl", 0, 0, "VS", "vs_4_0", 0, 0, 0, &mVsBlob, 0, 0));
	HR(md3dDevice->CreateVertexShader(mVsBlob->GetBufferPointer(), mVsBlob->GetBufferSize(), 0, &mVertexShader));

	HR(D3DX11CompileFromFile(L"Blend.hlsl", 0, 0, "PS", "ps_4_0", 0, 0, 0, &mPsBlob, 0, 0));
	HR(md3dDevice->CreatePixelShader(mPsBlob->GetBufferPointer(), mPsBlob->GetBufferSize(), 0, &mPixelShader));
}
HRESULT CAniShader::Init()
{
	D3D11_INPUT_ELEMENT_DESC tInputLayout[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "BONES", 0, DXGI_FORMAT_R32G32B32A32_UINT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "BONES", 1, DXGI_FORMAT_R32G32B32A32_UINT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "WEIGHTS", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "WEIGHTS", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	};
	UINT iElementNum = ARRAYSIZE(tInputLayout);


	DWORD swFlag = D3DCOMPILE_ENABLE_STRICTNESS;

#if defined( DEBUG ) || defined( _DEBUG )
	swFlag |= D3D10_SHADER_DEBUG;
#endif

	ID3DBlob* pBlob = NULL, *pErrorBlob = NULL;
	ID3D11Device* pDevice = m_pDevice->GetDevice();

	if (SUCCEEDED(D3DX11CompileFromFile(L"../bin/Data/Fx/VertexAni.fx", NULL, NULL,
		"VS", "vs_4_0", swFlag, 0, NULL, &pBlob, &pErrorBlob, NULL)))
	{
		pDevice->CreateVertexShader(pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, &m_pVertexShader);
		pDevice->CreateInputLayout(
			tInputLayout, iElementNum, pBlob->GetBufferPointer(), pBlob->GetBufferSize(), &m_pVertexLayout);
	}
	else
	{
		if (pErrorBlob) { FAILED_CHECK_MSG(E_FAIL, L"셰이더 컴파일 실패"); }
		else { FAILED_CHECK_MSG(E_FAIL, L"셰이더 파일이 존재하지 않습니다."); }
		return E_FAIL;
	}

	pBlob = pErrorBlob = NULL;
	if (SUCCEEDED(D3DX11CompileFromFile(L"../bin/Data/Fx/VertexAni.fx", NULL, NULL,
		"PS", "ps_4_0", swFlag, 0, NULL, &pBlob, &pErrorBlob, NULL)))
	{
		pDevice->CreatePixelShader(pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, &m_pPixelShader);
	}
	else
	{
		if (pErrorBlob) { FAILED_CHECK_MSG(E_FAIL, L"셰이더 컴파일 실패"); }
		else { FAILED_CHECK_MSG(E_FAIL, L"셰이더 파일이 존재하지 않습니다."); }
		return E_FAIL;
	}
	::Safe_Release(pBlob);
	::Safe_Release(pErrorBlob);

	return S_OK;
}
Exemple #5
0
	HRESULT CompileShaderFromFile(const WCHAR* szFileName,
		LPCSTR szEntryPoint,
		LPCSTR szShaderModel,
		ID3DBlob** ppBlobOut)
	{
		HRESULT hr = S_OK;

		DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )	
		dwShaderFlags |= D3DCOMPILE_DEBUG;
#endif
		ID3DBlob* pErrorBlob;
		hr = D3DX11CompileFromFile(szFileName, NULL, NULL, szEntryPoint, szShaderModel,
			dwShaderFlags, 0, NULL, ppBlobOut, &pErrorBlob, NULL);
		if (FAILED(hr))
		{
			if (pErrorBlob != NULL)
				OutputDebugStringA((char*)pErrorBlob->GetBufferPointer());
			if (pErrorBlob) pErrorBlob->Release();
			return hr;
		}
		if (pErrorBlob) pErrorBlob->Release();

		return S_OK;
	}
HRESULT CGraphics::CompileShaderFromFile( WCHAR* szFileName, LPCSTR szEntryPoint, LPCSTR szShaderModel, ID3DBlob** ppBlobOut )
{
	HRESULT hr = S_OK;

		DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
	#if defined( DEBUG ) || defined( _DEBUG )
		// Sirve para que el shader proveea de información
		//para debugueo, pero sin afectar el rendimiento.
		dwShaderFlags |= D3DCOMPILE_DEBUG;
	#endif
		
		//Variable que se usa para obtener informacion
		//de errores y poder saber en dónde ocurrió
		//el error al compilar el shader
		ID3DBlob* pErrorBlob;

		//Compila el shader
		hr = D3DX11CompileFromFile( szFileName, NULL, NULL, szEntryPoint, szShaderModel, 
			dwShaderFlags, 0, NULL, ppBlobOut, &pErrorBlob, NULL );

		if( FAILED(hr) )
		{
			if( pErrorBlob != NULL )
				OutputDebugStringA( (char*)pErrorBlob->GetBufferPointer() );
			if( pErrorBlob ) pErrorBlob->Release();
			return hr;
		}
		if( pErrorBlob ) pErrorBlob->Release();

		return S_OK;
}
Exemple #7
0
bool Dx11DemoBase::CompileD3DShader( char * filePath , char * entry , char * shaderModle , ID3DBlob ** buffer )
{
	DWORD shaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;

#if defined( DEBUG )||defined( _DEBUG )
		shaderFlags |= D3DCOMPILE_DEBUG;
#endif

		ID3DBlob * errorBuffer = 0;
		HRESULT result;

		result = D3DX11CompileFromFile( filePath , 0 , 0 , entry , shaderModle , shaderFlags , 0 , 0 , buffer , &errorBuffer , 0 );
		
		if( FAILED( result ))
		{
			if( errorBuffer != 0 )
			{
				OutputDebugStringA( ( char * )errorBuffer ->GetBufferPointer() );
				errorBuffer ->Release();
			}

			return false;
		}

		if( errorBuffer !=0 )
		{
			errorBuffer ->Release();
		}

		return true;

}
bool DirectX11ComputeShader::Load()
{
	auto file = mResourceData->mFileSystem.getFilePath(mResourceData->mFileName);
	if(!file.second)
	{
		mResourceData->mConsole.threadSafePrintError(StringUtility::format("Failed to locate file %", mResourceData->mFileName));
		return true;
	}

	UINT shaderFlags = D3D10_SHADER_ENABLE_STRICTNESS | D3D10_SHADER_PACK_MATRIX_ROW_MAJOR;
#if defined(SCGE_DEBUG)
	shaderFlags |= D3D10_SHADER_DEBUG;
#endif

	std::wstring fileName;
	fileName.assign(file.first.begin(), file.first.end());

	ComPtr<ID3D10Blob> errorMessage;
	if(FAILED(D3DX11CompileFromFile(fileName.c_str(), mResourceData->mShaderDefines, nullptr, mResourceData->mFunctionName.c_str(), "cs_5_0", shaderFlags, 0, nullptr, mShaderBuffer.getModifiablePointer(), errorMessage.getModifiablePointer(), nullptr)))
	{
		mResourceData->mConsole.threadSafePrintError(StringUtility::format("Failed to compile Compute Shader : %, function : %", mResourceData->mFileName, mResourceData->mFunctionName));

		if(errorMessage)
			mResourceData->mConsole.threadSafePrintError(static_cast<const char *>(errorMessage->GetBufferPointer()));

		return true;
	}

	return mResourceData->mMultiThreadLoad && finaliseLoad();
}
Exemple #9
0
//--------------------------------------------------------------------------------------
// Helper for compiling shaders with D3DX11
//--------------------------------------------------------------------------------------
HRESULT DxAssist::CompileShaderFromFile( const char* fileName, const char* entryPoint, const char* shaderModel, ID3DBlob** blobOut )
{
    HRESULT hr = S_OK;

    DWORD shaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
    // Set the D3DCOMPILE_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.
    shaderFlags |= D3DCOMPILE_DEBUG;
#endif

    ID3DBlob* errorBlob = 0;
    hr = D3DX11CompileFromFile( fileName, NULL, NULL, entryPoint, shaderModel, 
        shaderFlags, 0, NULL, blobOut, &errorBlob, NULL );
    if( FAILED(hr) )
    {
        if( errorBlob != NULL )
            OutputDebugStringA( (char*)errorBlob->GetBufferPointer() );
        if( errorBlob ) errorBlob->Release();
        return hr;
    }
    if( errorBlob ) errorBlob->Release();

    return S_OK;
}
HRESULT PixelShaderClass::CompileShaderFromFile
(WCHAR* szFileName,
LPCSTR szEntryPoint,
LPCSTR szShaderModel,
ID3DBlob** ppBlobOut)
{
	HRESULT hr = S_OK;

	DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
	// Set the D3DCOMPILE_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 |= D3DCOMPILE_DEBUG;
#endif

	ID3DBlob* pErrorBlob;
	hr = D3DX11CompileFromFile(szFileName, NULL, NULL, szEntryPoint, szShaderModel,
		dwShaderFlags, 0, NULL, ppBlobOut, &pErrorBlob, NULL);
	if (FAILED(hr))
	{
		if (pErrorBlob != NULL)
			OutError(pErrorBlob);
		if (pErrorBlob) pErrorBlob->Release();

		return hr;
	}
	if (pErrorBlob) pErrorBlob->Release();
	return S_OK;
}
Exemple #11
0
void GSDevice11::CompileShader(const char* fn, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11ComputeShader** cs)
{
	HRESULT hr;

	vector<D3D11_SHADER_MACRO> m;

	PrepareShaderMacro(m, macro);

	CComPtr<ID3D11Blob> shader, error;

    hr = D3DX11CompileFromFile(fn, &m[0], NULL, entry, m_shader.cs.c_str(), 0, 0, NULL, &shader, &error, NULL);

	if(error)
	{
		printf("%s\n", (const char*)error->GetBufferPointer());
	}

	if(FAILED(hr))
	{
		throw GSDXRecoverableError();
	}

	hr = m_dev->CreateComputeShader((void*)shader->GetBufferPointer(), shader->GetBufferSize(),NULL, cs);

	if(FAILED(hr))
	{
		throw GSDXRecoverableError();
	}
}
Exemple #12
0
void loadShader(char* fileName, char* entryPoint, char* shaderModel, ID3DBlob** ppBlobOut) 
{
	DWORD shaderFlags = D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_DEBUG;
	ID3DBlob* pErrorBlob;

	g_hResult = D3DX11CompileFromFile(fileName, NULL, NULL, entryPoint, shaderModel, shaderFlags, 0, NULL, ppBlobOut, &pErrorBlob, NULL);

	if (FAILED(g_hResult)) {
		OutputDebugString("!!!!!!!! Failed to compile shader\n");
		OutputDebugString(fileName);
		OutputDebugString("\n");
		OutputDebugString(entryPoint);
		OutputDebugString("\n");
		OutputDebugString(shaderModel);
		OutputDebugString("\n");
		if (pErrorBlob != NULL) {
			OutputDebugString((char*) pErrorBlob->GetBufferPointer());
			pErrorBlob->Release();			
		}	
		ExitProcess(0);
	}
	if (pErrorBlob) {
		pErrorBlob->Release();
	}		
}
/*-------------------------------------------
	シェーダの作成
--------------------------------------------*/
HRESULT CreateShader(void)
{
	HRESULT hr;

	// コンピュート・シェーダのコードをコンパイル
	ID3DBlob* pBlobVS = NULL;
	hr = D3DX11CompileFromFile(
			L"..\\misc\\D3D11Sample19.sh",  // ファイル名
			NULL,          // マクロ定義(なし)
			NULL,          // インクルード・ファイル定義(なし)
			"CS",          // 「CS関数」がシェーダから実行される
			"cs_4_0",      // コンピュート・シェーダ
			g_flagCompile, // コンパイル・オプション
			0,             // エフェクトのコンパイル・オプション(なし)
			NULL,          // 直ぐにコンパイルしてから関数を抜ける。
			&pBlobVS,      // コンパイルされたバイト・コード
			NULL,          // エラーメッセージは不要
			NULL);         // 戻り値
	if (FAILED(hr))
		return DXTRACE_ERR(L"D3DX11CompileShaderFromFile", hr);

	// コンピュート・シェーダの作成
	hr = g_pD3DDevice->CreateComputeShader(
			pBlobVS->GetBufferPointer(),// バイト・コードへのポインタ
			pBlobVS->GetBufferSize(),	// バイト・コードの長さ
			NULL,
			&g_pComputeShader);			//
	SAFE_RELEASE(pBlobVS);  // バイト・コードを解放
	if (FAILED(hr))
		return DXTRACE_ERR(L"g_pD3DDevice->CreateComputeShader", hr);

	return hr;
}
bool ParticleManager::CompileShader(ID3DBlob** shader, string filename, string entry, string shaderModel)
{
	DWORD shaderFlags = 0;
	ID3DBlob* errorBuffer = 0;
	HRESULT hResult;

	//If debugging then compile shader in debug mode for error messages
#if defined(DEBUG) || defined(_DEBUG)
	shaderFlags |= D3DCOMPILE_DEBUG;
#endif

	//Compile the shader using the determined filename, entry point, shader model
	hResult = D3DX11CompileFromFile(filename.c_str(), 0, 0, entry.c_str(), shaderModel.c_str(),
		shaderFlags, 0, 0, shader, &errorBuffer, 0);

	//If the returned shader has errored then see what line in the .fx file
	if (errorBuffer != 0)
	{
		MessageBoxA(NULL, (char*)errorBuffer->GetBufferPointer(), 0, 0);
		errorBuffer->Release();
		errorBuffer = 0;
	}

	//If the compile failed completely then return a DXTRACE msg to link back to this function call
	if (FAILED(hResult))
	{
		DXTRACE_MSG(__FILE__, (DWORD)__LINE__, hResult, "D3DX11CompileFromFile", true);
		return false;
	}

	return true;
}
Exemple #15
0
void Shader::LoadShader(ID3D11Device * d3ddev)
{
	sShaderReady = false;
	BOOL b = true;
	if (FAILED(D3DX11CompileFromFile(ShaderFileAddr, 0, 0, "CONEVS", "vs_5_0", 0, 0, 0, &VertexShaderBlob, 0, 0))) b = false;
	if (FAILED(D3DX11CompileFromFile(ShaderFileAddr, 0, 0, "CONEPS", "ps_5_0", 0, 0, 0, &PixelShaderBlob, 0, 0))) b = false;
	if (!b)
	{
		Log("Failed to load shader");
	}
	else {
		sShaderReady = true;
		d3ddev->CreatePixelShader(PixelShaderBlob->GetBufferPointer(), PixelShaderBlob->GetBufferSize(), NULL, &PS);
		d3ddev->CreateVertexShader(VertexShaderBlob->GetBufferPointer(), VertexShaderBlob->GetBufferSize(), NULL, &VS);
	}
}
Exemple #16
0
//--------------------------------------------------------------------------------------
// Find and compile the specified shader
//--------------------------------------------------------------------------------------
HRESULT CompileShaderFromFile( WCHAR* szFileName, LPCSTR szEntryPoint, LPCSTR szShaderModel, ID3DBlob** ppBlobOut )
{
    HRESULT hr = S_OK;

    // find the file
    WCHAR str[MAX_PATH];
    V_RETURN( DXUTFindDXSDKMediaFileCch( str, MAX_PATH, szFileName ) );

    DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
    // Set the D3DCOMPILE_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 |= D3DCOMPILE_DEBUG;
#endif

    ID3DBlob* pErrorBlob;
    hr = D3DX11CompileFromFile( str, NULL, NULL, szEntryPoint, szShaderModel, 
        dwShaderFlags, 0, NULL, ppBlobOut, &pErrorBlob, NULL );
    if( FAILED(hr) )
    {
        if( pErrorBlob != NULL )
            OutputDebugStringA( (char*)pErrorBlob->GetBufferPointer() );
        SAFE_RELEASE( pErrorBlob );
        return hr;
    }
    SAFE_RELEASE( pErrorBlob );

    return S_OK;
}
Exemple #17
0
void BoxApp::BuildFX()
{
	DWORD shaderFlags = 0;
#if defined( DEBUG ) || defined( _DEBUG )
    shaderFlags |= D3D10_SHADER_DEBUG;
	shaderFlags |= D3D10_SHADER_SKIP_OPTIMIZATION;
#endif
 
	ID3D10Blob* compiledShader = 0;
	ID3D10Blob* compilationMsgs = 0;
	HRESULT hr = D3DX11CompileFromFile(L"FX/color.fx", 0, 0, 0, "fx_5_0", shaderFlags, 
		0, 0, &compiledShader, &compilationMsgs, 0);

	// compilationMsgs can store errors or warnings.
	if( compilationMsgs != 0 )
	{
		MessageBoxA(0, (char*)compilationMsgs->GetBufferPointer(), 0, 0);
		ReleaseCOM(compilationMsgs);
	}
	
	// Even if there are no compilationMsgs, check to make sure there were no other errors.
	if(FAILED(hr))
	{
		// DXTrace(__FILE__, (DWORD)__LINE__, hr, L"D3DX11CompileFromFile", true);
	}

	HR(D3DX11CreateEffectFromMemory(compiledShader->GetBufferPointer(), compiledShader->GetBufferSize(), 
		0, md3dDevice, &mFX));

	// Done with compiled shader.
	ReleaseCOM(compiledShader);

	mTech    = mFX->GetTechniqueByName("ColorTech");
	mfxWorldViewProj = mFX->GetVariableByName("gWorldViewProj")->AsMatrix();
}
Exemple #18
0
HRESULT SoftParticles::LoadEffectFromFile( ID3D11Device* pd3dDevice, WCHAR* szFileName, ID3DX11Effect** ppEffect )
{
	HRESULT hr = S_OK;

	// Compile the effect file
	ID3DBlob* pBlobFX = NULL;
	ID3DBlob* pErrorBlob = NULL;
	hr = D3DX11CompileFromFile(szFileName, NULL, NULL, NULL, "fx_5_0", NULL, NULL, NULL, &pBlobFX, &pErrorBlob, NULL);
	if (FAILED(hr))
	{
		char* err = (char*)pErrorBlob->GetBufferPointer();
		SAFE_RELEASE(pErrorBlob);
		return hr;
	}

	// Create the effect
	hr = D3DX11CreateEffectFromMemory(pBlobFX->GetBufferPointer(), pBlobFX->GetBufferSize(), 0, pd3dDevice, ppEffect);
	if( FAILED(hr) )
	{
		OutputDebugString( TEXT("Failed to load effect file.") );
		return hr;
	}

	SAFE_RELEASE(pBlobFX);
	SAFE_RELEASE(pErrorBlob);

	return S_OK;
}
//--------------------------------------------------------------------------------------
// Helper for compiling shaders with D3DX11
//--------------------------------------------------------------------------------------
static HRESULT CompileShaderFromFile( const char* szFileName, LPCSTR szEntryPoint, LPCSTR szShaderModel, ID3DBlob** ppBlobOut )
{
    HRESULT hr = S_OK;

#ifndef D3DCOMPILE_ENABLE_STRICTNESS
// allow the plug-in to compile against the Maya 2011 default DXSDK version (August 2009)
#define D3DCOMPILE_ENABLE_STRICTNESS D3D10_SHADER_ENABLE_STRICTNESS
#define D3DCOMPILE_DEBUG D3D10_SHADER_DEBUG
#endif
	
    DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
    // Set the D3DCOMPILE_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 |= D3DCOMPILE_DEBUG;
#endif

    ID3DBlob* pErrorBlob;
    hr = D3DX11CompileFromFile( szFileName, NULL, NULL, szEntryPoint, szShaderModel, 
        dwShaderFlags, 0, NULL, ppBlobOut, &pErrorBlob, NULL );
    if( FAILED(hr) )
    {
        if( pErrorBlob != NULL )
            MGlobal::displayInfo( (char*)pErrorBlob->GetBufferPointer() );
        if( pErrorBlob ) pErrorBlob->Release();
        return hr;
    }
    if( pErrorBlob ) pErrorBlob->Release();

    return S_OK;
}
Exemple #20
0
	HRESULT CompileShaderFromFile( TCHAR* szFileName, LPCSTR szEntryPoint, LPCSTR szShaderModel, ID3DBlob** ppBlobOut, const D3D_SHADER_MACRO* pDefines )
	{
		HRESULT hr = S_OK;

		DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
		#if defined( DEBUG ) || defined( _DEBUG )
			// Set the D3DCOMPILE_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 |= D3DCOMPILE_DEBUG;
		#endif

		// compile the shader
		ID3DBlob* pErrorBlob = NULL;
		hr = D3DX11CompileFromFile( szFileName, pDefines, NULL, szEntryPoint, szShaderModel, dwShaderFlags, NULL, NULL, ppBlobOut, &pErrorBlob, NULL );
		if( FAILED(hr) )
		{
			if( pErrorBlob != NULL )
				OutputDebugStringA( ( char* )pErrorBlob->GetBufferPointer() );
			SAFE_DX_RELEASE( pErrorBlob );
			return hr;
		}
		SAFE_DX_RELEASE( pErrorBlob );

		return S_OK;   
	}
HRESULT CompileShaderFromFile(LPCTSTR str, 
                              const D3D_SHADER_MACRO* pDefines, 
                              LPCSTR functionName,
							  LPCSTR profile, 
                              ID3DBlob **ppBlobOut)
{
    DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#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
	HRESULT hr;
	do
	{
		CComPtr<ID3DBlob> errors;
		hr = D3DX11CompileFromFile(str, pDefines, NULL, functionName, profile, dwShaderFlags, 0, NULL, ppBlobOut, &errors, NULL);
		if( errors )
		{
			OutputDebugStringA((char*) errors->GetBufferPointer());
			if( FAILED(hr) && 
				IDRETRY != MessageBoxA(NULL, (char*) errors->GetBufferPointer(), "FX Error", MB_ICONERROR|MB_ABORTRETRYIGNORE) )
			{
				break;
			}
		}
	} while( FAILED(hr) );
	return hr;
}
ID3DX11Effect* Assignment5::InitialiseShader(const std::wstring& a_FilePath)
{
    DWORD shaderFlags = 0;
#if defined( DEBUG ) || defined( _DEBUG )
    shaderFlags |= D3D10_SHADER_DEBUG;
    shaderFlags |= D3D10_SHADER_SKIP_OPTIMIZATION;
#endif

    ID3D10Blob* compiledShader = 0;
    ID3D10Blob* compilationMsgs = 0;
    HRESULT hr = D3DX11CompileFromFile(std::wstring(L"FX/" + a_FilePath).c_str(),
        0, 0, 0, "fx_5_0", shaderFlags,
        0, 0, &compiledShader, &compilationMsgs, 0);

    // compilationMsgs can store errors or warnings.
    if(compilationMsgs != 0)
    {
        MessageBoxA(0, (char*)compilationMsgs->GetBufferPointer(), 0, 0);
        ReleaseCOM(compilationMsgs);
    }

    // Even if there are no compilationMsgs, check to make sure there were no other errors.
    if(FAILED(hr))
    {
        DXTrace(__FILE__, (DWORD)__LINE__, hr, L"D3DX11CompileFromFile", true);
    }
    ID3DX11Effect* shader;
    HR(D3DX11CreateEffectFromMemory(compiledShader->GetBufferPointer(), compiledShader->GetBufferSize(),
        0, md3dDevice, &shader));

    // Done with compiled shader.
    ReleaseCOM(compiledShader);
    return shader;
}
peBool proShaderDomain::Create(const peChar *shaderName)
{

	if(g_pAppDef->m_featureLevel < D3D_FEATURE_LEVEL_11_0)
	{
		return FALSE;
	}

	peChar filePath[PRO_MAX_PATH];
	ID3D10Blob* errorMessage;
	proUtil::ConstructFilePath(&filePath[0], PRO_MAX_PATH, shaderName);

	HRESULT result = D3DX11CompileFromFile(filePath, NULL, NULL, "peDomainShader", &g_pAppDef->m_aDSVer[0], D3D10_SHADER_ENABLE_STRICTNESS,
		0, NULL, &m_pDSBuffer, &errorMessage, NULL);

	if(FAILED(result))
	{
		HandleShaderError(errorMessage, filePath);
		return FALSE;
	}

	if(!m_pDSBuffer)
	{
		return FALSE;
	}

	result = g_pAppDef->m_pDevice->CreateDomainShader(m_pDSBuffer->GetBufferPointer(), m_pDSBuffer->GetBufferSize(), NULL, &m_pDShader);
	if(FAILED(result))
	{
		proDebug::Log(proDebug::kLog_Render, proDebug::kDefcon_2, "proShaderDomain::Create(%s) - Failed creating Domain Shader", shaderName);
		return FALSE;
	}
	return TRUE;
}
HRESULT c_post_effect::compile_shader(const std::wstring& fx_file_name)
{
    HRESULT hr;

    d3d11_blob_ptr effect_blob, error_blob;
    V(D3DX11CompileFromFile(fx_file_name.c_str(),           // effect file name
        NULL,                           // defines
        NULL,                           // includes
        NULL,                           // function name
        "fx_5_0",                       // profile
        D3D10_SHADER_DEBUG,             // compile flag
        NULL,                           // compile flag
        NULL,                           // thread pump
        &effect_blob,                   // effect buffer
        &error_blob,                    // error buffer
        NULL));

    if (m_effect)
        m_effect = NULL;
    V(D3DX11CreateEffectFromMemory(effect_blob->GetBufferPointer(),         // effect buffer pointer
        effect_blob->GetBufferSize(),
        0,
        m_render_sys_context->get_d3d11_device(),
        &m_effect));

    return S_OK;
}
Exemple #25
0
bool BlurShaderH::Initalize(ID3D11Device* pd3dDevice)
{
	blurSizeH = (1.0f/400);

	ID3D10Blob*	pBlob = NULL;
	ID3D10Blob*	pErrorBlob = NULL;

	DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;

	#if defined( DEBUG ) || defined( _DEBUG )
	// Il settaggio di questo flag permette di eseguire il debug diretto dello shader, senza
	// impattare in modo marcato sulle performance.
	dwShaderFlags |= D3DCOMPILE_DEBUG;
	#endif
	// Creazione effetto in g_pEffect, caricandolo dal file fx
	HRESULT hr = D3DX11CompileFromFile(L"Shaders/blur_h.fx", NULL, NULL,NULL, "fx_5_0", dwShaderFlags, 0,
		NULL, &pBlob, &pErrorBlob, NULL);


    if( FAILED( hr ) )
    {
		MessageBox(NULL, L"Problema nel caricamento di blur_h.fx.", L"Error", MB_OK );

		if (pErrorBlob)
		{
			MessageBoxA(0, (char*)pErrorBlob->GetBufferPointer(), 0, 0);
		}
		return false;
    }

	D3DX11CreateEffectFromMemory(pBlob->GetBufferPointer(), pBlob->GetBufferSize(), NULL, pd3dDevice ,&m_Effect);

	// Trova la tecnica definita nel .fx - nota come un effetto.fx può avere diverse tecniche.
	m_Technique = m_Effect->GetTechniqueByName( "Blur_h" );


	//Definiamo gli input da agganciare (bind) al vertex shader
	//In questo caso passeremo solo le informazioni sulla posizione con un vertex buffer
	D3D11_INPUT_ELEMENT_DESC layout[] =
	{
		{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
		{"TEXCOORD",   0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
	};

	UINT numElements = sizeof( layout ) / sizeof( layout[0] );

	// Creiamo e configuriamo il layout di input
	D3DX11_PASS_DESC PassDesc;
	m_Technique->GetPassByIndex( 0 )->GetDesc( &PassDesc );
	hr = pd3dDevice->CreateInputLayout(layout, numElements, PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, &m_VertexLayout );
	if( FAILED( hr ) )
		return false;

	m_Effect->GetVariableByName("blurSizeH")->AsScalar()->SetFloat(blurSizeH);

	return true;
}
Exemple #26
0
Effect::Effect(ID3D11Device * pDevice, const std::wstring &fileName)
	:m_pShader(nullptr)
{

#if DEBUG_SHADER
	DWORD shaderFlags = 0;
	//这些一般在shader编译器中设置的选项
#if defined(DEBUG) || defined(_DEBUG)
	shaderFlags |= D3D10_SHADER_DEBUG;
	shaderFlags |= D3D10_SHADER_SKIP_OPTIMIZATION;
#endif


	ID3D10Blob * compiledShader = nullptr;
	ID3D10Blob * compilationMsgs = nullptr;

	HRESULT hr = D3DX11CompileFromFile(fileName.c_str(), nullptr, nullptr, nullptr, "fx_5_0", shaderFlags,
		0, nullptr, &compiledShader, &compilationMsgs, nullptr);

	//这些信息是编译错误信息
	if (compilationMsgs != 0)
	{
		MessageBoxA(0, (char *)compilationMsgs->GetBufferPointer(), 0, 0);
		ReleaseCOM(compilationMsgs);
	}

	//Even if there are no compliation msgs,check to make sure there no other errors.
	if (FAILED(hr))
	{
		DXTrace(__FILE__, (DWORD)__LINE__, hr, L"D3DX11CompileFromFile", true);
	}

	HR(D3DX11CreateEffectFromMemory(compiledShader->GetBufferPointer(),
		compiledShader->GetBufferSize(), 0, pDevice, &m_pShader));

	//Done with compiled shader
	ReleaseCOM(compiledShader);

	/************************************************************************/

#else
	std::ifstream fin(fileName, std::ios::binary);

	fin.seekg(0, std::ios_base::end);//定位至文件末尾,以求长度
	int size = (int)fin.tellg();
	fin.seekg(0, std::ios_base::beg);
	std::vector<char> compiledShaderFile(size);

	fin.read(&compiledShaderFile[0], size);
	fin.close();

	HR(D3DX11CreateEffectFromMemory(&compiledShaderFile[0],
		size, 0, pDevice, &m_pShader));


#endif
}
void RenderInterfaceDx11::initEffect()
{
	//Debug
	DWORD shaderFlags = D3D10_SHADER_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
	shaderFlags |= D3D10_SHADER_DEBUG;
	shaderFlags |= D3D10_SHADER_SKIP_OPTIMIZATION;
#endif

	//Send blob to gather debug data
	ID3DBlob*	pBlobEffect = NULL;
	ID3DBlob*	pBlobErrors = NULL;
	HRESULT hr = 0;

	hr = D3DX11CompileFromFile(
		L"../shaders/effect.fx",
		NULL,
		NULL,
		"",
		"fx_5_0",
		shaderFlags,
		NULL,
		NULL,
		&pBlobEffect,
		&pBlobErrors,
		NULL
		);


	// If compilation of the .fx-file fails. Present compilation errors to the user
	char* l_pError = NULL;
	if( FAILED(hr) )
	{
		char msg[20000];
		strcpy_s(msg, sizeof(msg), (char*)pBlobErrors->GetBufferPointer());
		OutputDebugStringA(msg); // A as in ASCII. dx11 conversion
		MessageBoxA(GetDesktopWindow(), msg, "Effect compilation error", MB_OK | MB_ICONERROR); // A as in ASCII. dx11 conversion
		return;
	}

	if(FAILED(hr = D3DX11CreateEffectFromMemory(
		pBlobEffect->GetBufferPointer(),
		pBlobEffect->GetBufferSize(),
		shaderFlags,
		m_device,
		&m_effect
		)))
	{
		MessageBoxA(0, "Cannot create effect from memory.", "D3DX11CreateEffectFromMemory error", MB_OK | MB_ICONERROR); // A as in ASCII. dx11 conversion
		return;
	}

	//hr = D3DX11CompileFromFile(L"../shaders/effect.fx", 0, 0, "fx_4_0", shaderFlags, 0,
	//	m_device, 0, 0, &m_effect, &compilationErrors, 0);
	// the FAILED() macro modifies the hr, this copy is used with the HR() macro
}
void DX11PixelShader::Initialize(const string& shaderFileName,
    ID3D11Device* pDevice)
{
    //Force strict compile, which might not allow for legacy syntax.
    UINT compileFlags = D3DCOMPILE_ENABLE_STRICTNESS;

#ifdef POLY_DEBUG_SHADERS
    //Insert debug file/line/type/symbol information into the output code.
    compileFlags |= D3DCOMPILE_DEBUG;

    //Treat all warnings as errors.
    compileFlags |= D3DCOMPILE_WARNINGS_ARE_ERRORS;
#endif

    //Interfaces used to return arbitrary length data.
    ID3D10Blob* pErrorMessage;
    ID3D10Blob* pPixelShaderBlob;

    //Load and compile the pixel shader.
    HRESULT result = D3DX11CompileFromFile(
        (std::wstring(shaderFileName.begin(),shaderFileName.end())).c_str(),
        nullptr,nullptr,"Main","ps_5_0",compileFlags,0,nullptr,
        &pPixelShaderBlob,&pErrorMessage,nullptr);

    if (FAILED(result))
    {
        if (pErrorMessage != nullptr)
        {
            //Log the shader compilation errors.
            string compileErrors((char*)(pErrorMessage->GetBufferPointer()));

            pErrorMessage->Release();

            throw Exception("Direct3D 11 init failed (CompilePixelShader): " +
                compileErrors + "." + DEBUG_INFO,result);
        }
        else
        {
            throw Exception("Direct3D 11 init failed (CompilePixelShader)." +
                DEBUG_INFO,result);
        }
    }

    //Encapsulate the pixel shader into a shader object.
    result = pDevice->CreatePixelShader(pPixelShaderBlob->GetBufferPointer(),
        pPixelShaderBlob->GetBufferSize(),nullptr,&mpPixelShader);

    if (FAILED(result))
    {
        throw Exception("Direct3D 11 init failed (CreatePixelShader)." +
            DEBUG_INFO,result);
    }

    //This object is no longer needed.
    pPixelShaderBlob->Release();
}
// initialize the Direct3D pipeline
void init_pipeline(void)
{
   // load and compile the two shaders
   ID3D10Blob *vertex_shader_blob_ptr;
   ID3D10Blob *pixel_shader_blob_ptr;
   ID3D10Blob *VS, *PS;
   D3DX11CompileFromFile(L"shaders.shader", 0, 0, "VShader", "vs_4_0", 0, 0, 0, &vertex_shader_blob_ptr, 0, 0);
   D3DX11CompileFromFile(L"shaders.shader", 0, 0, "PShader", "ps_4_0", 0, 0, 0, &pixel_shader_blob_ptr, 0, 0);
   //D3DX11CompileFromFile(L"shaders.shader", 0, 0, "VShader", "vs_4_0", 0, 0, 0, &vertex_shader_blob_ptr, 0, 0);
   //D3DX11CompileFromFile(L"shaders.shader", 0, 0, "PShader", "ps_4_0", 0, 0, 0, &pixel_shader_blob_ptr, 0, 0);

   // encapsulate bother shader blobs into their own shader objects
   g_dev_ptr->CreateVertexShader(vertex_shader_blob_ptr->GetBufferPointer(), vertex_shader_blob_ptr->GetBufferSize(), NULL, &g_vertex_shader_ptr);
   g_dev_ptr->CreatePixelShader(pixel_shader_blob_ptr->GetBufferPointer(), pixel_shader_blob_ptr->GetBufferSize(), NULL, &g_pixel_shader_ptr);

   // register the shader objects with the graphical context
   g_dev_context_ptr->VSSetShader(g_vertex_shader_ptr, 0, 0);
   g_dev_context_ptr->PSSetShader(g_pixel_shader_ptr, 0, 0);


   // now for the actual vertex data

   // describe how the data is layed out in the vertex buffer
   // - Create input element descriptions for each unique item in my custom vertex.  In this case, I have a position, and 3 floats later I have a color.
   // - Create an input layout object and assign it to the global input layout pointer.
   // - Register the input layout object with the context so that it can make sense of the data in the vertex buffer.
   D3D11_INPUT_ELEMENT_DESC input_elem_desc_arr[] =
   {
      // the position will use 3 32bit floats
      { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },

      // the color will use 4 32bit floats
      { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA },
   };
   g_dev_ptr->CreateInputLayout(
      input_elem_desc_arr,
      sizeof(input_elem_desc_arr) / sizeof(D3D11_INPUT_ELEMENT_DESC),
      vertex_shader_blob_ptr->GetBufferPointer(),
      vertex_shader_blob_ptr->GetBufferSize(),
      &g_input_layout_ptr);
   g_dev_context_ptr->IASetInputLayout(g_input_layout_ptr);
}
Exemple #30
0
// this function loads and prepares the shaders
void InitPipeline()
{
    // load and compile the two shaders
    ID3D10Blob *VS, *PS;
    D3DX11CompileFromFile( L"shaders.hlsl", 0, 0, "VShader", "vs_4_1", 0, 0, 0, &VS, 0, 0 );
    D3DX11CompileFromFile( L"shaders.hlsl", 0, 0, "PShader", "ps_4_1", 0, 0, 0, &PS, 0, 0 );

    // encapsulate both shaders into shader objects
    dev->CreateVertexShader( VS->GetBufferPointer(), VS->GetBufferSize(), NULL, &pVS );
    dev->CreatePixelShader( PS->GetBufferPointer(), PS->GetBufferSize(), NULL, &pPS );

    // set the shader objects
    devcon->VSSetShader(pVS, 0, 0);
    devcon->PSSetShader(pPS, 0, 0);

		// create the input layout object
		D3D11_INPUT_ELEMENT_DESC ied[] =
		{
			{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
			{"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
    
			// Data from the instance buffer
			{ "INSTANCEPOS", 0, DXGI_FORMAT_R32G32B32_FLOAT,    1, 0, D3D11_INPUT_PER_INSTANCE_DATA, 1},
			{ "INSTANCECOLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT,    1, 12, D3D11_INPUT_PER_INSTANCE_DATA, 1},
			{ "INSTANCEPOS", 0, DXGI_FORMAT_R32G32B32_FLOAT, 1, 0, D3D11_INPUT_PER_INSTANCE_DATA }
		};

    dev->CreateInputLayout( ied, 2, VS->GetBufferPointer(), VS->GetBufferSize(), &pLayout );
    devcon->IASetInputLayout( pLayout );

    D3D11_BUFFER_DESC bd;
    ZeroMemory( &bd, sizeof( bd ));

    bd.Usage = D3D11_USAGE_DEFAULT;
    bd.ByteWidth = 64;
    bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;

    dev->CreateBuffer( &bd, NULL, &pCBuffer );
    devcon->VSSetConstantBuffers( 0, 1, &pCBuffer );

		
}