0

基本上我制作了一个带有动画的 .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 迄今为止最令人困惑的部分!

4

1 回答 1

0

好的,看看“EdgeFuzz.fx” *请发布文件给大家看看着色器使用以下顶点输入。

/* data from application vertex buffer */
  struct appdata {
     float3 Position    : POSITION;
     float4 UV      : TEXCOORD0;
     float4 Normal  : NORMAL;
     float4 Tangent : TANGENT0;
     float4 Binormal    : BINORMAL0;
};

我在您的代码中没有看到与上述语义相匹配的顶点缓冲区?即您将需要创建一个顶点缓冲区,匹配信息顶点(语义:POSITION),纹理坐标:语义:TEXCOORD0,法线(用于照明,语义:NORMAL),(凹凸贴图的切线和副法线)

然后必须用上述结构中的网格几何体填充顶点缓冲区(您需要创建一个 c++ 结构以匹配上述 hlsl 结构)

还是您可能从帖子中排除了更多代码?我希望这对您有所帮助,因为当您调用技术(Main)(在“EdgeFuzz.fx”着色器中定义)时,该顶点着色器将获取该几何信息,并做这件事

于 2012-01-25T05:25:34.000 回答