Hi all,
I have an issue with the color generation of my meshes which I used vertex color to generate (I have used shader graph with connected node from vertex to frag color and it has worked with the normal mesh gen). I have debugged each vertex color (in the step of assigning to the vertex data) and there are numerous colours available – all with varying quantity ofc – but the output sphere (attached) seemd to just use an average of all the colors rather than each vertex having its own color? I am not exactly sure what is the problem here or is that the way it should be? (Pls excuse me if this is not the supposed format for topic or how I attach stuff as I have never used this before)
The code that is responsible for mesh setup (which I speculate to be the issue) cannot be attached as I am a new user, and I don’t know what the supposed format is, so I put in in the preformatted text option, would be grateful if anyone would let me know. Thanks a lot in advanced.
using UnityEngine;
using Unity.Mathematics;
using System.Collections.Generic;
using Unity.Collections;
using UnityEngine.Rendering;
using System.Runtime.InteropServices;
using Unity.Collections.LowLevel.Unsafe;
public struct AdvancedMeshGenSetup
{
[NativeDisableContainerSafetyRestriction]
private NativeArray<Vertex> vertices;
[NativeDisableContainerSafetyRestriction]
private NativeArray<TriangleUInt16> triangles;
public void Setup(Mesh.MeshData meshData, int vertexCount, int indexCount)
{
NativeArray<VertexAttributeDescriptor> meshDataDescriptor = new NativeArray<VertexAttributeDescriptor>(2, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
meshDataDescriptor[0] = new VertexAttributeDescriptor(VertexAttribute.Position, dimension: 3);
//meshDataDescriptor[1] = new VertexAttributeDescriptor(VertexAttribute.Normal, dimension: 3);
//meshDataDescriptor[2] = new VertexAttributeDescriptor(VertexAttribute.Tangent, dimension: 4);
meshDataDescriptor[1] = new VertexAttributeDescriptor(VertexAttribute.Color, dimension: 1);
meshData.SetVertexBufferParams(vertexCount, meshDataDescriptor);
meshDataDescriptor.Dispose();
meshData.SetIndexBufferParams(indexCount, IndexFormat.UInt16);
meshData.subMeshCount = 1;
meshData.SetSubMesh(0, new SubMeshDescriptor(0, indexCount)
{
vertexCount = vertexCount
},
MeshUpdateFlags.DontRecalculateBounds | MeshUpdateFlags.DontValidateIndices);
vertices = meshData.GetVertexData<Vertex>();
triangles = meshData.GetIndexData<ushort>().Reinterpret<TriangleUInt16>(2);
}
public void SetVertex(int index, Vertex vertex)
{
vertices[index] = new Vertex
{
position = vertex.position,
//normal = vertex.normal,
//tangent = vertex.tangent,
color = vertex.color
};
Debug.Log($"vertex color: {vertices[index].color}");
}
public void SetTriangle(int index, int3 triangle)
{
triangles[index] = triangle;
}
}