GeoMipTerrain - position issue

Hello,
I’m playing with the GeoMipTerrain functionality and I’ve noticed quite strange behavior. If I change the position of the nodePath (move (0, 0, 0) into middle of the map) then the terrain is rendered with unwanted artefacts. When I remove the translation then it renders fine.

Here is the code:

self._terrain = GeoMipTerrain("surface")
self._terrain.setHeightfield("textures/heightmaps/heightmap_gs_%s.png" % (self.T_MAPPING[self._size], ))
#self._terrain.setColorMap("textures/heightmaps/heightmap_gs_%s.png" % (self.T_MAPPING[self._size], ))

self._hf = self._terrain.heightfield()
self._hfSizeX = self._hf.getXSize() - 1
self._hfSizeY = self._hf.getYSize() - 1

self._terrain.setBlockSize(max(self._hfSizeX, self._hfSizeY) // 4)
self._terrain.setBruteforce(True)

self._np = self._terrain.getRoot()
# If position does not start at (0, 0, 0) then artefacts re present
self._np.setPos(-self._scale * self._hfSizeX // 2, -self._scale * self._hfSizeY // 2, 0.0)
self._np.setScale(self._scale, self._scale, self._scaleZ)
self._np.reparentTo(parentNP)

self._terrain.generate()

If I remove following line then artefacts are gone:

self._np.setPos(-self._scale * self._hfSizeX // 2, -self._scale * self._hfSizeY // 2, 0.0)

No artefacts (no setPos):

Artefact (setPos used):

Zoomed in artefact (setPos used):

Can anyone explain why is this happening and how to prevent it?

Huh, that is pretty weird. I’m not sure what’s going on here. If you viewed it in wireframe mode, perhaps it might be clearer what was going on? Does this occur at the block boundary?

Hi,
I did change the blockSize to fixed no. 16 and it had no effect. I do not know how to check if it’s a line between two blocks but I guess it might be. On the other hand the block size change did not impact the length or size of the line artefakt in any way.

Here are screenshots depicting the model in wire frame mode:


It seems to me that there might be wrongly calculated normals because this kind of grey color disappears (surroundings become same as the color of the artefakt) immediately as my directional light (sun) turns to other side and only the ambient light is applied.

So I tried:

self._np.setRenderModeWireframe(1)
self._np.setTwoSided(True, 1)




…and the artefakt is visible from both sides but I’ve noticed that both sides are illuminated same way at the same time - meaning if the sun is under the plane then both sides are dark grey and if the sun is above the plane then both sides are illuminated - is that normal?

If I try functionally generated terrain then there is no artefakt no matter I’m moving the position into the middle like before. Could it be connected to some optimization feature because of big flat surfaces in original map?

It might indeed be an issue with normals. Would you mind sharing your original heightfield and the code to reproduce it so that I could see it for myself?

Hello,
I backed it up before my further changes so it should match the state of my original post:

20191129.zip (2.6 MB)

It’s carved out code (for testing purposes) from my different project so it contains some commented parts of code which are unrelated. Please also ignore a bit messy coding style - it’s my testing program :wink:

I’m using:
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Panda3D 1.10.4.1

Hi, were you able to reproduce the issue?