Sky Gradients?

SGDK only sub forum

Moderator: Stef

Post Reply
masteries
Very interested
Posts: 53
Joined: Thu Jul 30, 2020 3:33 pm

Sky Gradients?

Post by masteries » Tue Nov 02, 2021 1:29 pm

Greetings I was trying to figure out how to create gradient effects in MegaDrive / Genesis via switching colour 0, or background colour

I found this piece of code:

Code: Select all

void handleHBlank()
{
	asm("move.l #0xc0000000, 0xc00004.l");
	while((*((volatile u16*)GFX_CTRL_PORT) & 4) == 0);
	asm("move.w gradientTestColor2, 0xc00000.l");
	gradientTestColor2 -= 0x100;
}
But it produces side effects, such change colour 1 instead of 0; and many garbage tiles when horizontal scroll is being used.

My HInt setup is this one:

Code: Select all

	        //Configurar interrupciones
	        SYS_setHIntCallback(&hint_irq);
			VDP_setHInterrupt(1);
			VDP_setHIntCounter(1);//HInt occurs each 1+1 Hint, each 2 scanlines
Any idea about how to vreate these sort of very good looking effects?

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

Re: Sky Gradients?

Post by Stef » Wed Nov 03, 2021 8:40 am

I should have replied here as this is definitely a SGDK solution that I propose here :p

So you should declare your H-Int function like this:

Code: Select all

void hint()
{
  PAL_setColor(0, gradientColor);
  gradientColor-= 0x100;
}

Then prepare your H-Int gradient effect using this from your main code:

Code: Select all

        // each 4 lines
        VDP_setHIntCounter(4);
        // enable H-Int
        VDP_setHInterrupt(TRUE);
        // set H-Int callback method
        SYS_setHIntCallback(hint);
        
        ...
        
        while(TRUE)
        {
          ..
          SYS_doVBlankProcess();
          // init base h-int color during vblank
          gradientColor = 0xE82;
        }

masteries
Very interested
Posts: 53
Joined: Thu Jul 30, 2020 3:33 pm

Re: Sky Gradients?

Post by masteries » Thu Nov 04, 2021 12:58 pm

Stef wrote:
Wed Nov 03, 2021 8:40 am
I should have replied here as this is definitely a SGDK solution that I propose here :p

So you should declare your H-Int function like this:

Code: Select all

void hint()
{
  PAL_setColor(0, gradientColor);
  gradientColor-= 0x100;
}

Then prepare your H-Int gradient effect using this from your main code:

Code: Select all

        // each 4 lines
        VDP_setHIntCounter(4);
        // enable H-Int
        VDP_setHInterrupt(TRUE);
        // set H-Int callback method
        SYS_setHIntCallback(hint);
        
        ...
        
        while(TRUE)
        {
          ..
          SYS_doVBlankProcess();
          // init base h-int color during vblank
          gradientColor = 0xE82;
        }
Thanks for the tip code...

but result is the same; some CDOTs at screen, random tiles when horizontal scroll is in action (its a slow scroll, one or two pixels per frame), and many random modifications of colour 1 instead color 0.

Personally I think this will need to be embedded into "sega.s", and read gradientColor from a lookup table; but the initial look up table reading offset needs to be different per each map you planned in your game.

An example of this "deep" SGDK would be great, thanks in advance

masteries
Very interested
Posts: 53
Joined: Thu Jul 30, 2020 3:33 pm

Re: Sky Gradients?

Post by masteries » Fri Dec 03, 2021 5:07 pm

Stef wrote:
Wed Nov 03, 2021 8:40 am
I should have replied here as this is definitely a SGDK solution that I propose here :p

So you should declare your H-Int function like this:

Code: Select all

void hint()
{
  PAL_setColor(0, gradientColor);
  gradientColor-= 0x100;
}

Then prepare your H-Int gradient effect using this from your main code:

Code: Select all

        // each 4 lines
        VDP_setHIntCounter(4);
        // enable H-Int
        VDP_setHInterrupt(TRUE);
        // set H-Int callback method
        SYS_setHIntCallback(hint);
        
        ...
        
        while(TRUE)
        {
          ..
          SYS_doVBlankProcess();
          // init base h-int color during vblank
          gradientColor = 0xE82;
        }
Due to C DOTS are still present, as well the problems exposed previously; using this provided code...

Can you post an example performing these sort of things via modifying sega.s assembly code?

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

Re: Sky Gradients?

Post by Joe Musashi » Sun Dec 26, 2021 6:30 pm

For an SGDK example of how to change colors each scan line you can have a look here:

https://github.com/a-dietrich/SEGA-Gene ... e/main/tf2

In src/main.c look for scene4().

masteries
Very interested
Posts: 53
Joined: Thu Jul 30, 2020 3:33 pm

Re: Sky Gradients?

Post by masteries » Wed Feb 02, 2022 1:30 pm

Joe Musashi wrote:
Sun Dec 26, 2021 6:30 pm
For an SGDK example of how to change colors each scan line you can have a look here:

https://github.com/a-dietrich/SEGA-Gene ... e/main/tf2

In src/main.c look for scene4().
Thanks a lot!

The technique appears pretty advanced, and works well

Post Reply