{
  "Name": "FadeAtDistanceShader",
  "_id": "641d71e4-96c0-4d6f-acfd-d89d63d5ebe9",
  "Namespace": "lib.3d.material",
  "Description": "",
  "Inputs": [
    {
      "Name": "Code",
      "MetaInstanceID": "315dc8e1-9e4f-447b-a148-7d017ce190fa",
      "DefaultValue": {
        "Type": "Text",
        "Value": [
          "float4x4 worldToCameraMatrix;\r",
          "float4x4 projMatrix;\r",
          "float4x4 textureMatrix;\r",
          "\r",
          "float4 ColorMul;",
          "float Distance;",
          "\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 colr=txDiffuse.Sample(samLinear, input.texCoord) * input.col*ColorMul;\r",
          "    float depth = pow(min(1,(1-input.pos.z)*Distance),3);\r",
          "    colr.a *=depth;\r",
          "\r",
          "    return  colr;\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": "22d02ad6-a207-4c33-9d7e-77d415d9abce",
      "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": "e370f795-e9e8-4aec-8aab-10f4d60ce46d",
      "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": "8fd93428-38d5-4c27-9d3b-83ac51e9e013",
      "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": "80302463-0803-4b6c-89ab-2ac6eae37e9b",
      "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": "6bd805b5-0261-4e2a-8b53-7dcdbeb1edba",
      "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": "43cec989-d676-4dda-aa4f-4b10d8494b24",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0"
      },
      "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"
        }
      ]
    },
    {
      "Name": "Distance",
      "MetaInstanceID": "e34c3e41-4775-4522-9574-34c30e38b928",
      "DefaultValue": {
        "Type": "Float",
        "Value": "30000"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    }
  ],
  "Outputs": [
    {
      "Name": "Scene",
      "MetaInstanceID": "11feed23-0882-4e5a-94fd-6d5cc2fb03bb",
      "MetaID": "79122951-7bc4-4c68-b085-866eab828248"
    }
  ],
  "OperatorParts": [
    {
      "MetaInstanceID": "7eff19e0-c5ec-4c83-a62e-22ee3d1b2761",
      "MetaID": "777ec336-d457-4826-b1b4-988c1d0318cd",
      "Name": "FadeAtDistanceShaderFunc",
      "Version": "09dc45a8-d40c-48b8-90b5-8ad9cb9ca740",
      "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.ID777ec336_d457_4826_b1b4_988c1d0318cd",
        "{",
        "    public class Class_FadeAtDistanceShader : 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,",
        "            Distance = 7",
        "        }",
        "        //<<< _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;",
        "            var Distance = inputs[(int)InputId.Distance].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)); ",
        "            _effect.GetVariableByName(\"Distance\").AsScalar().Set(Distance); ",
        "",
        "            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": "7eff19e0-c5ec-4c83-a62e-22ee3d1b2761",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "11feed23-0882-4e5a-94fd-6d5cc2fb03bb"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "315dc8e1-9e4f-447b-a148-7d017ce190fa",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "7eff19e0-c5ec-4c83-a62e-22ee3d1b2761"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "22d02ad6-a207-4c33-9d7e-77d415d9abce",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "7eff19e0-c5ec-4c83-a62e-22ee3d1b2761"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "e370f795-e9e8-4aec-8aab-10f4d60ce46d",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "7eff19e0-c5ec-4c83-a62e-22ee3d1b2761"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "8fd93428-38d5-4c27-9d3b-83ac51e9e013",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "7eff19e0-c5ec-4c83-a62e-22ee3d1b2761"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "80302463-0803-4b6c-89ab-2ac6eae37e9b",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "7eff19e0-c5ec-4c83-a62e-22ee3d1b2761"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "6bd805b5-0261-4e2a-8b53-7dcdbeb1edba",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "7eff19e0-c5ec-4c83-a62e-22ee3d1b2761"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "43cec989-d676-4dda-aa4f-4b10d8494b24",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "7eff19e0-c5ec-4c83-a62e-22ee3d1b2761"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "e34c3e41-4775-4522-9574-34c30e38b928",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "7eff19e0-c5ec-4c83-a62e-22ee3d1b2761"
    }
  ]
}