Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/shader_canvas/core/webgl_programs/shaders.ts>FragmentShader

A rendering engine where you can write WebGL 2.0 shaders using custom tags.
Latest
class FragmentShader
extends ShaderCode
import { FragmentShader } from "https://deno.land/x/shader_canvas@v1.1.1/core/webgl_programs/shaders.ts";

This class implements the "load" function for the fragment shader. All other functionality is done by extending the ShaderCode class.

Methods

load(gl: WebGL2RenderingContext)

Simple wrapper for the ShaderCode.loadShader() method. Sets the shader type as a FRAGMENT_SHADER

Static Properties

tag: string

<fragment-shader> {#FragmentShader}

This tag holds the fragment shader code of a WebGL program. The code must be valid WebGL 2 GLSL. It is parsed and the variables analyzed and retrieved to allow Shader Canvas to be able to easily reference them and track their locations at compilation/linking time.

The allowed children for the <fragment-shader>:

  • <code> Plain HTML <code> tag that holds the fragment code. Code tag is useful because it allows preformatted text as content.

Example

<shader-canvas>
 <webgl-canvas>
   <webgl-programs>
     <some-program>
       <vertex-shader>
         <code>
           <!--
             Write the vertex shader code for
             "some-program" here.
           -->
         </code>
       </vertex-shader>
       <fragment-shader>
         <code>
           #version 300 es
           precision highp float;
           out vec4 outColor;
           
           void main() {
             outColor = vec4(1, 0, 1, 1);
           }
         </code>
       </fragment-shader>
     </some-program>
   </webgl-programs>
 </webgl-canvas>
</shader-canvas>

For a usable example check the 1st example - simple triangle

The <fragment-shader> tag is meant to be used as a child of the <{{program-name}}> custom named tag.