Skip to content

Commit 1b42d92

Browse files
authored
Add option for HalfFloat in vertexAnimationBaker's textureFromBakedVertexData (#16750)
For devices that support it and animations whose precision is not affected by the precision of float16, using HalfFloat can cut down memory usage by 50%. Currently have a warning when the engine caps don't include HalfFloat - don't know if might make sense to return null instead since whatever happens down the line will not be supported, likely crazy polygon soup from the VAT shader.
1 parent 86bda66 commit 1b42d92

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

packages/dev/core/src/BakedVertexAnimation/vertexAnimationBaker.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import type { Scene } from "../scene";
77
import { Constants } from "../Engines/constants";
88
import { Skeleton } from "core/Bones/skeleton";
99
import type { Nullable } from "core/types";
10-
import { ToHalfFloat } from "core/Misc/textureTools";
10+
import { ToHalfFloat } from "../Misc/textureTools";
11+
import { Logger } from "../Misc/logger";
1112

1213
/**
1314
* Class to bake vertex animation textures.
@@ -140,15 +141,22 @@ export class VertexAnimationBaker {
140141
}
141142
/**
142143
* Builds a vertex animation texture given the vertexData in an array.
143-
* @param vertexData The vertex animation data. You can generate it with bakeVertexData().
144+
* @param vertexData The vertex animation data. You can generate it with bakeVertexData(). You can pass in a Float32Array to return a full precision texture, or a Uint16Array to return a half-float texture.
145+
* If you pass in a Uint16Array, make sure your device supports half-float textures
144146
* @returns The vertex animation texture to be used with BakedVertexAnimationManager.
145147
*/
146-
public textureFromBakedVertexData(vertexData: Float32Array): RawTexture {
148+
public textureFromBakedVertexData(vertexData: Float32Array | Uint16Array): RawTexture {
147149
if (!this._skeleton) {
148150
throw new Error("No skeleton provided.");
149151
}
150152
const boneCount = this._skeleton.bones.length;
151153

154+
if (vertexData instanceof Uint16Array) {
155+
if (!this._scene.getEngine().getCaps().textureHalfFloatRender) {
156+
Logger.Warn("VertexAnimationBaker: Half-float textures are not supported on this device");
157+
}
158+
}
159+
152160
const texture = RawTexture.CreateRGBATexture(
153161
vertexData,
154162
(boneCount + 1) * 4,
@@ -157,7 +165,7 @@ export class VertexAnimationBaker {
157165
false,
158166
false,
159167
Texture.NEAREST_NEAREST,
160-
Constants.TEXTURETYPE_FLOAT
168+
vertexData instanceof Float32Array ? Constants.TEXTURETYPE_FLOAT : Constants.TEXTURETYPE_HALF_FLOAT
161169
);
162170
texture.name = "VAT" + this._skeleton.name;
163171
return texture;

0 commit comments

Comments
 (0)