[orx-color, orx-fx] turbo_colormap and spectral_zucconi6 provided as shader phrases (#338)
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
package org.openrndr.extra.fx.colormap
|
||||
|
||||
import org.openrndr.draw.Filter
|
||||
import org.openrndr.draw.Filter1to1
|
||||
import org.openrndr.extra.fx.mppFilterShader
|
||||
import org.openrndr.extra.parameters.DoubleParameter
|
||||
|
||||
@@ -2,14 +2,25 @@
|
||||
|
||||
package org.openrndr.extra.fx.colormap
|
||||
|
||||
import org.openrndr.extra.color.colormaps.ColormapPhraseBook
|
||||
import org.openrndr.extra.fx.fx_spectral_zucconi_colormap
|
||||
import org.openrndr.extra.parameters.Description
|
||||
import org.openrndr.extra.shaderphrases.preprocess
|
||||
|
||||
/**
|
||||
* Maps values of the RED color channel to natural light dispersion spectrum as described
|
||||
* by Alan Zucconi in the
|
||||
* [Improving the Rainbow](https://www.alanzucconi.com/2017/07/15/improving-the-rainbow/)
|
||||
* article.
|
||||
*
|
||||
* @see ColormapPhraseBook.spectralZucconi6
|
||||
* @see org.openrndr.extra.color.colormaps.spectralZucconi6
|
||||
*/
|
||||
@Description("spectral colormap")
|
||||
class SpectralZucconiColormap : ColormapFilter(fx_spectral_zucconi_colormap, "spectral-zucconi-colormap")
|
||||
class SpectralZucconiColormap : ColormapFilter(
|
||||
code = run {
|
||||
ColormapPhraseBook.register()
|
||||
fx_spectral_zucconi_colormap.preprocess()
|
||||
},
|
||||
name = "spectral-zucconi-colormap"
|
||||
)
|
||||
|
||||
@@ -2,13 +2,24 @@
|
||||
|
||||
package org.openrndr.extra.fx.colormap
|
||||
|
||||
import org.openrndr.extra.color.colormaps.ColormapPhraseBook
|
||||
import org.openrndr.extra.fx.fx_turbo_colormap
|
||||
import org.openrndr.extra.parameters.Description
|
||||
import org.openrndr.extra.shaderphrases.preprocess
|
||||
|
||||
/**
|
||||
* Maps values of the RED color channel to Turbo Colormap according to
|
||||
* [Turbo, An Improved Rainbow Colormap for Visualization](https://ai.googleblog.com/2019/08/turbo-improved-rainbow-colormap-for.html)
|
||||
* by Google.
|
||||
*
|
||||
* @see ColormapPhraseBook.spectralZucconi6
|
||||
* @see org.openrndr.extra.color.colormaps.spectralZucconi6
|
||||
*/
|
||||
@Description("turbo colormap")
|
||||
open class TurboColormap : ColormapFilter(fx_turbo_colormap, "turbo-colormap")
|
||||
class TurboColormap : ColormapFilter(
|
||||
code = run {
|
||||
ColormapPhraseBook.register()
|
||||
fx_turbo_colormap.preprocess()
|
||||
},
|
||||
name = "turbo-colormap"
|
||||
)
|
||||
|
||||
21
orx-fx/src/jvmDemo/kotlin/DemoColormapGrayscale.kt
Normal file
21
orx-fx/src/jvmDemo/kotlin/DemoColormapGrayscale.kt
Normal file
@@ -0,0 +1,21 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.draw.ColorType
|
||||
import org.openrndr.draw.createEquivalent
|
||||
import org.openrndr.draw.loadImage
|
||||
import org.openrndr.extra.fx.colormap.GrayscaleColormap
|
||||
import kotlin.math.sin
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
program {
|
||||
val colormap = GrayscaleColormap()
|
||||
val image = loadImage("demo-data/images/image-001.png")
|
||||
val colormapImage = image.createEquivalent(type = ColorType.FLOAT32)
|
||||
extend {
|
||||
colormap.curve = 1.0 + sin(seconds) * .5
|
||||
colormap.apply(image, colormapImage)
|
||||
drawer.image(colormapImage)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
21
orx-fx/src/jvmDemo/kotlin/DemoColormapSpectralZucconi.kt
Normal file
21
orx-fx/src/jvmDemo/kotlin/DemoColormapSpectralZucconi.kt
Normal file
@@ -0,0 +1,21 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.draw.ColorType
|
||||
import org.openrndr.draw.createEquivalent
|
||||
import org.openrndr.draw.loadImage
|
||||
import org.openrndr.extra.fx.colormap.SpectralZucconiColormap
|
||||
import kotlin.math.sin
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
program {
|
||||
val colormap = SpectralZucconiColormap()
|
||||
val image = loadImage("demo-data/images/image-001.png")
|
||||
val colormapImage = image.createEquivalent(type = ColorType.FLOAT32)
|
||||
extend {
|
||||
colormap.curve = 1.0 + sin(seconds) * .5
|
||||
colormap.apply(image, colormapImage)
|
||||
drawer.image(colormapImage)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
21
orx-fx/src/jvmDemo/kotlin/DemoColormapTurbo.kt
Normal file
21
orx-fx/src/jvmDemo/kotlin/DemoColormapTurbo.kt
Normal file
@@ -0,0 +1,21 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.draw.ColorType
|
||||
import org.openrndr.draw.createEquivalent
|
||||
import org.openrndr.draw.loadImage
|
||||
import org.openrndr.extra.fx.colormap.TurboColormap
|
||||
import kotlin.math.sin
|
||||
|
||||
fun main() {
|
||||
application {
|
||||
program {
|
||||
val colormap = TurboColormap()
|
||||
val image = loadImage("demo-data/images/image-001.png")
|
||||
val colormapImage = image.createEquivalent(type = ColorType.FLOAT32)
|
||||
extend {
|
||||
colormap.curve = 1.0 + sin(seconds) * .5
|
||||
colormap.apply(image, colormapImage)
|
||||
drawer.image(colormapImage)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,4 @@
|
||||
// Spectral Colour Schemes
|
||||
// By Alan Zucconi
|
||||
// Website: www.alanzucconi.com
|
||||
// Twitter: @AlanZucconi
|
||||
|
||||
// Example of different spectral colour schemes
|
||||
// to convert visible wavelengths of light (400-700 nm) to RGB colours.
|
||||
|
||||
// The function "spectral_zucconi6" provides the best approximation
|
||||
// without including any branching.
|
||||
// Its faster version, "spectral_zucconi", is advised for mobile applications.
|
||||
|
||||
|
||||
// Read "Improving the Rainbow" for more information
|
||||
// http://www.alanzucconi.com/?p=6703
|
||||
#pragma import colormap.spectral_zucconi6
|
||||
|
||||
#ifdef OR_IN_OUT
|
||||
in vec2 v_texCoord0;
|
||||
@@ -29,47 +15,6 @@ uniform float curve;
|
||||
out vec4 o_color;
|
||||
#endif
|
||||
|
||||
float saturate (float x)
|
||||
{
|
||||
return min(1.0, max(0.0,x));
|
||||
}
|
||||
vec3 saturate (vec3 x)
|
||||
{
|
||||
return min(vec3(1.,1.,1.), max(vec3(0.,0.,0.),x));
|
||||
}
|
||||
|
||||
// --- Spectral Zucconi --------------------------------------------
|
||||
// By Alan Zucconi
|
||||
// Based on GPU Gems: https://developer.nvidia.com/sites/all/modules/custom/gpugems/books/GPUGems/gpugems_ch08.html
|
||||
// But with values optimised to match as close as possible the visible spectrum
|
||||
// Fits this: https://commons.wikimedia.org/wiki/File:Linear_visible_spectrum.svg
|
||||
// With weighter MSE (RGB weights: 0.3, 0.59, 0.11)
|
||||
vec3 bump3y (vec3 x, vec3 yoffset)
|
||||
{
|
||||
vec3 y = vec3(1.,1.,1.) - x * x;
|
||||
y = saturate(y-yoffset);
|
||||
return y;
|
||||
}
|
||||
|
||||
// --- Spectral Zucconi 6 --------------------------------------------
|
||||
|
||||
// Based on GPU Gems
|
||||
// Optimised by Alan Zucconi
|
||||
vec3 spectral_zucconi6 (float x)
|
||||
{
|
||||
const vec3 c1 = vec3(3.54585104, 2.93225262, 2.41593945);
|
||||
const vec3 x1 = vec3(0.69549072, 0.49228336, 0.27699880);
|
||||
const vec3 y1 = vec3(0.02312639, 0.15225084, 0.52607955);
|
||||
|
||||
const vec3 c2 = vec3(3.90307140, 3.21182957, 3.96587128);
|
||||
const vec3 x2 = vec3(0.11748627, 0.86755042, 0.66077860);
|
||||
const vec3 y2 = vec3(0.84897130, 0.88445281, 0.73949448);
|
||||
|
||||
return
|
||||
bump3y(c1 * (x - x1), y1) +
|
||||
bump3y(c2 * (x - x2), y2);
|
||||
}
|
||||
|
||||
void main() {
|
||||
#ifndef OR_GL_TEXTURE2D
|
||||
float red = texture(tex0, v_texCoord0).r;
|
||||
|
||||
@@ -1,13 +1,4 @@
|
||||
// TurboColormap
|
||||
// Copyright 2019 Google LLC.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Polynomial approximation in GLSL for the Turbo colormap
|
||||
// Original LUT: https://gist.github.com/mikhailov-work/ee72ba4191942acecc03fe6da94fc73f
|
||||
|
||||
// Authors:
|
||||
// Colormap Design: Anton Mikhailov (mikhailov@google.com)
|
||||
// GLSL Approximation: Ruofei Du (ruofei@google.com)
|
||||
#pragma import colormap.turbo_colormap
|
||||
|
||||
#ifdef OR_IN_OUT
|
||||
in vec2 v_texCoord0;
|
||||
@@ -24,28 +15,6 @@ uniform float curve;
|
||||
out vec4 o_color;
|
||||
#endif
|
||||
|
||||
float saturate(in float x) {
|
||||
return max(0, min(1, x));
|
||||
}
|
||||
|
||||
vec3 TurboColormap(in float x) {
|
||||
const vec4 kRedVec4 = vec4(0.13572138, 4.61539260, -42.66032258, 132.13108234);
|
||||
const vec4 kGreenVec4 = vec4(0.09140261, 2.19418839, 4.84296658, -14.18503333);
|
||||
const vec4 kBlueVec4 = vec4(0.10667330, 12.64194608, -60.58204836, 110.36276771);
|
||||
const vec2 kRedVec2 = vec2(-152.94239396, 59.28637943);
|
||||
const vec2 kGreenVec2 = vec2(4.27729857, 2.82956604);
|
||||
const vec2 kBlueVec2 = vec2(-89.90310912, 27.34824973);
|
||||
|
||||
x = saturate(x);
|
||||
vec4 v4 = vec4( 1.0, x, x * x, x * x * x);
|
||||
vec2 v2 = v4.zw * v4.z;
|
||||
return vec3(
|
||||
dot(v4, kRedVec4) + dot(v2, kRedVec2),
|
||||
dot(v4, kGreenVec4) + dot(v2, kGreenVec2),
|
||||
dot(v4, kBlueVec4) + dot(v2, kBlueVec2)
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
#ifndef OR_GL_TEXTURE2D
|
||||
float red = texture(tex0, v_texCoord0).r;
|
||||
@@ -53,7 +22,7 @@ void main() {
|
||||
float red = texture2D(tex0, v_texCoord0).r;
|
||||
#endif
|
||||
float value = (red - minValue) / (maxValue - minValue);
|
||||
vec3 color = TurboColormap(pow(value, curve));
|
||||
vec3 color = turbo_colormap(pow(value, curve));
|
||||
color *= step(value, 1.) * step(0., value);
|
||||
vec4 result = vec4(color, 1.);
|
||||
#ifdef OR_GL_FRAGCOLOR
|
||||
|
||||
Reference in New Issue
Block a user