Used to create a PipelineEntry specifically designed to handle RenderMaterial.

Shaders patching

The RenderPipelineEntry uses each of its bind groups Binding to patch the given vertex and fragment shaders before creating the GPUShaderModule.
It will prepend every Binding WGSL code snippets (or fragments) with the correct bind group and bindings indices.

Pipeline compilation

The RenderPipelineEntry will then create a GPURenderPipeline (asynchronously by default).

Default attributes and uniforms

Attributes

Attributes are only added to the vertex shaders. They are generated based on the Geometry used and may vary in case you're using a geometry with custom attributes. Here are the default ones:

struct Attributes {
@builtin(vertex_index) vertexIndex : u32,
@builtin(instance_index) instanceIndex : u32,
@location(0) position: vec3f,
@location(1) uv: vec2f,
@location(2) normal: vec3f
};

// you can safely access them in your vertex shader
// using attributes.position or attributes.uv for example

Uniforms

If the Mesh is one of Mesh, DOMMesh or Plane, some additional uniforms are added to the shaders.

Vertex shaders

struct Matrices {
model: mat4x4f,
modelView: mat4x4f,
normal: mat3x3f
};

struct Camera {
view: mat4x4f,
projection: mat4x4f,
position: vec3f
};

@group(0) @binding(0) var<uniform> camera: Camera;

// note that matrices uniform @group index might change depending on use cases
@group(1) @binding(0) var<uniform> matrices: Matrices;

// you can safely access these uniforms in your vertex shader
// using matrices.modelView or camera.projection for example

Fragment shaders

struct Matrices {
model: mat4x4f,
modelView: mat4x4f,
normal: mat3x3f
};

// note that matrices uniform @group index might change depending on use cases
@group(1) @binding(0) var<uniform> matrices: Matrices;

// you can safely access these uniforms in your fragment shader
// using matrices.model or matrices.modelView for example

Helpers

Finally, some helpers functions are added to the shaders as well.

Vertex and fragment shaders

To help you compute scaled UV based on a texture matrix, this function is always added to both vertex and fragment shaders:

fn getUVCover(uv: vec2f, textureMatrix: mat4x4f) -> vec2f {
return (textureMatrix * vec4f(uv, 0.0, 1.0)).xy;
}

Vertex shaders

If the Mesh is one of Mesh, DOMMesh or Plane, some functions are added to the vertex shader to help you compute the vertices positions and normals.

Position

Position helper function:

fn getOutputPosition(position: vec3f) -> vec4f {
return camera.projection * matrices.modelView * vec4f(position, 1.0);
}

Note that it is not mandatory to use it. If you want to do these computations yourself, you are free to do it the way you like most. You could for example use this formula instead:

var transformed: vec3f = camera.projection * camera.view * matrices.model * vec4f(position, 1.0);
Normal

The normal matrix provided, available as matrices.normal, is computed in world space (i.e. it is the inverse transpose of the world matrix). A couple helpers functions are added to help you compute the normals in the right space:

fn getWorldNormal(normal: vec3f) -> vec3f {
return normalize(matrices.normal * normal);
}

fn getViewNormal(normal: vec3f) -> vec3f {
return normalize((camera.view * vec4(matrices.normal * normal, 0.0)).xyz);
}

Fragment shaders

Last but not least, those couple functions are added to the fragment shaders to help you convert vertex positions to UV coordinates:

fn getVertex2DToUVCoords(vertex: vec2f) -> vec2f {
return vec2(
vertex.x * 0.5 + 0.5,
0.5 - vertex.y * 0.5
);
}

fn getVertex3DToUVCoords(vertex: vec3f) -> vec2f {
return getVertex2DToUVCoords( vec2(vertex.x, vertex.y) );
}

Hierarchy (view full)

Constructors

Properties

type: string

The type of the PipelineEntry

renderer: Renderer

The Renderer used to create this PipelineEntry

index: number

Index of this PipelineEntry, i.e. creation order

layout: GPUPipelineLayout

GPUPipelineLayout | Pipeline layout created based on the given bind groups

pipeline: GPURenderPipeline | GPUComputePipeline

The GPU pipeline

The pipeline compilation status

bindGroups: AllowedBindGroups[]

bind groups used to patch the shaders and create the pipeline layout

Shaders to use with this RenderPipelineEntry

descriptor: GPURenderPipelineDescriptor

GPURenderPipelineDescriptor | Render pipeline descriptor based on layout and shaders

Options used to create this RenderPipelineEntry

Accessors

  • get canCompile(): boolean
  • Get whether the pipeline is ready to be compiled, i.e. we have not already tried to compile it, and it's not currently compiling neither

    Returns boolean

Methods