@woosh/meep-engine 3.65.0 → 3.67.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/format/lut/cube/CubeLut.d.ts +38 -0
- package/src/format/lut/cube/CubeLut.d.ts.map +1 -0
- package/src/format/lut/cube/CubeLut.js +23 -0
- package/src/format/lut/cube/cube_read.d.ts +23 -0
- package/src/format/lut/cube/cube_read.d.ts.map +1 -0
- package/src/format/lut/cube/cube_read.js +199 -0
- package/src/format/lut/cube/cube_write.d.ts +15 -0
- package/src/format/lut/cube/cube_write.d.ts.map +1 -0
- package/src/format/lut/cube/cube_write.js +90 -0
- package/src/shade/playground/probe_clipmap/README.md +1 -0
- package/src/shade/playground/probe_clipmap/index.html +5 -0
- package/src/shade/playground/probe_clipmap/main.d.ts.map +1 -1
- package/src/shade/playground/probe_clipmap/main.js +7 -0
- package/src/shade/renderer/Renderer.js +12 -12
- package/src/shade/renderer/deferred/tonemap/ColorGrade.d.ts +73 -4
- package/src/shade/renderer/deferred/tonemap/ColorGrade.d.ts.map +1 -1
- package/src/shade/renderer/deferred/tonemap/ColorGrade.js +113 -7
- package/src/shade/renderer/deferred/tonemap/TONEMAP_PURKINJE_SHIFT.d.ts +12 -0
- package/src/shade/renderer/deferred/tonemap/TONEMAP_PURKINJE_SHIFT.d.ts.map +1 -0
- package/src/shade/renderer/deferred/tonemap/TONEMAP_PURKINJE_SHIFT.js +12 -0
- package/src/shade/renderer/deferred/tonemap/ToneMapper.d.ts +15 -1
- package/src/shade/renderer/deferred/tonemap/ToneMapper.d.ts.map +1 -1
- package/src/shade/renderer/deferred/tonemap/ToneMapper.js +31 -3
- package/src/shade/renderer/deferred/tonemap/chunk_tonemap_purkinje.d.ts +25 -0
- package/src/shade/renderer/deferred/tonemap/chunk_tonemap_purkinje.d.ts.map +1 -0
- package/src/shade/renderer/deferred/tonemap/chunk_tonemap_purkinje.js +51 -0
- package/src/shade/renderer/deferred/tonemap/shader_tonemap_HDR_lut.d.ts +2 -2
- package/src/shade/renderer/deferred/tonemap/shader_tonemap_HDR_lut.d.ts.map +1 -1
- package/src/shade/renderer/deferred/tonemap/shader_tonemap_HDR_lut.js +6 -3
- package/src/shade/renderer/deferred/tonemap/shader_tonemap_LDR_lut.d.ts +3 -2
- package/src/shade/renderer/deferred/tonemap/shader_tonemap_LDR_lut.d.ts.map +1 -1
- package/src/shade/renderer/deferred/tonemap/shader_tonemap_LDR_lut.js +7 -3
- package/src/shade/renderer/postprocess/eye/GPUCameraExposureManager.d.ts +35 -9
- package/src/shade/renderer/postprocess/eye/GPUCameraExposureManager.d.ts.map +1 -1
- package/src/shade/renderer/postprocess/eye/GPUCameraExposureManager.js +81 -11
- package/src/shade/renderer/postprocess/eye/shader_autoexposure_adapt.d.ts.map +1 -1
- package/src/shade/renderer/postprocess/eye/shader_autoexposure_adapt.js +4 -1
- package/src/shade/renderer/shader/chunk/color/conversion/chunk_CRM_REC709_AP1.d.ts +6 -0
- package/src/shade/renderer/shader/chunk/color/conversion/chunk_CRM_REC709_AP1.d.ts.map +1 -1
- package/src/shade/renderer/shader/chunk/color/conversion/chunk_CRM_REC709_AP1.js +7 -0
- package/src/shade/renderer/shader/chunk/color/grade/chunk_color_grade.d.ts +4 -4
- package/src/shade/renderer/shader/chunk/color/grade/chunk_color_grade.d.ts.map +1 -1
- package/src/shade/renderer/shader/chunk/color/grade/chunk_color_grade.js +86 -5
- package/src/shade/renderer/shader/chunk/color/tonemap/purkinje/chunk_apply_purkinje_shift.d.ts +65 -0
- package/src/shade/renderer/shader/chunk/color/tonemap/purkinje/chunk_apply_purkinje_shift.d.ts.map +1 -0
- package/src/shade/renderer/shader/chunk/color/tonemap/purkinje/chunk_apply_purkinje_shift.js +136 -0
- package/src/shade/renderer/shader/chunk/color/tonemap/purkinjie/chunk_apply_purkinjie_shift.d.ts +0 -11
- package/src/shade/renderer/shader/chunk/color/tonemap/purkinjie/chunk_apply_purkinjie_shift.d.ts.map +0 -1
- package/src/shade/renderer/shader/chunk/color/tonemap/purkinjie/chunk_apply_purkinjie_shift.js +0 -56
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { CodeChunk } from "../../../../compiler/CodeChunk.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Rec.709 photopic luminance weights: what the cones see of a linear Rec.709 colour.
|
|
5
|
+
* @type {ReadonlyArray<number>}
|
|
6
|
+
*/
|
|
7
|
+
export const PURKINJE_REC709_PHOTOPIC = Object.freeze([0.2126, 0.7152, 0.0722]);
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Rec.709 scotopic luminance weights: what the rods see of a linear Rec.709 colour. They sum to 1, so a grey has the
|
|
11
|
+
* same scotopic luminance as photopic.
|
|
12
|
+
* @type {ReadonlyArray<number>}
|
|
13
|
+
*/
|
|
14
|
+
export const PURKINJE_REC709_SCOTOPIC = Object.freeze([0.0070, 0.5190, 0.4740]);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* "Rod blue": the colour the scotopic signal is carried by. Artistic: (0.3, 0.5, 0.9) mimics the sensation of the
|
|
18
|
+
* rods' 507 nm peak.
|
|
19
|
+
* @type {ReadonlyArray<number>}
|
|
20
|
+
*/
|
|
21
|
+
export const PURKINJE_NIGHT_TINT = Object.freeze([0.3, 0.5, 0.9]);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* CIE 191's mesopic range, cd/m²: rods alone below the lower bound (scotopic), cones alone above the upper (photopic).
|
|
25
|
+
*/
|
|
26
|
+
export const PURKINJE_MESOPIC_MIN_NITS = 0.005;
|
|
27
|
+
export const PURKINJE_MESOPIC_MAX_NITS = 5;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The least adaptation the share is read at, cd/m²: under it, the rods alone see, as they do at the bound itself.
|
|
31
|
+
*/
|
|
32
|
+
const ADAPTATION_FLOOR_NITS = 1e-5;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* How much of the eye's response is the rods', at an adaptation: 1 at and below {@link PURKINJE_MESOPIC_MIN_NITS}, 0 at
|
|
36
|
+
* and above {@link PURKINJE_MESOPIC_MAX_NITS}, linear in log luminance in between. The share `apply_purkinje_shift`
|
|
37
|
+
* blends by, for code that needs it on the CPU.
|
|
38
|
+
*
|
|
39
|
+
* @param {number} adaptation_luminance cd/m²
|
|
40
|
+
* @returns {number} 0 to 1
|
|
41
|
+
*/
|
|
42
|
+
export function purkinje_rod_share(adaptation_luminance) {
|
|
43
|
+
const low = Math.log(PURKINJE_MESOPIC_MIN_NITS);
|
|
44
|
+
const high = Math.log(PURKINJE_MESOPIC_MAX_NITS);
|
|
45
|
+
const t = (Math.log(Math.max(adaptation_luminance, ADAPTATION_FLOOR_NITS)) - low) / (high - low);
|
|
46
|
+
|
|
47
|
+
return 1 - Math.min(1, Math.max(0, t));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @param {number} value
|
|
52
|
+
* @returns {string} as a WGSL float literal, with a point
|
|
53
|
+
*/
|
|
54
|
+
function wgsl_float(value) {
|
|
55
|
+
const text = String(value);
|
|
56
|
+
return /[.e]/.test(text) ? text : `${text}.0`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @param {ReadonlyArray<number>} v
|
|
61
|
+
* @returns {string}
|
|
62
|
+
*/
|
|
63
|
+
function wgsl_vec3(v) {
|
|
64
|
+
return `vec3<f32>(${v.map(wgsl_float).join(", ")})`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Purkinje shift.
|
|
69
|
+
* Human vision system shifts color perception away from red in night-time conditions.
|
|
70
|
+
*
|
|
71
|
+
* ```wgsl
|
|
72
|
+
* fn apply_purkinje_shift(color_rec709: vec3<f32>, adaptation_luminance: f32) -> vec3<f32>
|
|
73
|
+
* fn purkinje_rod_share(adaptation_luminance: f32) -> f32
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* `color_rec709` is scene-linear Rec.709; `adaptation_luminance` is the luminance the eye is adapted to, cd/m². Above
|
|
77
|
+
* 5 cd/m² the colour is returned as it is; below 0.005 cd/m² it is the rod response alone, its scotopic luminance
|
|
78
|
+
* carried by a blue tint; in between the two blend linearly in log luminance, by `purkinje_rod_share`. The shift is
|
|
79
|
+
* linear in the colour, so it gives the same result ahead of the exposure as after it.
|
|
80
|
+
*
|
|
81
|
+
* The constants are the module's exports ({@link PURKINJE_REC709_SCOTOPIC} and the rest), and
|
|
82
|
+
* {@link purkinje_rod_share} is the share on the CPU.
|
|
83
|
+
*
|
|
84
|
+
* NOTE: this should go before the tonemapper.
|
|
85
|
+
*
|
|
86
|
+
* Notes on deriving it from the rod and cone responses: PURKINJE_PHYSICAL_DERIVATION_NOTES.md, beside this file.
|
|
87
|
+
*
|
|
88
|
+
* @see J. Patry, "Real-Time Samurai Cinema: Lighting, Atmosphere, and Tonemapping in Ghost of Tsushima", Advances in
|
|
89
|
+
* Real-Time Rendering in Games, SIGGRAPH 2021 — the primary reference.
|
|
90
|
+
* https://www.advances.realtimerendering.com/s2021/jpatry_advances2021/index.html
|
|
91
|
+
* @see A. G. Kirk, J. F. O'Brien, "Perceptually based tone mapping for low-light conditions", ACM TOG 30(4), 2011.
|
|
92
|
+
* https://www2.eecs.berkeley.edu/Pubs/TechRpts/2011/EECS-2011-91.pdf
|
|
93
|
+
* @see D. Cao, J. Pokorny, V. C. Smith, A. J. Zele, "Rod contributions to color perception: linear with rod
|
|
94
|
+
* contrast", Vision Research 48(26), 2008.
|
|
95
|
+
*
|
|
96
|
+
* @type {CodeChunk}
|
|
97
|
+
*/
|
|
98
|
+
export const chunk_apply_purkinje_shift = CodeChunk.from(
|
|
99
|
+
//language=WGSL
|
|
100
|
+
`
|
|
101
|
+
const PURKINJE_REC709_PHOTOPIC = ${wgsl_vec3(PURKINJE_REC709_PHOTOPIC)}; // Day (Cones)
|
|
102
|
+
const PURKINJE_REC709_SCOTOPIC = ${wgsl_vec3(PURKINJE_REC709_SCOTOPIC)}; // Night (Rods) - Validated
|
|
103
|
+
const PURKINJE_NIGHT_TINT = ${wgsl_vec3(PURKINJE_NIGHT_TINT)};
|
|
104
|
+
const PURKINJE_MESOPIC_MIN_NITS = ${wgsl_float(PURKINJE_MESOPIC_MIN_NITS)}; // Rods dominate below this
|
|
105
|
+
const PURKINJE_MESOPIC_MAX_NITS = ${wgsl_float(PURKINJE_MESOPIC_MAX_NITS)}; // Cones dominate above this
|
|
106
|
+
|
|
107
|
+
// how much of the response is the rods', linear in log luminance across the mesopic range: a perceptually linear
|
|
108
|
+
// transition
|
|
109
|
+
fn purkinje_rod_share(adaptation_luminance: f32) -> f32 {
|
|
110
|
+
let logLum = log(max(adaptation_luminance, ${wgsl_float(ADAPTATION_FLOOR_NITS)}));
|
|
111
|
+
|
|
112
|
+
const logLow = log(PURKINJE_MESOPIC_MIN_NITS);
|
|
113
|
+
const logHigh = log(PURKINJE_MESOPIC_MAX_NITS);
|
|
114
|
+
const logDelta = logHigh - logLow;
|
|
115
|
+
|
|
116
|
+
return 1.0 - saturate( (logLum - logLow) / logDelta );
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
fn apply_purkinje_shift(
|
|
120
|
+
color_rec709: vec3<f32>,
|
|
121
|
+
adaptation_luminance: f32
|
|
122
|
+
) -> vec3<f32>{
|
|
123
|
+
// 1. Calculate Rod Luminance (Night)
|
|
124
|
+
// Note: Red objects will have a near-zero Y_night, making them turn black.
|
|
125
|
+
// Blue objects will have a high Y_night, making them appear brighter.
|
|
126
|
+
let Y_night = dot(color_rec709, PURKINJE_REC709_SCOTOPIC);
|
|
127
|
+
|
|
128
|
+
// 2. Construct the Night Vision Image
|
|
129
|
+
// We treat the rod signal as a scalar intensity applied to our blue tint
|
|
130
|
+
let color_night = Y_night * PURKINJE_NIGHT_TINT;
|
|
131
|
+
|
|
132
|
+
// 3. Lerp from Day view to Night view, by the rods' share at the adaptation
|
|
133
|
+
return mix(color_rec709, color_night, purkinje_rod_share(adaptation_luminance));
|
|
134
|
+
}
|
|
135
|
+
`
|
|
136
|
+
);
|
package/src/shade/renderer/shader/chunk/color/tonemap/purkinjie/chunk_apply_purkinjie_shift.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Purkinjie shift.
|
|
3
|
-
* Human vision system shifts color perception away from red in nigh-time conditions.
|
|
4
|
-
*
|
|
5
|
-
* NOTE: this should go before the tonemapper.
|
|
6
|
-
*
|
|
7
|
-
* @type {CodeChunk}
|
|
8
|
-
*/
|
|
9
|
-
export const chunk_apply_purkinjie_shift: CodeChunk;
|
|
10
|
-
import { CodeChunk } from "../../../../compiler/CodeChunk.js";
|
|
11
|
-
//# sourceMappingURL=chunk_apply_purkinjie_shift.d.ts.map
|
package/src/shade/renderer/shader/chunk/color/tonemap/purkinjie/chunk_apply_purkinjie_shift.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chunk_apply_purkinjie_shift.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/shade/renderer/shader/chunk/color/tonemap/purkinjie/chunk_apply_purkinjie_shift.js"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,0CAFU,SAAS,CA+ClB;0BAvDyB,mCAAmC"}
|
package/src/shade/renderer/shader/chunk/color/tonemap/purkinjie/chunk_apply_purkinjie_shift.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { CodeChunk } from "../../../../compiler/CodeChunk.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Purkinjie shift.
|
|
5
|
-
* Human vision system shifts color perception away from red in nigh-time conditions.
|
|
6
|
-
*
|
|
7
|
-
* NOTE: this should go before the tonemapper.
|
|
8
|
-
*
|
|
9
|
-
* @type {CodeChunk}
|
|
10
|
-
*/
|
|
11
|
-
export const chunk_apply_purkinjie_shift = CodeChunk.from(
|
|
12
|
-
//language=WGSL
|
|
13
|
-
`
|
|
14
|
-
fn apply_purkinjie_shift(
|
|
15
|
-
color_rec709: vec3<f32>,
|
|
16
|
-
adaptation_luminance: f32
|
|
17
|
-
) -> vec3<f32>{
|
|
18
|
-
// --- Constants for Rec.709 / sRGB ---
|
|
19
|
-
const kRec709Photopic = vec3(0.2126, 0.7152, 0.0722); // Day (Cones)
|
|
20
|
-
const kRec709Scotopic = vec3(0.0070, 0.5190, 0.4740); // Night (Rods) - Validated
|
|
21
|
-
|
|
22
|
-
// "Rod Blue" - The color we tint the scotopic signal towards
|
|
23
|
-
// This is artistic, but (0.3, 0.5, 0.9) mimics the 507nm peak sensation
|
|
24
|
-
const kNightTint = vec3(0.3, 0.5, 0.9);
|
|
25
|
-
|
|
26
|
-
// 1. Calculate Standard Luminance (Day)
|
|
27
|
-
let Y_day = dot(color_rec709, kRec709Photopic);
|
|
28
|
-
|
|
29
|
-
// 2. Calculate Rod Luminance (Night)
|
|
30
|
-
// Note: Red objects will have a near-zero Y_night, making them turn black.
|
|
31
|
-
// Blue objects will have a high Y_night, making them appear brighter.
|
|
32
|
-
let Y_night = dot(color_rec709, kRec709Scotopic);
|
|
33
|
-
|
|
34
|
-
// 3. Construct the Night Vision Image
|
|
35
|
-
// We treat the rod signal as a scalar intensity applied to our blue tint
|
|
36
|
-
let color_night = Y_night * kNightTint;
|
|
37
|
-
|
|
38
|
-
// 4. Blend based on Adaptation
|
|
39
|
-
const MESOPIC_MIN_NITS = 0.005; // Rods dominate below this
|
|
40
|
-
const MESOPIC_MAX_NITS = 5.0; // Cones dominate above this
|
|
41
|
-
|
|
42
|
-
let logLum = log(max(adaptation_luminance, 1e-5));
|
|
43
|
-
|
|
44
|
-
const logLow = log(MESOPIC_MIN_NITS);
|
|
45
|
-
const logHigh = log(MESOPIC_MAX_NITS);
|
|
46
|
-
const logDelta = logHigh - logLow;
|
|
47
|
-
|
|
48
|
-
// 2. Calculate Blend Factor in Log Space
|
|
49
|
-
// This creates a perceptually linear transition
|
|
50
|
-
let t = 1.0 - saturate( (logLum - logLow) / logDelta );
|
|
51
|
-
|
|
52
|
-
// Lerp from Day view to Night view
|
|
53
|
-
return mix(color_rec709, color_night, t);
|
|
54
|
-
}
|
|
55
|
-
`
|
|
56
|
-
)
|