Tilemap & Scaling WORKING with SMOOTHSHADING TRUE

Previous topic - Next topic

spicypixel

I have been using a series of POLYVECTOR functions that I grabbed from here a long time ago (I'd credit the original other and post but I've forgotten), having now understood what the PV routines were doing I changed them a little and recently decided to tweak the values to try and get rid of the nasty edge artifacts when using SMOOTHSHADING TRUE. This is one of the functions, the principle is the same for all.

I have tried this with a full-screen tilemap and it works very well.

Code (glbasic) Select

FUNCTION PolySpriteZoom: sprite, xpos#, ypos#, scalex#, scaley#
// Texture UV Info.
patx      = GE_pv_Sprite[sprite].GE_pv_X + 0.38
paty      = GE_pv_Sprite[sprite].GE_pv_Y + 0.38
patxx     = GE_pv_Sprite[sprite].GE_pv_X + GE_pv_Sprite[sprite].GE_pv_W - 0.76
patyy     = GE_pv_Sprite[sprite].GE_pv_Y + GE_pv_Sprite[sprite].GE_pv_H - 0.76

// Sprite Info.
pminx = xpos
pminy = ypos
pmaxx = pminx + GE_pv_Sprite[sprite].GE_pv_W * scalex#
pmaxy = pminy + GE_pv_Sprite[sprite].GE_pv_H * scaley#

POLYVECTOR pminx, pminy, patx , paty , RGB(255,255,255) // Top-Left
POLYVECTOR pminx, pmaxy, patx , patyy, RGB(255,255,255) // Bottom-Left
POLYVECTOR pmaxx, pminy, patxx, paty , RGB(255,255,255) // Top-Right
POLYVECTOR pmaxx, pmaxy, patxx, patyy, RGB(255,255,255) // Bottom-Right
POLYNEWSTRIP
ENDFUNCTION


The trick is to use floating point values to determine the UV edge values. Above I used 0.38 to be added to the top XY position and 0.76 to be subtracted from the bottom right hand position. You may be able to get them nearer to 0 dependent on the tileset used, for me these values work with a tileset that has fulltiles and partially filled tiles adjacent to each other.

One thing I did notice was that the edge artifacts depicted were showing thin lines with the original transparent colour. For example in my paint package which is using an indexed 256 colour palette, I had set the first colour (0) to be RGB 255,0,255 and although set to transparent the artifacts shown had purple hues to them. Pointless observation I'm sure but I'd have thought the edge (smoothing) would have been the adjacent tile ---> transparent and NOT adjacent tile ---> faint transparent set coloured hue ---> transparent.

Anyway, hope some of you like this experimenting :)
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

Wampus

   // Texture UV Info.
   patx      = GE_pv_Sprite[sprite].GE_pv_X + 0.38
   paty      = GE_pv_Sprite[sprite].GE_pv_Y + 0.38
   patxx     = GE_pv_Sprite[sprite].GE_pv_X + GE_pv_Sprite[sprite].GE_pv_W - 0.76
   patyy     = GE_pv_Sprite[sprite].GE_pv_Y + GE_pv_Sprite[sprite].GE_pv_H - 0.76


Cool! Very useful tip. Another alternative technique is to extrude the edges of textures for tiles or any sprites that need to seamlessly connect with others. Example:-



Extruding the sprite as in the second example above will work with...

   // Texture UV Info.
   patx      = GE_pv_Sprite[sprite].GE_pv_X
   paty      = GE_pv_Sprite[sprite].GE_pv_Y
   patxx     = GE_pv_Sprite[sprite].GE_pv_X + GE_pv_Sprite[sprite].GE_pv_W
   patyy     = GE_pv_Sprite[sprite].GE_pv_Y + GE_pv_Sprite[sprite].GE_pv_H


...so no need to alter the texture co-ords. Extruding textures is built into programs like Texture Packer. It could also be added to a texture packing routine like I wrote here: http://www.glbasic.com/forum/index.php?topic=7896.msg66139#msg66139

spicypixel

The only thing I don't like about the extrusion is that in say my 64x64 tileset (which are packed together without seperation lines as a real tilesheet should be lol). I am effectively using only 63x63 pixels in my UV defined area.

Thus
Code (glbasic) Select

   // Texture UV Info.
   patx      = GE_pv_Sprite[sprite].GE_pv_X + 1
   paty      = GE_pv_Sprite[sprite].GE_pv_Y + 1
   patxx     = GE_pv_Sprite[sprite].GE_pv_X + GE_pv_Sprite[sprite].GE_pv_W - 2
   patyy     = GE_pv_Sprite[sprite].GE_pv_Y + GE_pv_Sprite[sprite].GE_pv_H - 2


+1 and -2 used here to represent the 63x63 grabbed but could be hardcoded numbers, is this what you mean?
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

spacefractal

#3
I did seen that issues in Greedy Mouse as well, but with a different issue. Here its was the dreadfull MULTIPLY issue when offbuffer was used. Its was also a 40% loss of speed, I dropped the OFFSCREEN and used backbuffer scaling directly instead (using a similar code like those). I also did make sure its diddent scaled into a float, but more a integer size (etc the scaled sprite should finally been a integer).

So its seen its can been fixed in differents way, so its more about a experimentation what that works best (etc I diddent use INDEX color as well).

So in the game I diddent use extrusion on all regular tiles (few tiles did require carefull placement), but did that with font as well the main sprite (where we diddent use edges at all), but not sure its was this issue, but I guess its was very similar.

Howover the game did never zoom out over its size, only in. The tilesize here was 200x200px for the max size.

Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/