提交 483196c2 编写于 作者: M Mugen87

WebGLClipping: Refactoring.

上级 662e7e1b
......@@ -149,7 +149,6 @@ function WebGLRenderer( parameters ) {
// clipping
const _clipping = new WebGLClipping();
let _clippingEnabled = false;
let _localClippingEnabled = false;
......@@ -252,7 +251,7 @@ function WebGLRenderer( parameters ) {
let extensions, capabilities, state, info;
let properties, textures, cubemaps, attributes, geometries, objects;
let programCache, materials, renderLists, renderStates;
let programCache, materials, renderLists, renderStates, clipping;
let background, morphtargets, bufferRenderer, indexedBufferRenderer;
......@@ -294,11 +293,11 @@ function WebGLRenderer( parameters ) {
geometries = new WebGLGeometries( _gl, attributes, info, bindingStates );
objects = new WebGLObjects( _gl, geometries, attributes, info );
morphtargets = new WebGLMorphtargets( _gl );
programCache = new WebGLPrograms( _this, cubemaps, extensions, capabilities, bindingStates );
clipping = new WebGLClipping( properties );
programCache = new WebGLPrograms( _this, cubemaps, extensions, capabilities, bindingStates, clipping );
materials = new WebGLMaterials( properties );
renderLists = new WebGLRenderLists( properties );
renderStates = new WebGLRenderStates();
background = new WebGLBackground( _this, cubemaps, state, objects, _premultipliedAlpha );
bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities );
......@@ -1012,7 +1011,7 @@ function WebGLRenderer( parameters ) {
_frustum.setFromProjectionMatrix( _projScreenMatrix );
_localClippingEnabled = this.localClippingEnabled;
_clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
_clippingEnabled = clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
currentRenderList = renderLists.get( scene, camera );
currentRenderList.init();
......@@ -1029,7 +1028,7 @@ function WebGLRenderer( parameters ) {
//
if ( _clippingEnabled === true ) _clipping.beginShadows();
if ( _clippingEnabled === true ) clipping.beginShadows();
const shadowsArray = currentRenderState.state.shadowsArray;
......@@ -1037,7 +1036,7 @@ function WebGLRenderer( parameters ) {
currentRenderState.setupLights( camera );
if ( _clippingEnabled === true ) _clipping.endShadows();
if ( _clippingEnabled === true ) clipping.endShadows();
//
......@@ -1306,7 +1305,7 @@ function WebGLRenderer( parameters ) {
const lightsStateVersion = lights.state.version;
const parameters = programCache.getParameters( material, lights.state, shadowsArray, scene, _clipping.numPlanes, _clipping.numIntersection, object );
const parameters = programCache.getParameters( material, lights.state, shadowsArray, scene, object );
const programCacheKey = programCache.getProgramCacheKey( parameters );
let program = materialProperties.program;
......@@ -1394,9 +1393,9 @@ function WebGLRenderer( parameters ) {
! material.isRawShaderMaterial ||
material.clipping === true ) {
materialProperties.numClippingPlanes = _clipping.numPlanes;
materialProperties.numIntersection = _clipping.numIntersection;
uniforms.clippingPlanes = _clipping.uniform;
materialProperties.numClippingPlanes = clipping.numPlanes;
materialProperties.numIntersection = clipping.numIntersection;
uniforms.clippingPlanes = clipping.uniform;
}
......@@ -1468,9 +1467,7 @@ function WebGLRenderer( parameters ) {
// 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 );
clipping.setState( material, camera, useCache );
}
......@@ -1495,8 +1492,8 @@ function WebGLRenderer( parameters ) {
initMaterial( material, scene, object );
} else if ( materialProperties.numClippingPlanes !== undefined &&
( materialProperties.numClippingPlanes !== _clipping.numPlanes ||
materialProperties.numIntersection !== _clipping.numIntersection ) ) {
( materialProperties.numClippingPlanes !== clipping.numPlanes ||
materialProperties.numIntersection !== clipping.numIntersection ) ) {
initMaterial( material, scene, object );
......
import { Camera } from './../../cameras/Camera';
import { Material } from './../../materials/Material';
import { WebGLProperties } from './WebGLProperties';
export class WebGLClipping {
constructor( properties: WebGLProperties );
uniform: { value: any; needsUpdate: boolean };
/**
......@@ -18,12 +22,9 @@ export class WebGLClipping {
beginShadows(): void;
endShadows(): void;
setState(
planes: any[],
clipIntersection: boolean,
clipShadows: boolean,
material: Material,
camera: Camera,
cache: any,
fromCache: boolean
useCache: boolean
): void;
}
import { Matrix3 } from '../../math/Matrix3.js';
import { Plane } from '../../math/Plane.js';
function WebGLClipping() {
function WebGLClipping( properties ) {
const scope = this;
......@@ -52,7 +52,13 @@ function WebGLClipping() {
};
this.setState = function ( planes, clipIntersection, clipShadows, camera, cache, fromCache ) {
this.setState = function ( material, camera, useCache ) {
const planes = material.clippingPlanes,
clipIntersection = material.clipIntersection,
clipShadows = material.clipShadows;
const materialProperties = properties.get( material );
if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) {
......@@ -75,11 +81,11 @@ function WebGLClipping() {
const nGlobal = renderingShadows ? 0 : numGlobalPlanes,
lGlobal = nGlobal * 4;
let dstArray = cache.clippingState || null;
let dstArray = materialProperties.clippingState || null;
uniform.value = dstArray; // ensure unique state
dstArray = projectPlanes( planes, camera, lGlobal, fromCache );
dstArray = projectPlanes( planes, camera, lGlobal, useCache );
for ( let i = 0; i !== lGlobal; ++ i ) {
......@@ -87,7 +93,7 @@ function WebGLClipping() {
}
cache.clippingState = dstArray;
materialProperties.clippingState = dstArray;
this.numIntersection = clipIntersection ? this.numPlanes : 0;
this.numPlanes += nGlobal;
......
......@@ -3,12 +3,14 @@ import { WebGLProgram } from './WebGLProgram';
import { WebGLCapabilities } from './WebGLCapabilities';
import { WebGLCubeMaps } from './WebGLCubeMaps';
import { WebGLExtensions } from './WebGLExtensions';
import { WebGLClipping } from './WebGLClipping';
import { WebGLBindingStates } from './WebGLBindingStates';
import { Material } from './../../materials/Material';
import { Scene } from './../../scenes/Scene';
export class WebGLPrograms {
constructor( renderer: WebGLRenderer, cubemaps: WebGLCubeMaps, extensions: WebGLExtensions, capabilities: WebGLCapabilities );
constructor( renderer: WebGLRenderer, cubemaps: WebGLCubeMaps, extensions: WebGLExtensions, capabilities: WebGLCapabilities, bindingStates: WebGLBindingStates, clipping: WebGLClipping );
programs: WebGLProgram[];
......@@ -17,8 +19,6 @@ export class WebGLPrograms {
lights: any,
shadows: object[],
scene: Scene,
nClipPlanes: number,
nClipIntersection: number,
object: any
): any;
getProgramCacheKey( parameters: any ): string;
......
......@@ -3,7 +3,7 @@ import { WebGLProgram } from './WebGLProgram.js';
import { ShaderLib } from '../shaders/ShaderLib.js';
import { UniformsUtils } from '../shaders/UniformsUtils.js';
function WebGLPrograms( renderer, cubemaps, extensions, capabilities, bindingStates ) {
function WebGLPrograms( renderer, cubemaps, extensions, capabilities, bindingStates, clipping ) {
const programs = [];
......@@ -108,7 +108,7 @@ function WebGLPrograms( renderer, cubemaps, extensions, capabilities, bindingSta
}
function getParameters( material, lights, shadows, scene, nClipPlanes, nClipIntersection, object ) {
function getParameters( material, lights, shadows, scene, object ) {
const fog = scene.fog;
const environment = material.isMeshStandardMaterial ? scene.environment : null;
......@@ -240,8 +240,8 @@ function WebGLPrograms( renderer, cubemaps, extensions, capabilities, bindingSta
numPointLightShadows: lights.pointShadowMap.length,
numSpotLightShadows: lights.spotShadowMap.length,
numClippingPlanes: nClipPlanes,
numClipIntersection: nClipIntersection,
numClippingPlanes: clipping.numPlanes,
numClipIntersection: clipping.numIntersection,
dithering: material.dithering,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册