Skip to main content
gamedev.net
🔒 Locked

Shader with include files

Started by MrSparkle Aug 28, 2006 at 6:02 PM 3 replies 700+ views
Original Post
MrSparkle
MrSparkle
Hi, I have a shader that uses more than one include file (e.g. #include "shadows.inc") How can I load the shader with DirectX using the Effect.FromFile() function, which only expects *one* include file? Is there a neat trick to do this, or do I have to put all the stuff in one file? Thanks, Christian
circlesoft
circlesoft
I think I understand what you are asking (but not positive). Using #define, you can conditionally compile include statements in and out. For example:

#ifdef INC_SHADOWS   #include "shadows.inc"#endif#ifdef INC_LIGHTING   #include "lighting.inc"#endif


The effect APIs then take an array of define macros. You can set up this array at runtime, depending on what you want to include. If this isn't pertinent to your question, please clarify.
Namethatnobodyelsetook
Namethatnobodyelsetook
The C++ effect loading interface takes an optional ID3DXInclude interface, not a file. I have no idea what C# does.

In C++, you derive a class from the virtual interface it's expecting, filling in the Open and Close functions. The shader compiler will call your Open call whenever it needs to load a new include, and call Close when it's safe to free the memory. One oddity I've noticed is that if you have main.fx, which includes include.fx, the callback is called for main.fx twice, then for include.fx.

I'd assume C# has the same include functionality.
MrSparkle
MrSparkle
For example, I have an shader file "main.fx" that needs two include files, specified by the directives:

#include "quads.fx"
#include "shadow.fx"

The Effect.FromFile() in C# is defined as follows (see here:

public static Effect FromFile(
Device device,
string sourceDataFile,
Include includeFile,
ShaderFlags flags,
EffectPool pool
);

If I can use more than one include files with the Include-Class, I don't know how. It seems that I can only open one file, using the Include.Open() function, but not several includes.

If it's possible, I want to prevent joining the both include files to one file to work with my engine.

Thank you,
Christian
Namethatnobodyelsetook
Namethatnobodyelsetook
The Open function is passed several things. The type of include (quotes or angle brackets), the name, and some pointers. Simply take the name given, find the length of the file, allocate the needed memory, and load the file. When Close is called, you free the memory. If multiple includes are needed, Open is called multiple times with different names.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.