diff --git a/orx-color/src/commonTest/kotlin/colormaps/TestSpectralZucconi6Colormap.kt b/orx-color/src/commonTest/kotlin/colormaps/TestSpectralZucconi6Colormap.kt index fecf3a92..b11460f7 100644 --- a/orx-color/src/commonTest/kotlin/colormaps/TestSpectralZucconi6Colormap.kt +++ b/orx-color/src/commonTest/kotlin/colormaps/TestSpectralZucconi6Colormap.kt @@ -19,11 +19,11 @@ class TestSpectralZucconi6Colormap { @Test fun testSpectralZucconi6() { - spectralZucconi6(0.0) shouldBe ColorRGBa(0.0, 0.0, 0.026075309353279508, linearity = Linearity.SRGB) - spectralZucconi6(0.5) shouldBe ColorRGBa(0.49637374891706215, 0.8472371726323733, 0.18366091774095827, linearity = Linearity.SRGB) - spectralZucconi6(1.0) shouldBe ColorRGBa(0.0, 0.0, 0.0, linearity = Linearity.SRGB) - spectralZucconi6(-0.1) shouldBe ColorRGBa(0.0, 0.0, 0.0, linearity = Linearity.SRGB) - spectralZucconi6(1.1) shouldBe ColorRGBa(0.0, 0.0, 0.0, linearity = Linearity.SRGB) + spectralZucconi6(0.0) shouldBe ColorRGBa(0.0, 0.0, 0.026075309353279508, linearity = Linearity.LINEAR) + spectralZucconi6(0.5) shouldBe ColorRGBa(0.49637374891706215, 0.8472371726323733, 0.18366091774095827, linearity = Linearity.LINEAR) + spectralZucconi6(1.0) shouldBe ColorRGBa(0.0, 0.0, 0.0, linearity = Linearity.LINEAR) + spectralZucconi6(-0.1) shouldBe ColorRGBa(0.0, 0.0, 0.0, linearity = Linearity.LINEAR) + spectralZucconi6(1.1) shouldBe ColorRGBa(0.0, 0.0, 0.0, linearity = Linearity.LINEAR) } } diff --git a/orx-color/src/commonTest/kotlin/colormaps/TestTurboColormap.kt b/orx-color/src/commonTest/kotlin/colormaps/TestTurboColormap.kt index 3673b00a..9fff4521 100644 --- a/orx-color/src/commonTest/kotlin/colormaps/TestTurboColormap.kt +++ b/orx-color/src/commonTest/kotlin/colormaps/TestTurboColormap.kt @@ -19,11 +19,11 @@ class TestTurboColormap { @Test fun testTurboColormap() { - turboColormap(0.0) shouldBe ColorRGBa(0.13572138, 0.09140261, 0.1066733, linearity = Linearity.SRGB) - turboColormap(0.5) shouldBe ColorRGBa(0.5885220621875007, 0.981864383125, 0.31316869781249856, linearity = Linearity.SRGB) - turboColormap(1.0) shouldBe ColorRGBa(0.5658592099999993, 0.05038885999999998, -0.025520659999997974, linearity = Linearity.SRGB) - turboColormap(-0.1) shouldBe ColorRGBa(0.13572138, 0.09140261, 0.1066733, linearity = Linearity.SRGB) - turboColormap(1.1) shouldBe ColorRGBa(0.5658592099999993, 0.05038885999999998, -0.025520659999997974, linearity = Linearity.SRGB) + turboColormap(0.0) shouldBe ColorRGBa(0.13572138, 0.09140261, 0.1066733, linearity = Linearity.LINEAR) + turboColormap(0.5) shouldBe ColorRGBa(0.5885220621875007, 0.981864383125, 0.31316869781249856, linearity = Linearity.LINEAR) + turboColormap(1.0) shouldBe ColorRGBa(0.5658592099999993, 0.05038885999999998, -0.025520659999997974, linearity = Linearity.LINEAR) + turboColormap(-0.1) shouldBe ColorRGBa(0.13572138, 0.09140261, 0.1066733, linearity = Linearity.LINEAR) + turboColormap(1.1) shouldBe ColorRGBa(0.5658592099999993, 0.05038885999999998, -0.025520659999997974, linearity = Linearity.LINEAR) } } diff --git a/orx-compositor/src/commonMain/kotlin/Compositor.kt b/orx-compositor/src/commonMain/kotlin/Compositor.kt index 8a64d244..e3b4ea30 100644 --- a/orx-compositor/src/commonMain/kotlin/Compositor.kt +++ b/orx-compositor/src/commonMain/kotlin/Compositor.kt @@ -49,7 +49,7 @@ open class Layer internal constructor( val children: MutableList = mutableListOf() var blendFilter: Pair Unit>? = null val postFilters: MutableList, Filter.() -> Unit>> = mutableListOf() - var colorType = ColorType.UINT8 + var colorType = ColorType.UINT8_SRGB private var unresolvedAccumulation: ColorBuffer? = null var accumulation: ColorBuffer? = null diff --git a/orx-fx/src/commonMain/kotlin/Post.kt b/orx-fx/src/commonMain/kotlin/Post.kt index 4c2e2fe3..ca1b93a9 100644 --- a/orx-fx/src/commonMain/kotlin/Post.kt +++ b/orx-fx/src/commonMain/kotlin/Post.kt @@ -14,17 +14,17 @@ class Post : Extension { /** * The color type to use for the intermediate color buffers */ - var intermediateType = ColorType.UINT8 + var intermediateType = ColorType.UINT8_SRGB /** * The color type to use for the output color buffer */ - var outputType = ColorType.UINT8 + var outputType = ColorType.UINT8_SRGB /** * The color type to use for the input buffer */ - var inputType = ColorType.UINT8 + var inputType = ColorType.UINT8_SRGB /** * The depth format to use for the input buffer diff --git a/orx-fx/src/commonMain/kotlin/blend/BlendSpectral.kt b/orx-fx/src/commonMain/kotlin/blend/BlendSpectral.kt index f89b39d1..84837fff 100644 --- a/orx-fx/src/commonMain/kotlin/blend/BlendSpectral.kt +++ b/orx-fx/src/commonMain/kotlin/blend/BlendSpectral.kt @@ -16,29 +16,9 @@ in vec2 v_texCoord0; out vec4 o_color; -uniform bool linearizeInputA; -uniform bool linearizeInputB; -uniform bool delinearizeOutput; uniform float fill; uniform bool clip; -vec3 srgb_to_linear(vec3 c) { - const float t = 0.00313066844250063; - return vec3( - c.r <= t ? c.r / 12.92 : pow((c.r + 0.055) / 1.055, 2.4), - c.g <= t ? c.g / 12.92 : pow((c.g + 0.055) / 1.055, 2.4), - c.b <= t ? c.b / 12.92 : pow((c.b + 0.055) / 1.055, 2.4)); -} - -vec3 linear_to_srgb(vec3 c) { - const float t = 0.00313066844250063; - return vec3( - c.r <= t ? c.r * 12.92 : 1.055 * pow(c.r, 1.0 / 2.4) - 0.055, - c.g <= t ? c.g * 12.92 : 1.055 * pow(c.g, 1.0 / 2.4) - 0.055, - c.b <= t ? c.b * 12.92 : 1.055 * pow(c.b, 1.0 / 2.4) - 0.055 - ); -} - void main() { vec4 a = texture(tex0, v_texCoord0); vec4 b = texture(tex1, v_texCoord0); @@ -48,13 +28,6 @@ void main() { vec4 nb = b.a == 0.0 ? vec4(0.0): vec4(b.rgb / b.a,b.a); - if (linearizeInputA) { - na.rgb = srgb_to_linear(na.rgb); - } - - if (linearizeInputB) { - nb.rgb = srgb_to_linear(nb.rgb); - } vec4 mixed = vec4(spectral_mix(na.rgb, nb.rgb, min(1.0, fill)), 1.0); @@ -68,9 +41,6 @@ void main() { mixed.rgb = mixed.a == 0.0 ? vec3(0.0): mixed.rgb / mixed.a; - if (delinearizeOutput) { - mixed.rgb = linear_to_srgb(mixed.rgb); - } // premultiply alpha mixed.rgb *= mixed.a; diff --git a/orx-fx/src/commonMain/kotlin/blur/LaserBlur.kt b/orx-fx/src/commonMain/kotlin/blur/LaserBlur.kt index 6748658d..8913df26 100644 --- a/orx-fx/src/commonMain/kotlin/blur/LaserBlur.kt +++ b/orx-fx/src/commonMain/kotlin/blur/LaserBlur.kt @@ -18,8 +18,6 @@ private class LaserBlurPass : Filter(mppFilterShader(fx_laser_blur, "laser-blur" var vignette: Double by parameters var vignetteSize: Double by parameters var aberration: Double by parameters - var linearInput: Boolean by parameters - var linearOutput: Boolean by parameters init { radius = 0.0 @@ -29,8 +27,6 @@ private class LaserBlurPass : Filter(mppFilterShader(fx_laser_blur, "laser-blur" vignette = 0.0 vignetteSize = 1.0 aberration = 0.0 - linearInput = false - linearOutput = false } } @@ -60,12 +56,6 @@ class LaserBlur : Filter1to1() { @DoubleParameter("exp", -1.0, 1.0, order = 7) var exp = 0.739 - @BooleanParameter("linear input", order = 8) - var linearInput = false - - @BooleanParameter("linear output", order = 9) - var linearOutput = false - @DoubleParameter("phase", -1.0, 1.0, order = 7) var phase = 0.0 @@ -99,19 +89,13 @@ class LaserBlur : Filter1to1() { pass.radius = 1.0 + pow(exp, 0.0) * radius - pass.linearInput = linearInput - pass.linearOutput = true pass.apply(source[0], intermediates[0], clip) for (i in 0 until passes - 1) { - pass.linearInput = true - pass.linearOutput = true pass.radius = 1.0 + pow(exp, i + 1.0) * radius //(1.0 + simplex(0, phase + i)) / 2.0 pass.apply(intermediates[i % 2], intermediates[(i + 1) % 2], clip) } pass.radius = 1.0 + pow(exp, (passes) * 1.0) * radius - pass.linearInput = true - pass.linearOutput = linearOutput pass.apply(intermediates[(passes + 1) % 2], target[0], clip) } } diff --git a/orx-fx/src/commonMain/kotlin/distort/VideoGlitch.kt b/orx-fx/src/commonMain/kotlin/distort/VideoGlitch.kt index 362f9a5f..88d8bffc 100644 --- a/orx-fx/src/commonMain/kotlin/distort/VideoGlitch.kt +++ b/orx-fx/src/commonMain/kotlin/distort/VideoGlitch.kt @@ -37,12 +37,6 @@ class VideoGlitch : Filter1to1(mppFilterShader(fx_video_glitch, "video-glitch")) @DoubleParameter("scroll offset 1", 0.0, 1.0) var scrollOffset1: Double by parameters - @BooleanParameter("linear input") - var linearInput: Boolean by parameters - - @BooleanParameter("linear output") - var linearOutput: Boolean by parameters - init { amplitude = 1.0 vfreq = 4.0 @@ -52,7 +46,5 @@ class VideoGlitch : Filter1to1(mppFilterShader(fx_video_glitch, "video-glitch")) scrollOffset0 = 0.0 scrollOffset1 = 0.0 borderHeight = 0.05 - linearInput = false - linearOutput = false } } \ No newline at end of file diff --git a/orx-fx/src/shaders/glsl/blur/laser-blur.frag b/orx-fx/src/shaders/glsl/blur/laser-blur.frag index 18bf148b..30e43a9c 100644 --- a/orx-fx/src/shaders/glsl/blur/laser-blur.frag +++ b/orx-fx/src/shaders/glsl/blur/laser-blur.frag @@ -8,14 +8,9 @@ uniform vec2 center; uniform float vignette; uniform float vignetteSize; uniform float aberration; -uniform bool linearInput; -uniform bool linearOutput; void main() { vec4 i0 = texture(tex0, v_texCoord0); - if (!linearInput) { - i0.rgb = pow(i0.rgb, vec3(2.2)); - } vec2 vt = (v_texCoord0 - vec2(0.5, 0.5) + center) * radius + vec2(0.5, 0.5) - center; vec2 size = vec2(textureSize(tex0, 0)); @@ -32,16 +27,10 @@ void main() { i1b.rgb = i1b.a > 0.0 ? i1b.rgb / i1b.a : vec3(0.0); vec4 i1 = vec4(i1r.r, i1g.g, i1b.b, 1.0) * (i1r.a + i1g.a + i1b.a) / 3.0; - if (!linearInput) { - i1.rgb = pow(i1.rgb, vec3(2.2)); - } o_output = i0 * amp0 + i1 * amp1; } else { o_output = i0 * 0.5; } o_output.rgb *= mix(1.0, smoothstep(vignetteSize, 0.0, d), vignette); - if (!linearOutput) { - o_output.rgb = pow(o_output.rgb, vec3(1.0 / 2.2)); - } } \ No newline at end of file diff --git a/orx-fx/src/shaders/glsl/color/duotone.frag b/orx-fx/src/shaders/glsl/color/duotone.frag index 8750cefc..e80b1b37 100644 --- a/orx-fx/src/shaders/glsl/color/duotone.frag +++ b/orx-fx/src/shaders/glsl/color/duotone.frag @@ -24,15 +24,12 @@ void main() { if (!labInterpolation) { o_color = mix(bg, fg, c.r) * c.a; } else { - bg = srgb_to_linear_rgb(bg); bg = linear_rgb_to_oklab(bg); - fg = srgb_to_linear_rgb(fg); fg = linear_rgb_to_oklab(fg); vec4 m = mix(bg, fg, c.r); m = oklab_to_linear_rgb(m); m *= c.a; - m = linear_rgb_to_srgb(m); o_color = m; } } \ No newline at end of file diff --git a/orx-fx/src/shaders/glsl/distort/video-glitch.frag b/orx-fx/src/shaders/glsl/distort/video-glitch.frag index 1955c24d..9e5f514e 100644 --- a/orx-fx/src/shaders/glsl/distort/video-glitch.frag +++ b/orx-fx/src/shaders/glsl/distort/video-glitch.frag @@ -12,9 +12,6 @@ uniform float scrollOffset1; uniform float borderHeight; -uniform bool linearInput; -uniform bool linearOutput; - #define HASHSCALE 443.8975 vec2 hash22(vec2 p) { vec3 p3 = fract(vec3(p.xyx) * HASHSCALE); @@ -49,20 +46,11 @@ void main() { if (aa > 0.0 || ds > 0.0) { for (int i = 1; i < 16; ++i) { vec4 lc = getVideo(v_texCoord0 + vec2(0.0, scrollOffset0+ds*float(i)), aa, time-float(i)/(16.0*60.0)); - if (!linearInput) { - lc.rgb = pow(lc.rgb, vec3(2.2)); - } c += lc * (3.0/16.0) * aberrationColor(float(i)/16.0); } o_output = c; } else { vec4 lc = texture(tex0, mod(v_texCoord0 + vec2(0.0, scrollOffset1), vec2(1.0))); - if (!linearInput) { - lc.rgb = pow(lc.rgb, vec3(2.2)); - } o_output = lc; } - if (!linearOutput) { - o_output.rgb = pow(o_output.rgb, vec3(1.0/2.2)); - } } diff --git a/orx-fx/src/shaders/glsl/tonemap/aces-tonemap.frag b/orx-fx/src/shaders/glsl/tonemap/aces-tonemap.frag index d477d39b..f08f5936 100644 --- a/orx-fx/src/shaders/glsl/tonemap/aces-tonemap.frag +++ b/orx-fx/src/shaders/glsl/tonemap/aces-tonemap.frag @@ -20,6 +20,6 @@ vec3 ACESFilm(vec3 x) { void main() { vec3 texColor = texture(tex0,v_texCoord0).rgb; vec3 color = ACESFilm(texColor * exposureBias); - vec3 retColor = pow(color, vec3(1.0/2.2)); - o_output = vec4(retColor, 1.0); + + o_output = vec4(color, 1.0); } \ No newline at end of file diff --git a/orx-fx/src/shaders/glsl/tonemap/uncharted2-tonemap.frag b/orx-fx/src/shaders/glsl/tonemap/uncharted2-tonemap.frag index e5bf89af..ca5ad2c9 100644 --- a/orx-fx/src/shaders/glsl/tonemap/uncharted2-tonemap.frag +++ b/orx-fx/src/shaders/glsl/tonemap/uncharted2-tonemap.frag @@ -22,6 +22,5 @@ void main() { vec3 whiteScale = 1.0f/Uncharted2Tonemap(vec3(W)); vec3 color = curr*whiteScale; - vec3 retColor = pow(color, vec3(1.0/2.2)); - o_output = vec4(retColor, 1); + o_output = vec4(color, 1); } \ No newline at end of file diff --git a/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/elements/Colorpicker.kt b/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/elements/Colorpicker.kt index 310fde65..5133c5fb 100644 --- a/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/elements/Colorpicker.kt +++ b/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/elements/Colorpicker.kt @@ -141,7 +141,7 @@ class Colorpicker : Element { for (y in 0..49) { for (x in 0 until it.colorBuffer.width) { val hsv = ColorHSVa(360.0 / it.colorBuffer.width * x, saturation, (49 - y) / 49.0) - it.write(x, y, hsv.toRGBa()) + it.write(x, y, hsv.toRGBa().toLinear()) } } it.upload() @@ -155,7 +155,7 @@ class Colorpicker : Element { } drawer.image(colorMap!!, 0.0, 0.0) - drawer.fill = (color) + drawer.fill = color drawer.stroke = null drawer.shadeStyle = null drawer.rectangle(0.0, 50.0, layout.screenWidth, 20.0) diff --git a/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/elements/ColorpickerButton.kt b/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/elements/ColorpickerButton.kt index 32c39dc4..21381057 100644 --- a/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/elements/ColorpickerButton.kt +++ b/orx-jvm/orx-panel/src/main/kotlin/org/openrndr/panel/elements/ColorpickerButton.kt @@ -2,6 +2,7 @@ package org.openrndr.panel.elements import kotlinx.coroutines.yield import org.openrndr.color.ColorRGBa +import org.openrndr.color.Linearity import org.openrndr.draw.Drawer import org.openrndr.draw.LineCap @@ -16,7 +17,7 @@ class ColorpickerButton : Element(ElementType("colorpicker-button")), Disposable override var disposed: Boolean = false var label: String = "OK" - var color: ColorRGBa = ColorRGBa(0.5, 0.5, 0.5) + var color: ColorRGBa = ColorRGBa(0.5, 0.5, 0.5, linearity = Linearity.SRGB) set(value) { if (value != field) { field = value @@ -74,13 +75,13 @@ class ColorpickerButton : Element(ElementType("colorpicker-button")), Disposable val offset = Math.round((layout.screenWidth - textWidth) / 2.0) val yOffset = Math.round((layout.screenHeight / 2) + textHeight / 2.0) - 2.0 - drawer.fill = ((computedStyle.color as? Color.RGBa)?.color ?: ColorRGBa.WHITE) + drawer.fill = (computedStyle.color as? Color.RGBa)?.color ?: ColorRGBa.WHITE drawer.fontMap = font drawer.text(text, 0.0 + offset, 0.0 + yOffset) - drawer.stroke = (color) + drawer.stroke = color drawer.pushStyle() - drawer.strokeWeight = (4.0) - drawer.lineCap = (LineCap.ROUND) + drawer.strokeWeight = 4.0 + drawer.lineCap = LineCap.ROUND drawer.lineSegment(2.0, layout.screenHeight - 2.0, layout.screenWidth - 2.0, layout.screenHeight - 2.0) drawer.popStyle() }