Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qssgcputonemapper_p.h
Go to the documentation of this file.
1// Copyright (C) 2008-2012 NVIDIA Corporation.
2// Copyright (C) 2022 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
4// Qt-Security score:significant reason:default
5
6
7#ifndef QSSGCPUTONEMAPPER_P_H
8#define QSSGCPUTONEMAPPER_P_H
9
10//
11// W A R N I N G
12// -------------
13//
14// This file is not part of the Qt API. It exists purely as an
15// implementation detail. This header file may change from version to
16// version without notice, or even be removed.
17//
18// We mean it.
19//
20
21#include <QtGui/qvector3d.h>
22
23QT_BEGIN_NAMESPACE
24
25namespace QSSGTonemapper {
26
27inline QVector3D vsqrt(const QVector3D &a)
28{
29 return QVector3D(std::sqrt(a.x()), std::sqrt(a.y()), std::sqrt(a.z()));
30}
31
32inline QVector3D vmax(const QVector3D &a, const QVector3D &b)
33{
34 return QVector3D(std::max(a.x(), b.x()), std::max(a.y(), b.y()), std::max(a.z(), b.z()));
35}
36
37inline QVector3D vclamp(const QVector3D &a, float b, float c)
38{
39 return QVector3D(qBound(b, a.x(), c), qBound(b, a.y(), c), qBound(b, a.z(), c));
40}
41
42inline QVector3D vadd(const QVector3D &a, float b)
43{
44 return QVector3D(a.x() + b, a.y() + b, a.z() + b);
45}
46
47template<typename mType>
48inline QVector3D mad(mType m, const QVector3D &a, float b)
49{
50 return vadd(m * a, b);
51}
52
53// all the implementation here is expected to match tonemapper.glsllib
54
55inline QVector3D tonemapLinearToSrgb(const QVector3D &c)
56{
57 const QVector3D S1 = vsqrt(c);
58 const QVector3D S2 = vsqrt(S1);
59 const QVector3D S3 = vsqrt(S2);
60 return 0.58512238f * S1 + 0.78314035f * S2 - 0.36826273f * S3;
61}
62
63inline QVector3D tonemapHejlDawson(const QVector3D &c)
64{
65 const QVector3D cc = vmax(QVector3D(0.0f, 0.0f, 0.0f), vadd(c, -0.004f));
66 return (cc * mad(6.2f, cc, 0.5f)) / vadd(cc * mad(6.2f, cc, 1.7f), 0.06f);
67}
68
69inline QVector3D tonemapAces(const QVector3D &c)
70{
71 const float A = 2.51f;
72 const float B = 0.03f;
73 const float C = 2.43f;
74 const float D = 0.59f;
75 const float E = 0.14f;
76 return tonemapLinearToSrgb(vclamp((c * mad(A, c, B)) / vadd(c * mad(C, c, D), E), 0.0f, 1.0f));
77}
78
79inline QVector3D tonemapFilmicSub(const QVector3D &c)
80{
81 const float A = 0.15f;
82 const float B = 0.50f;
83 const float C = 0.10f;
84 const float D = 0.20f;
85 const float E = 0.02f;
86 const float F = 0.30f;
87 return vadd(vadd(c * mad(A, c, C * B), D * E) / vadd(c * mad(A, c, B), D * F), -E / F);
88}
89
90inline QVector3D tonemapFilmic(const QVector3D &c)
91{
92 static const QVector3D whiteScale = QVector3D(1.0f, 1.0f, 1.0f) / tonemapFilmicSub(QVector3D(11.2f, 11.2f, 11.2f));
93 return tonemapLinearToSrgb(tonemapFilmicSub(c * 2.0f) * whiteScale);
94}
95
96} // namespace QSSGTonemapper
97
98QT_END_NAMESPACE
99
100#endif
QVector3D vclamp(const QVector3D &a, float b, float c)
QVector3D vadd(const QVector3D &a, float b)
QVector3D tonemapFilmicSub(const QVector3D &c)
QVector3D vmax(const QVector3D &a, const QVector3D &b)
QVector3D mad(mType m, const QVector3D &a, float b)
QVector3D tonemapFilmic(const QVector3D &c)
QVector3D tonemapHejlDawson(const QVector3D &c)
QVector3D tonemapAces(const QVector3D &c)
QVector3D tonemapLinearToSrgb(const QVector3D &c)
QVector3D vsqrt(const QVector3D &a)