Update
I’have recreated this bug in a new clean project.
2020.31f1

I spawn one simple Entity with a RenderMesh:
using Unity.Entities;
using Unity.Mathematics;
using Unity.Rendering;
using Unity.Transforms;
using UnityEngine;
public class ManagerECS : MonoBehaviour
{
public Mesh mesh;
public Material material;
EntityManager entityManager;
EntityArchetype mainArchetype;
EntityArchetype childMeshArchetype;
Entity mainEntity;
void Start()
{
Init();
CreateNewEntity();
}
void Init()
{
entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
SetMainArchetype();
}
void SetMainArchetype()
{
mainArchetype = entityManager.CreateArchetype(
typeof(Translation),
typeof(Rotation),
typeof(LocalToWorld),
typeof(RenderMesh),
typeof(RenderBounds)
);
}
void CreateNewEntity()
{
mainEntity = entityManager.CreateEntity(mainArchetype);
SetMainComponentData();
}
void SetMainComponentData()
{
entityManager.SetComponentData
(mainEntity, new Translation { Value = new float3(0,0,0) });
entityManager.SetComponentData
(mainEntity, new Rotation { Value = quaternion.identity });
entityManager.SetSharedComponentData(mainEntity, new RenderMesh
{
mesh =mesh,
material = material,
layerMask = 1,
});
entityManager.SetComponentData(mainEntity, new RenderBounds
{
Value = new AABB
{
Center = float3.zero, Extents = new float3(1, 1, 1)
}
});
}
}
And I still have the problem with the Normal Vector in my Shadergraph shader.
So I made an HLSL shader because I thought the bug was maybe related with Shadergraph. But the problem is still here, all normals are black.
Shader "Universal Render Pipeline/Custom/NormalViewer"
{
Properties {}
SubShader
{
Tags
{
"RenderPipeline"="UniversalPipeline" "Queue"="Geometry"
}
Pass
{
Name "Forward"
Tags
{
"LightMode"="UniversalForward"
}
Cull Back
HLSLPROGRAM
#pragma exclude_renderers gles gles3 glcore
#pragma target 4.5
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_instancing
#pragma instancing_options renderinglayer
#pragma multi_compile _ DOTS_INSTANCING_ON
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
struct Attributes
{
float4 positionOS : POSITION;
half3 normal : NORMAL;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct Varyings
{
float4 positionHCS : SV_POSITION;
half3 normal : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
Varyings vert(Attributes IN)
{
Varyings OUT;
UNITY_SETUP_INSTANCE_ID(IN);
UNITY_TRANSFER_INSTANCE_ID(IN, OUT);
OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
OUT.normal = TransformObjectToWorldNormal(IN.normal);
return OUT;
}
half4 frag(Varyings IN) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(IN);
half4 color = 0;
color.rgb = IN.normal;
return color;
}
ENDHLSL
}
}
}
So I don’t think it’s a shadergraph bug.
I created a SystemBase that print in the console the value of each normal stored in the renderMesh.mesh. And they were not empty, it was the correct value I expected… So it’s not from the renderMesh neither.
Another strange thing, it’s not just a black color, I think it’s extremely negative because when I try to add it some value it stay black.