GPUImage3
GPUImage3 copied to clipboard
problem of sampler in fragement shader of LookupFilter
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
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)));
}