Skip to content

Commit

Permalink
Dump shaders
Browse files Browse the repository at this point in the history
  • Loading branch information
nanoqsh committed Nov 30, 2023
1 parent ba6f4fd commit 9c437a2
Show file tree
Hide file tree
Showing 5 changed files with 326 additions and 0 deletions.
57 changes: 57 additions & 0 deletions shaders/post0.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
struct Data {
size: vec2<f32>,
step: vec2<f32>,
factor: vec2<f32>,
pad: vec2<u32>,
}

@group(0) @binding(0)
var<uniform> data: Data;

struct VertexOutput {
@builtin(position) pos: vec4<f32>,
@location(0) uni: vec2<f32>,
@location(1) map: vec2<f32>,
}

@vertex
fn vsmain(@builtin(vertex_index) in_vertex_index: u32) -> VertexOutput {
var out: VertexOutput;
switch in_vertex_index {
case 0u {
out.pos = vec4(1., -1., 0., 1.);
out.uni = vec2(1., 1.);
out.map = data.factor.xy;
}
case 1u {
out.pos = vec4(1., 1., 0., 1.);
out.uni = vec2(1., 0.);
out.map = vec2(data.factor.x, 0.);
}
case 2u {
out.pos = vec4(-1., -1., 0., 1.);
out.uni = vec2(0., 1.);
out.map = vec2(0., data.factor.y);
}
case 3u {
out.pos = vec4(-1., 1., 0., 1.);
out.uni = vec2(0., 0.);
out.map = vec2(0., 0.);
}
default {}
}
return out;
}

@group(1) @binding(0)
var tmap: texture_2d<f32>;
@group(1) @binding(1)
var smap: sampler;

@fragment
fn fsmain(in: VertexOutput) -> @location(0) vec4<f32> {
var col: vec4<f32>;
col = textureSample(tmap, smap, in.map);

return col;
}
57 changes: 57 additions & 0 deletions shaders/post1.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
struct Data {
size: vec2<f32>,
step: vec2<f32>,
factor: vec2<f32>,
pad: vec2<u32>,
}

@group(0) @binding(0)
var<uniform> data: Data;

struct VertexOutput {
@builtin(position) pos: vec4<f32>,
@location(0) uni: vec2<f32>,
@location(1) map: vec2<f32>,
}

@vertex
fn vsmain(@builtin(vertex_index) in_vertex_index: u32) -> VertexOutput {
var out: VertexOutput;
switch in_vertex_index {
case 0u {
out.pos = vec4(1., -1., 0., 1.);
out.uni = vec2(1., 1.);
out.map = data.factor.xy;
}
case 1u {
out.pos = vec4(1., 1., 0., 1.);
out.uni = vec2(1., 0.);
out.map = vec2(data.factor.x, 0.);
}
case 2u {
out.pos = vec4(-1., -1., 0., 1.);
out.uni = vec2(0., 1.);
out.map = vec2(0., data.factor.y);
}
case 3u {
out.pos = vec4(-1., 1., 0., 1.);
out.uni = vec2(0., 0.);
out.map = vec2(0., 0.);
}
default {}
}
return out;
}

@group(1) @binding(0)
var tmap: texture_2d<f32>;
@group(1) @binding(1)
var smap: sampler;

@fragment
fn fsmain(in: VertexOutput) -> @location(0) vec4<f32> {
var col: vec4<f32>;
col = textureSample(tmap, smap, in.map);

return col;
}
61 changes: 61 additions & 0 deletions shaders/post2.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
struct Data {
size: vec2<f32>,
step: vec2<f32>,
factor: vec2<f32>,
pad: vec2<u32>,
}

@group(0) @binding(0)
var<uniform> data: Data;

struct VertexOutput {
@builtin(position) pos: vec4<f32>,
@location(0) uni: vec2<f32>,
@location(1) map: vec2<f32>,
}

@vertex
fn vsmain(@builtin(vertex_index) in_vertex_index: u32) -> VertexOutput {
var out: VertexOutput;
switch in_vertex_index {
case 0u {
out.pos = vec4(1., -1., 0., 1.);
out.uni = vec2(1., 1.);
out.map = data.factor.xy;
}
case 1u {
out.pos = vec4(1., 1., 0., 1.);
out.uni = vec2(1., 0.);
out.map = vec2(data.factor.x, 0.);
}
case 2u {
out.pos = vec4(-1., -1., 0., 1.);
out.uni = vec2(0., 1.);
out.map = vec2(0., data.factor.y);
}
case 3u {
out.pos = vec4(-1., 1., 0., 1.);
out.uni = vec2(0., 0.);
out.map = vec2(0., 0.);
}
default {}
}
return out;
}

@group(1) @binding(0)
var tmap: texture_2d<f32>;
@group(1) @binding(1)
var smap: sampler;

@fragment
fn fsmain(in: VertexOutput) -> @location(0) vec4<f32> {
var col: vec4<f32>;
col = textureSample(tmap, smap, in.map);

let vcol = vec4(0.0, 0.0, 0.0, 1.);
let vforce = length(in.uni * 2. - 1.) * 0.3;
col = mix(col, vcol, vforce);

return col;
}
99 changes: 99 additions & 0 deletions shaders/sh0.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
struct InstanceInput {
@location(0) r0: vec4<f32>,
@location(1) r1: vec4<f32>,
@location(2) r2: vec4<f32>,
@location(3) r3: vec4<f32>,
}

struct VertexInput {
@location(4) pos: vec3<f32>,
@location(5) map: vec2<f32>,
}

struct VertexOutput {
@builtin(position) pos: vec4<f32>,
@location(0) map: vec2<f32>,
@location(1) world: vec3<f32>,
@location(2) space_0: vec3<f32>,
}

struct Camera {
view: mat4x4<f32>,
}

struct Source {
col: vec3<f32>,
rad: f32,
pos: vec3<f32>,
}

struct Len {
n: u32,
pad0: u32,
pad1: u32,
pad2: u32,
}

struct Space {
model: mat4x4<f32>,
col: vec3<f32>,
}


@group(0) @binding(0) var<uniform> camera: Camera;
@group(0) @binding(1) var<uniform> ambient: vec4<f32>;
@group(1) @binding(0) var tmap_0: texture_2d<f32>;
@group(1) @binding(1) var smap: sampler;
@group(2) @binding(0) var<uniform> sources_array_0: array<Source, 3>;
@group(2) @binding(1) var<uniform> sources_len_0: Len;
@group(3) @binding(0) var<uniform> spaces: array<Space, 1>;
@group(3) @binding(1) var tspace_0: texture_3d<f32>;
@group(3) @binding(2) var sspace: sampler;


@vertex
fn vsmain(inst: InstanceInput, input: VertexInput) -> VertexOutput {
let model = mat4x4<f32>(
inst.r0,
inst.r1,
inst.r2,
inst.r3,
);

var out: VertexOutput;
let world = model * vec4(input.pos, 1.);
out.pos = camera.view * world;
out.map = input.map;
out.world = world.xyz;
out.space_0 = (spaces[0].model * world).xzy;

return out;
}

@fragment
fn fsmain(out: VertexOutput) -> @location(0) vec4<f32> {
var col: vec3<f32>;
let tex = textureSample(tmap_0, smap, out.map);
if tex.a < 0.9 { discard; }

var sources = vec3(0.);
for (var i = 0u; i < sources_len_0.n; i++) {
let src = sources_array_0[i];
if out.world.x > src.pos.x - src.rad && out.world.x < src.pos.x + src.rad && out.world.y > src.pos.y - src.rad && out.world.y < src.pos.y + src.rad && out.world.z > src.pos.z - src.rad && out.world.z < src.pos.z + src.rad {
let len = length(out.world - src.pos);
if len < src.rad {
let e = 1. - (len / src.rad);
sources += e * e * src.col;
}
}
}

var space = vec3(0.);
var space_a = textureSampleLevel(tspace_0, sspace, out.space_0, 0.);
space = space_a.rgb * spaces[0].col;

let light = ambient.rgb + sources + space;
col = light * tex.rgb;

return vec4(col, 1.);
}
52 changes: 52 additions & 0 deletions shaders/sh1.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
struct InstanceInput {
@location(0) r0: vec4<f32>,
@location(1) r1: vec4<f32>,
@location(2) r2: vec4<f32>,
@location(3) r3: vec4<f32>,
}

struct InstanceColorInput {
@location(4) col: vec3<f32>,
}

struct VertexInput {
@location(5) pos: vec3<f32>,
}

struct VertexOutput {
@builtin(position) pos: vec4<f32>,
@location(0) instcol: vec3<f32>,
}

struct Camera {
view: mat4x4<f32>,
}


@group(0) @binding(0) var<uniform> camera: Camera;


@vertex
fn vsmain(inst: InstanceInput, instcol: InstanceColorInput, input: VertexInput) -> VertexOutput {
let model = mat4x4<f32>(
inst.r0,
inst.r1,
inst.r2,
inst.r3,
);

var out: VertexOutput;
let world = model * vec4(input.pos, 1.);
out.pos = camera.view * world;
out.instcol = instcol.col;

return out;
}

@fragment
fn fsmain(out: VertexOutput) -> @location(0) vec4<f32> {
var col: vec3<f32>;
col = out.instcol;

return vec4(col, 1.);
}

0 comments on commit 9c437a2

Please sign in to comment.