Browse Source

WebGLRenderer: Try DFG LUT instead of Analytical approximation. (#32054)

* WebGLRenderer: Try DFG LUT instead of Analytical approximation.

* Potential fix for code scanning alert no. 3676: Unused variable, import, function or class

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>

* Potential fix for code scanning alert no. 3677: Unused variable, import, function or class

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>

* Clean up.

* Fix shader issue.

* Replaced Schlick approximation with Smith GGX Correlated visibility.

* Generate 16x16 DFG LUT

* Revert cubeUV change.

* Clean up.

* Updated screenshots.

* Generate 32x32 RG16F DFG LUT.

---------

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
mrdoob 2 months ago
parent
commit
bd3fe1f750

File diff suppressed because it is too large
+ 0 - 0
build/three.cjs


File diff suppressed because it is too large
+ 0 - 0
build/three.module.js


File diff suppressed because it is too large
+ 0 - 0
build/three.module.min.js


BIN
examples/screenshots/webgl_animation_walk.jpg


BIN
examples/screenshots/webgl_loader_gltf_compressed.jpg


BIN
examples/screenshots/webgl_materials_cubemap_dynamic.jpg


BIN
examples/screenshots/webgl_pmrem_test.jpg


+ 8 - 0
src/renderers/WebGLRenderer.js

@@ -54,6 +54,7 @@ import { WebGLMaterials } from './webgl/WebGLMaterials.js';
 import { WebGLUniformsGroups } from './webgl/WebGLUniformsGroups.js';
 import { createCanvasElement, probeAsync, warnOnce, error, warn, log } from '../utils.js';
 import { ColorManagement } from '../math/ColorManagement.js';
+import { getDFGLUT } from './shaders/DFGLUTData.js';
 
 /**
  * This renderer uses WebGL 2 to display scenes.
@@ -2511,6 +2512,13 @@ class WebGLRenderer {
 
 			}
 
+			// Set DFG LUT for physically-based materials
+			if ( m_uniforms.dfgLUT !== undefined ) {
+
+				m_uniforms.dfgLUT.value = getDFGLUT();
+
+			}
+
 			if ( refreshMaterial ) {
 
 				p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );

+ 66 - 0
src/renderers/shaders/DFGLUTData.js

@@ -0,0 +1,66 @@
+/**
+ * Precomputed DFG LUT for Image-Based Lighting
+ * Resolution: 32x32
+ * Samples: 1024 per texel
+ * Format: RG16F (2 half floats per texel: scale, bias)
+ */
+
+import { DataTexture } from '../../textures/DataTexture.js';
+import { RGFormat, HalfFloatType, LinearFilter, ClampToEdgeWrapping } from '../../constants.js';
+
+export const DFG_LUT_SIZE = 32;
+
+const DFG_LUT_DATA = new Uint16Array( [
+	0x2cd9, 0x3b64, 0x2d02, 0x3b40, 0x2deb, 0x3aa4, 0x3022, 0x39f8, 0x31fa, 0x397a, 0x3414, 0x3907, 0x3533, 0x3892, 0x3648, 0x381c, 0x3748, 0x3757, 0x3819, 0x3686, 0x3882, 0x35c7, 0x38df, 0x351a, 0x3931, 0x3481, 0x3978, 0x33f2, 0x39b7, 0x3303, 0x39ed, 0x3233, 0x3a1c, 0x317d, 0x3a45, 0x30df, 0x3a67, 0x3055, 0x3a84, 0x2fbc, 0x3a9d, 0x2eed, 0x3ab2, 0x2e3a, 0x3ac4, 0x2d9f, 0x3ad3, 0x2d18, 0x3adf, 0x2ca3, 0x3ae8, 0x2c3d, 0x3af0, 0x2bc8, 0x3af6, 0x2b2c, 0x3afb, 0x2aa4, 0x3afe, 0x2a2d, 0x3b01, 0x29c3, 0x3b02, 0x2967,
+	0x32d4, 0x3a4b, 0x32da, 0x3a46, 0x32fd, 0x3a25, 0x335f, 0x39d0, 0x340f, 0x394b, 0x34a9, 0x38be, 0x3572, 0x383d, 0x3655, 0x3793, 0x373e, 0x36c1, 0x380f, 0x3600, 0x3876, 0x3550, 0x38d3, 0x34b0, 0x3926, 0x3422, 0x396e, 0x3347, 0x39ad, 0x3268, 0x39e3, 0x31a6, 0x3a11, 0x30fc, 0x3a37, 0x3069, 0x3a57, 0x2fd0, 0x3a71, 0x2ef1, 0x3a86, 0x2e30, 0x3a97, 0x2d88, 0x3aa3, 0x2cf7, 0x3aac, 0x2c78, 0x3ab2, 0x2c0a, 0x3ab5, 0x2b52, 0x3ab5, 0x2aa9, 0x3ab4, 0x2a14, 0x3ab0, 0x2992, 0x3aab, 0x291e, 0x3aa4, 0x28b9, 0x3a9c, 0x2860,
+	0x3559, 0x3954, 0x3559, 0x3951, 0x3562, 0x3944, 0x357a, 0x391e, 0x35a9, 0x38d5, 0x35f5, 0x386a, 0x3667, 0x37eb, 0x36fc, 0x370b, 0x37a8, 0x363e, 0x382f, 0x3586, 0x3888, 0x34e0, 0x38dd, 0x344b, 0x392a, 0x338e, 0x396e, 0x32a3, 0x39aa, 0x31d5, 0x39de, 0x3121, 0x3a09, 0x3083, 0x3a2c, 0x2ff4, 0x3a49, 0x2f06, 0x3a5f, 0x2e38, 0x3a70, 0x2d84, 0x3a7b, 0x2ce7, 0x3a82, 0x2c60, 0x3a85, 0x2bd2, 0x3a84, 0x2b06, 0x3a80, 0x2a53, 0x3a79, 0x29b6, 0x3a70, 0x292d, 0x3a64, 0x28b6, 0x3a57, 0x284d, 0x3a47, 0x27df, 0x3a37, 0x273b,
+	0x3709, 0x387c, 0x3709, 0x387b, 0x370d, 0x3874, 0x371b, 0x3860, 0x3733, 0x3835, 0x375a, 0x37e1, 0x3797, 0x3731, 0x37ed, 0x3673, 0x382f, 0x35bb, 0x3870, 0x350f, 0x38b5, 0x3474, 0x38fa, 0x33d4, 0x393d, 0x32df, 0x3979, 0x3208, 0x39af, 0x314a, 0x39de, 0x30a3, 0x3a05, 0x3011, 0x3a24, 0x2f27, 0x3a3c, 0x2e4d, 0x3a4e, 0x2d8d, 0x3a59, 0x2ce6, 0x3a5f, 0x2c56, 0x3a60, 0x2bb3, 0x3a5d, 0x2ada, 0x3a56, 0x2a21, 0x3a4b, 0x297f, 0x3a3d, 0x28f1, 0x3a2d, 0x2876, 0x3a1a, 0x280a, 0x3a05, 0x2752, 0x39ef, 0x26a7, 0x39d6, 0x2611,
+	0x3840, 0x3780, 0x3840, 0x377f, 0x3841, 0x3778, 0x3844, 0x375f, 0x384b, 0x372c, 0x3854, 0x36d3, 0x3863, 0x3659, 0x387a, 0x35c5, 0x389a, 0x352b, 0x38c4, 0x3496, 0x38f4, 0x340a, 0x3928, 0x3318, 0x395c, 0x3239, 0x398e, 0x3172, 0x39bc, 0x30c6, 0x39e3, 0x302e, 0x3a04, 0x2f51, 0x3a1e, 0x2e68, 0x3a31, 0x2d9f, 0x3a3d, 0x2cf0, 0x3a43, 0x2c5a, 0x3a44, 0x2bad, 0x3a3f, 0x2ac9, 0x3a35, 0x2a05, 0x3a28, 0x295d, 0x3a18, 0x28cc, 0x3a03, 0x284b, 0x39ed, 0x27b6, 0x39d4, 0x26f1, 0x39ba, 0x2644, 0x39a1, 0x25ab, 0x3989, 0x2522,
+	0x38e2, 0x363b, 0x38e2, 0x363b, 0x38e2, 0x3636, 0x38e4, 0x3626, 0x38e7, 0x3608, 0x38eb, 0x35ce, 0x38f1, 0x357b, 0x38f9, 0x350d, 0x3909, 0x3493, 0x391f, 0x3416, 0x393d, 0x333f, 0x395f, 0x325f, 0x3985, 0x3196, 0x39ab, 0x30e6, 0x39cf, 0x3048, 0x39ee, 0x2f7e, 0x3a08, 0x2e8c, 0x3a1b, 0x2db9, 0x3a28, 0x2d01, 0x3a2e, 0x2c62, 0x3a2f, 0x2bb5, 0x3a29, 0x2ac8, 0x3a1f, 0x29fe, 0x3a10, 0x294d, 0x39fd, 0x28b4, 0x39e6, 0x282f, 0x39ce, 0x2776, 0x39b5, 0x26ae, 0x399e, 0x25fd, 0x3985, 0x2561, 0x3969, 0x24d7, 0x394c, 0x245c,
+	0x396e, 0x3524, 0x396e, 0x3524, 0x396d, 0x3521, 0x396d, 0x3517, 0x396f, 0x3504, 0x396f, 0x34de, 0x396f, 0x34a4, 0x396f, 0x3457, 0x3973, 0x33f7, 0x397b, 0x332f, 0x3989, 0x3267, 0x399d, 0x31ab, 0x39b4, 0x30fa, 0x39ce, 0x305d, 0x39e7, 0x2fa4, 0x39fd, 0x2eac, 0x3a0f, 0x2dd5, 0x3a1b, 0x2d15, 0x3a21, 0x2c71, 0x3a21, 0x2bc6, 0x3a1b, 0x2acf, 0x3a10, 0x29fd, 0x3a00, 0x2947, 0x39ec, 0x28aa, 0x39d6, 0x2820, 0x39bf, 0x274b, 0x39a8, 0x267b, 0x398f, 0x25c9, 0x3972, 0x252c, 0x3953, 0x24a1, 0x3932, 0x2425, 0x3910, 0x2371,
+	0x39e5, 0x3436, 0x39e5, 0x3435, 0x39e5, 0x3434, 0x39e4, 0x342f, 0x39e4, 0x3422, 0x39e1, 0x3409, 0x39de, 0x33c4, 0x39da, 0x335a, 0x39d5, 0x32d1, 0x39d3, 0x3237, 0x39d6, 0x3198, 0x39dc, 0x30fa, 0x39e7, 0x3066, 0x39f4, 0x2fb7, 0x3a03, 0x2ec4, 0x3a10, 0x2deb, 0x3a18, 0x2d29, 0x3a1c, 0x2c80, 0x3a1b, 0x2bd9, 0x3a15, 0x2adc, 0x3a0a, 0x2a05, 0x39f9, 0x2946, 0x39e5, 0x28a4, 0x39cf, 0x2816, 0x39bb, 0x2734, 0x39a3, 0x265c, 0x3987, 0x25a4, 0x3968, 0x2503, 0x3946, 0x2477, 0x3923, 0x23f6, 0x3900, 0x231d, 0x38dd, 0x2260,
+	0x3a4b, 0x32d6, 0x3a4a, 0x32d6, 0x3a4a, 0x32d5, 0x3a49, 0x32cf, 0x3a47, 0x32bd, 0x3a44, 0x32a0, 0x3a3d, 0x3269, 0x3a36, 0x321f, 0x3a2d, 0x31bf, 0x3a24, 0x314d, 0x3a1e, 0x30d0, 0x3a1a, 0x3051, 0x3a1b, 0x2faf, 0x3a1d, 0x2ec5, 0x3a21, 0x2df2, 0x3a24, 0x2d35, 0x3a24, 0x2c8b, 0x3a20, 0x2bed, 0x3a17, 0x2ae8, 0x3a0b, 0x2a0a, 0x39f9, 0x294a, 0x39e6, 0x28a4, 0x39d2, 0x2811, 0x39bd, 0x2721, 0x39a4, 0x2649, 0x3986, 0x258b, 0x3965, 0x24e7, 0x3942, 0x2458, 0x391f, 0x23b5, 0x38fa, 0x22d9, 0x38d4, 0x221c, 0x38ad, 0x2175,
+	0x3aa0, 0x3180, 0x3aa0, 0x3180, 0x3a9f, 0x3180, 0x3a9e, 0x317c, 0x3a9b, 0x3171, 0x3a97, 0x3160, 0x3a8f, 0x313c, 0x3a86, 0x310b, 0x3a7b, 0x30ca, 0x3a6e, 0x3076, 0x3a61, 0x3018, 0x3a55, 0x2f67, 0x3a4d, 0x2ea0, 0x3a47, 0x2de3, 0x3a40, 0x2d2b, 0x3a3a, 0x2c8c, 0x3a31, 0x2bf3, 0x3a25, 0x2af1, 0x3a15, 0x2a0e, 0x3a02, 0x294a, 0x39ed, 0x28a3, 0x39db, 0x280f, 0x39c5, 0x271c, 0x39ab, 0x2639, 0x398c, 0x2577, 0x396a, 0x24d0, 0x3947, 0x2440, 0x3922, 0x2385, 0x38fc, 0x22a9, 0x38d4, 0x21e6, 0x38ab, 0x213a, 0x3884, 0x20aa,
+	0x3ae8, 0x3062, 0x3ae7, 0x3062, 0x3ae7, 0x3062, 0x3ae5, 0x3060, 0x3ae2, 0x305a, 0x3ade, 0x3050, 0x3ad6, 0x303b, 0x3acb, 0x301a, 0x3abe, 0x2fdc, 0x3aae, 0x2f66, 0x3a9d, 0x2eda, 0x3a8c, 0x2e44, 0x3a7d, 0x2da8, 0x3a6f, 0x2d0e, 0x3a60, 0x2c79, 0x3a50, 0x2bdb, 0x3a40, 0x2aea, 0x3a2b, 0x2a09, 0x3a14, 0x2948, 0x39fd, 0x289d, 0x39eb, 0x2809, 0x39d4, 0x2713, 0x39b9, 0x262f, 0x3999, 0x256a, 0x3976, 0x24c0, 0x3952, 0x242c, 0x392c, 0x2358, 0x3905, 0x227f, 0x38dc, 0x21c1, 0x38b2, 0x2114, 0x3888, 0x207d, 0x385c, 0x1ff2,
+	0x3b23, 0x2ee8, 0x3b23, 0x2ee8, 0x3b22, 0x2ee9, 0x3b21, 0x2ee8, 0x3b1e, 0x2ee6, 0x3b19, 0x2edb, 0x3b11, 0x2ec3, 0x3b05, 0x2e97, 0x3af7, 0x2e5d, 0x3ae7, 0x2e11, 0x3ad2, 0x2dab, 0x3abe, 0x2d3d, 0x3aa9, 0x2cc4, 0x3a95, 0x2c4b, 0x3a7f, 0x2ba6, 0x3a67, 0x2abf, 0x3a4e, 0x29f3, 0x3a32, 0x2939, 0x3a17, 0x2892, 0x3a01, 0x2803, 0x39e9, 0x26ff, 0x39cc, 0x2620, 0x39ac, 0x255f, 0x3988, 0x24b0, 0x3963, 0x241b, 0x393d, 0x233a, 0x3914, 0x2258, 0x38e9, 0x2196, 0x38bf, 0x20f0, 0x3892, 0x205e, 0x3865, 0x1fb4, 0x3837, 0x1ec7,
+	0x3b54, 0x2d61, 0x3b54, 0x2d61, 0x3b53, 0x2d62, 0x3b52, 0x2d62, 0x3b4f, 0x2d64, 0x3b4a, 0x2d5e, 0x3b42, 0x2d54, 0x3b35, 0x2d39, 0x3b28, 0x2d19, 0x3b17, 0x2ce6, 0x3b01, 0x2ca0, 0x3aea, 0x2c51, 0x3ad2, 0x2bf1, 0x3ab9, 0x2b36, 0x3a9c, 0x2a76, 0x3a7d, 0x29bf, 0x3a5c, 0x2914, 0x3a3b, 0x287c, 0x3a20, 0x27de, 0x3a06, 0x26e8, 0x39e8, 0x260b, 0x39c5, 0x2548, 0x39a0, 0x24a2, 0x397a, 0x240e, 0x3952, 0x2310, 0x3929, 0x2239, 0x38fd, 0x217b, 0x38d1, 0x20ce, 0x38a3, 0x2037, 0x3874, 0x1f74, 0x3844, 0x1e9a, 0x3814, 0x1dcf,
+	0x3b7c, 0x2c22, 0x3b7c, 0x2c22, 0x3b7b, 0x2c24, 0x3b79, 0x2c25, 0x3b78, 0x2c2a, 0x3b72, 0x2c28, 0x3b6a, 0x2c25, 0x3b5e, 0x2c17, 0x3b51, 0x2c05, 0x3b3f, 0x2bcb, 0x3b2a, 0x2b78, 0x3b11, 0x2b06, 0x3af7, 0x2a88, 0x3ad9, 0x29fa, 0x3ab7, 0x2968, 0x3a92, 0x28d7, 0x3a6a, 0x284e, 0x3a48, 0x279e, 0x3a2c, 0x26bc, 0x3a0b, 0x25e5, 0x39e6, 0x252c, 0x39bf, 0x248b, 0x3997, 0x23f1, 0x396f, 0x22f7, 0x3943, 0x2214, 0x3916, 0x2154, 0x38ea, 0x20b3, 0x38ba, 0x2022, 0x3889, 0x1f38, 0x3857, 0x1e54, 0x3826, 0x1d9b, 0x37ec, 0x1cf9,
+	0x3b9c, 0x2a43, 0x3b9c, 0x2a43, 0x3b9b, 0x2a46, 0x3b9a, 0x2a4c, 0x3b98, 0x2a54, 0x3b92, 0x2a55, 0x3b8b, 0x2a5b, 0x3b80, 0x2a56, 0x3b73, 0x2a42, 0x3b61, 0x2a1f, 0x3b4e, 0x29f2, 0x3b33, 0x299f, 0x3b17, 0x294b, 0x3af7, 0x28e7, 0x3acf, 0x2878, 0x3aa4, 0x2808, 0x3a7a, 0x2739, 0x3a59, 0x266c, 0x3a36, 0x25b3, 0x3a0f, 0x2505, 0x39e4, 0x2465, 0x39bb, 0x23c0, 0x3991, 0x22cb, 0x3963, 0x21ee, 0x3935, 0x2134, 0x3907, 0x208f, 0x38d7, 0x2002, 0x38a4, 0x1f0a, 0x3870, 0x1e2d, 0x383d, 0x1d67, 0x380b, 0x1cbf, 0x37b4, 0x1c34,
+	0x3bb5, 0x28aa, 0x3bb5, 0x28ab, 0x3bb5, 0x28ad, 0x3bb4, 0x28b3, 0x3bb2, 0x28bc, 0x3bac, 0x28c2, 0x3ba6, 0x28ce, 0x3b9c, 0x28d2, 0x3b8f, 0x28cb, 0x3b7f, 0x28be, 0x3b6b, 0x28a5, 0x3b50, 0x2875, 0x3b34, 0x283e, 0x3b11, 0x27f0, 0x3ae6, 0x274e, 0x3ab6, 0x26a4, 0x3a8e, 0x2600, 0x3a68, 0x255e, 0x3a40, 0x24c8, 0x3a13, 0x243b, 0x39e5, 0x236d, 0x39b9, 0x2290, 0x398b, 0x21c5, 0x3959, 0x2109, 0x392a, 0x206a, 0x38f8, 0x1fc7, 0x38c4, 0x1ecf, 0x388e, 0x1df6, 0x3859, 0x1d3e, 0x3826, 0x1c9d, 0x37e5, 0x1c09, 0x377a, 0x1b13,
+	0x3bc9, 0x26d3, 0x3bc9, 0x26d4, 0x3bc9, 0x26d8, 0x3bc8, 0x26e4, 0x3bc6, 0x26f3, 0x3bc2, 0x270d, 0x3bbb, 0x271d, 0x3bb1, 0x272f, 0x3ba4, 0x2733, 0x3b96, 0x273a, 0x3b83, 0x2722, 0x3b6b, 0x26fa, 0x3b4c, 0x26ad, 0x3b27, 0x2653, 0x3af8, 0x25e2, 0x3ac8, 0x2566, 0x3aa1, 0x24ec, 0x3a77, 0x2470, 0x3a49, 0x23f0, 0x3a17, 0x2310, 0x39e8, 0x223c, 0x39b8, 0x2182, 0x3985, 0x20df, 0x3953, 0x2041, 0x391f, 0x1f75, 0x38ea, 0x1e92, 0x38b3, 0x1dc5, 0x387b, 0x1d08, 0x3845, 0x1c6c, 0x3811, 0x1bd0, 0x37b2, 0x1adb, 0x3743, 0x19f8,
+	0x3bd9, 0x24e4, 0x3bd9, 0x24e5, 0x3bd9, 0x24e8, 0x3bd8, 0x24f2, 0x3bd6, 0x2500, 0x3bd2, 0x251b, 0x3bcb, 0x252a, 0x3bc2, 0x2543, 0x3bb6, 0x2553, 0x3baa, 0x256a, 0x3b97, 0x2569, 0x3b80, 0x255c, 0x3b61, 0x252b, 0x3b3a, 0x24fa, 0x3b09, 0x24b0, 0x3adc, 0x2457, 0x3ab3, 0x23fc, 0x3a85, 0x2342, 0x3a51, 0x2287, 0x3a1e, 0x21d8, 0x39eb, 0x212f, 0x39b7, 0x2099, 0x3982, 0x2012, 0x394d, 0x1f27, 0x3915, 0x1e41, 0x38dc, 0x1d88, 0x38a3, 0x1cd8, 0x386a, 0x1c3d, 0x3833, 0x1b6d, 0x37f4, 0x1a92, 0x3781, 0x19c8, 0x3713, 0x1906,
+	0x3be5, 0x22d8, 0x3be5, 0x22d9, 0x3be4, 0x22de, 0x3be4, 0x22ef, 0x3be2, 0x2307, 0x3bdf, 0x2336, 0x3bd8, 0x235a, 0x3bd0, 0x238e, 0x3bc7, 0x23cb, 0x3bb9, 0x23f2, 0x3ba7, 0x2404, 0x3b92, 0x2409, 0x3b72, 0x23e6, 0x3b4a, 0x23b2, 0x3b1a, 0x2354, 0x3aef, 0x22de, 0x3ac3, 0x225f, 0x3a91, 0x21db, 0x3a5a, 0x214f, 0x3a26, 0x20c8, 0x39ee, 0x2044, 0x39b7, 0x1f96, 0x3980, 0x1ebe, 0x3946, 0x1df3, 0x390b, 0x1d37, 0x38d0, 0x1c9b, 0x3895, 0x1c0f, 0x385b, 0x1b12, 0x3820, 0x1a3a, 0x37c9, 0x197b, 0x3756, 0x18d3, 0x36e6, 0x1836,
+	0x3bed, 0x20a8, 0x3bed, 0x20a9, 0x3bed, 0x20ad, 0x3bed, 0x20bb, 0x3beb, 0x20cf, 0x3be9, 0x20fe, 0x3be1, 0x2117, 0x3bdb, 0x2152, 0x3bd3, 0x218c, 0x3bc5, 0x21af, 0x3bb6, 0x21dd, 0x3ba0, 0x21f3, 0x3b81, 0x21f4, 0x3b55, 0x21d3, 0x3b2b, 0x21a9, 0x3b01, 0x215f, 0x3ad1, 0x2107, 0x3a9b, 0x20ab, 0x3a64, 0x2044, 0x3a2c, 0x1fb7, 0x39f2, 0x1ef3, 0x39b9, 0x1e35, 0x397e, 0x1d8a, 0x3941, 0x1ce6, 0x3903, 0x1c52, 0x38c5, 0x1b97, 0x388a, 0x1abd, 0x384c, 0x19e2, 0x380d, 0x1929, 0x37a3, 0x188d, 0x372e, 0x1801, 0x36bb, 0x1702,
+	0x3bf4, 0x1e23, 0x3bf4, 0x1e25, 0x3bf3, 0x1e2b, 0x3bf3, 0x1e41, 0x3bf1, 0x1e61, 0x3bf0, 0x1eaf, 0x3be9, 0x1ee2, 0x3be3, 0x1f43, 0x3bdb, 0x1fa4, 0x3bcf, 0x1ff7, 0x3bc1, 0x202e, 0x3bad, 0x2052, 0x3b8d, 0x2062, 0x3b61, 0x2056, 0x3b3b, 0x204b, 0x3b10, 0x201e, 0x3ade, 0x1fca, 0x3aa6, 0x1f50, 0x3a6f, 0x1ec6, 0x3a33, 0x1e28, 0x39f7, 0x1d97, 0x39bb, 0x1d07, 0x397d, 0x1c7f, 0x393c, 0x1bff, 0x38fb, 0x1b13, 0x38bc, 0x1a3d, 0x387d, 0x1984, 0x383c, 0x18df, 0x37fa, 0x183f, 0x3780, 0x1781, 0x3708, 0x169e, 0x3692, 0x15c5,
+	0x3bf8, 0x1bca, 0x3bf8, 0x1bcc, 0x3bf8, 0x1bd6, 0x3bf8, 0x1bf6, 0x3bf7, 0x1c21, 0x3bf5, 0x1c51, 0x3bef, 0x1c85, 0x3be9, 0x1cc7, 0x3be2, 0x1d23, 0x3bd6, 0x1d6f, 0x3bca, 0x1dd3, 0x3bb6, 0x1e1b, 0x3b95, 0x1e4f, 0x3b6d, 0x1e5b, 0x3b49, 0x1e5c, 0x3b1d, 0x1e32, 0x3ae9, 0x1df7, 0x3ab2, 0x1da5, 0x3a78, 0x1d4a, 0x3a3a, 0x1cd6, 0x39fd, 0x1c6e, 0x39bd, 0x1c06, 0x397b, 0x1b35, 0x3938, 0x1a70, 0x38f5, 0x19bb, 0x38b4, 0x1912, 0x3871, 0x187e, 0x382f, 0x17ed, 0x37dc, 0x16fc, 0x375e, 0x1620, 0x36e3, 0x1568, 0x3669, 0x14c0,
+	0x3bfb, 0x18b9, 0x3bfb, 0x18ba, 0x3bfb, 0x18c1, 0x3bfb, 0x18d8, 0x3bfa, 0x1912, 0x3bf8, 0x195a, 0x3bf3, 0x19be, 0x3bed, 0x1a1c, 0x3be7, 0x1aad, 0x3bdd, 0x1b4e, 0x3bd0, 0x1bcf, 0x3bbe, 0x1c37, 0x3b9a, 0x1c69, 0x3b79, 0x1c90, 0x3b55, 0x1c99, 0x3b29, 0x1c98, 0x3af3, 0x1c78, 0x3abc, 0x1c45, 0x3a81, 0x1c0e, 0x3a42, 0x1b83, 0x3a02, 0x1aeb, 0x39bf, 0x1a53, 0x397a, 0x19b5, 0x3935, 0x1923, 0x38f1, 0x1895, 0x38ab, 0x1815, 0x3866, 0x1739, 0x3822, 0x1666, 0x37bf, 0x15a9, 0x373d, 0x14f8, 0x36be, 0x1462, 0x3645, 0x13b3,
+	0x3bfd, 0x156b, 0x3bfd, 0x156c, 0x3bfd, 0x1576, 0x3bfd, 0x1596, 0x3bfc, 0x15e9, 0x3bfa, 0x1650, 0x3bf6, 0x16eb, 0x3bf0, 0x1770, 0x3beb, 0x1831, 0x3be2, 0x18b3, 0x3bd5, 0x191e, 0x3bc4, 0x19ae, 0x3ba2, 0x1a10, 0x3b83, 0x1a61, 0x3b5f, 0x1a86, 0x3b32, 0x1aa5, 0x3afd, 0x1a83, 0x3ac6, 0x1a5b, 0x3a8a, 0x1a16, 0x3a49, 0x19b3, 0x3a07, 0x194b, 0x39c2, 0x18e4, 0x397a, 0x1876, 0x3933, 0x1803, 0x38ec, 0x1737, 0x38a4, 0x1677, 0x385c, 0x15be, 0x3816, 0x1518, 0x37a4, 0x1486, 0x371d, 0x13fc, 0x369d, 0x1306, 0x3622, 0x122d,
+	0x3bff, 0x11cb, 0x3bff, 0x11cd, 0x3bfe, 0x11d9, 0x3bfe, 0x1203, 0x3bfe, 0x1274, 0x3bfc, 0x1304, 0x3bf8, 0x13dc, 0x3bf2, 0x144f, 0x3bed, 0x1508, 0x3be6, 0x15bf, 0x3bda, 0x1677, 0x3bc7, 0x176f, 0x3ba8, 0x1805, 0x3b8b, 0x1847, 0x3b68, 0x1887, 0x3b3b, 0x18aa, 0x3b08, 0x18ab, 0x3acf, 0x189e, 0x3a93, 0x1877, 0x3a51, 0x1840, 0x3a0c, 0x17ff, 0x39c5, 0x1769, 0x397c, 0x16d1, 0x3932, 0x1635, 0x38e7, 0x1599, 0x389c, 0x1507, 0x3853, 0x1485, 0x380b, 0x13f8, 0x3789, 0x1321, 0x3700, 0x124c, 0x367e, 0x1199, 0x35ff, 0x10e6,
+	0x3bff, 0x0daa, 0x3bff, 0x0dad, 0x3bff, 0x0dbb, 0x3bff, 0x0dee, 0x3bff, 0x0e80, 0x3bfd, 0x0f3d, 0x3bfa, 0x1043, 0x3bf4, 0x10c5, 0x3bef, 0x11a3, 0x3be9, 0x12e6, 0x3bdd, 0x13f7, 0x3bc7, 0x1498, 0x3bae, 0x152a, 0x3b92, 0x15a3, 0x3b6f, 0x1618, 0x3b43, 0x1654, 0x3b11, 0x1687, 0x3ad8, 0x167a, 0x3a9c, 0x166c, 0x3a58, 0x1629, 0x3a12, 0x15d7, 0x39c8, 0x1580, 0x397d, 0x151a, 0x3930, 0x14b0, 0x38e3, 0x143e, 0x3896, 0x13ad, 0x384b, 0x12eb, 0x3801, 0x122e, 0x376f, 0x117e, 0x36e5, 0x10eb, 0x365f, 0x1058, 0x35de, 0x0fb5,
+	0x3c00, 0x08ea, 0x3c00, 0x08ed, 0x3c00, 0x08fc, 0x3bff, 0x0935, 0x3bff, 0x09e5, 0x3bfd, 0x0ad1, 0x3bfb, 0x0c5a, 0x3bf6, 0x0d16, 0x3bf1, 0x0e3c, 0x3bec, 0x0fe4, 0x3be0, 0x10b0, 0x3bca, 0x1181, 0x3bb4, 0x1278, 0x3b99, 0x1321, 0x3b75, 0x13de, 0x3b4b, 0x1432, 0x3b19, 0x1466, 0x3ae1, 0x146c, 0x3aa4, 0x147b, 0x3a5e, 0x144e, 0x3a17, 0x1431, 0x39cd, 0x13f6, 0x397e, 0x1368, 0x3930, 0x12e6, 0x38e0, 0x124e, 0x3891, 0x11b8, 0x3844, 0x1134, 0x37ec, 0x10aa, 0x3758, 0x102b, 0x36cb, 0x0f76, 0x3641, 0x0ea7, 0x35c1, 0x0de4,
+	0x3c00, 0x039b, 0x3c00, 0x039d, 0x3c00, 0x03ac, 0x3c00, 0x03e4, 0x3c00, 0x04a4, 0x3bff, 0x06ce, 0x3bfb, 0x07f8, 0x3bf6, 0x08e7, 0x3bf3, 0x0a42, 0x3bee, 0x0c3a, 0x3be0, 0x0d29, 0x3bcd, 0x0e4e, 0x3bb9, 0x0fa9, 0x3b9e, 0x1054, 0x3b7b, 0x10e4, 0x3b52, 0x1158, 0x3b20, 0x11a2, 0x3ae9, 0x11d4, 0x3aab, 0x11ef, 0x3a66, 0x11e6, 0x3a1d, 0x11c3, 0x39d0, 0x1183, 0x3980, 0x113e, 0x3930, 0x10e7, 0x38dc, 0x1083, 0x388d, 0x102c, 0x383b, 0x0f8b, 0x37da, 0x0ede, 0x3743, 0x0e2e, 0x36b0, 0x0d84, 0x3626, 0x0cf4, 0x35a3, 0x0c69,
+	0x3c00, 0x0107, 0x3c00, 0x0107, 0x3c00, 0x010d, 0x3c00, 0x0125, 0x3c00, 0x0182, 0x3bff, 0x02d6, 0x3bfc, 0x034a, 0x3bf8, 0x04a3, 0x3bf4, 0x05f6, 0x3bef, 0x082f, 0x3be1, 0x0990, 0x3bd0, 0x0aff, 0x3bbd, 0x0c3f, 0x3ba2, 0x0d09, 0x3b81, 0x0dc3, 0x3b59, 0x0e71, 0x3b27, 0x0edf, 0x3af1, 0x0f4d, 0x3ab2, 0x0f8c, 0x3a6d, 0x0fa8, 0x3a23, 0x0f7a, 0x39d4, 0x0f63, 0x3983, 0x0f09, 0x392f, 0x0eac, 0x38db, 0x0e3f, 0x3887, 0x0dc9, 0x3834, 0x0d51, 0x37c9, 0x0cdc, 0x372c, 0x0c5f, 0x3699, 0x0bf5, 0x360b, 0x0b1a, 0x3586, 0x0a68,
+	0x3c00, 0x0031, 0x3c00, 0x0031, 0x3c00, 0x0033, 0x3c00, 0x003a, 0x3c00, 0x0061, 0x3bff, 0x0117, 0x3bfc, 0x013b, 0x3bf8, 0x01d6, 0x3bf5, 0x02dd, 0x3bef, 0x03fc, 0x3be2, 0x05c5, 0x3bd3, 0x06eb, 0x3bc0, 0x0870, 0x3ba6, 0x0979, 0x3b84, 0x0a33, 0x3b5f, 0x0b4b, 0x3b2d, 0x0beb, 0x3af8, 0x0c47, 0x3ab9, 0x0c82, 0x3a74, 0x0c9d, 0x3a28, 0x0ca3, 0x39d9, 0x0c97, 0x3985, 0x0c75, 0x3930, 0x0c53, 0x38d9, 0x0c07, 0x3883, 0x0ba5, 0x382e, 0x0b11, 0x37b8, 0x0a82, 0x3718, 0x09f7, 0x3682, 0x096b, 0x35f2, 0x08ed, 0x356b, 0x0866,
+	0x3c00, 0x0004, 0x3c00, 0x0004, 0x3c00, 0x0004, 0x3c00, 0x0006, 0x3c00, 0x0012, 0x3c00, 0x0069, 0x3bfc, 0x006e, 0x3bf9, 0x00ce, 0x3bf6, 0x013f, 0x3bed, 0x018c, 0x3be3, 0x0291, 0x3bd5, 0x0315, 0x3bc2, 0x045a, 0x3baa, 0x053b, 0x3b89, 0x0627, 0x3b64, 0x076d, 0x3b33, 0x0802, 0x3afe, 0x087e, 0x3ac0, 0x08d6, 0x3a7a, 0x0909, 0x3a2e, 0x0928, 0x39dd, 0x0932, 0x3988, 0x0926, 0x3931, 0x090a, 0x38d8, 0x08d9, 0x3880, 0x089b, 0x3829, 0x0853, 0x37a8, 0x080d, 0x3705, 0x0771, 0x366b, 0x06ec, 0x35da, 0x0647, 0x3551, 0x05c0,
+	0x3c00, 0x0000, 0x3c00, 0x0000, 0x3c00, 0x0000, 0x3c00, 0x0000, 0x3c00, 0x0003, 0x3c00, 0x0029, 0x3bfe, 0x0056, 0x3bfa, 0x0044, 0x3bf7, 0x007e, 0x3bed, 0x0096, 0x3be5, 0x00ff, 0x3bd7, 0x0157, 0x3bc6, 0x01ad, 0x3bab, 0x0207, 0x3b8e, 0x0298, 0x3b68, 0x030c, 0x3b3a, 0x0370, 0x3b05, 0x03e9, 0x3ac6, 0x043b, 0x3a80, 0x0492, 0x3a35, 0x04d4, 0x39e2, 0x04fa, 0x398b, 0x0505, 0x3932, 0x0506, 0x38d7, 0x04e8, 0x387c, 0x04c7, 0x3823, 0x0495, 0x3799, 0x045c, 0x36f4, 0x041b, 0x3656, 0x03d8, 0x35c2, 0x038f, 0x3538, 0x034a
+] );
+
+let dfgLUTTexture = null;
+
+export function getDFGLUT() {
+
+	if ( dfgLUTTexture === null ) {
+
+		dfgLUTTexture = new DataTexture( DFG_LUT_DATA, DFG_LUT_SIZE, DFG_LUT_SIZE, RGFormat, HalfFloatType );
+		dfgLUTTexture.minFilter = LinearFilter;
+		dfgLUTTexture.magFilter = LinearFilter;
+		dfgLUTTexture.wrapS = ClampToEdgeWrapping;
+		dfgLUTTexture.wrapT = ClampToEdgeWrapping;
+		dfgLUTTexture.generateMipmaps = false;
+		dfgLUTTexture.needsUpdate = true;
+
+	}
+
+	return dfgLUTTexture;
+
+}

+ 1 - 1
src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js

@@ -10,6 +10,6 @@ export default /* glsl */`
 	#else
 		uniform sampler2D envMap;
 	#endif
-	
+
 #endif
 `;

+ 8 - 16
src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js

@@ -1,5 +1,7 @@
 export default /* glsl */`
 
+uniform sampler2D dfgLUT;
+
 struct PhysicalMaterial {
 
 	vec3 diffuseColor;
@@ -370,25 +372,15 @@ float IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float
 
 }
 
-// Analytical approximation of the DFG LUT, one half of the
-// split-sum approximation used in indirect specular lighting.
-// via 'environmentBRDF' from "Physically Based Shading on Mobile"
-// https://www.unrealengine.com/blog/physically-based-shading-on-mobile
+// DFG LUT sampling for physically-based rendering.
+// Uses a precomputed lookup table for the split-sum approximation
+// used in indirect specular lighting.
+// Reference: "Real Shading in Unreal Engine 4" by Brian Karis
 vec2 DFGApprox( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {
 
 	float dotNV = saturate( dot( normal, viewDir ) );
-
-	const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );
-
-	const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );
-
-	vec4 r = roughness * c0 + c1;
-
-	float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;
-
-	vec2 fab = vec2( - 1.04, 1.04 ) * a004 + r.zw;
-
-	return fab;
+	vec2 uv = vec2( roughness, dotNV );
+	return texture2D( dfgLUT, uv ).rg;
 
 }
 

+ 1 - 0
src/renderers/shaders/UniformsLib.js

@@ -35,6 +35,7 @@ const UniformsLib = {
 		reflectivity: { value: 1.0 }, // basic, lambert, phong
 		ior: { value: 1.5 }, // physical
 		refractionRatio: { value: 0.98 }, // basic, lambert, phong
+		dfgLUT: { value: null } // DFG LUT for physically-based rendering
 
 	},
 

+ 295 - 0
utils/generateDFGLUT.js

@@ -0,0 +1,295 @@
+/**
+ * DFG LUT Generator (16x16)
+ *
+ * Generates a precomputed lookup table for the split-sum approximation
+ * used in Image-Based Lighting. The 16x16 resolution provides a minimal
+ * memory footprint for DataTexture usage.
+ *
+ * Reference: "Real Shading in Unreal Engine 4" by Brian Karis
+ */
+
+import * as fs from 'fs';
+
+const LUT_SIZE = 32;
+const SAMPLE_COUNT = 1024;
+
+// Van der Corput sequence
+function radicalInverse_VdC( bits ) {
+
+	bits = ( bits << 16 ) | ( bits >>> 16 );
+	bits = ( ( bits & 0x55555555 ) << 1 ) | ( ( bits & 0xAAAAAAAA ) >>> 1 );
+	bits = ( ( bits & 0x33333333 ) << 2 ) | ( ( bits & 0xCCCCCCCC ) >>> 2 );
+	bits = ( ( bits & 0x0F0F0F0F ) << 4 ) | ( ( bits & 0xF0F0F0F0 ) >>> 4 );
+	bits = ( ( bits & 0x00FF00FF ) << 8 ) | ( ( bits & 0xFF00FF00 ) >>> 8 );
+	return ( bits >>> 0 ) * 2.3283064365386963e-10;
+
+}
+
+function hammersley( i, N ) {
+
+	return [ i / N, radicalInverse_VdC( i ) ];
+
+}
+
+function importanceSampleGGX( xi, N, roughness ) {
+
+	const a = roughness * roughness;
+	const phi = 2.0 * Math.PI * xi[ 0 ];
+	const cosTheta = Math.sqrt( ( 1.0 - xi[ 1 ] ) / ( 1.0 + ( a * a - 1.0 ) * xi[ 1 ] ) );
+	const sinTheta = Math.sqrt( 1.0 - cosTheta * cosTheta );
+
+	const H = [
+		Math.cos( phi ) * sinTheta,
+		Math.sin( phi ) * sinTheta,
+		cosTheta
+	];
+
+	const up = Math.abs( N[ 2 ] ) < 0.999 ? [ 0, 0, 1 ] : [ 1, 0, 0 ];
+	const tangent = normalize( cross( up, N ) );
+	const bitangent = cross( N, tangent );
+
+	const sampleVec = [
+		tangent[ 0 ] * H[ 0 ] + bitangent[ 0 ] * H[ 1 ] + N[ 0 ] * H[ 2 ],
+		tangent[ 1 ] * H[ 0 ] + bitangent[ 1 ] * H[ 1 ] + N[ 1 ] * H[ 2 ],
+		tangent[ 2 ] * H[ 0 ] + bitangent[ 2 ] * H[ 1 ] + N[ 2 ] * H[ 2 ]
+	];
+
+	return normalize( sampleVec );
+
+}
+
+function V_SmithGGXCorrelated( NdotV, NdotL, roughness ) {
+
+	const a2 = Math.pow( roughness, 4.0 );
+	const GGXV = NdotL * Math.sqrt( NdotV * NdotV * ( 1.0 - a2 ) + a2 );
+	const GGXL = NdotV * Math.sqrt( NdotL * NdotL * ( 1.0 - a2 ) + a2 );
+	return 0.5 / ( GGXV + GGXL );
+
+}
+
+function dot( a, b ) {
+
+	return a[ 0 ] * b[ 0 ] + a[ 1 ] * b[ 1 ] + a[ 2 ] * b[ 2 ];
+
+}
+
+function cross( a, b ) {
+
+	return [
+		a[ 1 ] * b[ 2 ] - a[ 2 ] * b[ 1 ],
+		a[ 2 ] * b[ 0 ] - a[ 0 ] * b[ 2 ],
+		a[ 0 ] * b[ 1 ] - a[ 1 ] * b[ 0 ]
+	];
+
+}
+
+function length( v ) {
+
+	return Math.sqrt( dot( v, v ) );
+
+}
+
+function normalize( v ) {
+
+	const len = length( v );
+	return len > 0 ? [ v[ 0 ] / len, v[ 1 ] / len, v[ 2 ] / len ] : [ 0, 0, 0 ];
+
+}
+
+function add( a, b ) {
+
+	return [ a[ 0 ] + b[ 0 ], a[ 1 ] + b[ 1 ], a[ 2 ] + b[ 2 ] ];
+
+}
+
+function scale( v, s ) {
+
+	return [ v[ 0 ] * s, v[ 1 ] * s, v[ 2 ] * s ];
+
+}
+
+// Convert float32 to float16 (half float)
+function floatToHalf( float ) {
+
+	const floatView = new Float32Array( 1 );
+	const int32View = new Int32Array( floatView.buffer );
+
+	floatView[ 0 ] = float;
+	const x = int32View[ 0 ];
+
+	let bits = ( x >> 16 ) & 0x8000; // sign bit
+	let m = ( x >> 12 ) & 0x07ff; // mantissa
+	const e = ( x >> 23 ) & 0xff; // exponent
+
+	// Handle special cases
+	if ( e < 103 ) return bits; // Zero or denormal (too small)
+	if ( e > 142 ) {
+
+		bits |= 0x7c00; // Infinity
+		bits |= ( ( e == 255 ) ? 0 : ( x & 0x007fffff ) ) >> 13; // NaN if e == 255 and mantissa != 0
+		return bits;
+
+	}
+
+	if ( e < 113 ) {
+
+		m |= 0x0800; // Add implicit leading bit
+		bits |= ( m >> ( 114 - e ) ) + ( ( m >> ( 113 - e ) ) & 1 ); // Denormal with rounding
+		return bits;
+
+	}
+
+	bits |= ( ( e - 112 ) << 10 ) | ( m >> 1 );
+	bits += m & 1; // Rounding
+	return bits;
+
+}
+
+function integrateBRDF( NdotV, roughness ) {
+
+	const V = [
+		Math.sqrt( 1.0 - NdotV * NdotV ),
+		0.0,
+		NdotV
+	];
+
+	let A = 0.0;
+	let B = 0.0;
+	const N = [ 0.0, 0.0, 1.0 ];
+
+	for ( let i = 0; i < SAMPLE_COUNT; i ++ ) {
+
+		const xi = hammersley( i, SAMPLE_COUNT );
+		const H = importanceSampleGGX( xi, N, roughness );
+		const L = normalize( add( scale( H, 2.0 * dot( V, H ) ), scale( V, - 1.0 ) ) );
+
+		const NdotL = Math.max( L[ 2 ], 0.0 );
+		const NdotH = Math.max( H[ 2 ], 0.0 );
+		const VdotH = Math.max( dot( V, H ), 0.0 );
+
+		if ( NdotL > 0.0 ) {
+
+			const V_pdf = V_SmithGGXCorrelated( NdotV, NdotL, roughness ) * VdotH * NdotL / NdotH;
+			const Fc = Math.pow( 1.0 - VdotH, 5.0 );
+
+			A += ( 1.0 - Fc ) * V_pdf;
+			B += Fc * V_pdf;
+
+		}
+
+	}
+
+	return [ 4.0 * A / SAMPLE_COUNT, 4.0 * B / SAMPLE_COUNT ];
+
+}
+
+function generateDFGLUT() {
+
+	console.log( `Generating ${LUT_SIZE}x${LUT_SIZE} DFG LUT with ${SAMPLE_COUNT} samples...` );
+
+	const data = [];
+
+	for ( let y = 0; y < LUT_SIZE; y ++ ) {
+
+		const NdotV = ( y + 0.5 ) / LUT_SIZE;
+
+		for ( let x = 0; x < LUT_SIZE; x ++ ) {
+
+			const roughness = ( x + 0.5 ) / LUT_SIZE;
+			const result = integrateBRDF( NdotV, roughness );
+
+			data.push( result[ 0 ], result[ 1 ] );
+
+		}
+
+		if ( ( y + 1 ) % 8 === 0 ) {
+
+			console.log( `Progress: ${( ( y + 1 ) / LUT_SIZE * 100 ).toFixed( 1 )}%` );
+
+		}
+
+	}
+
+	console.log( 'Generation complete!' );
+	return data;
+
+}
+
+// Save as JavaScript module
+function saveAsJavaScript( data ) {
+
+	// Convert float32 data to half floats (uint16)
+	const halfFloatData = [];
+
+	for ( let i = 0; i < data.length; i ++ ) {
+
+		halfFloatData.push( floatToHalf( data[ i ] ) );
+
+	}
+
+	const rows = [];
+
+	for ( let y = 0; y < LUT_SIZE; y ++ ) {
+
+		const rowData = [];
+		for ( let x = 0; x < LUT_SIZE; x ++ ) {
+
+			const idx = ( y * LUT_SIZE + x ) * 2;
+			rowData.push( `0x${halfFloatData[ idx ].toString( 16 ).padStart( 4, '0' )}`, `0x${halfFloatData[ idx + 1 ].toString( 16 ).padStart( 4, '0' )}` );
+
+		}
+
+		rows.push( `\t${rowData.join( ', ' )}` );
+
+	}
+
+	const jsContent = `/**
+ * Precomputed DFG LUT for Image-Based Lighting
+ * Resolution: ${LUT_SIZE}x${LUT_SIZE}
+ * Samples: ${SAMPLE_COUNT} per texel
+ * Format: RG16F (2 half floats per texel: scale, bias)
+ */
+
+import { DataTexture } from '../../textures/DataTexture.js';
+import { RGFormat, HalfFloatType, LinearFilter, ClampToEdgeWrapping } from '../../constants.js';
+
+export const DFG_LUT_SIZE = ${LUT_SIZE};
+
+const DFG_LUT_DATA = new Uint16Array( [
+${rows.join( ',\n' )}
+] );
+
+let dfgLUTTexture = null;
+
+export function getDFGLUT() {
+
+	if ( dfgLUTTexture === null ) {
+
+		dfgLUTTexture = new DataTexture( DFG_LUT_DATA, DFG_LUT_SIZE, DFG_LUT_SIZE, RGFormat, HalfFloatType );
+		dfgLUTTexture.minFilter = LinearFilter;
+		dfgLUTTexture.magFilter = LinearFilter;
+		dfgLUTTexture.wrapS = ClampToEdgeWrapping;
+		dfgLUTTexture.wrapT = ClampToEdgeWrapping;
+		dfgLUTTexture.generateMipmaps = false;
+		dfgLUTTexture.needsUpdate = true;
+
+	}
+
+	return dfgLUTTexture;
+
+}
+`;
+
+	fs.writeFileSync( './src/renderers/shaders/DFGLUTData.js', jsContent );
+	console.log( 'Saved JavaScript version to ./src/renderers/shaders/DFGLUTData.js' );
+
+}
+
+// Generate and save
+const lutData = generateDFGLUT();
+saveAsJavaScript( lutData );
+
+console.log( '\nDFG LUT generation complete!' );
+console.log( `Size: ${LUT_SIZE}x${LUT_SIZE} = ${LUT_SIZE * LUT_SIZE} texels` );
+console.log( `Data size: ${( lutData.length * 2 / 1024 ).toFixed( 2 )} KB (Uint16/Half Float)` );
+console.log( '\nThe LUT is used as a DataTexture in the renderer.' );

Some files were not shown because too many files changed in this diff

粤ICP备19079148号