渲染边缘助手和半透明的物体错误(Render error with edges helper and

2019-11-04 03:29发布

我想有三个JS像创建一个地球这个例子是从升级这一项 。 我的问题是,即使是在想我添加到现场第一的代码, 地球后,并在年底呈现接缝的气氛不明白这个顺序跟这个有respondes

现在,当我放大并获得地球近点物体渲染工作正确的给这个性反应。

正如你所看到的问题也与THREE.EdgesHelper时长缩放级别它在某些地方甚至认为它是地球后面被渲染,但在短期缩放级别它可以完美运行。 任何想法如何克服呢? 这是所有创建领域的代码:

function earthView(){
if (!scene){
    main();//here i create the controls,camera,scene,renderer etc
}

// create the geometry sphere stars
var geometry  = new THREE.SphereGeometry(6371000000, 36, 36)
// create the material, using a texture of startfield
var material  = new THREE.MeshBasicMaterial()
material.map   = THREE.ImageUtils.loadTexture('images/earthView/ESO_-_Milky_Way.jpg')
material.side  = THREE.BackSide
// create the mesh based on geometry and material
var mesh  = new THREE.Mesh(geometry, material)
mesh.position.set(0,0,-6371000)

scene.add(mesh)


//earth
var geometry   = new THREE.SphereGeometry(6371000, 36, 36)
var material  = new THREE.MeshPhongMaterial()
var earthMesh = new THREE.Mesh(geometry, material)
//earthMesh.position.set(0,-6371000,0)
//earthMesh.rotation.set(0,-Math.PI/2,0)
helper = new THREE.EdgesHelper( earthMesh );
helper.material.color.set( 0xffffff );


material.map    = THREE.ImageUtils.loadTexture('images/earthView/earthmap1k.jpg')
material.bumpMap    = THREE.ImageUtils.loadTexture('images/earthView/earthbump1k.jpg')
material.bumpScale = 100


material.specularMap = THREE.ImageUtils.loadTexture('images/earthView/earthspec1k.jpg')

scene.add(earthMesh);
scene.add( helper );


//atmosphere
var geometry   = new THREE.SphereGeometry(7365000, 36, 36)
var material  = new createAtmosphereMaterial()
material.uniforms.glowColor.value.set(0x00b3ff)
material.uniforms.coeficient.value  = 0.1
material.uniforms.power.value       = 2.0
//material.side = THREE.BackSide
var earthAtmo = new THREE.Mesh(geometry, material)
//earthAtmo.position.set(0,0,-6371000)

scene.add(earthAtmo);


/**
 * from http://stemkoski.blogspot.fr/2013/07/shaders-in-threejs-glow-and-    halo.html
 * @return {[type]} [description]
  */ 

function createAtmosphereMaterial(){
  var vertexShader  = [
    'varying vec3 vNormal;',
    'void main(){',
    '   // compute intensity',
    '   vNormal     = normalize( normalMatrix * normal );',
    '   // set gl_Position',
    '   gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );',
    '}',
].join('\n')
var fragmentShader  = [
    'uniform float coeficient;',
    'uniform float power;',
    'uniform vec3  glowColor;',

    'varying vec3  vNormal;',

    'void main(){',
    '   float intensity = pow( coeficient - dot(vNormal, vec3(0.0, 0.0, 1.0)), power );',
    '   gl_FragColor    = vec4( glowColor * intensity, 1.0 );',
    '}',
].join('\n')

// create custom material from the shader code above
//   that is within specially labeled script tags
var material    = new THREE.ShaderMaterial({
    uniforms: { 
        coeficient  : {
            type    : "f", 
            value   : 1.0
        },
        power       : {
            type    : "f",
            value   : 2
        },
        glowColor   : {
            type    : "c",
            value   : new THREE.Color('blue')
        },
    },
    vertexShader    : vertexShader,
    fragmentShader  : fragmentShader,
    side        : THREE.FrontSide,
    blending    : THREE.AdditiveBlending,
    transparent : true,
    depthWrite  : false,
});
return material
}

}

我用renderer.sortObjects = false ,当我定义渲染这样的对象得到由他们在场景中添加的顺序呈现。

小结:获得帮助并呈现如PIC 2在所有缩放级别的气氛。

更新提示 :1.might这是显卡的问题2.might长途。我正在使用的像素是问题?

Answer 1:

这个问题已经回答了,在这篇文章 。所以设置logarithmicDepthBuffer: true做的工作!



文章来源: Render error with edges helper and semi transparent object