@zephyr3d/scene 0.1.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/dist/animation/animation.js +173 -0
- package/dist/animation/animation.js.map +1 -0
- package/dist/animation/animationset.js +95 -0
- package/dist/animation/animationset.js.map +1 -0
- package/dist/animation/animationtrack.js +38 -0
- package/dist/animation/animationtrack.js.map +1 -0
- package/dist/animation/eulerrotationtrack.js +33 -0
- package/dist/animation/eulerrotationtrack.js.map +1 -0
- package/dist/animation/rotationtrack.js +37 -0
- package/dist/animation/rotationtrack.js.map +1 -0
- package/dist/animation/scaletrack.js +36 -0
- package/dist/animation/scaletrack.js.map +1 -0
- package/dist/animation/skeleton.js +97 -0
- package/dist/animation/skeleton.js.map +1 -0
- package/dist/animation/translationtrack.js +36 -0
- package/dist/animation/translationtrack.js.map +1 -0
- package/dist/animation/usertrack.js +47 -0
- package/dist/animation/usertrack.js.map +1 -0
- package/dist/app.js +173 -0
- package/dist/app.js.map +1 -0
- package/dist/asset/assetmanager.js +476 -0
- package/dist/asset/assetmanager.js.map +1 -0
- package/dist/asset/builtin.js +373 -0
- package/dist/asset/builtin.js.map +1 -0
- package/dist/asset/loaders/dds/dds.js +472 -0
- package/dist/asset/loaders/dds/dds.js.map +1 -0
- package/dist/asset/loaders/dds/dds_loader.js +38 -0
- package/dist/asset/loaders/dds/dds_loader.js.map +1 -0
- package/dist/asset/loaders/gltf/gltf_loader.js +981 -0
- package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -0
- package/dist/asset/loaders/gltf/helpers.js +314 -0
- package/dist/asset/loaders/gltf/helpers.js.map +1 -0
- package/dist/asset/loaders/hdr/hdr.js +175 -0
- package/dist/asset/loaders/hdr/hdr.js.map +1 -0
- package/dist/asset/loaders/image/tga_Loader.js +117 -0
- package/dist/asset/loaders/image/tga_Loader.js.map +1 -0
- package/dist/asset/loaders/image/webimage_loader.js +50 -0
- package/dist/asset/loaders/image/webimage_loader.js.map +1 -0
- package/dist/asset/loaders/loader.js +45 -0
- package/dist/asset/loaders/loader.js.map +1 -0
- package/dist/asset/model.js +264 -0
- package/dist/asset/model.js.map +1 -0
- package/dist/blitter/blitter.js +389 -0
- package/dist/blitter/blitter.js.map +1 -0
- package/dist/blitter/box.js +118 -0
- package/dist/blitter/box.js.map +1 -0
- package/dist/blitter/copy.js +22 -0
- package/dist/blitter/copy.js.map +1 -0
- package/dist/blitter/depthlimitedgaussion.js +166 -0
- package/dist/blitter/depthlimitedgaussion.js.map +1 -0
- package/dist/blitter/gaussianblur.js +229 -0
- package/dist/blitter/gaussianblur.js.map +1 -0
- package/dist/camera/base.js +90 -0
- package/dist/camera/base.js.map +1 -0
- package/dist/camera/camera.js +358 -0
- package/dist/camera/camera.js.map +1 -0
- package/dist/camera/fps.js +246 -0
- package/dist/camera/fps.js.map +1 -0
- package/dist/camera/orbit.js +157 -0
- package/dist/camera/orbit.js.map +1 -0
- package/dist/camera/orthocamera.js +126 -0
- package/dist/camera/orthocamera.js.map +1 -0
- package/dist/camera/perspectivecamera.js +133 -0
- package/dist/camera/perspectivecamera.js.map +1 -0
- package/dist/index.d.ts +8402 -0
- package/dist/index.js +87 -0
- package/dist/index.js.map +1 -0
- package/dist/input/inputmgr.js +242 -0
- package/dist/input/inputmgr.js.map +1 -0
- package/dist/material/blinn.js +75 -0
- package/dist/material/blinn.js.map +1 -0
- package/dist/material/grassmaterial.js +221 -0
- package/dist/material/grassmaterial.js.map +1 -0
- package/dist/material/lambert.js +52 -0
- package/dist/material/lambert.js.map +1 -0
- package/dist/material/lightmodel.js +2074 -0
- package/dist/material/lightmodel.js.map +1 -0
- package/dist/material/lit.js +578 -0
- package/dist/material/lit.js.map +1 -0
- package/dist/material/material.js +458 -0
- package/dist/material/material.js.map +1 -0
- package/dist/material/meshmaterial.js +311 -0
- package/dist/material/meshmaterial.js.map +1 -0
- package/dist/material/mixins/albedocolor.js +130 -0
- package/dist/material/mixins/albedocolor.js.map +1 -0
- package/dist/material/mixins/texture.js +110 -0
- package/dist/material/mixins/texture.js.map +1 -0
- package/dist/material/mixins/vertexcolor.js +45 -0
- package/dist/material/mixins/vertexcolor.js.map +1 -0
- package/dist/material/pbr.js +27 -0
- package/dist/material/pbr.js.map +1 -0
- package/dist/material/standard.js +282 -0
- package/dist/material/standard.js.map +1 -0
- package/dist/material/terrainlightmodel.js +259 -0
- package/dist/material/terrainlightmodel.js.map +1 -0
- package/dist/material/terrainmaterial.js +139 -0
- package/dist/material/terrainmaterial.js.map +1 -0
- package/dist/material/unlit.js +29 -0
- package/dist/material/unlit.js.map +1 -0
- package/dist/posteffect/bloom.js +398 -0
- package/dist/posteffect/bloom.js.map +1 -0
- package/dist/posteffect/compositor.js +264 -0
- package/dist/posteffect/compositor.js.map +1 -0
- package/dist/posteffect/fxaa.js +291 -0
- package/dist/posteffect/fxaa.js.map +1 -0
- package/dist/posteffect/grayscale.js +87 -0
- package/dist/posteffect/grayscale.js.map +1 -0
- package/dist/posteffect/posteffect.js +165 -0
- package/dist/posteffect/posteffect.js.map +1 -0
- package/dist/posteffect/sao.js +327 -0
- package/dist/posteffect/sao.js.map +1 -0
- package/dist/posteffect/tonemap.js +112 -0
- package/dist/posteffect/tonemap.js.map +1 -0
- package/dist/posteffect/water.js +535 -0
- package/dist/posteffect/water.js.map +1 -0
- package/dist/render/clipmap.js +462 -0
- package/dist/render/clipmap.js.map +1 -0
- package/dist/render/cluster_light.js +329 -0
- package/dist/render/cluster_light.js.map +1 -0
- package/dist/render/cull_visitor.js +124 -0
- package/dist/render/cull_visitor.js.map +1 -0
- package/dist/render/depth_pass.js +47 -0
- package/dist/render/depth_pass.js.map +1 -0
- package/dist/render/envlight.js +282 -0
- package/dist/render/envlight.js.map +1 -0
- package/dist/render/forward.js +186 -0
- package/dist/render/forward.js.map +1 -0
- package/dist/render/forward_pass.js +137 -0
- package/dist/render/forward_pass.js.map +1 -0
- package/dist/render/helper.js +38 -0
- package/dist/render/helper.js.map +1 -0
- package/dist/render/primitive.js +246 -0
- package/dist/render/primitive.js.map +1 -0
- package/dist/render/render_queue.js +163 -0
- package/dist/render/render_queue.js.map +1 -0
- package/dist/render/renderpass.js +151 -0
- package/dist/render/renderpass.js.map +1 -0
- package/dist/render/renderscheme.js +61 -0
- package/dist/render/renderscheme.js.map +1 -0
- package/dist/render/scatteringlut.js +634 -0
- package/dist/render/scatteringlut.js.map +1 -0
- package/dist/render/shadowmap_pass.js +70 -0
- package/dist/render/shadowmap_pass.js.map +1 -0
- package/dist/render/sky.js +881 -0
- package/dist/render/sky.js.map +1 -0
- package/dist/render/temporalcache.js +222 -0
- package/dist/render/temporalcache.js.map +1 -0
- package/dist/render/watermesh.js +835 -0
- package/dist/render/watermesh.js.map +1 -0
- package/dist/scene/environment.js +146 -0
- package/dist/scene/environment.js.map +1 -0
- package/dist/scene/graph_node.js +69 -0
- package/dist/scene/graph_node.js.map +1 -0
- package/dist/scene/light.js +436 -0
- package/dist/scene/light.js.map +1 -0
- package/dist/scene/mesh.js +215 -0
- package/dist/scene/mesh.js.map +1 -0
- package/dist/scene/model.js +111 -0
- package/dist/scene/model.js.map +1 -0
- package/dist/scene/octree.js +651 -0
- package/dist/scene/octree.js.map +1 -0
- package/dist/scene/octree_update_visitor.js +16 -0
- package/dist/scene/octree_update_visitor.js.map +1 -0
- package/dist/scene/raycast_visitor.js +72 -0
- package/dist/scene/raycast_visitor.js.map +1 -0
- package/dist/scene/scene.js +225 -0
- package/dist/scene/scene.js.map +1 -0
- package/dist/scene/scene_node.js +299 -0
- package/dist/scene/scene_node.js.map +1 -0
- package/dist/scene/terrain/grass.js +277 -0
- package/dist/scene/terrain/grass.js.map +1 -0
- package/dist/scene/terrain/heightfield.js +391 -0
- package/dist/scene/terrain/heightfield.js.map +1 -0
- package/dist/scene/terrain/patch.js +530 -0
- package/dist/scene/terrain/patch.js.map +1 -0
- package/dist/scene/terrain/quadtree.js +430 -0
- package/dist/scene/terrain/quadtree.js.map +1 -0
- package/dist/scene/terrain/terrain.js +258 -0
- package/dist/scene/terrain/terrain.js.map +1 -0
- package/dist/scene/xform.js +224 -0
- package/dist/scene/xform.js.map +1 -0
- package/dist/shaders/builtins.js +110 -0
- package/dist/shaders/builtins.js.map +1 -0
- package/dist/shaders/framework.js +709 -0
- package/dist/shaders/framework.js.map +1 -0
- package/dist/shaders/lighting.js +335 -0
- package/dist/shaders/lighting.js.map +1 -0
- package/dist/shaders/misc.js +405 -0
- package/dist/shaders/misc.js.map +1 -0
- package/dist/shaders/noise.js +157 -0
- package/dist/shaders/noise.js.map +1 -0
- package/dist/shaders/pbr.js +132 -0
- package/dist/shaders/pbr.js.map +1 -0
- package/dist/shaders/shadow.js +642 -0
- package/dist/shaders/shadow.js.map +1 -0
- package/dist/shaders/water.js +630 -0
- package/dist/shaders/water.js.map +1 -0
- package/dist/shadow/esm.js +235 -0
- package/dist/shadow/esm.js.map +1 -0
- package/dist/shadow/pcf_opt.js +182 -0
- package/dist/shadow/pcf_opt.js.map +1 -0
- package/dist/shadow/pcf_pd.js +190 -0
- package/dist/shadow/pcf_pd.js.map +1 -0
- package/dist/shadow/shadow_impl.js +15 -0
- package/dist/shadow/shadow_impl.js.map +1 -0
- package/dist/shadow/shadowmapper.js +709 -0
- package/dist/shadow/shadowmapper.js.map +1 -0
- package/dist/shadow/ssm.js +194 -0
- package/dist/shadow/ssm.js.map +1 -0
- package/dist/shadow/vsm.js +298 -0
- package/dist/shadow/vsm.js.map +1 -0
- package/dist/shapes/box.js +313 -0
- package/dist/shapes/box.js.map +1 -0
- package/dist/shapes/cylinder.js +74 -0
- package/dist/shapes/cylinder.js.map +1 -0
- package/dist/shapes/plane.js +48 -0
- package/dist/shapes/plane.js.map +1 -0
- package/dist/shapes/shape.js +33 -0
- package/dist/shapes/shape.js.map +1 -0
- package/dist/shapes/sphere.js +91 -0
- package/dist/shapes/sphere.js.map +1 -0
- package/dist/shapes/torus.js +100 -0
- package/dist/shapes/torus.js.map +1 -0
- package/dist/utility/aabbtree.js +390 -0
- package/dist/utility/aabbtree.js.map +1 -0
- package/dist/utility/bounding_volume.js +78 -0
- package/dist/utility/bounding_volume.js.map +1 -0
- package/dist/utility/panorama.js +163 -0
- package/dist/utility/panorama.js.map +1 -0
- package/dist/utility/pmrem.js +345 -0
- package/dist/utility/pmrem.js.map +1 -0
- package/dist/utility/shprojection.js +448 -0
- package/dist/utility/shprojection.js.map +1 -0
- package/dist/values.js +48 -0
- package/dist/values.js.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import { Vector3, Vector2 } from '@zephyr3d/base';
|
|
2
|
+
import { Application } from '../app.js';
|
|
3
|
+
|
|
4
|
+
let vertexLayout = null;
|
|
5
|
+
let renderStates = null;
|
|
6
|
+
const programs = {};
|
|
7
|
+
const faceDirections = [
|
|
8
|
+
[
|
|
9
|
+
new Vector3(0, 0, -1),
|
|
10
|
+
new Vector3(0, -1, 0),
|
|
11
|
+
new Vector3(1, 0, 0)
|
|
12
|
+
],
|
|
13
|
+
[
|
|
14
|
+
new Vector3(0, 0, 1),
|
|
15
|
+
new Vector3(0, -1, 0),
|
|
16
|
+
new Vector3(-1, 0, 0)
|
|
17
|
+
],
|
|
18
|
+
[
|
|
19
|
+
new Vector3(1, 0, 0),
|
|
20
|
+
new Vector3(0, 0, 1),
|
|
21
|
+
new Vector3(0, 1, 0)
|
|
22
|
+
],
|
|
23
|
+
[
|
|
24
|
+
new Vector3(1, 0, 0),
|
|
25
|
+
new Vector3(0, 0, -1),
|
|
26
|
+
new Vector3(0, -1, 0)
|
|
27
|
+
],
|
|
28
|
+
[
|
|
29
|
+
new Vector3(1, 0, 0),
|
|
30
|
+
new Vector3(0, -1, 0),
|
|
31
|
+
new Vector3(0, 0, 1)
|
|
32
|
+
],
|
|
33
|
+
[
|
|
34
|
+
new Vector3(-1, 0, 0),
|
|
35
|
+
new Vector3(0, -1, 0),
|
|
36
|
+
new Vector3(0, 0, -1)
|
|
37
|
+
]
|
|
38
|
+
];
|
|
39
|
+
function init() {
|
|
40
|
+
const device = Application.instance.device;
|
|
41
|
+
const vertices = new Float32Array([
|
|
42
|
+
1,
|
|
43
|
+
1,
|
|
44
|
+
-1,
|
|
45
|
+
1,
|
|
46
|
+
-1,
|
|
47
|
+
-1,
|
|
48
|
+
1,
|
|
49
|
+
-1
|
|
50
|
+
]);
|
|
51
|
+
const indices = new Uint16Array([
|
|
52
|
+
0,
|
|
53
|
+
1,
|
|
54
|
+
2,
|
|
55
|
+
0,
|
|
56
|
+
2,
|
|
57
|
+
3
|
|
58
|
+
]);
|
|
59
|
+
vertexLayout = device.createVertexLayout({
|
|
60
|
+
vertexBuffers: [
|
|
61
|
+
{
|
|
62
|
+
buffer: device.createVertexBuffer('position_f32x2', vertices)
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
indexBuffer: device.createIndexBuffer(indices)
|
|
66
|
+
});
|
|
67
|
+
renderStates = device.createRenderStateSet();
|
|
68
|
+
renderStates.useRasterizerState().setCullMode('none');
|
|
69
|
+
renderStates.useDepthState().enableTest(false).enableWrite(false);
|
|
70
|
+
}
|
|
71
|
+
function getProgramInfo(type, numSamples) {
|
|
72
|
+
const device = Application.instance.device;
|
|
73
|
+
const hash = `${type}:${numSamples}`;
|
|
74
|
+
let ret = programs[hash];
|
|
75
|
+
if (!ret) {
|
|
76
|
+
const program = createPMREMProgram(type, numSamples);
|
|
77
|
+
const bindgroup = device.createBindGroup(program.bindGroupLayouts[0]);
|
|
78
|
+
programs[hash] = ret = {
|
|
79
|
+
program,
|
|
80
|
+
bindgroup
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return ret;
|
|
84
|
+
}
|
|
85
|
+
function createPMREMProgram(type, numSamples) {
|
|
86
|
+
const device = Application.instance.device;
|
|
87
|
+
const pb = device;
|
|
88
|
+
return pb.buildRenderProgram({
|
|
89
|
+
vertex (pb) {
|
|
90
|
+
this.$inputs.pos = pb.vec2().attrib('position');
|
|
91
|
+
this.up = pb.vec3().uniform(0);
|
|
92
|
+
this.right = pb.vec3().uniform(0);
|
|
93
|
+
this.front = pb.vec3().uniform(0);
|
|
94
|
+
pb.main(function() {
|
|
95
|
+
this.$builtins.position = pb.vec4(this.$inputs.pos, 0, 1);
|
|
96
|
+
this.$outputs.direction = pb.mul(pb.mat3(this.up, this.right, this.front), pb.vec3(this.$inputs.pos, 1));
|
|
97
|
+
if (device.type === 'webgpu') {
|
|
98
|
+
this.$builtins.position.y = pb.neg(this.$builtins.position.y);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
},
|
|
102
|
+
fragment (pb) {
|
|
103
|
+
if (type === 'ggx') {
|
|
104
|
+
this.alphaG = pb.float().uniform(0);
|
|
105
|
+
}
|
|
106
|
+
this.vFilteringInfo = pb.vec2().uniform(0);
|
|
107
|
+
this.hdrScale = pb.float().uniform(0);
|
|
108
|
+
this.inputTexture = pb.texCube().uniform(0);
|
|
109
|
+
this.NUM_SAMPLES_FLOAT = pb.float(numSamples);
|
|
110
|
+
this.NUM_SAMPLES_FLOAT_INVERSED = pb.float(1 / numSamples);
|
|
111
|
+
this.K = pb.float(4);
|
|
112
|
+
this.$outputs.outcolor = pb.vec4();
|
|
113
|
+
if (device.type === 'webgl') {
|
|
114
|
+
pb.func('radicalInverse_VdC', [
|
|
115
|
+
pb.int('bits')
|
|
116
|
+
], function() {
|
|
117
|
+
this.$l.rand = pb.float(0);
|
|
118
|
+
this.$l.denom = pb.float(1);
|
|
119
|
+
this.$l.invBase = pb.float(0.5);
|
|
120
|
+
this.$l.n = this.bits;
|
|
121
|
+
this.$for(pb.int('i'), 0, 32, function() {
|
|
122
|
+
this.denom = pb.mul(this.denom, 2);
|
|
123
|
+
this.rand = pb.add(this.rand, pb.div(pb.mod(pb.float(this.n), 2), this.denom));
|
|
124
|
+
this.n = pb.div(this.n, 2);
|
|
125
|
+
this.$if(pb.equal(this.n, 0), function() {
|
|
126
|
+
this.$break();
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
this.$return(this.rand);
|
|
130
|
+
});
|
|
131
|
+
pb.func('hammersley2d', [
|
|
132
|
+
pb.int('i'),
|
|
133
|
+
pb.int('N')
|
|
134
|
+
], function() {
|
|
135
|
+
this.$return(pb.vec2(pb.div(pb.float(this.i), pb.float(this.N)), this.radicalInverse_VdC(this.i)));
|
|
136
|
+
});
|
|
137
|
+
} else {
|
|
138
|
+
pb.func('radicalInverse_VdC', [
|
|
139
|
+
pb.uint('bits')
|
|
140
|
+
], function() {
|
|
141
|
+
this.$l.n = this.bits;
|
|
142
|
+
this.n = pb.compOr(pb.sal(this.n, 16), pb.sar(this.n, 16));
|
|
143
|
+
this.n = pb.compOr(pb.sal(pb.compAnd(this.n, 0x55555555), 1), pb.sar(pb.compAnd(this.n, 0xAAAAAAAA), 1));
|
|
144
|
+
this.n = pb.compOr(pb.sal(pb.compAnd(this.n, 0x33333333), 2), pb.sar(pb.compAnd(this.n, 0xCCCCCCCC), 2));
|
|
145
|
+
this.n = pb.compOr(pb.sal(pb.compAnd(this.n, 0x0F0F0F0F), 4), pb.sar(pb.compAnd(this.n, 0xF0F0F0F0), 4));
|
|
146
|
+
this.n = pb.compOr(pb.sal(pb.compAnd(this.n, 0x00FF00FF), 8), pb.sar(pb.compAnd(this.n, 0xFF00FF00), 8));
|
|
147
|
+
this.$return(pb.mul(pb.float(this.n), 2.3283064365386963e-10));
|
|
148
|
+
});
|
|
149
|
+
pb.func('hammersley2d', [
|
|
150
|
+
pb.int('i'),
|
|
151
|
+
pb.int('N')
|
|
152
|
+
], function() {
|
|
153
|
+
this.$return(pb.vec2(pb.div(pb.float(this.i), pb.float(this.N)), this.radicalInverse_VdC(pb.uint(this.i))));
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
pb.func('log4', [
|
|
157
|
+
pb.float('x')
|
|
158
|
+
], function() {
|
|
159
|
+
this.$return(pb.mul(pb.log2(this.x), 0.5));
|
|
160
|
+
});
|
|
161
|
+
if (type === 'lambertian') {
|
|
162
|
+
pb.func('hemisphereCosSample', [
|
|
163
|
+
pb.vec2('u')
|
|
164
|
+
], function() {
|
|
165
|
+
this.$l.phi = pb.mul(this.u.x, 2 * Math.PI);
|
|
166
|
+
this.$l.cosTheta2 = pb.sub(1, this.u.y);
|
|
167
|
+
this.$l.cosTheta = pb.sqrt(this.cosTheta2);
|
|
168
|
+
this.$l.sinTheta = pb.sqrt(pb.sub(1, this.cosTheta2));
|
|
169
|
+
this.$return(pb.vec3(pb.mul(this.sinTheta, pb.cos(this.phi)), pb.mul(this.sinTheta, pb.sin(this.phi)), this.cosTheta));
|
|
170
|
+
});
|
|
171
|
+
pb.func('irradiance', [
|
|
172
|
+
pb.vec3('direction'),
|
|
173
|
+
pb.vec2('vFilteringInfo')
|
|
174
|
+
], function() {
|
|
175
|
+
this.$l.n = pb.normalize(this.direction);
|
|
176
|
+
this.$l.result = pb.vec3(0);
|
|
177
|
+
this.$l.tangent = pb.vec3();
|
|
178
|
+
this.$if(pb.lessThan(pb.abs(this.n.z), 0.999), function() {
|
|
179
|
+
this.tangent = pb.vec3(0, 0, 1);
|
|
180
|
+
}).$else(function() {
|
|
181
|
+
this.tangent = pb.vec3(1, 0, 0);
|
|
182
|
+
});
|
|
183
|
+
this.tangent = pb.normalize(pb.cross(this.tangent, this.n));
|
|
184
|
+
this.$l.bitangent = pb.cross(this.n, this.tangent);
|
|
185
|
+
this.$l.tbn = pb.mat3(this.tangent, this.bitangent, this.n);
|
|
186
|
+
this.$l.maxLevel = this.vFilteringInfo.y;
|
|
187
|
+
this.$l.dim0 = this.vFilteringInfo.x;
|
|
188
|
+
this.$l.omegaP = pb.div(4 * Math.PI, pb.mul(this.dim0, this.dim0, 6));
|
|
189
|
+
this.$for(pb.int('i'), 0, numSamples, function() {
|
|
190
|
+
this.$l.Xi = this.hammersley2d(this.i, numSamples);
|
|
191
|
+
this.$l.Ls = pb.normalize(this.hemisphereCosSample(this.Xi));
|
|
192
|
+
this.$l.Ns = pb.vec3(0, 0, 1);
|
|
193
|
+
this.$l.NoL = pb.dot(this.Ns, this.Ls);
|
|
194
|
+
this.$if(pb.greaterThan(this.NoL, 0), function() {
|
|
195
|
+
this.$l.pdf_inversed = pb.div(Math.PI, this.NoL);
|
|
196
|
+
this.$l.omegaS = pb.mul(this.pdf_inversed, this.NUM_SAMPLES_FLOAT_INVERSED);
|
|
197
|
+
this.$l.l = pb.add(pb.sub(this.log4(this.omegaS), this.log4(this.omegaP)), this.log4(this.K));
|
|
198
|
+
this.$l.mipLevel = pb.clamp(this.l, 0, this.maxLevel);
|
|
199
|
+
this.$l.c = pb.textureSampleLevel(this.inputTexture, pb.mul(this.tbn, this.Ls), this.mipLevel).rgb;
|
|
200
|
+
this.result = pb.add(this.result, this.c);
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
this.result = pb.mul(this.result, this.NUM_SAMPLES_FLOAT_INVERSED);
|
|
204
|
+
this.$return(this.result);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
if (type === 'ggx') {
|
|
208
|
+
pb.func('hemisphereImportanceSampleDggx', [
|
|
209
|
+
pb.vec2('u'),
|
|
210
|
+
pb.float('a')
|
|
211
|
+
], function() {
|
|
212
|
+
this.$l.phi = pb.mul(this.u.x, 2 * Math.PI);
|
|
213
|
+
this.$l.cosTheta2 = pb.div(pb.sub(1, this.u.y), pb.add(pb.mul(pb.add(this.a, 1), pb.sub(this.a, 1), this.u.y), 1));
|
|
214
|
+
this.$l.cosTheta = pb.sqrt(this.cosTheta2);
|
|
215
|
+
this.$l.sinTheta = pb.sqrt(pb.sub(1, this.cosTheta2));
|
|
216
|
+
this.$return(pb.vec3(pb.mul(pb.cos(this.phi), this.sinTheta), pb.mul(pb.sin(this.phi), this.sinTheta), this.cosTheta));
|
|
217
|
+
});
|
|
218
|
+
pb.func('normalDistributionFunction_TrowbridgeReitzGGX', [
|
|
219
|
+
pb.float('NoH'),
|
|
220
|
+
pb.float('alphaG')
|
|
221
|
+
], function() {
|
|
222
|
+
this.$l.a2 = pb.mul(this.alphaG, this.alphaG);
|
|
223
|
+
this.$l.d = pb.add(pb.mul(this.NoH, this.NoH, pb.sub(this.a2, 1)), 1);
|
|
224
|
+
this.$return(pb.div(this.a2, pb.mul(this.d, this.d, Math.PI)));
|
|
225
|
+
});
|
|
226
|
+
pb.func('radiance', [
|
|
227
|
+
pb.float('alphaG'),
|
|
228
|
+
pb.vec3('direction'),
|
|
229
|
+
pb.vec2('vFilteringInfo')
|
|
230
|
+
], function() {
|
|
231
|
+
this.$l.n = pb.normalize(this.direction);
|
|
232
|
+
this.$if(pb.equal(this.alphaG, 0), function() {
|
|
233
|
+
this.$l.c = pb.textureSampleLevel(this.inputTexture, this.n, 0).rgb;
|
|
234
|
+
this.$return(this.c);
|
|
235
|
+
}).$else(function() {
|
|
236
|
+
this.$l.result = pb.vec3(0);
|
|
237
|
+
this.$l.tangent = pb.vec3();
|
|
238
|
+
this.$if(pb.lessThan(pb.abs(this.n.z), 0.999), function() {
|
|
239
|
+
this.tangent = pb.vec3(0, 0, 1);
|
|
240
|
+
}).$else(function() {
|
|
241
|
+
this.tangent = pb.vec3(1, 0, 0);
|
|
242
|
+
});
|
|
243
|
+
this.tangent = pb.normalize(pb.cross(this.tangent, this.n));
|
|
244
|
+
this.$l.bitangent = pb.cross(this.n, this.tangent);
|
|
245
|
+
this.$l.tbn = pb.mat3(this.tangent, this.bitangent, this.n);
|
|
246
|
+
this.$l.maxLevel = this.vFilteringInfo.y;
|
|
247
|
+
this.$l.dim0 = this.vFilteringInfo.x;
|
|
248
|
+
this.$l.omegaP = pb.div(4 * Math.PI, pb.mul(this.dim0, this.dim0, 6));
|
|
249
|
+
this.$l.weight = pb.float(0);
|
|
250
|
+
this.$for(pb.int('i'), 0, numSamples, function() {
|
|
251
|
+
this.$l.Xi = this.hammersley2d(this.i, numSamples);
|
|
252
|
+
this.$l.H = this.hemisphereImportanceSampleDggx(this.Xi, this.alphaG);
|
|
253
|
+
this.$l.NoV = pb.float(1);
|
|
254
|
+
this.$l.NoH = this.H.z;
|
|
255
|
+
this.$l.NoH2 = pb.mul(this.H.z, this.H.z);
|
|
256
|
+
this.$l.NoL = pb.sub(pb.mul(this.NoH2, 2), 1);
|
|
257
|
+
this.$l.L = pb.normalize(pb.vec3(pb.mul(this.NoH, this.H.x, 2), pb.mul(this.NoH, this.H.y, 2), this.NoL));
|
|
258
|
+
this.$if(pb.greaterThan(this.NoL, 0), function() {
|
|
259
|
+
this.$l.pdf_inversed = pb.div(4, this.normalDistributionFunction_TrowbridgeReitzGGX(this.NoH, this.alphaG));
|
|
260
|
+
this.$l.omegaS = pb.mul(this.pdf_inversed, this.NUM_SAMPLES_FLOAT_INVERSED);
|
|
261
|
+
this.$l.l = pb.add(pb.sub(this.log4(this.omegaS), this.log4(this.omegaP)), this.log4(this.K));
|
|
262
|
+
this.$l.mipLevel = pb.clamp(this.l, 0, this.maxLevel);
|
|
263
|
+
this.weight = pb.add(this.weight, this.NoL);
|
|
264
|
+
this.$l.c = pb.textureSampleLevel(this.inputTexture, pb.mul(this.tbn, this.L), this.mipLevel).rgb;
|
|
265
|
+
this.result = pb.add(this.result, pb.mul(this.c, this.NoL));
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
this.result = pb.div(this.result, this.weight);
|
|
269
|
+
this.$return(this.result);
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
pb.main(function() {
|
|
274
|
+
if (type === 'ggx') {
|
|
275
|
+
this.$l.color = this.radiance(this.alphaG, this.$inputs.direction, this.vFilteringInfo);
|
|
276
|
+
}
|
|
277
|
+
if (type === 'lambertian') {
|
|
278
|
+
this.$l.color = this.irradiance(this.$inputs.direction, this.vFilteringInfo);
|
|
279
|
+
}
|
|
280
|
+
this.$outputs.outcolor = pb.vec4(pb.mul(this.color, this.hdrScale), 1);
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
function doPrefilterCubemap(type, roughness, miplevel, srcTexture, dstTexture, filteringInfo, numSamples) {
|
|
286
|
+
const device = Application.instance.device;
|
|
287
|
+
const framebuffer = device.createFrameBuffer([
|
|
288
|
+
dstTexture
|
|
289
|
+
], null);
|
|
290
|
+
framebuffer.setColorAttachmentMipLevel(0, miplevel);
|
|
291
|
+
framebuffer.setColorAttachmentGenerateMipmaps(0, false);
|
|
292
|
+
const { program, bindgroup } = getProgramInfo(type, numSamples);
|
|
293
|
+
bindgroup.setValue('vFilteringInfo', filteringInfo);
|
|
294
|
+
bindgroup.setValue('hdrScale', 1);
|
|
295
|
+
bindgroup.setTexture('inputTexture', srcTexture);
|
|
296
|
+
if (type === 'ggx') {
|
|
297
|
+
bindgroup.setValue('alphaG', roughness);
|
|
298
|
+
}
|
|
299
|
+
device.setProgram(program);
|
|
300
|
+
device.setBindGroup(0, bindgroup);
|
|
301
|
+
device.setFramebuffer(framebuffer);
|
|
302
|
+
for(let i = 0; i < 6; i++){
|
|
303
|
+
framebuffer.setColorAttachmentCubeFace(0, i);
|
|
304
|
+
device.setVertexLayout(vertexLayout);
|
|
305
|
+
device.setRenderStates(renderStates);
|
|
306
|
+
bindgroup.setValue('up', faceDirections[i][0]);
|
|
307
|
+
bindgroup.setValue('right', faceDirections[i][1]);
|
|
308
|
+
bindgroup.setValue('front', faceDirections[i][2]);
|
|
309
|
+
device.draw('triangle-list', 0, 6);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Prefilters an environment cubemap
|
|
314
|
+
*
|
|
315
|
+
* @param tex - The environment cubemap
|
|
316
|
+
* @param type - The prefilter type
|
|
317
|
+
* @param destTex - The output cubemap
|
|
318
|
+
*
|
|
319
|
+
* @public
|
|
320
|
+
*/ function prefilterCubemap(tex, type, destTex, numSamples) {
|
|
321
|
+
if (!tex || !tex.isTextureCube()) {
|
|
322
|
+
console.error('prefilterCubemap(): source texture must be cube texture');
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
const device = Application.instance.device;
|
|
326
|
+
if (!vertexLayout) {
|
|
327
|
+
init();
|
|
328
|
+
}
|
|
329
|
+
device.pushDeviceStates();
|
|
330
|
+
const rs = device.getRenderStates();
|
|
331
|
+
const srcTex = tex;
|
|
332
|
+
const width = tex.width;
|
|
333
|
+
const mipmapsCount = tex.mipLevelCount;
|
|
334
|
+
const filteringInfo = new Vector2(width, mipmapsCount);
|
|
335
|
+
const mips = type === 'ggx' ? destTex.mipLevelCount : 1;
|
|
336
|
+
for(let i = 0; i < mips; i++){
|
|
337
|
+
const alpha = i === 0 ? 0 : Math.pow(2, i) / width;
|
|
338
|
+
doPrefilterCubemap(type, alpha, i, srcTex, destTex, filteringInfo, numSamples ?? 64);
|
|
339
|
+
}
|
|
340
|
+
device.popDeviceStates();
|
|
341
|
+
device.setRenderStates(rs);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export { prefilterCubemap };
|
|
345
|
+
//# sourceMappingURL=pmrem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pmrem.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|