Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testqgs3drendering: Add a test for shadows effect #58111

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions tests/src/3d/testqgs3drendering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class TestQgs3DRendering : public QgsTest
void testFilteredFlatTerrain();
void testFilteredDemTerrain();
void testFilteredExtrudedPolygons();
void testShadowEffect();
void testDepthBuffer();
void testAmbientOcclusion();
void testDebugMap();
Expand Down Expand Up @@ -1525,6 +1526,55 @@ void TestQgs3DRendering::testFilteredExtrudedPolygons()
QGSVERIFYIMAGECHECK( "polygon3d_extrusion_filtered", "polygon3d_extrusion_filtered", img, QString(), 40, QSize( 0, 0 ), 2 );
}

void TestQgs3DRendering::testShadowEffect()
{
const QgsRectangle fullExtent = mLayerDtm->extent();

Qgs3DMapSettings *mapSettings = new Qgs3DMapSettings();
mapSettings->setCrs( mProject->crs() );
mapSettings->setExtent( fullExtent );
mapSettings->setLayers( QList<QgsMapLayer *>() << mLayerBuildings << mLayerRgb );
QgsDirectionalLightSettings defaultDirectionalLight;
mapSettings->setLightSources( {defaultDirectionalLight.clone() } );

QgsFlatTerrainGenerator *flatTerrain = new QgsFlatTerrainGenerator;
flatTerrain->setCrs( mapSettings->crs() );
mapSettings->setTerrainGenerator( flatTerrain );

QgsPhongMaterialSettings materialSettings;
materialSettings.setAmbient( Qt::black );
materialSettings.setDiffuse( Qt::lightGray );
QgsPolygon3DSymbol *symbol3d = new QgsPolygon3DSymbol;
symbol3d->setMaterialSettings( materialSettings.clone() );
symbol3d->setExtrusionHeight( 10.f );
QgsVectorLayer3DRenderer *renderer3d = new QgsVectorLayer3DRenderer( symbol3d );
mLayerBuildings->setRenderer3D( renderer3d );

QgsShadowSettings shadowSettings;
shadowSettings.setRenderShadows( true );
shadowSettings.setSelectedDirectionalLight( 0 );
shadowSettings.setMaximumShadowRenderingDistance( 1500 );
shadowSettings.setShadowMapResolution( 8192 );
mapSettings->setShadowSettings( shadowSettings );

QgsOffscreen3DEngine engine;
Qgs3DMapScene *scene = new Qgs3DMapScene( *mapSettings, &engine );
engine.setRootEntity( scene );

scene->cameraController()->setLookingAtPoint( QgsVector3D( 220, 0, 250 ), 125, 55, -35 );

// When running the test on Travis, it would initially return empty rendered image.
// Capturing the initial image and throwing it away fixes that. Hopefully we will
// find a better fix in the future.
Qgs3DUtils::captureSceneImage( engine, scene );
QImage img = Qgs3DUtils::captureSceneImage( engine, scene );

delete mapSettings;
delete scene;

QGSVERIFYIMAGECHECK( "shadow_effect", "shadow_effect", img, QString(), 40, QSize( 0, 0 ), 2 );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest using a solid color terrain here if possible -- it'd make it easier to see exactly what the test is checking

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only opened this PR to check if the shadows effect works in qt6. I can't make it work locally and it doesn't work on the ci too. The shadows are not visible.

}

void TestQgs3DRendering::testAmbientOcclusion()
{
// =============================================
Expand Down Expand Up @@ -1557,6 +1607,14 @@ void TestQgs3DRendering::testAmbientOcclusion()
mapSettings.setLightSources( {defaultPointLight.clone() } );
mapSettings.setOutputDpi( 92 );

QgsPhongMaterialSettings materialSettings;
materialSettings.setAmbient( Qt::lightGray );
QgsPolygon3DSymbol *symbol3d = new QgsPolygon3DSymbol;
symbol3d->setMaterialSettings( materialSettings.clone() );
symbol3d->setExtrusionHeight( 10.f );
QgsVectorLayer3DRenderer *renderer3d = new QgsVectorLayer3DRenderer( symbol3d );
mLayerBuildings->setRenderer3D( renderer3d );

// =========== creating Qgs3DMapScene
QPoint winSize = QPoint( 640, 480 ); // default window size

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading