Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 17 Dec 2012
Offline Last Active Feb 16 2014 10:34 PM

Topics I've Started

Can you use alpha to coverage with instancing and a geometry shader?

29 November 2013 - 09:11 PM



I am trying to set up alpha to coverage in DirectX 11. I am currently rendering a particle system using instancing and a geometry shader, so that I pass in a point (1 vert) to render all the particles of that particle system. This is what it looks like:




I'm trying to set up alpha to coverage but I can't seem to do so. I am getting a problem where it renders a black quad at the particle systems position


Here is the Alpha to coverage blend state:

D3D11_BLEND_DESC alphaToCoverageDesc = {0};
alphaToCoverageDesc.AlphaToCoverageEnable = true;
alphaToCoverageDesc.IndependentBlendEnable = false;
alphaToCoverageDesc.RenderTarget[0].BlendEnable = false;
alphaToCoverageDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;

result = device->CreateBlendState(&alphaToCoverageDesc, &AlphaToCoverageBS);

And this is what it looks like:



Even when I try to imitate it within the pixel shader with dithering it produces a similar error:




So I was wondering if it has anything to do with instancing or the geometry shader? I can't imagine it is but I have no idea. Any one think of any reason for this. 

If this is too vague just say


Shader (LPD3DXEFFECT) crashes when setting my Matrix

19 February 2013 - 11:12 PM



I am trying to get a shader to give an effect over sprites I draw. Currently I don't have the shader altering the sprites, I'm just trying to test that it works/compiles. 


Here is my TestShader.fx:


// World * View * Projection matrix
float4x4 g_mWorldViewProjection : WORLDVIEWPROJECTION;
float4x4 g_mWorld : WORLD;

texture g_SpriteTexture; //What Sprite('s Texture) to use

sampler SpriteSampler = 
    Texture = <g_SpriteTexture>;
    MipFilter = WRAP;
    MinFilter = WRAP;
    MagFilter = WRAP;

float4 PixelShaderFunction(float2 texCoord : TEXCOORD0) : COLOR
    //return float4(1, 0, 0, 1);  Turn every pixel red
	float4 color = tex2D(SpriteSampler, texCoord);  
	//color.gb = color.r; //make texture GreyScale
	return color;  
technique DefaultTechnique //Renders The current Sprite as is
    pass Pass1  
        PixelShader = compile ps_2_0 PixelShaderFunction();  


 Then I create it like so:


	//==== Load in our shader:
	wchar_t *str1 = L"TestShader.fx";
	DWORD dwShaderFlags = 0;
	//Create The First Shader
	if (FAILED(D3DXCreateEffectFromFile( g_pd3dDevice, str1, NULL, NULL, dwShaderFlags, NULL, &g_pTestShader, &pErrors ) ))
		if (pErrors != NULL)
			char *errorString = (char*)pErrors->GetBufferPointer();
			MessageBox( NULL, L"Could not Create Test Shader", L"Textures1.exe", MB_OK );
            //return E_FAIL;
		//return E_FAIL;




Then I try to set it's Matrix, but it crashes my program. I get an error:

Unhandled exception at 0x76fc15de in Sprites.exe: 0xC0000005: Access violation reading location 0x00000000.


g_pTestShader->SetMatrix( "g_mWorldViewProjection", &Cam.GetWorldViewProj());


The above line is the only code that tries to use my shader object and it crashes it.


Any ideas why?



ID3DXLine to world space (instead of screen)

06 February 2013 - 04:53 AM



I am using the LPD3DXLINE class. I have 2D sprites being rendered and each sprite has a physics object (4 verlets), I am trying to use the LPD3DXLINE class to Draw lines between each physics verlet/vertex. 


But when I pass the physics variables (world space) to the Line-> draw(); function it draws the lines in places I don't want (pixel/screen space, I think)


Here is what I mean:




There should be a red line around each sprite, (the bottom left corner is my world's (0,0)  so when it draws (0,0) it does it from the top left (the screens (0,0)).


So I assume this is a matrix problem? So do I need to give the LPD3DXLINE my view*world*porj matrix?


The LPD3DXLINE->DrawTransform(); function takes D3DVECTOR3 but the ->Draw(); uses a D3DVECTOR2 so I'm confused what to put here?


Or is it somehing else I'm doing wrong? 


Here is the code for drawing the lines (if it helps):


	D3DXCreateLine(g_pd3dDevice, &myLine);
	for (int i = 0; i < PhysicsWorld.GetBodyCount(); i++)
		int size = PhysicsWorld.Bodies[i]->VertexCount;

		//int* array=new int[len];
		D3DXVECTOR2* Vetecies = new D3DXVECTOR2[size];
		for (int j = 0; j < PhysicsWorld.Bodies[i]->VertexCount; j++)
			Vetecies[j].x =  PhysicsWorld.Bodies[i]->Vertices[j]->Position.x;
			Vetecies[j].y =  PhysicsWorld.Bodies[i]->Vertices[j]->Position.y;
		//myLine->DrawTransform(Vetecies, PhysicsWorld.Bodies[i]->VertexCount, , 
		myLine->Draw( Vetecies, PhysicsWorld.Bodies[i]->VertexCount, D3DCOLOR_ARGB( 255, 255, 0, 0 ));
		delete Vetecies;
		Vetecies = NULL;




Sprite (quad) that uses 1 texture repeated multiple times

31 January 2013 - 08:33 PM



I have a program that creates a sprites using quads in a vertex buffer. 


I'm wondering if it is possible to instead of creating multiple quads side by side it is possible to make them 1 quad the re-uses the texture drawn and repeat it multiple times?


e.g. Using the image below I'm trying to achieve b) using the Sprite, instead of  doing a), which uses 4 quads instead of 1 






How would I achieve this?


If this is hard to explain without my Texture/sprite code, I can post it if it makes it easier. 



Set class (member) pointer to a existing class (to allow editing)

27 January 2013 - 09:16 AM



I have two classes. I am trying to get the 2nd class to have a member pointer that points to an instance of the first class (Giving the 2nd class the ability to edit an instance of the first class) . But I am unsure how to set this up (when I use it the values I try to edit don't change) 


Here is what I have tried:

class A

class B
 void SetMemberPointer(*A _a)  {m_MemberB = _a;}
 A* m_MemberB

void main()
 A Class1;
 B Class2;




Can some one explain why this doesn't work/help with a solution?