About
Author: DeathByNukes
This is a part of my Audiosurf 2 scripting documentation.
This page is still very work-in-progress and some parts of it will probably be moved into the other pages.
Contents
Overview
Terms
- track
- The bumpy path that the player follows through the level. It is typically represented by one or more rails and is composed of track nodes.
- node
-
- track node : A single point along the track. Nodes are the "atoms" that tracks are made of. Each one has attributes like position, rotation, color, song intensity, etc. As the player moves between nodes, the game lerps between the attributes of those nodes. The
GetTrack
function gets a list of all nodes and their attributes.
- extrusion node : One of the points in the path that an extrusion follows.
- lerp
- Linear interpolation. A transition or fade between two values. For a pair of coordinates, this is finding a point on the line between them. For colors, this is a gradient from the first to the second color.
- extrude
-
- intensity
- Audiosurf 2's estimation of how intense a portion of the song is. This is different from the track slope.
- normalized intensity
- The intensity divided by the most intense part of the song.
- smooth intensity
- The intensity but it is prevented from changing quickly.
- rail
- A model that is extruded (CreateRail) or bent (CreateRepeatedMeshRail) along the track. Together, all of the rails serve to represent the track to the player. Individual rails typically represent things like lane dividers and the track "floor".
- ring
-
- track ring : In stock skins, the literal rings around the track. They are quads placed on nodes with high intensity and can be customized with the
SetRings
function.
- extrusion ring : An extrusion-shaped ring of vertices that correspond to a node in the extrusion path.
- block
- The objects that the player can collide with.
- skywires
- In stock skins and Audiosurf 1, the lines in the sky emanating from the end of the track.
- game object
- prefab
- prototype
- Unity
- Audiosurf 2 is built on the Unity engine. Unity is a closed-source multi-platform game engine and development tool with free and commercial licenses which has become popular in the game development community lately. AS2's Lua system is not part of Unity but reading Unity documentation can often help to understand the paradigm that AS2 works in. This is especially true of materials and shaders.
- coordinate
- A set of 3 numbers (X, Y, Z) used to represent a position. In Audiosurf 2, +X is to the left, +Y is up, and +Z is forward.
- origin
- The coordinate {0, 0, 0}; the position that coordinates are relative to in a given coordinate space.
- world space
- Coordinates in world space are relative to the center of the level. The first track node is usually in the center of world space, facing forward.
- node space
- Coordinates relative to a specific track node's position and rotation.
- object space
- Coordinates relative to the position and rotation that an object is placed at. Models are built in object space.
- screen space
- Coordinates relative to some point on the 2D viewport that the scene is rendered into. Generally X is horizontal, Y is vertical, and Z is depth.
- vector
- There are two relevant definitions of this term.
- computer science : A flat fixed-length collection of some type of data. In this case, numbers.
- mathematics : Euclidean vectors. (Coordinates, offsets, etc) There are many advanced math operations applicable to vectors.
Game developers tend to mix these up and rarely attempt to make a distinction between them. The result is you may see some documentation telling you that something is a vector but it contains something completely different like euler rotation angles. Adding a number to the name indicates how many numbers are in the collection. (3D coordinates are vector3)
- model
- In computer graphics, refers to a mesh and all of its associated materials, textures, animations, etc. This term is generally not used in the Unity world because a model's components are imported separately and added to a gameobject. Sometimes used interchangeably with "mesh".
- mesh
- A 3d shape made out of faces (polygons), which are made out of triangles, which are made of sets of 3 vertices. Typically a texture is mapped on to a mesh with UV mapping.
- sub-mesh
- The Unity engine can only apply one material to all faces in a mesh. When multiple materials are needed, the mesh faces must be grouped into sub-meshes. One material can be applied to each sub-mesh.
- OBJ file
- A file format that stores 3D models. Though the format is not entirely limited to mesh-based models, Audiosurf 2's OBJ file loader only supports meshes. MTL files, which are often paired with OBJ files, are also not supported.
- face
- A polygon in a mesh. A face is defined by referring to 3 or more vertices. (Technically, it's composed of one or more triangles.)
- triangle
- A face with 3 vertices. Internally, the engine only supports triangles. The OBJ file loader automatically converts 4-point faces (quads) to pairs of triangles and ignores all other face types.
- quad
- A face with 4 vertices. Internally, they are made out of 2 triangles.
- vertex
- A single point in a face. In addition to its coordinates, a vertex can have various attributes associated with it. (UV, UV2, normal, vertex color, tangent.) On the GPU, vertices and their attributes are processed by the vertex shader and then the resulting attributes are lerped across the surface of the face and converted into colors by the pixel shader.
- normal
- A vertex attribute containing a euclidean vector. It tells the shader which direction is up, relative to the model surface the vertex is a part of. Many shader techniques like smooth shading, specularity, and bump mapping depend on normals. OBJ files can specify custom normals.
- tangent
- A vector4 associated with a vertex. When used with normals and some heavy math, a shader can determine how the surface is oriented. Advanced shader techniques like bump and parallax mapping need this.
- vertex color
- A color and alpha value associated with a specific vertex. Differently colored vertices will lerp across the triangles, forming gradients. Vertex colors are how Audiosurf 2 colors different portions of the track according to the highway colors. (CreateRail's colorMode setting.) Vertex colors are also used for coloring SetWake and thrusters. OBJ files do not support vertex colors.
- UV
- Controls how a texture is applied to a model. Internally, each vertex on a face gets two numbers, U and V (X and Y) associated with it. {0, 0} is the bottom left of the texture and {1, 1} is the top right. Those points in the texture are stretched across the corresponding points on the face.
- texture
- A typical 2D image that is usually applied to a 3D surface.
- material
- A collection of settings that are applied to a face. Textures are one part of a material. Audiosurf 2 lets us specify material settings via the material type. Some AS2 customization functions only expose a limited number of material settings.
- shader
- A shader is a computer program which takes a model and material as its inputs then outputs a 2D image. All the graphics in Audiosurf 2 are drawn by shaders. AS2 shaders are written in the "Cg" programming language. Most shaders written for AS2 need to be compiled by the Unity 4 editor (free) before they can be used. GPUs execute the shader program in parallel for each vertex and each pixel. Due to its highly parallel nature, shader programming is very different from conventional programming. For instance, it is impossible for a shader program to write to any kind of global variable.
- vertex shader
- A shader subroutine that takes raw per-vertex data from the engine and prepares it for rendering. At a minimum this usually involves transforming the vertex coordinates from object space into projection space. (object -> world -> camera -> projection) The vertex shader's control over this process means it can animate and distort the object in some ways. Other shader-specific calculations are performed in the vertex shader when possible in order to conserve processing power since there are usually more pixels than vertices. The output of the vertex shader is interpolated across each triangle and the results of the interpolation are passed to many parallel instances of the pixel shader.
- pixel shader
- A shader subroutine that takes the interpolated output of the vertex shader and draws a single pixel. In OpenGL-influenced documents this is also known as a fragment shader.
- surface shader
- A shader subroutine specific to Unity. It serves the same role as a pixel shader but it is redesigned to eliminate the need to manually implement lighting. As such, surface shaders should only be used for shaders that can be influenced by light and shadow. (Skins styled like the Neon skin shouldn't use these.)
- layer
-
Objects in the game are marked as being on specific layers, which influences how they are rendered into the scene. Layers DO NOT work like Photoshop layers. Though specific layers might cause some objects to appear on top of others, that is not how all of them work. They are more like categories or labels.
- framebuffer
-
A 2D buffer on the GPU that holds a single frame image, usually sized according to the current screen resolution. When things are "rendered", they are drawn into the framebuffer sort of like painting on a canvas. A fragment shader function is responsible for drawing individual pixels into the framebuffer. In shaders you can make readable copies of the framebuffer via GrabPass.
- depth buffer
-
A 2D buffer of floating-point numbers that tracks the distance of objects from the camera on a per-pixel basis. Also known as the "Z buffer" because in screen space the Z coordinate usually represents depth. It is used to determine which parts of polygons cover up other polygons. Depth ordering issues are sometimes seen in transparent objects because the depth buffer is only useful for ordering opaque objects. In Unity, shaders determine how a material interacts with the depth buffer.
- render queue
-
Determines the order that materials are rendered in. Generally only matters for shaders that have some sort of transparency. If not set, it defaults to a value specified by the shader, which is usually appropriate. For solid objects, the depth buffer ensures things are visible in the correct order regardless of the queue order. Different transparent shaders can interact with the depth buffer in different ways.
- cull
-
Culling is the process of determining what should and shouldn't be rendered. This is done mostly for optimization but in the case of depth culling it is also critical to getting the correct image. Frustum culling, the process of culling entire objects that are out of the camera's field of view, can cause problems if an object's bounding box is incorrect.
- culling plane
- The front or back end of the depth buffer. Pixels of normal objects that are further away than the far culling plane or closer to the camera than the near culling plane will not be drawn.
- bounding box
- A simple box that completely encloses a smaller and more complex object, used to optimize and simplify various calculations. An axis-aligned bounding box (AABB) has no rotation, so it can be completely defined with just two coordinates representing opposite corners of the box. (Minecraft blocks are axis-aligned cubes.) Bounding boxes are used in frustum culling and objects can be incorrectly culled if the box doesn't correctly enclose the entire object.