mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
3d v1.0.0 release (#4717)
* fix alpha blending error * optimize ubo data copy
This commit is contained in:
@@ -4,8 +4,8 @@
|
||||
|
||||
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 { Mat4, Vec3, Vec4 } from '../core/value-types';
|
||||
import { mat4, vec3, vec4 } from '../core/vmath';
|
||||
import { GFXBuffer } from '../gfx/buffer';
|
||||
import {
|
||||
GFXBindingType,
|
||||
@@ -34,10 +34,9 @@ import { IRenderFlowInfo, RenderFlow } from './render-flow';
|
||||
import { RenderView } from './render-view';
|
||||
|
||||
const _vec4Array = new Float32Array(4);
|
||||
const _vec4ArrayZero = [0.0, 0.0, 0.0, 0.0];
|
||||
const _mat4Array = new Float32Array(16);
|
||||
const _outMat = new Mat4();
|
||||
const _v3tmp = new Vec3();
|
||||
const _v4Zero = new Vec4(0.0, 0.0, 0.0, 0.0);
|
||||
|
||||
/**
|
||||
* @zh
|
||||
@@ -301,7 +300,7 @@ export abstract class RenderPipeline {
|
||||
* 默认的全局UBO。
|
||||
*/
|
||||
public get defaultGlobalUBOData (): Float32Array {
|
||||
return this._defaultUboGlobal!.view;
|
||||
return this._uboGlobal!.view;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -560,7 +559,7 @@ export abstract class RenderPipeline {
|
||||
* @zh
|
||||
* 默认的全局UBO。
|
||||
*/
|
||||
protected _defaultUboGlobal: UBOGlobal = new UBOGlobal();
|
||||
protected _uboGlobal: UBOGlobal = new UBOGlobal();
|
||||
|
||||
/**
|
||||
* @zh
|
||||
@@ -1386,86 +1385,63 @@ export abstract class RenderPipeline {
|
||||
const device = this._root.device;
|
||||
|
||||
const mainLight = scene.mainLight;
|
||||
|
||||
const ambient = scene.ambient;
|
||||
const fv = this._uboGlobal.view;
|
||||
|
||||
// update UBOGlobal
|
||||
_vec4Array[0] = this._root.cumulativeTime;
|
||||
_vec4Array[1] = 0.0;
|
||||
_vec4Array[2] = 0.0;
|
||||
_vec4Array[3] = 0.0;
|
||||
this._defaultUboGlobal.view.set(_vec4Array, UBOGlobal.TIME_OFFSET);
|
||||
fv[UBOGlobal.TIME_OFFSET] = this._root.cumulativeTime;
|
||||
|
||||
_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);
|
||||
fv[UBOGlobal.SCREEN_SIZE_OFFSET] = device.width;
|
||||
fv[UBOGlobal.SCREEN_SIZE_OFFSET + 1] = device.height;
|
||||
fv[UBOGlobal.SCREEN_SIZE_OFFSET + 2] = 1.0 / fv[UBOGlobal.SCREEN_SIZE_OFFSET];
|
||||
fv[UBOGlobal.SCREEN_SIZE_OFFSET + 3] = 1.0 / fv[UBOGlobal.SCREEN_SIZE_OFFSET + 1];
|
||||
|
||||
_vec4Array[0] = camera.width / this._shadingWidth * this._shadingScale;
|
||||
_vec4Array[1] = camera.height / this._shadingHeight * this._shadingScale;
|
||||
_vec4Array[2] = 1.0 / _vec4Array[0];
|
||||
_vec4Array[3] = 1.0 / _vec4Array[1];
|
||||
this._defaultUboGlobal.view.set(_vec4Array, UBOGlobal.SCREEN_SCALE_OFFSET);
|
||||
fv[UBOGlobal.SCREEN_SCALE_OFFSET] = camera.width / this._shadingWidth * this._shadingScale;
|
||||
fv[UBOGlobal.SCREEN_SCALE_OFFSET + 1] = camera.height / this._shadingHeight * this._shadingScale;
|
||||
fv[UBOGlobal.SCREEN_SCALE_OFFSET + 2] = 1.0 / fv[UBOGlobal.SCREEN_SCALE_OFFSET];
|
||||
fv[UBOGlobal.SCREEN_SCALE_OFFSET + 3] = 1.0 / fv[UBOGlobal.SCREEN_SCALE_OFFSET + 1];
|
||||
|
||||
_vec4Array[0] = this._shadingWidth;
|
||||
_vec4Array[1] = this._shadingHeight;
|
||||
_vec4Array[2] = 1.0 / _vec4Array[0];
|
||||
_vec4Array[3] = 1.0 / _vec4Array[1];
|
||||
this._defaultUboGlobal.view.set(_vec4Array, UBOGlobal.NATIVE_SIZE_OFFSET);
|
||||
fv[UBOGlobal.NATIVE_SIZE_OFFSET] = this._shadingWidth;
|
||||
fv[UBOGlobal.NATIVE_SIZE_OFFSET + 1] = this._shadingHeight;
|
||||
fv[UBOGlobal.NATIVE_SIZE_OFFSET + 2] = 1.0 / fv[UBOGlobal.NATIVE_SIZE_OFFSET];
|
||||
fv[UBOGlobal.NATIVE_SIZE_OFFSET + 3] = 1.0 / fv[UBOGlobal.NATIVE_SIZE_OFFSET + 1];
|
||||
|
||||
mat4.array(_mat4Array, camera.matView);
|
||||
this._defaultUboGlobal.view.set(_mat4Array, UBOGlobal.MAT_VIEW_OFFSET);
|
||||
mat4.array(fv, camera.matView, UBOGlobal.MAT_VIEW_OFFSET);
|
||||
|
||||
mat4.invert(_outMat, camera.matView);
|
||||
mat4.array(_mat4Array, _outMat);
|
||||
this._defaultUboGlobal.view.set(_mat4Array, UBOGlobal.MAT_VIEW_INV_OFFSET);
|
||||
|
||||
mat4.array(_mat4Array, camera.matProj);
|
||||
this._defaultUboGlobal.view.set(_mat4Array, UBOGlobal.MAT_PROJ_OFFSET);
|
||||
|
||||
mat4.array(fv, _outMat, UBOGlobal.MAT_VIEW_INV_OFFSET);
|
||||
mat4.array(fv, camera.matProj, UBOGlobal.MAT_PROJ_OFFSET);
|
||||
mat4.invert(_outMat, camera.matProj);
|
||||
mat4.array(_mat4Array, _outMat);
|
||||
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);
|
||||
|
||||
mat4.array(_mat4Array, camera.matViewProjInv);
|
||||
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);
|
||||
mat4.array(fv, _outMat, UBOGlobal.MAT_PROJ_INV_OFFSET);
|
||||
mat4.array(fv, camera.matViewProj, UBOGlobal.MAT_VIEW_PROJ_OFFSET);
|
||||
mat4.array(fv, camera.matViewProjInv, UBOGlobal.MAT_VIEW_PROJ_INV_OFFSET);
|
||||
vec3.array(fv, camera.position, UBOGlobal.CAMERA_POS_OFFSET);
|
||||
|
||||
const exposure = camera.exposure;
|
||||
_vec4Array[0] = exposure;
|
||||
_vec4Array[1] = 1.0 / exposure;
|
||||
_vec4Array[2] = this._isHDR ? 1.0 : 0.0;
|
||||
_vec4Array[3] = this._fpScale / exposure;
|
||||
this._defaultUboGlobal.view.set(_vec4Array, UBOGlobal.EXPOSURE_OFFSET);
|
||||
fv[UBOGlobal.EXPOSURE_OFFSET] = exposure;
|
||||
fv[UBOGlobal.EXPOSURE_OFFSET + 1] = 1.0 / exposure;
|
||||
fv[UBOGlobal.EXPOSURE_OFFSET + 2] = this._isHDR ? 1.0 : 0.0;
|
||||
fv[UBOGlobal.EXPOSURE_OFFSET + 3] = this._fpScale / exposure;
|
||||
|
||||
vec3.array(_vec4Array, mainLight.direction);
|
||||
this._defaultUboGlobal.view.set(_vec4Array, UBOGlobal.MAIN_LIT_DIR_OFFSET);
|
||||
vec3.array(fv, mainLight.direction, UBOGlobal.MAIN_LIT_DIR_OFFSET);
|
||||
|
||||
if (mainLight.enabled) {
|
||||
vec3.array(_vec4Array, mainLight.color);
|
||||
vec3.array(fv, mainLight.color, UBOGlobal.MAIN_LIT_COLOR_OFFSET);
|
||||
if (mainLight.useColorTemperature) {
|
||||
const colorTempRGB = mainLight.colorTemperatureRGB;
|
||||
_vec4Array[0] *= colorTempRGB.x;
|
||||
_vec4Array[1] *= colorTempRGB.y;
|
||||
_vec4Array[2] *= colorTempRGB.z;
|
||||
fv[UBOGlobal.MAIN_LIT_COLOR_OFFSET] *= colorTempRGB.x;
|
||||
fv[UBOGlobal.MAIN_LIT_COLOR_OFFSET + 1] *= colorTempRGB.y;
|
||||
fv[UBOGlobal.MAIN_LIT_COLOR_OFFSET + 2] *= colorTempRGB.z;
|
||||
}
|
||||
|
||||
if (this._isHDR) {
|
||||
_vec4Array[3] = mainLight.illuminance * this._fpScale;
|
||||
fv[UBOGlobal.MAIN_LIT_COLOR_OFFSET + 3] = mainLight.illuminance * this._fpScale;
|
||||
} else {
|
||||
_vec4Array[3] = mainLight.illuminance * exposure;
|
||||
fv[UBOGlobal.MAIN_LIT_COLOR_OFFSET + 3] = mainLight.illuminance * exposure;
|
||||
}
|
||||
} else {
|
||||
_vec4Array.set(_vec4ArrayZero);
|
||||
vec4.array(fv, _v4Zero, UBOGlobal.MAIN_LIT_COLOR_OFFSET);
|
||||
}
|
||||
this._defaultUboGlobal.view.set(_vec4Array, UBOGlobal.MAIN_LIT_COLOR_OFFSET);
|
||||
|
||||
_vec4Array.set(ambient.skyColor);
|
||||
if (this._isHDR) {
|
||||
@@ -1473,13 +1449,12 @@ export abstract class RenderPipeline {
|
||||
} else {
|
||||
_vec4Array[3] = ambient.skyIllum * exposure;
|
||||
}
|
||||
this._defaultUboGlobal.view.set(_vec4Array, UBOGlobal.AMBIENT_SKY_OFFSET);
|
||||
this._uboGlobal.view.set(_vec4Array, UBOGlobal.AMBIENT_SKY_OFFSET);
|
||||
|
||||
_vec4Array.set(ambient.groundAlbedo);
|
||||
this._defaultUboGlobal.view.set(_vec4Array, UBOGlobal.AMBIENT_GROUND_OFFSET);
|
||||
this._uboGlobal.view.set(ambient.groundAlbedo, 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._uboGlobal.view.buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user