提交 1aabcb37 编写于 作者: M Mr.doob

Examples clean up.

上级 b61ead78
......@@ -358,6 +358,7 @@
"webgl_shadowmap",
"webgl_shadowmap_performance",
"webgl_shadowmap_viewer",
"webgl_shadowmesh",
"webgl_sprites",
"webgl_terrain_dynamic",
"webgl_test_memory",
......
/**
* @author zz85 / https://github.com/zz85
*
* Based on "A Practical Analytic Model for Daylight"
*
* Based on "A Practical Analytic Model for Daylight"
* aka The Preetham Model, the de facto standard analytic skydome model
* http://www.cs.utah.edu/~shirley/papers/sunsky/sunsky.pdf
*
*
* First implemented by Simon Wallner
* http://www.simonwallner.at/projects/atmospheric-scattering
*
*
* Improved by Martin Upitis
* http://blenderartists.org/forum/showthread.php?245954-preethams-sky-impementation-HDR
*
*
* Three.js integration by zz85 http://twitter.com/blurspline
*/
......@@ -30,13 +30,11 @@ THREE.ShaderLib['sky'] = {
vertexShader: [
"varying vec3 vWorldPosition;",
"varying vec2 vUv;",
"void main() {",
"vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
"vWorldPosition = worldPosition.xyz;",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
......@@ -46,12 +44,9 @@ THREE.ShaderLib['sky'] = {
fragmentShader: [
"uniform sampler2D skySampler;",
"uniform vec3 sunPosition;",
"varying vec3 vWorldPosition;",
"varying vec2 vUv;",
"vec3 cameraPos = vec3(0., 0., 0.);",
"// uniform sampler2D sDiffuse;",
......@@ -67,7 +62,6 @@ THREE.ShaderLib['sky'] = {
"uniform float mieCoefficient;",
"uniform float mieDirectionalG;",
"vec3 sunDirection = normalize(sunPosition);",
"float reileighCoefficient = reileigh;",
......@@ -165,9 +159,9 @@ THREE.ShaderLib['sky'] = {
"// luminance = 1.0 ;// vWorldPosition.y / 450000. + 0.5; //sunPosition.y / 450000. * 1. + 0.5;",
"// gl_FragColor = vec4(sunfade, sunfade, sunfade, 1.0);",
"reileighCoefficient = reileighCoefficient - (1.0* (1.0-sunfade));",
"float sunE = sunIntensity(dot(sunDirection, up));",
"// extinction (absorbtion + out scattering) ",
......@@ -210,7 +204,7 @@ THREE.ShaderLib['sky'] = {
"vec2 uv = vec2(phi, theta) / vec2(2.0*pi, pi) + vec2(0.5, 0.0);",
"// vec3 L0 = texture2D(skySampler, uv).rgb+0.1 * Fex;",
"vec3 L0 = vec3(0.1) * Fex;",
"// composition + solar disc",
"//if (cosTheta > sunAngularDiameterCos)",
"float sundisk = smoothstep(sunAngularDiameterCos,sunAngularDiameterCos+0.00002,cosTheta);",
......@@ -219,25 +213,25 @@ THREE.ShaderLib['sky'] = {
"vec3 whiteScale = 1.0/Uncharted2Tonemap(vec3(W));",
"vec3 texColor = (Lin+L0); ",
"texColor *= 0.04 ;",
"texColor += vec3(0.0,0.001,0.0025)*0.3;",
"float g_fMaxLuminance = 1.0;",
"float fLumScaled = 0.1 / luminance; ",
"float fLumCompressed = (fLumScaled * (1.0 + (fLumScaled / (g_fMaxLuminance * g_fMaxLuminance)))) / (1.0 + fLumScaled); ",
"float ExposureBias = fLumCompressed;",
"vec3 curr = Uncharted2Tonemap((log2(2.0/pow(luminance,4.0)))*texColor);",
"vec3 color = curr*whiteScale;",
"vec3 retColor = pow(color,vec3(1.0/(1.2+(1.2*sunfade))));",
"gl_FragColor.rgb = retColor;",
"gl_FragColor.a = 1.0;",
"}",
......@@ -250,9 +244,9 @@ THREE.Sky = function () {
var skyShader = THREE.ShaderLib[ "sky" ];
var skyUniforms = THREE.UniformsUtils.clone( skyShader.uniforms );
var skyMat = new THREE.ShaderMaterial( {
fragmentShader: skyShader.fragmentShader,
vertexShader: skyShader.vertexShader,
var skyMat = new THREE.ShaderMaterial( {
fragmentShader: skyShader.fragmentShader,
vertexShader: skyShader.vertexShader,
uniforms: skyUniforms,
side: THREE.BackSide
} );
......@@ -265,5 +259,4 @@ THREE.Sky = function () {
this.mesh = skyMesh;
this.uniforms = skyUniforms;
};
......@@ -300,7 +300,7 @@ THREE.Lut.prototype = {
contextTitle.fillText( this.legend.labels.title.toString() + this.legend.labels.um.toString(), borderThickness, this.legend.labels.fontsize + borderThickness );
var txtTitle = new THREE.Texture( canvasTitle );
txtTitle.minFilter = THREE.LinearFilter;
txtTitle.needsUpdate = true;
var spriteMaterialTitle = new THREE.SpriteMaterial( { map: txtTitle, useScreenCoordinates: false } );
......@@ -385,7 +385,7 @@ THREE.Lut.prototype = {
contextTick.fillText( value.toString(), borderThickness, this.legend.labels.fontsize + borderThickness );
var txtTick = new THREE.Texture( canvasTick );
txtTick.minFilter = THREE.LinearFilter;
txtTick.needsUpdate = true;
var spriteMaterialTick = new THREE.SpriteMaterial( { map: txtTick, useScreenCoordinates: false } );
......
......@@ -16,7 +16,7 @@ THREE.AdaptiveToneMappingPass = function ( adaptive, resolution ) {
this.luminanceRT = null;
this.previousLuminanceRT = null;
this.currentLuminanceRT = null;
if ( THREE.CopyShader === undefined )
console.error( "THREE.AdaptiveToneMappingPass relies on THREE.CopyShader" );
......@@ -72,15 +72,15 @@ THREE.AdaptiveToneMappingPass = function ( adaptive, resolution ) {
"uniform sampler2D currentLum;",
"uniform float delta;",
"uniform float tau;",
"void main() {",
"vec4 lastLum = texture2D( lastLum, vUv, MIP_LEVEL_1X1 );",
"vec4 currentLum = texture2D( currentLum, vUv, MIP_LEVEL_1X1 );",
"float fLastLum = lastLum.r;",
"float fCurrentLum = currentLum.r;",
//The adaption seems to work better in extreme lighting differences
//if the input luminance is squared.
"fCurrentLum *= fCurrentLum;",
......@@ -120,7 +120,7 @@ THREE.AdaptiveToneMappingPass = function ( adaptive, resolution ) {
this.camera = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 );
this.scene = new THREE.Scene();
this.quad = new THREE.Mesh( new THREE.PlaneGeometry( 2, 2 ), null );
this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
this.scene.add( this.quad );
};
......@@ -160,7 +160,7 @@ THREE.AdaptiveToneMappingPass.prototype = {
this.quad.material = this.materialToneMap;
this.materialToneMap.uniforms.tDiffuse.value = readBuffer;
renderer.render( this.scene, this.camera, writeBuffer, this.clear );
},
reset: function( renderer ) {
......@@ -184,7 +184,7 @@ THREE.AdaptiveToneMappingPass.prototype = {
//We only need mipmapping for the current luminosity because we want a down-sampled version to sample in our adaptive shader
pars.minFilter = THREE.LinearMipMapLinearFilter;
this.currentLuminanceRT = new THREE.WebGLRenderTarget( this.resolution, this.resolution, pars );
if ( this.adaptive ) {
this.materialToneMap.defines["ADAPTED_LUMINANCE"] = "";
this.materialToneMap.uniforms.luminanceMap.value = this.luminanceRT;
......@@ -261,4 +261,4 @@ THREE.AdaptiveToneMappingPass.prototype = {
}
}
};
\ No newline at end of file
};
......@@ -163,7 +163,7 @@
var actualHeight = hits[0].distance - birdsEye;
// collision: stick to the surface if landing on it
if( ( motion.velocity.y <= 0 ) && ( Math.abs( actualHeight ) < kneeDeep ) ) {
motion.position.y -= actualHeight;
motion.velocity.y = 0;
......@@ -185,9 +185,9 @@
// limit the tilt at ±0.4 radians
motion.rotation.x = Math.max( -0.4, Math.min ( +0.4, motion.rotation.x ) );
// wrap horizontal rotation to 0...2π
motion.rotation.y += tau; motion.rotation.y %= tau;
timeLeft -= dt;
......@@ -233,6 +233,7 @@
var placeholder = new THREE.Object3D();
var texture = THREE.ImageUtils.loadTexture( textureUrl );
texture.minFilter = THREE.LinearFilter;
texture.anisotropy = textureQuality;
var loader = new THREE.JSONLoader();
......@@ -256,7 +257,7 @@
var camera = new THREE.PerspectiveCamera( 60, 1, 0.1, 9000 );
var scene = new THREE.Scene();
scene.add( camera );
scene.add( makeSkybox( [
......@@ -294,7 +295,7 @@
// call our game loop with the time elapsed since last rendering, in ms
gameLoop( timeElapsed );
renderer.render( scene, camera );
requestAnimationFrame( render );
};
......
......@@ -75,6 +75,7 @@
pickingScene = new THREE.Scene();
pickingTexture = new THREE.WebGLRenderTarget( window.innerWidth, window.innerHeight );
pickingTexture.minFilter = THREE.LinearFilter;
pickingTexture.generateMipmaps = false;
scene.add( new THREE.AmbientLight( 0x555555 ) );
......
......@@ -20,8 +20,8 @@
}
#info {
color:#333;
text-shadow: 1px 1px #fff;
color:#ccc;
text-shadow: 1px 1px rgba(0,0,0,0.25);
position: absolute;
top: 0px; width: 100%;
padding: 5px;
......@@ -29,7 +29,7 @@
}
a {
color: #333;
color: #fff;
}
</style>
......@@ -90,7 +90,7 @@
mieDirectionalG: 0.8,
luminance: 1,
inclination: 0.49, // elevation / inclination
azimuth: 0.25, // Facing front,
azimuth: 0.25, // Facing front,
sun: !true
}
......@@ -108,8 +108,8 @@
var phi = 2 * Math.PI * (effectController.azimuth - 0.5);
sunSphere.position.x = distance * Math.cos(phi);
sunSphere.position.y = distance * Math.sin(phi) * Math.sin(theta);
sunSphere.position.z = distance * Math.sin(phi) * Math.cos(theta);
sunSphere.position.y = distance * Math.sin(phi) * Math.sin(theta);
sunSphere.position.z = distance * Math.sin(phi) * Math.cos(theta);
sunSphere.visible = effectController.sun;
......@@ -129,14 +129,14 @@
gui.add( effectController, "inclination", 0, 1, 0.0001).onChange( guiChanged );
gui.add( effectController, "azimuth", 0, 1, 0.0001).onChange( guiChanged );
gui.add( effectController, "sun").onChange( guiChanged );
guiChanged();
camera.lookAt(sunSphere.position)
}
......@@ -150,21 +150,10 @@
scene = new THREE.Scene();
var size = 500;
var geometryLines = new THREE.BoxGeometry( size, size, size );
var geometryPlane = new THREE.PlaneGeometry( size * 10, size * 10, 1, 1);
geometryPlane.applyMatrix( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
var materialLines = new THREE.MeshBasicMaterial( { wireframe: true } );
meshLines = new THREE.Mesh( geometryLines, materialLines );
// scene.add( meshLines );
scene.add( new THREE.Mesh( geometryPlane, materialLines ) );
var helper = new THREE.GridHelper( 5000, 5000 );
helper.color1.setHex( 0xffffff );
helper.color2.setHex( 0xffffff );
scene.add( helper );
initSky();
......@@ -206,7 +195,7 @@
time = Date.now();
requestAnimationFrame( animate );
controls.update();
render();
......
......@@ -606,7 +606,7 @@
var sceneTmp = new THREE.Scene();
var meshTmp = new THREE.Mesh( new THREE.PlaneGeometry( SCREEN_WIDTH, SCREEN_HEIGHT ), shaderMaterial );
var meshTmp = new THREE.Mesh( new THREE.PlaneBufferGeometry( SCREEN_WIDTH, SCREEN_HEIGHT ), shaderMaterial );
meshTmp.position.z = -500;
sceneTmp.add( meshTmp );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册