Hello…
I wanted to make a simple demo about rounding errors…
…and suddenly, after git pull, saw my demo and then my app rendering nothing. Scaaary.
Okay, the rendering is back again at
Ревизия: f3f70782eb8c56e1e159db395c9f879059b4c7e1
Автор: Michalis Kamburelis [email protected]
Дата: 06.02.2022 6:33:17
Сообщение:
Mention load_model_and_camera_manually is deliberately by code
The rendering is totally lost (nothing but background color) on today fetch.
JitterDemo.zip (3.4 KB)
If rendering something at all then by pressing left/right arrows you would be moving top grey shape.
And the rendering is not stable. The distance between leftmost triangle (cone) and the main body (cylinder or box) keeps varying on one pixel. Seems rounding is done differently one rotated elementary shapes, together making the shape.
Yet more weird is how the “bottom right” line of the rightmost cone keeps appearing and disappearing, but not the “top right” one! The movement is horizontal, so there should not be any jitter along the vertical axis.
Perhaps the rounding can be applied AFTER rotation, so the rounding errors would be the same over all the nodes?
Perhaps there can be some utility function that “fuses” a given shape with children, bringing all the inner nodes into the same flat array without nesting? This however would need destroying child components, which is dangerous of dangling pointers, or would need to turn children into hollow placeholders having zero nodes inside.
Maybe there is(was) something simple to make “antialiased” rendering that would conceal rounding errors but i failed to find it.
Keep right arrow pressed - and you would see the shape on the move distorted back-and-forth.
The idea was to keep coordinates in real world meters, so the numbers are quite large, but you said it was okay, there is no pre-fixed distance units in the engine.
Anyway, after upgrading to the latest engine - nothing is rendered at all :-/
procedure TfmSea.FormCreate(Sender: TObject);
begin
CreateScene;
end;
procedure TfmSea.CreateScene;
var ShipN: TCastleTransform; i: integer;
begin
Viewport := TCastleViewport.Create(Self);
Viewport.FullSize := true;
Viewport.Camera.Orthographic.Width := 2000 * pxInMeter;
Viewport.Camera.Orthographic.Height := 2000 * pxInMeter;
Viewport.Camera.Orthographic.Origin := Vector2(0.5, 0.5);
Viewport.Setup2D;
Viewport.Camera.ProjectionNear := -50000;
Viewport.Camera.ProjectionFar := +50000;
Viewport.BackgroundColor := Navy;
CastleSea.Controls.InsertFront(Viewport);
Ship1 := CreateShip1(Self, Vector4(0.2, 0.75, 0.75, 1), Teal);
Ship2 := CreateShip2(Self, Silver, Black);
Ship1.TranslationXY := Vector2(-5000, 0);
Ship2.TranslationXY := Vector2(-1500, +7500);
Ship2.Rotation := Vector4(0, 0, 1, - pi /2 );
Viewport.Items.Add(Ship1);
Viewport.Items.Add(Ship2);
for i := 1 to 10 do begin
ShipN := CreateShip2(Self, Teal, Blue);
ShipN.TranslationXY := Vector2(-1500 + i * pxInMeter, +7000 - pxInMeter * i * 40 );
ShipN.Rotation := Vector4(0, 0, 1, - pi /2 );
Viewport.Items.Add(ShipN);
end;
end;
function CreateShip2(const Owner: TComponent; const color, colorMark: TCastleColor
): TCastleTransform;
var
cf, cr: TCastleCone;
a: TCastlePlane; // TCastleCylinder;
b: TCastleBox;
L, W: integer;
procedure Setup1(const O: TCastleAbstractPrimitive);
begin
O.Material := pmUnlit;
O.Color := color;
// O.RenderOptions.Blending := True;
// O.RenderOptions.BlendingSort := bs2D;
end;
begin
Result := TCastleTransform.Create(Owner);
L := round(40 * pxInMeter);
W := round(15 * pxInMeter);
b := TCastleBox.Create(Owner);
a := TCastlePlane.Create(Owner);
cf := TCastleCone.Create(Owner);
cr := TCastleCone.Create(Owner);
Setup1(b);
Setup1(cf);
Setup1(cr);
//b.Height := L;
//b.Radius := W;
b.Size := Vector3(W*2, L, 2);
// a.Height := 3.5 * pxInMeter;
// a.Radius := 3.5 * pxInMeter;
a.Size := Vector2( 3 * pxInMeter, 2 * pxInMeter);
a.Axis := 2;
a.Material := pmUnlit;
a.Color := colorMark;
cf.BottomRadius := W;
cf.Height := W;
cr.BottomRadius := W;
cr.Height := W;
cf.TranslationXY := Vector2(0, -(L+W)/2);
cr.TranslationXY := Vector2(0, +(L+W)/2);
a.Translation := Vector3(0, 0, 2*W);
Result.Add(cf);
Result.Add(cr);
Result.Add(b);
b.Add(a);
end;