@takram/three-geospatial-effects 0.0.1-alpha.5 → 0.0.1-alpha.6
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/build/r3f.cjs +18 -18
- package/build/r3f.cjs.map +1 -1
- package/build/r3f.js +67 -65
- package/build/r3f.js.map +1 -1
- package/build/shared.cjs +70 -72
- package/build/shared.cjs.map +1 -1
- package/build/shared.js +227 -218
- package/build/shared.js.map +1 -1
- package/package.json +2 -2
- package/src/DepthEffect.ts +22 -18
- package/src/DitheringEffect.ts +1 -5
- package/src/DownsampleThresholdMaterial.ts +10 -11
- package/src/GeometryEffect.ts +19 -15
- package/src/LensFlareEffect.ts +33 -22
- package/src/LensFlareFeaturesMaterial.ts +12 -14
- package/src/NormalEffect.ts +30 -26
- package/src/setupMaterialsForGeometryPass.ts +4 -6
- package/src/shaders/depthEffect.frag +4 -11
- package/src/shaders/downsampleThreshold.frag +14 -16
- package/src/shaders/geometryEffect.frag +4 -2
- package/src/shaders/lensFlareEffect.frag +3 -6
- package/src/shaders/lensFlareFeatures.frag +4 -4
- package/src/shaders/normalEffect.frag +8 -4
- package/types/DepthEffect.d.ts +7 -0
- package/types/GeometryEffect.d.ts +6 -1
- package/types/LensFlareEffect.d.ts +9 -2
- package/types/NormalEffect.d.ts +8 -1
@@ -25,7 +25,7 @@ float clampToBorder(const vec2 uv) {
|
|
25
25
|
|
26
26
|
// Reference: https://learnopengl.com/Guest-Articles/2022/Phys.-Based-Bloom
|
27
27
|
void main() {
|
28
|
-
vec3 color = 0.125 *
|
28
|
+
vec3 color = 0.125 * texture(inputBuffer, vec2(vRowUv5)).rgb;
|
29
29
|
vec4 weight =
|
30
30
|
0.03125 *
|
31
31
|
vec4(
|
@@ -34,10 +34,10 @@ void main() {
|
|
34
34
|
clampToBorder(vRowUv7),
|
35
35
|
clampToBorder(vRowUv9)
|
36
36
|
);
|
37
|
-
color += weight.x *
|
38
|
-
color += weight.y *
|
39
|
-
color += weight.z *
|
40
|
-
color += weight.w *
|
37
|
+
color += weight.x * texture(inputBuffer, vec2(vRowUv1)).rgb;
|
38
|
+
color += weight.y * texture(inputBuffer, vec2(vRowUv3)).rgb;
|
39
|
+
color += weight.z * texture(inputBuffer, vec2(vRowUv7)).rgb;
|
40
|
+
color += weight.w * texture(inputBuffer, vec2(vRowUv9)).rgb;
|
41
41
|
|
42
42
|
weight =
|
43
43
|
0.0625 *
|
@@ -47,10 +47,10 @@ void main() {
|
|
47
47
|
clampToBorder(vRowUv6),
|
48
48
|
clampToBorder(vRowUv8)
|
49
49
|
);
|
50
|
-
color += weight.x *
|
51
|
-
color += weight.y *
|
52
|
-
color += weight.z *
|
53
|
-
color += weight.w *
|
50
|
+
color += weight.x * texture(inputBuffer, vec2(vRowUv2)).rgb;
|
51
|
+
color += weight.y * texture(inputBuffer, vec2(vRowUv4)).rgb;
|
52
|
+
color += weight.z * texture(inputBuffer, vec2(vRowUv6)).rgb;
|
53
|
+
color += weight.w * texture(inputBuffer, vec2(vRowUv8)).rgb;
|
54
54
|
|
55
55
|
weight =
|
56
56
|
0.125 *
|
@@ -60,10 +60,10 @@ void main() {
|
|
60
60
|
clampToBorder(vRowUv6),
|
61
61
|
clampToBorder(vRowUv8)
|
62
62
|
);
|
63
|
-
color += weight.x *
|
64
|
-
color += weight.y *
|
65
|
-
color += weight.z *
|
66
|
-
color += weight.w *
|
63
|
+
color += weight.x * texture(inputBuffer, vec2(vCenterUv1)).rgb;
|
64
|
+
color += weight.y * texture(inputBuffer, vec2(vCenterUv2)).rgb;
|
65
|
+
color += weight.z * texture(inputBuffer, vec2(vCenterUv3)).rgb;
|
66
|
+
color += weight.w * texture(inputBuffer, vec2(vCenterUv4)).rgb;
|
67
67
|
|
68
68
|
// WORKAROUND: Avoid screen flashes if the input buffer contains NaN texels.
|
69
69
|
// See: https://github.com/takram-design-engineering/three-geospatial/issues/7
|
@@ -73,8 +73,6 @@ void main() {
|
|
73
73
|
}
|
74
74
|
|
75
75
|
float l = luminance(color);
|
76
|
-
float scale = saturate(
|
77
|
-
smoothstep(thresholdLevel, thresholdLevel + thresholdRange, l)
|
78
|
-
);
|
76
|
+
float scale = saturate(smoothstep(thresholdLevel, thresholdLevel + thresholdRange, l));
|
79
77
|
gl_FragColor = vec4(color * scale, 1.0);
|
80
78
|
}
|
@@ -1,10 +1,12 @@
|
|
1
|
+
#include "core/packing"
|
2
|
+
|
1
3
|
uniform sampler2D geometryBuffer;
|
2
4
|
|
3
5
|
void mainImage(const vec4 inputColor, const vec2 uv, out vec4 outputColor) {
|
4
|
-
vec4 normalMetalnessRoughness =
|
6
|
+
vec4 normalMetalnessRoughness = texture(geometryBuffer, uv);
|
5
7
|
|
6
8
|
#ifdef OUTPUT_NORMAL
|
7
|
-
vec3 normal = unpackVec2ToNormal(
|
9
|
+
vec3 normal = unpackVec2ToNormal(texture(geometryBuffer, uv).xy);
|
8
10
|
outputColor = vec4(normal * 0.5 + 0.5, inputColor.a);
|
9
11
|
#endif // OUTPUT_NORMAL
|
10
12
|
|
@@ -3,10 +3,7 @@ uniform sampler2D featuresBuffer;
|
|
3
3
|
uniform float intensity;
|
4
4
|
|
5
5
|
void mainImage(const vec4 inputColor, const vec2 uv, out vec4 outputColor) {
|
6
|
-
vec3 bloom =
|
7
|
-
vec3 features =
|
8
|
-
outputColor = vec4(
|
9
|
-
inputColor.rgb + (bloom + features) * intensity,
|
10
|
-
inputColor.a
|
11
|
-
);
|
6
|
+
vec3 bloom = texture(bloomBuffer, uv).rgb;
|
7
|
+
vec3 features = texture(featuresBuffer, uv).rgb;
|
8
|
+
outputColor = vec4(inputColor.rgb + (bloom + features) * intensity, inputColor.a);
|
12
9
|
}
|
@@ -14,7 +14,7 @@ in vec2 vAspectRatio;
|
|
14
14
|
|
15
15
|
vec3 sampleGhost(const vec2 direction, const vec3 color, const float offset) {
|
16
16
|
vec2 suv = clamp(1.0 - vUv + direction * offset, 0.0, 1.0);
|
17
|
-
vec3 result =
|
17
|
+
vec3 result = texture(inputBuffer, suv).rgb * color;
|
18
18
|
|
19
19
|
// Falloff at the perimeter.
|
20
20
|
float d = clamp(length(0.5 - suv) / (0.5 * SQRT_2), 0.0, 1.0);
|
@@ -48,9 +48,9 @@ vec3 sampleHalo(const float radius) {
|
|
48
48
|
vec3 offset = vec3(texelSize.x * chromaticAberration) * vec3(-1.0, 0.0, 1.0);
|
49
49
|
vec2 suv = fract(1.0 - vUv + direction * radius);
|
50
50
|
vec3 result = vec3(
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
texture(inputBuffer, suv + direction * offset.r).r,
|
52
|
+
texture(inputBuffer, suv + direction * offset.g).g,
|
53
|
+
texture(inputBuffer, suv + direction * offset.b).b
|
54
54
|
);
|
55
55
|
|
56
56
|
// Falloff at the center and perimeter.
|
@@ -1,3 +1,7 @@
|
|
1
|
+
#include "core/depth"
|
2
|
+
#include "core/packing"
|
3
|
+
#include "core/transform"
|
4
|
+
|
1
5
|
uniform highp sampler2D normalBuffer;
|
2
6
|
|
3
7
|
uniform mat4 projectionMatrix;
|
@@ -20,16 +24,16 @@ vec3 reconstructNormal(const vec2 uv) {
|
|
20
24
|
|
21
25
|
vec3 readNormal(const vec2 uv) {
|
22
26
|
#ifdef OCT_ENCODED
|
23
|
-
return unpackVec2ToNormal(
|
24
|
-
#else
|
25
|
-
return 2.0 *
|
27
|
+
return unpackVec2ToNormal(texture(normalBuffer, uv).xy);
|
28
|
+
#else // OCT_ENCODED
|
29
|
+
return 2.0 * texture(normalBuffer, uv).xyz - 1.0;
|
26
30
|
#endif // OCT_ENCODED
|
27
31
|
}
|
28
32
|
|
29
33
|
void mainImage(const vec4 inputColor, const vec2 uv, out vec4 outputColor) {
|
30
34
|
#ifdef RECONSTRUCT_FROM_DEPTH
|
31
35
|
vec3 normal = reconstructNormal(uv);
|
32
|
-
#else
|
36
|
+
#else // RECONSTRUCT_FROM_DEPTH
|
33
37
|
vec3 normal = readNormal(uv);
|
34
38
|
#endif // RECONSTRUCT_FROM_DEPTH
|
35
39
|
|
package/types/DepthEffect.d.ts
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
import { UniformMap } from '@takram/three-geospatial';
|
2
|
+
import { Uniform } from 'three';
|
1
3
|
import { BlendFunction, Effect } from 'postprocessing';
|
2
4
|
|
3
5
|
export interface DepthEffectOptions {
|
@@ -6,6 +8,10 @@ export interface DepthEffectOptions {
|
|
6
8
|
near?: number;
|
7
9
|
far?: number;
|
8
10
|
}
|
11
|
+
export interface DepthEffectUniforms {
|
12
|
+
near: Uniform<number>;
|
13
|
+
far: Uniform<number>;
|
14
|
+
}
|
9
15
|
export declare const depthEffectOptionsDefaults: {
|
10
16
|
blendFunction: BlendFunction;
|
11
17
|
useTurbo: false;
|
@@ -13,6 +19,7 @@ export declare const depthEffectOptionsDefaults: {
|
|
13
19
|
far: number;
|
14
20
|
};
|
15
21
|
export declare class DepthEffect extends Effect {
|
22
|
+
uniforms: UniformMap<DepthEffectUniforms>;
|
16
23
|
constructor(options?: DepthEffectOptions);
|
17
24
|
get useTurbo(): boolean;
|
18
25
|
set useTurbo(value: boolean);
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import {
|
1
|
+
import { UniformMap } from '@takram/three-geospatial';
|
2
|
+
import { Uniform, Texture } from 'three';
|
2
3
|
import { BlendFunction, Effect } from 'postprocessing';
|
3
4
|
|
4
5
|
export type GeometryEffectOutput = 'normal' | 'pbr';
|
@@ -7,11 +8,15 @@ export interface GeometryEffectOptions {
|
|
7
8
|
geometryBuffer?: Texture | null;
|
8
9
|
output?: GeometryEffectOutput;
|
9
10
|
}
|
11
|
+
export interface GeometryEffectUniforms {
|
12
|
+
geometryBuffer: Uniform<Texture | null>;
|
13
|
+
}
|
10
14
|
export declare const geometryEffectOptionsDefaults: {
|
11
15
|
blendFunction: BlendFunction;
|
12
16
|
output: "normal";
|
13
17
|
};
|
14
18
|
export declare class GeometryEffect extends Effect {
|
19
|
+
uniforms: UniformMap<GeometryEffectUniforms>;
|
15
20
|
constructor(options?: GeometryEffectOptions);
|
16
21
|
get geometryBuffer(): Texture | null;
|
17
22
|
set geometryBuffer(value: Texture | null);
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { LensFlareFeaturesMaterial } from './LensFlareFeaturesMaterial';
|
2
2
|
import { DownsampleThresholdMaterial } from './DownsampleThresholdMaterial';
|
3
|
-
import {
|
3
|
+
import { UniformMap } from '@takram/three-geospatial';
|
4
|
+
import { Uniform, WebGLRenderTarget, Texture, TextureDataType, WebGLRenderer } from 'three';
|
4
5
|
import { BlendFunction, Effect, KawaseBlurPass, MipmapBlurPass, Resolution, ShaderPass } from 'postprocessing';
|
5
6
|
|
6
7
|
export interface LensFlareEffectOptions {
|
@@ -12,6 +13,11 @@ export interface LensFlareEffectOptions {
|
|
12
13
|
resolutionY?: number;
|
13
14
|
intensity?: number;
|
14
15
|
}
|
16
|
+
export interface LensFlareEffectUniforms {
|
17
|
+
bloomBuffer: Uniform<Texture | null>;
|
18
|
+
featuresBuffer: Uniform<Texture | null>;
|
19
|
+
intensity: Uniform<number>;
|
20
|
+
}
|
15
21
|
export declare const lensFlareEffectOptionsDefaults: {
|
16
22
|
blendFunction: BlendFunction;
|
17
23
|
resolutionScale: number;
|
@@ -20,6 +26,7 @@ export declare const lensFlareEffectOptionsDefaults: {
|
|
20
26
|
intensity: number;
|
21
27
|
};
|
22
28
|
export declare class LensFlareEffect extends Effect {
|
29
|
+
uniforms: UniformMap<LensFlareEffectUniforms>;
|
23
30
|
readonly resolution: Resolution;
|
24
31
|
readonly renderTarget1: WebGLRenderTarget;
|
25
32
|
readonly renderTarget2: WebGLRenderTarget;
|
@@ -33,7 +40,7 @@ export declare class LensFlareEffect extends Effect {
|
|
33
40
|
private readonly onResolutionChange;
|
34
41
|
initialize(renderer: WebGLRenderer, alpha: boolean, frameBufferType: TextureDataType): void;
|
35
42
|
update(renderer: WebGLRenderer, inputBuffer: WebGLRenderTarget, deltaTime?: number): void;
|
36
|
-
setSize(
|
43
|
+
setSize(baseWidth: number, baseHeight: number): void;
|
37
44
|
get intensity(): number;
|
38
45
|
set intensity(value: number);
|
39
46
|
get thresholdLevel(): number;
|
package/types/NormalEffect.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
import {
|
1
|
+
import { UniformMap } from '@takram/three-geospatial';
|
2
|
+
import { Matrix4, Uniform, Camera, Texture, WebGLRenderer, WebGLRenderTarget } from 'three';
|
2
3
|
import { BlendFunction, Effect } from 'postprocessing';
|
3
4
|
|
4
5
|
export interface NormalEffectOptions {
|
@@ -7,6 +8,11 @@ export interface NormalEffectOptions {
|
|
7
8
|
octEncoded?: boolean;
|
8
9
|
reconstructFromDepth?: boolean;
|
9
10
|
}
|
11
|
+
export interface NormalEffectUniforms {
|
12
|
+
normalBuffer: Uniform<Texture | null>;
|
13
|
+
projectionMatrix: Uniform<Matrix4>;
|
14
|
+
inverseProjectionMatrix: Uniform<Matrix4>;
|
15
|
+
}
|
10
16
|
export declare const normalEffectOptionsDefaults: {
|
11
17
|
blendFunction: BlendFunction;
|
12
18
|
octEncoded: false;
|
@@ -14,6 +20,7 @@ export declare const normalEffectOptionsDefaults: {
|
|
14
20
|
};
|
15
21
|
export declare class NormalEffect extends Effect {
|
16
22
|
private camera;
|
23
|
+
uniforms: UniformMap<NormalEffectUniforms>;
|
17
24
|
constructor(camera: Camera, options?: NormalEffectOptions);
|
18
25
|
get mainCamera(): Camera;
|
19
26
|
set mainCamera(value: Camera);
|