Refactor uniform creation in water material shaders and tests
This commit is contained in:
@@ -933,9 +933,8 @@ export function createWaterMaterial(options) {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const uniforms = UniformsUtils.merge([
|
const uniforms = UniformsUtils.clone(UniformsLib.fog);
|
||||||
UniformsLib.fog,
|
Object.assign(uniforms, {
|
||||||
{
|
|
||||||
time: animationUniform,
|
time: animationUniform,
|
||||||
waterColor: { value: [cr, cg, cb] },
|
waterColor: { value: [cr, cg, cb] },
|
||||||
surfaceOpacity: { value: clampedOpacity },
|
surfaceOpacity: { value: clampedOpacity },
|
||||||
@@ -949,8 +948,7 @@ export function createWaterMaterial(options) {
|
|||||||
reflectionTexture: reflectionTextureUniform,
|
reflectionTexture: reflectionTextureUniform,
|
||||||
reflectionMatrix: reflectionMatrixUniform,
|
reflectionMatrix: reflectionMatrixUniform,
|
||||||
reflectionEnabled: reflectionEnabledUniform
|
reflectionEnabled: reflectionEnabledUniform
|
||||||
}
|
});
|
||||||
]);
|
|
||||||
|
|
||||||
const material = new ShaderMaterial({
|
const material = new ShaderMaterial({
|
||||||
vertexShader,
|
vertexShader,
|
||||||
|
|||||||
@@ -1188,9 +1188,8 @@ export function createWaterMaterial(options: WaterMaterialOptions): WaterMateria
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const uniforms = UniformsUtils.merge([
|
const uniforms = UniformsUtils.clone(UniformsLib.fog);
|
||||||
UniformsLib.fog,
|
Object.assign(uniforms, {
|
||||||
{
|
|
||||||
time: animationUniform,
|
time: animationUniform,
|
||||||
waterColor: { value: [cr, cg, cb] },
|
waterColor: { value: [cr, cg, cb] },
|
||||||
surfaceOpacity: { value: clampedOpacity },
|
surfaceOpacity: { value: clampedOpacity },
|
||||||
@@ -1204,8 +1203,7 @@ export function createWaterMaterial(options: WaterMaterialOptions): WaterMateria
|
|||||||
reflectionTexture: reflectionTextureUniform,
|
reflectionTexture: reflectionTextureUniform,
|
||||||
reflectionMatrix: reflectionMatrixUniform,
|
reflectionMatrix: reflectionMatrixUniform,
|
||||||
reflectionEnabled: reflectionEnabledUniform
|
reflectionEnabled: reflectionEnabledUniform
|
||||||
}
|
});
|
||||||
]);
|
|
||||||
|
|
||||||
const material = new ShaderMaterial({
|
const material = new ShaderMaterial({
|
||||||
vertexShader,
|
vertexShader,
|
||||||
|
|||||||
@@ -616,5 +616,14 @@ describe("water material helpers", () => {
|
|||||||
expect(result.reflectionTextureUniform).not.toBeNull();
|
expect(result.reflectionTextureUniform).not.toBeNull();
|
||||||
expect(result.reflectionMatrixUniform).not.toBeNull();
|
expect(result.reflectionMatrixUniform).not.toBeNull();
|
||||||
expect(result.reflectionEnabledUniform?.value).toBe(0);
|
expect(result.reflectionEnabledUniform?.value).toBe(0);
|
||||||
|
expect(result.animationUniform).toBe(material.uniforms["time"]);
|
||||||
|
expect(result.reflectionEnabledUniform).toBe(material.uniforms["reflectionEnabled"]);
|
||||||
|
|
||||||
|
if (result.animationUniform !== null && result.reflectionEnabledUniform !== null) {
|
||||||
|
result.animationUniform.value = 2.5;
|
||||||
|
result.reflectionEnabledUniform.value = 0.36;
|
||||||
|
expect(material.uniforms["time"]?.value).toBe(2.5);
|
||||||
|
expect(material.uniforms["reflectionEnabled"]?.value).toBe(0.36);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user