mrdoob / three.js

JavaScript 3D Library.
https://threejs.org/
MIT License
102.6k stars 35.36k forks source link

Mirror reflection of other objects #286

Closed tehbelinda closed 12 years ago

tehbelinda commented 13 years ago

I'm trying to create a reflective surface like a mirror that reflects everything else in a scene. I've got it working with an envmap and texturecube for the background of the scene, but not the other objects in the scene. I've been hunting around examples and such, but haven't been able to figure out how to map it.

So basically, is what I'm trying to do possible with three js at the moment...? If it is, any pointers would be much appreciated! Otherwise, I guess I'll give up for now...

mrdoob commented 13 years ago

You basically need to do 6 render (to render targets) and use these as a cubemap for the object you want to be reflective.

Sounds like a fun thing to hack :)

tehbelinda commented 13 years ago

Oh okay, could you offer some tips on how to implement that by any chance? :) I'll see what I can do...

aminnaggar commented 13 years ago

I'm interested as well. If you can give me tips on how to save my renders into a variable perhaps I can figure it out. Cheers

mrdoob commented 13 years ago

This may give you some pointers: http://www.mandreel.com/demos/sailboat/webgl/index.html

aminnaggar commented 13 years ago

WICKED ! Thank's I'll be figuring this out. Cheers

aminnaggar commented 13 years ago

On second thought. That code is very convoluted. I'll have to push it down my to do list. Thank's for the find though. Cheers

mrdoob commented 13 years ago

Yeah, the code is the opposite os readable, specially because it's compiled code. But on there you can see the tricks used (rendering the scene from under the plane, etc).

aminnaggar commented 13 years ago

(yea even with http://jsbeautifier.org/ it still looked horrible hehe).

I'm still trying to understand the idea behind it. (Also thank's for clarifying the camera is under the plane (I thought they just rotated everything :s ) .

I think for refraction they're rendering special objects that are only as high as the water (which is really smart, cuz there's less polygons to render)

Very cool stuff. Thank's again.

mrdoob commented 12 years ago

4d1dd95d62ff48b1842bf4e3fe0c393f5bd6f4d6