【发布时间】:2015-05-13 01:12:21
【问题描述】:
这是我第一次使用着色器,我正在学习directx 编程教程,我的项目中包含两个着色器文件,文件类型分别为 .vs 和 .ps。我不确定这些文件类型是否被识别为视觉工作室中 hlsl 的文件类型,最后有 .hlsl。有没有办法让这些文件类型得到识别,如果没有,我将如何更改下面的代码以包含不同的文件类型?我的代码编译了,它只是返回我的错误消息说 color.vs missing。
在我的 colorshaderclass.cpp 的初始化函数下,返回函数调用如下:
result = InitializeShader(device, hwnd, L"../Engine/color.hlsl", L"../Engine/color.ps");
initializeShader函数本身定义如下:
bool ColorShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename)
{
HRESULT result;
ID3D10Blob* errorMessage;
ID3D10Blob* vertexShaderBuffer;
ID3D10Blob* pixelShaderBuffer;
D3D11_INPUT_ELEMENT_DESC polygonLayout[2];
unsigned int numElements;
D3D11_BUFFER_DESC matrixBufferDesc;
//initializ the pointers this function will use to null
errorMessage = 0;
vertexShaderBuffer = 0;
pixelShaderBuffer = 0;
//compile vertex shader code
result = D3DX11CompileFromFile(vsFilename, NULL, NULL, "ColorVertexShader", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL,
&vertexShaderBuffer, &errorMessage, NULL);
if (FAILED(result))
{
//if the shader failed to compile it should have written something to error message
if (errorMessage)
{
OutputShaderErrorMessage(errorMessage, hwnd, vsFilename);
}
//if there was nothing in error message then it couldnt find shader file
else
{
MessageBox(hwnd, vsFilename, L"Missing Shader File", MB_OK);
}
return false;
}
//compile pixel shader code
if (FAILED(result))
{
if (errorMessage)
{
OutputShaderErrorMessage(errorMessage, hwnd, psFilename);
}
else
{
MessageBox(hwnd, psFilename, L"Missing Shader File", MB_OK);
}
return false;
}
任何帮助将不胜感激。我不确定这是否是设置问题,或者我是否需要更改文件类型或是否需要包含标头(尽管尝试了此选项,VS 尝试使用 c++ 语法调试 hlsl 文件)。
【问题讨论】:
-
你作为
result得到的具体价值是什么?
标签: c++ visual-studio-2013 directx-11 hlsl vertex-shader