Skip to content

Commit 80a03dc

Browse files
svc-reach-platform-supportEvergreen
authored andcommitted
[Port] [6000.0][UUM-87636] Fix sprite instancing with 2d shaders
1 parent 53297a2 commit 80a03dc

35 files changed

Lines changed: 5287 additions & 18 deletions

Packages/com.unity.render-pipelines.universal/Editor/2D/ShaderGraph/Includes/SpriteLitPass.hlsl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ half4 _RendererColor;
2525
PackedVaryings vert(Attributes input)
2626
{
2727
Varyings output = (Varyings)0;
28+
UNITY_SETUP_INSTANCE_ID(input);
29+
30+
SetUpSpriteInstanceProperties();
2831
input.positionOS = UnityFlipSprite(input.positionOS, unity_SpriteProps.xy);
2932
output = BuildVaryings(input);
3033
output.color *= _RendererColor * unity_SpriteColor; // vertex color has to applied here

Packages/com.unity.render-pipelines.universal/Editor/2D/ShaderGraph/Includes/SpriteNormalPass.hlsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ PackedVaryings vert(Attributes input)
55
Varyings output = (Varyings)0;
66
input.positionOS = UnityFlipSprite(input.positionOS, unity_SpriteProps.xy);
77
output = BuildVaryings(input);
8+
output.color *= unity_SpriteColor;
89
output.normalWS = -GetViewForwardDir();
910
PackedVaryings packedOutput = PackVaryings(output);
1011
return packedOutput;

Packages/com.unity.render-pipelines.universal/Editor/2D/ShaderGraph/Includes/SpriteUnlitPass.hlsl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ half4 _RendererColor;
77
PackedVaryings vert(Attributes input)
88
{
99
Varyings output = (Varyings)0;
10+
UNITY_SETUP_INSTANCE_ID(input);
11+
12+
SetUpSpriteInstanceProperties();
1013
input.positionOS = UnityFlipSprite(input.positionOS, unity_SpriteProps.xy);
1114
output = BuildVaryings(input);
1215
output.color *= _RendererColor * unity_SpriteColor; // vertex color has to applied here

Packages/com.unity.render-pipelines.universal/Editor/2D/ShaderGraph/Targets/UniversalSpriteCustomLitSubTarget.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ public override void Setup(ref TargetSetupContext context)
2121
{
2222
base.Setup(ref context);
2323
context.AddAssetDependency(kSourceCodeGuid, AssetCollection.Flags.SourceDependency);
24-
#if HAS_VFX_GRAPH
24+
2525
var universalRPType = typeof(UnityEngine.Rendering.Universal.UniversalRenderPipelineAsset);
26-
if (TargetsVFX() && !context.HasCustomEditorForRenderPipeline(universalRPType))
27-
{
28-
context.AddCustomEditorForRenderPipeline(typeof(VFXGenericShaderGraphMaterialGUI).FullName, universalRPType);
29-
}
26+
var gui = typeof(ShaderGraphSpriteGUI);
27+
#if HAS_VFX_GRAPH
28+
if (TargetsVFX())
29+
gui = typeof(VFXGenericShaderGraphMaterialGUI);
3030
#endif
31+
context.AddCustomEditorForRenderPipeline(gui.FullName, universalRPType);
3132
context.AddSubShader(PostProcessSubShader(SubShaders.SpriteLit(target)));
3233
}
3334

@@ -244,6 +245,7 @@ static class SpriteLitRequiredFields
244245

245246
public static FieldCollection Normal = new FieldCollection()
246247
{
248+
StructFields.Varyings.color,
247249
StructFields.Varyings.normalWS,
248250
StructFields.Varyings.tangentWS,
249251
};

Packages/com.unity.render-pipelines.universal/Editor/2D/ShaderGraph/Targets/UniversalSpriteLitSubTarget.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ public override void Setup(ref TargetSetupContext context)
2323
{
2424
base.Setup(ref context);
2525
context.AddAssetDependency(kSourceCodeGuid, AssetCollection.Flags.SourceDependency);
26-
#if HAS_VFX_GRAPH
26+
2727
var universalRPType = typeof(UnityEngine.Rendering.Universal.UniversalRenderPipelineAsset);
28-
if (TargetsVFX() && !context.HasCustomEditorForRenderPipeline(universalRPType))
29-
{
30-
context.AddCustomEditorForRenderPipeline(typeof(VFXGenericShaderGraphMaterialGUI).FullName, universalRPType);
31-
}
28+
var gui = typeof(ShaderGraphSpriteGUI);
29+
#if HAS_VFX_GRAPH
30+
if (TargetsVFX())
31+
gui = typeof(VFXGenericShaderGraphMaterialGUI);
3232
#endif
33+
context.AddCustomEditorForRenderPipeline(gui.FullName, universalRPType);
3334
context.AddSubShader(PostProcessSubShader(SubShaders.SpriteLit(target)));
3435
}
3536

@@ -266,6 +267,7 @@ static class SpriteLitRequiredFields
266267

267268
public static FieldCollection Normal = new FieldCollection()
268269
{
270+
StructFields.Varyings.color,
269271
StructFields.Varyings.normalWS,
270272
StructFields.Varyings.tangentWS,
271273
};

Packages/com.unity.render-pipelines.universal/Editor/2D/ShaderGraph/Targets/UniversalSpriteUnlitSubTarget.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ public override void Setup(ref TargetSetupContext context)
2323
{
2424
base.Setup(ref context);
2525
context.AddAssetDependency(kSourceCodeGuid, AssetCollection.Flags.SourceDependency);
26-
#if HAS_VFX_GRAPH
26+
2727
var universalRPType = typeof(UnityEngine.Rendering.Universal.UniversalRenderPipelineAsset);
28-
if (TargetsVFX() && !context.HasCustomEditorForRenderPipeline(universalRPType))
29-
{
30-
context.AddCustomEditorForRenderPipeline(typeof(VFXGenericShaderGraphMaterialGUI).FullName, universalRPType);
31-
}
28+
var gui = typeof(ShaderGraphSpriteGUI);
29+
#if HAS_VFX_GRAPH
30+
if (TargetsVFX())
31+
gui = typeof(VFXGenericShaderGraphMaterialGUI);
3232
#endif
33+
context.AddCustomEditorForRenderPipeline(gui.FullName, universalRPType);
3334
context.AddSubShader(PostProcessSubShader(SubShaders.SpriteUnlit(target)));
3435
}
3536

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
area: Material
1+
area: Materials
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using UnityEngine;
2+
3+
namespace UnityEditor
4+
{
5+
// Used for ShaderGraph Sprite shaders
6+
class ShaderGraphSpriteGUI : BaseShaderGUI
7+
{
8+
protected override uint materialFilter => uint.MaxValue & ~(uint)Expandable.SurfaceOptions;
9+
10+
MaterialProperty[] properties;
11+
12+
// collect properties from the material properties
13+
public override void FindProperties(MaterialProperty[] properties)
14+
{
15+
// save off the list of all properties for shadergraph
16+
this.properties = properties;
17+
18+
var material = materialEditor?.target as Material;
19+
if (material == null)
20+
return;
21+
22+
base.FindProperties(properties);
23+
}
24+
25+
public override void DrawSurfaceInputs(Material material)
26+
{
27+
DrawShaderGraphProperties(material, properties);
28+
}
29+
}
30+
}

Packages/com.unity.render-pipelines.universal/Editor/ShaderGUI/ShadergraphSpriteGUI.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTarget.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,6 +1650,7 @@ static class CorePragmas
16501650
{
16511651
{ Pragma.Target(ShaderModel.Target20) },
16521652
{ Pragma.ExcludeRenderers(new[] { Platform.D3D9 }) },
1653+
{ Pragma.MultiCompileInstancing },
16531654
{ Pragma.Vertex("vert") },
16541655
{ Pragma.Fragment("frag") },
16551656
};

0 commit comments

Comments
 (0)