|
|
我编写了一个像素着色器,但是总是创建失败。错误提示:PS_1_X is no longer supported;use/Gec in fxc to automatically upgarde to PS_2_0;Alternately,fxc's/LD option allows use of the old compiler DLL.
请问该怎么办呢?
下面是创建着色器的代码,(完整的源代码在附件里),请多多指教。
// Globals
//
IDirect3DDevice9* Device = 0;
const int Width = 640;
const int Height = 480;
IDirect3DPixelShader9* MultiTexPS = 0;
ID3DXConstantTable* MultiTexCT = 0;
IDirect3DVertexBuffer9* QuadVB = 0;
IDirect3DTexture9* BaseTex = 0;
IDirect3DTexture9* SpotLightTex = 0;
IDirect3DTexture9* StringTex = 0;
D3DXHANDLE BaseTexHandle = 0;
D3DXHANDLE SpotLightTexHandle = 0;
D3DXHANDLE StringTexHandle = 0;
D3DXCONSTANT_DESC BaseTexDesc;
D3DXCONSTANT_DESC SpotLightTexDesc;
D3DXCONSTANT_DESC StringTexDesc;
//
// Structs
//
struct MultiTexVertex
{
MultiTexVertex(float x, float y, float z,
float u0, float v0,
float u1, float v1,
float u2, float v2)
{
_x = x; _y = y; _z = z;
_u0 = u0; _v0 = v0;
_u1 = u1; _v1 = v1;
_u2 = u2, _v2 = v2;
}
float _x, _y, _z;
float _u0, _v0;
float _u1, _v1;
float _u2, _v2;
static const DWORD FVF;
};
const DWORD MultiTexVertex::FVF = D3DFVF_XYZ | D3DFVF_TEX3;
//
// Framework functions
//
bool Setup()
{
HRESULT hr = 0;
//
// Create geometry.
//
Device->CreateVertexBuffer(
6 * sizeof(MultiTexVertex),
D3DUSAGE_WRITEONLY,
MultiTexVertex::FVF,
D3DPOOL_MANAGED,
&QuadVB,
0);
MultiTexVertex* v = 0;
QuadVB->Lock(0, 0, (void**)&v, 0);
v[0] = MultiTexVertex(-10.0f, -10.0f, 5.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f);
v[1] = MultiTexVertex(-10.0f, 10.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
v[2] = MultiTexVertex( 10.0f, 10.0f, 5.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f);
v[3] = MultiTexVertex(-10.0f, -10.0f, 5.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f);
v[4] = MultiTexVertex( 10.0f, 10.0f, 5.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f);
v[5] = MultiTexVertex( 10.0f, -10.0f, 5.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f);
QuadVB->Unlock();
//
// Compile shader
//
ID3DXBuffer* shader = 0;
ID3DXBuffer* errorBuffer = 0;
hr = D3DXCompileShaderFromFile(
"ps_multitex.txt",
0,
0,
"Main", // entry point function name
"ps_1_1",
D3DXSHADER_DEBUG,
&shader,
&errorBuffer,
&MultiTexCT);
// output any error messages
if( errorBuffer )
{
::MessageBox(0, (char*)errorBuffer->GetBufferPointer(), 0, 0);
d3d::Release<ID3DXBuffer*>(errorBuffer);
}
if(FAILED(hr))
{
::MessageBox(0, "D3DXCompileShaderFromFile() - FAILED", 0, 0);
return false;
}
//
// Create Pixel Shader
//
hr = Device->CreatePixelShader(
(DWORD*)shader->GetBufferPointer(),
&MultiTexPS);
if(FAILED(hr))
{
::MessageBox(0, "CreateVertexShader - FAILED", 0, 0);
return false;
}
d3d::Release<ID3DXBuffer*>(shader);
//
// Load textures.
//
D3DXCreateTextureFromFile(Device, "crate.bmp", &BaseTex);
D3DXCreateTextureFromFile(Device, "spotlight.bmp", &SpotLightTex);
D3DXCreateTextureFromFile(Device, "text.bmp", &StringTex);
//
// Set Projection Matrix
//
D3DXMATRIX P;
D3DXMatrixPerspectiveFovLH(
& , D3DX_PI * 0.25f,
(float)Width / (float)Height, 1.0f, 1000.0f);
Device->SetTransform(D3DTS_PROJECTION, &P);
//
// Disable lighting.
//
Device->SetRenderState(D3DRS_LIGHTING, false);
//
// Get Handles
//
BaseTexHandle = MultiTexCT->GetConstantByName(0, "BaseTex");
SpotLightTexHandle = MultiTexCT->GetConstantByName(0, "SpotLightTex");
StringTexHandle = MultiTexCT->GetConstantByName(0, "StringTex");
//
// Set constant descriptions:
//
UINT count;
MultiTexCT->GetConstantDesc(BaseTexHandle, &BaseTexDesc, &count);
MultiTexCT->GetConstantDesc(SpotLightTexHandle, &SpotLightTexDesc, &count);
MultiTexCT->GetConstantDesc(StringTexHandle, &StringTexDesc, &count);
MultiTexCT->SetDefaults(Device);
return true;
}
[em14] [em14] |
|