Crate three_d[][src]

A 3D renderer which enables out-of-the-box build to both desktop and web with the same code. See the README for more information and the examples for how to use it.

Modules

camera

Perspective and orthographic camera.

context

Thin and low-level graphics abstraction layer which maps one-to-one with the OpenGL graphics API on desktop and WebGL2 bindings provided by the web-sys crate on web. Can be used in combination with more high-level features or be ignored entirely.

core

Modular abstractions of common graphics concepts such as GPU shader program, buffer (vertex buffer, uniform buffer, element buffer), texture (2D texture, cube texture, ..) and render target. They are higher level than context but lower level than other features.

definition

Structs for constructing a CPU-side version of a GPU feature (for example a triangle mesh) before transferring it to the GPU. Can be constructed manually or loaded via io.

effect

Effects applied to each pixel, for example fog or anti-aliasing.

frame

Input/output from/to the window each frame.

gui

Graphical User Interface support.

io

Contain a loader for loading any type of asset runtime on both desktop and web and a saver for saving (available on desktop only).

light

A collection of light types. Currently implemented light types are ambient light, directional light, spot light and point light. Directional and spot lights can cast shadows.

math

Math functionality.

object

A collection of objects that can be rendered, for example a mesh.

phong

Lighting functionality based on the phong reflection model.

window

Default windows for easy setup and event handling. Currently glutin for cross-platform desktop and canvas using wasm-bindgen for web, but can be replaced by any other window with similar functionality.

Structs

AmbientLight

A light which shines equally on all parts of any surface.

Axes

Three arrows indicating the three main axes; the x-axis (red), the y-axis (green) and the z-axis (blue). Used for easily debugging where objects are placed in the 3D world.

AxisAlignedBoundingBox

A bounding box that aligns with the x, y and z axes.

BlendParameters

Defines which type of blending to use for a render call. Blending allows combining each color channel of a render call with the color already in the color channels of the render target. This is usually used to simulate transparency.

CPUMaterial

A CPU-side version of a material (for example phong material). Can be constructed manually or loaded via io.

CPUMesh

A CPU-side version of a triangle mesh (for example Mesh). Can be constructed manually or loaded via io or via the utility functions for generating simple triangle meshes.

CPUTexture

A CPU-side version of a texture (for example 2D texture. Can be constructed manually or loaded via io.

Camera

Used in a render call to define how to view the 3D world.

CameraControl

3D controls for a camera. Use this to add additional control functionality to a camera.

ClearState

Defines which channels (red, green, blue, alpha and depth) to clear when starting to write to a render target or the screen and which values they are set to (the values must be between 0 and 1).

ColorTargetTexture2D

A 2D texture that can be rendered into using a RenderTarget.

ColorTargetTexture2DArray

A 2D texture array that can be rendered into using a RenderTargetArray.

DepthTargetTexture2D

A 2D texture that can be rendered into using a RenderTarget.

DepthTargetTexture2DArray

A 2D texture array that can be rendered into using a RenderTargetArray.

DirectionalLight

A light which shines in the given direction. The light will cast shadows if you generate a shadow map.

ElementBuffer

A buffer containing indices for rendering, see for example draw_elements. Also known as an index buffer.

FXAAEffect

A simple anti-aliasing approach which smooths otherwise jagged edges (for example lines) but also smooths the rest of the image.

FogEffect

An effect that simulates fog, ie. the entire screen gets hazy white when objects are far away.

FrameInput

Input from the window to the rendering (and whatever else needs it) each frame.

FrameOutput

Output from the rendering to the window each frame.

GUI

Integration of egui, an immediate mode GUI.

ImageEffect

A customizable 2D effect. Can for example be used for adding an effect on top of the rendered 3D scene, like fog.

Imposters

A level-of-detail technique to replace rendering high-poly meshes at a distance. A mesh is rendered from different angles into a set of textures and the textures are then rendered continuously instead of the high-poly meshes.

InstancedMesh

Similar to Mesh, except it is possible to render many instances of the same triangle mesh efficiently.

InstancedMeshProgram

A shader program used for rendering one or more instances of a InstancedMesh. It has a fixed vertex shader and customizable fragment shader for custom lighting. Use this in combination with render.

Loaded

The resources loaded using the Loader. Use the bytes function to extract the raw byte array for the loaded resource or one of the other methods to both extract and deserialize a loaded resource.

Loader

Functionality for loading any type of resource runtime on both desktop and web.

Mesh

A triangle mesh which can be rendered with one of the default render functions or with a custom MeshProgram. See also PhongForwardMesh and PhongDeferredMesh for rendering a mesh with lighting.

MeshProgram

A shader program used for rendering one or more instances of a Mesh. It has a fixed vertex shader and customizable fragment shader for custom lighting. Use this in combination with render.

Modifiers

State of modifiers (alt, ctrl, shift and command).

ParticleData

Used to define the initial position and velocity of a particle in Particles.

Particles

Particle effect with fixed vertex shader and customizable fragment shader (see also ParticlesProgram).

ParticlesProgram

Shader program used for rendering Particles. The fragment shader code can use position (in vec3 pos;) normal (in vec3 nor;) and uv coordinates (in vec2 uvs;).

PhongDeferredInstancedMesh

An instanced triangle mesh that adds additional lighting functionality based on the Phong shading model to a InstancedMesh. Must be used in connection with a PhongDeferredPipeline.

PhongDeferredMesh

A triangle mesh that adds additional lighting functionality based on the Phong shading model to a Mesh. Must be used in connection with a PhongDeferredPipeline.

PhongDeferredPipeline

Deferred pipeline based on the Phong reflection model supporting a performance-limited amount of directional, point and spot lights with shadows. Supports colored, textured and instanced meshes.

PhongForwardInstancedMesh

An instanced triangle mesh that adds additional lighting functionality based on the Phong shading model to a InstancedMesh.

PhongForwardMesh

A triangle mesh that adds additional lighting functionality based on the Phong shading model to a Mesh.

PhongForwardPipeline

Forward pipeline based on the phong reflection model supporting a very limited amount of lights with shadows. Supports colored, transparent, textured and instanced meshes.

PhongMaterial

A material used for shading an object based on the Phong shading model.

PointLight

A light which shines from the given position in all directions.

Program

A shader program consisting of a programmable vertex shader followed by a programmable fragment shader. Functionality includes transferring per vertex data to the vertex shader (see the use_attribute functionality) and transferring uniform data to both shader stages (see the use_uniform and use_texture functionality) and execute the shader program (see the draw functionality).

RenderStates

A set of render specific states that has to be specified at each render call.

RenderTarget

Use a render target to render into a texture (color, depth or both). Can be created each time it is needed.

RenderTargetArray

Same as RenderTarget except that the render target contains an array of color textures and depth textures.

Saver

Functionality for saving resources. Only available on desktop at the moment.

Screen

The screen render target which is essential to get something on the screen (see the write function).

Skybox

An illusion of a sky.

SpotLight

A light which shines from the given position and in the given direction. The light will cast shadows if you generate a shadow map.

Texture2D

A 2D texture, basically an image that is transferred to the GPU. For a texture that can be rendered into, see ColorTargetTexture2D.

TextureCubeMap

A texture that covers all 6 sides of a cube.

UniformBuffer

A buffer for transferring a set of uniform variables to the shader program (see also use_uniform_block).

VertexBuffer

A buffer containing per vertex data, for example positions, normals, uv coordinates or colors (see also use_attribute, use_attribute_vec2, etc.).

Viewport

Defines the part of the screen/render target that is rendered to.

Window

Default window and event handler for easy setup.

WriteMask

Defines which channels (red, green, blue, alpha and depth) to write to in a render call.

Enums

BlendEquationType

How the source and target color or alpha value are combined in blend parameters.

BlendMultiplierType

Value multiplied with the source or target color or alpha value in blend parameters.

ColorSource

The source of color on an object, either a fixed value or a texture.

CullType

Defines whether the triangles that are backfacing, frontfacing or both should be skipped in a render call.

DebugType

Used for debug purposes.

DepthFormat

Type of formats for depth render targets (DepthTargetTexture2D and DepthTargetTexture2DArray).

DepthTestType

Defines the depth test in a render call. The depth test determines whether or not a fragment from the current render call should be discarded when comparing its depth with the depth of the current fragment.

Error

Error message from the core module.

Event

An input event (from mouse, keyboard or similar).

Format

Possible formats for pixels in a texture.

IOError

Error message from the core module.

Interpolation

Possible modes of interpolation which determines the texture output between texture pixels.

Key

Keyboard key input.

MouseButton

Type of mouse button.

ProjectionType

Either orthographic or perspective projection.

State

State of a key or button click.

WindowError

Error message from the window module.

Wrapping

Possible wrapping modes for a texture which determines how the texture is applied outside of the [0..1] uv coordinate range.

Traits

Texture

A texture that can be sampled in a fragment shader (see use_texture).

Functions

degrees
radians
rotation_matrix_from_dir_to_dir
vec2
vec3
vec4

Type Definitions

Degrees
Mat2
Mat3
Mat4
Point
Radians
Vec2
Vec3
Vec4