Exemple #1
0
 protected void SetAsVector(Vector4 vec, SlimDX.Direct3D11.Effect effect, int index, bool isVector3)
 {
     if (!isVector3)
     {
         effect.GetVariableByIndex(index).AsVector().Set(vec);
     }
     else
     {
         effect.GetVariableByIndex(index).AsVector().Set(new Vector3(vec.X, vec.Y, vec.Z));
     }
 }
Exemple #2
0
        public MMEEffectInfo(SlimDX.Direct3D11.Effect effect)
        {
            ScriptOutput         = "color";
            ScriptClass          = ScriptClass.Object;
            ScriptOrder          = ScriptOrder.Standard;
            StandardGlobalScript = "";
            SortedTechnique      = new List <EffectTechnique>();
            for (int i = 0; i < effect.Description.GlobalVariableCount; i++)
            {
                EffectVariable variable = effect.GetVariableByIndex(i);
                if (variable.Description.Semantic.ToUpper().Equals("STANDARDGLOBAL"))
                {
//この時この変数はSTANDARDGLOBAL
                    ParseStandardGlobal(effect, variable);
                    break;
                }
            }
        }
Exemple #3
0
        /// <summary>
        ///     コンストラクタ
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="context"></param>
        /// <param name="effect">解釈対象のエフェクト</param>
        /// <param name="model">使用対象のモデル</param>
        /// <param name="loader"></param>
        private MMEEffectManager(string fileName, RenderContext context, SlimDX.Direct3D11.Effect effect, IDrawable model, ISubresourceLoader loader)
        {
            this.fileName     = fileName;
            SubresourceLoader = loader;
            if (!fileName.Equals(MMFDefaultShaderResourcePath))
            {
                //ファイルパスがデフォルトのシェーダーと等しくない時は、デフォルトのシェーダーも読み込んでおく。
                DefaultShader = LoadFromResource(MMFDefaultShaderResourcePath, model, context, new BasicSubresourceLoader("Shader"));
            }
            else
            {
                DefaultShader = this; //等しい時は自身がデフォルトのシェーダーと等しい。
            }
            Context    = context;
            EffectFile = effect;
            EffectInfo = new MMEEffectInfo(effect);
            ActiveSubscriberByMaterial = new Dictionary <EffectVariable, SubscriberBase>();
            ActiveSubscriberByModel    = new Dictionary <EffectVariable, SubscriberBase>();
            ActivePeculiarSubscriber   = new Dictionary <EffectVariable, PeculiarValueSubscriberBase>();
            Techniques = new List <MMEEffectTechnique>();
            RenderColorTargetViewes   = new Dictionary <string, RenderTargetView>();
            RenderDepthStencilTargets = new Dictionary <string, DepthStencilView>();
            this.model = model;
            //グローバル変数の登録
            int valCount = effect.Description.GlobalVariableCount;

            for (int i = 0; i < valCount; i++)
            {
                string semantic         = Regex.Replace(effect.GetVariableByIndex(i).Description.Semantic, "[0-9]", "");
                string semanticIndexStr = Regex.Replace(effect.GetVariableByIndex(i).Description.Semantic, "[^0-9]", "");
                int    semanticIndex    = string.IsNullOrEmpty(semanticIndexStr)?0:int.Parse(semanticIndexStr);
                string typeName         = effect.GetVariableByIndex(i).GetVariableType().Description.TypeName.ToLower();
                semantic = semantic.ToUpper(); //小文字でもいいようにするため大文字に全て変換
                if (EffectSubscriber.ContainsKey(semantic))
                {                              //通常はセマンティクスに応じて登録
                    SubscriberBase subs     = EffectSubscriber[semantic];
                    EffectVariable variable = effect.GetVariableByIndex(i);
                    subs.CheckType(variable);
                    if (subs.UpdateTiming == UpdateBy.Material)
                    {
                        ActiveSubscriberByMaterial.Add(variable, subs.GetSubscriberInstance(variable, context, this, semanticIndex));
                    }
                    else
                    {
                        ActiveSubscriberByModel.Add(variable, subs.GetSubscriberInstance(variable, context, this, semanticIndex));
                    }
                }
                else if (typeName.Equals("texture") || typeName.Equals("texture2d") || typeName.Equals("texture3d") ||
                         typeName.Equals("texturecube")) //テクスチャのみ例外で、変数型に応じて登録する
                {
                    SubscriberBase subs     = new TextureSubscriber();
                    EffectVariable variable = effect.GetVariableByIndex(i);
                    subs.CheckType(variable);
                    ActiveSubscriberByModel.Add(variable, subs.GetSubscriberInstance(variable, context, this, semanticIndex));
                }
                else//特殊変数は変数名に応じて登録する
                {
                    string name = effect.GetVariableByIndex(i).Description.Name;
                    name = name.ToLower();
                    if (PeculiarEffectSubscriber.ContainsKey(name))
                    {
                        ActivePeculiarSubscriber.Add(effect.GetVariableByIndex(i), PeculiarEffectSubscriber[name]);
                    }
                }
            }
            //定数バッファの登録
            valCount = effect.Description.ConstantBufferCount;
            for (int i = 0; i < valCount; i++)
            {
                string name = effect.GetConstantBufferByIndex(i).Description.Name;
                name = name.ToUpper();
                if (EffectSubscriber.ContainsKey(name))
                {
                    SubscriberBase       subs     = EffectSubscriber[name]; //定数バッファにはセマンティクスが付けられないため、変数名で代用
                    EffectConstantBuffer variable = effect.GetConstantBufferByIndex(i);
                    subs.CheckType(variable);
                    if (subs.UpdateTiming == UpdateBy.Material)
                    {
                        ActiveSubscriberByMaterial.Add(variable, subs.GetSubscriberInstance(variable, context, this, 0));
                    }
                    else
                    {
                        ActiveSubscriberByModel.Add(variable, subs.GetSubscriberInstance(variable, context, this, 0));
                    }
                }
            }

            int subsetCount = model is ISubsetDivided ? ((ISubsetDivided)model).SubsetCount : 1;

            foreach (EffectTechnique t in EffectInfo.SortedTechnique)//MMEEffectTechniqueもソートしておく
            {
                //テクニックをすべて読みだす
                Techniques.Add(new MMEEffectTechnique(this, t, subsetCount, context));
            }
        }
Exemple #4
0
 protected void SetAsFloat(float val, SlimDX.Direct3D11.Effect effect, int index)
 {
     effect.GetVariableByIndex(index).AsScalar().Set(val);
 }
Exemple #5
0
 protected void SetAsVector(Vector3 vec, SlimDX.Direct3D11.Effect effect, int index)
 {
     effect.GetVariableByIndex(index).AsVector().Set(vec);
 }