Better method for scrolling textures?

Graphic based area of development (Graphics Processing Unit), including the Geometry Transform Engine (GTE), TIM, STR (MDEC), etc.
Post Reply
User avatar
ArthCarvalho
Curious PSXDEV User
Curious PSXDEV User
Posts: 21
Joined: January 29th, 2016, 2:45 am
I am a: Artist, Programmer
PlayStation Model: SCPH-103

Better method for scrolling textures?

Post by ArthCarvalho » November 6th, 2019, 9:00 pm

I'm trying to create a code to animate scrolling textures.
One of the ways I came up with was to using the MoveImage() function.
But it has one problem: You can't properly scroll 4bit textures or 8bit textures properly in the X axis (works fine for the Y axis though).
Plus I have no idea of how it impacts performance.

This is the code I'm currently using:

Code: Select all

// Texture Scroller
RECT txa_copy[4];
short txa_src_x, txa_src_y;
short txa_dst_x, txa_dst_y;
unsigned char txa_w, txa_h;
unsigned char txa_ofs_x, txa_ofs_y;
char txa_spd_x;
char txa_spd_y;

void TexAnim_Setup(short sx, short sy, short dx, short dy, unsigned char w, unsigned char h, char spdx, char spdy) {
  txa_src_x = sx;
  txa_src_y = sy;
  txa_dst_x = dx;
  txa_dst_y = dy;
  txa_w = w;
  txa_h = h;
  txa_ofs_x = 0;
  txa_ofs_y = 0;
  txa_spd_x = spdx;
  txa_spd_y = spdy;
}

void TexAnim_Update() {
  
  txa_copy[0].x = txa_src_x;
  txa_copy[0].y = txa_src_y;
  txa_copy[0].w = txa_w - txa_ofs_x;
  txa_copy[0].h = txa_h - txa_ofs_y;
  
  txa_copy[1].x = txa_src_x + (txa_w - txa_ofs_x) % txa_w;
  txa_copy[1].y = txa_src_y + (txa_h - txa_ofs_y) % txa_w;
  txa_copy[1].w = txa_ofs_x;
  txa_copy[1].h = txa_ofs_y;
  
  txa_copy[2].x = txa_copy[0].x;
  txa_copy[2].w = txa_copy[0].w;
  
  txa_copy[2].y = txa_copy[1].y;
  txa_copy[2].h = txa_copy[1].h;
  
  txa_copy[3].x = txa_copy[0].x;
  txa_copy[3].w = txa_copy[0].w;
  
  txa_copy[3].y = txa_copy[0].y;
  txa_copy[3].h = txa_copy[0].h;
  
  MoveImage(&txa_copy[0], txa_dst_x+txa_ofs_x, txa_dst_y+txa_ofs_y);
  MoveImage(&txa_copy[1], txa_dst_x, txa_dst_y);
  MoveImage(&txa_copy[2], txa_dst_x, txa_dst_y);
  MoveImage(&txa_copy[3], txa_dst_x, txa_dst_y+txa_ofs_y);
  
  txa_ofs_x = (txa_ofs_x + txa_spd_x)%txa_w;
  txa_ofs_y = (txa_ofs_y + txa_spd_y)%txa_h;
}
The code is messy, mainly because I'm still figuring out how to do this.

I've heard that I could change the Draw Environment and render polygons to some texture page in order to achieve this, but I'm not sure exactly how to do it, or even, if it has better performance than this.

User avatar
LameGuy64
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 380
Joined: April 10th, 2013, 3:47 pm
I am a: Hobbyist Game Developer
Motto: Commercial or not, play it!
PlayStation Model: H2000/7000
Location: Philippines
Contact:

Re: Better method for scrolling textures?

Post by LameGuy64 » November 8th, 2019, 11:51 am

You have to do texture scrolling by manipulating the UV coordinates of the sprite or textured polygon primitive. You will also need to use the DR_TWIN and SetTexWindow to place texture window primitives so you can set the texture window constraint to allow for textures smaller than 256x256 to be wrapped. Using MoveImage() to scroll textures is horribly inefficient and likely problematic.

I have an example that demonstrates scrolling textures and texture windows in the self-hosted SVN repo of PSn00bSDK inmy website, as well as direct render to texture using draw attribute primitives to change the drawing target on the fly.
Please don't forget to include my name if you share my work around. Credit where it is due.

Dev. Console: SCPH-7000 with SCPH-7501 ROM, MM3, PAL color fix, Direct AV ports, DB-9 port for Serial I/O, and a Xplorer FX with Caetla 0.35.

DTL-H2000 PC: Dell Optiplex GX110, Windows 98SE & Windows XP, Pentium III 933MHz, 384MB SDRAM, ATI Radeon 7000 VE 64MB, Soundblaster Audigy, 40GB Seagate HDD, Hitachi Lite-on CD-RW Drive, ZIP 250 and 3.5" Floppy.

User avatar
ArthCarvalho
Curious PSXDEV User
Curious PSXDEV User
Posts: 21
Joined: January 29th, 2016, 2:45 am
I am a: Artist, Programmer
PlayStation Model: SCPH-103

Re: Better method for scrolling textures?

Post by ArthCarvalho » November 9th, 2019, 9:34 am

Is using a Texture Window a good option? I don't think I've seen any comercial games using Texture Windows to scroll, so I thought it was no good.

Which one of the examples in your SDK has those functions?

User avatar
LameGuy64
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 380
Joined: April 10th, 2013, 3:47 pm
I am a: Hobbyist Game Developer
Motto: Commercial or not, play it!
PlayStation Model: H2000/7000
Location: Philippines
Contact:

Re: Better method for scrolling textures?

Post by LameGuy64 » November 12th, 2019, 11:44 am

Its not included in the github repository yet, but it is on my self hosted SVN. Its in the render2tex example.
Please don't forget to include my name if you share my work around. Credit where it is due.

Dev. Console: SCPH-7000 with SCPH-7501 ROM, MM3, PAL color fix, Direct AV ports, DB-9 port for Serial I/O, and a Xplorer FX with Caetla 0.35.

DTL-H2000 PC: Dell Optiplex GX110, Windows 98SE & Windows XP, Pentium III 933MHz, 384MB SDRAM, ATI Radeon 7000 VE 64MB, Soundblaster Audigy, 40GB Seagate HDD, Hitachi Lite-on CD-RW Drive, ZIP 250 and 3.5" Floppy.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests