Exemplo n.º 1
0
        // 根据输出限定符来输入数据
        public void SetInWithOut <T>(OutLayout layout, T value, int num = 0)
        {
            if (layout == OutLayout.SV_Target)
            {
                return;
            }
            InLayout inlayout = InLayout.SV_Position;

            if (layout == OutLayout.SV_Position) /* noops */; {
            }
Exemplo n.º 2
0
        // 根据输入限定符来输入数据
        public void SetIn <T>(InLayout layout, T value, int location = 0)
        {
#if SHOW_WARNING_NOT_FOUND_SHADER_FIELD
            if (inLayoutFieldDict.TryGetValue(layout, out Dictionary <int, FieldInfo> dict))
            {
                if (dict.TryGetValue(location, out FieldInfo f))
                {
                    f.SetValue(Owner, value);
                }
                else
                {
                    ;// Console.WriteLine($"Not found the location:{location}");
                }
            }
            else
            {
                ;// Console.WriteLine($"Not found the layout:{layout}");
            }
#else
            inLayoutFieldDict[layout][location].SetValue(Owner, value);
#endif
        }
Exemplo n.º 3
0
        public FuncFieldReflection(T owner)
        {
            Owner = owner;
            var type            = owner.GetType();
            var fs              = type.GetFields();
            var uniformAtType   = typeof(UniformAttribute);
            var inAtType        = typeof(InAttribute);
            var outAtType       = typeof(OutAttribute);
            var nointerpolation = typeof(NointerpolationAttribute);

            var fType    = typeof(float);
            var vec2Type = typeof(Vector2);
            var vec3Type = typeof(Vector3);
            var vec4Type = typeof(Vector4);

            foreach (var f in fs)
            {
                foreach (var at in f.CustomAttributes)
                {
                    // 收集in字段
                    if (at.AttributeType.IsEquivalentTo(inAtType))
                    {
                        var conflict = f.GetCustomAttribute <UniformAttribute>(); // conflict uniform
                        if (conflict != null)
                        {
                            throw new Exception($"Shader:{type.Name} field:{f.Name}'s {at.AttributeType.Name} conflict, it also has {conflict.GetType().Name}");
                        }
                        inFieldDictName[f.Name] = f;
                        inFieldDictHash[f.Name.GetHashCode()] = f;

                        var svpos    = f.GetCustomAttribute <SV_PositionAttribute>();
                        var svtarget = f.GetCustomAttribute <SV_TargetAttribute>();
                        var pos      = f.GetCustomAttribute <PositionAttribute>();
                        var color    = f.GetCustomAttribute <ColorAttribute>();
                        var uv       = f.GetCustomAttribute <TexcoordAttribute>();
                        var normal   = f.GetCustomAttribute <NormalAttribute>();
                        var tangent  = f.GetCustomAttribute <TangentAttribute>();
                        Dictionary <int, FieldInfo> dict = null;
                        InLayout layout   = InLayout.SV_Position;
                        var      location = 0;
                        if (svpos != null)
                        {
                            layout = InLayout.SV_Position; location = 0;
                        }                                                                   // only one:0
                        if (pos != null)
                        {
                            layout = InLayout.Position; location = 0;
                        }                                                              // only one:0
                        if (color != null)
                        {
                            layout = InLayout.Color; location = color.Location;
                        }
                        if (uv != null)
                        {
                            layout = InLayout.Texcoord; location = uv.Location;
                        }
                        if (normal != null)
                        {
                            layout = InLayout.Normal; location = normal.Location;
                        }
                        if (tangent != null)
                        {
                            layout = InLayout.Tangent; location = tangent.Location;
                        }
                        inLayoutFieldDict.TryGetValue(layout, out dict);
                        if (dict == null)
                        {
                            inLayoutFieldDict[layout] = dict = new Dictionary <int, FieldInfo>();
                        }
                        dict[location] = f;
                    }
                    else if (at.AttributeType.IsEquivalentTo(outAtType))
                    {
                        var uniformConflict = f.GetCustomAttribute <UniformAttribute>(); // conflict uniform
                        if (uniformConflict != null)
                        {
                            throw new Exception($"Shader:{type.Name} field:{f.Name}'s {at.AttributeType.Name} conflict, it also has {uniformConflict.GetType().Name}");
                        }
                        inFieldDictName[f.Name] = f;
                        inFieldDictHash[f.Name.GetHashCode()] = f;

                        var svpos    = f.GetCustomAttribute <SV_PositionAttribute>();
                        var svtarget = f.GetCustomAttribute <SV_TargetAttribute>();
                        var pos      = f.GetCustomAttribute <PositionAttribute>();
                        var color    = f.GetCustomAttribute <ColorAttribute>();
                        var uv       = f.GetCustomAttribute <TexcoordAttribute>();
                        var normal   = f.GetCustomAttribute <NormalAttribute>();
                        var tangent  = f.GetCustomAttribute <TangentAttribute>();
                        Dictionary <int, FieldInfo> dict = null;
                        OutLayout layout   = OutLayout.Tangent;
                        var       location = 0;
                        if (svpos != null)
                        {
                            layout = OutLayout.SV_Position; location = 0;
                        }                                                                    // only one:0
                        if (svtarget != null)
                        {
                            layout = OutLayout.SV_Target; location = svtarget.Location;
                        }
                        if (pos != null)
                        {
                            layout = OutLayout.Position; location = 0;
                        }                                                               // only one:0
                        if (color != null)
                        {
                            layout = OutLayout.Color; location = color.Location;
                        }
                        if (uv != null)
                        {
                            layout = OutLayout.Texcoord; location = uv.Location;
                        }
                        if (normal != null)
                        {
                            layout = OutLayout.Normal; location = normal.Location;
                        }
                        if (tangent != null)
                        {
                            layout = OutLayout.Tangent; location = tangent.Location;
                        }
                        outLayoutFieldDict.TryGetValue(layout, out dict);
                        if (dict == null)
                        {
                            outLayoutFieldDict[layout] = dict = new Dictionary <int, FieldInfo>();
                        }
                        dict[location] = f;
                    }
                    else if (at.AttributeType.IsEquivalentTo(nointerpolation))
                    {
                        nointerpolationFlagDict[f] = true;
                    }
                }

                var floatNum = LayoutFloatNum.Undefine;
                if (f.FieldType == fType)
                {
                    floatNum = LayoutFloatNum.F1;
                }
                else if (f.FieldType == vec2Type)
                {
                    floatNum = LayoutFloatNum.F2;
                }
                else if (f.FieldType == vec3Type)
                {
                    floatNum = LayoutFloatNum.F3;
                }
                else if (f.FieldType == vec4Type)
                {
                    floatNum = LayoutFloatNum.F4;
                }

                layoutFloatNumDict[f] = floatNum;
            }
        }