Reputation: 759
I have an outlined object.
Behind it I want to draw a transparent object. My problem is that the outline blends with the transparent object.
How can I draw the outline so it doesn't get blended?
# PLANE
geo1 = new THREE.PlaneGeometry 500, 500
mat1 = new THREE.MeshPhongMaterial({color: 0x00ff00, transparent: true, opacity: 0.5})
plane = new THREE.Mesh geo1, mat1
plane.position.z = -100
scene.add plane
# SHADED MODEL
torusKnotGeo = new THREE.TorusKnotGeometry 50, 10, 128, 16
phongMat2 = new THREE.MeshPhongMaterial 0xffffff
torusKnot = new THREE.Mesh torusKnotGeo, phongMat2
scene.add torusKnot
# OUTLINE
uniforms = offset:
type: "f"
value: 2
shader = shader['outline']
shaderMat = new THREE.ShaderMaterial
uniforms: uniforms,
vertexShader: shader.vertex_shader,
fragmentShader: shader.fragment_shader,
torusKnotOutline = new THREE.Mesh torusKnotGeo, shaderMat
torusKnotOutline.material.depthWrite = false
outScene.add torusKnotOutline
jsfiddle (based on https://stackoverflow.com/a/23198184/2785396)
Upvotes: 0
Views: 1643
Reputation: 4343
I cannot comment (not enough rep), so I will post an answer.
You took the example from the original JS fiddle: http://jsfiddle.net/Eskel/g593q/5/ and removed the composer. The composer ads a few extra operations in the rendering process.
composer.addPass normal
composer.addPass mask
composer.addPass outline
composer.addPass clearMask
composer.addPass copyPass
My advice is to fork the original example and keep the composer intact. In case you don't get it to work, remember to include the following scripts from the original example. If any of these go missing in action you have a broken composer, which means your page won't render.
Upvotes: 2