Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem of sampler in fragement shader of LookupFilter #140

Open
frostfeng opened this issue Oct 31, 2024 · 0 comments
Open

problem of sampler in fragement shader of LookupFilter #140

frostfeng opened this issue Oct 31, 2024 · 0 comments

Comments

@frostfeng
Copy link

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

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant