C# Shader Definition

Discussions concerning programming of SOFTIMAGE©
User avatar
TwinSnakes007
Posts: 316
Joined: 06 Jun 2011, 14:00

C# Shader Definition

Post by TwinSnakes007 » 25 Jan 2013, 15:33

Okay, got another mystery for you guys.

Why does a C# Shader definition not load in SI?

In the SDK there is an example included that defines a Shader via C#, I think its called CSShader or something. But SI refuses to load the plugin.

-TS-

User avatar
xsisupport
Posts: 713
Joined: 09 Jun 2009, 09:02
Location: Montreal Canada

Re: C# Shader Definition

Post by xsisupport » 25 Jan 2013, 19:15

TwinSnakes007 wrote:Okay, got another mystery for you guys.

Why does a C# Shader definition not load in SI?

In the SDK there is an example included that defines a Shader via C#, I think its called CSShader or something. But SI refuses to load the plugin.

-TS-
You think it's called CShader? That makes me think you didn't compile it.
// Steve Blair
// "You're not a runner, you're just a guy who runs" -- my wife
//
// My Blogs: Arnold | Softimage

User avatar
TwinSnakes007
Posts: 316
Joined: 06 Jun 2011, 14:00

Re: C# Shader Definition

Post by TwinSnakes007 » 25 Jan 2013, 20:26

Yes, I compiled it, and verified the syntax by removing the call to PluginRegistar.RegisterShader(); If you comment that line from the SDK example, the plugin loads fine (without registering a shader of course).

The project is called CSShaderExample.csproj

Since its included in the SDK, I assumed that shader definition via C# is possible?

User avatar
TwinSnakes007
Posts: 316
Joined: 06 Jun 2011, 14:00

Re: C# Shader Definition

Post by TwinSnakes007 » 25 Jan 2013, 20:53

I've got a huge 3000+ line python file with shader definitions in it, and wanted to refactor that using C#, so I could better manage the body of shaders. I didnt want to use C++, so when I saw the C# SDK example, I thought, that's just perfect. But SI wont load the darn thing.

User avatar
xsisupport
Posts: 713
Joined: 09 Jun 2009, 09:02
Location: Montreal Canada

Re: C# Shader Definition

Post by xsisupport » 25 Jan 2013, 22:56

I turned on Verbose messages and got this when I tried to load that plugin:

Code: Select all

// VERBOSE : 5359 - This plug-in doesn't have the correct entry-point and will be ignored:
// <entry-point requested: XSILoadPlugin>
// <path: C:\Program Files\Autodesk\Softimage 2013 SP1\XSISDK\examples\workgroup\Addons\ShaderDefinitions\cssrc_CSEnvBlur\obj\Release\CSShaderExample.dll>
// 
Edit: that's with Visual C# Express 2010, with or without the call to RegisterShader
// Steve Blair
// "You're not a runner, you're just a guy who runs" -- my wife
//
// My Blogs: Arnold | Softimage

User avatar
TwinSnakes007
Posts: 316
Joined: 06 Jun 2011, 14:00

Re: C# Shader Definition

Post by TwinSnakes007 » 25 Jan 2013, 23:53

Thanks Steve! Cool, I didnt know about verbose messages setting. That will help alot with debugging. I probably wont need a million Info() calls anymore.

I use MSVC 2010 Express as well. SI only works with the .Net 3.5 target. It defaults to 4.0 when you open SDK projects, so you have to manually set the target version in the project settings.

User avatar
TwinSnakes007
Posts: 316
Joined: 06 Jun 2011, 14:00

Re: C# Shader Definition

Post by TwinSnakes007 » 26 Jan 2013, 00:41

So, since I know the RegisterShader call is failing, if I wrap it in a try/catch, the plugin loads fine, and SI "kinda" thinks it a valid Shader. It's listed in the PluginManager as a Shader. But if you try to create it via scripting you get:

Code: Select all

// ERROR : 21000-REND-CreateShaderFromProgID - Unspecified failure
CreateShaderFromProgID("CSShaderExample.CSEnvBlur.1.0", "Sources.Materials.DefaultLib.Scene_Material", null);
// ERROR :  - [line 1]
Now, the SDK says you need two callbacks to register a shader, and those callbacks are there....I just think the signature is not correct somehow (even though it appears to be)

If you add some Info() calls in the code, you can see that the Base constructor is called, then LoadPlugin is called and then it fails on the RegisterShader method invocation, which I assume is because it cant successfully locate and invoke the required DefineInfo & Define methods.

-TS-

User avatar
TwinSnakes007
Posts: 316
Joined: 06 Jun 2011, 14:00

Re: C# Shader Definition

Post by TwinSnakes007 » 28 Jan 2013, 16:56

I emailed ivan @ autodesk and he said they will look into it.

Will post here if/when I hear anything back.

-TS-