I am reviewing my OSL notes and still unsure about one thing: Transparency.
My reference is this note by Steve May on RSL:
http://accad.osu.edu/~smay/RManNotes/WritingShaders/surf1.html
So far in my OSL Shader study, I only care about the procedural texture part. But I want to further understand and properly write code especially when “Layering, Masking, and dealing with Opacity”.
How do we actually implement the Os (related to Opacity) in OSL?
Below is my code so far.
#include "/Users/jimmygunawan/Desktop/rmannotes.sl"
shader layering2
(
vector Pos = P,
color ColA = color (0.3, 0.3, 0.3), // grey
color ColB = color(0,0,1), //blue
color ColC = color(0,1,0), // green
output color ColOut = 0,
output color TransOut = 0
)
{
float s = Pos[0];
float t = Pos[1];
color surface_color, layer_color;
color surface_opac, layer_opac;
float ss, tt;
point Nf, V;
/* background layer (layer 0) */
surface_color = ColA;
//surface_opac = Os;
/* layer 1 */
ss = repeat(s,4);
tt = repeat(t,4);
layer_color = ColB;
layer_opac = pulse(0.35, 0.65, 0.2, ss); /* vertical stripe */
layer_opac *= 0.75;
surface_color = blend(surface_color, layer_color, layer_opac);
surface_opac = union(surface_opac, layer_opac);
/* layer #2 */
ss = repeat(s,4);
tt = repeat(t,4);
layer_color = ColC;
layer_opac = pulse(0.35, 0.65, 0.02, tt);
layer_opac *= 0.5;
surface_color = blend(surface_color, layer_color, layer_opac);
surface_opac = union(surface_opac, layer_opac);
// OUTPUT
ColOut = surface_color;
TransOut = surface_opac; // this is wrong
}