mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
Remove the dependency of the pipeline on the model. (#7207)
This commit is contained in:
@@ -8,9 +8,7 @@ import { IRenderFlowInfo, RenderFlow } from '../render-flow';
|
||||
import { RenderView } from '../render-view';
|
||||
import { ForwardFlowPriority } from './enum';
|
||||
import { ForwardStage } from './forward-stage';
|
||||
import { sceneCulling } from './scene-culling';
|
||||
import { ForwardPipeline } from './forward-pipeline';
|
||||
import { RenderAdditiveLightQueue } from '../render-additive-light-queue';
|
||||
import { RenderPipeline } from '../render-pipeline';
|
||||
/**
|
||||
* @en The forward flow in forward render pipeline
|
||||
@@ -44,8 +42,6 @@ export class ForwardFlow extends RenderFlow {
|
||||
|
||||
public render (view: RenderView) {
|
||||
const pipeline = this._pipeline as ForwardPipeline;
|
||||
view.camera.update();
|
||||
sceneCulling(pipeline, view);
|
||||
pipeline.updateUBOs(view);
|
||||
super.render(view);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import { Ambient } from '../../renderer/scene/ambient';
|
||||
import { Skybox } from '../../renderer/scene/skybox';
|
||||
import { PlanarShadows } from '../../renderer/scene/planar-shadows';
|
||||
import { Shadow } from '../../renderer/scene/shadow';
|
||||
import { sceneCulling } from './scene-culling';
|
||||
|
||||
const matShadowView = new Mat4();
|
||||
const matShadowViewProj = new Mat4();
|
||||
@@ -123,6 +124,16 @@ export class ForwardPipeline extends RenderPipeline {
|
||||
return true;
|
||||
}
|
||||
|
||||
public render (views: RenderView[]) {
|
||||
for (let i = 0; i < views.length; i++) {
|
||||
const view = views[i];
|
||||
sceneCulling(this, view);
|
||||
for (let j = 0; j < view.flows.length; j++) {
|
||||
view.flows[j].render(view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public getRenderPass (clearFlags: GFXClearFlag): GFXRenderPass {
|
||||
let renderPass = this._renderPasses.get(clearFlags);
|
||||
if (renderPass) { return renderPass; }
|
||||
|
||||
@@ -3,7 +3,6 @@ import { Model, Camera } from '../../renderer';
|
||||
import { Layers } from '../../scene-graph';
|
||||
import { Vec3} from '../../math';
|
||||
import { SKYBOX_FLAG } from '../../renderer';
|
||||
import { legacyCC } from '../../global-exports';
|
||||
import { ForwardPipeline } from './forward-pipeline';
|
||||
import { RenderView } from '../render-view';
|
||||
import { Pool } from '../../memop';
|
||||
@@ -49,7 +48,6 @@ export function sceneCulling (pipeline: ForwardPipeline, view: RenderView) {
|
||||
const mainLight = scene.mainLight;
|
||||
const planarShadows = pipeline.planarShadows;
|
||||
if (mainLight) {
|
||||
mainLight.update();
|
||||
if (planarShadows.enabled) {
|
||||
planarShadows.updateDirLight(mainLight);
|
||||
}
|
||||
@@ -60,7 +58,6 @@ export function sceneCulling (pipeline: ForwardPipeline, view: RenderView) {
|
||||
}
|
||||
|
||||
const models = scene.models;
|
||||
const stamp = legacyCC.director.getTotalFrames();
|
||||
|
||||
for (let i = 0; i < models.length; i++) {
|
||||
const model = models[i];
|
||||
@@ -71,18 +68,14 @@ export function sceneCulling (pipeline: ForwardPipeline, view: RenderView) {
|
||||
if (vis) {
|
||||
if ((model.node && (view.visibility === model.node.layer)) ||
|
||||
view.visibility === model.visFlags) {
|
||||
model.updateTransform(stamp);
|
||||
model.updateUBOs(stamp);
|
||||
renderObjects.push(getRenderObject(model, camera));
|
||||
}
|
||||
} else {
|
||||
if (model.node && ((view.visibility & model.node.layer) === model.node.layer) ||
|
||||
(view.visibility & model.visFlags)) {
|
||||
model.updateTransform(stamp);
|
||||
|
||||
// shadow render Object
|
||||
if (model.castShadow) {
|
||||
model.updateUBOs(stamp);
|
||||
shadowObjects.push(getCastShadowRenderObject(model, camera));
|
||||
}
|
||||
|
||||
@@ -91,7 +84,6 @@ export function sceneCulling (pipeline: ForwardPipeline, view: RenderView) {
|
||||
continue;
|
||||
}
|
||||
|
||||
model.updateUBOs(stamp);
|
||||
renderObjects.push(getRenderObject(model, camera));
|
||||
}
|
||||
}
|
||||
@@ -99,6 +91,6 @@ export function sceneCulling (pipeline: ForwardPipeline, view: RenderView) {
|
||||
}
|
||||
|
||||
if (planarShadows.enabled) {
|
||||
planarShadows.updateShadowList(scene, camera.frustum, stamp, (camera.visibility & Layers.BitMask.DEFAULT) !== 0);
|
||||
planarShadows.updateShadowList(scene, camera.frustum, (camera.visibility & Layers.BitMask.DEFAULT) !== 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +122,6 @@ export class RenderAdditiveLightQueue {
|
||||
|
||||
for (let i = 0; i < sphereLights.length; i++) {
|
||||
const light = sphereLights[i];
|
||||
light.update();
|
||||
sphere.set(_sphere, light.position.x, light.position.y, light.position.z, light.range);
|
||||
if (intersect.sphere_frustum(_sphere, view.camera.frustum)) {
|
||||
validLights.push(light);
|
||||
@@ -131,7 +130,6 @@ export class RenderAdditiveLightQueue {
|
||||
const spotLights = view.camera.scene!.spotLights;
|
||||
for (let i = 0; i < spotLights.length; i++) {
|
||||
const light = spotLights[i];
|
||||
light.update();
|
||||
sphere.set(_sphere, light.position.x, light.position.y, light.position.z, light.range);
|
||||
if (intersect.sphere_frustum(_sphere, view.camera.frustum)) {
|
||||
validLights.push(light);
|
||||
|
||||
@@ -161,9 +161,12 @@ export abstract class RenderPipeline extends Asset {
|
||||
* @zh 渲染函数,对指定的渲染视图按顺序执行所有渲染流程。
|
||||
* @param view Render view。
|
||||
*/
|
||||
public render (view: RenderView) {
|
||||
for (let i = 0; i < view.flows.length; i++) {
|
||||
view.flows[i].render(view);
|
||||
public render (views: RenderView[]) {
|
||||
for (let i = 0; i < views.length; i++) {
|
||||
const view = views[i];
|
||||
for (let j = 0; j < view.flows.length; j++) {
|
||||
view.flows[j].render(view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ export class RenderView {
|
||||
private _window: RenderWindow | null = null;
|
||||
private _priority: number = 0;
|
||||
private _visibility: number = CAMERA_DEFAULT_MASK;
|
||||
private _camera: Camera;
|
||||
private _camera!: Camera;
|
||||
private _isEnable: boolean = false;
|
||||
private _flows: RenderFlow[] = [];
|
||||
|
||||
@@ -129,8 +129,7 @@ export class RenderView {
|
||||
* @zh 构造函数。
|
||||
* @param camera
|
||||
*/
|
||||
public constructor (camera: Camera) {
|
||||
this._camera = camera;
|
||||
public constructor () {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,7 +138,7 @@ export class RenderView {
|
||||
* @param info Render view information descriptor
|
||||
*/
|
||||
public initialize (info: IRenderViewInfo): boolean {
|
||||
|
||||
this._camera = info.camera;
|
||||
this._name = info.name;
|
||||
this.priority = info.priority;
|
||||
this.setExecuteFlows(info.flows);
|
||||
|
||||
@@ -12,7 +12,6 @@ import { GFXFramebuffer, GFXRenderPass, GFXLoadOp,
|
||||
GFXTextureType, GFXTextureUsageBit } from '../../gfx';
|
||||
import { RenderFlowTag } from '../pipeline-serialization';
|
||||
import { RenderView, ForwardPipeline } from '../..';
|
||||
import { sceneCulling } from '../forward/scene-culling';
|
||||
|
||||
/**
|
||||
* @zh 阴影贴图绘制流程
|
||||
@@ -124,8 +123,6 @@ export class ShadowFlow extends RenderFlow {
|
||||
this._height = shadowMapSize.y;
|
||||
}
|
||||
|
||||
view.camera.update();
|
||||
sceneCulling(pipeline, view);
|
||||
pipeline.updateUBOs(view);
|
||||
super.render(view);
|
||||
pipeline.descriptorSet.bindTexture(UNIFORM_SHADOWMAP.binding, this._shadowFrameBuffer!.colorTextures[0]!);
|
||||
|
||||
@@ -7,7 +7,6 @@ import { IRenderFlowInfo, RenderFlow } from '../render-flow';
|
||||
import { RenderView } from '../render-view';
|
||||
import { UIStage } from './ui-stage';
|
||||
import { RenderFlowTag } from '../pipeline-serialization';
|
||||
import { sceneCulling } from '../forward/scene-culling';
|
||||
import { ForwardPipeline } from '../forward/forward-pipeline';
|
||||
|
||||
/**
|
||||
@@ -40,8 +39,6 @@ export class UIFlow extends RenderFlow {
|
||||
|
||||
public render (view: RenderView) {
|
||||
const pipeline = this._pipeline as ForwardPipeline;
|
||||
view.camera.update();
|
||||
sceneCulling(pipeline, view);
|
||||
pipeline.updateUBOs(view);
|
||||
super.render(view);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,8 @@
|
||||
import { DEBUG, JSB } from 'internal:constants';
|
||||
import { NativeBufferPool, NativeObjectPool, NativeArrayPool } from './native-pools';
|
||||
import { GFXRasterizerState, GFXDepthStencilState, GFXBlendState, IGFXDescriptorSetInfo,
|
||||
GFXDevice, GFXDescriptorSet, GFXShaderInfo, GFXShader, IGFXInputAssemblerInfo, GFXInputAssembler, IGFXPipelineLayoutInfo, GFXPipelineLayout, GFXFramebuffer, IGFXFramebufferInfo } from '../../gfx';
|
||||
GFXDevice, GFXDescriptorSet, GFXShaderInfo, GFXShader, IGFXInputAssemblerInfo, GFXInputAssembler,
|
||||
IGFXPipelineLayoutInfo, GFXPipelineLayout, GFXFramebuffer, IGFXFramebufferInfo } from '../../gfx';
|
||||
import { Vec3, Mat4, IVec4Like } from '../../math';
|
||||
|
||||
interface ITypedArrayConstructor<T> {
|
||||
@@ -613,7 +614,7 @@ export enum CameraView {
|
||||
SCENE, // handle
|
||||
FRUSTUM, // handle
|
||||
FORWARD, // Vec3
|
||||
POSITION = FORWARD + 3, // Vec3
|
||||
POSITION = FORWARD + 3, // Vec3
|
||||
VIEW_PORT = POSITION + 3, // Rect
|
||||
CLEAR_COLOR = VIEW_PORT + 4, // Color
|
||||
MAT_VIEW = CLEAR_COLOR + 4, // Mat4
|
||||
|
||||
@@ -164,13 +164,13 @@ export class Camera {
|
||||
}
|
||||
|
||||
this.updateExposure();
|
||||
|
||||
this._view = legacyCC.director.root.createView({
|
||||
camera: this,
|
||||
name: this._name,
|
||||
priority: this._priority,
|
||||
flows: info.flows,
|
||||
});
|
||||
legacyCC.director.root.attachCamera(this);
|
||||
this.changeTargetWindow(info.window);
|
||||
|
||||
console.log('Created Camera: ' + this._name + ' ' + CameraPool.get(handle
|
||||
@@ -178,15 +178,18 @@ export class Camera {
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
legacyCC.director.root.destroyView(this._view);
|
||||
this._view = null;
|
||||
legacyCC.director.root.detachCamera(this);
|
||||
if (this._view) {
|
||||
this._view.destroy();
|
||||
this._view = null;
|
||||
}
|
||||
this._name = null;
|
||||
if (this._poolHandle) {
|
||||
CameraPool.free(this._poolHandle);
|
||||
this._poolHandle = NULL_HANDLE;
|
||||
FrustumPool.free(this._frustumHandle);
|
||||
this._frustumHandle = NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public attachToScene (scene: RenderScene) {
|
||||
|
||||
@@ -200,7 +200,7 @@ export class PlanarShadows {
|
||||
this._globalDescriptorSet!.getBuffer(UBOShadow.BLOCK.binding).update(this.data);
|
||||
}
|
||||
|
||||
public updateShadowList (scene: RenderScene, frstm: frustum, stamp: number, shadowVisible = false) {
|
||||
public updateShadowList (scene: RenderScene, frstm: frustum, shadowVisible = false) {
|
||||
this._pendingModels.length = 0;
|
||||
if (!scene.mainLight || !shadowVisible) { return; }
|
||||
const models = scene.models;
|
||||
@@ -214,7 +214,6 @@ export class PlanarShadows {
|
||||
let data = this._record.get(model);
|
||||
if (data && (!!data.instancedBuffer !== model.isInstancingEnabled)) { this.destroyShadowData(model); data = undefined; }
|
||||
if (!data) { data = this.createShadowData(model); this._record.set(model, data); }
|
||||
if (model.updateStamp !== stamp) { model.updateUBOs(stamp); } // for those outside the frustum
|
||||
this._pendingModels.push(data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,6 +124,35 @@ export class RenderScene {
|
||||
return true;
|
||||
}
|
||||
|
||||
public update (stamp: number) {
|
||||
const mainLight = this._mainLight;
|
||||
if (mainLight) {
|
||||
mainLight.update();
|
||||
}
|
||||
|
||||
const sphereLights = this._sphereLights;
|
||||
for (let i = 0; i < sphereLights.length; i++) {
|
||||
const light = sphereLights[i];
|
||||
light.update();
|
||||
}
|
||||
|
||||
const spotLights = this._spotLights;
|
||||
for (let i = 0; i < spotLights.length; i++) {
|
||||
const light = spotLights[i];
|
||||
light.update();
|
||||
}
|
||||
|
||||
const models = this._models;
|
||||
for (let i = 0; i < models.length; i++) {
|
||||
const model = models[i];
|
||||
|
||||
if (model.enabled && model.node) {
|
||||
model.updateTransform(stamp);
|
||||
model.updateUBOs(stamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
this.removeCameras();
|
||||
this.removeSphereLights();
|
||||
|
||||
+43
-37
@@ -114,14 +114,6 @@ export class Root {
|
||||
return this._scenes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh
|
||||
* 渲染视图列表
|
||||
*/
|
||||
public get views (): RenderView[] {
|
||||
return this._views;
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh
|
||||
* 累计时间(秒)
|
||||
@@ -191,6 +183,7 @@ export class Root {
|
||||
private _ui: UI | null = null;
|
||||
private _dataPoolMgr: DataPoolManager;
|
||||
private _scenes: RenderScene[] = [];
|
||||
private _cameras: Camera[] = [];
|
||||
private _views: RenderView[] = [];
|
||||
private _modelPools = new Map<Constructor<Model>, Pool<Model>>();
|
||||
private _cameraPool: Pool<Camera> | null = null;
|
||||
@@ -251,7 +244,7 @@ export class Root {
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
this.destroyViews();
|
||||
this.clearCameras();
|
||||
this.destroyScenes();
|
||||
|
||||
if (this._pipeline) {
|
||||
@@ -294,9 +287,9 @@ export class Root {
|
||||
}
|
||||
}
|
||||
|
||||
for (const view of this._views) {
|
||||
if (view.camera.isWindowSize) {
|
||||
view.camera.resize(width, height);
|
||||
for (const camera of this._cameras) {
|
||||
if (camera.isWindowSize) {
|
||||
camera.resize(width, height);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -320,8 +313,8 @@ export class Root {
|
||||
}
|
||||
|
||||
public onGlobalPipelineStateChanged () {
|
||||
for (let i = 0; i < this._views.length; i++) {
|
||||
this._views[i].onGlobalPipelineStateChanged();
|
||||
for (let i = 0; i < this._cameras.length; i++) {
|
||||
this._cameras[i].view.onGlobalPipelineStateChanged();
|
||||
}
|
||||
for (let i = 0; i < this._scenes.length; i++) {
|
||||
this._scenes[i].onGlobalPipelineStateChanged();
|
||||
@@ -375,15 +368,20 @@ export class Root {
|
||||
|
||||
if (this._pipeline) {
|
||||
this._device.acquire();
|
||||
|
||||
const views = this._views;
|
||||
this._views.length = 0;
|
||||
const views = this._cameras;
|
||||
const stamp = legacyCC.director.getTotalFrames();
|
||||
for (let i = 0; i < views.length; i++) {
|
||||
const view = views[i];
|
||||
const camera = this._cameras[i];
|
||||
const view = camera.view;
|
||||
if (view.isEnable && view.window) {
|
||||
this._pipeline.render(view);
|
||||
camera.update();
|
||||
camera.scene!.update(stamp);
|
||||
this._views.push(view);
|
||||
}
|
||||
}
|
||||
|
||||
this._pipeline.render(this._views);
|
||||
this._device.present();
|
||||
}
|
||||
}
|
||||
@@ -470,24 +468,35 @@ export class Root {
|
||||
* @param info 渲染视图描述信息
|
||||
*/
|
||||
public createView (info: IRenderViewInfo): RenderView {
|
||||
const view: RenderView = new RenderView(info.camera);
|
||||
const view: RenderView = new RenderView();
|
||||
view.initialize(info);
|
||||
// view.camera.resize(cc.game.canvas.width, cc.game.canvas.height);
|
||||
this._views.push(view);
|
||||
this.sortViews();
|
||||
return view;
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh
|
||||
* 销毁指定的渲染视图
|
||||
* @param view 渲染视图
|
||||
* 添加渲染相机
|
||||
* @param camera 渲染相机
|
||||
*/
|
||||
public destroyView (view: RenderView) {
|
||||
for (let i = 0; i < this._views.length; ++i) {
|
||||
if (this._views[i] === view) {
|
||||
this._views.splice(i, 1);
|
||||
view.destroy();
|
||||
public attachCamera (camera: Camera) {
|
||||
for (let i = 0; i < this._cameras.length; i++) {
|
||||
if (this._cameras[i] === camera) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
this._cameras.push(camera);
|
||||
this.sortViews();
|
||||
}
|
||||
|
||||
/**
|
||||
* @zh
|
||||
* 移除渲染相机
|
||||
* @param camera 相机
|
||||
*/
|
||||
public detachCamera (camera: Camera) {
|
||||
for (let i = 0; i < this._cameras.length; ++i) {
|
||||
if (this._cameras[i] === camera) {
|
||||
this._cameras.splice(i, 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -495,13 +504,10 @@ export class Root {
|
||||
|
||||
/**
|
||||
* @zh
|
||||
* 销毁全部渲染视图
|
||||
* 销毁全部渲染相机
|
||||
*/
|
||||
public destroyViews () {
|
||||
for (const view of this._views) {
|
||||
view.destroy();
|
||||
}
|
||||
this._views = [];
|
||||
public clearCameras () {
|
||||
this._cameras.length = 0;
|
||||
}
|
||||
|
||||
public createModel<T extends Model> (mClass: typeof Model): T {
|
||||
@@ -569,8 +575,8 @@ export class Root {
|
||||
}
|
||||
|
||||
public sortViews () {
|
||||
this._views.sort((a: RenderView, b: RenderView) => {
|
||||
return a.priority - b.priority;
|
||||
this._cameras.sort((a: Camera, b: Camera) => {
|
||||
return a.view.priority - b.view.priority;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user