1
0
mirror of https://github.com/TomHarte/CLK.git synced 2026-03-15 01:16:40 +00:00

Avoid hard-coded magi constant.

This commit is contained in:
Thomas Harte
2026-02-23 17:06:25 -05:00
parent 8119428d56
commit ea1df88083
3 changed files with 10 additions and 2 deletions

View File

@@ -129,6 +129,7 @@ struct Uniforms {
__fp16 outputAlpha;
__fp16 outputGamma;
__fp16 outputMultiplier;
__fp16 weightedMixAlpha;
};
// Kernel sizes above and in the shaders themselves assume a maximum filter kernel size.
@@ -273,6 +274,7 @@ using BufferingScanTarget = Outputs::Display::BufferingScanTarget;
- (void)setAlpha {
static constexpr float alpha = 0.64f;
self.uniforms->outputAlpha = __fp16(std::sqrt(alpha));
self.uniforms->weightedMixAlpha = __fp16(alpha);
}
- (nonnull instancetype)initWithView:(nonnull MTKView *)view {
@@ -931,6 +933,7 @@ using BufferingScanTarget = Outputs::Display::BufferingScanTarget;
[encoder setFragmentTexture:_frameBuffers[_fieldIndex ^ 1] atIndex:0];
[encoder setVertexTexture:_frameBuffers[_fieldIndex] atIndex:1];
[encoder setFragmentTexture:_frameBuffers[_fieldIndex] atIndex:1];
[encoder setFragmentBuffer:_uniformsBuffer offset:0 atIndex:0];
[encoder drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:4];
[encoder endEncoding];

View File

@@ -69,6 +69,7 @@ fragment half4 interpolateEqualMixFragment(
fragment half4 weightedMixFragment(
const CopyInterpolator vert [[stage_in]],
const constant Uniforms &uniforms [[buffer(0)]],
const metal::texture2d<half> texture1 [[texture(0)]],
const metal::texture2d<half> texture2 [[texture(1)]]
) {
@@ -76,12 +77,13 @@ fragment half4 weightedMixFragment(
metal::mix(
texture1.sample(nearestSampler, vert.textureCoordinates),
texture2.sample(nearestSampler, vert.textureCoordinates),
0.64
uniforms.weightedMixAlpha
);
}
fragment half4 interpolateWeightedMixFragment(
const CopyInterpolator vert [[stage_in]],
const constant Uniforms &uniforms [[buffer(0)]],
const metal::texture2d<half> texture1 [[texture(0)]],
const metal::texture2d<half> texture2 [[texture(1)]]
) {
@@ -89,7 +91,7 @@ fragment half4 interpolateWeightedMixFragment(
metal::mix(
texture1.sample(linearSampler, vert.textureCoordinates),
texture2.sample(linearSampler, vert.textureCoordinates),
0.64
uniforms.weightedMixAlpha
);
}

View File

@@ -44,4 +44,7 @@ struct Uniforms {
// Sets a brightness multiplier for output colours.
half outputMultiplier;
// Sets the opacity used by the weighted-mix copy shaders.
half weightedMixAlpha;
};