I’m rather illiterate when it comes to scripting, so all I can really do is “Frankenstein” bits from other scripts together. I’ve been trying to modify the camera script for the RTT water reflections just to get the proper camera position. The only problem I’m having is that the reflection camera is rendered to a small square in the bottom left of the screen. Since I’m not using it as a texture, it doesn’t need to be a little square, but I don’t know how to tell it that.
I’m guessing - and this is wild speculation - that the best way to do reflections without RTT would be similar to what Yoggy did in the Portals project,which was a very clever way to render directly to the screen, but only to a certain area (through the portal). I honestly don’t understand how he did it, but it could work for this.
Alternately, in your 3D app, you could just cut your level mesh in half at the wter’s plane, flip it, and make it semitransparent.
I’m using something similar to Yoggy’s portal technique (using the same shader in fact). What it does is make the “portal” object render as background, so you can use multiple cameras rendering the same scene from different angles.
I’ve taken the reflection camera script from a RTT setup and altered it a little to work for this purpose, but I can’t figure out how to make it not constrained to a small square at the bottom left of the screen.
I believe the script you’re referring to creates a camera at runtime, correct? This is probably an issue with the viewport rect - start up the game, pause it, and check the camera’s rect parameters. If they’re not (0,0,1,1), that’s probably the issue.
Of course, I’m not working with the project myself, so this is still more wild-ish speculation. Good job on getting that trick working so quick, though!
It may be completely defeating the point here … but wouldn’t it be easier to have a mirrored duplicate of all your objects and reflect their y coordinates and set the groundplane to partially transparant … now that’s oldschool. This way it doesn’t require render to texture and will give lovely fake reflections on non-pro version.
We did the copy&mirror hack for an old 24-hour game we did for a party. Worked great! It was a plane sim - the reflection gave a perfect serene fly-at-night over New York Bay.
We could also optimize by only mirroring large objects in the scene.
But that would only reflect the landscape, nothing active or moving above the water. Putting a scripted camera there is not a particularly hard thing to do, and if we can get one on the wiki, even better…
It will only reflect the landscape if you only create a copy of the landscape … but if you create duplicate objects for everything then you can assign scripts to them to mimic the movement of their doppelgangers.
In some situations this method can create a more flexible solution than render to texture as it can allow the reflected scene to be an ‘twisted reality’ where the reflection doesn’t have to be an exact copy of the main scene. For instance you may wish to create a good and evil parallel worlds and flip through the ‘reflection’ to move between them.
Okay, if I knew how to write a script to make something mimic, upside-down, the translation and rotation of another object relative to a plane object I’d just put it on the camera. The only reason I tried modifying the RTT script is because it seemed like a good jumping-off point for what I wanted to do. If someone could point me to a “mimic” script, I’d be very grateful.
var OrigTrans:Tranform//<--Remember set via Inspector
function Update(){
transform.x = OrigTrans.x
transform.y = -OrigTrans.y
transform.z = OrigTrans.z
}
/* This means anytime the OrignalGameObj moves the ReflectionGameObject will move with it. This is good for Reflection on the ground. If you want it on the wall you have to put the '-' on ether the .x or the .z depending on which way the wall faces.
*/
OK … I had a little play with the idea of just having a duplicate camera and no duplicate objects. This approach could only work if you assume a single flat refelective groundplane.
Roughly … set up a second camera … turn it upside down and place it at the same height below the plane of relection as the main camera is above it. Set the camera depth of the ‘refelction’ camera to -2 so its drawn first and set the clear flags of the main camera to depth only.
Only problem is now we need to flip the reflected image horizontally to get everything right … but it appears that there’s no option to do this. I tried swapping Xmin and Xmax in the normalised viewport rect, which flips the view but also appears to have the effect of turning all the normals inside out in the reflected view … close but no cigar.
The documentation for the camera says “This can create multiple mini-views like missile cams, map views, rear-view mirrors, etc.” … however without any way of flipping the view in the x axis then the rear-view mirror cannot be achieved. OTEE, am I missing something here ? … it appears that the addition of a couple of flags in the camera class to flip in x y could be useful.
Anyhow, I’ve attached the package for the flipped normal version … move the cube around in the editor to see the mirrored flipped normal cube move as well. There’s only one cube in the scene.
Something terribly odd happened. I took the modified RTT camera script I made and used it in a new scene that wasn’t already set-up for RTT (I had been using the original grass example scene), and it worked. I don’t know why it didn’t work before or why it works now, but it does.
My latest test scene with 2 non-RTT reflection planes:
Also, the idea occurred that the “twisted reality” thing could be done easier by using a flipped camera that renders objects on a different layer.
Okay, so I’ve included a unity package. The code is probably incredibly inefficient, so use with caution. If anyone can tell me how to improve it I’d really appreciate it.