12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651 |
- import { REVISION, MaxEquation, MinEquation, RGB_ETC1_Format, RGBA_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT5_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT1_Format, RGB_S3TC_DXT1_Format, SrcAlphaSaturateFactor, OneMinusDstColorFactor, DstColorFactor, OneMinusDstAlphaFactor, DstAlphaFactor, OneMinusSrcAlphaFactor, SrcAlphaFactor, OneMinusSrcColorFactor, SrcColorFactor, OneFactor, ZeroFactor, ReverseSubtractEquation, SubtractEquation, AddEquation, DepthFormat, DepthStencilFormat, LuminanceAlphaFormat, LuminanceFormat, RGBAFormat, RGBFormat, AlphaFormat, HalfFloatType, FloatType, UnsignedIntType, IntType, UnsignedShortType, ShortType, ByteType, UnsignedInt248Type, UnsignedShort565Type, UnsignedShort5551Type, UnsignedShort4444Type, UnsignedByteType, LinearMipMapLinearFilter, LinearMipMapNearestFilter, LinearFilter, NearestMipMapLinearFilter, NearestMipMapNearestFilter, NearestFilter, MirroredRepeatWrapping, ClampToEdgeWrapping, RepeatWrapping, FrontFaceDirectionCW, NoBlending, TriangleFanDrawMode, TriangleStripDrawMode, TrianglesDrawMode, NoColors, LinearToneMapping } from '../constants';
- import { _Math } from '../math/Math';
- import { Matrix4 } from '../math/Matrix4';
- import { DataTexture } from '../textures/DataTexture';
- import { WebGLUniforms } from './webgl/WebGLUniforms';
- import { UniformsLib } from './shaders/UniformsLib';
- import { UniformsUtils } from './shaders/UniformsUtils';
- import { ShaderLib } from './shaders/ShaderLib';
- import { LensFlarePlugin } from './webgl/plugins/LensFlarePlugin';
- import { SpritePlugin } from './webgl/plugins/SpritePlugin';
- import { WebGLShadowMap } from './webgl/WebGLShadowMap';
- import { WebGLAttributes } from './webgl/WebGLAttributes';
- import { WebGLBackground } from './webgl/WebGLBackground';
- import { WebGLRenderLists } from './webgl/WebGLRenderLists';
- import { WebGLIndexedBufferRenderer } from './webgl/WebGLIndexedBufferRenderer';
- import { WebGLBufferRenderer } from './webgl/WebGLBufferRenderer';
- import { WebGLGeometries } from './webgl/WebGLGeometries';
- import { WebGLLights } from './webgl/WebGLLights';
- import { WebGLObjects } from './webgl/WebGLObjects';
- import { WebGLPrograms } from './webgl/WebGLPrograms';
- import { WebGLTextures } from './webgl/WebGLTextures';
- import { WebGLProperties } from './webgl/WebGLProperties';
- import { WebGLState } from './webgl/WebGLState';
- import { WebGLCapabilities } from './webgl/WebGLCapabilities';
- import { WebVRManager } from './webvr/WebVRManager';
- import { BufferGeometry } from '../core/BufferGeometry';
- import { WebGLExtensions } from './webgl/WebGLExtensions';
- import { Vector3 } from '../math/Vector3';
- // import { Sphere } from '../math/Sphere';
- import { WebGLClipping } from './webgl/WebGLClipping';
- import { Frustum } from '../math/Frustum';
- import { Vector4 } from '../math/Vector4';
- /**
- * @author supereggbert / http://www.paulbrunt.co.uk/
- * @author mrdoob / http://mrdoob.com/
- * @author alteredq / http://alteredqualia.com/
- * @author szimek / https://github.com/szimek/
- * @author tschw
- */
- function WebGLRenderer( parameters ) {
- console.log( 'THREE.WebGLRenderer', REVISION );
- parameters = parameters || {};
- var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ),
- _context = parameters.context !== undefined ? parameters.context : null,
- _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
- _depth = parameters.depth !== undefined ? parameters.depth : true,
- _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
- _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
- _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
- _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false;
- var lightsArray = [];
- var shadowsArray = [];
- var currentRenderList = null;
- var morphInfluences = new Float32Array( 8 );
- var sprites = [];
- var lensFlares = [];
- // public properties
- this.domElement = _canvas;
- this.context = null;
- // clearing
- this.autoClear = true;
- this.autoClearColor = true;
- this.autoClearDepth = true;
- this.autoClearStencil = true;
- // scene graph
- this.sortObjects = true;
- // user-defined clipping
- this.clippingPlanes = [];
- this.localClippingEnabled = false;
- // physically based shading
- this.gammaFactor = 2.0; // for backwards compatibility
- this.gammaInput = false;
- this.gammaOutput = false;
- // physical lights
- this.physicallyCorrectLights = false;
- // tone mapping
- this.toneMapping = LinearToneMapping;
- this.toneMappingExposure = 1.0;
- this.toneMappingWhitePoint = 1.0;
- // morphs
- this.maxMorphTargets = 8;
- this.maxMorphNormals = 4;
- // internal properties
- var _this = this,
- _isContextLost = false,
- // internal state cache
- _currentRenderTarget = null,
- _currentFramebuffer = null,
- _currentMaterialId = - 1,
- _currentGeometryProgram = '',
- _currentCamera = null,
- _currentArrayCamera = null,
- _currentViewport = new Vector4(),
- _currentScissor = new Vector4(),
- _currentScissorTest = null,
- //
- _usedTextureUnits = 0,
- //
- _width = _canvas.width,
- _height = _canvas.height,
- _pixelRatio = 1,
- _viewport = new Vector4( 0, 0, _width, _height ),
- _scissor = new Vector4( 0, 0, _width, _height ),
- _scissorTest = false,
- // frustum
- _frustum = new Frustum(),
- // clipping
- _clipping = new WebGLClipping(),
- _clippingEnabled = false,
- _localClippingEnabled = false,
- // camera matrices cache
- _projScreenMatrix = new Matrix4(),
- _vector3 = new Vector3(),
- // info
- _infoMemory = {
- geometries: 0,
- textures: 0
- },
- _infoRender = {
- frame: 0,
- calls: 0,
- vertices: 0,
- faces: 0,
- points: 0
- };
- this.info = {
- render: _infoRender,
- memory: _infoMemory,
- programs: null
- };
- // initialize
- var _gl;
- try {
- var contextAttributes = {
- alpha: _alpha,
- depth: _depth,
- stencil: _stencil,
- antialias: _antialias,
- premultipliedAlpha: _premultipliedAlpha,
- preserveDrawingBuffer: _preserveDrawingBuffer
- };
- _gl = _context || _canvas.getContext( 'webgl', contextAttributes ) || _canvas.getContext( 'experimental-webgl', contextAttributes );
- if ( _gl === null ) {
- if ( _canvas.getContext( 'webgl' ) !== null ) {
- throw 'Error creating WebGL context with your selected attributes.';
- } else {
- throw 'Error creating WebGL context.';
- }
- }
- // Some experimental-webgl implementations do not have getShaderPrecisionFormat
- if ( _gl.getShaderPrecisionFormat === undefined ) {
- _gl.getShaderPrecisionFormat = function () {
- return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
- };
- }
- _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
- _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
- } catch ( error ) {
- console.error( 'THREE.WebGLRenderer: ' + error );
- }
- var extensions, capabilities, state;
- var properties, textures, attributes, geometries, objects, lights;
- var programCache, renderLists;
- var background, bufferRenderer, indexedBufferRenderer;
- function initGLContext() {
- extensions = new WebGLExtensions( _gl );
- extensions.get( 'WEBGL_depth_texture' );
- extensions.get( 'OES_texture_float' );
- extensions.get( 'OES_texture_float_linear' );
- extensions.get( 'OES_texture_half_float' );
- extensions.get( 'OES_texture_half_float_linear' );
- extensions.get( 'OES_standard_derivatives' );
- extensions.get( 'ANGLE_instanced_arrays' );
- if ( extensions.get( 'OES_element_index_uint' ) ) {
- BufferGeometry.MaxIndex = 4294967296;
- }
- capabilities = new WebGLCapabilities( _gl, extensions, parameters );
- state = new WebGLState( _gl, extensions, paramThreeToGL );
- state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
- state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
- properties = new WebGLProperties();
- textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, paramThreeToGL, _infoMemory );
- attributes = new WebGLAttributes( _gl );
- geometries = new WebGLGeometries( _gl, attributes, _infoMemory );
- objects = new WebGLObjects( _gl, geometries, _infoRender );
- programCache = new WebGLPrograms( _this, capabilities );
- lights = new WebGLLights();
- renderLists = new WebGLRenderLists();
- background = new WebGLBackground( _this, state, objects, _premultipliedAlpha );
- bufferRenderer = new WebGLBufferRenderer( _gl, extensions, _infoRender );
- indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, _infoRender );
- _this.info.programs = programCache.programs;
- }
- initGLContext();
- var vr = new WebVRManager( _this );
- //
- function getTargetPixelRatio() {
- return _currentRenderTarget === null ? _pixelRatio : 1;
- }
- this.context = _gl;
- this.capabilities = capabilities;
- this.extensions = extensions;
- this.properties = properties;
- this.renderLists = renderLists;
- this.state = state;
- this.vr = vr;
- // shadow map
- var shadowMap = new WebGLShadowMap( this, shadowsArray, objects, capabilities );
- this.shadowMap = shadowMap;
- // Plugins
- var spritePlugin = new SpritePlugin( this, sprites );
- var lensFlarePlugin = new LensFlarePlugin( this, lensFlares );
- // API
- this.getContext = function () {
- return _gl;
- };
- this.getContextAttributes = function () {
- return _gl.getContextAttributes();
- };
- this.forceContextLoss = function () {
- var extension = extensions.get( 'WEBGL_lose_context' );
- if ( extension ) extension.loseContext();
- };
- this.forceContextRestore = function () {
- var extension = extensions.get( 'WEBGL_lose_context' );
- if ( extension ) extension.restoreContext();
- };
- this.getMaxAnisotropy = function () {
- return capabilities.getMaxAnisotropy();
- };
- this.getPrecision = function () {
- return capabilities.precision;
- };
- this.getPixelRatio = function () {
- return _pixelRatio;
- };
- this.setPixelRatio = function ( value ) {
- if ( value === undefined ) return;
- _pixelRatio = value;
- this.setSize( _width, _height, false );
- };
- this.getSize = function () {
- return {
- width: _width,
- height: _height
- };
- };
- this.setSize = function ( width, height, updateStyle ) {
- var device = vr.getDevice();
- if ( device && device.isPresenting ) {
- console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
- return;
- }
- _width = width;
- _height = height;
- _canvas.width = width * _pixelRatio;
- _canvas.height = height * _pixelRatio;
- if ( updateStyle !== false ) {
- _canvas.style.width = width + 'px';
- _canvas.style.height = height + 'px';
- }
- this.setViewport( 0, 0, width, height );
- };
- this.getDrawingBufferSize = function () {
- return {
- width: _width * _pixelRatio,
- height: _height * _pixelRatio
- };
- };
- this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
- _width = width;
- _height = height;
- _pixelRatio = pixelRatio;
- _canvas.width = width * pixelRatio;
- _canvas.height = height * pixelRatio;
- this.setViewport( 0, 0, width, height );
- };
- this.setViewport = function ( x, y, width, height ) {
- _viewport.set( x, _height - y - height, width, height );
- state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
- };
- this.setScissor = function ( x, y, width, height ) {
- _scissor.set( x, _height - y - height, width, height );
- state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
- };
- this.setScissorTest = function ( boolean ) {
- state.setScissorTest( _scissorTest = boolean );
- };
- // Clearing
- this.getClearColor = background.getClearColor;
- this.setClearColor = background.setClearColor;
- this.getClearAlpha = background.getClearAlpha;
- this.setClearAlpha = background.setClearAlpha;
- this.clear = function ( color, depth, stencil ) {
- var bits = 0;
- if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
- if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
- if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
- _gl.clear( bits );
- };
- this.clearColor = function () {
- this.clear( true, false, false );
- };
- this.clearDepth = function () {
- this.clear( false, true, false );
- };
- this.clearStencil = function () {
- this.clear( false, false, true );
- };
- this.clearTarget = function ( renderTarget, color, depth, stencil ) {
- this.setRenderTarget( renderTarget );
- this.clear( color, depth, stencil );
- };
- //
- this.dispose = function () {
- _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
- _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
- renderLists.dispose();
- };
- // Events
- function onContextLost( event ) {
- event.preventDefault();
- console.log( 'THREE.WebGLRenderer: Context Lost.' );
- _isContextLost = true;
- }
- function onContextRestore( event ) {
- console.log( 'THREE.WebGLRenderer: Context Restored.' );
- _isContextLost = false;
- initGLContext();
- }
- function onMaterialDispose( event ) {
- var material = event.target;
- material.removeEventListener( 'dispose', onMaterialDispose );
- deallocateMaterial( material );
- }
- // Buffer deallocation
- function deallocateMaterial( material ) {
- releaseMaterialProgramReference( material );
- properties.remove( material );
- }
- function releaseMaterialProgramReference( material ) {
- var programInfo = properties.get( material ).program;
- material.program = undefined;
- if ( programInfo !== undefined ) {
- programCache.releaseProgram( programInfo );
- }
- }
- // Buffer rendering
- function renderObjectImmediate( object, program, material ) {
- object.render( function ( object ) {
- _this.renderBufferImmediate( object, program, material );
- } );
- }
- this.renderBufferImmediate = function ( object, program, material ) {
- state.initAttributes();
- var buffers = properties.get( object );
- if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
- if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
- if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
- if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
- var programAttributes = program.getAttributes();
- if ( object.hasPositions ) {
- _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
- _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
- state.enableAttribute( programAttributes.position );
- _gl.vertexAttribPointer( programAttributes.position, 3, _gl.FLOAT, false, 0, 0 );
- }
- if ( object.hasNormals ) {
- _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
- if ( ! material.isMeshPhongMaterial &&
- ! material.isMeshStandardMaterial &&
- ! material.isMeshNormalMaterial &&
- material.flatShading === true ) {
- for ( var i = 0, l = object.count * 3; i < l; i += 9 ) {
- var array = object.normalArray;
- var nx = ( array[ i + 0 ] + array[ i + 3 ] + array[ i + 6 ] ) / 3;
- var ny = ( array[ i + 1 ] + array[ i + 4 ] + array[ i + 7 ] ) / 3;
- var nz = ( array[ i + 2 ] + array[ i + 5 ] + array[ i + 8 ] ) / 3;
- array[ i + 0 ] = nx;
- array[ i + 1 ] = ny;
- array[ i + 2 ] = nz;
- array[ i + 3 ] = nx;
- array[ i + 4 ] = ny;
- array[ i + 5 ] = nz;
- array[ i + 6 ] = nx;
- array[ i + 7 ] = ny;
- array[ i + 8 ] = nz;
- }
- }
- _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
- state.enableAttribute( programAttributes.normal );
- _gl.vertexAttribPointer( programAttributes.normal, 3, _gl.FLOAT, false, 0, 0 );
- }
- if ( object.hasUvs && material.map ) {
- _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
- _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
- state.enableAttribute( programAttributes.uv );
- _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
- }
- if ( object.hasColors && material.vertexColors !== NoColors ) {
- _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
- _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
- state.enableAttribute( programAttributes.color );
- _gl.vertexAttribPointer( programAttributes.color, 3, _gl.FLOAT, false, 0, 0 );
- }
- state.disableUnusedAttributes();
- _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
- object.count = 0;
- };
- function absNumericalSort( a, b ) {
- return Math.abs( b[ 0 ] ) - Math.abs( a[ 0 ] );
- }
- this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
- state.setMaterial( material );
- var program = setProgram( camera, fog, material, object );
- var geometryProgram = geometry.id + '_' + program.id + '_' + ( material.wireframe === true );
- var updateBuffers = false;
- if ( geometryProgram !== _currentGeometryProgram ) {
- _currentGeometryProgram = geometryProgram;
- updateBuffers = true;
- }
- // morph targets
- var morphTargetInfluences = object.morphTargetInfluences;
- if ( morphTargetInfluences !== undefined ) {
- // TODO Remove allocations
- var activeInfluences = [];
- for ( var i = 0, l = morphTargetInfluences.length; i < l; i ++ ) {
- var influence = morphTargetInfluences[ i ];
- activeInfluences.push( [ influence, i ] );
- }
- activeInfluences.sort( absNumericalSort );
- if ( activeInfluences.length > 8 ) {
- activeInfluences.length = 8;
- }
- var morphAttributes = geometry.morphAttributes;
- for ( var i = 0, l = activeInfluences.length; i < l; i ++ ) {
- var influence = activeInfluences[ i ];
- morphInfluences[ i ] = influence[ 0 ];
- if ( influence[ 0 ] !== 0 ) {
- var index = influence[ 1 ];
- if ( material.morphTargets === true && morphAttributes.position ) geometry.addAttribute( 'morphTarget' + i, morphAttributes.position[ index ] );
- if ( material.morphNormals === true && morphAttributes.normal ) geometry.addAttribute( 'morphNormal' + i, morphAttributes.normal[ index ] );
- } else {
- if ( material.morphTargets === true ) geometry.removeAttribute( 'morphTarget' + i );
- if ( material.morphNormals === true ) geometry.removeAttribute( 'morphNormal' + i );
- }
- }
- for ( var i = activeInfluences.length, il = morphInfluences.length; i < il; i ++ ) {
- morphInfluences[ i ] = 0.0;
- }
- program.getUniforms().setValue( _gl, 'morphTargetInfluences', morphInfluences );
- updateBuffers = true;
- }
- //
- var index = geometry.index;
- var position = geometry.attributes.position;
- var rangeFactor = 1;
- if ( material.wireframe === true ) {
- index = geometries.getWireframeAttribute( geometry );
- rangeFactor = 2;
- }
- var attribute;
- var renderer = bufferRenderer;
- if ( index !== null ) {
- attribute = attributes.get( index );
- renderer = indexedBufferRenderer;
- renderer.setIndex( attribute );
- }
- if ( updateBuffers ) {
- setupVertexAttributes( material, program, geometry );
- if ( index !== null ) {
- _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, attribute.buffer );
- }
- }
- //
- var dataCount = 0;
- if ( index !== null ) {
- dataCount = index.count;
- } else if ( position !== undefined ) {
- dataCount = position.count;
- }
- var rangeStart = geometry.drawRange.start * rangeFactor;
- var rangeCount = geometry.drawRange.count * rangeFactor;
- var groupStart = group !== null ? group.start * rangeFactor : 0;
- var groupCount = group !== null ? group.count * rangeFactor : Infinity;
- var drawStart = Math.max( rangeStart, groupStart );
- var drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
- var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
- if ( drawCount === 0 ) return;
- //
- if ( object.isMesh ) {
- if ( material.wireframe === true ) {
- state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
- renderer.setMode( _gl.LINES );
- } else {
- switch ( object.drawMode ) {
- case TrianglesDrawMode:
- renderer.setMode( _gl.TRIANGLES );
- break;
- case TriangleStripDrawMode:
- renderer.setMode( _gl.TRIANGLE_STRIP );
- break;
- case TriangleFanDrawMode:
- renderer.setMode( _gl.TRIANGLE_FAN );
- break;
- }
- }
- } else if ( object.isLine ) {
- var lineWidth = material.linewidth;
- if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
- state.setLineWidth( lineWidth * getTargetPixelRatio() );
- if ( object.isLineSegments ) {
- renderer.setMode( _gl.LINES );
- } else if ( object.isLineLoop ) {
- renderer.setMode( _gl.LINE_LOOP );
- } else {
- renderer.setMode( _gl.LINE_STRIP );
- }
- } else if ( object.isPoints ) {
- renderer.setMode( _gl.POINTS );
- }
- if ( geometry && geometry.isInstancedBufferGeometry ) {
- if ( geometry.maxInstancedCount > 0 ) {
- renderer.renderInstances( geometry, drawStart, drawCount );
- }
- } else {
- renderer.render( drawStart, drawCount );
- }
- };
- function setupVertexAttributes( material, program, geometry, startIndex ) {
- if ( geometry && geometry.isInstancedBufferGeometry ) {
- if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) {
- console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
- return;
- }
- }
- if ( startIndex === undefined ) startIndex = 0;
- state.initAttributes();
- var geometryAttributes = geometry.attributes;
- var programAttributes = program.getAttributes();
- var materialDefaultAttributeValues = material.defaultAttributeValues;
- for ( var name in programAttributes ) {
- var programAttribute = programAttributes[ name ];
- if ( programAttribute >= 0 ) {
- var geometryAttribute = geometryAttributes[ name ];
- if ( geometryAttribute !== undefined ) {
- var normalized = geometryAttribute.normalized;
- var size = geometryAttribute.itemSize;
- var attribute = attributes.get( geometryAttribute );
- // TODO Attribute may not be available on context restore
- if ( attribute === undefined ) continue;
- var buffer = attribute.buffer;
- var type = attribute.type;
- var bytesPerElement = attribute.bytesPerElement;
- if ( geometryAttribute.isInterleavedBufferAttribute ) {
- var data = geometryAttribute.data;
- var stride = data.stride;
- var offset = geometryAttribute.offset;
- if ( data && data.isInstancedInterleavedBuffer ) {
- state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
- if ( geometry.maxInstancedCount === undefined ) {
- geometry.maxInstancedCount = data.meshPerAttribute * data.count;
- }
- } else {
- state.enableAttribute( programAttribute );
- }
- _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
- _gl.vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, ( startIndex * stride + offset ) * bytesPerElement );
- } else {
- if ( geometryAttribute.isInstancedBufferAttribute ) {
- state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
- if ( geometry.maxInstancedCount === undefined ) {
- geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
- }
- } else {
- state.enableAttribute( programAttribute );
- }
- _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
- _gl.vertexAttribPointer( programAttribute, size, type, normalized, 0, startIndex * size * bytesPerElement );
- }
- } else if ( materialDefaultAttributeValues !== undefined ) {
- var value = materialDefaultAttributeValues[ name ];
- if ( value !== undefined ) {
- switch ( value.length ) {
- case 2:
- _gl.vertexAttrib2fv( programAttribute, value );
- break;
- case 3:
- _gl.vertexAttrib3fv( programAttribute, value );
- break;
- case 4:
- _gl.vertexAttrib4fv( programAttribute, value );
- break;
- default:
- _gl.vertexAttrib1fv( programAttribute, value );
- }
- }
- }
- }
- }
- state.disableUnusedAttributes();
- }
- // Compile
- this.compile = function ( scene, camera ) {
- lightsArray.length = 0;
- shadowsArray.length = 0;
- scene.traverse( function ( object ) {
- if ( object.isLight ) {
- lightsArray.push( object );
- if ( object.castShadow ) {
- shadowsArray.push( object );
- }
- }
- } );
- lights.setup( lightsArray, shadowsArray, camera );
- scene.traverse( function ( object ) {
- if ( object.material ) {
- if ( Array.isArray( object.material ) ) {
- for ( var i = 0; i < object.material.length; i ++ ) {
- initMaterial( object.material[ i ], scene.fog, object );
- }
- } else {
- initMaterial( object.material, scene.fog, object );
- }
- }
- } );
- };
- // Rendering
- this.animate = function ( callback ) {
- function onFrame() {
- callback();
- ( vr.getDevice() || window ).requestAnimationFrame( onFrame );
- }
- ( vr.getDevice() || window ).requestAnimationFrame( onFrame );
- };
- this.render = function ( scene, camera, renderTarget, forceClear ) {
- if ( ! ( camera && camera.isCamera ) ) {
- console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
- return;
- }
- if ( _isContextLost ) return;
- // reset caching for this frame
- _currentGeometryProgram = '';
- _currentMaterialId = - 1;
- _currentCamera = null;
- // update scene graph
- if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
- // update camera matrices and frustum
- if ( camera.parent === null ) camera.updateMatrixWorld();
- if ( vr.enabled ) {
- camera = vr.getCamera( camera );
- }
- _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
- _frustum.setFromMatrix( _projScreenMatrix );
- lightsArray.length = 0;
- shadowsArray.length = 0;
- sprites.length = 0;
- lensFlares.length = 0;
- _localClippingEnabled = this.localClippingEnabled;
- _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
- currentRenderList = renderLists.get( scene, camera );
- currentRenderList.init();
- projectObject( scene, camera, _this.sortObjects );
- currentRenderList.finish();
- if ( _this.sortObjects === true ) {
- currentRenderList.sort();
- }
- //
- if ( _clippingEnabled ) _clipping.beginShadows();
- shadowMap.render( scene, camera );
- lights.setup( lightsArray, shadowsArray, camera );
- if ( _clippingEnabled ) _clipping.endShadows();
- //
- _infoRender.frame ++;
- _infoRender.calls = 0;
- _infoRender.vertices = 0;
- _infoRender.faces = 0;
- _infoRender.points = 0;
- if ( renderTarget === undefined ) {
- renderTarget = null;
- }
- this.setRenderTarget( renderTarget );
- //
- background.render( scene, camera, forceClear );
- // render scene
- var opaqueObjects = currentRenderList.opaque;
- var transparentObjects = currentRenderList.transparent;
- if ( scene.overrideMaterial ) {
- var overrideMaterial = scene.overrideMaterial;
- if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera, overrideMaterial );
- if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera, overrideMaterial );
- } else {
- // opaque pass (front-to-back order)
- if ( opaqueObjects.length ) renderObjects( opaqueObjects, scene, camera );
- // transparent pass (back-to-front order)
- if ( transparentObjects.length ) renderObjects( transparentObjects, scene, camera );
- }
- // custom render plugins (post pass)
- spritePlugin.render( scene, camera );
- lensFlarePlugin.render( scene, camera, _currentViewport );
- // Generate mipmap if we're using any kind of mipmap filtering
- if ( renderTarget ) {
- textures.updateRenderTargetMipmap( renderTarget );
- }
- // Ensure depth buffer writing is enabled so it can be cleared on next render
- state.buffers.depth.setTest( true );
- state.buffers.depth.setMask( true );
- state.buffers.color.setMask( true );
- if ( vr.enabled ) {
- vr.submitFrame();
- }
- // _gl.finish();
- };
- /*
- // TODO Duplicated code (Frustum)
- var _sphere = new Sphere();
- function isObjectViewable( object ) {
- var geometry = object.geometry;
- if ( geometry.boundingSphere === null )
- geometry.computeBoundingSphere();
- _sphere.copy( geometry.boundingSphere ).
- applyMatrix4( object.matrixWorld );
- return isSphereViewable( _sphere );
- }
- function isSpriteViewable( sprite ) {
- _sphere.center.set( 0, 0, 0 );
- _sphere.radius = 0.7071067811865476;
- _sphere.applyMatrix4( sprite.matrixWorld );
- return isSphereViewable( _sphere );
- }
- function isSphereViewable( sphere ) {
- if ( ! _frustum.intersectsSphere( sphere ) ) return false;
- var numPlanes = _clipping.numPlanes;
- if ( numPlanes === 0 ) return true;
- var planes = _this.clippingPlanes,
- center = sphere.center,
- negRad = - sphere.radius,
- i = 0;
- do {
- // out when deeper than radius in the negative halfspace
- if ( planes[ i ].distanceToPoint( center ) < negRad ) return false;
- } while ( ++ i !== numPlanes );
- return true;
- }
- */
- function projectObject( object, camera, sortObjects ) {
- if ( ! object.visible ) return;
- var visible = object.layers.test( camera.layers );
- if ( visible ) {
- if ( object.isLight ) {
- lightsArray.push( object );
- if ( object.castShadow ) {
- shadowsArray.push( object );
- }
- } else if ( object.isSprite ) {
- if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
- sprites.push( object );
- }
- } else if ( object.isLensFlare ) {
- lensFlares.push( object );
- } else if ( object.isImmediateRenderObject ) {
- if ( sortObjects ) {
- _vector3.setFromMatrixPosition( object.matrixWorld )
- .applyMatrix4( _projScreenMatrix );
- }
- currentRenderList.push( object, null, object.material, _vector3.z, null );
- } else if ( object.isMesh || object.isLine || object.isPoints ) {
- if ( object.isSkinnedMesh ) {
- object.skeleton.update();
- }
- if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
- if ( sortObjects ) {
- _vector3.setFromMatrixPosition( object.matrixWorld )
- .applyMatrix4( _projScreenMatrix );
- }
- var geometry = objects.update( object );
- var material = object.material;
- if ( Array.isArray( material ) ) {
- var groups = geometry.groups;
- for ( var i = 0, l = groups.length; i < l; i ++ ) {
- var group = groups[ i ];
- var groupMaterial = material[ group.materialIndex ];
- if ( groupMaterial && groupMaterial.visible ) {
- currentRenderList.push( object, geometry, groupMaterial, _vector3.z, group );
- }
- }
- } else if ( material.visible ) {
- currentRenderList.push( object, geometry, material, _vector3.z, null );
- }
- }
- }
- }
- var children = object.children;
- for ( var i = 0, l = children.length; i < l; i ++ ) {
- projectObject( children[ i ], camera, sortObjects );
- }
- }
- function renderObjects( renderList, scene, camera, overrideMaterial ) {
- for ( var i = 0, l = renderList.length; i < l; i ++ ) {
- var renderItem = renderList[ i ];
- var object = renderItem.object;
- var geometry = renderItem.geometry;
- var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
- var group = renderItem.group;
- if ( camera.isArrayCamera ) {
- _currentArrayCamera = camera;
- var cameras = camera.cameras;
- for ( var j = 0, jl = cameras.length; j < jl; j ++ ) {
- var camera2 = cameras[ j ];
- if ( object.layers.test( camera2.layers ) ) {
- var bounds = camera2.bounds;
- var x = bounds.x * _width;
- var y = bounds.y * _height;
- var width = bounds.z * _width;
- var height = bounds.w * _height;
- state.viewport( _currentViewport.set( x, y, width, height ).multiplyScalar( _pixelRatio ) );
- state.scissor( _currentScissor.set( x, y, width, height ).multiplyScalar( _pixelRatio ) );
- state.setScissorTest( true );
- renderObject( object, scene, camera2, geometry, material, group );
- }
- }
- } else {
- _currentArrayCamera = null;
- renderObject( object, scene, camera, geometry, material, group );
- }
- }
- }
- function renderObject( object, scene, camera, geometry, material, group ) {
- object.onBeforeRender( _this, scene, camera, geometry, material, group );
- object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
- object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
- if ( object.isImmediateRenderObject ) {
- state.setMaterial( material );
- var program = setProgram( camera, scene.fog, material, object );
- _currentGeometryProgram = '';
- renderObjectImmediate( object, program, material );
- } else {
- _this.renderBufferDirect( camera, scene.fog, geometry, material, object, group );
- }
- object.onAfterRender( _this, scene, camera, geometry, material, group );
- }
- function initMaterial( material, fog, object ) {
- var materialProperties = properties.get( material );
- var parameters = programCache.getParameters(
- material, lights.state, shadowsArray, fog, _clipping.numPlanes, _clipping.numIntersection, object );
- var code = programCache.getProgramCode( material, parameters );
- var program = materialProperties.program;
- var programChange = true;
- if ( program === undefined ) {
- // new material
- material.addEventListener( 'dispose', onMaterialDispose );
- } else if ( program.code !== code ) {
- // changed glsl or parameters
- releaseMaterialProgramReference( material );
- } else if ( parameters.shaderID !== undefined ) {
- // same glsl and uniform list
- return;
- } else {
- // only rebuild uniform list
- programChange = false;
- }
- if ( programChange ) {
- if ( parameters.shaderID ) {
- var shader = ShaderLib[ parameters.shaderID ];
- materialProperties.shader = {
- name: material.type,
- uniforms: UniformsUtils.clone( shader.uniforms ),
- vertexShader: shader.vertexShader,
- fragmentShader: shader.fragmentShader
- };
- } else {
- materialProperties.shader = {
- name: material.type,
- uniforms: material.uniforms,
- vertexShader: material.vertexShader,
- fragmentShader: material.fragmentShader
- };
- }
- material.onBeforeCompile( materialProperties.shader );
- program = programCache.acquireProgram( material, materialProperties.shader, parameters, code );
- materialProperties.program = program;
- material.program = program;
- }
- var programAttributes = program.getAttributes();
- if ( material.morphTargets ) {
- material.numSupportedMorphTargets = 0;
- for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
- if ( programAttributes[ 'morphTarget' + i ] >= 0 ) {
- material.numSupportedMorphTargets ++;
- }
- }
- }
- if ( material.morphNormals ) {
- material.numSupportedMorphNormals = 0;
- for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
- if ( programAttributes[ 'morphNormal' + i ] >= 0 ) {
- material.numSupportedMorphNormals ++;
- }
- }
- }
- var uniforms = materialProperties.shader.uniforms;
- if ( ! material.isShaderMaterial &&
- ! material.isRawShaderMaterial ||
- material.clipping === true ) {
- materialProperties.numClippingPlanes = _clipping.numPlanes;
- materialProperties.numIntersection = _clipping.numIntersection;
- uniforms.clippingPlanes = _clipping.uniform;
- }
- materialProperties.fog = fog;
- // store the light setup it was created for
- materialProperties.lightsHash = lights.state.hash;
- if ( material.lights ) {
- // wire up the material to this renderer's lighting state
- uniforms.ambientLightColor.value = lights.state.ambient;
- uniforms.directionalLights.value = lights.state.directional;
- uniforms.spotLights.value = lights.state.spot;
- uniforms.rectAreaLights.value = lights.state.rectArea;
- uniforms.pointLights.value = lights.state.point;
- uniforms.hemisphereLights.value = lights.state.hemi;
- uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
- uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
- uniforms.spotShadowMap.value = lights.state.spotShadowMap;
- uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
- uniforms.pointShadowMap.value = lights.state.pointShadowMap;
- uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
- // TODO (abelnation): add area lights shadow info to uniforms
- }
- var progUniforms = materialProperties.program.getUniforms(),
- uniformsList =
- WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
- materialProperties.uniformsList = uniformsList;
- }
- function setProgram( camera, fog, material, object ) {
- _usedTextureUnits = 0;
- var materialProperties = properties.get( material );
- if ( _clippingEnabled ) {
- if ( _localClippingEnabled || camera !== _currentCamera ) {
- var useCache =
- camera === _currentCamera &&
- material.id === _currentMaterialId;
- // we might want to call this function with some ClippingGroup
- // object instead of the material, once it becomes feasible
- // (#8465, #8379)
- _clipping.setState(
- material.clippingPlanes, material.clipIntersection, material.clipShadows,
- camera, materialProperties, useCache );
- }
- }
- if ( material.needsUpdate === false ) {
- if ( materialProperties.program === undefined ) {
- material.needsUpdate = true;
- } else if ( material.fog && materialProperties.fog !== fog ) {
- material.needsUpdate = true;
- } else if ( material.lights && materialProperties.lightsHash !== lights.state.hash ) {
- material.needsUpdate = true;
- } else if ( materialProperties.numClippingPlanes !== undefined &&
- ( materialProperties.numClippingPlanes !== _clipping.numPlanes ||
- materialProperties.numIntersection !== _clipping.numIntersection ) ) {
- material.needsUpdate = true;
- }
- }
- if ( material.needsUpdate ) {
- initMaterial( material, fog, object );
- material.needsUpdate = false;
- }
- var refreshProgram = false;
- var refreshMaterial = false;
- var refreshLights = false;
- var program = materialProperties.program,
- p_uniforms = program.getUniforms(),
- m_uniforms = materialProperties.shader.uniforms;
- if ( state.useProgram( program.program ) ) {
- refreshProgram = true;
- refreshMaterial = true;
- refreshLights = true;
- }
- if ( material.id !== _currentMaterialId ) {
- _currentMaterialId = material.id;
- refreshMaterial = true;
- }
- if ( refreshProgram || camera !== _currentCamera ) {
- p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
- if ( capabilities.logarithmicDepthBuffer ) {
- p_uniforms.setValue( _gl, 'logDepthBufFC',
- 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
- }
- // Avoid unneeded uniform updates per ArrayCamera's sub-camera
- if ( _currentCamera !== ( _currentArrayCamera || camera ) ) {
- _currentCamera = ( _currentArrayCamera || camera );
- // lighting uniforms depend on the camera so enforce an update
- // now, in case this material supports lights - or later, when
- // the next material that does gets activated:
- refreshMaterial = true; // set to true on material change
- refreshLights = true; // remains set until update done
- }
- // load material specific uniforms
- // (shader material also gets them for the sake of genericity)
- if ( material.isShaderMaterial ||
- material.isMeshPhongMaterial ||
- material.isMeshStandardMaterial ||
- material.envMap ) {
- var uCamPos = p_uniforms.map.cameraPosition;
- if ( uCamPos !== undefined ) {
- uCamPos.setValue( _gl,
- _vector3.setFromMatrixPosition( camera.matrixWorld ) );
- }
- }
- if ( material.isMeshPhongMaterial ||
- material.isMeshLambertMaterial ||
- material.isMeshBasicMaterial ||
- material.isMeshStandardMaterial ||
- material.isShaderMaterial ||
- material.skinning ) {
- p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
- }
- }
- // skinning uniforms must be set even if material didn't change
- // auto-setting of texture unit for bone texture must go before other textures
- // not sure why, but otherwise weird things happen
- if ( material.skinning ) {
- p_uniforms.setOptional( _gl, object, 'bindMatrix' );
- p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
- var skeleton = object.skeleton;
- if ( skeleton ) {
- var bones = skeleton.bones;
- if ( capabilities.floatVertexTextures ) {
- if ( skeleton.boneTexture === undefined ) {
- // layout (1 matrix = 4 pixels)
- // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
- // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
- // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
- // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
- // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
- var size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
- size = _Math.nextPowerOfTwo( Math.ceil( size ) );
- size = Math.max( size, 4 );
- var boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
- boneMatrices.set( skeleton.boneMatrices ); // copy current values
- var boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
- skeleton.boneMatrices = boneMatrices;
- skeleton.boneTexture = boneTexture;
- skeleton.boneTextureSize = size;
- }
- p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture );
- p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
- } else {
- p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
- }
- }
- }
- if ( refreshMaterial ) {
- p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
- p_uniforms.setValue( _gl, 'toneMappingWhitePoint', _this.toneMappingWhitePoint );
- if ( material.lights ) {
- // the current material requires lighting info
- // note: all lighting uniforms are always set correctly
- // they simply reference the renderer's state for their
- // values
- //
- // use the current material's .needsUpdate flags to set
- // the GL state when required
- markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
- }
- // refresh uniforms common to several materials
- if ( fog && material.fog ) {
- refreshUniformsFog( m_uniforms, fog );
- }
- if ( material.isMeshBasicMaterial ||
- material.isMeshLambertMaterial ||
- material.isMeshPhongMaterial ||
- material.isMeshStandardMaterial ||
- material.isMeshNormalMaterial ||
- material.isMeshDepthMaterial ||
- material.isMeshDistanceMaterial ) {
- refreshUniformsCommon( m_uniforms, material );
- }
- // refresh single material specific uniforms
- if ( material.isLineBasicMaterial ) {
- refreshUniformsLine( m_uniforms, material );
- } else if ( material.isLineDashedMaterial ) {
- refreshUniformsLine( m_uniforms, material );
- refreshUniformsDash( m_uniforms, material );
- } else if ( material.isPointsMaterial ) {
- refreshUniformsPoints( m_uniforms, material );
- } else if ( material.isMeshLambertMaterial ) {
- refreshUniformsLambert( m_uniforms, material );
- } else if ( material.isMeshToonMaterial ) {
- refreshUniformsToon( m_uniforms, material );
- } else if ( material.isMeshPhongMaterial ) {
- refreshUniformsPhong( m_uniforms, material );
- } else if ( material.isMeshPhysicalMaterial ) {
- refreshUniformsPhysical( m_uniforms, material );
- } else if ( material.isMeshStandardMaterial ) {
- refreshUniformsStandard( m_uniforms, material );
- } else if ( material.isMeshDepthMaterial ) {
- refreshUniformsDepth( m_uniforms, material );
- } else if ( material.isMeshDistanceMaterial ) {
- refreshUniformsDistance( m_uniforms, material );
- } else if ( material.isMeshNormalMaterial ) {
- refreshUniformsNormal( m_uniforms, material );
- }
- // RectAreaLight Texture
- // TODO (mrdoob): Find a nicer implementation
- if ( m_uniforms.ltcMat !== undefined ) m_uniforms.ltcMat.value = UniformsLib.LTC_MAT_TEXTURE;
- if ( m_uniforms.ltcMag !== undefined ) m_uniforms.ltcMag.value = UniformsLib.LTC_MAG_TEXTURE;
- WebGLUniforms.upload(
- _gl, materialProperties.uniformsList, m_uniforms, _this );
- }
- // common matrices
- p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
- p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
- p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
- return program;
- }
- // Uniforms (refresh uniforms objects)
- function refreshUniformsCommon( uniforms, material ) {
- uniforms.opacity.value = material.opacity;
- uniforms.diffuse.value = material.color;
- if ( material.emissive ) {
- uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
- }
- uniforms.map.value = material.map;
- uniforms.specularMap.value = material.specularMap;
- uniforms.alphaMap.value = material.alphaMap;
- if ( material.lightMap ) {
- uniforms.lightMap.value = material.lightMap;
- uniforms.lightMapIntensity.value = material.lightMapIntensity;
- }
- if ( material.aoMap ) {
- uniforms.aoMap.value = material.aoMap;
- uniforms.aoMapIntensity.value = material.aoMapIntensity;
- }
- // uv repeat and offset setting priorities
- // 1. color map
- // 2. specular map
- // 3. normal map
- // 4. bump map
- // 5. alpha map
- // 6. emissive map
- var uvScaleMap;
- if ( material.map ) {
- uvScaleMap = material.map;
- } else if ( material.specularMap ) {
- uvScaleMap = material.specularMap;
- } else if ( material.displacementMap ) {
- uvScaleMap = material.displacementMap;
- } else if ( material.normalMap ) {
- uvScaleMap = material.normalMap;
- } else if ( material.bumpMap ) {
- uvScaleMap = material.bumpMap;
- } else if ( material.roughnessMap ) {
- uvScaleMap = material.roughnessMap;
- } else if ( material.metalnessMap ) {
- uvScaleMap = material.metalnessMap;
- } else if ( material.alphaMap ) {
- uvScaleMap = material.alphaMap;
- } else if ( material.emissiveMap ) {
- uvScaleMap = material.emissiveMap;
- }
- if ( uvScaleMap !== undefined ) {
- // backwards compatibility
- if ( uvScaleMap.isWebGLRenderTarget ) {
- uvScaleMap = uvScaleMap.texture;
- }
- var offset = uvScaleMap.offset;
- var repeat = uvScaleMap.repeat;
- uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
- }
- uniforms.envMap.value = material.envMap;
- // don't flip CubeTexture envMaps, flip everything else:
- // WebGLRenderTargetCube will be flipped for backwards compatibility
- // WebGLRenderTargetCube.texture will be flipped because it's a Texture and NOT a CubeTexture
- // this check must be handled differently, or removed entirely, if WebGLRenderTargetCube uses a CubeTexture in the future
- uniforms.flipEnvMap.value = ( ! ( material.envMap && material.envMap.isCubeTexture ) ) ? 1 : - 1;
- uniforms.reflectivity.value = material.reflectivity;
- uniforms.refractionRatio.value = material.refractionRatio;
- }
- function refreshUniformsLine( uniforms, material ) {
- uniforms.diffuse.value = material.color;
- uniforms.opacity.value = material.opacity;
- }
- function refreshUniformsDash( uniforms, material ) {
- uniforms.dashSize.value = material.dashSize;
- uniforms.totalSize.value = material.dashSize + material.gapSize;
- uniforms.scale.value = material.scale;
- }
- function refreshUniformsPoints( uniforms, material ) {
- uniforms.diffuse.value = material.color;
- uniforms.opacity.value = material.opacity;
- uniforms.size.value = material.size * _pixelRatio;
- uniforms.scale.value = _height * 0.5;
- uniforms.map.value = material.map;
- if ( material.map !== null ) {
- var offset = material.map.offset;
- var repeat = material.map.repeat;
- uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
- }
- }
- function refreshUniformsFog( uniforms, fog ) {
- uniforms.fogColor.value = fog.color;
- if ( fog.isFog ) {
- uniforms.fogNear.value = fog.near;
- uniforms.fogFar.value = fog.far;
- } else if ( fog.isFogExp2 ) {
- uniforms.fogDensity.value = fog.density;
- }
- }
- function refreshUniformsLambert( uniforms, material ) {
- if ( material.emissiveMap ) {
- uniforms.emissiveMap.value = material.emissiveMap;
- }
- }
- function refreshUniformsPhong( uniforms, material ) {
- uniforms.specular.value = material.specular;
- uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
- if ( material.emissiveMap ) {
- uniforms.emissiveMap.value = material.emissiveMap;
- }
- if ( material.bumpMap ) {
- uniforms.bumpMap.value = material.bumpMap;
- uniforms.bumpScale.value = material.bumpScale;
- }
- if ( material.normalMap ) {
- uniforms.normalMap.value = material.normalMap;
- uniforms.normalScale.value.copy( material.normalScale );
- }
- if ( material.displacementMap ) {
- uniforms.displacementMap.value = material.displacementMap;
- uniforms.displacementScale.value = material.displacementScale;
- uniforms.displacementBias.value = material.displacementBias;
- }
- }
- function refreshUniformsToon( uniforms, material ) {
- refreshUniformsPhong( uniforms, material );
- if ( material.gradientMap ) {
- uniforms.gradientMap.value = material.gradientMap;
- }
- }
- function refreshUniformsStandard( uniforms, material ) {
- uniforms.roughness.value = material.roughness;
- uniforms.metalness.value = material.metalness;
- if ( material.roughnessMap ) {
- uniforms.roughnessMap.value = material.roughnessMap;
- }
- if ( material.metalnessMap ) {
- uniforms.metalnessMap.value = material.metalnessMap;
- }
- if ( material.emissiveMap ) {
- uniforms.emissiveMap.value = material.emissiveMap;
- }
- if ( material.bumpMap ) {
- uniforms.bumpMap.value = material.bumpMap;
- uniforms.bumpScale.value = material.bumpScale;
- }
- if ( material.normalMap ) {
- uniforms.normalMap.value = material.normalMap;
- uniforms.normalScale.value.copy( material.normalScale );
- }
- if ( material.displacementMap ) {
- uniforms.displacementMap.value = material.displacementMap;
- uniforms.displacementScale.value = material.displacementScale;
- uniforms.displacementBias.value = material.displacementBias;
- }
- if ( material.envMap ) {
- //uniforms.envMap.value = material.envMap; // part of uniforms common
- uniforms.envMapIntensity.value = material.envMapIntensity;
- }
- }
- function refreshUniformsPhysical( uniforms, material ) {
- uniforms.clearCoat.value = material.clearCoat;
- uniforms.clearCoatRoughness.value = material.clearCoatRoughness;
- refreshUniformsStandard( uniforms, material );
- }
- function refreshUniformsDepth( uniforms, material ) {
- if ( material.displacementMap ) {
- uniforms.displacementMap.value = material.displacementMap;
- uniforms.displacementScale.value = material.displacementScale;
- uniforms.displacementBias.value = material.displacementBias;
- }
- }
- function refreshUniformsDistance( uniforms, material ) {
- if ( material.displacementMap ) {
- uniforms.displacementMap.value = material.displacementMap;
- uniforms.displacementScale.value = material.displacementScale;
- uniforms.displacementBias.value = material.displacementBias;
- }
- uniforms.referencePosition.value.copy( material.referencePosition );
- uniforms.nearDistance.value = material.nearDistance;
- uniforms.farDistance.value = material.farDistance;
- }
- function refreshUniformsNormal( uniforms, material ) {
- if ( material.bumpMap ) {
- uniforms.bumpMap.value = material.bumpMap;
- uniforms.bumpScale.value = material.bumpScale;
- }
- if ( material.normalMap ) {
- uniforms.normalMap.value = material.normalMap;
- uniforms.normalScale.value.copy( material.normalScale );
- }
- if ( material.displacementMap ) {
- uniforms.displacementMap.value = material.displacementMap;
- uniforms.displacementScale.value = material.displacementScale;
- uniforms.displacementBias.value = material.displacementBias;
- }
- }
- // If uniforms are marked as clean, they don't need to be loaded to the GPU.
- function markUniformsLightsNeedsUpdate( uniforms, value ) {
- uniforms.ambientLightColor.needsUpdate = value;
- uniforms.directionalLights.needsUpdate = value;
- uniforms.pointLights.needsUpdate = value;
- uniforms.spotLights.needsUpdate = value;
- uniforms.rectAreaLights.needsUpdate = value;
- uniforms.hemisphereLights.needsUpdate = value;
- }
- // GL state setting
- this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
- state.setCullFace( cullFace );
- state.setFlipSided( frontFaceDirection === FrontFaceDirectionCW );
- };
- // Textures
- function allocTextureUnit() {
- var textureUnit = _usedTextureUnits;
- if ( textureUnit >= capabilities.maxTextures ) {
- console.warn( 'THREE.WebGLRenderer: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
- }
- _usedTextureUnits += 1;
- return textureUnit;
- }
- this.allocTextureUnit = allocTextureUnit;
- // this.setTexture2D = setTexture2D;
- this.setTexture2D = ( function () {
- var warned = false;
- // backwards compatibility: peel texture.texture
- return function setTexture2D( texture, slot ) {
- if ( texture && texture.isWebGLRenderTarget ) {
- if ( ! warned ) {
- console.warn( "THREE.WebGLRenderer.setTexture2D: don't use render targets as textures. Use their .texture property instead." );
- warned = true;
- }
- texture = texture.texture;
- }
- textures.setTexture2D( texture, slot );
- };
- }() );
- this.setTexture = ( function () {
- var warned = false;
- return function setTexture( texture, slot ) {
- if ( ! warned ) {
- console.warn( "THREE.WebGLRenderer: .setTexture is deprecated, use setTexture2D instead." );
- warned = true;
- }
- textures.setTexture2D( texture, slot );
- };
- }() );
- this.setTextureCube = ( function () {
- var warned = false;
- return function setTextureCube( texture, slot ) {
- // backwards compatibility: peel texture.texture
- if ( texture && texture.isWebGLRenderTargetCube ) {
- if ( ! warned ) {
- console.warn( "THREE.WebGLRenderer.setTextureCube: don't use cube render targets as textures. Use their .texture property instead." );
- warned = true;
- }
- texture = texture.texture;
- }
- // currently relying on the fact that WebGLRenderTargetCube.texture is a Texture and NOT a CubeTexture
- // TODO: unify these code paths
- if ( ( texture && texture.isCubeTexture ) ||
- ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
- // CompressedTexture can have Array in image :/
- // this function alone should take care of cube textures
- textures.setTextureCube( texture, slot );
- } else {
- // assumed: texture property of THREE.WebGLRenderTargetCube
- textures.setTextureCubeDynamic( texture, slot );
- }
- };
- }() );
- this.getRenderTarget = function () {
- return _currentRenderTarget;
- };
- this.setRenderTarget = function ( renderTarget ) {
- _currentRenderTarget = renderTarget;
- if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
- textures.setupRenderTarget( renderTarget );
- }
- var framebuffer = null;
- var isCube = false;
- if ( renderTarget ) {
- var __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
- if ( renderTarget.isWebGLRenderTargetCube ) {
- framebuffer = __webglFramebuffer[ renderTarget.activeCubeFace ];
- isCube = true;
- } else {
- framebuffer = __webglFramebuffer;
- }
- _currentViewport.copy( renderTarget.viewport );
- _currentScissor.copy( renderTarget.scissor );
- _currentScissorTest = renderTarget.scissorTest;
- } else {
- _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio );
- _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio );
- _currentScissorTest = _scissorTest;
- }
- if ( _currentFramebuffer !== framebuffer ) {
- _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
- _currentFramebuffer = framebuffer;
- }
- state.viewport( _currentViewport );
- state.scissor( _currentScissor );
- state.setScissorTest( _currentScissorTest );
- if ( isCube ) {
- var textureProperties = properties.get( renderTarget.texture );
- _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + renderTarget.activeCubeFace, textureProperties.__webglTexture, renderTarget.activeMipMapLevel );
- }
- };
- this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
- if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
- console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
- return;
- }
- var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
- if ( framebuffer ) {
- var restore = false;
- if ( framebuffer !== _currentFramebuffer ) {
- _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
- restore = true;
- }
- try {
- var texture = renderTarget.texture;
- var textureFormat = texture.format;
- var textureType = texture.type;
- if ( textureFormat !== RGBAFormat && paramThreeToGL( textureFormat ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
- console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
- return;
- }
- if ( textureType !== UnsignedByteType && paramThreeToGL( textureType ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE ) && // IE11, Edge and Chrome Mac < 52 (#9513)
- ! ( textureType === FloatType && ( extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
- ! ( textureType === HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) {
- console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
- return;
- }
- if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
- // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
- if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
- _gl.readPixels( x, y, width, height, paramThreeToGL( textureFormat ), paramThreeToGL( textureType ), buffer );
- }
- } else {
- console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
- }
- } finally {
- if ( restore ) {
- _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
- }
- }
- }
- };
- // Map three.js constants to WebGL constants
- function paramThreeToGL( p ) {
- var extension;
- if ( p === RepeatWrapping ) return _gl.REPEAT;
- if ( p === ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
- if ( p === MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;
- if ( p === NearestFilter ) return _gl.NEAREST;
- if ( p === NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
- if ( p === NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;
- if ( p === LinearFilter ) return _gl.LINEAR;
- if ( p === LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
- if ( p === LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;
- if ( p === UnsignedByteType ) return _gl.UNSIGNED_BYTE;
- if ( p === UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
- if ( p === UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
- if ( p === UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;
- if ( p === ByteType ) return _gl.BYTE;
- if ( p === ShortType ) return _gl.SHORT;
- if ( p === UnsignedShortType ) return _gl.UNSIGNED_SHORT;
- if ( p === IntType ) return _gl.INT;
- if ( p === UnsignedIntType ) return _gl.UNSIGNED_INT;
- if ( p === FloatType ) return _gl.FLOAT;
- if ( p === HalfFloatType ) {
- extension = extensions.get( 'OES_texture_half_float' );
- if ( extension !== null ) return extension.HALF_FLOAT_OES;
- }
- if ( p === AlphaFormat ) return _gl.ALPHA;
- if ( p === RGBFormat ) return _gl.RGB;
- if ( p === RGBAFormat ) return _gl.RGBA;
- if ( p === LuminanceFormat ) return _gl.LUMINANCE;
- if ( p === LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;
- if ( p === DepthFormat ) return _gl.DEPTH_COMPONENT;
- if ( p === DepthStencilFormat ) return _gl.DEPTH_STENCIL;
- if ( p === AddEquation ) return _gl.FUNC_ADD;
- if ( p === SubtractEquation ) return _gl.FUNC_SUBTRACT;
- if ( p === ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;
- if ( p === ZeroFactor ) return _gl.ZERO;
- if ( p === OneFactor ) return _gl.ONE;
- if ( p === SrcColorFactor ) return _gl.SRC_COLOR;
- if ( p === OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
- if ( p === SrcAlphaFactor ) return _gl.SRC_ALPHA;
- if ( p === OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
- if ( p === DstAlphaFactor ) return _gl.DST_ALPHA;
- if ( p === OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;
- if ( p === DstColorFactor ) return _gl.DST_COLOR;
- if ( p === OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
- if ( p === SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;
- if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
- p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) {
- extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
- if ( extension !== null ) {
- if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
- if ( p === RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
- if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
- if ( p === RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
- }
- }
- if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
- p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
- extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
- if ( extension !== null ) {
- if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
- if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
- if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
- if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
- }
- }
- if ( p === RGB_ETC1_Format ) {
- extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
- if ( extension !== null ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
- }
- if ( p === MinEquation || p === MaxEquation ) {
- extension = extensions.get( 'EXT_blend_minmax' );
- if ( extension !== null ) {
- if ( p === MinEquation ) return extension.MIN_EXT;
- if ( p === MaxEquation ) return extension.MAX_EXT;
- }
- }
- if ( p === UnsignedInt248Type ) {
- extension = extensions.get( 'WEBGL_depth_texture' );
- if ( extension !== null ) return extension.UNSIGNED_INT_24_8_WEBGL;
- }
- return 0;
- }
- }
- export { WebGLRenderer };
|