From 7553a3741731c30c5b3000f75178597c17f34506 Mon Sep 17 00:00:00 2001 From: Elizabeth LeGros Date: Sat, 14 Oct 2023 12:46:26 +0000 Subject: [PATCH] [ShaderGraph] Fix sprite previews for URP Sets default material properties that are needed by sprite previews. This is a bit of a hotfix- it's probably better if the sprite target were to create these as hidden material properties so that these default values could be setup. --- .../Editor/Drawing/PreviewManager.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Packages/com.unity.shadergraph/Editor/Drawing/PreviewManager.cs b/Packages/com.unity.shadergraph/Editor/Drawing/PreviewManager.cs index 1f60923460f..ce8006a755a 100644 --- a/Packages/com.unity.shadergraph/Editor/Drawing/PreviewManager.cs +++ b/Packages/com.unity.shadergraph/Editor/Drawing/PreviewManager.cs @@ -11,7 +11,6 @@ using Object = UnityEngine.Object; using Unity.Profiling; - namespace UnityEditor.ShaderGraph.Drawing { delegate void OnPrimaryMasterChanged(); @@ -518,6 +517,9 @@ bool TimedNodesShouldUpdate(EditorWindow editorWindow) } private static readonly ProfilerMarker RenderPreviewsMarker = new ProfilerMarker("RenderPreviews"); + private static int k_spriteProps = Shader.PropertyToID("unity_SpriteProps"); + private static int k_spriteColor = Shader.PropertyToID("unity_SpriteColor"); + private static int k_rendererColor = Shader.PropertyToID("_RendererColor"); public void RenderPreviews(EditorWindow editorWindow, bool requestShaders = true) { using (RenderPreviewsMarker.Auto()) @@ -673,6 +675,11 @@ public void RenderPreviews(EditorWindow editorWindow, bool requestShaders = true previewTransform *= Matrix4x4.Scale(scale * Vector3.one * (Vector3.one).magnitude / mesh.bounds.size.magnitude); previewTransform *= Matrix4x4.Translate(-mesh.bounds.center); + //bugfix for some variables that need to be setup for URP Sprite material previews. Want a better isolated place to put them, + //but I dont believe such a place exists and would be too costly to add. + masterRenderData.shaderData.mat.SetVector(k_spriteProps, new Vector4(1, 1, -1, 0)); + masterRenderData.shaderData.mat.SetVector(k_spriteColor, new Vector4(1, 1, 1, 1)); + masterRenderData.shaderData.mat.SetVector(k_rendererColor, new Vector4(1, 1, 1, 1)); RenderPreview(masterRenderData, mesh, previewTransform, perMaterialPreviewProperties); }