What is iFrame and texelFetch in shadertoy?

Hello Creators,
I wanted to understand two questions i have been feeling helpless about.
I would appreciate if you can fill these voids.

1. iFrame in shadertoy :
I understand its a shader playback frame which is a uniform int data type.
So essentially in a use case we write :

if(iFrame < 5)
  • I want to understand how do we make sense of this in spark AR ?
  • How do we get the shader playback frame in spark AR ?
  1. TexelFetch in shadertoy : I would really appreciate if you can explain this one with an example.

    • What does texelFetch(iVec2(uv), 0) mean ?
    • How is it different from texture.sample(vec2) ?
    • What is the difference between iVec2 and vec2, in sparkSL how do we make iVec2 ?

“Texel” is short for texture-element or texture-pixel. Sampling a texel means that you are working on pixels as opposed to vertices. I think by default, the fragment stage works on screen pixels, but texel sampling works on pixels in the texture itself. The screen pixels could be much less than expected, based on geometry orientation and distance from the camera. I’m sort of guessing on this :slight_smile:

Here’s how you can track the current frame number, purely in patches:

Then you can pass that into the SL shader. The main difference is that int isn’t supported as an input type in Spark SL, so you need to use float.

Here’s a doc on ivec2 data type.

I think you can convert a float into an int by doing something like this: int(3.4)