コード例 #1
0
ファイル: BoxDemo.cpp プロジェクト: MaybeS/DirectX
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();
}
コード例 #2
0
ファイル: Material.cpp プロジェクト: Manaluusua/Dx11Sandbox
bool Material::bind(RenderContext* context)
{

    if( this == context->getBoundMaterial() )
    {
        return false;
    }

    ID3DX11Effect* effect = m_shader->getEffect();



    context->getImmediateContext()->IASetInputLayout( m_layout );


    for(std::map<string, ResourceID>::iterator iter = m_textureRefs.begin(); iter!=m_textureRefs.end(); ++iter)
    {

        ID3DX11EffectVariable* var = effect->GetVariableByName(iter->first.c_str());
        if(var->IsValid())
        {
            ID3DX11EffectShaderResourceVariable* texResource = var->AsShaderResource();
            Texture* tex = TextureManager::singleton()->getTexture(iter->second);
            if(tex)
            {
                texResource->SetResource(tex->getShaderResourceView());
            }
            else {
                texResource->SetResource(0);
            }
        }
    }

    return true;
}
コード例 #3
0
void InitDirect3DApp::BuildEffect()
{
	DWORD shaderFlags = 0;

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

	ID3D10Blob* compiledShader = 0;
	ID3D10Blob* compilationErrors = 0;

	HRESULT hr = D3DX11CompileFromFile(L"FX/color.fx",		// Name of the .fx file
									   0,					// Advanced option
									   0,					// Advanced option
									   0,					// Using the effects framework so set it to null
									   "fx_5_0",			// Shader version we are using
									   shaderFlags,			// Flags to specify how the code should be compiled
									   0,					// Advanced effect compilation options
									   0,					// Advanced option to compile the shader asynchronously
									   &compiledShader,		// Pointer to the compiled shader
									   &compilationErrors,	// Pointer to compilation errors if there are any
									   0);                  // Return error code for compiling asynchronously
	
	// Check for any compilation errors
	if (compilationErrors != 0)
	{
		MessageBoxA(0, (char*)compilationErrors->GetBufferPointer(), 0, 0);
		ReleaseCOM(compilationErrors);
	}

	// Check for any other errors with compiling the shader
	if (FAILED(hr))
	{
		DXTrace(__FILE__, (DWORD)__LINE__, hr, L"D3DX11CompileFromFile", true);
	}

	// Shader compiled successfully, time to create the effect
	HR(D3DX11CreateEffectFromMemory(compiledShader->GetBufferPointer(), compiledShader->GetBufferSize(), 0, md3dDevice, &effect));

	ReleaseCOM(compiledShader);

	// Get the technique location from the effect
	technique = effect->GetTechniqueByName("ColorTechnique");

	// Get the World View Proj Matrix location from the effect
	worldViewProj = effect->GetVariableByName("WorldViewProj")->AsMatrix();
}
コード例 #4
0
ファイル: HillsDemo.cpp プロジェクト: Dr-Wol/JWAGP
void HillsApp::BuildFX()
{
	std::ifstream fin("fx/color.fxo", 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> compiledShader(size);

	fin.read(&compiledShader[0], size);
	fin.close();
	
	HR(D3DX11CreateEffectFromMemory(&compiledShader[0], size, 
		0, md3dDevice, &mFX));

	mTech    = mFX->GetTechniqueByName("ColorTech");
	mfxWorldViewProj = mFX->GetVariableByName("gWorldViewProj")->AsMatrix();
}
コード例 #5
0
ファイル: WavesDemo.cpp プロジェクト: wjingzhe/DX11
void WavesApp::BuildFX()
{
#define DEBUG_SHADER 1
#if DEBUG_SHADER

	/************************************************************************/
	/*    以下的编译处理已经被 项目为color.fx 添加的预编译处理代替                                                                  */


	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(L"FX/color.fx", 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 compliationmsgs,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, m_pD3dDevice, &m_pShader));

	//Done with compiled shader
	ReleaseCOM(compiledShader);

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

#else
	std::ifstream fin("FX/color.fxo", 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, m_pD3dDevice, &m_pShader));


#endif

	

	



	

	m_pShaderTech = m_pShader->GetTechniqueByName("ColorTech");//和shader文件对应

	m_pShaderMVP = m_pShader->GetVariableByName("gWorldViewProj")->AsMatrix();
}
コード例 #6
0
ファイル: StandardShader.cpp プロジェクト: krustur/eengine2
	void StandardShader::BuildFX()
	{
		DWORD shaderFlags = 0;
#if defined( DEBUG ) || defined( _DEBUG )
		shaderFlags |= D3D10_SHADER_DEBUG;
		shaderFlags |= D3D10_SHADER_SKIP_OPTIMIZATION;
#endif

		ID3D10Blob* compiledShader = 0;
		ID3D10Blob* compilationMessages = 0;
		HRESULT hresult = D3DCompileFromFile(L"../EEngine/HLSL/StandardShader.fx", 0, 0, 0, "fx_5_0", shaderFlags, 0, &compiledShader, &compilationMessages);

		if (compilationMessages != 0)
		{
			_logger.LogLine((char *)compilationMessages->GetBufferPointer());

			compilationMessages->Release();
			compilationMessages = 0;
		}

		if (FAILED(hresult))
		{
			_logger.LogHResult(hresult);
		}

		ID3DX11Effect* effect;
		hresult = (D3DX11CreateEffectFromMemory(compiledShader->GetBufferPointer(), compiledShader->GetBufferSize(), 0, _renderer.GetD3dDevice(), &effect));
		if (FAILED(hresult))
		{
			_logger.LogHResult(hresult);
		}

		if (compiledShader)
		{
			compiledShader->Release();
			compiledShader = 0;
		}

		ID3DX11EffectTechnique* effectTechnique = effect->GetTechniqueByName("StandardShaderTechnique");
		ID3DX11EffectMatrixVariable* effectWorldViewProj = effect->GetVariableByName("g_WorldViewProj")->AsMatrix();

		D3D11_INPUT_ELEMENT_DESC inputElementDescriptions[] =
		{
			{ "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 }
		};

		D3DX11_PASS_DESC effectPassDescription;
		effectTechnique->GetPassByIndex(0)->GetDesc(&effectPassDescription);

		ID3D11InputLayout* inputLayout;

		hresult = (_renderer.GetD3dDevice()->CreateInputLayout(inputElementDescriptions, 2, effectPassDescription.pIAInputSignature, effectPassDescription.IAInputSignatureSize, &inputLayout));
		if (FAILED(hresult))
		{
			_logger.LogHResult(hresult);
		}

		_effect = effect;
		_effectTechnique = effectTechnique;
		_effectWorldViewProj = effectWorldViewProj;
		_inputLayout = inputLayout;
	}
コード例 #7
0
ファイル: main.cpp プロジェクト: unixunited/Direct3D11
void App::buildFX( void )
{
    DWORD shaderFlags = 0;
#if defined( DEBUG ) || defined ( _DEBUG )   
    shaderFlags |= D3DCOMPILE_DEBUG;
    shaderFlags |= D3DCOMPILE_SKIP_OPTIMIZATION;
#endif

    ID3DBlob* compiledShader = nullptr;
    ID3DBlob* compilationMsgs = nullptr;
    /*HRESULT hr = D3DX11CompileEffectFromFile( L"FX/color.fx",
                                        nullptr,
                                        D3D_COMPILE_STANDARD_FILE_INCLUDE,
                                        shaderFlags,
                                        0,
                                        mD3DDevice,
                                        &mFX,
                                        &compilationMsgs );*/
    HRESULT hr = D3DCompileFromFile( L"FX/color.fx",
                                     nullptr,
                                     D3D_COMPILE_STANDARD_FILE_INCLUDE,
                                     nullptr,
                                     "fx_5_0",
                                     shaderFlags,
                                     0,
                                     &compiledShader,
                                     &compilationMsgs );

    if ( compilationMsgs != nullptr ) {
        // Filter out warning about deprecated compiler since effects are being used.
        if ( std::strstr( static_cast<const char*>( compilationMsgs->GetBufferPointer() ), 
                          "X4717" ) == 0 ) {
            MessageBoxA( 0,
                         static_cast<char*>( compilationMsgs->GetBufferPointer() ),
                         nullptr,
                         0 );
        }
        ReleaseCOM( compilationMsgs );
    }

    // Check for other errors.
    if ( FAILED( hr ) ) {
        DXTrace( __FILEW__,
        static_cast<DWORD>( __LINE__ ),
        hr,
        L"D3DX11CompileFromFile",
        true );
    }

    hr = D3DX11CreateEffectFromMemory( compiledShader->GetBufferPointer(),
                                      compiledShader->GetBufferSize(),
                                      0,
                                      mD3DDevice,
                                      &mFX );
    if ( FAILED( hr ) ) {
        DXTrace( __FILEW__,
                 static_cast<DWORD>( __LINE__ ),
                 hr,
                 L"D3DX11CreateEffectFromMemory",
                 true );
    }

    ReleaseCOM( compiledShader );

    mTech = mFX->GetTechniqueByName( "ColorTech" );
    // Store a pointer to constant buffer gWorldViewProj.
    mfxWorldViewProj = mFX->GetVariableByName( "gWorldViewProj" )->AsMatrix();
}