Skip to content

Commit

Permalink
Add ACES2065-1 and ACEScg as shading system color spaces
Browse files Browse the repository at this point in the history
To make functions like blackbody, wavelength and luminance work with these
color spaces.

Signed-off-by: Brecht Van Lommel <[email protected]>
  • Loading branch information
brechtvl authored and lgritz committed Apr 15, 2022
1 parent 4e96ab1 commit beb78b6
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/cmake/testing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ macro (osl_add_all_tests)
bug-array-heapoffsets bug-locallifetime bug-outputinit
bug-param-duplicate bug-peep bug-return
calculatenormal-reg
cellnoise closure closure-array color color-reg comparison
cellnoise closure closure-array color color-reg colorspace comparison
complement-reg compile-buffer compassign-reg
component-range
control-flow-reg connect-components
Expand Down
2 changes: 2 additions & 0 deletions src/include/OSL/strdecls.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ STRDECL("SMPTE", SMPTE)
STRDECL("HDTV", HDTV)
STRDECL("CIE", CIE)
STRDECL("AdobeRGB", AdobeRGB)
STRDECL("ACES2065-1", ACES2065_1)
STRDECL("ACEScg", ACEScg)
STRDECL("colorsystem", colorsystem)
STRDECL("arraylength", arraylength)
STRDECL("unknown", unknown)
Expand Down
41 changes: 24 additions & 17 deletions src/liboslexec/opcolor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,26 @@ OSL_NAMESPACE_ENTER
namespace pvt {

// White point chromaticities.
#define IlluminantC 0.3101, 0.3162 /* For NTSC television */
#define IlluminantD65 0.3127, 0.3291 /* For EBU and SMPTE */
#define IlluminantE 0.33333333, 0.33333333 /* CIE equal-energy illuminant */

OSL_CONSTANT_DATA const static ColorSystem::Chroma k_color_systems[11] = {
// Index, Name xRed yRed xGreen yGreen xBlue yBlue White point
/* 0 Rec709 */ { 0.64, 0.33, 0.30, 0.60, 0.15, 0.06, IlluminantD65 },
/* 1 sRGB */ { 0.64, 0.33, 0.30, 0.60, 0.15, 0.06, IlluminantD65 },
/* 2 NTSC */ { 0.67, 0.33, 0.21, 0.71, 0.14, 0.08, IlluminantC },
/* 3 EBU */ { 0.64, 0.33, 0.29, 0.60, 0.15, 0.06, IlluminantD65 },
/* 4 PAL */ { 0.64, 0.33, 0.29, 0.60, 0.15, 0.06, IlluminantD65 },
/* 5 SECAM */ { 0.64, 0.33, 0.29, 0.60, 0.15, 0.06, IlluminantD65 },
/* 6 SMPTE */ { 0.630, 0.340, 0.310, 0.595, 0.155, 0.070, IlluminantD65 },
/* 7 HDTV */ { 0.670, 0.330, 0.210, 0.710, 0.150, 0.060, IlluminantD65 },
/* 8 CIE */ { 0.7355, 0.2645, 0.2658, 0.7243, 0.1669, 0.0085, IlluminantE },
/* 9 AdobeRGB */ { 0.64, 0.33, 0.21, 0.71, 0.15, 0.06, IlluminantD65 },
/* 10 XYZ */ { 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, IlluminantE },
#define IlluminantC 0.3101, 0.3162 /* For NTSC television */
#define IlluminantD65 0.3127, 0.3291 /* For EBU and SMPTE */
#define IlluminantE 0.33333333, 0.33333333 /* CIE equal-energy illuminant */
#define IlluminantACES 0.32168, 0.33767 /* For ACES, approximate D60 */

OSL_CONSTANT_DATA const static ColorSystem::Chroma k_color_systems[13] = {
// Index, Name xRed yRed xGreen yGreen xBlue yBlue White point
/* 0 Rec709 */ { 0.64, 0.33, 0.30, 0.60, 0.15, 0.06, IlluminantD65 },
/* 1 sRGB */ { 0.64, 0.33, 0.30, 0.60, 0.15, 0.06, IlluminantD65 },
/* 2 NTSC */ { 0.67, 0.33, 0.21, 0.71, 0.14, 0.08, IlluminantC },
/* 3 EBU */ { 0.64, 0.33, 0.29, 0.60, 0.15, 0.06, IlluminantD65 },
/* 4 PAL */ { 0.64, 0.33, 0.29, 0.60, 0.15, 0.06, IlluminantD65 },
/* 5 SECAM */ { 0.64, 0.33, 0.29, 0.60, 0.15, 0.06, IlluminantD65 },
/* 6 SMPTE */ { 0.630, 0.340, 0.310, 0.595, 0.155, 0.070, IlluminantD65 },
/* 7 HDTV */ { 0.670, 0.330, 0.210, 0.710, 0.150, 0.060, IlluminantD65 },
/* 8 CIE */ { 0.7355, 0.2645, 0.2658, 0.7243, 0.1669, 0.0085, IlluminantE },
/* 9 AdobeRGB */ { 0.64, 0.33, 0.21, 0.71, 0.15, 0.06, IlluminantD65 },
/* 10 XYZ */ { 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, IlluminantE },
/* 11 ACES2065-1 */ { 0.7347, 0.2653, 0.0, 1.0, 0.0001, -0.077, IlluminantACES },
/* 12 ACEScg */ { 0.713, 0.293, 0.165, 0.83, 0.128, 0.044, IlluminantACES },
};


Expand Down Expand Up @@ -74,6 +77,10 @@ ColorSystem::fromString(StringParam colorspace) {
return &k_color_systems[9];
if (colorspace == STRING_PARAMS(XYZ))
return &k_color_systems[10];
if (colorspace == STRING_PARAMS(ACES2065_1))
return &k_color_systems[11];
if (colorspace == STRING_PARAMS(ACEScg))
return &k_color_systems[12];
return nullptr;
}

Expand Down
5 changes: 5 additions & 0 deletions src/testshade/testshade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ static std::string raytype = "camera";
static bool raytype_opt = false;
static std::string extraoptions;
static std::string texoptions;
static std::string colorspace;
static OSL::Matrix44 Mshad; // "shader" space to "common" space matrix
static OSL::Matrix44 Mobj; // "object" space to "common" space matrix
static ShaderGroupRef shadergroup;
Expand Down Expand Up @@ -189,6 +190,9 @@ set_shadingsys_options ()
if (texoptions.size())
shadingsys->texturesys()->attribute ("options", texoptions);

if (colorspace.size())
shadingsys->attribute ("colorspace", colorspace);

if (const char *opt_env = getenv ("TESTSHADE_BATCHED"))
batched = atoi(opt_env);

Expand Down Expand Up @@ -628,6 +632,7 @@ getargs (int argc, const char *argv[])
"-g %d %d", &xres, &yres, "", // synonym for -res
"--options %s", &extraoptions, "Set extra OSL options",
"--texoptions %s", &texoptions, "Set extra TextureSystem options",
"--colorspace %s", &colorspace, "Set ShadingSysem colorspace",
"-o %L %L", &outputvars, &outputfiles,
"Output (variable, filename) [filename='null' means don't save]",
"-d %s", &dataformatname, "Set the output data format to one of: "
Expand Down
Empty file added testsuite/colorspace/BATCHED
Empty file.
5 changes: 5 additions & 0 deletions testsuite/colorspace/ref/out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Compiled test.osl -> test.oso
RGB to XYZ (0.1 0.7 0.2) = (0.191286 0.509818 0.204353)
blackbody (1500) = 75.0559 22.3461 2.22219
wavelength (500) = 0 0.207563 0.105645

7 changes: 7 additions & 0 deletions testsuite/colorspace/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env python

# Copyright Contributors to the Open Shading Language project.
# SPDX-License-Identifier: BSD-3-Clause
# https://github.com/AcademySoftwareFoundation/OpenShadingLanguage

command = testshade("-colorspace ACEScg test")
18 changes: 18 additions & 0 deletions testsuite/colorspace/test.osl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright Contributors to the Open Shading Language project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage

#include "../common/shaders/pretty.h"

shader
test ()
{
color c = color (.1, .7, .2);
printf (" RGB to XYZ (%g) = (%g)\n", pretty(c), pretty(transformc("RGB", "XYZ", c)));

float temperature = 1500;
printf (" blackbody (%g) = %g\n", pretty(temperature), pretty(blackbody(temperature)));

float cyan = 500;
printf (" wavelength (%g) = %g\n", pretty(cyan), pretty(wavelength_color(cyan)));
}

0 comments on commit beb78b6

Please sign in to comment.