You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
currently I try to migrate this post process to work with pmdrs/postprocessing. Unfortunately I failed.
I would really appreciate if someone could help me with this.
import{Color,HalfFloatType,NearestFilter,RGBAFormat,Uniform,Vector2,Vector4,WebGLRenderTarget}from"three"import{Effect}from'postprocessing'import{getSurfaceIdMaterial}from"./FindSurfaces"exportdefaultclassOutlineEffectextendsEffect{constructor(resolution,scene,camera){super('OutlineEffect',fragmentShader,{uniforms: newMap([["surfaceBuffer",newUniform(null)],['outlineColor',newUniform(newColor(1,0,0))],['multiplierParameters',newUniform(newVector2(.9,20))],['screenSize',newUniform(newVector4(resolution.x,resolution.y,1/resolution.x,1/resolution.y))]])})this.resolution=newVector2(resolution.x,resolution.y)this.scene=scenethis.camera=camerathis.surfaceBuffer=newWebGLRenderTarget(this.resolution.x,this.resolution.y)this.surfaceBuffer.texture.format=RGBAFormatthis.surfaceBuffer.texture.type=HalfFloatTypethis.surfaceBuffer.texture.minFilter=NearestFilterthis.surfaceBuffer.texture.magFilter=NearestFilterthis.surfaceBuffer.texture.generateMipmaps=falsethis.surfaceBuffer.stencilBuffer=falsethis.uniforms.get("surfaceBuffer").value=this.surfaceBuffer.texturethis.surfaceIdOverrideMaterial=getSurfaceIdMaterial()}update(renderer,inputBuffer,deltaTime){// Turn off writing to the depth buffer because we need to read from it in the subsequent passes.constdepthBufferValue=writeBuffer.depthBufferwriteBuffer.depthBuffer=false// 1. Re-render the scene to capture all suface IDs in a texture.renderer.setRenderTarget(this.surfaceBuffer)constoverrideMaterialValue=this.scene.overrideMaterialthis.scene.overrideMaterial=this.surfaceIdOverrideMaterialrenderer.render(this.scene,this.camera)this.scene.overrideMaterial=overrideMaterialValue// 2. Draw the outlines using the depth texture and normal texture and combine it with the scene colorif(this.renderToScreen){// If this is the last effect, then renderToScreen is true.// So we should render to the screen by setting target null// Otherwise, just render into the writeBuffer that the next effect will use as its read buffer.renderer.setRenderTarget(null)this.fsQuad.render(renderer)}else{renderer.setRenderTarget(writeBuffer)this.fsQuad.render(renderer)}// Reset the depthBuffer value so we continue writing to it in the next render.writeBuffer.depthBuffer=depthBufferValue}updateMaxSurfaceId(maxSurfaceId){this.surfaceIdOverrideMaterial.uniforms.maxSurfaceId.value=maxSurfaceId}setSize(width,height){this.resolution.set(width,height)this.surfaceBuffer.setSize(width,height)this.uniforms.get('screenSize').value.set(this.resolution.x,this.resolution.y,1/this.resolution.x,1/this.resolution.y)}}constfragmentShader= `
uniformsampler2DsurfaceBuffer;uniformvec4screenSize;uniformvec3outlineColor;uniformvec2multiplierParameters;floatreadDepth(sampler2DdepthSampler,vec2coord){floatfragCoordZ=texture2D(depthSampler,coord).x;floatviewZ=perspectiveDepthToViewZ(fragCoordZ,cameraNear,cameraFar);returnviewZToOrthographicDepth(viewZ,cameraNear,cameraFar);}floatgetLinearDepth(vec3pos){return-(viewMatrix*vec4(pos,1.0)).z;}floatgetLinearScreenDepth(sampler2Dmap){vec2vUv=gl_FragCoord.xy*screenSize.zw;returnreadDepth(map,vUv);}floatgetPixelDepth(intx,inty,vec2uv){returnreadDepth(depthBuffer,uv+screenSize.zw*vec2(x,y));}vec3getSurfaceValue(intx,inty,vec2uv){vec3val=texture2D(surfaceBuffer,uv+screenSize.zw*vec2(x,y)).rgb;returnval;}floatsaturateValue(floatnum){returnclamp(num,0.0,1.0);}floatgetSufaceIdDiff(vec3surfaceValue,vec2uv){floatsurfaceIdDiff=0.0;surfaceIdDiff+=distance(surfaceValue,getSurfaceValue(1,0,uv));surfaceIdDiff+=distance(surfaceValue,getSurfaceValue(0,1,uv));surfaceIdDiff+=distance(surfaceValue,getSurfaceValue(0,1,uv));surfaceIdDiff+=distance(surfaceValue,getSurfaceValue(0,-1,uv));surfaceIdDiff+=distance(surfaceValue,getSurfaceValue(1,1,uv));surfaceIdDiff+=distance(surfaceValue,getSurfaceValue(1,-1,uv));surfaceIdDiff+=distance(surfaceValue,getSurfaceValue(-1,1,uv));surfaceIdDiff+=distance(surfaceValue,getSurfaceValue(-1,-1,uv));returnsurfaceIdDiff;}voidmainImage(constinvec4inputColor,constinvec2uv,outvec4outputColor){floatdepth=getPixelDepth(0,0,uv);vec3surfaceValue=getSurfaceValue(0,0,uv);// Get the difference between depth of neighboring pixels and currentfloatdepthDiff=0.0;depthDiff+=abs(depth-getPixelDepth(1,0,uv));depthDiff+=abs(depth-getPixelDepth(-1,0,uv));depthDiff+=abs(depth-getPixelDepth(0,1,uv));depthDiff+=abs(depth-getPixelDepth(0,-1,uv));// Get the difference between surface values of neighboring pixels and currentfloatsurfaceValueDiff=getSufaceIdDiff(surfaceValue,uv);// Apply multiplier & bias to eachfloatdepthBias=multiplierParameters.x;floatdepthMultiplier=multiplierParameters.y;depthDiff=depthDiff*depthMultiplier;depthDiff=saturateValue(depthDiff);depthDiff=pow(depthDiff,depthBias);if(surfaceValueDiff!=0.0)surfaceValueDiff=1.0;floatoutline=saturateValue(surfaceValueDiff+depthDiff);// Combine outline with scene colorvec4outlineColor=vec4(outlineColor,1.0);outputColor=vec4(mix(inputColor,outlineColor,outline));}
`
The text was updated successfully, but these errors were encountered:
Hi,
currently I try to migrate this post process to work with pmdrs/postprocessing. Unfortunately I failed.
I would really appreciate if someone could help me with this.
`
The text was updated successfully, but these errors were encountered: