Esempio n. 1
0
        public override 数管理  数登録インスタンスを生成して返す(EffectVariable variable, エフェクト effect, int semanticIndex)
        {
            // 行列の場合は、それぞれCameraかLightか調べる。

            EffectVariable Objectアノテーション = EffectParseHelper.アノテーションを取得する(variable, "Object", "string");

            string obj = (Objectアノテーション == null) ? "" : Objectアノテーション.AsString().GetString();               // アノテーションが存在しない時は""とする

            switch (obj.ToLower())
            {
            case "camera":
                return(行列変数登録インスタンスを生成して返す(Object種別.カメラ));

            case "light":
                return(行列変数登録インスタンスを生成して返す(Object種別.ライト));

            case "":
                return(行列変数登録インスタンスを生成して返す(Object種別.カメラ));        // 既定値

            default:
                throw new InvalidMMEEffectShader例外(
                          $"変数「{variable.TypeInfo.Description.TypeName.ToLower()} {variable.Description.Name}:{variable.Description.Semantic}」には、" +
                          $"アノテーション「string Object=\"Camera\"」または、「string Object=\"Light\"」が必須ですが指定されたのは「string Object=\"{obj}\"」でした。(スペルミス?)");
            }
        }
Esempio n. 2
0
        public override 数管理  数登録インスタンスを生成して返す(EffectVariable variable, エフェクト effectManager, int semanticIndex)
        {
            // アノテーション "string Object = ..." を取得

            EffectVariable annotation = EffectParseHelper.アノテーションを取得する(variable, "Object", "string");

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


            // Object の内容で type を決める。

            Object種別 type;
            string   objectStr = annotation.AsString().GetString().ToLower();

            switch (objectStr)
            {
            case "camera":
                type = Object種別.カメラ;
                break;

            case "light":
                type = Object種別.ライト;
                break;

            default:
                throw new InvalidMMEEffectShader例外(
                          string.Format(
                              "変数「{0} {1}:{2}」にはアノテーション「string Object=\"Light\"」または「string object=\"Camera\"」が必須ですが指定されたのは,「string object=\"{3}\"でした。(スペルミス?)",
                              variable.TypeInfo.Description.TypeName.ToLower(),
                              variable.Description.Name,
                              variable.Description.Semantic,
                              objectStr));
            }


            // 決定された type へ引き継ぐ。

            return(GetSubscriberInstance(type));
        }
Esempio n. 3
0
        public override 数管理  数登録インスタンスを生成して返す(EffectVariable d3dEffectVariable, エフェクト effect, int semanticIndex)
        {
            bool isVector3 = d3dEffectVariable.TypeInfo.Description.TypeName.ToLower().Equals("float3");


            if (!_Objectアノテーションが必須なセマンティクス.Contains(セマンティクス))
            {
                // (A) Object アノテーションが不要なセマンティクスの場合

                return(材質変数登録インスタンスを生成して返す(ターゲット種別.未使用, isVector3));
            }
            else
            {
                // (B) Object アノテーションが必須のセマンティクスの場合

                EffectVariable Objectアノテーション = EffectParseHelper.アノテーションを取得する(d3dEffectVariable, "Object", "string");

                if (Objectアノテーション == null)
                {
                    throw new InvalidMMEEffectShader例外($"このセマンティクス\"{セマンティクス}\"にはアノテーション「Object」が必須ですが、記述されませんでした。");
                }

                string annotation = Objectアノテーション.AsString().GetString().ToLower();

                if (string.IsNullOrWhiteSpace(annotation))
                {
                    throw new InvalidMMEEffectShader例外($"このセマンティクス\"{セマンティクス}\"にはアノテーション「Object」が必須ですが、記述されませんでした。");
                }

                switch (annotation)
                {
                case "geometry":
                    return(材質変数登録インスタンスを生成して返す(ターゲット種別.ジオメトリ, isVector3));

                case "light":
                    return(材質変数登録インスタンスを生成して返す(ターゲット種別.ライト, isVector3));

                default:
                    throw new InvalidMMEEffectShader例外($"アノテーション\"{annotation}\"は認識されません。");
                }
            }
        }
Esempio n. 4
0
        public override 数管理  数登録インスタンスを生成して返す(EffectVariable variable, エフェクト effect, int semanticIndex)
        {
            数型           type     = 0;
            TargetObject target   = TargetObject.UnUsed;
            string       itemName = null;
            string       typeName = variable.TypeInfo.Description.TypeName.ToLower();

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

            case "float":
                type = 数型.Float;
                break;

            case "float3":
                type = 数型.Float3;
                break;

            case "float4":
                type = 数型.Float4;
                break;

            case "float4x4":
                type = 数型.Float4x4;
                break;

            default:
                break;
            }

            EffectVariable nameVariable = EffectParseHelper.アノテーションを取得する(variable, "name", "string");

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

            string name = nameVariable.AsString().GetString();

            // Selfの場合はターゲットは自分自身となる

            if (name.ToLower().Equals("(self)"))
            {
                _isSelf = true;
            }
            else
            {
                // TODO: (OffscreenOwner)がnameに指定されたときの対応
            }


            EffectVariable itemVariable = EffectParseHelper.アノテーションを取得する(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 == 数型.Float ? TargetObject.FaceName : TargetObject.BoneName;
                    break;
                }

                if (NeedFloat.Contains(target) && type != 数型.Float)
                {
                    throw new InvalidMMEEffectShader例外($"定義済みセマンティクス「CONTROLOBJECT」の適用されている変数「{typeName} {variable.Description.Name}:CONTROLOBJECT」にはアノテーション「string item=\"{itemName}\"」が適用されていますが、「{itemName}」の場合は「float {variable.Description.Name}:CONTROLOBJECT」である必要があります。");
                }

                if (NeedFloat3.Contains(target) && type != 数型.Float3)
                {
                    throw new InvalidMMEEffectShader例外($"定義済みセマンティクス「CONTROLOBJECT」の適用されている変数「{typeName} {variable.Description.Name}:CONTROLOBJECT」にはアノテーション「string item=\"{itemName}\"」が適用されていますが、「{itemName}」の場合は「float3 {variable.Description.Name}:CONTROLOBJECT」である必要があります。");
                }
            }

            return(new CONTROLOBJECT変数(type, itemName, name, target, _isSelf));
        }
Esempio n. 5
0
        public override 数管理  数登録インスタンスを生成して返す(EffectVariable variable, エフェクト effect, int semanticIndex)
        {
            var    subscriber = new テクスチャ変数();
            string typeName   = variable.TypeInfo.Description.TypeName.ToLower();

            int    width, height, depth, mip;
            Format textureFormat, viewFormat, resourceFormat;

            テクスチャのアノテーション解析.解析する(variable, Format.B8G8R8A8_UNorm, Vector2.Zero, true, out width, out height, out depth, out mip, out textureFormat, out viewFormat, out resourceFormat);

            EffectVariable rawTypeVariable   = EffectParseHelper.アノテーションを取得する(variable, "ResourceType", "string");
            EffectVariable rawStringVariable = EffectParseHelper.アノテーションを取得する(variable, "ResourceName", "string");


            // type を決定

            string type;

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

                case "2d":
                    type = (typeName.Equals("texture2d") || typeName.Equals("texture")) ? "texture2d" : throw new InvalidMMEEffectShader例外("ResourceTypeには2Dが指定されていますが、型がtexture2Dもしくはtextureではありません。");
                    break;

                case "3d":
                    type = (typeName.Equals("texture3d")) ? "texture3d" : throw new InvalidMMEEffectShader例外("ResourceTypeには3Dが指定されていますが、型がtexture3dではありません。");
                    break;

                default:
                    throw new InvalidMMEEffectShader例外("認識できないResourceTypeが指定されました。");
                }
            }
            else
            {
                type = typeName;
            }


            // テクスチャリソースを読み込む

            if (rawStringVariable != null)
            {
                string resourceName = rawStringVariable.AsString().GetString();
                Stream stream;

                switch (type)
                {
                case "texture2d":
                    stream = effect.テクスチャなどのパスの解決に利用するローダー.リソースのストリームを返す(resourceName);
                    if (stream != null)
                    {
                        subscriber._resourceTexture = MMFTexture2D.FromStream(RenderContext.Instance.DeviceManager.D3DDevice, stream);
                    }
                    break;

                case "texture3d":
                    stream = effect.テクスチャなどのパスの解決に利用するローダー.リソースのストリームを返す(resourceName);
                    if (stream != null)
                    {
                        subscriber._resourceTexture = MMFTexture3D.FromStream(RenderContext.Instance.DeviceManager.D3DDevice, stream);
                    }
                    break;

                case "texturecube":
                    //TODO CUBEの場合を実装する
                    //stream = effectManager.SubresourceLoader.getSubresourceByName(resourceName);
                    //subscriber.resourceTexture=.FromStream(context.DeviceManager.Device, stream, (int)stream.Length);
                    break;
                }
            }

            // シェーダーリソースビューを割り当て
            subscriber._resourceView = new ShaderResourceView(RenderContext.Instance.DeviceManager.D3DDevice, subscriber._resourceTexture);

            return(subscriber);
        }
        /// <summary>
        /// テクスチャのアノテーション解釈に一般的に必要な項目を取得するメソッド
        /// </summary>
        /// <param name="variable">エフェクト変数</param>
        /// <param name="context">レンダーコンテキスト</param>
        /// <param name="defaultFormat"></param>
        /// <param name="defaultViewPortRatio"></param>
        /// <param name="width">テクスチャの幅</param>
        /// <param name="height">テクスチャの高さ</param>
        /// <param name="depth">テクスチャの深さ(ない場合は-1)</param>
        /// <param name="mip">mipレベル</param>
        /// <param name="textureFormat">指定されているフォーマット</param>
        public static void 解析する(EffectVariable variable, Format defaultFormat, Vector2 defaultViewPortRatio, bool isTextureSubscriber, out int width, out int height, out int depth, out int mip, out Format textureFormat, out Format viewFormat, out Format resourceFormat)
        {
            width          = -1;
            height         = -1;
            depth          = -1;
            mip            = 0;
            textureFormat  = defaultFormat;
            viewFormat     = defaultFormat;
            resourceFormat = defaultFormat;

            #region " int width = ... "
            //----------------
            EffectVariable rawWidthVal = EffectParseHelper.アノテーションを取得する(variable, "width", "int");
            if (rawWidthVal != null)
            {
                width = rawWidthVal.AsScalar().GetInt();
            }
            //----------------
            #endregion

            #region " int height = ... "
            //----------------
            EffectVariable rawHeightVal = EffectParseHelper.アノテーションを取得する(variable, "height", "int");
            if (rawHeightVal != null)
            {
                height = rawHeightVal.AsScalar().GetInt();
            }
            //----------------
            #endregion

            #region " int depth = ... "
            //----------------
            EffectVariable rawDepthVal = EffectParseHelper.アノテーションを取得する(variable, "depth", "int");
            if (rawDepthVal != null)
            {
                depth = rawDepthVal.AsScalar().GetInt();
            }
            //----------------
            #endregion

            #region " float2 ViewportRatio = ... "
            //----------------
            EffectVariable rawViewportRatio = EffectParseHelper.アノテーションを取得する(variable, "viewportratio", "float2");
            if (rawViewportRatio != null)

            {
                if (width != -1 || height != -1 || depth != -1)
                {
                    throw new InvalidMMEEffectShader例外(
                              string.Format("変数「{0} {1}」のサイズ指定が不正です。Width,Height,Depth/ViewportRatio/Dimensionsはそれぞれ同時に使用できません。", variable.TypeInfo.Description.TypeName.ToLower(), variable.Description.Name));
                }
                else
                {
                    Vector4 rawRatio = rawViewportRatio.AsVector().GetFloatVector();
                    var     vp       = RenderContext.Instance.DeviceManager.D3DDeviceContext.Rasterizer.GetViewports <ViewportF>()[0];
                    width  = (int)(vp.Width * rawRatio.X);
                    height = (int)(vp.Height * rawRatio.Y);
                }
            }
            //----------------
            #endregion

            #region " uing2/uint3 Dimensions = ... "
            //----------------
            EffectVariable rawDimensions = EffectParseHelper.アノテーションを取得する(variable, "dimensions", "uint2/uint3");

            if (rawDimensions != null)
            {
                if (width != -1 || height != -1 || depth != -1)
                {
                    throw new InvalidMMEEffectShader例外(
                              string.Format(
                                  "変数「{0} {1}」のサイズ指定が不正です。Width,Height,Depth/ViewportRatio/Dimensionsはそれぞれ同時に使用できません。",
                                  variable.TypeInfo.Description.TypeName.ToLower(), variable.Description.Name));
                }
                else
                {
                    string typeName = rawDimensions.TypeInfo.Description.TypeName.ToLower();
                    if (typeName == "int2")
                    {
                        var rawDimension = rawDimensions.AsVector().GetIntVector();
                        width  = rawDimension.X;
                        height = rawDimension.Y;
                    }
                    else
                    {
                        var rawDimension = rawDimensions.AsVector().GetIntVector();
                        width  = rawDimension.X;
                        height = rawDimension.Y;
                        depth  = rawDimension.Z;
                    }
                }
            }
            //----------------
            #endregion

            #region "width, height チェック "
            //----------------
            if (width == -1 || height == -1)
            {
                if (defaultViewPortRatio != Vector2.Zero)
                {
                    var port = RenderContext.Instance.DeviceManager.D3DDeviceContext.Rasterizer.GetViewports <ViewportF>()[0];
                    width  = (int)(port.Width * defaultViewPortRatio.X);
                    height = (int)(port.Height * defaultViewPortRatio.Y);
                }
                else
                {
                    if (!isTextureSubscriber)
                    {
                        throw new InvalidMMEEffectShader例外(string.Format("width,heightのどちらかの指定は必須です。"));
                    }
                }
            }
            //----------------
            #endregion

            #region " int MipLevels = ... / int RawLevel = ... "
            //----------------
            EffectVariable rawMipLevel = EffectParseHelper.アノテーションを取得する(variable, "MipLevels", "int");
            EffectVariable rawLevel    = EffectParseHelper.アノテーションを取得する(variable, "levels", "int");

            if (rawMipLevel != null && rawLevel != null)
            {
                throw new InvalidMMEEffectShader例外(
                          string.Format("変数「{0} {1}」のミップマップレベルが重複して指定されています。「int Miplevels」、「int Levels」は片方しか指定できません。",
                                        variable.TypeInfo.Description.TypeName.ToLower(), variable.Description.Name));
            }
            else if (rawMipLevel != null || rawLevel != null)
            {
                EffectVariable mipVal = rawMipLevel ?? rawLevel;
                mip = mipVal.AsScalar().GetInt();
            }
            //----------------
            #endregion

            #region " string Format = ... "
            //----------------
            EffectVariable rawFormat = EffectParseHelper.アノテーションを取得する(variable, "format", "string");

            if (rawFormat != null)
            {
                string formatString = rawFormat.AsString().GetString();
                テクスチャフォーマットを返す(formatString, out textureFormat, out viewFormat, out resourceFormat);
            }
            //----------------
            #endregion
        }