Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class FakeRenderCubemapFace : MonoBehaviour {
- private Texture2D texture;
- public Cubemap cubemap;
- public CubemapFace cubemapFace;
- public float updateFrequency = .5f;
- private float lastUpdate = 0f;
- private Rect sourceRect;
- // Use this for initialization
- void Start() {
- float x = 0;
- float y = cubemap.height;
- if (cubemapFace == CubemapFace.PositiveZ) {
- x = cubemap.width;
- }
- if (cubemapFace == CubemapFace.PositiveX) {
- x = cubemap.width * 2;
- }
- if (cubemapFace == CubemapFace.NegativeZ) {
- x = cubemap.width * 3;
- }
- if (cubemapFace == CubemapFace.PositiveY) {
- y = cubemap.width * 2;
- }
- if (cubemapFace == CubemapFace.NegativeY) {
- y = 0;
- }
- texture = new Texture2D (cubemap.width, cubemap.height);
- sourceRect = new Rect (x, y, cubemap.width, cubemap.height);
- camera.pixelRect = sourceRect;
- }
- void Update() {
- if (Time.time > lastUpdate + updateFrequency) {
- camera.enabled = true;
- lastUpdate = Time.time;
- }
- }
- void OnPostRender() {
- texture.ReadPixels (sourceRect, 0, 0);
- cubemap.SetPixels (texture.GetPixels (), cubemapFace);
- camera.enabled = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment