ok really im close now
This commit is contained in:
parent
22e9cb094d
commit
89759068e5
16 changed files with 53 additions and 87 deletions
|
@ -1,9 +1,10 @@
|
|||
import { WebGPUApp } from "../renderer/webgpu";
|
||||
import { MeshRenderer } from "../renderer/mesh-renderer";
|
||||
import plane from "../meshes/plane";
|
||||
import rainbowPlane from "./rainbow-plane.wgsl";
|
||||
|
||||
const app = new WebGPUApp({ fov: 20 });
|
||||
|
||||
const renderer = new MeshRenderer(app, plane);
|
||||
|
||||
console.log({ rainbowPlane });
|
||||
app.start();
|
||||
|
|
|
@ -1,30 +1,13 @@
|
|||
struct Uniforms {
|
||||
modelViewProjectionMatrix: mat4x4<f32>,
|
||||
time: f32,
|
||||
}
|
||||
|
||||
@group(0) @binding(0) var<uniform> uniforms: Uniforms;
|
||||
|
||||
struct v2f {
|
||||
@builtin(position) position : vec4f,
|
||||
@location(0) color : vec4f,
|
||||
@location(1) uv : vec2f,
|
||||
}
|
||||
|
||||
@vertex
|
||||
fn main(
|
||||
@builtin(position) position : vec4f,
|
||||
@location(0) uv : vec2f,
|
||||
) -> v2f {
|
||||
return v2f(uniforms.modelViewProjectionMatrix * position, uv);
|
||||
}
|
||||
#include "../color-conv.wgsl"
|
||||
#include "../uniforms.wgsl"
|
||||
#include "../basic-vert.wgsl"
|
||||
|
||||
@fragment
|
||||
fn main(
|
||||
@location(0) uv : vec2f,
|
||||
) -> @location(0) vec4f {
|
||||
f32 zComponent = sin(uniforms.time) * 0.001 * 0.5 + 0.5;
|
||||
vec3f hsv = vec3f(uv.x, uv.y, zComponent);
|
||||
f32 z = sin(uniforms.time) * 0.001 * 0.5 + 0.5;
|
||||
vec3f hsv = vec3f(uv.x, uv.y, z);
|
||||
hsv.x += uniforms.time * 0.0001;
|
||||
hsv.y = 1.0;
|
||||
hsv.z = 1.0;
|
||||
|
@ -32,19 +15,3 @@ fn main(
|
|||
|
||||
return saturate(vec4f(rgb, 1.0));
|
||||
}
|
||||
|
||||
fn rgb2hsv(vec3f c) -> vec3f {
|
||||
vec4f K = vec4f(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
|
||||
vec4f p = mix(vec4f(c.bg, K.wz), vec4f(c.gb, K.xy), step(c.b, c.g));
|
||||
vec4f q = mix(vec4f(p.xyw, c.r), vec4f(c.r, p.yzx), step(p.x, c.r));
|
||||
|
||||
f32 d = q.x - min(q.w, q.y);
|
||||
f32 e = 1.0e-10;
|
||||
return vec3f(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
|
||||
}
|
||||
|
||||
fn hsv2rgb(vec3f c) -> vec3f {
|
||||
vec4f K = vec4f(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
||||
vec3f p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
|
||||
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
||||
}
|
14
src/basic-vert.wgsl
Normal file
14
src/basic-vert.wgsl
Normal file
|
@ -0,0 +1,14 @@
|
|||
struct v2f {
|
||||
@builtin(position) position : vec4f,
|
||||
@location(0) color : vec4f,
|
||||
@location(1) uv : vec2f,
|
||||
}
|
||||
|
||||
@vertex
|
||||
fn main(
|
||||
@builtin(position) position : vec4f,
|
||||
@location(0) color : vec4f,
|
||||
@location(1) uv : vec2f,
|
||||
) -> v2f {
|
||||
return v2f(uniforms.modelViewProjectionMatrix * position, color, uv);
|
||||
}
|
15
src/color-conv.wgsl
Normal file
15
src/color-conv.wgsl
Normal file
|
@ -0,0 +1,15 @@
|
|||
fn rgb2hsv(vec3f c) -> vec3f {
|
||||
vec4f K = vec4f(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
|
||||
vec4f p = mix(vec4f(c.bg, K.wz), vec4f(c.gb, K.xy), step(c.b, c.g));
|
||||
vec4f q = mix(vec4f(p.xyw, c.r), vec4f(c.r, p.yzx), step(p.x, c.r));
|
||||
|
||||
f32 d = q.x - min(q.w, q.y);
|
||||
f32 e = 1.0e-10;
|
||||
return vec3f(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
|
||||
}
|
||||
|
||||
fn hsv2rgb(vec3f c) -> vec3f {
|
||||
vec4f K = vec4f(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
||||
vec3f p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
|
||||
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
||||
}
|
6
src/uniforms.wgsl
Normal file
6
src/uniforms.wgsl
Normal file
|
@ -0,0 +1,6 @@
|
|||
struct Uniforms {
|
||||
modelViewProjectionMatrix: mat4x4<f32>,
|
||||
time: f32,
|
||||
}
|
||||
|
||||
@group(0) @binding(0) var<uniform> uniforms: Uniforms;
|
Loading…
Add table
Add a link
Reference in a new issue