mirror of
https://github.com/Rezmason/matrix.git
synced 2026-04-17 05:49:30 -07:00
Runtime target textures seem to need to be the same format as the canvas current texture. Requires additional investigation.
Created a computeToTexture shader to experiment with writing directly to textures as a means of performing post processing.
This commit is contained in:
23
shaders/wgsl/computeToTexture.wgsl
Normal file
23
shaders/wgsl/computeToTexture.wgsl
Normal file
@@ -0,0 +1,23 @@
|
||||
[[block]] struct Time {
|
||||
seconds : f32;
|
||||
frames : i32;
|
||||
};
|
||||
|
||||
[[group(0), binding(0)]] var textureSampler : sampler;
|
||||
[[group(0), binding(1)]] var inputTex : texture_2d<f32>;
|
||||
[[group(0), binding(2)]] var outputTex : texture_storage_2d<rgba8unorm, write>;
|
||||
|
||||
// Compute shader
|
||||
|
||||
[[stage(compute), workgroup_size(32, 1, 1)]] fn computeMain([[builtin(global_invocation_id)]] id : vec3<u32>) {
|
||||
var row = i32(id.y);
|
||||
var column = i32(id.x);
|
||||
|
||||
if (column >= i32(textureDimensions(inputTex).x)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var color = textureSampleLevel(inputTex, textureSampler, vec2<f32>(f32(column), f32(row)), 0.0);
|
||||
color.g = color.r;
|
||||
textureStore(outputTex, vec2<i32>(column, row), color);
|
||||
}
|
||||
@@ -13,5 +13,5 @@ struct VertOutput {
|
||||
}
|
||||
|
||||
[[stage(fragment)]] fn fragMain(input : VertOutput) -> [[location(0)]] vec4<f32> {
|
||||
return textureSample(inputTexture, inputSampler, input.uv);
|
||||
return textureSample(inputTexture, inputSampler, vec2<f32>(input.uv.x, 1.0 - input.uv.y));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user