Measure value upper/lower boundaries for normalisation?

Could an OSL-shader measure min/max boundaries from an input value?

My thread is inspired by this thread …
Normalize any value to 0-1

My little OSL-shader tries to use (OSL) getmessage and setmessage to measure min/max boundaries. But it does not work, sadly. I dont see why.

Liddle shader appended.

meassure_range.osl (721 Bytes)


Code here


shader meassure_range(
	float value = 1.0,
    output float Min = 10000.0,
    output float Max = -10000.0 )
{   
    float current_min=Min;
    float current_max=Max;

    if (getmessage("min", current_min) == 0) {
        setmessage("min", 10000.0);
    }
    else {
        if (value < current_min) {
            setmessage("min", value);
            Min = value;
        }
        else {
            Min = current_min;
        }
    }


    if (getmessage("max", current_max) == 0) {
        setmessage("max", -10000.0);
    }
    else {
        if ( value > current_max ) {
            setmessage("max", value);
            Max = value;
        } 
        else {
            Max = current_max;
        }
    }
	
}

I didn’t test the script, but I don’t think messaging works like that… I also doubt that you can have global variables that could be acessed by sample calls (specially when we have parallel calls happening). :frowning:

Hi Secrop.

I tried to use messages like global variables. But I dont know enough about OSL messages.

( Currently I look for more information on how to use OSL messages. )

Ending with my nose in Cycles sources …
there is no setmessage?! :neutral_face:

you should try it with Appleseed… afaik it has a better osl support.

Not sure it makes a difference.
“setmessage” not mentoned in sources …