void FLandscapeVertexFactoryMobile::InitRHI() { // list of declaration items FVertexDeclarationElementList Elements; // position decls Elements.Add(AccessStreamComponent(MobileData.PositionComponent,0)); if (MobileData.LODHeightsComponent.Num()) { const int32 BaseAttribute = 1; for(int32 Index = 0;Index < MobileData.LODHeightsComponent.Num();Index++) { Elements.Add(AccessStreamComponent(MobileData.LODHeightsComponent[Index], BaseAttribute + Index)); } } // create the actual device decls InitDeclaration(Elements); }
void FMeshParticleVertexFactory::InitRHI() { FVertexDeclarationElementList Elements; const bool bInstanced = GetFeatureLevel() >= ERHIFeatureLevel::SM4; if (Data.bInitialized) { if(bInstanced) { // Stream 0 - Instance data { checkf(DynamicVertexStride != -1, TEXT("FMeshParticleVertexFactory does not have a valid DynamicVertexStride - likely an empty one was made, but SetStrides was not called")); FVertexStream VertexStream; VertexStream.VertexBuffer = NULL; VertexStream.Stride = 0; VertexStream.Offset = 0; Streams.Add(VertexStream); // @todo metal: this will need a valid stride when we get to instanced meshes! Elements.Add(FVertexElement(0, Data.TransformComponent[0].Offset, Data.TransformComponent[0].Type, 8, DynamicVertexStride, Data.TransformComponent[0].bUseInstanceIndex)); Elements.Add(FVertexElement(0, Data.TransformComponent[1].Offset, Data.TransformComponent[1].Type, 9, DynamicVertexStride, Data.TransformComponent[1].bUseInstanceIndex)); Elements.Add(FVertexElement(0, Data.TransformComponent[2].Offset, Data.TransformComponent[2].Type, 10, DynamicVertexStride, Data.TransformComponent[2].bUseInstanceIndex)); Elements.Add(FVertexElement(0, Data.SubUVs.Offset, Data.SubUVs.Type, 11, DynamicVertexStride, Data.SubUVs.bUseInstanceIndex)); Elements.Add(FVertexElement(0, Data.SubUVLerpAndRelTime.Offset, Data.SubUVLerpAndRelTime.Type, 12, DynamicVertexStride, Data.SubUVLerpAndRelTime.bUseInstanceIndex)); Elements.Add(FVertexElement(0, Data.ParticleColorComponent.Offset, Data.ParticleColorComponent.Type, 14, DynamicVertexStride, Data.ParticleColorComponent.bUseInstanceIndex)); Elements.Add(FVertexElement(0, Data.VelocityComponent.Offset, Data.VelocityComponent.Type, 15, DynamicVertexStride, Data.VelocityComponent.bUseInstanceIndex)); } // Stream 1 - Dynamic parameter { checkf(DynamicParameterVertexStride != -1, TEXT("FMeshParticleVertexFactory does not have a valid DynamicParameterVertexStride - likely an empty one was made, but SetStrides was not called")); FVertexStream VertexStream; VertexStream.VertexBuffer = NULL; VertexStream.Stride = 0; VertexStream.Offset = 0; Streams.Add(VertexStream); Elements.Add(FVertexElement(1, 0, VET_Float4, 13, DynamicParameterVertexStride, true)); } } if(Data.PositionComponent.VertexBuffer != NULL) { Elements.Add(AccessStreamComponent(Data.PositionComponent,0)); } // only tangent,normal are used by the stream. the binormal is derived in the shader uint8 TangentBasisAttributes[2] = { 1, 2 }; for(int32 AxisIndex = 0;AxisIndex < 2;AxisIndex++) { if(Data.TangentBasisComponents[AxisIndex].VertexBuffer != NULL) { Elements.Add(AccessStreamComponent(Data.TangentBasisComponents[AxisIndex],TangentBasisAttributes[AxisIndex])); } } // Vertex color if(Data.VertexColorComponent.VertexBuffer != NULL) { Elements.Add(AccessStreamComponent(Data.VertexColorComponent,3)); } else { //If the mesh has no color component, set the null color buffer on a new stream with a stride of 0. //This wastes 4 bytes of bandwidth per vertex, but prevents having to compile out twice the number of vertex factories. FVertexStreamComponent NullColorComponent(&GNullColorVertexBuffer, 0, 0, VET_Color); Elements.Add(AccessStreamComponent(NullColorComponent,3)); } if(Data.TextureCoordinates.Num()) { const int32 BaseTexCoordAttribute = 4; for(int32 CoordinateIndex = 0;CoordinateIndex < Data.TextureCoordinates.Num();CoordinateIndex++) { Elements.Add(AccessStreamComponent( Data.TextureCoordinates[CoordinateIndex], BaseTexCoordAttribute + CoordinateIndex )); } for(int32 CoordinateIndex = Data.TextureCoordinates.Num();CoordinateIndex < MAX_TEXCOORDS;CoordinateIndex++) { Elements.Add(AccessStreamComponent( Data.TextureCoordinates[Data.TextureCoordinates.Num() - 1], BaseTexCoordAttribute + CoordinateIndex )); } } if(Streams.Num() > 0) { InitDeclaration(Elements,Data); check(IsValidRef(GetDeclaration())); } } }
void TGPUSkinVertexFactory<bExtraBoneInfluencesT>::AddVertexElements(DataType& InData, FVertexDeclarationElementList& OutElements) { // position decls OutElements.Add(AccessStreamComponent(InData.PositionComponent,0)); // tangent basis vector decls OutElements.Add(AccessStreamComponent(InData.TangentBasisComponents[0],1)); OutElements.Add(AccessStreamComponent(InData.TangentBasisComponents[1],2)); // texture coordinate decls if(InData.TextureCoordinates.Num()) { const uint8 BaseTexCoordAttribute = 5; for(int32 CoordinateIndex = 0;CoordinateIndex < InData.TextureCoordinates.Num();CoordinateIndex++) { OutElements.Add(AccessStreamComponent( InData.TextureCoordinates[CoordinateIndex], BaseTexCoordAttribute + CoordinateIndex )); } for(int32 CoordinateIndex = InData.TextureCoordinates.Num();CoordinateIndex < MAX_TEXCOORDS;CoordinateIndex++) { OutElements.Add(AccessStreamComponent( InData.TextureCoordinates[InData.TextureCoordinates.Num() - 1], BaseTexCoordAttribute + CoordinateIndex )); } } // Account for the possibility that the mesh has no vertex colors if( InData.ColorComponent.VertexBuffer ) { OutElements.Add(AccessStreamComponent(InData.ColorComponent, 13)); } else { //If the mesh has no color component, set the null color buffer on a new stream with a stride of 0. //This wastes 4 bytes of bandwidth per vertex, but prevents having to compile out twice the number of vertex factories. FVertexStreamComponent NullColorComponent(&GNullColorVertexBuffer, 0, 0, VET_Color); OutElements.Add(AccessStreamComponent(NullColorComponent,13)); } // bone indices decls OutElements.Add(AccessStreamComponent(InData.BoneIndices,3)); // bone weights decls OutElements.Add(AccessStreamComponent(InData.BoneWeights,4)); if (bExtraBoneInfluencesT) { // Extra bone indices & weights decls OutElements.Add(AccessStreamComponent(InData.ExtraBoneIndices, 14)); OutElements.Add(AccessStreamComponent(InData.ExtraBoneWeights, 15)); } }