/// <summary> /// Fills the current chroma keys with the data from a file. /// </summary> public void LoadGreenScreenData(bool forcegarbagemate = false) { GreenScreenData gsData; if (LoadData(out gsData)) { ChromaKeyData chromaKeyData = gsData.chromaKeyData; garbageMatteData = gsData.garbageMatteData; erosion = chromaKeyData.erosion; sigma_ = chromaKeyData.blurPower; numberBlurIterations = chromaKeyData.numberBlurIterations; whiteClip = chromaKeyData.whiteClip; blackClip = chromaKeyData.blackClip; spill = chromaKeyData.spill; keyColors = chromaKeyData.chromaKeys.color; smoothness = chromaKeyData.chromaKeys.smoothness; range = chromaKeyData.chromaKeys.range; } UpdateShader(); if (forcegarbagemate && garbageMatte != null) { if (!garbageMatte.IsInit) { garbageMatte = new GarbageMatte(GetComponent <Camera>(), finalMat, transform, garbageMatte); } enableGarbageMatte = true; garbageMatte.LoadData(gsData.garbageMatteData); garbageMatte.ApplyGarbageMatte(); } }
private void Awake() { //cameraManager = gameObject.GetComponent<ZEDManager> (); Shader.SetGlobalInt("_ZEDStencilComp", 0); if (screen == null) { screen = gameObject.transform.GetChild(0).gameObject; finalMat = screen.GetComponent <Renderer>().material; } if (enableGarbageMatte) { garbageMatte = new GarbageMatte(cameraManager, finalMat, transform, garbageMatte); } #if ZED_LWRP || ZED_HDRP cam = GetComponent <Camera>(); if (!cam) { Debug.LogError("GreenScreenManager is not attached to a Camera."); } RenderPipelineManager.beginCameraRendering += OnSRPPreRender; #endif #if !UNITY_EDITOR Debug.Log("Load Chroma keys"); LoadGreenScreenData(); UpdateShader(); CreateFileWatcher(""); #endif }
private void Update() { if (screenManager != null && !textureOverlayInit) //Need to tell the shader to apply the mask. { if (screenManager.ManageKeywordForwardMat(true, "DEPTH_ALPHA")) { textureOverlayInit = true; } } if (toUpdateConfig) //Need to load available greenscreen configuration data into the current, active data. { toUpdateConfig = false; LoadGreenScreenData(); } if (enableGarbageMatte) //Set up the garbage matte if needed. { if (garbageMatte != null && garbageMatte.IsInit) { garbageMatte.Update(); } else { garbageMatte = new GarbageMatte(GetComponent <Camera>(), finalMat, transform, garbageMatte); } } }
private void Update() { if (screenManager != null && !textureOverlayInit) { if (screenManager.ManageKeyWordForwardMat(true, "DEPTH_ALPHA")) { textureOverlayInit = true; } } if (toUpdateConfig) { toUpdateConfig = false; LoadGreenScreenData(); } if (enableGarbageMatte) { if (garbageMatte != null && garbageMatte.IsInit) { garbageMatte.Update(); } else { garbageMatte = new GarbageMatte(GetComponent <Camera>(), finalMat, transform, garbageMatte); } } }
/// <summary> /// Sets up the greenscreen with saved data. /// Used exclusively by ZEDSteamVRControllerManager to make sure this happens after controllers are set up. /// Otherwise, included logic gets set elsewhere in different places. /// </summary> public void PadReady() { if (garbageMatteData.numberMeshes != 0 && garbageMatte != null) { if (enableGarbageMatte) { garbageMatte = new GarbageMatte(GetComponent <Camera>(), finalMat, transform, garbageMatte); } garbageMatte.LoadData(garbageMatteData); } }
/// <summary> /// Constructor that sets up the garbage matte for the desired camera in the desired place. /// </summary> /// <param name="cam">Camera in which to apply the matte effect</param> /// <param name="greenScreenMaterial">Material reference, usually Mat_ZED_Greenscreen</param> /// <param name="target">Center location of the matte effect</param> /// <param name="matte">Optional reference to another garbage matte, used to copy its current edit mode. </param> public GarbageMatte(Camera cam, Material greenScreenMaterial, Transform target, GarbageMatte matte) { this.target = target; currentPlaneIndex = 0; zed = sl.ZEDCamera.GetInstance(); this.cam = cam; points.Clear(); outlineMaterial = Resources.Load("Materials/Mat_ZED_Outlined") as Material; go = new List <GameObject>(); meshFilters = new List <MeshFilter>(); shader_greenScreen = greenScreenMaterial; ResetPoints(false); if (matte != null) { editMode = matte.editMode; } if (commandBuffer == null) { //Create a command buffer to clear the depth and stencil commandBuffer = new CommandBuffer(); commandBuffer.name = "GarbageMatte"; commandBuffer.SetRenderTarget(BuiltinRenderTextureType.CurrentActive, BuiltinRenderTextureType.Depth); //Remove the previous command buffer to set the garbage matte first CommandBuffer[] cmd = cam.GetCommandBuffers(CameraEvent.BeforeDepthTexture); cam.RemoveCommandBuffers(CameraEvent.BeforeDepthTexture); if (cmd.Length > 0) { cam.AddCommandBuffer(CameraEvent.BeforeDepthTexture, commandBuffer); for (int i = 0; i < cmd.Length; ++i) { cam.AddCommandBuffer(CameraEvent.BeforeDepthTexture, cmd[i]); } } } if (loadAtStart && Load()) { Debug.Log("Config garbage matte found, and loaded ( " + garbageMattePath + " )"); ApplyGarbageMatte(); editMode = false; } isInit = true; }
private void Awake() { Shader.SetGlobalInt("_ZEDStencilComp", 0); if (screen == null) { screen = gameObject.transform.GetChild(0).gameObject; finalMat = screen.GetComponent <Renderer>().material; } if (enableGarbageMatte) { garbageMatte = new GarbageMatte(GetComponent <Camera>(), finalMat, transform, garbageMatte); } #if !UNITY_EDITOR Debug.Log("Load Chroma keys"); LoadGreenScreenData(); UpdateShader(); CreateFileWatcher(""); #endif }
public override void OnInspectorGUI() { serializedObject.Update(); greenScreen = (GreenScreenManager)target; key_colors(); if (ToggleButtonStyleNormal == null) { ToggleButtonStyleNormal = "Button"; ToggleButtonStyleToggled = new GUIStyle(ToggleButtonStyleNormal); ToggleButtonStyleToggled.normal.background = ToggleButtonStyleToggled.active.background; } //matte = (ZEDGarbageMatte)target; matte = greenScreen.garbageMatte; GUI.enabled = greenScreen.screenManager != null && greenScreen.screenManager.ActualRenderingPath == RenderingPath.Forward; enableGrabageMatte.boolValue = EditorGUILayout.Toggle("Enable Garbage Matte", enableGrabageMatte.boolValue); GUI.enabled = true; if (enableGrabageMatte.boolValue && greenScreen.screenManager != null && greenScreen.screenManager.ActualRenderingPath == RenderingPath.Forward) { //serializedObject.Update(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Place Markers", matte.editMode ? ToggleButtonStyleToggled : ToggleButtonStyleNormal)) { matte.editMode = !matte.editMode; if (matte.editMode) { matte.EnterEditMode(); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Remove Last Marker")) { matte.RemoveLastPoint(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Apply Garbage Matte")) { matte.ApplyGarbageMatte(); } EditorGUILayout.EndHorizontal(); GUI.enabled = true; if (GUILayout.Button("Reset")) { matte.ResetPoints(true); } } GUILayout.Space(20); EditorGUILayout.BeginHorizontal(); pathfileconfig.stringValue = EditorGUILayout.TextField("Save Config", greenScreen.pathFileConfig); serializedObject.ApplyModifiedProperties(); if (GUILayout.Button("...", optionsButtonBrowse)) { pathfileconfig.stringValue = EditorUtility.OpenFilePanel("Load save file", "", "json"); serializedObject.ApplyModifiedProperties(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Save")) { greenScreen.SaveData(greenScreen.RegisterDataChromaKeys(), greenScreen.garbageMatte.RegisterData()); } GUI.enabled = File.Exists(greenScreen.pathFileConfig); if (GUILayout.Button("Load")) { greenScreen.LoadGreenScreenData(true); keyColors.colorValue = greenScreen.keyColors; range.floatValue = greenScreen.range; smoothness.floatValue = greenScreen.smoothness; whiteclip.floatValue = greenScreen.whiteClip; blackclip.floatValue = greenScreen.blackClip; erosion.intValue = greenScreen.erosion; sigma.floatValue = greenScreen.sigma_; despill.floatValue = greenScreen.spill; } if (GUILayout.Button("Clean")) { matte.CleanSpheres(); } GUI.enabled = true; EditorGUILayout.EndHorizontal(); GUILayout.Space(20); if (GUILayout.Button("Camera Control")) { EditorWindow.GetWindow(typeof(ZEDCameraSettingsEditor), false, "ZED Camera").Show(); } serializedObject.ApplyModifiedProperties(); }