From 25607709a5e829cad234e79d71b2314f70c4438e Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 10 Mar 2016 21:44:43 -0800 Subject: [PATCH] Add test for skybox --- examples/tests/skybox/px.fs | 18 ++++++ examples/tests/skybox/px_rgba.fs | 20 +++++++ examples/tests/skybox/px_tex.fs | 22 ++++++++ examples/tests/skybox/px_tex_rgba.fs | 24 ++++++++ examples/tests/skybox/skyboxTest.js | 83 ++++++++++++++++++++++++++++ 5 files changed, 167 insertions(+) create mode 100644 examples/tests/skybox/px.fs create mode 100644 examples/tests/skybox/px_rgba.fs create mode 100644 examples/tests/skybox/px_tex.fs create mode 100644 examples/tests/skybox/px_tex_rgba.fs create mode 100644 examples/tests/skybox/skyboxTest.js diff --git a/examples/tests/skybox/px.fs b/examples/tests/skybox/px.fs new file mode 100644 index 0000000000..8b6bdc0e5c --- /dev/null +++ b/examples/tests/skybox/px.fs @@ -0,0 +1,18 @@ +// +// px.fs +// examples/tests/skybox +// +// Created by Zach Pomerantz on 3/10/2016 +// Copyright 2016 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + + +vec3 getSkyboxColor() { + float red = (cos(iGlobalTime) + 1) / 2; + vec3 color = vec3(red, 1.0, 1.0); + + return color; +} + diff --git a/examples/tests/skybox/px_rgba.fs b/examples/tests/skybox/px_rgba.fs new file mode 100644 index 0000000000..59bac7d963 --- /dev/null +++ b/examples/tests/skybox/px_rgba.fs @@ -0,0 +1,20 @@ +// +// px_rgba.fs +// examples/tests/skybox +// +// Created by Zach Pomerantz on 3/10/2016 +// Copyright 2016 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + + +vec3 getSkyboxColor() { + float red = (cos(iGlobalTime) + 1) / 2; + vec3 color = vec3(red, 1.0, 1.0); + + color *= skybox.color.rgb; + + return color; +} + diff --git a/examples/tests/skybox/px_tex.fs b/examples/tests/skybox/px_tex.fs new file mode 100644 index 0000000000..9d9da7ba10 --- /dev/null +++ b/examples/tests/skybox/px_tex.fs @@ -0,0 +1,22 @@ +// +// px_rgba.fs +// examples/tests/skybox +// +// Created by Zach Pomerantz on 3/10/2016 +// Copyright 2016 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + + +vec3 getSkyboxColor() { + float red = (cos(iGlobalTime) + 1) / 2; + vec3 color = vec3(red, 1.0, 1.0); + + vec3 coord = normalize(_normal); + vec3 texel = texture(cubeMap, coord).rgb; + color *= texel; + + return color; +} + diff --git a/examples/tests/skybox/px_tex_rgba.fs b/examples/tests/skybox/px_tex_rgba.fs new file mode 100644 index 0000000000..d44a32e33e --- /dev/null +++ b/examples/tests/skybox/px_tex_rgba.fs @@ -0,0 +1,24 @@ +// +// px_rgba.fs +// examples/tests/skybox +// +// Created by Zach Pomerantz on 3/10/2016 +// Copyright 2016 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + + +vec3 getSkyboxColor() { + float red = (cos(iGlobalTime) + 1) / 2; + vec3 color = vec3(red, 1.0, 1.0); + + vec3 coord = normalize(_normal); + vec3 texel = texture(cubeMap, coord).rgb; + color *= texel; + + color *= skybox.color.rgb; + + return color; +} + diff --git a/examples/tests/skybox/skyboxTest.js b/examples/tests/skybox/skyboxTest.js new file mode 100644 index 0000000000..76d80ab153 --- /dev/null +++ b/examples/tests/skybox/skyboxTest.js @@ -0,0 +1,83 @@ +// skyboxTest.js +// examples/tests/skybox +// +// Created by Zach Pomerantz on 3/10/2016. +// Copyright 2016 High Fidelity, Inc. +// +// This test cycles through different variations on the skybox with a mouseclick. +// For the test to pass, you should observe the following cycle: +// - Procedural skybox (no texture, no color) +// - Procedural skybox (no texture, with color) +// - Procedural skybox (with texture, no color) +// - Procedural skybox (with texture, with color) +// - Color skybox (no texture) +// - Color skybox (with texture) +// - Texture skybox (no color) +// +// As you run the test, descriptions of the expected rendered skybox will appear as overlays. +// +// NOTE: This does not test uniforms/textures applied to a procedural shader through userData. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +var PX_URL = Script.resolvePath('px.fs'); +var PX_RGBA_URL = Script.resolvePath('px_rgba.fs'); +var PX_TEX_URL = Script.resolvePath('px_tex.fs'); +var PX_TEX_RGBA_URL = Script.resolvePath('px_tex_rgba.fs'); + +var TEX_URL = 'https://hifi-public.s3.amazonaws.com/alan/Playa/Skies/Test-Sky_out.png'; +var NO_TEX = ''; + +var COLOR = { red: 255, green: 0, blue: 255 }; +var NO_COLOR = { red: 0, green: 0, blue: 0 }; + +var data = { ProceduralEntity: { shaderUrl: PX_URL } }; + +var zone = Entities.addEntity({ + type: 'Zone', + dimensions: { x: 50, y: 50, z: 50 }, + position: MyAvatar.position, + backgroundMode: 'skybox' +}); +var text = Overlays.addOverlay('text', { + text: 'Click this box to advance tests; note that red value cycling means white->light blue', + x: Window.innerWidth / 2 - 250, y: Window.innerHeight / 2 - 25, + width: 500, height: 50 +}); + +print('Zone:', zone); +print('Text:', text); + +var edits = [ + ['Red value should cycle', getEdit(PX_URL, NO_TEX, NO_COLOR)], + ['Red value should cycle, no green', getEdit(PX_RGBA_URL, NO_TEX, COLOR)], + ['Red value should cycle, each face tinted differently', getEdit(PX_TEX_URL, TEX_URL, NO_COLOR)], + ['Red value should cycle, each face tinted differently, no green', getEdit(PX_TEX_RGBA_URL, TEX_URL, COLOR)], + ['No green', getEdit(null, NO_TEX, COLOR)], + ['Each face colored differently, no green', getEdit(null, TEX_URL, COLOR)], + ['Each face colored differently', getEdit(null, TEX_URL, NO_COLOR)], +]; + +Controller.mousePressEvent.connect(function(e) { if (Overlays.getOverlayAtPoint(e) === text) next(); }); + +Script.scriptEnding.connect(function() { + Overlays.deleteOverlay(text); + Entities.deleteEntity(zone); +}); + +var i = 0; +function next() { + var edit = edits[i]; + Overlays.editOverlay(text, { text: edit[0] }); + Entities.editEntity(zone, edit[1]); + i++; + i %= edits.length; +} + +function getEdit(px, url, color) { + return { userData: px ? getUserData(px) : '', backgroundMode: 'skybox', skybox: { url: url, color: color } } +} +function getUserData(px) { return JSON.stringify({ ProceduralEntity: { shaderUrl: px } }); } +