6 registered members (AndrewAMD, Ayumi, degenerate_762, 7th_zorro, VoroneTZ, HoopyDerFrood),
1,268
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Pixel alpha problems , paint image on terrain
#457174
01/02/16 10:42
01/02/16 10:42
|
Joined: Jan 2006
Posts: 968
EpsiloN
OP
User
|
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):
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
Last edited by EpsiloN; 01/02/16 11:02.
|
|
|
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
Serious User
|
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.
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: EpsiloN]
#457180
01/02/16 13:59
01/02/16 13:59
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
vec_lerp computes a factorized average between two vectors
vec_lerp ( resultant_color, terrain_color, blood_color, blood_alpha/100 );
you are right, you need to sample the terrain pixel color...
|
|
|
|