PDA

View Full Version : Mentalray shader writing web resources


DSedov
09-11-2005, 05:48 PM
Are there any web tutorials or resources about writing shaders for MR?

Pixero
09-11-2005, 06:17 PM
Here are some links to get you started:

http://www.nanomation.co.uk/Programming-101.html (http://www.nanomation.co.uk/Programming-101.html)
http://www.nanomation.co.uk/Programming-102.html (http://www.nanomation.co.uk/Programming-102.html)
http://www.play.org/articles/XSI+MentalRayCustomShader.html (http://www.play.org/articles/XSI+MentalRayCustomShader.html)
http://www.arts.arizona.edu/christensen/programming/mraynotes/index.html (http://www.arts.arizona.edu/christensen/programming/mraynotes/index.html)

There also was a great site called Mentalray Primer with info that got me started. Unfortunally its no longer online. I have most of it saved in a zip file here: http://www.pixero.com/stuff/Mentalray_Primer.zip (http://www.pixero.com/stuff/Mentalray_Primer.zip)

Also take a look at the source code for the MR base shaders. You can find them at mentalimages: ftp://ftp.mentalimages.com/data/pub/shaders/ (ftp://ftp.mentalimages.com/data/pub/shaders/)

DSedov
09-11-2005, 07:42 PM
Thanks alot, thats actually a good start =)

brogh
09-12-2005, 12:23 AM
http://www.uni-duesseldorf.de/URZ/hardware/parallel/local/softimage/Soft3D_html/mray/_mefirst.htm

DSedov
09-12-2005, 08:36 AM
Just wanted to see if it works and made a very simple shader. It compiles fine, loads in maya but during render it sais this:

-----
API 0.0 warn 302004: C:\Program Files\Alias\Maya6.0\mentalray/include/fl_shaders.mi, line 108: while defining declaration "fl_color": declaring nonexisting function fl_color
PHEN 0.2 error 051011: shader "fl_color" not found
-----

Here is what my mi and dll look like:

-- fl_color.mi --
declare shader
color "fl_color" (
color "color",
)
version 2
apply material
end declare
-- fl_color.mi --





-- fl_color.cpp --
#include <stdio.h>
#include <math.h>
#include <shader.h>

typedef struct {
miColor color;
} fl_color_t;
DLLEXPORT int fl_color_version(void) {return(2);}
DLLEXPORT miBoolean fl_color_init(
miState *state,
fl_color_t *param,
miBoolean *init_req)
{
if (!param) {
/* shader init */
*init_req = miTRUE; /* do instance inits */
} else {
/* shader instance init */
}
return(miTRUE);
}
DLLEXPORT miBoolean fl_color_exit(
miState *state,
fl_color_t *param)
{
if (param) {
/* shader instance exit */
} else {
/* shader exit */
}
return(miTRUE);
}
DLLEXPORT miBoolean fl_color(
miColor *result,
miState *state,
fl_color_t *param)
{


result->r = param->color.r;
result->g = param->color.g;
result->b = param->color.b;
result->a = param->color.a;
return(miTRUE);
}

-- fl_color.cpp --

-- maya.rayrc --
registry "{MAYABASE}" value "C:\Program Files\Alias\Maya6.0\mentalray" end registry
registry "{SYSTEM}" value "windows" end registry
registry "{DSO}" value "dll" end registry
$lookup "{MAYABASE}"
$lookup "{SYSTEM}"
$lookup "{DSO}"
registry "{MRMAYA_START}"
link "{MAYABASE}/lib/base.{DSO}"
link "{MAYABASE}/lib/physics.{DSO}"
link "{MAYABASE}/lib/mayabase.{DSO}"
link "{MAYABASE}/lib/contour.{DSO}"
link "{MAYABASE}/lib/Dirtmap.{DSO}"
link "{MAYABASE}/lib/lm_2DMV.{DSO}"
link "{MAYABASE}/lib/fl_shaders.{DSO}"
mi "{MAYABASE}/include/mayabase.mi"
mi "{MAYABASE}/include/base.mi"
mi "{MAYABASE}/include/physics.mi"
mi "{MAYABASE}/include/contour.mi"
mi "{MAYABASE}/include/Dirtmap.mi"
mi "{MAYABASE}/include/lm_2DMV.mi"
mi "{MAYABASE}/include/fl_shaders.mi"

echo "mental ray for Maya - startup done"
end registry
$lookup "{MRMAYA_START}"

Puppet|
09-13-2005, 07:11 AM
If you use C++ you should use extern "C" for your functions.

"result->r = param->color.r;" - it's wrong.
You should use mi_eval_color() function for eval color value.

Try this code...

#include <math.h>
#include <shader.h>
typedef struct {
miColor color;
} fl_color_t;

extern "C"
{
DLLEXPORT int fl_color_version(void) {return(2);}
DLLEXPORT miBoolean fl_color(miColor *result, miState *state, fl_color_t *param)
{
*result = *mi_eval_color(&param->color);
return(miTRUE);
}
}

DSedov
09-13-2005, 09:03 AM
Works now. Thanks alot!!!.

mybe you know what do do with this problem? =)

http://forums.cgsociety.org/showthread.php?t=276559


If you use C++ you should use extern "C" for your functions.

"result->r = param->color.r;" - it's wrong.
You should use mi_eval_color() function for eval color value.

Try this code...

CGTalk Moderation
09-13-2005, 09:03 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.