1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
// -*- compile-command: "./test_single_testcase.sh TTestCastleInternalGLShadowVolumes" -*-
{
Copyright 2023-2023 Michalis Kamburelis.
This file is part of "Castle Game Engine".
"Castle Game Engine" is free software; see the file COPYING.txt,
included in this distribution, for details about the copyright.
"Castle Game Engine" is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
----------------------------------------------------------------------------
}
unit TestCastleInternalGLShadowVolumes;
interface
uses
Classes, SysUtils,
CastleTester;
type
TTestCastleInternalGLShadowVolumes = class(TCastleTestCase)
published
procedure TestCasterShadowPossiblyVisible;
end;
implementation
uses CastleTransform, CastleFrustum, CastleInternalGLShadowVolumes, CastleProjection,
CastleVectors, CastleViewport, CastleBoxes;
procedure TTestCastleInternalGLShadowVolumes.TestCasterShadowPossiblyVisible;
var
Viewport: TCastleViewport;
Camera: TCastleCamera;
Projection: TProjection;
Frustum: TFrustum;
SvRenderer: TGLShadowVolumeRenderer;
begin
Viewport := TCastleViewport.Create(nil);
Camera := Viewport.Camera;
{ stand at (10, 0, 0), looking in -Z, up in +Y }
Camera.SetView(
Vector3(10, 0, 0),
Vector3(0, 0, -1),
Vector3(0, 1, 0));
FillChar(Projection, SizeOf(Projection), #0);
Projection.ProjectionType := ptPerspective;
Projection.PerspectiveAnglesRad := Vector2(Pi / 3, Pi / 3);
Projection.ProjectionNear := 1;
Projection.ProjectionFar := ZFarInfinity;
Frustum.Init(Projection.Matrix(1), Camera.Matrix);
AssertTrue(Frustum.FarInfinity);
SvRenderer := TGLShadowVolumeRenderer.Create;
try
// point light test
SvRenderer.InitFrustumAndLight(Frustum, Vector4(-10, 0, 0, 1));
AssertTrue(SvRenderer.GetCasterShadowPossiblyVisible(
Box3D(Vector3(-1, -1, -1), Vector3(1, 1, 1)).Transform(TranslationMatrix(0, 0, 0))
));
AssertTrue(SvRenderer.GetCasterShadowPossiblyVisible(
Box3D(Vector3(-1, -1, -1), Vector3(1, 1, 1)).Transform(TranslationMatrix(-10, 0, 0))
));
AssertTrue(SvRenderer.GetCasterShadowPossiblyVisible(
Box3D(Vector3(-1, -1, -1), Vector3(1, 1, 1)).Transform(TranslationMatrix(10, 0, 0))
));
// too far to the right to cast shadows
AssertFalse(SvRenderer.GetCasterShadowPossiblyVisible(
Box3D(Vector3(-1, -1, -1), Vector3(1, 1, 1)).Transform(TranslationMatrix(20, 0, 0))
));
// directional light test
SvRenderer.InitFrustumAndLight(Frustum, Vector4(1, 0, 0, 0));
AssertTrue(SvRenderer.GetCasterShadowPossiblyVisible(
Box3D(Vector3(-1, -1, -1), Vector3(1, 1, 1)).Transform(TranslationMatrix(0, 0, 0))
));
AssertTrue(SvRenderer.GetCasterShadowPossiblyVisible(
Box3D(Vector3(-1, -1, -1), Vector3(1, 1, 1)).Transform(TranslationMatrix(-10, 0, 0))
));
AssertTrue(SvRenderer.GetCasterShadowPossiblyVisible(
Box3D(Vector3(-1, -1, -1), Vector3(1, 1, 1)).Transform(TranslationMatrix(10, 0, 0))
));
// too far to the right to cast shadows
AssertFalse(SvRenderer.GetCasterShadowPossiblyVisible(
Box3D(Vector3(-1, -1, -1), Vector3(1, 1, 1)).Transform(TranslationMatrix(20, 0, 0))
));
finally
FreeAndNil(SvRenderer);
FreeAndNil(Viewport);
end;
end;
initialization
RegisterTest(TTestCastleInternalGLShadowVolumes);
end.
|