Skip to content

problem of sampler in fragement shader of LookupFilter  #140

@frostfeng

Description

@frostfeng

Hi,BradLarson
I found some problem in fragment shader of LookupFilter from LookupFilter.metal。
The definition of sampler quadSampler has problem, you do not specified filter of sampler, which default value is nearest。This will cause sample value of lut texture(inputTexture2)is not precise。

It should be fixed with specified the sampler's filter property with value "linear". So, the sampler should be defined as:

constexpr sampler quadSampler(address::clamp_to_edge, filter::linear);

fragment half4 lookupFragment(TwoInputVertexIO fragmentInput [[stage_in]],
texture2d inputTexture [[texture(0)]],
texture2d inputTexture2 [[texture(1)]],
constant IntensityUniform& uniform [[ buffer(1) ]])
{
// constexpr sampler quadSampler;
constexpr sampler quadSampler(address::clamp_to_edge, filter::linear);
half4 base = inputTexture.sample(quadSampler, fragmentInput.textureCoordinate);

half blueColor = base.b * 63.0h;

half2 quad1;
quad1.y = floor(floor(blueColor) / 8.0h);
quad1.x = floor(blueColor) - (quad1.y * 8.0h);

half2 quad2;
quad2.y = floor(ceil(blueColor) / 8.0h);
quad2.x = ceil(blueColor) - (quad2.y * 8.0h);

float2 texPos1;
texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * base.r);
texPos1.y = (quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * base.g);

float2 texPos2;
texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * base.r);
texPos2.y = (quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * base.g);

// constexpr sampler quadSampler3;
constexpr sampler quadSampler3(address::clamp_to_edge, filter::linear);
half4 newColor1 = inputTexture2.sample(quadSampler3, texPos1);
// constexpr sampler quadSampler4;
constexpr sampler quadSampler4(address::clamp_to_edge, filter::linear);
half4 newColor2 = inputTexture2.sample(quadSampler4, texPos2);

half4 newColor = mix(newColor1, newColor2, fract(blueColor));
return half4(mix(base, half4(newColor.rgb, base.w), half(uniform.intensity)));

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions