Pages: [1]
  Print  
Author Topic: tcMod atlas  (Read 13758 times)
fromhell
Administrator
GET A LIFE!
**********

Cakes 35
Posts: 14520



WWW
« on: March 21, 2012, 06:58:51 PM »

I've been trying to port Darkplaces' tcMod page which is like animmap but just animates from uv coordinates across the texture with rows, columns, and speed

my variation would have a 4th value in which it'd be the start frame, for specifying individual pictures in a page (like numbers)

This command would help save on texture switching and improve performance for non-tiled effects, such as fire, explosion, ripples, marks...


So far this is my shade_calc function which doesn't really work:

Code:

/*
** RB_CalcAtlasTexCoords      - a bit ported from darkplaces
atw/artw = width
ath/arth = height
atsp/artsp = speed
atst/artst = startframe
*/
void RB_CalcAtlasTexCoords( const float artw, const float arth, const float artsp, const float artst, float *st )
{
int i, w, h, idx;
double f;
w = (int) artw;
h = (int) arth;
f = *st / (artsp * w * h);
f = f - floor(f);
idx = (int) floor(f * w * h);


for ( i = 0; i < tess.numVertexes; i++, st += 2 )
{
st[0] = (idx % w) / artw;
st[1] = (idx / w) / arth;
}
}


Logged

asking when OA3 will be done won't get OA3 done.
Progress of OA3 currently occurs behind closed doors alone

I do not provide technical support either.

new code development on github
Hitchhiker
Member


Cakes 11
Posts: 181


« Reply #1 on: March 22, 2012, 01:33:45 PM »


maybe the line:
   f = *st / (artsp * w * h);
gives bad results. that (I think - not sure) should maybe be:
   f = &st / (artsp * w * h);
?

If you can provide the function with sizes of the texture and frame in pixels, this might work:

/*
** RB_CalcAtlasTexCoords      - a bit ported from darkplaces
assuming:
frame -> frame to find in atlas
w -> width of the atlas in pixels
h -> height of the atlas in pixels
framew -> single frame width in pixels
frameh -> single frame height in pixels
*/
void RB_CalcAtlasTexCoords( const int frame, const int w, const int h, const int framew, const int frameh, float *st )
{

int x,y;
int cols, rows;
float tx,ty;

cols=w/framew;
rows=h/frameh;

x=frame%cols;
y=(frame-x)/rows;

tx=x/cols;
ty=y/rows;

   for ( i = 0; i < tess.numVertexes; i++ )
   {
      st[i*2] = tx;
      st[i*2+1] = ty;
   }
}

but this will calculate only the top left corner coordinate of the atlas frame requested... I'm not sure why the loop it there Undecided

hope this helps..
Logged
fromhell
Administrator
GET A LIFE!
**********

Cakes 35
Posts: 14520



WWW
« Reply #2 on: March 22, 2012, 02:02:45 PM »

you shouldn't need pixel sizes for a shader

you just need to section it off by a number of rows and cols
Logged

asking when OA3 will be done won't get OA3 done.
Progress of OA3 currently occurs behind closed doors alone

I do not provide technical support either.

new code development on github
Hitchhiker
Member


Cakes 11
Posts: 181


« Reply #3 on: March 22, 2012, 02:58:48 PM »

ah .. ok.. i get it ( I think Smiley )
then you would need to specify the max number of rows and cols in the shader and pass them to the function.
the function would be even simpler and look something like:
void RB_CalcAtlasTexCoords( const int frame, const int cols, const int rows, float *st )
{

int x,y;
float tx,ty;

x=frame%cols;
....

but how could the frame number be generated (get the frame from time maybe)? I imagine the shader would need to specify the max number of frames in the atlas as well.. as well as speed at which they  change..
maybe i'm way off here.. if so, sorry about that. Smiley
Logged
fromhell
Administrator
GET A LIFE!
**********

Cakes 35
Posts: 14520



WWW
« Reply #4 on: March 22, 2012, 07:13:30 PM »

but how could the frame number be generated (get the frame from time maybe)?

Yep, shadertime would determine the frame. It would start off as 0 (first frame), then incremented by the speed. Some localentity shaders like explosions have their own local shadertime


My idea would also be able to specify a starting frame, for the application of picking single images from an atlas for a shader, without any speed value (0 = halted)

it's a shame atlasing wasn't done for id tech 3 in the first place. It should have been. RTCW could have ran much faster, I even wanted to do a Free content project years ago with minimal image use in mind, but hit a roadblock due to rtcw's new model formats having no support at all. All that was done for it was minimal shader scripts from scratch trying out the approach, some muzzleflashes, and a bunch of low quality sound replacements
Logged

asking when OA3 will be done won't get OA3 done.
Progress of OA3 currently occurs behind closed doors alone

I do not provide technical support either.

new code development on github
fromhell
Administrator
GET A LIFE!
**********

Cakes 35
Posts: 14520



WWW
« Reply #5 on: May 19, 2016, 05:00:20 AM »

Bump.  This is now FINALLY! integrated into the engine, with some of my concepts and no darkplaces code Smiley Grin
Logged

asking when OA3 will be done won't get OA3 done.
Progress of OA3 currently occurs behind closed doors alone

I do not provide technical support either.

new code development on github
Pages: [1]
  Print  
 
Jump to: