internal static bool CheckFlags(TechniqueKey key, PropertyInfo property) { var vsData = property.GetCustomAttributes(true).OfType <VertexShaderAttribute>(); var psData = property.GetCustomAttributes(true).OfType <PixelShaderAttribute>(); return(vsData.All(vsAttribute => key.Supports(vsAttribute.Features)) && psData.All(psAttribute => key.Supports(psAttribute.Features))); }
public override void Validate(TechniqueKey key) { base.Validate(key); if (LightingMethod == null) { LightingMethod = new PhongLighting(); } LightingMethod.ActivateSignature(key); LightingMethod.SetFlag(SpecularFlag, Specular); LightingMethod.SetFlag(DiffuseMapFlag, DiffuseMap); LightingMethod.SetFlag(CubeMapFlag, CubeMap); LightingMethod.SetFlag(ShadowsFlag, Shadows); if (!Shadows) { return; } shadowMethod = new PCFShadows(); shadowMethod.ActivateSignature(key); LightingMethod.AddReference(new MethodReference(shadowMethod, new[] { MethodBase.Vectors.ShadowProjection, ShadowMapSample.Texture.FullName, ShadowMapSample.Sampler.FullName })); }
public PhongCubeMapPS() { Name = "PhongCubeMapPS"; KeyPart = new TechniqueKey(ps: PixelShaderFlags.Diffuse | PixelShaderFlags.Specular | PixelShaderFlags.CubeMap); var input = PhongCubeMapVS.VSOut; input.Name = "input"; InputStruct = input; PhongLightingNode nPhongLighting = (PhongLightingNode)((PSOutputNode)Result).FinalColor; nPhongLighting.DiffuseMap = true; nPhongLighting.CubeMap = true; Texture tDiffuse = Texture.CubeMap; Sampler sDiffuseSampler = Sampler.MinMagMipLinearWrap; nPhongLighting.DiffuseMapSample = new TextureSampleNode { Coordinates = new ReferenceNode { Value = InputStruct[Param.SemanticVariables.Texture] }, Texture = tDiffuse, Sampler = sDiffuseSampler, IsVerbose = true }; Add(tDiffuse); Add(sDiffuseSampler); }
public PhongShadowsVS() { Name = "PhongShadowsVS"; KeyPart = new TechniqueKey(vs: VertexShaderFlags.Position | VertexShaderFlags.Normal | VertexShaderFlags.TextureUV); Clear(); PhongVSOutputNode oldOutput = (PhongVSOutputNode)Result; InputStruct = Struct.VertexPositionNormalTexture; OutputStruct = VSOut; Add(CBStatic); Add(ConstantBuffer.CBPerFrame); Add(CBPerInstance); MatrixMultiplyNode mShadow = new MatrixMultiplyNode { Input1 = new ReferenceNode { Value = InputStruct[Param.SemanticVariables.Position] }, Input2 = MatrixMultiplyNode.LightWorldViewProjection }; Result = new PhongShadowsVSOutputNode { Position = oldOutput.Position, Normal = oldOutput.Normal, WorldPosition = oldOutput.WorldPosition, Texture = oldOutput.Texture, ShadowProjection = mShadow, Output = OutputStruct }; }
public FullScreenQuadVS() { Name = "FullScreenQuadVS"; Type = ShaderType.Vertex; FeatureLevel = FeatureLevel.VS_4_0_Level_9_1; KeyPart = new TechniqueKey(vs: VertexShaderFlags.Position | VertexShaderFlags.TextureUV | VertexShaderFlags.Normal); EnableSeparators = true; InputStruct = Struct.VertexPositionNormalTexture; OutputStruct = SpriteVS.VSOut; Structs.ConstantBuffer cbStatic = SpriteVS.CBStatic; Add(cbStatic); DeclarationNode nClip = ClipSpaceTransformNode.FullScreenNode(InputStruct, cbStatic[Param.Vectors.ViewportSize]); CustomOutputNode outputNode = new CustomOutputNode() { Output = OutputStruct }; outputNode.RegisterField(Vector.ClipPosition, nClip, Shaders.Type.Float4); outputNode.RegisterField(Vector.TextureUV, new ReferenceNode { Value = InputStruct[Param.SemanticVariables.Texture] }, Shaders.Type.Float2); Result = outputNode; }
public ShapeVS() { Name = "ShapeVS"; Type = ShaderType.Vertex; FeatureLevel = FeatureLevel.VS_4_0_Level_9_1; KeyPart = new TechniqueKey(vs: VertexShaderFlags.Position | VertexShaderFlags.Color); EnableSeparators = true; InputStruct = Struct.VertexPositionColor; OutputStruct = VSOut; ConstantBuffer cbScene = CBPerFrame; ConstantBuffer cbInstance = CBPerInstance; Add(cbScene); Add(cbInstance); var nPosV3toV4 = CastNode.PositionV3toV4(InputStruct[Param.SemanticVariables.Position]); var mulPosWVP = new MatrixMultiplyNode { Input1 = nPosV3toV4, Input2 = MatrixMultiplyNode.WorldViewProjection, }; CustomOutputNode outputNode = new CustomOutputNode() { Output = OutputStruct }; outputNode.RegisterField(Vector.ClipPosition, mulPosWVP, Shaders.Type.Float4); outputNode.RegisterField(Vector.Color, new ReferenceNode { Value = InputStruct[Param.SemanticVariables.Color] }, Shaders.Type.Float4); Result = outputNode; }
public SpriteDebugPS() { Name = "SpriteDebugPS"; Type = ShaderType.Pixel; KeyPart = new TechniqueKey(ps: PixelShaderFlags.Diffuse); FeatureLevel = FeatureLevel.PS_4_0_Level_9_1; EnableSeparators = true; var inputStruct = SpriteVS.VSOut; inputStruct.Name = "input"; InputStruct = inputStruct; OutputStruct = Struct.PixelShaderOutput; Struct cbMaterial = ConstantBuffer.CBMaterial; Struct material = (Struct)cbMaterial[Param.Struct.Material]; Add(cbMaterial); Result = new PSOutputNode() { FinalColor = new ReferenceNode { Value = material["Diffuse"] }, Output = OutputStruct }; }
public override void Validate(TechniqueKey key) { Contract.Requires <ArgumentNullException>(Method != null, "method"); Contract.Requires <InvalidOperationException>(Output.Type == ReturnType, "Output variable does not match return type"); base.Validate(key); Method.ActivateSignature(key); }
public ShaderBuilder(TechniqueKey key) { this.key = key; stringList = new List <string>(); parsedNodes = new List <INode>(); IndentSpaces = 4; currentIndentation = 1; }
public virtual void Validate(TechniqueKey key) { ValidateBindings(key); if (PreCondition != null) { AddNode("PreCondition", PreCondition); } RegisterNodes(); }
public override void Validate(TechniqueKey key) { base.Validate(key); if (clipSpaceMethod == null) { clipSpaceMethod = new ClipSpaceTransform(); } clipSpaceMethod.ActivateSignature(key); }
public MethodSignature(IMethod method, TechniqueKey key, string[] signatureTypes, string[] parameters, Type returnType) : this() { Contract.Requires <ArgumentException>(signatureTypes.Length == parameters.Length); Method = method; Key = key; SignatureTypes = signatureTypes; Parameters = parameters; this.returnType = returnType; }
public SpritePS() { Name = "SpritePS"; Type = ShaderType.Pixel; KeyPart = new TechniqueKey(ps: PixelShaderFlags.Diffuse | PixelShaderFlags.DiffuseMap); FeatureLevel = FeatureLevel.PS_4_0_Level_9_1; EnableSeparators = true; var inputStruct = SpriteVS.VSOut; inputStruct.Name = "input"; InputStruct = inputStruct; OutputStruct = Struct.PixelShaderOutput; Struct cbMaterial = ConstantBuffer.CBMaterial; Struct material = (Struct)cbMaterial[Param.Struct.Material]; Variable tDiffuse = Texture.Diffuse; Variable sDiffuse = Sampler.MinMagMipLinearWrap; Add(cbMaterial); Add(sDiffuse); Add(tDiffuse); TextureSampleNode nTexSample = new TextureSampleNode { Coordinates = new ReferenceNode { Value = InputStruct[Param.SemanticVariables.Texture] }, Texture = tDiffuse, Sampler = sDiffuse, IsVerbose = true, Output = new Vector() { Name = "cDiffuse", Type = Shaders.Type.Float4 } }; MultiplyNode nMultiply = new MultiplyNode { Input1 = nTexSample, Input2 = new ReferenceNode { Value = material[Param.Material.Diffuse] }, Output = new Vector { Name = "cFinal", Type = Shaders.Type.Float4 } }; Result = new PSOutputNode { FinalColor = nMultiply, Output = OutputStruct }; }
public PhongCubeMapVS() { Name = "PhongCubeMapVS"; KeyPart = new TechniqueKey(vs: VertexShaderFlags.Position | VertexShaderFlags.Normal | VertexShaderFlags.TextureUVW); InputStruct = Struct.VertexPositionNormalTextureUVW; OutputStruct = VSOut; var outputNode = (PhongVSOutputNode)Result; outputNode.Texture = new ReferenceNode { Value = InputStruct[Param.SemanticVariables.Texture] }; }
public SkyboxVS() { Name = "SkyboxVS"; Type = ShaderType.Vertex; KeyPart = new TechniqueKey(vs: VertexShaderFlags.Position | VertexShaderFlags.Normal | VertexShaderFlags.TextureUVW); FeatureLevel = FeatureLevel.VS_4_0_Level_9_1; EnableSeparators = true; InputStruct = Struct.VertexPositionNormalTextureUVW; OutputStruct = VSOutput; Add(CBStatic); Add(Structs.ConstantBuffer.CBPerFrame); IVariable position = InputStruct[Param.SemanticVariables.ObjectPosition]; IVariable texture = InputStruct[Param.SemanticVariables.Texture]; CastNode nV3toV4 = new CastNode { Input = new SwizzleNode { Input = new ReferenceNode { Value = position }, Swizzle = new[] { Swizzle.X, Swizzle.Y, Swizzle.Z, Swizzle.Null } }, Output = new Vector { Type = Shaders.Type.Float4, Name = "vPosition" }, Mask = new[] { "0", "0", "0", "1" }, IsVerbose = true }; MatrixMultiplyNode mulPosWVP = new MatrixMultiplyNode { Input1 = nV3toV4, Input2 = MatrixMultiplyNode.WorldViewProjection, Output = new Vector { Type = Shaders.Type.Float4, Name = "vSkyBoxPosition", }, }; Result = new PhongVSOutputNode { Position = new SwizzleNode { Input = mulPosWVP, Swizzle = new[] { Swizzle.X, Swizzle.Y, Swizzle.W, Swizzle.W } }, Texture = new ReferenceNode { Value = texture }, Output = OutputStruct }; }
public SkyboxPS() { Name = "SkyboxPS"; Type = ShaderType.Pixel; KeyPart = new TechniqueKey(ps: PixelShaderFlags.Diffuse); FeatureLevel = FeatureLevel.PS_4_0_Level_9_1; EnableSeparators = true; var inputStruct = SkyboxVS.VSOutput; inputStruct.Name = "input"; InputStruct = inputStruct; OutputStruct = Struct.PixelShaderOutput; Struct cbMaterial = Structs.ConstantBuffer.CBMaterial; Struct material = (Struct)cbMaterial[Param.Struct.Material]; Add(cbMaterial); Texture tDiffuse = Texture.CubeMap; Sampler sDiffuseSampler = Sampler.MinMagMipLinearWrap; Add(tDiffuse); Add(sDiffuseSampler); TextureSampleNode textureSample = new TextureSampleNode { Coordinates = new ReferenceNode { Value = InputStruct[Param.SemanticVariables.Texture] }, Texture = tDiffuse, Sampler = sDiffuseSampler }; MultiplyNode multiply = new MultiplyNode { Input1 = textureSample, Input2 = new ReferenceNode { Value = material[Param.Material.Diffuse] } }; Result = new PSOutputNode { FinalColor = multiply, Output = OutputStruct }; }
private void ValidateBindings(TechniqueKey key) { var properties = GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.PropertyType == typeof(INode)) .Concat(GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.PropertyType == typeof(IVariable))); foreach (var property in properties) { var data = property.GetValue(this); var ignoreAttribute = property.GetCustomAttribute <IgnoreValidationAttribute>(); if (ignoreAttribute != null && ignoreAttribute.Value) { Log.Daedalus.Warning(string.Format("{0} is marked to ignore validation.", property.Name)); continue; } ValidateProperty(property, key, data); } }
public void UpdateToolTip() { TechniqueKey key = TechniqueMapping.Key; StringBuilder sb = new StringBuilder(); if (key.VertexShader != VertexShaderFlags.None) { sb.AppendLine("Vertex Shader flags:"); sb.AppendLine(key.VertexShader.WriteValues()); } if (key.PixelShader != PixelShaderFlags.None) { sb.AppendLine("Pixel Shader flags:"); sb.AppendLine(key.PixelShader.WriteValues()); } ToolTip = sb.ToString(); }
public NormalMappingPS() { Name = "NormalMappingPS"; KeyPart = new TechniqueKey(ps: PixelShaderFlags.Diffuse | PixelShaderFlags.DiffuseMap | PixelShaderFlags.Specular | PixelShaderFlags.NormalMap); Struct inputStruct = Struct.VertexPositionNormalTextureTangentOut; inputStruct.Name = "input"; InputStruct = inputStruct; PhongLightingNode nPhongLighting = (PhongLightingNode)((PSOutputNode)Result).FinalColor; Texture tNormal = Texture.NormalMap; Sampler sDiffuseSampler = Get <Sampler>(Param.Samplers.MinMagMipLinearWrap); Add(tNormal); TextureSampleNode nNormalMapSample = new TextureSampleNode { Coordinates = new ReferenceNode { Value = InputStruct[Param.SemanticVariables.Texture] }, Texture = tNormal, Sampler = sDiffuseSampler, IsVerbose = true }; TrinaryFunctionNode nNormalMapping = new TrinaryFunctionNode { Input1 = nPhongLighting.Normal, Input2 = new ReferenceNode { Value = InputStruct[Param.SemanticVariables.Tangent] }, Input3 = nNormalMapSample, Function = new NormalMappingMethod(), Output = new Vector { Type = Shaders.Type.Float3, Name = "vNormalTS" }, IsVerbose = true }; nPhongLighting.Normal = nNormalMapping; }
public override void Validate(TechniqueKey key) { base.Validate(key); foreach (var nodeId in fields.Values) { var node = nodeId.Node; Type outputType = node.Output.Type; if (node == null) { throw new InvalidOperationException(string.Format("Node [{0}] cannot be null", nodeId.Variable.Name)); } if (nodeId.SupportedType != outputType) { throw new InvalidOperationException(string.Format("Node [{0}] cannot be of type [{1}]", nodeId.Variable.Name, outputType)); } if (fields.Count != ((Struct)Output).VariableCount) { throw new InvalidOperationException("Mismatch between Output struct and registered fields"); } } }
public FullScreenQuadPS() { Name = "FullScreenQuadPS"; Type = ShaderType.Pixel; KeyPart = new TechniqueKey(ps: PixelShaderFlags.DiffuseMap); FeatureLevel = FeatureLevel.PS_4_0_Level_9_1; EnableSeparators = true; var inputStruct = SpriteVS.VSOut; inputStruct.Name = "input"; InputStruct = inputStruct; OutputStruct = Struct.PixelShaderOutput; Variable tDiffuse = Texture.Diffuse; Variable sDiffuse = Sampler.MinMagMipLinearWrap; Add(sDiffuse); Add(tDiffuse); TextureSampleNode nTexSample = new TextureSampleNode { Coordinates = new ReferenceNode { Value = InputStruct[Param.SemanticVariables.Texture] }, Texture = tDiffuse, Sampler = sDiffuse, IsVerbose = true, Output = new Vector() { Name = "cDiffuse", Type = Shaders.Type.Float4 } }; Result = new PSOutputNode { FinalColor = nTexSample, Output = OutputStruct }; }
public virtual void ActivateSignature(TechniqueKey key) { try { var signatures = from kvp in methodSignatures where key.Supports(kvp.Key) let rank = key.Rank(kvp.Key) orderby rank descending select new { Rank = rank, Signature = kvp.Value }; ActiveSignature = signatures.First().Signature; } catch (InvalidOperationException e) { LogEvent.Tool.Error("Shader does not support Technique [{0}]", key); } foreach (var kvp in methodReferences) { kvp.Value.Method.ActivateSignature(key); } }
public ShapePS() { Name = "ShapePS"; Type = ShaderType.Pixel; KeyPart = new TechniqueKey(ps: PixelShaderFlags.Diffuse); FeatureLevel = FeatureLevel.PS_4_0_Level_9_1; EnableSeparators = true; var inputStruct = ShapeVS.VSOut; inputStruct.Name = "input"; InputStruct = inputStruct; OutputStruct = Struct.PixelShaderOutput; Result = new PSOutputNode { FinalColor = new ReferenceNode() { Value = InputStruct[Param.SemanticVariables.Color] }, Output = OutputStruct }; }
public PhongShadowsPS() { Name = "PhongShadowsPS"; FeatureLevel = FeatureLevel.PS_5_0; KeyPart = new TechniqueKey(ps: PixelShaderFlags.Diffuse | PixelShaderFlags.Specular | PixelShaderFlags.Shadows | PixelShaderFlags.ShadowMap, sm: FromFeatureLevel(FeatureLevel)); Clear(); PhongLightingNode nPhongLighting = (PhongLightingNode)((PSOutputNode)Result).FinalColor; var inputStruct = PhongShadowsVS.VSOut; inputStruct.Name = "input"; InputStruct = inputStruct; Structs.ConstantBuffer cbStatic = CBStatic; Structs.ConstantBuffer cbFrame = CBFrame; Texture tShadow = Texture.ShadowMap; Sampler sShadowSampler = Sampler.MinMagMiLinearMirrorLessEqual; sShadowSampler.Name = "sShadowMap"; Add(tShadow); Add(sShadowSampler); Add(cbStatic); Add(cbFrame); TextureSampleNode nShadowMapSampler = new TextureSampleNode { Coordinates = new ReferenceNode { Value = inputStruct[Param.SemanticVariables.ShadowProjection] }, Texture = tShadow, Sampler = sShadowSampler, IsVerbose = false, }; nPhongLighting.ShadowMapSample = nShadowMapSampler; nPhongLighting.Shadows = true; }
public SpriteVS() { Name = "SpriteVS"; Type = ShaderType.Vertex; FeatureLevel = FeatureLevel.VS_4_0_Level_9_1; KeyPart = new TechniqueKey(vs: VertexShaderFlags.Position | VertexShaderFlags.TextureUV | VertexShaderFlags.Normal); EnableSeparators = true; InputStruct = Struct.VertexPositionNormalTexture; OutputStruct = VSOut; Structs.ConstantBuffer cbStatic = CBStatic; Structs.ConstantBuffer cbInstance = CBPerInstance; Add(cbStatic); Add(cbInstance); ClipSpaceTransformNode cstNode = new ClipSpaceTransformNode { Position = new ReferenceNode { Value = InputStruct[Param.SemanticVariables.ObjectPosition] }, InstancePosition = cbInstance[Param.Vectors.SpritePosition], Size = cbInstance[Param.Vectors.SpriteSize], ScreenSize = cbStatic[Param.Vectors.ViewportSize] }; CustomOutputNode outputNode = new CustomOutputNode() { Output = OutputStruct }; outputNode.RegisterField(Vector.ClipPosition, cstNode, Shaders.Type.Float4); outputNode.RegisterField(Vector.TextureUV, new ReferenceNode { Value = InputStruct[Param.SemanticVariables.Texture] }, Shaders.Type.Float2); Result = outputNode; }
private static void ValidateProperty(PropertyInfo property, TechniqueKey key, object data) { bool test = false; bool dataNull = data == null; Type expectedType = Type.None; var node = data as INode; if (!dataNull) { expectedType = node != null ? node.Output.Type : ((IVariable)data).Type; } foreach (SupportedTypeAttribute attribute in property.GetCustomAttributes(true).OfType <SupportedTypeAttribute>()) { if (!CheckFlags(key, property)) { test = true; Log.Daedalus.Warning("Property [{0}] is marked as not being required. Skipping validation.", property.Name); continue; } SupportedTypeAttribute supportedTypeAttribute = attribute; if (data == null) { throw new InvalidOperationException(string.Format("Property [{0}] cannot be null.", property.Name)); } else if (SupportsType(supportedTypeAttribute.SupportedType, expectedType)) { test = true; break; } } if (!test) { throw new InvalidOperationException(string.Format("Node [{0}] cannot be of type [{1}].", property.Name, expectedType)); } }
public GlowPS() { Name = "GlowPS"; Type = ShaderType.Pixel; KeyPart = new TechniqueKey(ps: PixelShaderFlags.Diffuse | PixelShaderFlags.DiffuseMap); FeatureLevel = FeatureLevel.PS_4_0_Level_9_1; EnableSeparators = true; var inputStruct = SpriteVS.VSOut; inputStruct.Name = "input"; InputStruct = inputStruct; OutputStruct = Struct.PixelShaderOutput; Texture tDiffuse = Texture.Diffuse; Texture tGlow = new Texture { Name = "tGlow", Type = Shaders.Type.Texture2D }; Variable sLinearWrap = Sampler.MinMagMipLinearWrap; var cbFrame = CBFrame; Add(sLinearWrap); Add(tDiffuse); Add(tGlow); Add(cbFrame); TextureSampleNode nTexSample = new TextureSampleNode { Coordinates = new ReferenceNode { Value = InputStruct[Param.SemanticVariables.Texture] }, Texture = tDiffuse, Sampler = sLinearWrap, IsVerbose = true, Output = new Vector { Name = "cDiffuse", Type = Shaders.Type.Float4 } }; TextureSampleNode nGlowSample = new TextureSampleNode { Coordinates = new ReferenceNode { Value = InputStruct[Param.SemanticVariables.Texture] }, Texture = tGlow, Sampler = sLinearWrap, IsVerbose = true, Output = new Vector { Name = "cGlow", Type = Shaders.Type.Float4 } }; UnaryFunctionNode nSaturate = new UnaryFunctionNode { Input1 = new AdditionNode { Input1 = nTexSample, Input2 = new MultiplyNode { Input1 = nGlowSample, Input2 = new ReferenceNode { Value = cbFrame[Param.Floats.GlowStrength] }, Parenthesize = true } }, Function = HlslIntrinsics.Saturate }; Result = new PSOutputNode { FinalColor = nSaturate, Output = OutputStruct }; }
public BloomExtractPS() { Name = "BloomExtractPS"; Type = ShaderType.Pixel; KeyPart = new TechniqueKey(ps: PixelShaderFlags.Diffuse | PixelShaderFlags.DiffuseMap); FeatureLevel = FeatureLevel.PS_4_0_Level_9_1; EnableSeparators = true; var inputStruct = SpriteVS.VSOut; inputStruct.Name = "input"; InputStruct = inputStruct; OutputStruct = Struct.PixelShaderOutput; Texture tDiffuse = Texture.Diffuse; Sampler sLinearWrap = Sampler.MinMagMipLinearWrap; var cbFrame = CBFrame; Add(sLinearWrap); Add(tDiffuse); Add(cbFrame); TextureSampleNode nTexSample = new TextureSampleNode { Coordinates = new ReferenceNode { Value = InputStruct[Param.SemanticVariables.Texture] }, Texture = tDiffuse, Sampler = sLinearWrap, IsVerbose = true, Output = new Vector { Name = "cDiffuse", Type = Shaders.Type.Float4 } }; UnaryFunctionNode nSaturate = new UnaryFunctionNode { Input1 = new DivisionNode() { Input1 = new SubtractionNode() { Input1 = nTexSample, Input2 = new ReferenceNode() { Value = cbFrame[Param.Floats.BloomThreshold] }, Parenthesize = true }, Input2 = new SubtractionNode() { Input1 = new ScalarNode() { Value = 1.0f }, Input2 = new ReferenceNode() { Value = cbFrame[Param.Floats.BloomThreshold] }, Parenthesize = true } }, Function = HlslIntrinsics.Saturate }; Result = new PSOutputNode { FinalColor = nSaturate, Output = OutputStruct }; }
public override void Validate(TechniqueKey key) { lightingTechniqueKey = new TechniqueKey(ps: PixelShaderFlags.Diffuse | PixelShaderFlags.DiffuseMap | PixelShaderFlags.Specular); base.Validate(lightingTechniqueKey); }
public WireframeVS() { Name = "WireframeVS"; Type = ShaderType.Vertex; KeyPart = new TechniqueKey(vs: VertexShaderFlags.Position | VertexShaderFlags.Normal | VertexShaderFlags.TextureUV | VertexShaderFlags.Barycentric); FeatureLevel = FeatureLevel.VS_4_0_Level_9_1; EnableSeparators = true; InputStruct = VertexPositionNormalBarycentric; OutputStruct = VertexPositionTextureIntensityBarycentricOut; ConstantBuffer cbFrame = CBPerFrame; ConstantBuffer cbInstance = CBPerInstance; Add(cbFrame); Add(cbInstance); IVariable position = InputStruct[Param.SemanticVariables.ObjectPosition]; IVariable lightDirection = cbFrame[Param.Vectors.LightDirection]; IVariable normal = InputStruct[Param.SemanticVariables.Normal]; IVariable texture = InputStruct[Param.SemanticVariables.Texture]; IVariable barycentric = InputStruct[Param.SemanticVariables.Barycentric]; CastNode nV3toV4 = new CastNode { Input = new SwizzleNode { Input = new ReferenceNode { Value = position }, Swizzle = new[] { Swizzle.X, Swizzle.Y, Swizzle.Z, Swizzle.Null } }, Output = new Vector { Type = Shaders.Type.Float4, Name = "vPosition" }, Mask = new[] { "0", "0", "0", "1" }, IsVerbose = true }; MatrixMultiplyNode mulPosWVP = new MatrixMultiplyNode { Input1 = nV3toV4, Input2 = MatrixMultiplyNode.WorldViewProjection, Output = new Vector() { Type = Shaders.Type.Float4, Name = "vClipPosition" }, IsVerbose = true }; MultiplyNode perspectiveCorrection = new MultiplyNode() { Input1 = new ReferenceNode() { Value = barycentric }, Input2 = new SwizzleNode() { Input = mulPosWVP, Swizzle = new Swizzle[] { Swizzle.W, } } }; BinaryFunctionNode dotLightNormal = new BinaryFunctionNode { Input1 = new ReferenceNode { Value = lightDirection }, Input2 = new ReferenceNode { Value = normal }, Function = HlslIntrinsics.Dot }; BinaryFunctionNode maxIntensity = new BinaryFunctionNode { Input1 = dotLightNormal, Input2 = new ScalarNode() { Value = 0.3f }, Function = HlslIntrinsics.Max }; CustomOutputNode outputNode = new CustomOutputNode() { Output = OutputStruct }; outputNode.RegisterField(Vector.ClipPosition, mulPosWVP, Shaders.Type.Float4); outputNode.RegisterField(Param.SemanticVariables.Intensity, Semantics.Intensity, maxIntensity, Shaders.Type.Float3); outputNode.RegisterField(Vector.TextureUV, new ReferenceNode { Value = texture }, Shaders.Type.Float2); outputNode.RegisterField(Param.SemanticVariables.Barycentric, Semantics.Barycentric, perspectiveCorrection, Shaders.Type.Float3); Result = outputNode; }