Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: merge
Browse files Browse the repository at this point in the history
johanzhu committed Aug 21, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 07109f1 + 22f80f0 commit d0b52ab
Showing 20 changed files with 129 additions and 32 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@

[Galacean](https://galacean.antgroup.com/editor) is a **web-first** and **mobile-first** high-performance real-time interactive engine. Use **component system design** and pursue ease of use and light weight. Developers can independently use and write Typescript scripts to develop projects using pure code.

![image](https://github.com/user-attachments/assets/057c2c99-85a8-4ace-a268-c70daa1a449e)

## Features

- 🖥  **Platform** - Support HTML5 and Alipay miniprogram
79 changes: 79 additions & 0 deletions e2e/case/particleRenderer-textureSheetAnimation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* @title Particle TextureSheetAnimation
* @category Particle
*/
import {
AssetType,
BlendMode,
Camera,
Color,
Logger,
ParticleCurveMode,
ParticleMaterial,
ParticleRenderer,
Vector3,
WebGLEngine,
Vector2,
BoxShape,
Entity
} from "@galacean/engine";
import { initScreenshot, updateForE2E } from "./.mockForE2E";

// Create engine
WebGLEngine.create({
canvas: "canvas"
}).then((engine) => {
Logger.enable();
engine.canvas.resizeByClientSize();
const scene = engine.sceneManager.activeScene;

const ambientLight = scene.ambientLight;
ambientLight.diffuseSolidColor.set(0.8, 0.8, 1, 1);
ambientLight.diffuseIntensity = 0.5;

const rootEntity = scene.createRootEntity();
scene.background.solidColor = new Color(25 / 255, 25 / 255, 112 / 255, 1);

// Create camera
const cameraEntity = rootEntity.createChild("camera_entity");
cameraEntity.transform.position = new Vector3(0, 10, 30);
const camera = cameraEntity.addComponent(Camera);
camera.fieldOfView = 60;

engine.run();

engine.resourceManager
.load({
url: "https://mdn.alipayobjects.com/huamei_qbugvr/afts/img/A*5EyLSqmA7q0AAAAAAAAAAAAADtKFAQ/original",
type: AssetType.Texture2D
})
.then((texture) => {
const particleEntity = new Entity(engine);
const particleRenderer = particleEntity.addComponent(ParticleRenderer);

const material = new ParticleMaterial(engine);
material.baseColor = new Color(1.0, 1.0, 1.0, 1.0);
material.blendMode = BlendMode.Additive;
material.baseTexture = texture;
particleRenderer.setMaterial(material);

particleRenderer.generator.useAutoRandomSeed = false;

const shape = new BoxShape();
shape.size.set(22, 1, 0);
particleRenderer.generator.emission.shape = shape;

const { textureSheetAnimation } = particleRenderer.generator;
textureSheetAnimation.enabled = true;
textureSheetAnimation.tiling = new Vector2(5, 3);

textureSheetAnimation.frameOverTime.mode = ParticleCurveMode.TwoConstants;
textureSheetAnimation.frameOverTime.constantMin = 0;
textureSheetAnimation.frameOverTime.constantMax = 3 / 15;

cameraEntity.addChild(particleEntity);

updateForE2E(engine, 500);
initScreenshot(engine, camera);
});
});
5 changes: 5 additions & 0 deletions e2e/config.ts
Original file line number Diff line number Diff line change
@@ -189,6 +189,11 @@ export const E2E_CONFIG = {
category: "Particle",
caseFileName: "particleRenderer-dream",
threshold: 0.3
},
textureSheetAnimation: {
category: "Particle",
caseFileName: "particleRenderer-textureSheetAnimation",
threshold: 0.3
}
},
PostProcess: {
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/video-background.ts
Original file line number Diff line number Diff line change
@@ -92,6 +92,7 @@ void main() {
dom.crossOrigin = "anonymous";
dom.loop = true;
dom.muted = true;
dom.playsInline = true;
dom.play();

// create video background
1 change: 1 addition & 0 deletions examples/video-transparent.ts
Original file line number Diff line number Diff line change
@@ -112,6 +112,7 @@ WebGLEngine.create({ canvas: "canvas" }).then((engine) => {
dom.crossOrigin = "anonymous";
dom.loop = true;
dom.muted = true;
dom.playsInline = true;
dom.play();

// create video texture
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@galacean/engine-core",
"version": "1.3.6",
"version": "1.3.7",
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
21 changes: 15 additions & 6 deletions packages/core/src/particle/ParticleGenerator.ts
Original file line number Diff line number Diff line change
@@ -806,12 +806,21 @@ export class ParticleGenerator {
}

// Simulation UV
if (this.textureSheetAnimation.enabled) {
const tillingInfo = this.textureSheetAnimation._tillingInfo;
instanceVertices[offset + ParticleBufferUtils.simulationUVOffset] = tillingInfo.x;
instanceVertices[offset + 35] = tillingInfo.y;
instanceVertices[offset + 36] = 0;
instanceVertices[offset + 37] = 0;
if (textureSheetAnimation.enabled) {
const { frameOverTime } = textureSheetAnimation;
const { x, y, z } = textureSheetAnimation._tillingInfo;

let tileRow = 0;
if (frameOverTime.mode === ParticleCurveMode.Constant || frameOverTime.mode === ParticleCurveMode.TwoConstants) {
tileRow =
Math.floor(frameOverTime.evaluate(undefined, textureSheetAnimation._frameOverTimeRand.random()) * z) * x;
}
const tileRowIndex = Math.floor(tileRow);

instanceVertices[offset + ParticleBufferUtils.simulationUVOffset] = x;
instanceVertices[offset + 35] = y;
instanceVertices[offset + 36] = tileRow - tileRowIndex;
instanceVertices[offset + 37] = tileRowIndex * y;
} else {
instanceVertices[offset + ParticleBufferUtils.simulationUVOffset] = 1;
instanceVertices[offset + 35] = 1;
Original file line number Diff line number Diff line change
@@ -16,14 +16,12 @@ export class TextureSheetAnimationModule extends ParticleGeneratorModule {
private static readonly _frameCurveMacro = ShaderMacro.getByName("RENDERER_TSA_FRAME_CURVE");
private static readonly _frameRandomCurvesMacro = ShaderMacro.getByName("RENDERER_TSA_FRAME_RANDOM_CURVES");

private static readonly _cycleCountProperty = ShaderProperty.getByName("renderer_TSACycles");
private static readonly _tillingParamsProperty = ShaderProperty.getByName("renderer_TSATillingParams");
private static readonly _frameMinCurveProperty = ShaderProperty.getByName("renderer_TSAFrameMinCurve");
private static readonly _frameMaxCurveProperty = ShaderProperty.getByName("renderer_TSAFrameMaxCurve");

/** Start frame of the texture sheet. */
@deepClone
readonly startFrame = new ParticleCompositeCurve(0);
private static readonly _cycleCountProperty = ShaderProperty.getByName("renderer_TSACycles");
private static readonly _tillingParamsProperty = ShaderProperty.getByName("renderer_TSATillingParams");

/** Frame over time curve of the texture sheet. */
@deepClone
readonly frameOverTime = new ParticleCompositeCurve(new ParticleCurve(new CurveKey(0, 0), new CurveKey(1, 1)));
@@ -42,7 +40,7 @@ export class TextureSheetAnimationModule extends ParticleGeneratorModule {
@deepClone
private _tiling = new Vector2(1, 1);
@ignoreClone
private _textureSheetMacro: ShaderMacro;
private _frameCurveMacro: ShaderMacro;

/**
* Tiling of the texture sheet.
@@ -78,7 +76,7 @@ export class TextureSheetAnimationModule extends ParticleGeneratorModule {
}
}

this._textureSheetMacro = this._enableMacro(shaderData, this._textureSheetMacro, frameMacro);
this._frameCurveMacro = this._enableMacro(shaderData, this._frameCurveMacro, frameMacro);
}

/**
Original file line number Diff line number Diff line change
@@ -2,28 +2,27 @@
uniform float renderer_TSACycles;
uniform vec3 renderer_TSATillingParams; // x:subU y:subV z:tileCount
uniform vec2 renderer_TSAFrameMaxCurve[4]; // x:time y:value
#endif

#ifdef RENDERER_TSA_FRAME_RANDOM_CURVES
uniform vec2 renderer_TSAFrameMinCurve[4]; // x:time y:value
#ifdef RENDERER_TSA_FRAME_RANDOM_CURVES
uniform vec2 renderer_TSAFrameMinCurve[4]; // x:time y:value
#endif
#endif

vec2 computeParticleUV(in vec2 uv, in float normalizedAge) {
#if defined(RENDERER_TSA_FRAME_CURVE) || defined(RENDERER_TSA_FRAME_RANDOM_CURVES)
float scaledNormalizedAge = normalizedAge * renderer_TSACycles;
float cycleNormalizedAge = scaledNormalizedAge - floor(scaledNormalizedAge);
float normalizedFrame = evaluateParticleCurve(renderer_TSAFrameMaxCurve, cycleNormalizedAge);

#ifdef RENDERER_TSA_FRAME_RANDOM_CURVES
normalizedFrame = mix(evaluateParticleCurve(renderer_TSAFrameMinCurve, cycleNormalizedAge), normalizedFrame, a_Random1.x);
#endif

float frame = floor(normalizedFrame * renderer_TSATillingParams.z);

float totalULength = frame * renderer_TSATillingParams.x;
float floorTotalULength = floor(totalULength);
uv.x += totalULength - floorTotalULength;
uv.y += floorTotalULength * renderer_TSATillingParams.y;
float tileRow = frame * renderer_TSATillingParams.x;
float floorTotalULength = floor(tileRow);
uv.x += tileRow - tileRowIndex;
uv.y += tileRowIndex * renderer_TSATillingParams.y;
#endif

return uv;
2 changes: 1 addition & 1 deletion packages/design/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@galacean/engine-design",
"version": "1.3.6",
"version": "1.3.7",
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
2 changes: 1 addition & 1 deletion packages/galacean/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@galacean/engine",
"version": "1.3.6",
"version": "1.3.7",
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
2 changes: 1 addition & 1 deletion packages/loader/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@galacean/engine-loader",
"version": "1.3.6",
"version": "1.3.7",
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
2 changes: 1 addition & 1 deletion packages/math/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@galacean/engine-math",
"version": "1.3.6",
"version": "1.3.7",
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
2 changes: 1 addition & 1 deletion packages/physics-lite/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@galacean/engine-physics-lite",
"version": "1.3.6",
"version": "1.3.7",
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
2 changes: 1 addition & 1 deletion packages/physics-physx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@galacean/engine-physics-physx",
"version": "1.3.6",
"version": "1.3.7",
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
2 changes: 1 addition & 1 deletion packages/rhi-webgl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@galacean/engine-rhi-webgl",
"version": "1.3.6",
"version": "1.3.7",
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
2 changes: 1 addition & 1 deletion packages/shader-lab/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@galacean/engine-shader-lab",
"version": "1.3.6",
"version": "1.3.7",
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
2 changes: 1 addition & 1 deletion packages/xr-webxr/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@galacean/engine-xr-webxr",
"version": "1.3.6",
"version": "1.3.7",
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
2 changes: 1 addition & 1 deletion packages/xr/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@galacean/engine-xr",
"version": "1.3.6",
"version": "1.3.7",
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"

0 comments on commit d0b52ab

Please sign in to comment.