Skip to content

Commit 7d1b828

Browse files
committed
Added the support for color spaces (LuxCore and OpenColorIO) to constant textures
1 parent 2297231 commit 7d1b828

File tree

13 files changed

+222
-161
lines changed

13 files changed

+222
-161
lines changed

include/slg/core/colorspace.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,19 @@ class ColorSpaceConfig {
4444
// OPENCOLORIO_COLORSPACE constructor
4545
ColorSpaceConfig(const std::string &configName, const std::string &colorSpaceName);
4646
// From properties constructor
47-
ColorSpaceConfig(const luxrays::Properties &props, const std::string &prefix);
47+
ColorSpaceConfig(const luxrays::Properties &props, const std::string &prefix,
48+
const ColorSpaceConfig &defaultCfg);
4849

4950
~ColorSpaceConfig();
5051

5152
static void FromProperties(const luxrays::Properties &props, const std::string &prefix,
52-
ColorSpaceConfig &colorSpaceCfg);
53+
ColorSpaceConfig &colorSpaceCfg, const ColorSpaceConfig &defaultCfg);
54+
static ColorSpaceType String2ColorSpaceType(const std::string &type);
55+
static std::string ColorSpaceType2String(const ColorSpaceConfig::ColorSpaceType type);
56+
57+
static const ColorSpaceConfig defaultNopConfig;
58+
static const ColorSpaceConfig defaultLuxCoreConfig;
59+
static const ColorSpaceConfig defaultOpenColorIOConfig;
5360

5461
ColorSpaceType colorSpaceType;
5562

include/slg/scene/colorspaceconverters.h

+15-4
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@
2020
#define _SLG_COLORSPACECONVERTERS_H
2121

2222
#include <string>
23+
#include <boost/unordered_map.hpp>
2324

24-
#include <boost/unordered_set.hpp>
25+
#include <OpenColorIO/OpenColorIO.h>
26+
namespace OCIO = OCIO_NAMESPACE;
2527

2628
#include "luxrays/core/color/color.h"
2729
#include "slg/slg.h"
30+
#include "slg/core/colorspace.h"
2831

2932
namespace slg {
3033

@@ -36,12 +39,20 @@ class ColorSpaceConverters {
3639
public:
3740
ColorSpaceConverters();
3841
virtual ~ColorSpaceConverters();
39-
42+
43+
void ConvertFrom(const ColorSpaceConfig &cfg, float &v);
44+
void ConvertFrom(const ColorSpaceConfig &cfg, luxrays::Spectrum &c);
45+
46+
private:
4047
void ConvertFromLuxCore(const float gamma, float &v);
4148
void ConvertFromLuxCore(const float gamma, luxrays::Spectrum &c);
4249

43-
private:
44-
//std::string GetKey() const;
50+
void ConvertFromOpenColorIO(const std::string &configFileName,
51+
const std::string &inputColorSpace, float &v);
52+
void ConvertFromOpenColorIO(const std::string &configFileName,
53+
const std::string &inputColorSpace, luxrays::Spectrum &c);
54+
55+
boost::unordered_map<std::string, OCIO::ConstCPUProcessorRcPtr> ocioProcessorCache;
4556
};
4657

4758
}

include/slg/scene/scene.h

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
#include "slg/scene/extmeshcache.h"
4848
#include "slg/scene/colorspaceconverters.h"
4949

50-
5150
namespace slg {
5251

5352
// OpenCL data types

release-notes.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
* Introduced (partial) multi-thread support in pre-processing of Light sources
88
* Integrated OpenColorIO v2.0
99
* Added the support for new TONEMAP_OPENCOLORIO tone mapper
10-
* Added the support for color spaces (LuxCore and OpenColorIO) to image maps
10+
* Added the support for color spaces (Nop, LuxCore and OpenColorIO) to image maps
11+
* Added the support for color spaces (Nop, LuxCore and OpenColorIO) to constant textures
1112
* FILESAVER avoids to save the internal random image map (used by randomized tiling)
1213

1314
### Fixed Bugs

scenes/opencolorio/cornell.scn

+14-121
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,30 @@
11
scene.camera.type = "perspective"
2-
#scene.camera.lookat.orig = -2.78071809 -3.70725536 1.98850083
3-
#scene.camera.lookat.target = -2.84487319 5.99062538 -0.45017153
42
scene.camera.lookat.orig = -2.78 -8. 2.73
53
scene.camera.lookat.target = -2.78 2. 2.73
64
scene.camera.fieldofview = 39.1463
7-
##
8-
#scene.camera.shutteropen = 0.1
9-
#scene.camera.shutterclose = 0.11
10-
#scene.camera.motion.0.time = 0.0
11-
#scene.camera.motion.0.transformation = 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 -6.0 0.0 0.0 1.0
12-
#scene.camera.motion.1.time = 1.0
13-
#scene.camera.motion.1.transformation = 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 6.0 0.0 0.0 1.0
14-
##
15-
#scene.camera.type = "orthographic"
16-
#scene.camera.screenwindow = -5 5 -5 5
5+
################################################################################
6+
scene.textures.KhakiCol.type = constfloat3
7+
scene.textures.KhakiCol.value = 1. 0.824176 0.549451
8+
scene.textures.KhakiCol.colorspace = luxcore
9+
scene.textures.KhakiCol.colorspace.gamma = 2.2
10+
##
11+
scene.textures.DarkGreenCol.type = constfloat3
12+
scene.textures.DarkGreenCol.value = 0. 0.4 0.
13+
scene.textures.DarkGreenCol.colorspace = opencolorio
14+
scene.textures.DarkGreenCol.colorspace.name = vd8
1715
################################################################################
1816
scene.materials.Khaki.type = matte
19-
scene.materials.Khaki.kd = 1. 0.824176 0.549451
20-
##
21-
#scene.materials.Khaki.type = glossy2
22-
#scene.materials.Khaki.kd = 0.75 0.75 0.75
23-
#scene.materials.Khaki.ks = 0.5 0.5 0.5
24-
#scene.materials.Khaki.uroughness = 0.06
25-
#scene.materials.Khaki.vroughness = 0.06
26-
############################
27-
scene.materials.HalveRed.type = matte
28-
scene.materials.HalveRed.kd = 0.70003 0. 0.
29-
##
30-
#scene.materials.HalveRed.type = glossy2
31-
#scene.materials.HalveRed.kd = 0.75 0.0 0.0
32-
#scene.materials.HalveRed.ks = 0.5 0.5 0.5
33-
#scene.materials.HalveRed.uroughness = 0.06
34-
#scene.materials.HalveRed.vroughness = 0.06
35-
##scene.materials.HalveRed.photongi.enable = 1
36-
##
37-
#scene.materials.HalveRed.type = glossy2
38-
#scene.materials.HalveRed.kd = 0.0 0.0 0.0
39-
#scene.materials.HalveRed.ks = 0.95 0.5 0.5
40-
#scene.materials.HalveRed.uroughness = 0.051
41-
#scene.materials.HalveRed.vroughness = 0.051
42-
#scene.materials.HalveRed.photongi.enable = 1
43-
##
44-
#scene.materials.HalveRed.type = mirror
45-
#scene.materials.HalveRed.kr = 0.9 0.0 0.0
46-
##scene.materials.HalveRed.photongi.enable = 1
47-
##
48-
#scene.materials.HalveRed.type = carpaint
49-
#scene.materials.HalveRed.preset = "opel titan"
17+
scene.materials.Khaki.kd = KhakiCol
5018
##
51-
#scene.materials.HalveRed.type = cloth
52-
#scene.materials.HalveRed.preset = silk_charmeuse
53-
#scene.materials.HalveRed.warp_kd = 0.065344 0.00076876 0.00051252
54-
#scene.materials.HalveRed.warp_ks = 0.27408 0.048368 0.040844
55-
#scene.materials.HalveRed.weft_kd = 0.065344 0.00076876 0.00051252
56-
#scene.materials.HalveRed.weft_ks = 0.27085 0.047292 0.040844
57-
#scene.materials.HalveRed.repeat_u = 200.0
58-
#scene.materials.HalveRed.repeat_v = 100.0
59-
##
60-
#scene.materials.HalveRed.type = metal2
61-
##scene.materials.HalveRed.preset = gold
62-
##scene.materials.HalveRed.preset = silver
63-
#scene.materials.HalveRed.preset = copper
64-
##scene.materials.HalveRed.preset = "amorphous carbon"
65-
##scene.materials.HalveRed.preset = aluminium
66-
#scene.materials.HalveRed.uroughness = 0.2
67-
#scene.materials.HalveRed.vroughness = 0.2
68-
############################
6919
scene.materials.DarkGreen.type = matte
70-
scene.materials.DarkGreen.kd = 0. 0.4 0.
20+
scene.materials.DarkGreen.kd = DarkGreenCol
7121
##
72-
#scene.materials.DarkGreen.type = glossy2
73-
#scene.materials.DarkGreen.kd = 0.0 0.0 0.0
74-
#scene.materials.DarkGreen.ks = 0.5 0.95 0.5
75-
#scene.materials.DarkGreen.uroughness = 0.06
76-
#scene.materials.DarkGreen.vroughness = 0.06
77-
#scene.materials.DarkGreen.photongi.enable = 1
22+
scene.materials.HalveRed.type = matte
23+
scene.materials.HalveRed.kd = 0.70003 0. 0.
7824
##
7925
scene.materials.Light.type = matte
8026
scene.materials.Light.emission = 30. 30. 30.
8127
scene.materials.Light.emission.id = 0
82-
#scene.materials.Light.emission = 10 5 5
83-
#scene.materials.Light.emission.gain = 1 1 1
84-
#scene.materials.Light.emission.gain.normalizebycolor = 1
85-
#scene.materials.Light.emission.power = 1
86-
#scene.materials.Light.emission.normalizebycolor = 0
87-
#scene.materials.Light.emission.efficency = 17
88-
#scene.materials.Light.emission.directlightsampling.type = DISABLED
89-
#scene.materials.Light.emission.theta = 20.0
9028
scene.materials.Light.kd = 0.75 0.75 0.75
9129
################################################################################
9230
scene.objects.Khaki.material = Khaki
@@ -98,48 +36,3 @@ scene.objects.DarkGreen.ply = scenes/cornell/DarkGreen.ply
9836
################################################################################
9937
scene.objects.Grey.material = Light
10038
scene.objects.Grey.ply = scenes/cornell/Grey.ply
101-
# Instance
102-
#scene.objects.Grey.transformation = 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 -1.95 0.0 0.0 1.0
103-
# Motion blur
104-
#scene.objects.Grey.motion.0.time = 0.0
105-
#scene.objects.Grey.motion.0.transformation = 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 -1.95 0.0 0.0 1.0
106-
#scene.objects.Grey.motion.1.time = 1.0
107-
#scene.objects.Grey.motion.1.transformation = 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 1.95 0.0 0.0 1.0
108-
##
109-
#scene.lights.l1.type = point
110-
#scene.lights.l1.position = -2.78 2.79 4
111-
#scene.lights.l1.radius = 0.5
112-
#scene.lights.l1.power = 10
113-
#scene.lights.l1.efficency = 17
114-
#scene.lights.l1.color = 0 0 1
115-
#scene.lights.l1.id = 1
116-
#scene.lights.l2.type = point
117-
##scene.lights.l2.color = 0 0 1
118-
#scene.lights.l2.position = -2.78 2.79 2
119-
#scene.lights.l2.power = 10
120-
#scene.lights.l2.efficency = 17
121-
##
122-
#scene.lights.infinitelight.type = sky2
123-
#scene.lights.infinitelight.dir = 0.166974 -0.59908 0.783085
124-
#scene.lights.infinitelight.turbidity = 2.2
125-
#scene.lights.infinitelight.gain = 0.0003 0.0003 0.0003
126-
##
127-
#scene.lights.infinitelight.type = constantinfinite
128-
#scene.lights.infinitelight.color = 1.0 1.0 1.0
129-
#scene.lights.infinitelight.gain = 2.0 2.0 2.0
130-
##
131-
#scene.lights.infinitelight.type = infinite
132-
#scene.lights.infinitelight.file = scenes/simple-mat/arch.exr
133-
#scene.lights.infinitelight.gamma = 1.0
134-
#scene.lights.infinitelight.gain = 3.0 3.0 3.0
135-
#scene.lights.infinitelight.storage = byte
136-
##
137-
#scene.lights.infinitelight.visibilitymap.enable = 1
138-
#scene.lights.infinitelight.visibilitymap.samples = 10000000
139-
#scene.lights.infinitelight.visibilitymap.width = 128
140-
#scene.lights.infinitelight.visibilitymap.height = 64
141-
##
142-
#scene.lights.infinitelight.visibilitymapcache.enable = 1
143-
#scene.lights.infinitelight.visibilitymapcache.map.width = 128
144-
#scene.lights.infinitelight.visibilitymapcache.map.height = 64
145-
#scene.lights.infinitelight.visibilitymapcache.map.samplecount = 8

src/luxcore/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ set(PYLUXCORE_SRCS
175175
add_library(pyluxcore MODULE ${PYLUXCORE_SRCS} ${LUXCORE_LIB_SRCS} ${LUX_PARSER_SRC})
176176

177177
include_directories(${LuxRays_SOURCE_DIR}/deps/openvdb-7.0.0)
178+
include_directories(${LuxRays_SOURCE_DIR}/deps/opencolorio-2.0.0/include)
178179

179180
add_definitions(-DOPENVDB_STATICLIB ${VISIBILITY_FLAGS})
180181
if(APPLE)

src/slg/core/colorspace.cpp

+69-18
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <OpenColorIO/OpenColorIO.h>
2020
namespace OCIO = OCIO_NAMESPACE;
2121

22+
#include "luxrays/utils/strutils.h"
2223
#include "slg/core/colorspace.h"
2324

2425
using namespace std;
@@ -29,42 +30,92 @@ using namespace slg;
2930
// ColorSpaceConfig
3031
//------------------------------------------------------------------------------
3132

33+
namespace slg {
34+
const ColorSpaceConfig ColorSpaceConfig::defaultNopConfig = ColorSpaceConfig();
35+
const ColorSpaceConfig ColorSpaceConfig::defaultLuxCoreConfig = ColorSpaceConfig(2.2f);
36+
const ColorSpaceConfig ColorSpaceConfig::defaultOpenColorIOConfig = ColorSpaceConfig("", OCIO::ROLE_TEXTURE_PAINT);
37+
}
38+
3239
ColorSpaceConfig::ColorSpaceConfig() {
3340
colorSpaceType = NOP_COLORSPACE;
41+
luxcore.gamma = 2.2f;
42+
ocio.configName = "";
43+
ocio.colorSpaceName = OCIO::ROLE_TEXTURE_PAINT;
3444
}
3545

3646
ColorSpaceConfig::ColorSpaceConfig(const float gamma) {
3747
colorSpaceType = LUXCORE_COLORSPACE;
3848
luxcore.gamma = gamma;
49+
50+
ocio.configName = "";
51+
ocio.colorSpaceName = OCIO::ROLE_TEXTURE_PAINT;
3952
}
4053

4154
ColorSpaceConfig::ColorSpaceConfig(const string &configName, const string &colorSpaceName) {
4255
colorSpaceType = OPENCOLORIO_COLORSPACE;
4356
ocio.configName = configName;
4457
ocio.colorSpaceName = colorSpaceName;
58+
59+
luxcore.gamma = 2.2f;
4560
}
4661

4762
ColorSpaceConfig::~ColorSpaceConfig() {
4863
}
4964

50-
ColorSpaceConfig::ColorSpaceConfig(const Properties &props, const string &prefix) {
51-
FromProperties(props, prefix, *this);
65+
ColorSpaceConfig::ColorSpaceConfig(const Properties &props, const string &prefix, const ColorSpaceConfig &defaultCfg) {
66+
FromProperties(props, prefix, *this, defaultCfg);
67+
}
68+
69+
void ColorSpaceConfig::FromProperties(const Properties &props, const string &prefix,
70+
ColorSpaceConfig &colorSpaceCfg, const ColorSpaceConfig &defaultCfg) {
71+
ColorSpaceType type = String2ColorSpaceType(props.Get(Property(prefix + ".colorspace")(
72+
ColorSpaceType2String(defaultCfg.colorSpaceType))).Get<string>());
73+
74+
colorSpaceCfg = defaultCfg;
75+
76+
switch (type) {
77+
case ColorSpaceConfig::NOP_COLORSPACE: {
78+
colorSpaceCfg.colorSpaceType = NOP_COLORSPACE;
79+
break;
80+
}
81+
case ColorSpaceConfig::LUXCORE_COLORSPACE: {
82+
colorSpaceCfg.colorSpaceType = LUXCORE_COLORSPACE;
83+
// For compatibility with the past
84+
const float oldGamma = props.Get(Property(prefix + ".gamma")(defaultCfg.luxcore.gamma)).Get<float>();
85+
colorSpaceCfg.luxcore.gamma = props.Get(Property(prefix + ".colorspace.gamma")(oldGamma)).Get<float>();
86+
break;
87+
}
88+
case ColorSpaceConfig::OPENCOLORIO_COLORSPACE: {
89+
colorSpaceCfg.colorSpaceType = OPENCOLORIO_COLORSPACE;
90+
colorSpaceCfg.ocio.configName = props.Get(Property(prefix + ".colorspace.config")(defaultCfg.ocio.configName)).Get<string>();
91+
colorSpaceCfg.ocio.colorSpaceName = props.Get(Property(prefix + ".colorspace.name")(defaultCfg.ocio.colorSpaceName)).Get<string>();
92+
break;
93+
}
94+
default:
95+
throw runtime_error("Unknown color space in ColorSpaceConfig::FromProperties(): " + ToString(type));
96+
}
97+
}
98+
99+
ColorSpaceConfig::ColorSpaceType ColorSpaceConfig::String2ColorSpaceType(const string &type) {
100+
if (type == "nop")
101+
return ColorSpaceConfig::NOP_COLORSPACE;
102+
else if (type == "luxcore")
103+
return ColorSpaceConfig::LUXCORE_COLORSPACE;
104+
else if (type == "opencolorio")
105+
return ColorSpaceConfig::OPENCOLORIO_COLORSPACE;
106+
else
107+
throw runtime_error("Unknown color space config type: " + type);
52108
}
53109

54-
void ColorSpaceConfig::FromProperties(const Properties &props, const string &prefix, ColorSpaceConfig &colorSpaceCfg) {
55-
const string colorSpace = props.Get(Property(prefix + ".colorspace")("luxcore")).Get<string>();
56-
57-
if (colorSpace == "nop") {
58-
colorSpaceCfg.colorSpaceType = NOP_COLORSPACE;
59-
} else if (colorSpace == "luxcore") {
60-
colorSpaceCfg.colorSpaceType = LUXCORE_COLORSPACE;
61-
// For compatibility with the past
62-
const float oldGamma = props.Get(Property(prefix + ".gamma")(2.2f)).Get<float>();
63-
colorSpaceCfg.luxcore.gamma = props.Get(Property(prefix + ".colorspace.gamma")(oldGamma)).Get<float>();
64-
} else if (colorSpace == "opencolorio") {
65-
colorSpaceCfg.colorSpaceType = OPENCOLORIO_COLORSPACE;
66-
colorSpaceCfg.ocio.configName = props.Get(Property(prefix + ".colorspace.config")("")).Get<string>();
67-
colorSpaceCfg.ocio.colorSpaceName = props.Get(Property(prefix + ".colorspace.name")(OCIO::ROLE_TEXTURE_PAINT)).Get<string>();
68-
} else
69-
throw runtime_error("Unknown color space in ColorSpaceConfig::FromProperties(): " + colorSpace);
110+
string ColorSpaceConfig::ColorSpaceType2String(const ColorSpaceConfig::ColorSpaceType type) {
111+
switch (type) {
112+
case ColorSpaceConfig::NOP_COLORSPACE:
113+
return "nop";
114+
case ColorSpaceConfig::LUXCORE_COLORSPACE:
115+
return "luxcore";
116+
case ColorSpaceConfig::OPENCOLORIO_COLORSPACE:
117+
return "opencolorio";
118+
default:
119+
throw runtime_error("Unsupported wrap type in ColorSpaceConfig::ColorSpaceType2String(): " + ToString(type));
120+
}
70121
}

src/slg/engines/caches/photongi/photongicache.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ PhotonGISamplerType PhotonGICache::String2SamplerType(const string &type) {
557557
else if (type == "METROPOLIS")
558558
return PhotonGISamplerType::PGIC_SAMPLER_METROPOLIS;
559559
else
560-
throw runtime_error("Unknown PhotonGI cache debug type: " + type);
560+
throw runtime_error("Unknown PhotonGI cache sampler type: " + type);
561561
}
562562

563563
string PhotonGICache::SamplerType2String(const PhotonGISamplerType type) {
@@ -567,7 +567,7 @@ string PhotonGICache::SamplerType2String(const PhotonGISamplerType type) {
567567
case PhotonGISamplerType::PGIC_SAMPLER_METROPOLIS:
568568
return "METROPOLIS";
569569
default:
570-
throw runtime_error("Unsupported wrap type in PhotonGICache::SamplerType2String(): " + ToString(type));
570+
throw runtime_error("Unsupported sampler type in PhotonGICache::SamplerType2String(): " + ToString(type));
571571
}
572572
}
573573

src/slg/film/imagepipeline/plugins/tonemaps/opencolorio.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,6 @@ void OpenColorIOToneMap::Apply(Film &film, const u_int index) {
160160
throw runtime_error("Unknown mode in OpenColorIOToneMap::Apply(): " + ToString(conversionType));
161161
}
162162
} catch (OCIO::Exception &exception) {
163-
SLG_LOG("OpenColorIO Error in OpenColorIOToneMap::Apply(): " << exception.what());
163+
throw runtime_error("OpenColorIO Error in OpenColorIOToneMap::Apply(): " + string(exception.what()));
164164
}
165165
}

0 commit comments

Comments
 (0)