Skip to content

Commit cf216e1

Browse files
committed
Add setting: fillHole.
1 parent 0a32b95 commit cf216e1

File tree

3 files changed

+53
-11
lines changed

3 files changed

+53
-11
lines changed

examples/jsm/postprocessing/SSRrPass.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ var SSRrPass = function ( { renderer, scene, camera, width, height, selects, enc
6565
}
6666
} );
6767

68+
this._fillHole = SSRrShader.defines.FILL_HOLE;
69+
Object.defineProperty( this, 'fillHole', {
70+
get() {
71+
72+
return this._fillHole;
73+
74+
},
75+
set( val ) {
76+
77+
if ( this._fillHole === val ) return;
78+
this._fillHole = val;
79+
this.ssrrMaterial.defines.FILL_HOLE = val;
80+
this.ssrrMaterial.needsUpdate = true;
81+
82+
}
83+
} );
84+
6885
this._infiniteThick = SSRrShader.defines.INFINITE_THICK;
6986
Object.defineProperty( this, 'infiniteThick', {
7087
get() {

examples/jsm/shaders/SSRrShader.js

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ var SSRrShader = {
99
MAX_STEP: 0,
1010
PERSPECTIVE_CAMERA: true,
1111
SPECULAR: true,
12-
INFINITE_THICK: true,
12+
FILL_HOLE: true,
13+
INFINITE_THICK: false,
1314
},
1415

1516
uniforms: {
@@ -113,6 +114,18 @@ var SSRrShader = {
113114
xy*=resolution;//screen
114115
return xy;
115116
}
117+
void setResultColor(vec2 uv){
118+
vec4 refractColor=texture2D(tDiffuse,uv);
119+
#ifdef SPECULAR
120+
vec4 specularColor=texture2D(tSpecular,vUv);
121+
gl_FragColor.xyz=mix(refractColor.xyz,vec3(1),specularColor.r);
122+
// gl_FragColor.xyz=refractColor.xyz*(1.+specularColor.r*3.);
123+
#else
124+
gl_FragColor.xyz=refractColor.xyz;
125+
#endif
126+
gl_FragColor.a=1.;
127+
128+
}
116129
void main(){
117130
if(ior==1.) return; // Adding this line may have better performance, but more importantly, it can avoid display errors at the very edges of the model when IOR is equal to 1.
118131
@@ -160,6 +173,10 @@ var SSRrShader = {
160173
float totalStep=max(abs(xLen),abs(yLen));
161174
float xSpan=xLen/totalStep;
162175
float ySpan=yLen/totalStep;
176+
#ifdef FILL_HOLE
177+
bool isRough=false;
178+
vec2 uvRough;
179+
#endif
163180
for(float i=0.;i<float(MAX_STEP);i++){
164181
if(i>=totalStep) break;
165182
vec2 xy=vec2(d0.x+i*xSpan,d0.y+i*ySpan);
@@ -182,24 +199,31 @@ var SSRrShader = {
182199
float sD=surfDist;
183200
#endif
184201
202+
#ifdef FILL_HOLE // TODO: May can improve performance by check if INFINITE_THICK too.
203+
if(viewRefractRayZ<=vZ){
204+
if(!isRough){
205+
uvRough=uv;
206+
isRough=true;
207+
}
208+
}
209+
#endif
210+
185211
#ifdef INFINITE_THICK
186212
if(viewRefractRayZ<=vZ){
187213
#else
188214
if(viewRefractRayZ-sD>vZ) continue;
189215
float away=pointToLineDistance(vP,viewPosition,d1viewPosition);
190216
if(away<=sD){
191217
#endif
192-
vec4 refractColor=texture2D(tDiffuse,uv);
193-
#ifdef SPECULAR
194-
vec4 specularColor=texture2D(tSpecular,vUv);
195-
gl_FragColor.xyz=mix(refractColor.xyz,vec3(1),specularColor.r);
196-
// gl_FragColor.xyz=refractColor.xyz*(1.+specularColor.r*3.);
197-
#else
198-
gl_FragColor.xyz=refractColor.xyz;
199-
#endif
200-
gl_FragColor.a=1.;
218+
setResultColor(uv);
201219
return;
202220
}
221+
222+
#ifdef FILL_HOLE
223+
if(isRough){
224+
setResultColor(uvRough);
225+
}
226+
#endif
203227
}
204228
}
205229
`

examples/webgl_postprocessing_ssrr.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@
189189
gui.add(params, 'enableSSRr').name('Enable SSRr');
190190
ssrrPass.ior = 1.1;
191191
gui.add(ssrrPass, 'ior').name('IOR').min(1).max(1.5).step(.0001);
192-
gui.add( ssrrPass, 'infiniteThick' );
192+
gui.add( ssrrPass, 'fillHole' );
193193
gui.add(params, 'autoRotate').onChange(() => {
194194

195195
controls.enabled = !params.autoRotate;
@@ -218,6 +218,7 @@
218218
folder.add( ssrrPass, 'surfDist' ).min( 0 ).max( .005 ).step( .0001 );
219219
ssrrPass.maxDistance = 50;
220220
folder.add( ssrrPass, 'maxDistance' ).min( 0 ).max( 100 ).step( .001 )
221+
folder.add( ssrrPass, 'infiniteThick' );
221222
// folder.open()
222223
// gui.close()
223224

0 commit comments

Comments
 (0)