Sign in to follow this  

Effect files:

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

I've built a program that exports files from a custom type into x files, but some of the data is a bit tricky to display unless you know the render states, so I want to use fx files to do that. I read that effect data can also be stored in x files and would prefere to use this method, but it looks like the x files only store references to an fx file like it would with the textures. Is that true or is there a way to have the x files store all the render state information? I've been trying to store this info in an fx file and have the x file (the mesh) have all the info it needs to make use of the effects, but most of the examples I've seen are either a lot more complicated than I need right now or don't explain what is being done. I want to use the same render states for all of the mesh, but I'd also prefer if the user didn't need to know what's in the fx file and that programs (or as many as possible) could figure out what do do with it ar runtime.
D3DDevice.RenderState.AlphaTestEnable = true;
D3DDevice.RenderState.AlphaFunction = Compare.Greater;
D3DDevice.RenderState.ReferenceAlpha = 0xA0;
D3DDevice.RenderState.ColorVertex = true;
D3DDevice.RenderState.Lighting = false;
D3DDevice.RenderState.AmbientMaterialSource = ColorSource.Color1;
D3DDevice.SetTextureStageState(
   0, TextureStageStates.ColorOperation, (int)TextureOperation.Modulate4X
);
So I'm looking for a simple example of an fx file, but one that can be loaded by programs that don't have any prior knowledge on what's in the file. I think I've seen that it can be done, but havn't found any simple enough examples.

Share this post


Link to post
Share on other sites
Heres a quick conversion to an FX file, but it is meant just as a sample. I'd appreciate it if you understand the code before copying and pasting it, if that's what you intend to do.


technique textured
{
pass p0
{
AlphaTestEnable = true;
AlphaFunc = Greater;
AlphaRef = 0xA0;
ColorVertex = true;
Lighting = false;
AmbientMaterialSource = Color1;
ColorOp[0] = Modulate4x;
}
}




Hope this helps.

Share this post


Link to post
Share on other sites
I actually got the same thing when I spent a bit longer researching (it seemed more complicated than it was). This at least confirms I got the first part right, however there's still one other problem. I need it to be SAS complient. The mesh viewer that came with DirectX 9 and 10 gives me this:

"SAS: 'File:C:\Program Files\Meshes\SoulReaver1Room.fx' - Global parameter not found. Effect is not SAS-compliant."

I've used this when saving my meshes:

EffectInstance[] effects = new EffectInstance[D3DMaterials.Length];
EffectDefault[] defaults = new EffectDefault[1];
defaults[0] = new EffectDefault();
for (UInt16 e = 0; e < D3DMaterials.Length; e++)
{
effects[e] = new EffectInstance();
effects[e].EffectFilename = "SoulReaver1Room.fx";
effects[e].SetDefaults(defaults);
}


Do I need to store a blank default even though I havn't added any parameters to the effects file or am I missing something?

EDIT:
The old MeshView utility that came with DirectX 8 seems to load the mesh and the fx file pretty well. All the lighting is there that wasn't showing up before I introduced the fx file, but the textures themselves don't seem to show up. I don't suppose you know if that will be something I can fix by changing my fx file or if it's that the application doesn't use textures and effects at the same time.

[Edited by - CodeReaver on September 28, 2006 8:05:48 PM]

Share this post


Link to post
Share on other sites
I added a few more settings (the SasGlobal stuff) to my effects file and added in a few lines at the beginning to make the fx file SAS complient. The DirectX viewer recognised the file once I'd added that, but nothing was being rendered. Do I need to add something else?

The object is rendered properly in MeshView except that the textures don't get used. From what I read on msdn, I assumed that I should one EffectInstance for each material and that each subset would use the texture and lighting from it's corresponding material and the effect from the same position in the EffectInstance array, but MeshView just seems to use the first effect for all subsets and ignores the information in the materials. I tried using a texture parameter (which I since commented out) in the effect defaults stored in the x file, but then all subsets use the first texture. Is there any way I can fix it by changing the fx file or is the problem down to how MeshView was coded?

int global : SasGlobal
<
bool SasUiVisible = false;
int3 SasVersion = {1,0,0};
>;

// texture texture0;

technique SoulReaver1Room
{
pass p0
{
// Texture[0] = <texture0>;
Lighting = FALSE;
ColorVertex = TRUE;
CullMode = NONE;
ZEnable = TRUE;
ZWriteEnable = TRUE;
DitherEnable = TRUE;
SpecularEnable = FALSE;
NormalizeNormals = TRUE;
AlphaTestEnable = TRUE;
AlphaFunc = GREATER;
AlphaRef = 0xA0;
ColorOp[0] = MODULATE4X;
ColorArg1[0] = TEXTURE;
ColorArg2[0] = CURRENT;
AlphaOp[0] = MODULATE;
AlphaArg1[0] = TEXTURE;
AlphaArg2[0] = DIFFUSE;
MagFilter[0] = LINEAR;
MinFilter[0] = LINEAR;
AmbientMaterialSource = COLOR1;
}
}


EDIT: Looks like I was just saving the default parameters incorrectly in the mesh file. It works with MeshView now, so the only problem now is the SAS compliance stuff.

[Edited by - CodeReaver on September 29, 2006 6:32:11 PM]

Share this post


Link to post
Share on other sites

This topic is 4095 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.

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