11import {
2- Matrix4 ,
3- Vector2
4- } from " ../../../build/three.module.js" ;
2+ Matrix4 ,
3+ Vector2
4+ } from ' ../../../build/three.module.js' ;
55/**
66 * References:
77 * https://lettier.github.io/3d-game-shaders-for-beginners/screen-space-reflection.html
88 */
99
1010var SSRShader = {
1111
12- defines : {
13- MAX_STEP : 0 ,
14- PERSPECTIVE_CAMERA : true ,
15- DISTANCE_ATTENUATION : true ,
16- FRESNEL : true ,
17- INFINITE_THICK : false ,
18- SELECTIVE : false ,
19- } ,
12+ defines : {
13+ MAX_STEP : 0 ,
14+ PERSPECTIVE_CAMERA : true ,
15+ DISTANCE_ATTENUATION : true ,
16+ FRESNEL : true ,
17+ INFINITE_THICK : false ,
18+ SELECTIVE : false ,
19+ } ,
20+
21+ uniforms : {
22+
23+ 'tDiffuse' : { value : null } ,
24+ 'tNormal' : { value : null } ,
25+ 'tMetalness' : { value : null } ,
26+ 'tDepth' : { value : null } ,
27+ 'cameraNear' : { value : null } ,
28+ 'cameraFar' : { value : null } ,
29+ 'resolution' : { value : new Vector2 ( ) } ,
30+ 'cameraProjectionMatrix' : { value : new Matrix4 ( ) } ,
31+ 'cameraInverseProjectionMatrix' : { value : new Matrix4 ( ) } ,
32+ 'opacity' : { value : .5 } ,
33+ 'maxDistance' : { value : 180 } ,
34+ 'cameraRange' : { value : 0 } ,
35+ 'surfDist' : { value : .007 } ,
36+ 'thickTolerance' : { value : .03 } ,
37+
38+ } ,
39+
40+ vertexShader : /* glsl */ `
2041
21- uniforms : {
22-
23- "tDiffuse" : { value : null } ,
24- "tNormal" : { value : null } ,
25- "tMetalness" : { value : null } ,
26- "tDepth" : { value : null } ,
27- "cameraNear" : { value : null } ,
28- "cameraFar" : { value : null } ,
29- "resolution" : { value : new Vector2 ( ) } ,
30- "cameraProjectionMatrix" : { value : new Matrix4 ( ) } ,
31- "cameraInverseProjectionMatrix" : { value : new Matrix4 ( ) } ,
32- "opacity" : { value : .5 } ,
33- "maxDistance" : { value : 180 } ,
34- "cameraRange" : { value : 0 } ,
35- "surfDist" : { value : .007 } ,
36- "thickTolerance" : { value : .03 } ,
37-
38- } ,
39-
40- vertexShader : /* glsl */ `
41-
42- varying vec2 vUv;
42+ varying vec2 vUv;
4343
44- void main() {
44+ void main() {
4545
4646 vUv = uv;
4747
4848 gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
4949
50- }
50+ }
5151
52- `,
52+ `,
5353
54- fragmentShader : /* glsl */ `
54+ fragmentShader : /* glsl */ `
5555 // precision highp float;
5656 precision highp sampler2D;
5757 varying vec2 vUv;
@@ -221,41 +221,41 @@ var SSRShader = {
221221
222222var SSRDepthShader = {
223223
224- defines : {
225- " PERSPECTIVE_CAMERA" : 1
226- } ,
224+ defines : {
225+ ' PERSPECTIVE_CAMERA' : 1
226+ } ,
227227
228- uniforms : {
228+ uniforms : {
229229
230- " tDepth" : { value : null } ,
231- " cameraNear" : { value : null } ,
232- " cameraFar" : { value : null } ,
230+ ' tDepth' : { value : null } ,
231+ ' cameraNear' : { value : null } ,
232+ ' cameraFar' : { value : null } ,
233233
234- } ,
234+ } ,
235235
236- vertexShader : /* glsl */ `
236+ vertexShader : /* glsl */ `
237237
238- varying vec2 vUv;
238+ varying vec2 vUv;
239239
240- void main() {
240+ void main() {
241241
242- vUv = uv;
243- gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
242+ vUv = uv;
243+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
244244
245- }
245+ }
246246
247- `,
247+ `,
248248
249- fragmentShader : /* glsl */ `
249+ fragmentShader : /* glsl */ `
250250
251- uniform sampler2D tDepth;
251+ uniform sampler2D tDepth;
252252
253- uniform float cameraNear;
254- uniform float cameraFar;
253+ uniform float cameraNear;
254+ uniform float cameraFar;
255255
256- varying vec2 vUv;
256+ varying vec2 vUv;
257257
258- #include <packing>
258+ #include <packing>
259259
260260 float getLinearDepth( const in vec2 uv ) {
261261
@@ -273,51 +273,51 @@ var SSRDepthShader = {
273273
274274 }
275275
276- void main() {
276+ void main() {
277277
278- float depth = getLinearDepth( vUv );
278+ float depth = getLinearDepth( vUv );
279279 float d = 1.0 - depth;
280280 // d=(d-.999)*1000.;
281- gl_FragColor = vec4( vec3( d ), 1.0 );
281+ gl_FragColor = vec4( vec3( d ), 1.0 );
282282
283- }
283+ }
284284
285- `
285+ `
286286
287287} ;
288288
289289var SSRBlurShader = {
290290
291- uniforms : {
291+ uniforms : {
292292
293- " tDiffuse" : { value : null } ,
294- " resolution" : { value : new Vector2 ( ) } ,
295- " opacity" : { value : .5 } ,
293+ ' tDiffuse' : { value : null } ,
294+ ' resolution' : { value : new Vector2 ( ) } ,
295+ ' opacity' : { value : .5 } ,
296296
297- } ,
297+ } ,
298298
299- vertexShader : /* glsl */ `
299+ vertexShader : /* glsl */ `
300300
301- varying vec2 vUv;
301+ varying vec2 vUv;
302302
303- void main() {
303+ void main() {
304304
305- vUv = uv;
306- gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
305+ vUv = uv;
306+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
307307
308- }
308+ }
309309
310- `,
310+ `,
311311
312- fragmentShader : /* glsl */ `
312+ fragmentShader : /* glsl */ `
313313
314- uniform sampler2D tDiffuse;
315- uniform vec2 resolution;
316- varying vec2 vUv;
317- void main() {
314+ uniform sampler2D tDiffuse;
315+ uniform vec2 resolution;
316+ varying vec2 vUv;
317+ void main() {
318318 //reverse engineering from PhotoShop blur filter, then change coefficient
319319
320- vec2 texelSize = ( 1.0 / resolution );
320+ vec2 texelSize = ( 1.0 / resolution );
321321
322322 vec4 c=texture2D(tDiffuse,vUv);
323323
0 commit comments