• 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

Rendering blended stuff before skybox?

4 posts in this topic

Hi,

I played around with the order af drawing stuff and setting states in my engine.

There are 3 main to be rendered things:

 

1 - opaque objects

2 - blended objects

3 - skybox

 

Preferably I want to render things in that order, but when I do this, the blended objects disappear/ are not visible.

If I switch 3 and 2, skybox first, then blended objects, it looks all fine.

 

Does someone have an idea why this happens/ which state I'm overlooking?

Or maybe the order 1, 3 is 2 is better anyway? (and why?)

 

Here's the code, working:

	/** OPAQUE: RENDER SCENE USING BASE UBERSHADER **/
	mStateMachine.SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
	mStateMachine.SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
	mStateMachine.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
	mStateMachine.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);

	if(!RenderScene(*pD3dscene, "SingleTexTech", mRenderQueue.GetRefRenderablesOpaque(), mRenderQueue.GetRefBucketOpaque())) return false;
	
	/** RENDER SKYBOX **/ 
	if(pD3dscene->HasSkybox())
	{
		if(!pD3dscene->mSkyBox.Render(pCam->GetPosition(), *pCam)) return false;
		mStateMachine.SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
		mStateMachine.SetRenderState(D3DRS_ZWRITEENABLE, FALSE);										
		mStateMachine.SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
		mStateMachine.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_MIRROR);
		mStateMachine.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_MIRROR);
	}

	/** BLENDED: RENDER SCENE USING UBERSHADER **/
	mStateMachine.SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
	mStateMachine.SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
	mStateMachine.SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);

	if(!RenderScene(*pD3dscene, "SingleTexTech", mRenderQueue.GetRefRenderablesBlended(), mRenderQueue.GetRefBucketBlendedSorted())) return false;

And not working (blended objects first):

	/** OPAQUE: RENDER SCENE USING BASE UBERSHADER **/
	mStateMachine.SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
	mStateMachine.SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
	mStateMachine.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
	mStateMachine.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);

	if(!RenderScene(*pD3dscene, "SingleTexTech", mRenderQueue.GetRefRenderablesOpaque(), mRenderQueue.GetRefBucketOpaque())) return false;

	/** BLENDED: RENDER SCENE USING UBERSHADER **/
	mStateMachine.SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
	mStateMachine.SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
	mStateMachine.SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);

	if(!RenderScene(*pD3dscene, "SingleTexTech", mRenderQueue.GetRefRenderablesBlended(), mRenderQueue.GetRefBucketBlendedSorted())) return false;

	/** RENDER SKYBOX **/ 
	if(pD3dscene->HasSkybox())
	{
		if(!pD3dscene->mSkyBox.Render(pCam->GetPosition(), *pCam)) return false;
		mStateMachine.SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
		mStateMachine.SetRenderState(D3DRS_ZWRITEENABLE, FALSE);										
		mStateMachine.SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
		mStateMachine.SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_MIRROR);
		mStateMachine.SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_MIRROR);
	}

Edited by cozzie
0

Share this post


Link to post
Share on other sites

I would draw the skybox first since it should always be furthest in the background anyway and you should sort your opaque objects from back-to-front.

If you draw the skybox last, your transparent objects will only blend with opaque and other, previously drawn transparent ones, but not the skybox. This means they will get an edge around the transparent parts of the colour it was blended with which will be the render target clear colour in areas where only the skybox would be behind these objects. Of course this won't look pretty once the sky gets filled in to the non-transparent pixels surrounding those blended areas ;)

-1

Share this post


Link to post
Share on other sites

Actually with the code above, the blended objects are not visible at all.

I only get them visible in that rendering order, when I set D3DRS_ZWRITEENABLE to TRUE (instead of false). But then blending get's messed up.

Playing around so far didn't bring me the effect you're describing.

 

For now, I'll stick to opaque, skybox, transparent, since that gives the expected result (still don't understand though why I can't get the blended objects visible when rendering the skybox last). Switching skybox to 1 and then opaque works, but gives no difference (because I disable Z-write Always when drawing the skybox, and in the skybox shader is set pos.Z to pos.W so it's Always 1.

0

Share this post


Link to post
Share on other sites

Opaque geometry should be drawed from front to back and before any transparent objects. Sky box is opaque object so it has to be drawed before blended stuff.

2

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