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; }
ID3D10Effect* CreateFX(ID3D10Device* device, std::wstring filename) { DWORD shaderFlags = D3D10_SHADER_ENABLE_STRICTNESS; #if defined( DEBUG ) || defined( _DEBUG ) shaderFlags |= D3D10_SHADER_DEBUG; shaderFlags |= D3D10_SHADER_SKIP_OPTIMIZATION; #endif ID3D10Blob* compilationErrors = 0; HRESULT hr = 0; ID3D10Effect* fx = 0; hr = D3DX10CreateEffectFromFile(filename.c_str(), 0, 0, "fx_4_0", shaderFlags, 0, device, 0, 0, &fx, &compilationErrors, 0); if(FAILED(hr)) { if( compilationErrors ) { MessageBoxA(0, (char*)compilationErrors->GetBufferPointer(), 0, 0); ReleaseCOM(compilationErrors); } DXTrace(__FILE__, (DWORD)__LINE__, hr, filename.c_str(), true); } return fx; }
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(); }
void C_DefaultShader::buildFX() { // Create the Default shader DWORD shaderFlags = D3D10_SHADER_ENABLE_STRICTNESS; #if defined( DEBUG ) || defined( _DEBUG ) shaderFlags |= D3D10_SHADER_DEBUG; shaderFlags |= D3D10_SHADER_SKIP_OPTIMIZATION; #endif ID3D10Blob* compilationErrors = 0; HRESULT hr = 0; hr = D3DX10CreateEffectFromFile(DEFAULT_SHADER_FILE, 0, 0, "fx_4_0", shaderFlags, 0, d_pDevice, 0, 0, &d_pFX, &compilationErrors, 0); // TODO - make the effect file in the header file as a string and use D3DX10CreateEffectFromMemory() if(FAILED(hr)) { if( compilationErrors ) { MessageBoxA(0, (char*)compilationErrors->GetBufferPointer(), 0, 0); ReleaseCOM(compilationErrors); } DXTrace(__FILE__, (DWORD)__LINE__, hr, "D3DX10CreateEffectFromFile", true); } d_pTextureTech = d_pFX->GetTechniqueByName("TextureDefaultTech"); d_pNoTextureTech = d_pFX->GetTechniqueByName("NoTextureDefaultTech"); d_fxViewProjVar = d_pFX->GetVariableByName("gVP")->AsMatrix(); d_fxWorld = d_pFX->GetVariableByName("gWorld")->AsMatrix(); d_fxEyePosVar = d_pFX->GetVariableByName("gEyePosW")->AsVector(); d_fxTextureParams = d_pFX->GetVariableByName("gTextureParams")->AsVector(); d_fxLightParams = d_pFX->GetVariableByName("gLightParams")->AsVector(); d_fxTexture = d_pFX->GetVariableByName("gTexture")->AsShaderResource(); d_fxLightVar = d_pFX->GetVariableByName("gLights"); }
void Pyramid::buildFX() { DWORD shaderFlags = D3D10_SHADER_ENABLE_STRICTNESS; #if defined( DEBUG ) || defined( _DEBUG ) shaderFlags |= D3D10_SHADER_DEBUG; shaderFlags |= D3D10_SHADER_SKIP_OPTIMIZATION; #endif ID3D10Blob* compilationErrors = 0; HRESULT hr = 0; hr = D3DX10CreateEffectFromFile(L"object.fx", 0, 0, "fx_4_0", shaderFlags, 0, md3dDevice, 0, 0, &mFX, &compilationErrors, 0); if (FAILED(hr)) { if (compilationErrors) { MessageBoxA(0, (char*)compilationErrors->GetBufferPointer(), 0, 0); ReleaseCOM(compilationErrors); } DXTrace(__FILE__, (DWORD)__LINE__, hr, L"D3DX10CreateEffectFromFile", true); } mTechnique = mFX->GetTechniqueByName("ObjectTech"); mfxWVPVar = mFX->GetVariableByName("gWVP")->AsMatrix(); //D3D10_RASTERIZER_DESC cmdesc; //ZeroMemory(&cmdesc, sizeof(D3D10_RASTERIZER_DESC)); //cmdesc.CullMode = D3D10_CULL_NONE; //cmdesc.FillMode = D3D10_FILL_SOLID; //hr = md3dDevice->CreateRasterizerState(&cmdesc, &RSCullNone); }
void ColoredCubeApp::buildFX() { DWORD shaderFlags = D3D10_SHADER_ENABLE_STRICTNESS; #if defined( DEBUG ) || defined( _DEBUG ) shaderFlags |= D3D10_SHADER_DEBUG; shaderFlags |= D3D10_SHADER_SKIP_OPTIMIZATION; #endif ID3D10Blob* compilationErrors = 0; HRESULT hr = 0; hr = D3DX10CreateEffectFromFile(L"color.fx", 0, 0, "fx_4_0", shaderFlags, 0, md3dDevice, 0, 0, &mFX, &compilationErrors, 0); if(FAILED(hr)) { if( compilationErrors ) { MessageBoxA(0, (char*)compilationErrors->GetBufferPointer(), 0, 0); ReleaseCOM(compilationErrors); } DXTrace(__FILE__, (DWORD)__LINE__, hr, L"D3DX10CreateEffectFromFile", true); } mTech = mFX->GetTechniqueByName("ColorTech"); mfxWVPVar = mFX->GetVariableByName("gWVP")->AsMatrix(); mfxFLIPVar = mFX->GetVariableByName("flip"); }
void CrateApp::buildFX() { DWORD shaderFlags = D3D10_SHADER_ENABLE_STRICTNESS; //#if defined( DEBUG ) || defined( _DEBUG ) // shaderFlags |= D3D10_SHADER_DEBUG; // shaderFlags |= D3D10_SHADER_SKIP_OPTIMIZATION; //#endif ID3D10Blob* compilationErrors = 0; HRESULT hr = 0; hr = D3DX10CreateEffectFromFile(L"tex.fx", 0, 0, "fx_4_0", shaderFlags, 0, md3dDevice, 0, 0, &mFX, &compilationErrors, 0); if(FAILED(hr)) { if( compilationErrors ) { MessageBoxA(0, (char*)compilationErrors->GetBufferPointer(), 0, 0); ReleaseCOM(compilationErrors); } DXTrace(__FILE__, (DWORD)__LINE__, hr, L"D3DX10CreateEffectFromFile", true); } mTech = mFX->GetTechniqueByName("TexTech"); mfxWVPVar = mFX->GetVariableByName("gWVP")->AsMatrix(); mfxWorldVar = mFX->GetVariableByName("gWorld")->AsMatrix(); mfxEyePosVar = mFX->GetVariableByName("gEyePosW"); mfxLightVar = mFX->GetVariableByName("gLight"); mfxDiffuseMapVar = mFX->GetVariableByName("gDiffuseMap")->AsShaderResource(); mfxSpecMapVar = mFX->GetVariableByName("gSpecMap")->AsShaderResource(); mfxTexMtxVar = mFX->GetVariableByName("gTexMtx")->AsMatrix(); }
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 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(); }
void Scene::BuildFX() { DWORD shaderFlags = D3D10_SHADER_ENABLE_STRICTNESS; #if defined (DEBUG) || (_DEBUG) shaderFlags |= D3D10_SHADER_SKIP_OPTIMIZATION; #endif ID3D10Blob* compilationErrors = 0; HRESULT hr = 0; hr = D3DX10CreateEffectFromFile(L"tex.fx", // The name of the effects file to compile 0, // pDefines 0, // pInlcude "fx_4_0", // The version of the shader we are using shaderFlags, // Specify how the shader code will be complied 0, // FXflags m_Direct3DDevice, // A pointer to the direct device 0, // pEffectPool 0, // pPump &m_FX, // Returns a pointer to the created object &compilationErrors, // Returns a pointer to a string containing the comiplation errors 0 // pttResult, used with pPump ); if( FAILED(hr) ) { if( compilationErrors ) { // Print out any errors MessageBoxA( 0, (char*)compilationErrors->GetBufferPointer(), 0, 0); ReleaseCOM(compilationErrors); } DXTrace(__FILE__, (DWORD)__LINE__, hr, L"D3DX10CreateEffectFromFile", true); } // Set the technique to color tech m_Tech = m_FX->GetTechniqueByName("ColorTech"); // Setup variable pointers to the designated name in effect files m_fxWVPVar = m_FX->GetVariableByName("gWVP")->AsMatrix(); // Set the effect file WVP matrix to m_fxDiffuseMapVar = m_FX->GetVariableByName("gDiffuseMap")->AsShaderResource(); m_FxSpecMapVar = m_FX->GetVariableByName("gSpecMap")->AsShaderResource(); m_FxEyePosVar = m_FX->GetVariableByName("gEyePosW"); m_FxLightVar = m_FX->GetVariableByName("gLight"); m_FxTexMatVar = m_FX->GetVariableByName("gTexMat")->AsMatrix(); m_FxBoxWorldVar = m_FX->GetVariableByName("gBoxWorld")->AsMatrix(); }
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/Lighting.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("LightTech"); mTech2 = mFX->GetTechniqueByName("IllumTech"); mTechSkyBox = mFX->GetTechniqueByName("SkyBoxTech"); mfxWorldViewProj = mFX->GetVariableByName("gWorldViewProj")->AsMatrix(); mfxWorld = mFX->GetVariableByName("gWorld")->AsMatrix(); mfxWorldInvTranspose = mFX->GetVariableByName("gWorldInvTranspose")->AsMatrix(); mfxEyePosW = mFX->GetVariableByName("gEyePosW")->AsVector(); mfxDirLight = mFX->GetVariableByName("gDirLight"); mfxPointLight = mFX->GetVariableByName("gPointLight"); mfxPointLight2 = mFX->GetVariableByName("gPointLight2"); mfxSpotLight = mFX->GetVariableByName("gSpotLight"); mfxMaterial = mFX->GetVariableByName("gMaterial"); diffuseMap = mFX->GetVariableByName("gDiffuseMap")->AsShaderResource(); }
void D3DRenderer::InitEffects() { ID3D10Blob* compiledShader = 0; ID3D10Blob* compilationMsgs = 0; HRESULT hr = D3DX11CompileFromFile(L"Effects/color.fx", 0, 0, 0, "fx_5_0", 0, 0, 0, &compiledShader, &compilationMsgs, 0); if (compilationMsgs !=0) { MessageBoxA(0, (char*)compilationMsgs->GetBufferPointer(), 0 ,0); ReleaseCOM(compilationMsgs); } if (FAILED(hr)) { DXTrace(__FILE__,(DWORD)__LINE__, hr, L"D3DX11CompileFromFile", true); } HR(D3DX11CreateEffectFromMemory(compiledShader->GetBufferPointer(), compiledShader->GetBufferSize(), 0, md3dDevice, &mEffect)); ReleaseCOM(compiledShader); mETech = mEffect->GetTechniqueByName("ColorTech"); }
bool C_Graphics::initDirect3D(const C_Window& window) { // Fill out a DXGI_SWAP_CHAIN_DESC to describe our swap chain. DXGI_SWAP_CHAIN_DESC sd; ZeroMemory( &sd, sizeof( sd ) ); sd.BufferDesc.Width = window.getWidth(); sd.BufferDesc.Height = window.getHeight(); sd.BufferDesc.RefreshRate.Numerator = 60; sd.BufferDesc.RefreshRate.Denominator = 1; sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; sd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; sd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; // No multisampling sd.SampleDesc.Count = 1; sd.SampleDesc.Quality = 0; sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; sd.BufferCount = 1; sd.OutputWindow = window.getWindowHandle(); sd.Windowed = true; sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; sd.Flags = 0; // Create the device UINT createDeviceFlags = 0; //#if defined(DEBUG) || defined(_DEBUG) // createDeviceFlags |= D3D10_CREATE_DEVICE_DEBUG; //#endif HRESULT hr = D3D10CreateDeviceAndSwapChain( 0, //default adapter d_D3DDriverType, 0, // no software device createDeviceFlags, D3D10_SDK_VERSION, &sd, &d_SwapChain, &d_D3DDevice); if(FAILED(hr)) { DEBUGLOG(L"D3DDevice INIT FAILED"); DXTrace(__FILE__, (DWORD)__LINE__, hr, 0, true); return false; } DEBUGLOG(L"D3DDevice INIT SUCCESSFUL"); // The remaining steps that need to be carried out for D3D creation // also need to be executed every time the window is resized. So // just call the OnResize method here to avoid code duplication. onResize(window); D3DX10_FONT_DESC fontDesc; fontDesc.Height = 14; fontDesc.Width = 0; fontDesc.Weight = 0; fontDesc.MipLevels = 1; fontDesc.Italic = false; fontDesc.CharSet = DEFAULT_CHARSET; fontDesc.OutputPrecision = OUT_DEFAULT_PRECIS; fontDesc.Quality = DEFAULT_QUALITY; fontDesc.PitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; wcscpy_s(fontDesc.FaceName, L"Times New Roman"); hr = D3DX10CreateFontIndirect(d_D3DDevice, &fontDesc, &d_Font); if(FAILED(hr)) { DEBUGLOG(L"Font INIT FAILED"); return false; } DEBUGLOG(L"Font INIT SUCCESSFUL"); // Init the defualt shader //d_pDefaultShader = new C_DefaultShader(d_D3DDevice); return true; }
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(); }
void BuildShaderFX() { m_diffuseTextureRV[0] = NULL; m_diffuseTextureTV[0] = NULL; m_distDirTextureRV = NULL; m_distDirTextureTV = NULL; m_TextureRV = NULL; m_TextureTV = NULL; m_pDepthStencilView = NULL; m_otherTextureRV = NULL; m_otherTextureTV = NULL; m_pDrawVectorsTechnique = NULL; m_pDiffuseTechnique = NULL; m_pLineAntiAliasTechnique = NULL; m_pDisplayImage = NULL; m_pInTex[0] = NULL; m_pInTex[1] = NULL; m_pInTex[2] = NULL; m_pDiffTex = NULL; m_pDiffX = NULL; m_pDiffY = NULL; m_pScale = NULL; m_pPan = NULL; m_pPolySize = NULL; m_vp.Width = (int)(WIDTH); m_vp.Height = (int)(HEIGHT); m_vp.MinDepth = 0.0f; m_vp.MaxDepth = 1.0f; m_vp.TopLeftX = 0; m_vp.TopLeftY = 0; ID3DBlob* pCode; ID3DBlob* pError; ID3DX11Effect* pEffect11; //Picture HRESULT hr = 0; hr = D3DX11CompileFromFile(_T("DiffusionCurves.fx"), NULL, NULL, NULL, "fx_5_0", D3D10_SHADER_ENABLE_STRICTNESS | D3D10_SHADER_DEBUG, NULL, NULL, &pCode, &pError, NULL); if (FAILED(hr)) { if (pError) { MessageBoxA(0, (char*)pError->GetBufferPointer(), 0, 0); SAFE_RELEASE(pError); } DXTrace(__FILE__, __LINE__, hr, _T("D3DX11CreateEffectFromFile"), TRUE); } V(D3DX11CreateEffectFromMemory(pCode->GetBufferPointer(), pCode->GetBufferSize(), NULL, m_pd3dDevice, &pEffect11)); m_pDrawVectorsTechnique = pEffect11->GetTechniqueByName("DrawCurves"); m_pDiffuseTechnique = pEffect11->GetTechniqueByName("Diffuse"); m_pLineAntiAliasTechnique = pEffect11->GetTechniqueByName("LineAntiAlias"); m_pDisplayImage = pEffect11->GetTechniqueByName("DisplayDiffusionImage"); m_pDiffTex = pEffect11->GetVariableByName("g_diffTex")->AsShaderResource(); for (int i = 0; i < 3; i++) { m_pInTex[i] = (pEffect11->GetVariableByName("g_inTex"))->GetElement( i)->AsShaderResource(); } m_blurOn = pEffect11->GetVariableByName("g_blurOn")->AsScalar(); m_pDiffX = pEffect11->GetVariableByName("g_diffX")->AsScalar(); m_pDiffY = pEffect11->GetVariableByName("g_diffY")->AsScalar(); m_pScale = pEffect11->GetVariableByName("g_scale")->AsScalar(); m_pPolySize = pEffect11->GetVariableByName("g_polySize")->AsScalar(); m_pPan = pEffect11->GetVariableByName("g_pan")->AsVector(); D3DX11_PASS_DESC PassDesc; m_pDrawVectorsTechnique->GetPassByIndex(0)->GetDesc(&PassDesc); if (FAILED(m_pd3dDevice->CreateInputLayout(VertexDesc_CurveVertex, 4, PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, &m_pCurveVertexLayout))) { return; } m_pDiffuseTechnique->GetPassByIndex(0)->GetDesc(&PassDesc); if (FAILED(m_pd3dDevice->CreateInputLayout(VertexDesc_VSOVertex, 2, PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, &m_pCurveVertex2Layout))) { return; } // create the depth buffer (only needed for curve mask rendering) DXGI_SAMPLE_DESC samdesc; samdesc.Count = 1; samdesc.Quality = 0; D3D11_TEXTURE2D_DESC texdesc; ZeroMemory(&texdesc, sizeof(D3D10_TEXTURE2D_DESC)); texdesc.MipLevels = 1; texdesc.ArraySize = 1; texdesc.SampleDesc = samdesc; texdesc.Width = (int)(WIDTH); texdesc.Height = (int)(HEIGHT); texdesc.Usage = D3D11_USAGE_DEFAULT; texdesc.BindFlags = D3D11_BIND_DEPTH_STENCIL; texdesc.Format = DXGI_FORMAT_D32_FLOAT; if (m_pDepthStencil != NULL) { m_pDepthStencil->Release(); } hr = m_pd3dDevice->CreateTexture2D(&texdesc, NULL, &m_pDepthStencil); hr = m_pd3dDevice->CreateDepthStencilView(m_pDepthStencil, NULL, &m_pDepthStencilView); //create diffusion textures (2 for ping pong rendering) if (m_diffuseTexture[0] != NULL) { m_diffuseTexture[0]->Release(); } if (m_diffuseTexture[1] != NULL) { m_diffuseTexture[1]->Release(); } if (m_distDirTexture != NULL) { m_distDirTexture->Release(); } if (m_otherTexture != NULL) { m_otherTexture->Release(); } texdesc.Width = (int)(WIDTH); texdesc.Height = (int)(HEIGHT); texdesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; //texdesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; // use this for higher accuracy diffusion texdesc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE; hr = m_pd3dDevice->CreateTexture2D(&texdesc, NULL, &m_diffuseTexture[0]); hr = m_pd3dDevice->CreateTexture2D(&texdesc, NULL, &m_diffuseTexture[1]); hr = m_pd3dDevice->CreateTexture2D(&texdesc, NULL, &m_otherTexture); // distance map + nearest point map texdesc.Usage = D3D11_USAGE_DEFAULT; texdesc.CPUAccessFlags = 0; texdesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE; texdesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; hr = m_pd3dDevice->CreateTexture2D(&texdesc, NULL, &m_distDirTexture); hr = m_pd3dDevice->CreateTexture2D(&texdesc, NULL, &m_Texture); //create render target views hr = m_pd3dDevice->CreateShaderResourceView(m_diffuseTexture[0], NULL, &m_diffuseTextureRV[0]); hr = m_pd3dDevice->CreateRenderTargetView(m_diffuseTexture[0], NULL, &m_diffuseTextureTV[0]); hr = m_pd3dDevice->CreateShaderResourceView(m_diffuseTexture[1], NULL, &m_diffuseTextureRV[1]); hr = m_pd3dDevice->CreateRenderTargetView(m_diffuseTexture[1], NULL, &m_diffuseTextureTV[1]); hr = m_pd3dDevice->CreateShaderResourceView(m_distDirTexture, NULL, &m_distDirTextureRV); hr = m_pd3dDevice->CreateRenderTargetView(m_distDirTexture, NULL, &m_distDirTextureTV); hr = m_pd3dDevice->CreateShaderResourceView(m_Texture, NULL, &m_TextureRV); hr = m_pd3dDevice->CreateRenderTargetView(m_Texture, NULL, &m_TextureTV); hr = m_pd3dDevice->CreateShaderResourceView(m_otherTexture, NULL, &m_otherTextureRV); hr = m_pd3dDevice->CreateRenderTargetView(m_otherTexture, NULL, &m_otherTextureTV); char s[255] = "zephyr.xml"; ReadVectorFile(s); ConstructCurves(); }
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(); }
void PeaksAndValleys::init(int row, int column) { initMesh(row, column); //Create Effect Technique int shaderFlag = D3D10_SHADER_ENABLE_STRICTNESS; #if defined(DEBUG) || defined(_DEBUG ) shaderFlag |= D3D10_SHADER_DEBUG |D3D10_SHADER_SKIP_OPTIMIZATION; #endif ID3D10Device *device = DirectEngine::getInstance()->getDevice(); ID3D10Blob *errorBlob = nullptr; int result = D3DX10CreateEffectFromFile(L"color.fx", nullptr,nullptr, "fx_4_0", shaderFlag, 0, device, nullptr, nullptr, &_effect,&errorBlob,nullptr ); if (result < 0) { if (errorBlob) { MessageBoxA(nullptr, (char*)errorBlob->GetBufferPointer(), nullptr, 0); errorBlob->Release(); } DXTrace(__FILE__, __LINE__, result, L"D3DX10CreateEffectFromFile",true); } _effectTech = _effect->GetTechniqueByName("ColorTech"); _mvpMatrixV = _effect->GetVariableByName("g_MVPMatrix")->AsMatrix(); //Create Layout D3D10_INPUT_ELEMENT_DESC inputDesc[2]; inputDesc[0].SemanticName = "POSITION"; inputDesc[0].SemanticIndex = 0; inputDesc[0].Format = DXGI_FORMAT_R32G32B32_FLOAT; inputDesc[0].InputSlot = 0; inputDesc[0].AlignedByteOffset = 0; inputDesc[0].InputSlotClass = D3D10_INPUT_PER_VERTEX_DATA; inputDesc[0].InstanceDataStepRate = 0; inputDesc[1].SemanticName = "COLOR"; inputDesc[1].SemanticIndex = 0; inputDesc[1].Format = DXGI_FORMAT_R32G32B32A32_FLOAT; inputDesc[1].InputSlot = 0; inputDesc[1].AlignedByteOffset = sizeof(float) * 3; inputDesc[1].InputSlotClass = D3D10_INPUT_PER_VERTEX_DATA; inputDesc[1].InstanceDataStepRate = 0; // D3D10_PASS_DESC passDesc; _effectTech->GetPassByName("P0")->GetDesc(&passDesc); result = device->CreateInputLayout(inputDesc, 2, passDesc.pIAInputSignature,passDesc.IAInputSignatureSize,&_inputLayout); assert(result>=0); //Matrix D3DXMatrixIdentity(&_modelMatrix); D3DXMatrixIdentity(&_projMatrix); D3DXMatrixIdentity(&_viewMatrix); //Create Project Matrix auto &winSize = DirectEngine::getInstance()->getWinSize(); D3DXMatrixPerspectiveFovLH(&_projMatrix,M_PI/4,winSize.width/winSize.height,1.0f,400.0f); D3DXVECTOR3 eyePosition(0,80,-120); D3DXVECTOR3 targetPosition(0,0,0); D3DXVECTOR3 upperVec(0,1,0); D3DXMatrixLookAtLH(&_viewMatrix, &eyePosition, &targetPosition, &upperVec); }