V3.4 performance (#9191)

* use start rotation as euler in shader

* do calculate start rotation once

Co-authored-by: Santy-Wang <wh19930829@qq.com>
This commit is contained in:
zxx43
2021-09-16 17:12:17 +08:00
committed by GitHub
parent 3dcc271494
commit f78395cd90
10 changed files with 70 additions and 39 deletions
+3 -2
View File
@@ -104,7 +104,7 @@ export const effects = [
"shaders": [
{
"name": "particle-gpu|particle-vs-gpu:gpvs_main|tinted-fs:add",
"hash": 3001336778,
"hash": 3170483155,
"builtins": {
"statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 60, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 38 },
"globals": { "buffers": [], "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }], "samplerTextures": [], "images": [] },
@@ -237,7 +237,7 @@ export const effects = [
"shaders": [
{
"name": "particle|particle-vs-legacy:lpvs_main|tinted-fs:add",
"hash": 1675533382,
"hash": 1226214400,
"builtins": {
"statistics": { "CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS": 49, "CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS": 38 },
"globals": { "buffers": [], "blocks": [{ "name": "CCGlobal", "defines": [] }, { "name": "CCCamera", "defines": [] }], "samplerTextures": [], "images": [] },
@@ -246,6 +246,7 @@ export const effects = [
"defines": [
{ "name": "CC_RENDER_MODE", "type": "number", "range": [0, 4] },
{ "name": "CC_USE_WORLD_SPACE", "type": "boolean" },
{ "name": "ROTATION_OVER_TIME_MODULE_ENABLE", "type": "boolean" },
{ "name": "CC_USE_HDR", "type": "boolean" }
],
"buffers": [],
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -142,6 +142,18 @@ export default class RotationOvertimeModule extends ParticleModuleBase {
p.deltaMat = Mat4.fromQuat(p.deltaMat, p.deltaQuat);
p.localMat = p.localMat.multiply(p.deltaMat); // accumulate rotation
if (!p.startRotated) {
if (renderMode !== RenderMode.Mesh) {
if (renderMode === RenderMode.StrecthedBillboard) {
p.startEuler.set(0, 0, 0);
} else if (renderMode !== RenderMode.Billboard) {
p.startEuler.set(0, 0, p.startEuler.z);
}
}
Quat.fromEuler(p.startRotation, p.startEuler.x * Particle.R2D, p.startEuler.y * Particle.R2D, p.startEuler.z * Particle.R2D);
p.startRotated = true;
}
this._startMat = Mat4.fromQuat(this._startMat, p.startRotation);
this._matRot = this._startMat.multiply(p.localMat);
+1 -22
View File
@@ -834,26 +834,6 @@ export class ParticleSystem extends RenderableComponent {
}
}
private _processRotation (particle) {
// Same as the particle-vs-legacy.chunk glsl statemants in remark
const renderMode = this.processor.getInfo().renderMode;
if (renderMode !== RenderMode.Mesh) {
if (renderMode === RenderMode.StrecthedBillboard) {
particle.startEuler.set(0, 0, 0);
} else if (renderMode !== RenderMode.Billboard) {
particle.startEuler.set(0, 0, particle.startEuler.z);
}
}
// eslint-disable-next-line max-len
Quat.fromEuler(particle.startRotation, particle.startEuler.x * Particle.R2D, particle.startEuler.y * Particle.R2D, particle.startEuler.z * Particle.R2D);
particle.startRotation = Quat.normalize(particle.startRotation, particle.startRotation);
if (particle.startRotation.w < 0.0) { // Use vec3 to save quat so we need identify negative w
particle.startRotation.x += Particle.INDENTIFY_NEG_QUAT; // Indentify negative w & revert the quat in shader
}
}
private emit (count: number, dt: number) {
const loopDelta = (this._time % this.duration) / this.duration; // loop delta value
@@ -907,8 +887,7 @@ export class ParticleSystem extends RenderableComponent {
} else {
particle.startEuler.set(0, 0, this.startRotationZ.evaluate(loopDelta, rand));
}
this._processRotation(particle);
Vec3.set(particle.rotation, particle.startRotation.x, particle.startRotation.y, particle.startRotation.z);
Vec3.set(particle.rotation, particle.startEuler.x, particle.startEuler.y, particle.startEuler.z);
// apply startSize.
if (this.startSize3D) {
+3
View File
@@ -46,6 +46,7 @@ export class Particle {
public rotation: Vec3;
public startEuler: Vec3;
public startRotation: Quat;
public startRotated: boolean;
public deltaQuat: Quat;
public deltaMat: Mat4;
public localMat: Mat4;
@@ -75,6 +76,7 @@ export class Particle {
this.rotation = new Vec3(0, 0, 0);
this.startEuler = new Vec3(0, 0, 0);
this.startRotation = new Quat();
this.startRotated = false;
this.deltaQuat = new Quat();
this.deltaMat = new Mat4();
this.localMat = new Mat4();
@@ -98,6 +100,7 @@ export class Particle {
this.rotation.set(0, 0, 0);
this.startEuler.set(0, 0, 0);
this.startRotation.set(0, 0, 0, 1);
this.startRotated = false;
this.deltaQuat.set(0, 0, 0, 1);
this.deltaMat.identity();
this.localMat.identity();
@@ -62,6 +62,7 @@ const _uvs = [
const CC_USE_WORLD_SPACE = 'CC_USE_WORLD_SPACE';
const CC_RENDER_MODE = 'CC_RENDER_MODE';
const ROTATION_OVER_TIME_MODULE_ENABLE = 'ROTATION_OVER_TIME_MODULE_ENABLE';
const RENDER_MODE_BILLBOARD = 0;
const RENDER_MODE_STRETCHED_BILLBOARD = 1;
const RENDER_MODE_HORIZONTAL_BILLBOARD = 2;
@@ -236,6 +237,8 @@ export default class ParticleSystemRendererCPU extends ParticleSystemRendererBas
this._runAnimateList.push(p);
}
}
this.updateMaterialParams();
}
public updateAlignSpace (space) {
@@ -525,6 +528,12 @@ export default class ParticleSystemRendererCPU extends ParticleSystemRendererBas
} else {
pass.setUniform(this._uLenHandle, vlenScale);
}
let enable = false;
const roationModule = this._particleSystem._rotationOvertimeModule;
enable = roationModule && roationModule.enable;
this._defines[ROTATION_OVER_TIME_MODULE_ENABLE] = enable;
mat.recompileShaders(this._defines);
if (this._model) {
this._model.updateMaterial(mat);
+13 -1
View File
@@ -238,7 +238,19 @@ vec4 gpvs_main () {
// rotation
vec3 startRotation = a_rotation_uv.xyz;
vec4 rot = toQuat(startRotation);
#if CC_RENDER_MODE != RENDER_MODE_MESH
#if CC_RENDER_MODE == RENDER_MODE_BILLBOARD
vec3 rotEuler = startRotation.xyz;
#elif CC_RENDER_MODE == RENDER_MODE_STRETCHED_BILLBOARD
vec3 rotEuler = vec3(0.);
#else
vec3 rotEuler = vec3(0., 0., startRotation.z);
#endif
vec4 rot = quaternionFromEuler(rotEuler);
#else
vec4 rot = quaternionFromEuler(startRotation);
#endif
#if ROTATION_OVER_TIME_MODULE_ENABLE
if (u_rotation_mode == CURVE_MODE_FIX) {
vec3 euler = unpackCurveData(rotation_over_time_tex0, timeCoord0) * normalizedTime * a_dir_life.w;
+23 -8
View File
@@ -37,14 +37,29 @@ vec4 lpvs_main () {
#define INDENTIFY_NEG_QUAT 10.0
vec3 rotTmp = a_texCoord2;
float mulFactor = 1.0;
if (rotTmp.x > INDENTIFY_NEG_QUAT * 0.5) {
rotTmp.x -= INDENTIFY_NEG_QUAT;
mulFactor = -1.0;
}
vec4 rot = vec4(rotTmp, 0.0);
rot.w = mulFactor * sqrt(1.0 - rot.x * rot.x - rot.y * rot.y - rot.z * rot.z);
#if ROTATION_OVER_TIME_MODULE_ENABLE
vec3 rotTmp = a_texCoord2;
float mulFactor = 1.0;
if (rotTmp.x > INDENTIFY_NEG_QUAT * 0.5) {
rotTmp.x -= INDENTIFY_NEG_QUAT;
mulFactor = -1.0;
}
vec4 rot = vec4(rotTmp, 0.0);
rot.w = mulFactor * sqrt(1.0 - rot.x * rot.x - rot.y * rot.y - rot.z * rot.z);
#else
#if CC_RENDER_MODE != RENDER_MODE_MESH
#if CC_RENDER_MODE == RENDER_MODE_BILLBOARD
vec3 rotEuler = a_texCoord2;
#elif CC_RENDER_MODE == RENDER_MODE_STRETCHED_BILLBOARD
vec3 rotEuler = vec3(0.);
#else
vec3 rotEuler = vec3(0., 0., a_texCoord2.z);
#endif
vec4 rot = quaternionFromEuler(rotEuler);
#else
vec4 rot = quaternionFromEuler(a_texCoord2);
#endif
#endif
#if CC_RENDER_MODE != RENDER_MODE_MESH
vec2 cornerOffset = vec2((a_texCoord.xy - 0.5));