This article has links to websites or programs outside of Scratch and Wikipedia. Remember to stay safe while using the internet as we cannot guarantee the safety of other websites.
"3D" redirects here. For the suggestion of a 3-dimensional stage, see List of Officially Rejected Suggestions#3D Scratch.
An example of a 3D project made in Scratch.
The rendering of a 3D world in Middle Earth: Shadow of Mordor (2014).

Three-Dimensional Projects, often referred to as 3D Projects, are projects that render scenes with three dimensions: length, width, and height. Scratch does not provide in-built tools for displaying, creating, or manipulating 3D graphics; however, Scratch does provide blocks for 2D sprite movement, sprite resizing, pen drawing, math functions, lists and more. Most 3D rendering methods can be recreated with Scratch blocks.

Overview

In order for a 3D scene to be rendered, it must first be represented as a set of 3D objects that can be drawn, called primitives. Common examples of primitives include triangles, spheres, and boxes, however more complex shapes are possible. These can be imported from an external program or defined manually in written form or code. A rendering script will then use this set of primitives, as well as the position and rotation of a virtual "camera" to represent these shapes on the two-dimensional screen.

Broadly, the two most common methods used are triangle-filling (also sometimes called rasterization, particularly outside of Scratch) and ray-intersection.

  • Triangle-filling methods use 3D triangles as primitives. For each triangle the position and rotation of the camera is used to determine the screen position of each vertex, and a 2D triangle is then drawn between these points. These tend to be flexible and relatively fast, at the cost of graphical fidelity. They are a subset of projection-based methods.
  • Ray-intersection methods create a ray corresponding to each pixel on the screen. Mathematical formulae are used to determine which, if any, of the primitives the ray intersects. These methods approximate the true nature of light, so can render realistic surfaces, reflection and shadow, often at the cost of performance.

In some cases introducing restrictions such as limiting camera rotation or representing the world as a voxel grid can allow special rendering techniques that grant large performance gains.


Projection-Based Methods

Projection-based methods are based on an algorithm (often called a transform function) that takes in a point in world coordinates and returns it's position relative to the camera. The 'camera-space' position is then used to determine the position of the point on screen in a process called 'projection'. Projection based methods tend to be flexible and simple, however their graphical quality may be lower.

Point Clouds

Point cloud example.

A 3D scene is represented as a "cloud" of points. These points are transformed and projected and simply drawn as colored dots on the screen with pen.

One variant of this method is sourcing the points from a 2D image's pixels, such as an image of a terrain.

Examples


Wireframe

Main article: 3D Wireframes
Wireframe example.

A 3D scene is drawn as lines. This is often an extension of the point cloud method, where lines are drawn between pairs of points rather than the points themselves.

Examples


Billboards

Billboard example.

A "billboard" is a flat image oriented to the camera. The image is located at a point in 3D space. In Scratch, billboards are either stamped or cloned.

Examples


Sorted Triangles

Sorted triangles example.

This is a very popular method on Scratch. It involves drawing the scene as triangles. The triangles are drawn furthest to closest, which is called the painter's algorithm. A sorting algorithm is used to sort the triangles by their depth (distance from camera), using for example the depth at the centroid. This doesn't provide a perfect result due to a point not being representative of the entire surface, so a more advanced method is to further split the triangles and use binary space partitioning.

Examples


Depth Buffer

Example of rasterized triangles using a depth buffer. Lighting is "baked" into the texture, not calculated in Scratch.

Surfaces (usually triangles) are rasterized and drawn using a depth buffer (also known as a Z buffer). Each pixel in the output image or screen contains its color and depth. The surfaces are looped over and rasterized. A pixel will only be updated if the new rasterized depth is closer to the camera. Outside of Scratch, this is the dominant rendering method as it is efficient to compute in parallel on a GPU, while offering greater flexibility.

Examples


Ray-Based Methods

Ray Casting

Main article: Raycaster
Ray casting example with the results used to draw vertical walls.

Ray casting is a method that sends rays from a camera into a scene of objects. The ray's length and object hit is information used to then draw a pixel or line of pixels on the screen. While the term "ray casting" is broad and unspecifying of direction, in Scratch it is generally used to mean casting rays horizontally only. More advanced methods tend to fall under terms such as "ray tracing" and "path tracing".

"Ray casting ... can be thought of as an abridged, and significantly faster, version of the ray tracing algorithm."[1]

This method was used in early 3D games like Wolfenstein 3D to get fast, real-time performance out of slow computers.

Examples


Ray Tracing

For more information, see Ray tracing (graphics) on Wikipedia.
Ray tracing example.

"In computer graphics, ray tracing is a technique for generating an image by tracing the path of light through pixels in an image plane and simulating the effects of its encounters with virtual objects."[2]

Although it is usually real-time in lower-level languages and is able to be real-time on Scratch, it can still be very slow. However, it can recreate natural effects like reflection, shading, and shadows. This complex technique is usually used in demoscene and films and TV shows using computer-generated imagery (CGI).

Examples


Path Tracing

For more information, see Path tracing on Wikipedia.

Path tracing is a subset of ray tracing that creates paths of light based on physical properties of the materials the rays intersect, and computes a final result for each pixel using the rendering equation.

These paths are generated randomly, due to the fact that the integral in the rendering equation does not have an explicit solution, and has to be solved with Monte-Carlo integration. The use of randomness is what causes noise in path tracing.[3] The number of paths used for a pixel is the number of samples, and the increase in samples reduces noise in the image and converges it to the true result. The use of many samples also allows effects like depth of field and anti-aliasing.

In practice, path tracers also have global illumination, which is the indirect bouncing of light. Path tracing is slower than ray tracing, but is more realistic. Path tracing is also what is used to render CGI and 3D animated movies.

A common misconception is that the use of Monte-Carlo integration makes a ray tracer a path tracer; this is not the case, as a path tracer needs to create random light paths based off of material properties. A standard ray tracer with Monte-Carlo integration would be classified as a distributed ray tracer.

Examples


Ray Marching

Main article: Ray Marching
Ray marching example showing a Menger sponge fractal.

Ray marching is a similar method to ray tracing, but instead of jumping to objects using math, it "marches" the ray forward until it intersects with the object. The basic ray marching algorithm works by estimating the closest distance, moving the ray that distance, and repeating the process over and over until the ray intersects with the object. Ray marching is useful in situations where estimating a distance to the scene's shapes are efficient, such as in fractals. Elsewhere, ray marching is slower than ray tracing due to the need for many steps.

Examples


Other Methods

Pre-rendered

Pre-rendered graphics example.

Images created with 3D programs like Blender or SketchUp are imported as costumes in a sprite. Costumes portraying different angles of the object are switched quickly to make the object appear to rotate.

Examples


Slices

Main article: Animating a 3D Object
Costume slices example. The orca consists of 45 costumes.

This method involves slicing a 3D object into many images at a series of depths. The images are imported as costumes and displayed as many sprites, clones, or stamps, each slightly offset on the screen to give the appearance of three dimensions. The images can be scaled or rotated for a more advanced effect.

Examples


Implementation

Some users want a 3D editor to be implemented into Scratch. The Scratch Team has rejected this suggestion, stating that it would make Scratch confusing for beginners.[4] Some users argue the point, saying that to make it less confusing, it could be restricted to only Scratchers,[5] or saying that there could be two separate editors[6].


2.5D Projects

For more information, see 2.5D on Wikipedia.

"2.5D" refers to gameplay or graphics that are somewhere in-between 2D and 3D. This could include movement that is constrained to a 2D plane but appears to be within a 3D environment. It could also include 3D graphics implemented with 2D techniques like slices of a model moving with parallax. The simplifications can be more performant and easier to create than "true" 3D projects.

2.5D is commonly used in video games. Examples include LittleBigPlanet and Crash Bandicoot.

Examples

See Also

You can create one of these! A tutorial is available here.


References

Cookies help us deliver our services. By using our services, you agree to our use of cookies.