Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flickering planes

Tags:

three.js

webgl

I have an application with large 2D planes with textures, but I am experience some flickering problems.

It is possible to see the flickering problem here (planes are withouth textures): EXAMPLE CODE

Is this depth buffer (z-buffer) precision issues or something else?

Is the solution to scale down everything, not to allow large planes/objects? What is the best practice?

I know that z near and far also influence the precision, so setting z near to 1000 fixes the flickering in this example.

The code:

/*
 * Scale = 1, no flickering. Scale = 1000, flickering. 
 */
  var scale = 1000;

  var scene = new THREE.Scene();

  var camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1000, 1000000);
  camera.position.x = 0;
  camera.position.y = 0;
  camera.position.z = 100 * scale;
  var renderer = new THREE.WebGLRenderer({
      antialias: false
  });
  renderer.setSize(window.innerWidth, window.innerHeight);
  document.body.appendChild(renderer.domElement);

  var light = new THREE.AmbientLight(0xFFFFFF);
  scene.add(light);

  var material = new THREE.MeshBasicMaterial({
      transparent: false,
      side: THREE.DoubleSide,
      fog: false,
      color: 0xFFFF00,
      opacity: 1.0
  });

  var cubeGeometry = new THREE.PlaneGeometry(50 * scale, 50 * scale, 1, 1);
  var cubeMesh = new THREE.Mesh(cubeGeometry, material);
  cubeMesh.position.set(0, 0, 1 * scale);
  scene.add(cubeMesh);

  var material = new THREE.MeshBasicMaterial({
      transparent: false,
      side: THREE.DoubleSide,
      fog: false,
      color: 0xFF0000,
      opacity: 1.0
  });

  var cubeGeometry = new THREE.PlaneGeometry(100 * scale, 100 * scale, 1, 1);
  var cubeMesh = new THREE.Mesh(cubeGeometry, material);
  scene.add(cubeMesh);

  function render() {
      var time = Date.now() * 0.5;
      camera.position.x = Math.sin(time / 1000) * 150 * scale;
      camera.position.y = 0;
      camera.position.z = Math.cos(time / 1000) * 150 * scale;
      camera.lookAt(scene.position);
      renderer.render(scene, camera);  
      requestAnimationFrame(render);
  }
  render();
like image 830
eoaksnes Avatar asked Jul 22 '13 11:07

eoaksnes


People also ask

What does it mean when a plane is flashing?

Strobe lights. These are the flashing white lights you see if you look at aircraft in the night sky. These are for collision avoidance, simply to make the aircraft more visible. They are usually activated for the whole flight, but often not until reaching the active runway.

Why do lights flicker on planes?

There's a very legitimate and frightening reason for planes to dim their lights at takeoff and landing. The idea behind the dimming lights is to give passengers time to adjust their eyes to the lighting outside.

What is it called when planes shake?

Turbulence is a sudden change in airflow and can be caused by several factors. The most common cause of turbulence is due to turbulent air in Earth's atmosphere. The jet streams around Earth can cause sudden changes in the wind speed that can rock airplanes.

What is a death spiral in flying?

In aviation, a graveyard spiral is a type of dangerous spiral dive entered into accidentally by a pilot who is not trained or not proficient in flying in instrument meteorological conditions (IMC). Other names for this phenomenon include suicide spiral, deadly spiral, death spiral and vicious spiral.


2 Answers

What you're seeing is the GPU running out of precision because the ranges you're using are too big. By setting the near plane of the camera to 100 (instead of 1) the flickering is gone.

http://jsfiddle.net/GYQ5v/74/

like image 164
mrdoob Avatar answered Oct 26 '22 14:10

mrdoob


Try out this code to see if it works:

cubeMesh.position.set(0, 0, 1);
like image 34
Bhawani Singh Bhati Avatar answered Oct 26 '22 14:10

Bhawani Singh Bhati