340 likes | 526 Views
GAM531 DPS931 – Week 5. The Scene. Reviewing the Engine. DX11 Object. DX 11 API. iEngine. Engine. Controller. Manager. Model. 1 or 1. 1 m. 1 m. 1 m. 1 . GL 4.3 Object. GL 4.3 API. 1. DX11 Device. GL 4.3 Device. iController. iModel. 1 or 1. GL 4.3 API. DX 11 API.
E N D
GAM531DPS931 – Week 5 The Scene
Reviewing the Engine DX11 Object DX 11 API iEngine Engine Controller Manager Model 1 or 1 1 m 1 m 1 m 1 GL 4.3 Object GL 4.3 API 1 DX11 Device GL 4.3 Device iController iModel 1 or 1 GL 4.3 API DX 11 API
Expanding the Engine Singleton <Engine<RS>> iEngine iEngine Engine<RS> Engine class Engine : public iEngine , public Singleton<Engine<RS>>
Expanding the Controllers iResourceController iSceneController iController Controller SceneController<RS> WindowController ResourceController<RS> class SceneController : public iSceneController class ResourceController : public iResourceController class WindowController
Expanding the Managers Singleton <NodeManager<RS>> BaseManager <Node<RS>> Manager NodeManager <RS> class NodeManager : public Singleton<NodeManager<RS>>, public BaseManager<Node<RS>>
Expanding the Manager Bases BaseManager <T> IterativeManager <T> ResourceManager <T> BM IM RM template <class T>class BaseManager { protected: ArrayList<T*> objects; ArrayList<T*> activeObjects; … } template <class T> class IterativeManager : public BaseManager<T> { protected: typenameArrayList<T*>::iterator it; … } template <class T> class ResourceManager { protected: HashMap<String, T*> resources; … }
Expanding all Managers RM BM IM IM IM RM S S S S S S NodeManager <RS> BlendStateManager <RS> LightManager <RS> ActorManager <RS> CameraManager <RS> MaterialManager<RS> RM RM BM RM RM S S S S S S VertexFormatManager<RS> WindowManager TextureManager<RS> MeshManager <RS> SamplerManager<RS> ShaderManager <RS>
Expanding the Models iSModel iModel iResource iNode SceneObject SModel Model Resource Node
Expanding the Resource Models iVertexFormat iTextureSampler iBlendState iMaterial iMesh iTexture BlendState <RS> Material <RS> Mesh <RS> Texture <RS> VertexFormat<RS> TextureSampler <RS> Shader VertexShader<RS> FragmentShader<RS>
Expanding the Scene Models Camera <RS> SceneObject<RS, iCamera> iCamera iNode Actor<RS> iActor SceneObject<RS, iActor> iSceneObject Node <RS> Light <RS> SceneObject<RS, iLight> iLight
One last look at the simple engine… DX11 Object DX 11 API iEngine Engine Controller Manager Model 1 or 1 1 m 1 m 1 m 1 GL 4.3 Object GL 4.3 API 1 DX11 Device GL 4.3 Device iController iModel 1 or 1 GL 4.3 API DX 11 API
Interface Base ClassRM = Resource ManagerBM = Base ManagerIM = Iterative ManagerSh = ShaderSO = SceneObject BlendState <RS> Singleton Texture <RS> DX/GL Uniform Buffer Contains (m = many) m RM m Either or (only one) DX/GL API Wrapper BlendStateManager <RS> RM Mesh <RS> DX11Device GL 4.3 Device IM MaterialManager <RS> ActorManager<RS> SO m m Actor <RS> RM ResourceController <RS> SceneController <RS> IM MeshManager<RS> TextureSampler <RS> Engine <RS> CameraManager <RS> m RM m SO BM SamplerManager<RS> Camera <RS> VertexFormat <RS> IM NodeManager<RS> LightManager<RS> RM RM m ShaderManager <RS> m VertexFormatManager<RS> TextureManager<RS> m SO m m Light <RS> Sh Sh m Node <RS> Material <RS> m VertexShader<RS> FragmentShader <RS>
Looking into the code SceneController.hpp template <RenderSystem RS> class SceneController : public iSceneController { … public: ActorManager<RS> actMan; CameraManager<RS> camMan; LightManager<RS> lgtMan; NodeManager<RS> nodMan; … } Engine.hpp template <RenderSystem RS> class Engine: public iEngine, public Singleton<Engine<RS>> { private: … //Controllers SceneController<RS> sCont; ResourceController<RS> rCont; //Devices Device<RS> dev; … } Managers.hpp template <RenderSystem RS> class LightManager : public Singleton<LightManager<RS>>, public IterativeManager<Light<RS>> { … }
Looking into the code… SceneObject.hpp template <RenderSystem RS, class I = iSceneObject> class SceneObject : public I { protected: boolactive; Node<RS>* node; UniformBuffer<RS> buffer; … } Buffers.hpp template <RenderSystem RS> class UniformBuffer : public Buffer<RS> {…}template <RenderSystem RS> class Buffer { protected: APIBuffer<RS>* buffer; ArrayList<uint32> dynamIndex; uint32 byteSize; uint32 indexSize; uint32 padding; … } Light.hpp template <RenderSystem RS> class Light : public SceneObject<RS,iLight> { private: LightTypetype; Color diffuse; Color specular; Vector<float,4> attenuation; Vector<float,3> spot; … }
Graphics Buffers Struct Light {int type; int state; }Light a; UniformBuffer<RS> lb;lb.addType<int>(); lb.addType<int>(); lb.fill((byte*)&a, sizeof(Light)); type state Light a System Memory type state Light a Graphics Memory
Interface Base ClassRM = Resource ManagerBM = Base ManagerIM = Iterative ManagerSh = Shader BlendState <RS> Singleton The Scene Texture <RS> DX/GL Uniform Buffer Contains (m = many) m RM m Either of (only one) DX/GL API Wrapper BlendStateManager <RS> RM Mesh <RS> DX11Device GL 4.3 Device IM MaterialManager <RS> ActorManager<RS> SO m m Actor <RS> RM ResourceController <RS> SceneController <RS> IM MeshManager<RS> TextureSampler <RS> Engine <RS> CameraManager <RS> m RM m SO BM SamplerManager<RS> Camera <RS> VertexFormat <RS> IM NodeManager<RS> LightManager<RS> RM RM m ShaderManager <RS> m VertexFormatManager<RS> TextureManager<RS> m SO m m Light <RS> Sh Sh m Node <RS> Material <RS> m VertexShader<RS> FragmentShader <RS>
What is the Scene? ActorNodeID: 1029MeshID: 32192MaterialID: 212 LightNodeID: 909Diffuse: 0 0 1 0 Type: Point CameraNodeID: 123Field of View: 1.2 Aspect: 1.25
Scene Node Scene Object Scene Object Node Node Node Node Node Matrix<float,4> localT; ArrayList<SceneObject<RS>*> objects; Scene Object ArrayList<Node*> children; Node* parent;
Scene Node Example [ 1 0 0 0 ][ 0 1 0 0 ][ 0 0 1 0 ] [ 1 1 0 1 ] 4 4 [ 1 0 0 0 ][ 0 1 0 0 ][ 0 0 1 0 ] [ 10 0 1 ] 1 3 2 [ 1 0 0 0 ][ 0 1 0 0 ][ 0 0 1 0 ] [ 1 -1 0 1 ] [ 1 0 0 0 ][ 0 1 0 0 ][ 0 0 1 0 ] [ 1 1 0 1 ] 5 [ 1 0 0 0 ][ 0 1 0 0 ][ 0 0 1 0 ] [ 0 -1 0 1 ]
Scene Node Example [ 1 0 0 0 ][ 0 1 0 0 ][ 0 0 1 0 ] [ 1 1 0 1 ] 4 [ 1 0 0 0 ][ 0 1 0 0 ][ 0 0 1 0 ] [ 10 0 1 ] [ 1 0 0 0 ][ 0 1 0 0 ][ 0 0 1 0 ] [ 10 0 1 ] [ 1 0 0 0 ][ 0 1 0 0 ][ 0 0 1 0 ] [ 1 1 0 1 ] [ 1 0 0 0 ][ 0 1 0 0 ][ 0 0 1 0 ] [ 0 -1 0 1 ] [ 1 0 0 0 ][ 0 1 0 0 ][ 0 0 1 0 ] [ 1 -1 0 1 ] 3 2 [ 1 0 0 0 ][ 0 1 0 0 ][ 0 0 1 0 ] [ 1 -1 0 1 ] [ 1 0 0 0 ][ 0 1 0 0 ][ 0 0 1 0 ] [ 1 1 0 1 ] 1 5 [ 1 0 0 0 ][ 0 1 0 0 ][ 0 0 1 0 ] [ 0 -1 0 1 ] [ 1 0 0 0 ][ 0 1 0 0 ][ 0 0 1 0 ] [ 2 0 0 1 ] [ 1 0 0 0 ][ 0 1 0 0 ][ 0 0 1 0 ] [ 3 -1 0 1 ] [ 1 0 0 0 ][ 0 1 0 0 ][ 0 0 1 0 ] [ 1 0 0 1 ] [ 1 0 0 0 ][ 0 1 0 0 ][ 0 0 1 0 ] [ 0 -1 0 1 ]
Node Class The local transformation of Node The calculated absolute transformation of the Node for this frame, refreshed before each render template <RenderSystem RS> class Node : public iNode { private: Matrix<float,4> localT; Matrix<float,4> _tempAbs; uint32 nIndex; Node* parent; ArrayList<Node*> children; ArrayList<SceneObject<RS>*> objects; public: … void _addChild(Node* a); void _removeChild(Node*); void _notifyAttach(SceneObject<RS>* a); void _notifyDetach(SceneObject<RS>*); }; The parent of the node, null if the node is a root node All of the nodes to which this node is the parent node All of the scene objects that are attached to this node Adds/Removes a node from the children list Adds/Removes a scene object from the objects list
Scene Scene Object Scene Object Node Node Node Node Node Scene Object
SceneObject Class Indicates if the object is part of it’s manager’s active objects list The node that the scene object is attached to, null if it is not in the scene template <RenderSystem RS, class I = iSceneObject> class SceneObject : public I { protected: bool active; Node<RS>* node; UniformBuffer<RS> buffer; SceneObject(); virtual ~SceneObject(); public: void attachTo(constiNode* n); constiNode* getNode() const; boolisActive(); inline void _bindVertex(uint32 slot); inline void _bindFragment(uint32 slot); }; A Uniform Buffer which enables the scene object to store information on the graphics card for use when rendering Protected Ctor and Dtor to prevent scene objects from being instantiated Used to attach the scene object to a node Returns the node the object is attached to Binds the data in “buffer” to a specific slot in the graphics card (for vertex and fragment shaders)
Scene Scene Object Scene Object Actor Node Node Node Node Node Scene Object
What is an Actor? Everything you see in the game world is an actor! Things that are not actors:- The sky- The HUD (heads up display)
What makes up an Actor? Mesh Mesh + Material template <RenderSystem RS> class Actor : public SceneObject<RS, iActor> { private: Material<RS>* mat; Mesh<RS>* mesh; … };
Scene Light Scene Object Actor Node Node Node Node Node Scene Object
What is a Light? template <RenderSystem RS> class Light : public SceneObject<RS,iLight> { private: LightTypetype; Color diffuse; Color specular; Vector<float,4> attenuation; Vector<float,3> spot; … }; Point Light Spot Light Directional Light
What does a light do? 1 Actor, 0 Lights 1 Actor, 1 Light 0 Actors, 1 Light 1 Actor, 2 Lights
Scene Light Actor Node Node Node Node Node Scene Object Camera
What is a Camera? Far Clipping Plane template <RenderSystem RS> class Camera : public SceneObject<RS,iCamera> { private: Matrix<float,4> projMatrix; float fov; float aspect; float nearClip; float farClip; RasterizerState<RS> rend; … }; Field of View * Aspect Ratio Near Clipping Plane Field of View
How does the camera work? Clipping Planes Wide Aspect Ratio (5.71) Field of View &Aspect Ratio Small FOV (0.39 rad) Large FOV (1.57 rad)
Scene Light Actor Node Node Node Node Node Scene Object Camera
To Do • Do some basic research on your team’s enhancement • Begin writing your enhancement proposal document (due Oct 18th) • Read course notes (week 1 – 6) in preparation for Mid-term next week