Jump to content

  • Log In with Google      Sign In   
  • Create Account


Focusrite

Member Since 06 Apr 2011
Offline Last Active May 04 2012 12:17 PM

Topics I've Started

Stencil test and shader

20 April 2012 - 01:43 PM

Hello Gamedev,
I'm working on a 2d shadow system (by drawing to an alpha layer texture, which blends the world accordingly) and require a stencil test to make multiple light sources to work propperly.
However, there's an issue with the stencil test when it passes through the shader, it still renders. The "algorithm" used is:
  • Draw point light onto stencil.
  • Apply shadow (ie. remove the drawn light where it does not reach, behind walls etc)
  • Render the point light to the alpha layer where stencil allows (ie. where shadows haven't removed)
The render, step 3, has to pass through the shader and isn't blocked by the stencil, and it's completely rendered onto the alpha layer, is there any way you can make the shader too be blocked by the stencil test?

Regards
Focusrite Posted Image

DirectX polygons

21 March 2012 - 10:21 AM

Hey Gamedev!

I need to render 2d polygons and thus came up with this solution:

if(FAILED(gd3dDevice->CreateVertexBuffer(sizeof(RectVertex) *32, D3DUSAGE_DYNAMIC, 0, D3DPOOL_DEFAULT, &mVB_Rect, NULL)))
  MessageBox(0, "Error creating RectVertex buffer", 0, 0); //Slightly misleading name, it's a vertexdefiniton containing just position and color

//----------

void Graphics::drawPolygon(cPolygon* shape, D3DCOLOR color, bool filled)
{
	if(shape->requireTriangulation())
		shape->triangulate(); //Triangulates the polygon if not already done - stores in "shape->triangles"

	// Set vertex declaration and stream source
	gd3dDevice->SetVertexDeclaration(RectVertex::Decl);
	gd3dDevice->SetStreamSource(0, mVB_Rect, 0, sizeof(RectVertex));

	// Lock and set the vertices position and texture coordinates
	RectVertex *vertices = 0;
	mVB_texture->Lock(0, 0, (void**)&vertices, 0);

	for(int i = 0; i<shape->getTriangles().size()/3; i++)
	{
		vertices[i*3+0].color = color;
		vertices[i*3+0].pos.x = shape->getTriangles()[i*3+0].x + shape->getPos().x; //Due to triangles beeing in local coordinates
		vertices[i*3+0].pos.y = shape->getTriangles()[i*3+0].y + shape->getPos().y;
		vertices[i*3+0].pos.z = 0.0f;

		vertices[i*3+1].color = color;
		vertices[i*3+1].pos.x = shape->getTriangles()[i*3+1].x + shape->getPos().x;
		vertices[i*3+1].pos.y = shape->getTriangles()[i*3+1].y + shape->getPos().y;
		vertices[i*3+1].pos.z = 0.0f;

		vertices[i*3+2].color = color;
		vertices[i*3+2].pos.x = shape->getTriangles()[i*3+2].x + shape->getPos().x;
		vertices[i*3+2].pos.y = shape->getTriangles()[i*3+2].y + shape->getPos().y;
		vertices[i*3+2].pos.z = 0.0f;
	}
	// Unlock the vertex buffer
	mVB_texture->Unlock();

	if(filled)
		gd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
	else
		gd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
	
	// Draw image
	gd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, shape->getTriangles().size()/3);
}


But it doesn't render at all! If i debug, it's ran, and the shape has the values it is supposed to have.
I do not believe the triangulation is the issue, it was not originally written by me, and on debug it gives *very* plausable results.

The (only slightly modded) triangulation technique here: http://www.flipcode....ngulation.shtml

Anyone have any clue on why it does not work?

Thanks in advance!
- Focusrite

Setup, DXTrace and other fun stuff

20 April 2011 - 04:46 PM

Hey GameDev,
as a first time poster I figured another of those pesky problems could be in order! I recently upgraded to windows 7/VC10 from my ol' buddy XP and getting directX was in order. Everything was installed and a test project was created (Frank Luna's "Hello World!" App), libraries/includes set up et al. (Libraries: d3d9.lib, d3dx9d.lib, dxguid.lib, DxErr.lib, dinput8.lib).

Onwards to compiling were things doesn't exactly go very well - DXTrace is apparently an unresolved external! I've figured this is due to the character set used (Multi-byte) but changing this causes problems elsewhere in the project due to wrong the wrong character set. At some places things can be fixed with that _T macro (when using Unicode) but at some places I can't seem to sort it out without causing new problems and errors. Google was to little help, not many seems to have had this problem.

Thanks in advance
Focusrite

Error 2 error LNK2019: unresolved external symbol _DXTraceA@20 referenced in function "public: virtual void __thiscall D3DApp::initDirect3D(void)" (?initDirect3D@D3DApp@@UAEXXZ) D:\Dokument\Viktor\VC\Projects\Nyctophobia\Nyctophobia\d3dApp.obj
Error 4 error LNK2019: unresolved external symbol _Direct3DCreate9@4 referenced in function "public: virtual void __thiscall D3DApp::initDirect3D(void)" (?initDirect3D@D3DApp@@UAEXXZ) D:\Dokument\Viktor\VC\Projects\Nyctophobia\Nyctophobia\d3dApp.obj
Error 5 error LNK2019: unresolved external symbol _D3DXCreateFontIndirectA@12 referenced in function "public: __thiscall HelloD3DApp::HelloD3DApp(struct HINSTANCE__ *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,enum _D3DDEVTYPE,unsigned long)" (??0HelloD3DApp@@QAE@PAUHINSTANCE__@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@W4_D3DDEVTYPE@@K@Z) D:\Dokument\Viktor\VC\Projects\Nyctophobia\Nyctophobia\HelloDirect3D.obj
Error 3 error LNK2001: unresolved external symbol _DXTraceA@20 D:\Dokument\Viktor\VC\Projects\Nyctophobia\Nyctophobia\HelloDirect3D.obj
Error 6 error LNK1120: 3 unresolved externals D:\Dokument\Viktor\VC\Projects\Nyctophobia\Debug\Nyctophobia.exe


PS: It's DX9 btw, since the book by Luna is written for 9c (It's the "a shaders approach" edition). Why I really want to get this to work is because the whole book is based on this framwork! (The framework can be read here: http://www.dreaminco...irectx-part-ii/) DS

Edit: Might be worth noting that I've had it up and running previously on XP/VC08.

PARTNERS