0
\$\begingroup\$

MSDN has an example of a custom HLSL effect importer and processor. Here is the importer's code:

public override PSSourceCode Import(string filename, 
    ContentImporterContext context)
{
    string sourceCode = System.IO.File.ReadAllText(filename);
    return new PSSourceCode(sourceCode, System.IO.Path.GetFileNameWithoutExtension(filename));
}

In the processor they do this:

    EffectContent effectSource = new EffectContent();
    effectSource.EffectCode = input.SourceCode;
    EffectProcessor processor = new EffectProcessor();
    compiledEffect = processor.Process(effectSource, context);

The sample works okay, however, when you try to import and process an effect file that has #include "otherEffect.fx" directive in it, the build process throws an error "Failed to open source file 'otherEffect.fx'". I presume that is because the relative path of the file is not specified correctly but I don't know where to specify it. Does anyne know this?

\$\endgroup\$
1
\$\begingroup\$

For those having the same trouble, you should add two lines in the processor:

EffectContent effectSource = new EffectContent();
effectSource.EffectCode = input.SourceCode;
//Add these two lines:
effectSource.Identity = new ContentIdentity();
effectSource.Identity.SourceFilename = input.name;
//End of correction
EffectProcessor processor = new EffectProcessor();
compiledEffect = processor.Process(effectSource, context);
|improve this answer|||||
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.