Issue encountered with edges helper and a partly opaque object rendering

My goal is to create a realistic earth using three.js, similar to this example, which is an improvement from this one. However, I am facing an issue where the rendering order of the sky, earth, and atmosphere is not being properly interpreted by the render engine, resulting in unexpected outcomes.

Interestingly, upon zooming in and closely inspecting the earth object, the rendering behaves as expected, yielding the desired output.

One specific problem arises with the THREE.EdgesHelper where, at longer zoom levels, parts of the helper are rendered even when they should be behind the earth. This issue does not occur at shorter zoom levels. I am seeking suggestions on how to address this inconsistency. Below is the code snippet responsible for creating the spheres:

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
}

}

To address the rendering issue, I have utilized renderer.sortObjects = false in defining the renderer to ensure objects are rendered based on their order in the scene.

In summary, the objective is to achieve consistent rendering for the helper and atmosphere as depicted in the second image across all zoom levels.

Update Hint: 1. Could the problem be related to the graphics card? 2. Is the extended distance in pixels causing this issue?

Answer №1

Wondering how to handle rendering large distant objects in Three.js while still maintaining correct z indices? Look no further, the solution can be found in this helpful post. By simply setting the logarithmicDepthBuffer: true, you'll see the magic happen!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I am facing an issue with Recharts not occupying the full width in my Nextjs/Reactjs project. Despite setting it to 100% width, it does not behave as

I am currently working with Recharts in combination with Next.js and Tailwindcss. I decided to create my own barchart by copying a code snippet from Recharts, but encountered an issue where changing the height to aspect worked fine, however setting the wid ...

A single button that performs multiple actions with just one click

Summary: Seeking assistance in implementing a button that triggers three different actions upon being clicked thrice. Detailed description: On one page of my website, there is an introduction with text and images. I currently have a button that switches t ...

Learn how to properly configure the React useState hook within the useEffect function and in combination with the

I am currently encountering an issue with my code. At the initial page load, the program checks for an available agent and sets the setDefault state variable to true if an agent is available. Then, if a language change event occurs and there is an availabl ...

Guidelines for populating data with an array

I have the following array: const dataArr = [[15, 14, 5], [16, 10, 2], [17, 6, 13], [18, 4, 8], [19, 7, 4]]; Now, I am populating another array using the above data as shown below: for (let i=0; i<dataArr.length; i++){ newData.push(dataArr[i]); ...

Developing an interactive input field using JavaScript's Document Object Model (DOM)

I am struggling with creating an editable text field using JavaScript. I have come across a function that allows for editing, but I am unsure if it is possible to change the title from High School to Middle School, which is generated by the function create ...

The link in Next.js is updating the URL but the page is not refreshing

I am facing a peculiar issue where a dynamic link within a component functions correctly in most areas of the site, but fails to work inside a specific React Component - Algolia InstantSearch (which is very similar in functionality to this example componen ...

An internal server error has occurred within the asp.net framework, resulting in

Seeking Solution: Currently, I am in the process of developing an application where I have implemented an HTML select list to choose a category. Using AJAX web method, I am trying to retrieve items and their respective images based on the selected category ...

JavaScript: Add an element to the precise middle of an array

Sorry if this is a repeat question, but I couldn't find the answer despite searching. Let's say there's an array of unknown length and you want to insert items at a specific position, such as the center. How can you achieve this? Here&apos ...

Is the script failing to retrieve the innerHTML content?

Here is a snippet of HTML code: <div id="team_players"> <h3>Players</h3> <button class="bold-btn" onclick="teamAct('player_list');">Refresh List ↻</button> <table> <thead> <tr> ...

Browsersync in Gulp keeps triggering numerous reloads every time a file is changed

As I utilize browsersync with Gulp for running specific tasks upon file changes, I notice that each time I save a file, my terminal displays 10+ [BS] Reloading Browsers... messages and the overall performance suffers. Below is an outline of my gulpfile: ...

What issues are hindering the successful export of my Vue component packaged with npm?

I created a small local npm package called fomantic-ui-vue with the following main js file: import Vue from 'vue' // Import vue component import button from './elements/button/button.vue' import buttonGroup from './elements/butt ...

What is the most effective way to access content from a webpage that is rendered

Is there a reliable way to download from links on a JavaScript rendered webpage using Python as the preferred language? I have attempted to use the Selenium Python bindings on a headless server, but it has proven to be slow, error-prone, and unable to acc ...

Is it possible to access the chrome://webrtc-internals/ variables through an API in JavaScript?

I couldn't find any information about how to access the logged variables in chrome://webrtc-internals/ on google. There is not even a description of the graphs available there. I am specifically interested in packetsLost, googCurrentDelayMs, and goo ...

Optimizing workflow with express.js, backbone.js, and connect-assets for maximum efficiency

As a newcomer to node.js, I'm embarking on the challenge of setting up an application that utilizes Backbone.js on the client-side while being supported by express.js and node.js for server-side extensibility. The lack of online examples showcasing a ...

Is it recommended to start off by creating a new Discord collection for the client's commands when setting up an advanced commands handler with discord.js?

Currently, I am delving into the realm of advanced command handling by moving beyond basic commands. As I follow various YouTube tutorials and guides to aid me in this endeavor, I have encountered a roadblock. An error stating that "Discord.Collections is ...

Create a dynamic table using an array in jQuery

Currently, my goal is to generate a table using an array with the following format: [ { header: 'ID', values: [1, 2] }, { header: 'First Name', values: ['John', 'Jayne'] }, { header: &ap ...

I am looking to implement an animation that automatically scrolls to the bottom of a scrollable DIV when the page is loaded

My DIV is configured with overflow-y set to scroll. .scrolling-div { width: 85%; height: 200px; overflow-y: scroll; } If I have an abundance of content within this div, my goal is for it to automatically scroll to the bottom upon loading the page. I am ...

Receive information from the server and display it on the front-end

Hello! I'm currently in the process of developing a video uploader for my website. So far, I've successfully been able to upload videos from the front-end (built with React.js) to the back-end public folder (using Node.js) through the POST method ...

Encountering a problem with the getJSON() function within the app.js file connected to a solidity

Currently, I am working on developing a simple dapp in Truffle. However, I encountered an error when using $.getJSON() function in my app.js file. Below is a snippet of my app.js: App ={ web3Provider: null, contracts: {}, init: function (){ return A ...

Tips to avoid the page from scrolling to the top when the menu is opened

Whenever a user taps the menu button on the page, a full-page menu opens. However, there is an issue - the main content page automatically scrolls to the top. Can you provide suggestions on how to prevent this from happening? I have already looked into a s ...