Merge pull request #92 from YunHsiao/gfx

Gfx
This commit is contained in:
Weiliang Wang
2019-01-22 15:27:00 +08:00
committed by GitHub
11 changed files with 60 additions and 27 deletions
+1 -3
View File
@@ -383,9 +383,7 @@ export default class AnimationComponent extends Component {
* @property clips
* @type {AnimationClip[]}
*/
@property({
type: [AnimationClip],
})
@property({ type: [AnimationClip] })
get clips() {
return this._clips;
}
+1 -4
View File
@@ -6,9 +6,7 @@ const { ccclass, property } = _decorator;
@ccclass('cc.RenderableComponent')
export class RenderableComponent extends Component {
@property({
type: [Material],
})
@property({ type: [Material] })
private _materials: Array<Material | null> = [];
constructor () {
@@ -18,7 +16,6 @@ export class RenderableComponent extends Component {
@property({
type: [Material],
displayName: 'Materials',
default: [],
})
get sharedMaterials () {
return this._materials;
+2 -2
View File
@@ -144,7 +144,7 @@ function defineProp (cls, className, propName, val, es6) {
appendProp(cls, propName);
// apply attributes
var attrs = parseAttributes(cls, val, className, propName, false);
var attrs = parseAttributes(cls, val, className, propName, false);
if (attrs) {
var onAfterProp = tmpArray;
for (var i = 0; i < attrs.length; i++) {
@@ -1240,4 +1240,4 @@ CCClass.escapeForJS = escapeForJS;
CCClass.IDENTIFIER_RE = IDENTIFIER_RE;
CCClass.getNewValueTypeCode = CC_SUPPORT_JIT && getNewValueTypeCodeJit;
cc.Class = CCClass;
cc.Class = CCClass;
+14
View File
@@ -68,6 +68,20 @@ export default class quat {
return out;
}
/**
* Sets a quaternion as identity quaternion.
*
* @param out - Quaternion to set.
* @return out.
*/
public static identity<Out extends IQuatLike> (out: Out) {
out.x = 0;
out.y = 0;
out.z = 0;
out.w = 1;
return out;
}
/**
* Sets a quaternion to represent the shortest rotation from one
* vector to another.
+6
View File
@@ -2,3 +2,9 @@
export enum RenderPassStage {
DEFAULT = 100,
}
export enum RenderPriority {
MIN = 0,
MAX = 0xff,
DEFAULT = 0x80,
}
+4 -3
View File
@@ -1,5 +1,6 @@
import { intersect } from '../3d/geom-utils';
import { Root } from '../core/root';
import { Mat4, Vec3 } from '../core/value-types';
import { mat4, vec3 } from '../core/vmath';
import { GFXBuffer } from '../gfx/buffer';
import { GFXBufferUsageBit, GFXFormat, GFXMemoryUsageBit, GFXType } from '../gfx/define';
@@ -9,7 +10,6 @@ import { GFXRenderPass } from '../gfx/render-pass';
import { GFXUniformBlock } from '../gfx/shader';
import { GFXTexture } from '../gfx/texture';
import { GFXTextureView } from '../gfx/texture-view';
import { Camera } from '../renderer/scene/camera';
import { IRenderFlowInfo, RenderFlow } from './render-flow';
import { RenderQueue } from './render-queue';
import { RenderView } from './render-view';
@@ -64,7 +64,8 @@ export class UBOLocal {
const _vec4Array = new Float32Array(4);
const _mat4Array = new Float32Array(16);
const _outMat = new mat4();
const _outMat = new Mat4();
const _outVec3 = new Vec3();
export abstract class RenderPipeline {
@@ -330,7 +331,7 @@ export abstract class RenderPipeline {
mat4.array(_mat4Array, view.camera.matViewProjInv);
this._uboGlobal.view.set(_mat4Array, UBOGlobal.MAT_VIEW_PROJ_INV_OFFSET);
vec3.array(_vec4Array, view.camera.node && view.camera.node.getPosition());
vec3.array(_vec4Array, view.camera.node && view.camera.node.getWorldPosition(_outVec3));
_vec4Array[3] = 1.0;
this._uboGlobal.view.set(_vec4Array, UBOGlobal.CAMERA_POS_OFFSET);
+6 -8
View File
@@ -1,16 +1,11 @@
import { CachedArray } from '../core/memop/cached-array';
import { Vec3 } from '../core/value-types';
import { vec3 } from '../core/vmath';
import { GFXCommandBuffer } from '../gfx/command-buffer';
import { Camera } from '../renderer/scene/camera';
import { Model } from '../renderer/scene/model';
import { SubModel } from '../renderer/scene/submodel';
export enum RenderPriority {
MIN = 0,
MAX = 0xff,
DEFAULT = 0x80,
}
export interface IRenderItem {
hash: number;
depth: number;
@@ -19,6 +14,8 @@ export interface IRenderItem {
cmdBuff: GFXCommandBuffer;
}
const _v3tmp = new Vec3();
export class RenderQueue {
public opaques: CachedArray<IRenderItem>;
public transparents: CachedArray<IRenderItem>;
@@ -65,8 +62,9 @@ export class RenderQueue {
}
public add (model: Model, camera: Camera) {
const depth = vec3.distance(camera.node.getPosition(), model.node!.getPosition());
model.node.getWorldPosition(_v3tmp);
vec3.sub(_v3tmp, _v3tmp, camera.position);
const depth = vec3.dot(_v3tmp, camera.forward);
for (let i = 0; i < model.subModelNum; ++i) {
const subModel = model.getSubModel(i);
+1 -2
View File
@@ -14,9 +14,8 @@ import { GFXRenderPass } from '../../gfx/render-pass';
import { GFXSampler } from '../../gfx/sampler';
import { GFXShader } from '../../gfx/shader';
import { GFXTextureView } from '../../gfx/texture-view';
import { RenderPassStage } from '../../pipeline/define';
import { RenderPassStage, RenderPriority } from '../../pipeline/define';
import { UBOGlobal, UBOLocal } from '../../pipeline/render-pipeline';
import { RenderPriority } from '../../pipeline/render-queue';
export interface IPassInfoFull extends IPassInfo {
// generated part
+19 -1
View File
@@ -1,5 +1,5 @@
import { frustum, ray } from '../../3d/geom-utils';
import { Color, Mat4, Rect } from '../../core/value-types';
import { Color, Mat4, Rect, Vec3 } from '../../core/value-types';
import { color4, lerp, mat4, toRadian, vec3 } from '../../core/vmath';
import { GFXClearFlag, IGFXColor } from '../../gfx/define';
import { RenderView, RenderViewPriority } from '../../pipeline/render-view';
@@ -53,6 +53,8 @@ export class Camera {
private _matViewProj: Mat4 = new Mat4();
private _matViewProjInv: Mat4 = new Mat4();
private _frustum: frustum = new frustum();
private _forward: Vec3 = new Vec3();
private _position: Vec3 = new Vec3();
private _node: Node | null = null;
private _view: RenderView;
private _visibility: number = 0;
@@ -120,6 +122,14 @@ export class Camera {
mat4.mul(this._matViewProj, this._matProj, this._matView);
mat4.invert(this._matViewProjInv, this._matViewProj);
vec3.set(
this._forward,
-this._matView.m02,
-this._matView.m06,
-this._matView.m10,
);
this._node.getWorldPosition(this._position);
this._frustum.update(this._matViewProj, this._matViewProjInv);
}
@@ -259,6 +269,14 @@ export class Camera {
return this._frustum;
}
get forward () {
return this._forward;
}
get position () {
return this._position;
}
set visibility (vis) {
this._visibility = vis;
}
+5 -3
View File
@@ -168,12 +168,14 @@ export class RenderScene {
if (distance <= 0) { continue; }
for (let i = 0; i < m.subModelNum; ++i) {
const subModel = m.getSubModel(i).subMeshData;
if (!subModel || !subModel.geometricInfo) { continue; }
const { positions: vb, indices: ib, doubleSided: sides } = subModel.geometricInfo;
narrowphase(vb, ib, subModel.primitiveMode, sides);
if (subModel && subModel.geometricInfo) {
const { positions: vb, indices: ib, doubleSided: sides } = subModel.geometricInfo;
narrowphase(vb, ib, subModel.primitiveMode, sides);
}
if (distance < Infinity) {
const r = pool.add();
r.node = node;
// @ts-ignore
r.distance = distance * vec3.magnitude(vec3.mul(v3, modelRay.d, node._scale));
results[pool.length - 1] = r;
}
+1 -1
View File
@@ -5,7 +5,7 @@ import { GFXCommandBufferType } from '../../gfx/define';
import { GFXDevice } from '../../gfx/device';
import { GFXInputAssembler, IGFXInputAssemblerInfo } from '../../gfx/input-assembler';
import { GFXPipelineState } from '../../gfx/pipeline-state';
import { RenderPriority } from '../../pipeline/render-queue';
import { RenderPriority } from '../../pipeline/define';
import { Pass } from '../core/pass';
export class SubModel {