Issues with sampling Lut in Skia Effect

132 views
Skip to first unread message

Jurek Bielicki

unread,
Nov 8, 2022, 8:41:45 AM11/8/22
to skia-discuss
Hi Skia Team,

I'm working on a custom Skia effect for Android OS.
To implement the effect I need to pass Lut (Look Up Table) in the form of  4 float bitmap (SkColorType::kRGBA_F32_SkColorType), as below (only x-horizontal coord is in focus for simplicity):

fn(std::vector<float> lut, int w, int h) {
SkImageInfo info = SkImageInfo::Make(w, h, SkColorType::kRGBA_F32_SkColorType,
        SkAlphaType::kOpaque_SkAlphaType);
SkPixmap map(info, lut.data(), w * 4 * sizeof(float));
bmp.allocPixels(info);
bmp.writePixels(map);
return SkImage::MakeFromBitmap(bmp);
},
where only green channel - ctr % 4 == 1, for every 4th pixel starting from third - x % 4 == 2 is populated in lut:

std::vector<float> lut(w * h * 4, 0);
int ctr = 0;
for (auto &e : lut) {
    int x = (ctr / 4) % w;
    if (x % 4 == 2 && ctr % 4 == 1)
         e = (float) x / (float) w;
    ctr++;
}

In the effect I can properly sample and display either:
  • uniform shader uContentTexture;  // containing processed content
  • uniform shader fLutTexture;  // containing passed lok up table,
I can see that each pixel is displayed as expected.

But when I sample Lut and use obtained value to sample content, the position is correct, but color is wrong (seem to be incorectly interpolated), code below splits display to three parts:
  • top - correctly displayed content (black, red, green, blue repeatedly)
  • middle - correctly displayed lut (black, black, green, black repeatedly)
  • bottom - incorrectly coloured every 4th pixel (so location is good)
    uniform shader uContentTexture;
    uniform shader fLut;
    uniform 
fWidth;
    vec4 main(float2 p) {
        if (p.y < 250) {
            return sample(uContentTexture, p);
        }
        if (p.y < 500) {
            return sample(fLut, p);
        }
        float4 lut = sample(fLut, p);
        return sample(uContentTexture, float2(fWidth * lut.y + 0.5, p.y));
    }

image (15).png

I suspect some inconsistency in interpolation of content color based on lut.x value, but have no clue how to verify and correct such misalignment. 
I am aware of Skia/Sksl specific sampling rules described here: https://groups.google.com/g/skia-discuss/c/8l_y6zEteX8

Any help would be really appreciated.
Best Regards,
Jurek

Brian Osman

unread,
Nov 8, 2022, 11:09:42 AM11/8/22
to skia-d...@googlegroups.com
Hmm, are you able to recreate the problem on fiddle.skia.org ? That would make it easier for us to see how everything fits together.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/e2385db7-a0dc-40ec-9f31-6cb0cb8b417cn%40googlegroups.com.

Brian Salomon

unread,
Nov 8, 2022, 11:36:13 AM11/8/22
to skia-d...@googlegroups.com
Also, the GPU backend does not support F32 textures so I believe your texture will get downgraded to F16.



--

Brian Salomon | Office Hours: go/bsalomon-office | bsal...@google.com

Jurek Bielicki

unread,
Nov 17, 2022, 9:27:27 AM11/17/22
to skia-discuss
Using F32 was the reason (no issue with OpenGL GL_RGBA32F though), replaced with F16 and stored each float with two fields on F16 texture. Thank you Brian for helpful hint!
Reply all
Reply to author
Forward
0 new messages