MDL - creating a gradient based on relative height?

I'm trying to create a gradient based on the surface points height on the object. I can get the height with

export float height() {
    float3 int_pos = state::transform_point(state::coordinate_internal,state::coordinate_object,state::position());
    return int_pos[1];
}

which gets the height of the point in object space... but unless I already know exactly how tall the object is, it's not too helpful. I basically need the height as a percentage of object height - alternately I need to be able to get the object height, so I can divide the surface point height by the object height to derive my percentage, I'm cool either way.

Unfortunately I'm going batty trying to find object height, or bounding box, or anything in MDL. Is there a simpler way to do this?

Comments

  • SyndarylSyndaryl Posts: 521

    I'm also interested relative to the scene bounding box instead of the object (or being able to set another object) but my primary need is for the object itself.

    I've noticed if I use the bricks instead of writing my own MDL, the Position brick takes into account object scaling, whereas the state::position() function returns absolute position. I.E., if I have a 10CM tall sphere, and I scale it to be 100 cm tall, and compare the output of the Position block and the state::position() function to 2CM, the Position block will be equal at 20CM, but the state::position() function will be equal at 2CM as I expected.

    That suggests at least some information about relative size is available in there somewhere, or at least about scaling, but I really need that bounding box.

  • algovincianalgovincian Posts: 2,636

    I've written numerous shaders for 3DL designed to render what I call analysis passes for my NPR work. I know you're interested in MDL, but the approach I took may apply to your situation, too.

    Like you, I wanted access to information in the scene about the scale/position of objects. My solution was to apply the analysis shaders via a script. The custom shaders included custom parameter values that the script could set after applying the shader.

    The script workflow is something like this:

    1. Gather and store information from the scene

    2. Apply custom shaders

    3. Set custom parameters for the shaders based on the info gathered from the scene

    Hope this helps.

    - Greg

  • SyndarylSyndaryl Posts: 521

    Thanks Greg!

    That definitely is applicable to my situtaion! A little baroque, but totally workable for my purposes. I didn't even think about bringing the info in via script. Bam! Perfect.

Sign In or Register to comment.