Hello Guest

Light Distortions

  • 6 Replies
  • 13092 Views
Light Distortions
« on: January 20, 2005, 15:50:47 »
Ok, I've just about gotten all the basic shapes and things down. Now I'm wanting to move onto something a bit more interesting...

How do you do light distortions? For instance, I want to put a 2D texture inside a sphere, and have the sphere's round front distort the texture as if it were a glass lens. Any ideas on how to do that?
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

*

Offline tomb

  • ***
  • 148
Light Distortions
« Reply #1 on: January 20, 2005, 17:29:48 »
Pixel shaders maybe. But it's way too advanced for you. Think of something easier.

Light Distortions
« Reply #2 on: January 20, 2005, 17:32:23 »
I'm getting by with some sphere-mapping for reflections. I'm mostly just wondering if there's a way to project what's on the inside of the sphere to the outside of it.
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

*

Offline Teeth

  • *
  • 14
Light Distortions
« Reply #3 on: January 20, 2005, 18:11:28 »
Well, it's ray tracing innit.

There would be loads of ways to fake it, but you could look up ray tracing on the net and find out some stuff about it there. There are loads of resources. Here's how one might do it:

If it's only one texture you're thinking about (which I guess you could do by reading the pixels off the frame buffer beneath the object), then (assuming the surface is inside the object) at every vertex of your object you could calculate the vector created by a beam of light running perpendicular to the screen's surface (i.e. straight down the Z axis) as it passes into your object at that vertex.

The refractive index of the object will bend the beam of light away from its previous course. You would then project this new vector down onto the  texture surface, and map the UV for the vertex you originally passed the beam through to that UV on the texture you read off the frame buffer. If the texture you were looking at wasn't flat you could add calculations to find out where the vector impacted the texture surface. Also if the object is behind the object you'll need to calculate where the beam of light exits the medium and which direction it'll be going in afterwards, and work from there.

I've forgotten the equation for calculating the resultant vector given two refractive indexes. You can probably find it in most A-level (high school?) maths books, or online somewhere. Wolfram maybe, or as I said above at probably any ray tracing website. You could fake the calculations by just using the vertex's normal and projecting that inwards. Might look a bit funny.

*

Offline Teeth

  • *
  • 14
Light Distortions
« Reply #4 on: January 20, 2005, 18:17:17 »
Or you could fake it - after your render, make a circular, radial type mesh like a spider web and map the texture underneath to it, then project the UVs outwards with d*Cosine(r) where d is how far out you'd like to project the dots at the centre (d < 1) and r is a function of your radius where r(radius of your circle) gives pi/2.

Light Distortions
« Reply #5 on: January 20, 2005, 18:23:51 »
I like the idea of faking it.  :D

What's the easiest way to "snap a picture" of the texture (or compilation of textures) underneath the object? I'm not familiar with any specific command to do it, although I'm guessing OpenGL must have a way, as that's how it handles alpha blending.
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

*

Offline Teeth

  • *
  • 14
Light Distortions
« Reply #6 on: January 20, 2005, 19:39:15 »
I was just thinking to read it off the frame buffer with glReadPixels. Wouldn't be very accurate if the scene behind varied wildly in Z though.