HLSL load equivalent in SKSL ?

128 views
Skip to first unread message

Sushanth Rajasankar

unread,
Apr 29, 2021, 6:51:08 PM4/29/21
to skia-discuss
Hello Skia folks,

I am experimenting with SkiaRuntimeEffects and find myself in a situation where I need to sample exact texels from an input texture. I used skia's sample for this purpose but am running into sampler issues where on some hardware reading the normalized co-ordinate within a texture are resulting in the adjacent texel being read rather than the nearest texel.


I order to avoid this problem, I would like to use the equivalent of HLSL load - which I believe is GLSL texelFetch and use non normalized texel positions. Is there a way to have the equivalent of HLSL load in a SkSL ?

Thanks,
Sushanth


Brian Osman

unread,
May 2, 2021, 9:03:55 AM5/2/21
to skia-d...@googlegroups.com
Not really, no. However: By default, an image shader (created with SkImage::makeShader) will use non-normalized coordinates. Are you making sure to add a half-texel offset when doing your sample, so that the sample locations land in the middle of a texel? If your sample locations are integers (or integers / width,height for normalized coordinates), you will definitely get inconsistent sampling. But if you use integers + 0.5 (or those values / width, height), I would expect precise results on all hardware.

--
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/89a1afca-8ce6-4332-b97c-2523710135c5n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages