1- import decode from './decode.js' ;
2- import encode from './encode.js' ;
3-
4- export default /* glsl */ `
51// This shader requires the following #DEFINEs:
62//
73// PROCESS_FUNC - must be one of reproject, prefilter
@@ -13,6 +9,7 @@ export default /* glsl */`
139// When filtering:
1410// NUM_SAMPLES - number of samples
1511// NUM_SAMPLES_SQRT - sqrt of number of samples
12+ export default /* glsl */ `
1613
1714varying vec2 vUv0;
1815
@@ -45,8 +42,8 @@ float saturate(float x) {
4542 return clamp(x, 0.0, 1.0);
4643}
4744
48- ${ decode }
49- ${ encode }
45+ #include "decodePS"
46+ #include "encodePS"
5047
5148//-- supported projections
5249
@@ -116,8 +113,8 @@ vec2 octEncode(in vec3 v) {
116113 }
117114
118115 vec4 sampleCubemap(vec2 sph) {
119- return sampleCubemap(fromSpherical(sph));
120- }
116+ return sampleCubemap(fromSpherical(sph));
117+ }
121118
122119 vec4 sampleCubemap(vec3 dir, float mipLevel) {
123120 return textureCubeLod(sourceCube, modifySeams(dir, 1.0), mipLevel);
@@ -204,24 +201,24 @@ mat3 matrixFromVectorSlow(vec3 n) {
204201}
205202
206203vec4 reproject() {
207- if (NUM_SAMPLES <= 1) {
204+ if ({ NUM_SAMPLES} <= 1) {
208205 // single sample
209- return ENCODE_FUNC( DECODE_FUNC( SOURCE_FUNC( TARGET_FUNC())));
206+ return { ENCODE_FUNC}({ DECODE_FUNC}({ SOURCE_FUNC}({ TARGET_FUNC} ())));
210207 } else {
211208 // multi sample
212- vec3 t = TARGET_FUNC();
209+ vec3 t = { TARGET_FUNC} ();
213210 vec3 tu = dFdx(t);
214211 vec3 tv = dFdy(t);
215212
216213 vec3 result = vec3(0.0);
217- for (float u = 0.0; u < NUM_SAMPLES_SQRT; ++u) {
218- for (float v = 0.0; v < NUM_SAMPLES_SQRT; ++v) {
219- result += DECODE_FUNC( SOURCE_FUNC(normalize(t +
220- tu * (u / NUM_SAMPLES_SQRT - 0.5) +
221- tv * (v / NUM_SAMPLES_SQRT - 0.5))));
214+ for (float u = 0.0; u < { NUM_SAMPLES_SQRT} ; ++u) {
215+ for (float v = 0.0; v < { NUM_SAMPLES_SQRT} ; ++v) {
216+ result += { DECODE_FUNC}({ SOURCE_FUNC} (normalize(t +
217+ tu * (u / { NUM_SAMPLES_SQRT} - 0.5) +
218+ tv * (v / { NUM_SAMPLES_SQRT} - 0.5))));
222219 }
223220 }
224- return ENCODE_FUNC(result / (NUM_SAMPLES_SQRT * NUM_SAMPLES_SQRT));
221+ return { ENCODE_FUNC} (result / ({ NUM_SAMPLES_SQRT} * { NUM_SAMPLES_SQRT} ));
225222 }
226223}
227224
@@ -245,42 +242,42 @@ vec4 unpackFloat = vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0);
245242 // convolve an environment given pre-generated samples
246243 vec4 prefilterSamples() {
247244 // construct vector space given target direction
248- mat3 vecSpace = matrixFromVectorSlow(TARGET_FUNC());
245+ mat3 vecSpace = matrixFromVectorSlow({ TARGET_FUNC} ());
249246
250247 vec3 L;
251248 float mipLevel;
252249
253250 vec3 result = vec3(0.0);
254251 float totalWeight = 0.0;
255- for (int i = 0; i < NUM_SAMPLES; ++i) {
252+ for (int i = 0; i < { NUM_SAMPLES} ; ++i) {
256253 unpackSample(i, L, mipLevel);
257- result += DECODE_FUNC( SOURCE_FUNC(vecSpace * L, mipLevel)) * L.z;
254+ result += { DECODE_FUNC}({ SOURCE_FUNC} (vecSpace * L, mipLevel)) * L.z;
258255 totalWeight += L.z;
259256 }
260257
261- return ENCODE_FUNC(result / totalWeight);
258+ return { ENCODE_FUNC} (result / totalWeight);
262259 }
263260
264261 // unweighted version of prefilterSamples
265262 vec4 prefilterSamplesUnweighted() {
266263 // construct vector space given target direction
267- mat3 vecSpace = matrixFromVectorSlow(TARGET_FUNC());
264+ mat3 vecSpace = matrixFromVectorSlow({ TARGET_FUNC} ());
268265
269266 vec3 L;
270267 float mipLevel;
271268
272269 vec3 result = vec3(0.0);
273270 float totalWeight = 0.0;
274- for (int i = 0; i < NUM_SAMPLES; ++i) {
271+ for (int i = 0; i < { NUM_SAMPLES} ; ++i) {
275272 unpackSample(i, L, mipLevel);
276- result += DECODE_FUNC( SOURCE_FUNC(vecSpace * L, mipLevel));
273+ result += { DECODE_FUNC}({ SOURCE_FUNC} (vecSpace * L, mipLevel));
277274 }
278275
279- return ENCODE_FUNC(result / float(NUM_SAMPLES));
276+ return { ENCODE_FUNC} (result / float({ NUM_SAMPLES} ));
280277 }
281278#endif
282279
283280void main(void) {
284- gl_FragColor = PROCESS_FUNC();
281+ gl_FragColor = { PROCESS_FUNC} ();
285282}
286283` ;
0 commit comments