@threedog/post-effects 0.1.0 → 0.2.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.
Files changed (3) hide show
  1. package/dof.js +5 -5
  2. package/outline.js +4 -4
  3. package/package.json +2 -2
package/dof.js CHANGED
@@ -11,13 +11,13 @@ class DofPass extends Pass {
11
11
  this.camera = camera;
12
12
  this.keepsDepth = true;
13
13
  this.material = new THREE.ShaderMaterial({
14
- uniforms: { tDiffuse: { value: null }, tDepth: { value: null }, uTexel: { value: new THREE.Vector2() }, uNear: { value: 0.3 }, uFar: { value: 1000 },
14
+ uniforms: { tDiffuse: { value: null }, tDepth: { value: null }, uTexel: { value: new THREE.Vector2() }, uNear: { value: 0.3 }, uFar: { value: 1000 }, uOrtho: { value: 0 },
15
15
  uFocus: { value: 10 }, uRange: { value: 2 }, uFalloff: { value: 20 }, uMaxBlur: { value: 6 } },
16
16
  vertexShader: 'varying vec2 vUv; void main(){ vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }',
17
- fragmentShader: `uniform sampler2D tDiffuse; uniform sampler2D tDepth; uniform vec2 uTexel; uniform float uNear; uniform float uFar;
17
+ fragmentShader: `uniform sampler2D tDiffuse; uniform sampler2D tDepth; uniform vec2 uTexel; uniform float uNear; uniform float uFar; uniform float uOrtho;
18
18
  uniform float uFocus; uniform float uRange; uniform float uFalloff; uniform float uMaxBlur;
19
19
  varying vec2 vUv;
20
- float lin(vec2 uv){ float z = texture2D(tDepth, uv).x * 2.0 - 1.0; return 2.0 * uNear * uFar / (uFar + uNear - z * (uFar - uNear)); }
20
+ float lin(vec2 uv){ float z = texture2D(tDepth, uv).x * 2.0 - 1.0; if (uOrtho > 0.5) return uNear + (z * 0.5 + 0.5) * (uFar - uNear); return 2.0 * uNear * uFar / (uFar + uNear - z * (uFar - uNear)); }
21
21
  float coc(float d){ return clamp((abs(d - uFocus) - uRange) / uFalloff, 0.0, 1.0) * uMaxBlur; }
22
22
  void main(){
23
23
  gl_FragDepth = texture2D(tDepth, vUv).x;
@@ -42,7 +42,7 @@ class DofPass extends Pass {
42
42
  const u = this.material.uniforms;
43
43
  u.tDiffuse.value = readBuffer.texture; u.tDepth.value = readBuffer.depthTexture;
44
44
  u.uTexel.value.set(1 / readBuffer.width, 1 / readBuffer.height);
45
- u.uNear.value = this.camera.near; u.uFar.value = this.camera.far;
45
+ u.uNear.value = this.camera.near; u.uFar.value = this.camera.far; u.uOrtho.value = this.camera.isOrthographicCamera ? 1 : 0; // ortho depth is linear already
46
46
  renderer.setRenderTarget(this.renderToScreen ? null : writeBuffer);
47
47
  this.quad.render(renderer);
48
48
  }
@@ -53,7 +53,7 @@ class DofPass extends Pass {
53
53
  * Depth of field (hdr slot, costly): everything farther from `focus` than `range` blurs, up to `maxBlur` pixels over `falloff` meters.
54
54
  * It reads scene depth, so it must run before any pass that swaps buffers; it passes the scene depth on in its output, so a depth reader
55
55
  * after it (outline, whose default order is later) works: both can be on, lines drawn over the blurred image. Move the focus per frame with
56
- * engine.post.get('dof').set({ focus: distanceToTarget }).
56
+ * engine.look.post.set({ 'dof.focus': distanceToTarget }).
57
57
  * @example post: [dof({ enabled: true, focus: 8, range: 3, maxBlur: 5 })]
58
58
  * @param {{ focus?: number, range?: number, falloff?: number, maxBlur?: number, enabled?: boolean, order?: number }} [o]
59
59
  * focus, range, falloff in meters; maxBlur in device pixels
package/outline.js CHANGED
@@ -18,14 +18,14 @@ class OutlinePass extends Pass {
18
18
  this.normalRT = null; this.maskRT = null;
19
19
  this.material = new THREE.ShaderMaterial({
20
20
  uniforms: { tDiffuse: { value: null }, tDepth: { value: null }, tNormal: { value: null }, tMask: { value: null }, tMaskDepth: { value: null },
21
- uTexel: { value: new THREE.Vector2() }, uNear: { value: 0.3 }, uFar: { value: 1000 }, uColor: { value: new THREE.Color(p.color) },
21
+ uTexel: { value: new THREE.Vector2() }, uNear: { value: 0.3 }, uFar: { value: 1000 }, uOrtho: { value: 0 }, uColor: { value: new THREE.Color(p.color) },
22
22
  uThick: { value: 1 }, uStrength: { value: 1 }, uMode: { value: 0 }, uFade: { value: 1 }, uWobble: { value: 0 }, uTime: { value: 0 }, uUseMask: { value: 0 } },
23
23
  vertexShader: 'varying vec2 vUv; void main(){ vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }',
24
24
  fragmentShader: `uniform sampler2D tDiffuse; uniform sampler2D tDepth; uniform sampler2D tNormal; uniform sampler2D tMask; uniform sampler2D tMaskDepth;
25
- uniform vec2 uTexel; uniform float uNear; uniform float uFar; uniform vec3 uColor; uniform float uThick; uniform float uStrength;
25
+ uniform vec2 uTexel; uniform float uNear; uniform float uFar; uniform float uOrtho; uniform vec3 uColor; uniform float uThick; uniform float uStrength;
26
26
  uniform float uMode; uniform float uFade; uniform float uWobble; uniform float uTime; uniform float uUseMask;
27
27
  varying vec2 vUv;
28
- float lin(sampler2D t, vec2 uv){ float z = texture2D(t, uv).x * 2.0 - 1.0; return 2.0 * uNear * uFar / (uFar + uNear - z * (uFar - uNear)); }
28
+ float lin(sampler2D t, vec2 uv){ float z = texture2D(t, uv).x * 2.0 - 1.0; if (uOrtho > 0.5) return uNear + (z * 0.5 + 0.5) * (uFar - uNear); return 2.0 * uNear * uFar / (uFar + uNear - z * (uFar - uNear)); }
29
29
  float h2(vec2 p){ return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
30
30
  float vn(vec2 p){ vec2 i = floor(p), f = fract(p); f = f * f * (3.0 - 2.0 * f);
31
31
  return mix(mix(h2(i), h2(i + vec2(1, 0)), f.x), mix(h2(i + vec2(0, 1)), h2(i + vec2(1, 1)), f.x), f.y); }
@@ -85,7 +85,7 @@ class OutlinePass extends Pass {
85
85
  if (useMask) { this.maskRT = this._target(this.maskRT, w, h, true); this._pass(renderer, this.maskRT, this.maskMat, p.offLayer); u.tMask.value = this.maskRT.texture; u.tMaskDepth.value = this.maskRT.depthTexture; }
86
86
  u.tDiffuse.value = readBuffer.texture; u.tDepth.value = readBuffer.depthTexture;
87
87
  u.uTexel.value.set(1 / w, 1 / h);
88
- u.uNear.value = this.camera.near; u.uFar.value = this.camera.far;
88
+ u.uNear.value = this.camera.near; u.uFar.value = this.camera.far; u.uOrtho.value = this.camera.isOrthographicCamera ? 1 : 0; // ortho depth is linear already
89
89
  u.uMode.value = mode; u.uUseMask.value = useMask ? 1 : 0; u.uTime.value = Math.floor(this.time * 8);
90
90
  renderer.setRenderTarget(this.renderToScreen ? null : writeBuffer);
91
91
  this.quad.render(renderer);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threedog/post-effects",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Optional post effects for threedog: bloom, ambient occlusion, outline, LUT color grading, film grain, vignette, chromatic aberration and depth of field (light ldr effects are fused into one fullscreen pass)",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -24,7 +24,7 @@
24
24
  "*.d.ts"
25
25
  ],
26
26
  "peerDependencies": {
27
- "threedog": "^0.1.0",
27
+ "threedog": "^0.2.0",
28
28
  "three": "^0.187.0"
29
29
  }
30
30
  }