예제 #1
0
        void Update_FadingToScene()
        {
            Environment.RenderSettingsLite rDesired = m_DesiredEnvironment.m_RenderSettings;

            if (m_HasCustomLights)
            {
                rDesired.m_AmbientColor = LightsControlScript.m_Instance.m_EnvLights[0].color;
            }

            if (m_SkipFade)
            {
                m_TransitionValue = 1.0f;
            }
            else
            {
                m_TransitionValue += (m_TransitionSpeed * Time.deltaTime);
                m_TransitionValue  = Mathf.Min(m_TransitionValue, 1.0f);
            }

            //fade in scene
            m_InterimValues.m_ClearColor   = Color.Lerp(m_CurrentValues.m_ClearColor, rDesired.m_ClearColor, m_TransitionValue);
            m_InterimValues.m_AmbientColor = Color.Lerp(m_CurrentValues.m_AmbientColor, rDesired.m_AmbientColor, m_TransitionValue);
            m_InterimValues.m_FogColor     = Color.Lerp(m_CurrentValues.m_FogColor,
                                                        m_LoadingCustomEnvironment ? m_CustomFogColor : rDesired.m_FogColor, m_TransitionValue);
            m_InterimValues.m_ReflectionIntensity = Mathf.Lerp(m_CurrentValues.m_ReflectionIntensity,
                                                               m_LoadingCustomEnvironment ? m_CustomReflectionIntensity : rDesired.m_ReflectionIntensity, m_TransitionValue);
            m_InterimValues.m_SkyboxTint = Color.Lerp(m_CurrentValues.m_SkyboxTint, rDesired.m_SkyboxTint, m_TransitionValue);

            //fade in lights
            for (int i = 0; i < m_TransitionLights.Count; ++i)
            {
                m_TransitionLights[i].LerpCurrentToDesired(m_TransitionValue);
            }

            //fade in custom shader values
            Shader.SetGlobalFloat("_SceneFadeAmount", m_TransitionValue);

            //tint the skybox if it's valid
            if (RenderSettings.skybox)
            {
                RenderSettings.skybox.SetColor("_Tint", m_InterimValues.m_SkyboxTint);
                RenderSettings.skybox.SetColor("_ColorA", Color.Lerp(Color.black, m_SkyColorA, m_TransitionValue));
                RenderSettings.skybox.SetColor("_ColorB", Color.Lerp(Color.black, m_SkyColorB, m_TransitionValue));
            }

            if (m_TransitionValue >= 1.0f)
            {
                m_CurrentState  = TransitionState.Scene;
                m_CurrentValues = rDesired;
                FogDensity      = m_LoadingCustomEnvironment ? m_CustomFogDensity : rDesired.m_FogDensity;
                if (RenderSettings.skybox)
                {
                    RenderSettings.skybox.SetColor("_ColorA", m_SkyColorA);
                    RenderSettings.skybox.SetColor("_ColorB", m_SkyColorB);
                }
                m_LoadingCustomEnvironment = false;
                m_CurrentEnvironment       = m_DesiredEnvironment;
            }
        }
예제 #2
0
        /// If forceTransition, perform the fade-to-black-and-back even if the
        /// requested environment is the same.
        /// If keepTransforms, don't reset the canvas or scene transforms.
        public void SetDesiredPreset(
            Environment env,
            bool forceTransition    = false,
            bool keepSceneTransform = false,
            bool hasCustomLights    = false,
            bool skipFade           = false)
        {
            m_SkipFade = skipFade;
            if (m_RequestInstantSceneSwitch > 0)
            {
                m_SkipFade = true;
            }
            bool bEnvironmentModified =
                LightsControlScript.m_Instance.LightsChanged || SceneSettings.m_Instance.EnvironmentChanged;

            if (env == null)
            {
                Debug.Log("null environment");
            }
            else if (env == m_DesiredEnvironment && !bEnvironmentModified &&
                     !hasCustomLights && !m_LoadingCustomEnvironment && !forceTransition)
            {
                // same environment and lights not changed; but make sure we inhibit scene reset if requested
                m_InhibitSceneReset = keepSceneTransform;
            }
            else
            {
                m_HasCustomLights = hasCustomLights;

                if (!m_LoadingCustomEnvironment)
                {
                    InGradient = (CurrentEnvironment == null) ? false :
                                 (env.m_RenderSettings.m_SkyboxCubemap == null);
                    m_CustomFogColor = env.m_RenderSettings.m_FogColor;
                    m_SkyColorA      = env.m_SkyboxColorA;
                    m_SkyColorB      = env.m_SkyboxColorB;
                    m_GradientSkew   = Quaternion.identity;
                }

                m_DesiredEnvironment = env;
                m_CurrentValues      = m_InterimValues;
                m_TransitionValue    = 0.0f;
                m_CurrentState       = TransitionState.FadingToBlack;
                m_InhibitSceneReset  = keepSceneTransform;

                if (FadingToDesiredEnvironment != null)
                {
                    FadingToDesiredEnvironment();
                }
            }
        }
예제 #3
0
        void CreateEnvironment(Environment.RenderSettingsLite env)
        {
            //change lightning environment if requested is different from current
            if (m_RoomGeometryName != env.m_EnvironmentPrefab)
            {
                Destroy(m_RoomGeometry);
                Destroy(m_RoomReverbZone);
                GameObject rNewEnvironment = Resources.Load <GameObject>(env.m_EnvironmentPrefab);
                if (rNewEnvironment != null)
                {
                    m_RoomGeometry = Instantiate(rNewEnvironment);
                    Transform t = m_RoomGeometry.transform;
                    Debug.Assert(TrTransform.FromTransform(t) == TrTransform.identity);
                    t.SetParent(App.Instance.m_EnvironmentTransform, false);

                    // Create reverb zone but do not set its parent.  It should live in room space.
                    GameObject rNewReverbZone = Resources.Load <GameObject>(env.m_EnvironmentReverbZonePrefab);
                    m_RoomReverbZone = Instantiate(rNewReverbZone);

                    // Construct lists of objects that are only in low or only in high LOD.
                    m_EnvironmentObjectsLowLOD  = new List <GameObject>();
                    m_EnvironmentObjectsHighLOD = new List <GameObject>();
                    foreach (Transform child in m_RoomGeometry.transform)
                    {
                        if (IsLowLod(child))
                        {
                            m_EnvironmentObjectsLowLOD.Add(child.gameObject);
                        }
                        else if (IsHighLod(child))
                        {
                            m_EnvironmentObjectsHighLOD.Add(child.gameObject);
                        }
                    }
                }
                else
                {
                    // Clear LOD lists and room geo reference
                    m_RoomGeometry              = null;
                    m_RoomReverbZone            = null;
                    m_EnvironmentObjectsLowLOD  = new List <GameObject>();
                    m_EnvironmentObjectsHighLOD = new List <GameObject>();
                }
                // for b/37256058: crash seems to happen between this and the intro sketch load
                System.Console.WriteLine("Setenv: Unload 1");
                Resources.UnloadUnusedAssets();
                System.Console.WriteLine("Setenv: Unload 2");
                m_RoomGeometryName = env.m_EnvironmentPrefab;
            }
        }
예제 #4
0
  void Transition_FadingBlackToFadingScene() {
    Environment.RenderSettingsLite rDesired = m_DesiredEnvironment.m_RenderSettings;

    m_CurrentValues = m_InterimValues;
    m_InterimValues.m_FogEnabled = rDesired.m_FogEnabled;
    m_InterimValues.m_FogMode = rDesired.m_FogMode;
    FogDensity = m_LoadingCustomEnvironment ? m_CustomFogDensity :
      rDesired.m_FogDensity;
    RenderSettings.fogStartDistance = rDesired.m_FogStartDistance;
    RenderSettings.fogEndDistance = rDesired.m_FogEndDistance;
    m_TransitionValue = 0.0f;

    //create as many lights as will be in the scene and prep them to fade in
    m_TransitionLights.Clear();
    List<Environment.Light> aLights = m_DesiredEnvironment.m_Lights;
    for (int i = 0; i < aLights.Count; ++i) {
      LightTransition rNewTransition = new LightTransition();
      rNewTransition.m_DesiredValues = aLights[i];
      rNewTransition.m_InterimValues.m_Type = aLights[i].m_Type;
      rNewTransition.m_InterimValues.m_ShadowsEnabled = aLights[i].m_ShadowsEnabled;
      rNewTransition.m_InterimValues.m_Position = aLights[i].m_Position;
      rNewTransition.m_InterimValues.m_Rotation = aLights[i].m_Rotation;
      if (m_HasCustomLights) {
        rNewTransition.m_DesiredValues.Color = LightsControlScript.m_Instance.m_EnvLights[i + 1].color;
        rNewTransition.m_DesiredValues.m_Rotation = LightsControlScript.m_Instance.m_EnvLights[i + 1].rotation;
        rNewTransition.m_InterimValues.m_Rotation = LightsControlScript.m_Instance.m_EnvLights[i + 1].rotation;
      }
      m_TransitionLights.Add(rNewTransition);
    }

    // Create geometry and reverb zone for new environment.
    CreateEnvironment(rDesired);

    // Set the reflection cubemap
    RenderSettings.customReflection = rDesired.m_ReflectionCubemap;
    if (!m_LoadingCustomEnvironment) {
      if (rDesired.m_SkyboxCubemap) {
        RenderSettings.skybox = m_DesiredEnvironment.m_SkyboxMaterial;
        RenderSettings.skybox.SetColor("_Tint", Color.black);
        RenderSettings.skybox.SetFloat("_Exposure", rDesired.m_SkyboxExposure);
        RenderSettings.skybox.SetTexture("_Tex", rDesired.m_SkyboxCubemap);
      } else {
        InGradient = true;
        if (!m_FadingOutGradient) {
          RenderSettings.skybox = Instantiate(m_SkyboxMaterial);
        }
        if (RenderSettings.skybox != null) {
          RenderSettings.skybox.SetVector("_GradientDirection", Vector3.up);
        }
      }
    } else {
      if (!m_InGradient) {
        RenderSettings.skybox = m_DesiredEnvironment.m_SkyboxMaterial;
        RenderSettings.skybox.SetColor("_Tint", Color.black);
        RenderSettings.skybox.SetFloat("_Exposure", rDesired.m_SkyboxExposure);
        RenderSettings.skybox.SetTexture("_Tex", rDesired.m_SkyboxCubemap);
      } else if (!m_FadingOutGradient) {
        InGradient = true;
      }
    }

    // Fire off messages that say 'everything changed!'
    TriggerFogDensityChanged();
    TriggerFogColorChanged();
    TriggerSkyboxChanged();

    m_TeleportBoundsHalfWidth = m_DesiredEnvironment.m_TeleportBoundsHalfWidth;
    m_ControllerXRayHeight = m_DesiredEnvironment.m_ControllerXRayHeight;

    if (!m_InhibitSceneReset) {
      // Ugh. Can we do something better than this?
      // Maybe ask the teleport tool to enforce proper bounds (since it knows how)
      // instead of teleporting back to the origin? Then we could kill the hacky
      // m_InhibitSceneReset API.
      App.Scene.Pose = TrTransform.identity;
    }

    WidgetManager.m_Instance.SetHomePosition(m_DesiredEnvironment.m_WidgetHome);

    m_FadingOutGradient = false;

    m_CurrentState = TransitionState.FadingToScene;
  }
예제 #5
0
        private static void ExportEnvironments()
        {
#if !GAMEOBJ_EXPORT_TO_GLTF
            Debug.LogError("Enable the define and fix up the code");
#else
            // Save the original RenderSettings
            Environment.RenderSettingsLite originalRenderSettings = Environment.GetRenderSettings();

            // Clear out the existing environments directory to do a clean export
            string projectPath           = Path.GetDirectoryName(Application.dataPath);
            string environmentExportPath = Path.Combine(projectPath,
                                                        ExportUtils.kProjectRelativeEnvironmentExportRoot);
            try {
                Directory.Delete(environmentExportPath, recursive: true);
            } catch (DirectoryNotFoundException) {
                // It's okay if this directory doesn't exist yet as it will be created later.
            }

            // Clear out the existing textures directory to do a clean export
            string textureExportPath = Path.Combine(projectPath,
                                                    ExportUtils.kProjectRelativeTextureExportRoot);
            try {
                Directory.Delete(textureExportPath, recursive: true);
            } catch (DirectoryNotFoundException) {
                // It's okay if this directory doesn't exist yet as it will be created later.
            }
            if (!FileUtils.InitializeDirectoryWithUserError(
                    textureExportPath, "Failed to export, can't create texture export directory"))
            {
                return;
            }

            // Get the environment
            TiltBrushManifest manifest = AssetDatabase.LoadAssetAtPath <TiltBrushManifest>("Assets/Manifest.asset");
            foreach (Environment env in manifest.Environments)
            {
                // Copy over the RenderSettings
                Environment.SetRenderSettings(env.m_RenderSettings);

                // Set up the environment
                string envGuid = env.m_Guid.ToString("D");
                Debug.LogFormat("Exporting environment: {0}", env.m_RenderSettings.m_EnvironmentPrefab);
                GameObject envPrefab     = Resources.Load <GameObject>(env.m_RenderSettings.m_EnvironmentPrefab);
                GameObject envGameObject = UObject.Instantiate(envPrefab);
                envGameObject.name = envGuid;

                // Hide game objects that don't get exported to Poly.
                foreach (Transform child in envGameObject.transform)
                {
                    if (SceneSettings.ExcludeFromPolyExport(child))
                    {
                        child.gameObject.SetActive(false);
                    }
                }

                // Set up the environment export directory
                string directoryName = Path.Combine(environmentExportPath, envGuid);
                if (!FileUtils.InitializeDirectoryWithUserError(
                        directoryName, "Failed to export, can't create environment export directory"))
                {
                    return;
                }

                string basename = FileUtils.SanitizeFilename(envGameObject.name);
                string gltfName = Path.Combine(directoryName, basename + ".gltf");

                var exporter = new ExportGlTF();
                exporter.ExportGameObject(envGameObject, gltfName, env);

                // DestroyImmediate is required because editor mode never runs object garbage collection.
                UObject.DestroyImmediate(envGameObject);
            }

            // Restore the original RenderSettings
            Environment.SetRenderSettings(originalRenderSettings);
#endif
        }