@zephyr3d/scene 0.5.0 → 0.6.1
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/README.md +1 -1
- package/dist/animation/animationset.js +37 -37
- package/dist/animation/morphtrack.js +7 -5
- package/dist/animation/morphtrack.js.map +1 -1
- package/dist/animation/skeleton.js +11 -9
- package/dist/animation/skeleton.js.map +1 -1
- package/dist/asset/assetmanager.js +2 -2
- package/dist/asset/loaders/gltf/gltf_loader.js +7 -3
- package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -1
- package/dist/asset/loaders/image/webimage_loader.js +16 -0
- package/dist/asset/loaders/image/webimage_loader.js.map +1 -1
- package/dist/asset/model.js +3 -9
- package/dist/asset/model.js.map +1 -1
- package/dist/blitter/bilateralblur.js +222 -0
- package/dist/{render/temporalcache.js.map → blitter/bilateralblur.js.map} +1 -1
- package/dist/blitter/blitter.js +7 -1
- package/dist/blitter/blitter.js.map +1 -1
- package/dist/blitter/depthlimitedgaussion.js +96 -39
- package/dist/blitter/depthlimitedgaussion.js.map +1 -1
- package/dist/blitter/gaussianblur.js +21 -21
- package/dist/camera/camera.js +142 -1
- package/dist/camera/camera.js.map +1 -1
- package/dist/index.d.ts +1178 -745
- package/dist/index.js +11 -6
- package/dist/index.js.map +1 -1
- package/dist/material/blinn.js +9 -3
- package/dist/material/blinn.js.map +1 -1
- package/dist/material/lambert.js +6 -2
- package/dist/material/lambert.js.map +1 -1
- package/dist/material/material.js +3 -1
- package/dist/material/material.js.map +1 -1
- package/dist/material/meshmaterial.js +73 -33
- package/dist/material/meshmaterial.js.map +1 -1
- package/dist/material/mixins/albedocolor.js +5 -4
- package/dist/material/mixins/albedocolor.js.map +1 -1
- package/dist/material/mixins/lightmodel/blinnphong.js +17 -7
- package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
- package/dist/material/mixins/lightmodel/lambert.js +5 -5
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +13 -4
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js +13 -4
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
- package/dist/material/mixins/pbr/common.js +27 -15
- package/dist/material/mixins/pbr/common.js.map +1 -1
- package/dist/material/pbrmr.js +14 -3
- package/dist/material/pbrmr.js.map +1 -1
- package/dist/material/pbrsg.js +14 -3
- package/dist/material/pbrsg.js.map +1 -1
- package/dist/material/shader/helper.js +36 -21
- package/dist/material/shader/helper.js.map +1 -1
- package/dist/posteffect/bloom.js +1 -10
- package/dist/posteffect/bloom.js.map +1 -1
- package/dist/posteffect/compositor.js +43 -24
- package/dist/posteffect/compositor.js.map +1 -1
- package/dist/posteffect/fxaa.js +3 -11
- package/dist/posteffect/fxaa.js.map +1 -1
- package/dist/posteffect/grayscale.js +3 -11
- package/dist/posteffect/grayscale.js.map +1 -1
- package/dist/posteffect/posteffect.js +4 -0
- package/dist/posteffect/posteffect.js.map +1 -1
- package/dist/posteffect/sao.js +44 -24
- package/dist/posteffect/sao.js.map +1 -1
- package/dist/posteffect/ssr.js +536 -0
- package/dist/{material/lit.js.map → posteffect/ssr.js.map} +1 -1
- package/dist/posteffect/tonemap.js +3 -11
- package/dist/posteffect/tonemap.js.map +1 -1
- package/dist/posteffect/water.js +305 -337
- package/dist/posteffect/water.js.map +1 -1
- package/dist/render/abuffer_oit.js +2 -2
- package/dist/render/clipmap.js +16 -19
- package/dist/render/clipmap.js.map +1 -1
- package/dist/render/cull_visitor.js +5 -3
- package/dist/render/cull_visitor.js.map +1 -1
- package/dist/render/depthpass.js +17 -1
- package/dist/render/depthpass.js.map +1 -1
- package/dist/render/drawable_mixin.js +25 -19
- package/dist/render/drawable_mixin.js.map +1 -1
- package/dist/render/envlight.js +4 -2
- package/dist/render/envlight.js.map +1 -1
- package/dist/render/fft_wavegenerator.js +989 -0
- package/dist/{shaders/framework.js.map → render/fft_wavegenerator.js.map} +1 -1
- package/dist/render/gerstner_wavegenerator.js +265 -0
- package/dist/{material/standard.js.map → render/gerstner_wavegenerator.js.map} +1 -1
- package/dist/render/globalbindgroup_allocator.js +2 -1
- package/dist/render/globalbindgroup_allocator.js.map +1 -1
- package/dist/render/hzb.js +273 -0
- package/dist/{material/terrainlightmodel.js.map → render/hzb.js.map} +1 -1
- package/dist/render/lightpass.js +35 -3
- package/dist/render/lightpass.js.map +1 -1
- package/dist/render/objectcolorpass.js +2 -1
- package/dist/render/objectcolorpass.js.map +1 -1
- package/dist/render/render_queue.js +72 -52
- package/dist/render/render_queue.js.map +1 -1
- package/dist/render/renderbundle_wrapper.js +79 -0
- package/dist/render/renderbundle_wrapper.js.map +1 -1
- package/dist/render/renderer.js +75 -36
- package/dist/render/renderer.js.map +1 -1
- package/dist/render/renderpass.js +16 -13
- package/dist/render/renderpass.js.map +1 -1
- package/dist/render/shadowmap_pass.js +6 -0
- package/dist/render/shadowmap_pass.js.map +1 -1
- package/dist/render/sky.js +12 -13
- package/dist/render/sky.js.map +1 -1
- package/dist/render/watermesh.js +94 -828
- package/dist/render/watermesh.js.map +1 -1
- package/dist/render/wavegenerator.js +8 -0
- package/dist/render/wavegenerator.js.map +1 -0
- package/dist/scene/batchgroup.js +60 -14
- package/dist/scene/batchgroup.js.map +1 -1
- package/dist/scene/environment.js +2 -2
- package/dist/scene/graph_node.js +0 -5
- package/dist/scene/graph_node.js.map +1 -1
- package/dist/scene/light.js +5 -5
- package/dist/scene/mesh.js +34 -18
- package/dist/scene/mesh.js.map +1 -1
- package/dist/scene/octree.js +5 -2
- package/dist/scene/octree.js.map +1 -1
- package/dist/scene/raycast_visitor.js +4 -2
- package/dist/scene/raycast_visitor.js.map +1 -1
- package/dist/scene/scene.js +1 -1
- package/dist/scene/scene_node.js +9 -5
- package/dist/scene/scene_node.js.map +1 -1
- package/dist/scene/terrain/grass.js +3 -4
- package/dist/scene/terrain/grass.js.map +1 -1
- package/dist/scene/terrain/heightfield.js +135 -53
- package/dist/scene/terrain/heightfield.js.map +1 -1
- package/dist/scene/terrain/patch.js +3 -4
- package/dist/scene/terrain/patch.js.map +1 -1
- package/dist/scene/terrain/terrain.js +1 -1
- package/dist/scene/xform.js +7 -9
- package/dist/scene/xform.js.map +1 -1
- package/dist/shaders/misc.js +10 -1
- package/dist/shaders/misc.js.map +1 -1
- package/dist/shaders/noise.js +81 -16
- package/dist/shaders/noise.js.map +1 -1
- package/dist/shaders/shadow.js +1 -9
- package/dist/shaders/shadow.js.map +1 -1
- package/dist/shaders/ssr.js +442 -0
- package/dist/{material/terrainmat.js.map → shaders/ssr.js.map} +1 -1
- package/dist/shaders/water.js +377 -250
- package/dist/shaders/water.js.map +1 -1
- package/dist/shadow/shadowmapper.js +11 -11
- package/dist/shapes/cylinder.js +6 -5
- package/dist/shapes/cylinder.js.map +1 -1
- package/dist/utility/bounding_volume.js +1 -53
- package/dist/utility/bounding_volume.js.map +1 -1
- package/dist/utility/misc.js +93 -0
- package/dist/utility/misc.js.map +1 -0
- package/dist/utility/shprojection.js +2 -7
- package/dist/utility/shprojection.js.map +1 -1
- package/dist/utility/textures/ggxlut.js +213 -0
- package/dist/utility/textures/ggxlut.js.map +1 -0
- package/dist/utility/textures/gradientnoise.js +61 -0
- package/dist/utility/textures/gradientnoise.js.map +1 -0
- package/dist/utility/textures/randomnoise.js +41 -0
- package/dist/utility/textures/randomnoise.js.map +1 -0
- package/dist/values.js +8 -1
- package/dist/values.js.map +1 -1
- package/package.json +4 -8
- package/dist/animation/usertrack.js +0 -47
- package/dist/animation/usertrack.js.map +0 -1
- package/dist/material/grassmat.js +0 -127
- package/dist/material/grassmat.js.map +0 -1
- package/dist/material/lightmodel.js +0 -2074
- package/dist/material/lightmodel.js.map +0 -1
- package/dist/material/lit.js +0 -578
- package/dist/material/mixins/pbr/metallicroughness.js +0 -126
- package/dist/material/mixins/pbr/metallicroughness.js.map +0 -1
- package/dist/material/mixins/pbr/specularglossness.js +0 -104
- package/dist/material/mixins/pbr/specularglossness.js.map +0 -1
- package/dist/material/pbr.js +0 -27
- package/dist/material/pbr.js.map +0 -1
- package/dist/material/standard.js +0 -282
- package/dist/material/terrainlightmodel.js +0 -259
- package/dist/material/terrainmat.js +0 -357
- package/dist/render/depth_pass.js +0 -47
- package/dist/render/depth_pass.js.map +0 -1
- package/dist/render/forward.js +0 -186
- package/dist/render/forward.js.map +0 -1
- package/dist/render/forward_pass.js +0 -137
- package/dist/render/forward_pass.js.map +0 -1
- package/dist/render/helper.js +0 -38
- package/dist/render/helper.js.map +0 -1
- package/dist/render/objectpool.js +0 -295
- package/dist/render/objectpool.js.map +0 -1
- package/dist/render/renderscheme.js +0 -61
- package/dist/render/renderscheme.js.map +0 -1
- package/dist/render/temporalcache.js +0 -222
- package/dist/scene/model.js +0 -111
- package/dist/scene/model.js.map +0 -1
- package/dist/scene/octree_update_visitor.js +0 -20
- package/dist/scene/octree_update_visitor.js.map +0 -1
- package/dist/shaders/builtins.js +0 -110
- package/dist/shaders/builtins.js.map +0 -1
- package/dist/shaders/framework.js +0 -723
- package/dist/shaders/lighting.js +0 -335
- package/dist/shaders/lighting.js.map +0 -1
- package/dist/utility/sheenlut.js +0 -196
- package/dist/utility/sheenlut.js.map +0 -1
package/dist/shaders/lighting.js
DELETED
|
@@ -1,335 +0,0 @@
|
|
|
1
|
-
import { PBInsideFunctionScope } from '@zephyr3d/device';
|
|
2
|
-
import { RENDER_PASS_TYPE_FORWARD, LIGHT_TYPE_DIRECTIONAL, LIGHT_TYPE_POINT, LIGHT_TYPE_SPOT } from '../values.js';
|
|
3
|
-
import { ShaderFramework } from './framework.js';
|
|
4
|
-
import { nonLinearDepthToLinear } from './misc.js';
|
|
5
|
-
import { Application } from '../app.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Calculate lighting for forward renderer
|
|
9
|
-
*
|
|
10
|
-
* @param scope - Current shader scope
|
|
11
|
-
* @param lm - The light model
|
|
12
|
-
* @param ctx - The drawing context
|
|
13
|
-
* @returns The final color
|
|
14
|
-
*/ function forwardComputeLighting(scope, lm, ctx) {
|
|
15
|
-
const env = ctx.drawEnvLight ? ctx.env.light.envLight : null;
|
|
16
|
-
const funcNameIllumPointLight = 'stdmat_illumPointLight';
|
|
17
|
-
const funcNameIllumDirectionalLight = 'stdmat_illumDirectionalLight';
|
|
18
|
-
const funcNameIllumSpotLight = 'stdmat_illumSpotLight';
|
|
19
|
-
const funcNameIllumDirectionalShadowLight = 'stdmat_illumDirectionalShadowLight';
|
|
20
|
-
const funcNameIllumPointShadowLight = 'stdmat_illumPointShadowLight';
|
|
21
|
-
const funcNameIllumCascadedShadowLight = 'stdmat_illumCascadedShadowLight';
|
|
22
|
-
const funcNameIllumUnshadowedLights = 'stdmat_illumUnshadowedLights';
|
|
23
|
-
const funcNameGetClusterIndex = 'stdmat_getClusterIndex';
|
|
24
|
-
const funcNameIllumOneLight = 'stdmat_illumOneLight';
|
|
25
|
-
const funcNameComputeLighting = 'stdmat_computeLighting';
|
|
26
|
-
const pb = scope.$builder;
|
|
27
|
-
if (!scope || !(scope instanceof PBInsideFunctionScope)) {
|
|
28
|
-
throw new Error('forwardComputeLighting() failed: forwardComputeLighting() must be called inside a function');
|
|
29
|
-
}
|
|
30
|
-
if (ctx.renderPass.type !== RENDER_PASS_TYPE_FORWARD) {
|
|
31
|
-
throw new Error(`forwardComputeLighting() failed: invalid render pass type: ${ctx.renderPass.type}`);
|
|
32
|
-
}
|
|
33
|
-
function illumPointLight(lm, ...args) {
|
|
34
|
-
pb.func(funcNameIllumPointLight, [
|
|
35
|
-
pb.vec4('lightPositionRange'),
|
|
36
|
-
pb.vec4('lightDirectionCutoff'),
|
|
37
|
-
pb.vec3('lightDir'),
|
|
38
|
-
pb.vec3('attenuation')
|
|
39
|
-
], function() {
|
|
40
|
-
this.$l.dist = pb.distance(this.lightPositionRange.xyz, ShaderFramework.getWorldPosition(this).xyz);
|
|
41
|
-
this.$l.a = pb.div(1, pb.add(1, pb.mul(this.dist, this.dist)));
|
|
42
|
-
this.$l.falloff = pb.mul(this.a, pb.clamp(pb.sub(1, pb.div(this.dist, this.lightPositionRange.w)), 0, 1));
|
|
43
|
-
//this.$l.t = pb.div(pb.mul(this.dist, 16), this.lightPositionRange.w);
|
|
44
|
-
//this.$l.falloff = pb.div(1, pb.add(1, pb.mul(this.t, this.t)));
|
|
45
|
-
//this.$l.falloff = pb.div(1, ) pb.max(0, pb.sub(1, pb.div(this.dist, this.lightPositionRange.w)));
|
|
46
|
-
//this.falloff = pb.mul(this.falloff, this.falloff);
|
|
47
|
-
this.$if(pb.greaterThan(this.falloff, 0), function() {
|
|
48
|
-
lm.directBRDF(this, this.lightDir, pb.mul(this.attenuation, this.falloff));
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
pb.getGlobalScope()[funcNameIllumPointLight](...args);
|
|
52
|
-
}
|
|
53
|
-
function illumDirectionalLight(lm, ...args) {
|
|
54
|
-
pb.func(funcNameIllumDirectionalLight, [
|
|
55
|
-
pb.vec4('lightPositionRange'),
|
|
56
|
-
pb.vec4('lightDirectionCutoff'),
|
|
57
|
-
pb.vec3('lightDir'),
|
|
58
|
-
pb.vec3('attenuation')
|
|
59
|
-
], function() {
|
|
60
|
-
lm.directBRDF(this, this.lightDir, this.attenuation);
|
|
61
|
-
});
|
|
62
|
-
pb.getGlobalScope()[funcNameIllumDirectionalLight](...args);
|
|
63
|
-
}
|
|
64
|
-
function illumSpotLight(lm, ...args) {
|
|
65
|
-
pb.func(funcNameIllumSpotLight, [
|
|
66
|
-
pb.vec4('lightPositionRange'),
|
|
67
|
-
pb.vec4('lightDirectionCutoff'),
|
|
68
|
-
pb.vec3('lightDir'),
|
|
69
|
-
pb.vec3('attenuation')
|
|
70
|
-
], function() {
|
|
71
|
-
this.$l.spotFactor = pb.dot(this.lightDir, this.lightDirectionCutoff.xyz);
|
|
72
|
-
this.spotFactor = pb.smoothStep(this.lightDirectionCutoff.w, pb.mix(this.lightDirectionCutoff.w, 1, 0.5), this.spotFactor);
|
|
73
|
-
this.$if(pb.greaterThan(this.spotFactor, 0), function() {
|
|
74
|
-
illumPointLight(lm, this.lightPositionRange, this.lightDirectionCutoff, this.lightDir, pb.mul(this.attenuation, this.spotFactor));
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
pb.getGlobalScope()[funcNameIllumSpotLight](...args);
|
|
78
|
-
}
|
|
79
|
-
function illumLight(scope, lightType, lm, ...args) {
|
|
80
|
-
if (typeof lightType === 'number') {
|
|
81
|
-
if (lightType === LIGHT_TYPE_DIRECTIONAL) {
|
|
82
|
-
illumDirectionalLight(lm, ...args);
|
|
83
|
-
} else if (lightType === LIGHT_TYPE_POINT) {
|
|
84
|
-
illumPointLight(lm, ...args);
|
|
85
|
-
} else if (lightType === LIGHT_TYPE_SPOT) {
|
|
86
|
-
illumSpotLight(lm, ...args);
|
|
87
|
-
}
|
|
88
|
-
} else {
|
|
89
|
-
scope.$if(pb.equal(lightType, LIGHT_TYPE_DIRECTIONAL), function() {
|
|
90
|
-
illumDirectionalLight(lm, ...args);
|
|
91
|
-
}).$elseif(pb.equal(lightType, LIGHT_TYPE_POINT), function() {
|
|
92
|
-
illumPointLight(lm, ...args);
|
|
93
|
-
}).$elseif(pb.equal(lightType, LIGHT_TYPE_SPOT), function() {
|
|
94
|
-
illumSpotLight(lm, ...args);
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
function illumDirectionalShadowLight(lightType, lm) {
|
|
99
|
-
pb.func(funcNameIllumDirectionalShadowLight, [], function() {
|
|
100
|
-
this.$l.positionRange = scope.global.light.positionAndRange; //ShaderFramework.getLightPositionAndRange(this, 0);
|
|
101
|
-
this.$l.directionCutoff = scope.global.light.directionAndCutoff; //ShaderFramework.getLightDirectionAndCutoff(this, 0);
|
|
102
|
-
this.$l.diffuseIntensity = scope.global.light.diffuseAndIntensity; //ShaderFramework.getLightColorAndIntensity(this, 0);
|
|
103
|
-
this.$l.lightcolor = pb.mul(this.diffuseIntensity.xyz, this.diffuseIntensity.w);
|
|
104
|
-
this.$l.lightDir = pb.vec3();
|
|
105
|
-
this.$l.nl = pb.float();
|
|
106
|
-
this.$l.NdotL = pb.float();
|
|
107
|
-
if (lightType === LIGHT_TYPE_DIRECTIONAL) {
|
|
108
|
-
this.lightDir = this.directionCutoff.xyz;
|
|
109
|
-
this.nl = pb.dot(this.surfaceData.normal, this.lightDir);
|
|
110
|
-
this.NdotL = pb.clamp(pb.neg(this.nl), 0, 1);
|
|
111
|
-
} else {
|
|
112
|
-
this.lightDir = pb.sub(ShaderFramework.getWorldPosition(this).xyz, this.positionRange.xyz);
|
|
113
|
-
this.lightDir = pb.normalize(this.lightDir);
|
|
114
|
-
this.nl = pb.dot(this.surfaceData.normal, this.lightDir);
|
|
115
|
-
this.NdotL = pb.clamp(pb.neg(this.nl), 0, 1);
|
|
116
|
-
}
|
|
117
|
-
this.shadowVertex = ShaderFramework.calculateShadowSpaceVertex(this);
|
|
118
|
-
const shadowMapParams = ctx.shadowMapInfo.get(ctx.currentShadowLight);
|
|
119
|
-
this.$l.shadow = shadowMapParams.impl.computeShadow(shadowMapParams, this, this.shadowVertex, this.NdotL);
|
|
120
|
-
this.$l.shadowDistance = ShaderFramework.getShadowCameraParams(scope).w;
|
|
121
|
-
this.shadow = pb.mix(this.shadow, 1, pb.smoothStep(pb.mul(this.shadowDistance, 0.8), this.shadowDistance, pb.distance(ShaderFramework.getCameraPosition(this), ShaderFramework.getWorldPosition(this).xyz)));
|
|
122
|
-
// TODO: cannot early exit, shoud make computeShadow() running in non-uniform control flow
|
|
123
|
-
if (lightType !== LIGHT_TYPE_DIRECTIONAL) {
|
|
124
|
-
this.$if(pb.greaterThan(pb.length(this.lightDir), this.positionRange.w), function() {
|
|
125
|
-
this.$return();
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
this.$if(pb.greaterThan(this.NdotL, 0), function() {
|
|
129
|
-
this.$l.attenuation = pb.mul(pb.mul(this.lightcolor, this.NdotL), pb.vec3(this.shadow));
|
|
130
|
-
illumLight(this, lightType, lm, this.positionRange, this.directionCutoff, this.lightDir, this.attenuation);
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
pb.getGlobalScope()[funcNameIllumDirectionalShadowLight]();
|
|
134
|
-
}
|
|
135
|
-
function illumPointShadowLight(lm) {
|
|
136
|
-
pb.func(funcNameIllumPointShadowLight, [], function() {
|
|
137
|
-
const worldPos = ShaderFramework.getWorldPosition(this);
|
|
138
|
-
this.$l.positionRange = scope.global.light.positionAndRange; //ShaderFramework.getLightPositionAndRange(this, 0);
|
|
139
|
-
this.$l.directionCutoff = scope.global.light.directionAndCutoff; //ShaderFramework.getLightDirectionAndCutoff(this, 0);
|
|
140
|
-
this.$l.diffuseIntensity = scope.global.light.diffuseAndIntensity; //ShaderFramework.getLightColorAndIntensity(this, 0);
|
|
141
|
-
this.$l.lightcolor = pb.mul(this.diffuseIntensity.xyz, this.diffuseIntensity.w);
|
|
142
|
-
this.$l.lightDir = pb.sub(worldPos.xyz, this.positionRange.xyz);
|
|
143
|
-
this.$if(pb.greaterThan(pb.length(this.lightDir), this.positionRange.w), function() {
|
|
144
|
-
this.$return();
|
|
145
|
-
});
|
|
146
|
-
this.lightDir = pb.normalize(this.lightDir);
|
|
147
|
-
this.$l.nl = pb.dot(this.surfaceData.normal, this.lightDir);
|
|
148
|
-
this.$l.NdotL = pb.clamp(pb.neg(this.nl), 0, 1);
|
|
149
|
-
this.shadowBound = pb.vec4(0, 0, 1, 1);
|
|
150
|
-
this.shadowVertex = ShaderFramework.calculateShadowSpaceVertex(this);
|
|
151
|
-
const shadowMapParams = ctx.shadowMapInfo.get(ctx.currentShadowLight);
|
|
152
|
-
this.$l.shadow = shadowMapParams.impl.computeShadow(shadowMapParams, this, this.shadowVertex, this.NdotL);
|
|
153
|
-
this.$l.shadowDistance = ShaderFramework.getShadowCameraParams(scope).w;
|
|
154
|
-
this.shadow = pb.mix(this.shadow, 1, pb.smoothStep(pb.mul(this.shadowDistance, 0.8), this.shadowDistance, pb.distance(ShaderFramework.getCameraPosition(this), ShaderFramework.getWorldPosition(this).xyz)));
|
|
155
|
-
this.$if(pb.greaterThan(this.NdotL, 0), function() {
|
|
156
|
-
this.$l.attenuation = pb.mul(pb.mul(this.lightcolor, this.NdotL), pb.vec3(this.shadow));
|
|
157
|
-
illumLight(this, LIGHT_TYPE_POINT, lm, this.positionRange, this.directionCutoff, this.lightDir, this.attenuation);
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
pb.getGlobalScope()[funcNameIllumPointShadowLight]();
|
|
161
|
-
}
|
|
162
|
-
function illumCascadedShadowLight(lm) {
|
|
163
|
-
pb.func(funcNameIllumCascadedShadowLight, [], function() {
|
|
164
|
-
this.$l.shadowCascades = this.global.light.shadowCascades; //ShaderFramework.getLightInfo(this, 0).y;
|
|
165
|
-
this.$l.positionRange = this.global.light.positionAndRange; //ShaderFramework.getLightPositionAndRange(this, 0);
|
|
166
|
-
this.$l.directionCutoff = this.global.light.directionAndCutoff; //ShaderFramework.getLightDirectionAndCutoff(this, 0);
|
|
167
|
-
this.$l.diffuseIntensity = this.global.light.diffuseAndIntensity; //ShaderFramework.getLightColorAndIntensity(this, 0);
|
|
168
|
-
this.$l.lightcolor = pb.mul(this.diffuseIntensity.xyz, this.diffuseIntensity.w);
|
|
169
|
-
this.$l.lightDir = pb.vec3();
|
|
170
|
-
this.lightDir = this.directionCutoff.xyz;
|
|
171
|
-
this.$l.nl = pb.dot(this.surfaceData.normal, this.lightDir);
|
|
172
|
-
this.$l.NdotL = pb.clamp(pb.neg(this.nl), 0, 1);
|
|
173
|
-
this.$l.shadowBound = pb.vec4(0, 0, 1, 1);
|
|
174
|
-
this.$l.linearDepth = nonLinearDepthToLinear(this, this.$builtins.fragCoord.z);
|
|
175
|
-
this.$l.splitDistances = ShaderFramework.getCascadeDistances(this);
|
|
176
|
-
this.$l.comparison = pb.vec4(pb.greaterThan(pb.vec4(this.linearDepth), this.splitDistances));
|
|
177
|
-
this.$l.cascadeFlags = pb.vec4(pb.float(pb.greaterThan(this.shadowCascades, 0)), pb.float(pb.greaterThan(this.shadowCascades, 1)), pb.float(pb.greaterThan(this.shadowCascades, 2)), pb.float(pb.greaterThan(this.shadowCascades, 3)));
|
|
178
|
-
this.$l.split = pb.int(pb.dot(this.comparison, this.cascadeFlags));
|
|
179
|
-
this.$l.shadowVertex = pb.vec4();
|
|
180
|
-
if (Application.instance.device.type === 'webgl') {
|
|
181
|
-
this.$for(pb.int('cascade'), 0, 4, function() {
|
|
182
|
-
this.$if(pb.equal(this.cascade, this.split), function() {
|
|
183
|
-
this.shadowVertex = ShaderFramework.calculateShadowSpaceVertex(this, this.cascade);
|
|
184
|
-
this.$break();
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
} else {
|
|
188
|
-
this.shadowVertex = ShaderFramework.calculateShadowSpaceVertex(this, this.split);
|
|
189
|
-
}
|
|
190
|
-
const shadowMapParams = ctx.shadowMapInfo.get(ctx.currentShadowLight);
|
|
191
|
-
this.$l.shadow = shadowMapParams.impl.computeShadowCSM(shadowMapParams, this, this.shadowVertex, this.NdotL, this.split);
|
|
192
|
-
this.$l.shadowDistance = ShaderFramework.getShadowCameraParams(scope).w;
|
|
193
|
-
this.shadow = pb.mix(this.shadow, 1, pb.smoothStep(pb.mul(this.shadowDistance, 0.8), this.shadowDistance, pb.distance(ShaderFramework.getCameraPosition(this), ShaderFramework.getWorldPosition(this).xyz)));
|
|
194
|
-
this.$if(pb.greaterThan(this.NdotL, 0), function() {
|
|
195
|
-
this.$l.attenuation = pb.mul(pb.mul(this.lightcolor, this.NdotL), pb.vec3(this.shadow));
|
|
196
|
-
illumLight(this, LIGHT_TYPE_DIRECTIONAL, lm, this.positionRange, this.directionCutoff, this.lightDir, this.attenuation);
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
pb.getGlobalScope()[funcNameIllumCascadedShadowLight]();
|
|
200
|
-
}
|
|
201
|
-
function illumOneLight(lm, positionRange, directionCutoff, diffuseIntensity) {
|
|
202
|
-
pb.func(funcNameIllumOneLight, [
|
|
203
|
-
pb.vec4('positionRange'),
|
|
204
|
-
pb.vec4('directionCutoff'),
|
|
205
|
-
pb.vec4('diffuseIntensity')
|
|
206
|
-
], function() {
|
|
207
|
-
this.$l.lightcolor = pb.mul(this.diffuseIntensity.xyz, this.diffuseIntensity.w);
|
|
208
|
-
this.$l.lightDir = pb.vec3();
|
|
209
|
-
this.$l.nl = pb.float();
|
|
210
|
-
this.$l.NdotL = pb.float();
|
|
211
|
-
this.$l.lightType = pb.int();
|
|
212
|
-
this.$if(pb.lessThan(this.positionRange.w, 0), function() {
|
|
213
|
-
this.lightDir = this.directionCutoff.xyz;
|
|
214
|
-
this.nl = pb.dot(this.surfaceData.normal, this.lightDir);
|
|
215
|
-
this.NdotL = pb.clamp(pb.neg(this.nl), 0, 1);
|
|
216
|
-
this.lightType = LIGHT_TYPE_DIRECTIONAL;
|
|
217
|
-
}).$else(function() {
|
|
218
|
-
this.lightDir = pb.sub(ShaderFramework.getWorldPosition(this).xyz, this.positionRange.xyz);
|
|
219
|
-
this.$if(pb.greaterThan(pb.length(this.lightDir), this.positionRange.w), function() {
|
|
220
|
-
this.$return();
|
|
221
|
-
});
|
|
222
|
-
this.lightDir = pb.normalize(this.lightDir);
|
|
223
|
-
this.nl = pb.dot(this.surfaceData.normal, this.lightDir);
|
|
224
|
-
this.NdotL = pb.clamp(pb.neg(this.nl), 0, 1);
|
|
225
|
-
this.$if(pb.lessThan(this.directionCutoff.w, 0), function() {
|
|
226
|
-
this.lightType = LIGHT_TYPE_POINT;
|
|
227
|
-
}).$else(function() {
|
|
228
|
-
this.lightType = LIGHT_TYPE_SPOT;
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
this.$if(pb.greaterThan(this.NdotL, 0), function() {
|
|
232
|
-
illumLight(this, this.lightType, lm, this.positionRange, this.directionCutoff, this.lightDir, pb.mul(this.lightcolor, this.NdotL));
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
pb.getGlobalScope()[funcNameIllumOneLight](positionRange, directionCutoff, diffuseIntensity);
|
|
236
|
-
}
|
|
237
|
-
function getClusterIndex(fragCoord) {
|
|
238
|
-
pb.func(funcNameGetClusterIndex, [
|
|
239
|
-
pb.vec3('fragCoord')
|
|
240
|
-
], function() {
|
|
241
|
-
const clusterParams = ShaderFramework.getClusterParams(this);
|
|
242
|
-
const countParams = ShaderFramework.getCountParams(this);
|
|
243
|
-
this.$l.zTile = pb.int(pb.max(pb.add(pb.mul(pb.log2(nonLinearDepthToLinear(this, this.fragCoord.z)), clusterParams.z), clusterParams.w), 0));
|
|
244
|
-
this.$l.f = pb.vec2(this.fragCoord.x, pb.sub(clusterParams.y, pb.add(this.fragCoord.y, 1)));
|
|
245
|
-
this.$l.xyTile = pb.ivec2(pb.div(this.f, pb.div(clusterParams.xy, pb.vec2(countParams.xy))));
|
|
246
|
-
this.$return(pb.ivec3(this.xyTile, this.zTile));
|
|
247
|
-
});
|
|
248
|
-
return pb.getGlobalScope()[funcNameGetClusterIndex](fragCoord);
|
|
249
|
-
}
|
|
250
|
-
function illumUnshadowedLights(lm) {
|
|
251
|
-
pb.func(funcNameIllumUnshadowedLights, [], function() {
|
|
252
|
-
const countParams = ShaderFramework.getCountParams(this);
|
|
253
|
-
this.$l.cluster = getClusterIndex(this.$builtins.fragCoord.xyz);
|
|
254
|
-
this.$l.clusterIndex = pb.add(this.cluster.x, pb.mul(this.cluster.y, countParams.x), pb.mul(this.cluster.z, countParams.x, countParams.y));
|
|
255
|
-
this.$l.texSize = this.global.light.lightIndexTexSize;
|
|
256
|
-
if (pb.getDevice().type === 'webgl') {
|
|
257
|
-
this.$l.texCoordX = pb.div(pb.add(pb.mod(pb.float(this.clusterIndex), pb.float(this.texSize.x)), 0.5), pb.float(this.texSize.x));
|
|
258
|
-
this.$l.texCoordY = pb.div(pb.add(pb.float(pb.div(this.clusterIndex, this.texSize.x)), 0.5), pb.float(this.texSize.y));
|
|
259
|
-
this.$l.samp = pb.textureSample(ShaderFramework.getClusteredLightIndexTexture(this), pb.vec2(this.texCoordX, this.texCoordY));
|
|
260
|
-
} else {
|
|
261
|
-
// this.$l.texSize = pb.ivec2(pb.textureDimensions(ShaderFramework.getClusteredLightIndexTexture(this), 0));
|
|
262
|
-
this.$l.texCoordX = pb.mod(this.clusterIndex, this.texSize.x);
|
|
263
|
-
this.$l.texCoordY = pb.div(this.clusterIndex, this.texSize.x);
|
|
264
|
-
this.$l.samp = pb.textureLoad(ShaderFramework.getClusteredLightIndexTexture(this), pb.ivec2(this.texCoordX, this.texCoordY), 0);
|
|
265
|
-
}
|
|
266
|
-
if (pb.getDevice().type === 'webgl') {
|
|
267
|
-
this.$for(pb.int('i'), 0, 4, function() {
|
|
268
|
-
this.$l.k = this.samp.at(this.i);
|
|
269
|
-
this.$l.lights = pb.int[2]();
|
|
270
|
-
this.$l.lights[0] = pb.int(pb.mod(this.k, 256));
|
|
271
|
-
this.$l.lights[1] = pb.int(pb.div(this.k, 256));
|
|
272
|
-
this.$for(pb.int('k'), 0, 2, function() {
|
|
273
|
-
this.$l.li = this.lights.at(this.k);
|
|
274
|
-
this.$if(pb.greaterThan(this.li, 0), function() {
|
|
275
|
-
this.$for(pb.int('j'), 1, 256, function() {
|
|
276
|
-
this.$if(pb.equal(this.j, this.li), function() {
|
|
277
|
-
this.$l.positionRange = ShaderFramework.getLightPositionAndRange(this, this.j);
|
|
278
|
-
this.$l.directionCutoff = ShaderFramework.getLightDirectionAndCutoff(this, this.j);
|
|
279
|
-
this.$l.diffuseIntensity = ShaderFramework.getLightColorAndIntensity(this, this.j);
|
|
280
|
-
illumOneLight(lm, this.positionRange, this.directionCutoff, this.diffuseIntensity);
|
|
281
|
-
this.$break();
|
|
282
|
-
});
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
});
|
|
286
|
-
});
|
|
287
|
-
} else {
|
|
288
|
-
this.$for(pb.uint('i'), 0, 4, function() {
|
|
289
|
-
this.$for(pb.uint('k'), 0, 4, function() {
|
|
290
|
-
this.$l.c = pb.compAnd(pb.sar(this.samp.at(this.i), pb.mul(this.k, 8)), 0xff);
|
|
291
|
-
this.$if(pb.greaterThan(this.c, 0), function() {
|
|
292
|
-
this.$l.positionRange = ShaderFramework.getLightPositionAndRange(this, this.c);
|
|
293
|
-
this.$l.directionCutoff = ShaderFramework.getLightDirectionAndCutoff(this, this.c);
|
|
294
|
-
this.$l.diffuseIntensity = ShaderFramework.getLightColorAndIntensity(this, this.c);
|
|
295
|
-
illumOneLight(lm, this.positionRange, this.directionCutoff, this.diffuseIntensity);
|
|
296
|
-
});
|
|
297
|
-
});
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
pb.getGlobalScope()[funcNameIllumUnshadowedLights]();
|
|
302
|
-
}
|
|
303
|
-
pb.func(funcNameComputeLighting, [], function() {
|
|
304
|
-
const worldPosition = ShaderFramework.getWorldPosition(this);
|
|
305
|
-
const worldNormal = ShaderFramework.getWorldNormal(this);
|
|
306
|
-
const worldTangent = ShaderFramework.getWorldTangent(this);
|
|
307
|
-
const worldBinormal = ShaderFramework.getWorldBinormal(this);
|
|
308
|
-
lm.getSurfaceData(this, env, worldPosition, worldNormal, worldTangent, worldBinormal);
|
|
309
|
-
ShaderFramework.discardIfClipped(this);
|
|
310
|
-
if (lm.supportLighting()) {
|
|
311
|
-
if (env) {
|
|
312
|
-
lm.envBRDF(env, this);
|
|
313
|
-
}
|
|
314
|
-
if (ctx.currentShadowLight) {
|
|
315
|
-
const shadowMapParams = ctx.shadowMapInfo.get(ctx.currentShadowLight);
|
|
316
|
-
if (shadowMapParams.numShadowCascades > 1) {
|
|
317
|
-
illumCascadedShadowLight(lm);
|
|
318
|
-
} else if (shadowMapParams.shadowMap.isTextureCube()) {
|
|
319
|
-
illumPointShadowLight(lm);
|
|
320
|
-
} else {
|
|
321
|
-
illumDirectionalShadowLight(shadowMapParams.lightType, lm);
|
|
322
|
-
}
|
|
323
|
-
} else {
|
|
324
|
-
illumUnshadowedLights(lm);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
this.$return(lm.finalComposite(this));
|
|
328
|
-
// this.$l.result = pb.add(this.lightDiffuse, this.lightSpecular);
|
|
329
|
-
// this.$return(pb.vec4(this.result, this.surfaceData.diffuse.a));
|
|
330
|
-
});
|
|
331
|
-
return pb.getGlobalScope()[funcNameComputeLighting]();
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
export { forwardComputeLighting };
|
|
335
|
-
//# sourceMappingURL=lighting.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lighting.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/utility/sheenlut.js
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { Vector3, Vector2 } from '@zephyr3d/base';
|
|
2
|
-
import { Application } from '../app.js';
|
|
3
|
-
|
|
4
|
-
const bits = new Uint32Array(1);
|
|
5
|
-
//Van der Corput radical inverse
|
|
6
|
-
function radicalInverse_VdC(i) {
|
|
7
|
-
bits[0] = i;
|
|
8
|
-
bits[0] = (bits[0] << 16 | bits[0] >> 16) >>> 0;
|
|
9
|
-
bits[0] = (bits[0] & 0x55555555) << 1 | (bits[0] & 0xaaaaaaaa) >>> 1 >>> 0;
|
|
10
|
-
bits[0] = (bits[0] & 0x33333333) << 2 | (bits[0] & 0xcccccccc) >>> 2 >>> 0;
|
|
11
|
-
bits[0] = (bits[0] & 0x0f0f0f0f) << 4 | (bits[0] & 0xf0f0f0f0) >>> 4 >>> 0;
|
|
12
|
-
bits[0] = (bits[0] & 0x00ff00ff) << 8 | (bits[0] & 0xff00ff00) >>> 8 >>> 0;
|
|
13
|
-
return bits[0] * 2.3283064365386963e-10; // / 0x100000000 or / 4294967296
|
|
14
|
-
}
|
|
15
|
-
function hammersley(i, iN, out) {
|
|
16
|
-
out.setXY(i * iN, radicalInverse_VdC(i));
|
|
17
|
-
}
|
|
18
|
-
function distributionCharlie(NdotH, roughness) {
|
|
19
|
-
// roughness = Math.max(roughness, 0.000001);
|
|
20
|
-
const invAlpha = 1 / roughness;
|
|
21
|
-
const cos2h = NdotH * NdotH;
|
|
22
|
-
const sin2h = 1 - cos2h;
|
|
23
|
-
return (2 + invAlpha) * Math.pow(sin2h, invAlpha * 0.5) / (2 * Math.PI);
|
|
24
|
-
}
|
|
25
|
-
function visibilityAshikhmin(NdotV, NdotL) {
|
|
26
|
-
return Math.min(Math.max(1 / (4 * (NdotL + NdotV - NdotL * NdotV)), 0), 1);
|
|
27
|
-
}
|
|
28
|
-
function hemisphereUniformSample(u, out) {
|
|
29
|
-
const phi = 2 * Math.PI * u.x;
|
|
30
|
-
const cosTheta = 1 - u.y;
|
|
31
|
-
const sinTheta = Math.sqrt(1 - cosTheta * cosTheta);
|
|
32
|
-
out.setXYZ(sinTheta * Math.cos(phi), sinTheta * Math.sin(phi), cosTheta);
|
|
33
|
-
}
|
|
34
|
-
function dfvCharlieUniform(NdotV, roughness, numSamples) {
|
|
35
|
-
let r = 0;
|
|
36
|
-
const V = new Vector3(Math.sqrt(1 - NdotV * NdotV), 0, NdotV);
|
|
37
|
-
const u = new Vector2();
|
|
38
|
-
const H = new Vector3();
|
|
39
|
-
const L = new Vector3();
|
|
40
|
-
for(let i = 0; i < numSamples; i++){
|
|
41
|
-
hammersley(i, 1 / numSamples, u);
|
|
42
|
-
hemisphereUniformSample(u, H);
|
|
43
|
-
Vector3.scale(H, Vector3.dot(V, H) * 2, L).subBy(V);
|
|
44
|
-
const VdotH = Math.min(Math.max(Vector3.dot(V, H), 0), 1);
|
|
45
|
-
const NdotL = Math.min(Math.max(L.z, 0), 1);
|
|
46
|
-
const NdotH = Math.min(Math.max(H.z, 0), 1);
|
|
47
|
-
if (NdotL > 0) {
|
|
48
|
-
const v = visibilityAshikhmin(NdotV, NdotL);
|
|
49
|
-
// const v = visibilityCharlie(NdotV, NdotL, roughness);
|
|
50
|
-
const d = distributionCharlie(NdotH, roughness);
|
|
51
|
-
r += v * d * NdotL * VdotH;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return r * (4 * 2 * Math.PI / numSamples);
|
|
55
|
-
}
|
|
56
|
-
const _tables = function _generateTables() {
|
|
57
|
-
// float32 to float16 helpers
|
|
58
|
-
const buffer = new ArrayBuffer(4);
|
|
59
|
-
const floatView = new Float32Array(buffer);
|
|
60
|
-
const uint32View = new Uint32Array(buffer);
|
|
61
|
-
const baseTable = new Uint32Array(512);
|
|
62
|
-
const shiftTable = new Uint32Array(512);
|
|
63
|
-
for(let i = 0; i < 256; ++i){
|
|
64
|
-
const e = i - 127;
|
|
65
|
-
// very small number (0, -0)
|
|
66
|
-
if (e < -27) {
|
|
67
|
-
baseTable[i] = 0x0000;
|
|
68
|
-
baseTable[i | 0x100] = 0x8000;
|
|
69
|
-
shiftTable[i] = 24;
|
|
70
|
-
shiftTable[i | 0x100] = 24;
|
|
71
|
-
// small number (denorm)
|
|
72
|
-
} else if (e < -14) {
|
|
73
|
-
baseTable[i] = 0x0400 >> -e - 14;
|
|
74
|
-
baseTable[i | 0x100] = 0x0400 >> -e - 14 | 0x8000;
|
|
75
|
-
shiftTable[i] = -e - 1;
|
|
76
|
-
shiftTable[i | 0x100] = -e - 1;
|
|
77
|
-
// normal number
|
|
78
|
-
} else if (e <= 15) {
|
|
79
|
-
baseTable[i] = e + 15 << 10;
|
|
80
|
-
baseTable[i | 0x100] = e + 15 << 10 | 0x8000;
|
|
81
|
-
shiftTable[i] = 13;
|
|
82
|
-
shiftTable[i | 0x100] = 13;
|
|
83
|
-
// large number (Infinity, -Infinity)
|
|
84
|
-
} else if (e < 128) {
|
|
85
|
-
baseTable[i] = 0x7c00;
|
|
86
|
-
baseTable[i | 0x100] = 0xfc00;
|
|
87
|
-
shiftTable[i] = 24;
|
|
88
|
-
shiftTable[i | 0x100] = 24;
|
|
89
|
-
// stay (NaN, Infinity, -Infinity)
|
|
90
|
-
} else {
|
|
91
|
-
baseTable[i] = 0x7c00;
|
|
92
|
-
baseTable[i | 0x100] = 0xfc00;
|
|
93
|
-
shiftTable[i] = 13;
|
|
94
|
-
shiftTable[i | 0x100] = 13;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
// float16 to float32 helpers
|
|
98
|
-
const mantissaTable = new Uint32Array(2048);
|
|
99
|
-
const exponentTable = new Uint32Array(64);
|
|
100
|
-
const offsetTable = new Uint32Array(64);
|
|
101
|
-
for(let i = 1; i < 1024; ++i){
|
|
102
|
-
let m = i << 13; // zero pad mantissa bits
|
|
103
|
-
let e = 0; // zero exponent
|
|
104
|
-
// normalized
|
|
105
|
-
while((m & 0x00800000) === 0){
|
|
106
|
-
m <<= 1;
|
|
107
|
-
e -= 0x00800000; // decrement exponent
|
|
108
|
-
}
|
|
109
|
-
m &= ~0x00800000; // clear leading 1 bit
|
|
110
|
-
e += 0x38800000; // adjust bias
|
|
111
|
-
mantissaTable[i] = m | e;
|
|
112
|
-
}
|
|
113
|
-
for(let i = 1024; i < 2048; ++i){
|
|
114
|
-
mantissaTable[i] = 0x38000000 + (i - 1024 << 13);
|
|
115
|
-
}
|
|
116
|
-
for(let i = 1; i < 31; ++i){
|
|
117
|
-
exponentTable[i] = i << 23;
|
|
118
|
-
}
|
|
119
|
-
exponentTable[31] = 0x47800000;
|
|
120
|
-
exponentTable[32] = 0x80000000;
|
|
121
|
-
for(let i = 33; i < 63; ++i){
|
|
122
|
-
exponentTable[i] = 0x80000000 + (i - 32 << 23);
|
|
123
|
-
}
|
|
124
|
-
exponentTable[63] = 0xc7800000;
|
|
125
|
-
for(let i = 1; i < 64; ++i){
|
|
126
|
-
if (i !== 32) {
|
|
127
|
-
offsetTable[i] = 1024;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return {
|
|
131
|
-
floatView: floatView,
|
|
132
|
-
uint32View: uint32View,
|
|
133
|
-
baseTable: baseTable,
|
|
134
|
-
shiftTable: shiftTable,
|
|
135
|
-
mantissaTable: mantissaTable,
|
|
136
|
-
exponentTable: exponentTable,
|
|
137
|
-
offsetTable: offsetTable
|
|
138
|
-
};
|
|
139
|
-
}();
|
|
140
|
-
function encodeF16(val) {
|
|
141
|
-
val = Math.min(Math.max(val, -65504), 65504);
|
|
142
|
-
_tables.floatView[0] = val;
|
|
143
|
-
const f = _tables.uint32View[0];
|
|
144
|
-
const e = f >> 23 & 0x1ff;
|
|
145
|
-
return _tables.baseTable[e] + ((f & 0x007fffff) >> _tables.shiftTable[e]);
|
|
146
|
-
}
|
|
147
|
-
/*
|
|
148
|
-
function decodeF16(val: number) {
|
|
149
|
-
const exponent = (val & 0x7c00) >> 10;
|
|
150
|
-
const fraction = val & 0x03ff;
|
|
151
|
-
return (
|
|
152
|
-
(val >> 15 ? -1 : 1) *
|
|
153
|
-
(exponent
|
|
154
|
-
? exponent === 0x1f
|
|
155
|
-
? fraction
|
|
156
|
-
? NaN
|
|
157
|
-
: Infinity
|
|
158
|
-
: Math.pow(2, exponent - 15) * (1 + fraction / 0x400)
|
|
159
|
-
: 6.103515625e-5 * (fraction / 0x400))
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
*/ async function createSheenLUT(textureSize, texture) {
|
|
163
|
-
if (texture) {
|
|
164
|
-
if (!texture.isTexture2D()) {
|
|
165
|
-
throw new Error('can not reload sheen lut texture: invalid texture type');
|
|
166
|
-
}
|
|
167
|
-
if (texture.format !== 'rgba16f') {
|
|
168
|
-
throw new Error('can not reload sheen lut texture: invalid texture format');
|
|
169
|
-
}
|
|
170
|
-
if (texture.width !== textureSize || texture.height !== textureSize) {
|
|
171
|
-
throw new Error('can not reload sheen lut texture: invalid texture size');
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
const tex = texture || Application.instance.device.createTexture2D('rgba16f', textureSize, textureSize);
|
|
175
|
-
const image = new Uint16Array(textureSize * textureSize * 4);
|
|
176
|
-
let p = 0;
|
|
177
|
-
const one = encodeF16(1);
|
|
178
|
-
for(let y = textureSize - 1; y >= 0; y--){
|
|
179
|
-
const coord = Math.min(Math.max((y + 0.5) / textureSize, 0), 1);
|
|
180
|
-
const roughness = coord * coord;
|
|
181
|
-
for(let x = 0; x < textureSize; x++){
|
|
182
|
-
const NdotV = Math.min(Math.max((x + 0.5) / textureSize, 0), 1);
|
|
183
|
-
const c = dfvCharlieUniform(NdotV, roughness, 512);
|
|
184
|
-
const f16 = encodeF16(c);
|
|
185
|
-
image[p++] = 0;
|
|
186
|
-
image[p++] = 0;
|
|
187
|
-
image[p++] = f16;
|
|
188
|
-
image[p++] = one;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
tex.update(image, 0, 0, textureSize, textureSize);
|
|
192
|
-
return tex;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
export { createSheenLUT };
|
|
196
|
-
//# sourceMappingURL=sheenlut.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sheenlut.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|