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:
Rezmason
2021-11-03 09:03:05 -07:00
parent 35afa7ca01
commit 7eab0fd654
4 changed files with 58 additions and 27 deletions

View 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);
}

View File

@@ -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));
}