Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

screen-space-reflections

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

screen-space-reflections - npm Package Compare versions

Comparing version 2.0.4 to 2.0.5

376

dist/index.js

@@ -1,3 +0,3 @@

import { Pass, RenderPass, DepthPass, Effect } from 'postprocessing';
import { WebGLRenderTarget, NearestFilter, ShaderMaterial, Uniform, ShaderChunk, Matrix4, Vector2, Matrix3, UniformsUtils, TangentSpaceNormalMap, GLSL3, HalfFloatType, FrontSide, VideoTexture, WebGLMultipleRenderTargets, FramebufferTexture, RGBAFormat, Vector3, Quaternion } from 'three';
import { Pass, RenderPass, DepthPass, Effect, Selection } from 'postprocessing';
import { Vector2, WebGLRenderTarget, NearestFilter, ShaderMaterial, Uniform, FramebufferTexture, RGBAFormat, ShaderChunk, Matrix4, Matrix3, UniformsUtils, TangentSpaceNormalMap, GLSL3, HalfFloatType, FrontSide, VideoTexture, WebGLMultipleRenderTargets, DataTexture, FloatType, Vector3, Quaternion } from 'three';

@@ -37,9 +37,19 @@ function _extends() {

var fragmentShader$2 = "#define GLSLIFY 1\n#define EULER 2.718281828459045\n#define FLOAT_EPSILON 0.00001\nuniform sampler2D inputTexture;uniform sampler2D lastFrameReflectionsTexture;uniform sampler2D velocityTexture;uniform float samples;uniform float maxSamples;uniform float temporalResolveMix;uniform float temporalResolveCorrectionMix;varying vec2 vUv;\n#include <packing>\n#define min3(a, b, c) min(a, min(b, c))\n#define min4(a, b, c, d) min(a, min3(b, c, d))\n#define min5(a, b, c, d, e) min(a, min4(b, c, d, e))\n#define min6(a, b, c, d, e, f) min(a, min5(b, c, d, e, f))\n#define min7(a, b, c, d, e, f, g) min(a, min6(b, c, d, e, f, g))\n#define min8(a, b, c, d, e, f, g, h) min(a, min7(b, c, d, e, f, g, h))\n#define min9(a, b, c, d, e, f, g, h, i) min(a, min8(b, c, d, e, f, g, h, i))\n#define max3(a, b, c) max(a, max(b, c))\n#define max4(a, b, c, d) max(a, max3(b, c, d))\n#define max5(a, b, c, d, e) max(a, max4(b, c, d, e))\n#define max6(a, b, c, d, e, f) max(a, max5(b, c, d, e, f))\n#define max7(a, b, c, d, e, f, g) max(a, max6(b, c, d, e, f, g))\n#define max8(a, b, c, d, e, f, g, h) max(a, max7(b, c, d, e, f, g, h))\n#define max9(a, b, c, d, e, f, g, h, i) max(a, max8(b, c, d, e, f, g, h, i))\nvoid main(){vec4 inputTexel=texture2D(inputTexture,vUv);vec4 lastFrameReflectionsTexel;vec3 newColor;\n#ifdef TEMPORAL_RESOLVE\nvec2 velUv=texture2D(velocityTexture,vUv).xy;float movement=length(velUv)*100.;if(samples<2.){vec2 reprojectedUv=vUv-velUv;if(reprojectedUv.x>=0.&&reprojectedUv.x<=1.&&reprojectedUv.y>=0.&&reprojectedUv.y<=1.){lastFrameReflectionsTexel=texture2D(lastFrameReflectionsTexture,reprojectedUv);if(samples<2.){ivec2 size=textureSize(inputTexture,0);vec2 pxSize=vec2(float(size.x),float(size.y));vec2 px=1./pxSize;vec3 c02=texture2D(inputTexture,vUv+vec2(-px.x,px.y)).rgb;vec3 c12=texture2D(inputTexture,vUv+vec2(0.,px.y)).rgb;vec3 c22=texture2D(inputTexture,vUv+vec2(px.x,px.y)).rgb;vec3 c01=texture2D(inputTexture,vUv+vec2(-px.x,0.)).rgb;vec3 c11=inputTexel.rgb;vec3 c21=texture2D(inputTexture,vUv+vec2(px.x,0.)).rgb;vec3 c00=texture2D(inputTexture,vUv+vec2(-px.x,-px.y)).rgb;vec3 c10=texture2D(inputTexture,vUv+vec2(0.,-px.y)).rgb;vec3 c20=texture2D(inputTexture,vUv+vec2(px.x,-px.y)).rgb;vec3 minNeighborColor=min9(c02,c12,c22,c01,c11,c21,c00,c10,c20);vec3 maxNeighborColor=max9(c02,c12,c22,c01,c11,c21,c00,c10,c20);vec3 clampedColor=clamp(lastFrameReflectionsTexel.rgb,minNeighborColor,maxNeighborColor);lastFrameReflectionsTexel.rgb=mix(lastFrameReflectionsTexel.rgb,clampedColor,temporalResolveCorrectionMix);}}else{lastFrameReflectionsTexel.rgb=inputTexel.rgb;}}else{lastFrameReflectionsTexel=texture2D(lastFrameReflectionsTexture,vUv);}float alpha=min(inputTexel.a,lastFrameReflectionsTexel.a);alpha=samples<2.||movement<FLOAT_EPSILON ?(0.05+alpha): 0.;if(maxSamples!=0.&&samples>maxSamples&&alpha>1.-FLOAT_EPSILON){gl_FragColor=lastFrameReflectionsTexel;return;}if(alpha<1.){newColor=mix(lastFrameReflectionsTexel.rgb,inputTexel.rgb,(1.-alpha)*0.25);}else if(samples>4.&&movement<FLOAT_EPSILON&&length(lastFrameReflectionsTexel.rgb)<FLOAT_EPSILON){newColor=lastFrameReflectionsTexel.rgb;}else if(1./samples>=1.-temporalResolveMix){newColor=lastFrameReflectionsTexel.rgb*(temporalResolveMix)+inputTexel.rgb*(1.-temporalResolveMix);}else{float mixVal=(1./samples)/EULER;if(alpha<FLOAT_EPSILON&&samples<15.)mixVal+=0.3;newColor=mix(lastFrameReflectionsTexel.rgb,inputTexel.rgb,mixVal);}gl_FragColor=vec4(newColor,alpha);\n#else\nlastFrameReflectionsTexel=texture2D(lastFrameReflectionsTexture,vUv);vec2 velUv=texture2D(velocityTexture,vUv).xy;float movement=length(velUv)*100.;float alpha=min(inputTexel.a,lastFrameReflectionsTexel.a);alpha=samples<2.||movement<FLOAT_EPSILON ?(0.05+alpha): 0.;if(maxSamples!=0.&&samples>maxSamples&&alpha>1.-FLOAT_EPSILON){newColor=lastFrameReflectionsTexel.rgb;}else{float samplesMultiplier=pow(samples/32.,4.)+1.;if(samples>1.&&alpha>1.-FLOAT_EPSILON){newColor=lastFrameReflectionsTexel.rgb*(1.-1./(samples*samplesMultiplier))+inputTexel.rgb/(samples*samplesMultiplier);}else{newColor=inputTexel.rgb;}}gl_FragColor=vec4(newColor,alpha);\n#endif\n}"; // eslint-disable-line
var fragmentShader$2 = "#define GLSLIFY 1\n#define EULER 2.718281828459045\n#define FLOAT_EPSILON 0.00001\nuniform sampler2D inputTexture;uniform sampler2D accumulatedReflectionsTexture;uniform sampler2D velocityTexture;uniform float samples;uniform float maxSamples;uniform float temporalResolveMix;uniform float temporalResolveCorrectionMix;varying vec2 vUv;\n#include <packing>\n#define min3(a, b, c) min(a, min(b, c))\n#define min4(a, b, c, d) min(a, min3(b, c, d))\n#define min5(a, b, c, d, e) min(a, min4(b, c, d, e))\n#define min6(a, b, c, d, e, f) min(a, min5(b, c, d, e, f))\n#define min7(a, b, c, d, e, f, g) min(a, min6(b, c, d, e, f, g))\n#define min8(a, b, c, d, e, f, g, h) min(a, min7(b, c, d, e, f, g, h))\n#define min9(a, b, c, d, e, f, g, h, i) min(a, min8(b, c, d, e, f, g, h, i))\n#define max3(a, b, c) max(a, max(b, c))\n#define max4(a, b, c, d) max(a, max3(b, c, d))\n#define max5(a, b, c, d, e) max(a, max4(b, c, d, e))\n#define max6(a, b, c, d, e, f) max(a, max5(b, c, d, e, f))\n#define max7(a, b, c, d, e, f, g) max(a, max6(b, c, d, e, f, g))\n#define max8(a, b, c, d, e, f, g, h) max(a, max7(b, c, d, e, f, g, h))\n#define max9(a, b, c, d, e, f, g, h, i) max(a, max8(b, c, d, e, f, g, h, i))\nvoid main(){vec4 inputTexel=texture2D(inputTexture,vUv);vec4 lastFrameReflectionsTexel;vec3 newColor;\n#ifdef TEMPORAL_RESOLVE\nvec4 velocityTexel=texture2D(velocityTexture,vUv);if(velocityTexel.a>1.-FLOAT_EPSILON){return;}vec2 velUv=velocityTexel.xy;float movement=length(velUv)*100.;if(movement>0.){vec2 reprojectedUv=vUv-velUv;if(reprojectedUv.x>=0.&&reprojectedUv.x<=1.&&reprojectedUv.y>=0.&&reprojectedUv.y<=1.){lastFrameReflectionsTexel=texture2D(accumulatedReflectionsTexture,reprojectedUv);ivec2 size=textureSize(inputTexture,0);vec2 pxSize=vec2(float(size.x),float(size.y));vec2 px=1./pxSize;vec3 c02=texture2D(inputTexture,vUv+vec2(-px.x,px.y)).rgb;vec3 c12=texture2D(inputTexture,vUv+vec2(0.,px.y)).rgb;vec3 c22=texture2D(inputTexture,vUv+vec2(px.x,px.y)).rgb;vec3 c01=texture2D(inputTexture,vUv+vec2(-px.x,0.)).rgb;vec3 c11=inputTexel.rgb;vec3 c21=texture2D(inputTexture,vUv+vec2(px.x,0.)).rgb;vec3 c00=texture2D(inputTexture,vUv+vec2(-px.x,-px.y)).rgb;vec3 c10=texture2D(inputTexture,vUv+vec2(0.,-px.y)).rgb;vec3 c20=texture2D(inputTexture,vUv+vec2(px.x,-px.y)).rgb;vec3 minNeighborColor=min9(c02,c12,c22,c01,c11,c21,c00,c10,c20);vec3 maxNeighborColor=max9(c02,c12,c22,c01,c11,c21,c00,c10,c20);vec3 clampedColor=clamp(lastFrameReflectionsTexel.rgb,minNeighborColor,maxNeighborColor);float mixFactor=temporalResolveCorrectionMix*(1.+movement);mixFactor=min(mixFactor,1.);lastFrameReflectionsTexel.rgb=mix(lastFrameReflectionsTexel.rgb,clampedColor,mixFactor);}else{lastFrameReflectionsTexel.rgb=inputTexel.rgb;}}else{lastFrameReflectionsTexel=texture2D(accumulatedReflectionsTexture,vUv);}float alpha=min(inputTexel.a,lastFrameReflectionsTexel.a);alpha=samples<2.||movement<FLOAT_EPSILON ?(0.05+alpha): 0.;if(maxSamples!=0.&&samples>maxSamples&&alpha>1.-FLOAT_EPSILON){gl_FragColor=lastFrameReflectionsTexel;return;}if(alpha<1.){newColor=mix(lastFrameReflectionsTexel.rgb,inputTexel.rgb,(1.-alpha)*0.25);}else if(samples>4.&&movement<FLOAT_EPSILON&&length(lastFrameReflectionsTexel.rgb)<FLOAT_EPSILON){newColor=lastFrameReflectionsTexel.rgb;}else if(1./samples>=1.-temporalResolveMix){newColor=lastFrameReflectionsTexel.rgb*(temporalResolveMix)+inputTexel.rgb*(1.-temporalResolveMix);}else{float mixVal=(1./samples)/EULER;if(alpha<FLOAT_EPSILON&&samples<15.)mixVal+=0.3;newColor=mix(lastFrameReflectionsTexel.rgb,inputTexel.rgb,mixVal);}\n#else\nlastFrameReflectionsTexel=texture2D(accumulatedReflectionsTexture,vUv);vec2 velUv=texture2D(velocityTexture,vUv).xy;float movement=length(velUv)*100.;float alpha=min(inputTexel.a,lastFrameReflectionsTexel.a);alpha=samples<2.||movement<FLOAT_EPSILON ?(0.05+alpha): 0.;if(maxSamples!=0.&&samples>maxSamples&&alpha>1.-FLOAT_EPSILON){newColor=lastFrameReflectionsTexel.rgb;}else{float samplesMultiplier=pow(samples/32.,4.)+1.;if(samples>1.&&alpha>1.-FLOAT_EPSILON){newColor=lastFrameReflectionsTexel.rgb*(1.-1./(samples*samplesMultiplier))+inputTexel.rgb/(samples*samplesMultiplier);}else{newColor=inputTexel.rgb;}}\n#endif\ngl_FragColor=vec4(newColor,alpha);}"; // eslint-disable-line
const zeroVec2 = new Vector2();
var _ssrEffect$1 = /*#__PURE__*/_classPrivateFieldLooseKey("ssrEffect");
class ComposeReflectionsPass extends Pass {
constructor(ssrEffect) {
constructor(ssrEffect, options = {}) {
super("ComposeReflectionsPass");
this.ssrEffect = ssrEffect;
this.renderTarget = new WebGLRenderTarget(typeof window !== "undefined" ? window.innerWidth : 2000, typeof window !== "undefined" ? window.innerHeight : 1000, {
Object.defineProperty(this, _ssrEffect$1, {
writable: true,
value: void 0
});
_classPrivateFieldLooseBase(this, _ssrEffect$1)[_ssrEffect$1] = ssrEffect;
const width = options.width || typeof window !== "undefined" ? window.innerWidth : 2000;
const height = options.height || typeof window !== "undefined" ? window.innerHeight : 1000;
this.renderTarget = new WebGLRenderTarget(width, height, {
minFilter: NearestFilter,

@@ -52,8 +62,8 @@ magFilter: NearestFilter

inputTexture: new Uniform(null),
lastFrameReflectionsTexture: new Uniform(null),
accumulatedReflectionsTexture: new Uniform(null),
velocityTexture: new Uniform(null),
samples: new Uniform(1),
samples: new Uniform(0),
maxSamples: new Uniform(0),
temporalResolveMix: new Uniform(0.9),
temporalResolveCorrectionMix: new Uniform(0.3875)
temporalResolveMix: new Uniform(0),
temporalResolveCorrectionMix: new Uniform(0)
},

@@ -63,2 +73,3 @@ vertexShader,

});
this.setupAccumulatedReflectionsTexture(width, height);
}

@@ -68,2 +79,3 @@

this.renderTarget.dispose();
this.accumulatedReflectionsTexture.dispose();
this.fullscreenMaterial.dispose();

@@ -74,8 +86,20 @@ }

this.renderTarget.setSize(width, height);
this.accumulatedReflectionsTexture.dispose();
this.setupAccumulatedReflectionsTexture(width, height);
this.fullscreenMaterial.uniforms.accumulatedReflectionsTexture.value = this.accumulatedReflectionsTexture;
this.fullscreenMaterial.needsUpdate = true;
}
setupAccumulatedReflectionsTexture(width, height) {
this.accumulatedReflectionsTexture = new FramebufferTexture(width, height, RGBAFormat);
this.accumulatedReflectionsTexture.minFilter = NearestFilter;
this.accumulatedReflectionsTexture.magFilter = NearestFilter;
}
render(renderer) {
this.fullscreenMaterial.uniforms.samples.value = this.ssrEffect.samples;
this.fullscreenMaterial.uniforms.samples.value = _classPrivateFieldLooseBase(this, _ssrEffect$1)[_ssrEffect$1].samples;
renderer.setRenderTarget(this.renderTarget);
renderer.render(this.scene, this.camera);
renderer.render(this.scene, this.camera); // save the render target's texture for use in next frame
renderer.copyFramebufferToTexture(zeroVec2, this.accumulatedReflectionsTexture);
}

@@ -87,3 +111,3 @@

var fragmentShader$1 = "#define GLSLIFY 1\n#define MODE_DEFAULT 0\n#define MODE_REFLECTIONS 1\n#define MODE_RAW_REFLECTION 2\n#define MODE_BLURRED_REFLECTIONS 3\n#define MODE_INPUT 4\n#define MODE_BLUR_MIX 5\n#define FLOAT_EPSILON 0.00001\n#define SQRT_3 1.7320508075688772 + FLOAT_EPSILON\nuniform sampler2D inputTexture;uniform sampler2D reflectionsTexture;uniform sampler2D depthTexture;uniform float samples;uniform float blurMix;\n#include <bilateralBlur>\nvoid mainImage(const in vec4 inputColor,const in vec2 uv,out vec4 outputColor){vec4 reflectionsTexel=texture2D(reflectionsTexture,vUv);vec3 reflectionClr=reflectionsTexel.xyz;\n#ifdef ENABLE_BLUR\nvec4 blurredReflectionsTexel=blur(reflectionsTexture,depthTexture);reflectionClr=mix(reflectionClr,blurredReflectionsTexel.xyz,blurMix);\n#endif\n#if RENDER_MODE == MODE_DEFAULT\noutputColor=vec4(inputColor.rgb+reflectionClr,1.);\n#endif\n#if RENDER_MODE == MODE_REFLECTIONS\noutputColor=vec4(reflectionClr,1.);\n#endif\n#if RENDER_MODE == MODE_RAW_REFLECTION\noutputColor=vec4(reflectionsTexel.xyz,1.);\n#endif\n#if RENDER_MODE == MODE_BLURRED_REFLECTIONS\n#ifdef ENABLE_BLUR\noutputColor=vec4(blurredReflectionsTexel.xyz,1.);\n#endif\n#endif\n#if RENDER_MODE == MODE_INPUT\noutputColor=vec4(inputColor.xyz,1.);\n#endif\n#if RENDER_MODE == MODE_BLUR_MIX\n#ifdef ENABLE_BLUR\noutputColor=vec4(vec3(blurMix),1.);\n#endif\n#endif\n}"; // eslint-disable-line
var fragmentShader$1 = "#define GLSLIFY 1\n#define MODE_DEFAULT 0\n#define MODE_REFLECTIONS 1\n#define MODE_RAW_REFLECTION 2\n#define MODE_BLURRED_REFLECTIONS 3\n#define MODE_INPUT 4\n#define MODE_BLUR_MIX 5\n#define FLOAT_EPSILON 0.00001\n#define SQRT_3 1.7320508075688772 + FLOAT_EPSILON\nuniform sampler2D inputTexture;uniform sampler2D reflectionsTexture;\n#ifdef ENABLE_BLUR\nuniform sampler2D depthTexture;\n#endif\nuniform float samples;uniform float blurMix;\n#include <bilateralBlur>\nvoid mainImage(const in vec4 inputColor,const in vec2 uv,out vec4 outputColor){vec4 reflectionsTexel=texture2D(reflectionsTexture,vUv);vec3 reflectionClr=reflectionsTexel.xyz;\n#ifdef ENABLE_BLUR\nvec4 blurredReflectionsTexel=blur(reflectionsTexture,depthTexture);reflectionClr=mix(reflectionClr,blurredReflectionsTexel.xyz,blurMix);\n#endif\n#if RENDER_MODE == MODE_DEFAULT\noutputColor=vec4(inputColor.rgb+reflectionClr,1.);\n#endif\n#if RENDER_MODE == MODE_REFLECTIONS\noutputColor=vec4(reflectionClr,1.);\n#endif\n#if RENDER_MODE == MODE_RAW_REFLECTION\noutputColor=vec4(reflectionsTexel.xyz,1.);\n#endif\n#if RENDER_MODE == MODE_BLURRED_REFLECTIONS\n#ifdef ENABLE_BLUR\noutputColor=vec4(blurredReflectionsTexel.xyz,1.);\n#endif\n#endif\n#if RENDER_MODE == MODE_INPUT\noutputColor=vec4(inputColor.xyz,1.);\n#endif\n#if RENDER_MODE == MODE_BLUR_MIX\n#ifdef ENABLE_BLUR\noutputColor=vec4(vec3(blurMix),1.);\n#endif\n#endif\n}"; // eslint-disable-line

@@ -170,2 +194,5 @@ var helperFunctions = "#define GLSLIFY 1\nvec3 getViewPosition(const float depth){float clipW=_projectionMatrix[2][3]*depth+_projectionMatrix[3][3];vec4 clipPosition=vec4((vec3(vUv,depth)-0.5)*2.0,1.0);clipPosition*=clipW;return(_inverseProjectionMatrix*clipPosition).xyz;}float getViewZ(const float depth){return perspectiveDepthToViewZ(depth,cameraNear,cameraFar);}vec3 screenSpaceToWorldSpace(const vec2 uv,const float depth){vec4 ndc=vec4((uv.x-0.5)*2.0,(uv.y-0.5)*2.0,(depth-0.5)*2.0,1.0);vec4 clip=_inverseProjectionMatrix*ndc;vec4 view=cameraMatrixWorld*(clip/clip.w);return view.xyz;}\n#define Scale (vec3(0.8, 0.8, 0.8))\n#define K (19.19)\nvec3 hash(vec3 a){a=fract(a*Scale);a+=dot(a,a.yxz+K);return fract((a.xxy+a.yxx)*a.zyx);}float fresnel_dielectric_cos(float cosi,float eta){float c=abs(cosi);float g=eta*eta-1.0+c*c;float result;if(g>0.0){g=sqrt(g);float A=(g-c)/(g+c);float B=(c*(g+c)-1.0)/(c*(g-c)+1.0);result=0.5*A*A*(1.0+B*B);}else{result=1.0;}return result;}float fresnel_dielectric(vec3 Incoming,vec3 Normal,float eta){float cosine=dot(Incoming,Normal);return min(1.0,5.0*fresnel_dielectric_cos(cosine,eta));}float czm_luminance(vec3 rgb){const vec3 W=vec3(0.2125,0.7154,0.0721);return dot(rgb,W);}"; // eslint-disable-line

},
boneTexture: {
value: null
},
alphaTest: {

@@ -231,10 +258,12 @@ value: 0.0

// WebGL2: will render normals to RGB channel of "gNormal" buffer, roughness to A channel of "gNormal" buffer, depth to RGBA channel of "gDepth" buffer
// and velocity to "gVelocity" buffer
class NormalDepthRoughnessMaterial extends ShaderMaterial {
class MRTMaterial extends ShaderMaterial {
constructor() {
super({
type: "NormalDepthRoughnessMaterial",
type: "MRTMaterial",
defines: {
USE_UV: "",
TEMPORAL_RESOLVE: ""
TEMPORAL_RESOLVE: "",
MAX_BONES: 256
},

@@ -258,2 +287,5 @@ uniforms: _extends({

${ShaderChunk.skinning_pars_vertex}
${prev_skinning_pars_vertex}
uniform mat4 prevProjectionMatrix;

@@ -275,3 +307,2 @@ uniform mat4 prevModelViewMatrix;

#include <morphtarget_pars_vertex>
#include <skinning_pars_vertex>
#include <logdepthbuf_pars_vertex>

@@ -290,3 +321,2 @@ #include <clipping_planes_pars_vertex>

#include <morphtarget_vertex>
#include <skinning_vertex>
#include <displacementmap_vertex>

@@ -309,6 +339,13 @@ #include <project_vertex>

#ifdef TEMPORAL_RESOLVE
#ifndef NEEDS_UPDATED_REFLECTIONS
// #ifndef NEEDS_UPDATED_REFLECTIONS
transformed = vec3( position );
${ShaderChunk.skinning_vertex}
newPosition = modelViewMatrix * vec4( transformed, 1.0 );
transformed = vec3( position );
${ShaderChunk.skinbase_vertex.replace(/mat4 /g, "").replace(/getBoneMatrix/g, "getPrevBoneMatrix")}
${ShaderChunk.skinning_vertex.replace(/vec4 /g, "")}
newPosition = modelViewMatrix * vec4( transformed, 1.0 );
prevPosition = prevModelViewMatrix * vec4( transformed, 1.0 );

@@ -319,4 +356,4 @@

// gl_Position = mix( newPosition, prevPosition, interpolateGeometry );
#endif
gl_Position = mix( newPosition, prevPosition, interpolateGeometry );
// #endif
#endif

@@ -342,3 +379,2 @@

#include <roughnessmap_pars_fragment>

@@ -367,6 +403,16 @@ #ifdef USE_MRT

#include <normal_fragment_maps>
#include <roughnessmap_fragment>
float roughnessFactor = roughness;
if(roughness > 10.0e9){
roughnessFactor = 1.;
}else{
#ifdef USE_ROUGHNESSMAP
vec4 texelRoughness = texture2D( roughnessMap, vUv );
// reads channel G, compatible with a combined OcclusionRoughnessMetallic (RGB) texture
roughnessFactor *= texelRoughness.g;
#endif
}
vec3 normalColor = packNormalToRGB( normal );
float roughnessValue = min(1., roughnessFactor);

@@ -377,3 +423,3 @@ #ifdef USE_MRT

gNormal = vec4( normalColor, 1.0 );
gNormal.a = roughnessValue;
gNormal.a = roughnessFactor;
gDepth = depthColor;

@@ -394,4 +440,6 @@

vec3 vel = pos1 - pos0;
float skyVal = fragCoordZ == 0. ? 1. : 0.;
gVelocity = vec4( vel * intensity, 1.0 );
gVelocity = vec4( vel * intensity, skyVal);
#endif

@@ -401,3 +449,3 @@ #endif

#else
gl_FragColor = vec4(normalColor, roughnessValue);
gl_FragColor = vec4(normalColor, roughnessFactor);
#endif

@@ -423,3 +471,3 @@

var fragmentShader = "#define GLSLIFY 1\nvarying vec2 vUv;uniform sampler2D inputTexture;uniform sampler2D lastFrameReflectionsTexture;uniform sampler2D normalTexture;uniform sampler2D depthTexture;uniform mat4 _projectionMatrix;uniform mat4 _inverseProjectionMatrix;uniform mat4 cameraMatrixWorld;uniform float cameraNear;uniform float cameraFar;uniform float rayStep;uniform float intensity;uniform float maxDepthDifference;uniform float roughnessFadeOut;uniform float maxRoughness;uniform float maxDepth;uniform float rayFadeOut;uniform float thickness;uniform float ior;uniform float samples;\n#ifdef ENABLE_JITTERING\nuniform float jitter;uniform float jitterRough;uniform float jitterSpread;\n#endif\n#define FLOAT_EPSILON 0.00001\n#define EARLY_OUT_COLOR vec4(0., 0., 0., 1.)\nconst vec2 INVALID_RAY_COORDS=vec2(-1.);float _maxDepthDifference;\n#include <packing>\n#include <helperFunctions>\nvec2 BinarySearch(inout vec3 dir,inout vec3 hitPos,inout float rayHitDepthDifference);vec2 RayMarch(vec3 dir,inout vec3 hitPos,inout float rayHitDepthDifference);void main(){vec4 depthTexel=texture2D(depthTexture,vUv);if(dot(depthTexel.rgb,depthTexel.rgb)<FLOAT_EPSILON){gl_FragColor=EARLY_OUT_COLOR;return;}float unpackedDepth=unpackRGBAToDepth(depthTexel);if(unpackedDepth>maxDepth){gl_FragColor=EARLY_OUT_COLOR;return;}vec4 normalTexel=texture2D(normalTexture,vUv);float roughness=normalTexel.a;if(roughness>maxRoughness){gl_FragColor=EARLY_OUT_COLOR;return;}if(roughness>1.-FLOAT_EPSILON&&roughnessFadeOut>1.-FLOAT_EPSILON){gl_FragColor=EARLY_OUT_COLOR;return;}float specular=1.-roughness;specular*=specular;normalTexel.rgb=unpackRGBToNormal(normalTexel.rgb);float depth=getViewZ(unpackedDepth);vec3 viewNormal=normalTexel.xyz;vec3 viewPos=getViewPosition(depth);vec3 worldPos=screenSpaceToWorldSpace(vUv,unpackedDepth);vec3 jitt=vec3(0.);\n#ifdef ENABLE_JITTERING\nvec3 randomJitter=hash(5.*(samples*worldPos))-0.5;float spread=((2.-specular)+roughness*jitterRough)*jitterSpread;float jitterMix=jitter+jitterRough*roughness;if(jitterMix>1.)jitterMix=1.;jitt=mix(vec3(0.),randomJitter*spread,jitterMix);\n#endif\njitt=mix(jitt,vec3(0.),0.5);viewNormal+=jitt;vec3 reflected=normalize(reflect(normalize(viewPos),normalize(viewNormal)));_maxDepthDifference=maxDepthDifference*0.01;vec3 rayDir=reflected*-viewPos.z;vec3 hitPos=viewPos;float rayHitDepthDifference;vec2 coords=RayMarch(rayDir,hitPos,rayHitDepthDifference);if(coords.x==-1.){gl_FragColor=EARLY_OUT_COLOR;return;}vec2 coordsNDC=(coords*2.0-1.0);float screenFade=0.1;float maxDimension=min(1.0,max(abs(coordsNDC.x),abs(coordsNDC.y)));float screenEdgefactor=1.0-(max(0.0,maxDimension-screenFade)/(1.0-screenFade));screenEdgefactor=max(0.,screenEdgefactor);vec4 SSRTexel=texture2D(inputTexture,coords.xy);vec4 SSRTexelReflected=texture2D(lastFrameReflectionsTexture,coords.xy);vec3 SSR=SSRTexel.rgb+SSRTexelReflected.rgb;float roughnessFactor=mix(specular,1.,max(0.,1.-roughnessFadeOut));vec3 finalSSR=SSR*screenEdgefactor*roughnessFactor;vec3 hitWorldPos=screenSpaceToWorldSpace(coords,rayHitDepthDifference);float reflectionDistance=distance(hitWorldPos,worldPos);reflectionDistance+=1.;if(rayFadeOut!=0.){float opacity=1./(reflectionDistance*reflectionDistance*rayFadeOut*0.01);if(opacity>1.)opacity=1.;finalSSR*=opacity;}float blurMix=0.;\n#ifdef ENABLE_BLUR\nblurMix=sqrt(reflectionDistance)*maxRoughness;if(blurMix>1.)blurMix=1.;\n#endif\nfloat fresnelFactor=fresnel_dielectric(normalize(viewPos),viewNormal,ior);finalSSR=finalSSR*fresnelFactor*intensity;finalSSR=min(vec3(1.),finalSSR);gl_FragColor=vec4(finalSSR,SSRTexelReflected.a);\n#include <encodings_fragment>\n}vec2 RayMarch(vec3 dir,inout vec3 hitPos,inout float rayHitDepthDifference){dir=normalize(dir);dir*=rayStep;float depth;int steps;vec4 projectedCoord;vec4 lastProjectedCoord;float unpackedDepth;float stepMultiplier=1.;vec4 depthTexel;for(int i=0;i<MAX_STEPS;i++){hitPos+=dir*stepMultiplier;projectedCoord=_projectionMatrix*vec4(hitPos,1.0);projectedCoord.xy/=projectedCoord.w;projectedCoord.xy=projectedCoord.xy*0.5+0.5;if(projectedCoord.x>1.||projectedCoord.y>1.){hitPos-=dir*stepMultiplier;stepMultiplier*=0.5;continue;}depthTexel=textureLod(depthTexture,projectedCoord.xy,0.);unpackedDepth=unpackRGBAToDepth(depthTexel);depth=getViewZ(unpackedDepth);rayHitDepthDifference=depth-hitPos.z;if(rayHitDepthDifference>=0.&&rayHitDepthDifference<thickness){\n#if NUM_BINARY_SEARCH_STEPS == 0\nif(dot(depthTexel.rgb,depthTexel.rgb)<FLOAT_EPSILON)return INVALID_RAY_COORDS;\n#else\nprojectedCoord.xy=BinarySearch(dir,hitPos,rayHitDepthDifference);\n#endif\nreturn projectedCoord.xy;}steps++;lastProjectedCoord=projectedCoord;}\n#ifndef STRETCH_MISSED_RAYS\nreturn INVALID_RAY_COORDS;\n#endif\nrayHitDepthDifference=unpackedDepth;return projectedCoord.xy;}vec2 BinarySearch(inout vec3 dir,inout vec3 hitPos,inout float rayHitDepthDifference){float depth;vec4 projectedCoord;vec2 lastMinProjectedCoordXY;float unpackedDepth;vec4 depthTexel;for(int i=0;i<NUM_BINARY_SEARCH_STEPS;i++){projectedCoord=_projectionMatrix*vec4(hitPos,1.0);projectedCoord.xy/=projectedCoord.w;projectedCoord.xy=projectedCoord.xy*0.5+0.5;if((lastMinProjectedCoordXY.x>1.||lastMinProjectedCoordXY.y>1.)&&(projectedCoord.x>1.||projectedCoord.y>1.))return INVALID_RAY_COORDS;depthTexel=textureLod(depthTexture,projectedCoord.xy,0.);unpackedDepth=unpackRGBAToDepth(depthTexel);depth=getViewZ(unpackedDepth);rayHitDepthDifference=depth-hitPos.z;dir*=0.5;if(rayHitDepthDifference>0.0){hitPos-=dir;}else{hitPos+=dir;lastMinProjectedCoordXY=projectedCoord.xy;}}if(dot(depthTexel.rgb,depthTexel.rgb)<FLOAT_EPSILON)return INVALID_RAY_COORDS;if(abs(rayHitDepthDifference)>_maxDepthDifference)return INVALID_RAY_COORDS;projectedCoord=_projectionMatrix*vec4(hitPos,1.0);projectedCoord.xy/=projectedCoord.w;projectedCoord.xy=projectedCoord.xy*0.5+0.5;\n#ifndef STRETCH_MISSED_RAYS\nif(projectedCoord.x>1.||projectedCoord.y>1.)return INVALID_RAY_COORDS;\n#endif\nrayHitDepthDifference=unpackedDepth;return projectedCoord.xy;}"; // eslint-disable-line
var fragmentShader = "#define GLSLIFY 1\nvarying vec2 vUv;uniform sampler2D inputTexture;uniform sampler2D accumulatedReflectionsTexture;uniform sampler2D normalTexture;uniform sampler2D depthTexture;uniform mat4 _projectionMatrix;uniform mat4 _inverseProjectionMatrix;uniform mat4 cameraMatrixWorld;uniform float cameraNear;uniform float cameraFar;uniform float rayStep;uniform float intensity;uniform float maxDepthDifference;uniform float roughnessFadeOut;uniform float maxRoughness;uniform float maxDepth;uniform float rayFadeOut;uniform float thickness;uniform float ior;uniform float samples;\n#ifdef ENABLE_JITTERING\nuniform float jitter;uniform float jitterRough;uniform float jitterSpread;\n#endif\n#define FLOAT_EPSILON 0.00001\n#define EARLY_OUT_COLOR vec4(0., 0., 0., 1.)\nconst vec2 INVALID_RAY_COORDS=vec2(-1.);float _maxDepthDifference;\n#include <packing>\n#include <helperFunctions>\nvec2 BinarySearch(inout vec3 dir,inout vec3 hitPos,inout float rayHitDepthDifference);vec2 RayMarch(vec3 dir,inout vec3 hitPos,inout float rayHitDepthDifference);void main(){vec4 depthTexel=texture2D(depthTexture,vUv);if(dot(depthTexel.rgb,depthTexel.rgb)<FLOAT_EPSILON){gl_FragColor=EARLY_OUT_COLOR;return;}float unpackedDepth=unpackRGBAToDepth(depthTexel);if(unpackedDepth>maxDepth){gl_FragColor=EARLY_OUT_COLOR;return;}vec4 normalTexel=texture2D(normalTexture,vUv);float roughness=normalTexel.a;if(roughness>maxRoughness||(roughness>1.-FLOAT_EPSILON&&roughnessFadeOut>1.-FLOAT_EPSILON)){gl_FragColor=EARLY_OUT_COLOR;return;}float specular=1.-roughness;specular*=specular;normalTexel.rgb=unpackRGBToNormal(normalTexel.rgb);float depth=getViewZ(unpackedDepth);vec3 viewNormal=normalTexel.xyz;vec3 viewPos=getViewPosition(depth);vec3 worldPos=screenSpaceToWorldSpace(vUv,unpackedDepth);vec3 jitt=vec3(0.);\n#ifdef ENABLE_JITTERING\nvec3 randomJitter=hash(5.*(samples*worldPos))-0.5;float spread=((2.-specular)+roughness*jitterRough)*jitterSpread;float jitterMix=jitter+jitterRough*roughness;if(jitterMix>1.)jitterMix=1.;jitt=mix(vec3(0.),randomJitter*spread,jitterMix);\n#endif\njitt=mix(jitt,vec3(0.),0.5);viewNormal+=jitt;vec3 reflected=normalize(reflect(normalize(viewPos),normalize(viewNormal)));_maxDepthDifference=maxDepthDifference*0.01;vec3 rayDir=reflected*-viewPos.z;vec3 hitPos=viewPos;float rayHitDepthDifference;vec2 coords=RayMarch(rayDir,hitPos,rayHitDepthDifference);if(coords.x==-1.){gl_FragColor=EARLY_OUT_COLOR;return;}vec2 coordsNDC=(coords*2.0-1.0);float screenFade=0.1;float maxDimension=min(1.0,max(abs(coordsNDC.x),abs(coordsNDC.y)));float screenEdgefactor=1.0-(max(0.0,maxDimension-screenFade)/(1.0-screenFade));screenEdgefactor=max(0.,screenEdgefactor);vec4 SSRTexel=texture2D(inputTexture,coords.xy);vec4 SSRTexelReflected=texture2D(accumulatedReflectionsTexture,coords.xy);vec3 SSR=SSRTexel.rgb+SSRTexelReflected.rgb;float roughnessFactor=mix(specular,1.,max(0.,1.-roughnessFadeOut));vec3 finalSSR=SSR*screenEdgefactor*roughnessFactor;vec3 hitWorldPos=screenSpaceToWorldSpace(coords,rayHitDepthDifference);float reflectionDistance=distance(hitWorldPos,worldPos);reflectionDistance+=1.;if(rayFadeOut!=0.){float opacity=1./(reflectionDistance*reflectionDistance*rayFadeOut*0.01);if(opacity>1.)opacity=1.;finalSSR*=opacity;}float blurMix=0.;\n#ifdef ENABLE_BLUR\nblurMix=sqrt(reflectionDistance)*maxRoughness;if(blurMix>1.)blurMix=1.;\n#endif\nfloat fresnelFactor=fresnel_dielectric(normalize(viewPos),viewNormal,ior);finalSSR=finalSSR*fresnelFactor*intensity;finalSSR=min(vec3(1.),finalSSR);gl_FragColor=vec4(finalSSR,SSRTexel.a);\n#include <encodings_fragment>\n}vec2 RayMarch(vec3 dir,inout vec3 hitPos,inout float rayHitDepthDifference){dir=normalize(dir);dir*=rayStep;float depth;int steps;vec4 projectedCoord;vec4 lastProjectedCoord;float unpackedDepth;float stepMultiplier=1.;vec4 depthTexel;for(int i=0;i<MAX_STEPS;i++){hitPos+=dir*stepMultiplier;projectedCoord=_projectionMatrix*vec4(hitPos,1.0);projectedCoord.xy/=projectedCoord.w;projectedCoord.xy=projectedCoord.xy*0.5+0.5;if(projectedCoord.x>1.||projectedCoord.y>1.){hitPos-=dir*stepMultiplier;stepMultiplier*=0.5;continue;}depthTexel=textureLod(depthTexture,projectedCoord.xy,0.);unpackedDepth=unpackRGBAToDepth(depthTexel);depth=getViewZ(unpackedDepth);rayHitDepthDifference=depth-hitPos.z;if(rayHitDepthDifference>=0.&&rayHitDepthDifference<thickness){\n#if NUM_BINARY_SEARCH_STEPS == 0\nif(dot(depthTexel.rgb,depthTexel.rgb)<FLOAT_EPSILON)return INVALID_RAY_COORDS;\n#else\nprojectedCoord.xy=BinarySearch(dir,hitPos,rayHitDepthDifference);\n#endif\nreturn projectedCoord.xy;}steps++;lastProjectedCoord=projectedCoord;}\n#ifndef STRETCH_MISSED_RAYS\nreturn INVALID_RAY_COORDS;\n#endif\nrayHitDepthDifference=unpackedDepth;return projectedCoord.xy;}vec2 BinarySearch(inout vec3 dir,inout vec3 hitPos,inout float rayHitDepthDifference){float depth;vec4 projectedCoord;vec2 lastMinProjectedCoordXY;float unpackedDepth;vec4 depthTexel;for(int i=0;i<NUM_BINARY_SEARCH_STEPS;i++){projectedCoord=_projectionMatrix*vec4(hitPos,1.0);projectedCoord.xy/=projectedCoord.w;projectedCoord.xy=projectedCoord.xy*0.5+0.5;if((lastMinProjectedCoordXY.x>1.||lastMinProjectedCoordXY.y>1.)&&(projectedCoord.x>1.||projectedCoord.y>1.))return INVALID_RAY_COORDS;depthTexel=textureLod(depthTexture,projectedCoord.xy,0.);unpackedDepth=unpackRGBAToDepth(depthTexel);depth=getViewZ(unpackedDepth);rayHitDepthDifference=depth-hitPos.z;dir*=0.5;if(rayHitDepthDifference>0.0){hitPos-=dir;}else{hitPos+=dir;lastMinProjectedCoordXY=projectedCoord.xy;}}if(dot(depthTexel.rgb,depthTexel.rgb)<FLOAT_EPSILON)return INVALID_RAY_COORDS;if(abs(rayHitDepthDifference)>_maxDepthDifference)return INVALID_RAY_COORDS;projectedCoord=_projectionMatrix*vec4(hitPos,1.0);projectedCoord.xy/=projectedCoord.w;projectedCoord.xy=projectedCoord.xy*0.5+0.5;\n#ifndef STRETCH_MISSED_RAYS\nif(projectedCoord.x>1.||projectedCoord.y>1.)return INVALID_RAY_COORDS;\n#endif\nrayHitDepthDifference=unpackedDepth;return projectedCoord.xy;}"; // eslint-disable-line

@@ -432,3 +480,3 @@ class ReflectionsMaterial extends ShaderMaterial {

inputTexture: new Uniform(null),
lastFrameReflectionsTexture: new Uniform(null),
accumulatedReflectionsTexture: new Uniform(null),
normalTexture: new Uniform(null),

@@ -469,7 +517,7 @@ depthTexture: new Uniform(null),

var _defaultMaterials$1 = /*#__PURE__*/_classPrivateFieldLooseKey("defaultMaterials");
var _defaultMaterials = /*#__PURE__*/_classPrivateFieldLooseKey("defaultMaterials");
var _velocityMaterials = /*#__PURE__*/_classPrivateFieldLooseKey("velocityMaterials");
var _prevProjectionMatrix = /*#__PURE__*/_classPrivateFieldLooseKey("prevProjectionMatrix");
var _prevProjectionMatrix$1 = /*#__PURE__*/_classPrivateFieldLooseKey("prevProjectionMatrix");

@@ -489,3 +537,3 @@ var _setVelocityMaterialInScene = /*#__PURE__*/_classPrivateFieldLooseKey("setVelocityMaterialInScene");

});
Object.defineProperty(this, _defaultMaterials$1, {
Object.defineProperty(this, _defaultMaterials, {
writable: true,

@@ -498,3 +546,3 @@ value: {}

});
Object.defineProperty(this, _prevProjectionMatrix, {
Object.defineProperty(this, _prevProjectionMatrix$1, {
writable: true,

@@ -512,3 +560,3 @@ value: new Matrix4()

render(renderer, inputTexture) {
render(renderer) {
_classPrivateFieldLooseBase(this, _setVelocityMaterialInScene)[_setVelocityMaterialInScene]();

@@ -522,3 +570,3 @@

_classPrivateFieldLooseBase(this, _prevProjectionMatrix)[_prevProjectionMatrix].copy(this._camera.projectionMatrix);
_classPrivateFieldLooseBase(this, _prevProjectionMatrix$1)[_prevProjectionMatrix$1].copy(this._camera.projectionMatrix);
}

@@ -532,3 +580,3 @@

const origMat = c.material;
_classPrivateFieldLooseBase(this, _defaultMaterials$1)[_defaultMaterials$1][c.material.uuid] = origMat;
_classPrivateFieldLooseBase(this, _defaultMaterials)[_defaultMaterials][c.material.uuid] = origMat;

@@ -552,3 +600,3 @@ if (_classPrivateFieldLooseBase(this, _velocityMaterials)[_velocityMaterials][origMat.uuid] === undefined) {

velocityMaterial.uniforms.prevModelViewMatrix.value.multiplyMatrices(this._camera.matrixWorldInverse, c.matrixWorld);
velocityMaterial.uniforms.prevProjectionMatrix.value = _classPrivateFieldLooseBase(this, _prevProjectionMatrix)[_prevProjectionMatrix];
velocityMaterial.uniforms.prevProjectionMatrix.value = _classPrivateFieldLooseBase(this, _prevProjectionMatrix$1)[_prevProjectionMatrix$1];

@@ -559,8 +607,8 @@ if (c.userData.prevModelViewMatrix) {

const needsUpatedReflections = c.material.userData.needsUpatedReflections || c.material.map instanceof VideoTexture; // mark the material as "ANIMATED" so that, when using temporal resolve, we get updated reflections
const needsUpdatedReflections = c.material.userData.needsUpdatedReflections || c.material.map instanceof VideoTexture; // mark the material as "ANIMATED" so that, when using temporal resolve, we get updated reflections
if (needsUpatedReflections && !Object.keys(velocityMaterial.defines).includes("NEEDS_UPDATED_REFLECTIONS")) {
if (needsUpdatedReflections && !Object.keys(velocityMaterial.defines).includes("NEEDS_UPDATED_REFLECTIONS")) {
velocityMaterial.defines.NEEDS_UPDATED_REFLECTIONS = "";
velocityMaterial.needsUpdate = true;
} else if (!needsUpatedReflections && Object.keys(velocityMaterial.defines).includes("NEEDS_UPDATED_REFLECTIONS")) {
} else if (!needsUpdatedReflections && Object.keys(velocityMaterial.defines).includes("NEEDS_UPDATED_REFLECTIONS")) {
delete velocityMaterial.defines.NEEDS_UPDATED_REFLECTIONS;

@@ -580,3 +628,3 @@ velocityMaterial.needsUpdate = true;

c.userData.prevModelViewMatrix.multiplyMatrices(this._camera.matrixWorldInverse, c.matrixWorld);
c.material = _classPrivateFieldLooseBase(this, _defaultMaterials$1)[_defaultMaterials$1][c.material._originalUuid];
c.material = _classPrivateFieldLooseBase(this, _defaultMaterials)[_defaultMaterials][c.material._originalUuid];
}

@@ -595,6 +643,8 @@ });

var _defaultMaterials = /*#__PURE__*/_classPrivateFieldLooseKey("defaultMaterials");
var _ssrEffect = /*#__PURE__*/_classPrivateFieldLooseKey("ssrEffect");
var _normalDepthMaterials = /*#__PURE__*/_classPrivateFieldLooseKey("normalDepthMaterials");
var _cachedMaterials = /*#__PURE__*/_classPrivateFieldLooseKey("cachedMaterials");
var _prevProjectionMatrix = /*#__PURE__*/_classPrivateFieldLooseKey("prevProjectionMatrix");
var _USE_MRT = /*#__PURE__*/_classPrivateFieldLooseKey("USE_MRT");

@@ -606,28 +656,37 @@

var _keepMaterialUpdated = /*#__PURE__*/_classPrivateFieldLooseKey("keepMaterialUpdated");
var _keepMaterialMapUpdated = /*#__PURE__*/_classPrivateFieldLooseKey("keepMaterialMapUpdated");
var _setNormalDepthRoughnessMaterialInScene = /*#__PURE__*/_classPrivateFieldLooseKey("setNormalDepthRoughnessMaterialInScene");
var _setMRTMaterialInScene = /*#__PURE__*/_classPrivateFieldLooseKey("setMRTMaterialInScene");
var _unsetNormalDepthRoughnessMaterialInScene = /*#__PURE__*/_classPrivateFieldLooseKey("unsetNormalDepthRoughnessMaterialInScene");
var _updateBoneTexture = /*#__PURE__*/_classPrivateFieldLooseKey("updateBoneTexture");
var _unsetMRTMaterialInScene = /*#__PURE__*/_classPrivateFieldLooseKey("unsetMRTMaterialInScene");
class ReflectionsPass extends Pass {
constructor(ssrPass, options = {}) {
constructor(ssrEffect, options = {}) {
super("ReflectionsPass");
Object.defineProperty(this, _unsetNormalDepthRoughnessMaterialInScene, {
value: _unsetNormalDepthRoughnessMaterialInScene2
Object.defineProperty(this, _unsetMRTMaterialInScene, {
value: _unsetMRTMaterialInScene2
});
Object.defineProperty(this, _setNormalDepthRoughnessMaterialInScene, {
value: _setNormalDepthRoughnessMaterialInScene2
Object.defineProperty(this, _updateBoneTexture, {
value: _updateBoneTexture2
});
Object.defineProperty(this, _keepMaterialUpdated, {
value: _keepMaterialUpdated2
Object.defineProperty(this, _setMRTMaterialInScene, {
value: _setMRTMaterialInScene2
});
Object.defineProperty(this, _defaultMaterials, {
Object.defineProperty(this, _keepMaterialMapUpdated, {
value: _keepMaterialMapUpdated2
});
Object.defineProperty(this, _ssrEffect, {
writable: true,
value: {}
value: void 0
});
Object.defineProperty(this, _normalDepthMaterials, {
Object.defineProperty(this, _cachedMaterials, {
writable: true,
value: {}
value: new WeakMap()
});
Object.defineProperty(this, _prevProjectionMatrix, {
writable: true,
value: new Matrix4()
});
Object.defineProperty(this, _USE_MRT, {

@@ -645,6 +704,5 @@ writable: true,

});
this.samples = 1;
this.ssrPass = ssrPass;
this._scene = ssrPass._scene;
this._camera = ssrPass._camera;
_classPrivateFieldLooseBase(this, _ssrEffect)[_ssrEffect] = ssrEffect;
this._scene = ssrEffect._scene;
this._camera = ssrEffect._camera;
this.fullscreenMaterial = new ReflectionsMaterial();

@@ -661,3 +719,3 @@ const width = options.width || typeof window !== "undefined" ? window.innerWidth : 2000;

if (_classPrivateFieldLooseBase(this, _USE_MRT)[_USE_MRT]) {
// buffers: normal, depth (2), roughness will be written to the alpha channel of the normal buffer
// buffers: normal, depth, velocity (3), roughness will be written to the alpha channel of the normal buffer
this.gBuffersRenderTarget = new WebGLMultipleRenderTargets(width, height, 3, {

@@ -694,8 +752,5 @@ minFilter: NearestFilter,

this.lastFrameReflectionsTexture = new FramebufferTexture(width, height, RGBAFormat);
this.lastFrameReflectionsTexture.minFilter = NearestFilter;
this.lastFrameReflectionsTexture.magFilter = NearestFilter;
this.fullscreenMaterial.uniforms.normalTexture.value = this.normalTexture;
this.fullscreenMaterial.uniforms.depthTexture.value = this.depthTexture;
this.fullscreenMaterial.uniforms.lastFrameReflectionsTexture.value = this.lastFrameReflectionsTexture;
this.fullscreenMaterial.uniforms.accumulatedReflectionsTexture.value = _classPrivateFieldLooseBase(this, _ssrEffect)[_ssrEffect].composeReflectionsPass.accumulatedReflectionsTexture;
this.fullscreenMaterial.uniforms.cameraMatrixWorld.value = this._camera.matrixWorld;

@@ -707,12 +762,6 @@ this.fullscreenMaterial.uniforms._projectionMatrix.value = this._camera.projectionMatrix;

setSize(width, height) {
this.renderTarget.setSize(width * this.ssrPass.resolutionScale, height * this.ssrPass.resolutionScale);
this.gBuffersRenderTarget.setSize(width * this.ssrPass.resolutionScale, height * this.ssrPass.resolutionScale);
this.lastFrameReflectionsTexture.dispose();
this.lastFrameReflectionsTexture = new FramebufferTexture(width, height, RGBAFormat);
this.lastFrameReflectionsTexture.minFilter = NearestFilter;
this.lastFrameReflectionsTexture.magFilter = NearestFilter;
this.fullscreenMaterial.uniforms.lastFrameReflectionsTexture.value = this.lastFrameReflectionsTexture;
this.renderTarget.setSize(width * _classPrivateFieldLooseBase(this, _ssrEffect)[_ssrEffect].resolutionScale, height * _classPrivateFieldLooseBase(this, _ssrEffect)[_ssrEffect].resolutionScale);
this.gBuffersRenderTarget.setSize(width * _classPrivateFieldLooseBase(this, _ssrEffect)[_ssrEffect].resolutionScale, height * _classPrivateFieldLooseBase(this, _ssrEffect)[_ssrEffect].resolutionScale);
this.fullscreenMaterial.uniforms.accumulatedReflectionsTexture.value = _classPrivateFieldLooseBase(this, _ssrEffect)[_ssrEffect].composeReflectionsPass.accumulatedReflectionsTexture;
this.fullscreenMaterial.needsUpdate = true;
this.ssrPass.composeReflectionsPass.fullscreenMaterial.uniforms.lastFrameReflectionsTexture.value = this.lastFrameReflectionsTexture;
this.ssrPass.composeReflectionsPass.fullscreenMaterial.needsUpdate = true;

@@ -738,3 +787,2 @@ if (!_classPrivateFieldLooseBase(this, _USE_MRT)[_USE_MRT]) {

this.lastFrameReflectionsTexture.dispose();
this.normalTexture = null;

@@ -745,4 +793,4 @@ this.depthTexture = null;

render(renderer, inputTexture) {
_classPrivateFieldLooseBase(this, _setNormalDepthRoughnessMaterialInScene)[_setNormalDepthRoughnessMaterialInScene]();
render(renderer, inputBuffer) {
_classPrivateFieldLooseBase(this, _setMRTMaterialInScene)[_setMRTMaterialInScene]();

@@ -752,3 +800,3 @@ renderer.setRenderTarget(this.gBuffersRenderTarget);

_classPrivateFieldLooseBase(this, _unsetNormalDepthRoughnessMaterialInScene)[_unsetNormalDepthRoughnessMaterialInScene](); // render depth and velocity in seperate passes
_classPrivateFieldLooseBase(this, _unsetMRTMaterialInScene)[_unsetMRTMaterialInScene](); // render depth and velocity in seperate passes

@@ -759,7 +807,7 @@

if (this.ssrPass.temporalResolve) _classPrivateFieldLooseBase(this, _webgl1VelocityPass)[_webgl1VelocityPass].render(renderer, inputTexture);
if (_classPrivateFieldLooseBase(this, _ssrEffect)[_ssrEffect].temporalResolve) _classPrivateFieldLooseBase(this, _webgl1VelocityPass)[_webgl1VelocityPass].render(renderer);
}
this.fullscreenMaterial.uniforms.inputTexture.value = inputTexture.texture;
this.fullscreenMaterial.uniforms.samples.value = this.ssrPass.samples;
this.fullscreenMaterial.uniforms.inputTexture.value = inputBuffer.texture;
this.fullscreenMaterial.uniforms.samples.value = _classPrivateFieldLooseBase(this, _ssrEffect)[_ssrEffect].samples;
this.fullscreenMaterial.uniforms.cameraNear.value = this._camera.near;

@@ -773,68 +821,66 @@ this.fullscreenMaterial.uniforms.cameraFar.value = this._camera.far;

function _keepMaterialUpdated2(normalDepthMaterial, origMat, prop, define) {
if (this.ssrPass[define]) {
if (origMat[prop] !== normalDepthMaterial[prop]) {
normalDepthMaterial[prop] = origMat[prop];
normalDepthMaterial.uniforms[prop].value = origMat[prop];
function _keepMaterialMapUpdated2(mrtMaterial, originalMaterial, prop, define) {
if (_classPrivateFieldLooseBase(this, _ssrEffect)[_ssrEffect][define]) {
if (originalMaterial[prop] !== mrtMaterial[prop]) {
mrtMaterial[prop] = originalMaterial[prop];
mrtMaterial.uniforms[prop].value = originalMaterial[prop];
if (origMat[prop]) {
normalDepthMaterial.defines[define] = "";
if (originalMaterial[prop]) {
mrtMaterial.defines[define] = "";
} else {
delete normalDepthMaterial.defines[define];
delete mrtMaterial.defines[define];
}
normalDepthMaterial.needsUpdate = true;
mrtMaterial.needsUpdate = true;
}
} else if (normalDepthMaterial[prop] !== undefined) {
normalDepthMaterial[prop] = undefined;
normalDepthMaterial.uniforms[prop].value = undefined;
delete normalDepthMaterial.defines[define];
normalDepthMaterial.needsUpdate = true;
} else if (mrtMaterial[prop] !== undefined) {
mrtMaterial[prop] = undefined;
mrtMaterial.uniforms[prop].value = undefined;
delete mrtMaterial.defines[define];
mrtMaterial.needsUpdate = true;
}
}
function _setNormalDepthRoughnessMaterialInScene2() {
function _setMRTMaterialInScene2() {
this._scene.traverse(c => {
if (c.material) {
const origMat = c.material;
_classPrivateFieldLooseBase(this, _defaultMaterials)[_defaultMaterials][c.material.uuid] = origMat;
const originalMaterial = c.material;
let [cachedOriginalMaterial, mrtMaterial] = _classPrivateFieldLooseBase(this, _cachedMaterials)[_cachedMaterials].get(c) || [];
if (_classPrivateFieldLooseBase(this, _normalDepthMaterials)[_normalDepthMaterials][origMat.uuid] === undefined) {
_classPrivateFieldLooseBase(this, _normalDepthMaterials)[_normalDepthMaterials][origMat.uuid] = new NormalDepthRoughnessMaterial();
if (!_classPrivateFieldLooseBase(this, _cachedMaterials)[_cachedMaterials].has(c) || originalMaterial !== cachedOriginalMaterial) {
mrtMaterial = new MRTMaterial();
if (_classPrivateFieldLooseBase(this, _USE_MRT)[_USE_MRT]) mrtMaterial.defines.USE_MRT = "";
mrtMaterial.uniforms.prevProjectionMatrix.value = _classPrivateFieldLooseBase(this, _prevProjectionMatrix)[_prevProjectionMatrix];
mrtMaterial.normalScale = originalMaterial.normalScale;
mrtMaterial.uniforms.normalScale.value = originalMaterial.normalScale;
const map = originalMaterial.map || originalMaterial.normalMap || originalMaterial.roughnessMap || originalMaterial.metalnessMap;
if (map) mrtMaterial.uniforms.uvTransform.value = map.matrix;
const normalDepthMaterial = _classPrivateFieldLooseBase(this, _normalDepthMaterials)[_normalDepthMaterials][origMat.uuid];
_classPrivateFieldLooseBase(this, _cachedMaterials)[_cachedMaterials].set(c, [originalMaterial, mrtMaterial]);
} // update the child's MRT material
if (_classPrivateFieldLooseBase(this, _USE_MRT)[_USE_MRT]) normalDepthMaterial.defines.USE_MRT = "";
normalDepthMaterial._originalUuid = c.material.uuid;
Object.defineProperty(normalDepthMaterial.uniforms.roughness, "value", {
get() {
return origMat.roughness || 0;
},
set(_) {}
_classPrivateFieldLooseBase(this, _keepMaterialMapUpdated)[_keepMaterialMapUpdated](mrtMaterial, originalMaterial, "normalMap", "USE_NORMALMAP");
});
normalDepthMaterial.normalScale = origMat.normalScale;
normalDepthMaterial.uniforms.normalScale.value = origMat.normalScale;
const map = origMat.map || origMat.normalMap || origMat.roughnessMap || origMat.metalnessMap;
if (map) normalDepthMaterial.uniforms.uvTransform.value = map.matrix;
}
_classPrivateFieldLooseBase(this, _keepMaterialMapUpdated)[_keepMaterialMapUpdated](mrtMaterial, originalMaterial, "roughnessMap", "USE_ROUGHNESSMAP");
const normalDepthMaterial = _classPrivateFieldLooseBase(this, _normalDepthMaterials)[_normalDepthMaterials][c.material.uuid];
const needsUpdatedReflections = c.material.userData.needsUpdatedReflections || c.material.map instanceof VideoTexture; // mark the material as "NEEDS_UPDATED_REFLECTIONS" so that, when using temporal resolve, we get updated reflections
_classPrivateFieldLooseBase(this, _keepMaterialUpdated)[_keepMaterialUpdated](normalDepthMaterial, origMat, "normalMap", "USE_NORMALMAP");
if (needsUpdatedReflections && !Object.keys(mrtMaterial.defines).includes("NEEDS_UPDATED_REFLECTIONS")) {
mrtMaterial.defines.NEEDS_UPDATED_REFLECTIONS = "";
mrtMaterial.needsUpdate = true;
} else if (!needsUpdatedReflections && Object.keys(mrtMaterial.defines).includes("NEEDS_UPDATED_REFLECTIONS")) {
delete mrtMaterial.defines.NEEDS_UPDATED_REFLECTIONS;
mrtMaterial.needsUpdate = true;
}
_classPrivateFieldLooseBase(this, _keepMaterialUpdated)[_keepMaterialUpdated](normalDepthMaterial, origMat, "roughnessMap", "USE_ROUGHNESSMAP");
if (c.skeleton) {
mrtMaterial.defines.USE_SKINNING = "";
mrtMaterial.defines.BONE_TEXTURE = "";
const needsUpatedReflections = c.material.userData.needsUpatedReflections || c.material.map instanceof VideoTexture; // mark the material as "ANIMATED" so that, when using temporal resolve, we get updated reflections
if (needsUpatedReflections && !Object.keys(normalDepthMaterial.defines).includes("NEEDS_UPDATED_REFLECTIONS")) {
normalDepthMaterial.defines.NEEDS_UPDATED_REFLECTIONS = "";
normalDepthMaterial.needsUpdate = true;
} else if (!needsUpatedReflections && Object.keys(normalDepthMaterial.defines).includes("NEEDS_UPDATED_REFLECTIONS")) {
delete normalDepthMaterial.defines.NEEDS_UPDATED_REFLECTIONS;
normalDepthMaterial.needsUpdate = true;
_classPrivateFieldLooseBase(this, _updateBoneTexture)[_updateBoneTexture](mrtMaterial, c.skeleton, "boneTexture", "boneMatrices");
}
c.material = normalDepthMaterial;
mrtMaterial.uniforms.roughness.value = _classPrivateFieldLooseBase(this, _ssrEffect)[_ssrEffect].selection.size === 0 || _classPrivateFieldLooseBase(this, _ssrEffect)[_ssrEffect].selection.has(c) ? originalMaterial.roughness || 0 : 10e10;
c.material = mrtMaterial;
}

@@ -844,19 +890,39 @@ });

function _unsetNormalDepthRoughnessMaterialInScene2() {
function _updateBoneTexture2(material, skeleton, uniformName, boneMatricesName) {
let boneMatrices = material[boneMatricesName];
if (material[boneMatricesName]?.length !== skeleton.boneMatrices.length) {
delete material[boneMatricesName];
boneMatrices = new Float32Array(skeleton.boneMatrices.length);
material[boneMatricesName] = boneMatrices;
}
material[boneMatricesName].set(skeleton.boneMatrices);
const size = Math.sqrt(skeleton.boneMatrices.length / 4);
const boneTexture = new DataTexture(boneMatrices, size, size, RGBAFormat, FloatType);
boneTexture.needsUpdate = true;
if (material.uniforms[uniformName].value) material.uniforms[uniformName].value.dispose();
material.uniforms[uniformName].value = boneTexture;
}
function _unsetMRTMaterialInScene2() {
this._scene.traverse(c => {
if (c.material?.type === "NormalDepthRoughnessMaterial") {
c.material.uniforms.prevProjectionMatrix.value.copy(this._camera.projectionMatrix);
if (c.material?.type === "MRTMaterial") {
c.material.uniforms.prevModelViewMatrix.value.copy(c.modelViewMatrix);
c.material.uniforms.prevModelViewMatrix.value.multiplyMatrices(this._camera.matrixWorldInverse, c.matrixWorld);
c.material = _classPrivateFieldLooseBase(this, _defaultMaterials)[_defaultMaterials][c.material._originalUuid];
if (c.skeleton) _classPrivateFieldLooseBase(this, _updateBoneTexture)[_updateBoneTexture](c.material, c.skeleton, "prevBoneTexture", "prevBoneMatrices"); // set material back to the original one
const [originalMaterial] = _classPrivateFieldLooseBase(this, _cachedMaterials)[_cachedMaterials].get(c);
c.material = originalMaterial;
}
});
_classPrivateFieldLooseBase(this, _prevProjectionMatrix)[_prevProjectionMatrix].copy(this._camera.projectionMatrix);
}
const finalFragmentShader = fragmentShader$1.replace("#include <helperFunctions>", helperFunctions).replace("#include <bilateralBlur>", bilateralBlur);
const zeroVec2 = new Vector2();
const defaultSSROptions = {
temporalResolve: true,
temporalResolveMix: 0.9,
temporalResolveCorrectionMix: 0.3875,
temporalResolveCorrectionMix: 1,
maxSamples: 0,

@@ -866,3 +932,3 @@ resolutionScale: 1,

height: typeof window !== "undefined" ? window.innerHeight : 1000,
ENABLE_BLUR: true,
ENABLE_BLUR: false,
blurMix: 0.5,

@@ -877,3 +943,3 @@ blurKernelSize: 8,

jitterSpread: 0.1,
jitterRough: 0.1,
jitterRough: 0,
roughnessFadeOut: 1,

@@ -903,3 +969,3 @@ rayFadeOut: 0,

constructor(scene, camera, _options = defaultSSROptions) {
super("SSRPass", finalFragmentShader, {
super("SSREffect", finalFragmentShader, {
type: "FinalSSRMaterial",

@@ -912,2 +978,4 @@ uniforms: new Map([["inputTexture", new Uniform(null)], ["reflectionsTexture", new Uniform(null)], ["depthTexture", new Uniform(null)], ["samples", new Uniform(0)], ["blurMix", new Uniform(0)], ["g_Sharpness", new Uniform(0)], ["g_InvResolutionDirection", new Uniform(new Vector2())], ["kernelRadius", new Uniform(0)]]),

});
this.samples = 0;
this.selection = new Selection();
Object.defineProperty(this, _lastSize, {

@@ -917,3 +985,2 @@ writable: true,

});
this.samples = 0;
Object.defineProperty(this, _lastCameraTransform, {

@@ -928,3 +995,13 @@ writable: true,

this._camera = camera;
_options = _extends({}, defaultSSROptions, _options);
_options = _extends({}, defaultSSROptions, _options); // set up passes
this.composeReflectionsPass = new ComposeReflectionsPass(this, _options);
this.reflectionsPass = new ReflectionsPass(this, _options);
const {
uniforms
} = this.composeReflectionsPass.fullscreenMaterial;
uniforms.inputTexture.value = this.reflectionsPass.renderTarget.texture;
uniforms.accumulatedReflectionsTexture.value = this.reflectionsPass.accumulatedReflectionsTexture;
uniforms.velocityTexture.value = this.reflectionsPass.velocityTexture;
this.uniforms.get("reflectionsTexture").value = this.composeReflectionsPass.renderTarget.texture;
_classPrivateFieldLooseBase(this, _lastSize)[_lastSize] = {

@@ -938,12 +1015,4 @@ width: _options.width,

_classPrivateFieldLooseBase(this, _lastCameraTransform)[_lastCameraTransform].quaternion.copy(camera.quaternion); // returns just the calculates reflections
_classPrivateFieldLooseBase(this, _lastCameraTransform)[_lastCameraTransform].quaternion.copy(camera.quaternion);
this.reflectionsPass = new ReflectionsPass(this, _options);
this.composeReflectionsPass = new ComposeReflectionsPass(this);
this.composeReflectionsPass.fullscreenMaterial.uniforms.inputTexture.value = this.reflectionsPass.renderTarget.texture;
this.composeReflectionsPass.fullscreenMaterial.uniforms.lastFrameReflectionsTexture.value = this.reflectionsPass.lastFrameReflectionsTexture;
this.composeReflectionsPass.fullscreenMaterial.uniforms.velocityTexture.value = this.reflectionsPass.velocityTexture;
this.uniforms.get("reflectionsTexture").value = this.composeReflectionsPass.renderTarget.texture;
this.uniforms.get("depthTexture").value = this.reflectionsPass.depthTexture;
this.setSize(_options.width, _options.height);

@@ -985,3 +1054,3 @@

update(renderer, inputTexture) {
update(renderer, inputBuffer) {
this.samples++;

@@ -992,7 +1061,5 @@ this.checkNeedsResample(); // update uniforms

this.reflectionsPass.render(renderer, inputTexture); // compose reflection of last and current frame into one reflection
this.reflectionsPass.render(renderer, inputBuffer); // compose reflection of last and current frame into one reflection
this.composeReflectionsPass.render(renderer);
renderer.setRenderTarget(this.composeReflectionsPass.renderTarget);
renderer.copyFramebufferToTexture(zeroVec2, this.reflectionsPass.lastFrameReflectionsTexture);
}

@@ -1005,2 +1072,3 @@

if (options.ENABLE_BLUR) {
this.uniforms.get("depthTexture").value = this.reflectionsPass.depthTexture;
this.defines.set("ENABLE_BLUR", "");

@@ -1091,4 +1159,2 @@ this.reflectionsPass.fullscreenMaterial.defines.ENABLE_BLUR = "";

case "USE_NORMALMAP":
break;
case "USE_ROUGHNESSMAP":

@@ -1095,0 +1161,0 @@ break;

@@ -68,3 +68,3 @@ {

},
"version": "2.0.4",
"version": "2.0.5",
"lint-staged": {

@@ -71,0 +71,0 @@ "*.{js,css,md}": "prettier --write"

@@ -68,3 +68,3 @@ # three.js Screen Space Reflections

temporalResolveMix: 0.9,
temporalResolveCorrectionMix: 0.3875,
temporalResolveCorrectionMix: 1,
maxSamples: 0,

@@ -74,3 +74,3 @@ resolutionScale: 1,

height: typeof window !== "undefined" ? window.innerHeight : 1000,
ENABLE_BLUR: true,
ENABLE_BLUR: false,
blurMix: 0.5,

@@ -85,3 +85,3 @@ blurKernelSize: 8,

jitterSpread: 0.1,
jitterRough: 0.1,
jitterRough: 0,
roughnessFadeOut: 1,

@@ -228,3 +228,3 @@ rayFadeOut: 0,

If your material is not using a `VideoTexture` but is still animated (e.g. it's a custom animated shader material), then you can get updated reflections for it by setting
`mesh.material.userData.needsUpatedReflections = true`. This will make the SSR effect recalculate its reflections each frame.
`mesh.material.userData.needsUpdatedReflections = true`. This will make the SSR effect recalculate its reflections each frame.

@@ -231,0 +231,0 @@ ### Server Side Rendering and `window` being undefined

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc