Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: Bobboau on July 25, 2002, 12:15:33 am

Title: beam texture tileing
Post by: Bobboau on July 25, 2002, 12:15:33 am
make this you're new beam rendering function

Code: [Select]

void beam_render(beam_weapon_info *bwi, vector *start, vector *shot, float shrink)
{
int idx, s_idx;
vertex h1[4]; // halves of a beam section
vertex *verts[4] = { &h1[0], &h1[1], &h1[2], &h1[3] };
vector fvec, top1, bottom1, top2, bottom2;
float scale;
float u_scale; // beam tileing -Bobboau
float length; // beam tileing -Bobboau

// bogus weapon info index
if(bwi == NULL){
return;
}

// if the beam start and endpoints are the same
if(vm_vec_same(start, shot)){
return;
}

// get beam direction
vm_vec_sub(&fvec, shot, start);
vm_vec_normalize_quick(&fvec);

// turn off backface culling
gr_set_cull(0);

// draw all sections
for(s_idx=0; s_idxbeam_num_sections; s_idx++){
// calculate the beam points
scale = frand_range(1.0f - bwi->sections[s_idx].flicker, 1.0f + bwi->sections[s_idx].flicker);
beam_calc_facing_pts(&top1, &bottom1, &fvec, start, bwi->sections[s_idx].width * scale * shrink, bwi->sections[s_idx].z_add);
beam_calc_facing_pts(&top2, &bottom2, &fvec, shot, bwi->sections[s_idx].width * scale * scale * shrink, bwi->sections[s_idx].z_add);
R_VERTICES(); // rotate and project the vertices
P_VERTICES();
STUFF_VERTICES(); // stuff the beam with creamy goodness (texture coords)

length = vm_vec_dist(start, shot); // beam tileing -Bobboau
u_scale = length / bwi->sections[s_idx].width /2; // beam tileing, might make a tileing factor in beam index later -Bobboau
verts[1]->u = verts[1]->u * u_scale; // beam tileing -Bobboau
verts[2]->u = verts[2]->u * u_scale; // beam tileing -Bobboau

// set the right texture with additive alpha, and draw the poly
gr_set_bitmap(bwi->sections[s_idx].texture, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 0.9999f);
g3_draw_poly( 4, verts, TMAP_FLAG_TEXTURED | TMAP_FLAG_TILED | TMAP_FLAG_CORRECT); // added TMAP_FLAG_TILED flag for beam texture tileing -Bobboau
}

// turn backface culling back on
gr_set_cull(1);
}



still needs a bit of tweaking, but it's basicly there
Title: beam texture tileing
Post by: WMCoolmon on July 25, 2002, 01:24:04 am
Any screenshots of this in action? :D
Title: beam texture tileing
Post by: LAM3O on July 25, 2002, 01:40:26 am
Great job!   I didn't think there would be this much progress for a long time.

Can't wait to see shots, think it'll work with fighter beams?
Title: beam texture tileing
Post by: Bobboau on July 25, 2002, 01:45:42 am
it works on the fighter beam, actualy that's the only beam I've tested it on, but the rendering function is the same for all beams, I'll see about makeing some screens
Title: beam texture tileing
Post by: Bobboau on July 25, 2002, 01:57:49 am
also it looks like it will be relitivly easy to get that texture panning idea implemented
Title: beam texture tileing
Post by: ##UnknownPlayer## on July 25, 2002, 04:51:20 am
Wait, does this mean we can make like, beams which that look like arcing electricity easily?
Title: beam texture tileing
Post by: Hudzy on July 25, 2002, 07:13:19 am
Great if it does. :nod:
Title: beam texture tileing
Post by: Nuke on July 25, 2002, 08:09:43 pm
this should make my happy spiral beams alot cooler. any thoughts on implementing a particle effect along with beams so that you see particles flying down the length of the beam. this would also make a good special effect for missiles and prety much everything else in the game.
Title: beam texture tileing
Post by: Inquisitor on July 25, 2002, 08:22:42 pm
Sticking this so we get it added...
Title: beam texture tileing
Post by: WMCoolmon on July 25, 2002, 09:59:12 pm
Commited :nod:
Title: beam texture tileing
Post by: Inquisitor on July 26, 2002, 07:53:47 am
excellent :)
Title: beam texture tileing
Post by: Raven2001 on July 26, 2002, 08:51:52 am
Make an .exe of this, along with the fighter beams... :)
Title: beam texture tileing
Post by: Inquisitor on July 26, 2002, 09:10:02 am
Yes, probably around the 1st of August ;)
Title: beam texture tileing
Post by: Raven2001 on July 26, 2002, 09:53:44 am
Ok, now I'm happier!! :D

BTW, Inquisitor could you explain me that CVS thingy and how do I access it??
Title: beam texture tileing
Post by: Inquisitor on July 26, 2002, 10:14:54 am
Yeah:

http://www.3dap.com/hlp/hosted/fsscp/

and a preconfigured CVS batch is:
http://fs2source.warpcore.org/CVS.zip
Title: beam texture tileing
Post by: Raven2001 on July 27, 2002, 08:51:58 am
Thanks :)
Title: beam texture tileing
Post by: ##UnknownPlayer## on July 27, 2002, 09:04:30 am
Just saw the new beams in action then - reminds me a lot of the beams in Homeworld. While the jagged saw effect is pretty cool, it is possible to make the beams look like true FS beams again isn't it?
Title: beam texture tileing
Post by: Bobboau on July 27, 2002, 11:04:29 am
I have set a tileing factor, I am going to set it up so that, positive numbers are relitive (to the beam liength) and negitive are absolute (total number of times tiled acros the beam), also remember I am trying to get this set up to translate the texture down the beam
Title: beam texture tileing
Post by: Inquisitor on August 03, 2002, 01:08:57 pm
How is this going?
Title: beam texture tileing
Post by: Nico on August 03, 2002, 01:31:55 pm
also, what about screenshots? ;)
Title: beam texture tileing
Post by: WMCoolmon on August 03, 2002, 01:47:53 pm
(http://members.cox.net/~wmcoolmon/images/beam.jpg)
Title: beam texture tileing
Post by: an0n on August 03, 2002, 02:02:14 pm
Oooooooooh. Railguns!
Title: beam texture tileing
Post by: Sesquipedalian on August 03, 2002, 04:55:46 pm
Quote
Originally posted by Bobboau
I have set a tileing factor, I am going to set it up so that, positive numbers are relitive (to the beam liength) and negitive are absolute (total number of times tiled acros the beam), also remember I am trying to get this set up to translate the texture down the beam


So a beam tiling factor of +1 will draw the beams the way they were in the original, right?  Perhaps that should be the default value, and if the parser doesn't find a beam tiling factor listed in the table entry, it should use that value.
Title: beam texture tileing
Post by: Nico on August 03, 2002, 08:26:08 pm
stupid question number 132134: would it be possible to have a different map for the ends of the beams? Guess not, but anyway?
Title: beam texture tileing
Post by: Bobboau on August 03, 2002, 09:28:46 pm
oh, kina forgot about this, I got a tileing factor set up and I was working of getting it to move, I needed to make a time based offset (as oposed to moveing the offset every frame on a beam by beam basis), or it won't work on fighter beams

U_offset = (float)( (float)(timestamp()%1000) * bwi->sections->translation)/1000.0f;

this is one of the places my ineptitude in C is biteing me
I tried several diferent things, this is what it looks like now

basicly I'm trying to get a floating point value between 0.0 and 1.0 based on the current time and the translaton rate for the beam

I don't supose there is something way to modulo that works on floating point values, I got some sort of error when I tryed something like
(timestamp() * bwi->sections->translation)%1.0f
it's been about a week sense I did this so I can't recall exactly what I did (other than screwing up something in the HUD :D)
Title: beam texture tileing
Post by: Bobboau on August 03, 2002, 10:06:36 pm
the way I am setting up the tile factor 1 would be like it is now (my altered exe) bigger numbers would streach it out more, I am going to set it up so negitive numbers will be the absolute tile factor, so -1 would make it like the old rendering code -5 would tile it 5 times along the beam length, how ever far that would be

and what do you mean have a different map for the ends ??
Title: beam texture tileing
Post by: LAM3O on August 04, 2002, 12:47:51 am
wow that's great!

About the ends, say you had a lighting bolt texture, the last tile could be extra fragmented, looking like it's flailing more wildly at the end, i guess.

Who cares though, this is a great mod, it'll really change the way the game looks.
Title: beam texture tileing
Post by: Sesquipedalian on August 04, 2002, 05:36:21 am
Quote
Originally posted by Bobboau
the way I am setting up the tile factor 1 would be like it is now (my altered exe) bigger numbers would streach it out more, I am going to set it up so negitive numbers will be the absolute tile factor, so -1 would make it like the old rendering code -5 would tile it 5 times along the beam length, how ever far that would be


Oh, I see.  I took "absolute" to refer to the tile width being absolute, as in the beam would be drawn by repeating the tiles however many times were necessary to reach the target.  You meant that the number of tiles was absolute.  Gotcha.

Btw, you might want to make that explicit in your documentation, just to avoid all possibility for confusion. :)
Title: beam texture tileing
Post by: Nico on August 04, 2002, 06:01:48 am
yeah, what lam3o says, about. for exemple to have a  beam with "round" ends for exemples, stuff like that.
Title: beam texture tileing
Post by: Kazan on August 04, 2002, 02:50:02 pm
[not claiming to have read thread, so if this has already been stated, slap me]
you need to make tiled beam textures a weapon flag - so the origional beams maintain their appearance, and only beams that we wwant tiled tile
and does the texture traverse the beam? ie if you made it have "pulse bulges" would they travel down the beam
Title: beam texture tileing
Post by: Bobboau on August 04, 2002, 02:54:58 pm
working on it, if you read the thread, you'' see I am going to make this an optional tag in the beam section stuff,
Title: beam texture tileing
Post by: Nico on August 05, 2002, 03:46:04 am
Quote
Originally posted by Kazan
slap me


here you go:
"slaps kazan".
Anyway, I'm looking forward to that "animated" beam bob, could improve many beam ideas :)
Title: beam texture tileing
Post by: Fry_Day on August 05, 2002, 12:52:28 pm
Just a small note to Bobbau, look at the math.h functions, and there is a floating-point mod function, but it's slow, so try avoiding it.
Title: beam texture tileing
Post by: Nuke on August 05, 2002, 09:55:49 pm
i dont think compatibility with older beams is an issue, most of the original beam textures are very low resolution, and you cant tell one colom of pixels from another.
Title: beam texture tileing
Post by: WMCoolmon on August 05, 2002, 11:41:48 pm
But there is a very obvious difference between the original beams and the new beams, as is shown in the screenshot. Slash beams probably won't look right, anyway...
Title: beam texture tileing
Post by: Raven2001 on August 06, 2002, 04:44:19 pm
I like the way old beams looks :) I just wish they could be "animated" (really noticing them "flowing", if you know what I mean...)
Title: beam texture tileing
Post by: Bobboau on August 07, 2002, 02:14:56 am
*Bobboau pulls head out of his ass*
I'm such an idiot, I was only adding the U offset to the far verts, no wonder it wasn't working

ok let's try this
Code: [Select]

float U_offset =0; // beam translation thing -Bobboau
void beam_render(beam_weapon_info *bwi, vector *start, vector *shot, float shrink)
{
int idx, s_idx;
vertex h1[4]; // halves of a beam section
vertex *verts[4] = { &h1[0], &h1[1], &h1[2], &h1[3] };
vector fvec, top1, bottom1, top2, bottom2;
float scale;
float u_scale; // beam tileing -Bobboau
float length; // beam tileing -Bobboau
// bogus weapon info index
if(bwi == NULL){
return;
}

// if the beam start and endpoints are the same
if(vm_vec_same(start, shot)){
return;
}

// get beam direction
vm_vec_sub(&fvec, shot, start);
vm_vec_normalize_quick(&fvec);

// turn off backface culling
gr_set_cull(0);

// draw all sections
for(s_idx=0; s_idxbeam_num_sections; s_idx++){
// calculate the beam points
scale = frand_range(1.0f - bwi->sections[s_idx].flicker, 1.0f + bwi->sections[s_idx].flicker);
beam_calc_facing_pts(&top1, &bottom1, &fvec, start, bwi->sections[s_idx].width * scale * shrink, bwi->sections[s_idx].z_add);
beam_calc_facing_pts(&top2, &bottom2, &fvec, shot, bwi->sections[s_idx].width * scale * scale * shrink, bwi->sections[s_idx].z_add);
R_VERTICES(); // rotate and project the vertices
P_VERTICES();
STUFF_VERTICES(); // stuff the beam with creamy goodness (texture coords)

length = vm_vec_dist(start, shot); // beam tileing -Bobboau
u_scale = length / (bwi->sections[s_idx].width /2) / bwi->sections[s_idx].tile_factor; // beam tileing, might make a tileing factor in beam index later -Bobboau

U_offset = U_offset + flFrametime; //beam texture translation -Bobboau
if (U_offset > 1.0f){
U_offset -= 1.0f;
}

verts[1]->u = (verts[1]->u * u_scale) + (U_offset * bwi->sections[s_idx].translation); // beam tileing/translation -Bobboau
verts[2]->u = (verts[2]->u * u_scale) + (U_offset * bwi->sections[s_idx].translation); // beam tileing/translation -Bobboau
verts[3]->u = verts[3]->u + (U_offset * bwi->sections[s_idx].translation); //beam translation
verts[4]->u = verts[4]->u + (U_offset * bwi->sections[s_idx].translation); //beam translation

// set the right texture with additive alpha, and draw the poly
gr_set_bitmap(bwi->sections[s_idx].texture, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 0.9999f);
g3_draw_poly( 4, verts, TMAP_FLAG_TEXTURED | TMAP_FLAG_TILED | TMAP_FLAG_CORRECT); // added TMAP_FLAG_TILED flag for beam texture tileing -Bobboau
}

// turn backface culling back on
gr_set_cull(1);
}


Code: [Select]

if( optional_string("+Tile Factor:")){ //beam texture tileing factor -Bobboau
stuff_float(&i.tile_factor);
}else{
i.tile_factor = 1.0f;
}

if( optional_string("+Translation:")){ //beam texture moveing stuff -Bobboau
stuff_float(&i.tile_factor);
}else{
i.translation = 0.0f;
}

in end of the beam sections loading code, in weapons .cpp

and of corse
add this
Code: [Select]

float tile_factor; // texture tile factor -Bobboau
float translation; // makes the beam texture move -Bobboau

to the beam_weapon_section_info struct
Title: beam texture tileing
Post by: Bobboau on August 07, 2002, 03:46:01 am
that doesn't seem to work, I realy should test stuff before I post it, and not code when I'm so tired I can barly see
Title: beam texture tileing
Post by: Bobboau on August 24, 2002, 12:34:38 am
can someone tell me why this causes a crash
Code: [Select]

U_offset = 0.0f;

verts[1]->u = ((verts[1]->u * u_scale) + U_offset); // beam tileing -Bobboau
verts[2]->u = ((verts[2]->u * u_scale) + U_offset); // beam tileing -Bobboau
verts[3]->u = (verts[3]->u + U_offset);
verts[3]->u = (verts[4]->u + U_offset);
Title: beam texture tileing
Post by: penguin on August 24, 2002, 05:02:44 am
Quote
Originally posted by Bobboau
can someone tell me why this causes a crash
 

Unless you changed it, verts is declared:
Code: [Select]

vertex *verts[4]

so the subscripts should be 0-3

You're accessing verts[4], and then trying to dereference == crasharoo
Title: beam texture tileing
Post by: Bobboau on August 24, 2002, 05:31:52 am
:eek2: I can't beleve I didn't see that
Title: beam texture tileing
Post by: Kazan on August 24, 2002, 08:09:35 am
yeah it should be 0,1,2,3
Title: beam texture tileing
Post by: Bobboau on August 28, 2002, 11:41:44 pm
ok I'm almost done with this, I just need to know why this(changes in bold) screws up the displaying of weapons in the HUD

from the bottom end of parse_weapon, in weapons.cpp
Code: [Select]

while( optional_string("$Section:") ){
beam_weapon_section_info i;
char tex_name[255] = "";

// section width
required_string("+Width:");
stuff_float(&i.width);

// texture
required_string("+Texture:");
stuff_string(tex_name, F_NAME, NULL);
i.texture = -1;
if(!Fred_running){
i.texture = bm_load(tex_name);
if(i.texture >= 0){
bm_lock(i.texture, 16, BMP_TEX_OTHER);
bm_unlock(i.texture);
}
}

// rgba inner
required_string("+RGBA Inner:");
stuff_byte(&i.rgba_inner[0]);
stuff_byte(&i.rgba_inner[1]);
stuff_byte(&i.rgba_inner[2]);
stuff_byte(&i.rgba_inner[3]);

// rgba outer
required_string("+RGBA Outer:");
stuff_byte(&i.rgba_outer[0]);
stuff_byte(&i.rgba_outer[1]);
stuff_byte(&i.rgba_outer[2]);
stuff_byte(&i.rgba_outer[3]);

// flicker
required_string("+Flicker:");
stuff_float(&i.flicker);

// zadd
required_string("+Zadd:");
stuff_float(&i.z_add);

[b]i.tile_factor = -1.0f;
if( optional_string("+Tile Factor:")){ //beam texture tileing factor -Bobboau
stuff_float(&(i.tile_factor));
}


i.translation = 0.0f;
if( optional_string("+Translation:")){ //beam texture moveing stuff -Bobboau
stuff_float(&(i.translation));
}[/b]

// maybe copy it
if(wip->b_info.beam_num_sections < MAX_BEAM_SECTIONS - 1){
wip->b_info.sections[wip->b_info.beam_num_sections++] = i;
}
}

yes I made changes to the beam section structure
Title: beam texture tileing
Post by: Bobboau on August 29, 2002, 12:42:32 am
what the hell, here's the new rendering function
Code: [Select]

float U_offset =0.0f; // beam texture offset -Bobboau
void beam_render(beam_weapon_info *bwi, vector *start, vector *shot, float shrink)
{
int idx, s_idx;
vertex h1[4]; // halves of a beam section
vertex *verts[4] = { &h1[0], &h1[1], &h1[2], &h1[3] };
vector fvec, top1, bottom1, top2, bottom2;
float scale;
float u_scale; // beam tileing -Bobboau
float length; // beam tileing -Bobboau

// bogus weapon info index
if(bwi == NULL){
return;
}

// if the beam start and endpoints are the same
if(vm_vec_same(start, shot)){
return;
}

// get beam direction
vm_vec_sub(&fvec, shot, start);
vm_vec_normalize_quick(&fvec);

// turn off backface culling
gr_set_cull(0);

// draw all sections
for(s_idx=0; s_idxbeam_num_sections; s_idx++){
// calculate the beam points
scale = frand_range(1.0f - bwi->sections[s_idx].flicker, 1.0f + bwi->sections[s_idx].flicker);
beam_calc_facing_pts(&top1, &bottom1, &fvec, start, bwi->sections[s_idx].width * scale * shrink, bwi->sections[s_idx].z_add);
beam_calc_facing_pts(&top2, &bottom2, &fvec, shot, bwi->sections[s_idx].width * scale * scale * shrink, bwi->sections[s_idx].z_add);
R_VERTICES(); // rotate and project the vertices
P_VERTICES();
STUFF_VERTICES(); // stuff the beam with creamy goodness (texture coords)

//U_offset = ( ( ((float)timestamp() * bwi->sections[s_idx].translation)/1000.0f) - (float)(timestamp() * (int)bwi->sections[s_idx].translation /1000));

length = vm_vec_dist(start, shot); // beam tileing -Bobboau

if (bwi->sections[s_idx].tile_factor){
u_scale = length / (bwi->sections[s_idx].width /2) / bwi->sections[s_idx].tile_factor; // beam tileing, might make a tileing factor in beam index later -Bobboau
}else{
u_scale = bwi->sections[s_idx].tile_factor * -1;
}


verts[1]->u = (u_scale + (U_offset * bwi->sections[s_idx].translation)); // beam tileing -Bobboau
verts[2]->u = (u_scale + (U_offset * bwi->sections[s_idx].translation)); // beam tileing -Bobboau
verts[3]->u = (0 + (U_offset * bwi->sections[s_idx].translation));
verts[0]->u = (0 + (U_offset * bwi->sections[s_idx].translation));

// set the right texture with additive alpha, and draw the poly
gr_set_bitmap(bwi->sections[s_idx].texture, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 0.9999f);
g3_draw_poly( 4, verts, TMAP_FLAG_TEXTURED | TMAP_FLAG_TILED | TMAP_FLAG_CORRECT); // added TMAP_FLAG_TILED flag for beam texture tileing -Bobboau
}

// turn backface culling back on
gr_set_cull(1);
}


and jam this line

Code: [Select]
U_offset = ( (float)(timestamp()/1000) - ( ((float)timestamp())/1000.0f)); //beam texture offset, so it looks like it is moveing, -Bobboau

into beam_render_all

change made in weapons.h
Code: [Select]

#define MAX_BEAM_SECTIONS 10
typedef struct beam_weapon_section_info {
float width; // width of the section
int texture; // texture bitmap
ubyte rgba_inner[4]; // for non-textured beams
ubyte rgba_outer[4]; // for non-textured beams
float flicker; // how much it flickers (0.0 to 1.0)
float z_add; // is this necessary?
float tile_factor; // texture tile factor -Bobboau
float translation; // makes the beam texture move -Bobboau
} beam_weapon_section_info;
Title: beam texture tileing
Post by: Bobboau on August 31, 2002, 06:25:07 pm
will someone tell me why my parseing code isn't working, please
Title: beam texture tileing
Post by: Anaz on August 31, 2002, 07:17:08 pm
make sure that your loading the tileing properly...
Title: beam texture tileing
Post by: penguin on August 31, 2002, 07:19:29 pm
Quote
Originally posted by Bobboau
will someone tell me why my parseing code isn't working, please
I haven't played w/ the parsing code enough to provide a useful answer, sorry :(