By implementing Alexa LogC converters (El 1000) inside the Substance Painter Shader, we will learn how to build a structure and directly declare the data type using the structure.

Usually, you can think of LogC as Alexa LogC.

Alexa Color Processing documents define:


Logarithmic Encoded Data
Log C (film matrix off)
The Log C curve was first introduced with the ARRIFLEX D-20 camera. It’s an encoding with a gray-scale characteristic similar to a scan from negative film.
Because of the fundamental differences between digital cameras and negatives, the color characteristics remain different, though.
The Log C curve is depicted below. You see that the relation between exposure measured in stops and the signal is linear (straight) over a wide range.
The slope of this part of the curve is called gamma. You see also the toe at the bottom of the curve. The toe occurs because the sensor can not see low light levels with the same quantization as higher levels.
The overall shape of the curve is similar to the exposure curves of film negatives.

In fact, this post is not intended to very deeper into LogC.
For a deeper understanding based on the above, take a look at the pdf file above.
Let’s see if we can add a shader that converts linear spatial information to LogC space in Substance Painter again.

There are five LogC parameters.
You need 7 parameter values, Cut and a to f.
Let’s define this as a structure.

//-------- LogC Color Conversion --------------------------------------//
//: param custom { "default": false, "label": "LogC" }
uniform bool b_logC;


struct ParamsLogC
{
    float cut;
    float a, b, c, d, e, f;
};

We defined a variable of type Bool as b_logC, and added a: param custom and bound it in a pair.
You can now turn it on and off in the shader inspector.
Let’s create a user-defined data type defined with a specific constant.

const ParamsLogC LogC =
        {
            0.011361, // cut
            5.555556, // a
            0.047996, // b
            0.244161, // c
            0.386036, // d
            5.301883, // e
            0.092819  // f
        };

ParamsLogC structure was used as data type.
The log10 () function is used for the final transformation calculation, but there is no log10 () math function in the Substance Painter shader library.
Let’s make it yourself.

float log10(float x)
{
  float o;
  o = (1 / log(10)) * log(x);
  return o;
}

Create a LinearToLogC_Precise () function.
This part referred to ConvertToLog.shader of Unity3D URP.

float LinearToLogC_Precise(float x)
{
    float o;
    if (x > LogC.cut)
        o = LogC.c * log10(LogC.a * x + LogC.b) + LogC.d;
    else
        o = LogC.e * x + LogC.f;
    return o;
}


Let’s apply it to diffColor.

if(b_logC)
  {
    diffColor.xyz = vec3(LinearToLogC_Precise(diffColor.x), LinearToLogC_Precise(diffColor.y) ,  LinearToLogC_Precise(diffColor.z));
  }

logC off.
LogC on.

Related Post.

https://leegoonz.blog/2020/03/26/substance-painter-shader-guide-part-1-adding-to-custom-sun-light/

1 Comment »

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s