Unity Canon Portal: http://www.ceeger.com/Script/Camera/Camera.RenderToCubemap.html
Camera.rendertocubemap has 4 overloads
(1) bool Rendertocubemap (Cubemap Cubemap)
BOOL Rendertocubemap (Cubemap cubemap,int facemask)
can be used to generate a scene static cube map in the editor. Facemask is a bitfield bit number that indicates that the cubic map surface should be rendered, and each bit pair
Should be on one side. The number of bits is the integer value of the Cubemapface enumeration. All of the default six cubic map polygons are rendered (the low 6 bits of the default value of 63 are open).
1 //Render scene from a given point into a static cube map.2 //renders a scene from a given point to a static cubic map3 //Place the This script in Editor folder of your project.4 //place this script into the project's editor folder5 //Then use the cubemap with one of reflective shaders!6 //and use this cubic map with a reflective shaders.7 classRendercubemapwizard extends Scriptablewizard {8 varRenderfromposition:transform;9 varCubemap:cubemap;Ten One function Onwizardupdate () { Ahelpstring ="Select transform to render from and cubemap to render into"; -IsValid = (renderfromposition! =NULL) && (CubeMap! =NULL); - } the - function Onwizardcreate () { - //create temporary camera for rendering - //create a temporary camera for rendering + varGo =NewGameobject ("Cubemapcamera", Camera); - //Place it on the object + //put it on the object. AGo.transform.position =renderfromposition.position; atGo.transform.rotation =quaternion.identity; - - //render into CubeMap - //render to cubic map - Go.camera.RenderToCubemap (cubemap); - in //Destroy temporary camera - //destroying a temporary camera to destroyimmediate (go); + } - the@MenuItem ("Gameobject/render into Cubemap") * Staticfunction Rendercubemap () { $Scriptablewizard.displaywizard.<rendercubemapwizard>(Panax Notoginseng "Render cubemap","render!"); - } the}
(2)bool Rendertocubemap (rendertexture cubemap)
bool Rendertocubemap (rendertexture cubemap,int facemask)
This is used for real-time reflection to cubic map rendering textures. This is very time consuming, especially when all six cubic map polygons are rendered in each frame.
If rendering fails this function will return false, some graphics cards do not support this function.
Also, be sure to Rendertexture.iscubemap = True
1 usingUnityengine;2 usingSystem.Collections;3 usingUnityengine.ui;4 usingUnityeditor;5 6 //Attach This script to an object that uses a reflective shader.7 //Realtime Reflective cubemaps!8 //attach this script to an object that uses reflective shader9 //Real-time reflection cubic mapTen [Executeineditmode] One Public classRealtimecubemap:monobehaviour A { - intCubemapsize = -; - //one-frame rendering side the BOOLOnefaceperframe =false; -Camera cam =NULL; -Rendertexture CubeMap =NULL; -Material mat =NULL; + - voidStart () + { A //render all six faces at startup atUpdatecubemap ( the); - } - - voidlateupdate () - { - if(Onefaceperframe) in { - intFacetorender = time.framecount%6; to intFacemask =1<<Facetorender; + Updatecubemap (facemask); - } the Else * { $ //all six facesPanax NotoginsengUpdatecubemap ( the); - } the } + A the voidUpdatecubemap (intfacemask) + { - if(Cam = =NULL) $ { $Gameobject go =NewGameobject ("Cubemapcamera",typeof(Camera)); - - //hidden in the scene theGo.hideflags =Hideflags.hideanddontsave; -Go.transform.position =transform.position;WuyiGo.transform.rotation =quaternion.identity; theCam = go. Getcomponent<camera>(); - Wu ///do not render the farther part -Cam.farclipplane = -; Aboutcam.enabled =false; $ } - if(Mat = =NULL) - { -Mat =NewMaterial (Shader.find ("Custom/realtimecubemap")); AMat.hideflags =Hideflags.hideanddontsave; +Getcomponent<renderer> (). Material =Mat; the } - $ if(CubeMap = =NULL) the { theCubeMap =NewRendertexture (Cubemapsize, Cubemapsize, -); theCubemap.ispoweroftwo =true; theCubemap.iscubemap =true; -Cubemap.hideflags =Hideflags.hideanddontsave; inMat. SetTexture ("_cubemap", cubemap); the } the AboutCam.transform.position =transform.position; the Cam. Rendertocubemap (CubeMap, facemask); the } the + voidondisable () - { the destroyimmediate (CAM);Bayi destroyimmediate (cubemap); the } the -}
Unity3d Camera rendertocubemap rendering to cube textures