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

前端 未结 4 1145
梦谈多话
梦谈多话 2020-11-27 19:27

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 to

4条回答
  •  孤独总比滥情好
    2020-11-27 20:20

    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).

提交回复
热议问题