Browse Source

Starting to prepare stuff for adding Fog. Having Fog.js inside /scenes doesn't sound right, but I guess it can be there for now...
The idea would be to do `scene.fog = new THREE.Fog( color, near, far );` This way seems consistent with the rest of the API. By default `scene.fog` is `null`.

Mr.doob 14 years ago
parent
commit
17c1349d55
3 changed files with 14 additions and 5 deletions
  1. 2 5
      src/renderers/WebGLRenderer2.js
  2. 11 0
      src/scenes/Fog.js
  3. 1 0
      src/scenes/Scene.js

+ 2 - 5
src/renderers/WebGLRenderer2.js

@@ -481,8 +481,7 @@ THREE.WebGLRenderer2 = function () {
 
 
 				}
 				}
 
 
-				identifiers.push( 'mColor' );
-				identifiers.push( 'mOpacity' );
+				identifiers.push( 'mColor', 'mOpacity' );
 
 
 				vs += '}';
 				vs += '}';
 				fs += '}';
 				fs += '}';
@@ -513,10 +512,10 @@ THREE.WebGLRenderer2 = function () {
 
 
 				vs += 'gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n';
 				vs += 'gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n';
 
 
+				pfs += 'uniform float mOpacity;\n';
 				pfs += 'uniform float m2Near;\n';
 				pfs += 'uniform float m2Near;\n';
 				pfs += 'uniform float mFarPlusNear;\n';
 				pfs += 'uniform float mFarPlusNear;\n';
 				pfs += 'uniform float mFarMinusNear;\n';
 				pfs += 'uniform float mFarMinusNear;\n';
-				pfs += 'uniform float mOpacity;\n';
 				fs += 'float w = 1.0 - ( m2Near / ( mFarPlusNear - gl_FragCoord.z * mFarMinusNear ) );\n';
 				fs += 'float w = 1.0 - ( m2Near / ( mFarPlusNear - gl_FragCoord.z * mFarMinusNear ) );\n';
 				fs += 'gl_FragColor = vec4( w, w, w, mOpacity );\n';
 				fs += 'gl_FragColor = vec4( w, w, w, mOpacity );\n';
 
 
@@ -525,8 +524,6 @@ THREE.WebGLRenderer2 = function () {
 				vs += '}';
 				vs += '}';
 				fs += '}';
 				fs += '}';
 
 
-
-
 			} else if ( material instanceof THREE.MeshShaderMaterial ) {
 			} else if ( material instanceof THREE.MeshShaderMaterial ) {
 
 
 				vs = material.vertex_shader;
 				vs = material.vertex_shader;

+ 11 - 0
src/scenes/Fog.js

@@ -0,0 +1,11 @@
+/**
+ * @author mr.doob / http://mrdoob.com/
+ */
+
+THREE.Fog = function ( color, near, far ) {
+
+	this.color = color || new THREE.Color( 0xffffff );
+	this.near = near || 1;
+	this.far = far || 2000;
+
+};

+ 1 - 0
src/scenes/Scene.js

@@ -6,6 +6,7 @@ THREE.Scene = function () {
 
 
 	this.objects = [];
 	this.objects = [];
 	this.lights = [];
 	this.lights = [];
+	this.fog = null;
 
 
 	this.addObject = function ( object ) {
 	this.addObject = function ( object ) {