-
-
Notifications
You must be signed in to change notification settings - Fork 304
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
Support trail effects (#1251) #1431
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportPatch coverage:
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## dev/1.0 #1431 +/- ##
===========================================
- Coverage 50.77% 50.67% -0.10%
===========================================
Files 364 364
Lines 18818 18863 +45
Branches 2702 2699 -3
===========================================
+ Hits 9554 9558 +4
- Misses 8307 8348 +41
Partials 957 957
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
did fix |
Component 没有提交上来 |
已经看到 |
constructor(props) { | ||
super(props); | ||
|
||
this._createMaterial(); |
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.
对于所有 Renderer,Material 都应该保持开放性,开发者可以调用接口更换材质对象和修改材质属性。不要在渲染器内部使用绑定和内置策略
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.
已经抽离一个独立的 Trail Material,如果需要自定义 Material 使用 Renderer 的 setMaterial 即可替换。
set trailColor(value: any) { | ||
this._trailColor.copyFrom(value); | ||
this.material.shaderData.setVector4("u_tailColor", value); | ||
} |
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.
Trail Color 属于渲染器,所以其数据存在material 身上并不合理,需要改为renderer
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.
该属性已经与Material解绑,开发者可以在 Shader 中获取 Trail Color 自行实现
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.
this.getMaterial().shaderData.setColor("u_tailColor", value);
逻辑上并未未解绑,依然使用的是材质的 shaderData
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.
this.getMaterial().shaderData.setColor("u_tailColor", value);
逻辑上并未未解绑,依然使用的是材质的 shaderData
已更新为 renderer shaderData
set textureTileT(value: number) { | ||
this._textureTileT = value; | ||
this.material.shaderData.setFloat("u_textureTileT", value); | ||
} |
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.
S 和 T 代表什么,API 和注释要写清楚
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.
已经添加注释
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.
注释里也没有讲清楚 S 和T 是什么,API 要考虑开发者的理解成本
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.
注释里也没有讲清楚 S 和T 是什么,API 要考虑开发者的理解成本
已经更新变量个解释:
/**
- Texture UV S-axis for trail.
- textureScaleY == 1 => Texture AspectFill;
- textureScaleY > 1 => Texture Tile;
- textureScaleY < 1 => Texture Strech;
*/
后续会在案例中演示。
/** | ||
* NodeIDs vertex of trail. | ||
*/ | ||
get nodeIDs(): Float32Array { |
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.
nodeIDs 作为公开 API 对用户的作用和功能是什么,需要考虑清楚,为什么需要这个 API?
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.
确实不需要 Public,已经改为 Private
|
||
set headColor(value: any) { | ||
this._headColor.copyFrom(value); | ||
this.material.shaderData.setVector4("u_headColor", value); |
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.
和 trailColor 一样,不要把渲染器熟悉塞到材质中,同理梳理一下其他的变量
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.
该属性已经与Material解绑,开发者可以在 Shader 中获取 Head Color 自行实现,其他变量也修改。
} | ||
|
||
this._prePointsNum = this._curPointNum; | ||
const currentEntityMatrix = new Matrix(); |
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.
不应该在帧循环中 new Matrix() ,要注意 GC 因素
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.
以修改,使用成员变量。
return this._headColor; | ||
} | ||
|
||
set headColor(value: any) { |
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.
不应该用 any
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.
已修改
拖尾很重要的一个属性是宽度变化,现在是固定宽度,比如尾巴逐渐变窄无法实现 |
this._currentLength = 0; | ||
this._currentEnd = -1; | ||
this._currentNodeIndex = 0; | ||
this._maxLength = this._time * 120; |
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.
默认长度直接采用 maxLength,最好根据使用情况动态扩容
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.
对一个 Trail 来说,Time 是确定的话,因为是跟随屏幕刷新的,
屏幕中显示的 Trail 长度 最多不超过 maxLength = time * FPS,
拖尾运动如果超过 maxLength 可以从头开始复用数组空间,
所以目前这个 maxLength 是不需要扩容的。
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.
要考虑初始内存占用,如果我的设备降级为30帧呢?
} | ||
|
||
/** | ||
* Head color for trail |
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.
这类注释写句号
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.
所有注释都已经补上句号.
// 将 TriangleStrip 分成两个 subMesh, | ||
// 要在第一段末尾多绘制第二段的首节点, | ||
// 不然会出现断层; | ||
let lastIndex = this._currentLength * this._verticesPerNode * 3; |
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.
用英文写注释
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.
// Split TriangleStrip into two subMeshes;
// Copy the head node of the second submesh to the end of the first submesh;
// Avoid gap in the trail.
return this._positions; | ||
} | ||
|
||
set positions(value: Float32Array) { |
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.
把内部顶点数据公开出去的价值是什么,可以考虑下是否要公开
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.
确实不需要 Public,已经改为 Private
和 dev/1.0 的冲突要解决一下 |
冲突已解决。 |
目前先基于匀速的宽度缩减做一个简单实现,下个版本迭代宽度曲线变化。 |
# Conflicts: # packages/core/src/trail/trail.vs.glsl
new VertexElement("a_trailBirthTime", 0, VertexElementFormat.Float, 3), | ||
new VertexElement("a_nodeCenter", 0, VertexElementFormat.Vector3, 4), | ||
]) | ||
mesh.addSubMesh(0, 0, MeshTopology.TriangleStrip); |
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.
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.
案例上最好结合这种贴图,渲染出项目可接受的效果:https://layaair.layabox.com/3.x/demo/resources/res/threeDimen/trail/Assets/tex/wenli00154.jpg 素材图片
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.
案例上最好结合这种贴图,渲染出项目可接受的效果:https://layaair.layabox.com/3.x/demo/resources/res/threeDimen/trail/Assets/tex/wenli00154.jpg 素材图片
纹理的拉伸模式可以通过调整 :
- scaleX&scaleY = 1 -> 纹理 1:1 拉伸遮盖轨迹;
- scaleX&scaleY > 1 -> 纹理缩放平铺 Tile 模式;
- scaleX&scaleY < 1 -> 纹理拉伸裁剪 Stretch 模式;
ScreenFlow.mp4
新增了一个 TextureDragging 参数,设置了之后可以让纹理从头拉长
该案例 scaleX&scaleY = 1 且 TextureDragging = true,
即可复原 laya 的纹理拉伸效果。
mesh.setVertexBufferBinding(trailBirthTimesBuffer, 4, 3); | ||
|
||
const nodeCentersBuffer = new Buffer(this.engine, BufferBindFlag.VertexBuffer, this._nodeCenters, BufferUsage.Dynamic); | ||
mesh.setVertexBufferBinding(nodeCentersBuffer, 12, 4); |
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.
拖尾动态更新的Buffer 需要尽可能合并,每帧多次 setData 对性能有影响
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.
拖尾动态更新的Buffer 需要尽可能合并,每帧多次 setData 对性能有影响
已经将 a_nodeIndex&a_vertexNodeIndex&a_trailBirthTime 三个buffer 的 setData 合并成一个,除此之外都是独立顶点数据。
set time(value: number) { | ||
this._time = value; | ||
this._init(); | ||
this.getMaterial().shaderData.setFloat("u_trailLifeTime", value); |
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.
时间存储在 ShaderData 上,如果两个TrailRenderer 共享一个材质,会不会出错呢?
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.
时间存储在 ShaderData 上,如果两个TrailRenderer 共享一个材质,会不会出错呢?
已经修改成基于 renderer 的 shaderdata
set trailColor(value: any) { | ||
this._trailColor.copyFrom(value); | ||
this.material.shaderData.setVector4("u_tailColor", value); | ||
} |
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.
this.getMaterial().shaderData.setColor("u_tailColor", value);
逻辑上并未未解绑,依然使用的是材质的 shaderData
所有基于 material 的 shaderData 已经全部改成 Renderer 的。 |
新增 TrailRenderer 支持。
playground 效果预览:
https://l60fjz.csb.app/