The problem is that your
board.x3dv contains both front and back faces. While they don’t exactly overlap, but they are really close (one at Z = 0.000049999998736893758 , one at Z = -0.000049999998736893758 ). The GPU makes the calculations with rather poor precision, and in this case it is doing linear interpolation of depths for the front and for the back face. It seems that are detected as overlapping at some pixels, at some angles.
One solution is just to remove the back face from your model. You can just comment the last
Shape from your
board.x3dv. Note that the board is visible from the back anyway (since you use “solid FALSE” in your X3D file).
I would also remove the sides of the board (1st shape of
board.x3dv) – they are visible only as occasional pixels, they are extremely thin.
Alternative solution would be to make the board thicker. In my tests, changing the coordinates to be 100x larger (so Z = -0.0049999998736893758 or 0.0049999998736893758) is enough to eliminate any artifacts, and doesn’t change the look of the model in any visible way.
Oh, and I’m honestly not sure why the problem is visible in TCastleControlBase (on Lazarus form), but not visible in view3dscene. While view3dscene initializes OpenGL context in a different way (using TCastleWindowBase) but the default context bit depths are the same, and they result in the same default DepthBits = 24, at least on my system. Yet, just like you, I can see the artifacts in your
project1, but not in
view3dscene – really don’t know why.
Some additional comments, not related to the problem at hand:
Is there a Viewport.Save(…) by any chance?
You can save
TCastleUserInterface descendant using
CastleComponentSerialize unit (this is used to save/load designs using our editor too, https://castle-engine.io/manual_editor.php ). And
TCastleViewport is a descendant of
TCastleUserInterface. This will include the
Viewport.Items, which is a hierarchy of TCastleTransform descendants (which usually contains TCastleScene instances as leafs).
You can also save
You can open resulting files in a text editor (these are just JSON files) or CGE editor.
Although I’m afraid that this advise isn’t really useful to you – we don’t save the X3D nodes graph of each TCastleScene. We only save the
TCastleScene.URL, which is empty, since you load the scene using
So, the answer is “yes, but it isn’t really useful to you at this point”, sorry:)
Forgot - test01.zip’s source includes the use of etpackage
Note that we have a way to measure time in
CastleTimeUtils already See the Timer routine. It’s used throughout the engine, and is suitable for measuring times precisely, even to make a simple “manual” profiler (see TCastleProfiler, used through the singleton
P.S. Testing your code, adding
InitializeLog in Unit1 initialization, I see that you have many non-power-of-2 textures. By default engine resizes them before loading to GPU, reporting to log this:
Textures: Resizing 2D texture "file:///mnt/data-linux/sources/castle-engine/castle-engine-priv/contrib/card_game_forum_peardox/test01/board/artcache/angel.jpg" from 1920x1090 to 2048x2048
Textures: Resizing 2D texture "file:///mnt/data-linux/sources/castle-engine/castle-engine-priv/contrib/card_game_forum_peardox/test01/card/artcache/70652.jpg" from 488x680 to 512x1024
Textures: Resizing 2D texture "file:///mnt/data-linux/sources/castle-engine/castle-engine-priv/contrib/card_game_forum_peardox/test01/card/back.jpg" from 672x936 to 1024x1024
Textures: Resizing 2D texture "file:///mnt/data-linux/sources/castle-engine/castle-engine-priv/contrib/card_game_forum_peardox/test01/card/artcache/69235.jpg" from 488x680 to 512x1024
Textures: Resizing 2D texture "file:///mnt/data-linux/sources/castle-engine/castle-engine-priv/contrib/card_game_forum_peardox/test01/card/artcache/70267.jpg" from 488x680 to 512x1024
Textures: Resizing 2D texture "file:///mnt/data-linux/sources/castle-engine/castle-engine-priv/contrib/card_game_forum_peardox/test01/card/artcache/69587.jpg" from 488x680 to 512x1024
Textures: Resizing 2D texture "file:///mnt/data-linux/sources/castle-engine/castle-engine-priv/contrib/card_game_forum_peardox/test01/card/artcache/70764.jpg" from 488x680 to 512x1024
Textures: Resizing 2D texture "file:///mnt/data-linux/sources/castle-engine/castle-engine-priv/contrib/card_game_forum_peardox/test01/card/artcache/70386.jpg" from 488x680 to 512x1024
Textures: Resizing 2D texture "file:///mnt/data-linux/sources/castle-engine/castle-engine-priv/contrib/card_game_forum_peardox/test01/card/artcache/70636.jpg" from 488x680 to 512x1024
Textures: Resizing 2D texture "file:///mnt/data-linux/sources/castle-engine/castle-engine-priv/contrib/card_game_forum_peardox/test01/card/artcache/70285.jpg" from 488x680 to 512x1024
Textures: Resizing 2D texture "file:///mnt/data-linux/sources/castle-engine/castle-engine-priv/contrib/card_game_forum_peardox/test01/card/artcache/68576.jpg" from 488x680 to 512x1024
Textures: Resizing 2D texture "file:///mnt/data-linux/sources/castle-engine/castle-engine-priv/contrib/card_game_forum_peardox/test01/card/artcache/70294.jpg" from 488x680 to 512x1024
Textures: Resizing 2D texture "file:///mnt/data-linux/sources/castle-engine/castle-engine-priv/contrib/card_game_forum_peardox/test01/card/artcache/70271.jpg" from 488x680 to 512x1024
Textures: Resizing 2D texture "file:///mnt/data-linux/sources/castle-engine/castle-engine-priv/contrib/card_game_forum_peardox/test01/card/artcache/69944.jpg" from 488x680 to 512x1024
This is not a problem. But if you’d like to have faster loading times (it may matter if you add thousands of Magic the Gathering cards ):
P.P.S. Note that you get nice specular highlights on the board now, because it uses Phong shading, which is implicitly requested by “solid FALSE” (two-sided lighting requires Phong shading). You can compare it by removing “solid FALSE”, the front face of the board will then be lit in a worse way.
So, to make sure you always use Phong shading, I would suggest to add
shading "PHONG" inside all shapes in your
board.x3dv. See https://castle-engine.io/x3d_implementation_shape_extensions.php#section_ext_shading .