-
Notifications
You must be signed in to change notification settings - Fork 792
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added VirtualTexture property type (no list yet), got everything comp…
…iling again.
- Loading branch information
Chris Tchou
committed
Apr 22, 2020
1 parent
61481e2
commit ee59f50
Showing
17 changed files
with
301 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
com.unity.shadergraph/Editor/Data/Graphs/SerializableVirtualTexture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace UnityEditor.ShaderGraph.Internal | ||
{ | ||
[Serializable] | ||
public sealed class SerializableVirtualTexture : ISerializationCallbackReceiver | ||
{ | ||
[SerializeField] | ||
public List<string> layerNames = new List<string>(); | ||
|
||
[SerializeField] | ||
public List<SerializableTexture> layerTextures = new List<SerializableTexture>(); | ||
|
||
[SerializeField] | ||
public bool procedural; | ||
|
||
public void OnBeforeSerialize() | ||
{ | ||
} | ||
|
||
public void OnAfterDeserialize() | ||
{ | ||
} | ||
} | ||
} | ||
|
2 changes: 1 addition & 1 deletion
2
.../Editor/Data/Util/IncludeRegistry.cs.meta → ...Graphs/SerializableVirtualTexture.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
123 changes: 123 additions & 0 deletions
123
com.unity.shadergraph/Editor/Data/Graphs/VirtualTextureShaderProperty.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
using System; | ||
using System.Text; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using UnityEditor.ShaderGraph.Drawing.Controls; | ||
using UnityEngine; | ||
using UnityEditor.Graphing; | ||
using UnityEditor.ShaderGraph.Internal; | ||
|
||
namespace UnityEditor.ShaderGraph | ||
{ | ||
[Serializable] | ||
class VirtualTextureShaderProperty : AbstractShaderProperty<SerializableVirtualTexture> | ||
{ | ||
public VirtualTextureShaderProperty() | ||
{ | ||
displayName = "VirtualTexture"; | ||
value = new SerializableVirtualTexture(); | ||
|
||
// add at least one layer | ||
value.layerNames.Add("Layer0"); | ||
value.layerTextures.Add(new SerializableTexture()); | ||
} | ||
|
||
public override PropertyType propertyType => PropertyType.VirtualTexture; | ||
|
||
// isBatchable should never be called of we override hasBatchable / hasNonBatchableProperties | ||
internal override bool isBatchable | ||
{ | ||
get { throw new NotImplementedException(); } | ||
} | ||
|
||
internal override bool hasBatchableProperties => true; | ||
internal override bool hasNonBatchableProperties => true; | ||
|
||
internal override bool isExposable => true; // the textures are exposable at least.. | ||
internal override bool isRenamable => true; | ||
|
||
// this is used for properties exposed to the Material in the shaderlab Properties{} block | ||
internal override string GetPropertyBlockString() | ||
{ | ||
// something along the lines of: | ||
// [TextureStack.MyStack(0)] [NoScaleOffset] Layer0("Layer0", 2D) = "white" {} | ||
string result = ""; | ||
for (int layer= 0; layer < value.layerNames.Count; layer++) | ||
{ | ||
string layerName = value.layerNames[layer]; | ||
result += $"[TextureStack.{referenceName}({layer})] [NoScaleOffset] {layerName}(\"{layerName}\", 2D) = \"white\" {{}}{Environment.NewLine}"; | ||
} | ||
return result; | ||
} | ||
|
||
internal override void AppendBatchablePropertyDeclarations(ShaderStringBuilder builder, string delimiter = ";") | ||
{ | ||
int numLayers = value.layerNames.Count; | ||
if (numLayers > 0) | ||
{ | ||
builder.Append("DECLARE_STACK_CB("); | ||
builder.Append(referenceName); | ||
builder.Append(")"); | ||
builder.AppendLine(delimiter); | ||
} | ||
} | ||
|
||
internal override void AppendNonBatchablePropertyDeclarations(ShaderStringBuilder builder, string delimiter = ";") | ||
{ | ||
int numLayers = value.layerNames.Count; | ||
if (numLayers > 0) | ||
{ | ||
builder.Append("DECLARE_STACK"); | ||
builder.Append((numLayers <= 1) ? "" : numLayers.ToString()); | ||
builder.Append("("); | ||
builder.Append(referenceName); | ||
builder.Append(","); | ||
for (int i = 0; i < value.layerNames.Count; i++) | ||
{ | ||
if (i != 0) builder.Append(","); | ||
builder.Append(value.layerNames[i]); | ||
} | ||
builder.Append(")"); | ||
builder.AppendLine(delimiter); // TODO: don't like delimiter, pretty sure it's not necessary if we invert the defaults on GEtPropertyDeclaration / GetPropertyArgument string | ||
} | ||
} | ||
|
||
internal override string GetPropertyDeclarationString(string delimiter = ";") | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
// argument string used to pass this property to a subgraph | ||
internal override string GetPropertyAsArgumentString() | ||
{ | ||
// throw new NotImplementedException(); | ||
return "VirtualTexturePropertyArgumentStringGoesHere " + referenceName; | ||
} | ||
|
||
// if a blackboard property is deleted, all node instances of it are replaced with this: | ||
internal override AbstractMaterialNode ToConcreteNode() | ||
{ | ||
// TODO: | ||
return null; // new GradientNode { }; | ||
} | ||
|
||
internal override PreviewProperty GetPreviewMaterialProperty() | ||
{ | ||
return new PreviewProperty(propertyType) | ||
{ | ||
name = referenceName | ||
}; | ||
} | ||
|
||
internal override ShaderInput Copy() | ||
{ | ||
return new VirtualTextureShaderProperty | ||
{ | ||
displayName = displayName, | ||
hidden = hidden, | ||
value = value, | ||
precision = precision | ||
}; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
com.unity.shadergraph/Editor/Data/Graphs/VirtualTextureShaderProperty.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.