Programming > Lightweight Java Gaming Library
Black Hole
Azraton:
Hey guys,
I am currently creating a nice little game using LWJGL 2.9.3, and I wanted to add a new feature to the game, and as a cool gimmick I thought of black holes. The gravitational effect shouldn't be a problem, but I want it to look good as well. I found a few tutorials how to do this in Blender, but wasn't sure how to port something like that to my engine. I hope someone will be able to tell me how ;)
Link to a blender tutorial I found:
http://blender.stackexchange.com/questions/18703/creating-a-black-hole-in-blender
EDIT: Not really a tutorial, but you can see how he did it anyway
Thanks,
Azraton
Kai:
Think about what a massive gravitational force like a black hole does to the trajectories of light passing near it. The direction of light gets bent towards the center of the black hole.
If the light passes the black hole too near to its center, that light gets swallowed and becomes black (i.e. not visible to the viewer).
Knowing all this I'd simply render the scene environment (the stars and planets and galaxies) into a cubemap. Or maybe you have that already as some static environment texture.
Then you need a shader that will sample that cubemap texture using a lookup direction that is bent towards the black hole if the view direction passes near the black hole. Or simply render black if the view direction passes too close to the center of the black hole.
For this you also need some math, such as the shortest distance between a point (that black hole) and a ray (the light direction towards the eye) to determine how much bending needs to be applied.
That's it.
Azraton:
Thanks man :)
Exactly what I needed. :D
Azraton:
Could you give me a hint on what was the most effective method to bend the cubemap in the shader? Thanks, Azraton
Kai:
I don't know how much you know about cubemaps in OpenGL and about how to sample them.
If not much :) then look here. Especially the section "Texture Access."
I also don't know how much you know about linear algebra, vector spaces and coordinate systems in OpenGL.
To do the black hole thingy, you need to know about that stuff to compute the cubemap lookup vectors correctly.
That does not mean that you could not probably hack your way to get some approximation somehow, still, which would probably look just as believable. :)
Navigation
[0] Message Index
[#] Next page
Go to full version