基本的に、アニメーションを含む .x ファイル モデル クラスを作成し、各モデル クラスにはエフェクト ファイル クラスへのポインタがあるため、さまざまなモデルを多数作成し、たとえば、グローのような単一のエフェクトをすべて使用するようにします。問題は私DrawSubset()
の.fxファイルの90%(FX composerBegin()
とEnd()
Rendermonkeyで作ってみた、サンプルを読み込んでみた、単純なものでも)それらが読み込まれず、効果がnullであり、何かがロードされた場合、すべてのジオメトリが灰色になるか、その一部がスライスされます.これは基本的に私のコードです(ああ、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 ファイルはテクスチャとアニメーションで完全にレンダリングされます...これは非常に難しいもので、DirectX で最も紛らわしい部分のようです!