• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
cozzie

Scenegraph redesign and improving the draw 'loop'

3 posts in this topic

Hi,

 

I've decided to fully redesign my scenegraph/ renderqueue, meaning completely starting over from scratch.

Adding stuff on and on even makes it difficult for myself to understand the current approach and code.

 

New approach:

- make 2 'buckets' of renderables, opaque and blended

- simply loop through the buckets in my 2 main drawing functions

- the scenegraph will use the d3dscene class and it's objects and only saves ID's and other parameters dependent on actual rendering

 

First (pseudo) code:

typedef struct Q_Renderable
{
	unsigned int	Effect;
	unsigned int	Material;
	unsigned int	Mesh;
	unsigned int	Instance;
	unsigned int	Id;				// subset/ renderable of the mesh
	// bool			Visible;
}

class CSceneGraph
{
public:
	void Update(const Crealysm_d3drenderer::CD3dscene *pD3dscene);

	std::vector<Q_Renderable>	mOpaqueBucket;
	std::vector<Q_Renderable>	mBlendedBucket;

private:
	std::vector<Q_Mesh>		mMeshes;
	std::vector<Q_Material>	mMaterials;
	std::vector<Q_Instance>	mInstances;
	std::vector<Q_Light>	mLights;
	// etc., saves ID's, visibility state after culling, distances etc.
	
	// functions to update the renderables buckets, based on visibility, sorting, culling etc.
	// etc.
}

Then in the drawing function my approach is something like this:

bool CD3d::RenderSceneOpaque(const char *pTechnique, const CD3dcam &pCam)
{
	/** retrieve the 1st element from bucket and set all buffers/ shader constants **
	Q_Renderable last = mSceneGraph.mOpaqueBucket[0];
	
	ShaderSetTechnique(last.Effect, pTechnique);
	mD3dscene->mShaders[last.Effect].Begin();
	mD3dscene->ShaderSelectMaterial(last.Material, lastEffect);
	mD3dscene->mMeshes[last.Mesh].SetBuffers();
	mD3dscene->ShaderSetWorld(last.Instance, lastId);

	bool bucketDone = false;
	bool nextEffect = false;
	int renderable = 0;

	while(!bucketDone)
	{
		auto &next = mSceneGraph.mOpaqueBucket[renderable];
		if(next.Effect != last.Effect) 
		{
			mD3dscene->mShaders[last.Effect].End();

			ShaderSetTechnique(next.Effect, pTechnique);
			mD3dscene->mShaders[next.Effect].Begin();
			nextEffect = false;
		}

		for(unsigned int p=0;p<shader.GetNumPasses();++p)
		{
			mD3dscene->mShaders[next.Effect].BeginPass(p);

			if(next.Material	!= last.Material)	mD3dscene->ShaderSelectMaterial(next.Material, lastEffect);
			if(next.Mesh		!= last.Mesh)		mD3dscene->mMeshes[next.Mesh].SetBuffers();

			mD3dscene->ShaderSetWorld(next.Instance, next.Id);
			mD3dscene->mShaders[next.Effect].Commit();
			mD3dscene->mMeshes[next.Mesh].RenderSubMesh(next.Id, LIST);	// does the draw call
			mD3dscene->mShaders[next.Effect].EndPass(p);
		}
		last = mSceneGraph.mOpaqueBucket[renderable];	
		++renderable;

		if(renderable = (int)mSceneGraph.mOpaqueBucket.size()) bucketDone = true;
	}
}

(Nb. 1: I'm aware that this assumes all my effect files have a shared technique name)

(Nb. 2: I've left out error checking/ returning false to keep it readable for now)

 

My questions/ I'm curious about your opinion on:

1 - the approach itself

2 - although it might sound like 'pre optimization'/evil, would you store only visible renderables in the bucket, or do a 'if(visible)' check in the drawing loop? (more cpu activity per frame or maybe not). Only visibles gives a cleaner code draw loop for sure.

3 - what are your suggestions to 'clean' the somewhat ugly main drawing loop?

(it feels like it could be done easier and/or more efficiently)

 

Any input is appreciated.

Edited by cozzie
0

Share this post


Link to post
Share on other sites

I like the idea of buckets, however that is a renderer-specific thing, which should not fall in the scenegraph design really.

You should separate the scenegraph from rendering, the scenegraph is handling the scene hierarchy, culling, and so on.

 

Rendering is better to be separate from that process.

As a side-note, you may want to add render-order functionality to your engine, so that you can define the rendering order of different materials.

0

Share this post


Link to post
Share on other sites

culling, and so on

It most certainly is not.
Scene Graphs

And here it is not implemented correctly. It is not a structure/class in itself. It is simply the fact that the most base class of all game entities has a parent-child relationship with itself. Meaning up to 1 parent and an array of children.


It is however correct to have 2 different render queues: One for opaques and one for translucents. But this is also unrelated to the scene graph. Read my link.

A scene manager has a list of scene objects as well as some form of spacial structure containing them all.
The scene objects between themselves create a scenegraph, apart from the scene manager/scene itself.
The scene manager uses as many render-queue pairs (solid/non-solid) instances as it needs (one for the main scene, one or more for each shadow-casting light, etc.) and handles culling and rendering (after the render queues sort) by itself on a high level.


L. Spiro
0

Share this post


Link to post
Share on other sites

Thanks both. Here's a bit more background on what I do at the moment:

- scene is loaded into a d3dscene object

- the d3dscene object has member vectors of d3dmesh, d3dmeshinstance, d3dlight, d3dmaterial etc. objects

- these objects keep all the properties of the meshes, instances, lights etc.

 

- then I have one 'scenegraph' object, which keeps the ID's, visibility state etc. of meshes, instances, materials, light etc.

(results of culling are also stored in there)

- based on this information, I 'rebuild' the two buckets, sorting etc.

 

The main render function uses the two buckets to render the frame.

Where the used ID's in the buckets match the ID's of the materials, meshes, instances etc. in the d3dscene object

 

Though I'm not sure if this would be the 'ideal' way to go, but it works quite fine and gives me the flexibility I need (up till now).

If I wanted to change rendering order or order things I just fill the buckets differently and keep my main draw function the same).

 

Besides the naming/ design, can you give me some pointers on how you would 'improve' the concept draw function?

(both and readabillity as efficiency). It doesn't quit feel çlean'.

 

update

@LSpiro; I've read the article, really clears things up. My conclusion is that up till now I've been only working on a renderqueue and not even have a scenegraph :)

To keep it clean I'll do some name changing in my engine codebase.

Really like to hear your opinions also on the draw function for rendering a bucket.
Below the improved version, with less 'data copying' which is not needed obvisously:

bool CD3d::RenderScene(const char *pTechnique, const CD3dcam &pCam, std::vector<Q_Renderable &pRenderBucket)
{
	/** retrieve the 1st element from bucket and do all bindings **
	Q_Renderable *last = &pRenderBucket[0];

	ShaderSetTechnique(last.Effect, pTechnique);
	mD3dscene->mShaders[last.Effect].Begin();
	mD3dscene->ShaderSelectMaterial(last.Material, lastEffect);
	mD3dscene->mMeshes[last.Mesh].SetBuffers();
	mD3dscene->ShaderSetWorld(last.Instance, lastId);
	
	bool bucketDone = false;
	int renderable = 0;

	while(!bucketDone)
	{
		auto &next = &pRenderBucket[renderable];
		if(next.Effect != last.Effect) 
		{
			mD3dscene->mShaders[last.Effect].End();

			ShaderSetTechnique(next.Effect, pTechnique);
			mD3dscene->mShaders[next.Effect].Begin();
		}

		for(unsigned int p=0;p<shader.GetNumPasses();++p)
		{
			mD3dscene->mShaders[next.Effect].BeginPass(p);

			if(next.Material	!= last.Material)	mD3dscene->ShaderSelectMaterial(next.Material, lastEffect);
			if(next.Mesh		!= last.Mesh)		mD3dscene->mMeshes[next.Mesh].SetBuffers();

			mD3dscene->ShaderSetWorld(next.Instance, next.Id);
			mD3dscene->mShaders[next.Effect].Commit();

			mD3dscene->mMeshes[next.Mesh].RenderSubMesh(next.Id, LIST);	// does the draw call
			mD3dscene->mShaders[next.Effect].EndPass(p);
		}
		last = &&pRenderBucket[renderable];	
		++renderable;

		if(renderable == (int)&pRenderBucket.size()) bucketDone = true;
	}
}

I've tried to get rid of doing the bindings of the first renderable outside the loop, but didn't manage this so far, because in that case I'll be trying to 'end' an effect which was not started at all with 'begin'.

Edited by cozzie
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0