diff --git a/cocos/3d/assets/effect-asset.ts b/cocos/3d/assets/effect-asset.ts index f3e58736d2..1accdbacab 100644 --- a/cocos/3d/assets/effect-asset.ts +++ b/cocos/3d/assets/effect-asset.ts @@ -2,7 +2,6 @@ import { Asset } from '../../assets/asset'; import { ccclass, property } from '../../core/data/class-decorator'; import { GFXDynamicState, GFXPrimitiveMode, GFXType } from '../../gfx/define'; import { GFXBlendState, GFXDepthStencilState, GFXRasterizerState } from '../../gfx/pipeline-state'; -import { IGFXSamplerInfo } from '../../gfx/sampler'; import { RenderPassStage } from '../../pipeline/define'; import { programLib } from '../../renderer/core/program-lib'; @@ -20,6 +19,7 @@ export interface IPassStates { depthStencilState?: GFXDepthStencilState; blendState?: GFXBlendState; dynamics?: GFXDynamicState[]; + customizations?: string[]; } export interface IPassInfo extends IPassStates { program: string; // auto-generated diff --git a/cocos/3d/builtin/init.ts b/cocos/3d/builtin/init.ts index 99f2fa6750..13fd989b43 100644 --- a/cocos/3d/builtin/init.ts +++ b/cocos/3d/builtin/init.ts @@ -4,7 +4,10 @@ import { ImageAsset } from '../../assets/image-asset'; import { Texture2D } from '../../assets/texture-2d'; import { Rect } from '../../core/value-types'; import { GFXDevice } from '../../gfx/device'; +import { Model } from '../../renderer'; +import { customizationManager } from '../../renderer/scene/customization-manager'; import { TextureCube } from '../assets/texture-cube'; +import { aabb } from '../geom-utils'; import effects from './effects'; class BuiltinResMgr { @@ -165,6 +168,26 @@ class BuiltinResMgr { defaultParticleMtl._uuid = 'default-particle-material'; defaultParticleMtl.initialize({ effectName: 'builtin-particle' }); resources[defaultParticleMtl._uuid] = defaultParticleMtl; + + // customization for special effects + const tmp = aabb.create(); + customizationManager.register('bounds-merge-shadow', { + onAttach: (m: Model) => { + const update = Model.prototype.updateTransform.bind(m); + const light = m.scene.mainLight; + const shadow = m.scene.planarShadow; + m.updateTransform = () => { + update(); + const bounds = m.worldBounds; + if (!m.node.hasChanged && !light.node.hasChanged || !bounds) { return; } + bounds.transform(shadow.matLight, null, null, null, tmp); + aabb.merge(bounds, bounds, tmp); + }; + }, + onDetach: (m: Model) => { + m.updateTransform = Model.prototype.updateTransform.bind(m); + }, + }); } public get (uuid: string) { diff --git a/cocos/3d/framework/sphere-light-component.ts b/cocos/3d/framework/sphere-light-component.ts index f51c2299c2..77274a160c 100644 --- a/cocos/3d/framework/sphere-light-component.ts +++ b/cocos/3d/framework/sphere-light-component.ts @@ -45,7 +45,9 @@ export class SphereLightComponent extends LightComponent { protected _type = LightType.SPHERE; protected _light: SphereLight | null = null; - @property + @property({ + unit: 'lm', + }) get luminousPower () { return this._luminance * nt2lm(this._size); } @@ -55,7 +57,9 @@ export class SphereLightComponent extends LightComponent { if (this._light) { this._light.setLuminousPower(val, this._size); } } - @property + @property({ + unit: 'cd', + }) get luminance () { return this._luminance; } @@ -110,7 +114,7 @@ export class SphereLightComponent extends LightComponent { console.warn('we don\'t support this many lights in forward pipeline.'); return; } - this.luminance = this._luminance; + this._light.luminance = this._luminance; this.size = this._size; this.range = this._range; super._createLight(scene); diff --git a/cocos/3d/framework/spot-light-component.ts b/cocos/3d/framework/spot-light-component.ts index a6df578c30..67745c2b5e 100644 --- a/cocos/3d/framework/spot-light-component.ts +++ b/cocos/3d/framework/spot-light-component.ts @@ -131,8 +131,8 @@ export class SpotLightComponent extends LightComponent { console.warn('we don\'t support this many lights in forward pipeline.'); return; } + this._light.luminance = this._luminance; this.size = this._size; - this.luminance = this._luminance; this.range = this._range; this.spotAngle = this._spotAngle; super._createLight(scene); diff --git a/cocos/3d/geom-utils/aabb.ts b/cocos/3d/geom-utils/aabb.ts index d702c33402..4883b6867f 100644 --- a/cocos/3d/geom-utils/aabb.ts +++ b/cocos/3d/geom-utils/aabb.ts @@ -3,6 +3,8 @@ import enums from './enums'; const _v3_tmp = vec3.create(); const _v3_tmp2 = vec3.create(); +const _v3_tmp3 = vec3.create(); +const _v3_tmp4 = vec3.create(); const _m3_tmp = mat3.create(); // https://zeuxcg.org/2010/10/17/aabb-from-obb-with-component-wise-abs/ @@ -88,6 +90,16 @@ export default class aabb { return out; } + public static merge (out: aabb, a: aabb, b: aabb) { + vec3.sub(_v3_tmp, a.center, a.halfExtents); + vec3.sub(_v3_tmp2, b.center, b.halfExtents); + vec3.add(_v3_tmp3, a.center, a.halfExtents); + vec3.add(_v3_tmp4, b.center, b.halfExtents); + vec3.max(_v3_tmp4, _v3_tmp3, _v3_tmp4); + vec3.min(_v3_tmp3, _v3_tmp, _v3_tmp2); + return aabb.fromPoints(out, _v3_tmp3, _v3_tmp4); + } + public center: vec3; public halfExtents: vec3; protected _type: number = enums.SHAPE_AABB; @@ -109,18 +121,26 @@ export default class aabb { /** * Transform this shape - * @param {mat4} m the transform matrix - * @param {vec3} pos the position part of the transform - * @param {quat} rot the rotation part of the transform - * @param {vec3} scale the scale part of the transform - * @param {aabb} [out] the target shape + * @param m - the transform matrix + * @param pos - the position part of the transform + * @param rot - the rotation part of the transform + * @param scale - the scale part of the transform + * @param out - the target shape */ - public transform (m, pos, rot, scale, out) { + public transform (m, pos, rot, scale, out?: aabb) { if (!out) { out = this; } vec3.transformMat4(out.center, this.center, m); transform_extent_m4(out.halfExtents, this.halfExtents, m); } + public clone () { + return aabb.clone(this); + } + + public copy (a: aabb) { + return aabb.copy(this, a); + } + get type (){ return this._type; } diff --git a/cocos/3d/geom-utils/sphere.ts b/cocos/3d/geom-utils/sphere.ts index 929ae8a3be..4f688dd562 100644 --- a/cocos/3d/geom-utils/sphere.ts +++ b/cocos/3d/geom-utils/sphere.ts @@ -84,6 +84,14 @@ export default class sphere { this.r = r; } + public clone () { + return sphere.clone(this); + } + + public copy (a: sphere) { + return sphere.copy(this, a); + } + /** * Get the bounding points of this shape * @param {vec3} minPos diff --git a/cocos/core/data/class.js b/cocos/core/data/class.js index cfac3fc81d..3321c8d8f4 100644 --- a/cocos/core/data/class.js +++ b/cocos/core/data/class.js @@ -1160,12 +1160,14 @@ function parseAttributes (cls, attrs, className, propName, usedInGetter) { //parseSimpleAttr('preventDeferredLoad', 'boolean'); if (CC_DEV) { parseSimpleAttr('displayName', 'string'); + parseSimpleAttr('displayOrder', 'number'); parseSimpleAttr('multiline', 'boolean'); if (attrs.readonly) { (attrsProto || getAttrsProto())[attrsProtoKey + 'readonly'] = true; } parseSimpleAttr('tooltip', 'string'); parseSimpleAttr('slide', 'boolean'); + parseSimpleAttr('unit', 'string'); } if (attrs.url) { diff --git a/cocos/pipeline/define.ts b/cocos/pipeline/define.ts index dd471db082..d423056a86 100644 --- a/cocos/pipeline/define.ts +++ b/cocos/pipeline/define.ts @@ -88,6 +88,8 @@ export class UBOShadow { { name: 'cc_shadowColor', type: GFXType.FLOAT4, count: 1 }, ], }; + + public view: Float32Array = new Float32Array(UBOShadow.COUNT); } export const localBindingsDesc: Map = new Map(); diff --git a/cocos/pipeline/forward/forward-pipeline.ts b/cocos/pipeline/forward/forward-pipeline.ts index 5aeaefb592..d98c2bd0aa 100644 --- a/cocos/pipeline/forward/forward-pipeline.ts +++ b/cocos/pipeline/forward/forward-pipeline.ts @@ -16,8 +16,8 @@ import { SMAAEdgeFlow } from '../ppfx/smaa-flow'; import { ToneMapFlow } from '../ppfx/tonemap-flow'; import { IRenderPipelineInfo, RenderPipeline } from '../render-pipeline'; import { RenderView } from '../render-view'; -import { ForwardFlow } from './forward-flow'; import { UIFlow } from '../ui/ui-flow'; +import { ForwardFlow } from './forward-flow'; export enum ForwardFlowPriority { FORWARD = 0, diff --git a/cocos/pipeline/render-pipeline.ts b/cocos/pipeline/render-pipeline.ts index 550c26eadf..482f592a58 100644 --- a/cocos/pipeline/render-pipeline.ts +++ b/cocos/pipeline/render-pipeline.ts @@ -184,7 +184,7 @@ export abstract class RenderPipeline { protected _quadVB: GFXBuffer | null = null; protected _quadIB: GFXBuffer | null = null; protected _quadIA: GFXInputAssembler | null = null; - protected _defaultUboGlobal: UBOGlobal | null = null; + protected _defaultUboGlobal: UBOGlobal = new UBOGlobal(); protected _globalBindings: Map = new Map(); protected _defaultTex: GFXTexture | null = null; protected _defaultTexView: GFXTextureView | null = null; @@ -212,10 +212,11 @@ export abstract class RenderPipeline { view.camera.update(); - this.sceneCulling(view); - + // update UBO first for culling may depend on some of them this.updateUBOs(view); + this.sceneCulling(view); + for (const flow of view.flows) { flow.render(view); } @@ -709,8 +710,6 @@ export abstract class RenderPipeline { return false; } - this._defaultUboGlobal = new UBOGlobal(); - this._globalBindings.set(UBOGlobal.BLOCK.name, { type: GFXBindingType.UNIFORM_BUFFER, blockInfo: UBOGlobal.BLOCK, @@ -770,58 +769,58 @@ export abstract class RenderPipeline { _vec4Array[1] = 0.0; _vec4Array[2] = 0.0; _vec4Array[3] = 0.0; - this._defaultUboGlobal!.view.set(_vec4Array, UBOGlobal.TIME_OFFSET); + this._defaultUboGlobal.view.set(_vec4Array, UBOGlobal.TIME_OFFSET); _vec4Array[0] = device.width; _vec4Array[1] = device.height; _vec4Array[2] = 1.0 / _vec4Array[0]; _vec4Array[3] = 1.0 / _vec4Array[1]; - this._defaultUboGlobal!.view.set(_vec4Array, UBOGlobal.SCREEN_SIZE_OFFSET); + this._defaultUboGlobal.view.set(_vec4Array, UBOGlobal.SCREEN_SIZE_OFFSET); _vec4Array[0] = camera.width / this._shadingTexWidth; _vec4Array[1] = camera.height / this._shadingTexHeight; _vec4Array[2] = 1.0 / _vec4Array[0]; _vec4Array[3] = 1.0 / _vec4Array[1]; - this._defaultUboGlobal!.view.set(_vec4Array, UBOGlobal.SCREEN_SCALE_OFFSET); + this._defaultUboGlobal.view.set(_vec4Array, UBOGlobal.SCREEN_SCALE_OFFSET); _vec4Array[0] = this._shadingTexWidth; _vec4Array[1] = this._shadingTexHeight; _vec4Array[2] = 1.0 / _vec4Array[0]; _vec4Array[3] = 1.0 / _vec4Array[1]; - this._defaultUboGlobal!.view.set(_vec4Array, UBOGlobal.NATIVE_SIZE_OFFSET); + this._defaultUboGlobal.view.set(_vec4Array, UBOGlobal.NATIVE_SIZE_OFFSET); mat4.array(_mat4Array, camera.matView); - this._defaultUboGlobal!.view.set(_mat4Array, UBOGlobal.MAT_VIEW_OFFSET); + this._defaultUboGlobal.view.set(_mat4Array, UBOGlobal.MAT_VIEW_OFFSET); mat4.invert(_outMat, camera.matView); mat4.array(_mat4Array, _outMat); - this._defaultUboGlobal!.view.set(_mat4Array, UBOGlobal.MAT_VIEW_INV_OFFSET); + this._defaultUboGlobal.view.set(_mat4Array, UBOGlobal.MAT_VIEW_INV_OFFSET); mat4.array(_mat4Array, camera.matProj); - this._defaultUboGlobal!.view.set(_mat4Array, UBOGlobal.MAT_PROJ_OFFSET); + this._defaultUboGlobal.view.set(_mat4Array, UBOGlobal.MAT_PROJ_OFFSET); mat4.invert(_outMat, camera.matProj); mat4.array(_mat4Array, _outMat); - this._defaultUboGlobal!.view.set(_mat4Array, UBOGlobal.MAT_PROJ_INV_OFFSET); + this._defaultUboGlobal.view.set(_mat4Array, UBOGlobal.MAT_PROJ_INV_OFFSET); mat4.array(_mat4Array, camera.matViewProj); - this._defaultUboGlobal!.view.set(_mat4Array, UBOGlobal.MAT_VIEW_PROJ_OFFSET); + this._defaultUboGlobal.view.set(_mat4Array, UBOGlobal.MAT_VIEW_PROJ_OFFSET); mat4.array(_mat4Array, camera.matViewProjInv); - this._defaultUboGlobal!.view.set(_mat4Array, UBOGlobal.MAT_VIEW_PROJ_INV_OFFSET); + this._defaultUboGlobal.view.set(_mat4Array, UBOGlobal.MAT_VIEW_PROJ_INV_OFFSET); vec3.array(_vec4Array, camera.position); _vec4Array[3] = 1.0; - this._defaultUboGlobal!.view.set(_vec4Array, UBOGlobal.CAMERA_POS_OFFSET); + this._defaultUboGlobal.view.set(_vec4Array, UBOGlobal.CAMERA_POS_OFFSET); _vec4Array[0] = camera.exposure; _vec4Array[1] = _vec4Array[0] * this._fpScaleInv; _vec4Array[2] = this._isHDR ? 1.0 : 0.0; _vec4Array[3] = 1.0 / _vec4Array[1]; - this._defaultUboGlobal!.view.set(_vec4Array, UBOGlobal.EXPOSURE_OFFSET); + this._defaultUboGlobal.view.set(_vec4Array, UBOGlobal.EXPOSURE_OFFSET); vec3.array(_vec4Array, mainLight.direction); - this._defaultUboGlobal!.view.set(_vec4Array, UBOGlobal.MAIN_LIT_DIR_OFFSET); + this._defaultUboGlobal.view.set(_vec4Array, UBOGlobal.MAIN_LIT_DIR_OFFSET); if (mainLight.enabled) { vec3.array(_vec4Array, mainLight.color); @@ -835,17 +834,17 @@ export abstract class RenderPipeline { } else { _vec4Array.set(_vec4ArrayZero); } - this._defaultUboGlobal!.view.set(_vec4Array, UBOGlobal.MAIN_LIT_COLOR_OFFSET); + this._defaultUboGlobal.view.set(_vec4Array, UBOGlobal.MAIN_LIT_COLOR_OFFSET); _vec4Array.set(ambient.skyColor); _vec4Array[3] = ambient.skyIllum; - this._defaultUboGlobal!.view.set(_vec4Array, UBOGlobal.AMBIENT_SKY_OFFSET); + this._defaultUboGlobal.view.set(_vec4Array, UBOGlobal.AMBIENT_SKY_OFFSET); _vec4Array.set(ambient.groundAlbedo); - this._defaultUboGlobal!.view.set(_vec4Array, UBOGlobal.AMBIENT_GROUND_OFFSET); + this._defaultUboGlobal.view.set(_vec4Array, UBOGlobal.AMBIENT_GROUND_OFFSET); // update ubos - this._globalBindings.get(UBOGlobal.BLOCK.name)!.buffer!.update(this._defaultUboGlobal!.view.buffer); + this._globalBindings.get(UBOGlobal.BLOCK.name)!.buffer!.update(this._defaultUboGlobal.view.buffer); const planarShadow = scene.planarShadow; planarShadow.updateDirLight(scene.mainLight); @@ -869,11 +868,10 @@ export abstract class RenderPipeline { continue; } - model._updateTransform(); + model.updateTransform(); // frustum culling if (model.worldBounds && !intersect.aabb_frustum(model.worldBounds, camera.frustum)) { - // console.log('model is not in view frustum.'); continue; } diff --git a/cocos/renderer/core/pass.ts b/cocos/renderer/core/pass.ts index b0f9364066..eb92168dd0 100644 --- a/cocos/renderer/core/pass.ts +++ b/cocos/renderer/core/pass.ts @@ -114,6 +114,7 @@ export class Pass { protected _rs: GFXRasterizerState = new GFXRasterizerState(); protected _dynamicStates: GFXDynamicState[] = []; protected _dynamics: IPassDynamics = {}; + protected _customizations: string[] = []; protected _handleMap: Record = {}; protected _blocks: IBlock[] = []; protected _shaderInfo: IShaderInfo | null = null; @@ -294,6 +295,7 @@ export class Pass { public createPipelineState (): GFXPipelineState | null { if ((!this._renderPass || !this._shader || !this._bindings.length) && !this.tryCompile()) { + console.warn(`pass resources not complete, create PSO failed`); return null; } // bind resources @@ -362,6 +364,7 @@ export class Pass { if (info.primitive !== undefined) { this._primitive = info.primitive; } if (info.stage !== undefined) { this._stage = info.stage; } if (info.dynamics !== undefined) { this._dynamicStates = info.dynamics; } + if (info.customizations) { this._customizations = info.customizations; } const bs = this._bs; if (info.blendState) { @@ -387,6 +390,7 @@ export class Pass { get depthStencilState () { return this._dss; } get rasterizerState () { return this._rs; } get dynamics () { return this._dynamics; } + get customizations () { return this._customizations; } } const serializeBlendState = (bs: GFXBlendState) => { diff --git a/cocos/renderer/models/skinning-model.ts b/cocos/renderer/models/skinning-model.ts index 85c28adb1f..f2bc0ea78b 100644 --- a/cocos/renderer/models/skinning-model.ts +++ b/cocos/renderer/models/skinning-model.ts @@ -7,9 +7,9 @@ import { mat4 } from '../../core/vmath'; import { GFXBuffer } from '../../gfx/buffer'; import { GFXBufferUsageBit, GFXMemoryUsageBit } from '../../gfx/define'; import { GFXFeature } from '../../gfx/device'; -import { GFXPipelineState } from '../../gfx/pipeline-state'; import { UBOSkinning, UNIFORM_JOINTS_TEXTURE } from '../../pipeline/define'; import { Node } from '../../scene-graph/node'; +import { Pass } from '../core/pass'; import { samplerLib } from '../core/sampler-lib'; import { Model } from '../scene/model'; import { RenderScene } from '../scene/render-scene'; @@ -89,8 +89,8 @@ export class SkinningModel extends Model { } } - protected _onCreatePSO (pso: GFXPipelineState) { - super._onCreatePSO(pso); + protected _doCreatePSO (pass: Pass) { + const pso = super._doCreatePSO(pass); pso.pipelineLayout.layouts[0].bindBuffer(UBOSkinning.BLOCK.binding, this._skinningUBO); if (this._jointStorage && isTextureStorage(this._jointStorage)) { const jointTexture = this._jointStorage.texture; @@ -101,6 +101,7 @@ export class SkinningModel extends Model { pso.pipelineLayout.layouts[0].bindSampler(UNIFORM_JOINTS_TEXTURE.binding, sampler); } } + return pso; } private _destroyJointStorage () { diff --git a/cocos/renderer/scene/customization-manager.ts b/cocos/renderer/scene/customization-manager.ts new file mode 100644 index 0000000000..cb2c9f7613 --- /dev/null +++ b/cocos/renderer/scene/customization-manager.ts @@ -0,0 +1,57 @@ +// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. +import { Model } from './model'; + +export type CustomCallback = (m: Model) => void; +export interface ICustomization { + onAttach?: CustomCallback; + onDetach?: CustomCallback; +} + +class Customization { + protected _onAttach?: CustomCallback; + protected _onDetach?: CustomCallback; + protected _models: Record = {}; + + constructor (info: ICustomization) { + this._onAttach = info.onAttach; + this._onDetach = info.onDetach; + } + + public attach (model: Model) { + const models = this._models; + const id = model.id; + if (models[id]) { models[id]++; return; } + if (this._onAttach) { this._onAttach(model); } + models[id] = 1; + } + + public detach (model: Model) { + const models = this._models; + const id = model.id; + if (!models[id] || --models[id] > 0) { return; } + if (this._onDetach) { this._onDetach(model); } + } +} + +class CustomizationManager { + protected _customs: Record = {}; + + public register (name: string, info: ICustomization) { + this._customs[name] = new Customization(info); + } + + public attach (name: string, model: Model) { + const cus = this._customs[name]; + if (!cus) { console.warn(`no customization named '${name}'`); return; } + cus.attach(model); + } + + public detach (name: string, model: Model) { + const cus = this._customs[name]; + if (!cus) { console.warn(`no customization named '${name}'`); return; } + cus.detach(model); + } +} + +export const customizationManager = new CustomizationManager(); +cc.customizationManager = customizationManager; diff --git a/cocos/renderer/scene/model.ts b/cocos/renderer/scene/model.ts index eaf18cfb5c..9df10fcb7d 100644 --- a/cocos/renderer/scene/model.ts +++ b/cocos/renderer/scene/model.ts @@ -6,14 +6,16 @@ import Pool from '../../3d/memop/pool'; import { Vec3 } from '../../core/value-types'; import { mat4 } from '../../core/vmath'; import { GFXBuffer } from '../../gfx/buffer'; -import { GFXBufferUsageBit, GFXMemoryUsageBit, GFXBindingType, GFXGetTypeSize } from '../../gfx/define'; +import { GFXBindingType, GFXBufferUsageBit, GFXGetTypeSize, GFXMemoryUsageBit } from '../../gfx/define'; import { GFXDevice } from '../../gfx/device'; import { GFXPipelineState } from '../../gfx/pipeline-state'; +import { GFXUniformBlock } from '../../gfx/shader'; +import { IInternalBindingInst, UBOForwardLight, UBOLocal } from '../../pipeline/define'; import { Node } from '../../scene-graph/node'; +import { Pass } from '../core/pass'; +import { customizationManager } from './customization-manager'; import { RenderScene } from './render-scene'; import { SubModel } from './submodel'; -import { UBOLocal, IInternalBindingInst, UBOForwardLight, IInternalBindingDesc } from '../../pipeline/define'; -import { GFXUniformBlock } from '../../gfx/shader'; const _temp_floatx16 = new Float32Array(16); const _temp_mat4 = mat4.create(); @@ -173,14 +175,14 @@ export class Model { return this._subModels[idx]; } - public _updateTransform () { + public updateTransform () { if (this._node && this._node.hasChanged) { this._node.updateWorldTransformFull(); if (this._modelBounds) { this._modelBounds.transform( // @ts-ignore this._node._mat, this._node._pos, this._node._rot, this._node._scale, - this._worldBounds); + this._worldBounds!); } } } @@ -265,23 +267,27 @@ export class Model { protected createPipelineState (mat: Material): GFXPipelineState[] { const ret = new Array(mat.passes.length); for (let i = 0; i < ret.length; i++) { - ret[i] = mat.passes[i].createPipelineState()!; - this._onCreatePSO(ret[i]); + ret[i] = this._doCreatePSO(mat.passes[i]); } return ret; } protected destroyPipelineState (mat: Material, pso: GFXPipelineState[]) { for (let i = 0; i < mat.passes.length; i++) { - mat.passes[i].destroyPipelineState(pso[i]); + const pass = mat.passes[i]; + pass.destroyPipelineState(pso[i]); + for (const cus of pass.customizations) { customizationManager.detach(cus, this); } } } - protected _onCreatePSO (pso: GFXPipelineState) { + protected _doCreatePSO (pass: Pass) { + for (const cus of pass.customizations) { customizationManager.attach(cus, this); } + const pso = pass.createPipelineState()!; pso.pipelineLayout.layouts[0].bindBuffer(UBOLocal.BLOCK.binding, this._localBindings.get(UBOLocal.BLOCK.name)!.buffer!); if (this._localBindings.has(UBOForwardLight.BLOCK.name)) { pso.pipelineLayout.layouts[0].bindBuffer(UBOForwardLight.BLOCK.binding, this._localBindings.get(UBOForwardLight.BLOCK.name)!.buffer!); } + return pso; } protected onSetLocalBindings (mat: Material) { diff --git a/cocos/renderer/scene/planar-shadow.ts b/cocos/renderer/scene/planar-shadow.ts index f4c2e12a06..6ea15674b4 100644 --- a/cocos/renderer/scene/planar-shadow.ts +++ b/cocos/renderer/scene/planar-shadow.ts @@ -1,5 +1,5 @@ -import { Color, Quat, Vec3 } from '../../core/value-types'; -import { color4, vec3 } from '../../core/vmath'; +import { Color, Mat4, Quat, Vec3 } from '../../core/value-types'; +import { color4, mat4, vec3 } from '../../core/vmath'; import { UBOShadow } from '../../pipeline/define'; import { DirectionalLight } from './directional-light'; import { RenderScene } from './render-scene'; @@ -29,6 +29,10 @@ export class PlanarShadow { color4.array(this._data, color, UBOShadow.SHADOW_COLOR_OFFSET); } + get matLight () { + return this._matLight; + } + get data () { return this._data; } @@ -36,6 +40,7 @@ export class PlanarShadow { protected _scene: RenderScene; protected _normal = new Vec3(0, 1, 0); protected _distance = 0; + protected _matLight = new Mat4(); protected _data = Float32Array.from([ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, // matLightPlaneProj 0.3, 0.3, 0.3, 1.0, // shadowColor @@ -52,49 +57,52 @@ export class PlanarShadow { const NdL = vec3.dot(n, _v3); const lx = _v3.x, ly = _v3.y, lz = _v3.z; const nx = n.x, ny = n.y, nz = n.z; - const m = this._data; - m[0] = NdL - d - lx * nx; - m[1] = -ly * nx; - m[2] = -lz * nx; - m[3] = -nx; - m[4] = -lx * ny; - m[5] = NdL - d - ly * ny; - m[6] = -lz * ny; - m[7] = -ny; - m[8] = -lx * nz; - m[9] = -ly * nz; - m[10] = NdL - d - lz * nz; - m[11] = -nz; - m[12] = lx * d; - m[13] = ly * d; - m[14] = lz * d; - m[15] = NdL; + const m = this._matLight; + m.m00 = NdL - d - lx * nx; + m.m01 = -ly * nx; + m.m02 = -lz * nx; + m.m03 = -nx; + m.m04 = -lx * ny; + m.m05 = NdL - d - ly * ny; + m.m06 = -lz * ny; + m.m07 = -ny; + m.m08 = -lx * nz; + m.m09 = -ly * nz; + m.m10 = NdL - d - lz * nz; + m.m11 = -nz; + m.m12 = lx * d; + m.m13 = ly * d; + m.m14 = lz * d; + m.m15 = NdL; + mat4.array(this.data, this._matLight); } public updateDirLight (light: DirectionalLight) { + if (!light.node.hasChanged) { return; } light.node.getWorldRotation(_qt); vec3.transformQuat(_v3, _forward, _qt); const n = this._normal, d = this._distance; const NdL = vec3.dot(n, _v3), scale = 1 / NdL; const lx = _v3.x * scale, ly = _v3.y * scale, lz = _v3.z * scale; const nx = n.x, ny = n.y, nz = n.z; - const m = this._data; - m[0] = 1 - nx * lx; - m[1] = -nx * ly; - m[2] = -nx * lz; - m[3] = 0; - m[4] = -ny * lx; - m[5] = 1 - ny * ly; - m[6] = -ny * lz; - m[7] = 0; - m[8] = -nz * lx; - m[9] = -nz * ly; - m[10] = 1 - nz * lz; - m[11] = 0; - m[12] = lx * d; - m[13] = ly * d; - m[14] = lz * d; - m[15] = 1; + const m = this._matLight; + m.m00 = 1 - nx * lx; + m.m01 = -nx * ly; + m.m02 = -nx * lz; + m.m03 = 0; + m.m04 = -ny * lx; + m.m05 = 1 - ny * ly; + m.m06 = -ny * lz; + m.m07 = 0; + m.m08 = -nz * lx; + m.m09 = -nz * ly; + m.m10 = 1 - nz * lz; + m.m11 = 0; + m.m12 = lx * d; + m.m13 = ly * d; + m.m14 = lz * d; + m.m15 = 1; + mat4.array(this.data, this._matLight, UBOShadow.MAT_LIGHT_PLANE_PROJ_OFFSET); } // tslint:enable: one-variable-per-declaration } diff --git a/cocos/renderer/ui/ui-batch-model.ts b/cocos/renderer/ui/ui-batch-model.ts index ec4f5384c9..997b1117d3 100644 --- a/cocos/renderer/ui/ui-batch-model.ts +++ b/cocos/renderer/ui/ui-batch-model.ts @@ -15,7 +15,7 @@ export class UIBatchModel extends Model { this._subModel = new UISubModel(); } - public _updateTransform () { + public updateTransform () { } public updateUBOs () {