Sphere created by ShapeMeshes3D::solidSphere has a black area?


I want to create spheres using ShapeMeshes3D::solidSphere. My code:

HMesh CreateSphere(float radius) {
    SPtr<VertexDataDesc> vertexDesc = bs_shared_ptr_new<VertexDataDesc>();
    vertexDesc->addVertElem(VET_FLOAT3, VES_POSITION);
    vertexDesc->addVertElem(VET_FLOAT2, VES_TEXCOORD);
    vertexDesc->addVertElem(VET_FLOAT3, VES_NORMAL);
    vertexDesc->addVertElem(VET_FLOAT4, VES_TANGENT);

    UINT32 numVertices = 0;
    UINT32 numIndices = 0;
    ShapeMeshes3D::getNumElementsSphere(3, numVertices, numIndices);
    SPtr<MeshData> meshData = bs_shared_ptr_new<MeshData>(numVertices, numIndices, vertexDesc);

    Sphere localSphere(Vector3::ZERO, radius);
    ShapeMeshes3D::solidSphere(localSphere, meshData, 0, 0, 3);

    return Mesh::create(meshData);

I replaced the sphere creation in the Physics example:

// HMesh sphereMesh = gBuiltinResources().getMesh(BuiltinMesh::Sphere);
HMesh sphereMesh = CreateSphere(1.0);

But my sphere has a black area that does not look right:

I didn’t change anything except for the sphere creation.
What’s wrong with my code? Thank you very much!


Try passing your MeshData through RendererMeshData::convert, by changing the last line like so:

return Mesh::create(RendererMeshData::convert(meshData));

Renderer expects normals & tangents to be encoded in a 32-bit format, but the default output from ShapeMeshes3D is a more precise floating point format, which is likely causing the shading issue.


Solved! Thank you very much!