// TODO: Add API docs public static void ConfigureFilmGrain(PostProcessData data, FilmGrain settings, int cameraPixelWidth, int cameraPixelHeight, Material material) { var texture = settings.texture.value; if (settings.type.value != FilmGrainLookup.Custom) { texture = data.textures.filmGrainTex[(int)settings.type.value]; } #if LWRP_DEBUG_STATIC_POSTFX float offsetX = 0f; float offsetY = 0f; #else float offsetX = Random.value; float offsetY = Random.value; #endif var tilingParams = texture == null ? Vector4.zero : new Vector4(cameraPixelWidth / (float)texture.width, cameraPixelHeight / (float)texture.height, offsetX, offsetY); material.SetTexture(ShaderConstants._Grain_Texture, texture); material.SetVector(ShaderConstants._Grain_Params, new Vector2(settings.intensity.value * 4f, settings.response.value)); material.SetVector(ShaderConstants._Grain_TilingParams, tilingParams); }
///<inheritdoc/> public void Render(PostProcessPassContext ctx, CameraSensorBase sensor, PostProcessData data, CubemapFace cubemapFace = CubemapFace.Unknown) { if (PostProcessSystem == null) { return; } var lateQueue = PostProcessSystem.IsLatePostprocess(sensor, typeof(TData)); if (!IsActive) { PostProcessSystem.Skip(ctx.cmd, ctx.cameraColorBuffer, sensor, true, lateQueue); return; } if (!(data is TData tData)) { Debug.LogWarning($"Attempting to render postprocess with invalid data type (required {typeof(TData).Name}, got {data.GetType().Name})"); PostProcessSystem.Skip(ctx.cmd, ctx.cameraColorBuffer, sensor, true, lateQueue); return; } PostProcessSystem.GetRTHandles(ctx.cmd, ctx.cameraColorBuffer, sensor, false, lateQueue, out var source, out var target, cubemapFace); Render(ctx, source, target, tData); PostProcessSystem.RecycleSourceRT(source, ctx.cameraColorBuffer, false); if (cubemapFace != CubemapFace.Unknown) { PostProcessSystem.TryPerformFinalCubemapPass(ctx.cmd, sensor, target, ctx.cameraColorBuffer, cubemapFace); } }
public override void Action(int instanceId, string pathName, string resourceFile) { var instance = CreateInstance <Renderer2DData>(); instance.postProcessData = PostProcessData.GetDefaultPostProcessData(); AssetDatabase.CreateAsset(instance, pathName); Selection.activeObject = instance; onCreated?.Invoke(instance); }
private void ReloadAllNullProperties() { ResourceReloader.TryReloadAllNullIn(this, UniversalRenderPipelineAsset.packagePath); // As now post process data is stored in Universal Render Pipeline, we can dereference non custom data. if (m_PostProcessData == PostProcessData.GetDefaultPostProcessData()) { m_PostProcessData = null; } }
/// <summary> /// Creates a new <c>ColorGradingLutPass</c> instance. /// </summary> /// <param name="evt">The <c>RenderPassEvent</c> to use.</param> /// <param name="data">The <c>PostProcessData</c> resources to use.</param> /// <seealso cref="RenderPassEvent"/> /// <seealso cref="PostProcessData"/> public ColorGradingLutPass(RenderPassEvent evt, PostProcessData data) { base.profilingSampler = new ProfilingSampler(nameof(ColorGradingLutPass)); renderPassEvent = evt; overrideCameraTarget = true; Material Load(Shader shader) { if (shader == null) { Debug.LogError($"Missing shader. {GetType().DeclaringType.Name} render pass will not execute. Check for missing reference in the renderer resources."); return(null); } return(CoreUtils.CreateEngineMaterial(shader)); } m_LutBuilderLdr = Load(data.shaders.lutBuilderLdrPS); m_LutBuilderHdr = Load(data.shaders.lutBuilderHdrPS); // Warm up lut format as IsFormatSupported adds GC pressure... const FormatUsage kFlags = FormatUsage.Linear | FormatUsage.Render; if (SystemInfo.IsFormatSupported(GraphicsFormat.R16G16B16A16_SFloat, kFlags)) { m_HdrLutFormat = GraphicsFormat.R16G16B16A16_SFloat; } else if (SystemInfo.IsFormatSupported(GraphicsFormat.B10G11R11_UFloatPack32, kFlags)) { m_HdrLutFormat = GraphicsFormat.B10G11R11_UFloatPack32; } else { // Obviously using this for log lut encoding is a very bad idea for precision but we // need it for compatibility reasons and avoid black screens on platforms that don't // support floating point formats. Expect banding and posterization artifact if this // ends up being used. m_HdrLutFormat = GraphicsFormat.R8G8B8A8_UNorm; } m_LdrLutFormat = GraphicsFormat.R8G8B8A8_UNorm; base.useNativeRenderPass = false; if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLES3 && Graphics.minOpenGLESVersion <= OpenGLESVersion.OpenGLES30 && SystemInfo.graphicsDeviceName.StartsWith("Adreno (TM) 3")) { m_AllowColorGradingACESHDR = false; } }
public PostProcessPass(RenderPassEvent evt, PostProcessData data) { renderPassEvent = evt; m_Data = data; m_Materials = new MaterialLibrary(data); // Texture format pre-lookup if (SystemInfo.IsFormatSupported(GraphicsFormat.B10G11R11_UFloatPack32, FormatUsage.Linear | FormatUsage.Render)) { m_DefaultHDRFormat = GraphicsFormat.B10G11R11_UFloatPack32; m_UseRGBM = false; } else { m_DefaultHDRFormat = QualitySettings.activeColorSpace == ColorSpace.Linear ? GraphicsFormat.R8G8B8A8_SRGB : GraphicsFormat.R8G8B8A8_UNorm; m_UseRGBM = true; } if (SystemInfo.IsFormatSupported(GraphicsFormat.R16_UNorm, FormatUsage.Linear | FormatUsage.Render)) { m_GaussianCoCFormat = GraphicsFormat.R16_UNorm; } else if (SystemInfo.IsFormatSupported(GraphicsFormat.R16_SFloat, FormatUsage.Linear | FormatUsage.Render)) { m_GaussianCoCFormat = GraphicsFormat.R16_SFloat; } else // Expect CoC banding { m_GaussianCoCFormat = GraphicsFormat.R8_UNorm; } // Bloom pyramid shader ids - can't use a simple stackalloc in the bloom function as we // unfortunately need to allocate strings ShaderConstants._BloomMipUp = new int[k_MaxPyramidSize]; ShaderConstants._BloomMipDown = new int[k_MaxPyramidSize]; for (int i = 0; i < k_MaxPyramidSize; i++) { ShaderConstants._BloomMipUp[i] = Shader.PropertyToID("_BloomMipUp" + i); ShaderConstants._BloomMipDown[i] = Shader.PropertyToID("_BloomMipDown" + i); } m_MRT2 = new RenderTargetIdentifier[2]; m_ResetHistory = true; }
public Renderer2D(Renderer2DData data) : base(data) { m_BlitMaterial = CoreUtils.CreateEngineMaterial(data.blitShader); m_SamplingMaterial = CoreUtils.CreateEngineMaterial(data.samplingShader); m_Render2DLightingPass = new Render2DLightingPass(data, m_BlitMaterial, m_SamplingMaterial); m_FinalBlitPass = new FinalBlitPass(RenderPassEvent.AfterRendering + 1, m_BlitMaterial); UniversalRenderPipelineAsset urpAsset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset; #pragma warning disable 618 // Obsolete warning PostProcessData postProcessData = data.postProcessData ? data.postProcessData : urpAsset.postProcessData; #pragma warning restore 618 // Obsolete warning if (postProcessData != null) { m_ColorGradingLutPass = new ColorGradingLutPass(RenderPassEvent.BeforeRenderingOpaques, postProcessData); m_PostProcessPass = new PostProcessPass(RenderPassEvent.BeforeRenderingPostProcessing, postProcessData, m_BlitMaterial); m_FinalPostProcessPass = new PostProcessPass(RenderPassEvent.AfterRenderingPostProcessing, postProcessData, m_BlitMaterial); k_AfterPostProcessColorHandle.Init("_AfterPostProcessTexture"); k_ColorGradingLutHandle.Init("_InternalGradingLut"); } m_UseDepthStencilBuffer = data.useDepthStencilBuffer; // We probably should declare these names in the base class, // as they must be the same across all ScriptableRenderer types for camera stacking to work. k_ColorTextureHandle.Init("_CameraColorTexture"); k_DepthTextureHandle.Init("_CameraDepthAttachment"); m_Renderer2DData = data; supportedRenderingFeatures = new RenderingFeatures() { cameraStacking = true, }; m_LightCullResult = new Light2DCullResult(); m_Renderer2DData.lightCullResult = m_LightCullResult; }
// TODO: Add API docs public static int ConfigureDithering(PostProcessData data, int index, int cameraPixelWidth, int cameraPixelHeight, Material material) { var blueNoise = data.textures.blueNoise16LTex; if (blueNoise == null || blueNoise.Length == 0) { return(0); // Safe guard } #if LWRP_DEBUG_STATIC_POSTFX // Used by QA for automated testing index = 0; float rndOffsetX = 0f; float rndOffsetY = 0f; #else if (++index >= blueNoise.Length) { index = 0; } Random.InitState(Time.frameCount); float rndOffsetX = Random.value; float rndOffsetY = Random.value; #endif // Ideally we would be sending a texture array once and an index to the slice to use // on every frame but these aren't supported on all Universal targets var noiseTex = blueNoise[index]; material.SetTexture(ShaderConstants._BlueNoise_Texture, noiseTex); material.SetVector(ShaderConstants._Dithering_Params, new Vector4( cameraPixelWidth / (float)noiseTex.width, cameraPixelHeight / (float)noiseTex.height, rndOffsetX, rndOffsetY )); return(index); }
public static int ConfigureDithering(PostProcessData data, int index, Camera camera, Material material) { return(ConfigureDithering(data, index, camera.pixelWidth, camera.pixelHeight, material)); }
public static void ConfigureFilmGrain(PostProcessData data, FilmGrain settings, Camera camera, Material material) { ConfigureFilmGrain(data, settings, camera.pixelWidth, camera.pixelHeight, material); }
public override void OnInspectorGUI() { serializedObject.Update(); EditorGUILayout.Space(); EditorGUILayout.LabelField(Styles.FilteringLabel, EditorStyles.boldLabel); EditorGUI.indentLevel++; EditorGUILayout.PropertyField(m_OpaqueLayerMask, Styles.OpaqueMask); EditorGUILayout.PropertyField(m_TransparentLayerMask, Styles.TransparentMask); EditorGUI.indentLevel--; EditorGUILayout.Space(); EditorGUILayout.LabelField(Styles.RenderingLabel, EditorStyles.boldLabel); EditorGUI.indentLevel++; EditorGUILayout.PropertyField(m_RenderingMode, Styles.RenderingModeLabel); if (m_RenderingMode.intValue == (int)RenderingMode.Deferred) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(m_AccurateGbufferNormals, Styles.accurateGbufferNormalsLabel, true); //EditorGUILayout.PropertyField(m_TiledDeferredShading, Styles.tiledDeferredShadingLabel, true); EditorGUI.indentLevel--; } if (m_RenderingMode.intValue == (int)RenderingMode.Forward) { EditorGUI.indentLevel++; if (s_EnableClusteredUI) { EditorGUILayout.PropertyField(m_ClusteredRendering, Styles.clusteredRenderingLabel); EditorGUI.BeginDisabledGroup(!m_ClusteredRendering.boolValue); EditorGUILayout.PropertyField(m_TileSize); EditorGUI.EndDisabledGroup(); } EditorGUILayout.PropertyField(m_DepthPrimingMode, Styles.DepthPrimingModeLabel); if (m_DepthPrimingMode.intValue != (int)DepthPrimingMode.Disabled) { EditorGUILayout.HelpBox(Styles.DepthPrimingModeInfo.text, MessageType.Info); } EditorGUI.indentLevel--; } EditorGUI.indentLevel--; EditorGUILayout.Space(); EditorGUILayout.LabelField("RenderPass", EditorStyles.boldLabel); EditorGUI.indentLevel++; EditorGUILayout.PropertyField(m_UseNativeRenderPass, Styles.RenderPassLabel); EditorGUI.indentLevel--; EditorGUILayout.Space(); EditorGUILayout.LabelField("Shadows", EditorStyles.boldLabel); EditorGUI.indentLevel++; EditorGUILayout.PropertyField(m_ShadowTransparentReceiveProp, Styles.shadowTransparentReceiveLabel); EditorGUI.indentLevel--; EditorGUILayout.Space(); EditorGUILayout.LabelField("Post-processing", EditorStyles.boldLabel); EditorGUI.indentLevel++; EditorGUI.BeginChangeCheck(); var postProcessIncluded = EditorGUILayout.Toggle(Styles.PostProcessIncluded, m_PostProcessData.objectReferenceValue != null); if (EditorGUI.EndChangeCheck()) { m_PostProcessData.objectReferenceValue = postProcessIncluded ? PostProcessData.GetDefaultPostProcessData() : null; } EditorGUI.indentLevel++; EditorGUILayout.PropertyField(m_PostProcessData, Styles.PostProcessLabel); EditorGUI.indentLevel--; EditorGUI.indentLevel--; EditorGUILayout.Space(); EditorGUILayout.LabelField("Overrides", EditorStyles.boldLabel); EditorGUI.indentLevel++; EditorGUILayout.PropertyField(m_DefaultStencilState, Styles.defaultStencilStateLabel, true); SerializedProperty overrideStencil = m_DefaultStencilState.FindPropertyRelative("overrideStencilState"); if (overrideStencil.boolValue && m_RenderingMode.intValue == (int)RenderingMode.Deferred) { CompareFunction stencilFunction = (CompareFunction)m_DefaultStencilState.FindPropertyRelative("stencilCompareFunction").enumValueIndex; StencilOp stencilPass = (StencilOp)m_DefaultStencilState.FindPropertyRelative("passOperation").enumValueIndex; StencilOp stencilFail = (StencilOp)m_DefaultStencilState.FindPropertyRelative("failOperation").enumValueIndex; StencilOp stencilZFail = (StencilOp)m_DefaultStencilState.FindPropertyRelative("zFailOperation").enumValueIndex; bool invalidFunction = stencilFunction == CompareFunction.Disabled || stencilFunction == CompareFunction.Never; bool invalidOp = stencilPass != StencilOp.Replace && stencilFail != StencilOp.Replace && stencilZFail != StencilOp.Replace; if (invalidFunction || invalidOp) { EditorGUILayout.HelpBox(Styles.invalidStencilOverride.text, MessageType.Error, true); } } EditorGUI.indentLevel--; EditorGUILayout.Space(); serializedObject.ApplyModifiedProperties(); base.OnInspectorGUI(); // Draw the base UI, contains ScriptableRenderFeatures list // Add a "Reload All" button in inspector when we are in developer's mode if (EditorPrefs.GetBool("DeveloperMode")) { EditorGUILayout.Space(); EditorGUILayout.PropertyField(m_Shaders, true); if (GUILayout.Button("Reload All")) { var resources = target as UniversalRendererData; resources.shaders = null; ResourceReloader.ReloadAllNullIn(target, UniversalRenderPipelineAsset.packagePath); } } }
public static void ConfigureFilmGrain(PostProcessData data, FilmGrain settings, Camera camera, Material material) { // TODO: we need to deprecate camera reference and only use CameraData. ConfigureFilmGrain(data, settings, camera.pixelWidth, camera.pixelHeight, material); }
public static int ConfigureDithering(PostProcessData data, int index, Camera camera, Material material) { // TODO: we need to deprecate camera reference and only use CameraData. return(ConfigureDithering(data, index, camera.pixelWidth, camera.pixelHeight, material)); }
void DrawPostProcessingSettings() { m_PostProcessingSettingsFoldout.value = EditorGUILayout.BeginFoldoutHeaderGroup(m_PostProcessingSettingsFoldout.value, Styles.postProcessingSettingsText); if (m_PostProcessingSettingsFoldout.value) { bool isHdrOn = m_HDR.boolValue; EditorGUI.indentLevel++; #pragma warning disable 618 // Obsolete warning bool renderersUsePostProcessData = false; for (int i = 0; i < m_RendererDataProp.arraySize; i++) { var rendererData = m_RendererDataProp.GetArrayElementAtIndex(i).objectReferenceValue as ScriptableRendererData; var forwardRendererData = rendererData as ForwardRendererData; if (forwardRendererData != null && forwardRendererData.postProcessData != null) { renderersUsePostProcessData = true; break; } var renderer2DData = rendererData as UnityEngine.Experimental.Rendering.Universal.Renderer2DData; if (renderer2DData != null && renderer2DData.postProcessData != null) { renderersUsePostProcessData = true; break; } } #pragma warning restore 618 // Obsolete warning GUI.enabled = !renderersUsePostProcessData; EditorGUI.BeginChangeCheck(); var postProcessIncluded = EditorGUILayout.Toggle(Styles.postProcessIncluded, m_PostProcessData.objectReferenceValue != null); if (EditorGUI.EndChangeCheck()) { m_PostProcessData.objectReferenceValue = postProcessIncluded ? PostProcessData.GetDefaultPostProcessData() : null; } if (postProcessIncluded) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(m_PostProcessData, Styles.postProcessLabel); EditorGUI.indentLevel--; } GUI.enabled = true; if (renderersUsePostProcessData) { EditorGUILayout.HelpBox("The URP asset contains Renderers that use custom Post Processing data, this check box has no effect.", MessageType.Warning); } GUI.enabled = postProcessIncluded || renderersUsePostProcessData; EditorGUILayout.PropertyField(m_ColorGradingMode, Styles.colorGradingMode); if (!isHdrOn && m_ColorGradingMode.intValue == (int)ColorGradingMode.HighDynamicRange) { EditorGUILayout.HelpBox(Styles.colorGradingModeWarning, MessageType.Warning); } else if (isHdrOn && m_ColorGradingMode.intValue == (int)ColorGradingMode.HighDynamicRange) { EditorGUILayout.HelpBox(Styles.colorGradingModeSpecInfo, MessageType.Info); } EditorGUILayout.DelayedIntField(m_ColorGradingLutSize, Styles.colorGradingLutSize); m_ColorGradingLutSize.intValue = Mathf.Clamp(m_ColorGradingLutSize.intValue, UniversalRenderPipelineAsset.k_MinLutSize, UniversalRenderPipelineAsset.k_MaxLutSize); if (isHdrOn && m_ColorGradingMode.intValue == (int)ColorGradingMode.HighDynamicRange && m_ColorGradingLutSize.intValue < 32) { EditorGUILayout.HelpBox(Styles.colorGradingLutSizeWarning, MessageType.Warning); } GUI.enabled = true; EditorGUILayout.PropertyField(m_UseFastSRGBLinearConversion, Styles.useFastSRGBLinearConversion); EditorGUI.indentLevel--; EditorGUILayout.Space(); EditorGUILayout.Space(); } EditorGUILayout.EndFoldoutHeaderGroup(); }