MaterialXLab API  0.0.1
APIs For MaterialXLab Libraries
Loading...
Searching...
No Matches
glsl_to_wgsl.js File Reference

Go to the source code of this file.

Functions

function async convertGLSLtoWGSL (glslCode, shaderStage="vertex")
 
void main ()
 

Variables

import glslangModule from webgpu glslang
 
 import { compile } from "twgsl"
 
const vertexShaderGLSL
 
const fragmentShaderGLSL
 

Function Documentation

◆ convertGLSLtoWGSL()

function async convertGLSLtoWGSL ( glslCode,
shaderStage = "vertex" )

Definition at line 7 of file glsl_to_wgsl.js.

7 {
8 // Load glslang
9 const glslang = await glslangModule();
10
11 // Map shader stage string to glslang constant
12 const stageMap = {
13 vertex: "vertex",
14 fragment: "fragment",
15 compute: "compute"
16 };
17
18 if (!stageMap[shaderStage]) {
19 throw new Error(`Invalid shader stage: ${shaderStage}`);
20 }
21
22 // Step 1: GLSL → SPIR-V
23 const spirv = glslang.compileGLSL(glslCode, stageMap[shaderStage]);
24
25 // Step 2: SPIR-V → WGSL
26 const wgsl = compile(spirv);
27
28 return wgsl;
29}
import glslangModule from webgpu glslang

◆ main()

void main ( )

Definition at line 34 of file glsl_to_wgsl.js.

34 {
35 gl_Position = vec4(position, 1.0);
36}`;

Variable Documentation

◆ fragmentShaderGLSL

const fragmentShaderGLSL
Initial value:
= `#version 450
layout(location = 0) out vec4 outColor

Definition at line 38 of file glsl_to_wgsl.js.

◆ glslang

import glslangModule from webgpu glslang

Definition at line 4 of file glsl_to_wgsl.js.

◆ import

import { compile } from "twgsl"

Definition at line 5 of file glsl_to_wgsl.js.

5{ compile } from "twgsl";

◆ vertexShaderGLSL

const vertexShaderGLSL
Initial value:
= `#version 450
layout(location = 0) in vec3 position

Definition at line 32 of file glsl_to_wgsl.js.