-
-
Notifications
You must be signed in to change notification settings - Fork 395
Support trail render #2873
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
Support trail render #2873
Changes from 3 commits
Commits
Show all changes
85 commits
Select commit
Hold shift + click to select a range
1c376d4
feat: init trail render
GuoLei1990 2d070c1
feat: add e2e testing support for trail renderer
GuoLei1990 f8691ec
chore: remove unnecessary blank lines in trail-related files
GuoLei1990 5c8a90d
feat: add basic trail renderer image for e2e testing
GuoLei1990 72c953d
feat: update TrailRenderer to support texture loading and material setup
GuoLei1990 cdaec88
feat: add trail shader support in ShaderPool
GuoLei1990 0fe1e94
feat: add emissive color and texture support in TrailMaterial
GuoLei1990 2c646ad
feat: refactor TrailMaterial to use new blend and render face enums
GuoLei1990 7c73618
feat: remove unused imports and set render face to default in TrailMa…
GuoLei1990 9be80c4
feat: refactor ParticleMaterial and TrailMaterial to extend EffectMat…
GuoLei1990 b502942
feat: enhance TrailRenderer to optimize vertex buffer updates and man…
GuoLei1990 1ddda45
no message
GuoLei1990 451a2de
feat: optimize bounds calculation in TrailRenderer with caching and d…
GuoLei1990 9f24210
feat: optimize bounds calculation and shader data updates in TrailRen…
GuoLei1990 3f9ed76
feat: remove internal documentation comments and improve variable nam…
GuoLei1990 871a612
feat: simplify property initialization in TrailRenderer
GuoLei1990 461b87d
feat: refactor vertex buffer and primitive initialization in TrailRen…
GuoLei1990 dcd0193
feat: update vertex attributes in TrailRenderer for improved data str…
GuoLei1990 2a8b7b8
feat: streamline property definitions and improve code readability in…
GuoLei1990 aaca29e
feat: optimize color and alpha key handling in TrailRenderer
GuoLei1990 2857302
feat: rename tileScale to textureScale for consistency in TrailRenderer
GuoLei1990 11ecb81
feat: remove unnecessary blank line at the end of EffectMaterial.ts
GuoLei1990 e4350e4
feat: refactor TrailRenderer to use GradientColorKey and GradientAlph…
GuoLei1990 08a4b13
feat: enhance TrailRenderer to support dynamic point capacity and buf…
GuoLei1990 4f15c06
feat: refactor TrailRenderer to eliminate index buffer and optimize v…
GuoLei1990 f08e3ec
refactor: opt code
GuoLei1990 ea809c4
feat: optimize TrailRenderer for better vertex data handling and mate…
GuoLei1990 021144d
feat: simplify TrailRenderer's rendering logic and improve buffer man…
GuoLei1990 5683fab
feat: optimize vertex upload logic in TrailRenderer for improved perf…
GuoLei1990 85eda25
feat: add oldest and newest birth time calculations for UV mapping in…
GuoLei1990 df12aa2
feat: update TrailRenderer settings and optimize background color
GuoLei1990 36eb579
feat: enhance TrailRenderer by managing retired points and optimizing…
GuoLei1990 a113b8f
feat: optimize TrailRenderer update logic and improve point management
GuoLei1990 69d2e82
feat: refine width curve handling in TrailRenderer for improved flexi…
GuoLei1990 66ef04e
feat: update width curve handling in TrailRenderer for improved clari…
GuoLei1990 a1a9c50
feat: streamline shader data updates in TrailRenderer for improved pe…
GuoLei1990 ea58aa7
feat: simplify width curve evaluation in TrailRenderer for improved c…
GuoLei1990 8c7bece
feat: refactor TrailRenderer to use packed uniforms for time and trai…
GuoLei1990 eab4d2e
feat: consolidate static constants in TrailRenderer for improved clar…
GuoLei1990 7700d68
feat: improve comments for clarity in TrailRenderer parameters
GuoLei1990 2ce9918
refactor: opt code
GuoLei1990 e4a5ecf
feat: improve comments for clarity in TrailRenderer
GuoLei1990 18ea3a8
feat: rename subPrimitive variables for clarity in TrailRenderer
GuoLei1990 558d83d
fix: correct vertex count calculation and clean up vertex buffer bind…
GuoLei1990 7a2c617
feat: update point stride constants for improved clarity in TrailRend…
GuoLei1990 c0d31f2
fix: streamline vertex buffer creation and clarify comments in TrailR…
GuoLei1990 864b952
refactor: simplify comments and streamline vertex data migration in T…
GuoLei1990 3151a42
refactor: rename _tryAddNewPoint to _emitNewPoint for clarity in Trai…
GuoLei1990 23dbb36
fix: optimize time parameter updates and streamline vertex upload log…
GuoLei1990 7528533
refactor: improve rendering logic and encapsulate sub-render element …
GuoLei1990 557c533
feat: add segment bounds management for improved trail rendering effi…
GuoLei1990 1dea411
refactor: update segment bounds management for improved frame handlin…
GuoLei1990 fe30e39
refactor: streamline segment bounds generation logic in TrailRenderer
GuoLei1990 f6cfd79
fix: update oldest birth time handling in time parameters for TrailRe…
GuoLei1990 9e10b9c
refactor: reorganize shader parameters and improve point management i…
GuoLei1990 8984ad3
refactor: remove unused segment bounds management in TrailRenderer
GuoLei1990 2b164b0
refactor: optimize world bounds calculation in TrailRenderer
GuoLei1990 bda2efb
refactor: simplify point position initialization in TrailRenderer
GuoLei1990 99cb1af
refactor: move emitting property declaration and improve point initia…
GuoLei1990 4878fa3
refactor: streamline vertex buffer binding and improve point retireme…
GuoLei1990 209faae
refactor: optimize tangent handling and improve active point count ca…
GuoLei1990 09a8fc6
refactor: reorganize uniform declarations for clarity in TrailRenderer
GuoLei1990 8d73117
refactor: opt code
GuoLei1990 9decb80
refactor: enhance gradient handling in TrailRenderer and shader modules
GuoLei1990 bbf45ef
refactor: update TrailRenderer to use distance-based calculations and…
GuoLei1990 be0abf8
refactor: update TrailRenderer image asset with new version and size
GuoLei1990 b67786e
refactor: optimize TrailRenderer bounds calculation and add unit tests
GuoLei1990 18b6ef1
refactor: format code for better readability in TrailRenderer
GuoLei1990 1b3bbc6
refactor: enhance TrailRenderer with multiple artistic trails and mov…
GuoLei1990 c905100
refactor: improve vertex buffer management in TrailRenderer for bette…
GuoLei1990 610fcdf
refactor: streamline vertex processing in TrailRenderer by removing e…
GuoLei1990 768042b
refactor: rename gradientMaxTime to curveMaxTime for consistency in T…
GuoLei1990 40adcb8
refactor: enhance buffer handling in TrailRenderer to improve wrap-ar…
GuoLei1990 3818ceb
refactor: simplify conditional checks and formatting in TrailRenderer…
GuoLei1990 58fda34
refactor: optimize right vector calculation in TrailRenderer for impr…
GuoLei1990 1e7cd8b
refactor: clarify minVertexDistance comment to specify units in Trail…
GuoLei1990 1520daa
refactor: update clone decorators for trail parameters to deepClone i…
GuoLei1990 47a14d7
refactor: calculate half width using max width multiplier from widthC…
GuoLei1990 122ff01
refactor: improve boundary handling in point merging logic in TrailRe…
GuoLei1990 2ebcbc7
refactor: add dirty flag update for retired points in TrailRenderer
GuoLei1990 4787769
refactor: clarify comment for a_PositionBirthTime and remove unused v…
GuoLei1990 698d26a
refactor: update distance parameters in TrailRenderer and shader to u…
GuoLei1990 55c08ee
refactor: update comment for engine.update() in Trail test to clarify…
GuoLei1990 da302d9
refactor: add cumulativeDistance and playTime properties in TrailRend…
GuoLei1990 3dfea8b
refactor: clarify fade-out duration comment in TrailRenderer
GuoLei1990 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| /** | ||
| * @title Trail Renderer Basic | ||
| * @category Trail | ||
| */ | ||
| import { | ||
| Camera, | ||
| Color, | ||
| CurveKey, | ||
| GradientAlphaKey, | ||
| GradientColorKey, | ||
| Logger, | ||
| ParticleCompositeCurve, | ||
| ParticleCurve, | ||
| ParticleGradient, | ||
| Script, | ||
| TrailRenderer, | ||
| Vector3, | ||
| WebGLEngine | ||
| } 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 rootEntity = scene.createRootEntity(); | ||
| scene.background.solidColor = new Color(0.1, 0.1, 0.15, 1); | ||
|
|
||
| // Create camera | ||
| const cameraEntity = rootEntity.createChild("camera"); | ||
| cameraEntity.transform.position = new Vector3(0, 5, 15); | ||
| cameraEntity.transform.lookAt(new Vector3(0, 0, 0)); | ||
| const camera = cameraEntity.addComponent(Camera); | ||
| camera.fieldOfView = 60; | ||
|
|
||
| // Create trail entity | ||
| const trailEntity = rootEntity.createChild("trail"); | ||
| trailEntity.transform.position = new Vector3(0, 0, 0); | ||
|
|
||
| // Add TrailRenderer component | ||
| const trail = trailEntity.addComponent(TrailRenderer); | ||
| trail.time = 2.0; | ||
| trail.width = 0.5; | ||
| trail.minVertexDistance = 0.05; | ||
| trail.color.set(1, 0.5, 0, 1); | ||
|
|
||
| // Setup width curve (taper from head to tail) | ||
| trail.widthCurve = new ParticleCompositeCurve( | ||
| new ParticleCurve(new CurveKey(0, 1), new CurveKey(1, 0)) | ||
| ); | ||
|
|
||
| // Setup color gradient (orange to blue with fade out) | ||
| const gradient = new ParticleGradient( | ||
| [ | ||
| new GradientColorKey(0, new Color(1, 0.5, 0, 1)), | ||
| new GradientColorKey(0.5, new Color(1, 0, 0.5, 1)), | ||
| new GradientColorKey(1, new Color(0, 0.5, 1, 1)) | ||
| ], | ||
| [ | ||
| new GradientAlphaKey(0, 1), | ||
| new GradientAlphaKey(0.7, 0.8), | ||
| new GradientAlphaKey(1, 0) | ||
| ] | ||
| ); | ||
| trail.colorGradient = gradient; | ||
|
|
||
| // Add movement script | ||
| class MoveScript extends Script { | ||
| private _time = 0; | ||
| private _radius = 4; | ||
| private _speed = 2; | ||
| private _verticalSpeed = 1.5; | ||
|
|
||
| onUpdate(deltaTime: number): void { | ||
| this._time += deltaTime; | ||
| const t = this._time * this._speed; | ||
|
|
||
| // Lissajous curve movement | ||
| const x = Math.sin(t) * this._radius; | ||
| const y = Math.sin(t * this._verticalSpeed) * 2; | ||
| const z = Math.cos(t * 0.7) * this._radius; | ||
|
|
||
| this.entity.transform.position.set(x, y, z); | ||
| } | ||
| } | ||
|
|
||
| trailEntity.addComponent(MoveScript); | ||
|
|
||
| // engine.run(); | ||
|
|
||
| // Run for e2e testing | ||
| updateForE2E(engine, 50, 20); | ||
| initScreenshot(engine, camera); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,85 @@ | ||
| import { Color } from "@galacean/engine-math"; | ||
| import { Engine } from "../Engine"; | ||
| import { Material } from "../material/Material"; | ||
| import { BlendFactor, Shader } from "../shader"; | ||
| import { BlendFactor, CullMode, Shader, ShaderPass, SubShader } from "../shader"; | ||
| import { Texture2D } from "../texture"; | ||
| import { ShaderMacro } from "../shader/ShaderMacro"; | ||
| import { ShaderProperty } from "../shader/ShaderProperty"; | ||
| import FRAG_SHADER from "./trail.fs.glsl"; | ||
| import VERT_SHADER from "./trail.vs.glsl"; | ||
|
|
||
| Shader.create("trail", VERT_SHADER, FRAG_SHADER); | ||
|
|
||
| /** | ||
| * Trail material. | ||
| */ | ||
| export class TrailMaterial extends Material { | ||
| private static _baseTextureMacro: ShaderMacro = ShaderMacro.getByName("MATERIAL_HAS_BASETEXTURE"); | ||
| private static _baseColorProp: ShaderProperty = ShaderProperty.getByName("material_BaseColor"); | ||
| private static _baseTextureProp: ShaderProperty = ShaderProperty.getByName("material_BaseTexture"); | ||
|
|
||
| private static _isShaderCreated = false; | ||
|
|
||
| private static _createShader(): void { | ||
| if (TrailMaterial._isShaderCreated) return; | ||
|
|
||
| const shaderPass = new ShaderPass(VERT_SHADER, FRAG_SHADER); | ||
| const subShader = new SubShader("default", [shaderPass]); | ||
| Shader.create("trail", [subShader]); | ||
| TrailMaterial._isShaderCreated = true; | ||
| } | ||
|
|
||
| /** | ||
| * Base color. | ||
| */ | ||
| get baseColor(): Color { | ||
| return this.shaderData.getColor(TrailMaterial._baseColorProp); | ||
| } | ||
|
|
||
| set baseColor(value: Color) { | ||
| const baseColor = this.shaderData.getColor(TrailMaterial._baseColorProp); | ||
| if (value !== baseColor) { | ||
| baseColor.copyFrom(value); | ||
| } | ||
| } | ||
GuoLei1990 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Base texture. | ||
| */ | ||
| get baseTexture(): Texture2D { | ||
| return <Texture2D>this.shaderData.getTexture(TrailMaterial._baseTextureProp); | ||
| } | ||
|
|
||
| set baseTexture(value: Texture2D) { | ||
| this.shaderData.setTexture(TrailMaterial._baseTextureProp, value); | ||
| if (value) { | ||
| this.shaderData.enableMacro(TrailMaterial._baseTextureMacro); | ||
| } else { | ||
| this.shaderData.disableMacro(TrailMaterial._baseTextureMacro); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Create a trail material instance. | ||
| * @param engine - Engine to which the material belongs | ||
| */ | ||
| constructor(engine: Engine) { | ||
| TrailMaterial._createShader(); | ||
| super(engine, Shader.find("trail")); | ||
|
|
||
| const shaderData = this.shaderData; | ||
| shaderData.setColor(TrailMaterial._baseColorProp, new Color(1, 1, 1, 1)); | ||
|
|
||
| // Default blend state for additive blending | ||
| const target = this.renderState.blendState.targetBlendState; | ||
| target.enabled = true; | ||
| target.sourceColorBlendFactor = target.sourceAlphaBlendFactor = BlendFactor.SourceAlpha; | ||
| target.destinationColorBlendFactor = target.destinationAlphaBlendFactor = BlendFactor.One; | ||
| target.sourceColorBlendFactor = BlendFactor.SourceAlpha; | ||
| target.destinationColorBlendFactor = BlendFactor.One; | ||
| target.sourceAlphaBlendFactor = BlendFactor.SourceAlpha; | ||
| target.destinationAlphaBlendFactor = BlendFactor.One; | ||
|
|
||
| // Disable depth write for transparent rendering | ||
| this.renderState.depthState.writeEnabled = false; | ||
|
|
||
| // Disable culling for double-sided rendering | ||
| this.renderState.rasterState.cullMode = CullMode.Off; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused imports BloomEffect, PostProcess, TonemappingEffect, TonemappingMode.