Ejemplo n.º 1
0
        void FillStreamWithTerrainBatch(int materialId,
                                        int vertexMaterialIndex, int indexCount, int startIndex, int baseVertex)
        {
            MyGPUFoliageGenerating implementation = MyGPUFoliageGenerating.GetInstance();

            // all necessary data should be same - geometry and input layout
            var renderable = m_owner.GetRenderable();
            var proxy      = renderable.m_lods[0].RenderableProxies[0];

            // get shader for streaming

            var bundle = MyMaterialShaders.Get(X.TEXT(MyVoxelMesh.MULTI_MATERIAL_TAG), X.TEXT("foliage_streaming"), MyMeshes.VoxelLayout, MyShaderUnifiedFlags.NONE);

            //var bundle = MyShaderBundleFactory.Get(renderable.GetMesh().LODs[0].m_meshInfo.VertexLayout, MyVoxelMesh.MULTI_MATERIAL_TAG,
            //    "foliage_streaming", renderable.m_vsFlags | MyShaderUnifiedFlags.NONE);

            //var scaleMat = Matrix.CreateScale(renderable.m_voxelScale);
            //proxy.ObjectData.LocalMatrix = scaleMat;

            //var worldMat = proxy.WorldMatrix;
            //worldMat.Translation -= MyEnvironment.CameraPosition;
            //proxy.ObjectData.LocalMatrix = worldMat;

            implementation.RecordCommands(proxy, m_streams[materialId], materialId,
                                          bundle.VS, bundle.IL,
                                          vertexMaterialIndex, indexCount, startIndex, baseVertex);
        }
Ejemplo n.º 2
0
        internal void BuildProxy(out MyRenderableProxy_2 proxy, out UInt64 key)
        {
            proxy = new MyRenderableProxy_2
            {
                MaterialType = MyMaterialType.OPAQUE,

                ObjectConstants = new MyConstantsPack {
                },

                ObjectSRVs = new MySrvTable {
                    StartSlot = MyCommon.INSTANCE_INDIRECTION, SRVs = m_mergeGroup.m_SRVs, BindFlag = MyBindFlag.BIND_VS, Version = this.GetHashCode()
                },
                VertexData = new MyVertexDataProxy_2 {
                },

                DepthShaders   = MyMaterialShaders.Get(X.TEXT("standard"), X.TEXT(MyGeometryRenderer.DEFAULT_DEPTH_PASS), MyVertexLayouts.Empty, MyShaderUnifiedFlags.USE_MERGE_INSTANCING | MyShaderUnifiedFlags.DEPTH_ONLY),
                Shaders        = MyMaterialShaders.Get(X.TEXT("standard"), X.TEXT(MyGeometryRenderer.DEFAULT_OPAQUE_PASS), MyVertexLayouts.Empty, MyShaderUnifiedFlags.USE_MERGE_INSTANCING),
                ForwardShaders = MyMaterialShaders.Get(X.TEXT("standard"), X.TEXT(MyGeometryRenderer.DEFAULT_FORWARD_PASS), MyVertexLayouts.Empty, MyShaderUnifiedFlags.USE_MERGE_INSTANCING | MyShaderUnifiedFlags.USE_SHADOW_CASCADES),

                RenderFlags = MyRenderableProxyFlags.DepthSkipTextures,

                Submeshes = new MyDrawSubmesh_2[] { new MyDrawSubmesh_2 {
                                                        DrawCommand = MyDrawCommandEnum.Draw, Count = m_mergeGroup.VerticesNum, MaterialId = MyMeshMaterials1.GetProxyId(MyMeshMaterials1.MaterialRkIndex.Get(m_rootMaterialRK, MyMeshMaterialId.NULL))
                                                    } },
                SubmeshesDepthOnly = new MyDrawSubmesh_2[] { new MyDrawSubmesh_2 {
                                                                 DrawCommand = MyDrawCommandEnum.Draw, Count = m_mergeGroup.VerticesNum, MaterialId = MyMeshMaterials1.GetProxyId(MyMeshMaterials1.MaterialRkIndex.Get(m_rootMaterialRK, MyMeshMaterialId.NULL))
                                                             } },

                InstanceCount = 0,
                StartInstance = 0,
            };

            key = 0;
        }
Ejemplo n.º 3
0
        private static MyMergeInstancingShaderBundle GetMergeInstancing(MyStringId pass, MyShaderUnifiedFlags flags = MyShaderUnifiedFlags.NONE)
        {
            MyMergeInstancingShaderBundle ret = new MyMergeInstancingShaderBundle();

            flags |= MyShaderUnifiedFlags.USE_MERGE_INSTANCING;

            ret.MultiInstance  = MyMaterialShaders.Get(STANDARD_MATERIAL, pass, MyVertexLayouts.Empty, flags, MyFileTextureEnum.UNSPECIFIED);
            ret.SingleInstance = MyMaterialShaders.Get(STANDARD_MATERIAL, pass, MyVertexLayouts.Empty, flags | MyShaderUnifiedFlags.USE_SINGLE_INSTANCE, MyFileTextureEnum.UNSPECIFIED);
            return(ret);
        }
Ejemplo n.º 4
0
        private static MyMergeInstancingShaderBundle GetMergeInstancing(string pass, MyShaderUnifiedFlags flags = MyShaderUnifiedFlags.NONE)
        {
            MyMergeInstancingShaderBundle ret = new MyMergeInstancingShaderBundle();

            flags |= MyShaderUnifiedFlags.USE_MERGE_INSTANCING;

            var passId = MyStringId.GetOrCompute(pass);

            ret.MultiInstance  = MyMaterialShaders.Get(STANDARD_MATERIAL, passId, MyVertexLayouts.Empty, flags);
            ret.SingleInstance = MyMaterialShaders.Get(STANDARD_MATERIAL, passId, MyVertexLayouts.Empty, flags | MyShaderUnifiedFlags.USE_SINGLE_INSTANCE);
            return(ret);
        }
Ejemplo n.º 5
0
        void FillStreamWithTerrainBatch(int materialId,
                                        int vertexMaterialIndex, int indexCount, int startIndex, int baseVertex)
        {
            // all necessary data should be same - geometry and input layout
            var renderable = Owner.GetRenderable();
            var proxy      = renderable.Lods[0].RenderableProxies[0];

            // get shader for streaming

            var bundle = MyMaterialShaders.Get(MyStringId.GetOrCompute(MyVoxelMesh.MULTI_MATERIAL_TAG), MyStringId.GetOrCompute("foliage_streaming"), MyMeshes.VoxelLayout, renderable.Lods[0].VertexShaderFlags & ~MyShaderUnifiedFlags.USE_VOXEL_MORPHING);

            MyRender11.FoliageGenerator.RecordCommands(proxy, m_streams[materialId], materialId,
                                                       bundle.VS, bundle.IL,
                                                       vertexMaterialIndex, indexCount, startIndex, baseVertex);
        }
Ejemplo n.º 6
0
        void FillStreamWithTerrainBatch(int materialId,
                                        int vertexMaterialIndex, int indexCount, int startIndex, int baseVertex)
        {
            // all necessary data should be same - geometry and input layout
            var renderable = Owner.GetRenderable();
            var proxy      = renderable.Lods[0].RenderableProxies[0];

            // get shader for streaming
            MyFileTextureEnum textureTypes = proxy.Material == MyMeshMaterialId.NULL ? MyFileTextureEnum.UNSPECIFIED : proxy.Material.Info.TextureTypes;
            var bundle = MyMaterialShaders.Get(MyMaterialShaders.MULTI_MATERIAL_TAG,
                                               MyMaterialShaders.FOLIAGE_STREAMING_PASS_ID, MyMeshes.VoxelLayout,
                                               renderable.Lods[0].VertexShaderFlags & ~MyShaderUnifiedFlags.USE_VOXEL_MORPHING, textureTypes);

            MyRender11.FoliageGenerator.RecordCommands(proxy, m_streams[materialId], materialId,
                                                       bundle.VS, bundle.IL,
                                                       vertexMaterialIndex, indexCount, startIndex, baseVertex);
        }
        private void CreateRenderableProxyForPart(MyRenderLod lod, int objectConstantsSize, int proxyIndex, int partIndex, bool shadowsOnly)
        {
            var partId    = MyMeshes.GetVoxelPart(Mesh, partIndex);
            var technique = partId.Info.MaterialTriple.IsMultimaterial() ? MyVoxelMesh.MULTI_MATERIAL_TAG : MyVoxelMesh.SINGLE_MATERIAL_TAG;

            if (shadowsOnly)
            {
                technique = MyVoxelMesh.SINGLE_MATERIAL_TAG;
            }

            lod.RenderableProxies[proxyIndex].WorldMatrix = Owner.WorldMatrix;
            //lod.RenderableProxies[p].ObjectData.LocalMatrix = m_owner.WorldMatrix;

            lod.RenderableProxies[proxyIndex].NonVoxelObjectData = MyObjectDataNonVoxel.Invalid;
            lod.RenderableProxies[proxyIndex].VoxelCommonObjectData.VoxelOffset         = m_voxelOffset;
            lod.RenderableProxies[proxyIndex].VoxelCommonObjectData.MassiveCenterRadius = Vector4.Zero; // Set in UpdateLodState
            lod.RenderableProxies[proxyIndex].VoxelCommonObjectData.VoxelScale          = m_voxelScale;


            AssignLodMeshToProxy(Mesh, lod.RenderableProxies[proxyIndex]);
            lod.RenderableProxies[proxyIndex].DepthShaders = MyMaterialShaders.Get(
                X.TEXT(MapTechniqueToShaderMaterial(technique)),
                X.TEXT(MyGeometryRenderer.DEFAULT_DEPTH_PASS),
                lod.VertexLayout1,
                lod.VertexShaderFlags | MyShaderUnifiedFlags.DEPTH_ONLY | MapTechniqueToShaderMaterialFlags(technique) | MyShaderUnifiedFlags.DITHERED);
            lod.RenderableProxies[proxyIndex].Shaders = MyMaterialShaders.Get(
                X.TEXT(MapTechniqueToShaderMaterial(technique)),
                X.TEXT(MyGeometryRenderer.DEFAULT_OPAQUE_PASS),
                lod.VertexLayout1,
                lod.VertexShaderFlags | MapTechniqueToShaderMaterialFlags(technique) | MyShaderUnifiedFlags.DITHERED);
            lod.RenderableProxies[proxyIndex].ForwardShaders = MyMaterialShaders.Get(
                X.TEXT(MapTechniqueToShaderMaterial(technique)),
                X.TEXT(MyGeometryRenderer.DEFAULT_FORWARD_PASS),
                lod.VertexLayout1,
                lod.VertexShaderFlags | MapTechniqueToShaderMaterialFlags(technique) | MyShaderUnifiedFlags.DITHERED);

            var partInfo = partId.Info;

            MyDrawSubmesh drawSubmesh;

            if (shadowsOnly)
            {
                MyMeshBuffers buffers;
                if (MyMeshes.IsMergedVoxelMesh(Mesh))
                {
                    buffers = MyMeshes.GetMergedLodMesh(Mesh, 0).Buffers;
                }
                else
                {
                    buffers = MyMeshes.GetLodMesh(Mesh, 0).Buffers;
                }

                drawSubmesh = new MyDrawSubmesh
                {
                    BaseVertex   = 0,
                    StartIndex   = 0,
                    IndexCount   = buffers.IB.Capacity,
                    BonesMapping = null,
                    MaterialId   = MyVoxelMaterials1.GetMaterialProxyId(partId.Info.MaterialTriple),
                    Flags        = MyDrawSubmesh.MySubmeshFlags.Depth
                };
            }
            else
            {
                drawSubmesh = new MyDrawSubmesh
                {
                    BaseVertex   = partInfo.BaseVertex,
                    StartIndex   = partInfo.StartIndex,
                    IndexCount   = partInfo.IndexCount,
                    BonesMapping = null,
                    MaterialId   = MyVoxelMaterials1.GetMaterialProxyId(partId.Info.MaterialTriple),
                    Flags        = MyDrawSubmesh.MySubmeshFlags.Gbuffer | MyDrawSubmesh.MySubmeshFlags.Forward
                };
            }

            lod.RenderableProxies[proxyIndex].DrawSubmesh      = drawSubmesh;
            lod.RenderableProxies[proxyIndex].SkinningMatrices = null;

            lod.RenderableProxies[proxyIndex].ObjectBuffer  = MyCommon.GetObjectCB(objectConstantsSize);
            lod.RenderableProxies[proxyIndex].InstanceCount = m_instanceCount;
            lod.RenderableProxies[proxyIndex].StartInstance = m_startInstance;
            lod.RenderableProxies[proxyIndex].Flags         = MapTechniqueToRenderableFlags(technique) | m_additionalFlags;
            lod.RenderableProxies[proxyIndex].Type          = MapTechniqueToMaterialType(technique);
            lod.RenderableProxies[proxyIndex].Parent        = this;
            lod.RenderableProxies[proxyIndex].Lod           = 0;
            lod.RenderableProxies[proxyIndex].Instancing    = m_instancing;

            AnyDrawOutsideViewDistance |= lod.RenderableProxies[proxyIndex].Flags.HasFlags(MyRenderableProxyFlags.DrawOutsideViewDistance);

            ulong sortingKey = 0;

            My64BitValueHelper.SetBits(ref sortingKey, 36, 2, (ulong)lod.RenderableProxies[proxyIndex].Type);
            My64BitValueHelper.SetBits(ref sortingKey, 32, 4, (ulong)drawSubmesh.MaterialId.Index);
            My64BitValueHelper.SetBits(ref sortingKey, 26, 6, (ulong)MyShaderMaterial.GetID(MapTechniqueToShaderMaterial(technique)));
            My64BitValueHelper.SetBits(ref sortingKey, 22, 4, (ulong)m_voxelLod);
            My64BitValueHelper.SetBits(ref sortingKey, 16, 6, (ulong)lod.VertexShaderFlags);
            //My64BitValueHelper.SetBits(ref sortingKey, 14, 6, (ulong)lod.VertexLayout1.Index);
            //My64BitValueHelper.SetBits(ref sortingKey, 0, 14, (ulong)m_owner.ID);

            lod.SortingKeys[proxyIndex] = sortingKey;
        }