Here is my simple alpha preloader for now... Without tiling, will add that eventually (actually, I may just code in a texture generator that doesn't rely on a colour map)
When I uncomment where the texture is applied to the cube though, nothing shows up even though it clearly exists.
;This section, for now, just grabs a texture, and an alpha map,
;and generates a new texture to correspond with that.
graphics3d 800,600,32,2
seedrnd millisecs()
setbuffer backbuffer()
Drawn = generatealphaTexture(256,256,"detail.png","color_shade.png")
savebuffer(texturebuffer(Drawn),"Drawn.bmp")
ambientlight 255,255,255
Rock = loadTExture("rock.png")
;Drawn = loadtexture("Drawn.bmp",5)
;textureblend drawn,5
cube = createcube()
entitytexture cube,Rock,false,0
;entitytexture cube,Drawn,false,1
positionentity cube,0,0,5,true
cam = createcamera()
positionentity cam,0,0,0,true
pointentity cam,cube
while not keydown(1)
turnentity cube,0,0.5,0
if keydown(16) then moveentity cam,0,0,0.1
if keydown(30) then moveentity cam,0,0,-0.1
renderworld
flip
wend
end
function GenerateAlphaTexture(w,h,Maintex$,mask$,Scatter=5)
Copy = loadimage(MainTex$)
Alpha = loadimage(mask$)
Tex = createtexture(w,h,5)
for x = 0 to w
for y = 0 to h
lockbuffer imagebuffer(copy)
Colour = readpixelfast(x,y,imagebuffer(Copy))
ColourR = BitToComponentRed(Colour)
ColourG = BitToComponentgreen(Colour)
ColourB = BitToComponentblue(Colour)
unlockbuffer()
lockbuffer imagebuffer(alpha)
fadea# = bittocomponentred(readpixelfast(x,y,imagebuffer(Alpha)))
fade# = fadea# / 255
unlockbuffer()
if fade# < 0.7 ;This area decides whether to draw or not - feel free to play with this
draw = int(fade * (rnd(0,scatter) / scatter))
else
draw = 1
endif
lockbuffer texturebuffer(tex)
if draw then writepixelfast(x,y,componenttobit(ColourR,ColourG,ColourB),texturebuffer(Tex))
unlockbuffer()
next
next
return Tex
end function
; // Bit (argb) to Component for local use(r,g,b)
Function BitToComponentRed(ARGB)
r=ARGB Shr 16 And $FF
return r
End Function
; // Bit (argb) to Component for local use(r,g,b)
Function BitToComponentGreen(ARGB)
g=ARGB Shr 8 And $FF
return g
End Function; // Bit (argb) to Component for local use(r,g,b)
Function BitToComponentBlue(ARGB)
b=ARGB And $FF
return b
End Function
; // Component (r,g,b) to Bit (argb)
Function ComponentToBit(r,g,b)
Return (r Shl 16)+(g Shl 8)+b
End Function