Author Topic: dynamic Reflection?  (Read 2118 times)

Offline buffonomics

  • byte
  • *
  • Posts: 4
    • View Profile
dynamic Reflection?
« on: February 26, 2013, 02:41:22 am »
I'm curious, is it possible to achieve real-time dynamic reflection? perhaps via GLSL shaders?
I'm pretty new to shaders in general. Still reading up on them.
But say I wanted to make a chrome ball that reflects everything around it real time, What shaders would I attach to that sphere?

Thanks.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: dynamic Reflection?
« Reply #1 on: February 26, 2013, 08:01:11 pm »
You can't do that with a shader alone. Shaders can't access anything outside of their own context, i.e. they can access a mesh's vertex and texturing information, but they can't access the framebuffer (except from writing into it, of course). So for reflections, you would have to render the scene to reflect in textures and map them onto the mesh. In theory, this can be done by using cube mapping (which jPCT doesn't support), but you would have to render the scene 6 times for the cube map alone, which is pretty expensive. It's usually simpler to create a spherical environment map from some static image and apply this as faked reflection. jPCT supports this: http://www.jpct.net/doc/com/threed/jpct/Object3D.html#setEnvmapped(boolean)

Offline buffonomics

  • byte
  • *
  • Posts: 4
    • View Profile
Re: dynamic Reflection?
« Reply #2 on: February 27, 2013, 09:43:46 pm »
Being a complete noob, how will I go about generating this image to use as an envmap texture?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: dynamic Reflection?
« Reply #3 on: February 28, 2013, 07:12:17 am »
The easiest (albeit not "correct" way) is to take some random image and apply a spherical distortion filter on it in the image editor of choice. While the result isn't really spherical environment map, it should look good enough in most cases. Another option is to download a free one. Just search for "environment map" and look at the results that show a sphere with an image projected onto it.