From a5af23aa96b78ce145ed06d7ef15483c8a39cb9b Mon Sep 17 00:00:00 2001 From: Gregg Tavares Date: Sun, 19 May 2024 08:55:15 +0900 Subject: [PATCH] add test files --- test/data/test.js | 61 +++++++++++++++++++++++++++++++++++++++++++++ test/data/test.wgsl | 42 +++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 test/data/test.js create mode 100644 test/data/test.wgsl diff --git a/test/data/test.js b/test/data/test.js new file mode 100644 index 0000000..3c006f0 --- /dev/null +++ b/test/data/test.js @@ -0,0 +1,61 @@ + +export const c2 = `// wgsl + struct VSUniforms { + worldViewProjection: mat4x4, + worldInverseTranspose: mat4x4, + }; + @group(0) @binding(0) var vsUniforms: VSUniforms; + @vertex + fn myVSMain(v: MyVSInput) -> MyVSOutput { + var vsOut: MyVSOutput; + vsOut.position = vsUniforms.worldViewProjection * v.position; + vsOut.normal = (vsUniforms.worldInverseTranspose * vec4(v.normal, 0.0)).xyz; + vsOut.texcoord = v.texcoord; + return vsOut; + } +`; + +export const c1 = /* wgsl */` + struct VSUniforms { + worldViewProjection: mat4x4, + worldInverseTranspose: mat4x4, + }; + @group(0) @binding(0) var vsUniforms: VSUniforms; + + struct MyVSInput { + @location(0) position: vec4, + @location(1) normal: vec3, + @location(2) texcoord: vec2, + }; + + struct MyVSOutput { + @builtin(position) position: vec4, + @location(0) normal: vec3, + @location(1) texcoord: vec2, + }; + + @vertex + fn myVSMain(v: MyVSInput) -> MyVSOutput { + var vsOut: MyVSOutput; + vsOut.position = vsUniforms.worldViewProjection * v.position; + vsOut.normal = (vsUniforms.worldInverseTranspose * vec4(v.normal, 0.0)).xyz; + vsOut.texcoord = v.texcoord; + return vsOut; + } + + struct FSUniforms { + lightDirection: vec3, + }; + + @group(0) @binding(1) var fsUniforms: FSUniforms; + @group(0) @binding(2) var diffuseSampler: sampler; + @group(0) @binding(3) var diffuseTexture: texture_2d; + + @fragment + fn myFSMain(v: MyVSOutput) -> @location(0) vec4 { + var diffuseColor = textureSample(diffuseTexture, diffuseSampler, v.texcoord); + var a_normal = normalize(v.normal); + var l = dot(a_normal, fsUniforms.lightDirection) * 0.5 + 0.5; + return vec4(diffuseColor.rgb * l, diffuseColor.a); + } +`; diff --git a/test/data/test.wgsl b/test/data/test.wgsl new file mode 100644 index 0000000..81892b2 --- /dev/null +++ b/test/data/test.wgsl @@ -0,0 +1,42 @@ +struct VSUniforms { + worldViewProjection: mat4x4, + worldInverseTranspose: mat4x4, +}; +@group(0) @binding(0) var vsUniforms: VSUniforms; + +struct MyVSInput { + @location(0) position: vec4, + @location(1) normal: vec3, + @location(2) texcoord: vec2, +}; + +struct MyVSOutput { + @builtin(position) position: vec4, + @location(0) normal: vec3, + @location(1) texcoord: vec2, +}; + +@vertex +fn myVSMain(v: MyVSInput) -> MyVSOutput { + var vsOut: MyVSOutput; + vsOut.position = vsUniforms.worldViewProjection * v.position; + vsOut.normal = (vsUniforms.worldInverseTranspose * vec4(v.normal, 0.0)).xyz; + vsOut.texcoord = v.texcoord; + return vsOut; +} + +struct FSUniforms { + lightDirection: vec3, +}; + +@group(0) @binding(1) var fsUniforms: FSUniforms; +@group(0) @binding(2) var diffuseSampler: sampler; +@group(0) @binding(3) var diffuseTexture: texture_2d; + +@fragment +fn myFSMain(v: MyVSOutput) -> @location(0) vec4 { + var diffuseColor = textureSample(diffuseTexture, diffuseSampler, v.texcoord); + var a_normal = normalize(v.normal); + var l = dot(a_normal, fsUniforms.lightDirection) * 0.5 + 0.5; + return vec4(diffuseColor.rgb * l, diffuseColor.a); +} \ No newline at end of file