private void NewGrainRender(RenderTargetIdentifier source, RenderTargetIdentifier destination, CommandBuffer cmd, Camera cam) { PostProf profile = stylizer.profile; PostCont m_Context = stylizer.m_Context; if (profile.grain.enabled == false) { profile.grain.enabled = true; } var context = m_Context.Reset(); context.profile = profile; context.renderTextureFactory = stylizer.m_RenderTextureFactory; context.materialFactory = stylizer.m_MaterialFactory; context.camera = cam; #if UNITY_EDITOR var uberMaterial = stylizer.m_MaterialFactory.Get("Hidden/Post FX/Uber Shader_Grain"); #else var uberMaterial = ub; #endif uberMaterial.shaderKeywords = null; Texture autoExposure = GU.whiteTexture; uberMaterial.SetTexture("_AutoExposure", autoExposure); stylizer.m_Grain.Init(context, profile.grain); TryPrepareUberImageEffect(stylizer.m_Grain, uberMaterial); cmd.Blit(source, destination, uberMaterial, 0); stylizer.m_RenderTextureFactory.ReleaseAll(); }
private void NewCombine(RenderTargetIdentifier destination, CommandBuffer cmd, Camera cam, RenderTextureDescriptor opaqueDescriptor) { PostProf profile = stylizer.profile; if (profile.grain.enabled == false) { profile.grain.enabled = true; } var context = stylizer.m_Context.Reset(); context.profile = profile; context.renderTextureFactory = stylizer.m_RenderTextureFactory; context.materialFactory = stylizer.m_MaterialFactory; context.camera = cam; #if UNITY_EDITOR var uberMaterial = stylizer.m_MaterialFactory.Get("Hidden/Post FX/Uber Shader_Grain"); #else var uberMaterial = ub; #endif uberMaterial.shaderKeywords = null; Texture autoExposure = GU.whiteTexture; uberMaterial.SetTexture("_AutoExposure", autoExposure); stylizer.m_Grain.Init(context, profile.grain); TryPrepareUberImageEffect(stylizer.m_Grain, uberMaterial); Palette palette = stylizer.Palette; Pattern pattern = stylizer.Pattern; Texture2D patternTexture = stylizer.PatternTexture; if (palette == null || (pattern == null && patternTexture == null)) { return; } if (!palette.HasTexture || (patternTexture == null && !pattern.HasTexture)) { return; } Texture2D patTex = (pattern == null ? patternTexture : pattern.Texture); Material material = stylizer.Material; material.SetFloat("_PaletteColorCount", palette.MixedColorCount); material.SetFloat("_PaletteHeight", palette.Texture.height); material.SetTexture("_PaletteTex", palette.Texture); material.SetFloat("_PatternSize", patTex.width); material.SetTexture("_PatternTex", patTex); //Blitting int ditherTemp = DitherID; int grainTemp = GrainID; RenderTargetIdentifier source = currentTarget; cmd.GetTemporaryRT(ditherTemp, cam.pixelWidth, cam.pixelHeight, 0, FilterMode.Point, RenderTextureFormat.Default); cmd.GetTemporaryRT(grainTemp, cam.pixelWidth, cam.pixelHeight, 0, FilterMode.Point, RenderTextureFormat.Default); //Dither cmd.Blit(source, ditherTemp, uberMaterial, 0); //Grain cmd.Blit(ditherTemp, grainTemp, material); //Output to Screen cmd.Blit(grainTemp, source); cmd.ReleaseTemporaryRT(ditherTemp); cmd.ReleaseTemporaryRT(grainTemp); stylizer.m_RenderTextureFactory.ReleaseAll(); }