Jump to content

  • Log In with Google      Sign In   
  • Create Account

D.V.D

Member Since 20 Aug 2012
Offline Last Active Yesterday, 08:26 PM

Posts I've Made

In Topic: Uniform Buffer Confusion

17 October 2014 - 12:46 PM

I'm dealing with this issue by suiting the graphics rendering pipeline and the shader scripts together. A specific kind of render pipeline has its specific stages: Forward lighting, material rendering, screen-space lighting, tone mapping, image post-processing, ... whatever. There are several kinds of properties needed: Material properties for physical based shading (or the suitable NPR properties for NPR rendering; let's call this material, too), camera set-up, screen rect, lights, and so on. Different stages have (partially) distinct requirements, but inside a stage the requirements are fixed.

 

So here is the deal: A camera provides a uniform block with its parameters, the screen provides one with its own parameters, the model provides one with its material, a post-process provides one with its parameters, a pipeline stage provides one, and perhaps other do so. Each block coming from such a source has an equivalent in the respective shader scripts, and there is a standard name used for it: E.g. CameraSetup, ScreenRect, Material, ... So it is convention that every script implementing forward rendering or material rendering has a slot for e.g. a Material block. Hence one can expect to have blocks with a specific name in a script suitable for a specific kind of rendering stage.

 

The higher level of rendering is implemented inside the stages of the render pipeline. It fetches the suitable blocks from the various sources and generates suitable binding instructions in the state part of the rendering jobs. The lower level of rendering (i.e. the one that calls OpenGL) then has to process those without the need to know the specific meaning of the parameters in a block.

 

Perhaps it is worth to mention that I use std140 layout. This makes things easier at least if the block is shared over many calls, like e.g. CameraSetup.

Okay so basically you avoid the whole problem of having to get a uniform buffer's index by making sure all shaders follow a naming convention for their uniform buffers. But what happens when I have a model which in the game, had something happen to it where before it was being rendered by a certain shader program but now were making it rendered by another shader program. This new shader program takes in 4 uniform buffers while the previous one took in 3. Do you just assume that while the renderable was being switched from one shader program to another, that whatever switched it knew it had to provide a new uniform buffer? It still seems weird to me that I can't get the uniform buffer requirments for each shader program by name.

 

I do it in the following way:

 

My UniformBuffer has a usage flag, which is "Default" or "Shared". Now we have 2 scenarios on using the UBO:

 

1) If the UniformBuffer usage is "Shared", then the UBO send an event to the ShaderManager to register this UBO to all the loaded shaders. In my engine it's guaranteed that all the shaders are pre-loaded, so when you create a shared UBO, it's also guaranteed that all the shaders will know about it. When the renderer is binding a shader, it also binds its registered UBOs.

 

2) If the UniformBuffer usage is "Default", then I manually register the UBO to whichever shader I want.

 

I use the std140 layout as well.

I am not sure if this approach is 100% correct though. Reading haegarr's approach makes me re-think of my design a bit.

I see, it still doesn't make sense how you would know if the uniform buffers provided fulfill the shader program requirments.


In Topic: Rendered Object disappears under Perspective Projection

27 September 2014 - 03:07 PM

Okay so I tried it and I found the issue with my code. When I had a value in the translation matrix for the object, it would disappear however when I tried your suggestion to put -10 to all z values, multiplying the vertices in the shader by just the projection matrix worked. So the issue had to be in the translation matrix since giving this any value in the z direction caused it to disappear. Turns out I didn't update the code in this matrix to use glm but instead I was setting the values manually and I probably made a mistake somewhere along the way. Changing that function made everything work properly in terms of the objects orientation :D. Thanks a lot!


In Topic: Game Actor and System Architecture

02 July 2014 - 08:02 PM

Hmm okay I'm starting to see a path through this. The perception idea is super cool but I probably don't need to implement something as complicated as that for my game in terms of touch, sound, smell etc with the stimuli. It is something I will want to look at in the future just because it sounds so cool and plays well with some other ideas I have bouncing around in my head. Okay so I think I figured out a nice way of organizing everything:

 

To start off, actors are as always just a id and a collection of components except now they are a collection of component id's instead of pointers. 

 

Components of each type are instead stored in each of their own component managers which might be just a list, a vector or a map. This would allow for future endeavors to compress the components since we know each component manager only holds variables of one component type. As an example, if my component manager holds orientation components for all actors, it could apply some sort of spacial optimization to all the components or reuse similar coordinates if such compression where ever needed. It also has the capability of being more data oriented although since my project isn't going to be huge, I'll just leave them as maps. Each component manager has to only implement simple methods like add/destroy component and get component manager type.

 

Components are same as always except now initialization will be a little different. So before, I just had a Init method for the actor to call Init on all components but now I added a post init which could be used to resolve all component dependencies. A orientation component won't have a dependency so its PostInit method will be empty. But something like a physics collision component could add in post init a dependency to the orientation by going through the owner actor pointer and searching for a component of type orientation. I could also have it add a collision response component/s which could be used to resolve collisions in the physics system when they happen. The benefit of post init is that we know all components are created, we are now just linking them together sort of like your program compiles everything, and then links. 

 

In PostInit, we could also attach our components to all the systems they have to be attached to. So a physics collision model could check to see if a orientation and collision response component exist on its current actor. If they do, it can link them up and attach itself to the physics system. Otherwise, it could signal an error or maybe run a default although I would rather signal an error.

 

As for BeerNutts method of solving the collisions, I think with the system I described above you could implement it since I sort of wrapped my head around settling dependencies between components. I do have two options however. I could make multiple collision responses for collision with different types of actors (although this creates a issue since a actor doesn't really have a type, its just a bundle of components). Or could make one large collision response component that handles multiple collision types. Both are a bit weird since a actor doesn't have a type. Would you somehow grab it from the collision model component which could potentially hold a type or add a type to each actor by default? 

 

There is another thing that bothers me that might be a bit more physics related but still something I think needs to be understood by me. Lets say two teleporters collide (yes this shouldn't ever happen but there could be other similar situations). Both objects have equal priority in terms of resolving the collision so which one would take priority and teleport the other to the teleporting location? Since its very likely two colliding actors will try to somehow resolve a collision, if both collision responses want to modify the other actor, it has to be somehow decided which one gets priority over the other and applies the modification first. 

 

I was also of thinking of just having a collision response actor that implements rigid body responses to collision, instead of having it in the physics system. That way, the physics system only ever worries about finding collisions and calling the appropriate collision response calls based on whatever priority. By doing so, the actor components technically implement all the systems while the system manages them to have everything work as a group.

 

Thanks for all the help so far!!

 

EDIT: Hmm, looking at it now, I think its better to skip having the component managers in the first place since for now, they don't really make a difference other than take extra implementation time. Maybe in the future I should add them in but everything else should apply as long as id's are changed to pointers.


In Topic: Abstract Class Deriving Upwards

21 June 2014 - 01:29 PM

Well thats embarrassing. Works fine now and loads the file properly :D Thanks a lot!


In Topic: Abstract Class Deriving Upwards

21 June 2014 - 12:11 AM

Okay I'm attempting to use templates now (never used them before) to get everything working but I'm getting a ton of errors regarding standard c++ files. So I have my Resource Manager and implementation over here for a text file:

//Resource Manager.h
	
	class IResource
	{
	protected:
		std::string m_filePath;

	public:
		virtual ~IResource () = 0;

		virtual bool VLoad (const std::string & sourcePath) = 0;
		virtual void VUnLoad () = 0;
	};

	class ResourceManager
	{
		std::map <std::string, IResource*> m_ResourceMap;
	public:

		template <class TResourceType>
		TResourceType* GetResource (const std::string & sourcePath)
		{
			if ( m_ResourceMap[sourcePath] != 0 )
			{
				return dynamic_cast <TResourceType*> (m_ResourceMap[sourcePath]);
			}

			TResourceType * pNewResource = new TResourceType();

			pNewResource->VLoad(sourcePath);
			m_ResourceMap[sourcePath] = pNewResource;
			return pNewResource;
		}
	};

//TextFile.h

	class TextFile : public IResource
	{
	private:
		char * m_pBuffer;
		std::string m_filePath;

	public:
		~TextFile ();

		virtual bool VLoad (const std::string & filePath);
		virtual void VUnLoad ();
		char* GetReadOnlyBuffer ();

	private:
		int GetFileSize (const std::string & filePath);
	};

//TextFile.cpp

#pragma once

#include "Text File.h"

	TextFile::~TextFile ()
	{
		if ( m_pBuffer != nullptr )
		{
			VUnLoad();
		}
	}

	bool TextFile::VLoad (const std::string & filePath)
	{
		m_filePath = filePath;
		unsigned int fileSize = GetFileSize(m_filePath);
		std::ifstream loadedFile (m_filePath, std::ios::in | std::ios::binary | std::ios::ate);

		//assert(fileSize > 0);
		//assert(m_pBuffer != nullptr);

		m_pBuffer = new char [fileSize];

		if ( loadedFile.is_open() )
		{
			loadedFile.seekg(0, std::ios::beg);
			loadedFile.read(m_pBuffer, fileSize);
			loadedFile.close();
		}

		//assert(loadedFile.fail());

		return true;
	}

	void TextFile::VUnLoad ()
	{
		//assert (m_pBuffer == nullptr);
		delete[] m_pBuffer;
		m_filePath = "";
	}

	char* TextFile::GetReadOnlyBuffer ()
	{
		return m_pBuffer;
	}

	int TextFile::GetFileSize (const std::string & filePath)
	{
		std::ifstream in(filePath.c_str(), std::ifstream::in | std::ifstream::binary);
		in.seekg(0, std::ifstream::end);
		return (int)(in.tellg()) + 1;
	}

The implementation is just a derivation of IResource which allows me to load and manipulate text files. I'm calling this from my main function like this:

		m_ResourceManager = ResourceManager ();

		TextFile * pTextFile = m_ResourceManager.GetResource<TextFile> ("test.txt");
		printf(pTextFile->GetReadOnlyBuffer()); //Make sure the file is loaded properly
		delete pTextFile;

I'm getting a ton of errors however about some stuff I'm assuming have to do with the parameters in the m_ResourceMap variable in Resource Manager:

1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\xtree(1885) : see declaration of 'std::operator <'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(124) : while compiling class template member function 'bool std::less<_Ty>::operator ()(const _Ty &,const _Ty &) const'
1>          with
1>          [
1>              _Ty=std::string
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\map(71) : see reference to class template instantiation 'std::less<_Ty>' being compiled
1>          with
1>          [
1>              _Ty=std::string
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\xtree(451) : see reference to class template instantiation 'std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,_Mfl>' being compiled
1>          with
1>          [
1>              _Kty=std::string,
1>              _Ty=IResource *,
1>              _Pr=std::less<std::string>,
1>              _Alloc=std::allocator<std::pair<const std::string,IResource *>>,
1>              _Mfl=false
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\xtree(520) : see reference to class template instantiation 'std::_Tree_nod<_Traits>' being compiled
1>          with
1>          [
1>              _Traits=std::_Tmap_traits<std::string,IResource *,std::less<std::string>,std::allocator<std::pair<const std::string,IResource *>>,false>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\xtree(659) : see reference to class template instantiation 'std::_Tree_val<_Traits>' being compiled
1>          with
1>          [
1>              _Traits=std::_Tmap_traits<std::string,IResource *,std::less<std::string>,std::allocator<std::pair<const std::string,IResource *>>,false>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\map(81) : see reference to class template instantiation 'std::_Tree<_Traits>' being compiled
1>          with
1>          [
1>              _Traits=std::_Tmap_traits<std::string,IResource *,std::less<std::string>,std::allocator<std::pair<const std::string,IResource *>>,false>
1>          ]
1>          c:\users\documents\visual studio 2010\projects\test\resource manager.h(20) : see reference to class template instantiation 'std::map<_Kty,_Ty>' being compiled
1>          with
1>          [
1>              _Kty=std::string,
1>              _Ty=IResource *
1>          ]
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\xtree(1885) : see declaration of 'std::operator <'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\xtree(1885) : see declaration of 'std::operator <'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::list<_Ty,_Ax> &,const std::list<_Ty,_Ax> &)' : could not deduce template argument for 'const std::list<_Ty,_Ax> &' from 'const std::string'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\list(1588) : see declaration of 'std::operator <'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::list<_Ty,_Ax> &,const std::list<_Ty,_Ax> &)' : could not deduce template argument for 'const std::list<_Ty,_Ax> &' from 'const std::string'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\list(1588) : see declaration of 'std::operator <'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::list<_Ty,_Ax> &,const std::list<_Ty,_Ax> &)' : could not deduce template argument for 'const std::list<_Ty,_Ax> &' from 'const std::string'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\list(1588) : see declaration of 'std::operator <'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::unique_ptr<_Ty,_Dx> &,const std::unique_ptr<_Ty2,_Dx2> &)' : could not deduce template argument for 'const std::unique_ptr<_Ty,_Dx> &' from 'const std::string'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\memory(2582) : see declaration of 'std::operator <'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::unique_ptr<_Ty,_Dx> &,const std::unique_ptr<_Ty2,_Dx2> &)' : could not deduce template argument for 'const std::unique_ptr<_Ty,_Dx> &' from 'const std::string'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\memory(2582) : see declaration of 'std::operator <'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::unique_ptr<_Ty,_Dx> &,const std::unique_ptr<_Ty2,_Dx2> &)' : could not deduce template argument for 'const std::unique_ptr<_Ty,_Dx> &' from 'const std::string'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\memory(2582) : see declaration of 'std::operator <'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::string'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(1356) : see declaration of 'std::operator <'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::string'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(1356) : see declaration of 'std::operator <'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::string'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(1356) : see declaration of 'std::operator <'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'const std::string'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(1179) : see declaration of 'std::operator <'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'const std::string'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(1179) : see declaration of 'std::operator <'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'const std::string'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\xutility(1179) : see declaration of 'std::operator <'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::string'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(318) : see declaration of 'std::operator <'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::string'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(318) : see declaration of 'std::operator <'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::string'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\utility(318) : see declaration of 'std::operator <'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\xfunctional(125): error C2676: binary '<' : 'const std::string' does not define this operator or a conversion to a type acceptable to the predefined operator

Is it because of the way I am initializing a new template type in GetResource that causes these errors? 


PARTNERS