{
  "Name": "FlatShader",
  "_id": "9173ca72-3c7c-4aa8-82e8-62a5fd659589",
  "Namespace": "lib.3d.material",
  "Description": "  ",
  "Inputs": [
    {
      "Name": "Code",
      "MetaInstanceID": "c8f46448-ff8d-4e20-b04e-e5e0960079f7",
      "DefaultValue": {
        "Type": "Text",
        "Value": [
          "float4x4 worldToCameraMatrix;\r",
          "float4x4 projMatrix;\r",
          "float4x4 textureMatrix;\r",
          "\r",
          "float4 ColorMul;",
          "\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",
          "    sample float4 pos : SV_POSITION;\r",
          "    sample float4 col : COLOR;\r",
          "    sample 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 colr=txDiffuse.Sample(samLinear, input.texCoord) * input.col*ColorMul;\r",
          "\r",
          "    return  colr;\r",
          "}\r",
          "\r",
          "technique10 Render\r",
          "{\r",
          "    pass P0\r",
          "    {\r",
          "        SetGeometryShader( 0 );\r",
          "        SetVertexShader( CompileShader( vs_5_0, VS() ) );\r",
          "        SetPixelShader( CompileShader( ps_5_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": "df4db8cd-470f-4398-b82e-e4190e2bd577",
      "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": "ColorMul.R",
      "MetaInstanceID": "a9bb8b91-6ab6-46c4-8f74-ed00a131d697",
      "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": "ColorMul.G",
      "MetaInstanceID": "d24362ac-1d40-4404-bf64-1e3edd5fea6b",
      "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": "ColorMul.B",
      "MetaInstanceID": "758c4f87-351a-4142-96f9-f46181bda5d6",
      "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": "ColorMul.A",
      "MetaInstanceID": "1319ea25-a06d-46c5-9df0-d51e5eeb494e",
      "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": "b747a7c6-00ae-479f-a6f2-564e3b31ef68",
      "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": "bdf97c80-3750-4c02-90c7-5e2d30e4782a",
      "MetaID": "79122951-7bc4-4c68-b085-866eab828248"
    }
  ],
  "OperatorParts": [
    {
      "MetaInstanceID": "55e956c9-2cfa-489b-b154-2bde7331424b",
      "MetaID": "a4570d8d-1922-4bda-9fe6-5f8ccb877ec9",
      "Name": "FlatShaderFunc",
      "Version": "cd179f44-68ef-4ad5-aa95-aec472dac6af",
      "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.IDa4570d8d_1922_4bda_9fe6_5f8ccb877ec9",
        "{",
        "    public class Class_FlatShader : FXSourceCodeFunction, IFXSceneSourceCode, IMaterial",
        "    {",
        "",
        "        class Renderer : BaseRenderer",
        "        {",
        "        }",
        "",
        "        public override void Dispose() {",
        "            Utilities.DisposeObj(ref _renderer);",
        "            base.Dispose();",
        "        }",
        "",
        "        //>>> _inputids",
        "        private enum InputId",
        "        {",
        "            Code = 0,",
        "            Scene = 1,",
        "            ColorMulR = 2,",
        "            ColorMulG = 3,",
        "            ColorMulB = 4,",
        "            ColorMulA = 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 ColorMulR = inputs[(int)InputId.ColorMulR].Eval(context).Value;",
        "            var ColorMulG = inputs[(int)InputId.ColorMulG].Eval(context).Value;",
        "            var ColorMulB = inputs[(int)InputId.ColorMulB].Eval(context).Value;",
        "            var ColorMulA = inputs[(int)InputId.ColorMulA].Eval(context).Value;",
        "            var ColorMul = new Color4(ColorMulR, ColorMulG, ColorMulB, ColorMulA);",
        "            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;",
        "            }",
        "",
        "            var prevEffect = context.Effect;",
        "            var prevRenderer = context.Renderer;",
        "            context.Effect = _effect;",
        "            context.Renderer = _renderer;",
        "",
        "            var prevMaterial = (IMaterial) context.Objects[OperatorPartContext.MATERIAL_ID];",
        "            context.Objects[OperatorPartContext.MATERIAL_ID] = this;",
        "            if (OverrideAlpha > 0.5f) ",
        "            {",
        "                ColorMulA *= prevMaterial.Diffuse.Alpha;",
        "                ColorMul.Alpha = ColorMulA;",
        "            }",
        "            Diffuse = ColorMul;",
        "",
        "            _effect.GetVariableByName(\"ColorMul\").AsVector().Set(new Vector4(ColorMulR, ColorMulG, ColorMulB,ColorMulA)); ",
        "",
        "            Scene.Eval(context);",
        "            context.Objects[OperatorPartContext.MATERIAL_ID] = prevMaterial;",
        "            context.Effect = prevEffect;",
        "            context.Renderer = prevRenderer;",
        "",
        "            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": "55e956c9-2cfa-489b-b154-2bde7331424b",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "bdf97c80-3750-4c02-90c7-5e2d30e4782a"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "c8f46448-ff8d-4e20-b04e-e5e0960079f7",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "55e956c9-2cfa-489b-b154-2bde7331424b"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "df4db8cd-470f-4398-b82e-e4190e2bd577",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "55e956c9-2cfa-489b-b154-2bde7331424b"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "a9bb8b91-6ab6-46c4-8f74-ed00a131d697",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "55e956c9-2cfa-489b-b154-2bde7331424b"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "d24362ac-1d40-4404-bf64-1e3edd5fea6b",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "55e956c9-2cfa-489b-b154-2bde7331424b"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "758c4f87-351a-4142-96f9-f46181bda5d6",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "55e956c9-2cfa-489b-b154-2bde7331424b"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "1319ea25-a06d-46c5-9df0-d51e5eeb494e",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "55e956c9-2cfa-489b-b154-2bde7331424b"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "b747a7c6-00ae-479f-a6f2-564e3b31ef68",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "55e956c9-2cfa-489b-b154-2bde7331424b"
    }
  ]
}