View Full Version : Editing Instance with Geometry Shader

April 16th, 2006, 12:29
3ds max 8, internal mental ray
Hi to ALL.

I'm trying to write geometry shader for editing flags of scene element instances (geometry object, camera or light) created in 3ds max.
As supposed that geometry shader will work during preprocessing stage - after 3ds max translate scene for mental ray and before actual rendering begin.
Shader receive instance tag from 3ds max as input parameter with mouse picking scene element in 3ds max Viewport,
get access to data fields of this instance and change (some of) their value:

miTag input_tag;
char const *name_tag;
miInstance *inst_for_edit;

input_tag = *mi_evaluate(&paras->input_tag) /* get instance tag from 3ds max */

name_tag = mi_api_tag_lookup(input_tag); /* get instance name */

inst_for_edit = (miInstance*)mi_db_access(name_tag); /*get instance address from DB*/

inst_for_edit->visibility = 1; /* change value some instance flags, for example - set visibility OFF */

mi_db_unpin(inst_for_edit); /* unpin instance */


But I have problem: result of the using this geoshader depend from order instances in list of the scene root group.

If instance of my geoshader stand before edited instance in list root group:

instgroup "SceneRoot|Group"

"My_Geo_Shader|Instance(Mesh00)" /my Geo Shader for editing instance/
"Edited_Inst|Instance(Mesh00)" /edited instance/
end instgroup

render "SceneRoot|Group" "Viewport|Instance" "SceneOptions|SceneOptions",

all work right (result of rendering is defined my geoshader, in my example instance disappear from rendered image).

But, if edited instance stand in list before instance geoshader:

instgroup "SceneRoot|Group"

"Edited_Inst|Instance(Mesh00)" /edited instance/
"My_Geo_Shader|Instance(Mesh00)" /my Geo Shader for editing instance/
end instgroup,

result are defined by original (not changed) value of instance.

I have tryed different approach:

1. direct access through mi_db_assecc;

2. incremental change with


inst_for_edit = mi_api_instance_begin(mi_mem_strdup(name_tag));

inst_for_edit->visibility = 1;

mi_api_instance_end(mi_mem_strdup(name_item), 0, 0); /name_item - name referenced item of edited instance/


inst_for_edit = (miInstance*)mi_screne_edit(input_tag);
inst_for_edit->visibility = 1;

But result always same as described above.
How can I resolve this problem?
Any suggestions will be very appreciated,