2 * @author mrdoob / http://mrdoob.com/
5 import { BackSide } from '../../constants';
6 import { OrthographicCamera } from '../../cameras/OrthographicCamera';
7 import { PerspectiveCamera } from '../../cameras/PerspectiveCamera';
8 import { BoxBufferGeometry } from '../../geometries/BoxGeometry';
9 import { PlaneBufferGeometry } from '../../geometries/PlaneGeometry';
10 import { MeshBasicMaterial } from '../../materials/MeshBasicMaterial';
11 import { ShaderMaterial } from '../../materials/ShaderMaterial';
12 import { Color } from '../../math/Color';
13 import { Mesh } from '../../objects/Mesh';
14 import { ShaderLib } from '../shaders/ShaderLib';
16 function WebGLBackground( renderer, state, geometries, premultipliedAlpha ) {
18 var clearColor = new Color( 0x000000 );
21 var planeCamera, planeMesh;
24 function render( renderList, scene, camera, forceClear ) {
26 var background = scene.background;
28 if ( background === null ) {
30 setClear( clearColor, clearAlpha );
32 } else if ( background && background.isColor ) {
34 setClear( background, 1 );
39 if ( renderer.autoClear || forceClear ) {
41 renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
45 if ( background && background.isCubeTexture ) {
47 if ( boxMesh === undefined ) {
50 new BoxBufferGeometry( 1, 1, 1 ),
52 uniforms: ShaderLib.cube.uniforms,
53 vertexShader: ShaderLib.cube.vertexShader,
54 fragmentShader: ShaderLib.cube.fragmentShader,
63 boxMesh.geometry.removeAttribute( 'normal' );
64 boxMesh.geometry.removeAttribute( 'uv' );
66 boxMesh.onBeforeRender = function ( renderer, scene, camera ) {
68 var scale = camera.far;
70 this.matrixWorld.makeScale( scale, scale, scale );
71 this.matrixWorld.copyPosition( camera.matrixWorld );
73 this.material.polygonOffsetUnits = scale * 10;
77 geometries.update( boxMesh.geometry );
81 boxMesh.material.uniforms.tCube.value = background;
83 renderList.push( boxMesh, boxMesh.geometry, boxMesh.material, 0, null );
85 } else if ( background && background.isTexture ) {
87 if ( planeCamera === undefined ) {
89 planeCamera = new OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
92 new PlaneBufferGeometry( 2, 2 ),
93 new MeshBasicMaterial( { depthTest: false, depthWrite: false, fog: false } )
96 geometries.update( planeMesh.geometry );
100 planeMesh.material.map = background;
102 // TODO Push this to renderList
104 renderer.renderBufferDirect( planeCamera, null, planeMesh.geometry, planeMesh.material, planeMesh, null );
110 function setClear( color, alpha ) {
112 state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
118 getClearColor: function () {
123 setClearColor: function ( color, alpha ) {
125 clearColor.set( color );
126 clearAlpha = alpha !== undefined ? alpha : 1;
127 setClear( clearColor, clearAlpha );
130 getClearAlpha: function () {
135 setClearAlpha: function ( alpha ) {
138 setClear( clearColor, clearAlpha );
148 export { WebGLBackground };