Sign in to follow this  
leidegren

D3DXCreateEffectFromFile always fail on me!

Recommended Posts

leidegren    139
I seem to be unable to load my pre-compiled shader...
HRESULT hr;
if( FAILED( hr = D3DXCreateEffectFromFile( d, 
    TEXT( "fx\plaster.fxo" ), 
    NULL, NULL, 0, NULL, &plaster, NULL ) ) )
{
    printf( "D3DXCreateEffectFromFile FAILED\n" );
    switch( hr )
    {
    case D3DXERR_INVALIDDATA:
        printf( "D3DXERR_INVALIDDATA\n" );
        break;
    }
}
I used the "Microsoft (R) D3D10 Shader Compiler 9.19.949.0046" to compile this shader and it successfully compiles into an object file with... fxc /T fx_2_0 /Od /Zi /Zpr /Fo Plaster.fxo Plaster.fx However I always get that D3DXERR_INVALIDDATA error. I'm using the June 2007 SDK, and developing for the DX9 platform. Here's the shader as well:
float4x4 matViewProjection  : ViewProjection ;
float4   vViewPosition      : ViewPosition ;

struct VS_OUTPUT 
{
   float4 pos       : POSITION0;
   float3 normal    : TEXCOORD0;
   float3 view      : TEXCOORD1;
};

VS_OUTPUT vs_main( 
    float4 pos      : POSITION0, 
    float3 normal   : NORMAL0 )
{
   VS_OUTPUT v;

   v.pos = mul( matViewProjection, pos );
   
   // World-space lightning
   v.normal = normal;
   v.view = vViewPosition - pos;
   
   return( v );
}

float4 color = float4( 1.00f, 0.36f, 0.33f, 1.00f );

float4 ps_main( 
    float3 normal   : TEXCOORD0, 
    float3 view     : TEXCOORD1 ) : COLOR0
{  
   float v = 0.5f * (1 + dot( normalize( view ), normal ));
   return v * color;
}

technique T0
{
   pass P0
   {
      VertexShader = compile vs_2_0 vs_main();
      PixelShader = compile ps_2_0 ps_main();
   }
}

Share this post


Link to post
Share on other sites
kauna    2922

Hi,

Without much reading your code, I'd suggest reading the error message the D3DXCreateEffectFromFile function gives.

HRESULT D3DXCreateEffectFromFile(
...
LPD3DXEFFECTPOOL pPool,
LPD3DXEFFECT * ppEffect,
LPD3DXBUFFER * ppCompilationErrors
);

ppCompilationErrors <- pass a LPD3DXBUFFER * variable here and read what it returns.

Good luck!

Share this post


Link to post
Share on other sites
S1CA    1418
As an alternative to what kauna suggests, link with d3dx9d.lib (the D at the end means Debug) instead of d3dx9.lib then look at the Output window of your debugger after D3DXCreateEffectFromFile() has failed. The Debug version of D3DX will produce extra human readable debug output when there errors.

One possibility since you're using a relative path for the filename is D3DXCreateEffectFromFile() simply can't find the file on the current path. The current path isn't always going to be the same as the location of your .exe. GetModuleFilename() with a NULL module handle will get you the proper path to your .exe

Share this post


Link to post
Share on other sites
leidegren    139
I was worried about that first, but it's actually an absolute path, I just edit the post a bit, kind stupid, but anyway... i'll try that debug library though.

the error buffer is optional, and it's not assigned to as the function return invalid data. and both effect and buffer pointer when i tried it, was assigned to zero.

Share this post


Link to post
Share on other sites
leidegren    139
I am such an idiot. Look at the string. I used all kinds of unrecognized escape sequences... BAWH! replace '\' with \\ !!!

Accidently, i did use d3dxd.lib without realizing that it wrote debug output.

Tanks for the help, it works now...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this