예제 #1
0
        internal static void DrawAtmosphereInscatter(uint ID)
        {
            var texR = MyAtmosphereRenderer.AtmosphereLUT[ID].InscatterLut;


            RC.Context.PixelShader.Set(m_blitTexture3DShader);
            RC.Context.PixelShader.SetShaderResource(0, texR.ShaderView);

            var cb = MyCommon.GetMaterialCB(sizeof(uint));

            RC.Context.PixelShader.SetConstantBuffer(5, cb);

            for (int i = 0; i < 16; ++i)
            {
                var mapping = MyMapping.MapDiscard(cb);
                mapping.stream.Write(((float)2 * i + 0.5f / 32.0f) / (float)32);
                mapping.Unmap();

                DrawQuad(0, 32 * i, 128, 32);

                mapping = MyMapping.MapDiscard(cb);
                mapping.stream.Write(((float)2 * i + 1 + 0.5f / 32.0f) / (float)32);
                mapping.Unmap();

                DrawQuad(128, 32 * i, 128, 32);
            }

            RC.Context.PixelShader.SetShaderResource(0, null);
        }
예제 #2
0
        internal static void DrawCascades()
        {
            RC.Context.PixelShader.Set(m_blitTextureArrayShader);
            RC.Context.PixelShader.SetShaderResource(0, MyShadows.m_cascadeShadowmapArray.ShaderView);

            var cb = MyCommon.GetMaterialCB(sizeof(uint));

            RC.Context.PixelShader.SetConstantBuffer(5, cb);

            for (uint i = 0; i < 4; i++)
            {
                var mapping = MyMapping.MapDiscard(cb);
                mapping.stream.Write((float)i);
                mapping.Unmap();
                DrawQuad(0, 256 * i, 410, 256);
            }
            RC.Context.PixelShader.SetShaderResource(0, null);
        }
예제 #3
0
        private static void DrawCascadeArray(RwTexId textureArray, int quadStartX, int quadStartY, int quadSize)
        {
            RC.DeviceContext.PixelShader.Set(m_blitTextureArrayShader);
            RC.DeviceContext.PixelShader.SetShaderResource(0, textureArray.ShaderView);

            var cb = MyCommon.GetMaterialCB(sizeof(uint));

            RC.DeviceContext.PixelShader.SetConstantBuffer(5, cb);

            for (uint cascadeIndex = 0; cascadeIndex < MyRender11.Settings.ShadowCascadeCount; cascadeIndex++)
            {
                float index   = (float)cascadeIndex;
                var   mapping = MyMapping.MapDiscard(cb);
                mapping.WriteAndPosition(ref index);
                mapping.Unmap();
                DrawQuad(quadStartX + (quadSize + quadStartX / 2) * cascadeIndex, quadStartY, quadSize, quadSize * MyRender11.ViewportResolution.Y / MyRender11.ViewportResolution.X);
            }
            RC.DeviceContext.PixelShader.SetShaderResource(0, null);
        }
        private static void DrawSrvArrayTexture(ISrvBindable textureArray, int texCount, int quadStartX, int quadStartY, int quadSize)
        {
            RC.PixelShader.Set(m_blitTextureArrayShader);
            RC.PixelShader.SetSrv(0, textureArray);

            var cb = MyCommon.GetMaterialCB(sizeof(uint));

            RC.PixelShader.SetConstantBuffer(5, cb);

            for (uint cascadeIndex = 0; cascadeIndex < texCount; cascadeIndex++)
            {
                float index   = (float)cascadeIndex;
                var   mapping = MyMapping.MapDiscard(cb);
                mapping.WriteAndPosition(ref index);
                mapping.Unmap();
                DrawQuad(quadStartX + (quadSize + quadStartX / 2) * cascadeIndex, quadStartY, quadSize, quadSize * MyRender11.ViewportResolution.Y / MyRender11.ViewportResolution.X);
            }
            RC.PixelShader.SetSrv(0, null);
        }
예제 #5
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,
                    }
                    )
                }
            });
        }
예제 #6
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
                    }
                    )
                }
            });
        }
예제 #7
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
            });
        }