@react-three/postprocessing 2.16.7 → 2.17.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.
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const THREE = require("three");
4
+ const postprocessing = require("postprocessing");
5
+ const util = require("../util.cjs");
6
+ const RampShader = {
7
+ fragmentShader: (
8
+ /* glsl */
9
+ `
10
+ uniform int rampType;
11
+
12
+ uniform vec2 rampStart;
13
+ uniform vec2 rampEnd;
14
+
15
+ uniform vec4 startColor;
16
+ uniform vec4 endColor;
17
+
18
+ uniform float rampBias;
19
+ uniform float rampGain;
20
+
21
+ uniform bool rampMask;
22
+ uniform bool rampInvert;
23
+
24
+ float getBias(float time, float bias) {
25
+ return time / (((1.0 / bias) - 2.0) * (1.0 - time) + 1.0);
26
+ }
27
+
28
+ float getGain(float time, float gain) {
29
+ if (time < 0.5)
30
+ return getBias(time * 2.0, gain) / 2.0;
31
+ else
32
+ return getBias(time * 2.0 - 1.0, 1.0 - gain) / 2.0 + 0.5;
33
+ }
34
+
35
+ void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
36
+ vec2 centerPixel = uv * resolution;
37
+ vec2 startPixel = rampStart * resolution;
38
+ vec2 endPixel = rampEnd * resolution;
39
+
40
+ float rampAlpha;
41
+
42
+ if (rampType == 1) {
43
+ vec2 fuv = centerPixel / resolution.y;
44
+ vec2 suv = startPixel / resolution.y;
45
+ vec2 euv = endPixel / resolution.y;
46
+
47
+ float radius = length(suv - euv);
48
+ float falloff = length(fuv - suv);
49
+ rampAlpha = smoothstep(0.0, radius, falloff);
50
+ } else {
51
+ float radius = length(startPixel - endPixel);
52
+ vec2 direction = normalize(vec2(endPixel.x - startPixel.x, -(startPixel.y - endPixel.y)));
53
+
54
+ float fade = dot(centerPixel - startPixel, direction);
55
+ if (rampType == 2) fade = abs(fade);
56
+
57
+ rampAlpha = smoothstep(0.0, 1.0, fade / radius);
58
+ }
59
+
60
+ rampAlpha = abs((rampInvert ? 1.0 : 0.0) - getBias(rampAlpha, rampBias) * getGain(rampAlpha, rampGain));
61
+
62
+ if (rampMask) {
63
+ vec4 inputBuff = texture2D(inputBuffer, uv);
64
+ outputColor = mix(inputBuff, inputColor, rampAlpha);
65
+ } else {
66
+ outputColor = mix(startColor, endColor, rampAlpha);
67
+ }
68
+ }
69
+ `
70
+ )
71
+ };
72
+ var RampType = /* @__PURE__ */ ((RampType2) => {
73
+ RampType2[RampType2["Linear"] = 0] = "Linear";
74
+ RampType2[RampType2["Radial"] = 1] = "Radial";
75
+ RampType2[RampType2["MirroredLinear"] = 2] = "MirroredLinear";
76
+ return RampType2;
77
+ })(RampType || {});
78
+ class RampEffect extends postprocessing.Effect {
79
+ constructor({
80
+ /**
81
+ * Type of ramp gradient.
82
+ */
83
+ rampType = 0,
84
+ /**
85
+ * Starting point of the ramp gradient in normalized coordinates.
86
+ *
87
+ * Ranges from `[0 - 1]` as `[x, y]`. Default is `[0.5, 0.5]`.
88
+ */
89
+ rampStart = [0.5, 0.5],
90
+ /**
91
+ * Ending point of the ramp gradient in normalized coordinates.
92
+ *
93
+ * Ranges from `[0 - 1]` as `[x, y]`. Default is `[1, 1]`
94
+ */
95
+ rampEnd = [1, 1],
96
+ /**
97
+ * Color at the starting point of the gradient.
98
+ *
99
+ * Default is black: `[0, 0, 0, 1]`
100
+ */
101
+ startColor = [0, 0, 0, 1],
102
+ /**
103
+ * Color at the ending point of the gradient.
104
+ *
105
+ * Default is white: `[1, 1, 1, 1]`
106
+ */
107
+ endColor = [1, 1, 1, 1],
108
+ /**
109
+ * Bias for the interpolation curve when both bias and gain are 0.5.
110
+ *
111
+ * Ranges from `[0 - 1]`. Default is `0.5`.
112
+ */
113
+ rampBias = 0.5,
114
+ /**
115
+ * Gain for the interpolation curve when both bias and gain are 0.5.
116
+ *
117
+ * Ranges from `[0 - 1]`. Default is `0.5`.
118
+ */
119
+ rampGain = 0.5,
120
+ /**
121
+ * When enabled, the ramp gradient is used as an effect mask, and colors are ignored.
122
+ *
123
+ * Default is `false`.
124
+ */
125
+ rampMask = false,
126
+ /**
127
+ * Controls whether the ramp gradient is inverted.
128
+ *
129
+ * When disabled, rampStart is transparent and rampEnd is opaque.
130
+ *
131
+ * Default is `false`.
132
+ */
133
+ rampInvert = false,
134
+ ...params
135
+ } = {}) {
136
+ super("RampEffect", RampShader.fragmentShader, {
137
+ ...params,
138
+ uniforms: /* @__PURE__ */ new Map([
139
+ ["rampType", new THREE.Uniform(rampType)],
140
+ ["rampStart", new THREE.Uniform(rampStart)],
141
+ ["rampEnd", new THREE.Uniform(rampEnd)],
142
+ ["startColor", new THREE.Uniform(startColor)],
143
+ ["endColor", new THREE.Uniform(endColor)],
144
+ ["rampBias", new THREE.Uniform(rampBias)],
145
+ ["rampGain", new THREE.Uniform(rampGain)],
146
+ ["rampMask", new THREE.Uniform(rampMask)],
147
+ ["rampInvert", new THREE.Uniform(rampInvert)]
148
+ ])
149
+ });
150
+ }
151
+ }
152
+ const Ramp = /* @__PURE__ */ util.wrapEffect(RampEffect);
153
+ exports.Ramp = Ramp;
154
+ exports.RampEffect = RampEffect;
155
+ exports.RampType = RampType;
156
+ //# sourceMappingURL=Ramp.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Ramp.cjs","sources":["../../src/effects/Ramp.tsx"],"sourcesContent":["import { Uniform } from 'three'\nimport { Effect } from 'postprocessing'\nimport { wrapEffect } from '../util'\n\nconst RampShader = {\n fragmentShader: /* glsl */ `\n uniform int rampType;\n\n uniform vec2 rampStart;\n uniform vec2 rampEnd;\n\n uniform vec4 startColor;\n uniform vec4 endColor;\n\n uniform float rampBias;\n uniform float rampGain;\n\n uniform bool rampMask;\n uniform bool rampInvert;\n\n float getBias(float time, float bias) {\n return time / (((1.0 / bias) - 2.0) * (1.0 - time) + 1.0);\n }\n\n float getGain(float time, float gain) {\n if (time < 0.5)\n return getBias(time * 2.0, gain) / 2.0;\n else\n return getBias(time * 2.0 - 1.0, 1.0 - gain) / 2.0 + 0.5;\n }\n\n void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {\n vec2 centerPixel = uv * resolution;\n vec2 startPixel = rampStart * resolution;\n vec2 endPixel = rampEnd * resolution;\n\n float rampAlpha;\n\n if (rampType == 1) {\n vec2 fuv = centerPixel / resolution.y;\n vec2 suv = startPixel / resolution.y;\n vec2 euv = endPixel / resolution.y;\n\n float radius = length(suv - euv);\n float falloff = length(fuv - suv);\n rampAlpha = smoothstep(0.0, radius, falloff);\n } else {\n float radius = length(startPixel - endPixel);\n vec2 direction = normalize(vec2(endPixel.x - startPixel.x, -(startPixel.y - endPixel.y)));\n\n float fade = dot(centerPixel - startPixel, direction);\n if (rampType == 2) fade = abs(fade);\n\n rampAlpha = smoothstep(0.0, 1.0, fade / radius);\n }\n\n rampAlpha = abs((rampInvert ? 1.0 : 0.0) - getBias(rampAlpha, rampBias) * getGain(rampAlpha, rampGain));\n\n if (rampMask) {\n vec4 inputBuff = texture2D(inputBuffer, uv);\n outputColor = mix(inputBuff, inputColor, rampAlpha);\n } else {\n outputColor = mix(startColor, endColor, rampAlpha);\n }\n }\n `,\n}\n\nexport enum RampType {\n Linear,\n Radial,\n MirroredLinear,\n}\n\nexport class RampEffect extends Effect {\n constructor({\n /**\n * Type of ramp gradient.\n */\n rampType = RampType.Linear,\n /**\n * Starting point of the ramp gradient in normalized coordinates.\n *\n * Ranges from `[0 - 1]` as `[x, y]`. Default is `[0.5, 0.5]`.\n */\n rampStart = [0.5, 0.5],\n /**\n * Ending point of the ramp gradient in normalized coordinates.\n *\n * Ranges from `[0 - 1]` as `[x, y]`. Default is `[1, 1]`\n */\n rampEnd = [1, 1],\n /**\n * Color at the starting point of the gradient.\n *\n * Default is black: `[0, 0, 0, 1]`\n */\n startColor = [0, 0, 0, 1],\n /**\n * Color at the ending point of the gradient.\n *\n * Default is white: `[1, 1, 1, 1]`\n */\n endColor = [1, 1, 1, 1],\n /**\n * Bias for the interpolation curve when both bias and gain are 0.5.\n *\n * Ranges from `[0 - 1]`. Default is `0.5`.\n */\n rampBias = 0.5,\n /**\n * Gain for the interpolation curve when both bias and gain are 0.5.\n *\n * Ranges from `[0 - 1]`. Default is `0.5`.\n */\n rampGain = 0.5,\n /**\n * When enabled, the ramp gradient is used as an effect mask, and colors are ignored.\n *\n * Default is `false`.\n */\n rampMask = false,\n /**\n * Controls whether the ramp gradient is inverted.\n *\n * When disabled, rampStart is transparent and rampEnd is opaque.\n *\n * Default is `false`.\n */\n rampInvert = false,\n ...params\n } = {}) {\n super('RampEffect', RampShader.fragmentShader, {\n ...params,\n uniforms: new Map<string, Uniform>([\n ['rampType', new Uniform(rampType)],\n ['rampStart', new Uniform(rampStart)],\n ['rampEnd', new Uniform(rampEnd)],\n ['startColor', new Uniform(startColor)],\n ['endColor', new Uniform(endColor)],\n ['rampBias', new Uniform(rampBias)],\n ['rampGain', new Uniform(rampGain)],\n ['rampMask', new Uniform(rampMask)],\n ['rampInvert', new Uniform(rampInvert)],\n ]),\n })\n }\n}\n\nexport const Ramp = /* @__PURE__ */ wrapEffect(RampEffect)\n"],"names":["RampType","Effect","Uniform"],"mappings":";;;;;AAIA,MAAM,aAAa;AAAA,EACjB;AAAA;AAAA,IAA2B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA6D7B;AAEY,IAAA,6BAAAA,cAAL;AACLA,Y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ClC,CAAC,YAAY,IAAIA,cAAQ,QAAQ,CAAC;AAAA,QAClC,CAAC,cAAc,IAAIA,cAAQ,UAAU,CAAC;AAAA,MAAA,CACvC;AAAA,IAAA,CACF;AAAA,EACH;AACF;AAEa,MAAA,uCAAkC,UAAU;;;;"}
@@ -0,0 +1,88 @@
1
+ /// <reference types="react" />
2
+ import { Effect } from 'postprocessing';
3
+ export declare enum RampType {
4
+ Linear = 0,
5
+ Radial = 1,
6
+ MirroredLinear = 2
7
+ }
8
+ export declare class RampEffect extends Effect {
9
+ constructor({
10
+ /**
11
+ * Type of ramp gradient.
12
+ */
13
+ rampType,
14
+ /**
15
+ * Starting point of the ramp gradient in normalized coordinates.
16
+ *
17
+ * Ranges from `[0 - 1]` as `[x, y]`. Default is `[0.5, 0.5]`.
18
+ */
19
+ rampStart,
20
+ /**
21
+ * Ending point of the ramp gradient in normalized coordinates.
22
+ *
23
+ * Ranges from `[0 - 1]` as `[x, y]`. Default is `[1, 1]`
24
+ */
25
+ rampEnd,
26
+ /**
27
+ * Color at the starting point of the gradient.
28
+ *
29
+ * Default is black: `[0, 0, 0, 1]`
30
+ */
31
+ startColor,
32
+ /**
33
+ * Color at the ending point of the gradient.
34
+ *
35
+ * Default is white: `[1, 1, 1, 1]`
36
+ */
37
+ endColor,
38
+ /**
39
+ * Bias for the interpolation curve when both bias and gain are 0.5.
40
+ *
41
+ * Ranges from `[0 - 1]`. Default is `0.5`.
42
+ */
43
+ rampBias,
44
+ /**
45
+ * Gain for the interpolation curve when both bias and gain are 0.5.
46
+ *
47
+ * Ranges from `[0 - 1]`. Default is `0.5`.
48
+ */
49
+ rampGain,
50
+ /**
51
+ * When enabled, the ramp gradient is used as an effect mask, and colors are ignored.
52
+ *
53
+ * Default is `false`.
54
+ */
55
+ rampMask,
56
+ /**
57
+ * Controls whether the ramp gradient is inverted.
58
+ *
59
+ * When disabled, rampStart is transparent and rampEnd is opaque.
60
+ *
61
+ * Default is `false`.
62
+ */
63
+ rampInvert, ...params }?: {
64
+ rampType?: RampType | undefined;
65
+ rampStart?: number[] | undefined;
66
+ rampEnd?: number[] | undefined;
67
+ startColor?: number[] | undefined;
68
+ endColor?: number[] | undefined;
69
+ rampBias?: number | undefined;
70
+ rampGain?: number | undefined;
71
+ rampMask?: boolean | undefined;
72
+ rampInvert?: boolean | undefined;
73
+ });
74
+ }
75
+ export declare const Ramp: import("react").ForwardRefExoticComponent<Omit<import("@react-three/fiber").ExtendedColors<import("@react-three/fiber").Overwrite<Partial<RampEffect>, import("@react-three/fiber").NodeProps<RampEffect, typeof RampEffect>>> & {
76
+ rampType?: RampType | undefined;
77
+ rampStart?: number[] | undefined;
78
+ rampEnd?: number[] | undefined;
79
+ startColor?: number[] | undefined;
80
+ endColor?: number[] | undefined;
81
+ rampBias?: number | undefined;
82
+ rampGain?: number | undefined;
83
+ rampMask?: boolean | undefined;
84
+ rampInvert?: boolean | undefined;
85
+ } & {
86
+ blendFunction?: import("postprocessing").BlendFunction | undefined;
87
+ opacity?: number | undefined;
88
+ }, "ref"> & import("react").RefAttributes<typeof RampEffect>>;
@@ -0,0 +1,156 @@
1
+ import { Uniform } from "three";
2
+ import { Effect } from "postprocessing";
3
+ import { wrapEffect } from "../util.js";
4
+ const RampShader = {
5
+ fragmentShader: (
6
+ /* glsl */
7
+ `
8
+ uniform int rampType;
9
+
10
+ uniform vec2 rampStart;
11
+ uniform vec2 rampEnd;
12
+
13
+ uniform vec4 startColor;
14
+ uniform vec4 endColor;
15
+
16
+ uniform float rampBias;
17
+ uniform float rampGain;
18
+
19
+ uniform bool rampMask;
20
+ uniform bool rampInvert;
21
+
22
+ float getBias(float time, float bias) {
23
+ return time / (((1.0 / bias) - 2.0) * (1.0 - time) + 1.0);
24
+ }
25
+
26
+ float getGain(float time, float gain) {
27
+ if (time < 0.5)
28
+ return getBias(time * 2.0, gain) / 2.0;
29
+ else
30
+ return getBias(time * 2.0 - 1.0, 1.0 - gain) / 2.0 + 0.5;
31
+ }
32
+
33
+ void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
34
+ vec2 centerPixel = uv * resolution;
35
+ vec2 startPixel = rampStart * resolution;
36
+ vec2 endPixel = rampEnd * resolution;
37
+
38
+ float rampAlpha;
39
+
40
+ if (rampType == 1) {
41
+ vec2 fuv = centerPixel / resolution.y;
42
+ vec2 suv = startPixel / resolution.y;
43
+ vec2 euv = endPixel / resolution.y;
44
+
45
+ float radius = length(suv - euv);
46
+ float falloff = length(fuv - suv);
47
+ rampAlpha = smoothstep(0.0, radius, falloff);
48
+ } else {
49
+ float radius = length(startPixel - endPixel);
50
+ vec2 direction = normalize(vec2(endPixel.x - startPixel.x, -(startPixel.y - endPixel.y)));
51
+
52
+ float fade = dot(centerPixel - startPixel, direction);
53
+ if (rampType == 2) fade = abs(fade);
54
+
55
+ rampAlpha = smoothstep(0.0, 1.0, fade / radius);
56
+ }
57
+
58
+ rampAlpha = abs((rampInvert ? 1.0 : 0.0) - getBias(rampAlpha, rampBias) * getGain(rampAlpha, rampGain));
59
+
60
+ if (rampMask) {
61
+ vec4 inputBuff = texture2D(inputBuffer, uv);
62
+ outputColor = mix(inputBuff, inputColor, rampAlpha);
63
+ } else {
64
+ outputColor = mix(startColor, endColor, rampAlpha);
65
+ }
66
+ }
67
+ `
68
+ )
69
+ };
70
+ var RampType = /* @__PURE__ */ ((RampType2) => {
71
+ RampType2[RampType2["Linear"] = 0] = "Linear";
72
+ RampType2[RampType2["Radial"] = 1] = "Radial";
73
+ RampType2[RampType2["MirroredLinear"] = 2] = "MirroredLinear";
74
+ return RampType2;
75
+ })(RampType || {});
76
+ class RampEffect extends Effect {
77
+ constructor({
78
+ /**
79
+ * Type of ramp gradient.
80
+ */
81
+ rampType = 0,
82
+ /**
83
+ * Starting point of the ramp gradient in normalized coordinates.
84
+ *
85
+ * Ranges from `[0 - 1]` as `[x, y]`. Default is `[0.5, 0.5]`.
86
+ */
87
+ rampStart = [0.5, 0.5],
88
+ /**
89
+ * Ending point of the ramp gradient in normalized coordinates.
90
+ *
91
+ * Ranges from `[0 - 1]` as `[x, y]`. Default is `[1, 1]`
92
+ */
93
+ rampEnd = [1, 1],
94
+ /**
95
+ * Color at the starting point of the gradient.
96
+ *
97
+ * Default is black: `[0, 0, 0, 1]`
98
+ */
99
+ startColor = [0, 0, 0, 1],
100
+ /**
101
+ * Color at the ending point of the gradient.
102
+ *
103
+ * Default is white: `[1, 1, 1, 1]`
104
+ */
105
+ endColor = [1, 1, 1, 1],
106
+ /**
107
+ * Bias for the interpolation curve when both bias and gain are 0.5.
108
+ *
109
+ * Ranges from `[0 - 1]`. Default is `0.5`.
110
+ */
111
+ rampBias = 0.5,
112
+ /**
113
+ * Gain for the interpolation curve when both bias and gain are 0.5.
114
+ *
115
+ * Ranges from `[0 - 1]`. Default is `0.5`.
116
+ */
117
+ rampGain = 0.5,
118
+ /**
119
+ * When enabled, the ramp gradient is used as an effect mask, and colors are ignored.
120
+ *
121
+ * Default is `false`.
122
+ */
123
+ rampMask = false,
124
+ /**
125
+ * Controls whether the ramp gradient is inverted.
126
+ *
127
+ * When disabled, rampStart is transparent and rampEnd is opaque.
128
+ *
129
+ * Default is `false`.
130
+ */
131
+ rampInvert = false,
132
+ ...params
133
+ } = {}) {
134
+ super("RampEffect", RampShader.fragmentShader, {
135
+ ...params,
136
+ uniforms: /* @__PURE__ */ new Map([
137
+ ["rampType", new Uniform(rampType)],
138
+ ["rampStart", new Uniform(rampStart)],
139
+ ["rampEnd", new Uniform(rampEnd)],
140
+ ["startColor", new Uniform(startColor)],
141
+ ["endColor", new Uniform(endColor)],
142
+ ["rampBias", new Uniform(rampBias)],
143
+ ["rampGain", new Uniform(rampGain)],
144
+ ["rampMask", new Uniform(rampMask)],
145
+ ["rampInvert", new Uniform(rampInvert)]
146
+ ])
147
+ });
148
+ }
149
+ }
150
+ const Ramp = /* @__PURE__ */ wrapEffect(RampEffect);
151
+ export {
152
+ Ramp,
153
+ RampEffect,
154
+ RampType
155
+ };
156
+ //# sourceMappingURL=Ramp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Ramp.js","sources":["../../src/effects/Ramp.tsx"],"sourcesContent":["import { Uniform } from 'three'\nimport { Effect } from 'postprocessing'\nimport { wrapEffect } from '../util'\n\nconst RampShader = {\n fragmentShader: /* glsl */ `\n uniform int rampType;\n\n uniform vec2 rampStart;\n uniform vec2 rampEnd;\n\n uniform vec4 startColor;\n uniform vec4 endColor;\n\n uniform float rampBias;\n uniform float rampGain;\n\n uniform bool rampMask;\n uniform bool rampInvert;\n\n float getBias(float time, float bias) {\n return time / (((1.0 / bias) - 2.0) * (1.0 - time) + 1.0);\n }\n\n float getGain(float time, float gain) {\n if (time < 0.5)\n return getBias(time * 2.0, gain) / 2.0;\n else\n return getBias(time * 2.0 - 1.0, 1.0 - gain) / 2.0 + 0.5;\n }\n\n void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {\n vec2 centerPixel = uv * resolution;\n vec2 startPixel = rampStart * resolution;\n vec2 endPixel = rampEnd * resolution;\n\n float rampAlpha;\n\n if (rampType == 1) {\n vec2 fuv = centerPixel / resolution.y;\n vec2 suv = startPixel / resolution.y;\n vec2 euv = endPixel / resolution.y;\n\n float radius = length(suv - euv);\n float falloff = length(fuv - suv);\n rampAlpha = smoothstep(0.0, radius, falloff);\n } else {\n float radius = length(startPixel - endPixel);\n vec2 direction = normalize(vec2(endPixel.x - startPixel.x, -(startPixel.y - endPixel.y)));\n\n float fade = dot(centerPixel - startPixel, direction);\n if (rampType == 2) fade = abs(fade);\n\n rampAlpha = smoothstep(0.0, 1.0, fade / radius);\n }\n\n rampAlpha = abs((rampInvert ? 1.0 : 0.0) - getBias(rampAlpha, rampBias) * getGain(rampAlpha, rampGain));\n\n if (rampMask) {\n vec4 inputBuff = texture2D(inputBuffer, uv);\n outputColor = mix(inputBuff, inputColor, rampAlpha);\n } else {\n outputColor = mix(startColor, endColor, rampAlpha);\n }\n }\n `,\n}\n\nexport enum RampType {\n Linear,\n Radial,\n MirroredLinear,\n}\n\nexport class RampEffect extends Effect {\n constructor({\n /**\n * Type of ramp gradient.\n */\n rampType = RampType.Linear,\n /**\n * Starting point of the ramp gradient in normalized coordinates.\n *\n * Ranges from `[0 - 1]` as `[x, y]`. Default is `[0.5, 0.5]`.\n */\n rampStart = [0.5, 0.5],\n /**\n * Ending point of the ramp gradient in normalized coordinates.\n *\n * Ranges from `[0 - 1]` as `[x, y]`. Default is `[1, 1]`\n */\n rampEnd = [1, 1],\n /**\n * Color at the starting point of the gradient.\n *\n * Default is black: `[0, 0, 0, 1]`\n */\n startColor = [0, 0, 0, 1],\n /**\n * Color at the ending point of the gradient.\n *\n * Default is white: `[1, 1, 1, 1]`\n */\n endColor = [1, 1, 1, 1],\n /**\n * Bias for the interpolation curve when both bias and gain are 0.5.\n *\n * Ranges from `[0 - 1]`. Default is `0.5`.\n */\n rampBias = 0.5,\n /**\n * Gain for the interpolation curve when both bias and gain are 0.5.\n *\n * Ranges from `[0 - 1]`. Default is `0.5`.\n */\n rampGain = 0.5,\n /**\n * When enabled, the ramp gradient is used as an effect mask, and colors are ignored.\n *\n * Default is `false`.\n */\n rampMask = false,\n /**\n * Controls whether the ramp gradient is inverted.\n *\n * When disabled, rampStart is transparent and rampEnd is opaque.\n *\n * Default is `false`.\n */\n rampInvert = false,\n ...params\n } = {}) {\n super('RampEffect', RampShader.fragmentShader, {\n ...params,\n uniforms: new Map<string, Uniform>([\n ['rampType', new Uniform(rampType)],\n ['rampStart', new Uniform(rampStart)],\n ['rampEnd', new Uniform(rampEnd)],\n ['startColor', new Uniform(startColor)],\n ['endColor', new Uniform(endColor)],\n ['rampBias', new Uniform(rampBias)],\n ['rampGain', new Uniform(rampGain)],\n ['rampMask', new Uniform(rampMask)],\n ['rampInvert', new Uniform(rampInvert)],\n ]),\n })\n }\n}\n\nexport const Ramp = /* @__PURE__ */ wrapEffect(RampEffect)\n"],"names":["RampType"],"mappings":";;;AAIA,MAAM,aAAa;AAAA,EACjB;AAA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AgB;AAAA,MAC7C,GAAG;AAAA,MACH,8BAAc,IAAqB;AAAA,QACjC,CAAC,YAAY,IAAI,QAAQ,QAAQ,CAAC;AAAA,QAClC,CAAC,aAAa,IAAI,QAAQ,SAAS,CAAC;AAAA,QACpC,CAAC,WAAW,IAAI,QAAQ,OAAO,CAAC;AAAA,QAChC,CAAC,cAAc,IAAI,QAAQ,UAAU,CAAC;AAAA,QACtC,CAAC,YAAY,IAAI,QAAQ,QAAQ,CAAC;AAAA,QAClC,CAAC,YAAY,IAAI,QAAQ,QAAQ,CAAC;AAAA,QAClC,CAAC,YAAY,IAAI,QAAQ,QAAQ,CAAC;AAAA,QAClC,CAAC,YAAY,IAAI,QAAQ,QAAQ,CAAC;AAAA,QAClC,CAAC,cAAc,IAAI,QAAQ,UAAU,CAAC;AAAA,MAAA,CACvC;AAAA,IAAA,CACF;AAAA,EACH;AACF;AAEa,MAAA,kCAAkC,UAAU;"}
package/dist/index.cjs CHANGED
@@ -26,6 +26,7 @@ const Sepia = require("./effects/Sepia.cjs");
26
26
  const SSAO = require("./effects/SSAO.cjs");
27
27
  const SMAA = require("./effects/SMAA.cjs");
28
28
  const FXAA = require("./effects/FXAA.cjs");
29
+ const Ramp = require("./effects/Ramp.cjs");
29
30
  const Texture = require("./effects/Texture.cjs");
30
31
  const ToneMapping = require("./effects/ToneMapping.cjs");
31
32
  const Vignette = require("./effects/Vignette.cjs");
@@ -69,6 +70,9 @@ exports.Sepia = Sepia.Sepia;
69
70
  exports.SSAO = SSAO.SSAO;
70
71
  exports.SMAA = SMAA.SMAA;
71
72
  exports.FXAA = FXAA.FXAA;
73
+ exports.Ramp = Ramp.Ramp;
74
+ exports.RampEffect = Ramp.RampEffect;
75
+ exports.RampType = Ramp.RampType;
72
76
  exports.Texture = Texture.Texture;
73
77
  exports.ToneMapping = ToneMapping.ToneMapping;
74
78
  exports.Vignette = Vignette.Vignette;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -24,6 +24,7 @@ export * from './effects/Sepia';
24
24
  export * from './effects/SSAO';
25
25
  export * from './effects/SMAA';
26
26
  export * from './effects/FXAA';
27
+ export * from './effects/Ramp';
27
28
  export * from './effects/Texture';
28
29
  export * from './effects/ToneMapping';
29
30
  export * from './effects/Vignette';
package/dist/index.js CHANGED
@@ -24,6 +24,7 @@ import { Sepia } from "./effects/Sepia.js";
24
24
  import { SSAO } from "./effects/SSAO.js";
25
25
  import { SMAA } from "./effects/SMAA.js";
26
26
  import { FXAA } from "./effects/FXAA.js";
27
+ import { Ramp, RampEffect, RampType } from "./effects/Ramp.js";
27
28
  import { Texture } from "./effects/Texture.js";
28
29
  import { ToneMapping } from "./effects/ToneMapping.js";
29
30
  import { Vignette } from "./effects/Vignette.js";
@@ -60,6 +61,9 @@ export {
60
61
  Noise,
61
62
  Outline,
62
63
  Pixelation,
64
+ Ramp,
65
+ RampEffect,
66
+ RampType,
63
67
  SMAA,
64
68
  SSAO,
65
69
  SSR,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/postprocessing",
3
- "version": "2.16.7",
3
+ "version": "2.17.0",
4
4
  "description": "postprocessing wrapper for React and @react-three/fiber",
5
5
  "keywords": [
6
6
  "postprocessing",