OKLab color gradients were partially implemented (#230)

in RadialGradient.kt and NPointLinearGradient.kt

Add OKLab variation to DemoNPointLinearGradient.kt

Mention OKLab (l, a, b) ranges and meaning.
This commit is contained in:
Abe Pazos
2022-02-28 21:00:25 +01:00
committed by GitHub
parent ccc3ed5bbc
commit 6e29423448
4 changed files with 52 additions and 24 deletions

View File

@@ -5,6 +5,8 @@ import org.openrndr.color.ColorRGBa
import org.openrndr.color.ConvertibleToColorRGBa
import org.openrndr.draw.ShadeStyle
import org.openrndr.extra.parameters.Description
import org.openrndr.extra.shaderphrases.preprocess
import org.openrndr.extras.color.phrases.ColorPhraseBook
import org.openrndr.extra.color.spaces.ColorOKLABa
import org.openrndr.math.CastableToVector4
import org.openrndr.math.Vector2
@@ -16,7 +18,7 @@ open class NPointLinearGradientBase<C>(
offset: Vector2 = Vector2.ZERO,
rotation: Double = 0.0
) : ShadeStyle()
where C : ConvertibleToColorRGBa, C : AlgebraicColor<C>, C : CastableToVector4 {
where C : ConvertibleToColorRGBa, C : AlgebraicColor<C>, C: CastableToVector4 {
var colors: Array<C> by Parameter()
@@ -26,11 +28,15 @@ open class NPointLinearGradientBase<C>(
var rotation: Double by Parameter()
init {
ColorPhraseBook.register()
this.colors = colors
this.points = points
this.offset = offset
this.rotation = rotation
fragmentPreamble = """
|#pragma import color.oklab_to_linear_rgb
|#pragma import color.linear_rgb_to_srgb""".trimMargin().preprocess()
fragmentTransform = """
vec2 coord = (c_boundsPosition.xy - 0.5 + p_offset);

View File

@@ -6,6 +6,8 @@ import org.openrndr.draw.shadeStyle
import org.openrndr.extra.parameters.ColorParameter
import org.openrndr.extra.parameters.Description
import org.openrndr.extra.parameters.DoubleParameter
import org.openrndr.extra.shaderphrases.preprocess
import org.openrndr.extras.color.phrases.ColorPhraseBook
import org.openrndr.extra.color.spaces.ColorOKLABa
import org.openrndr.math.CastableToVector4
import org.openrndr.math.Vector2
@@ -33,6 +35,7 @@ where C : ConvertibleToColorRGBa, C : AlgebraicColor<C>, C: CastableToVector4 {
var exponent: Double by Parameter()
init {
ColorPhraseBook.register()
this.color0 = color0
this.color1 = color1
this.offset = offset
@@ -40,6 +43,9 @@ where C : ConvertibleToColorRGBa, C : AlgebraicColor<C>, C: CastableToVector4 {
this.length = length
this.exponent = exponent
fragmentPreamble = """
|#pragma import color.oklab_to_linear_rgb
|#pragma import color.linear_rgb_to_srgb""".trimMargin().preprocess()
fragmentTransform = """
vec2 coord = (c_boundsPosition.xy - 0.5 + p_offset/2.0) * 2.0;