{
  "Name": "PremultiplyShader",
  "_id": "5deee034-cb90-4e19-bb9f-5391abc63f96",
  "Namespace": "lib.3d.material",
  "Description": "",
  "Inputs": [
    {
      "Name": "Code",
      "MetaInstanceID": "8c9fddca-7297-442d-88a6-f4bb4c263421",
      "DefaultValue": {
        "Type": "Text",
        "Value": [
          "float4x4 worldToCameraMatrix;\r",
          "float4x4 projMatrix;\r",
          "float4x4 textureMatrix;\r",
          "\r",
          "float4 Color;",
          "\r",
          "Texture2D txDiffuse;\r",
          "\r",
          "SamplerState samLinear\r",
          "{\r",
          "    Filter = MIN_MAG_MIP_LINEAR;\r",
          "    AddressU = Wrap;\r",
          "    AddressV = Wrap;\r",
          "};\r",
          "\r",
          "struct VS_IN\r",
          "{\r",
          "    float4 pos : POSITION;\r",
          "    float3 normal: NORMAL;\r",
          "    float4 col : COLOR;\r",
          "    float2 texCoord : TEXCOORD;\r",
          "    float3 tangent: TANGENT;\r",
          "    float3 binormal: BINORMAL;\r",
          "};\r",
          "\r",
          "struct PS_IN\r",
          "{\r",
          "    \r",
          "    float4 pos : SV_POSITION;\r",
          "    float4 col : COLOR;\r",
          "    float2 texCoord: TEXCOORD0;\r",
          "};\r",
          "\r",
          "PS_IN VS( VS_IN input )\r",
          "{\r",
          "    PS_IN output = (PS_IN)0;\r",
          "\r",
          "    output.pos = mul(input.pos, worldToCameraMatrix);\r",
          "    output.pos = mul(output.pos, projMatrix);\r",
          "    output.col = input.col;\r",
          "    output.texCoord = mul(float4(input.texCoord.xy, 0, 1), textureMatrix).xy;\r",
          "\r",
          "    return output;\r",
          "}\r",
          "\r",
          "float4 PS( PS_IN input ) : SV_Target\r",
          "{\r",
          "    float4 c_in=txDiffuse.Sample(samLinear, input.texCoord);\r",
          "    return  float4(Color.rgb, c_in.a * Color.a);\r",
          "}\r",
          "\r",
          "technique10 Render\r",
          "{\r",
          "    pass P0\r",
          "    {\r",
          "        SetGeometryShader( 0 );\r",
          "        SetVertexShader( CompileShader( vs_4_0, VS() ) );\r",
          "        SetPixelShader( CompileShader( ps_4_0, PS() ) );\r",
          "    }\r",
          "}\r",
          ""
        ]
      },
      "MetaID": "c522a66e-3260-4692-b3e3-79fd0361fa3d",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Scene",
      "MetaInstanceID": "812732e8-2a0d-4960-a27b-1525c635407e",
      "DefaultValue": {
        "Type": "Scene",
        "Value": "Framefield.Core.Scene"
      },
      "MetaID": "79122951-7bc4-4c68-b085-866eab828248",
      "IsMultiInput": "False",
      "Relevance": "Required",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Color.R",
      "MetaInstanceID": "d76acb2e-cd5b-43e5-b73d-58853d65bf3f",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "0",
      "Max": "1",
      "Scale": "0.01",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Color.G",
      "MetaInstanceID": "d1334e0b-5d1e-4eb7-a9c8-3a5ce59de653",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "0",
      "Max": "1",
      "Scale": "0.01",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Color.B",
      "MetaInstanceID": "798b807d-f49b-4a5d-a0aa-f1aa2c2600d6",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "0",
      "Max": "1",
      "Scale": "0.01",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Color.A",
      "MetaInstanceID": "a29c6a57-9e6b-4f7f-92c5-9c74f9cdd493",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "0",
      "Max": "1",
      "Scale": "0.01",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "OverrideAlpha",
      "MetaInstanceID": "8e546a83-6e16-47a9-9d3f-34d792389ca9",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": [
        {
          "Name": "Override",
          "Value": "0"
        },
        {
          "Name": "Multiply",
          "Value": "1"
        }
      ]
    }
  ],
  "Outputs": [
    {
      "Name": "Scene",
      "MetaInstanceID": "597c0ae6-9c8c-4200-a9e4-75a00ad2350f",
      "MetaID": "79122951-7bc4-4c68-b085-866eab828248"
    }
  ],
  "OperatorParts": [
    {
      "MetaInstanceID": "56e269b1-c44b-4fa4-abc1-9257331d29e8",
      "MetaID": "e4fb57ea-1e2a-4a45-9969-0356de61f2a7",
      "Name": "PremultiplyShaderFunc",
      "Version": "3d1ef0f3-96db-40c4-add4-ce1f4b9f4a4c",
      "Type": "Float",
      "IsMultiInput": "True",
      "Script": [
        "using System;",
        "using System.Collections.Generic;",
        "using System.Runtime.InteropServices;",
        "using SharpDX;",
        "using SharpDX.Direct3D11;",
        "using Framefield.Core.Rendering;",
        "using Buffer = SharpDX.Direct3D11.Buffer;",
        "",
        "namespace Framefield.Core.IDe4fb57ea_1e2a_4a45_9969_0356de61f2a7",
        "{",
        "    public class Class_PremultiplyShader : FXSourceCodeFunction, IFXSceneSourceCode, IMaterial    ",
        "    {",
        "",
        "        class Renderer : BaseRenderer",
        "        {",
        "        }",
        "",
        "        public override void Dispose() {",
        "            Utilities.DisposeObj(ref _renderer);",
        "            base.Dispose();",
        "        }",
        "",
        "        //>>> _inputids",
        "        private enum InputId",
        "        {",
        "            Code = 0,",
        "            Scene = 1,",
        "            ColorR = 2,",
        "            ColorG = 3,",
        "            ColorB = 4,",
        "            ColorA = 5,",
        "            OverrideAlpha = 6",
        "        }",
        "        //<<< _inputids",
        "        bool _firstEval = true;",
        "        public override OperatorPartContext Eval(OperatorPartContext context, List<OperatorPart> inputs, int outputIdx) {",
        "            //>>> _params",
        "            var Code = inputs[(int)InputId.Code].Eval(context).Text;",
        "            var Scene = inputs[(int)InputId.Scene];",
        "            var ColorR = inputs[(int)InputId.ColorR].Eval(context).Value;",
        "            var ColorG = inputs[(int)InputId.ColorG].Eval(context).Value;",
        "            var ColorB = inputs[(int)InputId.ColorB].Eval(context).Value;",
        "            var ColorA = inputs[(int)InputId.ColorA].Eval(context).Value;",
        "            var Color = new Color4(ColorR, ColorG, ColorB, ColorA);",
        "            var OverrideAlpha = (int) inputs[(int)InputId.OverrideAlpha].Eval(context).Value;",
        "            //<<< _params",
        "        ",
        "            if (_firstEval) {",
        "                for (int i = 0; i < NumCodes(); ++i)",
        "                    Compile(i);",
        "                _firstEval = false;",
        "                Changed = true;",
        "            }",
        "",
        "            using (new PropertyStasher<OperatorPartContext>(context, \"Effect\", \"Renderer\")) {",
        "                context.Effect = _effect;",
        "                context.Renderer = _renderer;",
        "            ",
        "",
        "                var prevMaterial = (IMaterial) context.Objects[OperatorPartContext.MATERIAL_ID];",
        "                ",
        "                if(OverrideAlpha > 0.5f) {",
        "                    ColorA *= prevMaterial.Diffuse.Alpha;",
        "                    ",
        "                }",
        "                Color.Alpha = ColorA;",
        "                Diffuse = Color;",
        "                ",
        "                _effect.GetVariableByName(\"Color\").AsVector().Set(new Vector4(ColorR, ColorG, ColorB,ColorA)); ",
        "                ",
        "                context.Objects[OperatorPartContext.MATERIAL_ID] = this;",
        "                Scene.Eval(context);",
        "                ",
        "                context.Objects[OperatorPartContext.MATERIAL_ID] = prevMaterial;",
        "                ",
        "            }",
        "",
        "            return context;",
        "        }",
        "",
        "        private Renderer _renderer = new Renderer();",
        "        ",
        "        public Color4 Ambient { get; private set; }",
        "        public Color4 Diffuse { get; private set; }",
        "        public Color4 Specular { get; private set; }",
        "        public Color4 Emission { get; private set; }",
        "        public float Shininess { get; private set; }",
        "    }",
        "}",
        "",
        "",
        ""
      ],
      "AdditionalAssemblies": []
    }
  ],
  "Operators": [],
  "Connections": [
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "56e269b1-c44b-4fa4-abc1-9257331d29e8",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "597c0ae6-9c8c-4200-a9e4-75a00ad2350f"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "8c9fddca-7297-442d-88a6-f4bb4c263421",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "56e269b1-c44b-4fa4-abc1-9257331d29e8"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "812732e8-2a0d-4960-a27b-1525c635407e",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "56e269b1-c44b-4fa4-abc1-9257331d29e8"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "d76acb2e-cd5b-43e5-b73d-58853d65bf3f",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "56e269b1-c44b-4fa4-abc1-9257331d29e8"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "d1334e0b-5d1e-4eb7-a9c8-3a5ce59de653",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "56e269b1-c44b-4fa4-abc1-9257331d29e8"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "798b807d-f49b-4a5d-a0aa-f1aa2c2600d6",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "56e269b1-c44b-4fa4-abc1-9257331d29e8"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "a29c6a57-9e6b-4f7f-92c5-9c74f9cdd493",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "56e269b1-c44b-4fa4-abc1-9257331d29e8"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "8e546a83-6e16-47a9-9d3f-34d792389ca9",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "56e269b1-c44b-4fa4-abc1-9257331d29e8"
    }
  ]
}