3d-falling-leaves
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese3D Falling Leaves
3D 落叶效果
Make individual leaves turn through face, edge, and back while drifting through the scene. The visible edge-on moment is essential to the effect.
让单片树叶在场景中飘移时,依次呈现正面、边缘和背面的翻转状态。边缘朝向视角的可见时刻是该效果的核心要点。
Build one convincing leaf
打造一片逼真的树叶
Use a two-sided quad or lightly bent mesh with a recognizable leaf silhouette, stem, and restrained vein detail. Camera-facing point sprites cannot turn edge-on. Begin with one slow leaf before increasing the count.
Give the back a slightly paler, less saturated appearance and orient its lighting normal correctly. For a custom shader, can distinguish front/back; do not flip normals twice if the engine's material already handles double-sided lighting. Keep light transmission subtle and linked to the scene sun rather than using an unconditionally glowing leaf.
gl_FrontFacingUse a padded texture atlas for multiple silhouettes. Extend edge colors into transparent texels and keep padding through mip levels to prevent dark rims and atlas bleed. Treat a color atlas as sRGB; treat an atlas encoding masks or material channels as data. Seijaku's procedural atlas encodes channels and is not an ordinary leaf photograph.
使用双面quad或轻微弯曲的mesh,搭配辨识度高的树叶轮廓、叶柄和克制的叶脉细节。朝向相机的point sprites无法实现边缘朝向的翻转效果。先从一片慢速下落的树叶开始调试,再逐步增加数量。
让树叶背面呈现稍浅、饱和度更低的效果,并正确设置其光照法线方向。对于自定义shader,可通过区分正面/背面;如果引擎材质已经处理了双面光照,请勿重复翻转法线。保持光线透射效果细腻,并与场景中的太阳光源关联,而非让树叶无条件自发光。
gl_FrontFacing使用带内边距的texture atlas来实现多种树叶轮廓。将边缘颜色扩展到透明texel中,并在所有mip层级中保持内边距,以避免出现黑边和atlas渗色。彩色图集按照sRGB处理;编码遮罩或材质通道的图集按照数据纹理处理。Seijaku的程序化图集采用通道编码方式,并非普通的树叶照片。
Couple tumble and drift
耦合翻滚与漂移
Assign persistent seeded values per leaf: position seed, scale, phase, tumble rate, roll rate, fall speed, lateral slip, and palette variation. Never generate new random values every frame.
The lateral velocity should follow the tumble, so a leaf slips fastest when edge-on. For angular speed bounded away from zero:
omegajs
const angle = phase + omega * time;
const sideOffset = -(slip / omega) * Math.cos(angle);
// d(sideOffset)/dt = slip * sin(angle)Apply that offset along the leaf's chosen horizontal direction. Use a separate slow roll and tilt; all leaves should not share one rhythm. Add a common wind field with small per-leaf response variation. Integrate changing wind over bounded simulation steps, or use a closed-form field; never catch up an entire hidden-tab interval with an unbounded loop.
为每片树叶分配持久的种子值:位置种子、缩放、相位、翻滚速率、滚动速率、下落速度、侧向滑移量和调色板变化。切勿每帧都生成新的随机值。
侧向速度应与翻滚动作联动,因此树叶在边缘朝向视角时滑移速度最快。对于不为零的角速度:
omegajs
const angle = phase + omega * time;
const sideOffset = -(slip / omega) * Math.cos(angle);
// d(sideOffset)/dt = slip * sin(angle)沿着树叶选定的水平方向应用该偏移量。添加独立的慢速滚动和倾斜效果;不要让所有树叶遵循相同的运动节奏。添加公共风场,并为每片树叶设置微小的响应差异。在有限的模拟步长内积分变化的风力,或使用闭式风场;切勿使用无边界循环来补全整个标签页隐藏期间的时间差。
Instance and recycle
实例化与回收
Use an with reusable CPU scratch objects for moderate counts, or instanced attributes and shader animation for larger fields. Upload seeded attributes once; update time, wind, season amount, and camera anchor uniforms. Refresh instance matrices/bounds correctly when using the CPU path. See InstancedMesh.
InstancedMeshCenter the recycling volume ahead of the camera along its horizontal viewing direction. Retain a fallback horizontal direction when looking nearly straight up or down. Preserve existing world positions as the camera moves; move the spawn/wrap boundaries rather than parenting all live leaves to the camera.
Wrap outside the visible central volume. Fade near boundaries with , where ; reversed GLSL edges are undefined. Hide reset events beyond the fog, near the volume top, or behind a soft boundary fade. Seed each fall cycle for variation without frame-to-frame jitter.
1.0 - smoothstep(inner, outer, distance)inner < outersmoothstepStart with a sparse field and tighten its visible volume before increasing the count. Distinguish capacity, active count, and leaves actually visible. Use a few near leaves, a readable middle layer, and smaller distant leaves. Keep the closest leaves from covering the camera as giant blurred shapes.
对于中等数量的树叶,使用搭配可复用的CPU临时对象;对于更大规模的叶群,则使用实例化属性和shader动画。一次性上传种子属性;仅更新时间、风力、季节程度和相机锚点等uniform变量。使用CPU路径时,需正确刷新实例矩阵/边界。参考InstancedMesh。
InstancedMesh将回收体积的中心设置在相机水平视向前方。当相机几乎垂直向上或向下看时,保留一个备用水平方向。相机移动时保留树叶的现有世界坐标;只需移动生成/包裹边界,而非将所有活动树叶都设为相机的子对象。
在可见中心体积之外进行包裹处理。使用在边界附近实现淡出效果,其中;GLSL中的边缘顺序反转时结果是未定义的。将重置操作隐藏在雾效之外、体积顶部附近或软边界淡出效果之后。为每个下落周期设置种子,以保证变化性且不会出现逐帧抖动。
1.0 - smoothstep(inner, outer, distance)inner < outersmoothstep先从稀疏的叶群开始,收紧其可见体积后再增加树叶数量。区分容量、活动数量和实际可见的树叶数量。使用少量近景树叶、清晰的中景层,以及更小的远景树叶。避免最近的树叶以巨大的模糊形状遮挡相机。
Integrate with the world
与场景世界融合
- Depth-test against architecture and ground. Exclude covered interior volumes or provide roof/terrain collision proxies; depth testing alone does not prevent leaves falling inside rooms.
- For crisp silhouettes, alpha testing with depth writes is a useful default. MSAA alpha-to-coverage can soften edges only when the actual target is multisampled. A custom shader must implement its alpha rejection; material settings alone do not insert arbitrary custom shader logic.
- If alpha blending is needed, handle depth writes and sorting deliberately. Instances are not individually depth-sorted by default.
- Match leaf cutouts and wind deformation in any shadow or occlusion pass. Disable leaf shadow casting when its cost or artifacts outweigh its visual contribution.
- Let seasonal state control palette and active density; do not allocate a new leaf system per season.
- 针对建筑和地面进行深度测试。排除被遮盖的内部体积,或提供屋顶/地形碰撞代理;仅靠深度测试无法避免树叶飘进室内。
- 若要获得清晰的轮廓,启用alpha测试并开启深度写入是实用的默认方案。MSAA的alpha-to-coverage仅在实际渲染目标为多采样时才能柔化边缘。自定义shader必须自行实现alpha剔除;仅靠材质设置无法插入任意自定义shader逻辑。
- 如果需要alpha混合,需谨慎处理深度写入和排序。默认情况下,实例不会单独进行深度排序。
- 在所有阴影或遮挡通道中,保持树叶裁剪和风力形变的一致性。当树叶阴影的性能开销或瑕疵超过其视觉贡献时,应禁用阴影投射。
- 让季节状态控制调色板和活动密度;不要为每个季节都分配新的树叶系统。
Verify
验证效果
Watch one leaf complete a tumble and a full fall cycle. Confirm its face/back differ, its edge thins, and its reset is hidden. Walk sideways, turn around, look up, enter a room, and resume after hiding the tab. Check the field at narrow and wide viewports, through the final tone mapper, and with reduced motion frozen at a composed state. Measure overdraw and update cost instead of assuming particles are free.
Read REFERENCES.md for the reference implementation. Seijaku's provides the closed-form animation pattern; replace its hardcoded roof rectangles with the target scene's geometry or volumes.
leafFall观察一片树叶完成一次翻滚和完整的下落周期。确认其正面/背面有差异、边缘会变细,且重置过程不可见。横向移动、转身、抬头看、进入室内,以及隐藏标签页后再恢复,都要测试一遍。在窄视口和宽视口下、经过最终色调映射后,以及在减少动效并冻结为构图状态时,都要检查叶群效果。实测过度绘制和更新开销,不要想当然地认为粒子效果是零成本的。
参考REFERENCES.md查看参考实现。Seijaku的提供了闭式动画模式;请将其硬编码的屋顶矩形替换为目标场景的几何体或体积。
leafFall