Esempio n. 1
0
        internal static MyMaterialProxy_2 CreateProxy(ref MyMeshMaterialInfo info)
        {
            ISrvBindable A, B, C, D;

            if (!info.GeometryTextureRef.IsUsed)
            {
                MyFileTextureManager texManager = MyManagers.FileTextures;
                A = texManager.GetTexture(info.ColorMetal_Texture, MyFileTextureEnum.COLOR_METAL);
                B = texManager.GetTexture(info.NormalGloss_Texture, MyFileTextureEnum.NORMALMAP_GLOSS);
                C = texManager.GetTexture(info.Extensions_Texture, MyFileTextureEnum.EXTENSIONS);
                D = texManager.GetTexture(info.Alphamask_Texture, MyFileTextureEnum.ALPHAMASK);
            }
            else
            {
                A = info.GeometryTextureRef.ColorMetalTexture;
                B = info.GeometryTextureRef.NormalGlossTexture;
                C = info.GeometryTextureRef.ExtensionTexture;
                D = info.GeometryTextureRef.AlphamaskTexture;
            }
            var materialSrvs = new MySrvTable
            {
                BindFlag  = MyBindFlag.BIND_PS,
                StartSlot = 0,
                Srvs      = new ISrvBindable[] { A, B, C, D },
                Version   = info.Id.GetHashCode()
            };

            return
                (new MyMaterialProxy_2 {
                MaterialSrvs = materialSrvs
            });
        }
Esempio n. 2
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
            });
        }
Esempio n. 3
0
        internal void SetSRVs(ref MySrvTable desc)
        {
            //if (desc.BindFlag.HasFlag(MyBindFlag.BIND_VS))
            //{
            //    var val = new MyStageSrvBinding { Stage = MyShaderStage.VS, Slot = desc.StartSlot, Length = desc.SRVs.Length, Version = desc.Version };

            //    int f = State.m_srvBindings1.BinarySearch(val);
            //    var index = ~f;
            //    bool match = f >= 0; // if yes no need to bind
            //    bool collision = (index < State.m_srvBindings1.Count) &&
            //        State.m_srvBindings1[index].Stage == val.Stage &&
            //        (val.Slot + val.Length) >= State.m_srvBindings1[index].Slot; // if yes replace, if no add before, bind anyway

            //    if(!match && collision)
            //    {
            //        State.m_srvBindings1[index] = val;
            //        Context.VertexShader.SetShaderResources(desc.StartSlot, desc.SRVs);
            //    }
            //    else if(!match && !collision)
            //    {
            //        State.m_srvBindings1.Insert(index, val);
            //        Context.VertexShader.SetShaderResources(desc.StartSlot, desc.SRVs);
            //    }
            //}


            if ((desc.BindFlag & MyBindFlag.BIND_VS) > 0 &&
                State.m_srvTableBindings.Get(new MyStageSrvBinding {
                Stage = MyShaderStage.VS, Slot = desc.StartSlot
            }, NO_VERSION) != desc.Version)
            {
                State.m_srvTableBindings[new MyStageSrvBinding {
                                             Stage = MyShaderStage.VS, Slot = desc.StartSlot
                                         }] = desc.Version;
                for (int i = 0; i < desc.SRVs.Length; i++)
                {
                    DeviceContext.VertexShader.SetShaderResource(desc.StartSlot + i, desc.SRVs[i].SRV);
                }
            }
            if ((desc.BindFlag & MyBindFlag.BIND_PS) > 0 &&
                State.m_srvTableBindings.Get(new MyStageSrvBinding {
                Stage = MyShaderStage.PS, Slot = desc.StartSlot
            }, NO_VERSION) != desc.Version)
            {
                State.m_srvTableBindings[new MyStageSrvBinding {
                                             Stage = MyShaderStage.PS, Slot = desc.StartSlot
                                         }] = desc.Version;
                for (int i = 0; i < desc.SRVs.Length; i++)
                {
                    DeviceContext.PixelShader.SetShaderResource(desc.StartSlot + i, desc.SRVs[i].SRV);
                }
            }
            MyRender11.ProcessDebugOutput();
        }
Esempio n. 4
0
 internal static void SetSrvs(MyRenderContext rc, ref MySrvTable desc)
 {
     if ((desc.BindFlag & MyBindFlag.BIND_VS) > 0)
     {
         for (int i = 0; i < desc.Srvs.Length; i++)
             rc.VertexShader.SetRawSrv(desc.StartSlot + i, desc.Srvs[i]);
     }
     if ((desc.BindFlag & MyBindFlag.BIND_PS) > 0)
     {
         for (int i = 0; i < desc.Srvs.Length; i++)
             rc.PixelShader.SetRawSrv(desc.StartSlot + i, desc.Srvs[i]);
     }
     MyRender11.ProcessDebugOutput();
 }
        internal static MyMaterialProxy_2 CreateProxy(ref MyMeshMaterialInfo info)
        {
            var A = MyTextures.GetTexture(info.ColorMetal_Texture, info.ContentPath, MyTextureEnum.COLOR_METAL);
            var B = MyTextures.GetTexture(info.NormalGloss_Texture, info.ContentPath, MyTextureEnum.NORMALMAP_GLOSS);
            var C = MyTextures.GetTexture(info.Extensions_Texture, info.ContentPath, MyTextureEnum.EXTENSIONS);
            var D = MyTextures.GetTexture(info.Alphamask_Texture, info.ContentPath, MyTextureEnum.ALPHAMASK);

			var materialSrvs = new MySrvTable
					{ 
                        BindFlag = MyBindFlag.BIND_PS, 
                        StartSlot = 0,
                        SRVs = new IShaderResourceBindable[] { A, B, C, D },
                        Version = info.Id.GetHashCode()
                    };
            return
				new MyMaterialProxy_2 { MaterialSRVs = materialSrvs };
        }
 internal static void SetSrvs(MyRenderContext rc, ref MySrvTable desc)
 {
     if ((desc.BindFlag & MyBindFlag.BIND_VS) > 0)
     {
         for (int i = 0; i < desc.Srvs.Length; i++)
         {
             rc.VertexShader.SetRawSrv(desc.StartSlot + i, desc.Srvs[i]);
         }
     }
     if ((desc.BindFlag & MyBindFlag.BIND_PS) > 0)
     {
         for (int i = 0; i < desc.Srvs.Length; i++)
         {
             rc.PixelShader.SetRawSrv(desc.StartSlot + i, desc.Srvs[i]);
         }
     }
     MyRender11.ProcessDebugOutput();
 }
Esempio n. 7
0
        internal static MyMaterialProxy_2 CreateProxy(ref MyMeshMaterialInfo info)
        {
            var A = MyTextures.GetTexture(info.ColorMetal_Texture, info.ContentPath, MyTextureEnum.COLOR_METAL);
            var B = MyTextures.GetTexture(info.NormalGloss_Texture, info.ContentPath, MyTextureEnum.NORMALMAP_GLOSS);
            var C = MyTextures.GetTexture(info.Extensions_Texture, info.ContentPath, MyTextureEnum.EXTENSIONS);
            var D = MyTextures.GetTexture(info.Alphamask_Texture, info.ContentPath, MyTextureEnum.ALPHAMASK);

            var materialSrvs = new MySrvTable
            {
                BindFlag  = MyBindFlag.BIND_PS,
                StartSlot = 0,
                SRVs      = new IShaderResourceBindable[] { A, B, C, D },
                Version   = info.Id.GetHashCode()
            };

            return
                (new MyMaterialProxy_2 {
                MaterialSRVs = materialSrvs
            });
        }
        internal static MyMaterialProxy_2 CreateProxy(ref MyMeshMaterialInfo info)
        {
            MyFileTextureManager texManager = MyManagers.FileTextures;
            string contentPath = info.ContentPath;

            var A = texManager.GetTexture(GetFilepath(contentPath, info.ColorMetal_Texture.ToString()), MyFileTextureEnum.COLOR_METAL);
            var B = texManager.GetTexture(GetFilepath(contentPath, info.NormalGloss_Texture.ToString()), MyFileTextureEnum.NORMALMAP_GLOSS);
            var C = texManager.GetTexture(GetFilepath(contentPath, info.Extensions_Texture.ToString()), MyFileTextureEnum.EXTENSIONS);
            var D = texManager.GetTexture(GetFilepath(contentPath, info.Alphamask_Texture.ToString()), MyFileTextureEnum.ALPHAMASK);

            var materialSrvs = new MySrvTable
            {
                BindFlag  = MyBindFlag.BIND_PS,
                StartSlot = 0,
                Srvs      = new ShaderResourceView[] { A.Srv, B.Srv, C.Srv, D.Srv },
                Version   = info.Id.GetHashCode()
            };

            return
                (new MyMaterialProxy_2 {
                MaterialSrvs = materialSrvs
            });
        }
Esempio n. 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
                };
        }
Esempio n. 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 SetSRVs(ref MySrvTable desc)
        {
            //if (desc.BindFlag.HasFlag(MyBindFlag.BIND_VS))
            //{
            //    var val = new MyStageSrvBinding { Stage = MyShaderStage.VS, Slot = desc.StartSlot, Length = desc.SRVs.Length, Version = desc.Version };

            //    int f = State.m_srvBindings1.BinarySearch(val);
            //    var index = ~f;
            //    bool match = f >= 0; // if yes no need to bind
            //    bool collision = (index < State.m_srvBindings1.Count) && 
            //        State.m_srvBindings1[index].Stage == val.Stage &&
            //        (val.Slot + val.Length) >= State.m_srvBindings1[index].Slot; // if yes replace, if no add before, bind anyway

            //    if(!match && collision)
            //    {
            //        State.m_srvBindings1[index] = val;
            //        Context.VertexShader.SetShaderResources(desc.StartSlot, desc.SRVs);
            //    }
            //    else if(!match && !collision)
            //    {
            //        State.m_srvBindings1.Insert(index, val);
            //        Context.VertexShader.SetShaderResources(desc.StartSlot, desc.SRVs);
            //    }
            //}


            if ((desc.BindFlag & MyBindFlag.BIND_VS) > 0 &&
                State.m_srvTableBindings.Get(new MyStageSrvBinding { Stage = MyShaderStage.VS, Slot = desc.StartSlot }, NO_VERSION) != desc.Version)
            {
                State.m_srvTableBindings[new MyStageSrvBinding { Stage = MyShaderStage.VS, Slot = desc.StartSlot }] = desc.Version;
                Context.VertexShader.SetShaderResources(desc.StartSlot, desc.SRVs);
            }
            if ((desc.BindFlag & MyBindFlag.BIND_PS) > 0 &&
                State.m_srvTableBindings.Get(new MyStageSrvBinding { Stage = MyShaderStage.PS, Slot = desc.StartSlot }, NO_VERSION) != desc.Version)
            {
                State.m_srvTableBindings[new MyStageSrvBinding { Stage = MyShaderStage.PS, Slot = desc.StartSlot }] = desc.Version;
                Context.PixelShader.SetShaderResources(desc.StartSlot, desc.SRVs);
            }
        }
Esempio n. 12
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
            });
        }
Esempio n. 13
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
                };
        }
Esempio n. 14
0
        internal static MyMaterialProxy_2 CreateProxy(ref MyMeshMaterialInfo info)
        {
            MyFileTextureManager texManager = MyManagers.FileTextures;
            string contentPath = info.ContentPath;

            var A = texManager.GetTexture(GetFilepath(contentPath, info.ColorMetal_Texture.ToString()), MyFileTextureEnum.COLOR_METAL);
            var B = texManager.GetTexture(GetFilepath(contentPath, info.NormalGloss_Texture.ToString()), MyFileTextureEnum.NORMALMAP_GLOSS);
            var C = texManager.GetTexture(GetFilepath(contentPath, info.Extensions_Texture.ToString()), MyFileTextureEnum.EXTENSIONS);
            var D = texManager.GetTexture(GetFilepath(contentPath, info.Alphamask_Texture.ToString()), MyFileTextureEnum.ALPHAMASK);

			var materialSrvs = new MySrvTable
					{ 
                        BindFlag = MyBindFlag.BIND_PS, 
                        StartSlot = 0,
                        Srvs = new ShaderResourceView[] { A.Srv, B.Srv, C.Srv, D.Srv },
                        Version = info.Id.GetHashCode()
                    };
            return
				new MyMaterialProxy_2 { MaterialSrvs = materialSrvs };
        }