/// <summary> /// Setup the player for use in Third person mode. /// </summary> void SetupThirdPerson() { playerSettings.RemoteObjects.SetActive(true); weaponCamera.enabled = false; //active the current TP Weapon OnLocalChangeWeapon(playerNetwork.gunManager.GetCurrentGunID); bl_UCrosshair.Instance.fadeOnAim = false; playerNetwork.m_PlayerAnimation.useFootSteps = false; playerNetwork.m_PlayerAnimation.GetComponent <bl_BodyPartManager>().ActiveLocalRagdoll(false); #if UNITY_POST_PROCESSING_STACK_V2 if (weaponCameraEffects != null) { if (playerCameraEffects == null) { playerCameraEffects = playerCamera.GetComponent <PostProcessLayer>(); } if (playerCameraEffects == null) { playerCameraEffects = playerCamera.gameObject.AddComponent <PostProcessLayer>(); playerCameraEffects.Init(bl_CameraViewSettings.Instance.postProcessResources); playerCameraEffects.volumeLayer = weaponCameraEffects.volumeLayer; playerCameraEffects.antialiasingMode = weaponCameraEffects.antialiasingMode; playerCameraEffects.fastApproximateAntialiasing.fastMode = weaponCameraEffects.fastApproximateAntialiasing.fastMode; playerCameraEffects.volumeTrigger = playerCamera; } playerCameraEffects.enabled = true; weaponCameraEffects.enabled = false; } #endif }
public static void CopyCameraValues(Camera refCamera, Camera camera) { if (refCamera != null) { camera.farClipPlane = refCamera.farClipPlane; camera.nearClipPlane = Mathf.Clamp(refCamera.nearClipPlane, 0.01f, 0.02f); camera.clearFlags = refCamera.clearFlags; camera.backgroundColor = refCamera.backgroundColor; camera.tag = "MainCamera"; #if UNITY_POST_PROCESSING_STACK_V2 PostProcessLayer refPostProcessLayer = refCamera.GetComponent <PostProcessLayer>(); if (refPostProcessLayer != null) { PostProcessLayer postProcessLayer = camera.gameObject.AddComponent <PostProcessLayer>(); postProcessLayer.volumeLayer = refPostProcessLayer.volumeLayer; postProcessLayer.volumeTrigger = refPostProcessLayer.volumeTrigger != refPostProcessLayer.transform ? refPostProcessLayer.volumeTrigger : postProcessLayer.volumeTrigger = camera.transform; // post processing should always be enabled. // postProcessLayer.enabled = refPostProcessLayer.enabled; // Use reflection to copy over resources : https://github.com/Unity-Technologies/PostProcessing/issues/467 FieldInfo resourcesInfo = typeof(PostProcessLayer).GetField("m_Resources", BindingFlags.NonPublic | BindingFlags.Instance); PostProcessResources postProcessResources = resourcesInfo.GetValue(refPostProcessLayer) as PostProcessResources; postProcessLayer.Init(postProcessResources); } #endif refCamera.gameObject.SetActive(false); } }
static void OnPlayerCreate() { Camera camera = GameManager.playerCamera; PostProcessLayer layer = camera.gameObject.AddComponent <PostProcessLayer>(); layer.volumeTrigger = camera.transform; layer.volumeLayer = 1 << LayerMask.NameToLayer(postProcessLayer); layer.stopNaNPropagation = true; layer.antialiasingMode = PostProcessLayer.Antialiasing.FastApproximateAntialiasing; FastApproximateAntialiasing aa = new FastApproximateAntialiasing(); aa.fastMode = true; aa.keepAlpha = true; layer.fastApproximateAntialiasing = aa; // Fog fog = new Fog(); // fog.enabled = false; // layer.fog = fog; // layer.finalBlitToCameraTarget = true; layer.Init(instance.postProcessResources); }
void Start() { PostProcessLayer postProcessLayer = Camera.main.gameObject.GetComponent <PostProcessLayer>(); postProcessLayer.Init(postProcessResources); //postProcessLayer.volumeTrigger = Camera.main.transform; //postProcessLayer.volumeLayer = LayerMask.GetMask("RotationEffects"); //camera = transform.parent.gameObject; PostProcessVolume vol = transform.GetComponent <PostProcessVolume>(); vol.profile.TryGetSettings(out motionBlurLayer); }
void Start() { foreach (Camera camera in FindObjectsOfType <Camera>()) { PostProcessLayer postLayer = camera.GetComponent <PostProcessLayer>(); if (postLayer == null) { camera.allowHDR = true; camera.allowMSAA = false; postLayer = camera.gameObject.AddComponent <PostProcessLayer>(); postLayer.Init(resources); postLayer.volumeLayer = 1 << LayerMask.NameToLayer("PostProcessing"); postLayer.volumeTrigger = postLayer.transform; } } }
// add camera private unsafe void AddCamera() { if (enable_rendering == false) { Destroy(GameObject.Find("PreviewCamera")); } else { Destroy(GameObject.Find("DummyCamera")); } // add camera under root GameObject camobj = new GameObject("camera"); camobj.layer = LayerMask.NameToLayer("PostProcessing"); camobj.transform.parent = root.transform; Camera thecamera = camobj.AddComponent <Camera>(); Shader segshader = Shader.Find("Unlit/SegmentationColor"); SegmentationShader shadersub = camobj.AddComponent <SegmentationShader>(); GameObject pp_obj = GameObject.Find("PostPocessing"); PostProcessLayer pp_layer = camobj.AddComponent <PostProcessLayer>(); var resources = Resources.FindObjectsOfTypeAll <PostProcessResources>(); pp_layer.Init(resources[0]); pp_layer.volumeTrigger = camobj.transform; pp_layer.volumeLayer = 1 << LayerMask.NameToLayer("PostProcessing"); // set field of view, near, far MJP.TCamera cam; MJP.GetCamera(-1, &cam); thecamera.fieldOfView = cam.fov; thecamera.nearClipPlane = cam.znear * this.transform.localScale.x; thecamera.farClipPlane = cam.zfar * this.transform.localScale.x; thecamera.enabled = false; //camobj.SetActive(enable_rendering); // set transform MJP.TTransform transform; MJP.GetCameraState(-1, &transform); SetCamera(thecamera, transform); }
protected override IEnumerator OnInitCoroutine() { GameObject cameraObject = new GameObject("MainCamera"); GameObject.DontDestroyOnLoad(cameraObject); Camera camera = cameraObject.AddComponent <Camera>(); camera.clearFlags = CameraClearFlags.Skybox; camera.transparencySortMode = TransparencySortMode.Perspective; camera.fieldOfView = 60; camera.nearClipPlane = 0.3f; camera.farClipPlane = 1000; camera.depth = 0; camera.tag = "MainCamera"; cameraObject.AddComponent <FlareLayer>(); cameraObject.AddComponent <GUILayer>(); cameraObject.AddComponent <AudioListener>(); cameraObject.AddComponent <AmplifyOcclusionEffect>(); PostProcessLayer postProcessLayer = cameraObject.AddComponent <PostProcessLayer>(); if (postProcessLayer != null) { GameObject obj = GameObject.Find("PostProcessing"); if (obj == null) { Debug.LogError("There is not PostProcessing object in the scene!"); } else { var component = obj.GetComponent <PostProcessingRes>(); postProcessLayer.Init(component.Resources); postProcessLayer.volumeTrigger = cameraObject.transform; postProcessLayer.volumeLayer = LayerMask.GetMask("PostProcessing"); //postProcessLayer.ambientOcclusion.enabled = true; } } yield return(1); }
/// <summary> /// Enables the input profile for the currently rendering scene (menu, ksc, editor, tracking, flight, flight-map) /// </summary> /// <param name="profileName"></param> internal void enableProfile(string profileName) { currentProfile = null; Camera activeCam = getActiveCamera(); Log.debug("TUFX: enableProfile( " + profileName + " ) scene: ( " + HighLogic.LoadedScene + " ) map: ( " + isMapScene + " ) camera: ( " + activeCam?.name + " )"); Log.debug(System.Environment.StackTrace); if (previousCamera != activeCam) { Log.log("Detected change of active camera; recreating post-process objects."); if (volume != null) { Log.log("Destroying existing PostProcessVolume (from previous camera)."); Component.DestroyImmediate(layer); UnityEngine.Object.DestroyImmediate(volume.sharedProfile); UnityEngine.Object.DestroyImmediate(volume); layer = null; volume = null; } previousScene = HighLogic.LoadedScene; wasMapScene = isMapScene; previousCamera = activeCam; } Log.debug("Active Camera (hashcode): " + activeCam?.GetHashCode()); if (activeCam == null) { Log.log("Active camera was null. Skipping profile setup for scene: " + HighLogic.LoadedScene); } else if (!string.IsNullOrEmpty(profileName) && Profiles.ContainsKey(profileName)) { Log.log("Enabling profile: " + profileName + ". Current GameScene: " + HighLogic.LoadedScene); TUFXProfile tufxProfile = Profiles[profileName]; currentProfile = tufxProfile; Log.debug("Profile (hashcode): " + tufxProfile?.GetHashCode() + " :: " + tufxProfile?.ProfileName); Log.log("Setting HDR for camera: " + activeCam.name + " to: " + tufxProfile.HDREnabled); activeCam.allowHDR = tufxProfile.HDREnabled; onAntiAliasingSelected(tufxProfile.AntiAliasing, false); layer = activeCam.gameObject.AddOrGetComponent <PostProcessLayer>(); layer.Init(Resources); layer.volumeLayer = ~0;//everything //TODO -- fix layer assignment... Log.debug("Layer: " + layer?.GetHashCode()); volume = activeCam.gameObject.AddOrGetComponent <PostProcessVolume>(); volume.isGlobal = true; volume.priority = 100; Log.debug("Volume: " + volume.GetHashCode()); if (volume.sharedProfile == null) { volume.sharedProfile = tufxProfile.GetPostProcessProfile(); } else { volume.sharedProfile.settings.Clear(); tufxProfile.Enable(volume); } Log.log("Profile enabled: " + profileName); TUFXScatteringManager.INSTANCE.debugProfileSetup(volume, layer); } else if (string.IsNullOrEmpty(profileName)) { Log.log("Clearing current profile for scene: " + HighLogic.LoadedScene); } else { Log.exception("Profile load was requested for: " + profileName + ", but no profile exists for that name."); } }
//<summary> //Initializes the state at start //Grabs the default values and stores them into the appropriate variables //</summary> void Start() { //Set up the post processing on the camera #if UNITY_POST_PROCESSING_STACK_V1 if (gameObjects.mainCamera.GetComponent <PostProcessingBehaviour>() == null) { gameObjects.mainCamera.AddComponent <PostProcessingBehaviour>(); } postProcessing = gameObjects.mainCamera.GetComponent <PostProcessingBehaviour>(); #endif #if UNITY_POST_PROCESSING_STACK_V2 && UNITY_EDITOR if (gameObjects.mainCamera.GetComponent <PostProcessLayer>() == null) { EditorUtility.DisplayDialog("No Post Process Layer detected", "The camera object is missing a Post Process Layer and a Post Process Volume. In the Editor AQUAS will try to add them when entering play mode. However it is recommended that you add them manually before entering playmode, or else they will be missing in the build.", "Got It!"); gameObjects.mainCamera.AddComponent <PostProcessLayer>(); postProcessing2 = gameObjects.mainCamera.GetComponent <PostProcessLayer>(); PostProcessResources resources; if ((PostProcessResources)AssetDatabase.LoadAssetAtPath("Assets/PostProcessing-2/PostProcessing/PostProcessResources.asset", typeof(PostProcessResources)) != null) { resources = (PostProcessResources)AssetDatabase.LoadAssetAtPath("Assets/PostProcessing-2/PostProcessing/PostProcessResources.asset", typeof(PostProcessResources)); } else if ((PostProcessResources)AssetDatabase.LoadAssetAtPath("Assets/PostProcessing/PostProcessResources.asset", typeof(PostProcessResources)) != null) { resources = (PostProcessResources)AssetDatabase.LoadAssetAtPath("Assets/PostProcessing/PostProcessResources.asset", typeof(PostProcessResources)); } else if ((PostProcessResources)AssetDatabase.LoadAssetAtPath("Assets/PostProcessing-2/PostProcessResources.asset", typeof(PostProcessResources)) != null) { resources = (PostProcessResources)AssetDatabase.LoadAssetAtPath("Assets/PostProcessing-2/PostProcessResources.asset", typeof(PostProcessResources)); } else { EditorUtility.DisplayDialog("Could not locate Post Process Resource file.", "Please make sure your post processing folder is at the top level of the assets folder and named either 'PostProcessing' or 'PostProcessing-2'", "Got It!"); resources = null; } postProcessing2.Init(resources); postProcessing2.volumeTrigger = gameObjects.mainCamera.transform; postProcessing2.volumeLayer = LayerMask.NameToLayer("Everything"); } if (gameObjects.mainCamera.GetComponent <PostProcessVolume>() == null) { gameObjects.mainCamera.AddComponent <PostProcessVolume>(); gameObjects.mainCamera.GetComponent <PostProcessVolume>().isGlobal = true; } postProcessingVolume = gameObjects.mainCamera.GetComponent <PostProcessVolume>(); #endif #if UNITY_EDITOR #if UNITY_POST_PROCESSING_STACK_V1 || UNITY_POST_PROCESSING_STACK_V2 if (underWaterParameters.defaultProfile2 == null) { EditorUtility.DisplayDialog("WARNING! - Post default post processing profile missing!", "The post processing profiles in the inspector of the underwater camera effects are missing a default profile! It's not recommended to leave the default profile empty. If you don't want to use post processing while afloat, you can use a profile with all image effects disabled", "Got it!"); } #endif #endif waterLensAudio = gameObjects.waterLens.GetComponent <AudioSource>(); airLensAudio = gameObjects.airLens.GetComponent <AudioSource>(); audioComp = GetComponent <AudioSource>(); cameraAudio = gameObjects.mainCamera.GetComponent <AudioSource>(); bubbleBehaviour = gameObjects.bubble.GetComponent <AQUAS_BubbleBehaviour>(); //Set initially active lenses gameObjects.airLens.SetActive(true); gameObjects.waterLens.SetActive(false); //Assign materials //waterLensMaterial = gameObjects.waterLens.GetComponent<Renderer> ().material; airLensMaterial = gameObjects.airLens.GetComponent <Renderer> ().material; waterPlaneMaterial = gameObjects.waterPlanes[0].GetComponent <Renderer> ().material; t = wetLens.wetTime + wetLens.dryingTime; t2 = 0; bubbleSpawnTimer = 0; //Initialize default values for --- //--- global fog defaultFog = RenderSettings.fog; defaultFogDensity = RenderSettings.fogDensity; defaultFogColor = RenderSettings.fogColor; /*if (globalFog != null) * { * globalFog.enabled = defaultFog; * }*/ //--- Some water parameters defaultFoamContrast = waterPlaneMaterial.GetFloat("_FoamContrast"); defaultSpecularity = waterPlaneMaterial.GetFloat("_Specular"); if (waterPlaneMaterial.HasProperty("_Refraction")) { defaultRefraction = waterPlaneMaterial.GetFloat("_Refraction"); } #if UNITY_POST_PROCESSING_STACK_V1 postProcessing.profile = underWaterParameters.defaultProfile; #endif #if UNITY_POST_PROCESSING_STACK_V2 postProcessingVolume.profile = underWaterParameters.defaultProfile2; #endif audioComp.clip = soundEffects.sounds[0]; audioComp.loop = true; audioComp.Stop(); airLensAudio.clip = soundEffects.sounds[1]; airLensAudio.loop = false; airLensAudio.Stop(); waterLensAudio.clip = soundEffects.sounds[2]; waterLensAudio.loop = false; waterLensAudio.Stop(); //Check if Tenkoku is in the scene if (GameObject.Find("Tenkoku DynamicSky") != null) { tenkokuObj = GameObject.Find("Tenkoku DynamicSky"); } }