static unsafe IConstantBuffer GetObjectCB(MyRenderContext RC, MyInstanceComponent instance, float stateData) { Vector4 col0, col1, col2; instance.GetMatrixCols(0, out col0, out col1, out col2); Matrix matrix = Matrix.Identity; matrix.SetRow(0, col0); matrix.SetRow(1, col1); matrix.SetRow(2, col2); matrix = Matrix.Transpose(matrix); int cbSize = sizeof(MyObjectDataCommon); cbSize += sizeof(MyObjectDataNonVoxel); IConstantBuffer cb = MyCommon.GetObjectCB(cbSize); var mapping = MyMapping.MapDiscard(RC, cb); MyObjectDataNonVoxel nonVoxelData = new MyObjectDataNonVoxel(); mapping.WriteAndPosition(ref nonVoxelData); MyObjectDataCommon commonData = new MyObjectDataCommon(); commonData.LocalMatrix = matrix; commonData.ColorMul = Vector3.One; commonData.KeyColor = new Vector3(0, -1f, 0f); commonData.CustomAlpha = stateData; mapping.WriteAndPosition(ref commonData); mapping.Unmap(); return(cb); }
void IDrawableGroupStrategy.Fill(int bufferOffset, MyInstanceComponent instance, MyLod lod, int multiTransformI, int instanceMaterialOffsetInData, MyInstanceLodState state, float stateData) { MyVbConstantElement element = new MyVbConstantElement { //WorldMatrixRow0 = new Vector4(matrix.M11, matrix.M12, matrix.M13, matrix.M14), //WorldMatrixRow1 = new Vector4(matrix.M21, matrix.M22, matrix.M23, matrix.M24), //WorldMatrixRow2 = new Vector4(matrix.M31, matrix.M32, matrix.M33, matrix.M34), }; //Much faster approach than naive: instance.GetMatrixCols(multiTransformI, out element.WorldMatrixRow0, out element.WorldMatrixRow1, out element.WorldMatrixRow2); m_vbData[bufferOffset] = element; m_validElements++; }
void IDrawableGroupStrategy.Fill(int bufferOffset, MyInstanceComponent instance, MyLod lod, int multiTransformI, int instanceMaterialOffsetInData, MyInstanceLodState state, float stateData) { HalfVector4 packedColorMultEmissivity = MyInstanceMaterial.Default.PackedColorMultEmissivity; if (instanceMaterialOffsetInData != -1) // if instance material is defined { MyInstanceMaterial instanceMaterial = instance.GetInstanceMaterial(instanceMaterialOffsetInData); packedColorMultEmissivity = instanceMaterial.PackedColorMultEmissivity; } else { packedColorMultEmissivity = instance.GlobalColorMultEmissivity; } HalfVector4 packedKeyColorDithering = instance.KeyColor.ToHalfVector4(); HalfVector4 dithering = new HalfVector4(); dithering.PackedValue = (ulong)HalfUtils.Pack(stateData); packedKeyColorDithering.PackedValue = packedKeyColorDithering.PackedValue | dithering.PackedValue << 48; MyVbConstantElement element = new MyVbConstantElement { //WorldMatrixRow0 = new Vector4(matrix.M11, matrix.M12, matrix.M13, matrix.M14), //WorldMatrixRow1 = new Vector4(matrix.M21, matrix.M22, matrix.M23, matrix.M24), //WorldMatrixRow2 = new Vector4(matrix.M31, matrix.M32, matrix.M33, matrix.M34), KeyColorDithering = packedKeyColorDithering, ColorMultEmissivity = packedColorMultEmissivity, }; // much faster approach than naive: instance.GetMatrixCols(multiTransformI, out element.WorldMatrixRow0, out element.WorldMatrixRow1, out element.WorldMatrixRow2); m_vbData[bufferOffset] = element; m_validElements++; }