• Advertisement
Sign in to follow this  

Use default material help

This topic is 3379 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

Im trying to load effects in my material system, but the application runs through the materials and will return an error message for every material that does not have an effect. So basically I'm trying to get the app to use the default material if an effect is not specified. Somethign liek this
// Load the effect file.
	ID3DXBuffer *errorBuffer = NULL;
	HRESULT result = D3DXCreateEffectFromFile( g_engine->GetDevice(), script->GetStringData( "effect" ), NULL, NULL, 0, NULL, &m_effect, &errorBuffer );
	if( script->GetStringData( "effect" ) == NULL ) 
	{
	// No valid effect for this material.  Use the default.
            
	
}
	else
		if( result != D3D_OK ){
		const char *error = NULL;
	if( errorBuffer )
      error = (const char*)errorBuffer->GetBufferPointer();
	else
      error = "Error loading effect file.";
	MessageBox( NULL, error, "Error", MB_OK ); // Display any errors.
	} 
I left it blank because I really dont even know how to proceed. Any ideas?

Share this post


Link to post
Share on other sites
Advertisement
You could just create a default fx and load it when none is specified. I'm probably missing something because I don't see the problem :
filename = script->GetStringData( "effect" );
if(filename == NULL)
filename = "default.fx";

ID3DXBuffer *errorBuffer = NULL;
HRESULT result = D3DXCreateEffectFromFile( g_engine->GetDevice(), filename, NULL, NULL, 0, NULL, &m_effect, &errorBuffer );
if( result != D3D_OK )
{
const char *error = NULL;
if( errorBuffer )
error = (const char*)errorBuffer->GetBufferPointer();
else
error = "Error loading effect file.";
MessageBox( NULL, error, "Error", MB_OK ); // Display any errors.
}

Share this post


Link to post
Share on other sites
I guess that could work, i know that directx had a default material somewhere. Its what the directx viewer uses if you don't specify a material.

Share this post


Link to post
Share on other sites
What kind of identifier would filename use, everything I use doesn't work. i'm started to get frustrated.

[Edited by - Njguy on November 23, 2008 12:36:24 PM]

Share this post


Link to post
Share on other sites
never mind its char * filename

I feel like an idiot now. Thanks though

Share this post


Link to post
Share on other sites
ok the good news is that, the scene loaded. The bad news is that it did not apply the effect. (Which is better than what I expected it to do). There are so many reasons for it not to apply , I do not really know where to start. Im surprised, that I didn't get an error message I haven't specified the effect constants. Is there a way for an application not automatically detect the effect file's constants and load them? Am I being clear?

Share this post


Link to post
Share on other sites
You can assign default values to your parameters in the effect file itself. If you want to automatically set parameters like the WorldViewProj matrix, you can use semantics. Give your parameters a semantic, then in your app you read the parameters description (D3DXPARAMETER_DESC). It holds the parameter name, semantic, type, class, bytecount, etc. That should be enough to set common parameters.

You can also add annotations in your effects : annotations contain a default value, but it wont initialize the object. But you can read it back in your application so you know how to set the parameter.

PS: I would use a std::string for the filename, and filename.c_str() in functions that need a const char pointer;

Share this post


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

  • Advertisement