Jo Engine Forum

Sega Saturn Development => General Jo Engine Help => Topic started by: 20EnderDude20 on August 03, 2018, 03:24:30 am

Title: Making a 'corrected texture' for a triangle.
Post by: 20EnderDude20 on August 03, 2018, 03:24:30 am
I've been looking at Sonic Z-Treme, and I've seen many triangular faces that are displaying the entire texture. Ever since, I've been thinking about making a texture become 'corrected', so to speak. I started out with messing around with the distort tool in Flash 8. But later, I thought that I could do this using UV mapping in Blender. however, I've hit a snag. I think UV distortion uses affine transformation, and if I use coordinates that aren't mathematically similar to the face, it won't give the intended result. Is there a solution to this?
Title: Re: Making a 'corrected texture' on a triangle.
Post by: ponut64 on August 03, 2018, 05:57:18 am
This is the concept:
Take your square texture.
Take the bottom right vertice and move it to the same position as the bottom left vertice. Do not merge them.
Done.

You can do this in Adobe Photoshop.

So this texture...
(https://i.imgur.com/7ObeMhW.jpg)

What does this look like, undistorted?
It's this:
(https://i.imgur.com/kBXz70N.jpg)

How do we pre-distort that .. when we want this:
(https://i.imgur.com/h8SEufT.jpg)

... I don't know.
Title: Re: Making a 'corrected texture' on a triangle.
Post by: XL2 on August 03, 2018, 01:36:15 pm
Ponut is right about that solution, but use caution as even if it has invisible pixels, the Saturn still needs to "render" them, so it can make things way slower quickly. The way around that is to use end codes, which none of my tools support. The other solution is to pre-distort the texture, but again I don't know much about it.
Title: Re: Making a 'corrected texture' on a triangle.
Post by: 20EnderDude20 on August 03, 2018, 04:30:36 pm
So, the thing that I noticed with 'correcting' a texture for an isosceles right triangle is that you form an isosceles triangle from the pixels that are outside the canvas. as an example, (https://i.imgur.com/SYLksPO.png) the vertex lines up with the top vertex of the triangle. Here are two triangles. The blue one being the face you're putting it on, and the dashed one being the amount of distortion on the texture. (https://i.imgur.com/uYvNgoy.png)

you can see it's just a mirrored version of the face. This process worked when I tried it on the Saturn, and it's very easy with right triangles, but I never did it on a triangle without a right angle, so that's new territory for me.  ;D I hope this helps.
Title: Re: Making a 'corrected texture' on a triangle.
Post by: corvusd on August 03, 2018, 05:36:56 pm
Ponut is right about that solution, but use caution as even if it has invisible pixels, the Saturn still needs to "render" them, so it can make things way slower quickly. The way around that is to use end codes, which none of my tools support. The other solution is to pre-distort the texture, but again I don't know much about it.

This days assault me this dubt:
Is need it config register=0 Trasparent pixel disable, to avoid draw pixels in a texture/pattern used only to make a mask?
Or can be used End code draw in texture/pattern pixel data to avoid draw this pixels?
Or need both of then "activated"
For CC VDP1 is need both activated. But if you only need a mask texture... what option is the best to gain maxium time or use less cycles?
Wherever, I undestand that is necesary generate the data(pixel data or command table data) for this features to avoid waste cycles in draw VDP1.
Title: Re: Making a 'corrected texture' on a triangle.
Post by: 20EnderDude20 on August 03, 2018, 06:26:40 pm
Here is a comparison:(https://i.imgur.com/pXEtBhR.png)
The one on the left uses the unmodified texture, or this one:(https://i.imgur.com/N4EHve6.png)

The one on the right is 'corrected', or this one:(https://i.imgur.com/ABS40ko.png).
Title: Re: Making a 'corrected texture' on a triangle.
Post by: XL2 on August 03, 2018, 07:00:06 pm
Ponut is right about that solution, but use caution as even if it has invisible pixels, the Saturn still needs to "render" them, so it can make things way slower quickly. The way around that is to use end codes, which none of my tools support. The other solution is to pre-distort the texture, but again I don't know much about it.

This assault me this dubt:
Is need it config register=0 Trasparent pixel disable, to avoid draw pixels in a texture/pattern used only to make a mask?
Or can be used End code draw in texture/pattern pixel data to avoid draw this pixels?
Or need both of then "activated"
For CC VDP1 is need both activated. But if you only need a mask texture... what option is the best to gain maxium time or use less cycles?
Wherever, I undestand that is necesary generate the data(pixel data or command table data) for this features to avoid waste cycles in draw VDP1.

The End code tells the VDP1 to stop processing that line, while transparent pixel just writes nothing to the framebuffer.
So if you have lots of transparent pixels, the processing speed is the same as an image full of colored pixels.

But the End code just tells the VDP1 to stop processing the line, so it's faster to render.
You need 2 end codes to stop processing a line, so the way to do it is to put one in front of your first colored pixel on each line and one right after your last colored pixel.

With clut sprites, you need to waste 2 colors for the transparent pixel and the end code.
Title: Re: Making a 'corrected texture' on a triangle.
Post by: corvusd on August 03, 2018, 07:14:26 pm
Ponut is right about that solution, but use caution as even if it has invisible pixels, the Saturn still needs to "render" them, so it can make things way slower quickly. The way around that is to use end codes, which none of my tools support. The other solution is to pre-distort the texture, but again I don't know much about it.

This assault me this dubt:
Is need it config register=0 Trasparent pixel disable, to avoid draw pixels in a texture/pattern used only to make a mask?
Or can be used End code draw in texture/pattern pixel data to avoid draw this pixels?
Or need both of then "activated"
For CC VDP1 is need both activated. But if you only need a mask texture... what option is the best to gain maxium time or use less cycles?
Wherever, I undestand that is necesary generate the data(pixel data or command table data) for this features to avoid waste cycles in draw VDP1.

The End code tells the VDP1 to stop processing that line, while transparent pixel just writes nothing to the framebuffer.
So if you have lots of transparent pixels, the processing speed is the same as an image full of colored pixels.

But the End code just tells the VDP1 to stop processing the line, so it's faster to render.
You need 2 end codes to stop processing a line, so the way to do it is to put one in front of your first colored pixel on each line and one right after your last colored pixel.

With clut sprites, you need to waste 2 colors for the transparent pixel and the end code.

Then, not it is possible gain speed or not "process" the transparent pixel, some way? I understand, that it save cycles in the fill pixels in the framebuffer? It not write nothing not would have cost... but in the same way to process texels data no?
Title: Re: Making a 'corrected texture' on a triangle.
Post by: ponut64 on August 03, 2018, 07:50:26 pm
As far as I gather, the transparent pixels consume cycles because they are present in the instruction for as long as any pixel would be until the next instruction.
The key to the end codes is to truncate the length of the instruction, not so much to reduce the computational intensity of that instruction.
It being based on filling the frame-buffer, it is timed with Vblank, so the computational intensity of what can be done by Vblank is something that you can more or less assume will never change, as it's always the same amount of time. Thus reducing the time spent on regions of the instruction is how you save performance in this case.
[I realize this is a very obvious series of statements, perhaps I shouldn't conjecture about things I don't understand]

Also, that's some good work on the pre-distortion, enderdude.
[If it wasn't clear, you grab the top-right vertice and drag it one box-size up]
Title: Re: Making a 'corrected texture' for a triangle.
Post by: 20EnderDude20 on August 03, 2018, 07:57:04 pm
Maybe you can use a black-and-white bitmap to tell your converter where the end codes are. I think we are making something that can possibly give a primitive version of uv mapping on the saturn. ;D
Title: Re: Making a 'corrected texture' for a triangle.
Post by: Jorhlok on August 03, 2018, 11:14:39 pm
I saw this and had an idea to try so I did a screen cap of manipulating an image in gimp and the result it drew. It got reasonable results so I cut the videos together and slapped it on youtube.
https://youtu.be/yTGtuu98AYw

For this I took each vertical column of pixels and stretched them vertically to fill the space.

EDIT: I was worried about texture warping horizontally so I added some lines to the corrected texture to see how it would be effected. I was expecting the grey lines to bend either left or right but to my surprise it didn't
Title: Re: Making a 'corrected texture' for a triangle.
Post by: 20EnderDude20 on August 06, 2018, 04:33:37 am
So, my original question was to find a way to correctly distort the texture on Blender to get the corrected texture, because Blender uses affine distortion for uv mapping. It looks like this: https://youtu.be/8TleepxIORU?t=33s .
Title: Re: Making a 'corrected texture' for a triangle.
Post by: 20EnderDude20 on August 07, 2018, 12:04:40 am
Okay, so after some thinking of a system to make start and stop addresses, I've made this diagram that gives a loose idea of a concept of primitive uv mapping. I honestly don't know if this is possible, but it's an idea. This is if you can change the start and stop addresses using interrupts, (preferably, v-interrupts): (https://i.imgur.com/rRkssAv.png) . The upside would be that the hardware won't have to draw transparent pixels.
Title: Re: Making a 'corrected texture' for a triangle.
Post by: 20EnderDude20 on August 07, 2018, 04:11:45 am
So, does this technique make uv mapping available on the Saturn?
Title: Re: Making a 'corrected texture' for a triangle.
Post by: corvusd on August 07, 2018, 07:15:38 pm
No. I explain in my post:
http://www.davidgamizjimenez.com/inpostivegames/sega-saturn-to-the-limit-i/ ->  1.1 Triangle vs Quadrangle – EXTRA Ball: UV Mapping

Well, I try to explain. XD
Title: Re: Making a 'corrected texture' for a triangle.
Post by: 20EnderDude20 on August 12, 2018, 11:19:25 pm
     Here is another way to make a corrected texture.
You would make a replica of the triangle to a bitmap, and place the area of the triangle within the area of the texture you want on the triangle. You can also scale or rotate the triangle to any size as seen here: (https://imgur.com/G0ry0CC.png)
.
     The third step is to mask the image. There are many ways to do this. One way is using flash by making the triangle the mask, and the image the masked layer. Another way is to go into GIMP and set the triangle as the mask layer: (https://imgur.com/neN505r.png).
     The fourth step is to export the image as a png.
     The fifth step is to scale the masked image so that it fits in the canvas' dimensions:(https://i.imgur.com/PXGCJon.gif)
     The sixth step is to scale the rows of pixels up on one axis so that they will fit onto the canvas:(https://i.imgur.com/QtMSnIw.gif)
... and the result will be a corrected texture! Now, there has got to be a faster way to do this. I don't want to waste my entire day scaling a 32x32 texture line by line. So, is there a way to make this a script?

Title: Re: Making a 'corrected texture' for a triangle.
Post by: Jorhlok on August 12, 2018, 11:36:44 pm
I was thinking of making a python script to do it and I may make it soon. However I think one or two of the edges of the triangle needs to span an entire edge of the sprite because that's how it'll be distorted when drawn as a quad.

Well, the python script I was imagining would stretch either columns or rows of pixels but maybe a full uv preprocessor could be made instead. I might make the simple version first and think on the latter later.