void Awake() { cam = GetComponent <Camera>(); cam.depthTextureMode = DepthTextureMode.Depth; outlineBufferCam = PostProcessUtils.GenerateBufferCamera(1 << LayerMask.NameToLayer("Outline") | 1 << LayerMask.NameToLayer("ColorAndOutline"), "Outline", cam); }
public override void OnPostProcess(RenderTexture src, RenderTexture dest) { if (!IsEnable()) { DoPostDefault(src, dest); return; } //blur RenderTexture blurRT = RenderTexture.GetTemporary(src.width >> blurDownsample, src.height >> blurDownsample, 0, RenderTextureFormat.ARGB32); PostProcessUtils.GaussianBlur(src, blurRT, new Vector2(src.width, src.height), blurDownsample, blurIterations, blurSize); dofComposeMaterial.SetTexture("_BlurTex", blurRT); dofComposeMaterial.SetFloat("_focalDistance", FocalDistance01(focalDistance)); dofComposeMaterial.SetFloat("_nearBlurScale", nearBlurScale); dofComposeMaterial.SetFloat("_farBlurScale", farBlurScale); if (nextPostProcess != null) { RenderTexture dofDest = RenderTexture.GetTemporary(src.width, src.height, 0, RenderTextureFormat.ARGB32); Graphics.Blit(src, dofDest, dofComposeMaterial); nextPostProcess.OnPostProcess(dofDest, dest); RenderTexture.ReleaseTemporary(dofDest); } else { Graphics.Blit(src, dest, dofComposeMaterial); } RenderTexture.ReleaseTemporary(blurRT); }
public virtual void Initialize() { // Remove all children game objects foreach (var child in transform.Cast <Transform>().ToList()) { PostProcessUtils.Destroy(child.gameObject); } // Add room template component if (gameObject.GetComponent <RoomTemplateSettings>() == null) { gameObject.AddComponent <RoomTemplateSettings>(); } // Create tilemaps root var tilemapsRoot = new GameObject(GeneratorConstants.TilemapsRootName); tilemapsRoot.transform.parent = gameObject.transform; // Init tilemaps InitializeTilemaps(tilemapsRoot); // Fix positions tilemapsRoot.transform.localPosition = Vector3.zero; transform.localPosition = Vector3.zero; // Add doors InitializeDoors(); }
public override void OnPostProcess(RenderTexture src) { if (!IsRenderEnable()) { return; } bloomRT = RenderTexture.GetTemporary(src.width >> bloomDownSample, src.height >> bloomDownSample, 0, RenderTextureFormat.ARGB32); bloomComposeMaterial.SetVector("_colorThreshold", colorThreshold); Graphics.Blit(src, bloomRT, bloomComposeMaterial, 0); Material compose = m_postProcess.GetMaterial("compose"); compose.EnableKeyword("_BLOOM"); if (blurIterations > 0) { blurRT = RenderTexture.GetTemporary(src.width >> blurDownsample, src.height >> blurDownsample, 0, RenderTextureFormat.ARGB32); PostProcessUtils.GaussianBlur(bloomRT, blurRT, new Vector2(src.width, src.height), blurDownsample, blurIterations, blurSize); compose.SetTexture("_BloomMask", blurRT); } else { compose.SetTexture("_BloomMask", bloomRT); } compose.SetVector("_BloomColor", bloomColor); compose.SetFloat("_BloomFactor", bloomFactor); }
public override IEnumerator Process() { var config = Config.Config; if (config.InitializeSharedTilemaps) { var tilemapLayersHandler = (ITilemapLayersHandler)config.TilemapLayersHandler ?? new DungeonTilemapLayersHandler(); PostProcessUtils.InitializeSharedTilemaps(Payload.GeneratedLevel, tilemapLayersHandler); } if (config.CopyTilesToSharedTilemaps) { PostProcessUtils.CopyTilesToSharedTilemaps(Payload.GeneratedLevel); } if (config.CenterGrid) { PostProcessUtils.CenterGrid(Payload.GeneratedLevel); } if (config.DisableRoomTemplatesRenderers) { PostProcessUtils.DisableRoomTemplatesRenderers(Payload.GeneratedLevel); } if (config.DisableRoomTemplatesColliders) { PostProcessUtils.DisableRoomTemplatesColliders(Payload.GeneratedLevel); } yield return(null); }
void Awake() { cam = GetComponent <Camera>(); cam.depthTextureMode = DepthTextureMode.Depth; colorBufferCam = PostProcessUtils.GenerateBufferCamera(1 << LayerMask.NameToLayer("Color") | 1 << LayerMask.NameToLayer("ColorAndOutline"), "Color", cam); SceneManager.sceneLoaded += OnSceneWasLoaded; }
public void RemoveOutlineOverride() { if (!HasOutlineOverride()) { return; } var tilemapsRoot = RoomTemplateUtils.GetTilemapsRoot(gameObject); var outlineOverride = tilemapsRoot.transform.Find(GeneratorConstants.OutlineOverrideName).gameObject; PostProcessUtils.Destroy(outlineOverride); }
public override void OnPostProcess(RenderTexture src) { if (!IsRenderEnable()) { return; } Material mat = m_postProcess.GetMaterial("compose"); rt = RenderTexture.GetTemporary(src.width >> blurDownsample, src.height >> blurDownsample, 0, RenderTextureFormat.ARGB32); PostProcessUtils.GaussianBlur(src, rt, new Vector2(src.width, src.height), blurDownsample, blurIterations, blurSize); mat.SetTexture("_BlurTex", rt); mat.SetFloat("_focalDistance", FocalDistance01(focalDistance)); mat.SetFloat("_nearBlurScale", nearBlurScale); mat.SetFloat("_farBlurScale", farBlurScale); }
public override void OnPostProcess(RenderTexture src) { if (!IsRenderEnable()) { return; } Camera camera = m_postProcess.GetCamera("RTCamera"); if (camera != null) { camera.cullingMask = 1 << glowLayer; rt = RenderTexture.GetTemporary(src.width >> maskDownsample, src.height >> maskDownsample, 24, RenderTextureFormat.ARGB32); camera.targetTexture = rt; if (m_postProcess.IsNeedDepth()) { Shader.SetGlobalFloat("_zShift", ZShift); camera.RenderWithShader(glowMaskDepthShader, ""); } else { camera.RenderWithShader(glowMaskShader, ""); } camera.targetTexture = null; } Material mat = m_postProcess.GetMaterial("compose"); //blur //if(blurDownsample > 0) { blurRT = RenderTexture.GetTemporary(src.width >> blurDownsample, src.height >> blurDownsample, 0, RenderTextureFormat.ARGB32); PostProcessUtils.Blur(rt, blurRT, new Vector2(src.width, src.height), blurDownsample, blurIterations, blurSize); } //set mat.SetTexture("_GlowMask", rt); mat.SetTexture("_BlurMask", blurRT); mat.SetFloat("_GlowPower", glowPower); mat.SetFloat("_BlurPower", blurPower); mat.SetColor("_GlobalTint", globalGlowTint); }
private void RegisterCallbacks(PriorityCallbacks <DungeonGeneratorPostProcessCallback> callbacks) { if (config.InitializeSharedTilemaps) { callbacks.RegisterCallback(PostProcessPriorities.InitializeSharedTilemaps, (level, description) => { var tilemapLayersHandler = config.TilemapLayersHandler ? config.TilemapLayersHandler : defaultTilemapLayersHandlerFactory(); PostProcessUtils.InitializeSharedTilemaps(level, tilemapLayersHandler); }); } if (config.CopyTilesToSharedTilemaps) { callbacks.RegisterCallback(PostProcessPriorities.CopyTilesToSharedTilemaps, (level, description) => { PostProcessUtils.CopyTilesToSharedTilemaps(level); }); } if (config.CenterGrid) { callbacks.RegisterCallback(PostProcessPriorities.CenterGrid, (level, description) => { PostProcessUtils.CenterGrid(level); }); } if (config.DisableRoomTemplatesRenderers) { callbacks.RegisterCallback(PostProcessPriorities.DisableRoomTemplateRenderers, (level, description) => { PostProcessUtils.DisableRoomTemplatesRenderers(level); }); } if (config.DisableRoomTemplatesColliders) { callbacks.RegisterCallback(PostProcessPriorities.DisableRoomTemplateColliders, (level, description) => { PostProcessUtils.DisableRoomTemplatesColliders(level); }); } }
public override void OnPostProcess(RenderTexture src, RenderTexture dest) { #if UNITY_EDITOR PostProcess[] process = m_mgr.GetPostProcess(); bool renderEnable = false; for (int i = 0; i < process.Length; ++i) { renderEnable |= process[i].IsRenderEnable(); } if (!renderEnable) { DoPostDefault(src, dest); return; } PostProcessUtils.Flip(src, dest, new Vector4(1, -1, 1, 1)); #else DoPostDefault(src, dest); #endif }
public override void OnPostProcess(RenderTexture src, RenderTexture dest) { if (!IsEnable()) { DoPostDefault(src, dest); return; } RenderTexture bloomRT = RenderTexture.GetTemporary(src.width >> bloomDownSample, src.height >> bloomDownSample, 0, RenderTextureFormat.ARGB32); bloomComposeMaterial.SetVector("_colorThreshold", colorThreshold); Graphics.Blit(src, bloomRT, bloomComposeMaterial, 0); RenderTexture blurRT = RenderTexture.GetTemporary(src.width >> blurDownsample, src.height >> blurDownsample, 0, RenderTextureFormat.ARGB32); PostProcessUtils.GaussianBlur(bloomRT, blurRT, new Vector2(src.width, src.height), blurDownsample, blurIterations, blurSize); bloomComposeMaterial.SetTexture("_BlurTex", blurRT); bloomComposeMaterial.SetVector("_bloomColor", bloomColor); bloomComposeMaterial.SetFloat("_bloomFactor", bloomFactor); if (nextPostProcess != null) { RenderTexture bloomDest = RenderTexture.GetTemporary(src.width, src.height, 0, RenderTextureFormat.ARGB32); Graphics.Blit(src, bloomDest, bloomComposeMaterial, 1); nextPostProcess.OnPostProcess(bloomDest, dest); RenderTexture.ReleaseTemporary(bloomDest); } else { Graphics.Blit(src, dest, bloomComposeMaterial, 1); } RenderTexture.ReleaseTemporary(bloomRT); RenderTexture.ReleaseTemporary(blurRT); }
public override IEnumerator Process() { var levelDescription = Payload.LevelDescription; if (config.Timeout <= 0) { throw new ArgumentException($"{nameof(config.Timeout)} must be greater than 0", nameof(config.Timeout)); } var rootGameObject = config.RootGameObject; // If the root game objects was not set in the config, we do the following: // 1. Check if there already exists a game objects with a name reserved for the generated level // 2. Otherwise, we create a new empty game object if (rootGameObject == null) { rootGameObject = GameObject.Find("Generated Level"); if (rootGameObject == null) { rootGameObject = new GameObject("Generated Level"); } } // We delete all the children from the root game object - we do not want to combine levels from different runs of the algorithm foreach (var child in rootGameObject.transform.Cast <Transform>().ToList()) { child.transform.parent = null; PostProcessUtils.Destroy(child.gameObject); } // The LevelDescription class must be converted to MapDescription var mapDescription = levelDescription.GetMapDescription(); var configuration = new DungeonGeneratorConfiguration <RoomBase>() { RoomsCanTouch = false, RepeatModeOverride = GeneratorUtils.GetRepeatMode(config.RepeatModeOverride), EarlyStopIfTimeExceeded = TimeSpan.FromMilliseconds(config.Timeout), }; // We create the instance of the dungeon generator and inject the correct Random instance var generator = new DungeonGenerator <RoomBase>(mapDescription, configuration); generator.InjectRandomGenerator(Payload.Random); // Run the generator in a different class so that the computation is not blocking MapLayout <RoomBase> layout = null; var task = Task.Run(() => layout = generator.GenerateLayout()); while (!task.IsCompleted) { yield return(null); } // Throw an exception when a timeout is reached // TODO: this should be our own exception and not a generic exception if (layout == null) { throw new InvalidOperationException("Timeout was reached when generating level"); } // Transform the level to its Unity representation var generatedLevel = GeneratorUtils.TransformLayout(layout, levelDescription, rootGameObject); var stats = new GeneratorStats() { Iterations = generator.IterationsCount, TimeTotal = generator.TimeTotal, }; Debug.Log($"Layout generated in {stats.TimeTotal / 1000f:F} seconds"); Debug.Log($"{stats.Iterations} iterations needed, {stats.Iterations / (stats.TimeTotal / 1000d):0} iterations per second"); ((IGraphBasedGeneratorPayload)Payload).GeneratedLevel = generatedLevel; Payload.GeneratorStats = stats; yield return(null); }
void Update() { PostProcessUtils.GenerateBufferIfNecessary(ref colorBuffer, 0, RenderTextureFormat.R8, "Buffer"); PostProcessUtils.GenerateBufferIfNecessary(ref depthBuffer, 0, RenderTextureFormat.Depth, "Depth buffer"); }
void Update() { PostProcessUtils.GenerateBufferIfNecessary(ref outlineBuffer, 0, RenderTextureFormat.R8, "Buffer"); PostProcessUtils.GenerateBufferIfNecessary(ref depthBuffer, 0, RenderTextureFormat.Depth, "Depth buffer"); // redundant... refactor later }
public override IEnumerator Process() { var config = Config.Config; var levelDescription = Payload.LevelDescription; if (config.Timeout <= 0) { throw new ArgumentException($"{nameof(config.Timeout)} must be greater than 0", nameof(config.Timeout)); } var rootGameObject = config.RootGameObject; if (rootGameObject == null) { rootGameObject = GameObject.Find("Generated Level"); if (rootGameObject == null) { rootGameObject = new GameObject("Generated Level"); } } foreach (var child in rootGameObject.transform.Cast <Transform>().ToList()) { child.transform.parent = null; PostProcessUtils.Destroy(child.gameObject); } var mapDescription = levelDescription.GetMapDescription(); var configuration = new DungeonGeneratorConfiguration <Room>() { RoomsCanTouch = false, RepeatModeOverride = GeneratorUtils.GetRepeatMode(config.RepeatModeOverride), EarlyStopIfTimeExceeded = TimeSpan.FromMilliseconds(config.Timeout), }; var generator = new DungeonGenerator <Room>(mapDescription, configuration); generator.InjectRandomGenerator(Payload.Random); MapLayout <Room> layout = null; var task = Task.Run(() => layout = generator.GenerateLayout()); while (!task.IsCompleted) { yield return(null); } if (layout == null) { throw new InvalidOperationException("Timeout was reached when generating level"); } var generatedLevel = GeneratorUtils.TransformLayout(layout, levelDescription, rootGameObject); var stats = new GeneratorStats() { Iterations = generator.IterationsCount, TimeTotal = generator.TimeTotal, }; Debug.Log($"Layout generated in {stats.TimeTotal / 1000f:F} seconds"); Debug.Log($"{stats.Iterations} iterations needed, {stats.Iterations / (stats.TimeTotal / 1000d):0} iterations per second"); ((IGraphBasedGeneratorPayload)Payload).GeneratedLevel = generatedLevel; Payload.GeneratorStats = stats; yield return(null); }
public override void OnPostProcess(RenderTexture src, RenderTexture dest) { if (!IsEnable() || !IsRenderEnable()) { DoPostDefault(src, dest); return; } glowCamera.CopyFrom(m_mainCamera); glowCamera.rect = new Rect(0, 0, 1, 1); glowCamera.cullingMask = glowLayers; glowCamera.backgroundColor = new Color(0, 0, 0, 0); glowCamera.clearFlags = CameraClearFlags.SolidColor; glowCamera.depthTextureMode = DepthTextureMode.None; glowCamera.renderingPath = RenderingPath.VertexLit; RenderTexture glowRT = RenderTexture.GetTemporary(src.width >> maskDownsample, src.height >> maskDownsample, 24, RenderTextureFormat.ARGB32); glowCamera.targetTexture = glowRT; if (maskDownsample == 0) { Shader.SetGlobalFloat("_zShift", 0.999f); } else { Shader.SetGlobalFloat("_zShift", 0.99f); } //Shader.SetGlobalColor("_GlowColor", Color.white); //render downsample glow mask to glowRT if (glowMaskDepthEnable) { glowCamera.RenderWithShader(glowMaskDepthShader, "RenderType"); } else { glowCamera.RenderWithShader(glowMaskShader, "RenderType"); } //blur RenderTexture blurRT = RenderTexture.GetTemporary(src.width >> blurDownsample, src.height >> blurDownsample, 0, RenderTextureFormat.ARGB32); PostProcessUtils.Blur(glowRT, blurRT, new Vector2(src.width, src.height), blurDownsample, blurIterations, blurSize); //glow compose glowComposeMaterial.SetTexture("_GlowMask", glowRT); glowComposeMaterial.SetTexture("_BlurMask", blurRT); glowComposeMaterial.SetFloat("_GlowPower", glowPower); glowComposeMaterial.SetFloat("_BlurPower", blurPower); glowComposeMaterial.SetColor("_GlobalTint", globalGlowTint); //blit if (nextPostProcess != null) { RenderTexture glowDest = RenderTexture.GetTemporary(src.width, src.height, 0, RenderTextureFormat.ARGB32); Graphics.Blit(src, glowDest, glowComposeMaterial); nextPostProcess.OnPostProcess(glowDest, dest); RenderTexture.ReleaseTemporary(glowDest); } else { Graphics.Blit(src, dest, glowComposeMaterial); } RenderTexture.ReleaseTemporary(glowRT); RenderTexture.ReleaseTemporary(blurRT); }