advances in qt 3d - change | ervin...advances in qt 3d advances in qt 3d p.2 feature set entity...

48
Advances in Qt 3D Kévin Ottens, Software Craftsman at KDAB

Upload: others

Post on 17-Apr-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

AdvancesinQt3DKévinOttens,SoftwareCraftsmanatKDAB

AdvancesinQt3D

AdvancesinQt3D p.2

FeatureSet

EntityComponentSystem?What'sthat?

HelloDonut

InputHandling

AnimationwithQt3D

NewPBRMaterials

PaintedTextures

IntegratingQtQuickwithQt3Dagain

CapturingtheRendering

LevelofDetail

DisplayingText

TheFutureofQt3D

AdvancesinQt3D

FeatureSet p.3

FeatureSet

EntityComponentSystem?What'sthat?

HelloDonut

InputHandling

AnimationwithQt3D

NewPBRMaterials

PaintedTextures

IntegratingQtQuickwithQt3Dagain

CapturingtheRendering

LevelofDetail

DisplayingText

TheFutureofQt3D

WhatisQt3D?

FeatureSet p.4

Itisnotabout3D!

Multi-purpose,notjustagameengine

Softreal-timesimulationengine

Designedtobescalable

Extensibleandflexible

SimulationEngine

FeatureSet p.5

Thecoreisnotinherentlyabout3D

ItcandealwithseveralfunctionaldomainsatonceAI,logic,audio,etc.Andofcourseitcontainsa3Drenderertoo!

AllyouneedforacomplexsystemsimulationMechanicalsystemsPhysics...andalsogames

Scalability

FeatureSet p.6

Frontend/backendsplitFrontendislightweightandonthemainthreadBackendexecutedinasecondarythreadWheretheactualsimulationruns

Non-blockingfrontend/backendcommunication

Backendmaximizesthroughputviaathreadpool

ExtensibilityandFlexibility

FeatureSet p.7

Functionaldomainscanbeaddedbyextendingtheruntime...onlyifthere'snotsomethingfittingyourneedsalready

ProvidebothC++andQMLAPIs

IntegrateswellwiththerestofQtPullingyoursimulationdatafromadatabaseanyone?

EntityComponentSystemisusedtocombinebehaviorinyourownobjectsNodeepinheritancehierarchy

AdvancesinQt3D

EntityComponentSystem?What'sthat? p.8

FeatureSet

EntityComponentSystem?What'sthat?

HelloDonut

InputHandling

AnimationwithQt3D

NewPBRMaterials

PaintedTextures

IntegratingQtQuickwithQt3Dagain

CapturingtheRendering

LevelofDetail

DisplayingText

TheFutureofQt3D

ECS:Definitions

EntityComponentSystem?What'sthat? p.9

ECSisanarchitecturalpatternPopularingameenginesFavorscompositionoverinheritance

Anentityisageneralpurposeobject

Anentitygetsitsbehaviorbycombiningdata

Datacomesfromtypedcomponents

EntityComponentSystem

EntityComponentSystem?What'sthat? p.10

TheEntity/ComponentdatasplitgivesflexibilitytomanagetheAPI

TheSystemseparationmovesthebehaviorawayfromdataavoidingdependenciesbetweenComponents

AdvancesinQt3D

HelloDonut p.11

FeatureSet

EntityComponentSystem?What'sthat?

HelloDonut

InputHandling

AnimationwithQt3D

NewPBRMaterials

PaintedTextures

IntegratingQtQuickwithQt3Dagain

CapturingtheRendering

LevelofDetail

DisplayingText

TheFutureofQt3D

HelloDonut(QML)

HelloDonut p.12

GoodpracticehavingrootEntitytorepresentthescene

OneEntityper"object"inthescene

Objectsgivenbehaviorbyattachingcomponentsubclasses

ForanEntitytobedrawnitneeds:AmeshgeometrydescribingitsshapeAmaterialdescribingitssurfaceappearance

Demoqt3d/ex-hellodonut-qml

C++APIvsQMLAPI

HelloDonut p.13

QMLAPIisamirroroftheC++API

C++classnamesliketherestofQt

QMLelementnamesjustdon'thavetheQinfrontQt3DCore::QNodevsNodeQt3DCore::QEntityvsEntity...

AdvancesinQt3D

InputHandling p.14

FeatureSet

EntityComponentSystem?What'sthat?

HelloDonut

InputHandling

AnimationwithQt3D

NewPBRMaterials

PaintedTextures

IntegratingQtQuickwithQt3Dagain

CapturingtheRendering

LevelofDetail

DisplayingText

TheFutureofQt3D

PreviouslyinInputHandling

InputHandling p.15

PhysicaldevicessuchasKeyboardDeviceandMouseDeviceproduceevents

HandlerssuchasKeyboardHandlerandMouseHandler:ProcesseventsbyconvertingeventstosignalsforusercodetoreacttoArecomponentsthatshouldbeaddedtoEntitystoprovidebehaviorrelatedtoinput

ObjectPickerprovideshigh-levelpickingfunctionality

LogicalDevices:AllowanalogaxisvaluestobeproducedAllowmappingmultiplephysicaldevicesontoAxisandActionelements

HowtoControlaValueoverTime?

InputHandling p.16

ObviouslyusinganAxis

Butwegotonlytheaxisposition...

ForceustouseimperativecodeexecutedinthemainthreadTypicallyincrementavaluebasedontheaxispositionNeedstosampleovertime(andeventuallyintegrate!)

OruseAxisAccumulatorwhichdoesitforyouManagethevalueovertimebasedonaninputaxisCantreattheaxispositionasavelocityoranaccelerationAlltheworkisdoneinsecondarythreads

AxisAccumulator(since5.8)

InputHandling p.17

1 importQt3D.Input2.92 ...34 LogicalDevice{5     axes:Axis{6         id:mouseYAxis7         AnalogAxisInput{8             sourceDevice:mouseDevice9             axis:MouseDevice.Y10         }11     }12 }1314 AxisAccumulator{15     sourceAxis:mouseYAxis16     sourceAxisType:AxisAccumulator.Velocity17     scale:5018     //Canbindonvalue19 }

Demoqt3d/sol-moving-boxes-qml-step3

Demoqt3d/sol-moving-boxes-qml-step4

AdvancesinQt3D

AnimationwithQt3D p.18

FeatureSet

EntityComponentSystem?What'sthat?

HelloDonut

InputHandling

AnimationwithQt3D

NewPBRMaterials

PaintedTextures

IntegratingQtQuickwithQt3Dagain

CapturingtheRendering

LevelofDetail

DisplayingText

TheFutureofQt3D

AnimationSupportinQt3D

AnimationwithQt3D p.19

YoucoulduseQtQuickanimationsbut...TheyareexecutedonthemainthreadTheyarenotsynchronizedwiththeQt3Dengineframerate

Instead,youcanhaveanimationsintheQt3DenginebyregisteringtheQt3DAnimation::QAnimationAspect

LikeanyotheraspectitthenprovidesAPI,mainlytypesinheritingfrom:AbstractAnimationClipwhichcontainthedatarepresentingagivenanimationAbstractClipAnimator,Componentswhichrunclipsandmapthemtoothercomponentsproperties

AnimationClip,aKeyFrameBasedClip

AnimationwithQt3D p.20

AnimationCliprepresentsakeyframebasedclip

ItholdstheAnimationClipDatainitsclipDataproperty

CurrentlyAnimationClipDatainstancescanonlybecreatedfromC++

ClipdatahasasetofQChanneldescribingthepropertiesknowtotheclip

EachQChannelhasoneormoreQChannelComponentallowingtorepresentcomplextypesTypicallyacolorchannelhasthreechannelcomponents

AQChannelComponentisalistofkeyframesforthegivenchannelcomponent

AnimationClipLoader

AnimationwithQt3D p.21

CreatingaAnimationClipanditsdatacanbetediousandhardtomaintain

Alsoitisnotaccessibletoartists

AnimationClipLoadercanloadaclipfromaJSONfileTheformatiseasytoexportfromadesigntoolCurrentlyapluginforBlenderisavailable

1 importQt3D.Animation2.92 ...34 AnimationClipLoader{source:"qrc:/animation.json"}5 ...

Demoqt3d/ex-animationclip-loader

HowtoRunanAnimationClip?

AnimationwithQt3D p.22

1 importQt3D.Animation2.92 ...3 ClipAnimator{4     clip:AnimationClipLoader{source:"qrc:/animation.json"}56     channelMapper:ChannelMapper{7         ChannelMapping{8             channelName:"Location"9             target:transform10             property:"translation"11         }12         ChannelMapping{13             channelName:"Rotation"14             target:transform15             property:"rotation"16         }17         ChannelMapping{18             channelName:"Color"19             target:material20             property:"ambient"21         }22     }23 }24 ...

Demoqt3d/ex-animationclip-loader

AnimationBlending

AnimationwithQt3D p.23

Itisoftenusefultocombineseveralanimationsintoone

Makesiteasiertotunesimpleranimationsseparately,thenlettheenginecombinethem

Thisisdoneviablendingoperators

Makesitpossibletocreatenewvariationsfromabasicsetofanimations

Typicalexamplesingamesare:AcharacterwalkingthenstartingtorunAcharacterjumpingwhilewalkingorduringthetransitionbetweenwalkingandrunning

BlendedClipAnimator

AnimationwithQt3D p.24

1 importQt3D.Animation2.92 ...3 BlendedClipAnimator{4     blendTree:AdditiveClipBlend{5     additiveFactor:0.46     baseClip:LerpClipBlend{7         blendFactor:0.28         startClip:ClipBlendValue{9             clip:AnimationClipLoader{source:"qrc:/walk.json"}10         }11         endClip:ClipBlendValue{12             clip:AnimationClipLoader{source:"qrc:/run.json"}13         }14     }15     additiveClip:ClipBlendValue{16         clip:AnimationClipLoader{source:"qrc:/jump.json"}17     }18 }19 ...

Demoqt3d/sol-toyplane-pilot

AdvancesinQt3D

NewPBRMaterials p.25

FeatureSet

EntityComponentSystem?What'sthat?

HelloDonut

InputHandling

AnimationwithQt3D

NewPBRMaterials

PaintedTextures

IntegratingQtQuickwithQt3Dagain

CapturingtheRendering

LevelofDetail

DisplayingText

TheFutureofQt3D

Metal/RoughMaterials

NewPBRMaterials p.26

Qt3D5.9introducestwonewmaterialswithmuchmorerealisticrenderingQt3DExtras::QMetalRoughMaterialQt3DExtras::QTexturedMetalRoughMaterial

Thisisbasedonproperphysicstomodelthelighting

Italsointroducesnewricherlights

QtDemoqt3d-examples/pbr-textured-cube

QtDemoqt3d-examples/pbr-sphere

QtDemoqt3d-examples/pbr-spheres

EnvironmentLight(since5.9)

NewPBRMaterials p.27

1 importQt3D.Core2.02 importQt3D.Render2.93 ...45 components:[6     EnvironmentLight{7         irradiance:TextureLoader{...}8         specular:TextureLoader{...}9     }10 ]

Demoqt3d/ex-lights-qml

SkyBox(since5.9)

NewPBRMaterials p.28

1 importQt3D.Extras2.92 ...34 SkyboxEntity{5     baseName:"radianceTexture"6     extension:".dds"7     gammaCorrect:true//Since5.98 }

Demoqt3d/ex-lights-qml

AdvancesinQt3D

PaintedTextures p.29

FeatureSet

EntityComponentSystem?What'sthat?

HelloDonut

InputHandling

AnimationwithQt3D

NewPBRMaterials

PaintedTextures

IntegratingQtQuickwithQt3Dagain

CapturingtheRendering

LevelofDetail

DisplayingText

TheFutureofQt3D

IntegratingQPainterCode(since5.8)

PaintedTextures p.30

Often,wehavelegacyQPaintercode

NeedsintegrationtobeusablewithTextures

ProvidedbyQt3DRender::QPaintedTextureImageInheritfromitOverridethepaint()functionUselikeanyotherTextureImage

Demoqt3d/ex-painted-cube

AdvancesinQt3D

IntegratingQtQuickwithQt3Dagain p.31

FeatureSet

EntityComponentSystem?What'sthat?

HelloDonut

InputHandling

AnimationwithQt3D

NewPBRMaterials

PaintedTextures

IntegratingQtQuickwithQt3Dagain

CapturingtheRendering

LevelofDetail

DisplayingText

TheFutureofQt3D

TheScene2DElement(since5.9)

IntegratingQtQuickwithQt3Dagain p.32

ProvidedbytheQtQuick.Scene2Dmodule

TakesanItemaschildwhichwillbeyourwhole2Dscene

Itrendersthe2DsceneintoaRenderTargetOutputcontrolledbytheoutputpropertyItstexturecanbeusedbyanymaterial

TheentitiespropertyallowstodeclareonwhichentitiesthetexturewillbeusedNecessaryformouseeventhandlingRequiresPickingSettings.TrianglePickingtobesettohavethetriangleinformation

MouseeventsareonlyacceptedifthemouseEnabledpropertyistrue

Demoqt3d/ex-samegame

AdvancesinQt3D

CapturingtheRendering p.33

FeatureSet

EntityComponentSystem?What'sthat?

HelloDonut

InputHandling

AnimationwithQt3D

NewPBRMaterials

PaintedTextures

IntegratingQtQuickwithQt3Dagain

CapturingtheRendering

LevelofDetail

DisplayingText

TheFutureofQt3D

TheRenderCaptureElement(since5.9)

CapturingtheRendering p.34

Allowstocreatescreenshotsofthescenerendering

Alsoallowstodebugcomplexmulti-passrenderingOnecansaveasanimageoneoftheintermediatesteps

RenderCaptureisaFrameGraphNode

Eachtimeacaptureisneeded,acalltorequestCapture()isnecessarySuchrequestsareprocessedasynchronously

DebuggingMulti-PassRendering

CapturingtheRendering p.35

Thesceneallowstoselectobjectsbyclickingonthem

Aselectedobjectglows

Theeffectisimplementedusingamulti-passrender

WithRenderCaptureitiseasiertoseewhateachstageisdoing

Demoqt3d/sol-screenshot

AdvancesinQt3D

LevelofDetail p.36

FeatureSet

EntityComponentSystem?What'sthat?

HelloDonut

InputHandling

AnimationwithQt3D

NewPBRMaterials

PaintedTextures

IntegratingQtQuickwithQt3Dagain

CapturingtheRendering

LevelofDetail

DisplayingText

TheFutureofQt3D

ComplexObjectsvsDistance

LevelofDetail p.37

Scenesoftencontaincomplexobjects

Suchobjectsareexpensivetodisplay

Doesitstillmakesenseiftheyarefarfromthecamera?

Withlevelofdetailmanagement,simplerobjectscanbedisplayedinstead

ThisfeatureisprovidedwithLevelOfDetailandLevelOfDetailLoader

TheLevelOfDetailElement(since5.9)

LevelofDetail p.38

1 importQt3D.Render2.92 ...34 SphereMesh{5     slices:rings6     rings:[30,6,4][lod.currentIndex]7 },8 LevelOfDetail{9     id:lod10     camera:mainCamera11     thresholds:[100,500,1000]12     thresholdType:LevelOfDetail.DistanceToCameraThreshold13 }14 ...

Demoqt3d/ex-lod

Demoqt3d/sol-ogrehead

AdvancesinQt3D

DisplayingText p.39

FeatureSet

EntityComponentSystem?What'sthat?

HelloDonut

InputHandling

AnimationwithQt3D

NewPBRMaterials

PaintedTextures

IntegratingQtQuickwithQt3Dagain

CapturingtheRendering

LevelofDetail

DisplayingText

TheFutureofQt3D

ExtrudedTextMeshes(since5.9)

DisplayingText p.40

GeneratinggeometryoutoftextisdonewithExtrudedTextGeometryorExtrudedTextMesh

TheycanbeusedlikeanyotherGeometryorGeometryRenderer

fontandtextarecontrolledusingproperties

Thelengthoftheextrusioniscontrolledwiththedepthproperty

Demoqt3d/ex-text-3d

DistanceFieldText(since5.9)

DisplayingText p.41

DistancefieldtextisprovidedbyText2DEntity

ThisisafullfledgedEntitytoputintheobjecttree

font,colorandtextarecontrolledusingproperties

Thesizeofthesurfaceonwhichthetextisrenderedcanbecontrolledviawidthandheight

Demoqt3d/ex-text-2d

AdvancesinQt3D

TheFutureofQt3D p.42

FeatureSet

EntityComponentSystem?What'sthat?

HelloDonut

InputHandling

AnimationwithQt3D

NewPBRMaterials

PaintedTextures

IntegratingQtQuickwithQt3Dagain

CapturingtheRendering

LevelofDetail

DisplayingText

TheFutureofQt3D

ShaderGraphs(comingin5.10)

TheFutureofQt3D p.43

Currentlydifficulttoreuseandtunematerials

Forcedtoforktheshaderimplementations...

IntroducingShaderProgramBuilderwhichallowstoloadshadersfromagraph

JSONformat

Finergrainedbuildingblockswhichcanbereusedandreorganized

ShaderGraphs:QMetalRoughMaterial

TheFutureofQt3D p.44

ShaderGraphscont'd

TheFutureofQt3D p.45

WhatdoesthefutureholdforQt3D?

TheFutureofQt3D p.46

Qt3DCoreEfficiencyimprovemmentsBackendthreadpoolandjobhandlingimprovements-jobsspawningjobs

Qt3DRenderBillboards-camerafacingentitiesParticlesystems

Qt3DInputAdditionalinputdevicesupport3Dmousecontrollers,gamecontrollers

Enumeratedinputssuchas8-waybuttons,hatswitchesordials

WhatdoesthefutureholdforQt3D?

TheFutureofQt3D p.47

Newaspects:CollisionDetectionAspectAllowstodetectwhenentitiescollideorenter/exitvolumesinspace

AnimationAspectSkeletalanimationMorphtargetanimationRemovesanimationworkloadfrommainthread

PhysicsAspectRigidbodyandsoftbodyphysicssimulation

AIAspect,3DPositionalAudioAspect...

Tooling:Designtimetooling-sceneeditorBuildtimetooling-assetconditionersformeshes,texturesetc.

Thankyou!

www.kdab.com

[email protected]