Raster Effect with Gendev ( SGDK)

SGDK only sub forum

Moderator: Stef

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Tue Oct 11, 2011 9:13 am

sega16 wrote:Using this code it will double SOME lines but not all.I believe the reason for this is because the code is not fast enough but what could I do to make it better?
If you have H Int at each scanline your code should fit in a very small amount of cycles : we have about 488 68k cycles by scanline but the SGDK H int handler already eat a part of it (about 120 cycles) so it leave 350 cycles for your code.

You don't have to check for end of screen as H Int doesn't happen during VBlank so you can do frame initialization process in the V Int callback instead.

your H Int code can be :

Code: Select all

    *((u16 *) GFX_DATA_PORT) = vscroll;
    if (the_scroll ^= 1) vscroll--;
Then your V Int code should end by :

Code: Select all

    ...
    // re init VScroll
    vscroll=0x800; 
    // prepare H Int V Scroll writes
    *((u32 *) GFX_CTRL_PORT) = GFX_WRITE_VSRAM_ADDR(0);

alko
Very interested
Posts: 172
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Re: Raster Effect with Gendev ( SGDK)

Post by alko » Thu Jan 14, 2016 8:15 pm

Shalom.

Please show me the complete source code of this effect (vertical scaling).
Image

alko
Very interested
Posts: 172
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Re: Raster Effect with Gendev ( SGDK)

Post by alko » Sat Jan 16, 2016 1:53 pm

8) I really need this effect 8)
Image

alko
Very interested
Posts: 172
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Re: Raster Effect with Gendev ( SGDK)

Post by alko » Wed Feb 10, 2016 6:39 pm

up...
Image

alko
Very interested
Posts: 172
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Re: Raster Effect with Gendev ( SGDK)

Post by alko » Wed Mar 30, 2016 12:48 pm

alko wrote:Shalom.

Please show me the complete source code of this effect (vertical scaling).
:oops: It is even possible to implement by means of SGDK?
Image

ehaliewicz
Very interested
Posts: 50
Joined: Tue Dec 24, 2013 1:00 am

Re: Raster Effect with Gendev ( SGDK)

Post by ehaliewicz » Wed Mar 30, 2016 8:25 pm

alko wrote:
alko wrote:Shalom.

Please show me the complete source code of this effect (vertical scaling).
:oops: It is even possible to implement by means of SGDK?
What are you trying to do? Scaling sprites vertically?

Edit: nevermind, read the first page of the thread

alko
Very interested
Posts: 172
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Re: Raster Effect with Gendev ( SGDK)

Post by alko » Wed Mar 30, 2016 9:02 pm

Image

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Raster Effect with Gendev ( SGDK)

Post by Stef » Sat Apr 02, 2016 5:18 pm

Just use the h interrupt callback for that :)

Use :

Code: Select all

// Set H-Int callback
SYS_setHIntCallback(&hint_cb);
// enable H-Interrupt
VDP_setHInterrupt(1);
// set H-int line count occorence
VDP_setHIntCounter(1)
to define the hint callback method and enable H-Int for each scanline.
Then in the H-int callback you need to modify the Vertical scroll value using:

Code: Select all

void hint_cb()
{
  // modify vertical scroll
  VDP_setVerticalScroll(BPLAN, scrollValue);
}
of course you have to set a specific 'scrollValue' at each scanline to give scaling effect.

alko
Very interested
Posts: 172
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Re: Raster Effect with Gendev ( SGDK)

Post by alko » Mon Apr 04, 2016 5:45 pm

background is flattened, but an image is unstable.

Image

Code: Select all

....
static u32 vscrol;
void hint_cb()
{
   VDP_setVerticalScroll(PLAN_B, vscrol);
   vscrol += 8;
}

main()
{
...
while(TRUE)
{
...
SYS_setHIntCallback(&hint_cb);
VDP_setHInterrupt(1);
VDP_setHIntCounter(1);
VDP_waitVSync();   
}

}

Image

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Raster Effect with Gendev ( SGDK)

Post by Stef » Tue Apr 05, 2016 3:24 pm

Are you resetting 'vscrol' at V-Int ? looks like you aren't..

alko
Very interested
Posts: 172
Joined: Thu Aug 07, 2014 9:31 am
Location: Russian Federation

Re: Raster Effect with Gendev ( SGDK)

Post by alko » Tue Apr 05, 2016 5:52 pm

Stef wrote:Are you resetting 'vscrol' at V-Int ? looks like you aren't..
Oh, thanx! :roll:

Yet I keep getting flattened image.
How do stretch the picture?
Image

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Raster Effect with Gendev ( SGDK)

Post by Stef » Tue Apr 05, 2016 8:39 pm

Decrease 'vscrol' instead of increasing it =)
Using fix16 value will allow you to have smooth vertical scaling.

danibus
Very interested
Posts: 135
Joined: Sat Feb 03, 2018 12:41 pm

Re: Raster Effect with Gendev ( SGDK)

Post by danibus » Tue Feb 02, 2021 1:13 pm

Would you be so kind to provide an example? I'm trying to strech and scroll a plane (not sprites)
I want to use a plane to show a path, like sonic 3d bonus path or similar.
This is SGDK old version.

Trying with no success :(

This is my code, something is missed I think, nothing happens (?)

Code: Select all

#include <genesis.h>

static u32 vscrol;
            
            void hint_cb()
            {
               VDP_setVerticalScroll(PLAN_B, vscrol);
               vscrol += 8;
            }

int main(){

    s16 id_tile_inicial = 0;
    s16 id_tile_final_planB = 0;
    s16 id_tile_final_planA = 0;

    //PLANO B
    VDP_drawImageEx(PLAN_B, &fondo_fase3B, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, id_tile_inicial), 0, 0, FALSE, TRUE);
    id_tile_final_planB = id_tile_inicial + fondo_fase3B.tileset->numTile;
    //PLANO A
    VDP_drawImageEx(PLAN_A, &fondo_fase3A, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, id_tile_final_planB), 0, 0, FALSE, TRUE);
    id_tile_final_planA = id_tile_final_planB + fondo_fase3A.tileset->numTile;

	while (1) {

        VDP_setScreenWidth320();
        SPR_init();

        SYS_setHIntCallback(&hint_cb);
        VDP_setHInterrupt(1);
        VDP_setHIntCounter(1);

        SPR_update();
        VDP_waitVSync();
	}

	return 0;
}


Joe Musashi
Interested
Posts: 17
Joined: Sat Oct 13, 2018 10:08 pm

Re: Raster Effect with Gendev ( SGDK)

Post by Joe Musashi » Tue Feb 02, 2021 9:16 pm

Here's a quick example how this can be done with SGDK 1.60.

scaling.png
scaling.png (16.45 KiB) Viewed 7846 times

In this example HInt and VInt look like this:

Code: Select all

    static u8    lineDisplay  = 0;          // line position on display screen
    static fix16 lineGraphics = 0;          // line position in graphics texture
    static fix16 scroll       = 0;          // scrolling offset
    static fix16 scale        = FIX16(4.0); // scaling factor

    void HIntHandler()
    {
        // Set line to display
        VDP_setVerticalScroll(BG_B, fix16ToInt(lineGraphics) - lineDisplay);

        // Determine next graphics line to display (+1 means image is unscaled)
        lineGraphics += scale;

        // Count raster lines
        lineDisplay++;

        // Decrease scaling factor each line
        scale -= FIX16(0.02);
    }
    void VIntHandler()
    {
        // Make sure HInt always starts with line 0
        lineDisplay = 0;

        // Reset first line we want to display
	lineGraphics = scroll;

        // Decrease scrolling offset, reset after 64 lines
	scroll = (scroll - FIX16(1)) % FIX16(64);

        // Reset scaling factor
	scale = FIX16(4.0);
 }
There are a couple of things that are important:
  • We need to count the scanlines HInt is in. This is done with lineDisplay, which counts from 0 to 223, and is reset in VInt.
  • lineGraphics specifies in each scanline which graphics line we want to display. If the image is not scaled, this is the same as lineDisplay. If the image size is doubled this would be lineDisplay / 2. If we want a perspective effect the scaling factor needs to be modified each line (scale variable).
  • VDP_setVerticalScroll() requires a relative value, so we have to supply lineGraphics - lineDisplay to show a specific line.
  • The scaling factor needs to be FIX16 so we can have values < 1 (scale = 0.5 doubles the image size).
  • To achieve scrolling, the start value of lineGraphics must be altered each frame. Here we just count down 63, ... 0.
Attachments
scaling.zip
(38.62 KiB) Downloaded 221 times

danibus
Very interested
Posts: 135
Joined: Sat Feb 03, 2018 12:41 pm

Re: Raster Effect with Gendev ( SGDK)

Post by danibus » Tue Feb 02, 2021 10:43 pm

WoW! Nice explanation, many thanks.
Tomorrow morning I will try, still see these tricks like magic.

Post Reply