Exemple #1
0
void CShader::CreateShader(ID3D11Device *pd3dDevice)
{
	D3D11_INPUT_ELEMENT_DESC d3dInputLayout[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 }
	};
	UINT nElements = ARRAYSIZE(d3dInputLayout);
	CreateVertexShaderFromCompiledFile(pd3dDevice, L"VS.fxo", d3dInputLayout, nElements);
	CreatePixelShaderFromCompiledFile(pd3dDevice, L"PS.fxo");
	//컴파일된 쉐이더 코드의 이름이 VS.fxo와 PS.fxo이다.

	CreateShaderVariables(pd3dDevice);
}
	bool ShaderPass::LoadPassFromElement(TiXmlElement *passElementPtr)
	{ 
		// Vertex Shader - required
		TiXmlElement *shaderElementPtr = passElementPtr->FirstChildElement("VertexShader");
		if(nullptr == shaderElementPtr)
		{
			InternalOutput::GetReference().Error(
				"Failed to load shader, no VertexShader element found?\n");
			return false;
		}
		if(!CreateVertexShaderFromCompiledFile(shaderElementPtr->GetText()))
		{
			InternalOutput::GetReference().Error(
				"Failed to load vertex shader %s, is the file present?\n", shaderElementPtr->GetText());
			return false;
		}

		// Pixel Shader - required
		shaderElementPtr = passElementPtr->FirstChildElement("PixelShader");
		if(nullptr == shaderElementPtr)
		{
			InternalOutput::GetReference().Error(
				"Failed to load shader, no PixelShader element found?\n");
			return false;
		}
		if(!CreatePixelShaderFromCompiledFile(shaderElementPtr->GetText()))
		{
			InternalOutput::GetReference().Error(
				"Failed to load pixel shader %s, is the file present?\n", shaderElementPtr->GetText());
			return false;
		}

		// Geometry Shader - optional
		shaderElementPtr = passElementPtr->FirstChildElement("GeometryShader");
		if(shaderElementPtr)
		{
			if(!CreateGeometryShaderFromCompiledFile(shaderElementPtr->GetText()))
			{
				InternalOutput::GetReference().Error(
					"Failed to load geometry shader %s, is the file present?\n", shaderElementPtr->GetText());
				return false;
			}
		}
		// Hull Shader - optional
		shaderElementPtr = passElementPtr->FirstChildElement("HullShader");
		if(shaderElementPtr)
		{
			if(!CreateHullShaderFromCompiledFile(shaderElementPtr->GetText()))
			{
				InternalOutput::GetReference().Error(
					"Failed to load hull shader %s, is the file present?\n", shaderElementPtr->GetText());
				return false;
			}
		}

		// Domain Shader - optional
		shaderElementPtr = passElementPtr->FirstChildElement("DomainShader");
		if(shaderElementPtr)
		{
			if(!CreateDomainShaderFromCompiledFile(shaderElementPtr->GetText()))
			{
				InternalOutput::GetReference().Error(
					"Failed to load domain domain %s, is the file present?\n", shaderElementPtr->GetText());
				return false;
			}
		}

		return true; 
	}