function RenderToCubemap (cubemap : Cubemap, faceMask : int = 63) : bool
Description
Render into a cubemap from this camera.
This is mostly useful in the editor for "baking" static cubemaps of your scene. See
wizard example below.
Camera's position, clear flags and clipping plane distances will be used to
render into cubemap faces. faceMask is a bitfield indicating which cubemap faces should be rendered into. Each
bit that is set corresponds to a face. Bit numbers are integer values of CubemapFace enum.
By default all six cubemap faces will be rendered (default value 63 has six lowest bits on).
This function will return false if rendering to cubemap fails. Some graphics hardware does not
support the functionality.
Note: This is a Unity PRO feature.
See Also: Cubemap assets, Reflective shaders.
class RenderCubemapWizard
extends ScriptableWizard {
var renderFromPosition :
Transform;
var cubemap :
Cubemap;
function OnWizardUpdate () {
helpString =
"Select transform to render from and cubemap to render into";
isValid = (renderFromPosition != null) && (cubemap != null);
}
function OnWizardCreate () {
var go =
new GameObject(
"CubemapCamera", Camera );
go.transform.position = renderFromPosition.position;
go.transform.rotation =
Quaternion.identity;
go.camera.RenderToCubemap( cubemap );
DestroyImmediate( go );
}
@
MenuItem(
"GameObject/Render into Cubemap")
static function RenderCubemap () {
ScriptableWizard.DisplayWizard.<RenderCubemapWizard>(
"Render cubemap",
"Render!");
}
}
function RenderToCubemap (cubemap : RenderTexture, faceMask : int = 63) : bool
Description
Render into a cubemap from this camera.
This is used for real-time reflections into cubemap render textures. It can be quite expensive though,
especially if all six cubemap faces are rendered each frame.
Camera's position, clear flags and clipping plane distances will be used to
render into cubemap faces. faceMask is a bitfield indicating which cubemap faces should be rendered into. Each
bit that is set corresponds to a face. Bit numbers are integer values of CubemapFace enum.
By default all six cubemap faces will be rendered (default value 63 has six lowest bits on).
This function will return false if rendering to cubemap fails. Some graphics hardware does not
support the functionality.
Note: This is a Unity PRO feature.
See Also: RenderTexture.isCubemap, Reflective shaders.
@script ExecuteInEditModevar cubemapSize = 128;
var oneFacePerFrame =
false;
private var cam : Camera;
private var rtex :
RenderTexture;
function Start () {
UpdateCubemap( 63 );
}
function LateUpdate () {
if (oneFacePerFrame) {
var faceToRender =
Time.frameCount % 6;
var faceMask = 1 << faceToRender;
UpdateCubemap (faceMask);
}
else {
UpdateCubemap (63); }
}
function UpdateCubemap (faceMask :
int) {
if (!cam) {
var go =
new GameObject (
"CubemapCamera", Camera);
go.hideFlags =
HideFlags.HideAndDontSave;
go.transform.position = transform.position;
go.transform.rotation =
Quaternion.identity;
cam = go.camera;
cam.farClipPlane = 100; cam.enabled =
false;
}
if (!rtex) {
rtex =
new RenderTexture (cubemapSize, cubemapSize, 16);
rtex.isPowerOfTwo = true;
rtex.isCubemap = true;
rtex.hideFlags =
HideFlags.HideAndDontSave;
renderer.sharedMaterial.SetTexture (
"_Cube", rtex);
}
cam.transform.position = transform.position;
cam.RenderToCubemap (rtex, faceMask);
}
function OnDisable () {
DestroyImmediate (cam);
DestroyImmediate (rtex);
}