Skip to content

Commit f976309

Browse files
[VFX] Fix usage on texture internally in SG (#5793)
* Fix case https://fogbugz.unity3d.com/f/cases/1367167/ Regression introduced by #5416 We should also include texture internally declared in SG -_-' * *Improve coverage using a texture only internally in shaderGraph It shouldn't modify the image reference * *Update changelog.md (cherry picked from commit 9c71fab) # Conflicts: # com.unity.visualeffectgraph/CHANGELOG.md
1 parent 3639f88 commit f976309

File tree

4 files changed

+82
-140
lines changed

4 files changed

+82
-140
lines changed

TestProjects/VisualEffectGraph_URP/Assets/GraphicsTests/104_ShaderGraphGenerationFTP/Shaders/SG_Sorting.shadergraph

Lines changed: 66 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
"m_Properties": [
66
{
77
"m_Id": "bfc2ef0d785e473bb1da855fbf32e81c"
8-
},
9-
{
10-
"m_Id": "5f74ae1ed818410fa6fbdcf5b60f4b1f"
118
}
129
],
1310
"m_Keywords": [],
@@ -39,9 +36,6 @@
3936
{
4037
"m_Id": "6c09ac4a1359451dbabb76027521d9e8"
4138
},
42-
{
43-
"m_Id": "9e6aade070664df68aec125866f3e044"
44-
},
4539
{
4640
"m_Id": "8375cf07ef144904b64f4ea3c9610581"
4741
},
@@ -50,11 +44,28 @@
5044
},
5145
{
5246
"m_Id": "71b0774211904df6b27be9fa29c8c1fd"
47+
},
48+
{
49+
"m_Id": "26d34e6aa05e444786562d26de838950"
5350
}
5451
],
5552
"m_GroupDatas": [],
5653
"m_StickyNoteDatas": [],
5754
"m_Edges": [
55+
{
56+
"m_OutputSlot": {
57+
"m_Node": {
58+
"m_Id": "26d34e6aa05e444786562d26de838950"
59+
},
60+
"m_SlotId": 0
61+
},
62+
"m_InputSlot": {
63+
"m_Node": {
64+
"m_Id": "8375cf07ef144904b64f4ea3c9610581"
65+
},
66+
"m_SlotId": 1
67+
}
68+
},
5869
{
5970
"m_OutputSlot": {
6071
"m_Node": {
@@ -125,20 +136,6 @@
125136
"m_SlotId": 0
126137
}
127138
},
128-
{
129-
"m_OutputSlot": {
130-
"m_Node": {
131-
"m_Id": "9e6aade070664df68aec125866f3e044"
132-
},
133-
"m_SlotId": 0
134-
},
135-
"m_InputSlot": {
136-
"m_Node": {
137-
"m_Id": "8375cf07ef144904b64f4ea3c9610581"
138-
},
139-
"m_SlotId": 1
140-
}
141-
},
142139
{
143140
"m_OutputSlot": {
144141
"m_Node": {
@@ -373,6 +370,19 @@
373370
"m_Labels": []
374371
}
375372

373+
{
374+
"m_SGVersion": 0,
375+
"m_Type": "UnityEditor.ShaderGraph.Texture2DMaterialSlot",
376+
"m_ObjectId": "186c6ddca18447cbb82ad3e9a575125f",
377+
"m_Id": 0,
378+
"m_DisplayName": "Out",
379+
"m_SlotType": 1,
380+
"m_Hidden": false,
381+
"m_ShaderOutputName": "Out",
382+
"m_StageCapability": 3,
383+
"m_BareResource": false
384+
}
385+
376386
{
377387
"m_SGVersion": 0,
378388
"m_Type": "UnityEditor.ShaderGraph.CategoryData",
@@ -381,9 +391,6 @@
381391
"m_ChildObjectList": [
382392
{
383393
"m_Id": "bfc2ef0d785e473bb1da855fbf32e81c"
384-
},
385-
{
386-
"m_Id": "5f74ae1ed818410fa6fbdcf5b60f4b1f"
387394
}
388395
]
389396
}
@@ -421,6 +428,42 @@
421428
"m_SerializedDescriptor": "VertexDescription.Tangent"
422429
}
423430

431+
{
432+
"m_SGVersion": 0,
433+
"m_Type": "UnityEditor.ShaderGraph.Texture2DAssetNode",
434+
"m_ObjectId": "26d34e6aa05e444786562d26de838950",
435+
"m_Group": {
436+
"m_Id": ""
437+
},
438+
"m_Name": "Texture 2D Asset",
439+
"m_DrawState": {
440+
"m_Expanded": true,
441+
"m_Position": {
442+
"serializedVersion": "2",
443+
"x": -1036.0,
444+
"y": 39.00000762939453,
445+
"width": 144.99993896484376,
446+
"height": 105.99999237060547
447+
}
448+
},
449+
"m_Slots": [
450+
{
451+
"m_Id": "186c6ddca18447cbb82ad3e9a575125f"
452+
}
453+
],
454+
"synonyms": [],
455+
"m_Precision": 0,
456+
"m_PreviewExpanded": true,
457+
"m_PreviewMode": 0,
458+
"m_CustomColors": {
459+
"m_SerializableColors": []
460+
},
461+
"m_Texture": {
462+
"m_SerializedTexture": "{\"texture\":{\"fileID\":2800000,\"guid\":\"276d9e395ae18fe40a9b4988549f2349\",\"type\":3}}",
463+
"m_Guid": ""
464+
}
465+
}
466+
424467
{
425468
"m_SGVersion": 0,
426469
"m_Type": "UnityEditor.ShaderGraph.TangentMaterialSlot",
@@ -504,19 +547,6 @@
504547
"m_ObjectId": "3ea2f95559da441a89a1aee286328f8e"
505548
}
506549

507-
{
508-
"m_SGVersion": 0,
509-
"m_Type": "UnityEditor.ShaderGraph.Texture2DMaterialSlot",
510-
"m_ObjectId": "43cd707af0c242b8a6748949cc5de43d",
511-
"m_Id": 0,
512-
"m_DisplayName": "Texture2D",
513-
"m_SlotType": 1,
514-
"m_Hidden": false,
515-
"m_ShaderOutputName": "Out",
516-
"m_StageCapability": 3,
517-
"m_BareResource": false
518-
}
519-
520550
{
521551
"m_SGVersion": 0,
522552
"m_Type": "UnityEditor.ShaderGraph.DynamicValueMaterialSlot",
@@ -650,35 +680,6 @@
650680
"m_Space": 0
651681
}
652682

653-
{
654-
"m_SGVersion": 0,
655-
"m_Type": "UnityEditor.ShaderGraph.Internal.Texture2DShaderProperty",
656-
"m_ObjectId": "5f74ae1ed818410fa6fbdcf5b60f4b1f",
657-
"m_Guid": {
658-
"m_GuidSerialized": "8f6a5bf8-c1ae-4c91-80ff-47a6711a32f6"
659-
},
660-
"m_Name": "Texture2D",
661-
"m_DefaultRefNameVersion": 1,
662-
"m_RefNameGeneratedByDisplayName": "Texture2D",
663-
"m_DefaultReferenceName": "_Texture2D",
664-
"m_OverrideReferenceName": "",
665-
"m_GeneratePropertyBlock": true,
666-
"m_UseCustomSlotLabel": false,
667-
"m_CustomSlotLabel": "",
668-
"m_Precision": 0,
669-
"overrideHLSLDeclaration": false,
670-
"hlslDeclarationOverride": 0,
671-
"m_Hidden": false,
672-
"m_Value": {
673-
"m_SerializedTexture": "{\"texture\":{\"instanceID\":0}}",
674-
"m_Guid": ""
675-
},
676-
"isMainTexture": false,
677-
"useTilingAndOffset": false,
678-
"m_Modifiable": true,
679-
"m_DefaultType": 0
680-
}
681-
682683
{
683684
"m_SGVersion": 0,
684685
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
@@ -941,41 +942,6 @@
941942
}
942943
}
943944

944-
{
945-
"m_SGVersion": 0,
946-
"m_Type": "UnityEditor.ShaderGraph.PropertyNode",
947-
"m_ObjectId": "9e6aade070664df68aec125866f3e044",
948-
"m_Group": {
949-
"m_Id": ""
950-
},
951-
"m_Name": "Property",
952-
"m_DrawState": {
953-
"m_Expanded": true,
954-
"m_Position": {
955-
"serializedVersion": "2",
956-
"x": -1016.0000610351563,
957-
"y": 145.0,
958-
"width": 139.00006103515626,
959-
"height": 34.00001525878906
960-
}
961-
},
962-
"m_Slots": [
963-
{
964-
"m_Id": "43cd707af0c242b8a6748949cc5de43d"
965-
}
966-
],
967-
"synonyms": [],
968-
"m_Precision": 0,
969-
"m_PreviewExpanded": true,
970-
"m_PreviewMode": 0,
971-
"m_CustomColors": {
972-
"m_SerializableColors": []
973-
},
974-
"m_Property": {
975-
"m_Id": "5f74ae1ed818410fa6fbdcf5b60f4b1f"
976-
}
977-
}
978-
979945
{
980946
"m_SGVersion": 0,
981947
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",

TestProjects/VisualEffectGraph_URP/Assets/GraphicsTests/104_ShaderGraphGenerationFTP/VFX/VFX - SortingTest.vfx

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ MonoBehaviour:
2020
x: 686
2121
y: -190
2222
width: 679
23-
height: 1419
23+
height: 1399
2424
--- !u!114 &114350483966674976
2525
MonoBehaviour:
2626
m_ObjectHideFlags: 1
@@ -1659,7 +1659,6 @@ MonoBehaviour:
16591659
m_UISuperCollapsed: 0
16601660
m_InputSlots:
16611661
- {fileID: 8926484042661614874}
1662-
- {fileID: 8926484042661614873}
16631662
m_OutputSlots: []
16641663
m_Label:
16651664
m_Data: {fileID: 8926484042661614568}
@@ -1879,40 +1878,6 @@ MonoBehaviour:
18791878
m_Disabled: 0
18801879
mode: 0
18811880
axes: 4
1882-
--- !u!114 &8926484042661614873
1883-
MonoBehaviour:
1884-
m_ObjectHideFlags: 0
1885-
m_CorrespondingSourceObject: {fileID: 0}
1886-
m_PrefabInstance: {fileID: 0}
1887-
m_PrefabAsset: {fileID: 0}
1888-
m_GameObject: {fileID: 0}
1889-
m_Enabled: 1
1890-
m_EditorHideFlags: 0
1891-
m_Script: {fileID: 11500000, guid: 70a331b1d86cc8d4aa106ccbe0da5852, type: 3}
1892-
m_Name:
1893-
m_EditorClassIdentifier:
1894-
m_UIIgnoredErrors: []
1895-
m_Parent: {fileID: 0}
1896-
m_Children: []
1897-
m_UIPosition: {x: 0, y: 0}
1898-
m_UICollapsed: 1
1899-
m_UISuperCollapsed: 0
1900-
m_MasterSlot: {fileID: 8926484042661614873}
1901-
m_MasterData:
1902-
m_Owner: {fileID: 8926484042661614699}
1903-
m_Value:
1904-
m_Type:
1905-
m_SerializableType: UnityEngine.Texture2D, UnityEngine.CoreModule, Version=0.0.0.0,
1906-
Culture=neutral, PublicKeyToken=null
1907-
m_SerializableObject: '{"obj":{"fileID":2800000,"guid":"276d9e395ae18fe40a9b4988549f2349","type":3}}'
1908-
m_Space: 2147483647
1909-
m_Property:
1910-
name: _Texture2D
1911-
m_serializedType:
1912-
m_SerializableType: UnityEngine.Texture2D, UnityEngine.CoreModule, Version=0.0.0.0,
1913-
Culture=neutral, PublicKeyToken=null
1914-
m_Direction: 0
1915-
m_LinkedSlots: []
19161881
--- !u!114 &8926484042661614874
19171882
MonoBehaviour:
19181883
m_ObjectHideFlags: 0

com.unity.visualeffectgraph/CHANGELOG.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77
## [12.1.0] - 2021-09-23
8-
9-
Version Updated
10-
The version number for this package has increased due to a version update of a related graphics package.
8+
### Fixed
9+
- Compilation error while using not exposed texture in ShaderGraph [Case 1367167](https://issuetracker.unity3d.com/product/unity/issues/guid/1367167/)
1110

1211
## [12.0.0] - 2021-01-11
1312
### Added

com.unity.visualeffectgraph/Editor/ShaderGraph/VFXSubTarget.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,23 @@ static void GenerateVFXAdditionalCommands(VFXContext context, VFXSRPBinder srp,
175175
//Texture used as input of the shaderGraph will be declared by the shaderGraph generation
176176
//However, if we are sampling a texture (or a mesh), we have to declare them before the VFX code generation.
177177
//Thus, remove texture used in SG from VFX declaration and let the remainder.
178-
var filteredTextureInSG = context.inputSlots.Where(o =>
178+
var shaderGraphOutput = context as VFXShaderGraphParticleOutput;
179+
if (shaderGraphOutput == null)
180+
throw new InvalidOperationException("Unexpected null VFXShaderGraphParticleOutput");
181+
var shaderGraphObject = shaderGraphOutput.GetOrRefreshShaderGraphObject();
182+
if (shaderGraphObject == null)
183+
throw new InvalidOperationException("Unexpected null GetOrRefreshShaderGraphObject");
184+
var texureUsedInternallyInSG = shaderGraphObject.textureInfos.Select(o =>
185+
{
186+
return o.name;
187+
});
188+
var textureExposedFromSG = context.inputSlots.Where(o =>
179189
{
180190
return VFXExpression.IsTexture(o.property.type);
181191
}).Select(o => o.property.name);
182192

193+
var filteredTextureInSG = texureUsedInternallyInSG.Concat(textureExposedFromSG).ToArray();
194+
183195
// Parameter Cbuffer
184196
VFXCodeGenerator.BuildParameterBuffer(contextData, filteredTextureInSG, out var parameterBuffer);
185197
parameterBufferDescriptor = new AdditionalCommandDescriptor("VFXParameterBuffer", parameterBuffer);

0 commit comments

Comments
 (0)