Sign in to follow this  
Njguy

Use default material help

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
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
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

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