private void OnEnable() { // Save initial settings in case we wish to restore them startSky = RenderSettings.skybox; // Save initial light settings if (directionalLight != null) { startLightColor = directionalLight.color; startLightRot = directionalLight.transform.rotation; startLightBrightness = directionalLight.intensity; UpdateDirectionalLight(); } probe.mode = UnityEngine.Rendering.ReflectionProbeMode.Custom; CameraResolution resolution = new CameraResolution(); resolution.nativeResolution = NativeResolutionMode.Smallest; resolution.resize = ResizeWhen.Never; captureCamera.Initialize(true, resolution, () => { if (map == null) { map = new CubeMapper(); map.Create(captureCamera.FieldOfView * stampFovMultiplier, mapResolution); map.StampExpireDistance = stampExpireDistance; } probe.customBakedTexture = map.Map; RenderSettings.skybox = map.SkyMaterial; RenderSettings.ambientMode = AmbientMode.Skybox; }); DynamicGI.UpdateEnvironment(); }
private void OnEnable() { // Save initial settings in case we wish to restore them startSky = RenderSettings.skybox; probe.mode = UnityEngine.Rendering.ReflectionProbeMode.Custom; CameraResolution resolution = new CameraResolution(); resolution.nativeResolution = NativeResolutionMode.Smallest; resolution.resize = ResizeWhen.Never; captureCamera.Initialize(true, resolution, () => { if (map == null) { map = new CubeMapper(); map.Create(captureCamera.FieldOfView * stampFovMultiplier, mapResolution); map.StampExpireDistance = stampExpireDistance; } probe.customBakedTexture = map.Map; RenderSettings.skybox = map.SkyMaterial; RenderSettings.ambientMode = AmbientMode.Skybox; }); }
private void OnGUI() { // Display create new options GUILayout.Label("Cubemap Creator", EditorStyles.boldLabel); resolution = Mathf.NextPowerOfTwo(EditorGUILayout.DelayedIntField("Cubemap Resolution", resolution)); if (GUILayout.Button("Create New")) { if (map != null) { map.Destroy(); } map = new CubeMapper(); map.Create(cam.FieldOfView, resolution); Stamp(); } // Stamping options GUILayout.Label("Options", EditorStyles.boldLabel); fovModifier = EditorGUILayout.Slider("Stamp FOV modifier", fovModifier, 1, 4); overrideGyro = EditorGUILayout.Toggle("Override gyro direction", overrideGyro); EditorGUI.BeginDisabledGroup(!overrideGyro); overrideDir = EditorGUILayout.Vector3Field("Override direction", overrideDir); EditorGUI.EndDisabledGroup(); // Display options for the current cubemap GUILayout.Label("Current cubemap", EditorStyles.boldLabel); if (map != null) { if (GUILayout.Button("Stamp from camera")) { Stamp(); } } // Show an interactive preview if we have one Rect r = EditorGUILayout.GetControlRect(GUILayout.ExpandHeight(true)); if (previewAsset != null) { if (previewEditor == null) { previewEditor = UnityEditor.Editor.CreateEditor(previewAsset); } previewEditor.OnInteractivePreviewGUI(r, previewStyle); } else { EditorGUI.DrawRect(r, new Color(0, 0, 0, 0.1f)); } }
/// <summary> Saves the cubemap as a 6x1 png file to the indicated file. Format is recognized by Unity automatically as a Cubemap. </summary> /// <param name="aMap">Cubemap to save.</param> /// <param name="aPath">Filename.</param> private static void SaveCubemap(Cubemap aMap, string aPath) { // Save the cubemap to file byte[] pngData = CubeMapper.CreateCubemapTex(aMap).EncodeToPNG(); File.WriteAllBytes(aPath, pngData); AssetDatabase.Refresh(); // Make sure it's marked as a cubemap Texture file = AssetDatabase.LoadAssetAtPath <Texture>(aPath); TextureImporter importer = (TextureImporter)AssetImporter.GetAtPath(aPath); if (file.dimension != UnityEngine.Rendering.TextureDimension.Cube) { importer.textureShape = TextureImporterShape.TextureCube; importer.SaveAndReimport(); } }