Skip to content

Commit

Permalink
[Shaders] Added ShaderClassString and a common base class ShaderClass…
Browse files Browse the repository at this point in the history
…Code

* Where possible, the common base class is used.
* LoadShaderSource can now also take a source code string as input.
* Added package upgrader and increased MaterialAssetCompiler to version 5
* Added TestShaderLoadingString
  • Loading branch information
tebjan authored and xen2 committed Apr 11, 2020
1 parent 79827d0 commit 5fd0982
Show file tree
Hide file tree
Showing 21 changed files with 383 additions and 215 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private class MaterialCompileCommand : AssetCommand<MaterialAsset>
public MaterialCompileCommand(string url, AssetItem assetItem, MaterialAsset value, AssetCompilerContext context)
: base(url, value, assetItem.Package)
{
Version = 4;
Version = 5;
this.assetItem = assetItem;
colorSpace = context.GetColorSpace();
assetUrl = new UFile(url);
Expand Down
18 changes: 18 additions & 0 deletions sources/engine/Xenko.Assets/XenkoPackageUpgrader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ public partial class XenkoPackageUpgrader : PackageUpgrader

public override bool Upgrade(PackageLoadParameters loadParameters, PackageSession session, ILogger log, Package dependentPackage, PackageDependency dependency, Package dependencyPackage, IList<PackageLoadingAssetFile> assetFiles)
{
if (dependency.Version.MinVersion < new PackageVersion("3.1.0.2-beta01"))
{
foreach (var assetFile in assetFiles)
{
// Add new generic parameter to ShadowMapReceiverDirectional in effect log
if (assetFile.FilePath.GetFileExtension() == ".xkeffectlog")
{
var assetContent = assetFile.AssetContent ?? File.ReadAllBytes(assetFile.FilePath.FullPath);
var assetContentString = System.Text.Encoding.UTF8.GetString(assetContent);
var newAssetContentString = System.Text.RegularExpressions.Regex.Replace(assetContentString, @"([ ]*)- ClassName:", "$1- !ShaderClassSource\r\n$1 ClassName:");
if (assetContentString != newAssetContentString)
{
// Need replacement, update with replaced text
assetFile.AssetContent = System.Text.Encoding.UTF8.GetBytes(newAssetContentString);
}
}
}
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public override IEnumerable<IComputeNode> GetChildren(object context = null)

public override ShaderSource GenerateShaderSource(ShaderGeneratorContext context, MaterialComputeColorKeys baseKeys)
{
var leftShaderSource = LeftChild.GenerateShaderSource(context, baseKeys);
var rightShaderSource = RightChild.GenerateShaderSource(context, baseKeys);
var leftShaderSource = LeftChild?.GenerateShaderSource(context, baseKeys);
var rightShaderSource = RightChild?.GenerateShaderSource(context, baseKeys);

var shaderSource = new ShaderClassSource(GetCorrespondingShaderSourceName(Operator));
var mixin = new ShaderMixinSource();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<Class Name="Xenko.Rendering.Materials.ComputeColors.ComputeBinaryColor" Collapsed="true">
<Position X="8" Y="5.75" Width="2.5" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<HashCode>AAAAAAAAAAQAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Rendering\Materials\ComputeColors\ComputeBinaryColor.cs</FileName>
</TypeIdentifier>
<Lollipop Position="0.2" />
Expand All @@ -33,7 +33,7 @@
<Class Name="Xenko.Rendering.Materials.ComputeColors.ComputeColor" Collapsed="true">
<Position X="2" Y="7" Width="2" />
<TypeIdentifier>
<HashCode>AAAAAAAEAAAAAAAEAAAAAAAAAAAAAAAAAAIAAAAAAAA=</HashCode>
<HashCode>IAAAAAAEAAAAAIAEIAAAAAAABAAAAAAAAAIAAAAAAAA=</HashCode>
<FileName>Rendering\Materials\ComputeColors\ComputeColor.cs</FileName>
</TypeIdentifier>
<Lollipop Position="0.2" />
Expand All @@ -49,7 +49,7 @@
<Class Name="Xenko.Rendering.Materials.ComputeColors.ComputeFloat4" Collapsed="true">
<Position X="2" Y="8.25" Width="2" />
<TypeIdentifier>
<HashCode>AAAAAAAEAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<HashCode>IAAAAAAEAAQAAAAEIAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Rendering\Materials\ComputeColors\ComputeFloat4.cs</FileName>
</TypeIdentifier>
<Lollipop Position="0.2" />
Expand All @@ -72,14 +72,14 @@
<Class Name="Xenko.Rendering.Materials.ComputeColors.ComputeShaderClassBase&lt;T&gt;" Collapsed="true">
<Position X="9.75" Y="4.25" Width="2" />
<TypeIdentifier>
<HashCode>AACAAAAGAACIAAAEACAAAAAAAQAQQAAAAAAEgAAAgAA=</HashCode>
<HashCode>AAAAAAAGAAAAAAAEACAAAAAAAAAAQAAAAAAEAAAAgAA=</HashCode>
<FileName>Rendering\Materials\ComputeColors\ComputeShaderClassBase.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="Xenko.Rendering.Materials.ComputeColors.ComputeShaderClassColor" Collapsed="true">
<Position X="12" Y="5.75" Width="2.75" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<HashCode>AAgAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Rendering\Materials\ComputeColors\ComputeShaderClassColor.cs</FileName>
</TypeIdentifier>
<Lollipop Position="0.2" />
Expand All @@ -95,39 +95,39 @@
<Class Name="Xenko.Rendering.Materials.ComputeColors.ComputeTextureBase" Collapsed="true">
<Position X="4.25" Y="5.75" Width="1.75" />
<TypeIdentifier>
<HashCode>AAAAAAAEAAAQAAAEAAIAAAAAAAACAAAQAAIAIAIAgAA=</HashCode>
<HashCode>AAAAAAAUAAAQAIAEAAIgAAAAAAACAAAQAAIAIAIAgAA=</HashCode>
<FileName>Rendering\Materials\ComputeColors\ComputeTextureBase.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="Xenko.Rendering.Materials.ComputeColors.ComputeTextureColor" Collapsed="true">
<Position X="5.5" Y="7" Width="2" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<HashCode>IAAIAAAQAgAQAAAAIAAAAAAAAAAAAAAAAAAAAAEAAAA=</HashCode>
<FileName>Rendering\Materials\ComputeColors\ComputeTextureColor.cs</FileName>
</TypeIdentifier>
<Lollipop Position="0.2" />
</Class>
<Class Name="Xenko.Rendering.Materials.ComputeColors.ComputeTextureScalar" Collapsed="true">
<Position X="5.5" Y="8.25" Width="2" />
<TypeIdentifier>
<HashCode>AAAAAAAgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<HashCode>AAAIAAAwAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Rendering\Materials\ComputeColors\ComputeTextureScalar.cs</FileName>
</TypeIdentifier>
<Lollipop Position="0.2" />
</Class>
<Class Name="Xenko.Rendering.Materials.ComputeColors.ComputeStreamBase" Collapsed="true">
<Class Name="Xenko.Rendering.Materials.ComputeColors.ComputeVertexStreamBase" Collapsed="true">
<Position X="14.25" Y="4.25" Width="2" />
<TypeIdentifier>
<HashCode>AAAEAAAEAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAA=</HashCode>
<FileName>Rendering\Materials\ComputeColors\ComputeStreamBase.cs</FileName>
<FileName>Rendering\Materials\ComputeColors\ComputeVertexStreamBase.cs</FileName>
</TypeIdentifier>
<Lollipop Position="0.2" />
</Class>
<Class Name="Xenko.Rendering.Materials.ComputeColors.ComputeStreamColor" Collapsed="true">
<Class Name="Xenko.Rendering.Materials.ComputeColors.ComputeVertexStreamScalar" Collapsed="true">
<Position X="16" Y="5.75" Width="2.25" />
<TypeIdentifier>
<HashCode>AAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Rendering\Materials\ComputeColors\ComputeStreamColor.cs</FileName>
<HashCode>AAAEAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Rendering\Materials\ComputeColors\ComputeVertexStreamScalar.cs</FileName>
</TypeIdentifier>
<Lollipop Position="0.2" />
</Class>
Expand Down Expand Up @@ -156,15 +156,15 @@
<Interface Name="Xenko.Rendering.Materials.IComputeColor" Collapsed="true">
<Position X="2.75" Y="1.75" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<HashCode>AAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Rendering\Materials\IComputeColor.cs</FileName>
</TypeIdentifier>
</Interface>
<Interface Name="Xenko.Rendering.Materials.ComputeColors.IComputeStream" Collapsed="true">
<Position X="5" Y="1.75" Width="1.5" />
<Interface Name="Xenko.Rendering.Materials.ComputeColors.IComputeVertexStream" Collapsed="true">
<Position X="5" Y="1.75" Width="2.5" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAA=</HashCode>
<FileName>Rendering\Materials\ComputeColors\IComputeStream.cs</FileName>
<FileName>Rendering\Materials\ComputeColors\IComputeVertexStream.cs</FileName>
</TypeIdentifier>
</Interface>
<Font Name="Segoe UI" Size="9" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,14 @@ public ShaderSource GenerateStreamInitializers(MaterialShaderStage stage)
// the streams coming from the material layers
foreach (var streamInitializer in stageContext.StreamInitializers)
{
mixin.Mixins.Add(streamInitializer);
mixin.Mixins.Add(new ShaderClassSource(streamInitializer));
}
stageContext.StreamInitializers.Clear();

// the streams specific to a stage
// TODO: Use StreamInitializers instead of streams initializers hardcoded in MaterialPixelShadingStream.ResetStream
if (stage == MaterialShaderStage.Pixel)
mixin.Mixins.Add("MaterialPixelShadingStream");
mixin.Mixins.Add(new ShaderClassSource("MaterialPixelShadingStream"));

return mixin;
}
Expand Down
Loading

0 comments on commit 5fd0982

Please sign in to comment.