Dark Bit Factory & Gravity

PROGRAMMING => General coding questions => Topic started by: taj on September 28, 2006

Title: How oldskool effects are done
Post by: taj on September 28, 2006
I'm interested to know how some oldskool effects are done and maybe some software engine coders can enlighten me. Maybe even with code :-)

1. How is the image for the rotating rubber thing created? You know the one that runs from the top of the screen to the bottom and twists like it is made of rubber. It seems to be done by indexing into an image of one twist but whats the maths for the first image?

2. Lens effect. Is that done the obvious way by sort of raycasting or is there a much cleverer, simpler way?

Title: Re: How oldskool effects are done
Post by: Shockwave on September 28, 2006
Two questions, I don't know what you mean exactly by a lens effect as there are so many types...

The rotating rubber thing is really simple,  if you are making a bar for example, you go down the screen creating 4 X co-ordinates for each line. These are really simple, just some sine with 90 degree offsets for each.

Then you test 4 lines between co-ordinate pairs and if the line runs from L to R it is visible so draw it.

It's as simple as that!

You can make some improvements to the routine quite easilly by calculating the length of the line, it can be coloured accordingly, to give fake light sourcing.

Alternatively you can do a crude linear texture map, just divide line width by texture width and that's your interpolation value. It can look quite effective.
Title: Re: How oldskool effects are done
Post by: relsoft on September 29, 2006
I'm interested to know how some oldskool effects are done and maybe some software engine coders can enlighten me. Maybe even with code :-)

1. How is the image for the rotating rubber thing created? You know the one that runs from the top of the screen to the bottom and twists like it is made of rubber. It seems to be done by indexing into an image of one twist but whats the maths for the first image?

2. Lens effect. Is that done the obvious way by sort of raycasting or is there a much cleverer, simpler way?



1. Depends actually, if you want to do it in 3d, you could do radial displacement of the cylinder.  For 2d, some do it with texture offsets + sine displacement

Here's an example with source:
One is in OpenGL the other use tinyPTC

http://rel.betterwebber.com/junk.php?id=54
2. Lens effect could be done in OpenGL with vertex manipulation and wth sofware I used a texture displacement both uses this fomula: height = 1/distance^2.

Here's an example:
http://rel.betterwebber.com/junk.php?id=58

Screens:

Rubber:
(http://rel.betterwebber.com/images/screenies/flubber.jpg) (http://rel.betterwebber.com/junk.php?id=54)
(http://rel.betterwebber.com/images/screenies/flubber_tptc.jpg) (http://rel.betterwebber.com/junk.php?id=54)

Lens:
(http://rel.betterwebber.com/images/screenies/radial_lens.jpg) (http://rel.betterwebber.com/junk.php?id=58)

Title: Re: How oldskool effects are done
Post by: taj on September 29, 2006
Have some Karma dude - great answer for me. Thanks also shockwave. For the lens I meant this simple effect, you know the one where you have an image in the background and a sphere like object bouncing back and forth infront of it. I can think of complex maths ways to do it but was wondering if there are massive cheats :-)

Thats flower lens effect is great BTW. I think if you rendered to a texture each time you draw a lens then use that as input , the refractions would accumulate and end up looking just awesome.
Title: Re: How oldskool effects are done
Post by: relsoft on September 30, 2006
That's a great idea, sadly, my comp is not that fast.
 :cheers:
Title: Re: How oldskool effects are done
Post by: Optimus on September 30, 2006
For the sphere map, the math I used is the equation of a sphere: X^2 + Y^2 + Z^2 = R^2
solving this to Z: Z = SQRT(R^2 - X^2 - Y^2)

You can write it this way: Z = SQRT(R^2 - (X - ScreenWidth/2)^2 - (Y - ScreenHeight^2)) to translate the sphere calcs to the center of the screen.
R can be variable, depending in that the sphere is bigger or smaller, play with the values to find a good size.

Now, that equation gives a Z value for each (X,Y) pixel in the screen. That Z value by using a displacement functions gave the Xb, Yb of a bitmap according to real X, Y on screen. You read from the texture in Xb, Yb position to write in X, Y pixel position according to the following:

Xb = (X - ScreenWidth/2) / Z
Yb = (Y - ScreenHeight/2) / Z
iirc

Now, that's the math in few words. The trick for speed is to just calculate these displacements for each pixel in some buffer arrays, e.g. DIM SphereDispX[320*200] AS INTEGER and DIM SphereDispY[320*200] AS INTEGER for example and you can use the precalculated values now without calculating any slow math!

In a nutshell. If you have anything else maybe I'll be here to reply oneday..

p.s. The twirl is another effect I'd like to make. Aren't some of them done with voxels? Maybe I'll read the comments and think again about it. Maybe it's much easier than I thought..
Title: Re: How oldskool effects are done
Post by: taj on September 30, 2006
Great answer too optimus - thanks and karma!
Title: Re: How oldskool effects are done
Post by: Clyde on October 02, 2006
The twirl effect is often known as a Peristalsis effect. Meaning "A Whipping Motion"
Title: Re: How oldskool effects are done
Post by: Shockwave on October 02, 2006
Fnaaarrrr! ;)