Skip to content

Commit 9563913

Browse files
s-rigaudSamuel Rigaud
and
Samuel Rigaud
authored
Pass: improve types (#30789)
Co-authored-by: Samuel Rigaud <[email protected]>
1 parent 20b9cbb commit 9563913

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+144
-128
lines changed

examples/jsm/postprocessing/BloomPass.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class BloomPass extends Pass {
7373
this.convolutionUniforms = UniformsUtils.clone( convolutionShader.uniforms );
7474

7575
this.convolutionUniforms[ 'uImageIncrement' ].value = BloomPass.blurX;
76-
this.convolutionUniforms[ 'cKernel' ].value = ConvolutionShader.buildKernel( sigma );
76+
this.convolutionUniforms[ 'cKernel' ].value = buildKernel( sigma );
7777

7878
/**
7979
* The convolution pass material.
@@ -235,4 +235,39 @@ const CombineShader = {
235235
BloomPass.blurX = new Vector2( 0.001953125, 0.0 );
236236
BloomPass.blurY = new Vector2( 0.0, 0.001953125 );
237237

238+
239+
function gauss( x, sigma ) {
240+
241+
return Math.exp( - ( x * x ) / ( 2.0 * sigma * sigma ) );
242+
243+
}
244+
245+
function buildKernel( sigma ) {
246+
247+
// We loop off the sqrt(2 * pi) * sigma term, since we're going to normalize anyway.
248+
249+
const kMaxKernelSize = 25;
250+
let kernelSize = 2 * Math.ceil( sigma * 3.0 ) + 1;
251+
252+
if ( kernelSize > kMaxKernelSize ) kernelSize = kMaxKernelSize;
253+
254+
const halfWidth = ( kernelSize - 1 ) * 0.5;
255+
256+
const values = new Array( kernelSize );
257+
let sum = 0.0;
258+
for ( let i = 0; i < kernelSize; ++ i ) {
259+
260+
values[ i ] = gauss( i - halfWidth, sigma );
261+
sum += values[ i ];
262+
263+
}
264+
265+
// normalize the kernel
266+
267+
for ( let i = 0; i < kernelSize; ++ i ) values[ i ] /= sum;
268+
269+
return values;
270+
271+
}
272+
238273
export { BloomPass };

examples/jsm/shaders/ACESFilmicToneMappingShader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* The scale factor of 1/0.6 is subjective. See discussion in #19621.
99
*
1010
* @constant
11-
* @type {Object}
11+
* @type {Shader}
1212
*/
1313
const ACESFilmicToneMappingShader = {
1414

examples/jsm/shaders/AfterimageShader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Inspired by [Three.js FBO motion trails]{@link https://codepen.io/brunoimbrizi/pen/MoRJaN?page=1&}.
55
*
66
* @constant
7-
* @type {Object}
7+
* @type {Shader}
88
*/
99
const AfterimageShader = {
1010

examples/jsm/shaders/BasicShader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Simple shader for testing.
55
*
66
* @constant
7-
* @type {Object}
7+
* @type {Shader}
88
*/
99
const BasicShader = {
1010

examples/jsm/shaders/BleachBypassShader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* [Nvidia Shader library]{@link http://developer.download.nvidia.com/shaderlibrary/webpages/shader_library.html#post_bleach_bypass}.
77
*
88
* @constant
9-
* @type {Object}
9+
* @type {Shader}
1010
*/
1111
const BleachBypassShader = {
1212

examples/jsm/shaders/BlendShader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Blends two textures.
55
*
66
* @constant
7-
* @type {Object}
7+
* @type {Shader}
88
*/
99
const BlendShader = {
1010

examples/jsm/shaders/BokehShader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* [GLSL shader by Martins Upitis]{@link http://artmartinsh.blogspot.com/2010/02/glsl-lens-blur-filter-with-bokeh.html}.
66
*
77
* @constant
8-
* @type {Object}
8+
* @type {Shader}
99
*/
1010
const BokehShader = {
1111

examples/jsm/shaders/BokehShader2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
* Requires #define RINGS and SAMPLES integers
1212
*
1313
* @constant
14-
* @type {Object}
14+
* @type {Shader}
1515
*/
1616
const BokehShader = {
1717

examples/jsm/shaders/BrightnessContrastShader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Contrast: -1 to 1 (-1 is solid gray, 0 is no change, and 1 is maximum contrast)
77
*
88
* @constant
9-
* @type {Object}
9+
* @type {Shader}
1010
*/
1111
const BrightnessContrastShader = {
1212

examples/jsm/shaders/ColorCorrectionShader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
* Color correction shader.
99
*
1010
* @constant
11-
* @type {Object}
11+
* @type {Shader}
1212
*/
1313
const ColorCorrectionShader = {
1414

examples/jsm/shaders/ColorifyShader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
* Colorify shader.
99
*
1010
* @constant
11-
* @type {Object}
11+
* @type {Shader}
1212
*/
1313
const ColorifyShader = {
1414

examples/jsm/shaders/ConvolutionShader.js

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
* Convolution shader ported from o3d sample to WebGL / GLSL.
99
*
1010
* @constant
11-
* @type {Object}
11+
* @type {Shader}
1212
*/
1313
const ConvolutionShader = {
1414

@@ -65,42 +65,7 @@ const ConvolutionShader = {
6565
6666
gl_FragColor = sum;
6767
68-
}`,
69-
70-
buildKernel: function ( sigma ) {
71-
72-
// We lop off the sqrt(2 * pi) * sigma term, since we're going to normalize anyway.
73-
74-
const kMaxKernelSize = 25;
75-
let kernelSize = 2 * Math.ceil( sigma * 3.0 ) + 1;
76-
77-
if ( kernelSize > kMaxKernelSize ) kernelSize = kMaxKernelSize;
78-
79-
const halfWidth = ( kernelSize - 1 ) * 0.5;
80-
81-
const values = new Array( kernelSize );
82-
let sum = 0.0;
83-
for ( let i = 0; i < kernelSize; ++ i ) {
84-
85-
values[ i ] = gauss( i - halfWidth, sigma );
86-
sum += values[ i ];
87-
88-
}
89-
90-
// normalize the kernel
91-
92-
for ( let i = 0; i < kernelSize; ++ i ) values[ i ] /= sum;
93-
94-
return values;
95-
96-
}
97-
68+
}`
9869
};
9970

100-
function gauss( x, sigma ) {
101-
102-
return Math.exp( - ( x * x ) / ( 2.0 * sigma * sigma ) );
103-
104-
}
105-
10671
export { ConvolutionShader };

examples/jsm/shaders/CopyShader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Full-screen copy shader pass.
55
*
66
* @constant
7-
* @type {Object}
7+
* @type {Shader}
88
*/
99
const CopyShader = {
1010

examples/jsm/shaders/DOFMipMapShader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Requires power-of-2 sized render target with enabled mipmaps.
77
*
88
* @constant
9-
* @type {Object}
9+
* @type {Shader}
1010
*/
1111
const DOFMipMapShader = {
1212

examples/jsm/shaders/DepthLimitedBlurShader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
* Used by {@link SAOPass}.
1111
*
1212
* @constant
13-
* @type {Object}
13+
* @type {Shader}
1414
*/
1515
const DepthLimitedBlurShader = {
1616

examples/jsm/shaders/DigitalGlitch.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
* Digital glitch shader.
55
*
66
* @constant
7-
* @type {Object}
7+
* @type {Shader}
88
*/
99
const DigitalGlitch = {
1010

11+
name: 'DigitalGlitch',
12+
1113
uniforms: {
1214

1315
'tDiffuse': { value: null }, //diffuse texture

examples/jsm/shaders/DotScreenShader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
* Dot screen shader based on [glfx.js sepia shader]{@link https://github.com/evanw/glfx.js}.
99
*
1010
* @constant
11-
* @type {Object}
11+
* @type {Shader}
1212
*/
1313
const DotScreenShader = {
1414

examples/jsm/shaders/ExposureShader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* TODO
55
*
66
* @constant
7-
* @type {Object}
7+
* @type {Shader}
88
*/
99
const ExposureShader = {
1010

examples/jsm/shaders/FXAAShader.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
* - {@link https://catlikecoding.com/unity/tutorials/advanced-rendering/fxaa/}.
1313
*
1414
* @constant
15-
* @type {Object}
15+
* @type {Shader}
1616
*/
1717
const FXAAShader = {
1818

@@ -146,7 +146,7 @@ const FXAAShader = {
146146
float nGradient = abs( nLuminance - l.m );
147147
148148
e.pixelStep = e.isHorizontal ? texSize.y : texSize.x;
149-
149+
150150
if (pGradient < nGradient) {
151151
152152
e.pixelStep = -e.pixelStep;
@@ -226,7 +226,7 @@ const FXAAShader = {
226226
nDistance = uv.x - nuv.x;
227227
228228
} else {
229-
229+
230230
pDistance = puv.y - uv.y;
231231
nDistance = uv.y - nuv.y;
232232
@@ -287,7 +287,7 @@ const FXAAShader = {
287287
void main() {
288288
289289
gl_FragColor = ApplyFXAA( tDiffuse, resolution.xy, vUv );
290-
290+
291291
}`
292292

293293
};

examples/jsm/shaders/FilmShader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Used by {@link FilmPass}.
77
*
88
* @constant
9-
* @type {Object}
9+
* @type {Shader}
1010
*/
1111
const FilmShader = {
1212

examples/jsm/shaders/FocusShader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Focus shader based on [PaintEffect postprocess from ro.me]{@link http://code.google.com/p/3-dreams-of-black/source/browse/deploy/js/effects/PaintEffect.js}.
55
*
66
* @constant
7-
* @type {Object}
7+
* @type {Shader}
88
*/
99
const FocusShader = {
1010

examples/jsm/shaders/FreiChenShader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
* aspect: vec2 of (1/width, 1/height)
1212
*
1313
* @constant
14-
* @type {Object}
14+
* @type {Shader}
1515
*/
1616
const FreiChenShader = {
1717

0 commit comments

Comments
 (0)