@zephyr3d/scene 0.4.0 → 0.6.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 +25 -117
- package/dist/animation/animation.js.map +1 -1
- package/dist/animation/animationset.js +191 -51
- package/dist/animation/animationset.js.map +1 -1
- package/dist/animation/animationtrack.js +6 -18
- package/dist/animation/animationtrack.js.map +1 -1
- package/dist/animation/eulerrotationtrack.js +16 -6
- package/dist/animation/eulerrotationtrack.js.map +1 -1
- package/dist/animation/morphtarget.js +104 -0
- package/dist/animation/morphtarget.js.map +1 -0
- package/dist/animation/morphtrack.js +70 -0
- package/dist/animation/morphtrack.js.map +1 -0
- package/dist/animation/rotationtrack.js +15 -7
- package/dist/animation/rotationtrack.js.map +1 -1
- package/dist/animation/scaletrack.js +15 -7
- package/dist/animation/scaletrack.js.map +1 -1
- package/dist/animation/skeleton.js +107 -5
- package/dist/animation/skeleton.js.map +1 -1
- package/dist/animation/translationtrack.js +15 -7
- package/dist/animation/translationtrack.js.map +1 -1
- package/dist/app.js +4 -26
- package/dist/app.js.map +1 -1
- package/dist/asset/assetmanager.js +60 -109
- package/dist/asset/assetmanager.js.map +1 -1
- package/dist/asset/loaders/dds/dds.js +77 -3
- package/dist/asset/loaders/dds/dds.js.map +1 -1
- package/dist/asset/loaders/dds/dds_loader.js +1 -1
- package/dist/asset/loaders/gltf/gltf_loader.js +287 -40
- package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -1
- package/dist/asset/loaders/image/tga_Loader.js +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 +16 -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 +9 -3
- 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 +200 -4
- package/dist/camera/camera.js.map +1 -1
- package/dist/index.d.ts +6406 -5786
- package/dist/index.js +12 -10
- package/dist/index.js.map +1 -1
- package/dist/material/blinn.js +15 -4
- package/dist/material/blinn.js.map +1 -1
- package/dist/material/lambert.js +26 -17
- package/dist/material/lambert.js.map +1 -1
- package/dist/material/material.js +13 -2
- package/dist/material/material.js.map +1 -1
- package/dist/material/meshmaterial.js +103 -31
- 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 +16 -7
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js +16 -7
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
- package/dist/material/mixins/lit.js +2 -2
- package/dist/material/mixins/pbr/common.js +454 -19
- package/dist/material/mixins/pbr/common.js.map +1 -1
- package/dist/material/pbrmr.js +28 -6
- package/dist/material/pbrmr.js.map +1 -1
- package/dist/material/pbrsg.js +27 -9
- package/dist/material/pbrsg.js.map +1 -1
- package/dist/material/shader/helper.js +128 -23
- package/dist/material/shader/helper.js.map +1 -1
- package/dist/material/unlit.js +8 -4
- package/dist/material/unlit.js.map +1 -1
- package/dist/posteffect/bloom.js +34 -53
- package/dist/posteffect/bloom.js.map +1 -1
- package/dist/posteffect/compositor.js +48 -58
- 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 +55 -48
- 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 +306 -340
- 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 +8 -6
- package/dist/render/cull_visitor.js.map +1 -1
- package/dist/render/depthpass.js +30 -14
- package/dist/render/depthpass.js.map +1 -1
- package/dist/render/drawable_mixin.js +70 -22
- package/dist/render/drawable_mixin.js.map +1 -1
- package/dist/render/envlight.js +169 -33
- 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 +68 -28
- package/dist/render/lightpass.js.map +1 -1
- package/dist/render/objectcolorpass.js +51 -0
- package/dist/render/objectcolorpass.js.map +1 -0
- package/dist/render/render_queue.js +211 -158
- 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 +151 -35
- package/dist/render/renderer.js.map +1 -1
- package/dist/render/renderpass.js +27 -20
- package/dist/render/renderpass.js.map +1 -1
- package/dist/render/shadowmap_pass.js +20 -14
- 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/render/weightedblended_oit.js +11 -28
- package/dist/render/weightedblended_oit.js.map +1 -1
- package/dist/scene/batchgroup.js +60 -14
- package/dist/scene/batchgroup.js.map +1 -1
- package/dist/scene/environment.js +24 -3
- package/dist/scene/environment.js.map +1 -1
- package/dist/scene/graph_node.js +0 -14
- package/dist/scene/graph_node.js.map +1 -1
- package/dist/scene/light.js +5 -5
- package/dist/scene/mesh.js +62 -15
- 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 +6 -9
- package/dist/scene/scene.js.map +1 -1
- package/dist/scene/scene_node.js +11 -8
- package/dist/scene/scene_node.js.map +1 -1
- package/dist/scene/terrain/grass.js +10 -2
- 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 +10 -2
- package/dist/scene/terrain/patch.js.map +1 -1
- package/dist/scene/terrain/quadtree.js +2 -2
- 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/esm.js +4 -22
- package/dist/shadow/esm.js.map +1 -1
- package/dist/shadow/shadowmapper.js +56 -31
- package/dist/shadow/shadowmapper.js.map +1 -1
- package/dist/shadow/vsm.js +4 -24
- package/dist/shadow/vsm.js.map +1 -1
- 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/draco/decoder.js +116 -0
- package/dist/utility/draco/decoder.js.map +1 -0
- 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 +25 -1
- package/dist/values.js.map +1 -1
- package/package.json +5 -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/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
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
import { decodeNormalizedFloatFromRGBA } from './misc.js';
|
|
2
|
+
import { ShaderHelper } from '../material/shader/helper.js';
|
|
3
|
+
import '../material/lambert.js';
|
|
4
|
+
import '../material/blinn.js';
|
|
5
|
+
import '../material/unlit.js';
|
|
6
|
+
import '@zephyr3d/device';
|
|
7
|
+
import '../values.js';
|
|
8
|
+
import '../app.js';
|
|
9
|
+
import '../material/meshmaterial.js';
|
|
10
|
+
import '../material/grassmaterial.js';
|
|
11
|
+
import '../material/terrainmaterial.js';
|
|
12
|
+
import '../material/pbrmr.js';
|
|
13
|
+
import '../material/pbrsg.js';
|
|
14
|
+
import '@zephyr3d/base';
|
|
15
|
+
|
|
16
|
+
const MAX_FLOAT_VALUE = 3.402823466e38;
|
|
17
|
+
/** @internal */ function SSR_calcJitter(scope, viewPos, roughness) {
|
|
18
|
+
const pb = scope.$builder;
|
|
19
|
+
pb.func('SSR_calcJitter', [
|
|
20
|
+
pb.vec3('viewPos'),
|
|
21
|
+
pb.float('roughness')
|
|
22
|
+
], function() {
|
|
23
|
+
this.$l.h = pb.fract(pb.mul(this.viewPos, 0.8));
|
|
24
|
+
this.h = pb.add(this.h, pb.dot(this.h, pb.add(this.h.yxz, pb.vec3(19.19))));
|
|
25
|
+
this.h = pb.fract(pb.mul(pb.add(this.h.xxy, this.h.yxx), this.h.zyx));
|
|
26
|
+
this.h = pb.sub(this.h, pb.vec3(0.5));
|
|
27
|
+
this.$return(pb.mix(pb.vec3(0), this.h, this.roughness));
|
|
28
|
+
});
|
|
29
|
+
return scope.SSR_calcJitter(viewPos, roughness);
|
|
30
|
+
}
|
|
31
|
+
/** @internal */ function invProjectPosition(scope, pos, mat) {
|
|
32
|
+
const pb = scope.$builder;
|
|
33
|
+
pb.func('invProjectPosition', [
|
|
34
|
+
pb.vec3('p'),
|
|
35
|
+
pb.mat4('mat')
|
|
36
|
+
], function() {
|
|
37
|
+
this.$l.c = pb.sub(pb.mul(this.p, 2), pb.vec3(1));
|
|
38
|
+
this.$l.u = pb.mul(this.mat, pb.vec4(this.c, 1));
|
|
39
|
+
this.u = pb.div(this.u, this.u.w);
|
|
40
|
+
this.$return(this.u.xyz);
|
|
41
|
+
});
|
|
42
|
+
return scope.invProjectPosition(pos, mat);
|
|
43
|
+
}
|
|
44
|
+
/** @internal */ function validateHit(scope, hit2D, hit3D, surfaceZ, thickness, uv, traceRay, viewMatrix, invProjMatrix, textureSize, normalTexture) {
|
|
45
|
+
const pb = scope.$builder;
|
|
46
|
+
const funcName = hit3D ? 'SSR_validateHit_HiZ' : 'SSR_validateHit';
|
|
47
|
+
pb.func(funcName, [
|
|
48
|
+
pb.vec2('hit2d'),
|
|
49
|
+
...hit3D ? [
|
|
50
|
+
pb.vec3('hit3d')
|
|
51
|
+
] : [],
|
|
52
|
+
...hit3D ? [
|
|
53
|
+
pb.float('thickness')
|
|
54
|
+
] : [],
|
|
55
|
+
pb.float('surfaceZ'),
|
|
56
|
+
pb.vec2('uv'),
|
|
57
|
+
pb.vec3('viewSpaceRayDirection'),
|
|
58
|
+
pb.mat4('viewMatrix'),
|
|
59
|
+
pb.mat4('invProjMatrix'),
|
|
60
|
+
pb.vec4('textureSize')
|
|
61
|
+
], function() {
|
|
62
|
+
this.$if(pb.or(pb.any(pb.lessThan(this.hit2d, pb.vec2(0))), pb.any(pb.greaterThan(this.hit2d, pb.vec2(1)))), function() {
|
|
63
|
+
this.$return(pb.float(0));
|
|
64
|
+
});
|
|
65
|
+
this.$l.manhattanDist = pb.abs(pb.sub(this.hit2d, this.uv));
|
|
66
|
+
this.$if(pb.all(pb.lessThan(this.manhattanDist, pb.vec2(pb.div(pb.vec2(2), this.textureSize.xy)))), function() {
|
|
67
|
+
this.$return(pb.float(0));
|
|
68
|
+
});
|
|
69
|
+
if (normalTexture) {
|
|
70
|
+
this.$l.hitNormalWS = pb.sub(pb.mul(pb.textureSampleLevel(normalTexture, this.hit2d, 0).rgb, 2), pb.vec3(1));
|
|
71
|
+
this.$l.hitNormalVS = pb.mul(this.viewMatrix, pb.vec4(this.hitNormalWS, 0)).xyz;
|
|
72
|
+
this.$if(pb.greaterThan(pb.dot(this.hitNormalVS, this.viewSpaceRayDirection), 0), function() {
|
|
73
|
+
this.$return(pb.float(0));
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
this.$l.viewSpaceSurface = invProjectPosition(this, pb.vec3(this.hit2d, this.surfaceZ), this.invProjMatrix);
|
|
77
|
+
this.$l.fov = pb.mul(pb.vec2(pb.div(this.textureSize.y, this.textureSize.x), 1), 0.05);
|
|
78
|
+
this.$l.border = pb.mul(pb.smoothStep(pb.vec2(0), this.fov, this.hit2d), pb.sub(pb.vec2(1), pb.smoothStep(pb.sub(pb.vec2(1), this.fov), pb.vec2(1), this.hit2d)));
|
|
79
|
+
this.$l.vignette = pb.mul(this.border.x, this.border.y);
|
|
80
|
+
if (this.hit3d) {
|
|
81
|
+
this.$l.distance = pb.distance(this.viewSpaceSurface, this.hit3d);
|
|
82
|
+
this.$l.confidence = pb.sub(1, pb.smoothStep(0, this.thickness, this.distance));
|
|
83
|
+
this.$return(pb.mul(this.vignette, this.confidence, this.confidence));
|
|
84
|
+
} else {
|
|
85
|
+
this.$return(this.vignette);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
return hit3D ? scope[funcName](hit2D, hit3D, thickness, surfaceZ, uv, traceRay, viewMatrix, invProjMatrix, textureSize) : scope[funcName](hit2D, surfaceZ, uv, traceRay, viewMatrix, invProjMatrix, textureSize);
|
|
89
|
+
}
|
|
90
|
+
function sampleLinearDepth(scope, tex, uv, level) {
|
|
91
|
+
const pb = scope.$builder;
|
|
92
|
+
const depth = pb.textureSampleLevel(tex, uv, level);
|
|
93
|
+
return pb.getDevice().type === 'webgl' ? decodeNormalizedFloatFromRGBA(scope, depth) : depth.r;
|
|
94
|
+
}
|
|
95
|
+
function sampleLinearDepthWithBackface(scope, tex, uv, level) {
|
|
96
|
+
const pb = scope.$builder;
|
|
97
|
+
return pb.textureSampleLevel(tex, uv, level).rg;
|
|
98
|
+
}
|
|
99
|
+
function screenSpaceRayTracing_Linear2D(scope, viewPos, traceRay, viewMatrix, projMatrix, invProjMatrix, cameraNearFar, maxDistance, maxIterations, thickness, stride, textureSize, linearDepthTex, normalTexture, useBackfaceDepth) {
|
|
100
|
+
const pb = scope.$builder;
|
|
101
|
+
pb.func('distanceSquared', [
|
|
102
|
+
pb.vec2('a'),
|
|
103
|
+
pb.vec2('b')
|
|
104
|
+
], function() {
|
|
105
|
+
this.$l.x = pb.sub(this.a, this.b);
|
|
106
|
+
this.$return(pb.dot(this.x, this.x));
|
|
107
|
+
});
|
|
108
|
+
pb.func('rayIntersectDepth', [
|
|
109
|
+
pb.float('zA'),
|
|
110
|
+
pb.float('zB'),
|
|
111
|
+
pb.float('thickness'),
|
|
112
|
+
pb.vec2('uv'),
|
|
113
|
+
pb.float('cameraFar')
|
|
114
|
+
], function() {
|
|
115
|
+
let thickness = this.thickness;
|
|
116
|
+
if (useBackfaceDepth) {
|
|
117
|
+
this.$l.sceneZ = sampleLinearDepthWithBackface(this, linearDepthTex, this.uv, 0);
|
|
118
|
+
this.$l.sceneZMax01 = this.sceneZ.x;
|
|
119
|
+
thickness = pb.max(this.thickness, pb.mul(pb.sub(this.sceneZ.y, this.sceneZ.x), this.cameraFar));
|
|
120
|
+
} else {
|
|
121
|
+
this.$l.sceneZMax01 = sampleLinearDepth(this, linearDepthTex, this.uv, 0);
|
|
122
|
+
}
|
|
123
|
+
this.sceneZMax = pb.neg(pb.mul(this.sceneZMax01, this.cameraFar));
|
|
124
|
+
this.$return(pb.and(pb.lessThan(this.sceneZMax01, 1), pb.greaterThanEqual(this.zA, pb.sub(this.sceneZMax, thickness)), pb.lessThanEqual(this.zB, this.sceneZMax)));
|
|
125
|
+
});
|
|
126
|
+
pb.func('traceRayLinear2D', [
|
|
127
|
+
pb.vec3('rayOrigin'),
|
|
128
|
+
pb.vec3('rayDirection'),
|
|
129
|
+
pb.float('stride'),
|
|
130
|
+
pb.float('strideZCutoff'),
|
|
131
|
+
pb.float('maxDistance'),
|
|
132
|
+
pb.float('maxIterations'),
|
|
133
|
+
pb.float('thickness'),
|
|
134
|
+
pb.vec2('cameraNearFar'),
|
|
135
|
+
pb.mat4('projMatrix'),
|
|
136
|
+
pb.vec4('textureSize'),
|
|
137
|
+
pb.vec3('hit2D').out(),
|
|
138
|
+
pb.vec3('hit3D').out(),
|
|
139
|
+
pb.vec2('origin').out(),
|
|
140
|
+
pb.float('numIterations').out()
|
|
141
|
+
], function() {
|
|
142
|
+
this.$l.rayLen = this.$choice(pb.greaterThan(pb.add(this.rayOrigin.z, pb.mul(this.rayDirection.z, this.maxDistance)), pb.neg(this.cameraNearFar.x)), pb.div(pb.sub(pb.neg(this.cameraNearFar.x), this.rayOrigin.z), this.rayDirection.z), this.maxDistance);
|
|
143
|
+
this.$l.rayEnd = pb.add(this.rayOrigin, pb.mul(this.rayDirection, this.rayLen));
|
|
144
|
+
this.$l.zMin = pb.min(this.rayOrigin.z, this.rayEnd.z);
|
|
145
|
+
this.$l.zMax = pb.max(this.rayOrigin.z, this.rayEnd.z);
|
|
146
|
+
this.$l.rayOriginH = pb.mul(this.projMatrix, pb.vec4(this.rayOrigin, 1));
|
|
147
|
+
this.$l.rayEndH = pb.mul(this.projMatrix, pb.vec4(this.rayEnd, 1));
|
|
148
|
+
this.$l.k0 = pb.div(1, this.rayOriginH.w);
|
|
149
|
+
this.$l.k1 = pb.div(1, this.rayEndH.w);
|
|
150
|
+
this.$l.Q0 = pb.mul(this.rayOrigin, this.k0);
|
|
151
|
+
this.$l.Q1 = pb.mul(this.rayEnd, this.k1);
|
|
152
|
+
this.$l.rayOriginNDC = pb.mul(this.rayOriginH, this.k0);
|
|
153
|
+
this.$l.rayEndNDC = pb.mul(this.rayEndH, this.k1);
|
|
154
|
+
this.origin = pb.add(pb.mul(this.rayOriginNDC.xy, 0.5), pb.vec2(0.5));
|
|
155
|
+
this.$l.P0 = pb.mul(this.origin, this.textureSize.zw);
|
|
156
|
+
this.$l.P1 = pb.mul(pb.add(pb.mul(this.rayEndNDC.xy, 0.5), pb.vec2(0.5)), this.textureSize.zw);
|
|
157
|
+
this.$l.xMin = 0.5;
|
|
158
|
+
this.$l.xMax = pb.sub(this.textureSize.z, 0.5);
|
|
159
|
+
this.$l.yMin = 0.5;
|
|
160
|
+
this.$l.yMax = pb.sub(this.textureSize.w, 0.5);
|
|
161
|
+
this.$l.t = pb.float();
|
|
162
|
+
this.$if(pb.or(pb.greaterThan(this.P1.y, this.yMax), pb.lessThan(this.P1.y, this.yMin)), function() {
|
|
163
|
+
this.t = pb.div(pb.sub(this.P1.y, this.$choice(pb.greaterThan(this.P1.y, this.yMax), this.yMax, this.yMin)), pb.sub(this.P1.y, this.P0.y));
|
|
164
|
+
});
|
|
165
|
+
this.$if(pb.or(pb.greaterThan(this.P1.x, this.xMax), pb.lessThan(this.P1.x, this.xMin)), function() {
|
|
166
|
+
this.t2 = pb.div(pb.sub(this.P1.x, this.$choice(pb.greaterThan(this.P1.x, this.xMax), this.xMax, this.xMin)), pb.sub(this.P1.x, this.P0.x));
|
|
167
|
+
this.t = pb.max(this.t, this.t2);
|
|
168
|
+
});
|
|
169
|
+
this.P1 = pb.mix(this.P1, this.P0, this.t);
|
|
170
|
+
this.k1 = pb.mix(this.k1, this.k0, this.t);
|
|
171
|
+
this.Q1 = pb.mix(this.Q1, this.Q0, this.t);
|
|
172
|
+
this.P1 = this.$choice(pb.lessThan(this.distanceSquared(this.P0, this.P1), 0.0001), pb.add(this.P1, pb.vec2(0.01)), this.P1);
|
|
173
|
+
this.$l.delta = pb.sub(this.P1, this.P0);
|
|
174
|
+
this.$l.permute = false;
|
|
175
|
+
this.$if(pb.lessThan(pb.abs(this.delta.x), pb.abs(this.delta.y)), function() {
|
|
176
|
+
this.permute = true;
|
|
177
|
+
this.delta = this.delta.yx;
|
|
178
|
+
this.P0 = this.P0.yx;
|
|
179
|
+
this.P1 = this.P1.yx;
|
|
180
|
+
});
|
|
181
|
+
this.$l.stepDir = pb.sign(this.delta.x);
|
|
182
|
+
this.$l.invdx = pb.div(this.stepDir, this.delta.x);
|
|
183
|
+
this.$l.dQ = pb.mul(pb.sub(this.Q1, this.Q0), this.invdx);
|
|
184
|
+
this.$l.dK = pb.mul(pb.sub(this.k1, this.k0), this.invdx);
|
|
185
|
+
this.$l.dP = pb.vec2(this.stepDir, pb.mul(this.delta.y, this.invdx));
|
|
186
|
+
//this.$l.strideScalar = pb.sub(1, pb.min(1, pb.div(pb.neg(this.rayOrigin.z), this.strideZCutoff)));
|
|
187
|
+
//this.$l.pixelStride = pb.add(1, pb.mul(this.strideScalar, this.stride));
|
|
188
|
+
this.$l.pixelStride = this.stride;
|
|
189
|
+
this.dP = pb.mul(this.dP, this.pixelStride);
|
|
190
|
+
this.dQ = pb.mul(this.dQ, this.pixelStride);
|
|
191
|
+
this.dK = pb.mul(this.dK, this.pixelStride);
|
|
192
|
+
this.$l.jitter = pb.float(1); //dither(this, this.P0);
|
|
193
|
+
this.P0 = pb.add(this.P0, pb.mul(this.dP, this.jitter));
|
|
194
|
+
this.Q0 = pb.add(this.Q0, pb.mul(this.dQ, this.jitter));
|
|
195
|
+
this.k0 = pb.add(this.k0, pb.mul(this.dK, this.jitter));
|
|
196
|
+
this.$l.prevZMaxEstimate = this.rayOrigin.z;
|
|
197
|
+
this.$l.zA = this.prevZMaxEstimate;
|
|
198
|
+
this.$l.zB = this.prevZMaxEstimate;
|
|
199
|
+
this.$l.pqk = pb.vec4(this.P0, this.Q0.z, this.k0);
|
|
200
|
+
this.$l.dpqk = pb.vec4(this.dP, this.dQ.z, this.dK);
|
|
201
|
+
this.$l.invRenderTargetSize = pb.div(pb.vec2(1), this.textureSize.zw);
|
|
202
|
+
this.$l.intersected = false;
|
|
203
|
+
this.$l.hitUV = pb.vec2();
|
|
204
|
+
this.$l.hitZ = pb.float();
|
|
205
|
+
this.numIterations = 0;
|
|
206
|
+
this.skippedIterations = pb.min(this.maxIterations, 2);
|
|
207
|
+
this.$for(pb.float('i'), 0, pb.getDevice().type === 'webgl' ? 1000 : this.maxIterations, function() {
|
|
208
|
+
if (pb.getDevice().type === 'webgl') {
|
|
209
|
+
this.$if(pb.greaterThanEqual(this.i, this.maxIterations), function() {
|
|
210
|
+
this.$break();
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
this.$if(pb.and(this.intersected, pb.greaterThanEqual(this.i, this.skippedIterations)), function() {
|
|
214
|
+
this.$break();
|
|
215
|
+
});
|
|
216
|
+
this.numIterations = pb.add(this.numIterations, 1);
|
|
217
|
+
this.pqk = pb.add(this.pqk, this.dpqk);
|
|
218
|
+
this.zA = this.prevZMaxEstimate;
|
|
219
|
+
this.zB = pb.div(pb.add(pb.mul(this.dpqk.z, 0.5), this.pqk.z), pb.add(pb.mul(this.dpqk.w, 0.5), this.pqk.w));
|
|
220
|
+
this.zB = pb.clamp(this.zB, this.zMin, this.zMax);
|
|
221
|
+
this.prevZMaxEstimate = this.zB;
|
|
222
|
+
this.hitZ = this.zB;
|
|
223
|
+
this.$if(pb.greaterThan(this.zB, this.zA), function() {
|
|
224
|
+
this.$l.t = this.zB;
|
|
225
|
+
this.zB = this.zA;
|
|
226
|
+
this.zA = this.t;
|
|
227
|
+
});
|
|
228
|
+
this.hitUV = this.$choice(this.permute, this.pqk.yx, this.pqk.xy);
|
|
229
|
+
this.hitUV = pb.mul(this.hitUV, this.invRenderTargetSize);
|
|
230
|
+
this.intersected = this.rayIntersectDepth(this.zA, this.zB, this.thickness, this.hitUV, this.cameraNearFar.y);
|
|
231
|
+
});
|
|
232
|
+
this.hit2D = pb.vec3(this.hitUV, this.hitZ);
|
|
233
|
+
this.Q0 = pb.vec3(pb.add(this.Q0.xy, pb.mul(this.dQ.xy, this.numIterations)), this.pqk.z);
|
|
234
|
+
this.hit3D = pb.div(this.Q0, this.pqk.w);
|
|
235
|
+
this.$return(this.intersected);
|
|
236
|
+
});
|
|
237
|
+
pb.func('SSR_Linear2D', [
|
|
238
|
+
pb.vec3('rayOrigin'),
|
|
239
|
+
pb.vec3('rayDirection'),
|
|
240
|
+
pb.mat4('viewMatrix'),
|
|
241
|
+
pb.mat4('projMatrix'),
|
|
242
|
+
pb.mat4('invProjMatrix'),
|
|
243
|
+
pb.float('stride'),
|
|
244
|
+
pb.float('strideZCutoff'),
|
|
245
|
+
pb.float('maxDistance'),
|
|
246
|
+
pb.float('maxIterations'),
|
|
247
|
+
pb.float('thickness'),
|
|
248
|
+
pb.vec2('cameraNearFar'),
|
|
249
|
+
pb.vec4('textureSize')
|
|
250
|
+
], function() {
|
|
251
|
+
this.$l.hit2D = pb.vec3();
|
|
252
|
+
this.$l.hit3D = pb.vec3();
|
|
253
|
+
this.$l.origin = pb.vec2();
|
|
254
|
+
this.$l.numIterations = pb.float();
|
|
255
|
+
this.$l.intersected = this.traceRayLinear2D(this.rayOrigin, this.rayDirection, this.stride, this.strideZCutoff, this.maxDistance, this.maxIterations, this.thickness, this.cameraNearFar, this.projMatrix, this.textureSize, this.hit2D, this.hit3D, this.origin, this.numIterations);
|
|
256
|
+
this.$if(pb.not(this.intersected), function() {
|
|
257
|
+
this.$return(pb.vec4(0));
|
|
258
|
+
});
|
|
259
|
+
this.$l.surfaceZ01 = sampleLinearDepth(this, linearDepthTex, this.hit2D.xy, 0);
|
|
260
|
+
this.$if(pb.equal(this.surfaceZ01, 1), function() {
|
|
261
|
+
this.$return(pb.vec4(0));
|
|
262
|
+
});
|
|
263
|
+
this.$l.surfaceZ = ShaderHelper.linearDepthToNonLinear(this, pb.mul(this.surfaceZ01, this.cameraNearFar.y), this.cameraNearFar);
|
|
264
|
+
this.$l.confidence = validateHit(this, this.hit2D.xy, null, this.surfaceZ, null, this.origin, this.rayDirection, this.viewMatrix, this.invProjMatrix, this.textureSize, normalTexture);
|
|
265
|
+
this.$l.iterationAttenuation = pb.sub(1, pb.smoothStep(0, this.maxIterations, this.numIterations));
|
|
266
|
+
//this.$l.iterationAttenuation = pb.smoothStep(this.maxIterations, 1, this.numIterations);
|
|
267
|
+
this.confidence = pb.mul(this.confidence, this.iterationAttenuation);
|
|
268
|
+
this.$l.hitPixel = pb.mul(this.hit2D.xy, this.textureSize.zw);
|
|
269
|
+
this.$l.startPixel = pb.mul(this.origin.xy, this.textureSize.zw);
|
|
270
|
+
this.$l.hitDistance = pb.length(pb.sub(this.hitPixel, this.startPixel));
|
|
271
|
+
this.$return(pb.vec4(this.hit2D.xy, this.hitDistance, this.confidence));
|
|
272
|
+
});
|
|
273
|
+
return scope.SSR_Linear2D(viewPos, traceRay, viewMatrix, projMatrix, invProjMatrix, stride, 100, maxDistance, maxIterations, thickness, cameraNearFar, textureSize);
|
|
274
|
+
}
|
|
275
|
+
function screenSpaceRayTracing_HiZ(scope, viewPos, traceRay, viewMatrix, projMatrix, invProjMatrix, cameraNearFar, maxMipLevel, maxIterations, thickness, textureSize, HiZTexture, normalTexture) {
|
|
276
|
+
const pb = scope.$builder;
|
|
277
|
+
pb.func('getMipResolution', [
|
|
278
|
+
pb.int('mipLevel')
|
|
279
|
+
], function() {
|
|
280
|
+
this.$return(pb.vec2(pb.textureDimensions(HiZTexture, this.mipLevel)));
|
|
281
|
+
});
|
|
282
|
+
pb.func('SSR_loadDepth', [
|
|
283
|
+
pb.vec2('uv'),
|
|
284
|
+
pb.float('level')
|
|
285
|
+
], function() {
|
|
286
|
+
this.$return(pb.textureSampleLevel(HiZTexture, this.uv, this.level).r);
|
|
287
|
+
});
|
|
288
|
+
pb.func('invProjectPosition', [
|
|
289
|
+
pb.vec3('p'),
|
|
290
|
+
pb.mat4('mat')
|
|
291
|
+
], function() {
|
|
292
|
+
this.$l.c = pb.sub(pb.mul(this.p, 2), pb.vec3(1));
|
|
293
|
+
this.$l.u = pb.mul(this.mat, pb.vec4(this.c, 1));
|
|
294
|
+
this.u = pb.div(this.u, this.u.w);
|
|
295
|
+
this.$return(this.u.xyz);
|
|
296
|
+
});
|
|
297
|
+
pb.func('projectPosition', [
|
|
298
|
+
pb.vec3('p'),
|
|
299
|
+
pb.mat4('mat')
|
|
300
|
+
], function() {
|
|
301
|
+
this.$l.projected = pb.mul(this.mat, pb.vec4(this.p, 1));
|
|
302
|
+
this.projected = pb.div(this.projected, this.projected.w);
|
|
303
|
+
this.projected = pb.add(pb.mul(this.projected, 0.5), pb.vec4(0.5));
|
|
304
|
+
this.$return(this.projected.xyz);
|
|
305
|
+
});
|
|
306
|
+
pb.func('projectDirection', [
|
|
307
|
+
pb.vec3('p'),
|
|
308
|
+
pb.vec3('d'),
|
|
309
|
+
pb.vec3('screenSpacePos'),
|
|
310
|
+
pb.mat4('mat')
|
|
311
|
+
], function() {
|
|
312
|
+
this.$return(pb.sub(this.projectPosition(pb.add(this.p, this.d), this.mat), this.screenSpacePos));
|
|
313
|
+
});
|
|
314
|
+
pb.func('SSR_initialAdvanceRay', [
|
|
315
|
+
pb.vec3('origin'),
|
|
316
|
+
pb.vec3('direction'),
|
|
317
|
+
pb.vec3('invDirection'),
|
|
318
|
+
pb.vec2('currentMipResolution'),
|
|
319
|
+
pb.vec2('invCurrentMipResolution'),
|
|
320
|
+
pb.vec2('floorOffset'),
|
|
321
|
+
pb.vec2('uvOffset'),
|
|
322
|
+
pb.vec3('position').out(),
|
|
323
|
+
pb.float('currentT').out()
|
|
324
|
+
], function() {
|
|
325
|
+
this.$l.currentMipPosition = pb.mul(this.currentMipResolution, this.origin.xy);
|
|
326
|
+
this.$l.xyPlane = pb.add(pb.floor(this.currentMipPosition), this.floorOffset);
|
|
327
|
+
this.xyPlane = pb.add(pb.mul(this.xyPlane, this.invCurrentMipResolution), this.uvOffset);
|
|
328
|
+
this.$l.t = pb.mul(pb.sub(this.xyPlane, this.origin.xy), this.invDirection.xy);
|
|
329
|
+
this.currentT = pb.min(this.t.x, this.t.y);
|
|
330
|
+
this.position = pb.add(this.origin, pb.mul(this.direction, this.currentT));
|
|
331
|
+
});
|
|
332
|
+
pb.func('SSR_advanceRay', [
|
|
333
|
+
pb.vec3('origin'),
|
|
334
|
+
pb.vec3('direction'),
|
|
335
|
+
pb.vec3('invDirection'),
|
|
336
|
+
pb.vec2('currentMipPosition'),
|
|
337
|
+
pb.vec2('invCurrentMipResolution'),
|
|
338
|
+
pb.vec2('floorOffset'),
|
|
339
|
+
pb.vec2('uvOffset'),
|
|
340
|
+
pb.float('surfaceZ'),
|
|
341
|
+
pb.vec3('position').inout(),
|
|
342
|
+
pb.float('currentT').inout()
|
|
343
|
+
], function() {
|
|
344
|
+
this.$l.xyPlane = pb.add(pb.floor(this.currentMipPosition), this.floorOffset);
|
|
345
|
+
this.xyPlane = pb.add(pb.mul(this.xyPlane, this.invCurrentMipResolution), this.uvOffset);
|
|
346
|
+
this.$l.boundaryPlanes = pb.vec3(this.xyPlane, this.surfaceZ);
|
|
347
|
+
this.$l.t = pb.mul(pb.sub(this.boundaryPlanes, this.origin), this.invDirection);
|
|
348
|
+
this.t.z = this.$choice(pb.greaterThan(this.direction.z, 0), this.t.z, MAX_FLOAT_VALUE);
|
|
349
|
+
this.$l.tMin = pb.min(pb.min(this.t.x, this.t.y), this.t.z);
|
|
350
|
+
this.$l.aboveSurface = pb.greaterThan(this.surfaceZ, this.position.z);
|
|
351
|
+
this.$l.skippedTile = pb.and(pb.notEqual(pb.floatBitsToUint(this.tMin), pb.floatBitsToUint(this.t.z)), this.aboveSurface);
|
|
352
|
+
this.currentT = this.$choice(this.aboveSurface, this.tMin, this.currentT);
|
|
353
|
+
this.position = pb.add(this.origin, pb.mul(this.direction, this.currentT));
|
|
354
|
+
this.$return(this.skippedTile);
|
|
355
|
+
});
|
|
356
|
+
pb.func('SSR_RaymarchHiZ', [
|
|
357
|
+
pb.vec3('screenSpacePos'),
|
|
358
|
+
pb.vec3('screenSpaceDirection'),
|
|
359
|
+
pb.vec2('cameraNearFar'),
|
|
360
|
+
pb.vec2('screenSize'),
|
|
361
|
+
pb.int('mostDetailMip'),
|
|
362
|
+
pb.int('maxMipLevel'),
|
|
363
|
+
pb.float('maxIterations'),
|
|
364
|
+
pb.float('numIterations').out()
|
|
365
|
+
], function() {
|
|
366
|
+
this.$l.invDirection = this.$choice(pb.all(pb.compNotEqual(this.screenSpaceDirection, pb.vec3(0))), pb.div(pb.vec3(1), this.screenSpaceDirection), pb.vec3(MAX_FLOAT_VALUE));
|
|
367
|
+
this.$l.currentMip = this.mostDetailMip;
|
|
368
|
+
this.$l.currentMipResolution = this.getMipResolution(this.currentMip);
|
|
369
|
+
this.$l.invCurrentMipResolution = pb.div(pb.vec2(1), this.currentMipResolution);
|
|
370
|
+
this.$l.uvOffset = pb.div(pb.mul(0.005, pb.exp2(pb.float(this.mostDetailMip))), this.screenSize);
|
|
371
|
+
/*
|
|
372
|
+
this.$l.uvOffset = pb.div(
|
|
373
|
+
pb.vec2(0.001),
|
|
374
|
+
//pb.mul(pb.exp2(pb.float(this.mostDetailMip)), 0.005),
|
|
375
|
+
pb.vec2(pb.textureDimensions(HiZTexture, this.mostDetailMip))
|
|
376
|
+
);
|
|
377
|
+
*/ this.uvOffset = pb.vec2(this.$choice(pb.lessThan(this.screenSpaceDirection.x, 0), pb.neg(this.uvOffset.x), this.uvOffset.x), this.$choice(pb.lessThan(this.screenSpaceDirection.y, 0), pb.neg(this.uvOffset.y), this.uvOffset.y));
|
|
378
|
+
this.$l.floorOffset = pb.vec2(this.$choice(pb.lessThan(this.screenSpaceDirection.x, 0), pb.float(0), pb.float(1)), this.$choice(pb.lessThan(this.screenSpaceDirection.y, 0), pb.float(0), pb.float(1)));
|
|
379
|
+
this.$l.currentT = pb.float();
|
|
380
|
+
this.$l.position = pb.vec3();
|
|
381
|
+
this.SSR_initialAdvanceRay(this.screenSpacePos, this.screenSpaceDirection, this.invDirection, this.currentMipResolution, this.invCurrentMipResolution, this.floorOffset, this.uvOffset, this.position, this.currentT);
|
|
382
|
+
this.numIterations = pb.float(0);
|
|
383
|
+
this.$while(pb.and(pb.lessThan(this.numIterations, this.maxIterations), pb.greaterThanEqual(this.currentMip, this.mostDetailMip)), function() {
|
|
384
|
+
this.$l.currentMipPosition = pb.mul(this.currentMipResolution, this.position.xy);
|
|
385
|
+
this.$l.surfaceZ = pb.textureLoad(HiZTexture, pb.ivec2(this.currentMipPosition), this.currentMip).r;
|
|
386
|
+
this.$l.skippedTile = this.SSR_advanceRay(this.screenSpacePos, this.screenSpaceDirection, this.invDirection, this.currentMipPosition, this.invCurrentMipResolution, this.floorOffset, this.uvOffset, this.surfaceZ, this.position, this.currentT);
|
|
387
|
+
this.$l.nextMipIsOutOfRange = pb.and(this.skippedTile, pb.greaterThanEqual(this.currentMip, this.maxMipLevel));
|
|
388
|
+
this.$if(pb.not(this.nextMipIsOutOfRange), function() {
|
|
389
|
+
this.currentMip = pb.add(this.currentMip, this.$choice(this.skippedTile, pb.int(1), pb.int(-1)));
|
|
390
|
+
this.currentMipResolution = pb.mul(this.currentMipResolution, this.$choice(this.skippedTile, 0.5, 2));
|
|
391
|
+
this.invCurrentMipResolution = pb.mul(this.invCurrentMipResolution, this.$choice(this.skippedTile, 2, 0.5));
|
|
392
|
+
});
|
|
393
|
+
this.numIterations = pb.add(this.numIterations, 1);
|
|
394
|
+
});
|
|
395
|
+
this.$l.validHit = this.$choice(pb.lessThanEqual(this.numIterations, this.maxIterations), pb.float(1), pb.float(0));
|
|
396
|
+
this.$return(pb.vec4(this.position, this.validHit));
|
|
397
|
+
});
|
|
398
|
+
pb.func('SSR_HiZ', [
|
|
399
|
+
pb.vec3('viewPos'),
|
|
400
|
+
pb.vec3('traceRay'),
|
|
401
|
+
pb.mat4('viewMatrix'),
|
|
402
|
+
pb.mat4('projMatrix'),
|
|
403
|
+
pb.mat4('invProjMatrix'),
|
|
404
|
+
pb.vec2('cameraNearFar'),
|
|
405
|
+
pb.float('thickness'),
|
|
406
|
+
pb.vec4('textureSize'),
|
|
407
|
+
pb.int('maxMipLevel'),
|
|
408
|
+
pb.float('maxIterations')
|
|
409
|
+
], function() {
|
|
410
|
+
this.$if(pb.greaterThan(this.traceRay.z, 0), function() {
|
|
411
|
+
this.$return(pb.vec4(0));
|
|
412
|
+
});
|
|
413
|
+
this.$l.originH = pb.mul(this.projMatrix, pb.vec4(this.viewPos, 1));
|
|
414
|
+
this.$l.originCS = pb.div(this.originH.xyz, this.originH.w);
|
|
415
|
+
this.$l.originTS = pb.add(pb.mul(this.originCS, 0.5), pb.vec3(0.5));
|
|
416
|
+
this.$l.directionTS = this.projectDirection(this.viewPos, this.traceRay, this.originTS, this.projMatrix);
|
|
417
|
+
this.$l.mostDetailMip = pb.int(0);
|
|
418
|
+
this.$l.numIterations = pb.float();
|
|
419
|
+
this.$l.hit = this.SSR_RaymarchHiZ(this.originTS, this.directionTS, this.cameraNearFar, this.textureSize.zw, this.mostDetailMip, this.maxMipLevel, this.maxIterations, this.numIterations);
|
|
420
|
+
this.$l.confidence = pb.float(0);
|
|
421
|
+
this.$if(pb.notEqual(this.hit.w, 0), function() {
|
|
422
|
+
this.$l.surfaceZ = pb.textureSampleLevel(HiZTexture, this.hit.xy, 0).r;
|
|
423
|
+
this.$if(pb.equal(this.surfaceZ, 1), function() {
|
|
424
|
+
this.$return(pb.vec4(0));
|
|
425
|
+
});
|
|
426
|
+
this.$l.hit3D = invProjectPosition(this, this.hit.xyz, this.invProjMatrix);
|
|
427
|
+
this.confidence = validateHit(this, this.hit.xy, this.hit3D, this.surfaceZ, this.thickness, this.originTS.xy, this.traceRay, this.viewMatrix, this.invProjMatrix, this.textureSize, normalTexture);
|
|
428
|
+
});
|
|
429
|
+
this.$l.iterationAttenuation = pb.sub(1, pb.smoothStep(0, this.maxIterations, this.numIterations));
|
|
430
|
+
this.$l.viewAttenuation = pb.sub(1, pb.smoothStep(-0.5, 0, this.traceRay.z));
|
|
431
|
+
//this.$l.iterationAttenuation = pb.smoothStep(this.maxIterations, 1, this.numIterations);
|
|
432
|
+
this.confidence = pb.mul(this.confidence, this.iterationAttenuation, this.viewAttenuation);
|
|
433
|
+
this.$l.hitPixel = pb.mul(this.hit.xy, this.textureSize.zw);
|
|
434
|
+
this.$l.startPixel = pb.mul(this.originTS.xy, this.textureSize.zw);
|
|
435
|
+
this.$l.hitDistance = pb.length(pb.sub(this.hitPixel, this.startPixel));
|
|
436
|
+
this.$return(pb.vec4(this.hit.xy, this.hitDistance, this.confidence));
|
|
437
|
+
});
|
|
438
|
+
return scope.SSR_HiZ(viewPos, traceRay, viewMatrix, projMatrix, invProjMatrix, cameraNearFar, thickness, textureSize, pb.sub(maxMipLevel, 1), maxIterations);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
export { SSR_calcJitter, sampleLinearDepth, sampleLinearDepthWithBackface, screenSpaceRayTracing_HiZ, screenSpaceRayTracing_Linear2D };
|
|
442
|
+
//# sourceMappingURL=ssr.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"ssr.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|