Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (vicknick, howardR, sleakz), 691 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Pixel alpha problems , paint image on terrain #457174
01/02/16 10:42
01/02/16 10:42
Joined: Jan 2006
Posts: 968
EpsiloN Offline OP
User
EpsiloN  Offline OP
User

Joined: Jan 2006
Posts: 968
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

Last edited by EpsiloN; 01/02/16 11:02.

Extensive Multiplayer tutorial:
http://mesetts.com/index.php?page=201
Re: Pixel alpha problems , paint image on terrain [Re: EpsiloN] #457178
01/02/16 12:11
01/02/16 12:11
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
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!

Re: Pixel alpha problems , paint image on terrain [Re: txesmi] #457179
01/02/16 13:30
01/02/16 13:30
Joined: Jan 2006
Posts: 968
EpsiloN Offline OP
User
EpsiloN  Offline OP
User

Joined: Jan 2006
Posts: 968
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?


Extensive Multiplayer tutorial:
http://mesetts.com/index.php?page=201
Re: Pixel alpha problems , paint image on terrain [Re: EpsiloN] #457180
01/02/16 13:59
01/02/16 13:59
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
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...


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1