Change Texture Color

Blitz3D Forums/Blitz3D Programming/Change Texture Color

I need one thing that i think it cannot be done easily and fast... but perhaps i am missing something.

I have a model with a simple texture. I want to add a second texture, to mask some parts. But what i want is to change the second texture color in realtime, so i can mask with differente colors the original texture.

I cannot use vertexcolors, because that would change all the colors of both textures.

Do you understand? Is it possible?

You can create an empty texture using CreateTexture, and then draw to it using SetBuffer TextureBuffer:
tex = CreateTexture(64, 64)
SetBuffer TextureBuffer(tex)
;all drawing commands are applied to texture
Oval 0, 0, 50, 50
SetBuffer BackBuffer()
;apply texture like this:
EntityTexture mesh, tex, 0, 1


Thanks, Mmm, well, but then, i need to create empty texture, read the mask texture, and change the color while writing... too slow...

more ideas?

You can use a secound modell, set its alpha value to... 0.2? and then change the color of the secound modell. The only disadvantage is, you have double poly count...

Where's the since of this, by the way?

It is to change the color of the main models, but instead of having N textures with N different colors, i can change the texture color (colorize), and mask it over the model...

Maybe you could use this, you need to grayscale the original texture. It uses a small 2nd texture to change the color.
Graphics3D 800, 600, 0, 2
SetBuffer BackBuffer()

camera= CreateCamera()
MoveEntity camera, 0, 0, -5

cube = CreateCube()

tex2 = MakeTexture(256, 256)
EntityTexture cube, tex2

tex1 = CreateTexture(2, 2)
EntityTexture cube, tex1, 0, 1

Repeat
	
	red = Cos(tme +   0) * 127 + 128
	grn = Cos(tme +  90) * 127 + 128
	blu = Cos(tme + 180) * 127 + 128
	tme = tme + 5
	
	FillTexture(tex1, red, grn, blu)
	
	RenderWorld()
	
	Flip
	
Until KeyHit(1)

End
	
	
Function MakeTexture(w, h)

	oldb = GraphicsBuffer()
	tex = CreateTexture(w, h)
	SetBuffer TextureBuffer(tex)
	For x = 0 To w
	For y = 0 To h
		c = Rand(255)
		Color c, c, c
		Plot x, y
	Next
	Next
	SetBuffer oldb
	
	Return tex

End Function

Function FillTexture(tex, r, g, b)
	
	oldb = GraphicsBuffer()
	SetBuffer TextureBuffer(tex)
	ClsColor r, g, b
	Cls
	SetBuffer oldb
End Function


Mmm, is is interesting... the thing is that texturebuffer could do the trick...

Thanks, i will try...

Offtopic: I love this forum, people is always trying to help. I am in a lot of programming forums, and this is by far the best (i had some troubles with other user in other forum recently...)

Here's how I would do it, not sure how similar it is to Brams.

For the parts of the model which need to be changed by the colour texture ... make sure they are grey scale only, leave the rest as is.

Using the second UV channel , change the coords for those vertices which are to remain untouched to 0,0 and those which will be effected by the second colour texture to .5, .5. The color texture should be pure white with a coloured square in the middle. Leave at least a 2 pixel white edge. An 8x8 texture size would be fine for this.

Simply apply the second texture using multiply blend.

You could either change the colour by overwriting the coloured rect in the middle of the second texture or just make one larger animtexture and re-texture the model each time using a different frame.

Make sense?

Stevie

I think i have understood it, but i cannot separate the parts that need to be colores using vertices... because for example a simple quad has some parts to be colored and some parts not...


EDITED: I got it working!!! in a slow mode, but it is enough. I load the texture as loadimage, and for every pixel, if pixel is not white, i assign the pixel the color i want, then copyrect to texturebuffer, then multitexture with blend.

Thanks to all!

Instead of using pixel-pro-pixel for this, maybe you could use an image and set it's masking colour to white with MaskImage:
Graphics 320, 240, 0, 2
SetBuffer BackBuffer()

;load images
im1 = iMakeImage()
im2 = iMakeImage()

Cls
Color 255, 255, 255
Text 0, 0, "original images:"
DrawBlock im1, 0, 20
DrawBlock im2, 80, 20
Flip
Delay 1000


;set black color mask
MaskImage im1, 0, 0, 0
MaskImage im2, 0, 0, 0

;draw green rectangle
Color 0, 255, 0
Rect 0, 0, 64, 64
;draw image without black
DrawImage im1, 0, 0
;grab image with new green part
GrabImage im1, 0, 0

;draw red rectangle
Color 255, 0, 0
Rect 0, 0, 64, 64
;draw image2 without black
DrawImage im2, 0, 0
;grab image with new red part
GrabImage im2, 0, 0

;set white color mask
MaskImage im1, 255, 255, 255
MaskImage im2, 255, 255, 255

Cls

;draw images
DrawImage im2, 0, 0
DrawImage im1, 0, 0

Flip

WaitKey()

End

Function iMakeImage()
	im = CreateImage(64, 64)
	SetBuffer ImageBuffer(im)
	ClsColor 255, 255, 255
	Cls
	Color 0, 0, 0
	For g = 0 To 25
		Rect Rand(64), Rand(64), Rand(5, 15), Rand(5, 15)
	Next
	SetBuffer BackBuffer()
	ClsColor 0, 0, 0
	Return im
End Function


Wow, faster, indeed. Thanks!