public static void InitSharedData(ref PostSharedData data, PostProcessResources resources) { data = default(PostSharedData); data.uberMaterial = new Material(Shader.Find("Hidden/PostProcessing/Uber")); data.resources = resources; data.temporalRT = new List <RenderTexture>(20); data.shaderKeywords = new List <string>(10); data.keywordsTransformed = true; }
public static void Finalize(ref BloomData data, ref PostSharedData sharedData) { var uberMaterial = sharedData.uberMaterial; Object.Destroy(data.bloomMaterial); }
public static void PrepareRender(ref ColorGradingData data, ref PostSharedData sharedData) { Material uberMaterial = sharedData.uberMaterial; if (data.settings.active != data.enabledInUber) { data.enabledInUber = data.settings.active; sharedData.keywordsTransformed = true; if (data.enabledInUber) { sharedData.shaderKeywords.Add("COLOR_GRADING_HDR_3D"); } else { sharedData.shaderKeywords.Remove("COLOR_GRADING_HDR_3D"); } } if (!data.settings.enabled) { return; } CheckInternalLogLut(ref data.m_InternalLogLut); // Lut setup var compute = sharedData.resources.computeShaders.lut3DBaker; var kernel = data.kernel; var settings = data.settings; compute.SetTexture(data.kernel, _Output, data.m_InternalLogLut); compute.SetVector(_Size, new Vector4(k_Lut3DSize, 1f / (k_Lut3DSize - 1f), 0f, 0f)); var colorBalance = ColorUtilities.ComputeColorBalance(settings.temperature, settings.tint); compute.SetVector(_ColorBalance, colorBalance); compute.SetVector(_ColorFilter, settings.colorFilter); float hue = settings.hueShift / 360f; // Remap to [-0.5;0.5] float sat = settings.saturation / 100f + 1f; // Remap to [0;2] float con = settings.contrast / 100f + 1f; // Remap to [0;2] compute.SetVector(_HueSatCon, new Vector4(hue, sat, con, 0f)); var channelMixerR = new Vector4(settings.mixerRedOutRedIn, settings.mixerRedOutGreenIn, settings.mixerRedOutBlueIn, 0f); var channelMixerG = new Vector4(settings.mixerGreenOutRedIn, settings.mixerGreenOutGreenIn, settings.mixerGreenOutBlueIn, 0f); var channelMixerB = new Vector4(settings.mixerBlueOutRedIn, settings.mixerBlueOutGreenIn, settings.mixerBlueOutBlueIn, 0f); compute.SetVector(_ChannelMixerRed, channelMixerR / 100f); // Remap to [-2;2] compute.SetVector(_ChannelMixerGreen, channelMixerG / 100f); compute.SetVector(_ChannelMixerBlue, channelMixerB / 100f); var liftV = ColorUtilities.ColorToLift(settings.lift.value * 0.2f); var gainV = ColorUtilities.ColorToGain(settings.gain.value * 0.8f); var invgamma = ColorUtilities.ColorToInverseGamma(settings.gamma.value * 0.8f); compute.SetVector(_Lift, new Vector4(liftV.x, liftV.y, liftV.z, 0f)); compute.SetVector(_InvGamma, new Vector4(invgamma.x, invgamma.y, invgamma.z, 0f)); compute.SetVector(_Gain, new Vector4(gainV.x, gainV.y, gainV.z, 0f)); compute.SetTexture(kernel, _Curves, GetCurveTexture(ref data)); int groupSize = Mathf.CeilToInt(k_Lut3DSize / 4f); compute.Dispatch(kernel, groupSize, groupSize, groupSize); var lut = data.m_InternalLogLut; uberMaterial.SetTexture(ShaderIDs._Lut3D, lut); uberMaterial.SetVector(ShaderIDs._Lut3D_Params, new Vector2(1f / lut.width, lut.width - 1f)); uberMaterial.SetFloat(ShaderIDs._PostExposure, Mathf.Exp(settings.postExposure * 0.69314718055994530941723212145818f)); }