Document directory
- 1. Create VC project files
- 5. Modify Maya. env
- 6. Test
Note: a feasible method is provided by referring to the maya2009 document and slightly modifying it. If there are any errors or inappropriate ones, please correct them more. Thank you ~
1. Create VC project files
Create a new mytexture. vcproj according to the configuration of maya2009/devkit/mentalray/docs/writingshaders/mayashaderexample_32bit.vcproj to ensure that the output file is mytexture. dll.
2. mytexture
. C
Add code in mytexture. vcproj (see maya009 document --> Mental Ray for Maya reference
--> Example scene with custom shader
)
------------------------------------------------------------------------------
# Include <stdio. h>
# Include "shader. H"
Struct mytexture
{
Miscalar min;
Miscalar Max;
};
Extern "C" dllexport
Int mytexture_version (void) {return (1 );}
Extern "C" dllexport
Miboolean mytexture (
Micolor * result,
Mistate * state,
Struct mytexture * paras)
{
Mivector VEC;
Miscalar min, Max;
Mi_point_to_object (State, & VEC, & State-> point );
Min = * mi_eval_scalar (& paras-> min );
Max = * mi_eval_scalar (& paras-> MAX );
Result-> r = Vec. x <0? Min: Max;
Result-> G = Vec. Y <0? Min: Max;
Result-> B = Vec. z <0? Min: Max;
Result-> A = 1;
Return (mitrue );
}
------------------------------------------------------------------------------
Note: extern "C" dllexport must be added; otherwise, when rendering with mentalray, the following message is displayed:
Phen 0.3 error 051011: shader "mytexture" not found
3. mytexture
. Mi
Create mytexture. MI in the directory of the same level as mytexture. dll:
------------------------------------------------------------------------------
Min version "3.0.0"
Max version "3.6.99"
Declare shader
Color "mytexture
"(
Scalar "min", #: Default 0.3
Scalar "Max", #: Default 1.0
)
Version 1
# Apply Material
# If you use material
Hypershader --> Create mentalray nodes --> there will be mytexture under material,
#: Nodeid 2007;
End declare
------------------------------------------------------------------------------
4. aemytexture
Template. Mel
Under the directory of the same level as mytexture. dll
Create aemytexture
Template. MEL:
------------------------------------------------------------------------------
Global proc aemytexture
Template (string $ nodename)
{
Editortemplate-beginscrolllayout;
// MIB light attributes
Editortemplate-beginlayout "mytexture attributes"-collapse 0;
Editortemplate-label "min"-addcontrol "min ";
Editortemplate-label "Max"-addcontrol "Max"
Editortemplate-endlayout;
}
------------------------------------------------------------------------------
5. Modify Maya. env
Add the path of mytexture. dll, for example, add:
------------------------------------------------------------------------------
Maya_location
= D:/program files/Autodesk/maya2009
Path = $ maya_location
/Mentalray/LIB; $ path ;//! -Maya needs to find several DLL values of mentalray.
Mi_custom_shader_path =
$ Maya_location
/Devkit/mentalray/docs/writingshaders;
------------------------------------------------------------------------------
6. Test
Open Maya and choose Window> rendering editors> Mental Ray> shader manager. You can see mytexture.
. Mi has been loaded.
There will be mytexture nodes under hypershader --> Create mentalray nodes --> miscellaneous.
Create a mytexture texture, assign it to an object, and then use mentalray to render the texture.