Skip to main content

XR8.GlTextureRenderer.configure()

XR8.GlTextureRenderer.configure({ vertexSource, fragmentSource, toTexture, flipY, mirroredDisplay })

Description

Configures the pipeline module that draws the camera feed to the canvas.

Parameters

ParameterTypeDefaultDescription
vertexSource [Optional]StringA no-op vertex shaderThe vertex shader source to use for rendering.
fragmentSource [Optional]StringA no-op fragment shaderThe fragment shader source to use for rendering.
toTexture [Optional]WebGlTextureThe canvasA texture to draw to. If no texture is provided, drawing will be to the canvas.
flipY [Optional]BooleanfalseIf true, flip the rendering upside-down.
mirroredDisplay [Optional]BooleanfalseIf true, flip the rendering left-right.

Returns

None

Example

const purpleShader =
// Purple.
` precision mediump float;
varying vec2 texUv;
uniform sampler2D sampler;
void main() {
vec4 c = texture2D(sampler, texUv);
float y = dot(c.rgb, vec3(0.299, 0.587, 0.114));
vec3 p = vec3(.463, .067, .712);
vec3 p1 = vec3(1.0, 1.0, 1.0) - p;
vec3 rgb = y < .25 ? (y * 4.0) * p : ((y - .25) * 1.333) * p1 + p;
gl_FragColor = vec4(rgb, c.a);
}`

XR8.GlTextureRenderer.configure({fragmentSource: purpleShader})