CgFx support in OGRE

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

CgFx support in OGRE

Post by Assaf Raman »

I have been working on a new nun-roadmap feature - support for CgFx.
First of all let me explain the need as I see it - every time I create a shader in a shader creation tool like Render Monkey or FXComposer or mental mill - it takes me a long time to translate it to files that will work with OGRE - material, program, *.cg and such. Moreover - my help is always needed when I work with my artist - I would love it - if my artist will be able to create the shader\ material with mental mill graphically - then export to CgFx - then simply use in the application. Moreover - he will be able to work with mental mill open on one window and my application on a different window and just save from mental mill and reload the resources.

I am writing the code as part of the cg plugin.

I need the other OGRE team members to approve before I will commit this code (to 1.8 ).
Last edited by Assaf Raman on Tue Sep 23, 2008 6:57 pm, edited 6 times in total.
Watch out for my OGRE related tweets here.

User avatar
Praetor
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3335
Joined: Tue Jun 21, 2005 8:26 pm
Location: Rochester, New York, US
x 3
Contact:

Post by Praetor »

My first reaction is that maybe this should be an addon project. But then thinking about it, CgFX is a big part of Cg now. It really is meant to go as a package, even if you can easily use Cg without it. Since the Cg support is already an optional plugin, I think CgFX is a great addition to that system.

User avatar
Praetor
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3335
Joined: Tue Jun 21, 2005 8:26 pm
Location: Rochester, New York, US
x 3
Contact:

Post by Praetor »

I wonder if this would bring up the question of whether to directly support .fx files through the DirectX render systems. It would certainly be the case of one render system having features another doesn't, which I agree is not a good idea, but perhaps this is justifiable? Though I must say I'm rather partial to Ogre's material system. But then, I'm surely biased.

I think the main motivation here is tool support, correct?

Tenttu
Halfling
Posts: 74
Joined: Mon Dec 13, 2004 1:56 pm

Post by Tenttu »

I've been planning to implement cgfx support at some point if it's not done before that. Haven't written any code for it, but I did look into ways of implementing it.

I would definitely like to have it with Cg plugin, or as a separate plugin, not as addon. Because the .fx pipeline is very important on current generation applications and there are lots of applications that support cgfx authoring.

Other than that, the cgfx also does support features and concepts that are not possible with current material scripting.

User avatar
sparkprime
Ogre Magi
Posts: 1137
Joined: Mon May 07, 2007 3:43 am
Location: Ossining, New York
x 13
Contact:

Post by sparkprime »

Tenttu wrote: Other than that, the cgfx also does support features and concepts that are not possible with current material scripting.
I've not used cgfx but maybe you could elaborate on that as it sounds interesting?

User avatar
zarthrag
Greenskin
Posts: 128
Joined: Sat Jul 24, 2004 9:07 am
Location: Tulsa, Oklahoma

Post by zarthrag »

So CgFx is D3D only?
ZarthCode LLC

User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Post by Assaf Raman »

Both opengl and D3D.
Watch out for my OGRE related tweets here.

User avatar
syedhs
Silver Sponsor
Silver Sponsor
Posts: 2702
Joined: Mon Aug 29, 2005 3:24 pm
Location: Kuala Lumpur, Malaysia
x 47

Post by syedhs »

Needless to say, this is a very cool feature! Cg OGRE plugin IMO is the best place - plus the plugin is still very slim so adding a few features inside it make it 'more complete'.
Assaf Raman wrote: I need the other OGRE team members to approve before I will commit this code (to 1.8 ).
You mean it has been completed?
A willow deeply scarred, somebody's broken heart
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me

User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Post by Assaf Raman »

syedhs wrote:
Assaf Raman wrote: I need the other OGRE team members to approve before I will commit this code (to 1.8 ).
You mean it has been completed?
Near complete, I posted so I will have this approved by the time I will finish. I will post all the code in this thread as a patch later today (This is always a good stage before committing).
Watch out for my OGRE related tweets here.

User avatar
xadhoom
Minaton
Posts: 973
Joined: Fri Dec 28, 2007 4:35 pm
Location: Germany
x 1

Post by xadhoom »

I would appreciate this functionality, too. This really allows a fast pipeline!

User avatar
SiENcE
Goblin
Posts: 231
Joined: Thu May 11, 2006 3:07 pm
Location: Berlin
Contact:

Post by SiENcE »

Is it possible to link against CgFX with all compiler (esp. MingW)?

User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Post by Assaf Raman »

Why not?
Watch out for my OGRE related tweets here.

User avatar
cdleonard
Goblin
Posts: 266
Joined: Thu May 31, 2007 9:45 am

Post by cdleonard »

I don't understand exactly what this plugin would do. Isn't CgFX basically another complete way to define materials? Does this plugin map CgFX to an Ogre::Material or skip ogre materials completely? And what happens to stuff like light iteration from Ogre passes?

User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Post by Assaf Raman »

This plugin map CgFX to an Ogre::Material.
Watch out for my OGRE related tweets here.

User avatar
SiENcE
Goblin
Posts: 231
Joined: Thu May 11, 2006 3:07 pm
Location: Berlin
Contact:

Post by SiENcE »

I mean, does it only need the the cg.dll and cg header files or one of the other cg dlls too?

User avatar
syedhs
Silver Sponsor
Silver Sponsor
Posts: 2702
Joined: Mon Aug 29, 2005 3:24 pm
Location: Kuala Lumpur, Malaysia
x 47

Post by syedhs »

I guess the Ogre specific material stuff will not be applicable in this area which is fair enough for me. But probably in the future, you can combine cgfx with ogre material but that is for future, I guess :)
A willow deeply scarred, somebody's broken heart
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me

User avatar
cdleonard
Goblin
Posts: 266
Joined: Thu May 31, 2007 9:45 am

Post by cdleonard »

Assaf Raman wrote:This plugin map CgFX to an Ogre::Material.
So it will be an alternative syntax to declare Ogre::Materials; one with better tool support. This is interesting and could be very useful.

User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Post by Assaf Raman »

SiENcE wrote:I mean, does it only need the the cg.dll and cg header files or one of the other cg dlls too?
No other.
Watch out for my OGRE related tweets here.

User avatar
Brocan
Orc
Posts: 441
Joined: Tue Aug 01, 2006 1:43 am
Location: Spain!!
x 8

Post by Brocan »

This would be great :D .

User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Post by Assaf Raman »

Here is what I have so far, I wrote most of the code of this project, well, most of the hard code at least. I created all the major enums (about 40) and most of the translation tables between strings and enums. The code declares all the needed cg states so the cgfx loads without an error.

What mostly is missing are translation tables between ogre enums \ material states and cgfx state values.

I am posting the code; it has about 4000 new lines of code.

I hope I will have time soon to finish this. Feel free to pick up were I left or post any ideas\remarks.

Here it is: updated CgProgramManager.zip

[EDIT] Best to get the latest code from the SVN.[/EDIT]
Last edited by Assaf Raman on Tue Sep 23, 2008 3:32 pm, edited 1 time in total.
Watch out for my OGRE related tweets here.

User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19265
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

Cool - conversion support for .fx to .material is something I've wanted for a while just for convenience. Not a core thing, but putting it in the Cg plugin makes sense.

Good move on making it a ScriptLoader so you don't have to link to the plugin.

It's nice to support .fx, the only issue is that .fx doesn't support all the things that .material does, it might be nice to have a way to batch convert .fx instead, should you want to edit the results (without linking to the plugin so you can use the listener). But of course that would break the round-trip if the artist went back to FXComposer etc so it has its downsides.

Ideally I'd like to write a plugin for FXComposer or something sometime, I believe you can expose extra properties there.

User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Post by Assaf Raman »

I hope I will have some time next week to work on this. I will commit when I will have something working.
Watch out for my OGRE related tweets here.

User avatar
SiENcE
Goblin
Posts: 231
Joined: Thu May 11, 2006 3:07 pm
Location: Berlin
Contact:

Post by SiENcE »

Hi,

I tested it with the 1.6 branch and it also works to compile.
Nice idea to to speed up development.

regards
Last edited by SiENcE on Tue Sep 23, 2008 8:27 am, edited 1 time in total.

User avatar
Brocan
Orc
Posts: 441
Joined: Tue Aug 01, 2006 1:43 am
Location: Spain!!
x 8

Post by Brocan »

Some code snippet about how it works? :D

User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Post by Assaf Raman »

This doesn't work yet.
I hope I will post something working soon.
I am almost there in getting some basic samples working.
Watch out for my OGRE related tweets here.

Post Reply