I'm trying to write a "decal shader" for mentalRay. The idea is simple. This shader will look if the current location is covered by a decal object, then it will output a color given by the material set on the decal object instead of the actual object on which the decal shader is applied. This allows you to add details without making unique textures. However, I'm currently struggling with successfully calling mi_call_material to evaluate the replacement material. Here is what I do:
- Get an miTag for the decal object instance.
- Use mi_query() with miQ_INST_MATERIAL to get the decal object material.
- Build a new miState as a primary ray and set the material member to the miTag from the line above.
- Call mi_call_material() with the new miState. <-- crash
Code: Select all
// decalObj is a valid miTag referencing the decal object instance
miTag objMat = miNULLTAG;
mi_query(miQ_INST_MATERIAL, nullptr, decalObj, &objMat);
// Prepare the decal material state
miState decalState = *state; // Start with a copy of the state passed to this shader
decalState.parent = nullptr;
decalState.reflection_level = 0;
decalState.refraction_level = 0;
decalState.face = 'f';
decalState.material = objMat;
decalState.volume = miNULLTAG;
decalState.environment = miNULLTAG;
decalState.refraction_volume = miNULLTAG;
mi_query(miQ_INST_LABEL, nullptr, decalObj, &decalState.label);
decalState.instance = decalObj;
decalState.pri = nullptr; // Primary ray
// The fields commented below to be filled with proper math
//decalState.bary[0] = decalState.bary[1] = decalState.bary[2] = 0.0f;
//decalState.tex_list;
//decalState.bump_x_list;
//decalState.bump_y_list;
decalState.tex = uv;
decalState.shader = nullptr;
decalState.child = nullptr;
bRetval = mi_call_material(result, &decalState);
Any help is much appreciated!
Best