예제 #1
0
        static MyMaterialProxy_2 CreateProxyWithPlaceholderdMaterialConstants(MyVoxelMaterialTriple triple)
        {
            var version = triple.I0.GetHashCode();

            MyHashHelper.Combine(ref version, triple.I1.GetHashCode());
            MyHashHelper.Combine(ref version, triple.I2.GetHashCode());

            MySrvTable srvTable = new MySrvTable
            {
                BindFlag  = MyBindFlag.BIND_PS,
                StartSlot = 0,
                Version   = version,
                Srvs      = new ISrvBindable[]
                {
                    MyGlobalResources.FileArrayTextureVoxelCM,
                    MyGlobalResources.FileArrayTextureVoxelNG,
                    MyGlobalResources.FileArrayTextureVoxelExt,
                }
            };

            return(new MyMaterialProxy_2
            {
                MaterialConstants = new MyConstantsPack(),
                MaterialSrvs = srvTable
            });
        }
예제 #2
0
 internal static int GetMaterialProxyId(MyVoxelMaterialTriple materialSet)
 {
     if (!MaterialTripleIndex.ContainsKey(materialSet))
     {
         MaterialTripleIndex[materialSet] = MyMaterials.ProxyPool.Allocate();
     }
     return(MaterialTripleIndex[materialSet]);
 }
예제 #3
0
 internal static MyMaterialProxyId GetMaterialProxyId(MyVoxelMaterialTriple materialSet)
 {
     if (!MaterialProxyTripleIndex.ContainsKey(materialSet))
     {
         var matId = MaterialProxyTripleIndex[materialSet] = MyMaterials1.AllocateProxy();
         MyMaterials1.ProxyPool.Data[matId.Index] = CreateProxy(materialSet);
     }
     return(MaterialProxyTripleIndex[materialSet]);
 }
예제 #4
0
        internal static MyMaterialProxyId GetMaterialProxyId(MyVoxelMaterialTriple materialSet)
        {
            MyMaterialProxyId pid;

            if (!MaterialProxyTripleIndex.TryGetValue(materialSet, out pid))
            {
                pid = MaterialProxyTripleIndex[materialSet] = MyMaterials1.AllocateProxy();
                MyMaterials1.ProxyPool.Data[pid.Index] = CreateProxy(materialSet);
            }
            return(pid);
        }
예제 #5
0
 static MyMaterialProxy_2 CreateProxy(MyVoxelMaterialTriple triple)
 {
     if (triple.IsFillingMaterialCB)
     {
         return(CreateProxyWithValidMaterialConstants(triple));
     }
     else
     {
         return(CreateProxyWithPlaceholderdMaterialConstants(triple));
     }
 }
예제 #6
0
        static unsafe MyMaterialProxy_2 CreateProxy(MyVoxelMaterialTriple triple)
        {
            byte[] buffer;
            int size;

            MyRenderProxy.Assert(triple.I0 < Table.Length, "Index to table incorrect");
            MyRenderProxy.Assert(triple.I1 < Table.Length, "Index to table incorrect");
            MyRenderProxy.Assert(triple.I2 < Table.Length, "Index to table incorrect");

            //TODO: This shouldnt happen if Table is created correctly
            if (triple.I0 >= Table.Length) triple.I0 = 0;
            if (triple.I1 >= Table.Length) triple.I1 = -1;
            if (triple.I2 >= Table.Length) triple.I2 = -1;            
            //////end of hack

            bool singleMaterial = triple.I1 == -1 && triple.I2 == -1;

            if(singleMaterial)
            {
                size = sizeof(MyVoxelMaterialConstants);
                MyVoxelMaterialConstants constantsData = new MyVoxelMaterialConstants();
                FillVoxelMaterialEntry(ref constantsData.entry, ref Table[triple.I0]);

                buffer = new byte[size];
                fixed(byte* dstPtr = buffer)
                {
#if XB1
                    SharpDX.Utilities.CopyMemory(new IntPtr(dstPtr), new IntPtr(&constantsData), size);
#else // !XB1
                    MyMemory.CopyMemory(new IntPtr(dstPtr), new IntPtr(&constantsData), (uint)size);
#endif // !XB1
                }
            }
            else
            {
                size = sizeof(MyVoxelMultiMaterialConstants);
                MyVoxelMultiMaterialConstants constantsData = new MyVoxelMultiMaterialConstants();

                FillVoxelMaterialEntry(ref constantsData.entry0, ref Table[triple.I0]); 
                FillVoxelMaterialEntry(ref constantsData.entry1, ref Table[triple.I1]);
                if (triple.I2 >= 0)
                    FillVoxelMaterialEntry(ref constantsData.entry2, ref Table[triple.I2]);
                else
                    ResetVoxelMaterialEntry(out constantsData.entry2);

                buffer = new byte[size];
                fixed (byte* dstPtr = buffer)
                {
#if XB1
                    SharpDX.Utilities.CopyMemory(new IntPtr(dstPtr), new IntPtr(&constantsData), size);
#else // !XB1
                    MyMemory.CopyMemory(new IntPtr(dstPtr), new IntPtr(&constantsData), (uint)size);
#endif // !XB1
                }
            }

            var version = triple.I0.GetHashCode();
            MyHashHelper.Combine(ref version, triple.I1.GetHashCode());
            MyHashHelper.Combine(ref version, triple.I2.GetHashCode());

			MyConstantsPack materialConstants = new MyConstantsPack
				{
					BindFlag = MyBindFlag.BIND_PS,
					CB = MyCommon.GetMaterialCB(size),
					Version = version,
					Data = buffer
				};

			MySrvTable srvTable = new MySrvTable
				{
					// NOTE(AF) Adding BIND_VS here will interfere with shadows, causing flickering in the first cascade
					BindFlag = MyBindFlag.BIND_PS, 
					StartSlot = 0,
					Version = version,
					Srvs = new ISrvBindable[] 
							{ 
                                MyGlobalResources.FileArrayTextureVoxelCM,
                                MyGlobalResources.FileArrayTextureVoxelNG,
                                MyGlobalResources.FileArrayTextureVoxelExt,
							}
				};

            return new MyMaterialProxy_2
                {
                    MaterialConstants = materialConstants,
                    MaterialSrvs = srvTable
                };
        }
예제 #7
0
 internal static MyMaterialProxyId GetMaterialProxyId(MyVoxelMaterialTriple materialSet)
 {
     MyMaterialProxyId pid;
     if (!MaterialProxyTripleIndex.TryGetValue(materialSet, out pid))
     {
         pid = MaterialProxyTripleIndex[materialSet] = MyMaterials1.AllocateProxy();
         MyMaterials1.ProxyPool.Data[pid.Index] = CreateProxy(materialSet);
     }
     return pid;
 }
예제 #8
0
        static unsafe MyMaterialProxy_2 CreateProxy(MyVoxelMaterialTriple triple)
        {
            byte[] buffer;
            int    size;

            System.Diagnostics.Debug.Assert(triple.I0 < Table.Length, "Index to table incorrect");
            System.Diagnostics.Debug.Assert(triple.I1 < Table.Length, "Index to table incorrect");
            System.Diagnostics.Debug.Assert(triple.I2 < Table.Length, "Index to table incorrect");

            //TODO: This shouldnt happen if Table is created correctly
            if (triple.I0 >= Table.Length)
            {
                triple.I0 = 0;
            }
            if (triple.I1 >= Table.Length)
            {
                triple.I1 = -1;
            }
            if (triple.I2 >= Table.Length)
            {
                triple.I2 = -1;
            }
            //////end of hack


            bool singleMaterial = triple.I1 == -1 && triple.I2 == -1;

            if (singleMaterial)
            {
                size = sizeof(MyVoxelMaterialConstants);
                MyVoxelMaterialConstants constantsData = new MyVoxelMaterialConstants();
                constantsData.DistancesAndScale     = Table[triple.I0].DistanceAndScale;
                constantsData.DistancesAndScaleFar  = Table[triple.I0].DistanceAndScaleFar;
                constantsData.DistancesAndScaleFar3 = Table[triple.I0].DistanceAndScaleFar3;
                constantsData.Far3Color             = Table[triple.I0].Far3Color;
                constantsData.ExtensionDetailScale  = Table[triple.I0].ExtensionDetailScale;

                buffer = new byte[size];
                fixed(byte *dstPtr = buffer)
                {
                    MyMemory.CopyMemory(new IntPtr(dstPtr), new IntPtr(&constantsData), (uint)size);
                }
            }
            else
            {
                size = sizeof(MyVoxelMultiMaterialConstants);
                MyVoxelMultiMaterialConstants constantsData = new MyVoxelMultiMaterialConstants();

                constantsData.DistancesAndScale0     = Table[triple.I0].DistanceAndScale;
                constantsData.DistancesAndScale1     = Table[triple.I1].DistanceAndScale;
                constantsData.DistancesAndScale2     = triple.I2 >= 0 ? Table[triple.I2].DistanceAndScale : Vector4.Zero;
                constantsData.DistancesAndScaleFar0  = Table[triple.I0].DistanceAndScaleFar;
                constantsData.DistancesAndScaleFar1  = Table[triple.I1].DistanceAndScaleFar;
                constantsData.DistancesAndScaleFar2  = triple.I2 >= 0 ? Table[triple.I2].DistanceAndScaleFar : Vector4.Zero;
                constantsData.DistancesAndScaleFar31 = new Vector4(Table[triple.I0].DistanceAndScaleFar3.X, Table[triple.I0].DistanceAndScaleFar3.Y, 0, 0);
                constantsData.DistancesAndScaleFar32 = new Vector4(Table[triple.I1].DistanceAndScaleFar3.X, Table[triple.I1].DistanceAndScaleFar3.Y, 0, 0);
                constantsData.DistancesAndScaleFar33 = triple.I2 >= 0 ? new Vector4(Table[triple.I2].DistanceAndScaleFar3.X, Table[triple.I2].DistanceAndScaleFar3.Y, 0, 0) : Vector4.Zero;
                constantsData.Far3Color1             = Table[triple.I0].Far3Color.ToVector4();
                constantsData.Far3Color2             = Table[triple.I1].Far3Color.ToVector4();
                constantsData.Far3Color3             = triple.I2 >= 0 ? Table[triple.I2].Far3Color.ToVector4() : Vector4.Zero;
                constantsData.ExtensionDetailScale0  = Table[triple.I0].ExtensionDetailScale;
                constantsData.ExtensionDetailScale1  = Table[triple.I1].ExtensionDetailScale;
                constantsData.ExtensionDetailScale2  = triple.I2 >= 0 ? Table[triple.I2].ExtensionDetailScale : 0;

                buffer = new byte[size];
                fixed(byte *dstPtr = buffer)
                {
                    MyMemory.CopyMemory(new IntPtr(dstPtr), new IntPtr(&constantsData), (uint)size);
                }
            }

            var version = triple.I0.GetHashCode();

            MyHashHelper.Combine(ref version, triple.I1.GetHashCode());
            MyHashHelper.Combine(ref version, triple.I2.GetHashCode());

            return(new MyMaterialProxy_2
            {
                MaterialConstants =
                {
                    BindFlag = MyBindFlag.BIND_PS,
                    CB       = MyCommon.GetMaterialCB(size),
                    Version  = version,
                    Data     = buffer
                },
                MaterialSRVs =
                {
                    // NOTE(AF) Adding BIND_VS here will interfere with shadows, causing flickering in the first cascade
                    BindFlag  = MyBindFlag.BIND_PS,
                    StartSlot =                  0,
                    Version   = version,
                    SRVs      = singleMaterial
                            ?
                                new ShaderResourceView[]
                    {
                        Table[triple.I0].Near.ColorMetalArray.ShaderView, Table[triple.I0].Far1.ColorMetalArray.ShaderView, Table[triple.I0].Far2.ColorMetalArray.ShaderView,
                        Table[triple.I0].Near.NormalGlossArray.ShaderView, Table[triple.I0].Far1.NormalGlossArray.ShaderView, Table[triple.I0].Far2.NormalGlossArray.ShaderView,
                        Table[triple.I0].Near.ExtArray.ShaderView, Table[triple.I0].Far1.ExtArray.ShaderView, Table[triple.I0].Far2.ExtArray.ShaderView,
                    }
                            :
                    (
                        triple.I2 == -1
                                ?
                        new ShaderResourceView[]
                    {
                        Table[triple.I0].Near.ColorMetalArray.ShaderView, Table[triple.I0].Far1.ColorMetalArray.ShaderView, Table[triple.I0].Far2.ColorMetalArray.ShaderView,
                        Table[triple.I1].Near.ColorMetalArray.ShaderView, Table[triple.I1].Far1.ColorMetalArray.ShaderView, Table[triple.I1].Far2.ColorMetalArray.ShaderView,
                        null, null, null,
                        Table[triple.I0].Near.NormalGlossArray.ShaderView, Table[triple.I0].Far1.NormalGlossArray.ShaderView, Table[triple.I0].Far2.NormalGlossArray.ShaderView,
                        Table[triple.I1].Near.NormalGlossArray.ShaderView, Table[triple.I1].Far1.NormalGlossArray.ShaderView, Table[triple.I1].Far2.NormalGlossArray.ShaderView,
                        null, null, null,

                        Table[triple.I0].Near.ExtArray.ShaderView, Table[triple.I0].Far1.ExtArray.ShaderView, Table[triple.I0].Far2.ExtArray.ShaderView,
                        Table[triple.I1].Near.ExtArray.ShaderView, Table[triple.I1].Far1.ExtArray.ShaderView, Table[triple.I1].Far2.ExtArray.ShaderView,
                        null, null, null
                    }
                                :
                        new ShaderResourceView[]
                    {
                        Table[triple.I0].Near.ColorMetalArray.ShaderView, Table[triple.I0].Far1.ColorMetalArray.ShaderView, Table[triple.I0].Far2.ColorMetalArray.ShaderView,
                        Table[triple.I1].Near.ColorMetalArray.ShaderView, Table[triple.I1].Far1.ColorMetalArray.ShaderView, Table[triple.I1].Far2.ColorMetalArray.ShaderView,
                        Table[triple.I2].Near.ColorMetalArray.ShaderView, Table[triple.I2].Far1.ColorMetalArray.ShaderView, Table[triple.I2].Far2.ColorMetalArray.ShaderView,

                        Table[triple.I0].Near.NormalGlossArray.ShaderView, Table[triple.I0].Far1.NormalGlossArray.ShaderView, Table[triple.I0].Far2.NormalGlossArray.ShaderView,
                        Table[triple.I1].Near.NormalGlossArray.ShaderView, Table[triple.I1].Far1.NormalGlossArray.ShaderView, Table[triple.I1].Far2.NormalGlossArray.ShaderView,
                        Table[triple.I2].Near.NormalGlossArray.ShaderView, Table[triple.I2].Far1.NormalGlossArray.ShaderView, Table[triple.I2].Far2.NormalGlossArray.ShaderView,

                        Table[triple.I0].Near.ExtArray.ShaderView, Table[triple.I0].Far1.ExtArray.ShaderView, Table[triple.I0].Far2.ExtArray.ShaderView,
                        Table[triple.I1].Near.ExtArray.ShaderView, Table[triple.I1].Far1.ExtArray.ShaderView, Table[triple.I1].Far2.ExtArray.ShaderView,
                        Table[triple.I2].Near.ExtArray.ShaderView, Table[triple.I2].Far1.ExtArray.ShaderView, Table[triple.I2].Far2.ExtArray.ShaderView,
                    }
                    )
                }
            });
        }
예제 #9
0
 static MyMaterialProxy_2 CreateProxy(MyVoxelMaterialTriple triple)
 {
     // TODO: fill
     return new MyMaterialProxy_2();
 }
예제 #10
0
 internal static int GetMaterialProxyId(MyVoxelMaterialTriple materialSet)
 {
     if(!MaterialTripleIndex.ContainsKey(materialSet))
     {
         MaterialTripleIndex[materialSet] = MyMaterials.ProxyPool.Allocate();
     }
     return MaterialTripleIndex[materialSet];
 }
예제 #11
0
        static unsafe MyMaterialProxy_2 CreateProxy(MyVoxelMaterialTriple triple)
        {
            byte[] buffer;
            int size;

            System.Diagnostics.Debug.Assert(triple.I0 < Table.Length, "Index to table incorrect");
            System.Diagnostics.Debug.Assert(triple.I1 < Table.Length, "Index to table incorrect");
            System.Diagnostics.Debug.Assert(triple.I2 < Table.Length, "Index to table incorrect");

            //TODO: This shouldnt happen if Table is created correctly
            if (triple.I0 >= Table.Length) triple.I0 = 0;
            if (triple.I1 >= Table.Length) triple.I1 = -1;
            if (triple.I2 >= Table.Length) triple.I2 = -1;            
            //////end of hack


            bool singleMaterial = triple.I1 == -1 && triple.I2 == -1;

            if(singleMaterial)
            {
                size = sizeof(MyVoxelMaterialConstants);
                MyVoxelMaterialConstants constantsData = new MyVoxelMaterialConstants();
                constantsData.DistancesAndScale = Table[triple.I0].DistanceAndScale;
                constantsData.DistancesAndScaleFar = Table[triple.I0].DistanceAndScaleFar;
                constantsData.DistancesAndScaleFar3 = Table[triple.I0].DistanceAndScaleFar3;
                constantsData.Far3Color = Table[triple.I0].Far3Color;
                constantsData.ExtensionDetailScale = Table[triple.I0].ExtensionDetailScale;

                buffer = new byte[size];
                fixed(byte* dstPtr = buffer)
                {
                    MyMemory.CopyMemory(new IntPtr(dstPtr), new IntPtr(&constantsData), (uint)size);
                }
            }
            else
            {
                size = sizeof(MyVoxelMultiMaterialConstants);
                MyVoxelMultiMaterialConstants constantsData = new MyVoxelMultiMaterialConstants();

                constantsData.DistancesAndScale0 = Table[triple.I0].DistanceAndScale;
                constantsData.DistancesAndScale1 = Table[triple.I1].DistanceAndScale;
                constantsData.DistancesAndScale2 = triple.I2 >= 0 ? Table[triple.I2].DistanceAndScale : Vector4.Zero;
                constantsData.DistancesAndScaleFar0 = Table[triple.I0].DistanceAndScaleFar;
                constantsData.DistancesAndScaleFar1 = Table[triple.I1].DistanceAndScaleFar;
                constantsData.DistancesAndScaleFar2 = triple.I2 >= 0 ? Table[triple.I2].DistanceAndScaleFar : Vector4.Zero;
                constantsData.DistancesAndScaleFar3 = triple.I2 >= 0 ? Table[triple.I2].DistanceAndScaleFar3 : Vector2.Zero;
                constantsData.Far3Color = triple.I2 >= 0 ? Table[triple.I2].Far3Color : Color.Black;
                constantsData.ExtensionDetailScale0 = Table[triple.I0].ExtensionDetailScale;
                constantsData.ExtensionDetailScale1 = Table[triple.I1].ExtensionDetailScale;
                constantsData.ExtensionDetailScale2 = triple.I2 >= 0 ? Table[triple.I2].ExtensionDetailScale : 0;

                buffer = new byte[size];
                fixed (byte* dstPtr = buffer)
                {
                    MyMemory.CopyMemory(new IntPtr(dstPtr), new IntPtr(&constantsData), (uint)size);
                }
            }

            var version = triple.I0.GetHashCode();
            MyHashHelper.Combine(ref version, triple.I1.GetHashCode());
            MyHashHelper.Combine(ref version, triple.I2.GetHashCode());

            return new MyMaterialProxy_2
                {
                    MaterialConstants = 
                    { 
                        BindFlag = MyBindFlag.BIND_PS,  
                        CB = MyCommon.GetMaterialCB(size),
                        Version = version,
                        Data = buffer
                    },
                    MaterialSRVs = {
                        // NOTE(AF) Adding BIND_VS here will interfere with shadows, causing flickering in the first cascade
                        BindFlag = MyBindFlag.BIND_PS, 
                        StartSlot = 0,
                        Version = version,
                        SRVs = singleMaterial
                            ? 
                                new ShaderResourceView[] 
                                { 
                                    Table[triple.I0].Near.ColorMetalArray.ShaderView, Table[triple.I0].Far1.ColorMetalArray.ShaderView, Table[triple.I0].Far2.ColorMetalArray.ShaderView,
                                    Table[triple.I0].Near.NormalGlossArray.ShaderView, Table[triple.I0].Far1.NormalGlossArray.ShaderView, Table[triple.I0].Far2.NormalGlossArray.ShaderView,
                                    Table[triple.I0].Near.ExtArray.ShaderView, Table[triple.I0].Far1.ExtArray.ShaderView, Table[triple.I0].Far2.ExtArray.ShaderView,
                                }
                            : 
                            (
                            triple.I2 == -1 
                                ?
                                new ShaderResourceView[] 
                                { 
                                    Table[triple.I0].Near.ColorMetalArray.ShaderView, Table[triple.I0].Far1.ColorMetalArray.ShaderView, Table[triple.I0].Far2.ColorMetalArray.ShaderView,
                                    Table[triple.I1].Near.ColorMetalArray.ShaderView, Table[triple.I1].Far1.ColorMetalArray.ShaderView, Table[triple.I1].Far2.ColorMetalArray.ShaderView,
                                    null, null, null,
                                    Table[triple.I0].Near.NormalGlossArray.ShaderView, Table[triple.I0].Far1.NormalGlossArray.ShaderView, Table[triple.I0].Far2.NormalGlossArray.ShaderView,
                                    Table[triple.I1].Near.NormalGlossArray.ShaderView, Table[triple.I1].Far1.NormalGlossArray.ShaderView, Table[triple.I1].Far2.NormalGlossArray.ShaderView,
                                    null, null, null,

                                    Table[triple.I0].Near.ExtArray.ShaderView, Table[triple.I0].Far1.ExtArray.ShaderView, Table[triple.I0].Far2.ExtArray.ShaderView,
                                    Table[triple.I1].Near.ExtArray.ShaderView, Table[triple.I1].Far1.ExtArray.ShaderView, Table[triple.I1].Far2.ExtArray.ShaderView,
                                    null, null, null
                                }
                                :
                                new ShaderResourceView[] 
                                { 
                                    Table[triple.I0].Near.ColorMetalArray.ShaderView, Table[triple.I0].Far1.ColorMetalArray.ShaderView, Table[triple.I0].Far2.ColorMetalArray.ShaderView,
                                    Table[triple.I1].Near.ColorMetalArray.ShaderView, Table[triple.I1].Far1.ColorMetalArray.ShaderView, Table[triple.I1].Far2.ColorMetalArray.ShaderView,
                                    Table[triple.I2].Near.ColorMetalArray.ShaderView, Table[triple.I2].Far1.ColorMetalArray.ShaderView, Table[triple.I2].Far2.ColorMetalArray.ShaderView,

                                    Table[triple.I0].Near.NormalGlossArray.ShaderView, Table[triple.I0].Far1.NormalGlossArray.ShaderView, Table[triple.I0].Far2.NormalGlossArray.ShaderView,
                                    Table[triple.I1].Near.NormalGlossArray.ShaderView, Table[triple.I1].Far1.NormalGlossArray.ShaderView, Table[triple.I1].Far2.NormalGlossArray.ShaderView,
                                    Table[triple.I2].Near.NormalGlossArray.ShaderView, Table[triple.I2].Far1.NormalGlossArray.ShaderView, Table[triple.I2].Far2.NormalGlossArray.ShaderView,

                                    Table[triple.I0].Near.ExtArray.ShaderView, Table[triple.I0].Far1.ExtArray.ShaderView, Table[triple.I0].Far2.ExtArray.ShaderView,
                                    Table[triple.I1].Near.ExtArray.ShaderView, Table[triple.I1].Far1.ExtArray.ShaderView, Table[triple.I1].Far2.ExtArray.ShaderView,
                                    Table[triple.I2].Near.ExtArray.ShaderView, Table[triple.I2].Far1.ExtArray.ShaderView, Table[triple.I2].Far2.ExtArray.ShaderView,
                                }
                                )
                           
                    }
                };
        }
예제 #12
0
 internal static MyMaterialProxyId GetMaterialProxyId(MyVoxelMaterialTriple materialSet)
 {
     if (!MaterialProxyTripleIndex.ContainsKey(materialSet))
     {
         var matId = MaterialProxyTripleIndex[materialSet] = MyMaterials1.AllocateProxy();
         MyMaterials1.ProxyPool.Data[matId.Index] = CreateProxy(materialSet);
     }
     return MaterialProxyTripleIndex[materialSet];
 }
예제 #13
0
        static unsafe MyMaterialProxy_2 CreateProxy(MyVoxelMaterialTriple triple)
        {
            byte[] buffer;
            int size;
            bool singleMaterial = triple.I1 == -1 && triple.I2 == -1;

            if(singleMaterial)
            {
                size = sizeof(MyVoxelMaterialConstants);
                MyVoxelMaterialConstants constantsData = new MyVoxelMaterialConstants();
                constantsData.Scales = Table[triple.I0].ScaleFactors;
                buffer = new byte[size];
                fixed(byte* dstPtr = buffer)
                {
                    MyMemory.CopyMemory(new IntPtr(dstPtr), new IntPtr(&constantsData), (uint)size);
                }
            }
            else
            {
                size = sizeof(MyVoxelMultiMaterialConstants);
                MyVoxelMultiMaterialConstants constantsData = new MyVoxelMultiMaterialConstants();

                constantsData.Scales0 = Table[triple.I0].ScaleFactors;
                constantsData.Scales1 = Table[triple.I1].ScaleFactors;
                constantsData.Scales2 = triple.I2 >= 0 ? Table[triple.I2].ScaleFactors : Vector3.One;
                buffer = new byte[size];
                fixed (byte* dstPtr = buffer)
                {
                    MyMemory.CopyMemory(new IntPtr(dstPtr), new IntPtr(&constantsData), (uint)size);
                }
            }

            var version = triple.I0.GetHashCode();
            MyHashHelper.Combine(ref version, triple.I1.GetHashCode());
            MyHashHelper.Combine(ref version, triple.I2.GetHashCode());

            return new MyMaterialProxy_2
                {
                    MaterialConstants = 
                    { 
                        BindFlag = MyBindFlag.BIND_PS,
                        CB = MyCommon.GetMaterialCB(size),
                        Version = version,
                        Data = buffer
                    },
                    MaterialSRVs = { 
                        BindFlag = MyBindFlag.BIND_PS, 
                        StartSlot = 0,
                        Version = version,
                        SRVs = singleMaterial
                            ? 
                                new ShaderResourceView[] 
                                { 
                                    Table[triple.I0].Near.ColorMetalArray.ShaderView, Table[triple.I0].Far1.ColorMetalArray.ShaderView, Table[triple.I0].Far2.ColorMetalArray.ShaderView,
                                    Table[triple.I0].Near.NormalGlossArray.ShaderView, Table[triple.I0].Far1.NormalGlossArray.ShaderView, Table[triple.I0].Far2.NormalGlossArray.ShaderView,
                                }
                            : 
                            (
                            triple.I2 == -1 
                                ?
                                new ShaderResourceView[] 
                                { 
                                    Table[triple.I0].Near.ColorMetalArray.ShaderView, Table[triple.I0].Far1.ColorMetalArray.ShaderView, Table[triple.I0].Far2.ColorMetalArray.ShaderView,
                                    Table[triple.I1].Near.ColorMetalArray.ShaderView, Table[triple.I1].Far1.ColorMetalArray.ShaderView, Table[triple.I1].Far2.ColorMetalArray.ShaderView,
                                    null, null, null,
                                    Table[triple.I0].Near.NormalGlossArray.ShaderView, Table[triple.I0].Far1.NormalGlossArray.ShaderView, Table[triple.I0].Far2.NormalGlossArray.ShaderView,
                                    Table[triple.I1].Near.NormalGlossArray.ShaderView, Table[triple.I1].Far1.NormalGlossArray.ShaderView, Table[triple.I1].Far2.NormalGlossArray.ShaderView,
                                    null, null, null,

                                    null, null, null,
                                    null, null, null,
                                    null, null, null
                                }
                                :
                                new ShaderResourceView[] 
                                { 
                                    Table[triple.I0].Near.ColorMetalArray.ShaderView, Table[triple.I0].Far1.ColorMetalArray.ShaderView, Table[triple.I0].Far2.ColorMetalArray.ShaderView,
                                    Table[triple.I1].Near.ColorMetalArray.ShaderView, Table[triple.I1].Far1.ColorMetalArray.ShaderView, Table[triple.I1].Far2.ColorMetalArray.ShaderView,
                                    Table[triple.I2].Near.ColorMetalArray.ShaderView, Table[triple.I2].Far1.ColorMetalArray.ShaderView, Table[triple.I2].Far2.ColorMetalArray.ShaderView,

                                    Table[triple.I0].Near.NormalGlossArray.ShaderView, Table[triple.I0].Far1.NormalGlossArray.ShaderView, Table[triple.I0].Far2.NormalGlossArray.ShaderView,
                                    Table[triple.I1].Near.NormalGlossArray.ShaderView, Table[triple.I1].Far1.NormalGlossArray.ShaderView, Table[triple.I1].Far2.NormalGlossArray.ShaderView,
                                    Table[triple.I2].Near.NormalGlossArray.ShaderView, Table[triple.I2].Far1.NormalGlossArray.ShaderView, Table[triple.I2].Far2.NormalGlossArray.ShaderView,

                                    null, null, null,
                                    null, null, null,
                                    null, null, null
                                }
                                )
                           
                    }
                };
        }
예제 #14
0
        static unsafe MyMaterialProxy_2 CreateProxy(MyVoxelMaterialTriple triple)
        {
            byte[] buffer;
            int    size;
            bool   singleMaterial = triple.I1 == -1 && triple.I2 == -1;

            if (singleMaterial)
            {
                size = sizeof(MyVoxelMaterialConstants);
                MyVoxelMaterialConstants constantsData = new MyVoxelMaterialConstants();
                constantsData.Scales = Table[triple.I0].ScaleFactors;
                buffer = new byte[size];
                fixed(byte *dstPtr = buffer)
                {
                    MyMemory.CopyMemory(new IntPtr(dstPtr), new IntPtr(&constantsData), (uint)size);
                }
            }
            else
            {
                size = sizeof(MyVoxelMultiMaterialConstants);
                MyVoxelMultiMaterialConstants constantsData = new MyVoxelMultiMaterialConstants();

                constantsData.Scales0 = Table[triple.I0].ScaleFactors;
                constantsData.Scales1 = Table[triple.I1].ScaleFactors;
                constantsData.Scales2 = triple.I2 >= 0 ? Table[triple.I2].ScaleFactors : Vector3.One;
                buffer = new byte[size];
                fixed(byte *dstPtr = buffer)
                {
                    MyMemory.CopyMemory(new IntPtr(dstPtr), new IntPtr(&constantsData), (uint)size);
                }
            }

            var version = triple.I0.GetHashCode();

            MyHashHelper.Combine(ref version, triple.I1.GetHashCode());
            MyHashHelper.Combine(ref version, triple.I2.GetHashCode());

            return(new MyMaterialProxy_2
            {
                MaterialConstants =
                {
                    BindFlag = MyBindFlag.BIND_PS,
                    CB       = MyCommon.GetMaterialCB(size),
                    Version  = version,
                    Data     = buffer
                },
                MaterialSRVs =
                {
                    BindFlag  = MyBindFlag.BIND_PS,
                    StartSlot =                  0,
                    Version   = version,
                    SRVs      = singleMaterial
                            ?
                                new ShaderResourceView[]
                    {
                        Table[triple.I0].Near.ColorMetalArray.ShaderView, Table[triple.I0].Far1.ColorMetalArray.ShaderView, Table[triple.I0].Far2.ColorMetalArray.ShaderView,
                        Table[triple.I0].Near.NormalGlossArray.ShaderView, Table[triple.I0].Far1.NormalGlossArray.ShaderView, Table[triple.I0].Far2.NormalGlossArray.ShaderView,
                    }
                            :
                    (
                        triple.I2 == -1
                                ?
                        new ShaderResourceView[]
                    {
                        Table[triple.I0].Near.ColorMetalArray.ShaderView, Table[triple.I0].Far1.ColorMetalArray.ShaderView, Table[triple.I0].Far2.ColorMetalArray.ShaderView,
                        Table[triple.I1].Near.ColorMetalArray.ShaderView, Table[triple.I1].Far1.ColorMetalArray.ShaderView, Table[triple.I1].Far2.ColorMetalArray.ShaderView,
                        null, null, null,
                        Table[triple.I0].Near.NormalGlossArray.ShaderView, Table[triple.I0].Far1.NormalGlossArray.ShaderView, Table[triple.I0].Far2.NormalGlossArray.ShaderView,
                        Table[triple.I1].Near.NormalGlossArray.ShaderView, Table[triple.I1].Far1.NormalGlossArray.ShaderView, Table[triple.I1].Far2.NormalGlossArray.ShaderView,
                        null, null, null,

                        null, null, null,
                        null, null, null,
                        null, null, null
                    }
                                :
                        new ShaderResourceView[]
                    {
                        Table[triple.I0].Near.ColorMetalArray.ShaderView, Table[triple.I0].Far1.ColorMetalArray.ShaderView, Table[triple.I0].Far2.ColorMetalArray.ShaderView,
                        Table[triple.I1].Near.ColorMetalArray.ShaderView, Table[triple.I1].Far1.ColorMetalArray.ShaderView, Table[triple.I1].Far2.ColorMetalArray.ShaderView,
                        Table[triple.I2].Near.ColorMetalArray.ShaderView, Table[triple.I2].Far1.ColorMetalArray.ShaderView, Table[triple.I2].Far2.ColorMetalArray.ShaderView,

                        Table[triple.I0].Near.NormalGlossArray.ShaderView, Table[triple.I0].Far1.NormalGlossArray.ShaderView, Table[triple.I0].Far2.NormalGlossArray.ShaderView,
                        Table[triple.I1].Near.NormalGlossArray.ShaderView, Table[triple.I1].Far1.NormalGlossArray.ShaderView, Table[triple.I1].Far2.NormalGlossArray.ShaderView,
                        Table[triple.I2].Near.NormalGlossArray.ShaderView, Table[triple.I2].Far1.NormalGlossArray.ShaderView, Table[triple.I2].Far2.NormalGlossArray.ShaderView,

                        null, null, null,
                        null, null, null,
                        null, null, null
                    }
                    )
                }
            });
        }
예제 #15
0
 static MyMaterialProxy_2 CreateProxy(MyVoxelMaterialTriple triple)
 {
     // TODO: fill
     return(new MyMaterialProxy_2());
 }
예제 #16
0
        static unsafe MyMaterialProxy_2 CreateProxy(MyVoxelMaterialTriple triple)
        {
            byte[] buffer;
            int    size;

            MyRenderProxy.Assert(triple.I0 < Table.Length, "Index to table incorrect");
            MyRenderProxy.Assert(triple.I1 < Table.Length, "Index to table incorrect");
            MyRenderProxy.Assert(triple.I2 < Table.Length, "Index to table incorrect");

            //TODO: This shouldnt happen if Table is created correctly
            if (triple.I0 >= Table.Length)
            {
                triple.I0 = 0;
            }
            if (triple.I1 >= Table.Length)
            {
                triple.I1 = -1;
            }
            if (triple.I2 >= Table.Length)
            {
                triple.I2 = -1;
            }
            //////end of hack

            bool singleMaterial = triple.I1 == -1 && triple.I2 == -1;

            if (singleMaterial)
            {
                size = sizeof(MyVoxelMaterialConstants);
                MyVoxelMaterialConstants constantsData = new MyVoxelMaterialConstants();
                FillVoxelMaterialEntry(ref constantsData.entry, ref Table[triple.I0]);

                buffer = new byte[size];
                fixed(byte *dstPtr = buffer)
                {
#if XB1
                    SharpDX.Utilities.CopyMemory(new IntPtr(dstPtr), new IntPtr(&constantsData), size);
#else // !XB1
                    MyMemory.CopyMemory(new IntPtr(dstPtr), new IntPtr(&constantsData), (uint)size);
#endif // !XB1
                }
            }
            else
            {
                size = sizeof(MyVoxelMultiMaterialConstants);
                MyVoxelMultiMaterialConstants constantsData = new MyVoxelMultiMaterialConstants();

                FillVoxelMaterialEntry(ref constantsData.entry0, ref Table[triple.I0]);
                FillVoxelMaterialEntry(ref constantsData.entry1, ref Table[triple.I1]);
                if (triple.I2 >= 0)
                {
                    FillVoxelMaterialEntry(ref constantsData.entry2, ref Table[triple.I2]);
                }
                else
                {
                    ResetVoxelMaterialEntry(out constantsData.entry2);
                }

                buffer = new byte[size];
                fixed(byte *dstPtr = buffer)
                {
#if XB1
                    SharpDX.Utilities.CopyMemory(new IntPtr(dstPtr), new IntPtr(&constantsData), size);
#else // !XB1
                    MyMemory.CopyMemory(new IntPtr(dstPtr), new IntPtr(&constantsData), (uint)size);
#endif // !XB1
                }
            }

            var version = triple.I0.GetHashCode();
            MyHashHelper.Combine(ref version, triple.I1.GetHashCode());
            MyHashHelper.Combine(ref version, triple.I2.GetHashCode());

            MyConstantsPack materialConstants = new MyConstantsPack
            {
                BindFlag = MyBindFlag.BIND_PS,
                CB       = MyCommon.GetMaterialCB(size),
                Version  = version,
                Data     = buffer
            };

            MySrvTable srvTable = new MySrvTable
            {
                // NOTE(AF) Adding BIND_VS here will interfere with shadows, causing flickering in the first cascade
                BindFlag  = MyBindFlag.BIND_PS,
                StartSlot = 0,
                Version   = version,
                Srvs      = new ISrvBindable[]
                {
                    MyGlobalResources.FileArrayTextureVoxelCM,
                    MyGlobalResources.FileArrayTextureVoxelNG,
                    MyGlobalResources.FileArrayTextureVoxelExt,
                }
            };

            return(new MyMaterialProxy_2
            {
                MaterialConstants = materialConstants,
                MaterialSrvs = srvTable
            });
        }