Distant surfaces rendering in front of near surfaces


I have a problem that I know what is happening but I don’t know how to get Xenko to solve it. I am hoping someone may be able to point me in the right direction, it might requiring me pinging @xen2 or @Kryptos :rofl:

I am in the middle of trying to generate terrain for an enhanced flowing water demo. To create the plane I did a literal copy / paste of GeometricPrimitive.Plane.New from the engine’s code itself, with the only change is that I am using the height map to set a Y-Coordinate of the vertex instead of 0.0f, and I calculated my own normals (though I tried using UnitY before posting this).

When the game first loaded I was excited because I got what I expected; a mesh that looks like the heightmap I used, along with simplistic height based texturing.

But then I move around the world and noticed that this is happening:

The water way on the other side is showing through. You can see shadows cast from hills close to the camera, but not the hills themselves. It’s basically rendering far things first, or far things are replacing close things, etc.

I implemented the terrain by:

  1. Creating an empty entity with a script attached to it,
  2. The script creates the terrain primitive, an empty model, and a model component.
  3. Calls primitive.ToMeshDraw() and adds the mesh to the model, and adds the model to the model component.
  4. Lastly, adds my texture shader to the model, and adds the model to the entity that the script was attached to.

I was hoping that adding it to an entity already in the scene would let me make use of default mesh rendering to handle this sort of thing. I had tried playing with my own custom effect before going this route and was having a hard time getting that working. Now I am sort of lost and frustrated.

Any help would be greatly appreciated!


Actually, I just updated to Xenko and this appears to be working as I was expecting now!


Before you were using 2.x right? (nothing changed between and


Nope I had created the project after upgrading to v3. Odd that nothing changed then. It did tell me the project had to be converted to after I installed it, perhaps there was some pointer to something, some subtle setting, etc, that got corrected?


4 posts were split to a new topic: Xenko versioning (editor behavior & PackageReference dependencies)


@xen2 I figured out what actually fixed this. I had a MaterialTransparencyBlendFeature on the material I created in code when I was getting the issue. I had that disabled when I thought it was fixed by the update. Now, even though I had one attached, it was set to Alpha = 1.0, and the shader was returning alpha = 1.0 as well so I wasn’t expecting it to render distance surfaces. Not sure if that is a misunderstanding on my part, I’m still new to working with shaders in general, or if the depth logic needs to take alpha at 1.0 into consideration.