diff --git a/model/cubemap/assets/SourceSansPro-Semibold.ttf b/model/cubemap/assets/SourceSansPro-Semibold.ttf deleted file mode 100755 index 50205948..00000000 Binary files a/model/cubemap/assets/SourceSansPro-Semibold.ttf and /dev/null differ diff --git a/model/cubemap/assets/images/bar_round_large_grey.png b/model/cubemap/assets/images/bar_round_large_grey.png deleted file mode 100644 index 9486a6db..00000000 Binary files a/model/cubemap/assets/images/bar_round_large_grey.png and /dev/null differ diff --git a/model/cubemap/assets/images/bar_round_large_red.png b/model/cubemap/assets/images/bar_round_large_red.png deleted file mode 100644 index a6dcdc2f..00000000 Binary files a/model/cubemap/assets/images/bar_round_large_red.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee01.png b/model/cubemap/assets/images/bee/Bee01.png deleted file mode 100644 index c5f2fef3..00000000 Binary files a/model/cubemap/assets/images/bee/Bee01.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee02.png b/model/cubemap/assets/images/bee/Bee02.png deleted file mode 100644 index e121d4e7..00000000 Binary files a/model/cubemap/assets/images/bee/Bee02.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee03.png b/model/cubemap/assets/images/bee/Bee03.png deleted file mode 100644 index a6deb88b..00000000 Binary files a/model/cubemap/assets/images/bee/Bee03.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee04.png b/model/cubemap/assets/images/bee/Bee04.png deleted file mode 100644 index 60d3a97f..00000000 Binary files a/model/cubemap/assets/images/bee/Bee04.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee05.png b/model/cubemap/assets/images/bee/Bee05.png deleted file mode 100644 index 88aed730..00000000 Binary files a/model/cubemap/assets/images/bee/Bee05.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee06.png b/model/cubemap/assets/images/bee/Bee06.png deleted file mode 100644 index 9778f352..00000000 Binary files a/model/cubemap/assets/images/bee/Bee06.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee07.png b/model/cubemap/assets/images/bee/Bee07.png deleted file mode 100644 index a242c19e..00000000 Binary files a/model/cubemap/assets/images/bee/Bee07.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee08.png b/model/cubemap/assets/images/bee/Bee08.png deleted file mode 100644 index a79e4fe5..00000000 Binary files a/model/cubemap/assets/images/bee/Bee08.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee09.png b/model/cubemap/assets/images/bee/Bee09.png deleted file mode 100644 index 4977f9bf..00000000 Binary files a/model/cubemap/assets/images/bee/Bee09.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee10.png b/model/cubemap/assets/images/bee/Bee10.png deleted file mode 100644 index 8ff369f0..00000000 Binary files a/model/cubemap/assets/images/bee/Bee10.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee11.png b/model/cubemap/assets/images/bee/Bee11.png deleted file mode 100644 index bf1e616b..00000000 Binary files a/model/cubemap/assets/images/bee/Bee11.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee12.png b/model/cubemap/assets/images/bee/Bee12.png deleted file mode 100644 index cb6f2661..00000000 Binary files a/model/cubemap/assets/images/bee/Bee12.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee13.png b/model/cubemap/assets/images/bee/Bee13.png deleted file mode 100644 index 2cd74e24..00000000 Binary files a/model/cubemap/assets/images/bee/Bee13.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee14.png b/model/cubemap/assets/images/bee/Bee14.png deleted file mode 100644 index e3c2c57a..00000000 Binary files a/model/cubemap/assets/images/bee/Bee14.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee15.png b/model/cubemap/assets/images/bee/Bee15.png deleted file mode 100644 index 87b6eff4..00000000 Binary files a/model/cubemap/assets/images/bee/Bee15.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee16.png b/model/cubemap/assets/images/bee/Bee16.png deleted file mode 100644 index 25cdd151..00000000 Binary files a/model/cubemap/assets/images/bee/Bee16.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee17.png b/model/cubemap/assets/images/bee/Bee17.png deleted file mode 100644 index a4d73a60..00000000 Binary files a/model/cubemap/assets/images/bee/Bee17.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee18.png b/model/cubemap/assets/images/bee/Bee18.png deleted file mode 100644 index bca01fee..00000000 Binary files a/model/cubemap/assets/images/bee/Bee18.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee19.png b/model/cubemap/assets/images/bee/Bee19.png deleted file mode 100644 index 130ddb62..00000000 Binary files a/model/cubemap/assets/images/bee/Bee19.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee20.png b/model/cubemap/assets/images/bee/Bee20.png deleted file mode 100644 index e9f9a974..00000000 Binary files a/model/cubemap/assets/images/bee/Bee20.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee21.png b/model/cubemap/assets/images/bee/Bee21.png deleted file mode 100644 index a272b572..00000000 Binary files a/model/cubemap/assets/images/bee/Bee21.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee22.png b/model/cubemap/assets/images/bee/Bee22.png deleted file mode 100644 index 4e6f10e9..00000000 Binary files a/model/cubemap/assets/images/bee/Bee22.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee23.png b/model/cubemap/assets/images/bee/Bee23.png deleted file mode 100644 index bd8d4a20..00000000 Binary files a/model/cubemap/assets/images/bee/Bee23.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee24.png b/model/cubemap/assets/images/bee/Bee24.png deleted file mode 100644 index 9e6135a3..00000000 Binary files a/model/cubemap/assets/images/bee/Bee24.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee_shot01.png b/model/cubemap/assets/images/bee/Bee_shot01.png deleted file mode 100644 index a334d16d..00000000 Binary files a/model/cubemap/assets/images/bee/Bee_shot01.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee_shot02.png b/model/cubemap/assets/images/bee/Bee_shot02.png deleted file mode 100644 index fd74875c..00000000 Binary files a/model/cubemap/assets/images/bee/Bee_shot02.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee_shot03.png b/model/cubemap/assets/images/bee/Bee_shot03.png deleted file mode 100644 index 48d2d6c0..00000000 Binary files a/model/cubemap/assets/images/bee/Bee_shot03.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee_shot04.png b/model/cubemap/assets/images/bee/Bee_shot04.png deleted file mode 100644 index 0b80ded3..00000000 Binary files a/model/cubemap/assets/images/bee/Bee_shot04.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee_shot05.png b/model/cubemap/assets/images/bee/Bee_shot05.png deleted file mode 100644 index b8799bce..00000000 Binary files a/model/cubemap/assets/images/bee/Bee_shot05.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee_shot06.png b/model/cubemap/assets/images/bee/Bee_shot06.png deleted file mode 100644 index 0fc01d07..00000000 Binary files a/model/cubemap/assets/images/bee/Bee_shot06.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee_shot07.png b/model/cubemap/assets/images/bee/Bee_shot07.png deleted file mode 100644 index a6ce6085..00000000 Binary files a/model/cubemap/assets/images/bee/Bee_shot07.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee_shot08.png b/model/cubemap/assets/images/bee/Bee_shot08.png deleted file mode 100644 index 900b250e..00000000 Binary files a/model/cubemap/assets/images/bee/Bee_shot08.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee_shot09.png b/model/cubemap/assets/images/bee/Bee_shot09.png deleted file mode 100644 index ac45bc8f..00000000 Binary files a/model/cubemap/assets/images/bee/Bee_shot09.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Bee_shot10.png b/model/cubemap/assets/images/bee/Bee_shot10.png deleted file mode 100644 index 8155ae6b..00000000 Binary files a/model/cubemap/assets/images/bee/Bee_shot10.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Sting01.png b/model/cubemap/assets/images/bee/Sting01.png deleted file mode 100644 index 62ebb7e5..00000000 Binary files a/model/cubemap/assets/images/bee/Sting01.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Sting02.png b/model/cubemap/assets/images/bee/Sting02.png deleted file mode 100644 index c9e6e849..00000000 Binary files a/model/cubemap/assets/images/bee/Sting02.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Sting03.png b/model/cubemap/assets/images/bee/Sting03.png deleted file mode 100644 index 595a3d5f..00000000 Binary files a/model/cubemap/assets/images/bee/Sting03.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Sting04.png b/model/cubemap/assets/images/bee/Sting04.png deleted file mode 100644 index 525bb022..00000000 Binary files a/model/cubemap/assets/images/bee/Sting04.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Sting05.png b/model/cubemap/assets/images/bee/Sting05.png deleted file mode 100644 index 7eb5ae95..00000000 Binary files a/model/cubemap/assets/images/bee/Sting05.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Sting06.png b/model/cubemap/assets/images/bee/Sting06.png deleted file mode 100644 index fd1d8f3e..00000000 Binary files a/model/cubemap/assets/images/bee/Sting06.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Sting07.png b/model/cubemap/assets/images/bee/Sting07.png deleted file mode 100644 index 5a56c3bb..00000000 Binary files a/model/cubemap/assets/images/bee/Sting07.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Sting08.png b/model/cubemap/assets/images/bee/Sting08.png deleted file mode 100644 index 5ff6c1e9..00000000 Binary files a/model/cubemap/assets/images/bee/Sting08.png and /dev/null differ diff --git a/model/cubemap/assets/images/bee/Sting09.png b/model/cubemap/assets/images/bee/Sting09.png deleted file mode 100644 index bd15342a..00000000 Binary files a/model/cubemap/assets/images/bee/Sting09.png and /dev/null differ diff --git a/model/cubemap/assets/images/bunny1_ready.png b/model/cubemap/assets/images/bunny1_ready.png deleted file mode 100755 index be968a81..00000000 Binary files a/model/cubemap/assets/images/bunny1_ready.png and /dev/null differ diff --git a/model/cubemap/assets/images/bunny2_ready.png b/model/cubemap/assets/images/bunny2_ready.png deleted file mode 100755 index 12216d98..00000000 Binary files a/model/cubemap/assets/images/bunny2_ready.png and /dev/null differ diff --git a/model/cubemap/assets/images/carrot.png b/model/cubemap/assets/images/carrot.png deleted file mode 100755 index d630937f..00000000 Binary files a/model/cubemap/assets/images/carrot.png and /dev/null differ diff --git a/model/cubemap/assets/images/close.png b/model/cubemap/assets/images/close.png deleted file mode 100644 index de1a2ca3..00000000 Binary files a/model/cubemap/assets/images/close.png and /dev/null differ diff --git a/model/cubemap/assets/images/coin/dcoin_1.png b/model/cubemap/assets/images/coin/dcoin_1.png deleted file mode 100644 index fe991c27..00000000 Binary files a/model/cubemap/assets/images/coin/dcoin_1.png and /dev/null differ diff --git a/model/cubemap/assets/images/coin/dcoin_2.png b/model/cubemap/assets/images/coin/dcoin_2.png deleted file mode 100644 index 5b862ff5..00000000 Binary files a/model/cubemap/assets/images/coin/dcoin_2.png and /dev/null differ diff --git a/model/cubemap/assets/images/coin/dcoin_3.png b/model/cubemap/assets/images/coin/dcoin_3.png deleted file mode 100644 index d09ac010..00000000 Binary files a/model/cubemap/assets/images/coin/dcoin_3.png and /dev/null differ diff --git a/model/cubemap/assets/images/coin/dcoin_4.png b/model/cubemap/assets/images/coin/dcoin_4.png deleted file mode 100644 index f5a6c64e..00000000 Binary files a/model/cubemap/assets/images/coin/dcoin_4.png and /dev/null differ diff --git a/model/cubemap/assets/images/coin/dcoin_5.png b/model/cubemap/assets/images/coin/dcoin_5.png deleted file mode 100644 index ce40d5b6..00000000 Binary files a/model/cubemap/assets/images/coin/dcoin_5.png and /dev/null differ diff --git a/model/cubemap/assets/images/crosshair010.png b/model/cubemap/assets/images/crosshair010.png deleted file mode 100755 index ca83cce3..00000000 Binary files a/model/cubemap/assets/images/crosshair010.png and /dev/null differ diff --git a/model/cubemap/assets/images/elementMetal001.png b/model/cubemap/assets/images/elementMetal001.png deleted file mode 100755 index 22ba2237..00000000 Binary files a/model/cubemap/assets/images/elementMetal001.png and /dev/null differ diff --git a/model/cubemap/assets/images/elementStone019.png b/model/cubemap/assets/images/elementStone019.png deleted file mode 100755 index 0a85d3f2..00000000 Binary files a/model/cubemap/assets/images/elementStone019.png and /dev/null differ diff --git a/model/cubemap/assets/images/elementStone023.png b/model/cubemap/assets/images/elementStone023.png deleted file mode 100755 index a302187b..00000000 Binary files a/model/cubemap/assets/images/elementStone023.png and /dev/null differ diff --git a/model/cubemap/assets/images/enemyBlack1.png b/model/cubemap/assets/images/enemyBlack1.png deleted file mode 100755 index bc2fa4c1..00000000 Binary files a/model/cubemap/assets/images/enemyBlack1.png and /dev/null differ diff --git a/model/cubemap/assets/images/enemyFloating_1.png b/model/cubemap/assets/images/enemyFloating_1.png deleted file mode 100644 index d06ec183..00000000 Binary files a/model/cubemap/assets/images/enemyFloating_1.png and /dev/null differ diff --git a/model/cubemap/assets/images/flame.png b/model/cubemap/assets/images/flame.png deleted file mode 100755 index 083f8c56..00000000 Binary files a/model/cubemap/assets/images/flame.png and /dev/null differ diff --git a/model/cubemap/assets/images/green_button03.png b/model/cubemap/assets/images/green_button03.png deleted file mode 100755 index 3add9b6e..00000000 Binary files a/model/cubemap/assets/images/green_button03.png and /dev/null differ diff --git a/model/cubemap/assets/images/grid.png b/model/cubemap/assets/images/grid.png deleted file mode 100644 index d23eb9d7..00000000 Binary files a/model/cubemap/assets/images/grid.png and /dev/null differ diff --git a/model/cubemap/assets/images/header.png b/model/cubemap/assets/images/header.png deleted file mode 100644 index 04f48506..00000000 Binary files a/model/cubemap/assets/images/header.png and /dev/null differ diff --git a/model/cubemap/assets/images/hitman1_machine.png b/model/cubemap/assets/images/hitman1_machine.png deleted file mode 100755 index ddc7f059..00000000 Binary files a/model/cubemap/assets/images/hitman1_machine.png and /dev/null differ diff --git a/model/cubemap/assets/images/laserYellow_burst.png b/model/cubemap/assets/images/laserYellow_burst.png deleted file mode 100755 index 0496e0ce..00000000 Binary files a/model/cubemap/assets/images/laserYellow_burst.png and /dev/null differ diff --git a/model/cubemap/assets/images/lighting_blue.png b/model/cubemap/assets/images/lighting_blue.png deleted file mode 100755 index 784da1e2..00000000 Binary files a/model/cubemap/assets/images/lighting_blue.png and /dev/null differ diff --git a/model/cubemap/assets/images/logo-color.png b/model/cubemap/assets/images/logo-color.png deleted file mode 100644 index 0e227dcf..00000000 Binary files a/model/cubemap/assets/images/logo-color.png and /dev/null differ diff --git a/model/cubemap/assets/images/particle_brown.png b/model/cubemap/assets/images/particle_brown.png deleted file mode 100755 index 652076a3..00000000 Binary files a/model/cubemap/assets/images/particle_brown.png and /dev/null differ diff --git a/model/cubemap/assets/images/pattern_circle.png b/model/cubemap/assets/images/pattern_circle.png deleted file mode 100644 index 221dce93..00000000 Binary files a/model/cubemap/assets/images/pattern_circle.png and /dev/null differ diff --git a/model/cubemap/assets/images/plank_slice.png b/model/cubemap/assets/images/plank_slice.png deleted file mode 100644 index 7b8a5cae..00000000 Binary files a/model/cubemap/assets/images/plank_slice.png and /dev/null differ diff --git a/model/cubemap/assets/images/playerShip1_red.png b/model/cubemap/assets/images/playerShip1_red.png deleted file mode 100755 index 3695e09e..00000000 Binary files a/model/cubemap/assets/images/playerShip1_red.png and /dev/null differ diff --git a/model/cubemap/assets/images/rainbow.png b/model/cubemap/assets/images/rainbow.png deleted file mode 100644 index 00ea4574..00000000 Binary files a/model/cubemap/assets/images/rainbow.png and /dev/null differ diff --git a/model/cubemap/assets/images/red_button12.png b/model/cubemap/assets/images/red_button12.png deleted file mode 100755 index 7b6a2327..00000000 Binary files a/model/cubemap/assets/images/red_button12.png and /dev/null differ diff --git a/model/cubemap/assets/images/shipBeige_manned.png b/model/cubemap/assets/images/shipBeige_manned.png deleted file mode 100755 index 552a8438..00000000 Binary files a/model/cubemap/assets/images/shipBeige_manned.png and /dev/null differ diff --git a/model/cubemap/assets/images/shipBlue_manned.png b/model/cubemap/assets/images/shipBlue_manned.png deleted file mode 100644 index c5ecb9fa..00000000 Binary files a/model/cubemap/assets/images/shipBlue_manned.png and /dev/null differ diff --git a/model/cubemap/assets/images/shipGreen_manned.png b/model/cubemap/assets/images/shipGreen_manned.png deleted file mode 100644 index 82815b6a..00000000 Binary files a/model/cubemap/assets/images/shipGreen_manned.png and /dev/null differ diff --git a/model/cubemap/assets/images/shipPink_manned.png b/model/cubemap/assets/images/shipPink_manned.png deleted file mode 100644 index fb7c49e7..00000000 Binary files a/model/cubemap/assets/images/shipPink_manned.png and /dev/null differ diff --git a/model/cubemap/assets/images/smoke.png b/model/cubemap/assets/images/smoke.png deleted file mode 100755 index 21a4e68c..00000000 Binary files a/model/cubemap/assets/images/smoke.png and /dev/null differ diff --git a/model/cubemap/assets/images/spinner.png b/model/cubemap/assets/images/spinner.png deleted file mode 100644 index 27a9025b..00000000 Binary files a/model/cubemap/assets/images/spinner.png and /dev/null differ diff --git a/model/cubemap/assets/images/tilesheet_complete.png b/model/cubemap/assets/images/tilesheet_complete.png deleted file mode 100644 index 3403051d..00000000 Binary files a/model/cubemap/assets/images/tilesheet_complete.png and /dev/null differ diff --git a/model/cubemap/assets/sprites.atlas b/model/cubemap/assets/sprites.atlas deleted file mode 100644 index fa71c484..00000000 --- a/model/cubemap/assets/sprites.atlas +++ /dev/null @@ -1,93 +0,0 @@ -images { - image: "/assets/images/spinner.png" -} -images { - image: "/assets/images/elementStone019.png" -} -images { - image: "/assets/images/elementStone023.png" -} -images { - image: "/assets/images/bunny1_ready.png" -} -images { - image: "/assets/images/bunny2_ready.png" -} -images { - image: "/assets/images/carrot.png" -} -images { - image: "/assets/images/red_button12.png" -} -images { - image: "/assets/images/flame.png" -} -images { - image: "/assets/images/smoke.png" -} -images { - image: "/assets/images/rainbow.png" -} -images { - image: "/assets/images/enemyFloating_1.png" -} -images { - image: "/assets/images/logo-color.png" -} -images { - image: "/assets/images/shipGreen_manned.png" -} -images { - image: "/assets/images/elementMetal001.png" -} -images { - image: "/assets/images/plank_slice.png" -} -images { - image: "/assets/images/hitman1_machine.png" -} -images { - image: "/assets/images/green_button03.png" -} -images { - image: "/assets/images/playerShip1_red.png" -} -images { - image: "/assets/images/enemyBlack1.png" -} -images { - image: "/assets/images/lighting_blue.png" -} -images { - image: "/assets/images/particle_brown.png" -} -images { - image: "/assets/images/crosshair010.png" -} -images { - image: "/assets/images/bar_round_large_grey.png" -} -images { - image: "/assets/images/bar_round_large_red.png" -} -animations { - id: "coin" - images { - image: "/assets/images/coin/dcoin_1.png" - } - images { - image: "/assets/images/coin/dcoin_2.png" - } - images { - image: "/assets/images/coin/dcoin_3.png" - } - images { - image: "/assets/images/coin/dcoin_4.png" - } - images { - image: "/assets/images/coin/dcoin_5.png" - } - playback: PLAYBACK_LOOP_FORWARD - fps: 8 -} -extrude_borders: 2 diff --git a/model/cubemap/assets/text48.font b/model/cubemap/assets/text48.font deleted file mode 100644 index 2622c04d..00000000 --- a/model/cubemap/assets/text48.font +++ /dev/null @@ -1,5 +0,0 @@ -font: "/assets/SourceSansPro-Semibold.ttf" -material: "/builtins/fonts/font.material" -size: 48 -outline_alpha: 0.0 -outline_width: 0.0 diff --git a/model/cubemap/example.md b/model/cubemap/example.md index f6416a83..3ba1fd7e 100644 --- a/model/cubemap/example.md +++ b/model/cubemap/example.md @@ -1,9 +1,31 @@ --- -tags: model +tags: model, material, shader title: Cubemap Reflection -brief: This example shows how to use a cubemap to draw environment reflections on a model. +brief: Shows how to sample a cubemap in a model shader to create environment reflections. author: Defold Foundation -scripts: cubemap.script, cubemap_model.fp, cubemap_model.vp +scripts: cubemap_model.vp, cubemap_model.fp, orbit_camera.script +thumbnail: thumbnail.webp --- -This example contains a game object with a model component in the shape of the Defold logo. The model has a special `cubemap_model.material` which uses a cubemap sampler to calculate reflections on the model from the cubemap. \ No newline at end of file +The example renders the Defold logo with a custom material that reflects an environment cubemap. Drag or touch to orbit around the model and use the mouse wheel to zoom. + +## What You'll Learn + +- How to bind a cubemap texture to a model material sampler +- How to compute world-space reflection vectors for environment mapping + +## Setup + +The collection contains a `logo` game object with an embedded Model component using `/example/assets/defold_logo.gltf`. Its material is `/example/cubemap_model.material`, and the material's `env_map` sampler is bound to `/example/assets/env.cubemap`. + +The `camera` game object contains a perspective Camera component and `orbit_camera.script`. The script is used only to move the camera around the logo from pointer and mouse wheel input. + +There is also an `info` game object with a GUI with a text to display controls on screen. + +![setup](setup.png) + +## How It Works + +`cubemap_model.vp` receives the model position, normal, and per-instance `mtx_world` attribute. It transforms the normal into world space, derives the camera world position from the view matrix, and calculates a reflection vector for each vertex. + +`cubemap_model.fp` samples the cubemap with that reflection vector. A small Fresnel term makes the logo edges more reflective, which makes the environment reflection easier to see while keeping the shader focused on cubemap sampling. diff --git a/model/cubemap/example/cubemap.collection b/model/cubemap/example/cubemap.collection index af35edf1..0fcaaa68 100644 --- a/model/cubemap/example/cubemap.collection +++ b/model/cubemap/example/cubemap.collection @@ -10,10 +10,11 @@ embedded_instances { " name: \\\"Material\\\"\\n" " material: \\\"/example/cubemap_model.material\\\"\\n" " textures {\\n" - " sampler: \\\"envMap\\\"\\n" + " sampler: \\\"env_map\\\"\\n" " texture: \\\"/example/assets/env.cubemap\\\"\\n" " }\\n" "}\\n" + "create_go_bones: false\\n" "\"\n" "}\n" "" @@ -27,7 +28,7 @@ embedded_instances { id: "camera" data: "components {\n" " id: \"main\"\n" - " component: \"/example/cubemap.script\"\n" + " component: \"/example/orbit_camera.script\"\n" "}\n" "embedded_components {\n" " id: \"camera\"\n" @@ -35,7 +36,8 @@ embedded_instances { " data: \"aspect_ratio: 1.0\\n" "fov: 0.7854\\n" "near_z: 1.0\\n" - "far_z: 100.0\\n" + "far_z: 50.0\\n" + "auto_aspect_ratio: 1\\n" "\"\n" "}\n" "" @@ -43,3 +45,11 @@ embedded_instances { z: 10.0 } } +embedded_instances { + id: "info" + data: "components {\n" + " id: \"info\"\n" + " component: \"/example/info.gui\"\n" + "}\n" + "" +} diff --git a/model/cubemap/example/cubemap.script b/model/cubemap/example/cubemap.script deleted file mode 100644 index 3c29b771..00000000 --- a/model/cubemap/example/cubemap.script +++ /dev/null @@ -1,34 +0,0 @@ -local ZOOM_SPEED = 0.1 -local ROTATION_SPEED = 1 - -function init(self) - msg.post("@render:", "use_camera_projection") - msg.post(".", "acquire_input_focus") - self.yaw = 0 -- for camera rotation - self.pitch = 0 -- for camera rotation - self.zoom = 5 -- default zoom - self.zoom_offset = 0 -- modification from default zoom -end - -function update(self, dt) - local camera_yaw = vmath.quat_rotation_y(math.rad(self.yaw)) - local camera_pitch = vmath.quat_rotation_x(math.rad(self.pitch)) - local camera_rot = camera_yaw * camera_pitch - local camera_position = vmath.rotate(camera_rot, vmath.vector3(0, 0, self.zoom + self.zoom_offset)) - go.set_position(camera_position) - go.set_rotation(camera_rot) - - local cameraposv4 = vmath.vector4(camera_position.x, camera_position.y, camera_position.z, 1) - go.set("logo#model", "cameraPosition", cameraposv4) -end - -function on_input(self, action_id, action) - if action_id == hash("touch") then - self.yaw = self.yaw - action.dx * ROTATION_SPEED - self.pitch = self.pitch + action.dy * ROTATION_SPEED - elseif action_id == hash("mouse_wheel_up") then - self.zoom_offset = self.zoom_offset - ZOOM_SPEED - elseif action_id == hash("mouse_wheel_down") then - self.zoom_offset = self.zoom_offset + ZOOM_SPEED - end -end \ No newline at end of file diff --git a/model/cubemap/example/cubemap_model.fp b/model/cubemap/example/cubemap_model.fp index a15a9489..cda34186 100644 --- a/model/cubemap/example/cubemap_model.fp +++ b/model/cubemap/example/cubemap_model.fp @@ -1,11 +1,30 @@ #version 140 -in mediump vec3 vReflect; -out vec4 out_FragColor; +// These values are calculated per vertex in `cubemap_model.vp` and +// interpolated for each fragment. +in vec3 var_reflection; +in float var_fresnel; -uniform samplerCube envMap; +// Output fragment color +out vec4 out_frag_color; + +// Environment map +// This sampler name must match the sampler in `cubemap_model.material` and +// the texture binding in the Model component. +uniform samplerCube env_map; void main() { - out_FragColor = texture(envMap, vReflect); -} \ No newline at end of file + // Normalize after interpolation, then sample the cubemap in that direction. + vec3 reflected_color = texture(env_map, normalize(var_reflection)).rgb; + + // You can add a small base color so the logo still has shape in darker cubemap areas. + vec3 base_color = vec3(0.06, 0.08, 0.1); + + // Fresnel makes shallow viewing angles more reflective, which helps show + // that the cubemap is responding to the model's surface direction. + float reflection_strength = mix(0.72, 1.0, var_fresnel); + vec3 color = mix(base_color, reflected_color, reflection_strength); + + out_frag_color = vec4(color, 1.0); +} diff --git a/model/cubemap/example/cubemap_model.material b/model/cubemap/example/cubemap_model.material index 8c0a6ac4..e70c6a8f 100644 --- a/model/cubemap/example/cubemap_model.material +++ b/model/cubemap/example/cubemap_model.material @@ -2,24 +2,20 @@ name: "cubemap_model" tags: "model" vertex_program: "/example/cubemap_model.vp" fragment_program: "/example/cubemap_model.fp" +vertex_space: VERTEX_SPACE_LOCAL vertex_constants { - name: "view_proj" - type: CONSTANT_TYPE_VIEWPROJ + name: "mtx_view" + type: CONSTANT_TYPE_VIEW } vertex_constants { - name: "world" - type: CONSTANT_TYPE_WORLD -} -vertex_constants { - name: "cameraPosition" - type: CONSTANT_TYPE_USER - value { - } + name: "mtx_proj" + type: CONSTANT_TYPE_PROJECTION } samplers { - name: "envMap" + name: "env_map" wrap_u: WRAP_MODE_CLAMP_TO_EDGE wrap_v: WRAP_MODE_CLAMP_TO_EDGE filter_min: FILTER_MODE_MIN_LINEAR filter_mag: FILTER_MODE_MAG_LINEAR + max_anisotropy: 0.0 } diff --git a/model/cubemap/example/cubemap_model.vp b/model/cubemap/example/cubemap_model.vp index 0f672fac..72814bca 100644 --- a/model/cubemap/example/cubemap_model.vp +++ b/model/cubemap/example/cubemap_model.vp @@ -1,25 +1,63 @@ #version 140 -uniform vs_uniforms { - mediump mat4 view_proj; - mediump mat4 world; - mediump mat4 normal_transform; - mediump mat4 world_view; - mediump vec4 cameraPosition; +// Model components provide local vertex data. The material uses +// `VERTEX_SPACE_LOCAL`, so the shader must transform positions itself. +in vec4 position; +in vec3 normal; + +// Defold automatically provides `mtx_world` as a per-instance attribute for +// model materials in local vertex space. It is not listed as a material uniform. +in mat4 mtx_world; + +// `mtx_view` and `mtx_proj` are vertex constants declared in `cubemap_model.material`. +uniform general_vp +{ + mat4 mtx_view; + mat4 mtx_proj; }; -in mediump vec3 position; -in mediump vec3 normal; -in mediump vec2 texcoord0; +// The fragment shader samples the cubemap with this reflected world direction. +out vec3 var_reflection; -out mediump vec3 vReflect; +// The Fresnel value is used only to make grazing angles slightly brighter. +out float var_fresnel; + +// Build a world-space normal matrix from `mtx_world`. +// This is equivalent to transpose(inverse(mat3(mtx_world))) after normalize(), +// but avoids a full matrix inverse in the shader. +mat3 adjoint(mat4 m) +{ + return mat3( + cross(m[1].xyz, m[2].xyz), + cross(m[2].xyz, m[0].xyz), + cross(m[0].xyz, m[1].xyz) + ); +} + +// The cubemap reflection vector needs the camera position in world space. +// Defold gives us the view matrix, so this converts it back to camera origin. +vec3 camera_position_from_view(mat4 view) +{ + return -(transpose(mat3(view)) * view[3].xyz); +} void main() { - vec4 worldP = world * vec4(position, 1.0); - gl_Position = view_proj * worldP; - - vec3 worldNormal = normalize(normal); - vec3 cameraToVertex = normalize( worldP.xyz - cameraPosition.xyz ); - vReflect = reflect( cameraToVertex, worldNormal ); + // Move the vertex from model space to world space before projecting it. + vec4 world_position = mtx_world * vec4(position.xyz, 1.0); + + // Transform the model normal into world space so it matches the cubemap. + vec3 world_normal = normalize(adjoint(mtx_world) * normal); + + // Create the incident view direction used by GLSL `reflect()`. + vec3 camera_position = camera_position_from_view(mtx_view); + vec3 camera_to_vertex = normalize(world_position.xyz - camera_position); + + // Reflect the view direction around the surface normal. + // The result points into the cubemap and is interpolated across the model surface. + var_reflection = reflect(camera_to_vertex, world_normal); + var_fresnel = pow(1.0 - max(dot(-camera_to_vertex, world_normal), 0.0), 4.0); + + // Finish the model transform: world -> view -> projection. + gl_Position = mtx_proj * mtx_view * world_position; } diff --git a/model/cubemap/example/info.gui b/model/cubemap/example/info.gui new file mode 100644 index 00000000..ce9ca26c --- /dev/null +++ b/model/cubemap/example/info.gui @@ -0,0 +1,22 @@ +fonts { + name: "always_on_top" + font: "/builtins/fonts/default.font" +} +nodes { + position { + x: 360.0 + y: 680.0 + } + size { + x: 200.0 + y: 100.0 + } + type: TYPE_TEXT + text: "Click/touch and move to rotate\n" + "Scroll to zoom" + font: "always_on_top" + id: "text" + inherit_alpha: true +} +material: "/builtins/materials/gui.material" +adjust_reference: ADJUST_REFERENCE_PARENT diff --git a/model/cubemap/example/orbit_camera.script b/model/cubemap/example/orbit_camera.script new file mode 100644 index 00000000..d0794e32 --- /dev/null +++ b/model/cubemap/example/orbit_camera.script @@ -0,0 +1,73 @@ +local TOUCH = hash("touch") +local MOUSE_WHEEL_UP = hash("mouse_wheel_up") +local MOUSE_WHEEL_DOWN = hash("mouse_wheel_down") + +local ROTATION_SPEED = 0.8 +local ZOOM_STEP = 0.35 +local MIN_PITCH = -75 +local MAX_PITCH = 75 +local MIN_ZOOM = 3.0 +local MAX_ZOOM = 8.0 +local SMOOTHING = 0.15 + +local function clamp(value, min_value, max_value) + return math.max(min_value, math.min(max_value, value)) +end + +local function apply_camera(self) + local yaw = vmath.quat_rotation_y(math.rad(self.current_yaw)) -- <1> + local pitch = vmath.quat_rotation_x(math.rad(self.current_pitch)) -- <2> + local rotation = yaw * pitch -- <3> + local position = vmath.rotate(rotation, vmath.vector3(0, 0, self.current_zoom)) -- <4> + + go.set_position(position) -- <5> + go.set_rotation(rotation) -- <6> +end + +function init(self) + msg.post(".", "acquire_input_focus") -- <7> + + self.target_yaw = 0 + self.target_pitch = 0 + self.target_zoom = 5.0 + self.current_yaw = self.target_yaw + self.current_pitch = self.target_pitch + self.current_zoom = self.target_zoom + + apply_camera(self) +end + +function update(self, dt) + self.current_yaw = vmath.lerp(SMOOTHING, self.current_yaw, self.target_yaw) -- <8> + self.current_pitch = vmath.lerp(SMOOTHING, self.current_pitch, self.target_pitch) + self.current_zoom = vmath.lerp(SMOOTHING, self.current_zoom, self.target_zoom) + + apply_camera(self) +end + +function on_input(self, action_id, action) + if action_id == TOUCH and not action.pressed and not action.released then -- <9> + self.target_yaw = self.target_yaw - action.dx * ROTATION_SPEED -- <10> + self.target_pitch = clamp(self.target_pitch + action.dy * ROTATION_SPEED, MIN_PITCH, MAX_PITCH) -- <11> + elseif action_id == MOUSE_WHEEL_UP then + self.target_zoom = clamp(self.target_zoom - ZOOM_STEP, MIN_ZOOM, MAX_ZOOM) -- <12> + elseif action_id == MOUSE_WHEEL_DOWN then + self.target_zoom = clamp(self.target_zoom + ZOOM_STEP, MIN_ZOOM, MAX_ZOOM) -- <13> + end +end + +--[[ +1. Create the horizontal orbit rotation from the smoothed yaw angle. +2. Create the vertical orbit rotation from the smoothed pitch angle. +3. Combine yaw and pitch into the camera rotation. +4. Rotate a forward offset to place the camera on an orbit around the logo. +5. Move the camera game object to the calculated orbit position. +6. Rotate the camera so it keeps looking at the logo. +7. Acquire input focus so drag and mouse wheel input reaches this script. +8. Smoothly blend the visible camera values toward the latest input targets. +9. Handle pointer movement after the initial press and before release. +10. Drag left and right to orbit around the vertical axis. +11. Drag up and down to pitch the camera, clamped so it cannot flip over. +12. Scroll up to zoom in, clamped to the closest useful distance. +13. Scroll down to zoom out, clamped so the logo remains visible. +]] diff --git a/model/cubemap/game.project b/model/cubemap/game.project index d6286213..664bbac5 100644 --- a/model/cubemap/game.project +++ b/model/cubemap/game.project @@ -1,5 +1,5 @@ [project] -title = Cubemap +title = Cubemap Reflection version = 0.1 [bootstrap] @@ -59,7 +59,6 @@ max_instances = 32765 max_emitter_count = 1024 [render] -clear_color_blue = 1.0 -clear_color_green = 1.0 -clear_color_red = 1.0 - +clear_color_blue = 0.183594 +clear_color_green = 0.164063 +clear_color_red = 0.160156 diff --git a/model/cubemap/setup.png b/model/cubemap/setup.png new file mode 100644 index 00000000..94f35d68 Binary files /dev/null and b/model/cubemap/setup.png differ diff --git a/model/cubemap/thumbnail.webp b/model/cubemap/thumbnail.webp new file mode 100644 index 00000000..6466a75f Binary files /dev/null and b/model/cubemap/thumbnail.webp differ