mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
commit modified files
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { RenderFlow, RenderFlowInfo } from '../render-flow';
|
||||
import { IRenderFlowInfo, RenderFlow } from '../render-flow';
|
||||
import { RenderPipeline } from '../render-pipeline';
|
||||
import { TestMaterialStage } from './test-material-stage';
|
||||
import { TestStage } from './test-stage';
|
||||
@@ -13,7 +13,7 @@ export class ForwardFlow extends RenderFlow {
|
||||
super(pipeline);
|
||||
}
|
||||
|
||||
public initialize (info: RenderFlowInfo): boolean {
|
||||
public initialize (info: IRenderFlowInfo): boolean {
|
||||
|
||||
if (info.name !== undefined) {
|
||||
this._name = info.name;
|
||||
@@ -32,19 +32,19 @@ export class ForwardFlow extends RenderFlow {
|
||||
priority: ForwardStagePriority.FORWARD,
|
||||
framebuffer: mainWindow.framebuffer,
|
||||
});
|
||||
/* *
|
||||
*/
|
||||
this.createStage<TestMaterialStage>(TestMaterialStage, {
|
||||
name: 'TestMaterialStage',
|
||||
priority: ForwardStagePriority.FORWARD,
|
||||
framebuffer: mainWindow.framebuffer,
|
||||
});
|
||||
/* */
|
||||
/*
|
||||
this.createStage<TestStage>(TestStage, {
|
||||
name: 'TestStage',
|
||||
priority: ForwardStagePriority.FORWARD,
|
||||
framebuffer: mainWindow.framebuffer,
|
||||
});
|
||||
/* */
|
||||
*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
import { RenderPipeline, RenderPassStage, UBOGlobal } from "../render-pipeline";
|
||||
import { Root } from "../../core/root";
|
||||
import { ForwardFlow } from "./forward-flow";
|
||||
import { GFXRenderPass } from "../../gfx/render-pass";
|
||||
import { GFXBufferUsageBit, GFXMemoryUsageBit } from "../../gfx/define";
|
||||
import { GFXRenderPass } from "../../gfx/render-pass";
|
||||
import { RenderPassStage, RenderPipeline, UBOGlobal } from "../render-pipeline";
|
||||
import { RenderQueue } from "../render-queue";
|
||||
import { ForwardFlow } from "./forward-flow";
|
||||
|
||||
export enum ForwardFlowPriority {
|
||||
FORWARD = 0,
|
||||
};
|
||||
}
|
||||
|
||||
export class ForwardPipeline extends RenderPipeline {
|
||||
|
||||
constructor(root: Root) {
|
||||
constructor (root: Root) {
|
||||
super(root);
|
||||
}
|
||||
|
||||
public initialize(): boolean {
|
||||
|
||||
if(!this.createQuadInputAssembler()) {
|
||||
public initialize (): boolean {
|
||||
|
||||
if (!this.createQuadInputAssembler()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!this.createUBOs()) {
|
||||
if (!this.createUBOs()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let mainWindow = this._root.mainWindow;
|
||||
const mainWindow = this._root.mainWindow;
|
||||
let windowPass: GFXRenderPass | null = null;
|
||||
|
||||
if(mainWindow) {
|
||||
if (mainWindow) {
|
||||
windowPass = mainWindow.renderPass;
|
||||
}
|
||||
|
||||
if(!windowPass) {
|
||||
console.error("RenderPass of main window is null.");
|
||||
if (!windowPass) {
|
||||
console.error('RenderPass of main window is null.');
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -48,18 +48,18 @@ export class ForwardPipeline extends RenderPipeline {
|
||||
|
||||
// create flows
|
||||
this.createFlow<ForwardFlow>(ForwardFlow, {
|
||||
name: "ForwardFlow",
|
||||
name: 'ForwardFlow',
|
||||
priority: ForwardFlowPriority.FORWARD,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
public destroy () {
|
||||
this.destroyFlows();
|
||||
this.clearRenderPasses();
|
||||
this.destroyUBOs();
|
||||
this.destroyQuadInputAssembler();
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@@ -363,7 +363,7 @@ export abstract class RenderPipeline {
|
||||
}
|
||||
|
||||
// add model pass to render queue
|
||||
this._queue.add(model);
|
||||
this._queue.add(model, camera);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { vec3 } from '../core/vmath';
|
||||
import { GFXCommandBuffer } from '../gfx/command-buffer';
|
||||
import { Pass } from '../renderer/core/pass';
|
||||
import { Camera } from '../renderer/scene/camera';
|
||||
import Model from '../renderer/scene/model';
|
||||
|
||||
const _pos: vec3 = vec3.create();
|
||||
|
||||
export class RenderItem {
|
||||
public hash: number;
|
||||
public model: Model;
|
||||
@@ -28,30 +32,40 @@ export class RenderQueue {
|
||||
|
||||
private _opaques: RenderItem[] = [];
|
||||
private _transparents: RenderItem[] = [];
|
||||
private _buffer: ArrayBuffer;
|
||||
private _f32View: Float32Array;
|
||||
private _ui32View: Uint32Array;
|
||||
|
||||
constructor () {
|
||||
this._buffer = new ArrayBuffer(Float32Array.BYTES_PER_ELEMENT);
|
||||
this._f32View = new Float32Array(this._buffer);
|
||||
this._ui32View = new Uint32Array(this._buffer);
|
||||
}
|
||||
|
||||
public add (model: Model) {
|
||||
public add (model: Model, camera: Camera) {
|
||||
|
||||
model.node.getPosition(_pos);
|
||||
this._f32View[0] = vec3.distance(camera.position, _pos);
|
||||
let x = this._ui32View[0];
|
||||
|
||||
for (let i = 0; i < model.passes.length; ++i) {
|
||||
const pass = model.passes[i];
|
||||
const cmdBuff = model.commandBuffers[i];
|
||||
|
||||
model.node.getWorldPosition();
|
||||
|
||||
const pso = pass.pipelineState;
|
||||
|
||||
const isTransparent = pso.blendState.targets[0].blend;
|
||||
|
||||
let hash: number = 0;
|
||||
|
||||
if (!isTransparent) {
|
||||
// Opaque objects are sorted by depth front to back, then by shader id.
|
||||
hash = (0 << 63) | (pso.shader.id << 13);
|
||||
const hash = (0 << 63) | (pso.shader.id << 13);
|
||||
|
||||
this._opaques.push({hash, model, pass, cmdBuff});
|
||||
} else {
|
||||
// Transparent objects are sorted by depth back to front, then by by shader id.
|
||||
hash = (1 << 63) | (pso.shader.id << 13);
|
||||
const hash = (1 << 63) | (pso.shader.id << 13);
|
||||
|
||||
this._transparents.push({hash, model, pass, cmdBuff});
|
||||
}
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
import { RenderScene } from "./render-scene";
|
||||
import Node from "../../scene-graph/node";
|
||||
import { vec3, mat4, quat } from "../../core/vmath";
|
||||
import { frustum } from "../../3d/geom-utils/frustum";
|
||||
import { frustum } from '../../3d/geom-utils/frustum';
|
||||
import { mat4, quat, vec3 } from '../../core/vmath';
|
||||
import Node from '../../scene-graph/node';
|
||||
import { RenderScene } from './render-scene';
|
||||
|
||||
export enum NodeSpace
|
||||
{
|
||||
LOCAL,
|
||||
PARENT,
|
||||
WORLD,
|
||||
};
|
||||
export enum NodeSpace {
|
||||
LOCAL,
|
||||
PARENT,
|
||||
WORLD,
|
||||
}
|
||||
|
||||
export enum CameraProjection {
|
||||
PERSPECTIVE,
|
||||
ORTHO,
|
||||
};
|
||||
}
|
||||
|
||||
export class Camera {
|
||||
|
||||
@@ -27,22 +26,22 @@ export class Camera {
|
||||
private _fov: number;
|
||||
private _nearClip: number;
|
||||
private _farClip: number;
|
||||
private _matView: mat4 = new mat4;
|
||||
private _matProj: mat4 = new mat4;
|
||||
private _matViewProj: mat4 = new mat4;
|
||||
private _matViewProjInv: mat4 = new mat4;
|
||||
private _position: vec3 = new vec3;
|
||||
private _rotation: quat = new quat;
|
||||
private _direction: vec3 = new vec3;
|
||||
private _frustum: frustum = new frustum;
|
||||
private _matView: mat4 = new mat4();
|
||||
private _matProj: mat4 = new mat4();
|
||||
private _matViewProj: mat4 = new mat4();
|
||||
private _matViewProjInv: mat4 = new mat4();
|
||||
private _position: vec3 = new vec3();
|
||||
private _rotation: quat = new quat();
|
||||
private _direction: vec3 = new vec3();
|
||||
private _frustum: frustum = new frustum();
|
||||
|
||||
constructor(scene: RenderScene, name: string) {
|
||||
constructor (scene: RenderScene, name: string) {
|
||||
this._scene = scene;
|
||||
this._name = name;
|
||||
this._node = scene.createNode({ name: name + "Node", isStatic: false });
|
||||
this._node = scene.createNode({ name: name + 'Node', isStatic: false });
|
||||
this._proj = CameraProjection.PERSPECTIVE;
|
||||
|
||||
let window = scene.root.mainWindow;
|
||||
const window = scene.root.mainWindow;
|
||||
if (window) {
|
||||
this._width = window.width;
|
||||
this._height = window.height;
|
||||
@@ -57,13 +56,13 @@ export class Camera {
|
||||
this._farClip = 10000.0;
|
||||
}
|
||||
|
||||
public resize(width: number, height: number) {
|
||||
public resize (width: number, height: number) {
|
||||
this._width = width;
|
||||
this._height = height;
|
||||
this._aspect = this._width / this._height;
|
||||
}
|
||||
|
||||
public update() {
|
||||
public update () {
|
||||
// view matrix
|
||||
this._node.getWorldRT(this._matView);
|
||||
mat4.invert(this._matView, this._matView);
|
||||
@@ -72,8 +71,8 @@ export class Camera {
|
||||
if (this._proj === CameraProjection.PERSPECTIVE) {
|
||||
mat4.perspective(this._matProj, this._fov, this._aspect, this._nearClip, this._farClip);
|
||||
} else {
|
||||
let x = this._width;
|
||||
let y = this._height;
|
||||
const x = this._width;
|
||||
const y = this._height;
|
||||
mat4.ortho(this._matProj, -x, x, -y, y, this._nearClip, this._farClip);
|
||||
}
|
||||
|
||||
@@ -84,110 +83,110 @@ export class Camera {
|
||||
this._frustum.update(this._matViewProj, this._matViewProjInv);
|
||||
}
|
||||
|
||||
public set fov(fov: number) {
|
||||
public set fov (fov: number) {
|
||||
this._fov = fov;
|
||||
}
|
||||
|
||||
public set nearClip(nearClip: number) {
|
||||
public set nearClip (nearClip: number) {
|
||||
this._nearClip = nearClip;
|
||||
}
|
||||
|
||||
public set farClip(farClip: number) {
|
||||
public set farClip (farClip: number) {
|
||||
this._farClip = farClip;
|
||||
}
|
||||
|
||||
public get scene(): RenderScene {
|
||||
public get scene (): RenderScene {
|
||||
return this._scene;
|
||||
}
|
||||
|
||||
public get name(): string {
|
||||
public get name (): string {
|
||||
return this._name;
|
||||
}
|
||||
|
||||
public get node(): Node {
|
||||
public get node (): Node {
|
||||
return this._node;
|
||||
}
|
||||
|
||||
public get width(): number {
|
||||
public get width (): number {
|
||||
return this._width;
|
||||
}
|
||||
|
||||
public get height(): number {
|
||||
public get height (): number {
|
||||
return this._height;
|
||||
}
|
||||
|
||||
public get aspect(): number {
|
||||
public get aspect (): number {
|
||||
return this._aspect;
|
||||
}
|
||||
|
||||
public get fov(): number {
|
||||
public get fov (): number {
|
||||
return this._fov;
|
||||
}
|
||||
|
||||
public get nearClip(): number {
|
||||
public get nearClip (): number {
|
||||
return this._nearClip;
|
||||
}
|
||||
|
||||
public get farClip(): number {
|
||||
public get farClip (): number {
|
||||
return this._farClip;
|
||||
}
|
||||
|
||||
public get matView(): mat4 {
|
||||
public get matView (): mat4 {
|
||||
return this._matView;
|
||||
}
|
||||
|
||||
public get matProj(): mat4 {
|
||||
public get matProj (): mat4 {
|
||||
return this._matProj;
|
||||
}
|
||||
|
||||
public get matViewProj(): mat4 {
|
||||
public get matViewProj (): mat4 {
|
||||
return this._matViewProj;
|
||||
}
|
||||
|
||||
public get matViewProjInv(): mat4 {
|
||||
public get matViewProjInv (): mat4 {
|
||||
return this._matViewProjInv;
|
||||
}
|
||||
|
||||
public get frustum(): frustum {
|
||||
public get frustum (): frustum {
|
||||
return this._frustum;
|
||||
}
|
||||
|
||||
public get position(): vec3 {
|
||||
this._node.getWorldPosition(this._position);
|
||||
public get position (): vec3 {
|
||||
this._node.getPosition(this._position);
|
||||
return this._position;
|
||||
}
|
||||
|
||||
public rotate(rot: quat, ns?: NodeSpace) {
|
||||
let space = (ns !== undefined? ns : NodeSpace.LOCAL);
|
||||
if(space === NodeSpace.LOCAL || space === NodeSpace.PARENT) {
|
||||
public rotate (rot: quat, ns?: NodeSpace) {
|
||||
const space = (ns !== undefined ? ns : NodeSpace.LOCAL);
|
||||
if (space === NodeSpace.LOCAL || space === NodeSpace.PARENT) {
|
||||
this._node.rotate(rot);
|
||||
} else if (space === NodeSpace.WORLD) {
|
||||
this._node.rotateWorld(rot);
|
||||
}
|
||||
}
|
||||
|
||||
public rotateFromAxisAngle(axis: vec3, rad: number, ns?: NodeSpace) {
|
||||
public rotateFromAxisAngle (axis: vec3, rad: number, ns?: NodeSpace) {
|
||||
quat.fromAxisAngle(this._rotation, axis, rad);
|
||||
let space = (ns !== undefined? ns : NodeSpace.LOCAL);
|
||||
if(space === NodeSpace.LOCAL || space === NodeSpace.PARENT) {
|
||||
const space = (ns !== undefined ? ns : NodeSpace.LOCAL);
|
||||
if (space === NodeSpace.LOCAL || space === NodeSpace.PARENT) {
|
||||
this._node.rotate(this._rotation);
|
||||
} else if (space === NodeSpace.WORLD) {
|
||||
this._node.rotateWorld(this._rotation);
|
||||
}
|
||||
}
|
||||
|
||||
public setRotation(rot: quat, ns?: NodeSpace) {
|
||||
let space = (ns !== undefined? ns : NodeSpace.LOCAL);
|
||||
if(space === NodeSpace.LOCAL || space === NodeSpace.PARENT) {
|
||||
public setRotation (rot: quat, ns?: NodeSpace) {
|
||||
const space = (ns !== undefined ? ns : NodeSpace.LOCAL);
|
||||
if (space === NodeSpace.LOCAL || space === NodeSpace.PARENT) {
|
||||
this._node.setRotation(rot);
|
||||
} else if (space === NodeSpace.WORLD) {
|
||||
this._node.setWorldRotation(rot);
|
||||
}
|
||||
}
|
||||
|
||||
public pitch(rad: number, ns?: NodeSpace) {
|
||||
let space = (ns !== undefined? ns : NodeSpace.LOCAL);
|
||||
if(space === NodeSpace.LOCAL || space === NodeSpace.PARENT) {
|
||||
public pitch (rad: number, ns?: NodeSpace) {
|
||||
const space = (ns !== undefined ? ns : NodeSpace.LOCAL);
|
||||
if (space === NodeSpace.LOCAL || space === NodeSpace.PARENT) {
|
||||
this._node.getRotation(this._rotation);
|
||||
quat.toAxisX(this._direction, this._rotation);
|
||||
this.rotateFromAxisAngle(this._direction, rad, ns);
|
||||
@@ -198,9 +197,9 @@ export class Camera {
|
||||
}
|
||||
}
|
||||
|
||||
public yaw(rad: number, ns?: NodeSpace) {
|
||||
let space = (ns !== undefined? ns : NodeSpace.LOCAL);
|
||||
if(space === NodeSpace.LOCAL || space === NodeSpace.PARENT) {
|
||||
public yaw (rad: number, ns?: NodeSpace) {
|
||||
const space = (ns !== undefined ? ns : NodeSpace.LOCAL);
|
||||
if (space === NodeSpace.LOCAL || space === NodeSpace.PARENT) {
|
||||
this._node.getRotation(this._rotation);
|
||||
quat.toAxisY(this._direction, this._rotation);
|
||||
this.rotateFromAxisAngle(this._direction, rad, ns);
|
||||
@@ -208,12 +207,12 @@ export class Camera {
|
||||
this._node.getWorldRotation(this._rotation);
|
||||
quat.toAxisY(this._direction, this._rotation);
|
||||
this.rotateFromAxisAngle(this._direction, rad, ns);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public roll(rad: number, ns?: NodeSpace) {
|
||||
let space = (ns !== undefined? ns : NodeSpace.LOCAL);
|
||||
if(space === NodeSpace.LOCAL || space === NodeSpace.PARENT) {
|
||||
public roll (rad: number, ns?: NodeSpace) {
|
||||
const space = (ns !== undefined ? ns : NodeSpace.LOCAL);
|
||||
if (space === NodeSpace.LOCAL || space === NodeSpace.PARENT) {
|
||||
this._node.getRotation(this._rotation);
|
||||
quat.toAxisZ(this._direction, this._rotation);
|
||||
this.rotateFromAxisAngle(this._direction, rad, ns);
|
||||
@@ -221,25 +220,25 @@ export class Camera {
|
||||
this._node.getWorldRotation(this._rotation);
|
||||
quat.toAxisZ(this._direction, this._rotation);
|
||||
this.rotateFromAxisAngle(this._direction, rad, ns);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public set target(target: vec3) {
|
||||
public set target (target: vec3) {
|
||||
this._node.lookAt(target);
|
||||
}
|
||||
|
||||
public get direction(): vec3 {
|
||||
public get direction (): vec3 {
|
||||
this._node.getRotation(this._rotation);
|
||||
vec3.transformQuat(this._direction, vec3.UNIT_Z, this._rotation);
|
||||
return this._direction;
|
||||
}
|
||||
|
||||
public set position(pos: vec3) {
|
||||
public set position (pos: vec3) {
|
||||
this._node.setWorldPosition(pos.x, pos.y, pos.z);
|
||||
}
|
||||
|
||||
public set direction(dir: vec3) {
|
||||
public set direction (dir: vec3) {
|
||||
quat.rotationTo(this._rotation, vec3.UNIT_Z, dir);
|
||||
this._node.setRotation(this._rotation);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user