Sign in to follow this  
JulianMcKinlay

OpenGL Errors compiling CgFX effects using Direct3D9 .FX States

Recommended Posts

Hello,

I have recently begun using Cg and CgFX and have read through most of the Cg Tutorial book available at the nVidia Developer Zone. I am specifically interested in migrating an existing rendering effect system that uses Direct3D 9's .FX effect file format to Cg's .CgFX file format to increase portability, as CgFx is compatible with both Direct3D and OpenGL. CgFX seems well suited as according to the Cg Tutorial, it is "identical" to Direct3D 9's .FX file format. This is exactly what I need, as it will save me the effort of re-writing all of my effect scripts.

Unfortunately, my effect scripts are not compiling under Cg, and I am beginning to doubt that .CgFX and .FX are identical. Consulting the documentation, there seem to be places where the DirectX convention is used, such as with the "CullMode" state, which accepts the DirectX enumerants "None", "CW", "CCW", and other times where some other convention is used, such as with the "DiffuseMaterialSource" state that only appears to accept the enumerants "true" and "false". (Whatever that means.)

I am looking for a definitive answer: Should I expect to be able to compile under Cg any .FX script that compiles successfully under Direct3D 9? If so, what do I have to do to make this possible?

Here is an example to illustrate the problem.

My .CgFX effect, the contents of which compile successfuly as a DirectX .FX effect file under Direct3D 9:[code]technique Default
{
pass P0
{
Lighting = False;
CullMode = None;

AmbientMaterialSource = Color1;
DiffuseMaterialSource = Color1;
SpecularMaterialSource = Material;
EmissiveMaterialSource = Material;

LightEnable[0] = True;
LightType[0] = Directional;
LightDirection[0] = float3(0.0f, 1.0f, 0.0f);
LightAmbient[0] = float4(0.1f, 0.1f, 0.1f, 1.0f);
LightDiffuse[0] = float4(1.0f, 0.0f, 0.0f, 1.0f);
LightSpecular[0] = float4(1.0f, 1.0f, 1.0f, 1.0f);

MagFilter[0] = Linear;
MinFilter[0] = Linear;
MipFilter[0] = Linear;

AddressU[0] = Clamp;
AddressV[0] = Clamp;

VertexShader = null;
PixelShader = null;
}
}[/code]


My set up code, which initializes Cg and loads the effect:
[code]CGcontext cgContext = cgCreateContext();
cgD3D9RegisterStates(cgContext);
CGeffect cgEffect = cgCreateEffect(cgContext, "Data/Effects/Default.cgfx", nullptr);[/code]


The errors that are reported when trying to compile the effect in the code above:
[code]error C1056: invalid initialization
error C1008: undefined variable "Color1"
error C1008: undefined variable "Color1"
error C1008: undefined variable "Material"
error C1008: undefined variable "Material"
error C1008: undefined variable "Directional"
error C1056: invalid initialization
error C1008: undefined variable "Linear"
error C1008: undefined variable "Linear"[/code]

The Cg effect compiler is recognizing some of the Direct3D .FX script state enumerants, but not all of them. Why?

I would greatly appreciate any help with this problem.

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