Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

artifacts when rendering both sides of a transparent object with three.js

I try to render both sides of a transparent object with three.js. Other objects located within the transparent object should show too. Sadly I get artifacts I don't know too handle. Here is a test page: https://dl.dropbox.com/u/3778149/webgl_translucency/test.html

Here is an image of the said artifact. They seem to stem from the underlying sphere geometry. artifacts with blending mode: THREE.AdditiveBlending = 1

Interestingly the artifacts are not visible for blending mode THREE.SubtractiveBlending = 2. enter image description here

Any help appreciated!

Alex

like image 565
arose Avatar asked Nov 04 '12 18:11

arose


2 Answers

Self-transparency is particularly difficult in WebGL and three.js. You just have to really understand the issues, and then adapt your code to achieve the effect you want.

You can achieve the look of a double-sided, transparent sphere in three.js, with a trick: You need to render two transparent spheres -- one with material.side = THREE.BackSide, and one with material.side = THREE.FrontSide.

Using such methods is generally required if you want self-transparency without artifacts -- especially if you allow the camera or object to move.

three.js r.143

like image 51
WestLangley Avatar answered Oct 20 '22 23:10

WestLangley


Generally to do transparent objects you need to sort them front to back (I'm guessing three.js already does this). If your object is convex (like both of those are) then you can sometimes get by by rendering each object twice, once with gl.cullFace(gl.CCW) and again with gl.cullFace(gl.CW). So for example if the cube is inside the sphere you'd effectively do

gl.enable(gl.CULL_FACE);
gl.cullFace(gl.CW);
drawSphere();  // draws the back of the sphere
drawCube();    // draws the back of the cube
gl.cullFace(gl.CCW);
drawCube();    // draws the front of the cube.
drawSphere();  // draws the front of the sphere.

I have no idea how to do that in three.js

This only handles objects that are convex and not intersecting (one object is contained entirely inside the other).

like image 33
gman Avatar answered Oct 20 '22 23:10

gman