本文整理汇总了C#中CompilationContext.GetShaderTemplate方法的典型用法代码示例。如果您正苦于以下问题:C# CompilationContext.GetShaderTemplate方法的具体用法?C# CompilationContext.GetShaderTemplate怎么用?C# CompilationContext.GetShaderTemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CompilationContext
的用法示例。
在下文中一共展示了CompilationContext.GetShaderTemplate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compile
public void Compile(CompilationContext context, string inputPath, string outputPath, Database.ContentEntry contentData)
{
outputPath += ".mat";
Material material;
using (var nodeGraphPanel = new NodeGraphPanel())
{
nodeGraphPanel.View.RegisterDataType(new NodeGraphDataTypeFloat());
nodeGraphPanel.View.RegisterDataType(new NodeGraphDataTypeVector3());
nodeGraphPanel.View.RegisterDataType(new NodeGraphDataTypeVector4());
nodeGraphPanel.LoadCurrentViewPure(inputPath);
RootNode root = null;
foreach (var node in nodeGraphPanel.View.NodeCollection)
{
if (node is RootNode)
{
root = node as RootNode;
break;
}
}
var result = root.Process(0) as BuildShaderData;
material = new Material();
material.ShaderSource = result.Value;
material.Defines = result.Defines;
material.Samplers = new Dictionary<string, string>(Context.Samplers);
}
var murmur128 = MurmurHash.Create128(managed: false);
var shader = Encoding.UTF8.GetBytes(material.ShaderSource);
var hash = murmur128.ComputeHash(shader);
var shaderName = BitConverter.ToString(hash).ToLowerInvariant().Replace("-", "");
var shaderPath = "generated/shaders/" + shaderName;
var shaderOutputPath = context.GetOutputPath(shaderPath + ".glsl");
var template = context.GetShaderTemplate();
material.ShaderSource = template.Replace("//__MATERIAL__PLACEHOLDER__", material.ShaderSource);
if (material.Defines.Count > 0)
material.ShaderSource = material.Defines.Select(d => "#define " + d).Aggregate((a, b) => a + "\n" + b) + "\n" + material.ShaderSource;
using (var stream = context.OpenOutput(shaderPath + ".glsl"))
using (var writer = new StreamWriter(stream))
{
writer.Write(material.ShaderSource);
}
using (var stream = File.Open(outputPath, FileMode.Create))
using (var writer = new BinaryWriter(stream))
{
// Magic
writer.Write('M');
writer.Write('A');
writer.Write('T');
writer.Write('E');
// Version
writer.Write(Version);
// Shader reference
writer.Write("/shaders/" + shaderName);
// Samplers
writer.Write(material.Samplers.Count);
foreach (var sampler in material.Samplers)
{
writer.Write(sampler.Key);
writer.Write(sampler.Value);
}
}
}