Sign in to follow this  
Rectangle

Valid effects handle returning invalid technique handles

Recommended Posts

Rectangle    161
Please review the comments in the code below:
[source lang="cpp"]// The following code succesfully returns a valid effect handle without failure
ID3DXBuffer* piBuffer = NULL;
if(FAILED( D3DXCreateEffectFromFileA(m_d3dDev, m_szDefaultShaderFile, NULL, NULL, D3DXSHADER_DEBUG, NULL, &m_piDefaultEffect, &piBuffer) ))
{
if( piBuffer )
{
MessageBoxA(NULL, (LPCSTR)piBuffer->GetBufferPointer(), "HLSL", MB_OK);
piBuffer->Release();
}
return false;
}
if( piBuffer)
{
piBuffer->Release();
piBuffer = NULL;
}

// The following code succesfully returns the correct description data (6 params, 4 techs, 0 funcs)
D3DXEFFECT_DESC fxd;
m_piDefaultEffect->GetDesc(&fxd);

// The following code returns <Bad Ptr&gt, and any following use of this handle results in errors
D3DXHANDLE tech = m_piDefaultEffect->GetTechnique(1); // FAILS
tech = m_piDefaultEffect->GetCurrentTechnique(); // FAILS
m_piDefaultEffect->FindNextValidTechnique(NULL, &tech); // FAILS[/source]
Any idea why this could be happening? How can I fix this? Edited by Rectangle

Share this post


Link to post
Share on other sites
Asesh    276
How many techniques are there in that effect file? Seems like there's only one and if that's true then you should pass 0 as an argument to GetTechnique to retrieve the first technique

Share this post


Link to post
Share on other sites
Rectangle    161
[quote name='Asesh' timestamp='1346428723' post='4975167']
How many techniques are there in that effect file? Seems like there's only one and if that's true then you should pass 0 as an argument to GetTechnique to retrieve the first technique
[/quote]

As stated in the comments of my previous post, [i]GetDesc()[/i] returns 6 parameters, 4 techniques, and 0 functions.
No, [i]GetTechnique(0)[/i] fails all the same as [i]GetNextValidTechnique(NULL, NULL)[/i].
Here's the shader:
[source lang="cpp"]float4x4 WorldViewProjection : WORLDVIEWPROJECTION;
float4x4 World : WORLD;
float4x3 WorldInverseTranspose : WORLDINVERSETRANSPOSE;
float3 afLightColor[5];
float3 afLightDir[5];
float3 vCameraPos : CAMERAPOSITION;
struct VS_INPUT
{
float3 Position : POSITION;
float3 Normal : NORMAL;
};
struct VS_OUTPUT
{
float4 Position : POSITION;
float3 ViewDir : TEXCOORD0;
float3 Normal : TEXCOORD1;
};
VS_OUTPUT DefaultVShader(VS_INPUT IN)
{
VS_OUTPUT Out;
float3 objPos = IN.Position;
Out.Position = mul( float4( objPos, 1.0f), WorldViewProjection);
float3 WorldPos = mul( float4( objPos, 1.0f), World);
Out.ViewDir = vCameraPos - WorldPos;
Out.Normal = mul(IN.Normal, WorldInverseTranspose);
return Out;
}
float4 DefaultPShaderSpecular_D1(VS_OUTPUT IN) : COLOR0
{
float4 OUT = float4(0.0f, 0.0f, 0.0f, 1.0f);
float3 Normal = normalize(IN.Normal);
float3 ViewDir = normalize(IN.ViewDir);
{
float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;
float3 Reflect = reflect (Normal, afLightDir[0]);
float fHalfLambert = L1 * L1;
OUT.rgb += afLightColor[0] * (fHalfLambert + saturate(fHalfLambert * 4.0f) * pow(dot(Reflect, ViewDir), 9));
}
return OUT;
}
float4 DefaultPShaderSpecular_D2(VS_OUTPUT IN) : COLOR0
{
float4 OUT = float4(0.0f, 0.0f, 0.0f, 1.0f);
float3 Normal = normalize(IN.Normal);
float3 ViewDir = normalize(IN.ViewDir);
{
float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;
float3 Reflect = reflect (ViewDir, Normal);
float fHalfLambert = L1 * L1;
OUT.rgb += afLightColor[0] * (fHalfLambert + saturate(fHalfLambert * 4.0f) * pow(dot(Reflect, afLightDir[0]), 9));
}
{
float L1 = dot(Normal,afLightDir[1]) * 0.5f + 0.5f;
float3 Reflect = reflect (ViewDir,Normal);
float fHalfLambert = L1 * L1;
OUT.rgb += afLightColor[1] * (fHalfLambert + saturate(fHalfLambert * 4.0f) * pow(dot(Reflect,afLightDir[1]),9));
}
return OUT;
}
float4 DefaultPShaderSpecular_PS20_D1(VS_OUTPUT IN) : COLOR0
{
float4 OUT = float4(0.0f, 0.0f, 0.0f, 1.0f);
float3 Normal = normalize(IN.Normal);
float3 ViewDir = normalize(IN.ViewDir);
{
float L1 = dot(Normal,afLightDir[0]);
float3 Reflect = reflect (Normal,afLightDir[0]);
OUT.rgb += afLightColor[0] * ((L1) + pow(dot(Reflect,ViewDir),9));
}
return OUT;
}
float4 DefaultPShaderSpecular_PS20_D2(VS_OUTPUT IN) : COLOR0
{
float4 OUT = float4(0.0f, 0.0f, 0.0f, 1.0f);
float3 Normal = normalize(IN.Normal);
float3 ViewDir = normalize(IN.ViewDir);
{
float L1 = dot(Normal,afLightDir[0]);
float3 Reflect = reflect (Normal,afLightDir[0]);
OUT.rgb += afLightColor[0] * ((L1) + pow(dot(Reflect,ViewDir),9));
}
{
float L1 = dot(Normal,afLightDir[1]);
float3 Reflect = reflect (Normal,afLightDir[1]);
OUT.rgb += afLightColor[1] * ((L1) + pow(dot(Reflect,ViewDir),9));
}
return OUT;
}
technique DefaultFXSpecular_D1
{
pass p0
{
CullMode=none;
PixelShader = compile ps_3_0 DefaultPShaderSpecular_D1();
VertexShader = compile vs_3_0 DefaultVShader();
}
};
technique DefaultFXSpecular_D2
{
pass p0
{
CullMode=none;
PixelShader = compile ps_3_0 DefaultPShaderSpecular_D2();
VertexShader = compile vs_3_0 DefaultVShader();
}
};
technique DefaultFXSpecular_PS20_D1
{
pass p0
{
CullMode=none;
PixelShader = compile ps_2_0 DefaultPShaderSpecular_PS20_D1();
VertexShader = compile vs_2_0 DefaultVShader();
}
};
technique DefaultFXSpecular_PS20_D2
{
pass p0
{
CullMode=none;
PixelShader = compile ps_2_0 DefaultPShaderSpecular_PS20_D2();
VertexShader = compile vs_2_0 DefaultVShader();
}
};[/source]

Share this post


Link to post
Share on other sites
Rectangle    161
Well after a lot of searching, I came across this post: http://www.gamedev.net/topic/400760-efffects-and-bad-ptr/

Turns out, it's supposed to be a <bad ptr>? Either way, passing the handle into [i]SetTechnique()[/i] seems to return S_OK, so I can assume that all is well afterall.

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