@woosh/meep-engine 2.34.40 → 2.34.41
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/core/bvh2/BinaryNode.spec.js +1 -0
- package/engine/graphics/composit/CompositLayer.js +15 -1
- package/engine/graphics/ecs/highlight/plugin/OutlineRenderPlugin.js +7 -0
- package/engine/graphics/render/buffer/simple-fx/DepthLimitedBlur.js +27 -4
- package/engine/graphics/render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.js +7 -2
- package/engine/graphics/render/buffer/simple-fx/ao/SAOShader.js +186 -187
- package/engine/graphics/render/visibility/hiz/buildCanvasViewFromTexture.js +3 -3
- package/package.json +1 -1
|
@@ -58,7 +58,7 @@ export class CompositLayer {
|
|
|
58
58
|
*
|
|
59
59
|
* @type {BlendingType}
|
|
60
60
|
*/
|
|
61
|
-
this.
|
|
61
|
+
this.__blending = blending;
|
|
62
62
|
/**
|
|
63
63
|
*
|
|
64
64
|
* @type {WebGLRenderTarget}
|
|
@@ -98,6 +98,20 @@ export class CompositLayer {
|
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
get blending() {
|
|
102
|
+
return this.__blending;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
set blending(v) {
|
|
106
|
+
if (v === this.__blending) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
this.__blending = v;
|
|
111
|
+
|
|
112
|
+
assignMaterialBlending(this.object.material, v);
|
|
113
|
+
}
|
|
114
|
+
|
|
101
115
|
/**
|
|
102
116
|
*
|
|
103
117
|
* @param {number} v
|
|
@@ -8,6 +8,7 @@ import { ObjectPoolFactory } from "../../../../../core/model/object/ObjectPoolFa
|
|
|
8
8
|
import { HighlightRenderElement } from "../renderer/HighlightRenderElement.js";
|
|
9
9
|
import { noop } from "../../../../../core/function/Functions.js";
|
|
10
10
|
import { CompositingStages } from "../../../composit/CompositingStages.js";
|
|
11
|
+
import { ProcessState } from "../../../../../core/process/ProcessState.js";
|
|
11
12
|
|
|
12
13
|
export class OutlineRenderPlugin extends EnginePlugin {
|
|
13
14
|
constructor() {
|
|
@@ -137,6 +138,12 @@ export class OutlineRenderPlugin extends EnginePlugin {
|
|
|
137
138
|
}
|
|
138
139
|
|
|
139
140
|
async startup() {
|
|
141
|
+
|
|
142
|
+
if (this.getState().getValue() === ProcessState.Running) {
|
|
143
|
+
//already running
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
140
147
|
const graphics = this.engine.graphics;
|
|
141
148
|
const viewport_size = graphics.viewport.size;
|
|
142
149
|
|
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Color,
|
|
3
|
+
NoBlending,
|
|
4
|
+
RGBAFormat,
|
|
5
|
+
ShaderMaterial,
|
|
6
|
+
UniformsUtils,
|
|
7
|
+
Vector2,
|
|
8
|
+
WebGLMultisampleRenderTarget
|
|
9
|
+
} from "three";
|
|
2
10
|
import { BlurShaderUtils, DepthLimitedBlurShader } from "three/examples/jsm/shaders/DepthLimitedBlurShader.js";
|
|
3
11
|
import { renderScreenSpace } from "../../utils/renderScreenSpace.js";
|
|
4
12
|
|
|
13
|
+
const scratch_color = new Color();
|
|
14
|
+
|
|
5
15
|
export class DepthLimitedBlur {
|
|
6
|
-
constructor({ format = RGBAFormat, radius = 8 }) {
|
|
16
|
+
constructor({ format = RGBAFormat, radius = 8, clear_color = 0, clear_alpha = 1 }) {
|
|
7
17
|
|
|
8
18
|
/**
|
|
9
19
|
*
|
|
@@ -43,6 +53,9 @@ export class DepthLimitedBlur {
|
|
|
43
53
|
|
|
44
54
|
this.__blur_radius = radius;
|
|
45
55
|
this.__blur_std_dev = 4;
|
|
56
|
+
|
|
57
|
+
this.__clear_color = new Color(clear_color);
|
|
58
|
+
this.__clear_alpha = clear_alpha;
|
|
46
59
|
}
|
|
47
60
|
|
|
48
61
|
configureMaterials() {
|
|
@@ -113,21 +126,31 @@ export class DepthLimitedBlur {
|
|
|
113
126
|
mx.uniforms.size.value.set(this.__rt_output.width, this.__rt_output.height);
|
|
114
127
|
my.uniforms.size.value.set(this.__rt_output.width, this.__rt_output.height);
|
|
115
128
|
|
|
116
|
-
|
|
129
|
+
// remember renderer state
|
|
117
130
|
const __old_state_rt = renderer.getRenderTarget();
|
|
118
|
-
|
|
131
|
+
const __old_clear_color = scratch_color;
|
|
132
|
+
renderer.getClearColor(__old_clear_color);
|
|
133
|
+
const __old_clear_alpha = renderer.getClearAlpha();
|
|
134
|
+
const __old_auto_clear = renderer.autoClear;
|
|
135
|
+
|
|
136
|
+
//
|
|
137
|
+
renderer.autoClear = false;
|
|
138
|
+
renderer.setClearColor(this.__clear_color);
|
|
119
139
|
renderer.setRenderTarget(this.__intermediate);
|
|
120
140
|
renderer.clearColor();
|
|
121
141
|
|
|
122
142
|
renderScreenSpace(renderer, mx);
|
|
123
143
|
|
|
124
144
|
renderer.setRenderTarget(this.__rt_output);
|
|
145
|
+
|
|
125
146
|
renderer.clearColor();
|
|
126
147
|
|
|
127
148
|
renderScreenSpace(renderer, my);
|
|
128
149
|
|
|
129
150
|
// restore state
|
|
130
151
|
renderer.setRenderTarget(__old_state_rt);
|
|
152
|
+
renderer.setClearColor(__old_clear_color, __old_clear_alpha);
|
|
153
|
+
renderer.autoClear = __old_auto_clear;
|
|
131
154
|
}
|
|
132
155
|
|
|
133
156
|
/**
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
RedFormat,
|
|
7
7
|
ShaderMaterial,
|
|
8
8
|
UniformsUtils,
|
|
9
|
+
UnsignedByteType,
|
|
9
10
|
WebGLMultisampleRenderTarget
|
|
10
11
|
} from "three";
|
|
11
12
|
import { SAOShader } from "./SAOShader.js";
|
|
@@ -91,6 +92,8 @@ export class AmbientOcclusionPostProcessEffect extends EnginePlugin {
|
|
|
91
92
|
magFilter: LinearFilter,
|
|
92
93
|
|
|
93
94
|
format: RedFormat,
|
|
95
|
+
type: UnsignedByteType,
|
|
96
|
+
internalFormat: 'R8',
|
|
94
97
|
depthBuffer: false,
|
|
95
98
|
stencilBuffer: false,
|
|
96
99
|
generateMipmaps: false,
|
|
@@ -108,7 +111,7 @@ export class AmbientOcclusionPostProcessEffect extends EnginePlugin {
|
|
|
108
111
|
* @type {DepthLimitedBlur}
|
|
109
112
|
* @private
|
|
110
113
|
*/
|
|
111
|
-
this.__blur = new DepthLimitedBlur({ format: RedFormat });
|
|
114
|
+
this.__blur = new DepthLimitedBlur({ format: RedFormat, clear_color: 0xFFFFFF });
|
|
112
115
|
}
|
|
113
116
|
|
|
114
117
|
/**
|
|
@@ -304,7 +307,9 @@ export class AmbientOcclusionPostProcessEffect extends EnginePlugin {
|
|
|
304
307
|
// bind compositing layer
|
|
305
308
|
this.__composit_layer = graphics.layerComposer.createLayer(
|
|
306
309
|
{
|
|
307
|
-
format: RedFormat
|
|
310
|
+
format: RedFormat,
|
|
311
|
+
type: UnsignedByteType,
|
|
312
|
+
internalFormat: 'R8'
|
|
308
313
|
},
|
|
309
314
|
BlendingType.Multiply
|
|
310
315
|
);
|
|
@@ -1,187 +1,186 @@
|
|
|
1
|
-
import { Matrix4, Vector2 } from 'three';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* TODO
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const SAOShader = {
|
|
8
|
-
defines: {
|
|
9
|
-
'NUM_SAMPLES': 7,
|
|
10
|
-
'NUM_RINGS': 4,
|
|
11
|
-
'NORMAL_TEXTURE': 0,
|
|
12
|
-
'DIFFUSE_TEXTURE': 0,
|
|
13
|
-
'DEPTH_PACKING': 1,
|
|
14
|
-
'PERSPECTIVE_CAMERA': 1
|
|
15
|
-
},
|
|
16
|
-
uniforms: {
|
|
17
|
-
|
|
18
|
-
'tDepth': { value: null },
|
|
19
|
-
'tNormal': { value: null },
|
|
20
|
-
'size': { value: new Vector2(512, 512) },
|
|
21
|
-
|
|
22
|
-
'cameraNear': { value: 1 },
|
|
23
|
-
'cameraFar': { value: 100 },
|
|
24
|
-
'cameraProjectionMatrix': { value: new Matrix4() },
|
|
25
|
-
'cameraInverseProjectionMatrix': { value: new Matrix4() },
|
|
26
|
-
|
|
27
|
-
'intensity': { value: 0.1 },
|
|
28
|
-
'bias': { value: 0.5 },
|
|
29
|
-
|
|
30
|
-
'minResolution': { value: 0.0 },
|
|
31
|
-
'kernelRadius': { value: 100.0 },
|
|
32
|
-
'randomSeed': { value: 0.0 }
|
|
33
|
-
},
|
|
34
|
-
vertexShader: /* glsl */`
|
|
35
|
-
|
|
36
|
-
varying vec2 vUv;
|
|
37
|
-
|
|
38
|
-
void main() {
|
|
39
|
-
vUv = uv;
|
|
40
|
-
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
41
|
-
}`,
|
|
42
|
-
|
|
43
|
-
fragmentShader: /* glsl */`
|
|
44
|
-
|
|
45
|
-
#include <common>
|
|
46
|
-
|
|
47
|
-
varying vec2 vUv;
|
|
48
|
-
|
|
49
|
-
uniform sampler2D tDepth;
|
|
50
|
-
|
|
51
|
-
#if NORMAL_TEXTURE == 1
|
|
52
|
-
uniform sampler2D tNormal;
|
|
53
|
-
#endif
|
|
54
|
-
|
|
55
|
-
uniform float cameraNear;
|
|
56
|
-
uniform float cameraFar;
|
|
57
|
-
uniform mat4 cameraProjectionMatrix;
|
|
58
|
-
uniform mat4 cameraInverseProjectionMatrix;
|
|
59
|
-
|
|
60
|
-
uniform float intensity;
|
|
61
|
-
uniform float bias;
|
|
62
|
-
uniform float kernelRadius;
|
|
63
|
-
uniform float minResolution;
|
|
64
|
-
uniform vec2 size;
|
|
65
|
-
uniform float randomSeed;
|
|
66
|
-
|
|
67
|
-
// RGBA depth
|
|
68
|
-
|
|
69
|
-
#include <packing>
|
|
70
|
-
|
|
71
|
-
out float out_occlusion;
|
|
72
|
-
|
|
73
|
-
float getDepth( const in vec2 screenPosition ) {
|
|
74
|
-
#if DEPTH_PACKING == 1
|
|
75
|
-
return unpackRGBAToDepth( texture2D( tDepth, screenPosition ) );
|
|
76
|
-
#else
|
|
77
|
-
return texture2D( tDepth, screenPosition ).x;
|
|
78
|
-
#endif
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
float getViewZ( const in float depth ) {
|
|
82
|
-
#if PERSPECTIVE_CAMERA == 1
|
|
83
|
-
return perspectiveDepthToViewZ( depth, cameraNear, cameraFar );
|
|
84
|
-
#else
|
|
85
|
-
return orthographicDepthToViewZ( depth, cameraNear, cameraFar );
|
|
86
|
-
#endif
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
vec3 getViewPosition( const in vec2 screenPosition, const in float depth, const in float viewZ ) {
|
|
90
|
-
float clipW = cameraProjectionMatrix[2][3] * viewZ + cameraProjectionMatrix[3][3];
|
|
91
|
-
vec4 clipPosition = vec4( ( vec3( screenPosition, depth ) - 0.5 ) * 2.0, 1.0 );
|
|
92
|
-
clipPosition *= clipW; // unprojection.
|
|
93
|
-
|
|
94
|
-
return ( cameraInverseProjectionMatrix * clipPosition ).xyz;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
vec3 getViewNormal( const in vec3 viewPosition, const in vec2 screenPosition ) {
|
|
98
|
-
#if NORMAL_TEXTURE == 1
|
|
99
|
-
return unpackRGBToNormal( texture2D( tNormal, screenPosition ).xyz );
|
|
100
|
-
#else
|
|
101
|
-
return normalize( cross( dFdx( viewPosition ), dFdy( viewPosition ) ) );
|
|
102
|
-
#endif
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Non-sin based hash function, fast and has good randomness
|
|
106
|
-
float hash12(vec2 p){
|
|
107
|
-
vec3 p3 = fract(vec3(p.xyx) * .1031);
|
|
108
|
-
p3 += dot(p3, p3.yzx + 33.33);
|
|
109
|
-
return fract((p3.x + p3.y) * p3.z);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
float minResolutionMultipliedByCameraFar;
|
|
113
|
-
|
|
114
|
-
float getOcclusion( const in vec3 centerViewPosition, const in vec3 centerViewNormal, const in vec3 sampleViewPosition ) {
|
|
115
|
-
vec3 viewDelta = sampleViewPosition - centerViewPosition;
|
|
116
|
-
|
|
117
|
-
float viewDistance = length( viewDelta );
|
|
118
|
-
|
|
119
|
-
float vn = dot( centerViewNormal, viewDelta );
|
|
120
|
-
float a2 = (vn - minResolutionMultipliedByCameraFar) / viewDistance - bias;
|
|
121
|
-
float a1 = (1.0 + pow2( viewDistance ) );
|
|
122
|
-
|
|
123
|
-
return max(0.0, a2) / a1;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// moving costly divides into consts
|
|
127
|
-
const float ANGLE_STEP = PI2 * float( NUM_RINGS ) / float( NUM_SAMPLES );
|
|
128
|
-
const float INV_NUM_SAMPLES = 1.0 / float( NUM_SAMPLES );
|
|
129
|
-
|
|
130
|
-
float getAmbientOcclusion( const in vec3 centerViewPosition ) {
|
|
131
|
-
// precompute some variables require in getOcclusion.
|
|
132
|
-
minResolutionMultipliedByCameraFar = minResolution * cameraFar;
|
|
133
|
-
vec3 centerViewNormal = getViewNormal( centerViewPosition, vUv );
|
|
134
|
-
|
|
135
|
-
// jsfiddle that shows sample pattern: https://jsfiddle.net/a16ff1p7/
|
|
136
|
-
float angle = hash12( vUv + randomSeed ) * PI2;
|
|
137
|
-
vec2 radius = vec2( kernelRadius * INV_NUM_SAMPLES ) / size;
|
|
138
|
-
|
|
139
|
-
float occlusionSum = 0.0;
|
|
140
|
-
float weightSum = 0.0;
|
|
141
|
-
|
|
142
|
-
for( int i = 0; i < NUM_SAMPLES; i ++ ) {
|
|
143
|
-
vec2 sampleUv = vUv + vec2( cos( angle ), sin( angle ) ) * radius * float(i+1);
|
|
144
|
-
|
|
145
|
-
angle += ANGLE_STEP;
|
|
146
|
-
|
|
147
|
-
float sampleDepth = getDepth( sampleUv );
|
|
148
|
-
|
|
149
|
-
if( sampleDepth >= ( 1.0 - EPSILON ) ) {
|
|
150
|
-
// skip, too far
|
|
151
|
-
continue;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
float sampleViewZ = getViewZ( sampleDepth );
|
|
155
|
-
|
|
156
|
-
vec3 sampleViewPosition = getViewPosition( sampleUv, sampleDepth, sampleViewZ );
|
|
157
|
-
|
|
158
|
-
occlusionSum += getOcclusion( centerViewPosition, centerViewNormal, sampleViewPosition );
|
|
159
|
-
|
|
160
|
-
weightSum += 1.0;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if( weightSum == 0.0 ) discard;
|
|
164
|
-
|
|
165
|
-
return occlusionSum * ( intensity / weightSum );
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
void main() {
|
|
169
|
-
float centerDepth = getDepth( vUv );
|
|
170
|
-
if( centerDepth >= ( 1.0 - EPSILON ) ) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
export { SAOShader };
|
|
1
|
+
import { Matrix4, Vector2 } from 'three';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* TODO
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const SAOShader = {
|
|
8
|
+
defines: {
|
|
9
|
+
'NUM_SAMPLES': 7,
|
|
10
|
+
'NUM_RINGS': 4,
|
|
11
|
+
'NORMAL_TEXTURE': 0,
|
|
12
|
+
'DIFFUSE_TEXTURE': 0,
|
|
13
|
+
'DEPTH_PACKING': 1,
|
|
14
|
+
'PERSPECTIVE_CAMERA': 1
|
|
15
|
+
},
|
|
16
|
+
uniforms: {
|
|
17
|
+
|
|
18
|
+
'tDepth': { value: null },
|
|
19
|
+
'tNormal': { value: null },
|
|
20
|
+
'size': { value: new Vector2(512, 512) },
|
|
21
|
+
|
|
22
|
+
'cameraNear': { value: 1 },
|
|
23
|
+
'cameraFar': { value: 100 },
|
|
24
|
+
'cameraProjectionMatrix': { value: new Matrix4() },
|
|
25
|
+
'cameraInverseProjectionMatrix': { value: new Matrix4() },
|
|
26
|
+
|
|
27
|
+
'intensity': { value: 0.1 },
|
|
28
|
+
'bias': { value: 0.5 },
|
|
29
|
+
|
|
30
|
+
'minResolution': { value: 0.0 },
|
|
31
|
+
'kernelRadius': { value: 100.0 },
|
|
32
|
+
'randomSeed': { value: 0.0 }
|
|
33
|
+
},
|
|
34
|
+
vertexShader: /* glsl */`
|
|
35
|
+
|
|
36
|
+
varying vec2 vUv;
|
|
37
|
+
|
|
38
|
+
void main() {
|
|
39
|
+
vUv = uv;
|
|
40
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
41
|
+
}`,
|
|
42
|
+
|
|
43
|
+
fragmentShader: /* glsl */`
|
|
44
|
+
|
|
45
|
+
#include <common>
|
|
46
|
+
|
|
47
|
+
varying vec2 vUv;
|
|
48
|
+
|
|
49
|
+
uniform sampler2D tDepth;
|
|
50
|
+
|
|
51
|
+
#if NORMAL_TEXTURE == 1
|
|
52
|
+
uniform sampler2D tNormal;
|
|
53
|
+
#endif
|
|
54
|
+
|
|
55
|
+
uniform float cameraNear;
|
|
56
|
+
uniform float cameraFar;
|
|
57
|
+
uniform mat4 cameraProjectionMatrix;
|
|
58
|
+
uniform mat4 cameraInverseProjectionMatrix;
|
|
59
|
+
|
|
60
|
+
uniform float intensity;
|
|
61
|
+
uniform float bias;
|
|
62
|
+
uniform float kernelRadius;
|
|
63
|
+
uniform float minResolution;
|
|
64
|
+
uniform vec2 size;
|
|
65
|
+
uniform float randomSeed;
|
|
66
|
+
|
|
67
|
+
// RGBA depth
|
|
68
|
+
|
|
69
|
+
#include <packing>
|
|
70
|
+
|
|
71
|
+
out float out_occlusion;
|
|
72
|
+
|
|
73
|
+
float getDepth( const in vec2 screenPosition ) {
|
|
74
|
+
#if DEPTH_PACKING == 1
|
|
75
|
+
return unpackRGBAToDepth( texture2D( tDepth, screenPosition ) );
|
|
76
|
+
#else
|
|
77
|
+
return texture2D( tDepth, screenPosition ).x;
|
|
78
|
+
#endif
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
float getViewZ( const in float depth ) {
|
|
82
|
+
#if PERSPECTIVE_CAMERA == 1
|
|
83
|
+
return perspectiveDepthToViewZ( depth, cameraNear, cameraFar );
|
|
84
|
+
#else
|
|
85
|
+
return orthographicDepthToViewZ( depth, cameraNear, cameraFar );
|
|
86
|
+
#endif
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
vec3 getViewPosition( const in vec2 screenPosition, const in float depth, const in float viewZ ) {
|
|
90
|
+
float clipW = cameraProjectionMatrix[2][3] * viewZ + cameraProjectionMatrix[3][3];
|
|
91
|
+
vec4 clipPosition = vec4( ( vec3( screenPosition, depth ) - 0.5 ) * 2.0, 1.0 );
|
|
92
|
+
clipPosition *= clipW; // unprojection.
|
|
93
|
+
|
|
94
|
+
return ( cameraInverseProjectionMatrix * clipPosition ).xyz;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
vec3 getViewNormal( const in vec3 viewPosition, const in vec2 screenPosition ) {
|
|
98
|
+
#if NORMAL_TEXTURE == 1
|
|
99
|
+
return unpackRGBToNormal( texture2D( tNormal, screenPosition ).xyz );
|
|
100
|
+
#else
|
|
101
|
+
return normalize( cross( dFdx( viewPosition ), dFdy( viewPosition ) ) );
|
|
102
|
+
#endif
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Non-sin based hash function, fast and has good randomness
|
|
106
|
+
float hash12(vec2 p){
|
|
107
|
+
vec3 p3 = fract(vec3(p.xyx) * .1031);
|
|
108
|
+
p3 += dot(p3, p3.yzx + 33.33);
|
|
109
|
+
return fract((p3.x + p3.y) * p3.z);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
float minResolutionMultipliedByCameraFar;
|
|
113
|
+
|
|
114
|
+
float getOcclusion( const in vec3 centerViewPosition, const in vec3 centerViewNormal, const in vec3 sampleViewPosition ) {
|
|
115
|
+
vec3 viewDelta = sampleViewPosition - centerViewPosition;
|
|
116
|
+
|
|
117
|
+
float viewDistance = length( viewDelta );
|
|
118
|
+
|
|
119
|
+
float vn = dot( centerViewNormal, viewDelta );
|
|
120
|
+
float a2 = (vn - minResolutionMultipliedByCameraFar) / viewDistance - bias;
|
|
121
|
+
float a1 = (1.0 + pow2( viewDistance ) );
|
|
122
|
+
|
|
123
|
+
return max(0.0, a2) / a1;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// moving costly divides into consts
|
|
127
|
+
const float ANGLE_STEP = PI2 * float( NUM_RINGS ) / float( NUM_SAMPLES );
|
|
128
|
+
const float INV_NUM_SAMPLES = 1.0 / float( NUM_SAMPLES );
|
|
129
|
+
|
|
130
|
+
float getAmbientOcclusion( const in vec3 centerViewPosition ) {
|
|
131
|
+
// precompute some variables require in getOcclusion.
|
|
132
|
+
minResolutionMultipliedByCameraFar = minResolution * cameraFar;
|
|
133
|
+
vec3 centerViewNormal = getViewNormal( centerViewPosition, vUv );
|
|
134
|
+
|
|
135
|
+
// jsfiddle that shows sample pattern: https://jsfiddle.net/a16ff1p7/
|
|
136
|
+
float angle = hash12( vUv + randomSeed ) * PI2;
|
|
137
|
+
vec2 radius = vec2( kernelRadius * INV_NUM_SAMPLES ) / size;
|
|
138
|
+
|
|
139
|
+
float occlusionSum = 0.0;
|
|
140
|
+
float weightSum = 0.0;
|
|
141
|
+
|
|
142
|
+
for( int i = 0; i < NUM_SAMPLES; i ++ ) {
|
|
143
|
+
vec2 sampleUv = vUv + vec2( cos( angle ), sin( angle ) ) * radius * float(i+1);
|
|
144
|
+
|
|
145
|
+
angle += ANGLE_STEP;
|
|
146
|
+
|
|
147
|
+
float sampleDepth = getDepth( sampleUv );
|
|
148
|
+
|
|
149
|
+
if( sampleDepth >= ( 1.0 - EPSILON ) ) {
|
|
150
|
+
// skip, too far
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
float sampleViewZ = getViewZ( sampleDepth );
|
|
155
|
+
|
|
156
|
+
vec3 sampleViewPosition = getViewPosition( sampleUv, sampleDepth, sampleViewZ );
|
|
157
|
+
|
|
158
|
+
occlusionSum += getOcclusion( centerViewPosition, centerViewNormal, sampleViewPosition );
|
|
159
|
+
|
|
160
|
+
weightSum += 1.0;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if( weightSum == 0.0 ) discard;
|
|
164
|
+
|
|
165
|
+
return occlusionSum * ( intensity / weightSum );
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
void main() {
|
|
169
|
+
float centerDepth = getDepth( vUv );
|
|
170
|
+
if( centerDepth >= ( 1.0 - EPSILON ) ) {
|
|
171
|
+
discard;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
float centerViewZ = getViewZ( centerDepth );
|
|
175
|
+
vec3 viewPosition = getViewPosition( vUv, centerDepth, centerViewZ );
|
|
176
|
+
|
|
177
|
+
float ambientOcclusion = getAmbientOcclusion( viewPosition );
|
|
178
|
+
|
|
179
|
+
float invOcclusion = 1.0 - ambientOcclusion;
|
|
180
|
+
|
|
181
|
+
out_occlusion = invOcclusion;
|
|
182
|
+
}`
|
|
183
|
+
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export { SAOShader };
|
|
@@ -89,12 +89,12 @@ function makeShader(texture) {
|
|
|
89
89
|
* @param {THREE.Texture} texture
|
|
90
90
|
* @param {THREE.WebGLRenderer} renderer
|
|
91
91
|
* @param flipY
|
|
92
|
-
* @return {{view: View, render:
|
|
92
|
+
* @return {{view: View, render: function}}
|
|
93
93
|
*/
|
|
94
94
|
export function buildCanvasViewFromTexture({
|
|
95
|
-
height,
|
|
96
|
-
width,
|
|
97
95
|
texture = CheckersTexture.create(),
|
|
96
|
+
width = texture.image.width,
|
|
97
|
+
height = texture.image.height,
|
|
98
98
|
renderer,
|
|
99
99
|
flipY = true
|
|
100
100
|
}) {
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"productName": "Meep",
|
|
6
6
|
"description": "production-ready JavaScript game engine based on Entity Component System Architecture",
|
|
7
7
|
"author": "Alexander Goldring",
|
|
8
|
-
"version": "2.34.
|
|
8
|
+
"version": "2.34.41",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"gl-matrix": "3.4.3",
|
|
11
11
|
"fast-levenshtein": "2.0.6",
|