本文整理汇总了C#中ShaderMixinSource.AddComposition方法的典型用法代码示例。如果您正苦于以下问题:C# ShaderMixinSource.AddComposition方法的具体用法?C# ShaderMixinSource.AddComposition怎么用?C# ShaderMixinSource.AddComposition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShaderMixinSource
的用法示例。
在下文中一共展示了ShaderMixinSource.AddComposition方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Visit
public void Visit(MaterialGeneratorContext context)
{
var alpha = Alpha ?? new ComputeFloat(0.5f);
var tint = Tint ?? new ComputeColor(Color.White);
// Use pre-multiplied alpha to support both additive and alpha blending
var blendDesc = new BlendStateDescription(Blend.One, Blend.InverseSourceAlpha);
context.Material.HasTransparency = true;
context.Parameters.Set(Effect.BlendStateKey, BlendState.NewFake(blendDesc));
var alphaColor = alpha.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.DiffuseSpecularAlphaBlendMap, MaterialKeys.DiffuseSpecularAlphaBlendValue, Color.White));
var mixin = new ShaderMixinSource();
mixin.Mixins.Add(new ShaderClassSource("ComputeColorMaterialAlphaBlend"));
mixin.AddComposition("color", alphaColor);
context.SetStream(MaterialShaderStage.Pixel, AlphaBlendStream.Stream, MaterialStreamType.Float2, mixin);
context.SetStream(AlphaBlendColorStream.Stream, tint, MaterialKeys.AlphaBlendColorMap, MaterialKeys.AlphaBlendColorValue, Color.White);
if (!context.Tags.Get(HasFinalCallback))
{
context.Tags.Set(HasFinalCallback, true);
context.AddFinalCallback(MaterialShaderStage.Pixel, AddDiffuseSpecularAlphaBlendColor);
}
}
示例2: TestRenaming
public void TestRenaming()
{
var color1Mixin = new ShaderClassSource("ComputeColorFixed", "Material.DiffuseColorValue");
var color2Mixin = new ShaderClassSource("ComputeColorFixed", "Material.SpecularColorValue");
var compMixin = new ShaderMixinSource();
compMixin.Mixins.Add(new ShaderClassSource("ComputeColorMultiply"));
compMixin.AddComposition("color1", color1Mixin);
compMixin.AddComposition("color2", color2Mixin);
var mixinSource = new ShaderMixinSource { Name = "testRenaming", UsedParameters = MixinParameters };
mixinSource.Mixins.Add(new ShaderClassSource("ShadingBase"));
mixinSource.Mixins.Add(new ShaderClassSource("AlbedoFlatShading"));
mixinSource.AddComposition("albedoDiffuse", compMixin);
var byteCode = Compiler.Compile(mixinSource, new CompilerParameters());
Assert.IsNotNull(byteCode);
}
示例3: Visit
public void Visit(MaterialGeneratorContext context)
{
if (MetalnessMap != null)
{
var computeColorSource = MetalnessMap.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.MetalnessMap, MaterialKeys.MetalnessValue));
var mixin = new ShaderMixinSource();
mixin.Mixins.Add(new ShaderClassSource("MaterialSurfaceMetalness"));
mixin.AddComposition("metalnessMap", computeColorSource);
context.UseStream(MaterialShaderStage.Pixel, "matSpecular");
context.AddSurfaceShader(MaterialShaderStage.Pixel, mixin);
}
}
示例4: VisitFeature
public override void VisitFeature(MaterialGeneratorContext context)
{
if (GlossinessMap != null)
{
context.UseStream(MaterialShaderStage.Pixel, GlossinessStream.Stream);
var computeColorSource = GlossinessMap.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.GlossinessMap, MaterialKeys.GlossinessValue));
var mixin = new ShaderMixinSource();
mixin.Mixins.Add(new ShaderClassSource("MaterialSurfaceGlossinessMap", Invert));
mixin.AddComposition("glossinessMap", computeColorSource);
context.AddSurfaceShader(MaterialShaderStage.Pixel, mixin);
}
}
示例5: Visit
public void Visit(MaterialGeneratorContext context)
{
if (DiffuseMap != null)
{
var computeColorSource = DiffuseMap.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.DiffuseMap, MaterialKeys.DiffuseValue, Color.White));
var mixin = new ShaderMixinSource();
mixin.Mixins.Add(new ShaderClassSource("MaterialSurfaceDiffuse"));
mixin.AddComposition("diffuseMap", computeColorSource);
context.UseStream(MaterialShaderStage.Pixel, DiffuseStream.Stream);
context.UseStream(MaterialShaderStage.Pixel, ColorBaseStream.Stream);
context.AddSurfaceShader(MaterialShaderStage.Pixel, mixin);
}
}
示例6: VisitFeature
public override void VisitFeature(MaterialGeneratorContext context)
{
if (NormalMap != null)
{
// Inform the context that we are using matNormal (from the MaterialSurfaceNormalMap shader)
context.UseStreamWithCustomBlend(MaterialShaderStage.Pixel, NormalStream.Stream, new ShaderClassSource("MaterialStreamNormalBlend"));
context.Parameters.Set(MaterialKeys.HasNormalMap, true);
var computeColorSource = NormalMap.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.NormalMap, MaterialKeys.NormalValue, new Color(0x80, 0x80, 0xFF, 0xFF)));
var mixin = new ShaderMixinSource();
mixin.Mixins.Add(new ShaderClassSource("MaterialSurfaceNormalMap", IsXYNormal, ScaleAndBias));
mixin.AddComposition("normalMap", computeColorSource);
context.AddSurfaceShader(MaterialShaderStage.Pixel, mixin);
}
}
示例7: SetStream
public void SetStream(MaterialShaderStage stage, string stream, MaterialStreamType streamType, ShaderSource classSource)
{
if (stream == null) throw new ArgumentNullException(nameof(stream));
// Blend stream is not part of the stream used
if (stream != MaterialBlendLayer.BlendStream)
{
GetContextPerStage(stage).Streams.Add(stream);
}
string channel;
switch (streamType)
{
case MaterialStreamType.Float:
channel = "r";
break;
case MaterialStreamType.Float2:
channel = "rg";
break;
case MaterialStreamType.Float3:
channel = "rgb";
break;
case MaterialStreamType.Float4:
channel = "rgba";
break;
default:
throw new NotSupportedException("StreamType [{0}] is not supported".ToFormat(streamType));
}
var mixin = new ShaderMixinSource();
mixin.Mixins.Add(new ShaderClassSource("MaterialSurfaceSetStreamFromComputeColor", stream, channel));
mixin.AddComposition("computeColorSource", classSource);
GetContextPerStage(stage).ShaderSources.Add(mixin);
}
示例8: VisitFeature
public override void VisitFeature(MaterialGeneratorContext context)
{
if (NormalMap != null)
{
// Inform the context that we are using matNormal (from the MaterialSurfaceNormalMap shader)
context.UseStreamWithCustomBlend(MaterialShaderStage.Pixel, NormalStream.Stream, new ShaderClassSource("MaterialStreamNormalBlend"));
context.Parameters.Set(MaterialKeys.HasNormalMap, true);
var normalMap = NormalMap;
// Workaround to make sure that normal map are setup
var computeTextureColor = normalMap as ComputeTextureColor;
if (computeTextureColor != null)
{
if (computeTextureColor.FallbackValue.Value == Color.White)
{
computeTextureColor.FallbackValue.Value = DefaultNormalColor;
}
}
else
{
var computeColor = normalMap as ComputeColor;
if (computeColor != null)
{
if (computeColor.Value == Color.Black || computeColor.Value == Color.White)
{
computeColor.Value = DefaultNormalColor;
}
}
}
var computeColorSource = NormalMap.GenerateShaderSource(context, new MaterialComputeColorKeys(MaterialKeys.NormalMap, MaterialKeys.NormalValue, DefaultNormalColor, false));
var mixin = new ShaderMixinSource();
mixin.Mixins.Add(new ShaderClassSource("MaterialSurfaceNormalMap", IsXYNormal, ScaleAndBias));
mixin.AddComposition("normalMap", computeColorSource);
context.AddShaderSource(MaterialShaderStage.Pixel, mixin);
}
}
示例9: Generate
private void Generate(MaterialShaderStage stage, MaterialGeneratorContext context)
{
if (!context.HasSurfaceShaders(stage))
{
return;
}
// Blend setup for this layer
context.SetStream(stage, BlendStream, BlendMap, MaterialKeys.BlendMap, MaterialKeys.BlendValue);
// Generate a dynamic shader name
// Create a mixin
var shaderMixinSource = new ShaderMixinSource();
shaderMixinSource.Mixins.Add(new ShaderClassSource("MaterialSurfaceStreamsBlend"));
// Add all streams
foreach (var stream in context.Streams[stage])
{
shaderMixinSource.AddCompositionToArray("blends", context.GetStreamBlendShaderSource(stream));
}
var materialBlendLayerMixin = context.GenerateSurfaceShader(stage);
// Add the shader to the mixin
shaderMixinSource.AddComposition("layer", materialBlendLayerMixin);
context.ResetSurfaceShaders(stage);
context.AddSurfaceShader(stage, shaderMixinSource);
}