Switch to full stage
Loading Project
Loading project …

Instructions

Use the arrow keys or your mouse to move around the demo 3D prism. Given a polygon defined by a list of x and y points, this will render in 3D a prism with that polygon as the base. ------------------------------------------------------------------------- S - Save code L - Load code H - Hide code R - Reverse points (turn it inside out) Post your codes here: https://scratch.mit.edu/discuss/topic/429736/ ---------------------------------------------------------------------- I'm using a new algorithm to render the shadow and it's much faster and more concise. Also by using faster trifills and swapping from scanline fill to polygon decomposition I was able to get a huge speed boost. For a lag free version go to https://turbowarp.github.io/#415623498

Notes and Credits

This is type of rendering is called "rasterization", where we emulate real world lighting effects using vector shapes. It's much much faster than raytracing and as such means it can run in real time. Prisms have a constant layer shape, so I used this to my advantage by calculating one layer then just repeating the layers, instead of doing more calculations. This makes it faster and the code is more concise. Updates: 23/02/2020 (V0.5) - Implemented a basic depth sort. 15/04/2020 (V0.6) - Normalized coordinate system 16/04/2020 (V0.7) - Fixed face visibility script 25/04/2020 (V0.9) - Added shadows 03/08/2020 (v0.10) - Separated prism & shadow script 04/08/2020 (v0.11) - Added backface culling 04/08/2020 (v1) - Fixed shadow & face visibility bug 05/08/2020 (v1.1) - Improved shadow algorithm 06/08/2020 (v1.2) - Added "Edit Shape" 06/08/2020 (v1.3) - Made rotating with mouse possible 07/08/2020 (v1.4) - Points can be added/removed 08/08/2020 (v1.5) - Save/load codes 28/04/2021 (v1.6) - Improved the polygon/tri fill algos 30/04/2021 (v1.7) - Added sound/music 09/05/2021 (v1.8) - Made Light direction interactive 13/06/2021 (v1.9) - Fixed decomposition bug 17/07/2021 (v1.10) - True Depth Sort 09/04/2022 (v1.11) - Updated default shape Upcoming updates: v1.11 - Clipping v2.0 - Use my triangle filler instead of logfathers one. Known bugs: - 17 July: From some specific angles depth sort is wrong - 22 July: At a specific rotation the prism becomes 1 line and is stuck like that.

TurboWarp is a Scratch mod that compiles projects to JavaScript to make them run really fast. Try it out by inputting a project ID or URL above or choosing a featured project below.