BlendModeのVividLight

VividLightの計算式こうじゃん!

VividLightの計算式こうじゃん!

  • exrd
  • 2015/5/1 22:07
  • タグ:
  • タグはありません
screen 1, 256, 256
title "base color : bottom layer"
repeat 256
y = cnt
repeat 256
x = cnt
i = x
color i, i, i
pset x, y
loop
loop
screen 2, 256, 256
title "blend color : top layer"
repeat 256
y = cnt
repeat 256
x = cnt
i = 255 -y
color i, i, i
pset x, y
loop
loop
screen 0, 256, 256
title "final output"
repeat 256
y = cnt
repeat 256
x = cnt
base_i = double(x) /255.0
blend_i = double( 255 -y ) /255.0
#if 0
//
if ( blend_i < 0.5 ) {
final_i = base_i / ( 1.0 - 2.0*blend_i )
} else {
final_i = 1.0 - ( 1.0-base_i ) / ( 2.0 * ( blend_i - 0.5 ) )
}
#else
//
// 0
if ( blend_i < 0.5 ) {
div = ( 2.0 * blend_i )
if ( div > 0.0 ) {
final_i = 1.0 - ( 1.0-base_i ) / div
} else {
final_i = 0.0
}
} else {
div = ( 1.0 - 2.0*(blend_i-0.5) )
if ( div > 0.0 ) {
final_i = base_i / div
} else {
final_i = 1.0
}
}
#endif
// clamp
final_i = limitf( final_i, 0.0 , 1.0 )
i = int( 255.0 * final_i )
color i, i, i
pset x, y
loop
loop
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX