Page 1 of 1

Sky Gradients?

Posted: Tue Nov 02, 2021 1:29 pm
by masteries
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?

Re: Sky Gradients?

Posted: Wed Nov 03, 2021 8:40 am
by Stef
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;
        }

Re: Sky Gradients?

Posted: Thu Nov 04, 2021 12:58 pm
by masteries
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

Re: Sky Gradients?

Posted: Fri Dec 03, 2021 5:07 pm
by masteries
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?

Re: Sky Gradients?

Posted: Sun Dec 26, 2021 6:30 pm
by Joe Musashi
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().

Re: Sky Gradients?

Posted: Wed Feb 02, 2022 1:30 pm
by masteries
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