Texture stuff

Blitz3D Forums/Blitz3D Programming/Texture stuff

Picklesworth(Posted 2004) [#1]
Is there any straight-forward way to do alpha on a texture in code so that I can have a tiling texture that's told to be transparent in certain spots by a big alpha map texture? The reason why I don't want to combine them in photoshop, or using image editing commands, is because I want the two layers to have different blending modes.
And I couldn't just use a big texture with transparency, because in the future I would want to edit this transparency in code (that's for a semi-secret and very cool project), and I also want to be able to reuse textures so I don't get a ridiculous file size in my final product.


Picklesworth(Posted 2004) [#2]
Okay.... To rephrase because that was incomprehensible, and my topic title doesn't help (stupid, stupid, me!).
I have this:


This:


And this:


Allright, now on layer 1 I want the rock texture. Completely solid tiling texture. Layer 2 I want the grass texture, running with multiply 2x, and only visible in certain spots in referance to the first, black and white image. Let's also pretend that the grass map is tiling, but the black and white image is not. (Kind of the opposite of what I have there, but just try to ignore that)
Any ideas how to do this at all?


AdrianT(Posted 2004) [#3]
I tried this, but could only get it to work using alpha which caused sorting problems with other transparent geometry in the scene.

http://s93153354.onlinehome.us/rot.wmv

So I'm interested too, if there is a way to sort betweeen double geometry and other transparent objects above it.


_PJ_(Posted 2004) [#4]
Use EntityTexture texture,x,y

x=textureflag
y=LAYER NUMBER

then use EntityTexture texturetwo,x,y+1

then EntityTexture texturethree,x,y+2

To deal with the tiling, just remember ScaleTexture.

I have hugely differing results between my laptop and desktop PCs, though so beware of the amazing differences different cards produce...


ckob(Posted 2004) [#5]
the onlything I could figure out to do this was to create a terrain for each texture layer and use a mask texture to take out the parts of the layers that would be shown on the others


ckob(Posted 2004) [#6]
the onlything I could figure out to do this was to create a terrain for each texture layer and use a mask texture to take out the parts of the layers that would be shown on the others


MSW(Posted 2004) [#7]
You could do this easy enough by following old film special effects tricks (matte paintings ect.)

create your terrain...load in the rock texture...load in the mask texture...make a copy of the terrain, make a copy of the mask...and load in the grass texture.

so you should have two terrains, and two mask textures...

apply the rock texture to the first terrain, apply the grass texture to the second (copied) terrain.

Now comes the fun part...if the mask texture is ment for the grass texture (that is the white areas are where the grass will be visable, black where it is invisable) then multiply blend apply one of the masks to the terrain with the grass texture.

for the other mask...go through each pixel and invert it, that is you want a negative mask where all black areas become white, and white areas become black (newred = 255 - oldred, newgreen = 255 - oldgreen, etc..)...then multiply blend the negative mask on the terrain with the rock texture.

at this point the rock terrain will have darker black areas where the grass is suppost to show...and the grass terrain will have darker black areas where the rock is to show through...so to make them blend together correctly addiveblend the grass terrain entity...this allows the grass to show in the darkened areas of rock terrain, but allows the rock terrain to show in the darked areas of the grass terrain...


Picklesworth(Posted 2004) [#8]
All righty. I'll be sure to show you what I end up doing.
Thanks for the help so far :)

Isn't there any command that would let me delete pixels?

For now, I've given up in having an attractively small app, and I have a texture generator program under construction, which is just a simple little filter probably possible in photoshop. If I can make it run fast I'll be able to compile the textures on runtime so it can still be happy.


Picklesworth(Posted 2004) [#9]
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



jhocking(Posted 2004) [#10]
Have you had a look at CLE and/or FLE? Those are free terrain tools designed for layering tiled textures.