Skip to content

Commit 5f7a741

Browse files
committed
Add tonemapper that hashes to a random color
1 parent 2c7e709 commit 5f7a741

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

include/tev/Common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ enum ETonemap : int {
373373
Gamma,
374374
FalseColor,
375375
PositiveNegative,
376+
Hash,
376377

377378
// This enum value should never be used directly.
378379
// It facilitates looping over all members of this enum.

src/Common.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ ETonemap toTonemap(string name) {
232232
return FalseColor;
233233
} else if (name == "POSITIVENEGATIVE" || name == "POSNEG" || name == "PN" ||name == "+-") {
234234
return PositiveNegative;
235+
} else if (name == "HASH") {
236+
return Hash;
235237
} else {
236238
return SRGB;
237239
}

src/ImageViewer.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ using namespace std;
2525

2626
namespace tev {
2727

28-
static const int SIDEBAR_MIN_WIDTH = 230;
28+
static const int SIDEBAR_MIN_WIDTH = 245;
2929
static const float CROP_MIN_SIZE = 3;
3030

3131
ImageViewer::ImageViewer(
@@ -214,7 +214,7 @@ ImageViewer::ImageViewer(
214214
// Tonemap options
215215
{
216216
mTonemapButtonContainer = new Widget{mSidebarLayout};
217-
mTonemapButtonContainer->set_layout(new GridLayout{Orientation::Horizontal, 4, Alignment::Fill, 5, 2});
217+
mTonemapButtonContainer->set_layout(new GridLayout{Orientation::Horizontal, 5, Alignment::Fill, 5, 2});
218218

219219
auto makeTonemapButton = [&](const string& name, function<void()> callback) {
220220
auto button = new Button{mTonemapButtonContainer, name};
@@ -228,6 +228,7 @@ ImageViewer::ImageViewer(
228228
makeTonemapButton("Gamma", [this]() { setTonemap(ETonemap::Gamma); });
229229
makeTonemapButton("FC", [this]() { setTonemap(ETonemap::FalseColor); });
230230
makeTonemapButton("+/-", [this]() { setTonemap(ETonemap::PositiveNegative); });
231+
makeTonemapButton("Hash", [this]() { setTonemap(ETonemap::Hash); });
231232

232233
setTonemap(ETonemap::SRGB);
233234

@@ -244,7 +245,10 @@ ImageViewer::ImageViewer(
244245
"False-color visualization\n\n"
245246

246247
"+/-\n"
247-
"Positive=Green, Negative=Red"
248+
"Positive=Green, Negative=Red\n\n"
249+
250+
"Hash\n"
251+
"Hash values to random colors"
248252
);
249253
}
250254

src/UberShader.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ UberShader::UberShader(RenderPass* renderPass) {
5151
#define GAMMA 1
5252
#define FALSE_COLOR 2
5353
#define POS_NEG 3
54+
#define HASH 4
5455
5556
#define ERROR 0
5657
#define ABSOLUTE_ERROR 1
@@ -117,6 +118,10 @@ UberShader::UberShader(RenderPass* renderPass) {
117118
}
118119
}
119120
121+
vec3 hash(vec3 co){
122+
return fract(cos(dot(co.xyz, vec3(61.5499458, -40.7123604, 34.8567848))) * vec3(-41882.2148, 62285.1367, 38605.582));
123+
}
124+
120125
vec3 applyTonemap(vec3 col, vec4 background) {
121126
if (tonemap == SRGB) {
122127
col = col +
@@ -129,6 +134,8 @@ UberShader::UberShader(RenderPass* renderPass) {
129134
return falseColor(log2(average(col)+0.03125) / 10.0 + 0.5) + (background.rgb - falseColor(0.0)) * background.a;
130135
} else if (tonemap == POS_NEG) {
131136
return vec3(-average(min(col, vec3(0.0))) * 2.0, average(max(col, vec3(0.0))) * 2.0, 0.0) + background.rgb * background.a;
137+
} else if (tonemap == HASH) {
138+
return hash(col) + (background.rgb - hash(vec3(offset))) * background.a;
132139
}
133140
return vec3(0.0);
134141
}
@@ -230,6 +237,7 @@ UberShader::UberShader(RenderPass* renderPass) {
230237
#define GAMMA 1
231238
#define FALSE_COLOR 2
232239
#define POS_NEG 3
240+
#define HASH 4
233241
234242
#define ERROR 0
235243
#define ABSOLUTE_ERROR 1
@@ -272,6 +280,10 @@ UberShader::UberShader(RenderPass* renderPass) {
272280
}
273281
}
274282
283+
float3 hash(float3 co){
284+
return fract(cos(dot(co.xyz, float3(61.5499458f, -40.7123604f, 34.8567848f))) * float3(-41882.2148f, 62285.1367f, 38605.582f));
285+
}
286+
275287
float3 applyTonemap(float3 col, float4 background, int tonemap, float offset, float gamma, texture2d<float, access::sample> colormap, sampler colormapSampler) {
276288
switch (tonemap) {
277289
case SRGB:
@@ -286,6 +298,8 @@ UberShader::UberShader(RenderPass* renderPass) {
286298
return falseColor(log2(average(col)+0.03125f) / 10.0f + 0.5f, colormap, colormapSampler) + (background.rgb - falseColor(0.0f, colormap, colormapSampler)) * background.a;
287299
case POS_NEG:
288300
return float3(-average(min(col, float3(0.0f))) * 2.0f, average(max(col, float3(0.0f))) * 2.0f, 0.0f) + background.rgb * background.a;
301+
case HASH:
302+
return hash(col) + (background.rgb - hash(float3(offset))) * background.a;
289303
}
290304
return float3(0.0f);
291305
}

0 commit comments

Comments
 (0)