@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,405 @@
|
|
|
1
|
+
import { PBPrimitiveType, PBInsideFunctionScope } from '@zephyr3d/device';
|
|
2
|
+
import { ShaderFramework } from './framework.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Calculates the TBN matrix
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* This function computes the tangent frame for normal mapping without world normal
|
|
9
|
+
*
|
|
10
|
+
* @param scope - Current shader scope
|
|
11
|
+
* @param worldPosition - World position of current fragment
|
|
12
|
+
* @param uv - Texture coordinate for normal map
|
|
13
|
+
* @returns The calculated TBN matrix
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/ function calculateTBN(scope, worldPosition, uv, doubleSideLighting) {
|
|
17
|
+
const funcName = 'lib_calculateTBN';
|
|
18
|
+
const pb = scope.$builder;
|
|
19
|
+
pb.func(funcName, [
|
|
20
|
+
pb.vec3('posW'),
|
|
21
|
+
pb.vec2('uv')
|
|
22
|
+
], function() {
|
|
23
|
+
this.$l.uv_dx = pb.dpdx(pb.vec3(this.uv, 0));
|
|
24
|
+
this.$l.uv_dy = pb.dpdy(pb.vec3(this.uv, 0));
|
|
25
|
+
this.$if(pb.lessThanEqual(pb.add(pb.length(this.uv_dx), pb.length(this.uv_dy)), 0.000001), function() {
|
|
26
|
+
this.uv_dx = pb.vec3(1, 0, 0);
|
|
27
|
+
this.uv_dy = pb.vec3(0, 1, 0);
|
|
28
|
+
});
|
|
29
|
+
this.$l.t_ = pb.div(pb.sub(pb.mul(pb.dpdx(this.posW), this.uv_dy.y), pb.mul(pb.dpdy(this.posW), this.uv_dx.y)), pb.sub(pb.mul(this.uv_dx.x, this.uv_dy.y), pb.mul(this.uv_dx.y, this.uv_dy.x)));
|
|
30
|
+
this.$l.ng = pb.normalize(pb.cross(pb.dpdx(this.posW), pb.dpdy(this.posW)));
|
|
31
|
+
this.$l.t = pb.normalize(pb.sub(this.t_, pb.mul(this.ng, pb.dot(this.ng, this.t_))));
|
|
32
|
+
this.$l.b = pb.cross(this.ng, this.t);
|
|
33
|
+
if (doubleSideLighting) {
|
|
34
|
+
this.$if(pb.not(this.$builtins.frontFacing), function() {
|
|
35
|
+
this.t = pb.mul(this.t, -1);
|
|
36
|
+
this.b = pb.mul(this.b, -1);
|
|
37
|
+
this.ng = pb.mul(this.ng, -1);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
this.$return(pb.mat3(this.t, this.b, this.ng));
|
|
41
|
+
});
|
|
42
|
+
return pb.getGlobalScope()[funcName](worldPosition.xyz, uv);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Calculates the TBN matrix
|
|
46
|
+
*
|
|
47
|
+
* @remarks
|
|
48
|
+
* This function computes the tangent frame for normal mapping with world normal
|
|
49
|
+
*
|
|
50
|
+
* @param scope - Current shader scope
|
|
51
|
+
* @param worldPosition - World position of current fragment
|
|
52
|
+
* @param worldNormal - World normal of current fragment
|
|
53
|
+
* @param uv - Texture coordinate for normal map
|
|
54
|
+
* @returns The calculated TBN matrix
|
|
55
|
+
*
|
|
56
|
+
* @public
|
|
57
|
+
*/ function calculateTBNWithNormal(scope, worldPosition, worldNormal, uv, doubleSideLighting) {
|
|
58
|
+
const funcName = 'lib_calculateTBNWithNormal';
|
|
59
|
+
const pb = scope.$builder;
|
|
60
|
+
pb.func(funcName, [
|
|
61
|
+
pb.vec3('posW'),
|
|
62
|
+
pb.vec3('normalW'),
|
|
63
|
+
pb.vec2('uv')
|
|
64
|
+
], function() {
|
|
65
|
+
this.$l.uv_dx = pb.dpdx(pb.vec3(this.uv, 0));
|
|
66
|
+
this.$l.uv_dy = pb.dpdy(pb.vec3(this.uv, 0));
|
|
67
|
+
this.$if(pb.lessThanEqual(pb.add(pb.length(this.uv_dx), pb.length(this.uv_dy)), 0.000001), function() {
|
|
68
|
+
this.uv_dx = pb.vec3(1, 0, 0);
|
|
69
|
+
this.uv_dy = pb.vec3(0, 1, 0);
|
|
70
|
+
});
|
|
71
|
+
this.$l.t_ = pb.div(pb.sub(pb.mul(pb.dpdx(this.posW), this.uv_dy.y), pb.mul(pb.dpdy(this.posW), this.uv_dx.y)), pb.sub(pb.mul(this.uv_dx.x, this.uv_dy.y), pb.mul(this.uv_dx.y, this.uv_dy.x)));
|
|
72
|
+
this.$l.ng = pb.normalize(this.normalW);
|
|
73
|
+
this.$l.t = pb.normalize(pb.sub(this.t_, pb.mul(this.ng, pb.dot(this.ng, this.t_))));
|
|
74
|
+
this.$l.b = pb.cross(this.ng, this.t);
|
|
75
|
+
if (doubleSideLighting) {
|
|
76
|
+
this.$if(pb.not(this.$builtins.frontFacing), function() {
|
|
77
|
+
this.t = pb.mul(this.t, -1);
|
|
78
|
+
this.b = pb.mul(this.b, -1);
|
|
79
|
+
this.ng = pb.mul(this.ng, -1);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
this.$return(pb.mat3(this.t, this.b, this.ng));
|
|
83
|
+
});
|
|
84
|
+
return pb.getGlobalScope()[funcName](worldPosition, worldNormal, uv);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Calculates the non-linear depth from linear depth
|
|
88
|
+
*
|
|
89
|
+
* @param scope - Current shader scope
|
|
90
|
+
* @param depth - The linear depth
|
|
91
|
+
* @param nearFar - A vector that contains the near clip plane in x component and the far clip plane in y component
|
|
92
|
+
* @returns The calculated non-linear depth
|
|
93
|
+
*
|
|
94
|
+
* @public
|
|
95
|
+
*/ function linearDepthToNonLinear(scope, depth, nearFar) {
|
|
96
|
+
const pb = scope.$builder;
|
|
97
|
+
nearFar = nearFar || ShaderFramework.getCameraParams(scope);
|
|
98
|
+
return pb.div(pb.sub(nearFar.y, pb.div(pb.mul(nearFar.x, nearFar.y), depth)), pb.sub(nearFar.y, nearFar.x));
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Calculates the linear depth from non-linear depth
|
|
102
|
+
*
|
|
103
|
+
* @param scope - Current shader scope
|
|
104
|
+
* @param depth - The non-linear depth
|
|
105
|
+
* @param nearFar - A vector that contains the near clip plane in x component and the far clip plane in y component
|
|
106
|
+
* @returns The calculated linear depth
|
|
107
|
+
*
|
|
108
|
+
* @public
|
|
109
|
+
*/ function nonLinearDepthToLinear(scope, depth, nearFar) {
|
|
110
|
+
const pb = scope.$builder;
|
|
111
|
+
nearFar = nearFar || ShaderFramework.getCameraParams(scope);
|
|
112
|
+
return pb.div(pb.mul(nearFar.x, nearFar.y), pb.mix(nearFar.y, nearFar.x, depth));
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Calculates the normalized linear depth from non-linear depth
|
|
116
|
+
*
|
|
117
|
+
* @param scope - Current shader scope
|
|
118
|
+
* @param depth - The non-linear depth
|
|
119
|
+
* @param nearFar - A vector that contains the near clip plane in x component and the far clip plane in y component
|
|
120
|
+
* @returns The calculated normalized linear depth
|
|
121
|
+
*
|
|
122
|
+
* @public
|
|
123
|
+
*/ function nonLinearDepthToLinearNormalized(scope, depth, nearFar) {
|
|
124
|
+
const pb = scope.$builder;
|
|
125
|
+
nearFar = nearFar || ShaderFramework.getCameraParams(scope);
|
|
126
|
+
return pb.div(nearFar.x, pb.mix(nearFar.y, nearFar.x, depth));
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Decodes a float that was encoded into a rgba8unorm
|
|
130
|
+
*
|
|
131
|
+
* @param scope - Current shader scope
|
|
132
|
+
* @param value - The rgba8unorm to be decoded
|
|
133
|
+
* @returns The decoded float value
|
|
134
|
+
*
|
|
135
|
+
* @public
|
|
136
|
+
*/ function decodeFloatFromRGBA(scope, value) {
|
|
137
|
+
const pb = scope.$builder;
|
|
138
|
+
if (!value || !value.$typeinfo.isPrimitiveType() || value.$typeinfo.primitiveType !== PBPrimitiveType.F32VEC4) {
|
|
139
|
+
throw new Error('decodeFloatFromRGBA() failed: parameter type must be vec4');
|
|
140
|
+
}
|
|
141
|
+
if (!scope || !(scope instanceof PBInsideFunctionScope)) {
|
|
142
|
+
throw new Error('decodeFloatFromRGBA() failed: decodeNormalizedFloatFromRGBA() must be called inside a function');
|
|
143
|
+
}
|
|
144
|
+
const funcName = 'lib_DecodeFloatFromRGBA';
|
|
145
|
+
pb.func(funcName, [
|
|
146
|
+
pb.vec4('value')
|
|
147
|
+
], function() {
|
|
148
|
+
this.$l.pack = pb.floor(pb.add(pb.mul(this.value, 255), 0.5));
|
|
149
|
+
// Extract bits
|
|
150
|
+
this.$l.bitSign = pb.float(pb.greaterThan(this.pack.x, 127.0));
|
|
151
|
+
this.$l.bitExpn = pb.float(pb.greaterThan(this.pack.y, 127.0));
|
|
152
|
+
this.pack.x = pb.sub(this.pack.x, pb.mul(this.bitSign, 128));
|
|
153
|
+
this.pack.y = pb.sub(this.pack.y, pb.mul(this.bitExpn, 128));
|
|
154
|
+
// Compute parts of number
|
|
155
|
+
this.$l.exponent = pb.add(pb.mul(this.pack.x, 2.0), this.bitExpn);
|
|
156
|
+
this.exponent = pb.pow(2.0, pb.sub(this.exponent, 127.0));
|
|
157
|
+
this.$l.mantissa = pb.float(1.0);
|
|
158
|
+
this.mantissa = pb.add(this.mantissa, pb.div(this.pack.y, 128.0));
|
|
159
|
+
this.mantissa = pb.add(this.mantissa, pb.div(this.pack.z, 32768.0));
|
|
160
|
+
this.mantissa = pb.add(this.mantissa, pb.div(this.pack.w, 8388608.0));
|
|
161
|
+
// Return result
|
|
162
|
+
this.$return(pb.mul(pb.sub(1.0, pb.mul(this.bitSign, 2)), this.exponent, this.mantissa));
|
|
163
|
+
});
|
|
164
|
+
return scope[funcName](value);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Encodes a float into a rgba8unorm
|
|
168
|
+
*
|
|
169
|
+
* @param scope - Current shader scope
|
|
170
|
+
* @param value - The float value to be encode
|
|
171
|
+
* @returns The encoded rgba8unorm
|
|
172
|
+
*
|
|
173
|
+
* @public
|
|
174
|
+
*/ function encodeFloatToRGBA(scope, value) {
|
|
175
|
+
const pb = scope.$builder;
|
|
176
|
+
const funcName = 'lib_EncodeFloatToRGBA';
|
|
177
|
+
pb.func(funcName, [
|
|
178
|
+
pb.float('value')
|
|
179
|
+
], function() {
|
|
180
|
+
this.$l.floatMax = pb.mul(1.70141184, pb.pow(10, 38));
|
|
181
|
+
this.$l.floatMin = pb.mul(1.17549435, pb.pow(10, -38));
|
|
182
|
+
this.$l.absvalue = pb.abs(this.value);
|
|
183
|
+
this.$if(pb.lessThanEqual(this.absvalue, this.floatMin), function() {
|
|
184
|
+
this.$return(pb.vec4(0));
|
|
185
|
+
});
|
|
186
|
+
this.$if(pb.greaterThanEqual(this.value, this.floatMax), function() {
|
|
187
|
+
this.$return(pb.vec4(127 / 255, 128 / 255, 0, 0));
|
|
188
|
+
});
|
|
189
|
+
this.$if(pb.lessThanEqual(this.value, pb.neg(this.floatMax)), function() {
|
|
190
|
+
this.$return(pb.vec4(1, 128 / 255, 0, 0));
|
|
191
|
+
});
|
|
192
|
+
this.$l.pack = pb.vec4(0);
|
|
193
|
+
// Compute Exponent and Mantissa
|
|
194
|
+
this.$l.exponent = pb.floor(pb.log2(this.absvalue));
|
|
195
|
+
this.$l.mantissa = pb.sub(pb.mul(this.absvalue, pb.pow(2.0, pb.neg(this.exponent))), 1.0);
|
|
196
|
+
// Pack Mantissa into bytes
|
|
197
|
+
this.pack.y = pb.floor(pb.mul(this.mantissa, 128.0));
|
|
198
|
+
this.mantissa = pb.sub(this.mantissa, pb.div(this.pack.y, 128.0));
|
|
199
|
+
this.pack.z = pb.floor(pb.mul(this.mantissa, 32768.0));
|
|
200
|
+
this.mantissa = pb.sub(this.mantissa, pb.div(this.pack.z, 32768.0));
|
|
201
|
+
this.pack.w = pb.floor(pb.mul(this.mantissa, 8388608.0));
|
|
202
|
+
// Pack Sing and Exponent into bytes
|
|
203
|
+
this.$l.expbias = pb.add(this.exponent, 127.0);
|
|
204
|
+
this.pack.x = pb.add(this.pack.x, pb.floor(pb.div(this.expbias, 2.0)));
|
|
205
|
+
this.expbias = pb.sub(this.expbias, pb.mul(this.pack.x, 2.0));
|
|
206
|
+
this.pack.y = pb.add(this.pack.y, pb.mul(pb.floor(this.expbias), 128.0));
|
|
207
|
+
this.pack.x = pb.add(this.pack.x, pb.mul(128.0, pb.float(pb.lessThan(this.value, 0.)))); // Sign
|
|
208
|
+
this.$return(pb.div(pb.floor(pb.add(this.pack, pb.vec4(.5))), 255.0));
|
|
209
|
+
});
|
|
210
|
+
return pb.getGlobalScope()[funcName](value);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Decodes a float that was encoded into a rgba8unorm
|
|
214
|
+
*
|
|
215
|
+
* @param scope - Current shader scope
|
|
216
|
+
* @param value - The rgba8unorm to be decoded
|
|
217
|
+
* @returns The decoded float value
|
|
218
|
+
*
|
|
219
|
+
* @public
|
|
220
|
+
*/ function decodeNormalizedFloatFromRGBA(scope, value) {
|
|
221
|
+
const pb = scope.$builder;
|
|
222
|
+
if (!value || !value.$typeinfo.isPrimitiveType() || value.$typeinfo.primitiveType !== PBPrimitiveType.F32VEC4) {
|
|
223
|
+
throw new Error('decodeNormalizedFloatFromRGBA() failed: parameter type must be vec4');
|
|
224
|
+
}
|
|
225
|
+
if (!scope || !(scope instanceof PBInsideFunctionScope)) {
|
|
226
|
+
throw new Error('decodeNormalizedFloatFromRGBA() failed: decodeNormalizedFloatFromRGBA() must be called inside a function');
|
|
227
|
+
}
|
|
228
|
+
const funcName = 'lib_DecodeNormalizedFloatFromRGBA';
|
|
229
|
+
pb.func(funcName, [
|
|
230
|
+
pb.vec4('value')
|
|
231
|
+
], function() {
|
|
232
|
+
this.$l.bitShift = pb.vec4(1 / (256 * 256 * 256), 1 / (256 * 256), 1 / 256, 1);
|
|
233
|
+
this.$return(pb.dot(this.value, this.bitShift));
|
|
234
|
+
});
|
|
235
|
+
return scope[funcName](value);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Encodes a float into a rgba8unorm
|
|
239
|
+
*
|
|
240
|
+
* @param scope - Current shader scope
|
|
241
|
+
* @param value - The float value to be encode
|
|
242
|
+
* @returns The encoded rgba8unorm
|
|
243
|
+
*
|
|
244
|
+
* @public
|
|
245
|
+
*/ function encodeNormalizedFloatToRGBA(scope, value) {
|
|
246
|
+
const pb = scope.$builder;
|
|
247
|
+
const funcName = 'lib_EncodeNormalizedFloatToRGBA';
|
|
248
|
+
pb.func(funcName, [
|
|
249
|
+
pb.float('value')
|
|
250
|
+
], function() {
|
|
251
|
+
this.$l.bitShift = pb.vec4(256 * 256 * 256, 256 * 256, 256, 1);
|
|
252
|
+
this.$l.bitMask = pb.vec4(0, 1 / 256, 1 / 256, 1 / 256);
|
|
253
|
+
this.$l.t = pb.fract(pb.mul(this.value, this.bitShift));
|
|
254
|
+
this.$return(pb.sub(this.t, pb.mul(this.t.xxyz, this.bitMask)));
|
|
255
|
+
});
|
|
256
|
+
return pb.getGlobalScope()[funcName](value);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Encodes two half floats into a rgba8unorm
|
|
260
|
+
*
|
|
261
|
+
* @param scope - Current shader scope
|
|
262
|
+
* @param a - The first half float to be encode
|
|
263
|
+
* @param b - The second half float to be encode
|
|
264
|
+
* @returns The encoded rgba8unorm
|
|
265
|
+
*
|
|
266
|
+
* @public
|
|
267
|
+
*/ function encode2HalfToRGBA(scope, a, b) {
|
|
268
|
+
const pb = scope.$builder;
|
|
269
|
+
const funcName = 'lib_Encode2HalfToRGBA';
|
|
270
|
+
pb.func(funcName, [
|
|
271
|
+
pb.float('a'),
|
|
272
|
+
pb.float('b')
|
|
273
|
+
], function() {
|
|
274
|
+
this.$l.t = pb.vec4(this.a, pb.fract(pb.mul(this.a, 255)), this.b, pb.fract(pb.mul(this.b, 255)));
|
|
275
|
+
this.$return(pb.vec4(pb.sub(this.t.x, pb.div(this.t.y, 255)), this.t.y, pb.sub(this.t.z, pb.div(this.t.w, 255)), this.t.w));
|
|
276
|
+
});
|
|
277
|
+
return pb.getGlobalScope()[funcName](a, b);
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Decodes two half floats that was encoded into a rgba8unorm
|
|
281
|
+
*
|
|
282
|
+
* @param scope - Current shader scope
|
|
283
|
+
* @param value - The rgba8unorm to be decoded
|
|
284
|
+
* @returns A vec2 that contains the two half floats
|
|
285
|
+
*
|
|
286
|
+
* @public
|
|
287
|
+
*/ function decode2HalfFromRGBA(scope, value) {
|
|
288
|
+
const pb = scope.$builder;
|
|
289
|
+
const funcName = 'lib_Decode2HalfFromRGBA';
|
|
290
|
+
pb.func(funcName, [
|
|
291
|
+
pb.vec4('value')
|
|
292
|
+
], function() {
|
|
293
|
+
this.$return(pb.vec2(pb.add(this.value.x, pb.div(this.value.y, 255)), pb.add(this.value.z, pb.div(this.value.w, 255))));
|
|
294
|
+
});
|
|
295
|
+
return pb.getGlobalScope()[funcName](value);
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Transform color to sRGB color space if nessesary
|
|
299
|
+
*
|
|
300
|
+
* @param scope - Current shader scope
|
|
301
|
+
* @param outputColor - The color to be transformed
|
|
302
|
+
* @returns The transformed color
|
|
303
|
+
*
|
|
304
|
+
* @public
|
|
305
|
+
*/ function encodeColorOutput(scope, outputColor) {
|
|
306
|
+
const pb = scope.$builder;
|
|
307
|
+
const funcName = 'lib_EncodeColorOutput';
|
|
308
|
+
pb.func(funcName, [
|
|
309
|
+
pb.vec4('outputColor')
|
|
310
|
+
], function() {
|
|
311
|
+
const params = ShaderFramework.getCameraParams(this);
|
|
312
|
+
this.$if(pb.notEqual(params.w, 0), function() {
|
|
313
|
+
this.$return(pb.vec4(linearToGamma(this, this.outputColor.rgb), this.outputColor.w));
|
|
314
|
+
}).$else(function() {
|
|
315
|
+
this.$return(this.outputColor);
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
return pb.getGlobalScope()[funcName](outputColor);
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Encodes a color value into RGBM format
|
|
322
|
+
*
|
|
323
|
+
* @param scope - Current shader scope
|
|
324
|
+
* @param rgb - The color value to be encoded
|
|
325
|
+
* @param maxRange - The max range of color components
|
|
326
|
+
* @returns The encoded RGBA value
|
|
327
|
+
*
|
|
328
|
+
* @public
|
|
329
|
+
*/ function encodeRGBM(scope, rgb, maxRange) {
|
|
330
|
+
const pb = scope.$builder;
|
|
331
|
+
const funcName = 'lib_encodeRGBM';
|
|
332
|
+
pb.func(funcName, [
|
|
333
|
+
pb.vec3('rgb'),
|
|
334
|
+
pb.float('range')
|
|
335
|
+
], function() {
|
|
336
|
+
this.$l.maxRGB = pb.max(this.rgb.r, pb.max(this.rgb.g, this.rgb.b));
|
|
337
|
+
this.$l.M = pb.div(this.maxRGB, this.range);
|
|
338
|
+
this.M = pb.div(pb.ceil(pb.mul(this.M, 255)), 255);
|
|
339
|
+
this.$return(pb.vec4(pb.div(this.rgb, pb.mul(this.M, this.range)), this.M));
|
|
340
|
+
});
|
|
341
|
+
return pb.getGlobalScope()[funcName](rgb, maxRange);
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Decodes color value that was encoded into RGBM format
|
|
345
|
+
*
|
|
346
|
+
* @param scope - Current shader scope
|
|
347
|
+
* @param rgbm - The RGBM to be decoded
|
|
348
|
+
* @param maxRange - The max range of color components
|
|
349
|
+
* @returns The decoded RGB color value
|
|
350
|
+
*
|
|
351
|
+
* @public
|
|
352
|
+
*/ function decodeRGBM(scope, rgbm, maxRange) {
|
|
353
|
+
const pb = scope.$builder;
|
|
354
|
+
const funcName = 'lib_decodeRGBM';
|
|
355
|
+
pb.func(funcName, [
|
|
356
|
+
pb.vec4('rgbm'),
|
|
357
|
+
pb.float('range')
|
|
358
|
+
], function() {
|
|
359
|
+
this.$return(pb.mul(this.rgbm.rgb, this.rgbm.a, this.range));
|
|
360
|
+
});
|
|
361
|
+
return pb.getGlobalScope()[funcName](rgbm, maxRange);
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Converts a vec3 color from gamma space to linear space
|
|
365
|
+
*
|
|
366
|
+
* @param scope - Current shader scope
|
|
367
|
+
* @param color - The vec3 color to be converted
|
|
368
|
+
* @returns The linear space vec3 color
|
|
369
|
+
*
|
|
370
|
+
* @public
|
|
371
|
+
*/ function gammaToLinear(scope, color) {
|
|
372
|
+
const pb = scope.$builder;
|
|
373
|
+
const funcName = 'lib_gammaToLinear';
|
|
374
|
+
pb.func(funcName, [
|
|
375
|
+
pb.vec3('color')
|
|
376
|
+
], function() {
|
|
377
|
+
// Approximate version from http://chilliant.blogspot.com.au/2012/08/srgb-approximations-for-hlsl.html?m=1
|
|
378
|
+
// float3 RGB = sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878);
|
|
379
|
+
this.$return(pb.mul(this.color, pb.add(pb.mul(this.color, pb.add(pb.mul(this.color, 0.305306011), pb.vec3(0.682171111))), pb.vec3(0.012522878))));
|
|
380
|
+
});
|
|
381
|
+
return pb.getGlobalScope()[funcName](color);
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Converts a vec3 color from linear space to gamma space
|
|
385
|
+
*
|
|
386
|
+
* @param scope - Current shader scope
|
|
387
|
+
* @param color - The vec3 color to be converted
|
|
388
|
+
* @returns The gamma space vec3 color
|
|
389
|
+
*
|
|
390
|
+
* @public
|
|
391
|
+
*/ function linearToGamma(scope, color) {
|
|
392
|
+
const pb = scope.$builder;
|
|
393
|
+
const funcName = 'lib_linearToGamma';
|
|
394
|
+
pb.func(funcName, [
|
|
395
|
+
pb.vec3('color')
|
|
396
|
+
], function() {
|
|
397
|
+
// Almost perfect version from http://chilliant.blogspot.com.au/2012/08/srgb-approximations-for-hlsl.html?m=1
|
|
398
|
+
// C_srgb_2 = max(1.055 * pow(C_lin, 0.416666667) - 0.055, 0);
|
|
399
|
+
this.$return(pb.max(pb.sub(pb.mul(pb.pow(this.color, pb.vec3(0.416666667)), 1.055), pb.vec3(0.055)), pb.vec3(0)));
|
|
400
|
+
});
|
|
401
|
+
return pb.getGlobalScope()[funcName](color);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
export { calculateTBN, calculateTBNWithNormal, decode2HalfFromRGBA, decodeFloatFromRGBA, decodeNormalizedFloatFromRGBA, decodeRGBM, encode2HalfToRGBA, encodeColorOutput, encodeFloatToRGBA, encodeNormalizedFloatToRGBA, encodeRGBM, gammaToLinear, linearDepthToNonLinear, linearToGamma, nonLinearDepthToLinear, nonLinearDepthToLinearNormalized };
|
|
405
|
+
//# sourceMappingURL=misc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"misc.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate single float noise from a vec2
|
|
3
|
+
*
|
|
4
|
+
* @param scope - Current shader scope
|
|
5
|
+
* @param p - random seed
|
|
6
|
+
* @returns a float noise value
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/ function noisef(scope, p) {
|
|
10
|
+
const pb = scope.$builder;
|
|
11
|
+
const funcNameHash = 'lib_hashf';
|
|
12
|
+
const funcNameNoise = 'lib_noisef';
|
|
13
|
+
pb.func(funcNameHash, [
|
|
14
|
+
pb.vec2('p')
|
|
15
|
+
], function() {
|
|
16
|
+
this.h = pb.dot(this.p, pb.vec2(127.1, 311.7));
|
|
17
|
+
this.$return(pb.fract(pb.mul(pb.sin(this.h), 43758.5453123)));
|
|
18
|
+
});
|
|
19
|
+
pb.func(funcNameNoise, [
|
|
20
|
+
pb.vec2('p')
|
|
21
|
+
], function() {
|
|
22
|
+
this.i = pb.floor(this.p);
|
|
23
|
+
this.f = pb.fract(this.p);
|
|
24
|
+
this.u = pb.mul(this.f, this.f, pb.sub(3, pb.mul(this.f, 2)));
|
|
25
|
+
this.h1 = this[funcNameHash](this.i);
|
|
26
|
+
this.h2 = this[funcNameHash](pb.add(this.i, pb.vec2(1, 0)));
|
|
27
|
+
this.h3 = this[funcNameHash](pb.add(this.i, pb.vec2(0, 1)));
|
|
28
|
+
this.h4 = this[funcNameHash](pb.add(this.i, pb.vec2(1, 1)));
|
|
29
|
+
this.$return(pb.add(-1, pb.mul(2, pb.mix(pb.mix(this.h1, this.h2, this.u.x), pb.mix(this.h3, this.h4, this.u.x), this.u.y))));
|
|
30
|
+
});
|
|
31
|
+
return scope[funcNameNoise](p);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* worley 3d noise
|
|
35
|
+
*
|
|
36
|
+
* @param scope - current shader scope
|
|
37
|
+
* @param uv - uv coordinate
|
|
38
|
+
* @param freq - frequency
|
|
39
|
+
*
|
|
40
|
+
* @returns worley noise value
|
|
41
|
+
*
|
|
42
|
+
* @public
|
|
43
|
+
*/ function worleyNoise(scope, uv, freq) {
|
|
44
|
+
const pb = scope.$builder;
|
|
45
|
+
const funcNameHash = 'lib_worleyHash';
|
|
46
|
+
// https://www.shadertoy.com/view/4sc3z2
|
|
47
|
+
pb.func(funcNameHash, [
|
|
48
|
+
pb.vec3('p')
|
|
49
|
+
], function() {
|
|
50
|
+
/* eslint-disable no-constant-condition */ {
|
|
51
|
+
this.$l.mod3 = pb.vec3(0.1031, 0.11369, 0.13787);
|
|
52
|
+
this.$l.p3 = pb.fract(pb.mul(this.p, this.mod3));
|
|
53
|
+
this.p3 = pb.add(this.p3, pb.dot(this.p3, pb.add(this.p3.yxz, pb.vec3(19.19))));
|
|
54
|
+
this.$return(pb.sub(pb.mul(pb.fract(pb.vec3(pb.mul(pb.add(this.p3.x, this.p3.y), this.p3.z), pb.mul(pb.add(this.p3.x, this.p3.z), this.p3.y), pb.mul(pb.add(this.p3.y, this.p3.z), this.p3.x))), 2), 1));
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
const funcNameNoise = 'lib_worleyNoise';
|
|
58
|
+
pb.func(funcNameNoise, [
|
|
59
|
+
pb.vec3('uv'),
|
|
60
|
+
pb.float('freq')
|
|
61
|
+
], function() {
|
|
62
|
+
this.$l.id = pb.floor(this.uv);
|
|
63
|
+
this.$l.p = pb.fract(this.uv);
|
|
64
|
+
this.$l.minDist = pb.float(10000);
|
|
65
|
+
this.$for(pb.int('x'), -1, 2, function() {
|
|
66
|
+
this.$for(pb.int('y'), -1, 2, function() {
|
|
67
|
+
this.$for(pb.int('z'), -1, 2, function() {
|
|
68
|
+
this.$l.offset = pb.vec3(pb.float(this.x), pb.float(this.y), pb.float(this.z));
|
|
69
|
+
/* eslint-disable no-constant-condition */ {
|
|
70
|
+
this.$l.h = pb.add(pb.mul(this[funcNameHash](pb.mod(pb.add(this.id, this.offset), pb.vec3(this.freq))), 0.4), pb.vec3(0.3));
|
|
71
|
+
}
|
|
72
|
+
this.h = pb.add(this.h, this.offset);
|
|
73
|
+
this.$l.d = pb.sub(this.p, this.h);
|
|
74
|
+
this.minDist = pb.min(this.minDist, pb.dot(this.d, this.d));
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
this.$return(pb.sub(1, this.minDist));
|
|
79
|
+
});
|
|
80
|
+
return pb.getGlobalScope()[funcNameNoise](uv, freq);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Calculate worley FBM
|
|
84
|
+
*
|
|
85
|
+
* @param scope - current shader scope
|
|
86
|
+
* @param p - noise coordinate
|
|
87
|
+
* @param freq - frequency
|
|
88
|
+
* @returns worley FBM value
|
|
89
|
+
*
|
|
90
|
+
* @public
|
|
91
|
+
*/ function worleyFBM(scope, p, freq) {
|
|
92
|
+
const pb = scope.$builder;
|
|
93
|
+
const funcName = 'lib_worleyFBM';
|
|
94
|
+
pb.func(funcName, [
|
|
95
|
+
pb.vec3('p'),
|
|
96
|
+
pb.float('freq')
|
|
97
|
+
], function() {
|
|
98
|
+
this.$l.n1 = worleyNoise(this, pb.mul(this.p, this.freq), this.freq);
|
|
99
|
+
this.$l.n2 = worleyNoise(this, pb.mul(this.p, this.freq, 2), pb.mul(this.freq, 2));
|
|
100
|
+
this.$l.n3 = worleyNoise(this, pb.mul(this.p, this.freq, 4), pb.mul(this.freq, 4));
|
|
101
|
+
this.$l.fbm = pb.add(pb.mul(this.n1, 0.625), pb.mul(this.n2, 0.25), pb.mul(this.n3, 0.125));
|
|
102
|
+
this.$return(pb.max(pb.sub(pb.mul(this.fbm, 1.1), pb.vec3(0.1)), pb.vec3(0)));
|
|
103
|
+
});
|
|
104
|
+
return pb.getGlobalScope()[funcName](p, freq);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Calculate 3d noise by a 3d position
|
|
108
|
+
*
|
|
109
|
+
* @param scope - current shader scope
|
|
110
|
+
* @param p - 3d position at where to calculate noise
|
|
111
|
+
* @returns noise value between 0 and 1
|
|
112
|
+
*
|
|
113
|
+
* @public
|
|
114
|
+
*/ function noise3D(scope, p) {
|
|
115
|
+
const pb = scope.$builder;
|
|
116
|
+
const funcName = 'lib_noise3d';
|
|
117
|
+
pb.func(funcName, [
|
|
118
|
+
pb.vec3('p')
|
|
119
|
+
], function() {
|
|
120
|
+
this.$l.p3 = pb.fract(pb.mul(this.p, 0.1031));
|
|
121
|
+
this.$l.p3 = pb.add(this.p3, pb.vec3(pb.dot(this.p3, pb.add(this.p3.yzx, pb.vec3(33.33)))));
|
|
122
|
+
this.$return(pb.fract(pb.mul(pb.add(this.p3.x, this.p3.y), this.p3.z)));
|
|
123
|
+
});
|
|
124
|
+
return pb.getGlobalScope()[funcName](p);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Calculate smooth 3d noise by a 3d position
|
|
128
|
+
*
|
|
129
|
+
* @param scope - current shader scope
|
|
130
|
+
* @param p - 3d position at where to calculate noise
|
|
131
|
+
* @returns noise value between 0 and 1
|
|
132
|
+
*
|
|
133
|
+
* @public
|
|
134
|
+
*/ function smoothNoise3D(scope, p) {
|
|
135
|
+
const pb = scope.$builder;
|
|
136
|
+
const funcName = 'lib_smoothNoise3D';
|
|
137
|
+
pb.func(funcName, [
|
|
138
|
+
pb.vec3('p')
|
|
139
|
+
], function() {
|
|
140
|
+
this.$l.cell = pb.floor(this.p);
|
|
141
|
+
this.$l.local = pb.fract(this.p);
|
|
142
|
+
this.$l.local = pb.mul(this.local, pb.mul(this.local, pb.sub(pb.vec3(3), pb.mul(this.local, 2))));
|
|
143
|
+
this.$l.ldb = noise3D(this, this.cell);
|
|
144
|
+
this.$l.rdb = noise3D(this, pb.add(this.cell, pb.vec3(1, 0, 0)));
|
|
145
|
+
this.$l.ldf = noise3D(this, pb.add(this.cell, pb.vec3(0, 0, 1)));
|
|
146
|
+
this.$l.rdf = noise3D(this, pb.add(this.cell, pb.vec3(1, 0, 1)));
|
|
147
|
+
this.$l.lub = noise3D(this, pb.add(this.cell, pb.vec3(0, 1, 0)));
|
|
148
|
+
this.$l.rub = noise3D(this, pb.add(this.cell, pb.vec3(1, 1, 0)));
|
|
149
|
+
this.$l.luf = noise3D(this, pb.add(this.cell, pb.vec3(0, 1, 1)));
|
|
150
|
+
this.$l.ruf = noise3D(this, pb.add(this.cell, pb.vec3(1, 1, 1)));
|
|
151
|
+
this.$return(pb.mix(pb.mix(pb.mix(this.ldb, this.rdb, this.local.x), pb.mix(this.ldf, this.rdf, this.local.x), this.local.z), pb.mix(pb.mix(this.lub, this.rub, this.local.x), pb.mix(this.luf, this.ruf, this.local.x), this.local.z), this.local.y));
|
|
152
|
+
});
|
|
153
|
+
return pb.getGlobalScope()[funcName](p);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export { noise3D, noisef, smoothNoise3D, worleyFBM, worleyNoise };
|
|
157
|
+
//# sourceMappingURL=noise.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noise.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|