I have been meaning to write about this for months now but it feels too trivial and I put it off. Well, here’s how I stumbled upon the spongebob shader: I was playing around with the equation of a squircle

x4+y4=1 x^4 + y^4 = 1

A classic squircle

when I factored out the x and y raised to the powers of 4 as a square of squares.

x2⋅x2+y2⋅y2=1 x^2 \cdot x^2 + y^2 \cdot y^2 = 1

It helps to think of each squared term like x2x^2 as energy or intensity from a physics perspective.

We can make the corners wavy if we turn one of the intensities sinusoidal.

x2⋅sin(x)2+y2⋅sin(y)2=1 x^2 \cdot sin(x)^2 + y^2 \cdot sin(y)^2 = 1

These can still be thought of as intensities since sin(x)∈[−1,1]sin(x) \in [-1, 1] and sin(x)2∈[0,1]sin(x)^2 \in [0, 1] is a strength between 0 and 1.

Which gives us … yet another squircle with many islands around it. The waves essentially shunt off in the gaps between these islands.

Yet another squircle with islands around it

To make the waves more frequent, we simply make the sine go 6π 6 \pi radians or two full rotations every 1 unit step in the x or y direction.

The 6π 6 \pi is an artistic choice, using one full rotation of 2π 2 \pi radians would make the edges less wavy.

x2⋅sin(6πx)2+y2⋅sin(6πy)2=1 x^2 \cdot sin(6 \pi x)^2 + y^2 \cdot sin( 6 \pi y )^2 = 1

Now to get rid of the we can constrain the range of xx and yy to ∣x∣<1.1 |x| < 1.1 and ∣y∣<1.1|y| < 1.1 .

You’ll have to mess around to find the upper bound like 1.11.1 if you used a different wave frequency.

That’s it, behold the spongebob shader!

The spongebob shader using the above equations in desmos