it works somewhat, but not really

This commit is contained in:
Dynamitos
2025-02-28 10:41:29 +09:00
parent 7f83894d39
commit 4976e3bdcd
3 changed files with 92 additions and 24 deletions
+44
View File
@@ -272,3 +272,47 @@ kernel void computeKernel(
accumulator.write(result, threadId);
image.write(pow(max(result * resolver, 0), float4(0.45f)), threadId);
}
// Screen filling quad in normalized device coordinates.
constant float2 quadVertices[] = {
float2(-1, -1),
float2(-1, 1),
float2( 1, 1),
float2(-1, -1),
float2( 1, 1),
float2( 1, -1)
};
struct CopyVertexOut {
float4 position [[position]];
float2 uv;
};
// Simple vertex shader that passes through NDC quad positions.
vertex CopyVertexOut copyVertex(unsigned short vid [[vertex_id]]) {
float2 position = quadVertices[vid];
CopyVertexOut out;
out.position = float4(position, 0, 1);
out.uv = position * 0.5f + 0.5f;
return out;
}
// Simple fragment shader that copies a texture and applies a simple tonemapping function.
fragment float4 copyFragment(CopyVertexOut in [[stage_in]],
texture2d<float> tex)
{
constexpr sampler sam(min_filter::nearest, mag_filter::nearest, mip_filter::none);
float3 color = tex.sample(sam, in.uv).xyz;
// Apply a simple tonemapping function to reduce the dynamic range of the
// input image into a range which the screen can display.
color = color / (1.0f + color);
return float4(color, 1.0f);
}