Exemple #1
0
        public override FunctionBase GetExecuterInstance(int index, string value, RenderContext context, ScriptRuntime runtime,
                                                         MMEEffectManager manager, MMEEffectTechnique technique, MMEEffectPass pass)
        {
            LoopByCountFunction func = new LoopByCountFunction();

            func.runtime = runtime;
            if (string.IsNullOrWhiteSpace(value))
            {
                throw new InvalidMMEEffectShaderException("LoopByCount=;は指定できません。int,float,boolいずれかの変数名を伴う必要があります。");
            }
            EffectVariable rawVariable = manager.EffectFile.GetVariableByName(value);
            string         typeName    = rawVariable.GetVariableType().Description.TypeName.ToLower();
            int            loopCount   = 0;

            switch (typeName)
            {
            case "bool":
            case "int":
                loopCount = rawVariable.AsScalar().GetInt();
                break;

            case "float":
                loopCount = (int)rawVariable.AsScalar().GetFloat();
                break;

            default:
                throw new InvalidMMEEffectShaderException("LoopByCountに指定できる変数の型はfloat,int,boolのいずれかです。");
            }
            func.loopCount = loopCount;
            return(func);
        }
Exemple #2
0
        public override FunctionBase GetExecuterInstance(int index, string value, RenderContext context, ScriptRuntime runtime,
                                                         MMEEffectManager manager, MMEEffectTechnique technique, MMEEffectPass pass)
        {
            LoopEndFunction func = new LoopEndFunction();

            return(func);
        }
Exemple #3
0
 private void Parse(RenderContext context, MMEEffectManager manager, MMEEffectTechnique technique, MMEEffectPass pass)
 {
     ParsedExecuters = new List <FunctionBase>();
     if (string.IsNullOrWhiteSpace(ScriptCode))
     {
         return;
     }
     string[] splittedFunctions = ScriptCode.Split(';');//;で分割し1命令ごとにする
     foreach (string function in splittedFunctions)
     {
         if (string.IsNullOrWhiteSpace(function))
         {
             continue;
         }
         int      index    = 0;
         string[] segments = function.Split('=');//=で分割し、関数名と引数を分ける
         if (segments.Length > 2)
         {
             throw new InvalidMMEEffectShaderException("スクリプト中の=の数が多すぎます。");
         }
         char lastCharacter = segments[0][segments[0].Length - 1];
         if (char.IsNumber(lastCharacter))
         {
             segments[0] = segments[0].Remove(segments[0].Length - 1);
             index       = int.Parse(lastCharacter.ToString());
         }
         if (ScriptFunctions.ContainsKey(segments[0]))
         {
             ParsedExecuters.Add(ScriptFunctions[segments[0]].GetExecuterInstance(index, segments[1], context, this, manager, technique, pass));
         }
     }
 }
Exemple #4
0
        public override FunctionBase GetExecuterInstance(int index, string value, RenderContext context, ScriptRuntime runtime,
                                                         MMEEffectManager manager, MMEEffectTechnique technique, MMEEffectPass pass)
        {
            DrawFunction func = new DrawFunction();

            if (pass == null)
            {
                throw new InvalidMMEEffectShaderException(string.Format("Drawはテクニックのスクリプトに関して適用できません。"));
            }
            func.targetPass = pass;
            func.context    = context.DeviceManager.Context;
            switch (value)
            {
            case "Geometry":
                func.isDrawGeometry = true;
                break;

            case "Buffer":
                func.isDrawGeometry = false;
                break;

            default:
                throw new InvalidMMEEffectShaderException(string.Format("Draw={0}が指定されましたが、Drawに指定できるのはGeometryまたはBufferです。", value));
            }
            if (func.isDrawGeometry && manager.EffectInfo.ScriptClass == ScriptClass.Scene)
            {
                throw new InvalidMMEEffectShaderException("Draw=Geometryが指定されましたが、STANDARDGLOBALのScriptClassに\"scene\"を指定している場合、これはできません。");
            }
            if (!func.isDrawGeometry && manager.EffectInfo.ScriptClass == ScriptClass.Object)
            {
                throw new InvalidMMEEffectShaderException("Draw=Bufferが指定されましたが、STANDARDGLOBALのScriptClassに\"object\"を指定している場合、これはできません。");
            }
            return(func);
        }
Exemple #5
0
        public override FunctionBase GetExecuterInstance(int index, string value, RenderContext context, ScriptRuntime runtime,
                                                         MMEEffectManager manager, MMEEffectTechnique technique, MMEEffectPass pass)
        {
            LoopGetIndexFunction func = new LoopGetIndexFunction();

            func.targetVariable = manager.EffectFile.GetVariableByName(value);
            func.runtime        = runtime;
            return(func);
        }
Exemple #6
0
 private void Initialize()
 {
     Transformer = new BasicTransformer();
     for (int i = 0; i < modelScene.Meshes.Count; i++)
     {
         subsets.Add(new AssimpSubset(context, loader, this, modelScene, i));
     }
     effectManager = MMEEffectManager.LoadFromResource(@"MMF.Resource.Shader.DefaultShader.fx", this, context, loader);
     layout        = new InputLayout(context.DeviceManager.Device, effectManager.EffectFile.GetTechniqueByIndex(1).GetPassByIndex(0).Description.Signature, BasicInputLayout.VertexElements);
 }
Exemple #7
0
        //public Task LoadAsync(RenderContext renderContext)
        //{
        //    Task task=new Task(() => Load(renderContext));
        //    task.Start();
        //    return task;
        //}


        #endregion

        #region 初期化系

        /// <summary>
        /// Loads the effect.
        /// </summary>
        /// <param name="effectFile">The effect file.</param>
        public void LoadEffect(string effectFile)
        {
            if (Effect != null)
            {
                Effect.Dispose();
            }
            if (string.IsNullOrEmpty(effectFile))
            {
                Effect = MMEEffectManager.Load(@"Shader\DefaultShader.fx", this, RenderContext, SubresourceLoader);
            }
            else
            {
                Effect = MMEEffectManager.Load(effectFile, this, RenderContext, SubresourceLoader);
            }
            SubsetManager.ResetEffect(Effect);
        }
Exemple #8
0
        public override FunctionBase GetExecuterInstance(int index, string value, RenderContext context, ScriptRuntime runtime,
                                                         MMEEffectManager manager, MMEEffectTechnique technique, MMEEffectPass pass)
        {
            PassFunction func = new PassFunction();

            if (technique == null)
            {
                throw new InvalidMMEEffectShaderException(string.Format("スクリプト内でPassを利用できるのはテクニックに適用されたスクリプトのみです。パスのスクリプトでは実行できません。"));
            }
            if (!technique.Passes.ContainsKey(value))
            {
                throw new InvalidMMEEffectShaderException(string.Format("スクリプトで指定されたテクニック中では指定されたパス\"{0}\"は見つかりませんでした。(スペルミス?)", value));
            }
            func.targetPass = technique.Passes[value];
            return(func);
        }
Exemple #9
0
        public override FunctionBase GetExecuterInstance(int index, string value, RenderContext context, ScriptRuntime runtime,
                                                         MMEEffectManager manager, MMEEffectTechnique technique, MMEEffectPass pass)
        {
            ClearSetColorFunction func = new ClearSetColorFunction();

            func.sourceVariable = manager.EffectFile.GetVariableByName(value);
            func.context        = context;
            if (func.sourceVariable == null)
            {
                throw new InvalidMMEEffectShaderException(string.Format("ClearSetColor={0};が指定されましたが、変数\"{0}\"は見つかりませんでした。", value));
            }
            if (!func.sourceVariable.GetVariableType().Description.TypeName.ToLower().Equals("float4"))
            {
                throw new InvalidMMEEffectShaderException(string.Format("ClearSetColor={0};が指定されましたが、変数\"{0}\"はfloat4型ではありません。", value));
            }
            return(func);
        }
        /// <summary>
        ///     Device initialization
        /// </summary>
        /// <param name="control">A reference to the controls applied</param>
        public void Load(bool needDX11 = false, DeviceCreationFlags dx11flag = DeviceCreationFlags.None, SlimDX.Direct3D10.DeviceCreationFlags dx10flag_for2DDraw = SlimDX.Direct3D10.DeviceCreationFlags.BgraSupport)
        {
            ApplyDebugFlags(ref dx11flag, ref dx10flag_for2DDraw);
            this.Factory        = new Factory1();
            this.CurrentAdapter = this.Factory.GetAdapter1(0);
            //Initialization of the swap chain
            try
            {
                this.Device = new Device(this.CurrentAdapter, dx11flag,
                                         new[] { FeatureLevel.Level_11_0 });
            }
            catch (Direct3D11Exception)
            {
                if (needDX11)
                {
                    throw new NotSupportedException("DX11 is not supported. To initialize in DX10.1 should be the first argument needDraw = false of Load.");
                }
                try
                {
                    this.Device = new Device(this.CurrentAdapter, dx11flag, new[] { FeatureLevel.Level_10_0 });
                }
                catch (Direct3D11Exception)
                {
                    throw new NotSupportedException("DX11,DX10.1 An attempt was made to initialization in, but both are not supported.");
                }
            }

            this.DeviceFeatureLevel = this.Device.FeatureLevel;
            this.Context            = this.Device.ImmediateContext;
            SampleDescription sampleDesc = new SampleDescription(1, 0);

#if VSG_DEBUG
#else
            this.Device10 = new Device1(this.CurrentAdapter, DriverType.Hardware,
                                        dx10flag_for2DDraw, SlimDX.Direct3D10_1.FeatureLevel.Level_9_3);
#endif
            MMEEffectManager.IniatializeMMEEffectManager(this);
        }
        /// <summary>
        ///     デバイスの初期化処理
        /// </summary>
        /// <param name="control">適用するコントロールへの参照</param>
        public void Load(bool needDX11 = false, DeviceCreationFlags dx11flag = DeviceCreationFlags.None, SlimDX.Direct3D10.DeviceCreationFlags dx10flag_for2DDraw = SlimDX.Direct3D10.DeviceCreationFlags.BgraSupport)
        {
            ApplyDebugFlags(ref dx11flag, ref dx10flag_for2DDraw);
            Factory        = new Factory1();
            CurrentAdapter = Factory.GetAdapter1(0);
            //スワップチェーンの初期化
            try
            {
                Device = new Device(CurrentAdapter, dx11flag,
                                    new[] { FeatureLevel.Level_11_0 });
            }
            catch (Direct3D11Exception)
            {
                if (needDX11)
                {
                    throw new NotSupportedException("DX11がサポートされていません。DX10.1で初期化するにはLoadの第一引数needDraw=falseとして下さい。");
                }
                try
                {
                    Device = new Device(CurrentAdapter, dx11flag, new[] { FeatureLevel.Level_10_0 });
                }
                catch (Direct3D11Exception)
                {
                    throw new NotSupportedException("DX11,DX10.1での初期化を試みましたが、両方ともサポートされていません。");
                }
            }

            DeviceFeatureLevel = Device.FeatureLevel;
            Context            = Device.ImmediateContext;
            SampleDescription sampleDesc = new SampleDescription(1, 0);

#if VSG_DEBUG
#else
            Device10 = new Device1(CurrentAdapter, DriverType.Hardware,
                                   dx10flag_for2DDraw, SlimDX.Direct3D10_1.FeatureLevel.Level_9_3);
#endif
            MMEEffectManager.IniatializeMMEEffectManager(this);
        }
Exemple #12
0
        public override SubscriberBase GetSubscriberInstance(EffectVariable variable, RenderContext context, MMEEffectManager effectManager, int semanticIndex)
        {
            EffectVariable annotation = EffectParseHelper.getAnnotation(variable, "Object", "string");

            if (annotation == null || string.IsNullOrWhiteSpace(annotation.AsString().GetString()))
            {
                throw new InvalidMMEEffectShaderException(
                          string.Format(
                              "変数「{0} {1}:{2}」にはアノテーション「string Object=\"Light\"」または「string object=\"Camera\"」が必須ですが指定されませんでした。",
                              variable.GetVariableType().Description.TypeName.ToLower(), variable.Description.Name,
                              variable.Description.Semantic));
            }
            string objectStr = annotation.AsString().GetString().ToLower();
            ObjectAnnotationType type;

            switch (objectStr)
            {
            case "camera":
                type = ObjectAnnotationType.Camera;
                break;

            case "light":
                type = ObjectAnnotationType.Light;
                break;

            default:
                throw new InvalidMMEEffectShaderException(
                          string.Format(
                              "変数「{0} {1}:{2}」にはアノテーション「string Object=\"Light\"」または「string object=\"Camera\"」が必須ですが指定されたのは,「string object=\"{3}\"でした。(スペルミス?)"
                              , variable.GetVariableType().Description.TypeName.ToLower(), variable.Description.Name,
                              variable.Description.Semantic, objectStr));
            }
            return(GetSubscriberInstance(type));
        }
Exemple #13
0
        public void Initialze(RenderContext context, MMEEffectManager effectManager, ISubresourceLoader subresourceManager,
                              IToonTextureManager ToonManager)
        {
            MMEEffect               = effectManager;
            toonManager             = ToonManager;
            Subsets                 = new List <ISubset>();
            this.device             = context.DeviceManager.Device;
            this.subresourceManager = subresourceManager;
            ModelData model     = this.model;
            int       vertexSum = 0;

            for (int i = 0; i < model.MaterialList.MaterialCount; i++)
            {
                MaterialData material = model.MaterialList.Materials[i];//サブセットデータを作成する
                PMXSubset    dr       = new PMXSubset(Drawable, material, i);
                dr.DoCulling   = !material.bitFlag.HasFlag(RenderFlag.CullNone);
                dr.VertexCount = material.VertexNumber / 3;
                dr.StartIndex  = vertexSum;
                if (material.textureIndex >= toonManager.ResourceViews.Length)
                {
                    if (toonManager.ResourceViews.Length == 0)
                    {
                        int index = ToonManager.LoadToon(model.TextureList.TexturePathes[material.textureIndex]);
                        dr.MaterialInfo.ToonTexture = ToonManager.ResourceViews[index];
                        dr.MaterialInfo.IsToonUsed  = false;
                    }
                    else
                    {
                        dr.MaterialInfo.ToonTexture = ToonManager.ResourceViews[0];
                        dr.MaterialInfo.IsToonUsed  = false;
                    }
                }
                else
                {
                    if (material.ShareToonFlag == 1)
                    {
                        dr.MaterialInfo.ToonTexture = ToonManager.ResourceViews[material.textureIndex + 1];
                        dr.MaterialInfo.IsToonUsed  = true;
                    }
                    else if (material.textureIndex != -1)
                    {
                        if (model.TextureList.TexturePathes.Count < material.textureIndex + 1)
                        {
                            dr.MaterialInfo.ToonTexture = ToonManager.ResourceViews[0];
                            dr.MaterialInfo.IsToonUsed  = true;
                        }
                        else
                        {
                            int index = ToonManager.LoadToon(model.TextureList.TexturePathes[material.textureIndex]);
                            dr.MaterialInfo.ToonTexture = ToonManager.ResourceViews[index];
                            dr.MaterialInfo.IsToonUsed  = true;
                        }
                    }
                    else
                    {
                        dr.MaterialInfo.ToonTexture = ToonManager.ResourceViews[0];
                        dr.MaterialInfo.IsToonUsed  = true;
                    }
                }
                vertexSum += material.VertexNumber;

                //テクスチャの読み込み
                if (material.TextureTableReferenceIndex != -1)
                {
                    dr.MaterialInfo.MaterialTexture = getSubresourceById(model.TextureList.TexturePathes[material.TextureTableReferenceIndex]);
                }
                //スフィアマップの読み込み
                if (material.SphereTextureTableReferenceIndex != -1)
                {
                    dr.MaterialInfo.SphereMode        = material.SphereMode;
                    dr.MaterialInfo.MaterialSphereMap =
                        getSubresourceById(model.TextureList.TexturePathes[material.SphereTextureTableReferenceIndex]);
                }
                Subsets.Add(dr);
            }
        }
Exemple #14
0
 public void ResetEffect(MMEEffectManager effect)
 {
     this.MMEEffect = effect;
 }
Exemple #15
0
        public override FunctionBase GetExecuterInstance(int index, string value, RenderContext context, ScriptRuntime runtime, MMEEffectManager manager, MMEEffectTechnique technique, MMEEffectPass pass)
        {
            RenderDepthStencilTargetFunction func = new RenderDepthStencilTargetFunction();

            if (index != 0)
            {
                throw new InvalidMMEEffectShaderException("RenderDepthStencilTargetにはインデックス値を指定できません。");
            }
            func.context = context;
            if (!string.IsNullOrWhiteSpace(value) && !manager.RenderDepthStencilTargets.ContainsKey(value))
            {
                throw new InvalidMMEEffectShaderException("スクリプトに指定された名前の深度ステンシルバッファは存在しません。");
            }

            /*
             * valueが空なら→デフォルトの深度ステンシルバッファ
             * valueがあるなら→その名前のテクスチャ変数から取得
             */
            if (string.IsNullOrWhiteSpace(value))
            {
                func.isDefaultTarget = true;
            }
            func.stencilView = string.IsNullOrWhiteSpace(value)?null: manager.RenderDepthStencilTargets[value];
            return(func);
        }
        public override SubscriberBase GetSubscriberInstance(EffectVariable variable, RenderContext context, MMEEffectManager effectManager, int semanticIndex)
        {
            RenderColorTargetSubscriber subscriber = new RenderColorTargetSubscriber();

            this.variableName = variable.Description.Name;
            int    width, height, depth, mip;
            Format format;

            TextureAnnotationParser.GetBasicTextureAnnotations(variable, context, Format.R8G8B8A8_UNorm, new Vector2(1f, 1f), false, out width, out height, out depth, out mip, out format);
            if (depth != -1)
            {
                throw new InvalidMMEEffectShaderException(string.Format("RENDERCOLORTARGETの型はTexture2Dである必要があるためアノテーション「int depth」は指定できません。"));
            }
            Texture2DDescription tex2DDesc = new Texture2DDescription()
            {
                ArraySize         = 1,
                BindFlags         = BindFlags.RenderTarget | BindFlags.ShaderResource,
                CpuAccessFlags    = CpuAccessFlags.None,
                Format            = format,
                Height            = height,
                Width             = width,
                MipLevels         = mip,
                OptionFlags       = ResourceOptionFlags.None,
                SampleDescription = new SampleDescription(1, 0),
                Usage             = ResourceUsage.Default
            };

            subscriber.renderTexture  = new Texture2D(context.DeviceManager.Device, tex2DDesc);
            subscriber.renderTarget   = new RenderTargetView(context.DeviceManager.Device, subscriber.renderTexture);
            subscriber.shaderResource = new ShaderResourceView(context.DeviceManager.Device, subscriber.renderTexture);
            effectManager.RenderColorTargetViewes.Add(this.variableName, subscriber.renderTarget);
            return(subscriber);
        }
Exemple #17
0
 public ScriptRuntime(string script, RenderContext context, MMEEffectManager manager,
                      MMEEffectPass pass)
     : this(script, context, manager, null, pass)
 {
 }
Exemple #18
0
        public override SubscriberBase GetSubscriberInstance(EffectVariable variable, RenderContext context, MMEEffectManager effectManager, int semanticIndex)
        {
            TextureSubscriber subscriber = new TextureSubscriber();
            int    width, height, depth, mip;
            string typeName = variable.GetVariableType().Description.TypeName.ToLower();
            string type;
            Format format;

            TextureAnnotationParser.GetBasicTextureAnnotations(variable, context, Format.B8G8R8A8_UNorm, Vector2.Zero, true,
                                                               out width, out height, out depth, out mip, out format);
            EffectVariable rawTypeVariable   = EffectParseHelper.getAnnotation(variable, "ResourceType", "string");
            EffectVariable rawStringVariable = EffectParseHelper.getAnnotation(variable, "ResourceName", "string");

            if (rawTypeVariable != null)
            {
                switch (rawTypeVariable.AsString().GetString().ToLower())
                {
                case "cube":
                    if (!typeName.Equals("texturecube"))
                    {
                        throw new InvalidMMEEffectShaderException("ResourceTypeにはCubeが指定されていますが、型がtextureCUBEではありません。");
                    }
                    else
                    {
                        type = "texturecube";
                    }
                    break;

                case "2d":
                    if (!typeName.Equals("texture2d") && !typeName.Equals("texture"))
                    {
                        throw new InvalidMMEEffectShaderException("ResourceTypeには2Dが指定されていますが、型がtexture2Dもしくはtextureではありません。");
                    }
                    else
                    {
                        type = "texture2d";
                    }
                    break;

                case "3d":
                    if (!typeName.Equals("texture3d"))
                    {
                        throw new InvalidMMEEffectShaderException("ResourceTypeには3Dが指定されていますが、型がtexture3dではありません。");
                    }
                    else
                    {
                        type = "texture3d";
                    }
                    break;

                default:
                    throw new InvalidMMEEffectShaderException("認識できないResourceTypeが指定されました。");
                }
            }
            else
            {
                type = typeName;
            }
            if (rawStringVariable != null)
            {
                string resourceName          = rawStringVariable.AsString().GetString();
                ImageLoadInformation imgInfo = new ImageLoadInformation();
                Stream stream;
                switch (type)
                {
                case "texture2d":

                    imgInfo.Width          = width;
                    imgInfo.Height         = height;
                    imgInfo.MipLevels      = mip;
                    imgInfo.Format         = format;
                    imgInfo.Usage          = ResourceUsage.Default;
                    imgInfo.BindFlags      = BindFlags.ShaderResource;
                    imgInfo.CpuAccessFlags = CpuAccessFlags.None;
                    stream = effectManager.SubresourceLoader.getSubresourceByName(resourceName);
                    if (stream != null)
                    {
                        subscriber.resourceTexture = Texture2D.FromStream(context.DeviceManager.Device, stream, (int)stream.Length);
                    }
                    break;

                case "texture3d":
                    imgInfo.Width          = width;
                    imgInfo.Height         = height;
                    imgInfo.Depth          = depth;
                    imgInfo.MipLevels      = mip;
                    imgInfo.Format         = format;
                    imgInfo.Usage          = ResourceUsage.Default;
                    imgInfo.BindFlags      = BindFlags.ShaderResource;
                    imgInfo.CpuAccessFlags = CpuAccessFlags.None;
                    stream = effectManager.SubresourceLoader.getSubresourceByName(resourceName);
                    if (stream != null)
                    {
                        subscriber.resourceTexture = Texture3D.FromStream(context.DeviceManager.Device, stream, (int)stream.Length);
                    }
                    break;

                case "texturecube":
                    //TODO CUBEの場合に対応する
                    //imgInfo.Width = width;
                    //imgInfo.Height = height;
                    //imgInfo.Depth = depth;
                    //imgInfo.MipLevels = mip;
                    //imgInfo.Format = format;
                    //imgInfo.Usage=ResourceUsage.Default;
                    //imgInfo.BindFlags=BindFlags.ShaderResource;
                    //imgInfo.CpuAccessFlags=CpuAccessFlags.None;
                    //stream = effectManager.SubresourceLoader.getSubresourceByName(resourceName);
                    //subscriber.resourceTexture=.FromStream(context.DeviceManager.Device, stream, (int)stream.Length);
                    break;
                }
            }
            subscriber.resourceView = new ShaderResourceView(context.DeviceManager.Device, subscriber.resourceTexture);
            return(subscriber);
        }
Exemple #19
0
        public override FunctionBase GetExecuterInstance(int index, string value, RenderContext context, ScriptRuntime runtime, MMEEffectManager manager, MMEEffectTechnique technique, MMEEffectPass pass)
        {
            ClearFunction func = new ClearFunction();

            switch (value)
            {
            case "Color":
                func.isClearDepth = false;
                break;

            case "Depth":
                func.isClearDepth = true;
                break;

            default:
                throw new InvalidMMEEffectShaderException(string.Format("Clear={0}が指定されましたが、\"{0}\"は指定可能ではありません。ClearもしくはDepthが指定可能です。", value));
            }
            func.context = context;
            func.index   = index;
            return(func);
        }
Exemple #20
0
        public override SubscriberBase GetSubscriberInstance(EffectVariable variable, RenderContext context, MMEEffectManager effectManager, int semanticIndex)
        {
            EffectVariable annotation = variable.GetAnnotationByName("SyncInEditMode");
            bool           syncMode   = false;

            if (annotation != null)
            {
                syncMode = annotation.AsScalar().GetInt() == 1;
            }
            return(GetSubscriberInstance(syncMode));
        }
        public override SubscriberBase GetSubscriberInstance(EffectVariable variable, RenderContext context, MMEEffectManager effectManager, int semanticIndex)
        {
            RenderDepthStencilTargetSubscriber subscriber = new RenderDepthStencilTargetSubscriber();
            int    width, height, depth, mip;
            Format format;

            TextureAnnotationParser.GetBasicTextureAnnotations(variable, context, Format.D24_UNorm_S8_UInt, new Vector2(1f, 1f), false, out width, out height, out depth, out mip, out format);
            Texture2DDescription tex2DDesc = new Texture2DDescription()
            {
                ArraySize         = 1,
                BindFlags         = BindFlags.DepthStencil | BindFlags.ShaderResource,
                CpuAccessFlags    = CpuAccessFlags.None,
                Format            = format,
                Height            = height,
                Width             = width,
                MipLevels         = mip,
                OptionFlags       = ResourceOptionFlags.None,
                SampleDescription = new SampleDescription(1, 0),
                Usage             = ResourceUsage.Default
            };

            subscriber.depthStencilTexture = new Texture2D(context.DeviceManager.Device, tex2DDesc);
            subscriber.depthStencilView    = new DepthStencilView(context.DeviceManager.Device, subscriber.depthStencilTexture);
            subscriber.shaderResource      = new ShaderResourceView(context.DeviceManager.Device, subscriber.depthStencilTexture);
            effectManager.RenderDepthStencilTargets.Add(variable.Description.Name, subscriber.depthStencilView);
            return(subscriber);
        }
 public override SubscriberBase GetSubscriberInstance(EffectVariable variable, RenderContext context, MMEEffectManager effectManager, int semanticIndex)
 {
     return(new MiddleMouseDownSubscriber());
 }
Exemple #23
0
 private ScriptRuntime(string script, RenderContext context, MMEEffectManager manager, MMEEffectTechnique technique, MMEEffectPass pass)
 {
     ScriptCode = script;
     Parse(context, manager, technique, pass);
 }
Exemple #24
0
        /// <summary>
        ///     If the matrix each examine the Camera or Light?
        /// </summary>
        /// <param name="variable"></param>
        /// <param name="context"></param>
        /// <param name="effectManager"></param>
        /// <param name="semanticIndex"></param>
        /// <param name="effect">Effect of test</param>
        /// <param name="index">Inspect variable index</param>
        /// <returns></returns>
        public override SubscriberBase GetSubscriberInstance(EffectVariable variable, RenderContext context, MMEEffectManager effectManager, int semanticIndex)
        {
            string         obj;
            EffectVariable annotation = EffectParseHelper.getAnnotation(variable, "Object", "string");

            obj = annotation == null ? "" : annotation.AsString().GetString(); //The annotation is not present""とする
            if (string.IsNullOrWhiteSpace(obj))
            {
                return(GetSubscriberInstance(ObjectAnnotationType.Camera));
            }
            switch (obj.ToLower())
            {
            case "camera":
                return(GetSubscriberInstance(ObjectAnnotationType.Camera));

            case "light":
                return(GetSubscriberInstance(ObjectAnnotationType.Light));

            case "":
                throw new InvalidMMEEffectShaderException(
                          string.Format(
                              "変数「{0} {1}:{2}」には、アノテーション「string Object=\"Camera\"」または、「string Object=\"Light\"」が必須ですが指定されませんでした。",
                              variable.GetVariableType().Description.TypeName.ToLower(), variable.Description.Name,
                              variable.Description.Semantic));

            default:
                throw new InvalidMMEEffectShaderException(
                          string.Format(
                              "変数「{0} {1}:{2}」には、アノテーション「string Object=\"Camera\"」または、「string Object=\"Light\"」が必須ですが指定されたのは「string Object=\"{3}\"」でした。(スペルミス?)",
                              variable.GetVariableType().Description.TypeName.ToLower(), variable.Description.Name,
                              variable.Description.Semantic, obj));
            }
        }
        public override FunctionBase GetExecuterInstance(int index, string value, RenderContext context, ScriptRuntime runtime, MMEEffectManager manager, MMEEffectTechnique technique, MMEEffectPass pass)
        {
            RenderColorTargetFunction func = new RenderColorTargetFunction();

            if (index < 0 || index > 7)
            {
                throw new InvalidMMEEffectShaderException("RenderColorTarget[n](0<=n<=7)のnの制約が満たされていません。");
            }
            func.index   = index;
            func.context = context;
            if (!string.IsNullOrWhiteSpace(value) && !manager.RenderColorTargetViewes.ContainsKey(value))
            {
                throw new InvalidMMEEffectShaderException("指定されたRENDERCOLORTARGETの変数は存在しません。");
            }
            if (string.IsNullOrWhiteSpace(value))
            {
                func.isDefaultTarget = true;
            }
            func.targetView = string.IsNullOrWhiteSpace(value)?index == 0?context.CurrentTargetContext.RenderTargetView:null:manager.RenderColorTargetViewes[value];
            return(func);
        }
        public override SubscriberBase GetSubscriberInstance(EffectVariable variable, RenderContext context, MMEEffectManager effectManager, int semanticIndex)
        {
            VariableType type     = 0;
            TargetObject target   = TargetObject.UnUsed;
            string       itemName = null;
            string       typeName = variable.GetVariableType().Description.TypeName.ToLower();

            switch (typeName)
            {
            case "bool":
                type = VariableType.Bool;
                break;

            case "float":
                type = VariableType.Float;
                break;

            case "float3":
                type = VariableType.Float3;
                break;

            case "float4":
                type = VariableType.Float4;
                break;

            case "float4x4":
                type = VariableType.Float4x4;
                break;

            default:
                break;
            }
            EffectVariable nameVariable = EffectParseHelper.getAnnotation(variable, "name", "string");

            if (nameVariable == null)
            {
                throw new InvalidMMEEffectShaderException(
                          string.Format("定義済みセマンティクス「CONTROLOBJECT」の適用されている変数「{0} {1}:CONTROLOBJECT」に対してはアノテーション「string name」は必須ですが、指定されませんでした。", typeName, variable.Description.Name));
            }
            string name = nameVariable.AsString().GetString();

            //Selfの場合はターゲットは自分自身となる
            if (name.ToLower().Equals("(self)"))
            {
                isSelf = true;
            }
            else
            {
            }
            //TODO (OffscreenOwner)がnameに指定されたときの対応
            EffectVariable itemVariable = EffectParseHelper.getAnnotation(variable, "item", "string");

            if (itemVariable != null)
            {
                itemName = itemVariable.AsString().GetString();
                switch (itemName.ToLower())
                {
                case "x":
                    target = TargetObject.X;
                    break;

                case "y":
                    target = TargetObject.Y;
                    break;

                case "z":
                    target = TargetObject.Z;
                    break;

                case "xyz":
                    target = TargetObject.XYZ;
                    break;

                case "rx":
                    target = TargetObject.Rx;
                    break;

                case "ry":
                    target = TargetObject.Ry;
                    break;

                case "rz":
                    target = TargetObject.Rz;
                    break;

                case "rxyz":
                    target = TargetObject.Rxyz;
                    break;

                case "si":
                    target = TargetObject.Si;
                    break;

                case "tr":
                    target = TargetObject.Tr;
                    break;

                default:
                    target = type == VariableType.Float ? TargetObject.FaceName : TargetObject.BoneName;
                    break;
                }
                if (NeedFloat.Contains(target) && type != VariableType.Float)
                {
                    throw new InvalidMMEEffectShaderException(
                              string.Format("定義済みセマンティクス「CONTROLOBJECT」の適用されている変数「{0} {1}:CONTROLOBJECT」にはアノテーション「string item=\"{2}\"」が適用されていますが、「{2}」の場合は「float {1}:CONTROLOBJECT」である必要があります。", typeName, variable.Description.Name, itemName));
                }
                if (NeedFloat3.Contains(target) && type != VariableType.Float3)
                {
                    throw new InvalidMMEEffectShaderException(
                              string.Format("定義済みセマンティクス「CONTROLOBJECT」の適用されている変数「{0} {1}:CONTROLOBJECT」にはアノテーション「string item=\"{2}\"」が適用されていますが、「{2}」の場合は「float3 {1}:CONTROLOBJECT」である必要があります。", typeName, variable.Description.Name, itemName));
                }
            }
            return(new ControlObjectSubscriber(type, itemName, name, target, isSelf));
        }
Exemple #27
0
 /// <summary>
 ///     Check the index of the specified effect
 /// </summary>
 /// <param name="variable"></param>
 /// <param name="context"></param>
 /// <param name="effectManager"></param>
 /// <param name="semanticIndex"></param>
 /// <param name="effect">To examine effects</param>
 /// <param name="index">Index of variables to test</param>
 /// <return>登録時にアノテーションとして送るobject</return>
 public abstract SubscriberBase GetSubscriberInstance(EffectVariable variable, RenderContext context, MMEEffectManager effectManager, int semanticIndex);
Exemple #28
0
 public ScriptRuntime(string script, RenderContext context, MMEEffectManager manager,
                      MMEEffectTechnique technique) : this(script, context, manager, technique, null)
 {
 }
        public override SubscriberBase GetSubscriberInstance(EffectVariable variable, RenderContext context, MMEEffectManager effectManager, int semanticIndex)
        {
            FullMaterialConstantBufferManager manager = new FullMaterialConstantBufferManager();

            manager.Initialize(context.DeviceManager.Device, (EffectConstantBuffer)variable,
                               FullMaterialConstantBufferInputLayout.SizeInBytes, new FullMaterialConstantBufferInputLayout());
            return(new FullMaterialConstantSubscriber(manager));
        }
Exemple #30
0
        public override SubscriberBase GetSubscriberInstance(EffectVariable variable, RenderContext context, MMEEffectManager effectManager, int semanticIndex)
        {
            bool isVector3 =
                variable.GetVariableType().Description.TypeName.ToLower().Equals("float3");

            if (!NeedAnnotation.Contains(Semantics))
            {
                return(GetSubscriberInstance(TargetObject.UnUsed, isVector3));
            }
            EffectVariable objectAnnotation = EffectParseHelper.getAnnotation(variable, "Object", "string");

            if (objectAnnotation == null)
            {
                throw new InvalidMMEEffectShaderException(
                          string.Format("このセマンティクス\"{0}\"にはアノテーション「Object」が必須ですが、記述されませんでした。", Semantics));
            }
            string annotation = objectAnnotation.AsString().GetString().ToLower();

            if (!string.IsNullOrWhiteSpace(annotation))
            {
                switch (annotation)
                {
                case "geometry":
                    return(GetSubscriberInstance(TargetObject.Geometry, isVector3));

                case "light":
                    return(GetSubscriberInstance(TargetObject.Light, isVector3));

                default:
                    throw new InvalidMMEEffectShaderException(string.Format("アノテーション\"{0}\"は認識されません。", annotation));
                }
            }
            throw new InvalidMMEEffectShaderException(
                      string.Format("このセマンティクス\"{0}\"にはアノテーション「Object」が必須ですが、記述されませんでした。", Semantics));
        }