8000 Fix ColorOverLifetimeModule mode invalid bug by GuoLei1990 · Pull Request #1850 · galacean/engine · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix ColorOverLifetimeModule mode invalid bug #1850

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 31 additions & 29 deletions packages/core/src/particle/modules/ColorOverLifetimeModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,39 +48,41 @@ export class ColorOverLifetimeModule extends ParticleGeneratorModule {
if (this.enabled) {
const mode = this.color.mode;

if (mode === ParticleGradientMode.Gradient || mode === ParticleGradientMode.TwoGradients) {
co 8000 nst color = this.color;
const colorSpace = this._generator._renderer.engine.settings.colorSpace;
shaderData.setFloatArray(
ColorOverLifetimeModule._maxGradientColor,
color.gradientMax._getColorTypeArray(colorSpace)
);
shaderData.setFloatArray(ColorOverLifetimeModule._maxGradientAlpha, color.gradientMax._getAlphaTypeArray());

if (mode === ParticleGradientMode.Gradient) {
colorMacro = ColorOverLifetimeModule._gradientMacro;
} else {
shaderData.setFloatArray(
ColorOverLifetimeModule._minGradientColor,
color.gradientMin._getColorTypeArray(colorSpace)
);
shaderData.setFloatArray(ColorOverLifetimeModule._minGradientAlpha, color.gradientMin._getAlphaTypeArray());
colorMacro = ColorOverLifetimeModule._randomGradientsMacro;
}
if (mode !== ParticleGradientMode.Gradient && mode !== ParticleGradientMode.TwoGradients) {
throw new Error("Invalid color mode, only gradient and two gradients are supported in color over lifetime.");
}

const colorMinKeys = color.gradientMin.colorKeys;
const alphaMinKeys = color.gradientMin.alphaKeys;
const colorMaxKeys = color.gradientMax.colorKeys;
const alphaMaxKeys = color.gradientMax.alphaKeys;
const color = this.color;
const colorSpace = this._generator._renderer.engine.settings.colorSpace;
shaderData.setFloatArray(
ColorOverLifetimeModule._maxGradientColor,
color.gradientMax._getColorTypeArray(colorSpace)
);
shaderData.setFloatArray(ColorOverLifetimeModule._maxGradientAlpha, color.gradientMax._getAlphaTypeArray());

this._gradientKeysCount.set(
colorMinKeys.length ? colorMinKeys[colorMinKeys.length - 1].time : 0,
alphaMinKeys.length ? alphaMinKeys[alphaMinKeys.length - 1].time : 0,
colorMaxKeys.length ? colorMaxKeys[colorMaxKeys.length - 1].time : 0,
alphaMaxKeys.length ? alphaMaxKeys[alphaMaxKeys.length - 1].time : 0
if (mode === ParticleGradientMode.Gradient) {
colorMacro = ColorOverLifetimeModule._gradientMacro;
} else {
shaderData.setFloatArray(
ColorOverLifetimeModule._minGradientColor,
color.gradientMin._getColorTypeArray(colorSpace)
);
shaderData.setVector4(ColorOverLifetimeModule._gradientKeysCount, this._gradientKeysCount);
shaderData.setFloatArray(ColorOverLifetimeModule._minGradientAlpha, color.gradientMin._getAlphaTypeArray());
colorMacro = ColorOverLifetimeModule._randomGradientsMacro;
}

const colorMinKeys = color.gradientMin.colorKeys;
const alphaMinKeys = color.gradientMin.alphaKeys;
const colorMaxKeys = color.gradientMax.colorKeys;
const alphaMaxKeys = color.gradientMax.alphaKeys;

this._gradientKeysCount.set(
colorMinKeys.length ? colorMinKeys[colorMinKeys.length - 1].time : 0,
alphaMinKeys.length ? alphaMinKeys[alphaMinKeys.length - 1].time : 0,
colorMaxKeys.length ? colorMaxKeys[colorMaxKeys.length - 1].time : 0,
alphaMaxKeys.length ? alphaMaxKeys[alphaMaxKeys.length - 1].time : 0
);
shaderData.setVector4(ColorOverLifetimeModule._gradientKeysCount, this._gradientKeysCount);
}

this._colorMacro = this._enableMacro(shaderData, this._colorMacro, colorMacro);
Expand Down
0