基本上我制作了一个带有动画的 .x 文件模型类,每个模型类都有一个指向效果文件类的指针,所以我制作了一堆不同的模型,我让它们都使用一个单一的效果,例如发光,所以在DrawSubset()
每个模型的渲染功能中都是Begin()
为了End()
效果。问题是我 90% 的 .fx 文件(我尝试在 FX 作曲家和 Rendermonkey 中制作,我尝试加载样本,甚至是简单的样本)它们没有加载并且它说效果是空的,如果有东西设法加载,它会使所有几何图形变灰或切掉它的一部分。这基本上是我的代码(哦,d3d设备指针设置正确,别担心,问题不是那里):
***FXfileEntity.h***
#pragma once
#include <d3d9.h>
#include <d3dx9.h>
class CFXFileEntity{
private:
LPDIRECT3DDEVICE9 m_d3dDevice;
LPD3DXBUFFER pBufferErrors;
D3DXEFFECT_DESC pEffectDesc;
DWORD dwShaderFlags;
D3DXHANDLE ambient, attenuation, bbmax, bbmin, bbsize, bcenter, bssize, bsmin, bsmax, diffuse,
elapsed, emissive, envNormal, height, joint, jointW, jointWI, jointWIT, jointWV,
jointWVI, jointWVIT, jointWVP, jointWVPI, jointWVPIT, last, normal, opacity,
position, proj, projI, projIT, random, refraction, renderCT, renderDST, renderTC,
renderTD, specular, specularP, standarGlob, TextureMat, time, UnitsScale, view,
viewI, viewIT, viewP, viewPI, viewPIT, world, worldI, worldIT, worldV, worldVI,
worldVIT, worldVP, worldVPI, worldVPIT;
D3DXVECTOR4 amb4, att4, diff, emis, join, nor2, opa4, posit, ref4, rtc, spec, specP4;
D3DXVECTOR3 att3, bbMax, bbMin, bbSiz, bCen, nor1, opa3, ref3, specP3;
D3DXVECTOR2 opa2, ref2, rtd, specP2;
float bsSiz, bsMin, bsMax, elapTime, heigtMap1, lasTime, opa1, ran, ref1, specP1, tim, unit;
LPDIRECT3DTEXTURE9 envNorm, heightMapT, nor3, opa5, ref5, rct, rdst, stdG;
D3DXMATRIX jWor, jWI, jWIT, jWV, jWVI, jWVIT, jWVP, jWVPI, jWVPIT, pro, proI, proIT, texM,
vie, vieI, vieIT, vieP, viePI, viePIT, wor, worI, worIT, worV, worVI, worVIT, worVP, worVPI,
worVPIT;
public:
LPD3DXEFFECT anEffect;
UINT cPasses;
CFXFileEntity(LPDIRECT3DDEVICE9 d3dDevice);
~CFXFileEntity();
HRESULT Load(LPCTSTR path);
void Set();
};
对于功能体:
#include "FXfileEntity.h"
#include <iostream>
CFXFileEntity::CFXFileEntity(LPDIRECT3DDEVICE9 d3dDevice) : m_d3dDevice(d3dDevice)
{
anEffect = NULL;
pBufferErrors = NULL;
dwShaderFlags = 0;
cPasses = 0;
}
CFXFileEntity::~CFXFileEntity(void)
{
anEffect = NULL;
pBufferErrors = NULL;
dwShaderFlags = 0;
cPasses = 0;
}
HRESULT CFXFileEntity::Load(LPCTSTR path)
{
HRESULT hr;
hr=D3DXCreateEffectFromFile(m_d3dDevice,path,NULL,NULL,0,NULL,&anEffect,NULL);
if(!anEffect)
{
MessageBox(NULL, "fail", "f", MB_OK);
}
if(FAILED(hr))
{
MessageBox(NULL, "hr failed", "hrf", MB_OK);
}
ambient = anEffect->GetParameterBySemantic( NULL, "Ambient" );
attenuation = anEffect->GetParameterBySemantic( NULL, "Attenuation" );
bbmax = anEffect->GetParameterBySemantic( NULL, "BoundingBoxMax" );
bbmin = anEffect->GetParameterBySemantic( NULL, "BoundingBoxMin" );
bbsize = anEffect->GetParameterBySemantic( NULL, "BoundingBoxSize" );
bcenter = anEffect->GetParameterBySemantic( NULL, "BoundingCenter" );
bssize = anEffect->GetParameterBySemantic( NULL, "BoundingSphereSize" );
bsmin = anEffect->GetParameterBySemantic( NULL, "BoundingSphereMin" );
bsmax = anEffect->GetParameterBySemantic( NULL, "BoundingSphereMax" );
diffuse = anEffect->GetParameterBySemantic( NULL, "Diffuse" );
elapsed = anEffect->GetParameterBySemantic( NULL, "ElapsedTime" );
emissive = anEffect->GetParameterBySemantic( NULL, "Emissive" );
envNormal = anEffect->GetParameterBySemantic( NULL, "EnviromentNormal" );
height = anEffect->GetParameterBySemantic( NULL, "Height" );
joint = anEffect->GetParameterBySemantic( NULL, "Joint" );
jointW = anEffect->GetParameterBySemantic( NULL, "JointWorld" );
jointWI = anEffect->GetParameterBySemantic( NULL, "JointWorldInverse" );
jointWIT = anEffect->GetParameterBySemantic( NULL, "JointWorldInverseTranspose" );
jointWV = anEffect->GetParameterBySemantic( NULL, "JointWorldView" );
jointWVI = anEffect->GetParameterBySemantic( NULL, "JointWorldViewInverse" );
jointWVIT = anEffect->GetParameterBySemantic( NULL, "JointWolrdViewInverseTranspose" );
jointWVP = anEffect->GetParameterBySemantic( NULL, "JointWorldViewProjection" );
jointWVPI = anEffect->GetParameterBySemantic( NULL, "JointWorldViewProjectionInverse" );
jointWVPIT = anEffect->GetParameterBySemantic( NULL, "JointWorldViewProjectionTranspose" );
last = anEffect->GetParameterBySemantic( NULL, "LastTime" );
normal = anEffect->GetParameterBySemantic( NULL, "Normal" );
opacity = anEffect->GetParameterBySemantic( NULL, "Opacity" );
position = anEffect->GetParameterBySemantic( NULL, "Position" );
proj = anEffect->GetParameterBySemantic( NULL, "Projection" );
projI = anEffect->GetParameterBySemantic( NULL, "ProjectionInverse" );
projIT = anEffect->GetParameterBySemantic( NULL, "ProjectionInverseTranspose" );
random = anEffect->GetParameterBySemantic( NULL, "Random" );
refraction = anEffect->GetParameterBySemantic( NULL, "Refraction" );
renderCT = anEffect->GetParameterBySemantic( NULL, "RenderColorTarget" );
renderDST = anEffect->GetParameterBySemantic( NULL, "RenderDepthStencilTarget" );
renderTC = anEffect->GetParameterBySemantic( NULL, "RenderTargetClipping" );
renderTD = anEffect->GetParameterBySemantic( NULL, "RenderTargetDimension" );
specular = anEffect->GetParameterBySemantic( NULL, "Specular" );
specularP = anEffect->GetParameterBySemantic( NULL, "SpecularPower" );
standarGlob = anEffect->GetParameterBySemantic( NULL, "StandardGlobal" );
TextureMat = anEffect->GetParameterBySemantic( NULL, "TextureMatrix" );
time = anEffect->GetParameterBySemantic( NULL, "Time" );
UnitsScale = anEffect->GetParameterBySemantic( NULL, "UnitsScale" );
view = anEffect->GetParameterBySemantic( NULL, "View" );
viewI = anEffect->GetParameterBySemantic( NULL, "ViewInverse" );
viewIT = anEffect->GetParameterBySemantic( NULL, "ViewInverseTranspose" );
viewP = anEffect->GetParameterBySemantic( NULL, "ViewProjection" );
viewPI = anEffect->GetParameterBySemantic( NULL, "ViewProjectionInverse" );
viewPIT = anEffect->GetParameterBySemantic( NULL, "ViewProjectionInverseTranspose" );
world = anEffect->GetParameterBySemantic( NULL, "World" );
worldI = anEffect->GetParameterBySemantic( NULL, "WorldInverse" );
worldIT = anEffect->GetParameterBySemantic( NULL, "WorldInverseTranspose" );
worldV = anEffect->GetParameterBySemantic( NULL, "WorldView" );
worldVI = anEffect->GetParameterBySemantic( NULL, "WorldViewInverse" );
worldVIT = anEffect->GetParameterBySemantic( NULL, "WorldViewInverseTranspose" );
worldVP = anEffect->GetParameterBySemantic( NULL, "WorldViewProjection" );
worldVPI = anEffect->GetParameterBySemantic( NULL, "WorldViewProjectionInverse" );
worldVPIT = anEffect->GetParameterBySemantic( NULL, "WorldViewProjectionInverseTranspose" );
D3DXHANDLE hTech;
anEffect->FindNextValidTechnique( NULL, &hTech );
anEffect->SetTechnique( hTech );
return hr;
}
void CFXFileEntity::Set()
{
m_d3dDevice->GetTransform( D3DTS_WORLD, &wor );
m_d3dDevice->GetTransform( D3DTS_PROJECTION, &pro );
m_d3dDevice->GetTransform( D3DTS_VIEW, &vie );
D3DXMatrixInverse( &proI, NULL, &pro );
D3DXMatrixTranspose( &proIT, &proI );
D3DXMatrixInverse( &vieI, NULL, &vie );
D3DXMatrixTranspose( &vieIT, &vieI );
vieP = vie * pro;
D3DXMatrixInverse( &viePI, NULL, &vieP );
D3DXMatrixTranspose( &viePIT, &viePI );
D3DXMatrixInverse( &worI, NULL, &wor );
D3DXMatrixTranspose( &worIT, &worI );
worV = wor * vie;
D3DXMatrixInverse( &worVI, NULL, &worV );
D3DXMatrixTranspose( &worVIT, &worVI );
worVP= wor * vie * pro;
D3DXMatrixInverse( &worVPI, NULL, &worVP );
D3DXMatrixTranspose( &worVPIT, &worVPI );
tim = (float)GetTickCount()/1000.0f;
anEffect->SetFloat( time, tim );
anEffect->SetMatrix( proj, &pro );
anEffect->SetMatrix( projI, &proI );
anEffect->SetMatrix( projIT, &proIT );
anEffect->SetMatrix( view, &vie );
anEffect->SetMatrix( viewI, &vieI );
anEffect->SetMatrix( viewIT, &vieIT );
anEffect->SetMatrix( viewP, &vieP );
anEffect->SetMatrix( viewPI, &viePI );
anEffect->SetMatrix( viewPIT, &viePIT );
anEffect->SetMatrix( world, &wor );
anEffect->SetMatrix( worldI, &worI );
anEffect->SetMatrix( worldIT, &worIT );
anEffect->SetMatrix( worldV, &worV );
anEffect->SetMatrix( worldVI, &worVI );
anEffect->SetMatrix( worldVIT, &worVIT );
anEffect->SetMatrix( worldVP, &worVP );
anEffect->SetMatrix( worldVPI, &worVPI );
anEffect->SetMatrix( worldVPIT, &worVPIT );
}
在模型类中它呈现在这里:
this->Effect->Set();
this->Effect->cPasses = 0;
if( SUCCEEDED( Effect->anEffect->Begin(&this->Effect->cPasses, 0) ) ){
for (DWORD i = 0; i < this->Effect->cPasses; i++)
{
Effect->anEffect->BeginPass(i);
pDrawMesh->DrawSubset(iMaterial);
Effect->anEffect->EndPass();
}
Effect->anEffect->End();
}
我根据我在 .fx 文件中看到的内容在 cPasses 上尝试了不同的值,但这并没有真正的区别。没有 .fx 文件,我的 .x 文件可以完美地呈现纹理和动画……我从没想过 .fx 文件太难了,这就像 DirectX 迄今为止最令人困惑的部分!