Version: 2017.3
public bool RenderToCubemap (Cubemap cubemap, int faceMask= 63);

パラメーター

cubemap レンダリングするキューブマップ
faceMask 6つの面のどの面をレンダリングするか確定するビットマスク

戻り値

bool False if rendering fails, else true.

説明

このカメラから静的のキューブマップにレンダリングします。

This function is mostly useful in the editor for "baking" static cubemaps of your scene. See wizard example below. If you want a realtime-updated cubemap, use RenderToCubemap variant that uses a RenderTexture with a cubemap dimension, see 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.

リフレクションプローブはリアルタイム反射を実行するうえで、より高度な方法であることも頭に入れておきましょう。キューブマップは Create->Legacy オプションを選択することでエディターで作成することができます。

See Also: Cubemap assets, Reflective shaders.

using UnityEngine;
using UnityEditor;
using System.Collections;

public class RenderCubemapWizard : ScriptableWizard { public Transform renderFromPosition; public Cubemap cubemap;

void OnWizardUpdate() { string helpString = "Select transform to render from and cubemap to render into"; bool isValid = (renderFromPosition != null) && (cubemap != null); }

void OnWizardCreate() { // create temporary camera for rendering GameObject go = new GameObject("CubemapCamera"); go.AddComponent<Camera>(); // place it on the object go.transform.position = renderFromPosition.position; go.transform.rotation = Quaternion.identity; // render into cubemap go.GetComponent<Camera>().RenderToCubemap(cubemap);

// destroy temporary camera DestroyImmediate(go); }

[MenuItem("GameObject/Render into Cubemap")] static void RenderCubemap() { ScriptableWizard.DisplayWizard<RenderCubemapWizard>( "Render cubemap", "Render!"); } }

public bool RenderToCubemap (RenderTexture cubemap, int faceMask= 63);

パラメーター

faceMask キューブマップの各面にレンダリングされるべきかを示すビットフィールド
cubemap レンダリングするテクスチャ

戻り値

bool False if rendering fails, else true.

説明

このカメラからキューブマップにレンダリングします。

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.

The 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.

RenderTexture は isCubemap を true に設定されている必要があります。これは以下の例で説明します。

関連項目: RenderTexture.isCubemap、Reflective shaders.

// Attach this script to an object that uses a Reflective shader.
// Realtime reflective cubemaps!

@script ExecuteInEditMode

var cubemapSize = 128; var oneFacePerFrame = false; private var cam : Camera; private var rtex : RenderTexture;

function Start () { // render all six faces at startup UpdateCubemap( 63 ); }

function LateUpdate () { if (oneFacePerFrame) { var faceToRender = Time.frameCount % 6; var faceMask = 1 << faceToRender; UpdateCubemap (faceMask); } else { UpdateCubemap (63); // all six faces } }

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.GetComponent.<Camera>(); cam.farClipPlane = 100; // don't render very far into cubemap cam.enabled = false; }

if (!rtex) { rtex = new RenderTexture (cubemapSize, cubemapSize, 16); rtex.dimension = UnityEngine.Rendering.TextureDimension.Cube; rtex.hideFlags = HideFlags.HideAndDontSave; GetComponent.<Renderer>().sharedMaterial.SetTexture ("_Cube", rtex); }

cam.transform.position = transform.position; cam.RenderToCubemap (rtex, faceMask); }

function OnDisable () { DestroyImmediate (cam); DestroyImmediate (rtex); }