Jump to content
  • Advertisement
Sign in to follow this  
Claudio

ID3DXMesh and ID3DXEffect

This topic is 3264 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. The DirectX version is DirectX 9. I've two virtual objects in the scene they are defined as ID3DXMesh. The problem is: how can I associate the effect Shader1.fx to the first object and Shader2.fx to the second object ? Someone can help me ?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Claudio
Hi.

The DirectX version is DirectX 9.

I've two virtual objects in the scene they are defined as ID3DXMesh.

The problem is:
how can I associate the effect Shader1.fx to the first object and Shader2.fx to the second object ?

Someone can help me ?


I've to create two ID3DXEffect variables:

ID3DXEffect* D3DEffectObject1 = NULL; // D3DEffect file 1
ID3DXEffect* D3DEffectObject2 = NULL; // D3DEffect file 2



and then I can associate the two effect file to the D3DDevice "D3DDev":


D3DXCreateEffectFromFile(D3DDev, NameFile_OfEffect1.fx, NULL, NULL, 0, NULL, &D3DEffectObject1, NULL);

D3DXCreateEffectFromFile(D3DDev, NameFile_OfEffect2.fx, NULL, NULL, 0, NULL, &D3DEffectObject2, NULL);



where "NameFile_OfEffect1.fx" and "NameFile_OfEffect2.fx" are the two files of the two considered effect files.

This could be a part of the solution of my problem ?

But now how could associate "D3DEffectObject1" to the first virtual object "D3DMeshObject1" and "D3DEffectObject2" to the second virtual object "D3DMeshObject2" ?

I'm using "D3DMeshObject1->DrawSubset(0)" for drawing the first virtual object and "D3DMeshObject2->DrawSubset(0)" for drawing the second virtual object.


Share this post


Link to post
Share on other sites
Take a look at the BasicHLSL example in the SDK, particularly the OnFrameRender() routine in BasicHLSL.cpp. That does exactly what you're asking about.

I don't post an example here because there is a lot of code associated with getting the effect set up properly - getting parameter handles, handling OnResetDevice, etc. The example I cited should provide you with a lot of guidance.

Work through that example and see if you have further questions.

Share this post


Link to post
Share on other sites
Quote:
Original post by Buckeye
Take a look at the BasicHLSL example in the SDK, particularly the OnFrameRender() routine in BasicHLSL.cpp. That does exactly what you're asking about.


Hi.

Thanks.

I've looked the code about the routine "OnFrameRender(..., ..., ...)" of the sample BasicHLSL of SDK but it's not more clear for my problem.

In the two files "*.fx", I've only one tecnique.

Share this post


Link to post
Share on other sites
Quote:
In the two files "*.fx", I've only one tecnique.

Are you concerned that the techniques have the same name or that the techniques are the same?

If you have 2 separate effects and files, it doesn't matter if they use the same technique name, or that the techniques are identical, for that matter.

FYI - objects aren't "associated" with an effect. You can render any mesh you want with any effect, provided that the parameters are compatible.

Share this post


Link to post
Share on other sites
As Buckeye said, you can just keep two ID3DXEffect *pFX variables and then use the GetTechnique() method to get a handle to the desired technique from .fx1 or .fx2 and then just use either pFX1 or pFX2 as desired.

Share this post


Link to post
Share on other sites
Hi.

In each effect files, there are only one technique with the same name.

My solution is considered only one effect file for each virtual object, where the two effect file are associated to the D3D device.


hRes = D3DDev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xAABBCCDD, 1.0f, 0); // celestino scuro 0xAABBCCDD

// // // set index buffer and vertex declaration: // // //
hRes = D3DDev->SetIndices(D3DIB);
if (FAILED(hRes)) return hRes;

hRes = D3DDev->SetVertexDeclaration(D3DVD);
if (FAILED(hRes)) return hRes;

// // // visual rendering: // // //
hRes = D3DDev->BeginScene();

// // // // first virtual object: visual rendering: // // // //
#ifdef _EFFECT_DEFINED
unsigned int PassesObject1;
D3DEffectFile1->Begin(&PassesObject1, 0);
for (unsigned int i = 0; i < PassesObject1; i++)
{
D3DEffectFile1->BeginPass(i);
#endif
// here is the true rendering !!!
hRes = D3DMeshObject1->DrawSubset(0);
#ifdef _EFFECT_DEFINED
D3DEffectFile1->EndPass();
} // for (unsigned int i = 0; i < PassesObject1; i++)
D3DEffectFile1->End();
#endif

// // // // Second virtual object: visual rendering: // // // //
#ifdef _EFFECT_DEFINED
unsigned int PassesObject2;
D3DEffectFile2->Begin(&PassesObject2, 0);
for (unsigned int i = 0; i < PassesObject2; i++)
{
D3DEffectFile2->BeginPass(i);
#endif
// here is the true rendering !!!
hRes = D3DMeshObject2->DrawSubset(0); // draw the second object

#ifdef _EFFECT_DEFINED
D3DEffectFile2->EndPass();
} // for (unsigned int i = 0; i < PassesObject2; i++)
D3DEffectFile2->End();
#endif


// // // text rendering: // // //
TextRendering(); // writing to the screen the various string

hRes = D3DDev->EndScene();

hRes = D3DDev->Present(NULL, NULL, NULL, NULL);



It can be a right solution ?

If yes, can I make a simple optimization on the above code ?

Share this post


Link to post
Share on other sites
That *could* be a correct solution but you can also replace the preprocessor conditional with a normal conditional and use either or both D3DEffectFiles to render with based on a flag (which you could then control with a keypress for example).

I'm assuming that D3DEffectFile1 and D3DEffectFile2 are of LPD3DXEffect type (or ID3DXEffect *)?

I also assume that when you load/create each effect you already set the technique?

Maybe you could also show us your effect initialization code and the way you declare the two variables?

Share this post


Link to post
Share on other sites
Quote:
Original post by Steve_Segreto
I'm assuming that D3DEffectFile1 and D3DEffectFile2 are of LPD3DXEffect type (or ID3DXEffect *)?

I also assume that when you load/create each effect you already set the technique?

Maybe you could also show us your effect initialization code and the way you declare the two variables?


Hi.

I've not set the technique of the two file with extension "*.fx". There is only one technique in both two files "*.fx".

The initialization is at the top of this post, where:
D3DEffectFile1 is called D3DEffectObject1
and D3DEffectFile2 is called D3DEffectObject2.

Share this post


Link to post
Share on other sites
Oops sorry, yes I see your declaration and effect creation. :)

Well then yes your solution would work but you have to rebuild your project to switch effects is that what you want?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!