fix edl shining through meshes
This commit is contained in:
parent
a86b6e19ea
commit
65f6eb19ce
@ -19,15 +19,18 @@ export class EyeDomeLightingMaterial extends THREE.ShaderMaterial{
|
||||
screenWidth: { type: 'f', value: 0 },
|
||||
screenHeight: { type: 'f', value: 0 },
|
||||
edlStrength: { type: 'f', value: 1.0 },
|
||||
uNear: { type: 'f', value: 1.0 },
|
||||
uFar: { type: 'f', value: 1.0 },
|
||||
radius: { type: 'f', value: 1.0 },
|
||||
neighbours: { type: '2fv', value: [] },
|
||||
depthMap: { type: 't', value: null },
|
||||
//colorMap: { type: 't', value: null },
|
||||
uRegularColor: { type: 't', value: null },
|
||||
uRegularDepth: { type: 't', value: null },
|
||||
//uRegularColor: { type: 't', value: null },
|
||||
//uRegularDepth: { type: 't', value: null },
|
||||
uEDLColor: { type: 't', value: null },
|
||||
uEDLDepth: { type: 't', value: null },
|
||||
opacity: { type: 'f', value: 1.0 }
|
||||
opacity: { type: 'f', value: 1.0 },
|
||||
uProj: { type: "Matrix4fv", value: [] },
|
||||
};
|
||||
|
||||
this.setValues({
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
// https://github.com/cloudcompare/trunk/tree/master/plugins/qEDL/shaders/EDL
|
||||
//
|
||||
|
||||
#extension GL_EXT_frag_depth : enable
|
||||
|
||||
uniform float screenWidth;
|
||||
uniform float screenHeight;
|
||||
uniform vec2 neighbours[NEIGHBOUR_COUNT];
|
||||
@ -10,9 +12,11 @@ uniform float edlStrength;
|
||||
uniform float radius;
|
||||
uniform float opacity;
|
||||
|
||||
//uniform sampler2D colorMap;
|
||||
uniform sampler2D uRegularColor;
|
||||
uniform sampler2D uRegularDepth;
|
||||
uniform float uNear;
|
||||
uniform float uFar;
|
||||
|
||||
uniform mat4 uProj;
|
||||
|
||||
uniform sampler2D uEDLColor;
|
||||
uniform sampler2D uEDLDepth;
|
||||
|
||||
@ -42,7 +46,6 @@ float response(float depth){
|
||||
}
|
||||
|
||||
void main(){
|
||||
vec4 cReg = texture2D(uRegularColor, vUv);
|
||||
vec4 cEDL = texture2D(uEDLColor, vUv);
|
||||
|
||||
float depth = cEDL.a;
|
||||
@ -50,13 +53,20 @@ void main(){
|
||||
float res = response(depth);
|
||||
float shade = exp(-res * 300.0 * edlStrength);
|
||||
|
||||
float dReg = texture2D(uRegularDepth, vUv).r;
|
||||
float dEDL = texture2D(uEDLDepth, vUv).r;
|
||||
gl_FragColor = vec4(cEDL.rgb * shade, opacity);
|
||||
|
||||
if(dEDL < dReg){
|
||||
gl_FragColor = vec4(cEDL.rgb * shade, opacity);
|
||||
}else{
|
||||
gl_FragColor = vec4(cReg.rgb * shade, cReg.a);
|
||||
{ // write regular hyperbolic depth values to depth buffer
|
||||
float dl = pow(2.0, depth);
|
||||
|
||||
vec4 dp = uProj * vec4(0.0, 0.0, -dl, 1.0);
|
||||
float pz = dp.z / dp.w;
|
||||
float fragDepth = (pz + 1.0) / 2.0;
|
||||
|
||||
gl_FragDepthEXT = fragDepth;
|
||||
}
|
||||
|
||||
if(depth == 0.0){
|
||||
discard;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -201,7 +201,7 @@ export class EDLRenderer{
|
||||
|
||||
}
|
||||
|
||||
viewer.renderer.render(viewer.scene.scene, camera);
|
||||
//viewer.renderer.render(viewer.scene.scene, camera);
|
||||
|
||||
//viewer.renderer.clearTarget( this.rtColor, true, true, true );
|
||||
viewer.renderer.clearTarget(this.rtEDL, true, true, true);
|
||||
@ -240,10 +240,11 @@ export class EDLRenderer{
|
||||
});
|
||||
}
|
||||
|
||||
viewer.renderer.render(viewer.scene.scene, camera, this.rtRegular);
|
||||
//viewer.renderer.render(viewer.scene.scene, camera, this.rtRegular);
|
||||
viewer.renderer.render(viewer.scene.scene, camera);
|
||||
|
||||
//viewer.renderer.setRenderTarget(this.rtColor);
|
||||
viewer.dispatchEvent({type: "render.pass.scene", viewer: viewer, renderTarget: this.rtRegular});
|
||||
//viewer.dispatchEvent({type: "render.pass.scene", viewer: viewer, renderTarget: this.rtRegular});
|
||||
|
||||
{ // EDL OCCLUSION PASS
|
||||
this.edlMaterial.uniforms.screenWidth.value = width;
|
||||
@ -251,10 +252,17 @@ export class EDLRenderer{
|
||||
|
||||
//this.edlMaterial.uniforms.colorMap.value = this.rtColor.texture;
|
||||
|
||||
this.edlMaterial.uniforms.uRegularColor.value = this.rtRegular.texture;
|
||||
let proj = camera.projectionMatrix;
|
||||
let projArray = new Float32Array(16);
|
||||
projArray.set(proj.elements);
|
||||
|
||||
this.edlMaterial.uniforms.uNear.value = camera.near;
|
||||
this.edlMaterial.uniforms.uFar.value = camera.far;
|
||||
//this.edlMaterial.uniforms.uRegularColor.value = this.rtRegular.texture;
|
||||
this.edlMaterial.uniforms.uEDLColor.value = this.rtEDL.texture;
|
||||
this.edlMaterial.uniforms.uRegularDepth.value = this.rtRegular.depthTexture;
|
||||
//this.edlMaterial.uniforms.uRegularDepth.value = this.rtRegular.depthTexture;
|
||||
this.edlMaterial.uniforms.uEDLDepth.value = this.rtEDL.depthTexture;
|
||||
this.edlMaterial.uniforms.uProj.value = projArray;
|
||||
|
||||
this.edlMaterial.uniforms.edlStrength.value = viewer.edlStrength;
|
||||
this.edlMaterial.uniforms.radius.value = viewer.edlRadius;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user