Jump to content
  • Advertisement
Sign in to follow this  
john13to

Creating a rainbow simulation in a game

This topic is 3140 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am going to create a 3D-game using the XNA Game Studio in Windows and it will be a shooter game based in a TRON-like environment. You steer a spaceship where you, not so suprising will shoot down enemies with the lightbeam. What is special here is that you have the ability to shoot the lightbeam though a glass prism so that the famous rainbow effect comes up on the other side. This will help you eliminate several enemies at the same time, since the lightbeam is restricted to eliminate one enemy at the time. This is my idea so far in theory. But in practice, I don't know how to implement it reality. I have tried to find resources on the net that explain how you implement it generally but I haven't found so much in that area. Do you have any idea on how to implement it or do you know any resources that explain it? I am also sending a sketch on my idea. http://www.student.itn.liu.se/~johto970/game_project/game_project_sketch_optics.jpg

Share this post


Link to post
Share on other sites
Advertisement
This article explains the subject
http://en.wikipedia.org/wiki/Prism_%28optics%29

But I think this one is better
http://science.howstuffworks.com/question41.htm

the basic principal is that light is slowed down the thicker (or denser? I'm not quite sure whats the correct English word) the material it's traveling through is.

Imagine you are riding a sledge down a snowy hill, and your right side hits some grass. Then you will obviously turn a little right. This is the same for light, if it is traveling through one material, and its right side hits a material with a higher density, it will turn right. and vice versa.
The thing is that light consists of many rays of different colors and sizes. Red light waves are the longest, and blue are the shortest. therefore the red light waves are less infected by a change of density in the material it is traveling through, while blue are more affected by it, and will turn with a greater angle.

Therefore all the colors are split up according to their wave length. And this creates the rainbow effect.

But I don't think that any one will notice if you just fake the physics, and creates the visual effect with a texture, and some simple math :)

Btw I hope you can understand my English, it's the first time I'm explaining physics in an other language than Danish :)

Share this post


Link to post
Share on other sites
btw your sketch is wrong :O

since it is only vertically angled, the light will only bend vertically!


/\ .-*
------/ \< RAINBOW :D
/ \ *-.

Share this post


Link to post
Share on other sites
Well, you rotate the vertical bended light by 90 degrees and then you have the rainbow effect that I sketched! :P

No, but the idea was to have the incident raylight bended horizontally inside the glass prism and again bended horizontally when it comes out from the class.

I had a meeting with the examiner of the course and he said that it would be simplest to treat the raylight as a particle and I should create new color vectors when the light hits on the glass surface.

Each color vector will have one raycolor based upon how much one particular part of the incident raylight, for instance one color vector will be blue, other will be green and other will be red. He said that it is best to start with the RGB components, in other words I will only use three colors from the beginning.

Then the color vector will bend out from the glass to the airspace horizontally as previously mentioned.

This is the formula which I will be using to calculate the refracted transmitted light which is derived from the Snells law formula:

T_vector = u * I_vector - (cos(theta) + u * cos(phi)) * N_vector

where

u = u1/u2 is the fraction between the first media and the second media, in this case the fraction between the airspace and the glass.

cos(theta) = (1/u^2) * (1 - u^2 * (1 - (cos(phi))^2)^(1/2)

I_vector is the incident ray vector, N_vector is the normalvector to the surface and T_vector is the refracted ray the is being transmitted in the media.

Snells law:

u1 * sin(phi) = u2 * sin(theta)

These formulas can be found in the book 3D Computer Graphics by Alan Watt.

What do you think of the idea/solution? Do you think it can be done?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!