Pixel alpha problems , paint image on terrain

Posted By: EpsiloN

Pixel alpha problems , paint image on terrain - 01/02/16 10:42

Hi all,
having some problems again.
I'm trying to paint a blood splatter on a terrain skin at some position.
My problem is that the terrain skin is .pcx (I don't think its a problem) and my blood splatter is .tga with an alpha channel.
When I try bmap_blit there is no transparency, so I thought I'd paint myself, but failed again.
Here's what I'm using (COLOR and pixels):
Code:
typedef struct APIXEL {
	COLOR pix;
	var pixa;
} APIXEL;
APIXEL bloodSplatter1_pixels[32][32];

function readBloodSplatters() {
	var i , j;
	var bmapHandle = bmap_lock(bloodSplatter1_tga , 0);
	for( j = 0; j < 32 ; j++ ) {
		for( i = 0; i < 32; i++ ) {
			pixel_to_vec( bloodSplatter1_pixels[i][j].pix , bloodSplatter1_pixels[i][j].pixa , bmapHandle , pixel_for_bmap( bloodSplatter1_tga , i , j ) );
		}
	}
	bmap_unlock(bloodSplatter1_tga);
}

function placeBloodSplatter( VECTOR* posVec ) {
	var i , j;
	BMAP* terrainSkin = bmap_for_entity(terrainEntity,0);
	var bmapHandle = bmap_lock(terrainSkin , 0);
	posVec.x -= 16;
	posVec.y -= 16;
	if( posVec.x < 0 ) { posVec.x = 0; }
	if( posVec.y < 0 ) { posVec.y = 0; }
	if( posVec.x > 2016 ) { posVec.x = 2016; }
	if( posVec.y > 2016 ) { posVec.y = 2016; }
	for( j = 0; j < 32 ; j++ ) {
		for( i = 0; i < 32; i++ ) {
			pixel_to_bmap( terrainSkin , posVec.x + i , posVec.y + j , pixel_for_vec( bloodSplatter1_pixels[i][j].pix , bloodSplatter1_pixels[i][j].pixa , 8888 ) );
		}
	}
	bmap_unlock(terrainSkin);
}


Even if I set the alpha to 10 by hand, for each pixel, the black is still black...

Anyone knows a solution?

Thanks.

EDIT:
I tried using 32bit tga for terrain skin and transparent patches appear on the terrain with the blood stain barely visible...Lol laugh
Posted By: txesmi

Re: Pixel alpha problems , paint image on terrain - 01/02/16 12:11

Hi,
you need to discard blood translucent pixels so you only set full colored ones.
Code:
for( j = 0; j < 32 ; j++ ) {
	for( i = 0; i < 32; i++ ) {
		if ( bloodSplatter1_pixels[i][j].pixa < 100 )
			continue;
		var pixel = pixel_for_vec( bloodSplatter1_pixels[i][j].pix , 100 , bmapHandle )
		pixel_to_bmap( terrainSkin , posVec.x + i , posVec.y + j , pixel );
	}
}



if you want to use translucent blood pixels, you will need to compute the resultant color before.

Salud!
Posted By: EpsiloN

Re: Pixel alpha problems , paint image on terrain - 01/02/16 13:30

Yes, but how do I compute the resultant color?
r g and b * alpha ? (didn't try, but I think its wrong...)

I tested against pixa > 5, so I got most of the blood without the blackness, but I do have some very dark spots, that should have blended with the terrain...

I guess I have to somehow take the terrain's pixel and add the blood pixel times its alpha to the terrain pixel, right? But, it might result in values above 255?
Posted By: txesmi

Re: Pixel alpha problems , paint image on terrain - 01/02/16 13:59

vec_lerp computes a factorized average between two vectors

Code:
vec_lerp ( resultant_color, terrain_color, blood_color, blood_alpha/100 );



you are right, you need to sample the terrain pixel color...
© 2024 lite-C Forums