Skip to content

Commit

Permalink
fix wgsl buffer vertex code
Browse files Browse the repository at this point in the history
  • Loading branch information
Vipitis committed Jul 25, 2024
1 parent 253c5e1 commit 46833c7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
46 changes: 43 additions & 3 deletions examples/shadertoy_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,51 @@
}
"""

# theoretically we can use a buffer pass in wgsl as well, and mix them. Just set shader_type = "wgsl"!
buffer_code_wgsl = """
fn shader_main(frag_coord: vec2<f32>) -> vec4<f32>{
let uv = frag_coord / i_resolution.xy;
let col = textureSample(i_channel0, sampler0, uv).xyz;
var k = col.x;
var j = col.y;
let inc = ((uv.x + uv.y) / 100.0) * 0.99 + 0.01;
if (j == 0.0) {
k += inc;
}
else {
k -= inc;
}
if (k >= 1.0){
j = 1.0;
}
if (k <= 0.0){
j = 0.0;
}
return vec4<f32>(k, j, 0.0, 1.0);
}
"""


buffer_a_channel = ShadertoyChannelBuffer(buffer="a", wrap="repeat")
buffer_a_pass = BufferRenderPass(
buffer_idx="a", code=buffer_code, inputs=[buffer_a_channel]
# buffer_a_pass = BufferRenderPass(
# buffer_idx="a", code=buffer_code, inputs=[buffer_a_channel]
# )
# shader = Shadertoy(image_code, inputs=[buffer_a_channel], buffers={"a": buffer_a_pass})

# using the wgsl buffer pass instead
buffer_a_pass_wgsl = BufferRenderPass(
buffer_idx="a", code=buffer_code_wgsl, inputs=[buffer_a_channel], shader_type="wgsl"
)
shader = Shadertoy(
image_code, inputs=[buffer_a_channel], buffers={"a": buffer_a_pass_wgsl}
)
shader = Shadertoy(image_code, inputs=[buffer_a_channel], buffers={"a": buffer_a_pass})

if __name__ == "__main__":
shader.show()
2 changes: 1 addition & 1 deletion wgpu_shadertoy/passes.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
out.vert_uv = vec2<f32>(2.0, 0.0); // Flipped
} else {
out.position = vec4<f32>(-1.0, 3.0, 0.0, 1.0);
out.vert_uv = vec2<f32>(0.0, -2.0); // Flipped
out.vert_uv = vec2<f32>(0.0, 2.0); // Flipped
}
return out;
Expand Down

0 comments on commit 46833c7

Please sign in to comment.