Skip to content

Commit

Permalink
[ShaderGraph] Fix sprite previews for URP
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
elizabeth-legros authored and Evergreen committed Oct 14, 2023
1 parent a9f99ea commit 7553a37
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using Object = UnityEngine.Object;
using Unity.Profiling;


namespace UnityEditor.ShaderGraph.Drawing
{
delegate void OnPrimaryMasterChanged();
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 7553a37

Please sign in to comment.