07-12-2023, 09:30 PM
(07-12-2023, 02:36 PM)bplus Wrote:(07-12-2023, 02:21 PM)Dav Wrote: _HYPOT huh? Neat. I shouldn't have stopped reading the keyword of the day thread.
- Dav
Hi from ZXDunny at another forum that Charlie has inspired, this is a ball shader:
Code: (Select All)
' Ball shader
' by ZXDunny 2023
sw = 800
sh = 480
Screen _NewImage(sw, sh, 32) ' SpecBAS uses this as its default window size
xc = sw / 2
yc = sh / 2
r = 100
amb = 0.0125
k = 3
mxp = (1 - amb) * 255
r2 = r * r
Do
While _MouseInput: Wend
lx = xc - _MouseX
ly = yc - _MouseY
lz = -75
Cls
l = Sqr(lx * lx + ly * ly + lz * lz)
nlx = lx / l
nly = ly / l
nlz = lz / l
For x = -r To r
x2 = x * x
For y = -r To r
y2 = y * y
If x2 + y2 <= r2 Then
v2 = Sqr(r2 - x2 - y2)
l = Sqr(x2 + y2 + v2 * v2)
v0 = x / l
v1 = y / l
v2 = v2 / l
d = nlx * v0 + nly * v1 + nlz * v2
'i = mxp * (iff(d < 0, -d ^ k, 0) + amb)
If d < 0 Then i = mxp * (-d ^ k) + amp Else i = amp
PSet (x + xc, y + yc), _RGB32(Int(i), Int(i), Int(i))
End If
Next y
Next x
_Display
Loop
The mouse is light source, so move it around...
More things to play with!!!
ZXDunny's BAM program (ULTIMATE Gradient Ball):