'3D plasma, coded by Ashish 14 June, 2018
'Twitter : @KingOfCoders
'http://lodev.org/cgtutor/plasma.html
'for camera
mapSize = 200
tmp_buffer_image&
= _NEWIMAGE(mapSize
, mapSize
, 32)tmp_height_map&
= _NEWIMAGE(mapSize
, mapSize
, 32) 'this image will be treated as height mapheight_map_buffer
= _MEMIMAGE(tmp_height_map&
) 'the data in above image will access by this _MEM buffer
'storing calculation in memory for faster rendering
sin1
(x
, y
) = SIN(SQR(x
^ 2 + y
^ 2) * .09) sin2
(x
, y
) = SIN(y
* .03)
PRINT "Generating Textures "; f;
"/";
UBOUND(textureImage&
) - 1 f = f + 1
col = sin1(x, y) * 64 + sin2(x, y) * 64 + sin3(x, y) * 64 + 255 + f
PSET (x
, y
), hsb
(col2
, 255, 128, 255)
glAllow = -1
f = f + 1
col = sin1(x, y) * 64 + sin2(x, y) * 64 + sin3(x, y) * 64 + 255 + f
col
= SIN(col
* .01) * 64 + 128
STATIC cubeTexture&
(257), glSetup
glSetup = -1
'Convert all images to GL textures
_glTexImage2D _GL_TEXTURE_2D
, 0, _GL_RGB
, _WIDTH(textureImage&
(i
)), _HEIGHT(textureImage&
(i
)), 0, _GL_BGRA_EXT
, _GL_UNSIGNED_BYTE
, m.OFFSET
gluLookAt 0, 0, 4, 0, 0, 0, 0, 1, 0
i
= (frame
MOD (UBOUND(textureImage&
) - 1)) + 1
'select our texture
'rotation
drawPlane 2, 2, .05, height_map_buffer
frame = frame + 1
SUB drawPlane
(w
, h
, detail
, height_map
AS _MEM)
'texture coordinates
tx1 = 0: ty1 = 0
tx2 = 0: ty2 = 0
depth1 = 0 'used for depth effect by using height maps
depth2 = 0
hx1% = 0: hy1% = 0
hx2% = 0: hy2% = 0
tx1 = map(x, -w / 2, w / 2, 0, 1)
ty1 = map(y, -h / 2, h / 2, 1, 0)
ty2 = map(y + detail, -h / 2, h / 2, 1, 0)
hx1% = map(tx1, 0, 1, 1, mapSize - 1)
hy1% = map(ty1, 0, 1, mapSize - 1, 1)
hy2% = map(ty2, 0, 1, mapSize - 1, 1)
depth1
= _MEMGET(height_map
, height_map.OFFSET
+ memImageIndex
(hx1%
, hy1%
, mapSize
), _UNSIGNED _BYTE) / 400 depth2
= _MEMGET(height_map
, height_map.OFFSET
+ memImageIndex
(hx1%
, hy2%
, mapSize
), _UNSIGNED _BYTE) / 400
memImageIndex& = (x + y * w) * 4
FUNCTION map!
(value!
, minRange!
, maxRange!
, newMinRange!
, newMaxRange!
) map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
'method adapted form http://stackoverflow.com/questions/4106363/converting-rgb-to-hsb-colors
H = map(__H, 0, 255, 0, 360)
S = map(__S, 0, 255, 0, 1)
B = map(__B, 0, 255, 0, 1)
hsb~&
= _RGBA32(B
* 255, B
* 255, B
* 255, A
)
fmx = B - (B * S) + S
fmn = B + (B * S) - S
fmx = B + (B * S)
fmn = B - (B * S)
H = H - 360
H = H / 60
H
= H
- (2 * INT(((iSextant
+ 1) MOD 6) / 2))
fmd = (H * (fmx - fmn)) + fmn
fmd = fmn - (H * (fmx - fmn))