Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Can I reuse the Maya stock shaders?

Can I reuse the Maya stock shaders?

haggi_master
Advocate Advocate
1,094 Views
5 Replies
Message 1 of 6

Can I reuse the Maya stock shaders?

haggi_master
Advocate
Advocate

Hi,

with the shaderManager I can load a Maya stock shader, e.g. the k3dThickLineShader, and write the source to file.

 

import maya.api.OpenMayaRender as om
shaderM = om.MRenderer.getShaderManager()
shader = shaderM.getStockShader(omr.MShaderManager.k3dThickLineShader)
shader.writeEffectSourceToFile("C:/data/k3dThickLineShader.txt") 

Can I somehow reuse this shader? Loading as  a effects file shader with shaderManager->getEffectsFileShader() failed.

My goal is to modify it a little bit or write my own one based on a stock shader and use it in my subSceneOverride.

0 Likes
Accepted solutions (1)
1,095 Views
5 Replies
Replies (5)
Message 2 of 6

cheng_xi_li
Autodesk Support
Autodesk Support

Hi,

 

I should be working. Have you renamed the file properly and specified technique Main?

 

According to the document,

 

Get a new instance of a shader generated from an effects file stored on disk.

If a file extension is not supplied as part of the file name argument then the following strings are appended to the file name based on the drawing API which is currently being used by the renderer:

  • If the underlying drawing API is OpenGL then ".cgfx" is appended.
  • If the underlying drawing API is DirectX 10 or higher then "10.fx" is appended.
  • If the underlying drawing API is OpenGLCoreProfile then ".ogsfx" is appended.

If you would like to modify the input/output based on the original shader, you could use addInput/OutputFragment.

 

Yours,

Li

0 Likes
Message 3 of 6

haggi_master
Advocate
Advocate

Of course I fogot again to mention that I'm on Maya2015....

 

I exported the stock shader k3dFatPointShader as k3dFatPointShader.cgfx because I use OpenGL profile. Then I tried to load the shader in my geometryOverride with:

MHWRender::MShaderInstance* tstshader = shaderManager->getEffectsFileShader("C:/daten/k3dFatPointShader.cgfx", "Main");

This results in a nullpointer what means it didn't work.  I attached the gl code just in case I'm completly misunderstand the whole system.

0 Likes
Message 4 of 6

cheng_xi_li
Autodesk Support
Autodesk Support

Hi haggi,

 

It is just filename without extension.

 

MHWRender::MShaderInstance* tstshader = shaderManager->getEffectsFileShader("C:/daten/k3dFatPointShader", "Main");

And the filename should be k3dFatPoingShader.cgfx.

 

As the document indicates, if you are starting Maya in OpenGL (Should be OpenGL Legacy in latest Maya), it will append .cgfx to the path. 

 

Yours,

Li

0 Likes
Message 5 of 6

haggi_master
Advocate
Advocate

Okay, I changed the code to:

	MStatus status = shaderManager->addShaderPath("C:/daten/");
	MHWRender::MShaderInstance* tst = shaderManager->getEffectsFileShader("k3dFatPointShader", "Main");

But in the docs I can read (Maya2015): If a file extension is not supplied as part of the file name ...

So it doesn't matter if I add an extension or not. And it still does not work. Would be nice if this would be possible. If I have a closer look at the source code I get out of maya it seems to be quite different from a usual cgfx code. Maybe that's the reason.

 

0 Likes
Message 6 of 6

haggi_master
Advocate
Advocate
Accepted solution

Okay, it seems I could find a way to make my own cgfx shader. Unfortunately the code written by the mentioned commands above seems not to be in the usual cgfx format, maybe there are missing some include files.

 

To answer my own question: No, we cannot directly reuse the code exported from the script above. And I was unable to find the source code of the stock shaders anywhere in the maya installation. It could be a good idea to place the sources somewhere in the examples to let the developers see what's possible.

0 Likes