-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from MasatoMakino/add-tests-for-pass
add : unit tests and rendering tests for shader passes
- Loading branch information
Showing
11 changed files
with
294 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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,57 @@ | ||
import { beforeEach, describe, expect, it, test, vi } from "vitest"; | ||
import { renderingPass } from "./PassRender.js"; | ||
import { | ||
BloomEffectComposer, | ||
MixShaderPass, | ||
PostProcessRenderer, | ||
} from "../../src/index.js"; | ||
import { generateScene } from "./SceneGenerator.js"; | ||
import { RenderPass } from "three/examples/jsm/Addons.js"; | ||
import { BoxGeometry, Mesh, MeshBasicMaterial, MeshPhongMaterial } from "three"; | ||
|
||
describe("BloomEffectComposer", () => { | ||
it("should be able to render", () => { | ||
const { scene, camera, webGLRenderer } = generateScene(); | ||
const renderer = new PostProcessRenderer(scene, camera, webGLRenderer); | ||
const renderPass = new RenderPass(scene, camera); | ||
const bloom = new BloomEffectComposer(scene, webGLRenderer, { | ||
renderPass, | ||
}); | ||
|
||
const mixPass = new MixShaderPass(bloom.result); | ||
|
||
renderer.composers.push(bloom); | ||
const composer = renderer.createScreenRenderingComposer( | ||
[mixPass], | ||
renderPass, | ||
); | ||
|
||
const mesh = new Mesh(new BoxGeometry(1, 1, 1), new MeshPhongMaterial()); | ||
const meshWithArray = new Mesh(new BoxGeometry(1, 1, 1), [ | ||
new MeshBasicMaterial(), | ||
new MeshBasicMaterial(), | ||
new MeshBasicMaterial(), | ||
new MeshBasicMaterial(), | ||
new MeshBasicMaterial(), | ||
new MeshBasicMaterial(), | ||
]); | ||
scene.add(mesh, meshWithArray); | ||
|
||
composer.onAfterRender = vi.fn(); | ||
composer.onBeforeRender = vi.fn(); | ||
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {}); | ||
const message = "BloomEffectComposer"; | ||
|
||
renderer.render(0); | ||
renderer.render(1000); | ||
|
||
expect(composer.onAfterRender, message).toBeCalled(); | ||
expect(composer.onBeforeRender, message).toBeCalled(); | ||
expect( | ||
errorSpy, | ||
message + " : The compilation of the fragmentShader", | ||
).not.toBeCalled(); | ||
|
||
errorSpy.mockRestore(); | ||
}); | ||
}); |
35 changes: 35 additions & 0 deletions
35
__test__/postprocess/ChromaticAberrationShaderPass.spec.ts
This file contains 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,35 @@ | ||
import { beforeEach, describe, expect, it, test } from "vitest"; | ||
import { renderingPass } from "./PassRender.js"; | ||
import { ChromaticAberrationShaderPass } from "../../src/index.js"; | ||
|
||
describe("ChromaticAberrationShaderPass", () => { | ||
it("should be able to render", () => { | ||
renderingPass( | ||
"ChromaticAberrationShaderPass", | ||
new ChromaticAberrationShaderPass(), | ||
); | ||
}); | ||
}); | ||
|
||
describe("ChromaticAberrationShaderPass.accessor", () => { | ||
let pass: ChromaticAberrationShaderPass; | ||
|
||
beforeEach(() => { | ||
pass = new ChromaticAberrationShaderPass(); | ||
}); | ||
|
||
test("rate getter and setter", () => { | ||
pass.rate = 0.5; | ||
expect(pass.rate).toBe(0.5); | ||
}); | ||
|
||
test("radiusInner getter and setter", () => { | ||
pass.radiusInner = 0.5; | ||
expect(pass.radiusInner).toBe(0.5); | ||
}); | ||
|
||
test("radiusOuter getter and setter", () => { | ||
pass.radiusOuter = 0.5; | ||
expect(pass.radiusOuter).toBe(0.5); | ||
}); | ||
}); |
This file contains 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,42 @@ | ||
import { beforeEach, describe, expect, it, test } from "vitest"; | ||
import { ColorFilterShaderPass } from "../../src/index.js"; | ||
import { renderingPass } from "./PassRender.js"; | ||
|
||
describe("ColorFilter", () => { | ||
it("should be able to render", () => { | ||
renderingPass("ColorFilterPass", new ColorFilterShaderPass()); | ||
}); | ||
}); | ||
|
||
describe("ColorFilter.accessor", () => { | ||
let pass: ColorFilterShaderPass; | ||
|
||
beforeEach(() => { | ||
pass = new ColorFilterShaderPass(); | ||
}); | ||
|
||
test("h getter and setter", () => { | ||
pass.h = 0.5; | ||
expect(pass.h).toBe(0.5); | ||
}); | ||
|
||
test("multiS getter and setter", () => { | ||
pass.multiS = 0.5; | ||
expect(pass.multiS).toBe(0.5); | ||
}); | ||
|
||
test("multiB getter and setter", () => { | ||
pass.multiB = 0.5; | ||
expect(pass.multiB).toBe(0.5); | ||
}); | ||
|
||
test("addS getter and setter", () => { | ||
pass.addS = 0.5; | ||
expect(pass.addS).toBe(0.5); | ||
}); | ||
|
||
test("addB getter and setter", () => { | ||
pass.addB = 0.5; | ||
expect(pass.addB).toBe(0.5); | ||
}); | ||
}); |
This file contains 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,31 @@ | ||
import { beforeEach, describe, expect, it, test } from "vitest"; | ||
import { renderingPass } from "./PassRender.js"; | ||
import { DisplacementMapShaderPass } from "../../src/index.js"; | ||
|
||
describe("DisplacementMapShaderPass", () => { | ||
it("should be able to render", () => { | ||
renderingPass("DisplacementMapShaderPass", new DisplacementMapShaderPass()); | ||
}); | ||
}); | ||
|
||
describe("DisplacementMapShaderPass.accessor", () => { | ||
let pass: DisplacementMapShaderPass; | ||
|
||
beforeEach(() => { | ||
pass = new DisplacementMapShaderPass(); | ||
}); | ||
|
||
test("strengthX getter and setter", () => { | ||
pass.strengthX = 0.5; | ||
expect(pass.strengthX).toBe(0.5); | ||
}); | ||
|
||
test("strengthY getter and setter", () => { | ||
pass.strengthY = 0.5; | ||
expect(pass.strengthY).toBe(0.5); | ||
}); | ||
|
||
test("map getter and setter", () => { | ||
expect(pass.map).toBeNull(); | ||
}); | ||
}); |
This file contains 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,15 @@ | ||
import { Texture } from "three"; | ||
import { describe, expect, it } from "vitest"; | ||
import { MixShaderPass } from "../../src/index.js"; | ||
import { renderingPass } from "./PassRender.js"; | ||
|
||
describe("MixShaderPass", () => { | ||
it("should be able to render", () => { | ||
const texture = new Texture(); | ||
const pass = new MixShaderPass(texture); | ||
|
||
renderingPass("MixShaderPass", pass); | ||
|
||
expect(texture).toBe(pass.mixTexture); | ||
}); | ||
}); |
This file contains 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,29 @@ | ||
import { beforeEach, describe, expect, it, test } from "vitest"; | ||
import { renderingPass } from "./PassRender.js"; | ||
import { MonotoneShaderPass } from "../../src/index.js"; | ||
import { Color } from "three"; | ||
|
||
describe("MonotoneShaderPass", () => { | ||
it("should be able to render", () => { | ||
renderingPass("MonotoneShaderPass", new MonotoneShaderPass()); | ||
}); | ||
}); | ||
|
||
describe("MonotoneShaderPass.accessor", () => { | ||
let pass: MonotoneShaderPass; | ||
|
||
beforeEach(() => { | ||
pass = new MonotoneShaderPass(); | ||
}); | ||
|
||
test("strength getter and setter", () => { | ||
pass.strength = 0.5; | ||
expect(pass.strength).toBe(0.5); | ||
}); | ||
|
||
test("color getter and setter", () => { | ||
const color = new Color(0x123456); | ||
pass.color = color; | ||
expect(pass.color.getHex()).toBe(color.getHex()); | ||
}); | ||
}); |
This file contains 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,24 @@ | ||
import { expect, vi } from "vitest"; | ||
import { PostProcessRenderer, PostProcessShaderPass } from "../../src/index.js"; | ||
import { generateScene } from "./SceneGenerator.js"; | ||
|
||
export const renderingPass = (message: string, pass: PostProcessShaderPass) => { | ||
const { scene, camera, webGLRenderer } = generateScene(); | ||
const renderer = new PostProcessRenderer(scene, camera, webGLRenderer); | ||
|
||
const composer = renderer.createScreenRenderingComposer([pass]); | ||
composer.onAfterRender = vi.fn(); | ||
composer.onBeforeRender = vi.fn(); | ||
|
||
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {}); | ||
|
||
renderer.render(0); | ||
expect(composer.onAfterRender, message).toBeCalled(); | ||
expect(composer.onBeforeRender, message).toBeCalled(); | ||
expect( | ||
errorSpy, | ||
message + " : The compilation of the fragmentShader", | ||
).not.toBeCalled(); | ||
|
||
errorSpy.mockRestore(); | ||
}; |
This file contains 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,39 @@ | ||
import { beforeEach, describe, expect, it, test } from "vitest"; | ||
import { PeripheralLightShaderPass } from "../../src/index.js"; | ||
import { renderingPass } from "./PassRender.js"; | ||
import { Color } from "three"; | ||
|
||
describe("PeripheralLightShaderPass", () => { | ||
it("should be able to render", () => { | ||
renderingPass("PeripheralLightShaderPass", new PeripheralLightShaderPass()); | ||
}); | ||
}); | ||
|
||
describe("PeripheralLightShaderPass.accessor", () => { | ||
let pass: PeripheralLightShaderPass; | ||
|
||
beforeEach(() => { | ||
pass = new PeripheralLightShaderPass(); | ||
}); | ||
|
||
test("rate getter and setter", () => { | ||
pass.rate = 0.5; | ||
expect(pass.rate).toBe(0.5); | ||
}); | ||
|
||
test("radiusInner getter and setter", () => { | ||
pass.radiusInner = 0.5; | ||
expect(pass.radiusInner).toBe(0.5); | ||
}); | ||
|
||
test("radiusOuter getter and setter", () => { | ||
pass.radiusOuter = 0.5; | ||
expect(pass.radiusOuter).toBe(0.5); | ||
}); | ||
|
||
test("color getter and setter", () => { | ||
const color = new Color(0x123456); | ||
pass.color = color; | ||
expect(pass.color.getHex()).toBe(color.getHex()); | ||
}); | ||
}); |
This file contains 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 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 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,13 @@ | ||
import { PerspectiveCamera, Scene, WebGLRenderer } from "three"; | ||
|
||
const generateWebGLRenderer = (): WebGLRenderer => { | ||
const renderer = new WebGLRenderer(); | ||
return renderer; | ||
}; | ||
|
||
export const generateScene = () => { | ||
const scene = new Scene(); | ||
const camera = new PerspectiveCamera(75, 1, 0.1, 1000); | ||
const webGLRenderer = generateWebGLRenderer(); | ||
return { scene, camera, webGLRenderer }; | ||
}; |