Skip to content

Commit f10d226

Browse files
dkasugaDaisuke Kasuga
and
Daisuke Kasuga
authored
Add getter functions for settings to build ColorGrading object (#8699)
* add getter methods for ColorGrading builder settings * add tone mapper impl clone funcs * update the release notes --------- Co-authored-by: Daisuke Kasuga <[email protected]>
1 parent 28ecf5c commit f10d226

File tree

9 files changed

+348
-29
lines changed

9 files changed

+348
-29
lines changed

NEW_RELEASE_NOTES.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ for next branch cut* header.
77
appropriate header in [RELEASE_NOTES.md](./RELEASE_NOTES.md).
88

99
## Release notes for next branch cut
10-
1110
- materials: remove dependence on per-view descset layout from filamat. [⚠️ **New Material Version**]
11+
- `ColorGrading::Builder::toneMapper` now takes a `shared_ptr<ToneMapper>`

android/filament-android/src/main/cpp/ColorGrading.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <filament/ColorGrading.h>
2020
#include <filament/ToneMapper.h>
21+
#include <memory>
2122

2223
#include <math/vec3.h>
2324
#include <math/vec4.h>
@@ -67,8 +68,9 @@ extern "C" JNIEXPORT void JNICALL
6768
Java_com_google_android_filament_ColorGrading_nBuilderToneMapper(JNIEnv*, jclass,
6869
jlong nativeBuilder, jlong toneMapper_) {
6970
ColorGrading::Builder* builder = (ColorGrading::Builder*) nativeBuilder;
70-
const ToneMapper* toneMapper = (const ToneMapper*) toneMapper_;
71-
builder->toneMapper(toneMapper);
71+
ToneMapper* toneMapper = reinterpret_cast<ToneMapper*>(toneMapper_);
72+
std::shared_ptr<ToneMapper> toneMapperCopy(toneMapper->clone());
73+
builder->toneMapper(toneMapperCopy);
7274
}
7375

7476
#pragma clang diagnostic push

android/filament-android/src/main/java/com/google/android/filament/ColorGrading.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@ public Builder dimensions(int dim) {
214214
*
215215
* The default tone mapping operator is {@link ToneMapper.ACESLegacy}.
216216
*
217-
* The specified tone mapper must have a lifecycle that exceeds the lifetime of
218-
* this builder. Since the build(Engine&) method is synchronous, it is safe to
219-
* delete the tone mapper object after that finishes executing.
217+
* The copy of the specified tone mapper is set to this builder. It is safe to delete
218+
* the original tone mapper object while the copied one is held by the built ColorGrading
219+
* object.
220220
*
221221
* @param toneMapper The tone mapping operator to apply to the HDR color buffer
222222
*

filament/include/filament/ColorGrading.h

+119-5
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@
2121

2222
#include <filament/FilamentAPI.h>
2323
#include <filament/ToneMapper.h>
24+
#include <filament/ColorSpace.h>
2425

2526
#include <utils/compiler.h>
2627

2728
#include <math/mathfwd.h>
29+
#include <math/vec3.h>
30+
#include <math/vec4.h>
2831

2932
#include <stdint.h>
3033
#include <stddef.h>
34+
#include <memory>
3135

3236
namespace filament {
3337

@@ -201,15 +205,14 @@ class UTILS_PUBLIC ColorGrading : public FilamentAPI {
201205
*
202206
* The default tone mapping operator is ACESLegacyToneMapper.
203207
*
204-
* The specified tone mapper must have a lifecycle that exceeds the lifetime of
205-
* this builder. Since the build(Engine&) method is synchronous, it is safe to
206-
* delete the tone mapper object after that finishes executing.
208+
* The ownership of the specified tone mapper is shared with the builder and built
209+
* ColorGrading object.
207210
*
208211
* @param toneMapper The tone mapping operator to apply to the HDR color buffer
209212
*
210213
* @return This Builder, for chaining calls
211214
*/
212-
Builder& toneMapper(ToneMapper const* UTILS_NULLABLE toneMapper) noexcept;
215+
Builder& toneMapper(std::shared_ptr<ToneMapper> toneMapper) noexcept;
213216

214217
/**
215218
* Selects the tone mapping operator to apply to the HDR color buffer as the last
@@ -487,7 +490,118 @@ class UTILS_PUBLIC ColorGrading : public FilamentAPI {
487490
friend class FColorGrading;
488491
};
489492

490-
protected:
493+
/** Returns the quality level used to create this ColorGrading object. */
494+
QualityLevel getQuality() const noexcept;
495+
496+
/** Returns the LUT format used to create this ColorGrading object. */
497+
LutFormat getLutFormat() const noexcept;
498+
499+
/** Returns the LUT dimensions used to create this ColorGrading object. */
500+
uint8_t getLutDimensions() const noexcept;
501+
502+
/** Returns the tone mapper used to create this ColorGrading object. */
503+
const ToneMapper& getToneMapper() const noexcept;
504+
505+
/** Returns whether luminance scaling was enabled during creation. */
506+
bool isLuminanceScalingEnabled() const noexcept;
507+
508+
/** Returns whether gamut mapping was enabled during creation. */
509+
bool isGamutMappingEnabled() const noexcept;
510+
511+
/** Returns the exposure value used to create this ColorGrading object. */
512+
float getExposure() const noexcept;
513+
514+
/** Returns the night adaptation value used to create this ColorGrading object. */
515+
float getNightAdaptation() const noexcept;
516+
517+
/** Returns the white balance temperature used to create this ColorGrading object. */
518+
float getWhiteBalanceTemperature() const noexcept;
519+
520+
/** Returns the white balance tint used to create this ColorGrading object. */
521+
float getWhiteBalanceTint() const noexcept;
522+
523+
/** Returns the channel mixer output for the red channel. */
524+
math::float3 getChannelMixerOutRed() const noexcept;
525+
526+
/** Returns the channel mixer output for the green channel. */
527+
math::float3 getChannelMixerOutGreen() const noexcept;
528+
529+
/** Returns the channel mixer output for the blue channel. */
530+
math::float3 getChannelMixerOutBlue() const noexcept;
531+
532+
/** Returns the shadows adjustment used to create this ColorGrading object. */
533+
math::float3 getShadows() const noexcept;
534+
535+
/** Returns the midtones adjustment used to create this ColorGrading object. */
536+
math::float3 getMidtones() const noexcept;
537+
538+
/** Returns the highlights adjustment used to create this ColorGrading object. */
539+
math::float3 getHighlights() const noexcept;
540+
541+
/** Returns the shadow/midtones/highlights ranges used to create this ColorGrading object. */
542+
math::float4 getShadowMidtonesHighlightsRanges() const noexcept;
543+
544+
/** Returns the slope adjustment used to create this ColorGrading object. */
545+
math::float3 getSlope() const noexcept;
546+
547+
/** Returns the offset adjustment used to create this ColorGrading object. */
548+
math::float3 getOffset() const noexcept;
549+
550+
/** Returns the power adjustment used to create this ColorGrading object. */
551+
math::float3 getPower() const noexcept;
552+
553+
/** Returns the contrast value used to create this ColorGrading object. */
554+
float getContrast() const noexcept;
555+
556+
/** Returns the vibrance value used to create this ColorGrading object. */
557+
float getVibrance() const noexcept;
558+
559+
/** Returns the saturation value used to create this ColorGrading object. */
560+
float getSaturation() const noexcept;
561+
562+
/** Returns the shadow gamma curve adjustment used to create this ColorGrading object. */
563+
math::float3 getCurvesShadowGamma() const noexcept;
564+
565+
/** Returns the mid-point curve adjustment used to create this ColorGrading object. */
566+
math::float3 getCurvesMidPoint() const noexcept;
567+
568+
/** Returns the highlight scale curve adjustment used to create this ColorGrading object. */
569+
math::float3 getCurvesHighlightScale() const noexcept;
570+
571+
/** Returns the output color space used to create this ColorGrading object. */
572+
const color::ColorSpace& getOutputColorSpace() const noexcept;
573+
574+
protected :
575+
struct Settings {
576+
LutFormat lutFormat = LutFormat::INTEGER;
577+
uint8_t lutDimensions = 32;
578+
std::shared_ptr<ToneMapper> toneMapper = std::make_shared<ACESLegacyToneMapper>();
579+
bool luminanceScaling = false;
580+
bool gummapMapping = false;
581+
float exposure = 0.0f;
582+
float nightAdaptation = 0.0f;
583+
float whiteBalanceTemperature = 0.0f;
584+
float whiteBalanceTint = 0.0f;
585+
math::float3 channelMixerOutRed{1.0f, 0.0f, 0.0f};
586+
math::float3 channelMixerOutGreen{0.0f, 1.0f, 0.0f};
587+
math::float3 channelMixerOutBlue{0.0f, 0.0f, 1.0f};
588+
math::float3 shadows{1.0f, 1.0f, 1.0f};
589+
math::float3 midtones{1.0f, 1.0f, 1.0f};
590+
math::float3 highlights{1.0f, 1.0f, 1.0f};
591+
math::float4 ShadowMidtonesHighlightsRanges{0.0f, 0.333f, 0.55f, 1.0f};
592+
math::float3 slope{1.0f};
593+
math::float3 offset{0.0f};
594+
math::float3 power{1.0f};
595+
float contrast = 1.0f;
596+
float vibrance = 1.0f;
597+
float saturation = 1.0f;
598+
math::float3 curvesShadowGamma{1.0f, 1.0f, 1.0f};
599+
math::float3 curvesMidPoint{1.0f, 1.0f, 1.0f};
600+
math::float3 curvesHighlightScale{1.0f, 1.0f, 1.0f};
601+
color::ColorSpace colorSpace = color::Rec709 - color::sRGB - color::D65;
602+
};
603+
Settings mSettings;
604+
491605
// prevent heap allocation
492606
~ColorGrading() = default;
493607
};

filament/include/filament/ToneMapper.h

+26-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ namespace filament {
5454
struct UTILS_PUBLIC ToneMapper {
5555
ToneMapper() noexcept;
5656
virtual ~ToneMapper() noexcept;
57+
ToneMapper(ToneMapper const&) noexcept;
58+
ToneMapper& operator=(ToneMapper const&) noexcept = default;
5759

5860
/**
5961
* Maps an open domain (or "scene referred" values) color value to display
@@ -69,6 +71,13 @@ struct UTILS_PUBLIC ToneMapper {
6971
*/
7072
virtual math::float3 operator()(math::float3 c) const noexcept = 0;
7173

74+
/**
75+
* Creates a copy of this tone mapper instance.
76+
*
77+
* @return A pointer to a new ToneMapper instance that is a copy of this instance.
78+
*/
79+
virtual ToneMapper* clone() const noexcept = 0;
80+
7281
/**
7382
* If true, then this function holds that f(x) = vec3(f(x.r), f(x.g), f(x.b))
7483
*
@@ -92,8 +101,10 @@ struct UTILS_PUBLIC ToneMapper {
92101
struct UTILS_PUBLIC LinearToneMapper final : public ToneMapper {
93102
LinearToneMapper() noexcept;
94103
~LinearToneMapper() noexcept final;
104+
LinearToneMapper(LinearToneMapper const&) noexcept;
95105

96106
math::float3 operator()(math::float3 c) const noexcept override;
107+
LinearToneMapper* clone() const noexcept override;
97108
bool isOneDimensional() const noexcept override { return true; }
98109
bool isLDR() const noexcept override { return true; }
99110
};
@@ -106,8 +117,10 @@ struct UTILS_PUBLIC LinearToneMapper final : public ToneMapper {
106117
struct UTILS_PUBLIC ACESToneMapper final : public ToneMapper {
107118
ACESToneMapper() noexcept;
108119
~ACESToneMapper() noexcept final;
120+
ACESToneMapper(ACESToneMapper const&) noexcept;
109121

110122
math::float3 operator()(math::float3 c) const noexcept override;
123+
ACESToneMapper* clone() const noexcept override;
111124
bool isOneDimensional() const noexcept override { return false; }
112125
bool isLDR() const noexcept override { return false; }
113126
};
@@ -121,8 +134,10 @@ struct UTILS_PUBLIC ACESToneMapper final : public ToneMapper {
121134
struct UTILS_PUBLIC ACESLegacyToneMapper final : public ToneMapper {
122135
ACESLegacyToneMapper() noexcept;
123136
~ACESLegacyToneMapper() noexcept final;
137+
ACESLegacyToneMapper(ACESLegacyToneMapper const&) noexcept;
124138

125139
math::float3 operator()(math::float3 c) const noexcept override;
140+
ACESLegacyToneMapper* clone() const noexcept override;
126141
bool isOneDimensional() const noexcept override { return false; }
127142
bool isLDR() const noexcept override { return false; }
128143
};
@@ -136,8 +151,10 @@ struct UTILS_PUBLIC ACESLegacyToneMapper final : public ToneMapper {
136151
struct UTILS_PUBLIC FilmicToneMapper final : public ToneMapper {
137152
FilmicToneMapper() noexcept;
138153
~FilmicToneMapper() noexcept final;
154+
FilmicToneMapper(FilmicToneMapper const&) noexcept;
139155

140156
math::float3 operator()(math::float3 x) const noexcept override;
157+
FilmicToneMapper* clone() const noexcept override;
141158
bool isOneDimensional() const noexcept override { return true; }
142159
bool isLDR() const noexcept override { return false; }
143160
};
@@ -150,8 +167,10 @@ struct UTILS_PUBLIC FilmicToneMapper final : public ToneMapper {
150167
struct UTILS_PUBLIC PBRNeutralToneMapper final : public ToneMapper {
151168
PBRNeutralToneMapper() noexcept;
152169
~PBRNeutralToneMapper() noexcept final;
170+
PBRNeutralToneMapper(PBRNeutralToneMapper const&) noexcept;
153171

154172
math::float3 operator()(math::float3 x) const noexcept override;
173+
virtual PBRNeutralToneMapper* clone() const noexcept override;
155174
bool isOneDimensional() const noexcept override { return false; }
156175
bool isLDR() const noexcept override { return false; }
157176
};
@@ -173,8 +192,10 @@ struct UTILS_PUBLIC AgxToneMapper final : public ToneMapper {
173192
*/
174193
explicit AgxToneMapper(AgxLook look = AgxLook::NONE) noexcept;
175194
~AgxToneMapper() noexcept final;
195+
AgxToneMapper(AgxToneMapper const&) noexcept;
176196

177197
math::float3 operator()(math::float3 x) const noexcept override;
198+
virtual AgxToneMapper* clone() const noexcept override;
178199
bool isOneDimensional() const noexcept override { return false; }
179200
bool isLDR() const noexcept override { return false; }
180201

@@ -215,12 +236,13 @@ struct UTILS_PUBLIC GenericToneMapper final : public ToneMapper {
215236
) noexcept;
216237
~GenericToneMapper() noexcept final;
217238

218-
GenericToneMapper(GenericToneMapper const&) = delete;
219-
GenericToneMapper& operator=(GenericToneMapper const&) = delete;
239+
GenericToneMapper(GenericToneMapper const& rhs) noexcept;
240+
GenericToneMapper& operator=(GenericToneMapper const& rhs) noexcept;
220241
GenericToneMapper(GenericToneMapper&& rhs) noexcept;
221242
GenericToneMapper& operator=(GenericToneMapper&& rhs) noexcept;
222243

223244
math::float3 operator()(math::float3 x) const noexcept override;
245+
GenericToneMapper* clone() const noexcept override;
224246
bool isOneDimensional() const noexcept override { return true; }
225247
bool isLDR() const noexcept override { return false; }
226248

@@ -283,8 +305,10 @@ struct UTILS_PUBLIC GenericToneMapper final : public ToneMapper {
283305
struct UTILS_PUBLIC DisplayRangeToneMapper final : public ToneMapper {
284306
DisplayRangeToneMapper() noexcept;
285307
~DisplayRangeToneMapper() noexcept override;
308+
DisplayRangeToneMapper(DisplayRangeToneMapper const&) noexcept;
286309

287310
math::float3 operator()(math::float3 c) const noexcept override;
311+
DisplayRangeToneMapper* clone() const noexcept override;
288312
bool isOneDimensional() const noexcept override { return false; }
289313
bool isLDR() const noexcept override { return false; }
290314
};

0 commit comments

Comments
 (0)