Пример #1
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));
        }
Пример #2
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));
            }
        }
Пример #3
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));
        }
Пример #4
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);
        }
Пример #5
0
        /// <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 GetBasicTextureAnnotations(EffectVariable variable, RenderContext context, Format defaultFormat, Vector2 defaultViewPortRatio, bool isTextureSubscriber, out int width, out int height, out int depth,
                                                      out int mip, out Format textureFormat)
        {
            width         = -1;
            height        = -1;
            depth         = -1;
            mip           = 0;
            textureFormat = defaultFormat;
            EffectVariable rawWidthVal  = EffectParseHelper.getAnnotation(variable, "width", "int");
            EffectVariable rawHeightVal = EffectParseHelper.getAnnotation(variable, "height", "int");
            EffectVariable rawDepthVal  = EffectParseHelper.getAnnotation(variable, "depth", "int");

            if (rawWidthVal != null)
            {
                width = rawWidthVal.AsScalar().GetInt();
            }
            if (rawHeightVal != null)
            {
                height = rawHeightVal.AsScalar().GetInt();
            }
            if (rawDepthVal != null)
            {
                depth = rawDepthVal.AsScalar().GetInt();
            }
            EffectVariable rawViewportRatio = EffectParseHelper.getAnnotation(variable, "viewportratio", "float2");

            if (rawViewportRatio != null)
            {
                if (width != -1 || height != -1 || depth != -1)
                {
                    throw new InvalidMMEEffectShaderException(
                              string.Format("変数「{0} {1}」のサイズ指定が不正です。Width,Height,Depth/ViewportRatio/Dimensionsはそれぞれ同時に使用できません。",
                                            variable.GetVariableType().Description.TypeName.ToLower(), variable.Description.Name));
                }
                else
                {
                    Vector4  rawRatio = rawViewportRatio.AsVector().GetVector();
                    Viewport vp       = context.DeviceManager.Context.Rasterizer.GetViewports()[0];
                    width  = (int)(vp.Width * rawRatio.X);
                    height = (int)(vp.Height * rawRatio.Y);
                }
            }
            EffectVariable rawDimensions = EffectParseHelper.getAnnotation(variable, "dimension", "uint2/uint3");

            if (rawDimensions != null)
            {
                if (width != -1 || height != -1 || depth != -1)
                {
                    throw new InvalidMMEEffectShaderException(
                              string.Format(
                                  "変数「{0} {1}」のサイズ指定が不正です。Width,Height,Depth/ViewportRatio/Dimensionsはそれぞれ同時に使用できません。",
                                  variable.GetVariableType().Description.TypeName.ToLower(), variable.Description.Name));
                }
                else
                {
                    string typeName = rawDimensions.GetVariableType().Description.TypeName.ToLower();
                    if (typeName == "int2")
                    {
                        int[] rawDimension = rawDimensions.AsVector().GetIntVectorArray(2);
                        width  = rawDimension[0];
                        height = rawDimension[1];
                    }
                    else
                    {
                        int[] rawDimension = rawDimensions.AsVector().GetIntVectorArray(3);
                        width  = rawDimension[0];
                        height = rawDimension[1];
                        depth  = rawDimension[2];
                    }
                }
            }
            if (width == -1 || height == -1)
            {
                if (defaultViewPortRatio != Vector2.Zero)
                {
                    Viewport port = context.DeviceManager.Context.Rasterizer.GetViewports()[0];
                    width  = (int)(port.Width * defaultViewPortRatio.X);
                    height = (int)(port.Height * defaultViewPortRatio.Y);
                }
                else
                {
                    if (!isTextureSubscriber)
                    {
                        throw new InvalidMMEEffectShaderException(string.Format("width,heightのどちらかの指定は必須です。"));
                    }
                }
            }
            EffectVariable rawMipLevel = EffectParseHelper.getAnnotation(variable, "MipLevels", "int");
            EffectVariable rawLevel    = EffectParseHelper.getAnnotation(variable, "levels", "int");

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

            if (rawFormat != null)
            {
                string formatString = rawFormat.AsString().GetString();
                textureFormat = TextureFormat(formatString);
            }
        }
Пример #6
0
        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));
        }