Hello eveyone,
I’m having trouble getting a lit shader to work on my generated mesh.
The mesh appears completely black when using a URP/Lit material, but works fine with URP/Unlit materials.
Here are the components i add:
ecb.AddComponent<LocalToWorld>(entity);
ecb.AddComponent<WorldRenderBounds>(entity);
ecb.AddComponent<MaterialMeshInfo>(entity);
// enable later
ecb.SetComponentEnabled<MaterialMeshInfo>(entity, false);
ecb.AddComponent<RenderBounds>(entity);
ecb.AddComponent<PerInstanceCullingTag>(entity);
ecb.SetSharedComponent(entity, terrainChunkInfoSingleton.FilterSettings);
Later i have systems that calulate vertices, normals, and indices
and then in my Mesh instancing system i have a setup like this:
Mesh mesh = new Mesh();
VertexAttributeDescriptor[] layout = new[] {
new VertexAttributeDescriptor(VertexAttribute.Position, VertexAttributeFormat.Float32, 3, 0),
new VertexAttributeDescriptor(VertexAttribute.Normal, VertexAttributeFormat.Float32, 3, 1),
};
mesh.SetVertexBufferParams(vertices.Length, layout);
mesh.SetIndexBufferParams(indices.Length, IndexFormat.UInt32);
NativeArray<float3> vertexArray = vertices.Reinterpret<float3>().AsNativeArray();
NativeArray<float3> normalArray = normals.Reinterpret<float3>().AsNativeArray();
NativeArray<int> indexArray = indices.Reinterpret<int>().AsNativeArray();
mesh.SetVertexBufferData(vertexArray, 0, 0, vertices.Length, 0, MeshUpdateFlags.DontValidateIndices);
mesh.SetVertexBufferData(normalArray, 0, 0, normals.Length, 1, MeshUpdateFlags.DontValidateIndices);
mesh.SetIndexBufferData(indexArray, 0, 0, indices.Length, MeshUpdateFlags.DontValidateIndices);
mesh.subMeshCount = 1;
mesh.SetSubMesh(0, new SubMeshDescriptor(0, indices.Length));
//TODO: calc bounds differently
mesh.RecalculateBounds();
BatchMeshID meshID = graphicsSystem.RegisterMesh(mesh);
if (meshMapping.TryGetValue(entity, out BatchMeshID value)) {
graphicsSystem.UnregisterMesh(value);
}
meshMapping[entity] = meshID;
SystemAPI.SetComponent(entity, new MaterialMeshInfo {
MeshID = meshID,
MaterialID = new BatchMaterialID(){value = materialID.ValueRO.Value}
});
SystemAPI.SetComponentEnabled<MaterialMeshInfo>(entity, true);
SystemAPI.SetComponent(entity, new RenderBounds {
Value = mesh.bounds.ToAABB()
});
material is correctly registered in a baker earlier. I checked my Normals, Indices and Verts, all seem fine.
There is a cube in the scene with the same lit material that works.
Here a screen of what it looks like, I’m drawing the tris and normals with debug.
What could I be missing?