├── java
├── examples
│ ├── HelloMixbox.bat
│ └── HelloMixbox.java
├── mixbox.jar
├── src
│ └── main
│ │ └── resources
│ │ └── com
│ │ └── scrtwpns
│ │ └── mixbox_lut.dat
├── build.bat
├── pom.xml
└── README.md
├── rust
├── src
│ ├── lut.dat
│ └── lib.rs
├── Cargo.toml
└── README.md
├── shaders
├── mixbox_lut.png
├── mixbox.hlsl
├── mixbox.glsl
├── mixbox.metal
└── README.md
├── unity
├── Textures
│ ├── MixboxLUT.png
│ └── MixboxLUT.png.meta
├── Runtime
│ ├── Scrtwpns.Mixbox.asmdef
│ ├── Scrtwpns.Mixbox.asmdef.meta
│ └── Mixbox.cs.meta
├── LICENSE.md.meta
├── README.md.meta
├── package.json.meta
├── Runtime.meta
├── Textures.meta
├── ShaderGraph.meta
├── ShaderLibrary.meta
├── ShaderLibrary
│ ├── Mixbox.cginc.meta
│ ├── Mixbox.hlsl.meta
│ ├── Mixbox.cginc
│ └── Mixbox.hlsl
├── Samples~
│ ├── SamplesHDRP
│ │ ├── Scenes
│ │ │ └── Scene.unity.meta
│ │ ├── Scenes.meta
│ │ ├── Shaders.meta
│ │ ├── Materials.meta
│ │ ├── Materials
│ │ │ ├── MixboxSampleHDRPShaderGraphMaterial.mat.meta
│ │ │ └── MixboxSampleHDRPShaderGraphMaterial.mat
│ │ └── Shaders
│ │ │ └── MixboxSampleHDRPShaderGraph.shadergraph.meta
│ ├── SamplesURP
│ │ ├── Scenes
│ │ │ └── Scene.unity.meta
│ │ ├── Scenes.meta
│ │ ├── Shaders.meta
│ │ ├── Materials.meta
│ │ ├── Materials
│ │ │ ├── MixboxSampleShaderGraphMaterial.mat.meta
│ │ │ ├── MixboxSampleURPShaderMaterial.mat.meta
│ │ │ ├── MixboxSampleURPShaderMaterial.mat
│ │ │ └── MixboxSampleShaderGraphMaterial.mat
│ │ └── Shaders
│ │ │ ├── MixboxSampleURPShader.shader.meta
│ │ │ ├── MixboxSampleShaderGraph.shadergraph.meta
│ │ │ └── MixboxSampleURPShader.shader
│ └── SamplesBuiltin
│ │ ├── Scenes
│ │ ├── Scene.unity.meta
│ │ └── Scene.unity
│ │ ├── Materials.meta
│ │ ├── Scenes.meta
│ │ ├── Shaders.meta
│ │ ├── Materials
│ │ ├── MixboxSampleMaterial.mat.meta
│ │ └── MixboxSampleMaterial.mat
│ │ └── Shaders
│ │ ├── MixboxSampleShader.shader.meta
│ │ └── MixboxSampleShader.shader
├── ShaderGraph
│ ├── CustomFunctions.meta
│ ├── CustomFunctions
│ │ ├── MixboxFunctions.hlsl.meta
│ │ └── MixboxFunctions.hlsl
│ └── MixboxLerp.shadersubgraph.meta
├── package.json
├── Documentation~
│ └── README.md
└── README.md
├── godot
├── addons
│ └── mixbox
│ │ ├── mixbox.res
│ │ ├── mixbox_lut.png
│ │ ├── mixbox_lut.png.import
│ │ ├── mixbox.gdshaderinc
│ │ ├── mixbox.gdshader
│ │ ├── mixbox_lerp_node.gd
│ │ └── mixbox.gd
└── README.md
├── python
├── examples
│ ├── hello.py
│ ├── pillow.py
│ ├── blender.py
│ ├── npcv.py
│ └── opengl.py
└── README.md
├── csharp
├── examples
│ ├── HelloMixbox.csproj
│ └── HelloMixbox.cs
├── Mixbox.csproj
└── README.md
├── javascript
├── examples
│ ├── palette.html
│ ├── mixer.html
│ ├── mountains.html
│ ├── svg.html
│ ├── p5js.html
│ ├── canvas.html
│ ├── hello.html
│ ├── gradients.html
│ ├── threejs.html
│ ├── webgl.html
│ ├── mountains.js
│ ├── palette.js
│ ├── mixer.js
│ ├── gradients.js
│ └── splash.html
└── README.md
├── webgl
├── example.html
└── README.md
└── cpp
├── README.md
└── mixbox.h
/java/examples/HelloMixbox.bat:
--------------------------------------------------------------------------------
1 | java -cp ../mixbox.jar HelloMixbox.java
2 |
--------------------------------------------------------------------------------
/java/mixbox.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scrtwpns/mixbox/HEAD/java/mixbox.jar
--------------------------------------------------------------------------------
/rust/src/lut.dat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scrtwpns/mixbox/HEAD/rust/src/lut.dat
--------------------------------------------------------------------------------
/shaders/mixbox_lut.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scrtwpns/mixbox/HEAD/shaders/mixbox_lut.png
--------------------------------------------------------------------------------
/unity/Textures/MixboxLUT.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scrtwpns/mixbox/HEAD/unity/Textures/MixboxLUT.png
--------------------------------------------------------------------------------
/godot/addons/mixbox/mixbox.res:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scrtwpns/mixbox/HEAD/godot/addons/mixbox/mixbox.res
--------------------------------------------------------------------------------
/godot/addons/mixbox/mixbox_lut.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scrtwpns/mixbox/HEAD/godot/addons/mixbox/mixbox_lut.png
--------------------------------------------------------------------------------
/java/src/main/resources/com/scrtwpns/mixbox_lut.dat:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/scrtwpns/mixbox/HEAD/java/src/main/resources/com/scrtwpns/mixbox_lut.dat
--------------------------------------------------------------------------------
/unity/Runtime/Scrtwpns.Mixbox.asmdef:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Scrtwpns.Mixbox",
3 | "references": [],
4 | "includePlatforms": [],
5 | "excludePlatforms": []
6 | }
--------------------------------------------------------------------------------
/java/build.bat:
--------------------------------------------------------------------------------
1 | javac -source 1.7 -target 1.7 src\main\java\com\scrtwpns\Mixbox.java -d build && copy src\main\resources\com\scrtwpns\mixbox_lut.dat build\com\scrtwpns && jar -cvf mixbox.jar -C build .
2 |
--------------------------------------------------------------------------------
/unity/LICENSE.md.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4cdbb20e49a3f5f48ac2bbf852d78e9c
3 | TextScriptImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/unity/README.md.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 8cd3a0808b52e7f4ab62eaee07dd6f1a
3 | TextScriptImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/unity/package.json.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 561481a9fef54ef46a9685b2db21c5d0
3 | PackageManifestImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/unity/Runtime.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d7271a729fd4b944fbe2954475dfc065
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/unity/Textures.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c50cb8edb0194174ea9bcf461b6c5dc0
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/unity/ShaderGraph.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2ff6266ad4cadeb4191c07532420ca02
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/unity/ShaderLibrary.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: cd4c6311a8e214c4182bf19784f39f8f
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/unity/ShaderLibrary/Mixbox.cginc.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0dd349175be5d4e40aa8e73df152ac60
3 | ShaderIncludeImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/unity/ShaderLibrary/Mixbox.hlsl.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 99e868ffcd385494fb8d6670aba3b648
3 | ShaderIncludeImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/python/examples/hello.py:
--------------------------------------------------------------------------------
1 | import mixbox
2 |
3 | rgb1 = (0, 33, 133) # blue
4 | rgb2 = (252, 211, 0) # yellow
5 | t = 0.5 # mixing ratio
6 |
7 | rgb_mix = mixbox.lerp(rgb1, rgb2, t)
8 |
9 | print(rgb_mix)
10 |
--------------------------------------------------------------------------------
/unity/Samples~/SamplesHDRP/Scenes/Scene.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d8d378e5c22378842b3571445bf2d526
3 | DefaultImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/unity/Samples~/SamplesURP/Scenes/Scene.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d8d378e5c22378842b3571445bf2d526
3 | DefaultImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/unity/Runtime/Scrtwpns.Mixbox.asmdef.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0dc470e3a5755fe46bfc9aa687c0cff7
3 | AssemblyDefinitionImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/unity/Samples~/SamplesBuiltin/Scenes/Scene.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 80973dec35f0fe844ac839fa0ec89a06
3 | DefaultImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/unity/Samples~/SamplesHDRP/Scenes.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 8a01fcc32dcf85d46813ee6861fbf932
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/unity/Samples~/SamplesHDRP/Shaders.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: edc5a5718e48b2946b4993ac276dac26
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/unity/Samples~/SamplesURP/Scenes.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 8a01fcc32dcf85d46813ee6861fbf932
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/unity/Samples~/SamplesURP/Shaders.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: edc5a5718e48b2946b4993ac276dac26
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/unity/ShaderGraph/CustomFunctions.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 94751c8e8a8eee8418810170ed6644ac
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/unity/Samples~/SamplesBuiltin/Materials.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: fc126e37ec6a7e44a82670bbd8939a07
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/unity/Samples~/SamplesBuiltin/Scenes.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: a26204cd28a06d843b2ac6e8b9ea28d9
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/unity/Samples~/SamplesBuiltin/Shaders.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1cb9032d8063c954cbce2b919e5dc135
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/unity/Samples~/SamplesHDRP/Materials.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 892b07ffc6cd8954a8c7eb778299a7c8
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/unity/Samples~/SamplesURP/Materials.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 892b07ffc6cd8954a8c7eb778299a7c8
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/unity/ShaderGraph/CustomFunctions/MixboxFunctions.hlsl.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: cb159fec42c279547ac0aeb6aa800e61
3 | ShaderIncludeImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/unity/Samples~/SamplesBuiltin/Materials/MixboxSampleMaterial.mat.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 22f4a840af474fe47b98f7c563b06bd6
3 | NativeFormatImporter:
4 | externalObjects: {}
5 | mainObjectFileID: 0
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/unity/Samples~/SamplesURP/Materials/MixboxSampleShaderGraphMaterial.mat.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2cac3e2b2c0440f4ab9b4f7c213094a8
3 | NativeFormatImporter:
4 | externalObjects: {}
5 | mainObjectFileID: 2100000
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/unity/Samples~/SamplesURP/Materials/MixboxSampleURPShaderMaterial.mat.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d29eec281162ba64c92e1534c872aee0
3 | NativeFormatImporter:
4 | externalObjects: {}
5 | mainObjectFileID: 2100000
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/unity/Samples~/SamplesHDRP/Materials/MixboxSampleHDRPShaderGraphMaterial.mat.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e1c84425eb63f8840898cfae7d5104c1
3 | NativeFormatImporter:
4 | externalObjects: {}
5 | mainObjectFileID: 2100000
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/unity/Runtime/Mixbox.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: a83e1aa56c038094292cda8c7eb1a14d
3 | MonoImporter:
4 | externalObjects: {}
5 | serializedVersion: 2
6 | defaultReferences: []
7 | executionOrder: 0
8 | icon: {instanceID: 0}
9 | userData:
10 | assetBundleName:
11 | assetBundleVariant:
12 |
--------------------------------------------------------------------------------
/unity/Samples~/SamplesURP/Shaders/MixboxSampleURPShader.shader.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 2a107236c36652b42928a70f71fe9d06
3 | ShaderImporter:
4 | externalObjects: {}
5 | defaultTextures: []
6 | nonModifiableTextures: []
7 | preprocessorOverride: 0
8 | userData:
9 | assetBundleName:
10 | assetBundleVariant:
11 |
--------------------------------------------------------------------------------
/unity/Samples~/SamplesBuiltin/Shaders/MixboxSampleShader.shader.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: bb6490bc8e0170a40a722ad60ca9e82d
3 | ShaderImporter:
4 | externalObjects: {}
5 | defaultTextures: []
6 | nonModifiableTextures: []
7 | preprocessorOverride: 0
8 | userData:
9 | assetBundleName:
10 | assetBundleVariant:
11 |
--------------------------------------------------------------------------------
/csharp/examples/HelloMixbox.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net5.0
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/unity/ShaderGraph/MixboxLerp.shadersubgraph.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: cea2d6a55fe1f64458be5f69a8bff761
3 | ScriptedImporter:
4 | internalIDToNameTable: []
5 | externalObjects: {}
6 | serializedVersion: 2
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 | script: {fileID: 11500000, guid: 60072b568d64c40a485e0fc55012dc9f, type: 3}
11 |
--------------------------------------------------------------------------------
/python/examples/pillow.py:
--------------------------------------------------------------------------------
1 | from PIL import Image
2 | import mixbox
3 |
4 | rgb1 = (0, 33, 133) # blue
5 | rgb2 = (252, 211, 0) # yellow
6 |
7 | img = Image.new('RGB', (256, 256))
8 |
9 | pixels = img.load()
10 |
11 | width,height = img.size
12 | for x in range(width):
13 | for y in range(height):
14 | pixels[x, y] = mixbox.lerp(rgb1, rgb2, x / 256.0)
15 |
16 | img.show()
17 |
--------------------------------------------------------------------------------
/unity/Samples~/SamplesURP/Shaders/MixboxSampleShaderGraph.shadergraph.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 878861faca4e2fa4ea3130c47204b113
3 | ScriptedImporter:
4 | internalIDToNameTable: []
5 | externalObjects: {}
6 | serializedVersion: 2
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 | script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}
11 |
--------------------------------------------------------------------------------
/unity/Samples~/SamplesHDRP/Shaders/MixboxSampleHDRPShaderGraph.shadergraph.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 5078a8abaf2327c44bdceef809b956b1
3 | ScriptedImporter:
4 | internalIDToNameTable: []
5 | externalObjects: {}
6 | serializedVersion: 2
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 | script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}
11 |
--------------------------------------------------------------------------------
/rust/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "mixbox"
3 | version = "2.0.0"
4 | edition = "2021"
5 | description = "Pigment-Based Color Mixing"
6 | readme = "README.md"
7 | homepage = "https://scrtwpns.com/mixbox"
8 | repository = "https://github.com/scrtwpns/mixbox"
9 | license = "CC-BY-NC-4.0"
10 | keywords = ["color-mixing", "pigments", "rgb", "kubelka-munk", "paints"]
11 |
12 | [dependencies]
13 | libm = "0.2.5"
14 |
--------------------------------------------------------------------------------
/csharp/Mixbox.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | netstandard2.0
4 | Mixbox
5 | 2.0.0
6 | Pigment-Based Color Mixing
7 | Secret Weapons
8 | Copyright (c) Secret Weapons 2022
9 |
10 |
11 |
--------------------------------------------------------------------------------
/python/examples/blender.py:
--------------------------------------------------------------------------------
1 | import bpy
2 | import mixbox
3 |
4 | rgb1 = (0.0, 0.015, 0.235) # blue
5 | rgb2 = (0.973, 0.651, 0.0) # yellow
6 |
7 | n = 5
8 | for i in range(0, n):
9 | bpy.ops.mesh.primitive_cube_add(location = ((i - n/2 + 0.5) * 3, 0, 0))
10 | mat = bpy.data.materials.new("material")
11 | mat.diffuse_color = mixbox.lerp_linear_float(rgb1, rgb2, i / (n - 1))
12 | bpy.context.object.active_material = mat
13 |
--------------------------------------------------------------------------------
/python/examples/npcv.py:
--------------------------------------------------------------------------------
1 | import cv2
2 | import numpy as np
3 | import mixbox
4 |
5 | height = 256
6 | width = 256
7 | img = np.zeros((height, width, 3), np.uint8)
8 |
9 | rgb1 = (0, 33, 133) # blue
10 | rgb2 = (252, 211, 0) # yellow
11 |
12 | for x in range(0, 256):
13 | for y in range(0, 256):
14 | img[x, y] = mixbox.lerp(rgb1, rgb2, x / 255.0)
15 |
16 | cv2.imshow("image", cv2.cvtColor(img, cv2.COLOR_RGB2BGR))
17 | cv2.waitKey(0)
18 |
--------------------------------------------------------------------------------
/javascript/examples/palette.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/javascript/examples/mixer.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/java/examples/HelloMixbox.java:
--------------------------------------------------------------------------------
1 | import java.awt.Color;
2 | import com.scrtwpns.Mixbox;
3 |
4 | class HelloMixbox {
5 | public static void main(String[] args) {
6 | Color color1 = new Color(0, 33, 133); // blue
7 | Color color2 = new Color(252, 211, 0); // yellow
8 | float t = 0.5f; // mixing ratio
9 |
10 | Color colorMix = new Color(Mixbox.lerp(color1.getRGB(), color2.getRGB(), t));
11 |
12 | System.out.print(colorMix);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/javascript/examples/mountains.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/csharp/examples/HelloMixbox.cs:
--------------------------------------------------------------------------------
1 | using System.Drawing;
2 | using Scrtwpns.Mixbox;
3 |
4 | public class HelloMixbox
5 | {
6 | public static void Main(string[] args)
7 | {
8 | Color color1 = Color.FromArgb(0, 33, 133); // blue
9 | Color color2 = Color.FromArgb(252, 211, 0); // yellow
10 | float t = 0.5f; // mixing ratio
11 |
12 | Color colorMix = Color.FromArgb(Mixbox.Lerp(color1.ToArgb(), color2.ToArgb(), t));
13 |
14 | System.Console.WriteLine(colorMix);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/javascript/examples/svg.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
9 |
10 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/javascript/examples/p5js.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/python/examples/opengl.py:
--------------------------------------------------------------------------------
1 | import pygame as pg
2 | from pygame.locals import *
3 |
4 | from OpenGL.GL import *
5 | from OpenGL.GLU import *
6 |
7 | import mixbox
8 |
9 | pg.init()
10 | pg.display.set_mode((640, 480), DOUBLEBUF | OPENGL)
11 |
12 | while True:
13 | rgb1 = (0.0, 0.129, 0.522) # blue
14 | rgb2 = (0.988, 0.827, 0.0) # yellow
15 |
16 | n = 640
17 | glBegin(GL_LINES)
18 | for i in range(0, n+1):
19 | glColor(mixbox.lerp_float(rgb1, rgb2, i / n))
20 | glVertex((i / n)*2 - 1, -1)
21 | glVertex((i / n)*2 - 1, +1)
22 | glEnd()
23 |
24 | pg.display.flip()
25 |
26 | for event in pg.event.get():
27 | if event.type == pg.QUIT:
28 | pg.quit()
29 | quit()
30 |
--------------------------------------------------------------------------------
/javascript/examples/canvas.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/godot/addons/mixbox/mixbox_lut.png.import:
--------------------------------------------------------------------------------
1 | [remap]
2 |
3 | importer="texture"
4 | type="StreamTexture"
5 | path="res://.import/mixbox_lut.png-d8cb77d0d5322618f1648925da003780.stex"
6 | metadata={
7 | "vram_texture": false
8 | }
9 |
10 | [deps]
11 |
12 | source_file="res://addons/mixbox/mixbox_lut.png"
13 | dest_files=[ "res://.import/mixbox_lut.png-d8cb77d0d5322618f1648925da003780.stex" ]
14 |
15 | [params]
16 |
17 | compress/mode=3
18 | compress/lossy_quality=0.7
19 | compress/hdr_mode=0
20 | compress/bptc_ldr=0
21 | compress/normal_map=0
22 | flags/repeat=0
23 | flags/filter=true
24 | flags/mipmaps=false
25 | flags/anisotropic=false
26 | flags/srgb=2
27 | process/fix_alpha_border=false
28 | process/premult_alpha=false
29 | process/HDR_as_SRGB=false
30 | process/invert_color=false
31 | process/normal_map_invert_y=false
32 | stream=false
33 | size_limit=0
34 | detect_3d=false
35 | svg/scale=1.0
36 |
--------------------------------------------------------------------------------
/unity/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "com.scrtwpns.mixbox",
3 | "version": "2.0.0",
4 | "displayName": "Mixbox",
5 | "description": "Pigment-Based Color Mixing",
6 | "unity": "2019.3",
7 | "author": {
8 | "name": "Secret Weapons",
9 | "email": "mixbox@scrtwpns.com",
10 | "url": "https://scrtwpns.com"
11 | },
12 | "samples": [
13 | {
14 | "displayName": "Built-in Samples",
15 | "description": "Contains sample shaders for the Built-in Render Pipelne",
16 | "path": "Samples~/SamplesBuiltin"
17 | },
18 | {
19 | "displayName": "URP Samples",
20 | "description": "Contains sample shaders for the Universal Render Pipelne",
21 | "path": "Samples~/SamplesURP"
22 | },
23 | {
24 | "displayName": "HDRP Samples",
25 | "description": "Contains sample shaders for the High Definition Render Pipelne",
26 | "path": "Samples~/SamplesHDRP"
27 | }
28 | ]
29 | }
30 |
--------------------------------------------------------------------------------
/javascript/examples/hello.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | BLUE
7 | MIXED
8 | YELLOW
9 |
10 |
11 |
21 |
22 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/javascript/examples/gradients.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
21 |
22 |
23 |
24 |
25 |
Pick colors
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/unity/Samples~/SamplesBuiltin/Shaders/MixboxSampleShader.shader:
--------------------------------------------------------------------------------
1 | Shader "Mixbox/Mixbox Sample Shader"
2 | {
3 | Properties
4 | {
5 | [NoScaleOffset] _MixboxLUT ("Mixbox LUT", 2D) = "white" {} // assign "Packages/Mixbox/Textures/MixboxLUT.png"
6 |
7 | _Color1 ("Color 1", Color) = (0, 0.129, 0.522, 1) // blue
8 | _Color2 ("Color 2", Color) = (0.988, 0.827, 0, 1) // yellow
9 | }
10 | SubShader
11 | {
12 | Pass
13 | {
14 | CGPROGRAM
15 | #pragma vertex vert
16 | #pragma fragment frag
17 |
18 | #include "UnityCG.cginc"
19 |
20 | sampler2D _MixboxLUT;
21 | #include "Packages/com.scrtwpns.mixbox/ShaderLibrary/Mixbox.cginc"
22 |
23 | fixed4 _Color1;
24 | fixed4 _Color2;
25 |
26 | struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; };
27 | struct v2f { float2 uv : TEXCOORD0; float4 vertex : SV_POSITION; };
28 |
29 | v2f vert (appdata v)
30 | {
31 | v2f o;
32 | o.vertex = UnityObjectToClipPos(v.vertex);
33 | o.uv = v.uv;
34 | return o;
35 | }
36 |
37 | fixed4 frag (v2f i) : SV_Target
38 | {
39 | fixed4 mixedColor = MixboxLerp(_Color1, _Color2, i.uv.x);
40 | return mixedColor;
41 | }
42 | ENDCG
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/javascript/examples/threejs.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/unity/Samples~/SamplesURP/Shaders/MixboxSampleURPShader.shader:
--------------------------------------------------------------------------------
1 | Shader "Mixbox/Mixbox URP Sample Shader"
2 | {
3 | Properties
4 | {
5 | [NoScaleOffset] _MixboxLUT ("Mixbox LUT", 2D) = "white" {} // assign "Packages/Mixbox/Textures/MixboxLUT.png"
6 |
7 | _Color1 ("Color 1", Color) = (0, 0.129, 0.522, 1) // blue
8 | _Color2 ("Color 2", Color) = (0.988, 0.827, 0, 1) // yellow
9 | }
10 |
11 | SubShader
12 | {
13 | Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalRenderPipeline" }
14 |
15 | Pass
16 | {
17 | HLSLPROGRAM
18 | #pragma vertex vert
19 | #pragma fragment frag
20 |
21 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
22 |
23 | TEXTURE2D(_MixboxLUT);
24 | SAMPLER(sampler_MixboxLUT);
25 |
26 | #include "Packages/com.scrtwpns.mixbox/ShaderLibrary/Mixbox.hlsl"
27 |
28 | struct Attributes { float4 positionOS : POSITION; float2 uv : TEXCOORD0; };
29 | struct Varyings { float4 positionHCS : SV_POSITION; float2 uv : TEXCOORD0; };
30 |
31 | CBUFFER_START(UnityPerMaterial)
32 | half4 _Color1;
33 | half4 _Color2;
34 | CBUFFER_END
35 |
36 | Varyings vert(Attributes IN)
37 | {
38 | Varyings OUT;
39 | OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
40 | OUT.uv = IN.uv;
41 | return OUT;
42 | }
43 |
44 | half4 frag(Varyings IN) : SV_Target
45 | {
46 | return MixboxLerp(_Color1, _Color2, IN.uv.x);
47 | }
48 | ENDHLSL
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/unity/ShaderLibrary/Mixbox.cginc:
--------------------------------------------------------------------------------
1 | // ==========================================================
2 | // MIXBOX 2.0 (c) 2022 Secret Weapons. All rights reserved.
3 | // License: Creative Commons Attribution-NonCommercial 4.0
4 | // Authors: Sarka Sochorova and Ondrej Jamriska
5 | // ==========================================================
6 | //
7 | // BASIC USAGE
8 | //
9 | // float3 rgb = MixboxLerp(rgb1, rgb2, t);
10 | //
11 | // MULTI-COLOR MIXING
12 | //
13 | // MixboxLatent z1 = MixboxRGBToLatent(rgb1);
14 | // MixboxLatent z2 = MixboxRGBToLatent(rgb2);
15 | // MixboxLatent z3 = MixboxRGBToLatent(rgb3);
16 | //
17 | // // mix 30% of rgb1, 60% of rgb2, and 10% of rgb3
18 | // MixboxLatent z_mix = 0.3*z1 + 0.6*z2 + 0.1*z3;
19 | //
20 | // float3 rgb_mix = MixboxLatentToRGB(z_mix);
21 | //
22 | // PIGMENT COLORS
23 | //
24 | // Cadmium Yellow 0.996, 0.925, 0.000
25 | // Hansa Yellow 0.988, 0.827, 0.000
26 | // Cadmium Orange 1.000, 0.412, 0.000
27 | // Cadmium Red 1.000, 0.153, 0.008
28 | // Quinacridone Magenta 0.502, 0.008, 0.180
29 | // Cobalt Violet 0.306, 0.000, 0.259
30 | // Ultramarine Blue 0.098, 0.000, 0.349
31 | // Cobalt Blue 0.000, 0.129, 0.522
32 | // Phthalo Blue 0.051, 0.106, 0.267
33 | // Phthalo Green 0.000, 0.235, 0.196
34 | // Permanent Green 0.027, 0.427, 0.086
35 | // Sap Green 0.420, 0.580, 0.016
36 | // Burnt Sienna 0.482, 0.282, 0.000
37 | //
38 | // LICENSING
39 | //
40 | // If you want to obtain commercial license, please
41 | // contact us at: mixbox@scrtwpns.com
42 | //
43 |
44 | #include "Packages/com.scrtwpns.mixbox/ShaderLibrary/Mixbox.hlsl"
45 |
--------------------------------------------------------------------------------
/unity/Samples~/SamplesURP/Materials/MixboxSampleURPShaderMaterial.mat:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!21 &2100000
4 | Material:
5 | serializedVersion: 8
6 | m_ObjectHideFlags: 0
7 | m_CorrespondingSourceObject: {fileID: 0}
8 | m_PrefabInstance: {fileID: 0}
9 | m_PrefabAsset: {fileID: 0}
10 | m_Name: MixboxSampleURPShaderMaterial
11 | m_Shader: {fileID: 4800000, guid: 2a107236c36652b42928a70f71fe9d06, type: 3}
12 | m_ValidKeywords: []
13 | m_InvalidKeywords: []
14 | m_LightmapFlags: 4
15 | m_EnableInstancingVariants: 0
16 | m_DoubleSidedGI: 0
17 | m_CustomRenderQueue: -1
18 | stringTagMap: {}
19 | disabledShaderPasses: []
20 | m_SavedProperties:
21 | serializedVersion: 3
22 | m_TexEnvs:
23 | - _AlphaTex:
24 | m_Texture: {fileID: 0}
25 | m_Scale: {x: 1, y: 1}
26 | m_Offset: {x: 0, y: 0}
27 | - _MainTex:
28 | m_Texture: {fileID: 0}
29 | m_Scale: {x: 1, y: 1}
30 | m_Offset: {x: 0, y: 0}
31 | - _MaskTex:
32 | m_Texture: {fileID: 0}
33 | m_Scale: {x: 1, y: 1}
34 | m_Offset: {x: 0, y: 0}
35 | - _MixboxLUT:
36 | m_Texture: {fileID: 2800000, guid: 9bb177930f1b0624ebcd9bdad8029652, type: 3}
37 | m_Scale: {x: 1, y: 1}
38 | m_Offset: {x: 0, y: 0}
39 | - _MixboxLerpCustomFunction_6d215c5b13de4fa59f8aa951085a2436_MixboxLUT_4:
40 | m_Texture: {fileID: 2800000, guid: 9bb177930f1b0624ebcd9bdad8029652, type: 3}
41 | m_Scale: {x: 1, y: 1}
42 | m_Offset: {x: 0, y: 0}
43 | - _NormalMap:
44 | m_Texture: {fileID: 0}
45 | m_Scale: {x: 1, y: 1}
46 | m_Offset: {x: 0, y: 0}
47 | - unity_Lightmaps:
48 | m_Texture: {fileID: 0}
49 | m_Scale: {x: 1, y: 1}
50 | m_Offset: {x: 0, y: 0}
51 | - unity_LightmapsInd:
52 | m_Texture: {fileID: 0}
53 | m_Scale: {x: 1, y: 1}
54 | m_Offset: {x: 0, y: 0}
55 | - unity_ShadowMasks:
56 | m_Texture: {fileID: 0}
57 | m_Scale: {x: 1, y: 1}
58 | m_Offset: {x: 0, y: 0}
59 | m_Ints: []
60 | m_Floats:
61 | - _EnableExternalAlpha: 0
62 | - _QueueControl: 0
63 | - _QueueOffset: 0
64 | m_Colors:
65 | - _Color: {r: 1, g: 1, b: 1, a: 1}
66 | - _Color1: {r: 0.988, g: 0.827, b: 0, a: 1}
67 | - _Color2: {r: 0.11, g: 0.071, b: 0.294, a: 1}
68 | - _Flip: {r: 1, g: 1, b: 1, a: 1}
69 | - _RendererColor: {r: 1, g: 1, b: 1, a: 1}
70 | m_BuildTextureStacks: []
71 |
--------------------------------------------------------------------------------
/java/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.scrtwpns
7 | mixbox
8 | 2.0.0
9 | jar
10 |
11 | mixbox
12 | Pigment-Based Color Mixing
13 | https://scrtwpns.com/mixbox
14 |
15 |
16 |
17 | CC-BY-NC-4.0
18 | https://creativecommons.org/licenses/by-nc/4.0/legalcode
19 | If you want to obtain commercial license, please contact: mixbox@scrtwpns.com
20 |
21 |
22 |
23 |
24 |
25 | Secret Weapons
26 | mixbox@scrtwpns.com
27 | Secret Weapons
28 | https://scrtwpns.com
29 |
30 |
31 |
32 |
33 | scm:git:git://github.com/scrtwpns/mixbox.git
34 | http://github.com/scrtwpns/mixbox
35 |
36 |
37 |
38 | UTF-8
39 | 1.7
40 | 1.7
41 |
42 |
43 |
44 |
45 |
46 | org.apache.maven.plugins
47 | maven-source-plugin
48 | 2.2.1
49 |
50 |
51 | attach-sources
52 |
53 | jar-no-fork
54 |
55 |
56 |
57 |
58 |
59 | org.apache.maven.plugins
60 | maven-javadoc-plugin
61 | 2.9.1
62 |
63 |
64 | attach-javadocs
65 |
66 | jar
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/webgl/example.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/javascript/examples/webgl.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/unity/Samples~/SamplesBuiltin/Materials/MixboxSampleMaterial.mat:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!21 &2100000
4 | Material:
5 | serializedVersion: 8
6 | m_ObjectHideFlags: 0
7 | m_CorrespondingSourceObject: {fileID: 0}
8 | m_PrefabInstance: {fileID: 0}
9 | m_PrefabAsset: {fileID: 0}
10 | m_Name: MixboxSampleMaterial
11 | m_Shader: {fileID: 4800000, guid: bb6490bc8e0170a40a722ad60ca9e82d, type: 3}
12 | m_ValidKeywords: []
13 | m_InvalidKeywords: []
14 | m_LightmapFlags: 4
15 | m_EnableInstancingVariants: 0
16 | m_DoubleSidedGI: 0
17 | m_CustomRenderQueue: -1
18 | stringTagMap: {}
19 | disabledShaderPasses: []
20 | m_SavedProperties:
21 | serializedVersion: 3
22 | m_TexEnvs:
23 | - _BumpMap:
24 | m_Texture: {fileID: 0}
25 | m_Scale: {x: 1, y: 1}
26 | m_Offset: {x: 0, y: 0}
27 | - _DetailAlbedoMap:
28 | m_Texture: {fileID: 0}
29 | m_Scale: {x: 1, y: 1}
30 | m_Offset: {x: 0, y: 0}
31 | - _DetailMask:
32 | m_Texture: {fileID: 0}
33 | m_Scale: {x: 1, y: 1}
34 | m_Offset: {x: 0, y: 0}
35 | - _DetailNormalMap:
36 | m_Texture: {fileID: 0}
37 | m_Scale: {x: 1, y: 1}
38 | m_Offset: {x: 0, y: 0}
39 | - _EmissionMap:
40 | m_Texture: {fileID: 0}
41 | m_Scale: {x: 1, y: 1}
42 | m_Offset: {x: 0, y: 0}
43 | - _MainTex:
44 | m_Texture: {fileID: 0}
45 | m_Scale: {x: 1, y: 1}
46 | m_Offset: {x: 0, y: 0}
47 | - _MetallicGlossMap:
48 | m_Texture: {fileID: 0}
49 | m_Scale: {x: 1, y: 1}
50 | m_Offset: {x: 0, y: 0}
51 | - _MixboxLUT:
52 | m_Texture: {fileID: 2800000, guid: 9bb177930f1b0624ebcd9bdad8029652, type: 3}
53 | m_Scale: {x: 1, y: 1}
54 | m_Offset: {x: 0, y: 0}
55 | - _OcclusionMap:
56 | m_Texture: {fileID: 0}
57 | m_Scale: {x: 1, y: 1}
58 | m_Offset: {x: 0, y: 0}
59 | - _ParallaxMap:
60 | m_Texture: {fileID: 0}
61 | m_Scale: {x: 1, y: 1}
62 | m_Offset: {x: 0, y: 0}
63 | m_Ints: []
64 | m_Floats:
65 | - _BumpScale: 1
66 | - _Cutoff: 0.5
67 | - _DetailNormalMapScale: 1
68 | - _DstBlend: 0
69 | - _GlossMapScale: 1
70 | - _Glossiness: 0.5
71 | - _GlossyReflections: 1
72 | - _Metallic: 0
73 | - _Mode: 0
74 | - _OcclusionStrength: 1
75 | - _Parallax: 0.02
76 | - _SmoothnessTextureChannel: 0
77 | - _SpecularHighlights: 1
78 | - _SrcBlend: 1
79 | - _UVSec: 0
80 | - _ZWrite: 1
81 | m_Colors:
82 | - _Color: {r: 1, g: 1, b: 1, a: 1}
83 | - _Color1: {r: 0.988, g: 0.827, b: 0, a: 1}
84 | - _Color2: {r: 0.11, g: 0.071, b: 0.294, a: 1}
85 | - _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
86 | m_BuildTextureStacks: []
87 |
--------------------------------------------------------------------------------
/unity/Samples~/SamplesURP/Materials/MixboxSampleShaderGraphMaterial.mat:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &-1103843176518887914
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 11
6 | m_CorrespondingSourceObject: {fileID: 0}
7 | m_PrefabInstance: {fileID: 0}
8 | m_PrefabAsset: {fileID: 0}
9 | m_GameObject: {fileID: 0}
10 | m_Enabled: 1
11 | m_EditorHideFlags: 0
12 | m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
13 | m_Name:
14 | m_EditorClassIdentifier:
15 | version: 5
16 | --- !u!21 &2100000
17 | Material:
18 | serializedVersion: 8
19 | m_ObjectHideFlags: 0
20 | m_CorrespondingSourceObject: {fileID: 0}
21 | m_PrefabInstance: {fileID: 0}
22 | m_PrefabAsset: {fileID: 0}
23 | m_Name: MixboxSampleShaderGraphMaterial
24 | m_Shader: {fileID: -6465566751694194690, guid: 878861faca4e2fa4ea3130c47204b113,
25 | type: 3}
26 | m_ValidKeywords: []
27 | m_InvalidKeywords: []
28 | m_LightmapFlags: 4
29 | m_EnableInstancingVariants: 0
30 | m_DoubleSidedGI: 0
31 | m_CustomRenderQueue: -1
32 | stringTagMap: {}
33 | disabledShaderPasses: []
34 | m_SavedProperties:
35 | serializedVersion: 3
36 | m_TexEnvs:
37 | - _AlphaTex:
38 | m_Texture: {fileID: 0}
39 | m_Scale: {x: 1, y: 1}
40 | m_Offset: {x: 0, y: 0}
41 | - _MainTex:
42 | m_Texture: {fileID: 0}
43 | m_Scale: {x: 1, y: 1}
44 | m_Offset: {x: 0, y: 0}
45 | - _MaskTex:
46 | m_Texture: {fileID: 0}
47 | m_Scale: {x: 1, y: 1}
48 | m_Offset: {x: 0, y: 0}
49 | - _MixboxLUT:
50 | m_Texture: {fileID: 2800000, guid: 9bb177930f1b0624ebcd9bdad8029652, type: 3}
51 | m_Scale: {x: 1, y: 1}
52 | m_Offset: {x: 0, y: 0}
53 | - _MixboxLerpCustomFunction_6d215c5b13de4fa59f8aa951085a2436_MixboxLUT_4:
54 | m_Texture: {fileID: 2800000, guid: 9bb177930f1b0624ebcd9bdad8029652, type: 3}
55 | m_Scale: {x: 1, y: 1}
56 | m_Offset: {x: 0, y: 0}
57 | - _NormalMap:
58 | m_Texture: {fileID: 0}
59 | m_Scale: {x: 1, y: 1}
60 | m_Offset: {x: 0, y: 0}
61 | - unity_Lightmaps:
62 | m_Texture: {fileID: 0}
63 | m_Scale: {x: 1, y: 1}
64 | m_Offset: {x: 0, y: 0}
65 | - unity_LightmapsInd:
66 | m_Texture: {fileID: 0}
67 | m_Scale: {x: 1, y: 1}
68 | m_Offset: {x: 0, y: 0}
69 | - unity_ShadowMasks:
70 | m_Texture: {fileID: 0}
71 | m_Scale: {x: 1, y: 1}
72 | m_Offset: {x: 0, y: 0}
73 | m_Ints: []
74 | m_Floats:
75 | - _EnableExternalAlpha: 0
76 | - _QueueControl: 0
77 | - _QueueOffset: 0
78 | m_Colors:
79 | - _Color: {r: 1, g: 1, b: 1, a: 1}
80 | - _Color1: {r: 0.988, g: 0.827, b: 0, a: 1}
81 | - _Color2: {r: 0.10999996, g: 0.07099997, b: 0.29399997, a: 1}
82 | - _Flip: {r: 1, g: 1, b: 1, a: 1}
83 | - _RendererColor: {r: 1, g: 1, b: 1, a: 1}
84 | m_BuildTextureStacks: []
85 |
--------------------------------------------------------------------------------
/javascript/examples/mountains.js:
--------------------------------------------------------------------------------
1 | let magenta, yellow, phthalo_blue, titanium_white, phthalo_medium;
2 |
3 | function setup()
4 | {
5 | createCanvas(800, 650);
6 | background(80);
7 | colorMode(RGB);
8 | strokeWeight(2);
9 |
10 | magenta = color(128,2,46);
11 | yellow = color(255,236,4);
12 | phthalo_blue = color(13,27,68);
13 | titanium_white = color(249,251,249);
14 | phthalo_medium = color(mixbox.lerp(phthalo_blue, titanium_white, 0.5));
15 | }
16 |
17 | function draw()
18 | {
19 | for(let y=0; y | 254, 236, 0 | 0.996, 0.925, 0.0 | 0.991, 0.839, 0.0 |
39 | | Hansa Yellow |
| 252, 211, 0 | 0.988, 0.827, 0.0 | 0.973, 0.651, 0.0 |
40 | | Cadmium Orange |
| 255, 105, 0 | 1.0, 0.412, 0.0 | 1.0, 0.141, 0.0 |
41 | | Cadmium Red |
| 255, 39, 2 | 1.0, 0.153, 0.008 | 1.0, 0.02, 0.001 |
42 | | Quinacridone Magenta |
| 128, 2, 46 | 0.502, 0.008, 0.18 | 0.216, 0.001, 0.027 |
43 | | Cobalt Violet |
| 78, 0, 66 | 0.306, 0.0, 0.259 | 0.076, 0.0, 0.054 |
44 | | Ultramarine Blue |
| 25, 0, 89 | 0.098, 0.0, 0.349 | 0.01, 0.0, 0.1 |
45 | | Cobalt Blue |
| 0, 33, 133 | 0.0, 0.129, 0.522 | 0.0, 0.015, 0.235 |
46 | | Phthalo Blue |
| 13, 27, 68 | 0.051, 0.106, 0.267 | 0.004, 0.011, 0.058 |
47 | | Phthalo Green |
| 0, 60, 50 | 0.0, 0.235, 0.196 | 0.0, 0.045, 0.032 |
48 | | Permanent Green |
| 7, 109, 22 | 0.027, 0.427, 0.086 | 0.002, 0.153, 0.008 |
49 | | Sap Green |
| 107, 148, 4 | 0.42, 0.58, 0.016 | 0.147, 0.296, 0.001 |
50 | | Burnt Sienna |
| 123, 72, 0 | 0.482, 0.282, 0.0 | 0.198, 0.065, 0.0 |
51 |
52 | ## License
53 | Copyright (c) 2022, Secret Weapons. All rights reserved.
54 | Mixbox is provided under the CC BY-NC 4.0 license for non-commercial use only.
55 | If you want to obtain commercial license, please contact: mixbox@scrtwpns.com
56 |
--------------------------------------------------------------------------------
/rust/README.md:
--------------------------------------------------------------------------------
1 | # Mixbox for Rust
2 | ```ini
3 | mixbox = "2.0.0" # add this line to your Cargo.toml
4 | ```
5 |
6 | ## Usage
7 | ```rust
8 | fn main() {
9 | let rgb1 = [0, 33, 133]; // blue
10 | let rgb2 = [252, 211, 0]; // yellow
11 | let t = 0.5; // mixing ratio
12 |
13 | let [r, g, b] = mixbox::lerp(&rgb1, &rgb2, t);
14 |
15 | println!("{} {} {}", r, g, b);
16 | }
17 | ```
18 |
19 | ## Mixing Multiple Colors
20 | ```rust
21 | let z1 = mixbox::rgb_to_latent(&rgb1);
22 | let z2 = mixbox::rgb_to_latent(&rgb2);
23 | let z3 = mixbox::rgb_to_latent(&rgb3);
24 |
25 | let mut z_mix = [0.0; mixbox::LATENT_SIZE];
26 |
27 | for i in 0..z_mix.len() { // mix together:
28 | z_mix[i] = 0.3*z1[i] + // 30% of rgb1
29 | 0.6*z2[i] + // 60% of rgb2
30 | 0.1*z3[i]; // 10% of rgb3
31 | }
32 |
33 | let rgb_mix = mixbox::latent_to_rgb(&z_mix);
34 | ```
35 |
36 | ## Pigment Colors
37 | | Pigment | | RGB | Float RGB | Linear RGB |
38 | | --- | --- |:----:|:----:|:----:|
39 | | Cadmium Yellow |
| 254, 236, 0 | 0.996, 0.925, 0.0 | 0.991, 0.839, 0.0 |
40 | | Hansa Yellow |
| 252, 211, 0 | 0.988, 0.827, 0.0 | 0.973, 0.651, 0.0 |
41 | | Cadmium Orange |
| 255, 105, 0 | 1.0, 0.412, 0.0 | 1.0, 0.141, 0.0 |
42 | | Cadmium Red |
| 255, 39, 2 | 1.0, 0.153, 0.008 | 1.0, 0.02, 0.001 |
43 | | Quinacridone Magenta |
| 128, 2, 46 | 0.502, 0.008, 0.18 | 0.216, 0.001, 0.027 |
44 | | Cobalt Violet |
| 78, 0, 66 | 0.306, 0.0, 0.259 | 0.076, 0.0, 0.054 |
45 | | Ultramarine Blue |
| 25, 0, 89 | 0.098, 0.0, 0.349 | 0.01, 0.0, 0.1 |
46 | | Cobalt Blue |
| 0, 33, 133 | 0.0, 0.129, 0.522 | 0.0, 0.015, 0.235 |
47 | | Phthalo Blue |
| 13, 27, 68 | 0.051, 0.106, 0.267 | 0.004, 0.011, 0.058 |
48 | | Phthalo Green |
| 0, 60, 50 | 0.0, 0.235, 0.196 | 0.0, 0.045, 0.032 |
49 | | Permanent Green |
| 7, 109, 22 | 0.027, 0.427, 0.086 | 0.002, 0.153, 0.008 |
50 | | Sap Green |
| 107, 148, 4 | 0.42, 0.58, 0.016 | 0.147, 0.296, 0.001 |
51 | | Burnt Sienna |
| 123, 72, 0 | 0.482, 0.282, 0.0 | 0.198, 0.065, 0.0 |
52 |
53 | ## License
54 | Copyright (c) 2022, Secret Weapons. All rights reserved.
55 | Mixbox is provided under the CC BY-NC 4.0 license for non-commercial use only.
56 | If you want to obtain commercial license, please contact: mixbox@scrtwpns.com
57 |
--------------------------------------------------------------------------------
/cpp/README.md:
--------------------------------------------------------------------------------
1 | ## Usage
2 | ```c++
3 | #include
4 | #include "mixbox.h"
5 |
6 | int main() {
7 | unsigned char r1 = 0, g1 = 33, b1 = 133; // blue
8 | unsigned char r2 = 252, g2 = 211, b2 = 0; // yellow
9 | float t = 0.5;
10 | unsigned char r, g, b;
11 |
12 | mixbox_lerp(r1, g1, b1, // first color
13 | r2, g2, b2, // second color
14 | t, // mixing ratio
15 | &r, &g, &b); // result
16 |
17 | printf("%d %d %d\n", r, g, b);
18 | }
19 | ```
20 | ## Mixing Multiple Colors
21 | ```c++
22 | mixbox_latent z1, z2, z3, z_mix;
23 |
24 | mixbox_rgb_to_latent(r1, g1, b1, z1);
25 | mixbox_rgb_to_latent(r2, g2, b2, z2);
26 | mixbox_rgb_to_latent(r3, g3, b3, z3);
27 |
28 | for (int i = 0; i < MIXBOX_LATENT_SIZE; i++) {
29 | // mix 30% of rgb1, 60% of rgb2, and 10% of rgb3
30 | z_mix[i] = 0.3f*z1[i] + 0.6f*z2[i] + 0.1f*z3[i];
31 | }
32 |
33 | mixbox_latent_to_rgb(z_mix, &r, &g, &b);
34 | ```
35 |
36 | ## Pigment Colors
37 | | Pigment | | RGB | Float RGB | Linear RGB |
38 | | --- | --- |:----:|:----:|:----:|
39 | | Cadmium Yellow |
| 254, 236, 0 | 0.996, 0.925, 0.0 | 0.991, 0.839, 0.0 |
40 | | Hansa Yellow |
| 252, 211, 0 | 0.988, 0.827, 0.0 | 0.973, 0.651, 0.0 |
41 | | Cadmium Orange |
| 255, 105, 0 | 1.0, 0.412, 0.0 | 1.0, 0.141, 0.0 |
42 | | Cadmium Red |
| 255, 39, 2 | 1.0, 0.153, 0.008 | 1.0, 0.02, 0.001 |
43 | | Quinacridone Magenta |
| 128, 2, 46 | 0.502, 0.008, 0.18 | 0.216, 0.001, 0.027 |
44 | | Cobalt Violet |
| 78, 0, 66 | 0.306, 0.0, 0.259 | 0.076, 0.0, 0.054 |
45 | | Ultramarine Blue |
| 25, 0, 89 | 0.098, 0.0, 0.349 | 0.01, 0.0, 0.1 |
46 | | Cobalt Blue |
| 0, 33, 133 | 0.0, 0.129, 0.522 | 0.0, 0.015, 0.235 |
47 | | Phthalo Blue |
| 13, 27, 68 | 0.051, 0.106, 0.267 | 0.004, 0.011, 0.058 |
48 | | Phthalo Green |
| 0, 60, 50 | 0.0, 0.235, 0.196 | 0.0, 0.045, 0.032 |
49 | | Permanent Green |
| 7, 109, 22 | 0.027, 0.427, 0.086 | 0.002, 0.153, 0.008 |
50 | | Sap Green |
| 107, 148, 4 | 0.42, 0.58, 0.016 | 0.147, 0.296, 0.001 |
51 | | Burnt Sienna |
| 123, 72, 0 | 0.482, 0.282, 0.0 | 0.198, 0.065, 0.0 |
52 |
53 | ## License
54 | Copyright (c) 2022, Secret Weapons. All rights reserved.
55 | Mixbox is provided under the CC BY-NC 4.0 license for non-commercial use only.
56 | If you want to obtain commercial license, please contact: mixbox@scrtwpns.com
57 |
--------------------------------------------------------------------------------
/webgl/README.md:
--------------------------------------------------------------------------------
1 | ## Mixbox in WebGL
2 |
3 | ```html
4 |
5 | ```
6 | ```javascript
7 | import mixbox from 'https://scrtwpns.com/mixbox.esm.js'; // for ES6 module use this instead
8 | ```
9 |
10 | ```javascript
11 | var shader = `
12 | precision highp float;
13 |
14 | // uncomment the following line if you work in linear space
15 | // #define MIXBOX_COLORSPACE_LINEAR
16 |
17 | uniform sampler2D mixbox_lut; // bind mixbox.lutTexture(gl) here
18 |
19 | #include "mixbox.glsl"
20 |
21 | void main(void) {
22 | vec3 rgb1 = vec3(0, 0.129, 0.522); // blue
23 | vec3 rgb2 = vec3(0.988, 0.827, 0); // yellow
24 | float t = 0.5; // mixing ratio
25 |
26 | vec3 rgb = mixbox_lerp(rgb1, rgb2, t);
27 |
28 | gl_FragColor = vec4(rgb, 1.0);
29 | }
30 | `;
31 |
32 | shader = shader.replace('#include "mixbox.glsl"', mixbox.glsl());
33 | ```
34 |
35 | ```javascript
36 | gl.useProgram(shaderProgram);
37 | gl.activeTexture(gl.TEXTURE0);
38 | gl.bindTexture(gl.TEXTURE_2D, mixbox.lutTexture(gl));
39 | gl.uniform1i(gl.getUniformLocation(shaderProgram, "mixbox_lut"), 0);
40 | ```
41 |
42 | ## Pigment Colors
43 | | Pigment | | RGB | Float RGB | Linear RGB |
44 | | --- | --- |:----:|:----:|:----:|
45 | | Cadmium Yellow |
| 254, 236, 0 | 0.996, 0.925, 0.0 | 0.991, 0.839, 0.0 |
46 | | Hansa Yellow |
| 252, 211, 0 | 0.988, 0.827, 0.0 | 0.973, 0.651, 0.0 |
47 | | Cadmium Orange |
| 255, 105, 0 | 1.0, 0.412, 0.0 | 1.0, 0.141, 0.0 |
48 | | Cadmium Red |
| 255, 39, 2 | 1.0, 0.153, 0.008 | 1.0, 0.02, 0.001 |
49 | | Quinacridone Magenta |
| 128, 2, 46 | 0.502, 0.008, 0.18 | 0.216, 0.001, 0.027 |
50 | | Cobalt Violet |
| 78, 0, 66 | 0.306, 0.0, 0.259 | 0.076, 0.0, 0.054 |
51 | | Ultramarine Blue |
| 25, 0, 89 | 0.098, 0.0, 0.349 | 0.01, 0.0, 0.1 |
52 | | Cobalt Blue |
| 0, 33, 133 | 0.0, 0.129, 0.522 | 0.0, 0.015, 0.235 |
53 | | Phthalo Blue |
| 13, 27, 68 | 0.051, 0.106, 0.267 | 0.004, 0.011, 0.058 |
54 | | Phthalo Green |
| 0, 60, 50 | 0.0, 0.235, 0.196 | 0.0, 0.045, 0.032 |
55 | | Permanent Green |
| 7, 109, 22 | 0.027, 0.427, 0.086 | 0.002, 0.153, 0.008 |
56 | | Sap Green |
| 107, 148, 4 | 0.42, 0.58, 0.016 | 0.147, 0.296, 0.001 |
57 | | Burnt Sienna |
| 123, 72, 0 | 0.482, 0.282, 0.0 | 0.198, 0.065, 0.0 |
58 |
59 | ## License
60 | Copyright (c) 2022, Secret Weapons. All rights reserved.
61 | Mixbox is provided under the CC BY-NC 4.0 license for non-commercial use only.
62 | If you want to obtain commercial license, please contact: mixbox@scrtwpns.com
63 |
--------------------------------------------------------------------------------
/unity/Textures/MixboxLUT.png.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9bb177930f1b0624ebcd9bdad8029652
3 | TextureImporter:
4 | internalIDToNameTable: []
5 | externalObjects: {}
6 | serializedVersion: 11
7 | mipmaps:
8 | mipMapMode: 0
9 | enableMipMap: 0
10 | sRGBTexture: 0
11 | linearTexture: 0
12 | fadeOut: 0
13 | borderMipMap: 0
14 | mipMapsPreserveCoverage: 0
15 | alphaTestReferenceValue: 0.5
16 | mipMapFadeDistanceStart: 1
17 | mipMapFadeDistanceEnd: 3
18 | bumpmap:
19 | convertToNormalMap: 0
20 | externalNormalMap: 0
21 | heightScale: 0.25
22 | normalMapFilter: 0
23 | isReadable: 0
24 | streamingMipmaps: 0
25 | streamingMipmapsPriority: 0
26 | vTOnly: 0
27 | grayScaleToAlpha: 0
28 | generateCubemap: 6
29 | cubemapConvolution: 0
30 | seamlessCubemap: 0
31 | textureFormat: 1
32 | maxTextureSize: 2048
33 | textureSettings:
34 | serializedVersion: 2
35 | filterMode: 1
36 | aniso: 0
37 | mipBias: 0
38 | wrapU: 1
39 | wrapV: 1
40 | wrapW: 1
41 | nPOTScale: 1
42 | lightmap: 0
43 | compressionQuality: 50
44 | spriteMode: 0
45 | spriteExtrude: 1
46 | spriteMeshType: 1
47 | alignment: 0
48 | spritePivot: {x: 0.5, y: 0.5}
49 | spritePixelsToUnits: 100
50 | spriteBorder: {x: 0, y: 0, z: 0, w: 0}
51 | spriteGenerateFallbackPhysicsShape: 1
52 | alphaUsage: 0
53 | alphaIsTransparency: 0
54 | spriteTessellationDetail: -1
55 | textureType: 0
56 | textureShape: 1
57 | singleChannelComponent: 0
58 | flipbookRows: 1
59 | flipbookColumns: 1
60 | maxTextureSizeSet: 0
61 | compressionQualitySet: 0
62 | textureFormatSet: 0
63 | ignorePngGamma: 0
64 | applyGammaDecoding: 0
65 | platformSettings:
66 | - serializedVersion: 3
67 | buildTarget: DefaultTexturePlatform
68 | maxTextureSize: 4096
69 | resizeAlgorithm: 0
70 | textureFormat: 3
71 | textureCompression: 0
72 | compressionQuality: 50
73 | crunchedCompression: 0
74 | allowsAlphaSplitting: 0
75 | overridden: 0
76 | androidETC2FallbackOverride: 0
77 | forceMaximumCompressionQuality_BC6H_BC7: 0
78 | - serializedVersion: 3
79 | buildTarget: Standalone
80 | maxTextureSize: 4096
81 | resizeAlgorithm: 0
82 | textureFormat: 3
83 | textureCompression: 0
84 | compressionQuality: 50
85 | crunchedCompression: 0
86 | allowsAlphaSplitting: 0
87 | overridden: 0
88 | androidETC2FallbackOverride: 0
89 | forceMaximumCompressionQuality_BC6H_BC7: 0
90 | - serializedVersion: 3
91 | buildTarget: WebGL
92 | maxTextureSize: 4096
93 | resizeAlgorithm: 0
94 | textureFormat: 3
95 | textureCompression: 0
96 | compressionQuality: 50
97 | crunchedCompression: 0
98 | allowsAlphaSplitting: 0
99 | overridden: 0
100 | androidETC2FallbackOverride: 0
101 | forceMaximumCompressionQuality_BC6H_BC7: 0
102 | spriteSheet:
103 | serializedVersion: 2
104 | sprites: []
105 | outline: []
106 | physicsShape: []
107 | bones: []
108 | spriteID:
109 | internalID: 0
110 | vertices: []
111 | indices:
112 | edges: []
113 | weights: []
114 | secondaryTextures: []
115 | spritePackingTag:
116 | pSDRemoveMatte: 0
117 | pSDShowRemoveMatteOption: 0
118 | userData:
119 | assetBundleName:
120 | assetBundleVariant:
121 |
--------------------------------------------------------------------------------
/csharp/README.md:
--------------------------------------------------------------------------------
1 | # Mixbox for C#
2 |
3 | Install Mixbox from the NuGet package: [`https://www.nuget.org/packages/Mixbox/2.0.0`](https://www.nuget.org/packages/Mixbox/2.0.0)
4 |
5 | ## Usage
6 |
7 | ```csharp
8 | using System.Drawing;
9 | using Scrtwpns.Mixbox;
10 |
11 | public class HelloMixbox
12 | {
13 | public static void Main(string[] args)
14 | {
15 | Color color1 = Color.FromArgb(0, 33, 133); // blue
16 | Color color2 = Color.FromArgb(252, 211, 0); // yellow
17 | float t = 0.5f; // mixing ratio
18 |
19 | Color colorMix = Color.FromArgb(Mixbox.Lerp(color1.ToArgb(), color2.ToArgb(), t));
20 |
21 | System.Console.WriteLine(colorMix);
22 | }
23 | }
24 | ```
25 |
26 | ## Mixing Multiple Colors
27 |
28 | ```csharp
29 | Color MixThree(Color color1, Color color2, Color color3)
30 | {
31 | MixboxLatent z1 = Mixbox.RGBToLatent(color1.ToArgb());
32 | MixboxLatent z2 = Mixbox.RGBToLatent(color2.ToArgb());
33 | MixboxLatent z3 = Mixbox.RGBToLatent(color3.ToArgb());
34 |
35 | // mix 30% of color1, 60% of color2, and 10% of color3
36 | MixboxLatent zMix = 0.3f*z1 + 0.6f*z2 + 0.1f*z3;
37 |
38 | return Color.FromArgb(Mixbox.LatentToRGB(zMix));
39 | }
40 | ```
41 |
42 | ## Pigment Colors
43 | | Pigment | | RGB | Float RGB | Linear RGB |
44 | | --- | --- |:----:|:----:|:----:|
45 | | Cadmium Yellow |
| 254, 236, 0 | 0.996, 0.925, 0.0 | 0.991, 0.839, 0.0 |
46 | | Hansa Yellow |
| 252, 211, 0 | 0.988, 0.827, 0.0 | 0.973, 0.651, 0.0 |
47 | | Cadmium Orange |
| 255, 105, 0 | 1.0, 0.412, 0.0 | 1.0, 0.141, 0.0 |
48 | | Cadmium Red |
| 255, 39, 2 | 1.0, 0.153, 0.008 | 1.0, 0.02, 0.001 |
49 | | Quinacridone Magenta |
| 128, 2, 46 | 0.502, 0.008, 0.18 | 0.216, 0.001, 0.027 |
50 | | Cobalt Violet |
| 78, 0, 66 | 0.306, 0.0, 0.259 | 0.076, 0.0, 0.054 |
51 | | Ultramarine Blue |
| 25, 0, 89 | 0.098, 0.0, 0.349 | 0.01, 0.0, 0.1 |
52 | | Cobalt Blue |
| 0, 33, 133 | 0.0, 0.129, 0.522 | 0.0, 0.015, 0.235 |
53 | | Phthalo Blue |
| 13, 27, 68 | 0.051, 0.106, 0.267 | 0.004, 0.011, 0.058 |
54 | | Phthalo Green |
| 0, 60, 50 | 0.0, 0.235, 0.196 | 0.0, 0.045, 0.032 |
55 | | Permanent Green |
| 7, 109, 22 | 0.027, 0.427, 0.086 | 0.002, 0.153, 0.008 |
56 | | Sap Green |
| 107, 148, 4 | 0.42, 0.58, 0.016 | 0.147, 0.296, 0.001 |
57 | | Burnt Sienna |
| 123, 72, 0 | 0.482, 0.282, 0.0 | 0.198, 0.065, 0.0 |
58 |
59 | ## License
60 | Copyright (c) 2022, Secret Weapons. All rights reserved.
61 | Mixbox is provided under the CC BY-NC 4.0 license for non-commercial use only.
62 | If you want to obtain commercial license, please contact: mixbox@scrtwpns.com
63 |
--------------------------------------------------------------------------------
/cpp/mixbox.h:
--------------------------------------------------------------------------------
1 | // ==========================================================
2 | // MIXBOX 2.0 (c) 2022 Secret Weapons. All rights reserved.
3 | // License: Creative Commons Attribution-NonCommercial 4.0
4 | // Authors: Sarka Sochorova and Ondrej Jamriska
5 | // ==========================================================
6 | //
7 | // BASIC USAGE
8 | //
9 | // mixbox_lerp(r1, g1, b1, // 1st color
10 | // r2, g2, b2, // 2nd color
11 | // t, // mixing ratio
12 | // &r, &g, &b); // result
13 | //
14 | // MULTI-COLOR MIXING
15 | //
16 | // mixbox_latent z1, z2, z3, z_mix;
17 | // mixbox_rgb_to_latent(r1, g1, b1, z1);
18 | // mixbox_rgb_to_latent(r2, g2, b2, z2);
19 | // mixbox_rgb_to_latent(r3, g3, b3, z3);
20 | //
21 | // for (int i = 0; i < MIXBOX_LATENT_SIZE; i++) {
22 | // // mix 30% of rgb1, 60% of rgb2, and 10% of rgb3
23 | // z_mix[i] = 0.3f*z1[i] + 0.6f*z2[i] + 0.1f*z3[i];
24 | // }
25 | //
26 | // mixbox_latent_to_rgb(z_mix, &r, &g, &b);
27 | //
28 | // PIGMENT COLORS
29 | //
30 | // Cadmium Yellow 254, 236, 0
31 | // Hansa Yellow 252, 211, 0
32 | // Cadmium Orange 255, 105, 0
33 | // Cadmium Red 255, 39, 2
34 | // Quinacridone Magenta 128, 2, 46
35 | // Cobalt Violet 78, 0, 66
36 | // Ultramarine Blue 25, 0, 89
37 | // Cobalt Blue 0, 33, 133
38 | // Phthalo Blue 13, 27, 68
39 | // Phthalo Green 0, 60, 50
40 | // Permanent Green 7, 109, 22
41 | // Sap Green 107, 148, 4
42 | // Burnt Sienna 123, 72, 0
43 | //
44 | // LICENSING
45 | //
46 | // If you want to obtain commercial license, please
47 | // contact us at: mixbox@scrtwpns.com
48 | //
49 |
50 | #ifndef MIXBOX_H_
51 | #define MIXBOX_H_
52 |
53 | #ifdef __cplusplus
54 | extern "C" {
55 | #endif
56 |
57 | #define MIXBOX_LATENT_SIZE 7
58 |
59 | typedef float mixbox_latent[MIXBOX_LATENT_SIZE];
60 |
61 | void mixbox_lerp(unsigned char r1, unsigned char g1, unsigned char b1,
62 | unsigned char r2, unsigned char g2, unsigned char b2,
63 | float t,
64 | unsigned char* out_r, unsigned char* out_g, unsigned char* out_b);
65 |
66 | void mixbox_lerp_float(float r1, float g1, float b1,
67 | float r2, float g2, float b2,
68 | float t,
69 | float* out_r, float* out_g, float* out_b);
70 |
71 | void mixbox_lerp_linear_float(float r1, float g1, float b1,
72 | float r2, float g2, float b2,
73 | float t,
74 | float* out_r, float* out_g, float* out_b);
75 |
76 | void mixbox_rgb_to_latent(unsigned char r, unsigned char g, unsigned char b, mixbox_latent out_latent);
77 | void mixbox_latent_to_rgb(mixbox_latent latent, unsigned char* out_r, unsigned char* out_g, unsigned char* out_b);
78 |
79 | void mixbox_float_rgb_to_latent(float r, float g, float b, mixbox_latent out_latent);
80 | void mixbox_latent_to_float_rgb(mixbox_latent latent, float* out_r, float* out_g, float* out_b);
81 |
82 | void mixbox_linear_float_rgb_to_latent(float r, float g, float b, mixbox_latent out_latent);
83 | void mixbox_latent_to_linear_float_rgb(mixbox_latent latent, float* out_r, float* out_g, float* out_b);
84 |
85 | #ifdef __cplusplus
86 | }
87 | #endif
88 |
89 | #endif
90 |
--------------------------------------------------------------------------------
/javascript/examples/palette.js:
--------------------------------------------------------------------------------
1 | var visited = []; // coordinates of the boxes the mouse has visited while pressed once
2 | var boxes = []; // all boxes that should be displayed and colored, item is an array [x, y, R, G, B]
3 | let boxSize = 40;
4 | let color1;
5 | let color2;
6 | let valid_start = false;
7 | let valid_end = false;
8 |
9 | function setup() {
10 |
11 | createCanvas(800, 680);
12 | background(80);
13 | colorMode(RGB);
14 | rectMode(CENTER);
15 |
16 | boxes.push([ 60, 60,[ 13, 27, 68]]); // phthalo blue
17 | boxes.push([580, 180,[255, 236, 4]]); // bis yellow
18 | boxes.push([420, 60,[255, 236, 4]]); // bis yellow
19 | boxes.push([220, 300,[255, 208, 0]]); // hansa yellow
20 | boxes.push([420, 380,[ 25, 0, 89]]); // ultramarine blue
21 | boxes.push([500, 260,[ 25, 0, 89]]); // ultramarine blue
22 | boxes.push([700, 380,[225, 35, 1]]); // cadmium red
23 | boxes.push([580, 580,[128, 2, 46]]); // magenta
24 | boxes.push([100, 580,[249, 250, 249]]); // white
25 | boxes.push([260, 580,[249, 250, 249]]); // white
26 | drawBoxes();
27 | }
28 |
29 | function draw()
30 | {
31 | // record visited boxes
32 | if(mouseIsPressed === true)
33 | {
34 | let x = snapToGrid(mouseX);
35 | let y = snapToGrid(mouseY);
36 |
37 | let alreadyIn = false;
38 | for(let v=0; v 0)
47 | {
48 | stroke(230);
49 | noFill();
50 | setLineDash([5, 5]);
51 | for(let v=0; v1 ? v * 1.0/(numVisited-1) : 1;
78 | let mixedColor = mixbox.lerp(color1, color2, t);
79 | boxes.push([visited[v][0], visited[v][1], mixedColor]);
80 | }
81 | }
82 | else{alert("You must start and end inside colored squares.");}
83 | }
84 |
85 |
86 | // clear visited array
87 | visited = [];
88 |
89 | // redraw screen to erase the overlay, clear background, draw boxes
90 | background(80);
91 | drawBoxes();
92 |
93 | }
94 |
95 | function drawBoxes()
96 | {
97 | noStroke();
98 | for(let b=0; b 0 && mouseX < width && mouseY > 0 && mouseY < height) {return true;}
128 | else {return false};
129 | }
130 |
--------------------------------------------------------------------------------
/unity/ShaderGraph/CustomFunctions/MixboxFunctions.hlsl:
--------------------------------------------------------------------------------
1 | #ifndef MIXBOX_FUNCTIONS_INCLUDED
2 | #define MIXBOX_FUNCTIONS_INCLUDED
3 |
4 | #ifndef UNITY_COLORSPACE_GAMMA
5 | #define MIXBOX_COLORSPACE_LINEAR
6 | #endif
7 |
8 | #define MIXBOX_LUT(UV) SAMPLE_TEXTURE2D_LOD(MixboxLUT.tex, MixboxLUT.samplerstate, UV, 0)
9 |
10 | typedef float3x3 MixboxLatent;
11 |
12 | float3 MixboxEvalPolynomial(float3 c)
13 | {
14 | float c0 = c[0];
15 | float c1 = c[1];
16 | float c2 = c[2];
17 | float c3 = 1.0 - (c0 + c1 + c2);
18 |
19 | float c00 = c0 * c0;
20 | float c11 = c1 * c1;
21 | float c22 = c2 * c2;
22 | float c01 = c0 * c1;
23 | float c02 = c0 * c2;
24 | float c12 = c1 * c2;
25 | float c33 = c3 * c3;
26 |
27 | return (c0*c00) * float3(+0.07717053, +0.02826978, +0.24832992) +
28 | (c1*c11) * float3(+0.95912302, +0.80256528, +0.03561839) +
29 | (c2*c22) * float3(+0.74683774, +0.04868586, +0.00000000) +
30 | (c3*c33) * float3(+0.99518138, +0.99978149, +0.99704802) +
31 | (c00*c1) * float3(+0.04819146, +0.83363781, +0.32515377) +
32 | (c01*c1) * float3(-0.68146950, +1.46107803, +1.06980936) +
33 | (c00*c2) * float3(+0.27058419, -0.15324870, +1.98735057) +
34 | (c02*c2) * float3(+0.80478189, +0.67093710, +0.18424500) +
35 | (c00*c3) * float3(-0.35031003, +1.37855826, +3.68865000) +
36 | (c0*c33) * float3(+1.05128046, +1.97815239, +2.82989073) +
37 | (c11*c2) * float3(+3.21607125, +0.81270228, +1.03384539) +
38 | (c1*c22) * float3(+2.78893374, +0.41565549, -0.04487295) +
39 | (c11*c3) * float3(+3.02162577, +2.55374103, +0.32766114) +
40 | (c1*c33) * float3(+2.95124691, +2.81201112, +1.17578442) +
41 | (c22*c3) * float3(+2.82677043, +0.79933038, +1.81715262) +
42 | (c2*c33) * float3(+2.99691099, +1.22593053, +1.80653661) +
43 | (c01*c2) * float3(+1.87394106, +2.05027182, -0.29835996) +
44 | (c01*c3) * float3(+2.56609566, +7.03428198, +0.62575374) +
45 | (c02*c3) * float3(+4.08329484, -1.40408358, +2.14995522) +
46 | (c12*c3) * float3(+6.00078678, +2.55552042, +1.90739502);
47 | }
48 |
49 | float3 MixboxSRGBToLinear(float3 rgb)
50 | {
51 | return (rgb >= 0.04045) ? pow((abs(rgb) + 0.055) / 1.055, 2.4) : rgb/12.92;
52 | }
53 |
54 | float3 MixboxLinearToSRGB(float3 rgb)
55 | {
56 | return (rgb >= 0.0031308) ? 1.055*pow(abs(rgb), 1.0/2.4) - 0.055 : 12.92*rgb;
57 | }
58 |
59 | MixboxLatent MixboxRGBToLatent(UnityTexture2D MixboxLUT,float3 rgb)
60 | {
61 | #ifdef MIXBOX_COLORSPACE_LINEAR
62 | rgb = MixboxLinearToSRGB(saturate(rgb));
63 | #else
64 | rgb = saturate(rgb);
65 | #endif
66 |
67 | float x = rgb.r * 63.0;
68 | float y = rgb.g * 63.0;
69 | float z = rgb.b * 63.0;
70 |
71 | float iz = floor(z);
72 |
73 | float x0 = fmod(iz, 8.0) * 64.0;
74 | float y0 = floor(iz / 8.0) * 64.0;
75 |
76 | float x1 = fmod(iz + 1.0, 8.0) * 64.0;
77 | float y1 = floor((iz + 1.0) / 8.0) * 64.0;
78 |
79 | float2 uv0 = float2(x0 + x + 0.5, 512.0 - (y0 + y + 0.5)) / 512.0;
80 | float2 uv1 = float2(x1 + x + 0.5, 512.0 - (y1 + y + 0.5)) / 512.0;
81 |
82 | float3 c = lerp(MIXBOX_LUT(uv0).rgb, MIXBOX_LUT(uv1).rgb, z - iz);
83 |
84 | return MixboxLatent(c, rgb - MixboxEvalPolynomial(c), 0.0, 0.0, 0.0);
85 | }
86 |
87 | float3 MixboxLatentToRGB(MixboxLatent latent)
88 | {
89 | float3 rgb = saturate(MixboxEvalPolynomial(latent[0]) + latent[1]);
90 |
91 | #ifdef MIXBOX_COLORSPACE_LINEAR
92 | return MixboxSRGBToLinear(rgb);
93 | #else
94 | return rgb;
95 | #endif
96 | }
97 |
98 | void MixboxLerp_float(float4 A, float4 B, float T, UnityTexture2D MixboxLUT, out float4 Out)
99 | {
100 | Out = float4(MixboxLatentToRGB((1.0-T)*MixboxRGBToLatent(MixboxLUT, A.rgb) + T*MixboxRGBToLatent(MixboxLUT, B.rgb)), lerp(A.a, B.a, T));
101 | }
102 |
103 | #endif
104 |
--------------------------------------------------------------------------------
/godot/README.md:
--------------------------------------------------------------------------------
1 | # Mixbox for Godot
2 | ```gdscript
3 | var Mixbox = preload("res://addons/mixbox/mixbox.gd")
4 |
5 | var color1 = Color(0.0, 0.129, 0.522) # blue
6 | var color2 = Color(0.988, 0.827, 0.0) # yellow
7 | var t = 0.5 # mixing ratio
8 |
9 | var color_mix = Mixbox.lerp(color1, color2, t)
10 |
11 | print(color_mix)
12 | ```
13 |
14 | ## Mixing Multiple Colors
15 | ```gdscript
16 | var z1 = Mixbox.rgb_to_latent(color1)
17 | var z2 = Mixbox.rgb_to_latent(color2)
18 | var z3 = Mixbox.rgb_to_latent(color3)
19 |
20 | var z_mix = []
21 | z_mix.resize(Mixbox.LATENT_SIZE)
22 |
23 | for i in z_mix.size(): # mix together:
24 | z_mix[i] = (0.3*z1[i] + # 30% of color1
25 | 0.6*z2[i] + # 60% of color2
26 | 0.1*z3[i]) # 10% of color3
27 |
28 | var color_mix = Mixbox.latent_to_rgb(z_mix)
29 | ```
30 |
31 | # Shader
32 | ```c++
33 | shader_type canvas_item;
34 |
35 | uniform sampler2D mixbox_lut; // attach "addons/mixbox/mixbox_lut.png" here
36 |
37 | uniform vec4 color1 : hint_color = vec4(0.0, 0.129, 0.522, 1.0); // blue
38 | uniform vec4 color2 : hint_color = vec4(0.988, 0.827, 0.0, 1.0); // yellow
39 |
40 | // #include only works in Godot 4, if you are on Godot 3.X
41 | // you will need to paste the Mixbox code here manually.
42 | #include "addons/mixbox/mixbox.gdshaderinc"
43 |
44 | void fragment() {
45 | COLOR = mixbox_lerp(color1, color2, UV.x);
46 | }
47 | ```
48 |
49 |
50 |
51 |
52 | ## Mixing Multiple Colors
53 |
54 | ```glsl
55 | mat3 z1 = mixbox_rgb_to_latent(color1.rgb);
56 | mat3 z2 = mixbox_rgb_to_latent(color2.rgb);
57 | mat3 z3 = mixbox_rgb_to_latent(color3.rgb);
58 |
59 | // mix together 30% of color1, 60% of color2, and 10% of color3
60 | mat3 z_mix = 0.3*z1 + 0.6*z2 + 0.1*z3;
61 |
62 | vec3 rgb_mix = mixbox_latent_to_rgb(z_mix);
63 | ```
64 |
65 | # VisualShader
66 |
67 |
68 |
69 |
70 | ## Pigment Colors
71 | | Pigment | | RGB | Float RGB | Linear RGB |
72 | | --- | --- |:----:|:----:|:----:|
73 | | Cadmium Yellow |
| 254, 236, 0 | 0.996, 0.925, 0.0 | 0.991, 0.839, 0.0 |
74 | | Hansa Yellow |
| 252, 211, 0 | 0.988, 0.827, 0.0 | 0.973, 0.651, 0.0 |
75 | | Cadmium Orange |
| 255, 105, 0 | 1.0, 0.412, 0.0 | 1.0, 0.141, 0.0 |
76 | | Cadmium Red |
| 255, 39, 2 | 1.0, 0.153, 0.008 | 1.0, 0.02, 0.001 |
77 | | Quinacridone Magenta |
| 128, 2, 46 | 0.502, 0.008, 0.18 | 0.216, 0.001, 0.027 |
78 | | Cobalt Violet |
| 78, 0, 66 | 0.306, 0.0, 0.259 | 0.076, 0.0, 0.054 |
79 | | Ultramarine Blue |
| 25, 0, 89 | 0.098, 0.0, 0.349 | 0.01, 0.0, 0.1 |
80 | | Cobalt Blue |
| 0, 33, 133 | 0.0, 0.129, 0.522 | 0.0, 0.015, 0.235 |
81 | | Phthalo Blue |
| 13, 27, 68 | 0.051, 0.106, 0.267 | 0.004, 0.011, 0.058 |
82 | | Phthalo Green |
| 0, 60, 50 | 0.0, 0.235, 0.196 | 0.0, 0.045, 0.032 |
83 | | Permanent Green |
| 7, 109, 22 | 0.027, 0.427, 0.086 | 0.002, 0.153, 0.008 |
84 | | Sap Green |
| 107, 148, 4 | 0.42, 0.58, 0.016 | 0.147, 0.296, 0.001 |
85 | | Burnt Sienna |
| 123, 72, 0 | 0.482, 0.282, 0.0 | 0.198, 0.065, 0.0 |
86 |
87 | ## License
88 | Copyright (c) 2022, Secret Weapons. All rights reserved.
89 | Mixbox is provided under the CC BY-NC 4.0 license for non-commercial use only.
90 | If you want to obtain commercial license, please contact: mixbox@scrtwpns.com
91 |
--------------------------------------------------------------------------------
/javascript/examples/mixer.js:
--------------------------------------------------------------------------------
1 | let width = 650;
2 | let height = 650;
3 | let center_x = width/2;
4 | let center_y = height/2;
5 | let outer_radius = 300;
6 | let inner_radius = 100;
7 | let circle_radius = 45;
8 | var colors = [];
9 | var centers_outside = [];
10 | var centers_inside = [];
11 | var sliders_pos = [];
12 | var mix_t = [];
13 | let numPigments = 0;
14 | let step = 0;
15 | let dragged = -1;
16 |
17 | function setup() {
18 | createCanvas(650, 650);
19 | background(255);
20 | colorMode(RGB);
21 | stroke(125);
22 | strokeWeight(3);
23 |
24 | colors = [color( 255,236,4), color( 252,211,0), color( 255,105,0), color( 225,35,1), color( 191,0,18), color( 128,2,46), color( 78,1,66), color( 74,0,101), color( 16,31,61), color( 13, 27, 68), color( 25, 0, 89), color( 8,34,138), color( 12, 69,118), color( 6, 54, 51), color( 0,74,41), color( 84,50,36), color( 58,39,0), color( 13,9,1), color(249,250,249)];
25 |
26 | numPigments = colors.length;
27 | step = TWO_PI / numPigments;
28 |
29 | for(let i=0; i -1)
53 | {
54 | mix_t[dragged] = get_t(centers_outside[dragged].x, centers_outside[dragged].y, centers_inside[dragged].x, centers_inside[dragged].y, mouseX, mouseY);
55 | sliders_pos[dragged] = createVector(centers_outside[dragged].x - sin(dragged * step) * mix_t[dragged] * (outer_radius-inner_radius),
56 | centers_outside[dragged].y - cos(dragged * step) * mix_t[dragged] * (outer_radius-inner_radius));
57 |
58 | background(255);
59 | let weights = 0;
60 |
61 | for(let i=0; i 0.000001)
71 | {
72 | let latent_mix = [0,0,0,0,0,0,0];
73 | for(let j=0; j0.000001)
76 | {
77 | let latent = mixbox.rgbToLatent(colors[j]);
78 | let t = mix_t[j]/weights;
79 | for(let k=0; k sliders_pos[i].x - circle_radius/2 &&
104 | mouseX < sliders_pos[i].x + circle_radius/2 &&
105 | mouseY > sliders_pos[i].y - circle_radius/2 &&
106 | mouseY < sliders_pos[i].y + circle_radius/2)
107 | {
108 | dragged = i;
109 | }
110 | }
111 | }
112 |
113 | function mouseReleased()
114 | {
115 | dragged = -1;
116 | }
117 |
118 | function get_t (ax, ay, bx, by, qx, qy)
119 | {
120 | let u = createVector(bx-ax, by-ay);
121 | let v = createVector(qx-ax, qy-ay);
122 |
123 | let d = (u.x*v.x + u.y*v.y) / u.mag();
124 | let t = d/u.mag();
125 |
126 | return clamp(t, 0.0, 1.0);
127 | }
128 |
129 | function clamp(x, lowerlimit, upperlimit) {
130 | if (xupperlimit){return upperlimit;}
132 | else {return x;}
133 | }
134 |
--------------------------------------------------------------------------------
/java/README.md:
--------------------------------------------------------------------------------
1 | # Mixbox for Java
2 |
3 | ```java
4 | import java.awt.Color;
5 | import com.scrtwpns.Mixbox;
6 |
7 | class HelloMixbox {
8 | public static void main(String[] args) {
9 | Color color1 = new Color(0, 33, 133); // blue
10 | Color color2 = new Color(252, 211, 0); // yellow
11 | float t = 0.5f; // mixing ratio
12 |
13 | Color colorMix = new Color(Mixbox.lerp(color1.getRGB(), color2.getRGB(), t));
14 |
15 | System.out.print(colorMix);
16 | }
17 | }
18 | ```
19 |
20 | ## Android
21 | ```java
22 | package com.example.mixboxhelloworld;
23 |
24 | import android.app.Activity;
25 | import android.os.Bundle;
26 | import android.view.View;
27 | import android.graphics.Color;
28 |
29 | import com.scrtwpns.Mixbox;
30 |
31 | public class MainActivity extends Activity {
32 | @Override
33 | protected void onCreate(Bundle savedInstanceState) {
34 | super.onCreate(savedInstanceState);
35 |
36 | int color1 = Color.rgb(0, 33, 133); // blue
37 | int color2 = Color.rgb(252, 211, 0); // yellow
38 | float t = 0.5f; // mixing ratio
39 |
40 | int colorMix = Mixbox.lerp(color1, color2, t);
41 |
42 | View view = new View(this);
43 | view.setBackgroundColor(colorMix);
44 | setContentView(view);
45 | }
46 | }
47 | ```
48 |
49 | ## Mixing Multiple Colors
50 | ```java
51 | int mixThree(int color1, int color2, int color3) {
52 | float[] z1 = Mixbox.rgbToLatent(color1);
53 | float[] z2 = Mixbox.rgbToLatent(color2);
54 | float[] z3 = Mixbox.rgbToLatent(color3);
55 |
56 | float[] zMix = new float[Mixbox.LATENT_SIZE];
57 |
58 | for(int i = 0; i < zMix.length; i++) {
59 | // mix 30% of color1, 60% of color2, and 10% of color3
60 | zMix[i] = 0.3f*z1[i] + 0.6f*z2[i] + 0.1f*z3[i];
61 | }
62 |
63 | return Mixbox.latentToRgb(zMix);
64 | }
65 | ```
66 |
67 | ## Maven
68 | ```xml
69 |
70 | com.scrtwpns
71 | mixbox
72 | 2.0.0
73 | jar
74 |
75 | ```
76 |
77 | ## Gradle
78 | ```groovy
79 | implementation 'com.scrtwpns:mixbox:2.0.0' // Groovy
80 | ```
81 | ```kotlin
82 | implementation("com.scrtwpns:mixbox:2.0.0") // Kotlin
83 | ```
84 |
85 | ## Pigment Colors
86 | | Pigment | | RGB | Float RGB | Linear RGB |
87 | | --- | --- |:----:|:----:|:----:|
88 | | Cadmium Yellow |
| 254, 236, 0 | 0.996, 0.925, 0.0 | 0.991, 0.839, 0.0 |
89 | | Hansa Yellow |
| 252, 211, 0 | 0.988, 0.827, 0.0 | 0.973, 0.651, 0.0 |
90 | | Cadmium Orange |
| 255, 105, 0 | 1.0, 0.412, 0.0 | 1.0, 0.141, 0.0 |
91 | | Cadmium Red |
| 255, 39, 2 | 1.0, 0.153, 0.008 | 1.0, 0.02, 0.001 |
92 | | Quinacridone Magenta |
| 128, 2, 46 | 0.502, 0.008, 0.18 | 0.216, 0.001, 0.027 |
93 | | Cobalt Violet |
| 78, 0, 66 | 0.306, 0.0, 0.259 | 0.076, 0.0, 0.054 |
94 | | Ultramarine Blue |
| 25, 0, 89 | 0.098, 0.0, 0.349 | 0.01, 0.0, 0.1 |
95 | | Cobalt Blue |
| 0, 33, 133 | 0.0, 0.129, 0.522 | 0.0, 0.015, 0.235 |
96 | | Phthalo Blue |
| 13, 27, 68 | 0.051, 0.106, 0.267 | 0.004, 0.011, 0.058 |
97 | | Phthalo Green |
| 0, 60, 50 | 0.0, 0.235, 0.196 | 0.0, 0.045, 0.032 |
98 | | Permanent Green |
| 7, 109, 22 | 0.027, 0.427, 0.086 | 0.002, 0.153, 0.008 |
99 | | Sap Green |
| 107, 148, 4 | 0.42, 0.58, 0.016 | 0.147, 0.296, 0.001 |
100 | | Burnt Sienna |
| 123, 72, 0 | 0.482, 0.282, 0.0 | 0.198, 0.065, 0.0 |
101 |
102 | ## License
103 | Copyright (c) 2022, Secret Weapons. All rights reserved.
104 | Mixbox is provided under the CC BY-NC 4.0 license for non-commercial use only.
105 | If you want to obtain commercial license, please contact: mixbox@scrtwpns.com
106 |
--------------------------------------------------------------------------------
/javascript/examples/gradients.js:
--------------------------------------------------------------------------------
1 | let colorPicker_A;
2 | let colorPicker_B;
3 | let color_A;
4 | let color_B;
5 |
6 | function setup() {
7 | createCanvas(650, 465);
8 | background(255);
9 | colorMode(RGB);
10 |
11 | colorPicker_A = createColorPicker('#002185');
12 | colorPicker_A.parent('picker-A');
13 | color_A = colorPicker_A.color();
14 |
15 | colorPicker_B = createColorPicker('#fcd200');
16 | colorPicker_B.parent('picker-B');
17 | color_B = colorPicker_B.color();
18 |
19 | drawGradient("Mixbox", color_A, color_B, 50, 200, 65, 465);
20 | drawGradient("RGB", color_A, color_B, 250, 400, 65, 465);
21 | drawGradient("OkLab", color_A, color_B, 450, 600, 65, 465);
22 |
23 | }
24 |
25 | function draw() {
26 |
27 | if(color_A.toString() != colorPicker_A.color().toString() || color_B.toString() != colorPicker_B.color().toString())
28 | {
29 | background(255);
30 |
31 | color_A = colorPicker_A.color();
32 | color_B = colorPicker_B.color();
33 |
34 | drawGradient("Mixbox", color_A, color_B, 50, 200, 65, 465);
35 | drawGradient("RGB", color_A, color_B, 250, 400, 65, 465);
36 | drawGradient("OkLab", color_A, color_B, 450, 600, 65, 465);
37 | }
38 |
39 | }
40 |
41 | function drawGradient(method, color1, color2, x1, x2, y1, y2)
42 | {
43 | textSize(28);
44 | textStyle(BOLD);
45 | fill(79, 118, 123);
46 | text(method, x1 + (x2-x1)/2 - textWidth(method)/2, y1-30);
47 | let mixedColor;
48 |
49 | for (let y = y1; y <= y2; y++)
50 | {
51 | let t = (y-y1)/(y2-y1);
52 | if(match(method, 'Mixbox'))
53 | {
54 | mixedColor = mixbox.lerp(color1, color2, t);
55 | }
56 | else if(match(method, 'RGB'))
57 | {
58 | mixedColor = lerpColor(color1, color2, t);
59 | }
60 | else if(match(method, 'OkLab'))
61 | {
62 | let c1 = [red(color1), green(color1), blue(color1)];
63 | let c2 = [red(color2), green(color2), blue(color2)];
64 | let tmp = linear_to_rgb (oklab_to_linear_srgb(linearMix(linear_srgb_to_oklab(rgb_to_linear(c1)),linear_srgb_to_oklab(rgb_to_linear(c2)),t)));
65 | mixedColor = color(tmp[0], tmp[1], tmp[2]);
66 | }
67 | strokeWeight(2);
68 | stroke(mixedColor);
69 | line(x1, y, x2, y);
70 | noStroke();
71 | }
72 | }
73 |
74 | /* THE FOLLOWING CODE IS HANDLING THE CONVERSION TO OkLAB SPACE */
75 | /* https://bottosson.github.io/posts/oklab/ */
76 |
77 | function linear_srgb_to_oklab(c)
78 | {
79 | let l = 0.4122214708 * c[0] + 0.5363325363 * c[1] + 0.0514459929 * c[2];
80 | let m = 0.2119034982 * c[0] + 0.6806995451 * c[1] + 0.1073969566 * c[2];
81 | let s = 0.0883024619 * c[0] + 0.2817188376 * c[1] + 0.6299787005 * c[2];
82 |
83 | let l_ = Math.cbrt(l);
84 | let m_ = Math.cbrt(m);
85 | let s_ = Math.cbrt(s);
86 |
87 | var lab = [ 0.2104542553*l_ + 0.7936177850*m_ - 0.0040720468*s_,
88 | 1.9779984951*l_ - 2.4285922050*m_ + 0.4505937099*s_,
89 | 0.0259040371*l_ + 0.7827717662*m_ - 0.8086757660*s_ ];
90 |
91 | return lab;
92 | }
93 |
94 | function oklab_to_linear_srgb(c)
95 | {
96 | let l_ = c[0] + 0.3963377774 * c[1] + 0.2158037573 * c[2];
97 | let m_ = c[0] - 0.1055613458 * c[1] - 0.0638541728 * c[2];
98 | let s_ = c[0] - 0.0894841775 * c[1] - 1.2914855480 * c[2];
99 |
100 | let l = l_*l_*l_;
101 | let m = m_*m_*m_;
102 | let s = s_*s_*s_;
103 |
104 | var lrgb = [ 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
105 | -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
106 | -0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s];
107 | return lrgb;
108 | }
109 |
110 | function rgb_to_linear(rgb) // receiving Color object, returning array of 3 linear RGB values in range 0-1
111 | {
112 | var res = [0,0,0];
113 | var float_rgb = [rgb[0]/255, rgb[1]/255, rgb[2]/255];
114 | for (let i = 0; i < 3; ++i)
115 | {
116 | let c = float_rgb[i];
117 | if (c >= 0.04045)
118 | res[i] = pow((c + 0.055)/(1 + 0.055), 2.4);
119 | else
120 | res[i] = c / 12.92;
121 | }
122 | return res;
123 | }
124 |
125 | function linear_to_rgb(lrgb) // receiving array of 3 linear RGB values, returning an array of gamma encoded RGB values in range 0-255
126 | {
127 | var res = [0,0,0];
128 | for (let i = 0; i < 3; ++i)
129 | {
130 | let c = lrgb[i];
131 | if (c >= 0.0031308)
132 | res[i] = 1.055 * pow(c, 1.0/2.4) - 0.055;
133 | else
134 | res[i] = 12.92 * c;
135 | }
136 | return [round(res[0]*255), round(res[1]*255), round(res[2]*255)];
137 | }
138 |
139 | function linearMix (a, b, t)
140 | {
141 | var res = [0,0,0];
142 | for(let i=0; i<3; i++)
143 | {
144 | res[i] = a[i] * (1-t) + b[i]*t;
145 | }
146 | return res;
147 | }
148 |
--------------------------------------------------------------------------------
/unity/Documentation~/README.md:
--------------------------------------------------------------------------------
1 | # Mixbox for Unity
2 |
3 | Open `Window` > `Package Manager` and choose ` + ` > `Add packge from git URL...`:
4 | ```
5 | https://github.com/scrtwpns/mixbox.git#upm
6 | ```
7 |
8 | ## Script
9 | ```csharp
10 | using UnityEngine;
11 | using Scrtwpns.Mixbox;
12 |
13 | public class NewBehaviourScript : MonoBehaviour
14 | {
15 | void Start()
16 | {
17 | Color color1 = new Color(0.0f, 0.129f, 0.522f); // blue
18 | Color color2 = new Color(0.988f, 0.827f, 0.0f); // yellow
19 | float t = 0.5f; // mixing ratio
20 |
21 | Color colorMix = Mixbox.Lerp(color1, color2, t);
22 |
23 | Debug.Log(colorMix);
24 | }
25 | }
26 | ```
27 | ```csharp
28 | Color MixThree(Color color1, Color color2, Color color3)
29 | {
30 | MixboxLatent z1 = Mixbox.RGBToLatent(color1);
31 | MixboxLatent z2 = Mixbox.RGBToLatent(color2);
32 | MixboxLatent z3 = Mixbox.RGBToLatent(color3);
33 |
34 | // mix 30% of color1, 60% of color2, and 10% of color3
35 | MixboxLatent zMix = 0.3f*z1 + 0.6f*z2 + 0.1f*z3;
36 |
37 | Color colorMix = Mixbox.LatentToRGB(zMix);
38 |
39 | return colorMix;
40 | }
41 | ```
42 |
43 | ## Shader
44 | ```ShaderLab
45 | Shader "MixboxHelloShader"
46 | {
47 | Properties
48 | {
49 | [NoScaleOffset] _MixboxLUT ("Mixbox LUT", 2D) = "white" {} // assign "Packages/Mixbox/Textures/MixboxLUT.png"
50 |
51 | _Color1 ("Color 1", Color) = (0, 0.129, 0.522, 1) // blue
52 | _Color2 ("Color 2", Color) = (0.988, 0.827, 0, 1) // yellow
53 | }
54 | SubShader
55 | {
56 | Pass
57 | {
58 | CGPROGRAM
59 | #pragma vertex vert
60 | #pragma fragment frag
61 |
62 | #include "UnityCG.cginc"
63 |
64 | sampler2D _MixboxLUT;
65 | #include "Packages/com.scrtwpns.mixbox/ShaderLibrary/Mixbox.cginc"
66 |
67 | fixed4 _Color1;
68 | fixed4 _Color2;
69 |
70 | struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; };
71 | struct v2f { float2 uv : TEXCOORD0; float4 vertex : SV_POSITION; };
72 |
73 | v2f vert (appdata v)
74 | {
75 | v2f o;
76 | o.vertex = UnityObjectToClipPos(v.vertex);
77 | o.uv = v.uv;
78 | return o;
79 | }
80 |
81 | fixed4 frag (v2f i) : SV_Target
82 | {
83 | return MixboxLerp(_Color1, _Color2, i.uv.x);
84 | }
85 | ENDCG
86 | }
87 | }
88 | }
89 | ```
90 | ```hlsl
91 | float3 MixThree(float3 rgb1, float3 rgb2, float3 rgb3)
92 | {
93 | MixboxLatent z1 = MixboxRGBToLatent(rgb1);
94 | MixboxLatent z2 = MixboxRGBToLatent(rgb2);
95 | MixboxLatent z3 = MixboxRGBToLatent(rgb3);
96 |
97 | // mix together 30% of rgb1, 60% of rgb2, and 10% of rgb3
98 | MixboxLatent zMix = 0.3*z1 + 0.6*z2 + 0.1*z3;
99 |
100 | float3 rgbMix = MixboxLatentToRGB(zMix);
101 |
102 | return rgbMix;
103 | }
104 | ```
105 |
106 |
107 |
108 |
109 | ## URP Shader
110 | ```ShaderLab
111 | Shader "Mixbox/Mixbox URP Sample Shader"
112 | {
113 | Properties
114 | {
115 | [NoScaleOffset] _MixboxLUT ("Mixbox LUT", 2D) = "white" {} // assign "Packages/Mixbox/Textures/MixboxLUT.png"
116 |
117 | _Color1 ("Color 1", Color) = (0, 0.129, 0.522, 1) // blue
118 | _Color2 ("Color 2", Color) = (0.988, 0.827, 0, 1) // yellow
119 | }
120 |
121 | SubShader
122 | {
123 | Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalRenderPipeline" }
124 |
125 | Pass
126 | {
127 | HLSLPROGRAM
128 | #pragma vertex vert
129 | #pragma fragment frag
130 |
131 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
132 |
133 | TEXTURE2D(_MixboxLUT);
134 | SAMPLER(sampler_MixboxLUT);
135 |
136 | #include "Packages/com.scrtwpns.mixbox/ShaderLibrary/Mixbox.hlsl"
137 |
138 | struct Attributes { float4 positionOS : POSITION; float2 uv : TEXCOORD0; };
139 | struct Varyings { float4 positionHCS : SV_POSITION; float2 uv : TEXCOORD0; };
140 |
141 | CBUFFER_START(UnityPerMaterial)
142 | half4 _Color1;
143 | half4 _Color2;
144 | CBUFFER_END
145 |
146 | Varyings vert(Attributes IN)
147 | {
148 | Varyings OUT;
149 | OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
150 | OUT.uv = IN.uv;
151 | return OUT;
152 | }
153 |
154 | half4 frag(Varyings IN) : SV_Target
155 | {
156 | return MixboxLerp(_Color1, _Color2, IN.uv.x);
157 | }
158 | ENDHLSL
159 | }
160 | }
161 | }
162 | ```
163 |
164 | ## Shader Graph
165 |
166 |
167 |
168 |
--------------------------------------------------------------------------------
/godot/addons/mixbox/mixbox.gdshaderinc:
--------------------------------------------------------------------------------
1 | // ==========================================================
2 | // MIXBOX 2.0 (c) 2022 Secret Weapons. All rights reserved.
3 | // License: Creative Commons Attribution-NonCommercial 4.0
4 | // Authors: Sarka Sochorova and Ondrej Jamriska
5 | // ==========================================================
6 | //
7 | // BASIC USAGE
8 | //
9 | // vec3 rgb = mixbox_lerp(rgb1, rgb2, t);
10 | //
11 | // MULTI-COLOR MIXING
12 | //
13 | // mat3 z1 = mixbox_rgb_to_latent(rgb1);
14 | // mat3 z2 = mixbox_rgb_to_latent(rgb2);
15 | // mat3 z3 = mixbox_rgb_to_latent(rgb3);
16 | //
17 | // // mix 30% of rgb1, 60% of rgb2, and 10% of rgb3
18 | // mat3 z_mix = 0.3*z1 + 0.6*z2 + 0.1*z3;
19 | //
20 | // vec3 rgb_mix = mixbox_latent_to_rgb(z_mix);
21 | //
22 | // PIGMENT COLORS
23 | //
24 | // Cadmium Yellow 0.996, 0.925, 0.000
25 | // Hansa Yellow 0.988, 0.827, 0.000
26 | // Cadmium Orange 1.000, 0.412, 0.000
27 | // Cadmium Red 1.000, 0.153, 0.008
28 | // Quinacridone Magenta 0.502, 0.008, 0.180
29 | // Cobalt Violet 0.306, 0.000, 0.259
30 | // Ultramarine Blue 0.098, 0.000, 0.349
31 | // Cobalt Blue 0.000, 0.129, 0.522
32 | // Phthalo Blue 0.051, 0.106, 0.267
33 | // Phthalo Green 0.000, 0.235, 0.196
34 | // Permanent Green 0.027, 0.427, 0.086
35 | // Sap Green 0.420, 0.580, 0.016
36 | // Burnt Sienna 0.482, 0.282, 0.000
37 | //
38 | // LICENSING
39 | //
40 | // If you want to obtain commercial license, please
41 | // contact us at: mixbox@scrtwpns.com
42 | //
43 |
44 | vec3 _mixbox_eval_polynomial(vec3 _mixbox_c) {
45 | float _mixbox_c0 = _mixbox_c[0];
46 | float _mixbox_c1 = _mixbox_c[1];
47 | float _mixbox_c2 = _mixbox_c[2];
48 | float _mixbox_c3 = 1.0 - (_mixbox_c0 + _mixbox_c1 + _mixbox_c2);
49 |
50 | float _mixbox_c00 = _mixbox_c0 * _mixbox_c0;
51 | float _mixbox_c11 = _mixbox_c1 * _mixbox_c1;
52 | float _mixbox_c22 = _mixbox_c2 * _mixbox_c2;
53 | float _mixbox_c01 = _mixbox_c0 * _mixbox_c1;
54 | float _mixbox_c02 = _mixbox_c0 * _mixbox_c2;
55 | float _mixbox_c12 = _mixbox_c1 * _mixbox_c2;
56 | float _mixbox_c33 = _mixbox_c3 * _mixbox_c3;
57 |
58 | return (
59 | (_mixbox_c0 * _mixbox_c00) * vec3(+0.07717053, +0.02826978, +0.24832992) +
60 | (_mixbox_c1 * _mixbox_c11) * vec3(+0.95912302, +0.80256528, +0.03561839) +
61 | (_mixbox_c2 * _mixbox_c22) * vec3(+0.74683774, +0.04868586, +0.00000000) +
62 | (_mixbox_c3 * _mixbox_c33) * vec3(+0.99518138, +0.99978149, +0.99704802) +
63 | (_mixbox_c00 * _mixbox_c1) * vec3(+0.04819146, +0.83363781, +0.32515377) +
64 | (_mixbox_c01 * _mixbox_c1) * vec3(-0.68146950, +1.46107803, +1.06980936) +
65 | (_mixbox_c00 * _mixbox_c2) * vec3(+0.27058419, -0.15324870, +1.98735057) +
66 | (_mixbox_c02 * _mixbox_c2) * vec3(+0.80478189, +0.67093710, +0.18424500) +
67 | (_mixbox_c00 * _mixbox_c3) * vec3(-0.35031003, +1.37855826, +3.68865000) +
68 | (_mixbox_c0 * _mixbox_c33) * vec3(+1.05128046, +1.97815239, +2.82989073) +
69 | (_mixbox_c11 * _mixbox_c2) * vec3(+3.21607125, +0.81270228, +1.03384539) +
70 | (_mixbox_c1 * _mixbox_c22) * vec3(+2.78893374, +0.41565549, -0.04487295) +
71 | (_mixbox_c11 * _mixbox_c3) * vec3(+3.02162577, +2.55374103, +0.32766114) +
72 | (_mixbox_c1 * _mixbox_c33) * vec3(+2.95124691, +2.81201112, +1.17578442) +
73 | (_mixbox_c22 * _mixbox_c3) * vec3(+2.82677043, +0.79933038, +1.81715262) +
74 | (_mixbox_c2 * _mixbox_c33) * vec3(+2.99691099, +1.22593053, +1.80653661) +
75 | (_mixbox_c01 * _mixbox_c2) * vec3(+1.87394106, +2.05027182, -0.29835996) +
76 | (_mixbox_c01 * _mixbox_c3) * vec3(+2.56609566, +7.03428198, +0.62575374) +
77 | (_mixbox_c02 * _mixbox_c3) * vec3(+4.08329484, -1.40408358, +2.14995522) +
78 | (_mixbox_c12 * _mixbox_c3) * vec3(+6.00078678, +2.55552042, +1.90739502));
79 | }
80 |
81 | mat3 mixbox_rgb_to_latent(vec3 _mixbox_rgb) {
82 | _mixbox_rgb = clamp(_mixbox_rgb, 0.0, 1.0);
83 |
84 | float _mixbox_x = _mixbox_rgb.r * 63.0;
85 | float _mixbox_y = _mixbox_rgb.g * 63.0;
86 | float _mixbox_z = _mixbox_rgb.b * 63.0;
87 |
88 | float _mixbox_iz = floor(_mixbox_z);
89 |
90 | float _mixbox_x0 = mod(_mixbox_iz, 8.0) * 64.0;
91 | float _mixbox_y0 = floor(_mixbox_iz / 8.0) * 64.0;
92 |
93 | float _mixbox_x1 = mod(_mixbox_iz + 1.0, 8.0) * 64.0;
94 | float _mixbox_y1 = floor((_mixbox_iz + 1.0) / 8.0) * 64.0;
95 |
96 | vec2 _mixbox_uv0 = vec2(_mixbox_x0 + _mixbox_x + 0.5, _mixbox_y0 + _mixbox_y + 0.5) / 512.0;
97 | vec2 _mixbox_uv1 = vec2(_mixbox_x1 + _mixbox_x + 0.5, _mixbox_y1 + _mixbox_y + 0.5) / 512.0;
98 |
99 | vec3 _mixbox_c = mix(textureLod(mixbox_lut, _mixbox_uv0, 0.0).rgb, textureLod(mixbox_lut, _mixbox_uv1, 0.0).rgb, _mixbox_z - _mixbox_iz);
100 |
101 | return mat3(_mixbox_c, _mixbox_rgb - _mixbox_eval_polynomial(_mixbox_c), vec3(0.0));
102 | }
103 |
104 | vec3 mixbox_latent_to_rgb(mat3 _mixbox_latent) {
105 | return clamp(_mixbox_eval_polynomial(_mixbox_latent[0]) + _mixbox_latent[1], 0.0, 1.0);
106 | }
107 |
108 | vec4 mixbox_lerp(vec4 _mixbox_color1, vec4 _mixbox_color2, float _mixbox_t) {
109 | return vec4(mixbox_latent_to_rgb((1.0-_mixbox_t)*mixbox_rgb_to_latent(_mixbox_color1.rgb) + _mixbox_t*mixbox_rgb_to_latent(_mixbox_color2.rgb)), mix(_mixbox_color1.a, _mixbox_color2.a, _mixbox_t));
110 | }
111 |
--------------------------------------------------------------------------------
/javascript/README.md:
--------------------------------------------------------------------------------
1 | # Mixbox for Javascript
2 |
3 | ```html
4 |
5 | ```
6 | ```javascript
7 | import mixbox from 'https://scrtwpns.com/mixbox.esm.js'; // for ES6 module use this instead
8 | ```
9 |
10 | ### Node
11 | ```
12 | npm install mixbox
13 | ```
14 | ```javascript
15 | import mixbox from 'mixbox';
16 | ```
17 |
18 | ## Usage
19 | ```javascript
20 | var rgb1 = "rgb(0, 33, 133)"; // blue
21 | var rgb2 = "rgb(252, 211, 0)"; // yellow
22 | var t = 0.5; // mixing ratio
23 |
24 | var mixed = mixbox.lerp(rgb1, rgb2, t);
25 |
26 | console.log(mixed);
27 | ```
28 |
29 | ## Mixing Multiple Colors
30 | ```javascript
31 | var z1 = mixbox.rgbToLatent(rgb1);
32 | var z2 = mixbox.rgbToLatent(rgb2);
33 | var z3 = mixbox.rgbToLatent(rgb3);
34 |
35 | var zMix = new Array(mixbox.LATENT_SIZE);
36 |
37 | for (var i = 0; i < zMix.length; i++) { // mix:
38 | zMix[i] = (0.3*z1[i] + // 30% of rgb1
39 | 0.6*z2[i] + // 60% of rgb2
40 | 0.1*z3[i]); // 10% of rgb3
41 | }
42 |
43 | var rgbMix = mixbox.latentToRgb(zMix);
44 | ```
45 |
46 | ## Pigment Colors
47 | | Pigment | | RGB | Float RGB | Linear RGB |
48 | | --- | --- |:----:|:----:|:----:|
49 | | Cadmium Yellow |
| 254, 236, 0 | 0.996, 0.925, 0.0 | 0.991, 0.839, 0.0 |
50 | | Hansa Yellow |
| 252, 211, 0 | 0.988, 0.827, 0.0 | 0.973, 0.651, 0.0 |
51 | | Cadmium Orange |
| 255, 105, 0 | 1.0, 0.412, 0.0 | 1.0, 0.141, 0.0 |
52 | | Cadmium Red |
| 255, 39, 2 | 1.0, 0.153, 0.008 | 1.0, 0.02, 0.001 |
53 | | Quinacridone Magenta |
| 128, 2, 46 | 0.502, 0.008, 0.18 | 0.216, 0.001, 0.027 |
54 | | Cobalt Violet |
| 78, 0, 66 | 0.306, 0.0, 0.259 | 0.076, 0.0, 0.054 |
55 | | Ultramarine Blue |
| 25, 0, 89 | 0.098, 0.0, 0.349 | 0.01, 0.0, 0.1 |
56 | | Cobalt Blue |
| 0, 33, 133 | 0.0, 0.129, 0.522 | 0.0, 0.015, 0.235 |
57 | | Phthalo Blue |
| 13, 27, 68 | 0.051, 0.106, 0.267 | 0.004, 0.011, 0.058 |
58 | | Phthalo Green |
| 0, 60, 50 | 0.0, 0.235, 0.196 | 0.0, 0.045, 0.032 |
59 | | Permanent Green |
| 7, 109, 22 | 0.027, 0.427, 0.086 | 0.002, 0.153, 0.008 |
60 | | Sap Green |
| 107, 148, 4 | 0.42, 0.58, 0.016 | 0.147, 0.296, 0.001 |
61 | | Burnt Sienna |
| 123, 72, 0 | 0.482, 0.282, 0.0 | 0.198, 0.065, 0.0 |
62 |
63 | ## Mixbox in WebGL
64 | ```javascript
65 | var shader = `
66 | precision highp float;
67 |
68 | // uncomment the following line if you work in linear space
69 | // #define MIXBOX_COLORSPACE_LINEAR
70 |
71 | uniform sampler2D mixbox_lut; // bind mixbox.lutTexture(gl) here
72 |
73 | #include "mixbox.glsl"
74 |
75 | void main(void) {
76 | vec3 rgb1 = vec3(0, 0.129, 0.522); // blue
77 | vec3 rgb2 = vec3(0.988, 0.827, 0); // yellow
78 | float t = 0.5; // mixing ratio
79 |
80 | vec3 rgb = mixbox_lerp(rgb1, rgb2, t);
81 |
82 | gl_FragColor = vec4(rgb, 1.0);
83 | }
84 | `;
85 |
86 | shader = shader.replace('#include "mixbox.glsl"', mixbox.glsl());
87 | ```
88 |
89 | ```javascript
90 | gl.useProgram(shaderProgram);
91 | gl.activeTexture(gl.TEXTURE0);
92 | gl.bindTexture(gl.TEXTURE_2D, mixbox.lutTexture(gl));
93 | gl.uniform1i(gl.getUniformLocation(shaderProgram, "mixbox_lut"), 0);
94 | ```
95 |
96 | ## Examples
97 |
98 | | Gradients | Mountains | Palette Snakes |
99 | |:---:|:---:|:---:|
100 | |
|
|
|
101 | | [source code](examples/gradients.js) | [source code](examples/mountains.js) | [source code](examples/palette.js) |
102 |
103 | | Splash Art | Paint Mixer | Pigment Fluids |
104 | |:---:|:---:|:---:|
105 | |
|
|
|
106 | | [source code](examples/splash.html) | [source code](examples/mixer.js) | [source code](https://scrtwpns.com/mixbox/fluids/script.js) |
107 |
108 |
109 | ## License
110 | Copyright (c) 2022, Secret Weapons. All rights reserved.
111 | Mixbox is provided under the CC BY-NC 4.0 license for non-commercial use only.
112 | If you want to obtain commercial license, please contact: mixbox@scrtwpns.com
113 |
--------------------------------------------------------------------------------
/godot/addons/mixbox/mixbox.gdshader:
--------------------------------------------------------------------------------
1 | // ==========================================================
2 | // MIXBOX 2.0 (c) 2022 Secret Weapons. All rights reserved.
3 | // License: Creative Commons Attribution-NonCommercial 4.0
4 | // Authors: Sarka Sochorova and Ondrej Jamriska
5 | // ==========================================================
6 | //
7 | // BASIC USAGE
8 | //
9 | // vec3 rgb = mixbox_lerp(rgb1, rgb2, t);
10 | //
11 | // MULTI-COLOR MIXING
12 | //
13 | // mat3 z1 = mixbox_rgb_to_latent(rgb1);
14 | // mat3 z2 = mixbox_rgb_to_latent(rgb2);
15 | // mat3 z3 = mixbox_rgb_to_latent(rgb3);
16 | //
17 | // // mix 30% of rgb1, 60% of rgb2, and 10% of rgb3
18 | // mat3 z_mix = 0.3*z1 + 0.6*z2 + 0.1*z3;
19 | //
20 | // vec3 rgb_mix = mixbox_latent_to_rgb(z_mix);
21 | //
22 | // PIGMENT COLORS
23 | //
24 | // Cadmium Yellow 0.996, 0.925, 0.000
25 | // Hansa Yellow 0.988, 0.827, 0.000
26 | // Cadmium Orange 1.000, 0.412, 0.000
27 | // Cadmium Red 1.000, 0.153, 0.008
28 | // Quinacridone Magenta 0.502, 0.008, 0.180
29 | // Cobalt Violet 0.306, 0.000, 0.259
30 | // Ultramarine Blue 0.098, 0.000, 0.349
31 | // Cobalt Blue 0.000, 0.129, 0.522
32 | // Phthalo Blue 0.051, 0.106, 0.267
33 | // Phthalo Green 0.000, 0.235, 0.196
34 | // Permanent Green 0.027, 0.427, 0.086
35 | // Sap Green 0.420, 0.580, 0.016
36 | // Burnt Sienna 0.482, 0.282, 0.000
37 | //
38 | // LICENSING
39 | //
40 | // If you want to obtain commercial license, please
41 | // contact us at: mixbox@scrtwpns.com
42 | //
43 |
44 | shader_type canvas_item;
45 |
46 | uniform sampler2D mixbox_lut; // attach "addons/mixbox/mixbox_lut.png" here
47 |
48 | uniform vec4 color1 : hint_color = vec4(0.0, 0.129, 0.522, 1.0); // blue
49 | uniform vec4 color2 : hint_color = vec4(0.988, 0.827, 0.0, 1.0); // yellow
50 |
51 | vec3 _mixbox_eval_polynomial(vec3 _mixbox_c) {
52 | float _mixbox_c0 = _mixbox_c[0];
53 | float _mixbox_c1 = _mixbox_c[1];
54 | float _mixbox_c2 = _mixbox_c[2];
55 | float _mixbox_c3 = 1.0 - (_mixbox_c0 + _mixbox_c1 + _mixbox_c2);
56 |
57 | float _mixbox_c00 = _mixbox_c0 * _mixbox_c0;
58 | float _mixbox_c11 = _mixbox_c1 * _mixbox_c1;
59 | float _mixbox_c22 = _mixbox_c2 * _mixbox_c2;
60 | float _mixbox_c01 = _mixbox_c0 * _mixbox_c1;
61 | float _mixbox_c02 = _mixbox_c0 * _mixbox_c2;
62 | float _mixbox_c12 = _mixbox_c1 * _mixbox_c2;
63 | float _mixbox_c33 = _mixbox_c3 * _mixbox_c3;
64 |
65 | return (
66 | (_mixbox_c0 * _mixbox_c00) * vec3(+0.07717053, +0.02826978, +0.24832992) +
67 | (_mixbox_c1 * _mixbox_c11) * vec3(+0.95912302, +0.80256528, +0.03561839) +
68 | (_mixbox_c2 * _mixbox_c22) * vec3(+0.74683774, +0.04868586, +0.00000000) +
69 | (_mixbox_c3 * _mixbox_c33) * vec3(+0.99518138, +0.99978149, +0.99704802) +
70 | (_mixbox_c00 * _mixbox_c1) * vec3(+0.04819146, +0.83363781, +0.32515377) +
71 | (_mixbox_c01 * _mixbox_c1) * vec3(-0.68146950, +1.46107803, +1.06980936) +
72 | (_mixbox_c00 * _mixbox_c2) * vec3(+0.27058419, -0.15324870, +1.98735057) +
73 | (_mixbox_c02 * _mixbox_c2) * vec3(+0.80478189, +0.67093710, +0.18424500) +
74 | (_mixbox_c00 * _mixbox_c3) * vec3(-0.35031003, +1.37855826, +3.68865000) +
75 | (_mixbox_c0 * _mixbox_c33) * vec3(+1.05128046, +1.97815239, +2.82989073) +
76 | (_mixbox_c11 * _mixbox_c2) * vec3(+3.21607125, +0.81270228, +1.03384539) +
77 | (_mixbox_c1 * _mixbox_c22) * vec3(+2.78893374, +0.41565549, -0.04487295) +
78 | (_mixbox_c11 * _mixbox_c3) * vec3(+3.02162577, +2.55374103, +0.32766114) +
79 | (_mixbox_c1 * _mixbox_c33) * vec3(+2.95124691, +2.81201112, +1.17578442) +
80 | (_mixbox_c22 * _mixbox_c3) * vec3(+2.82677043, +0.79933038, +1.81715262) +
81 | (_mixbox_c2 * _mixbox_c33) * vec3(+2.99691099, +1.22593053, +1.80653661) +
82 | (_mixbox_c01 * _mixbox_c2) * vec3(+1.87394106, +2.05027182, -0.29835996) +
83 | (_mixbox_c01 * _mixbox_c3) * vec3(+2.56609566, +7.03428198, +0.62575374) +
84 | (_mixbox_c02 * _mixbox_c3) * vec3(+4.08329484, -1.40408358, +2.14995522) +
85 | (_mixbox_c12 * _mixbox_c3) * vec3(+6.00078678, +2.55552042, +1.90739502));
86 | }
87 |
88 | mat3 mixbox_rgb_to_latent(vec3 _mixbox_rgb) {
89 | _mixbox_rgb = clamp(_mixbox_rgb, 0.0, 1.0);
90 |
91 | float _mixbox_x = _mixbox_rgb.r * 63.0;
92 | float _mixbox_y = _mixbox_rgb.g * 63.0;
93 | float _mixbox_z = _mixbox_rgb.b * 63.0;
94 |
95 | float _mixbox_iz = floor(_mixbox_z);
96 |
97 | float _mixbox_x0 = mod(_mixbox_iz, 8.0) * 64.0;
98 | float _mixbox_y0 = floor(_mixbox_iz / 8.0) * 64.0;
99 |
100 | float _mixbox_x1 = mod(_mixbox_iz + 1.0, 8.0) * 64.0;
101 | float _mixbox_y1 = floor((_mixbox_iz + 1.0) / 8.0) * 64.0;
102 |
103 | vec2 _mixbox_uv0 = vec2(_mixbox_x0 + _mixbox_x + 0.5, _mixbox_y0 + _mixbox_y + 0.5) / 512.0;
104 | vec2 _mixbox_uv1 = vec2(_mixbox_x1 + _mixbox_x + 0.5, _mixbox_y1 + _mixbox_y + 0.5) / 512.0;
105 |
106 | vec3 _mixbox_c = mix(textureLod(mixbox_lut, _mixbox_uv0, 0.0).rgb, textureLod(mixbox_lut, _mixbox_uv1, 0.0).rgb, _mixbox_z - _mixbox_iz);
107 |
108 | return mat3(_mixbox_c, _mixbox_rgb - _mixbox_eval_polynomial(_mixbox_c), vec3(0.0));
109 | }
110 |
111 | vec3 mixbox_latent_to_rgb(mat3 _mixbox_latent) {
112 | return clamp(_mixbox_eval_polynomial(_mixbox_latent[0]) + _mixbox_latent[1], 0.0, 1.0);
113 | }
114 |
115 | vec4 mixbox_lerp(vec4 _mixbox_color1, vec4 _mixbox_color2, float _mixbox_t) {
116 | return vec4(mixbox_latent_to_rgb((1.0-_mixbox_t)*mixbox_rgb_to_latent(_mixbox_color1.rgb) + _mixbox_t*mixbox_rgb_to_latent(_mixbox_color2.rgb)), mix(_mixbox_color1.a, _mixbox_color2.a, _mixbox_t));
117 | }
118 |
119 | void fragment() {
120 | COLOR = mixbox_lerp(color1, color2, UV.x);
121 | }
122 |
--------------------------------------------------------------------------------
/shaders/mixbox.hlsl:
--------------------------------------------------------------------------------
1 | // ==========================================================
2 | // MIXBOX 2.0 (c) 2022 Secret Weapons. All rights reserved.
3 | // License: Creative Commons Attribution-NonCommercial 4.0
4 | // Authors: Sarka Sochorova and Ondrej Jamriska
5 | // ==========================================================
6 | //
7 | // BASIC USAGE
8 | //
9 | // float3 rgb = MixboxLerp(rgb1, rgb2, t);
10 | //
11 | // MULTI-COLOR MIXING
12 | //
13 | // MixboxLatent z1 = MixboxRGBToLatent(rgb1);
14 | // MixboxLatent z2 = MixboxRGBToLatent(rgb2);
15 | // MixboxLatent z3 = MixboxRGBToLatent(rgb3);
16 | //
17 | // // mix 30% of rgb1, 60% of rgb2, and 10% of rgb3
18 | // MixboxLatent z_mix = 0.3*z1 + 0.6*z2 + 0.1*z3;
19 | //
20 | // float3 rgb_mix = MixboxLatentToRGB(z_mix);
21 | //
22 | // PIGMENT COLORS
23 | //
24 | // Cadmium Yellow 0.996, 0.925, 0.000
25 | // Hansa Yellow 0.988, 0.827, 0.000
26 | // Cadmium Orange 1.000, 0.412, 0.000
27 | // Cadmium Red 1.000, 0.153, 0.008
28 | // Quinacridone Magenta 0.502, 0.008, 0.180
29 | // Cobalt Violet 0.306, 0.000, 0.259
30 | // Ultramarine Blue 0.098, 0.000, 0.349
31 | // Cobalt Blue 0.000, 0.129, 0.522
32 | // Phthalo Blue 0.051, 0.106, 0.267
33 | // Phthalo Green 0.000, 0.235, 0.196
34 | // Permanent Green 0.027, 0.427, 0.086
35 | // Sap Green 0.420, 0.580, 0.016
36 | // Burnt Sienna 0.482, 0.282, 0.000
37 | //
38 | // LICENSING
39 | //
40 | // If you want to obtain commercial license, please
41 | // contact us at: mixbox@scrtwpns.com
42 | //
43 |
44 | #ifndef MIXBOX_INCLUDED
45 | #define MIXBOX_INCLUDED
46 |
47 | #ifndef MIXBOX_LUT
48 | #define MIXBOX_LUT(UV) MixboxLUT.SampleLevel(MixboxSampler, UV, 0)
49 | #endif
50 |
51 | typedef float3x3 MixboxLatent;
52 |
53 | float3 MixboxEvalPolynomial(float3 c)
54 | {
55 | float c0 = c[0];
56 | float c1 = c[1];
57 | float c2 = c[2];
58 | float c3 = 1.0 - (c0 + c1 + c2);
59 |
60 | float c00 = c0 * c0;
61 | float c11 = c1 * c1;
62 | float c22 = c2 * c2;
63 | float c01 = c0 * c1;
64 | float c02 = c0 * c2;
65 | float c12 = c1 * c2;
66 | float c33 = c3 * c3;
67 |
68 | return (c0*c00) * float3(+0.07717053, +0.02826978, +0.24832992) +
69 | (c1*c11) * float3(+0.95912302, +0.80256528, +0.03561839) +
70 | (c2*c22) * float3(+0.74683774, +0.04868586, +0.00000000) +
71 | (c3*c33) * float3(+0.99518138, +0.99978149, +0.99704802) +
72 | (c00*c1) * float3(+0.04819146, +0.83363781, +0.32515377) +
73 | (c01*c1) * float3(-0.68146950, +1.46107803, +1.06980936) +
74 | (c00*c2) * float3(+0.27058419, -0.15324870, +1.98735057) +
75 | (c02*c2) * float3(+0.80478189, +0.67093710, +0.18424500) +
76 | (c00*c3) * float3(-0.35031003, +1.37855826, +3.68865000) +
77 | (c0*c33) * float3(+1.05128046, +1.97815239, +2.82989073) +
78 | (c11*c2) * float3(+3.21607125, +0.81270228, +1.03384539) +
79 | (c1*c22) * float3(+2.78893374, +0.41565549, -0.04487295) +
80 | (c11*c3) * float3(+3.02162577, +2.55374103, +0.32766114) +
81 | (c1*c33) * float3(+2.95124691, +2.81201112, +1.17578442) +
82 | (c22*c3) * float3(+2.82677043, +0.79933038, +1.81715262) +
83 | (c2*c33) * float3(+2.99691099, +1.22593053, +1.80653661) +
84 | (c01*c2) * float3(+1.87394106, +2.05027182, -0.29835996) +
85 | (c01*c3) * float3(+2.56609566, +7.03428198, +0.62575374) +
86 | (c02*c3) * float3(+4.08329484, -1.40408358, +2.14995522) +
87 | (c12*c3) * float3(+6.00078678, +2.55552042, +1.90739502);
88 | }
89 |
90 | float3 MixboxSRGBToLinear(float3 rgb)
91 | {
92 | return (rgb >= 0.04045) ? pow((abs(rgb) + 0.055) / 1.055, 2.4) : rgb/12.92;
93 | }
94 |
95 | float3 MixboxLinearToSRGB(float3 rgb)
96 | {
97 | return (rgb >= 0.0031308) ? 1.055*pow(abs(rgb), 1.0/2.4) - 0.055 : 12.92*rgb;
98 | }
99 |
100 | MixboxLatent MixboxRGBToLatent(float3 rgb)
101 | {
102 | #ifdef MIXBOX_COLORSPACE_LINEAR
103 | rgb = MixboxLinearToSRGB(saturate(rgb));
104 | #else
105 | rgb = saturate(rgb);
106 | #endif
107 |
108 | float x = rgb.r * 63.0;
109 | float y = rgb.g * 63.0;
110 | float z = rgb.b * 63.0;
111 |
112 | float iz = floor(z);
113 |
114 | float x0 = fmod(iz, 8.0) * 64.0;
115 | float y0 = floor(iz / 8.0) * 64.0;
116 |
117 | float x1 = fmod(iz + 1.0, 8.0) * 64.0;
118 | float y1 = floor((iz + 1.0) / 8.0) * 64.0;
119 |
120 | float2 uv0 = float2(x0 + x + 0.5, 512.0 - (y0 + y + 0.5)) / 512.0;
121 | float2 uv1 = float2(x1 + x + 0.5, 512.0 - (y1 + y + 0.5)) / 512.0;
122 |
123 | if (MIXBOX_LUT(float2(0.5, 0.5) / 512.0).b > 0.1)
124 | {
125 | uv0.y = 1.0 - uv0.y;
126 | uv1.y = 1.0 - uv1.y;
127 | }
128 |
129 | float3 c = lerp(MIXBOX_LUT(uv0).rgb, MIXBOX_LUT(uv1).rgb, z - iz);
130 |
131 | return MixboxLatent(c, rgb - MixboxEvalPolynomial(c), 0.0, 0.0, 0.0);
132 | }
133 |
134 | float3 MixboxLatentToRGB(MixboxLatent latent)
135 | {
136 | float3 rgb = saturate(MixboxEvalPolynomial(latent[0]) + latent[1]);
137 |
138 | #ifdef MIXBOX_COLORSPACE_LINEAR
139 | return MixboxSRGBToLinear(rgb);
140 | #else
141 | return rgb;
142 | #endif
143 | }
144 |
145 | float3 MixboxLerp(float3 color1, float3 color2, float t)
146 | {
147 | return MixboxLatentToRGB((1.0-t)*MixboxRGBToLatent(color1) + t*MixboxRGBToLatent(color2));
148 | }
149 |
150 | float4 MixboxLerp(float4 color1, float4 color2, float t)
151 | {
152 | return float4(MixboxLerp(color1.rgb, color2.rgb, t), lerp(color1.a, color2.a, t));
153 | }
154 |
155 | #endif
156 |
--------------------------------------------------------------------------------
/unity/ShaderLibrary/Mixbox.hlsl:
--------------------------------------------------------------------------------
1 | // ==========================================================
2 | // MIXBOX 2.0 (c) 2022 Secret Weapons. All rights reserved.
3 | // License: Creative Commons Attribution-NonCommercial 4.0
4 | // Authors: Sarka Sochorova and Ondrej Jamriska
5 | // ==========================================================
6 | //
7 | // BASIC USAGE
8 | //
9 | // float3 rgb = MixboxLerp(rgb1, rgb2, t);
10 | //
11 | // MULTI-COLOR MIXING
12 | //
13 | // MixboxLatent z1 = MixboxRGBToLatent(rgb1);
14 | // MixboxLatent z2 = MixboxRGBToLatent(rgb2);
15 | // MixboxLatent z3 = MixboxRGBToLatent(rgb3);
16 | //
17 | // // mix 30% of rgb1, 60% of rgb2, and 10% of rgb3
18 | // MixboxLatent z_mix = 0.3*z1 + 0.6*z2 + 0.1*z3;
19 | //
20 | // float3 rgb_mix = MixboxLatentToRGB(z_mix);
21 | //
22 | // PIGMENT COLORS
23 | //
24 | // Cadmium Yellow 0.996, 0.925, 0.000
25 | // Hansa Yellow 0.988, 0.827, 0.000
26 | // Cadmium Orange 1.000, 0.412, 0.000
27 | // Cadmium Red 1.000, 0.153, 0.008
28 | // Quinacridone Magenta 0.502, 0.008, 0.180
29 | // Cobalt Violet 0.306, 0.000, 0.259
30 | // Ultramarine Blue 0.098, 0.000, 0.349
31 | // Cobalt Blue 0.000, 0.129, 0.522
32 | // Phthalo Blue 0.051, 0.106, 0.267
33 | // Phthalo Green 0.000, 0.235, 0.196
34 | // Permanent Green 0.027, 0.427, 0.086
35 | // Sap Green 0.420, 0.580, 0.016
36 | // Burnt Sienna 0.482, 0.282, 0.000
37 | //
38 | // LICENSING
39 | //
40 | // If you want to obtain commercial license, please
41 | // contact us at: mixbox@scrtwpns.com
42 | //
43 |
44 | #ifndef MIXBOX_INCLUDED
45 | #define MIXBOX_INCLUDED
46 |
47 | #ifndef UNITY_COLORSPACE_GAMMA
48 | #define MIXBOX_COLORSPACE_LINEAR
49 | #endif
50 |
51 | #ifndef MIXBOX_LUT
52 | #ifdef SAMPLE_TEXTURE2D_LOD
53 | #define MIXBOX_LUT(UV) SAMPLE_TEXTURE2D_LOD(_MixboxLUT, sampler_MixboxLUT, UV, 0)
54 | #else
55 | #define MIXBOX_LUT(UV) tex2D(_MixboxLUT, UV)
56 | #endif
57 | #endif
58 |
59 | typedef float3x3 MixboxLatent;
60 |
61 | float3 MixboxEvalPolynomial(float3 c)
62 | {
63 | float c0 = c[0];
64 | float c1 = c[1];
65 | float c2 = c[2];
66 | float c3 = 1.0 - (c0 + c1 + c2);
67 |
68 | float c00 = c0 * c0;
69 | float c11 = c1 * c1;
70 | float c22 = c2 * c2;
71 | float c01 = c0 * c1;
72 | float c02 = c0 * c2;
73 | float c12 = c1 * c2;
74 | float c33 = c3 * c3;
75 |
76 | return (c0*c00) * float3(+0.07717053, +0.02826978, +0.24832992) +
77 | (c1*c11) * float3(+0.95912302, +0.80256528, +0.03561839) +
78 | (c2*c22) * float3(+0.74683774, +0.04868586, +0.00000000) +
79 | (c3*c33) * float3(+0.99518138, +0.99978149, +0.99704802) +
80 | (c00*c1) * float3(+0.04819146, +0.83363781, +0.32515377) +
81 | (c01*c1) * float3(-0.68146950, +1.46107803, +1.06980936) +
82 | (c00*c2) * float3(+0.27058419, -0.15324870, +1.98735057) +
83 | (c02*c2) * float3(+0.80478189, +0.67093710, +0.18424500) +
84 | (c00*c3) * float3(-0.35031003, +1.37855826, +3.68865000) +
85 | (c0*c33) * float3(+1.05128046, +1.97815239, +2.82989073) +
86 | (c11*c2) * float3(+3.21607125, +0.81270228, +1.03384539) +
87 | (c1*c22) * float3(+2.78893374, +0.41565549, -0.04487295) +
88 | (c11*c3) * float3(+3.02162577, +2.55374103, +0.32766114) +
89 | (c1*c33) * float3(+2.95124691, +2.81201112, +1.17578442) +
90 | (c22*c3) * float3(+2.82677043, +0.79933038, +1.81715262) +
91 | (c2*c33) * float3(+2.99691099, +1.22593053, +1.80653661) +
92 | (c01*c2) * float3(+1.87394106, +2.05027182, -0.29835996) +
93 | (c01*c3) * float3(+2.56609566, +7.03428198, +0.62575374) +
94 | (c02*c3) * float3(+4.08329484, -1.40408358, +2.14995522) +
95 | (c12*c3) * float3(+6.00078678, +2.55552042, +1.90739502);
96 | }
97 |
98 | float3 MixboxSRGBToLinear(float3 rgb)
99 | {
100 | return (rgb >= 0.04045) ? pow((abs(rgb) + 0.055) / 1.055, 2.4) : rgb/12.92;
101 | }
102 |
103 | float3 MixboxLinearToSRGB(float3 rgb)
104 | {
105 | return (rgb >= 0.0031308) ? 1.055*pow(abs(rgb), 1.0/2.4) - 0.055 : 12.92*rgb;
106 | }
107 |
108 | MixboxLatent MixboxRGBToLatent(float3 rgb)
109 | {
110 | #ifdef MIXBOX_COLORSPACE_LINEAR
111 | rgb = MixboxLinearToSRGB(saturate(rgb));
112 | #else
113 | rgb = saturate(rgb);
114 | #endif
115 |
116 | float x = rgb.r * 63.0;
117 | float y = rgb.g * 63.0;
118 | float z = rgb.b * 63.0;
119 |
120 | float iz = floor(z);
121 |
122 | float x0 = fmod(iz, 8.0) * 64.0;
123 | float y0 = floor(iz / 8.0) * 64.0;
124 |
125 | float x1 = fmod(iz + 1.0, 8.0) * 64.0;
126 | float y1 = floor((iz + 1.0) / 8.0) * 64.0;
127 |
128 | float2 uv0 = float2(x0 + x + 0.5, 512.0 - (y0 + y + 0.5)) / 512.0;
129 | float2 uv1 = float2(x1 + x + 0.5, 512.0 - (y1 + y + 0.5)) / 512.0;
130 |
131 | float3 c = lerp(MIXBOX_LUT(uv0).rgb, MIXBOX_LUT(uv1).rgb, z - iz);
132 |
133 | return MixboxLatent(c, rgb - MixboxEvalPolynomial(c), 0.0, 0.0, 0.0);
134 | }
135 |
136 | float3 MixboxLatentToRGB(MixboxLatent latent)
137 | {
138 | float3 rgb = saturate(MixboxEvalPolynomial(latent[0]) + latent[1]);
139 |
140 | #ifdef MIXBOX_COLORSPACE_LINEAR
141 | return MixboxSRGBToLinear(rgb);
142 | #else
143 | return rgb;
144 | #endif
145 | }
146 |
147 | float3 MixboxLerp(float3 color1, float3 color2, float t)
148 | {
149 | return MixboxLatentToRGB((1.0-t)*MixboxRGBToLatent(color1) + t*MixboxRGBToLatent(color2));
150 | }
151 |
152 | float4 MixboxLerp(float4 color1, float4 color2, float t)
153 | {
154 | return float4(MixboxLerp(color1.rgb, color2.rgb, t), lerp(color1.a, color2.a, t));
155 | }
156 |
157 | #endif
158 |
--------------------------------------------------------------------------------
/shaders/mixbox.glsl:
--------------------------------------------------------------------------------
1 | // ==========================================================
2 | // MIXBOX 2.0 (c) 2022 Secret Weapons. All rights reserved.
3 | // License: Creative Commons Attribution-NonCommercial 4.0
4 | // Authors: Sarka Sochorova and Ondrej Jamriska
5 | // ==========================================================
6 | //
7 | // BASIC USAGE
8 | //
9 | // vec3 rgb = mixbox_lerp(rgb1, rgb2, t);
10 | //
11 | // MULTI-COLOR MIXING
12 | //
13 | // mixbox_latent z1 = mixbox_rgb_to_latent(rgb1);
14 | // mixbox_latent z2 = mixbox_rgb_to_latent(rgb2);
15 | // mixbox_latent z3 = mixbox_rgb_to_latent(rgb3);
16 | //
17 | // // mix 30% of rgb1, 60% of rgb2, and 10% of rgb3
18 | // mixbox_latent z_mix = 0.3*z1 + 0.6*z2 + 0.1*z3;
19 | //
20 | // vec3 rgb_mix = mixbox_latent_to_rgb(z_mix);
21 | //
22 | // PIGMENT COLORS
23 | //
24 | // Cadmium Yellow 0.996, 0.925, 0.000
25 | // Hansa Yellow 0.988, 0.827, 0.000
26 | // Cadmium Orange 1.000, 0.412, 0.000
27 | // Cadmium Red 1.000, 0.153, 0.008
28 | // Quinacridone Magenta 0.502, 0.008, 0.180
29 | // Cobalt Violet 0.306, 0.000, 0.259
30 | // Ultramarine Blue 0.098, 0.000, 0.349
31 | // Cobalt Blue 0.000, 0.129, 0.522
32 | // Phthalo Blue 0.051, 0.106, 0.267
33 | // Phthalo Green 0.000, 0.235, 0.196
34 | // Permanent Green 0.027, 0.427, 0.086
35 | // Sap Green 0.420, 0.580, 0.016
36 | // Burnt Sienna 0.482, 0.282, 0.000
37 | //
38 | // LICENSING
39 | //
40 | // If you want to obtain commercial license, please
41 | // contact us at: mixbox@scrtwpns.com
42 | //
43 |
44 | #ifndef MIXBOX_INCLUDED
45 | #define MIXBOX_INCLUDED
46 |
47 | #ifndef MIXBOX_LUT
48 | #if __VERSION__ <= 120
49 | #define MIXBOX_LUT(UV) texture2D(mixbox_lut, UV)
50 | #else
51 | #define MIXBOX_LUT(UV) textureLod(mixbox_lut, UV, 0.0)
52 | #endif
53 | #endif
54 |
55 | #define mixbox_latent mat3
56 |
57 | vec3 mixbox_eval_polynomial(vec3 c)
58 | {
59 | float c0 = c[0];
60 | float c1 = c[1];
61 | float c2 = c[2];
62 | float c3 = 1.0 - (c0 + c1 + c2);
63 |
64 | float c00 = c0 * c0;
65 | float c11 = c1 * c1;
66 | float c22 = c2 * c2;
67 | float c01 = c0 * c1;
68 | float c02 = c0 * c2;
69 | float c12 = c1 * c2;
70 | float c33 = c3 * c3;
71 |
72 | return (c0*c00) * vec3(+0.07717053, +0.02826978, +0.24832992) +
73 | (c1*c11) * vec3(+0.95912302, +0.80256528, +0.03561839) +
74 | (c2*c22) * vec3(+0.74683774, +0.04868586, +0.00000000) +
75 | (c3*c33) * vec3(+0.99518138, +0.99978149, +0.99704802) +
76 | (c00*c1) * vec3(+0.04819146, +0.83363781, +0.32515377) +
77 | (c01*c1) * vec3(-0.68146950, +1.46107803, +1.06980936) +
78 | (c00*c2) * vec3(+0.27058419, -0.15324870, +1.98735057) +
79 | (c02*c2) * vec3(+0.80478189, +0.67093710, +0.18424500) +
80 | (c00*c3) * vec3(-0.35031003, +1.37855826, +3.68865000) +
81 | (c0*c33) * vec3(+1.05128046, +1.97815239, +2.82989073) +
82 | (c11*c2) * vec3(+3.21607125, +0.81270228, +1.03384539) +
83 | (c1*c22) * vec3(+2.78893374, +0.41565549, -0.04487295) +
84 | (c11*c3) * vec3(+3.02162577, +2.55374103, +0.32766114) +
85 | (c1*c33) * vec3(+2.95124691, +2.81201112, +1.17578442) +
86 | (c22*c3) * vec3(+2.82677043, +0.79933038, +1.81715262) +
87 | (c2*c33) * vec3(+2.99691099, +1.22593053, +1.80653661) +
88 | (c01*c2) * vec3(+1.87394106, +2.05027182, -0.29835996) +
89 | (c01*c3) * vec3(+2.56609566, +7.03428198, +0.62575374) +
90 | (c02*c3) * vec3(+4.08329484, -1.40408358, +2.14995522) +
91 | (c12*c3) * vec3(+6.00078678, +2.55552042, +1.90739502);
92 | }
93 |
94 | float mixbox_srgb_to_linear(float x)
95 | {
96 | return (x >= 0.04045) ? pow((x + 0.055) / 1.055, 2.4) : x/12.92;
97 | }
98 |
99 | float mixbox_linear_to_srgb(float x)
100 | {
101 | return (x >= 0.0031308) ? 1.055*pow(x, 1.0/2.4) - 0.055 : 12.92*x;
102 | }
103 |
104 | vec3 mixbox_srgb_to_linear(vec3 rgb)
105 | {
106 | return vec3(mixbox_srgb_to_linear(rgb.r),
107 | mixbox_srgb_to_linear(rgb.g),
108 | mixbox_srgb_to_linear(rgb.b));
109 | }
110 |
111 | vec3 mixbox_linear_to_srgb(vec3 rgb)
112 | {
113 | return vec3(mixbox_linear_to_srgb(rgb.r),
114 | mixbox_linear_to_srgb(rgb.g),
115 | mixbox_linear_to_srgb(rgb.b));
116 | }
117 |
118 | mixbox_latent mixbox_rgb_to_latent(vec3 rgb)
119 | {
120 | #ifdef MIXBOX_COLORSPACE_LINEAR
121 | rgb = mixbox_linear_to_srgb(clamp(rgb, 0.0, 1.0));
122 | #else
123 | rgb = clamp(rgb, 0.0, 1.0);
124 | #endif
125 |
126 | float x = rgb.r * 63.0;
127 | float y = rgb.g * 63.0;
128 | float z = rgb.b * 63.0;
129 |
130 | float iz = floor(z);
131 |
132 | float x0 = mod(iz, 8.0) * 64.0;
133 | float y0 = floor(iz / 8.0) * 64.0;
134 |
135 | float x1 = mod(iz + 1.0, 8.0) * 64.0;
136 | float y1 = floor((iz + 1.0) / 8.0) * 64.0;
137 |
138 | vec2 uv0 = vec2(x0 + x + 0.5, y0 + y + 0.5) / 512.0;
139 | vec2 uv1 = vec2(x1 + x + 0.5, y1 + y + 0.5) / 512.0;
140 |
141 | if (MIXBOX_LUT(vec2(0.5, 0.5) / 512.0).b < 0.1)
142 | {
143 | uv0.y = 1.0 - uv0.y;
144 | uv1.y = 1.0 - uv1.y;
145 | }
146 |
147 | vec3 c = mix(MIXBOX_LUT(uv0).rgb, MIXBOX_LUT(uv1).rgb, z - iz);
148 |
149 | return mixbox_latent(c, rgb - mixbox_eval_polynomial(c), vec3(0.0));
150 | }
151 |
152 | vec3 mixbox_latent_to_rgb(mixbox_latent latent)
153 | {
154 | vec3 rgb = clamp(mixbox_eval_polynomial(latent[0]) + latent[1], 0.0, 1.0);
155 |
156 | #ifdef MIXBOX_COLORSPACE_LINEAR
157 | return mixbox_srgb_to_linear(rgb);
158 | #else
159 | return rgb;
160 | #endif
161 | }
162 |
163 | vec3 mixbox_lerp(vec3 color1, vec3 color2, float t)
164 | {
165 | return mixbox_latent_to_rgb((1.0-t)*mixbox_rgb_to_latent(color1) + t*mixbox_rgb_to_latent(color2));
166 | }
167 |
168 | vec4 mixbox_lerp(vec4 color1, vec4 color2, float t)
169 | {
170 | return vec4(mixbox_lerp(color1.rgb, color2.rgb, t), mix(color1.a, color2.a, t));
171 | }
172 |
173 | #endif
174 |
--------------------------------------------------------------------------------
/shaders/mixbox.metal:
--------------------------------------------------------------------------------
1 | // ==========================================================
2 | // MIXBOX 2.0 (c) 2022 Secret Weapons. All rights reserved.
3 | // License: Creative Commons Attribution-NonCommercial 4.0
4 | // Authors: Sarka Sochorova and Ondrej Jamriska
5 | // ==========================================================
6 | //
7 | // BASIC USAGE
8 | //
9 | // float3 rgb = mixbox_lerp(lut, rgb1, rgb2, t);
10 | //
11 | // MULTI-COLOR MIXING
12 | //
13 | // mixbox_latent z1 = mixbox_rgb_to_latent(lut, rgb1);
14 | // mixbox_latent z2 = mixbox_rgb_to_latent(lut, rgb2);
15 | // mixbox_latent z3 = mixbox_rgb_to_latent(lut, rgb3);
16 | //
17 | // // mix 30% of rgb1, 60% of rgb2, and 10% of rgb3
18 | // mixbox_latent z_mix = 0.3*z1 + 0.6*z2 + 0.1*z3;
19 | //
20 | // float3 rgb_mix = mixbox_latent_to_rgb(z_mix);
21 | //
22 | // PIGMENT COLORS
23 | //
24 | // Cadmium Yellow 0.996, 0.925, 0.000
25 | // Hansa Yellow 0.988, 0.827, 0.000
26 | // Cadmium Orange 1.000, 0.412, 0.000
27 | // Cadmium Red 1.000, 0.153, 0.008
28 | // Quinacridone Magenta 0.502, 0.008, 0.180
29 | // Cobalt Violet 0.306, 0.000, 0.259
30 | // Ultramarine Blue 0.098, 0.000, 0.349
31 | // Cobalt Blue 0.000, 0.129, 0.522
32 | // Phthalo Blue 0.051, 0.106, 0.267
33 | // Phthalo Green 0.000, 0.235, 0.196
34 | // Permanent Green 0.027, 0.427, 0.086
35 | // Sap Green 0.420, 0.580, 0.016
36 | // Burnt Sienna 0.482, 0.282, 0.000
37 | //
38 | // LICENSING
39 | //
40 | // If you want to obtain commercial license, please
41 | // contact us at: mixbox@scrtwpns.com
42 | //
43 |
44 | #ifndef MIXBOX_INCLUDED
45 | #define MIXBOX_INCLUDED
46 |
47 | #include
48 |
49 | typedef metal::float3x3 mixbox_latent;
50 |
51 | inline float3 mixbox_eval_polynomial(float3 c)
52 | {
53 | float c0 = c[0];
54 | float c1 = c[1];
55 | float c2 = c[2];
56 | float c3 = 1.0 - (c0 + c1 + c2);
57 |
58 | float c00 = c0 * c0;
59 | float c11 = c1 * c1;
60 | float c22 = c2 * c2;
61 | float c01 = c0 * c1;
62 | float c02 = c0 * c2;
63 | float c12 = c1 * c2;
64 | float c33 = c3 * c3;
65 |
66 | return (c0*c00) * float3(+0.07717053, +0.02826978, +0.24832992) +
67 | (c1*c11) * float3(+0.95912302, +0.80256528, +0.03561839) +
68 | (c2*c22) * float3(+0.74683774, +0.04868586, +0.00000000) +
69 | (c3*c33) * float3(+0.99518138, +0.99978149, +0.99704802) +
70 | (c00*c1) * float3(+0.04819146, +0.83363781, +0.32515377) +
71 | (c01*c1) * float3(-0.68146950, +1.46107803, +1.06980936) +
72 | (c00*c2) * float3(+0.27058419, -0.15324870, +1.98735057) +
73 | (c02*c2) * float3(+0.80478189, +0.67093710, +0.18424500) +
74 | (c00*c3) * float3(-0.35031003, +1.37855826, +3.68865000) +
75 | (c0*c33) * float3(+1.05128046, +1.97815239, +2.82989073) +
76 | (c11*c2) * float3(+3.21607125, +0.81270228, +1.03384539) +
77 | (c1*c22) * float3(+2.78893374, +0.41565549, -0.04487295) +
78 | (c11*c3) * float3(+3.02162577, +2.55374103, +0.32766114) +
79 | (c1*c33) * float3(+2.95124691, +2.81201112, +1.17578442) +
80 | (c22*c3) * float3(+2.82677043, +0.79933038, +1.81715262) +
81 | (c2*c33) * float3(+2.99691099, +1.22593053, +1.80653661) +
82 | (c01*c2) * float3(+1.87394106, +2.05027182, -0.29835996) +
83 | (c01*c3) * float3(+2.56609566, +7.03428198, +0.62575374) +
84 | (c02*c3) * float3(+4.08329484, -1.40408358, +2.14995522) +
85 | (c12*c3) * float3(+6.00078678, +2.55552042, +1.90739502);
86 | }
87 |
88 | inline float mixbox_srgb_to_linear(float x)
89 | {
90 | return (x >= 0.04045) ? metal::pow((x + 0.055) / 1.055, 2.4) : x/12.92;
91 | }
92 |
93 | inline float mixbox_linear_to_srgb(float x)
94 | {
95 | return (x >= 0.0031308) ? 1.055*metal::pow(x, 1.0/2.4) - 0.055 : 12.92*x;
96 | }
97 |
98 | inline float3 mixbox_srgb_to_linear(float3 rgb)
99 | {
100 | return float3(mixbox_srgb_to_linear(rgb.r),
101 | mixbox_srgb_to_linear(rgb.g),
102 | mixbox_srgb_to_linear(rgb.b));
103 | }
104 |
105 | inline float3 mixbox_linear_to_srgb(float3 rgb)
106 | {
107 | return float3(mixbox_linear_to_srgb(rgb.r),
108 | mixbox_linear_to_srgb(rgb.g),
109 | mixbox_linear_to_srgb(rgb.b));
110 | }
111 |
112 | inline mixbox_latent mixbox_rgb_to_latent(metal::texture2d mixbox_lut, float3 rgb)
113 | {
114 | #ifdef MIXBOX_COLORSPACE_LINEAR
115 | rgb = mixbox_linear_to_srgb(metal::saturate(rgb));
116 | #else
117 | rgb = metal::saturate(rgb);
118 | #endif
119 |
120 | float x = rgb.r * 63.0;
121 | float y = rgb.g * 63.0;
122 | float z = rgb.b * 63.0;
123 |
124 | float iz = metal::floor(z);
125 |
126 | float x0 = metal::fmod(iz, 8.0) * 64.0;
127 | float y0 = metal::floor(iz / 8.0) * 64.0;
128 |
129 | float x1 = metal::fmod(iz + 1.0, 8.0) * 64.0;
130 | float y1 = metal::floor((iz + 1.0) / 8.0) * 64.0;
131 |
132 | float2 uv0 = float2(x0 + x + 0.5, y0 + y + 0.5) / 512.0;
133 | float2 uv1 = float2(x1 + x + 0.5, y1 + y + 0.5) / 512.0;
134 |
135 | constexpr metal::sampler lut_sampler(metal::mag_filter::linear, metal::min_filter::linear, metal::mip_filter::none);
136 |
137 | if (mixbox_lut.sample(lut_sampler, float2(0.5, 0.5) / 512.0).b < 0.1)
138 | {
139 | uv0.y = 1.0 - uv0.y;
140 | uv1.y = 1.0 - uv1.y;
141 | }
142 |
143 | float3 c = metal::mix(mixbox_lut.sample(lut_sampler, uv0).rgb, mixbox_lut.sample(lut_sampler, uv1).rgb, z - iz);
144 |
145 | return mixbox_latent(c, rgb - mixbox_eval_polynomial(c), float3(0.0, 0.0, 0.0));
146 | }
147 |
148 | inline float3 mixbox_latent_to_rgb(mixbox_latent latent)
149 | {
150 | float3 rgb = metal::saturate(mixbox_eval_polynomial(latent[0]) + latent[1]);
151 |
152 | #ifdef MIXBOX_COLORSPACE_LINEAR
153 | return mixbox_srgb_to_linear(rgb);
154 | #else
155 | return rgb;
156 | #endif
157 | }
158 |
159 | inline float3 mixbox_lerp(metal::texture2d mixbox_lut, float3 color1, float3 color2, float t)
160 | {
161 | return mixbox_latent_to_rgb((1.0-t)*mixbox_rgb_to_latent(mixbox_lut, color1) + t*mixbox_rgb_to_latent(mixbox_lut, color2));
162 | }
163 |
164 | inline float4 mixbox_lerp(metal::texture2d mixbox_lut, float4 color1, float4 color2, float t)
165 | {
166 | return float4(mixbox_lerp(mixbox_lut, color1.rgb, color2.rgb, t), metal::mix(color1.a, color2.a, t));
167 | }
168 |
169 | #endif
170 |
--------------------------------------------------------------------------------
/godot/addons/mixbox/mixbox_lerp_node.gd:
--------------------------------------------------------------------------------
1 | # ==========================================================
2 | # MIXBOX 2.0 (c) 2022 Secret Weapons. All rights reserved.
3 | # License: Creative Commons Attribution-NonCommercial 4.0
4 | # Authors: Sarka Sochorova and Ondrej Jamriska
5 | # ==========================================================
6 | #
7 | # USAGE
8 | #
9 | # VisualShader: Add Node... > Mixbox > MixboxLerp
10 | #
11 | # Inspector:
12 | # Drag file "res://addons/mixbox/mixbox_lut.png"
13 | # to "Material > Shader Param > Mixbox Lut" slot.
14 | #
15 | # PIGMENT COLORS
16 | #
17 | # Cadmium Yellow 0.996, 0.925, 0.000
18 | # Hansa Yellow 0.988, 0.827, 0.000
19 | # Cadmium Orange 1.000, 0.412, 0.000
20 | # Cadmium Red 1.000, 0.153, 0.008
21 | # Quinacridone Magenta 0.502, 0.008, 0.180
22 | # Cobalt Violet 0.306, 0.000, 0.259
23 | # Ultramarine Blue 0.098, 0.000, 0.349
24 | # Cobalt Blue 0.000, 0.129, 0.522
25 | # Phthalo Blue 0.051, 0.106, 0.267
26 | # Phthalo Green 0.000, 0.235, 0.196
27 | # Permanent Green 0.027, 0.427, 0.086
28 | # Sap Green 0.420, 0.580, 0.016
29 | # Burnt Sienna 0.482, 0.282, 0.000
30 | #
31 | # LICENSING
32 | #
33 | # If you want to obtain commercial license, please
34 | # contact us at: mixbox@scrtwpns.com
35 | #
36 |
37 | tool
38 | extends VisualShaderNodeCustom
39 | class_name VisualShaderNodeMixboxLerp
40 |
41 | func _init():
42 | set_input_port_default_value(0, Vector3(0.0, 0.129, 0.522))
43 | set_input_port_default_value(1, Vector3(0.988, 0.827, 0.0))
44 | set_input_port_default_value(2, 0.5)
45 |
46 | func _get_name():
47 | return "MixboxLerp"
48 |
49 | func _get_category():
50 | return "Mixbox"
51 |
52 | func _get_description():
53 | return "Mixbox"
54 |
55 | func _get_return_icon_type():
56 | return VisualShaderNode.PORT_TYPE_VECTOR
57 |
58 | func _get_input_port_count():
59 | return 3
60 |
61 | func _get_input_port_name(port):
62 | match port:
63 | 0:
64 | return "a"
65 | 1:
66 | return "b"
67 | 2:
68 | return "t"
69 |
70 | func _get_input_port_type(port):
71 | match port:
72 | 0:
73 | return VisualShaderNode.PORT_TYPE_VECTOR
74 | 1:
75 | return VisualShaderNode.PORT_TYPE_VECTOR
76 | 2:
77 | return VisualShaderNode.PORT_TYPE_SCALAR
78 |
79 | func _get_output_port_count():
80 | return 1
81 |
82 |
83 | func _get_output_port_name(port):
84 | return "result"
85 |
86 | func _get_output_port_type(port):
87 | return VisualShaderNode.PORT_TYPE_VECTOR
88 |
89 | func _get_global_code(mode):
90 | return """
91 | uniform sampler2D mixbox_lut;
92 |
93 | vec3 _mixbox_eval_polynomial(vec3 _mixbox_c) {
94 | float _mixbox_c0 = _mixbox_c[0];
95 | float _mixbox_c1 = _mixbox_c[1];
96 | float _mixbox_c2 = _mixbox_c[2];
97 | float _mixbox_c3 = 1.0 - (_mixbox_c0 + _mixbox_c1 + _mixbox_c2);
98 |
99 | float _mixbox_c00 = _mixbox_c0 * _mixbox_c0;
100 | float _mixbox_c11 = _mixbox_c1 * _mixbox_c1;
101 | float _mixbox_c22 = _mixbox_c2 * _mixbox_c2;
102 | float _mixbox_c01 = _mixbox_c0 * _mixbox_c1;
103 | float _mixbox_c02 = _mixbox_c0 * _mixbox_c2;
104 | float _mixbox_c12 = _mixbox_c1 * _mixbox_c2;
105 | float _mixbox_c33 = _mixbox_c3 * _mixbox_c3;
106 |
107 | return (
108 | (_mixbox_c0 * _mixbox_c00) * vec3(+0.07717053, +0.02826978, +0.24832992) +
109 | (_mixbox_c1 * _mixbox_c11) * vec3(+0.95912302, +0.80256528, +0.03561839) +
110 | (_mixbox_c2 * _mixbox_c22) * vec3(+0.74683774, +0.04868586, +0.00000000) +
111 | (_mixbox_c3 * _mixbox_c33) * vec3(+0.99518138, +0.99978149, +0.99704802) +
112 | (_mixbox_c00 * _mixbox_c1) * vec3(+0.04819146, +0.83363781, +0.32515377) +
113 | (_mixbox_c01 * _mixbox_c1) * vec3(-0.68146950, +1.46107803, +1.06980936) +
114 | (_mixbox_c00 * _mixbox_c2) * vec3(+0.27058419, -0.15324870, +1.98735057) +
115 | (_mixbox_c02 * _mixbox_c2) * vec3(+0.80478189, +0.67093710, +0.18424500) +
116 | (_mixbox_c00 * _mixbox_c3) * vec3(-0.35031003, +1.37855826, +3.68865000) +
117 | (_mixbox_c0 * _mixbox_c33) * vec3(+1.05128046, +1.97815239, +2.82989073) +
118 | (_mixbox_c11 * _mixbox_c2) * vec3(+3.21607125, +0.81270228, +1.03384539) +
119 | (_mixbox_c1 * _mixbox_c22) * vec3(+2.78893374, +0.41565549, -0.04487295) +
120 | (_mixbox_c11 * _mixbox_c3) * vec3(+3.02162577, +2.55374103, +0.32766114) +
121 | (_mixbox_c1 * _mixbox_c33) * vec3(+2.95124691, +2.81201112, +1.17578442) +
122 | (_mixbox_c22 * _mixbox_c3) * vec3(+2.82677043, +0.79933038, +1.81715262) +
123 | (_mixbox_c2 * _mixbox_c33) * vec3(+2.99691099, +1.22593053, +1.80653661) +
124 | (_mixbox_c01 * _mixbox_c2) * vec3(+1.87394106, +2.05027182, -0.29835996) +
125 | (_mixbox_c01 * _mixbox_c3) * vec3(+2.56609566, +7.03428198, +0.62575374) +
126 | (_mixbox_c02 * _mixbox_c3) * vec3(+4.08329484, -1.40408358, +2.14995522) +
127 | (_mixbox_c12 * _mixbox_c3) * vec3(+6.00078678, +2.55552042, +1.90739502));
128 | }
129 |
130 | mat3 _mixbox_rgb_to_latent(vec3 _mixbox_rgb) {
131 | _mixbox_rgb = clamp(_mixbox_rgb, 0.0, 1.0);
132 |
133 | float _mixbox_x = _mixbox_rgb.r * 63.0;
134 | float _mixbox_y = _mixbox_rgb.g * 63.0;
135 | float _mixbox_z = _mixbox_rgb.b * 63.0;
136 |
137 | float _mixbox_iz = floor(_mixbox_z);
138 |
139 | float _mixbox_x0 = mod(_mixbox_iz, 8.0) * 64.0;
140 | float _mixbox_y0 = floor(_mixbox_iz / 8.0) * 64.0;
141 |
142 | float _mixbox_x1 = mod(_mixbox_iz + 1.0, 8.0) * 64.0;
143 | float _mixbox_y1 = floor((_mixbox_iz + 1.0) / 8.0) * 64.0;
144 |
145 | vec2 _mixbox_uv0 = vec2(_mixbox_x0 + _mixbox_x + 0.5, _mixbox_y0 + _mixbox_y + 0.5) / 512.0;
146 | vec2 _mixbox_uv1 = vec2(_mixbox_x1 + _mixbox_x + 0.5, _mixbox_y1 + _mixbox_y + 0.5) / 512.0;
147 |
148 | vec3 _mixbox_c = mix(textureLod(mixbox_lut, _mixbox_uv0, 0.0).rgb, textureLod(mixbox_lut, _mixbox_uv1, 0.0).rgb, _mixbox_z - _mixbox_iz);
149 |
150 | return mat3(_mixbox_c, _mixbox_rgb - _mixbox_eval_polynomial(_mixbox_c), vec3(0.0));
151 | }
152 |
153 | vec3 _mixbox_latent_to_rgb(mat3 _mixbox_latent) {
154 | return clamp(_mixbox_eval_polynomial(_mixbox_latent[0]) + _mixbox_latent[1], 0.0, 1.0);
155 | }
156 |
157 | vec3 _mixbox_lerp(vec3 _mixbox_color1, vec3 _mixbox_color2, float _mixbox_t) {
158 | return _mixbox_latent_to_rgb((1.0-_mixbox_t)*_mixbox_rgb_to_latent(_mixbox_color1.rgb) + _mixbox_t*_mixbox_rgb_to_latent(_mixbox_color2.rgb));
159 | }
160 | """
161 |
162 | func _get_code(input_vars, output_vars, mode, type):
163 | return output_vars[0] + " = _mixbox_lerp(%s, %s, %s);" % [input_vars[0], input_vars[1], input_vars[2]]
164 |
--------------------------------------------------------------------------------
/javascript/examples/splash.html:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
161 |
162 |
163 |
--------------------------------------------------------------------------------
/shaders/README.md:
--------------------------------------------------------------------------------
1 | ## GLSL Shader
2 | ```glsl
3 | #ifdef GL_ES
4 | precision highp float;
5 | #endif
6 |
7 | // uncomment the following line if you work in linear space
8 | // #define MIXBOX_COLORSPACE_LINEAR
9 |
10 | uniform sampler2D mixbox_lut; // bind the "mixbox_lut.png" texture here
11 |
12 | #include "mixbox.glsl" // paste the contents of mixbox.glsl here
13 |
14 | void main(void)
15 | {
16 | vec3 rgb1 = vec3(0, 0.129, 0.522); // blue
17 | vec3 rgb2 = vec3(0.988, 0.827, 0); // yellow
18 | float t = 0.5; // mixing ratio
19 |
20 | vec3 rgb = mixbox_lerp(rgb1, rgb2, t);
21 |
22 | gl_FragColor = vec4(rgb, 1.0);
23 | }
24 | ```
25 | ```glsl
26 | vec3 mix_three(vec3 rgb1, vec3 rgb2, vec3 rgb3)
27 | {
28 | mixbox_latent z1 = mixbox_rgb_to_latent(rgb1);
29 | mixbox_latent z2 = mixbox_rgb_to_latent(rgb2);
30 | mixbox_latent z3 = mixbox_rgb_to_latent(rgb3);
31 |
32 | // mix together 30% of rgb1, 60% of rgb2, and 10% of rgb3
33 | mixbox_latent z_mix = 0.3*z1 + 0.6*z2 + 0.1*z3;
34 |
35 | vec3 rgb_mix = mixbox_latent_to_rgb(z_mix);
36 |
37 | return rgb_mix;
38 | }
39 | ```
40 |
41 | ## HLSL Shader
42 | ```hlsl
43 | // uncomment the following line if you work in linear space
44 | // #define MIXBOX_COLORSPACE_LINEAR
45 |
46 | Texture2D MixboxLUT; // bind the "mixbox_lut.png" texture here
47 | SamplerState MixboxSampler; // FILTER_MIN_MAG_LINEAR_MIP_POINT
48 |
49 | #define MIXBOX_LUT(UV) MixboxLUT.SampleLevel(MixboxSampler, UV, 0)
50 |
51 | #include "mixbox.hlsl"
52 |
53 | float4 PSMain() : SV_Target
54 | {
55 | float3 rgb1 = float3(0, 0.129, 0.522); // blue
56 | float3 rgb2 = float3(0.988, 0.827, 0); // yellow
57 | float t = 0.5; // mixing ratio
58 |
59 | float3 rgb_mix = MixboxLerp(rgb1, rgb2, t);
60 |
61 | return float4(rgb_mix, 1.0);
62 | }
63 | ```
64 | ```hlsl
65 | float3 MixThree(float3 rgb1, float3 rgb2, float3 rgb3)
66 | {
67 | MixboxLatent z1 = MixboxRGBToLatent(rgb1);
68 | MixboxLatent z2 = MixboxRGBToLatent(rgb2);
69 | MixboxLatent z3 = MixboxRGBToLatent(rgb3);
70 |
71 | // mix together 30% of rgb1, 60% of rgb2, and 10% of rgb3
72 | MixboxLatent zMix = 0.3*z1 + 0.6*z2 + 0.1*z3;
73 |
74 | float3 rgbMix = MixboxLatentToRGB(zMix);
75 |
76 | return rgbMix;
77 | }
78 | ```
79 |
80 | ## Metal Shader
81 | ```metal
82 | #include
83 | using namespace metal;
84 |
85 | // uncomment the following line if you work in linear space
86 | // #define MIXBOX_COLORSPACE_LINEAR
87 |
88 | #include "mixbox.metal"
89 |
90 | fragment float4 // load "mixbox_lut.png" into texture 0
91 | fragment_main(texture2d mixbox_lut [[texture(0)]])
92 | {
93 | float3 rgb1 = float3(0, 0.129, 0.522); // blue
94 | float3 rgb2 = float3(0.988, 0.827, 0); // yellow
95 |
96 | float t = 0.5; // mixing ratio
97 |
98 | float3 rgb_mix = mixbox_lerp(mixbox_lut, rgb1, rgb2, t);
99 |
100 | return float4(rgb_mix, 1.0);
101 | }
102 | ```
103 | ```metal
104 | float3 mix_three(texture2d mixbox_lut,
105 | float3 rgb1, float3 rgb2, float3 rgb3)
106 | {
107 | mixbox_latent z1 = mixbox_rgb_to_latent(mixbox_lut, rgb1);
108 | mixbox_latent z2 = mixbox_rgb_to_latent(mixbox_lut, rgb2);
109 | mixbox_latent z3 = mixbox_rgb_to_latent(mixbox_lut, rgb3);
110 |
111 | // mix together 30% of rgb1, 60% of rgb2, and 10% of rgb3
112 | mixbox_latent z_mix = 0.3*z1 + 0.6*z2 + 0.1*z3;
113 |
114 | float3 rgb_mix = mixbox_latent_to_rgb(z_mix);
115 |
116 | return rgb_mix;
117 | }
118 | ```
119 |
120 | ## OSL Shader
121 | ```c
122 | #include "mixbox.osl"
123 |
124 | shader mix(
125 | color rgb1 = color(0.0, 0.015, 0.235), // blue
126 | color rgb2 = color(0.973, 0.651, 0.0), // yellow
127 | float t = 0.5, // mixing ratio
128 | output color rgb_mix = 0
129 | )
130 | {
131 | rgb_mix = mixbox_lerp(rgb1, rgb2, t);
132 | }
133 | ```
134 | ```c
135 | color mix_three(color rgb1, color rgb2, color rgb3)
136 | {
137 | mixbox_latent z1 = mixbox_rgb_to_latent(rgb1);
138 | mixbox_latent z2 = mixbox_rgb_to_latent(rgb2);
139 | mixbox_latent z3 = mixbox_rgb_to_latent(rgb3);
140 |
141 | // mix together 30% of rgb1, 60% of rgb2, and 10% of rgb3
142 | mixbox_latent z_mix = 0.3*z1 + 0.6*z2 + 0.1*z3;
143 |
144 | color rgb_mix = mixbox_latent_to_rgb(z_mix);
145 |
146 | return rgb_mix;
147 | }
148 | ```
149 |
150 | ## Pigment Colors
151 | | Pigment | | RGB | Float RGB | Linear RGB |
152 | | --- | --- |:----:|:----:|:----:|
153 | | Cadmium Yellow |
| 254, 236, 0 | 0.996, 0.925, 0.0 | 0.991, 0.839, 0.0 |
154 | | Hansa Yellow |
| 252, 211, 0 | 0.988, 0.827, 0.0 | 0.973, 0.651, 0.0 |
155 | | Cadmium Orange |
| 255, 105, 0 | 1.0, 0.412, 0.0 | 1.0, 0.141, 0.0 |
156 | | Cadmium Red |
| 255, 39, 2 | 1.0, 0.153, 0.008 | 1.0, 0.02, 0.001 |
157 | | Quinacridone Magenta |
| 128, 2, 46 | 0.502, 0.008, 0.18 | 0.216, 0.001, 0.027 |
158 | | Cobalt Violet |
| 78, 0, 66 | 0.306, 0.0, 0.259 | 0.076, 0.0, 0.054 |
159 | | Ultramarine Blue |
| 25, 0, 89 | 0.098, 0.0, 0.349 | 0.01, 0.0, 0.1 |
160 | | Cobalt Blue |
| 0, 33, 133 | 0.0, 0.129, 0.522 | 0.0, 0.015, 0.235 |
161 | | Phthalo Blue |
| 13, 27, 68 | 0.051, 0.106, 0.267 | 0.004, 0.011, 0.058 |
162 | | Phthalo Green |
| 0, 60, 50 | 0.0, 0.235, 0.196 | 0.0, 0.045, 0.032 |
163 | | Permanent Green |
| 7, 109, 22 | 0.027, 0.427, 0.086 | 0.002, 0.153, 0.008 |
164 | | Sap Green |
| 107, 148, 4 | 0.42, 0.58, 0.016 | 0.147, 0.296, 0.001 |
165 | | Burnt Sienna |
| 123, 72, 0 | 0.482, 0.282, 0.0 | 0.198, 0.065, 0.0 |
166 |
167 | ## License
168 | Copyright (c) 2022, Secret Weapons. All rights reserved.
169 | Mixbox is provided under the CC BY-NC 4.0 license for non-commercial use only.
170 | If you want to obtain commercial license, please contact: mixbox@scrtwpns.com
171 |
--------------------------------------------------------------------------------
/unity/README.md:
--------------------------------------------------------------------------------
1 | # Mixbox for Unity
2 |
3 | Open `Window` > `Package Manager` and choose ` + ` > `Add packge from git URL...`:
4 | ```
5 | https://github.com/scrtwpns/mixbox.git#upm
6 | ```
7 |
8 | ## Script
9 | ```csharp
10 | using UnityEngine;
11 | using Scrtwpns.Mixbox;
12 |
13 | public class NewBehaviourScript : MonoBehaviour
14 | {
15 | void Start()
16 | {
17 | Color color1 = new Color(0.0f, 0.129f, 0.522f); // blue
18 | Color color2 = new Color(0.988f, 0.827f, 0.0f); // yellow
19 | float t = 0.5f; // mixing ratio
20 |
21 | Color colorMix = Mixbox.Lerp(color1, color2, t);
22 |
23 | Debug.Log(colorMix);
24 | }
25 | }
26 | ```
27 | ```csharp
28 | Color MixThree(Color color1, Color color2, Color color3)
29 | {
30 | MixboxLatent z1 = Mixbox.RGBToLatent(color1);
31 | MixboxLatent z2 = Mixbox.RGBToLatent(color2);
32 | MixboxLatent z3 = Mixbox.RGBToLatent(color3);
33 |
34 | // mix 30% of color1, 60% of color2, and 10% of color3
35 | MixboxLatent zMix = 0.3f*z1 + 0.6f*z2 + 0.1f*z3;
36 |
37 | Color colorMix = Mixbox.LatentToRGB(zMix);
38 |
39 | return colorMix;
40 | }
41 | ```
42 |
43 | ## Shader
44 | ```ShaderLab
45 | Shader "MixboxHelloShader"
46 | {
47 | Properties
48 | {
49 | [NoScaleOffset] _MixboxLUT ("Mixbox LUT", 2D) = "white" {} // assign "Packages/Mixbox/Textures/MixboxLUT.png"
50 |
51 | _Color1 ("Color 1", Color) = (0, 0.129, 0.522, 1) // blue
52 | _Color2 ("Color 2", Color) = (0.988, 0.827, 0, 1) // yellow
53 | }
54 | SubShader
55 | {
56 | Pass
57 | {
58 | CGPROGRAM
59 | #pragma vertex vert
60 | #pragma fragment frag
61 |
62 | #include "UnityCG.cginc"
63 |
64 | sampler2D _MixboxLUT;
65 | #include "Packages/com.scrtwpns.mixbox/ShaderLibrary/Mixbox.cginc"
66 |
67 | fixed4 _Color1;
68 | fixed4 _Color2;
69 |
70 | struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; };
71 | struct v2f { float2 uv : TEXCOORD0; float4 vertex : SV_POSITION; };
72 |
73 | v2f vert (appdata v)
74 | {
75 | v2f o;
76 | o.vertex = UnityObjectToClipPos(v.vertex);
77 | o.uv = v.uv;
78 | return o;
79 | }
80 |
81 | fixed4 frag (v2f i) : SV_Target
82 | {
83 | return MixboxLerp(_Color1, _Color2, i.uv.x);
84 | }
85 | ENDCG
86 | }
87 | }
88 | }
89 | ```
90 | ```hlsl
91 | float3 MixThree(float3 rgb1, float3 rgb2, float3 rgb3)
92 | {
93 | MixboxLatent z1 = MixboxRGBToLatent(rgb1);
94 | MixboxLatent z2 = MixboxRGBToLatent(rgb2);
95 | MixboxLatent z3 = MixboxRGBToLatent(rgb3);
96 |
97 | // mix together 30% of rgb1, 60% of rgb2, and 10% of rgb3
98 | MixboxLatent zMix = 0.3*z1 + 0.6*z2 + 0.1*z3;
99 |
100 | float3 rgbMix = MixboxLatentToRGB(zMix);
101 |
102 | return rgbMix;
103 | }
104 | ```
105 |
106 |
107 |
108 |
109 | ## URP Shader
110 | ```ShaderLab
111 | Shader "Mixbox/Mixbox URP Sample Shader"
112 | {
113 | Properties
114 | {
115 | [NoScaleOffset] _MixboxLUT ("Mixbox LUT", 2D) = "white" {} // assign "Packages/Mixbox/Textures/MixboxLUT.png"
116 |
117 | _Color1 ("Color 1", Color) = (0, 0.129, 0.522, 1) // blue
118 | _Color2 ("Color 2", Color) = (0.988, 0.827, 0, 1) // yellow
119 | }
120 |
121 | SubShader
122 | {
123 | Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalRenderPipeline" }
124 |
125 | Pass
126 | {
127 | HLSLPROGRAM
128 | #pragma vertex vert
129 | #pragma fragment frag
130 |
131 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
132 |
133 | TEXTURE2D(_MixboxLUT);
134 | SAMPLER(sampler_MixboxLUT);
135 |
136 | #include "Packages/com.scrtwpns.mixbox/ShaderLibrary/Mixbox.hlsl"
137 |
138 | struct Attributes { float4 positionOS : POSITION; float2 uv : TEXCOORD0; };
139 | struct Varyings { float4 positionHCS : SV_POSITION; float2 uv : TEXCOORD0; };
140 |
141 | CBUFFER_START(UnityPerMaterial)
142 | half4 _Color1;
143 | half4 _Color2;
144 | CBUFFER_END
145 |
146 | Varyings vert(Attributes IN)
147 | {
148 | Varyings OUT;
149 | OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
150 | OUT.uv = IN.uv;
151 | return OUT;
152 | }
153 |
154 | half4 frag(Varyings IN) : SV_Target
155 | {
156 | return MixboxLerp(_Color1, _Color2, IN.uv.x);
157 | }
158 | ENDHLSL
159 | }
160 | }
161 | }
162 | ```
163 |
164 | ## Shader Graph
165 |
166 |
167 |
168 |
169 | ## Pigment Colors
170 | | Pigment | | RGB | Float RGB | Linear RGB |
171 | | --- | --- |:----:|:----:|:----:|
172 | | Cadmium Yellow |
| 254, 236, 0 | 0.996, 0.925, 0.0 | 0.991, 0.839, 0.0 |
173 | | Hansa Yellow |
| 252, 211, 0 | 0.988, 0.827, 0.0 | 0.973, 0.651, 0.0 |
174 | | Cadmium Orange |
| 255, 105, 0 | 1.0, 0.412, 0.0 | 1.0, 0.141, 0.0 |
175 | | Cadmium Red |
| 255, 39, 2 | 1.0, 0.153, 0.008 | 1.0, 0.02, 0.001 |
176 | | Quinacridone Magenta |
| 128, 2, 46 | 0.502, 0.008, 0.18 | 0.216, 0.001, 0.027 |
177 | | Cobalt Violet |
| 78, 0, 66 | 0.306, 0.0, 0.259 | 0.076, 0.0, 0.054 |
178 | | Ultramarine Blue |
| 25, 0, 89 | 0.098, 0.0, 0.349 | 0.01, 0.0, 0.1 |
179 | | Cobalt Blue |
| 0, 33, 133 | 0.0, 0.129, 0.522 | 0.0, 0.015, 0.235 |
180 | | Phthalo Blue |
| 13, 27, 68 | 0.051, 0.106, 0.267 | 0.004, 0.011, 0.058 |
181 | | Phthalo Green |
| 0, 60, 50 | 0.0, 0.235, 0.196 | 0.0, 0.045, 0.032 |
182 | | Permanent Green |
| 7, 109, 22 | 0.027, 0.427, 0.086 | 0.002, 0.153, 0.008 |
183 | | Sap Green |
| 107, 148, 4 | 0.42, 0.58, 0.016 | 0.147, 0.296, 0.001 |
184 | | Burnt Sienna |
| 123, 72, 0 | 0.482, 0.282, 0.0 | 0.198, 0.065, 0.0 |
185 |
186 | ## License
187 | Copyright (c) 2022, Secret Weapons. All rights reserved.
188 | Mixbox is provided under the CC BY-NC 4.0 license for non-commercial use only.
189 | If you want to obtain commercial license, please contact: mixbox@scrtwpns.com
190 |
--------------------------------------------------------------------------------
/godot/addons/mixbox/mixbox.gd:
--------------------------------------------------------------------------------
1 | # ==========================================================
2 | # MIXBOX 2.0 (c) 2022 Secret Weapons. All rights reserved.
3 | # License: Creative Commons Attribution-NonCommercial 4.0
4 | # Authors: Sarka Sochorova and Ondrej Jamriska
5 | # ==========================================================
6 | #
7 | # BASIC USAGE
8 | #
9 | # var color_mix = Mixbox.lerp(color1, color2, t)
10 | #
11 | # MULTI-COLOR MIXING
12 | #
13 | # var z1 = Mixbox.rgb_to_latent(color1)
14 | # var z2 = Mixbox.rgb_to_latent(color2)
15 | # var z3 = Mixbox.rgb_to_latent(color3)
16 | #
17 | # var z_mix = []
18 | # z_mix.resize(Mixbox.LATENT_SIZE)
19 | #
20 | # for i in z_mix.size(): # mix together:
21 | # z_mix[i] = (0.3*z1[i] + # 30% of color1
22 | # 0.6*z2[i] + # 60% of color2
23 | # 0.1*z3[i]) # 10% of color3
24 | #
25 | # var color_mix = Mixbox.latent_to_rgb(z_mix)
26 | #
27 | # PIGMENT COLORS
28 | #
29 | # Cadmium Yellow 0.996, 0.925, 0.000
30 | # Hansa Yellow 0.988, 0.827, 0.000
31 | # Cadmium Orange 1.000, 0.412, 0.000
32 | # Cadmium Red 1.000, 0.153, 0.008
33 | # Quinacridone Magenta 0.502, 0.008, 0.180
34 | # Cobalt Violet 0.306, 0.000, 0.259
35 | # Ultramarine Blue 0.098, 0.000, 0.349
36 | # Cobalt Blue 0.000, 0.129, 0.522
37 | # Phthalo Blue 0.051, 0.106, 0.267
38 | # Phthalo Green 0.000, 0.235, 0.196
39 | # Permanent Green 0.027, 0.427, 0.086
40 | # Sap Green 0.420, 0.580, 0.016
41 | # Burnt Sienna 0.482, 0.282, 0.000
42 | #
43 | # LICENSING
44 | #
45 | # If you want to obtain commercial license, please
46 | # contact us at: mixbox@scrtwpns.com
47 | #
48 |
49 | const lut = preload("mixbox.res").__data__
50 |
51 | const LATENT_SIZE = 7
52 |
53 | static func clamp01(value : float) -> float:
54 | return clamp(value, 0.0, 1.0)
55 |
56 | static func eval_polynomial(c0 : float, c1 : float, c2 : float, c3 : float) -> Color:
57 | var r = 0.0
58 | var g = 0.0
59 | var b = 0.0
60 |
61 | var c00 = c0 * c0
62 | var c11 = c1 * c1
63 | var c22 = c2 * c2
64 | var c33 = c3 * c3
65 | var c01 = c0 * c1
66 | var c02 = c0 * c2
67 | var c12 = c1 * c2
68 |
69 | var w = 0.0
70 | w = c0*c00; r += +0.07717053*w; g += +0.02826978*w; b += +0.24832992*w;
71 | w = c1*c11; r += +0.95912302*w; g += +0.80256528*w; b += +0.03561839*w;
72 | w = c2*c22; r += +0.74683774*w; g += +0.04868586*w; b += +0.00000000*w;
73 | w = c3*c33; r += +0.99518138*w; g += +0.99978149*w; b += +0.99704802*w;
74 | w = c00*c1; r += +0.04819146*w; g += +0.83363781*w; b += +0.32515377*w;
75 | w = c01*c1; r += -0.68146950*w; g += +1.46107803*w; b += +1.06980936*w;
76 | w = c00*c2; r += +0.27058419*w; g += -0.15324870*w; b += +1.98735057*w;
77 | w = c02*c2; r += +0.80478189*w; g += +0.67093710*w; b += +0.18424500*w;
78 | w = c00*c3; r += -0.35031003*w; g += +1.37855826*w; b += +3.68865000*w;
79 | w = c0*c33; r += +1.05128046*w; g += +1.97815239*w; b += +2.82989073*w;
80 | w = c11*c2; r += +3.21607125*w; g += +0.81270228*w; b += +1.03384539*w;
81 | w = c1*c22; r += +2.78893374*w; g += +0.41565549*w; b += -0.04487295*w;
82 | w = c11*c3; r += +3.02162577*w; g += +2.55374103*w; b += +0.32766114*w;
83 | w = c1*c33; r += +2.95124691*w; g += +2.81201112*w; b += +1.17578442*w;
84 | w = c22*c3; r += +2.82677043*w; g += +0.79933038*w; b += +1.81715262*w;
85 | w = c2*c33; r += +2.99691099*w; g += +1.22593053*w; b += +1.80653661*w;
86 | w = c01*c2; r += +1.87394106*w; g += +2.05027182*w; b += -0.29835996*w;
87 | w = c01*c3; r += +2.56609566*w; g += +7.03428198*w; b += +0.62575374*w;
88 | w = c02*c3; r += +4.08329484*w; g += -1.40408358*w; b += +2.14995522*w;
89 | w = c12*c3; r += +6.00078678*w; g += +2.55552042*w; b += +1.90739502*w;
90 |
91 | return Color(r, g, b)
92 |
93 | static func rgb_to_latent(color : Color) -> Array:
94 | var r = clamp01(color.r)
95 | var g = clamp01(color.g)
96 | var b = clamp01(color.b)
97 |
98 | var x = r * 63.0
99 | var y = g * 63.0
100 | var z = b * 63.0
101 |
102 | var ix = int(x)
103 | var iy = int(y)
104 | var iz = int(z)
105 |
106 | var tx = x - ix
107 | var ty = y - iy
108 | var tz = z - iz
109 |
110 | var xyz = ix + iy*64 + iz*64*64
111 |
112 | var c0 = 0.0
113 | var c1 = 0.0
114 | var c2 = 0.0
115 |
116 | var w = 0.0
117 | w = (1.0-tx)*(1.0-ty)*(1.0-tz); c0 += w*lut[xyz+ 192]; c1 += w*lut[xyz+262336]; c2 += w*lut[xyz+524480];
118 | w = ( tx)*(1.0-ty)*(1.0-tz); c0 += w*lut[xyz+ 193]; c1 += w*lut[xyz+262337]; c2 += w*lut[xyz+524481];
119 | w = (1.0-tx)*( ty)*(1.0-tz); c0 += w*lut[xyz+ 256]; c1 += w*lut[xyz+262400]; c2 += w*lut[xyz+524544];
120 | w = ( tx)*( ty)*(1.0-tz); c0 += w*lut[xyz+ 257]; c1 += w*lut[xyz+262401]; c2 += w*lut[xyz+524545];
121 | w = (1.0-tx)*(1.0-ty)*( tz); c0 += w*lut[xyz+4288]; c1 += w*lut[xyz+266432]; c2 += w*lut[xyz+528576];
122 | w = ( tx)*(1.0-ty)*( tz); c0 += w*lut[xyz+4289]; c1 += w*lut[xyz+266433]; c2 += w*lut[xyz+528577];
123 | w = (1.0-tx)*( ty)*( tz); c0 += w*lut[xyz+4352]; c1 += w*lut[xyz+266496]; c2 += w*lut[xyz+528640];
124 | w = ( tx)*( ty)*( tz); c0 += w*lut[xyz+4353]; c1 += w*lut[xyz+266497]; c2 += w*lut[xyz+528641];
125 |
126 | c0 /= 255.0
127 | c1 /= 255.0
128 | c2 /= 255.0
129 |
130 | var c3 = 1.0 - (c0 + c1 + c2)
131 |
132 | var c00 = c0 * c0
133 | var c11 = c1 * c1
134 | var c22 = c2 * c2
135 | var c33 = c3 * c3
136 | var c01 = c0 * c1
137 | var c02 = c0 * c2
138 | var c12 = c1 * c2
139 |
140 | var rmix = 0.0
141 | var gmix = 0.0
142 | var bmix = 0.0
143 |
144 | w = c0*c00; rmix += +0.07717053*w; gmix += +0.02826978*w; bmix += +0.24832992*w;
145 | w = c1*c11; rmix += +0.95912302*w; gmix += +0.80256528*w; bmix += +0.03561839*w;
146 | w = c2*c22; rmix += +0.74683774*w; gmix += +0.04868586*w; bmix += +0.00000000*w;
147 | w = c3*c33; rmix += +0.99518138*w; gmix += +0.99978149*w; bmix += +0.99704802*w;
148 | w = c00*c1; rmix += +0.04819146*w; gmix += +0.83363781*w; bmix += +0.32515377*w;
149 | w = c01*c1; rmix += -0.68146950*w; gmix += +1.46107803*w; bmix += +1.06980936*w;
150 | w = c00*c2; rmix += +0.27058419*w; gmix += -0.15324870*w; bmix += +1.98735057*w;
151 | w = c02*c2; rmix += +0.80478189*w; gmix += +0.67093710*w; bmix += +0.18424500*w;
152 | w = c00*c3; rmix += -0.35031003*w; gmix += +1.37855826*w; bmix += +3.68865000*w;
153 | w = c0*c33; rmix += +1.05128046*w; gmix += +1.97815239*w; bmix += +2.82989073*w;
154 | w = c11*c2; rmix += +3.21607125*w; gmix += +0.81270228*w; bmix += +1.03384539*w;
155 | w = c1*c22; rmix += +2.78893374*w; gmix += +0.41565549*w; bmix += -0.04487295*w;
156 | w = c11*c3; rmix += +3.02162577*w; gmix += +2.55374103*w; bmix += +0.32766114*w;
157 | w = c1*c33; rmix += +2.95124691*w; gmix += +2.81201112*w; bmix += +1.17578442*w;
158 | w = c22*c3; rmix += +2.82677043*w; gmix += +0.79933038*w; bmix += +1.81715262*w;
159 | w = c2*c33; rmix += +2.99691099*w; gmix += +1.22593053*w; bmix += +1.80653661*w;
160 | w = c01*c2; rmix += +1.87394106*w; gmix += +2.05027182*w; bmix += -0.29835996*w;
161 | w = c01*c3; rmix += +2.56609566*w; gmix += +7.03428198*w; bmix += +0.62575374*w;
162 | w = c02*c3; rmix += +4.08329484*w; gmix += -1.40408358*w; bmix += +2.14995522*w;
163 | w = c12*c3; rmix += +6.00078678*w; gmix += +2.55552042*w; bmix += +1.90739502*w;
164 |
165 | return [
166 | c0,
167 | c1,
168 | c2,
169 | c3,
170 | r - rmix,
171 | g - gmix,
172 | b - bmix,
173 | ]
174 |
175 | static func latent_to_rgb(latent) -> Color:
176 | var rgb = eval_polynomial(latent[0], latent[1], latent[2], latent[3])
177 | return Color(
178 | clamp01(rgb.r + latent[4]),
179 | clamp01(rgb.g + latent[5]),
180 | clamp01(rgb.b + latent[6])
181 | );
182 |
183 | static func lerp(color1 : Color, color2 : Color, t : float) -> Color:
184 | var latent1 = rgb_to_latent(color1)
185 | var latent2 = rgb_to_latent(color2)
186 |
187 | var latent_mix = []
188 |
189 | latent_mix.resize(LATENT_SIZE)
190 |
191 | for i in latent_mix.size():
192 | latent_mix[i] = (1.0-t)*latent1[i] + t*latent2[i]
193 |
194 | var color_mix = latent_to_rgb(latent_mix)
195 |
196 | color_mix.a = (1.0-t)*color1.a + t*color2.a
197 |
198 | return color_mix
199 |
--------------------------------------------------------------------------------
/unity/Samples~/SamplesHDRP/Materials/MixboxSampleHDRPShaderGraphMaterial.mat:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &-6293881395593774545
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 11
6 | m_CorrespondingSourceObject: {fileID: 0}
7 | m_PrefabInstance: {fileID: 0}
8 | m_PrefabAsset: {fileID: 0}
9 | m_GameObject: {fileID: 0}
10 | m_Enabled: 1
11 | m_EditorHideFlags: 0
12 | m_Script: {fileID: 11500000, guid: da692e001514ec24dbc4cca1949ff7e8, type: 3}
13 | m_Name:
14 | m_EditorClassIdentifier:
15 | version: 12
16 | hdPluginSubTargetMaterialVersions:
17 | m_Keys: []
18 | m_Values:
19 | --- !u!21 &2100000
20 | Material:
21 | serializedVersion: 8
22 | m_ObjectHideFlags: 0
23 | m_CorrespondingSourceObject: {fileID: 0}
24 | m_PrefabInstance: {fileID: 0}
25 | m_PrefabAsset: {fileID: 0}
26 | m_Name: MixboxSampleHDRPShaderGraphMaterial
27 | m_Shader: {fileID: -6465566751694194690, guid: 5078a8abaf2327c44bdceef809b956b1,
28 | type: 3}
29 | m_ValidKeywords: []
30 | m_InvalidKeywords:
31 | - _DISABLE_SSR_TRANSPARENT
32 | - _NORMALMAP_TANGENT_SPACE
33 | m_LightmapFlags: 4
34 | m_EnableInstancingVariants: 0
35 | m_DoubleSidedGI: 0
36 | m_CustomRenderQueue: 2000
37 | stringTagMap:
38 | MotionVector: User
39 | disabledShaderPasses:
40 | - TransparentDepthPrepass
41 | - TransparentDepthPostpass
42 | - TransparentBackface
43 | - RayTracingPrepass
44 | - MOTIONVECTORS
45 | m_SavedProperties:
46 | serializedVersion: 3
47 | m_TexEnvs:
48 | - _AnisotropyMap:
49 | m_Texture: {fileID: 0}
50 | m_Scale: {x: 1, y: 1}
51 | m_Offset: {x: 0, y: 0}
52 | - _BaseColorMap:
53 | m_Texture: {fileID: 0}
54 | m_Scale: {x: 1, y: 1}
55 | m_Offset: {x: 0, y: 0}
56 | - _BentNormalMap:
57 | m_Texture: {fileID: 0}
58 | m_Scale: {x: 1, y: 1}
59 | m_Offset: {x: 0, y: 0}
60 | - _BentNormalMapOS:
61 | m_Texture: {fileID: 0}
62 | m_Scale: {x: 1, y: 1}
63 | m_Offset: {x: 0, y: 0}
64 | - _CoatMaskMap:
65 | m_Texture: {fileID: 0}
66 | m_Scale: {x: 1, y: 1}
67 | m_Offset: {x: 0, y: 0}
68 | - _DetailMap:
69 | m_Texture: {fileID: 0}
70 | m_Scale: {x: 1, y: 1}
71 | m_Offset: {x: 0, y: 0}
72 | - _EmissiveColorMap:
73 | m_Texture: {fileID: 0}
74 | m_Scale: {x: 1, y: 1}
75 | m_Offset: {x: 0, y: 0}
76 | - _HeightMap:
77 | m_Texture: {fileID: 0}
78 | m_Scale: {x: 1, y: 1}
79 | m_Offset: {x: 0, y: 0}
80 | - _IridescenceMaskMap:
81 | m_Texture: {fileID: 0}
82 | m_Scale: {x: 1, y: 1}
83 | m_Offset: {x: 0, y: 0}
84 | - _IridescenceThicknessMap:
85 | m_Texture: {fileID: 0}
86 | m_Scale: {x: 1, y: 1}
87 | m_Offset: {x: 0, y: 0}
88 | - _MainTex:
89 | m_Texture: {fileID: 0}
90 | m_Scale: {x: 1, y: 1}
91 | m_Offset: {x: 0, y: 0}
92 | - _MaskMap:
93 | m_Texture: {fileID: 0}
94 | m_Scale: {x: 1, y: 1}
95 | m_Offset: {x: 0, y: 0}
96 | - _MixboxLerpCustomFunction_6d215c5b13de4fa59f8aa951085a2436_MixboxLUT_4:
97 | m_Texture: {fileID: 2800000, guid: 9bb177930f1b0624ebcd9bdad8029652, type: 3}
98 | m_Scale: {x: 1, y: 1}
99 | m_Offset: {x: 0, y: 0}
100 | - _NormalMap:
101 | m_Texture: {fileID: 0}
102 | m_Scale: {x: 1, y: 1}
103 | m_Offset: {x: 0, y: 0}
104 | - _NormalMapOS:
105 | m_Texture: {fileID: 0}
106 | m_Scale: {x: 1, y: 1}
107 | m_Offset: {x: 0, y: 0}
108 | - _SpecularColorMap:
109 | m_Texture: {fileID: 0}
110 | m_Scale: {x: 1, y: 1}
111 | m_Offset: {x: 0, y: 0}
112 | - _SubsurfaceMaskMap:
113 | m_Texture: {fileID: 0}
114 | m_Scale: {x: 1, y: 1}
115 | m_Offset: {x: 0, y: 0}
116 | - _TangentMap:
117 | m_Texture: {fileID: 0}
118 | m_Scale: {x: 1, y: 1}
119 | m_Offset: {x: 0, y: 0}
120 | - _TangentMapOS:
121 | m_Texture: {fileID: 0}
122 | m_Scale: {x: 1, y: 1}
123 | m_Offset: {x: 0, y: 0}
124 | - _ThicknessMap:
125 | m_Texture: {fileID: 0}
126 | m_Scale: {x: 1, y: 1}
127 | m_Offset: {x: 0, y: 0}
128 | - _TransmittanceColorMap:
129 | m_Texture: {fileID: 0}
130 | m_Scale: {x: 1, y: 1}
131 | m_Offset: {x: 0, y: 0}
132 | - unity_Lightmaps:
133 | m_Texture: {fileID: 0}
134 | m_Scale: {x: 1, y: 1}
135 | m_Offset: {x: 0, y: 0}
136 | - unity_LightmapsInd:
137 | m_Texture: {fileID: 0}
138 | m_Scale: {x: 1, y: 1}
139 | m_Offset: {x: 0, y: 0}
140 | - unity_ShadowMasks:
141 | m_Texture: {fileID: 0}
142 | m_Scale: {x: 1, y: 1}
143 | m_Offset: {x: 0, y: 0}
144 | m_Ints: []
145 | m_Floats:
146 | - _AORemapMax: 1
147 | - _AORemapMin: 0
148 | - _ATDistance: 1
149 | - _AddPrecomputedVelocity: 0
150 | - _AlbedoAffectEmissive: 0
151 | - _AlphaCutoff: 0.5
152 | - _AlphaCutoffEnable: 0
153 | - _AlphaCutoffPostpass: 0.5
154 | - _AlphaCutoffPrepass: 0.5
155 | - _AlphaCutoffShadow: 0.5
156 | - _AlphaDstBlend: 0
157 | - _AlphaSrcBlend: 1
158 | - _AlphaToMask: 0
159 | - _AlphaToMaskInspectorValue: 0
160 | - _Anisotropy: 0
161 | - _BlendMode: 0
162 | - _CoatMask: 0
163 | - _ConservativeDepthOffsetEnable: 0
164 | - _CullMode: 2
165 | - _CullModeForward: 2
166 | - _Cutoff: 0.5
167 | - _DepthOffsetEnable: 0
168 | - _DetailAlbedoScale: 1
169 | - _DetailNormalScale: 1
170 | - _DetailSmoothnessScale: 1
171 | - _DiffusionProfile: 0
172 | - _DiffusionProfileHash: 0
173 | - _DisplacementLockObjectScale: 1
174 | - _DisplacementLockTilingScale: 1
175 | - _DisplacementMode: 0
176 | - _DoubleSidedEnable: 0
177 | - _DoubleSidedGIMode: 0
178 | - _DoubleSidedNormalMode: 1
179 | - _DstBlend: 0
180 | - _EmissiveColorMode: 1
181 | - _EmissiveExposureWeight: 1
182 | - _EmissiveIntensity: 1
183 | - _EmissiveIntensityUnit: 0
184 | - _EnableBlendModePreserveSpecularLighting: 1
185 | - _EnableFogOnTransparent: 1
186 | - _EnableGeometricSpecularAA: 0
187 | - _EnergyConservingSpecularColor: 1
188 | - _HeightAmplitude: 0.02
189 | - _HeightCenter: 0.5
190 | - _HeightMapParametrization: 0
191 | - _HeightMax: 1
192 | - _HeightMin: -1
193 | - _HeightOffset: 0
194 | - _HeightPoMAmplitude: 2
195 | - _HeightTessAmplitude: 2
196 | - _HeightTessCenter: 0.5
197 | - _InvTilingScale: 1
198 | - _Ior: 1.5
199 | - _IridescenceMask: 1
200 | - _IridescenceThickness: 1
201 | - _LinkDetailsWithBase: 1
202 | - _MaterialID: 1
203 | - _Metallic: 0
204 | - _MetallicRemapMax: 1
205 | - _MetallicRemapMin: 0
206 | - _NormalMapSpace: 0
207 | - _NormalScale: 1
208 | - _OpaqueCullMode: 2
209 | - _PPDLodThreshold: 5
210 | - _PPDMaxSamples: 15
211 | - _PPDMinSamples: 5
212 | - _PPDPrimitiveLength: 1
213 | - _PPDPrimitiveWidth: 1
214 | - _RayTracing: 0
215 | - _ReceivesSSR: 1
216 | - _ReceivesSSRTransparent: 0
217 | - _RefractionModel: 0
218 | - _RenderQueueType: 1
219 | - _Smoothness: 0.5
220 | - _SmoothnessRemapMax: 1
221 | - _SmoothnessRemapMin: 0
222 | - _SpecularAAScreenSpaceVariance: 0.1
223 | - _SpecularAAThreshold: 0.2
224 | - _SpecularOcclusionMode: 1
225 | - _SrcBlend: 1
226 | - _StencilRef: 0
227 | - _StencilRefDepth: 0
228 | - _StencilRefDistortionVec: 4
229 | - _StencilRefGBuffer: 2
230 | - _StencilRefMV: 32
231 | - _StencilWriteMask: 6
232 | - _StencilWriteMaskDepth: 8
233 | - _StencilWriteMaskDistortionVec: 4
234 | - _StencilWriteMaskGBuffer: 14
235 | - _StencilWriteMaskMV: 40
236 | - _SubsurfaceMask: 1
237 | - _SupportDecals: 1
238 | - _SurfaceType: 0
239 | - _TexWorldScale: 1
240 | - _TexWorldScaleEmissive: 1
241 | - _Thickness: 1
242 | - _TransmissionEnable: 1
243 | - _TransparentBackfaceEnable: 0
244 | - _TransparentCullMode: 2
245 | - _TransparentDepthPostpassEnable: 0
246 | - _TransparentDepthPrepassEnable: 0
247 | - _TransparentSortPriority: 0
248 | - _TransparentWritingMotionVec: 0
249 | - _TransparentZWrite: 0
250 | - _UVBase: 0
251 | - _UVDetail: 0
252 | - _UVEmissive: 0
253 | - _UseEmissiveIntensity: 0
254 | - _UseShadowThreshold: 0
255 | - _ZTestDepthEqualForOpaque: 3
256 | - _ZTestGBuffer: 4
257 | - _ZTestTransparent: 4
258 | - _ZWrite: 1
259 | m_Colors:
260 | - _BaseColor: {r: 1, g: 1, b: 1, a: 1}
261 | - _BaseColorMap_MipInfo: {r: 0, g: 0, b: 0, a: 0}
262 | - _Color: {r: 1, g: 1, b: 1, a: 1}
263 | - _DiffusionProfileAsset: {r: 0, g: 0, b: 0, a: 0}
264 | - _DoubleSidedConstants: {r: 1, g: 1, b: -1, a: 0}
265 | - _EmissionColor: {r: 1, g: 1, b: 1, a: 1}
266 | - _EmissiveColor: {r: 0, g: 0, b: 0, a: 1}
267 | - _EmissiveColorLDR: {r: 0, g: 0, b: 0, a: 1}
268 | - _InvPrimScale: {r: 1, g: 1, b: 0, a: 0}
269 | - _IridescenceThicknessRemap: {r: 0, g: 1, b: 0, a: 0}
270 | - _SpecularColor: {r: 1, g: 1, b: 1, a: 1}
271 | - _ThicknessRemap: {r: 0, g: 1, b: 0, a: 0}
272 | - _TransmittanceColor: {r: 1, g: 1, b: 1, a: 1}
273 | - _UVDetailsMappingMask: {r: 1, g: 0, b: 0, a: 0}
274 | - _UVMappingMask: {r: 1, g: 0, b: 0, a: 0}
275 | - _UVMappingMaskEmissive: {r: 1, g: 0, b: 0, a: 0}
276 | m_BuildTextureStacks: []
277 |
--------------------------------------------------------------------------------
/rust/src/lib.rs:
--------------------------------------------------------------------------------
1 | // ==========================================================
2 | // MIXBOX 2.0 (c) 2022 Secret Weapons. All rights reserved.
3 | // License: Creative Commons Attribution-NonCommercial 4.0
4 | // Authors: Sarka Sochorova and Ondrej Jamriska
5 | // ==========================================================
6 | //
7 | // BASIC USAGE
8 | //
9 | // let rgb_mix = mixbox::lerp(&rgb1, &rgb2, t);
10 | //
11 | // MULTI-COLOR MIXING
12 | //
13 | // let z1 = mixbox::rgb_to_latent(&rgb1);
14 | // let z2 = mixbox::rgb_to_latent(&rgb2);
15 | // let z3 = mixbox::rgb_to_latent(&rgb3);
16 | //
17 | // let mut z_mix = [0.0; mixbox::LATENT_SIZE];
18 | //
19 | // for i in 0..z_mix.len() { // mix together:
20 | // z_mix[i] = 0.3*z1[i] + // 30% of rgb1
21 | // 0.6*z2[i] + // 60% of rgb2
22 | // 0.1*z3[i]; // 10% of rgb3
23 | // }
24 | //
25 | // let rgb_mix = mixbox::latent_to_rgb(&z_mix);
26 | //
27 | // PIGMENT COLORS
28 | //
29 | // Cadmium Yellow 254, 236, 0
30 | // Hansa Yellow 252, 211, 0
31 | // Cadmium Orange 255, 105, 0
32 | // Cadmium Red 255, 39, 2
33 | // Quinacridone Magenta 128, 2, 46
34 | // Cobalt Violet 78, 0, 66
35 | // Ultramarine Blue 25, 0, 89
36 | // Cobalt Blue 0, 33, 133
37 | // Phthalo Blue 13, 27, 68
38 | // Phthalo Green 0, 60, 50
39 | // Permanent Green 7, 109, 22
40 | // Sap Green 107, 148, 4
41 | // Burnt Sienna 123, 72, 0
42 | //
43 | // LICENSING
44 | //
45 | // If you want to obtain commercial license, please
46 | // contact us at: mixbox@scrtwpns.com
47 | //
48 |
49 | #![no_std]
50 |
51 | use libm::powf;
52 |
53 | pub const LATENT_SIZE: usize = 7;
54 |
55 | const MIXBOX_LUT : &[u8] = include_bytes!("lut.dat");
56 |
57 | #[inline(always)]
58 | fn clamp01(x: f32) -> f32 {
59 | if x < 0.0 {
60 | 0.0
61 | } else if x > 1.0 {
62 | 1.0
63 | } else {
64 | x
65 | }
66 | }
67 |
68 | #[inline(always)]
69 | fn srgb_to_linear(x: f32) -> f32 {
70 | if x >= 0.04045 {
71 | powf((x + 0.055) / 1.055, 2.4)
72 | } else {
73 | x / 12.92
74 | }
75 | }
76 |
77 | #[inline(always)]
78 | fn linear_to_srgb(x: f32) -> f32 {
79 | if x >= 0.0031308 {
80 | 1.055 * powf(x, 1.0 / 2.4) - 0.055
81 | } else {
82 | 12.92 * x
83 | }
84 | }
85 |
86 | #[inline(always)]
87 | fn eval_polynomial(c0: f32, c1: f32, c2: f32, c3: f32) -> [f32; 3] {
88 | let c00 = c0 * c0;
89 | let c11 = c1 * c1;
90 | let c22 = c2 * c2;
91 | let c33 = c3 * c3;
92 | let c01 = c0 * c1;
93 | let c02 = c0 * c2;
94 | let c12 = c1 * c2;
95 |
96 | let mut r = 0.0;
97 | let mut g = 0.0;
98 | let mut b = 0.0;
99 |
100 | let w00 = c0 * c00; r += 0.07717053*w00; g += 0.02826978*w00; b += 0.24832992*w00;
101 | let w01 = c1 * c11; r += 0.95912302*w01; g += 0.80256528*w01; b += 0.03561839*w01;
102 | let w02 = c2 * c22; r += 0.74683774*w02; g += 0.04868586*w02; b += 0.00000000*w02;
103 | let w03 = c3 * c33; r += 0.99518138*w03; g += 0.99978149*w03; b += 0.99704802*w03;
104 | let w04 = c00 * c1; r += 0.04819146*w04; g += 0.83363781*w04; b += 0.32515377*w04;
105 | let w05 = c01 * c1; r += -0.68146950*w05; g += 1.46107803*w05; b += 1.06980936*w05;
106 | let w06 = c00 * c2; r += 0.27058419*w06; g += -0.15324870*w06; b += 1.98735057*w06;
107 | let w07 = c02 * c2; r += 0.80478189*w07; g += 0.67093710*w07; b += 0.18424500*w07;
108 | let w08 = c00 * c3; r += -0.35031003*w08; g += 1.37855826*w08; b += 3.68865000*w08;
109 | let w09 = c0 * c33; r += 1.05128046*w09; g += 1.97815239*w09; b += 2.82989073*w09;
110 | let w10 = c11 * c2; r += 3.21607125*w10; g += 0.81270228*w10; b += 1.03384539*w10;
111 | let w11 = c1 * c22; r += 2.78893374*w11; g += 0.41565549*w11; b += -0.04487295*w11;
112 | let w12 = c11 * c3; r += 3.02162577*w12; g += 2.55374103*w12; b += 0.32766114*w12;
113 | let w13 = c1 * c33; r += 2.95124691*w13; g += 2.81201112*w13; b += 1.17578442*w13;
114 | let w14 = c22 * c3; r += 2.82677043*w14; g += 0.79933038*w14; b += 1.81715262*w14;
115 | let w15 = c2 * c33; r += 2.99691099*w15; g += 1.22593053*w15; b += 1.80653661*w15;
116 | let w16 = c01 * c2; r += 1.87394106*w16; g += 2.05027182*w16; b += -0.29835996*w16;
117 | let w17 = c01 * c3; r += 2.56609566*w17; g += 7.03428198*w17; b += 0.62575374*w17;
118 | let w18 = c02 * c3; r += 4.08329484*w18; g += -1.40408358*w18; b += 2.14995522*w18;
119 | let w19 = c12 * c3; r += 6.00078678*w19; g += 2.55552042*w19; b += 1.90739502*w19;
120 |
121 | [r, g, b]
122 | }
123 |
124 | pub fn float_rgb_to_latent(rgb: &[f32; 3]) -> [f32; LATENT_SIZE] {
125 | let r01 = clamp01(rgb[0]);
126 | let g01 = clamp01(rgb[1]);
127 | let b01 = clamp01(rgb[2]);
128 |
129 | let x = r01 * 63.0;
130 | let y = g01 * 63.0;
131 | let z = b01 * 63.0;
132 |
133 | let ix = x as i32;
134 | let iy = y as i32;
135 | let iz = z as i32;
136 |
137 | let tx = x - (ix as f32);
138 | let ty = y - (iy as f32);
139 | let tz = z - (iz as f32);
140 |
141 | let lut = &MIXBOX_LUT[(((ix + iy*64 + iz*64*64) & 0x3FFFF) * 3) as usize ..];
142 |
143 | let mut c0 = 0.0;
144 | let mut c1 = 0.0;
145 | let mut c2 = 0.0;
146 |
147 | let w0 = (1.0-tx)*(1.0-ty)*(1.0-tz); c0 += w0*(lut[ 192] as f32); c1 += w0*(lut[ 193] as f32); c2 += w0*(lut[ 194] as f32);
148 | let w1 = ( tx)*(1.0-ty)*(1.0-tz); c0 += w1*(lut[ 195] as f32); c1 += w1*(lut[ 196] as f32); c2 += w1*(lut[ 197] as f32);
149 | let w2 = (1.0-tx)*( ty)*(1.0-tz); c0 += w2*(lut[ 384] as f32); c1 += w2*(lut[ 385] as f32); c2 += w2*(lut[ 386] as f32);
150 | let w3 = ( tx)*( ty)*(1.0-tz); c0 += w3*(lut[ 387] as f32); c1 += w3*(lut[ 388] as f32); c2 += w3*(lut[ 389] as f32);
151 | let w4 = (1.0-tx)*(1.0-ty)*( tz); c0 += w4*(lut[12480] as f32); c1 += w4*(lut[12481] as f32); c2 += w4*(lut[12482] as f32);
152 | let w5 = ( tx)*(1.0-ty)*( tz); c0 += w5*(lut[12483] as f32); c1 += w5*(lut[12484] as f32); c2 += w5*(lut[12485] as f32);
153 | let w6 = (1.0-tx)*( ty)*( tz); c0 += w6*(lut[12672] as f32); c1 += w6*(lut[12673] as f32); c2 += w6*(lut[12674] as f32);
154 | let w7 = ( tx)*( ty)*( tz); c0 += w7*(lut[12675] as f32); c1 += w7*(lut[12676] as f32); c2 += w7*(lut[12677] as f32);
155 |
156 | c0 *= 1.0 / 255.0;
157 | c1 *= 1.0 / 255.0;
158 | c2 *= 1.0 / 255.0;
159 |
160 | let c3 = 1.0 - (c0 + c1 + c2);
161 |
162 | let mixrgb = eval_polynomial(c0, c1, c2, c3);
163 |
164 | [
165 | c0,
166 | c1,
167 | c2,
168 | c3,
169 | r01 - mixrgb[0],
170 | g01 - mixrgb[1],
171 | b01 - mixrgb[2],
172 | ]
173 | }
174 |
175 | pub fn latent_to_float_rgb(latent: &[f32; LATENT_SIZE]) -> [f32; 3] {
176 | let rgb = eval_polynomial(latent[0], latent[1], latent[2], latent[3]);
177 |
178 | [
179 | clamp01(rgb[0] + latent[4]),
180 | clamp01(rgb[1] + latent[5]),
181 | clamp01(rgb[2] + latent[6]),
182 | ]
183 | }
184 |
185 | pub fn latent_to_rgb(latent: &[f32; LATENT_SIZE]) -> [u8; 3] {
186 | let rgb = latent_to_float_rgb(latent);
187 |
188 | [
189 | (rgb[0] * 255.0 + 0.5) as u8,
190 | (rgb[1] * 255.0 + 0.5) as u8,
191 | (rgb[2] * 255.0 + 0.5) as u8,
192 | ]
193 | }
194 |
195 | pub fn rgb_to_latent(rgb: &[u8; 3]) -> [f32; LATENT_SIZE] {
196 | float_rgb_to_latent(&[
197 | (rgb[0] as f32) / 255.0,
198 | (rgb[1] as f32) / 255.0,
199 | (rgb[2] as f32) / 255.0
200 | ])
201 | }
202 |
203 | pub fn linear_float_rgb_to_latent(rgb: &[f32; 3]) -> [f32; LATENT_SIZE] {
204 | float_rgb_to_latent(&[
205 | linear_to_srgb(rgb[0]),
206 | linear_to_srgb(rgb[1]),
207 | linear_to_srgb(rgb[2]),
208 | ])
209 | }
210 |
211 | pub fn latent_to_linear_float_rgb(latent: &[f32; LATENT_SIZE]) -> [f32; 3] {
212 | let rgb = latent_to_float_rgb(latent);
213 |
214 | [
215 | srgb_to_linear(rgb[0]),
216 | srgb_to_linear(rgb[1]),
217 | srgb_to_linear(rgb[2]),
218 | ]
219 | }
220 |
221 | pub fn lerp(rgb1: &[u8; 3], rgb2: &[u8; 3], t: f32) -> [u8; 3] {
222 | let latent1 = rgb_to_latent(rgb1);
223 | let latent2 = rgb_to_latent(rgb2);
224 |
225 | let mut latent_mix = [0.0; LATENT_SIZE];
226 |
227 | for i in 0..latent_mix.len() {
228 | latent_mix[i] = (1.0 - t) * latent1[i] + t * latent2[i];
229 | }
230 |
231 | latent_to_rgb(&latent_mix)
232 | }
233 |
234 | pub fn lerp_float(rgb1: &[f32; 3], rgb2: &[f32; 3], t: f32) -> [f32; 3] {
235 | let latent1 = float_rgb_to_latent(rgb1);
236 | let latent2 = float_rgb_to_latent(rgb2);
237 |
238 | let mut latent_mix = [0.0; LATENT_SIZE];
239 |
240 | for i in 0..latent_mix.len() {
241 | latent_mix[i] = (1.0 - t) * latent1[i] + t * latent2[i];
242 | }
243 |
244 | latent_to_float_rgb(&latent_mix)
245 | }
246 |
247 | pub fn lerp_linear_float(rgb1: &[f32; 3], rgb2: &[f32; 3], t: f32) -> [f32; 3] {
248 | let latent1 = linear_float_rgb_to_latent(rgb1);
249 | let latent2 = linear_float_rgb_to_latent(rgb2);
250 |
251 | let mut latent_mix = [0.0; LATENT_SIZE];
252 |
253 | for i in 0..latent_mix.len() {
254 | latent_mix[i] = (1.0 - t) * latent1[i] + t * latent2[i];
255 | }
256 |
257 | latent_to_linear_float_rgb(&latent_mix)
258 | }
259 |
--------------------------------------------------------------------------------
/unity/Samples~/SamplesBuiltin/Scenes/Scene.unity:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!29 &1
4 | OcclusionCullingSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 2
7 | m_OcclusionBakeSettings:
8 | smallestOccluder: 5
9 | smallestHole: 0.25
10 | backfaceThreshold: 100
11 | m_SceneGUID: 00000000000000000000000000000000
12 | m_OcclusionCullingData: {fileID: 0}
13 | --- !u!104 &2
14 | RenderSettings:
15 | m_ObjectHideFlags: 0
16 | serializedVersion: 9
17 | m_Fog: 0
18 | m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
19 | m_FogMode: 3
20 | m_FogDensity: 0.01
21 | m_LinearFogStart: 0
22 | m_LinearFogEnd: 300
23 | m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
24 | m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
25 | m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
26 | m_AmbientIntensity: 1
27 | m_AmbientMode: 0
28 | m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
29 | m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
30 | m_HaloStrength: 0.5
31 | m_FlareStrength: 1
32 | m_FlareFadeSpeed: 3
33 | m_HaloTexture: {fileID: 0}
34 | m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
35 | m_DefaultReflectionMode: 0
36 | m_DefaultReflectionResolution: 128
37 | m_ReflectionBounces: 1
38 | m_ReflectionIntensity: 1
39 | m_CustomReflection: {fileID: 0}
40 | m_Sun: {fileID: 0}
41 | m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
42 | m_UseRadianceAmbientProbe: 0
43 | --- !u!157 &3
44 | LightmapSettings:
45 | m_ObjectHideFlags: 0
46 | serializedVersion: 12
47 | m_GIWorkflowMode: 1
48 | m_GISettings:
49 | serializedVersion: 2
50 | m_BounceScale: 1
51 | m_IndirectOutputScale: 1
52 | m_AlbedoBoost: 1
53 | m_EnvironmentLightingMode: 0
54 | m_EnableBakedLightmaps: 1
55 | m_EnableRealtimeLightmaps: 0
56 | m_LightmapEditorSettings:
57 | serializedVersion: 12
58 | m_Resolution: 2
59 | m_BakeResolution: 40
60 | m_AtlasSize: 1024
61 | m_AO: 0
62 | m_AOMaxDistance: 1
63 | m_CompAOExponent: 1
64 | m_CompAOExponentDirect: 0
65 | m_ExtractAmbientOcclusion: 0
66 | m_Padding: 2
67 | m_LightmapParameters: {fileID: 0}
68 | m_LightmapsBakeMode: 1
69 | m_TextureCompression: 1
70 | m_FinalGather: 0
71 | m_FinalGatherFiltering: 1
72 | m_FinalGatherRayCount: 256
73 | m_ReflectionCompression: 2
74 | m_MixedBakeMode: 2
75 | m_BakeBackend: 1
76 | m_PVRSampling: 1
77 | m_PVRDirectSampleCount: 32
78 | m_PVRSampleCount: 512
79 | m_PVRBounces: 2
80 | m_PVREnvironmentSampleCount: 256
81 | m_PVREnvironmentReferencePointCount: 2048
82 | m_PVRFilteringMode: 1
83 | m_PVRDenoiserTypeDirect: 1
84 | m_PVRDenoiserTypeIndirect: 1
85 | m_PVRDenoiserTypeAO: 1
86 | m_PVRFilterTypeDirect: 0
87 | m_PVRFilterTypeIndirect: 0
88 | m_PVRFilterTypeAO: 0
89 | m_PVREnvironmentMIS: 1
90 | m_PVRCulling: 1
91 | m_PVRFilteringGaussRadiusDirect: 1
92 | m_PVRFilteringGaussRadiusIndirect: 5
93 | m_PVRFilteringGaussRadiusAO: 2
94 | m_PVRFilteringAtrousPositionSigmaDirect: 0.5
95 | m_PVRFilteringAtrousPositionSigmaIndirect: 2
96 | m_PVRFilteringAtrousPositionSigmaAO: 1
97 | m_ExportTrainingData: 0
98 | m_TrainingDataDestination: TrainingData
99 | m_LightProbeSampleCountMultiplier: 4
100 | m_LightingDataAsset: {fileID: 0}
101 | m_LightingSettings: {fileID: 0}
102 | --- !u!196 &4
103 | NavMeshSettings:
104 | serializedVersion: 2
105 | m_ObjectHideFlags: 0
106 | m_BuildSettings:
107 | serializedVersion: 2
108 | agentTypeID: 0
109 | agentRadius: 0.5
110 | agentHeight: 2
111 | agentSlope: 45
112 | agentClimb: 0.4
113 | ledgeDropHeight: 0
114 | maxJumpAcrossDistance: 0
115 | minRegionArea: 2
116 | manualCellSize: 0
117 | cellSize: 0.16666667
118 | manualTileSize: 0
119 | tileSize: 256
120 | accuratePlacement: 0
121 | maxJobWorkers: 0
122 | preserveTilesOutsideBounds: 0
123 | debug:
124 | m_Flags: 0
125 | m_NavMeshData: {fileID: 0}
126 | --- !u!1 &2016244961
127 | GameObject:
128 | m_ObjectHideFlags: 0
129 | m_CorrespondingSourceObject: {fileID: 0}
130 | m_PrefabInstance: {fileID: 0}
131 | m_PrefabAsset: {fileID: 0}
132 | serializedVersion: 6
133 | m_Component:
134 | - component: {fileID: 2016244963}
135 | - component: {fileID: 2016244962}
136 | m_Layer: 0
137 | m_Name: Directional Light
138 | m_TagString: Untagged
139 | m_Icon: {fileID: 0}
140 | m_NavMeshLayer: 0
141 | m_StaticEditorFlags: 0
142 | m_IsActive: 1
143 | --- !u!108 &2016244962
144 | Light:
145 | m_ObjectHideFlags: 0
146 | m_CorrespondingSourceObject: {fileID: 0}
147 | m_PrefabInstance: {fileID: 0}
148 | m_PrefabAsset: {fileID: 0}
149 | m_GameObject: {fileID: 2016244961}
150 | m_Enabled: 1
151 | serializedVersion: 10
152 | m_Type: 1
153 | m_Shape: 0
154 | m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
155 | m_Intensity: 1
156 | m_Range: 10
157 | m_SpotAngle: 30
158 | m_InnerSpotAngle: 21.80208
159 | m_CookieSize: 10
160 | m_Shadows:
161 | m_Type: 2
162 | m_Resolution: -1
163 | m_CustomResolution: -1
164 | m_Strength: 1
165 | m_Bias: 0.05
166 | m_NormalBias: 0.4
167 | m_NearPlane: 0.2
168 | m_CullingMatrixOverride:
169 | e00: 1
170 | e01: 0
171 | e02: 0
172 | e03: 0
173 | e10: 0
174 | e11: 1
175 | e12: 0
176 | e13: 0
177 | e20: 0
178 | e21: 0
179 | e22: 1
180 | e23: 0
181 | e30: 0
182 | e31: 0
183 | e32: 0
184 | e33: 1
185 | m_UseCullingMatrixOverride: 0
186 | m_Cookie: {fileID: 0}
187 | m_DrawHalo: 0
188 | m_Flare: {fileID: 0}
189 | m_RenderMode: 0
190 | m_CullingMask:
191 | serializedVersion: 2
192 | m_Bits: 4294967295
193 | m_RenderingLayerMask: 1
194 | m_Lightmapping: 4
195 | m_LightShadowCasterMode: 0
196 | m_AreaSize: {x: 1, y: 1}
197 | m_BounceIntensity: 1
198 | m_ColorTemperature: 6570
199 | m_UseColorTemperature: 0
200 | m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
201 | m_UseBoundingSphereOverride: 0
202 | m_UseViewFrustumForShadowCasterCull: 1
203 | m_ShadowRadius: 0
204 | m_ShadowAngle: 0
205 | --- !u!4 &2016244963
206 | Transform:
207 | m_ObjectHideFlags: 0
208 | m_CorrespondingSourceObject: {fileID: 0}
209 | m_PrefabInstance: {fileID: 0}
210 | m_PrefabAsset: {fileID: 0}
211 | m_GameObject: {fileID: 2016244961}
212 | m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
213 | m_LocalPosition: {x: 0, y: 3, z: 0}
214 | m_LocalScale: {x: 1, y: 1, z: 1}
215 | m_ConstrainProportionsScale: 0
216 | m_Children: []
217 | m_Father: {fileID: 0}
218 | m_RootOrder: 1
219 | m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
220 | --- !u!1 &2102167485
221 | GameObject:
222 | m_ObjectHideFlags: 0
223 | m_CorrespondingSourceObject: {fileID: 0}
224 | m_PrefabInstance: {fileID: 0}
225 | m_PrefabAsset: {fileID: 0}
226 | serializedVersion: 6
227 | m_Component:
228 | - component: {fileID: 2102167489}
229 | - component: {fileID: 2102167488}
230 | - component: {fileID: 2102167487}
231 | - component: {fileID: 2102167486}
232 | m_Layer: 0
233 | m_Name: Plane
234 | m_TagString: Untagged
235 | m_Icon: {fileID: 0}
236 | m_NavMeshLayer: 0
237 | m_StaticEditorFlags: 0
238 | m_IsActive: 1
239 | --- !u!64 &2102167486
240 | MeshCollider:
241 | m_ObjectHideFlags: 0
242 | m_CorrespondingSourceObject: {fileID: 0}
243 | m_PrefabInstance: {fileID: 0}
244 | m_PrefabAsset: {fileID: 0}
245 | m_GameObject: {fileID: 2102167485}
246 | m_Material: {fileID: 0}
247 | m_IsTrigger: 0
248 | m_Enabled: 1
249 | serializedVersion: 4
250 | m_Convex: 0
251 | m_CookingOptions: 30
252 | m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
253 | --- !u!23 &2102167487
254 | MeshRenderer:
255 | m_ObjectHideFlags: 0
256 | m_CorrespondingSourceObject: {fileID: 0}
257 | m_PrefabInstance: {fileID: 0}
258 | m_PrefabAsset: {fileID: 0}
259 | m_GameObject: {fileID: 2102167485}
260 | m_Enabled: 1
261 | m_CastShadows: 1
262 | m_ReceiveShadows: 1
263 | m_DynamicOccludee: 1
264 | m_StaticShadowCaster: 0
265 | m_MotionVectors: 1
266 | m_LightProbeUsage: 1
267 | m_ReflectionProbeUsage: 1
268 | m_RayTracingMode: 2
269 | m_RayTraceProcedural: 0
270 | m_RenderingLayerMask: 1
271 | m_RendererPriority: 0
272 | m_Materials:
273 | - {fileID: 2100000, guid: 22f4a840af474fe47b98f7c563b06bd6, type: 2}
274 | m_StaticBatchInfo:
275 | firstSubMesh: 0
276 | subMeshCount: 0
277 | m_StaticBatchRoot: {fileID: 0}
278 | m_ProbeAnchor: {fileID: 0}
279 | m_LightProbeVolumeOverride: {fileID: 0}
280 | m_ScaleInLightmap: 1
281 | m_ReceiveGI: 1
282 | m_PreserveUVs: 0
283 | m_IgnoreNormalsForChartDetection: 0
284 | m_ImportantGI: 0
285 | m_StitchLightmapSeams: 1
286 | m_SelectedEditorRenderState: 3
287 | m_MinimumChartSize: 4
288 | m_AutoUVMaxDistance: 0.5
289 | m_AutoUVMaxAngle: 89
290 | m_LightmapParameters: {fileID: 0}
291 | m_SortingLayerID: 0
292 | m_SortingLayer: 0
293 | m_SortingOrder: 0
294 | m_AdditionalVertexStreams: {fileID: 0}
295 | --- !u!33 &2102167488
296 | MeshFilter:
297 | m_ObjectHideFlags: 0
298 | m_CorrespondingSourceObject: {fileID: 0}
299 | m_PrefabInstance: {fileID: 0}
300 | m_PrefabAsset: {fileID: 0}
301 | m_GameObject: {fileID: 2102167485}
302 | m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
303 | --- !u!4 &2102167489
304 | Transform:
305 | m_ObjectHideFlags: 0
306 | m_CorrespondingSourceObject: {fileID: 0}
307 | m_PrefabInstance: {fileID: 0}
308 | m_PrefabAsset: {fileID: 0}
309 | m_GameObject: {fileID: 2102167485}
310 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
311 | m_LocalPosition: {x: 0, y: 0, z: 0}
312 | m_LocalScale: {x: 1, y: 1, z: 1}
313 | m_ConstrainProportionsScale: 0
314 | m_Children: []
315 | m_Father: {fileID: 0}
316 | m_RootOrder: 2
317 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
318 | --- !u!1 &2138933249
319 | GameObject:
320 | m_ObjectHideFlags: 0
321 | m_CorrespondingSourceObject: {fileID: 0}
322 | m_PrefabInstance: {fileID: 0}
323 | m_PrefabAsset: {fileID: 0}
324 | serializedVersion: 6
325 | m_Component:
326 | - component: {fileID: 2138933252}
327 | - component: {fileID: 2138933251}
328 | - component: {fileID: 2138933250}
329 | m_Layer: 0
330 | m_Name: Main Camera
331 | m_TagString: MainCamera
332 | m_Icon: {fileID: 0}
333 | m_NavMeshLayer: 0
334 | m_StaticEditorFlags: 0
335 | m_IsActive: 1
336 | --- !u!81 &2138933250
337 | AudioListener:
338 | m_ObjectHideFlags: 0
339 | m_CorrespondingSourceObject: {fileID: 0}
340 | m_PrefabInstance: {fileID: 0}
341 | m_PrefabAsset: {fileID: 0}
342 | m_GameObject: {fileID: 2138933249}
343 | m_Enabled: 1
344 | --- !u!20 &2138933251
345 | Camera:
346 | m_ObjectHideFlags: 0
347 | m_CorrespondingSourceObject: {fileID: 0}
348 | m_PrefabInstance: {fileID: 0}
349 | m_PrefabAsset: {fileID: 0}
350 | m_GameObject: {fileID: 2138933249}
351 | m_Enabled: 1
352 | serializedVersion: 2
353 | m_ClearFlags: 1
354 | m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
355 | m_projectionMatrixMode: 1
356 | m_GateFitMode: 2
357 | m_FOVAxisMode: 0
358 | m_SensorSize: {x: 36, y: 24}
359 | m_LensShift: {x: 0, y: 0}
360 | m_FocalLength: 50
361 | m_NormalizedViewPortRect:
362 | serializedVersion: 2
363 | x: 0
364 | y: 0
365 | width: 1
366 | height: 1
367 | near clip plane: 0.3
368 | far clip plane: 1000
369 | field of view: 60
370 | orthographic: 0
371 | orthographic size: 5
372 | m_Depth: -1
373 | m_CullingMask:
374 | serializedVersion: 2
375 | m_Bits: 4294967295
376 | m_RenderingPath: -1
377 | m_TargetTexture: {fileID: 0}
378 | m_TargetDisplay: 0
379 | m_TargetEye: 3
380 | m_HDR: 1
381 | m_AllowMSAA: 1
382 | m_AllowDynamicResolution: 0
383 | m_ForceIntoRT: 0
384 | m_OcclusionCulling: 1
385 | m_StereoConvergence: 10
386 | m_StereoSeparation: 0.022
387 | --- !u!4 &2138933252
388 | Transform:
389 | m_ObjectHideFlags: 0
390 | m_CorrespondingSourceObject: {fileID: 0}
391 | m_PrefabInstance: {fileID: 0}
392 | m_PrefabAsset: {fileID: 0}
393 | m_GameObject: {fileID: 2138933249}
394 | m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068}
395 | m_LocalPosition: {x: 0, y: 10, z: 0}
396 | m_LocalScale: {x: 1, y: 1, z: 1}
397 | m_ConstrainProportionsScale: 0
398 | m_Children: []
399 | m_Father: {fileID: 0}
400 | m_RootOrder: 0
401 | m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0}
402 |
--------------------------------------------------------------------------------