forums

TNT Basic Forums > Programming Q&A
FX Matrix
< Last Thread     Next Thread >
Author
Thread        Post A Reply

07-06-2002 20:24

Posted by:
Matthew

Click Here to Email Matthew   Find more posts by Matthew

Could someone explain me how FX Matrix works???

07-17-2002 14:38

Posted by:
Matthew

Find more posts by Matthew

Answer

Could somebody answer my question?

07-17-2002 19:04

Posted by:
Charles

Click Here to Email Charles   Find more posts by Charles

FX Matrix

Read the online help, Matthew.

It's for pre-processing images - like blurring - before you display them on-screen.

-Charles

07-18-2002 12:26

Posted by:
Matthew

Find more posts by Matthew

Example

I don't understand the example ( if we're talking about the same ). I already read in the TNT documention and don't understand anything.

07-18-2002 17:21

Posted by:
Charles Robinson

Click Here to Email Charles Robinson   Find more posts by Charles Robinson

Hi, Matthew.

I can't really explain it any further. The FX Matrix lets you filter an image, before you copy it to the screen in your prog. Are you planning to use it somehow ?

Maybe Mark or John can explain better than I can.

-Charles

07-18-2002 20:20

Posted by:
Mark Tully

Find more posts by Mark Tully

FX Matrix

Hi Matthew,

FX Matrix is really a bit of a toy command. Basically it allows you to apply what are known as 'kernal filters' to your images. A kernal filter is a grid of numbers, which are used to calculate a weighted average of all the pixels around a given pixel to generate a result one. The grid is moved across the image, 1 pixel at a time, always operating on the pixel in the centre of the grid, and filtering in it's neighbours as dictated by the weighting given to it by the grid.

This is probably better explained with an example:

If you had the matrix:

0 1 0
1 2 1
0 1 0

And applied it to an image, a pixel in the resultant image would be calculated by having 2*the colour value of itself, then 1* the colour value of the pixels above, below, left and right of it. The result would then be divided by the number of pixels factored in to give an average. In this case there were 2+1+1+1+1=6 pixels factored in. This would have the affect of a pixel retaining it's original colour, but being heavily infulenced in colour by its neighbours. This results in colour smoothing - or a 'gaussian blur' as photoshop calls it.

You can produces some really crazy convolutions of the image by typing randomly chosen numbers into the matrix. Photoshop has a kernal filter command in it's filter menu, which is what a lot of it's plug in filters are based on.

For instance, to emboss an image, you make each pixel have it's original value + the value of the pixel below and right (where the 'light' is shining from), and less the value of the pixel above and left (where the 'shadow' is). If all the image is the same colour, the resultant pixel is the same colour as the original, as the pixel above left and below right cancel each other out. But if there's a colour contrast, such as on the edge of a block of colour, it will become embossed.

An example matrix for embossing is:
-10 0 0
0 5 0
0 0 10

So that's the theory anyway. In TNT Basic, you make these matrices by filling out a 2D array with the numbers.

Eg
int mymatrix[3,3]

mymatrix[0,0]=-10 'top left
mymatrix[1,0]=0 'top middle
mymatrix[2,0]=0 ' top right
mymatrix[0,1]=0 ' left middle
mymatrix[1,1]=5 ' middle
mymatrix[2,1]=0 ' right middle
mymatrix[0,2]=0 ' bottom left
mymatrix[1,2]=0 ' bottom middle
mymatrix[2,2]=10 ' bottom right

Once the matrix is filled out, apply it to your image with the FX Matrix command as so:

FX Matrix mymatrix[],sourceCanvas to destCanvas

Where 'mymatrix' is the matrix to apply, the sourceCanvas is the number of a canvas to operate on and destCanvas is the number of the canvas to place the results in.

The FX Matrix example demonstrates several different FX Matrix effects and can be downloaded from http://www.tntbasic.com/download/examples/files/FX_Matrix_Example.sit.

You can read more about it in TNT Basic's help, available on your hard disk or online at http://www.tntbasic.com/learn/help/commands/fxmatrix.htm.

Unfortunately, the FX Matrix command isn't very fast, so probably won't be able to do real time fx unless you have a fast machine. But it's cool to use on your title screen, or for preprocessing your graphics as the game loads.

Hope this helps!

Mark

09-08-2002 20:29

Posted by:
eLL

Click Here to Email eLL   Find more posts by eLL

For those of you..

This may be familiar to those of you using IE etc...

Would this be a speedy solution for semi transparent rectangles,
for example under IE 5 you have the option of having transparent contextual menus.
I set the option thinking,"how PNG-esqe." then it came to my attention that these 'transparent' Cmenus utilize an FXMatrix of sorts.

I wanted to know if this would be a good option to animate a body of water, draw heat waves

09-08-2002 20:30

Posted by:
eLL

Click Here to Email eLL   Find more posts by eLL

anyone have any more sample FX Matrices

anyone have any more sample FX Matrices

09-10-2002 19:27

Posted by:
Mark Tully

Find more posts by Mark Tully

FX Matrix is slow

You might find it's too slow to do anything useful, it was more a toy command to help you pre-render special fx, but let me know how you get on.

Cheers,

Mark

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.