Possible to change Palette Number on Tiles/Sprites ??

For anything related to VDP (plane, color, sprite, tiles)

Moderators: BigEvilCorporation, Mask of Destiny

Post Reply
NightShadow
Interested
Posts: 19
Joined: Sun Oct 14, 2012 10:20 pm

Possible to change Palette Number on Tiles/Sprites ??

Post by NightShadow » Thu Oct 18, 2012 5:19 pm

Hi

I would like to know if it's possible to change the palette number of a background tiles or a sprite ?

I tried to find an answer about that but didn't find anything.

The idea is not having to redraw the data part on the tiles to save a Lot of cpu time for some effects... I don't want to change a color in a palette. I already know that's possible but that's useless for what I need.

The problem is that I don't know exactly how the VDP works... I know the C64 and Amiga but not the Genesis... In fact it's the only graphic chip I know that operate with like this with 4 palettes and you have to choose which one when blitting.

Then, I would like to know if we can assign another palette # for the background tiles and sprites without having to call the command to recopy everything..

I think the way the memory is looking to be done it should be possible with a single operation but I also think I probably wrong because if it would be possible I don't know why we would never see it before... It's like if we could assign a data part of a tile and a palette # part, for each memory block of the vdp..

That's crazy how I could do such effects if I could use this. Like neverseen effect on the genesis !!

That would be appreciated if someone could explain me if I can or why I cannot.

Sorry for my not so good english
Thanks
NightShadow

GManiac
Very interested
Posts: 92
Joined: Thu Jan 29, 2009 2:05 am
Location: Russia

Post by GManiac » Thu Oct 18, 2012 6:21 pm

No, you cannot link bunch of tiles to other palette within one command. Each tile of plane (A, B, ...) you see on the screen is represented by part of plane tilemap (2-byte value for usual planes, 8 bytes for Sprites) and actually tile image 8*8, 32 bytes. You can also call images CHARS. And for word "tile" I will mean area on screen, not char.
Both chars and tilemaps are located in VRAM. One char can be used in any plane(s) in any tile(s).
Every plane has its tilemap located in VRAM. Writing to VDP registers you configure starting address of tilemap for specific plane.

Tilemap is filled by strings of tiles, from left to right, then from top to bottom. If your plane is 32x32 tiles size, you need 32*32*2 = 2 kb of VRAM. Don't confuse plane size and screen size.
Format of tilemap value (one "tile") is

Code: Select all

Byte 1	PRI	CP1	CP0	VF	HF	PT10	PT9	PT8
Byte 2	PT7	PT6	PT5	PT4	PT3	PT2	PT1	PT0
PRI - priority
CP1, CP0 - palette number
VF - vertical flipping
HF - horizontal flipping
PT10-PT0 - char number in VRAM, starting from $0000.

So to change tile palette, you must change it's tilemap value in VRAM.
It's simpler to change palette itself, but only if it's not used by tiles you don't want to change their color.

NightShadow
Interested
Posts: 19
Joined: Sun Oct 14, 2012 10:20 pm

Post by NightShadow » Thu Oct 18, 2012 7:14 pm

Thabks a lot Gmaniac for explanation.

I knew I had no much chance to do it... I need to collect these kind of infos before starting to plan my palettes and tiles because I need to optimize them with what I know I'm able to do...

This trick would have been to make some kind of lightning / bumpmapping on full screen but unfortunately it would only work with slow techniques....


Thanks again

tomaitheous
Very interested
Posts: 256
Joined: Tue Sep 11, 2007 9:10 pm

Post by tomaitheous » Sun Nov 04, 2012 11:08 pm

NightShadow wrote:Thabks a lot Gmaniac for explanation.

I knew I had no much chance to do it... I need to collect these kind of infos before starting to plan my palettes and tiles because I need to optimize them with what I know I'm able to do...

This trick would have been to make some kind of lightning / bumpmapping on full screen but unfortunately it would only work with slow techniques....


Thanks again
So, you just want to change the palette association for the tile itself (but not the tile data nor the actual palette data)? Of course you can do this. And no, you don't need to change the whole tilemap. Just set the vram pointer to the tilemap entry in the vram and update it. No need to re-write the entire map.

Here's a game that does just that: https://www.youtube.com/watch?v=lr1oSq2SLbA @ 5:54 in the video (the pseudo light source effect). Sure, it's on PC-Engine but principle is exactly the same for Genesis.

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

Post by Stef » Mon Nov 05, 2012 6:26 pm

tomaitheous wrote: ...
Here's a game that does just that: https://www.youtube.com/watch?v=lr1oSq2SLbA @ 5:54 in the video (the pseudo light source effect). Sure, it's on PC-Engine but principle is exactly the same for Genesis.
The effect looks really neat :)
I guess we don't saw it in genesis games as it requires to waste 1 or more palettes, something you can easily do on PCE but not on genesis :p

NightShadow
Interested
Posts: 19
Joined: Sun Oct 14, 2012 10:20 pm

Post by NightShadow » Tue Nov 06, 2012 7:48 pm

Hi

Thanks for the tip tomaitheous


That's exactly what I want !!! Wow

The way you explain me how to do that seems really easy and doesn't seem to need a lot of code.. it seems like 2-3 code line just to assign another palette to a tile...

Unfortunately I miss some experience and I would really like to know if it's doable within SGDK in C or do we need to use Assembler to do it ?


I you or anybody could write the small part as an example I would be really grateful as I'm extremely interested in that technique for my project !! Just the lines to set one of the 4 palette to a tile on a plan..

Also, I would also really appreciate to have clearer explanations about the waste of 1 or more palette ... ??
I would reaaly like to understand the procedures that make it work with this limitation not like the Turbo. How it's working ?!

Also, if you have any links with good docs on that please post them !

Thank you guys !
NightShadow[/quote]

tomaitheous
Very interested
Posts: 256
Joined: Tue Sep 11, 2007 9:10 pm

Post by tomaitheous » Wed Nov 07, 2012 1:34 am

Well, the Genesis/Megadrive only has four 16 color subpalettes. That's for both BG and Sprite data to use. So, the more subpalettes you reserve for this effect, the less you have for sprites and such.

One option is to have a single 16 color subpalette for the main sprite. Be sure to include a few colors that can be reused for sprites (like low color projectiles and such). That leaves you with three subpalettes left. If you break those subpalettes down into 8 colors each, that gives you six subpalettes to work with. Of course you will need to have an alternate set of tiles of the original, that can use the upper 8 colors. So you'll have to change both the tile and the subpalette entry in the tilemap position, but this isn't a problem since you have to write the tile index part of the tilemap (of the WORD length entry) to vram anyway.

And, maybe it's possible to take advantage of shadow mode to expand on this to get more 'shades' for such an effect, although I believe you'll waste a tilemap/plane doing this. But that's the nature of special effects; they always have their limitations.

The Turbo gets away with this because it has 32 sixteen-color subpalettes (sprites have 16 and BG has its own 16 entries).

If you look at that video, you'll see that the movement is a little rigid because it's based on 8x8 grid (tile size). If you have enough sprite bandwidth, and your tile or pattern for the BG is small enough, you can use sprites to overlay on top of the tiles for this effect. But the area has to be smaller in nature because of the sprite scanline limitation.

Really, there are a few ways at doing this - but they all depend on exactly what the game engine or demo allows (again, that can be said of any special effect).

NightShadow
Interested
Posts: 19
Joined: Sun Oct 14, 2012 10:20 pm

Post by NightShadow » Fri Nov 09, 2012 5:51 pm

Hi again !


Thank you very much for the clear explanation on this... That confirm everything I though like it should be.

I already planned the grid trick + the fact that you have to sacrifice the number of palettes you need for this effect although I didn't think about splitting each palette in 8/8 to get more fades... I also understand that if you want to get the best of this effect you would have to use the shadow effect !!!

Actually I want to make a platformer and this trick would be only for some levels or parts...I want many different setup and effect for the different levels.. That's funny I have never seen this trick used in genesis games... The only game I would think possible would be the Vector man games although I haven't played them for years.. Would be interesting to look again.

So, now I would really like to know how to set the palette and the data parts individually.

How do I set the VDP pointer to the right tile and set the right value ??
Is there a function in SGDK ? I know I'll have to deal with the vdp memory map to get to tile I want but I miss some experience.

If I ever get an example just for 1 tile I'll be capable of figuring all the rest.


Thanks in advance for help.

NightShadow

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

Post by Stef » Fri Nov 09, 2012 6:13 pm

Here is a basic tutorial for SGDK.
It's quite simple but at least give you entries to do what you want :

http://code.google.com/p/sgdk/wiki/SGDKTutorial

Post Reply