示例#1
0
 public static void SetConstants(MyRenderContext rc, ref MyConstantsPack desc, int slot)
 {
     if ((desc.BindFlag & MyBindFlag.BIND_VS) > 0)
     {
         rc.VertexShader.SetConstantBuffer(slot, desc.CB);
     }
     if ((desc.BindFlag & MyBindFlag.BIND_PS) > 0)
     {
         rc.PixelShader.SetConstantBuffer(slot, desc.CB);
     }
     MyRender11.ProcessDebugOutput();
 }
 public static void SetConstants(MyRenderContext rc, ref MyConstantsPack desc, int slot)
 {
     if ((desc.BindFlag & MyBindFlag.BIND_VS) > 0)
     {
         rc.VertexShader.SetConstantBuffer(slot, desc.CB);
     }
     if ((desc.BindFlag & MyBindFlag.BIND_PS) > 0)
     {
         rc.PixelShader.SetConstantBuffer(slot, desc.CB);
     }
     MyRender11.ProcessDebugOutput();
 }
        internal unsafe void MoveConstants(ref MyConstantsPack desc)
        {
            if (desc.CB == null)
            {
                return;
            }
            if (State.m_constantsVersion.Get(desc.CB) != desc.Version)
            {
                State.m_constantsVersion[desc.CB] = desc.Version;

                var mapping = MyMapping.MapDiscard(DeviceContext, desc.CB);
                mapping.WriteAndPosition(desc.Data, 0, desc.Data.Length);
                mapping.Unmap();
            }
        }
示例#4
0
        public static unsafe void MoveConstants(MyRenderContext rc, ref MyConstantsPack desc)
        {
            if (desc.CB == null)
                return;
            // IMPORTANT: It is optimisation but that has not been very well implemented, it is not considered multithread approach, usage of buffers in multiple passes, 
            // reset device and and refillage of the buffers. More complex task to do it properly
            //if (m_staticData.m_constantsVersion.Get(desc.CB) != desc.Version)
            //{
            //    m_staticData.m_constantsVersion[desc.CB] = desc.Version;

                var mapping = MyMapping.MapDiscard(rc, desc.CB);
                mapping.WriteAndPosition(desc.Data, 0, desc.Data.Length);
                mapping.Unmap();
            //}
            //MyRender11.ProcessDebugOutput();
        }
        public static unsafe void MoveConstants(MyRenderContext rc, ref MyConstantsPack desc)
        {
            if (desc.CB == null)
            {
                return;
            }
            // IMPORTANT: It is optimisation but that has not been very well implemented, it is not considered multithread approach, usage of buffers in multiple passes,
            // reset device and and refillage of the buffers. More complex task to do it properly
            //if (m_staticData.m_constantsVersion.Get(desc.CB) != desc.Version)
            //{
            //    m_staticData.m_constantsVersion[desc.CB] = desc.Version;

            var mapping = MyMapping.MapDiscard(rc, desc.CB);

            mapping.WriteAndPosition(desc.Data, 0, desc.Data.Length);
            mapping.Unmap();
            //}
            //MyRender11.ProcessDebugOutput();
        }
示例#6
0
        internal unsafe void MoveConstants(ref MyConstantsPack desc)
        {
            if (desc.CB == null)
            {
                return;
            }
            if (State.m_constantsVersion.Get(desc.CB) != desc.Version)
            {
                State.m_constantsVersion[desc.CB] = desc.Version;

                var box = Context.MapSubresource((SharpDX.Direct3D11.Resource)desc.CB, 0, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None);
                // TODO: try with aligned memory
                fixed(byte *ptr = desc.Data)
                {
                    MyMemory.CopyMemory(box.DataPointer, new IntPtr(ptr), (uint)desc.Data.Length);
                }

                Context.UnmapSubresource(desc.CB, 0);
            }
        }
示例#7
0
 internal void SetConstants(ref MyConstantsPack desc, int slot)
 {
     if ((desc.BindFlag & MyBindFlag.BIND_VS) > 0 && State.m_constantBindings.Get(new MyStageBinding {
         Slot = slot, Stage = MyShaderStage.VS
     }) != desc.CB)
     {
         State.m_constantBindings[new MyStageBinding {
                                      Slot = slot, Stage = MyShaderStage.VS
                                  }] = desc.CB;
         Context.VertexShader.SetConstantBuffer(slot, desc.CB);
     }
     if ((desc.BindFlag & MyBindFlag.BIND_PS) > 0 && State.m_constantBindings.Get(new MyStageBinding {
         Slot = slot, Stage = MyShaderStage.PS
     }) != desc.CB)
     {
         State.m_constantBindings[new MyStageBinding {
                                      Slot = slot, Stage = MyShaderStage.PS
                                  }] = desc.CB;
         Context.PixelShader.SetConstantBuffer(slot, desc.CB);
     }
 }
示例#8
0
        internal void SetConstants(ref MyConstantsPack desc, int slot)
        {
            MyStageBinding key;

            key.Stage = MyShaderStage.VS;

            try
            {
                if ((desc.BindFlag & MyBindFlag.BIND_VS) > 0 && State.m_constantBindings.Get(new MyStageBinding {
                    Slot = slot, Stage = MyShaderStage.VS
                }) != desc.CB)
                {
                    key = new MyStageBinding {
                        Slot = slot, Stage = MyShaderStage.VS
                    };
                    State.m_constantBindings[key] = desc.CB;
                    DeviceContext.VertexShader.SetConstantBuffer(slot, desc.CB);
                }
                if ((desc.BindFlag & MyBindFlag.BIND_PS) > 0 && State.m_constantBindings.Get(new MyStageBinding {
                    Slot = slot, Stage = MyShaderStage.PS
                }) != desc.CB)
                {
                    key = new MyStageBinding {
                        Slot = slot, Stage = MyShaderStage.PS
                    };
                    State.m_constantBindings[key] = desc.CB;
                    DeviceContext.PixelShader.SetConstantBuffer(slot, desc.CB);
                }
                MyRender11.ProcessDebugOutput();
            }
            catch (Exception ex)
            {
                MyLog.Default.WriteLine(ex);
                MyLog.Default.WriteLine(string.Format("Some additional info: slot {0}, Stage {1}, desc {2}", slot, key.Stage, desc));
                MyLog.Default.WriteLine("m_constantBindings.Count: " + State.m_constantBindings.Count);
                MyLog.Default.WriteLine("m_constantBindings: " + State.m_constantBindings);
                throw;
            }
        }
示例#9
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
                };
        }
示例#10
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());

            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      = singleMaterial
                                                ?
                            new IShaderResourceBindable[]
                {
                    Table[triple.I0].Near.ColorMetalArray, Table[triple.I0].Far1.ColorMetalArray, Table[triple.I0].Far2.ColorMetalArray,
                    Table[triple.I0].Near.NormalGlossArray, Table[triple.I0].Far1.NormalGlossArray, Table[triple.I0].Far2.NormalGlossArray,
                    Table[triple.I0].Near.ExtArray, Table[triple.I0].Far1.ExtArray, Table[triple.I0].Far2.ExtArray,
                }
                                                :
                (
                    triple.I2 == -1
                                                        ?
                    new IShaderResourceBindable[]
                {
                    Table[triple.I0].Near.ColorMetalArray, Table[triple.I0].Far1.ColorMetalArray, Table[triple.I0].Far2.ColorMetalArray,
                    Table[triple.I1].Near.ColorMetalArray, Table[triple.I1].Far1.ColorMetalArray, Table[triple.I1].Far2.ColorMetalArray,
                    null, null, null,
                    Table[triple.I0].Near.NormalGlossArray, Table[triple.I0].Far1.NormalGlossArray, Table[triple.I0].Far2.NormalGlossArray,
                    Table[triple.I1].Near.NormalGlossArray, Table[triple.I1].Far1.NormalGlossArray, Table[triple.I1].Far2.NormalGlossArray,
                    null, null, null,

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

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

                    Table[triple.I0].Near.ExtArray, Table[triple.I0].Far1.ExtArray, Table[triple.I0].Far2.ExtArray,
                    Table[triple.I1].Near.ExtArray, Table[triple.I1].Far1.ExtArray, Table[triple.I1].Far2.ExtArray,
                    Table[triple.I2].Near.ExtArray, Table[triple.I2].Far1.ExtArray, Table[triple.I2].Far2.ExtArray,
                }
                )
            };

            return(new MyMaterialProxy_2
            {
                MaterialConstants = materialConstants,
                MaterialSRVs = srvTable
            });
        }
 internal void SetConstants(ref MyConstantsPack desc, int slot)
 {
     if ((desc.BindFlag & MyBindFlag.BIND_VS) > 0 && State.m_constantBindings.Get(new MyStageBinding { Slot = slot, Stage = MyShaderStage.VS }) != desc.CB)
     {
         State.m_constantBindings[new MyStageBinding { Slot = slot, Stage = MyShaderStage.VS }] = desc.CB;
         Context.VertexShader.SetConstantBuffer(slot, desc.CB);
     }
     if ((desc.BindFlag & MyBindFlag.BIND_PS) > 0 && State.m_constantBindings.Get(new MyStageBinding { Slot = slot, Stage = MyShaderStage.PS }) != desc.CB)
     {
         State.m_constantBindings[new MyStageBinding { Slot = slot, Stage = MyShaderStage.PS }] = desc.CB;
         Context.PixelShader.SetConstantBuffer(slot, desc.CB);
     }
 }
 internal unsafe void MoveConstants(ref MyConstantsPack desc)
 {
     if (desc.CB == null)
         return;
     if (State.m_constantsVersion.Get(desc.CB) != desc.Version)
     {
         State.m_constantsVersion[desc.CB] = desc.Version;
         
         var box = Context.MapSubresource((SharpDX.Direct3D11.Resource)desc.CB, 0, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None);
         // TODO: try with aligned memory
         fixed(byte* ptr = desc.Data)
         {
             MyMemory.CopyMemory(box.DataPointer, new IntPtr(ptr), (uint)desc.Data.Length);
         }
         Context.UnmapSubresource(desc.CB, 0);
     }
 }
示例#13
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
            });
        }
示例#14
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());

			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 = singleMaterial
						? 
                            new IShaderResourceBindable[] 
							{ 
								Table[triple.I0].Near.ColorMetalArray, Table[triple.I0].Far1.ColorMetalArray, Table[triple.I0].Far2.ColorMetalArray,
								Table[triple.I0].Near.NormalGlossArray, Table[triple.I0].Far1.NormalGlossArray, Table[triple.I0].Far2.NormalGlossArray,
								Table[triple.I0].Near.ExtArray, Table[triple.I0].Far1.ExtArray, Table[triple.I0].Far2.ExtArray,
							}
						: 
						(
						triple.I2 == -1 
							?
                            new IShaderResourceBindable[] 
							{ 
								Table[triple.I0].Near.ColorMetalArray, Table[triple.I0].Far1.ColorMetalArray, Table[triple.I0].Far2.ColorMetalArray,
								Table[triple.I1].Near.ColorMetalArray, Table[triple.I1].Far1.ColorMetalArray, Table[triple.I1].Far2.ColorMetalArray,
								null, null, null,
								Table[triple.I0].Near.NormalGlossArray, Table[triple.I0].Far1.NormalGlossArray, Table[triple.I0].Far2.NormalGlossArray,
								Table[triple.I1].Near.NormalGlossArray, Table[triple.I1].Far1.NormalGlossArray, Table[triple.I1].Far2.NormalGlossArray,
								null, null, null,

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

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

								Table[triple.I0].Near.ExtArray, Table[triple.I0].Far1.ExtArray, Table[triple.I0].Far2.ExtArray,
								Table[triple.I1].Near.ExtArray, Table[triple.I1].Far1.ExtArray, Table[triple.I1].Far2.ExtArray,
								Table[triple.I2].Near.ExtArray, Table[triple.I2].Far1.ExtArray, Table[triple.I2].Far2.ExtArray,
							}
						)
				};

            return new MyMaterialProxy_2
                {
                    MaterialConstants = materialConstants,
                    MaterialSRVs = srvTable
                };
        }