• 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
TaintedGear

Particle geometry shader bill boarding problem

2 posts in this topic

Hi GameDev.

 

Im currently having a problem with my geometry shader in which i want to billboard my particles to face the camera. Currently the bill boarding seems to work from most angles, however when i go to close to the particles they warp, and when at a certain position in which i look at the particles the bill board effect stops entirely until i have moved again.

 

Pictures to show, because my explanation skills are atrocious: 

http://s720.photobucket.com/user/jbshadow1993/media/HELP.png.html

http://s720.photobucket.com/user/jbshadow1993/media/HELP2-1.png.html

 

In my eyes the calculation of the vectors for bill boarding is correct. However im skeptical about the need to multiply the new position of each vertex by the world matrix, as that had already been done in the vertex shader and been assigned to each new vertex generated.

 

Here is both vertex shader and geometry shader, hopefully its something stupid that i have missed or not understood correctly.

Any help is greatly appreciated. biggrin.png

cbuffer cbNeverChanges : register( b0 ) 
{ 
	matrix g_view; 
}; 
 
cbuffer cbChangeOnResize : register( b1 ) 
{ 
	matrix g_proj; 
}; 
			
//Camera position to work out billboarding
cbuffer cbCameraPos : register( b2 )
{
	float4 g_camPos;
};
			 
struct VS_Input 
{ 
	float4 pos : POSITION; 
	float2 tex0 : TEXCOORD0; 
	float4x4 InstWorld : WORLD; 
	float Size : SIZE; 
	uint InstID : SV_InstanceID; 
}; 
			 
struct GS_Input 
{ 
	float4 posL : POSITION1; 
	float4 posH : POSITION2; 
	float2 tex0 : TEXCOORD0; 
	float4x4 InstWorld : WORLD; 
	float Size : SIZE; 
}; 
		
struct GS_Output  
{  
	float4 Pos : SV_POSITION;  
	float2 TexCoords : TEXCOORD0;  
};  
	
		
GS_Input VS( VS_Input vertex ) 
{ 
	GS_Input vsOut = ( GS_Input )0; 
	
	//Transform the vertex position
	vsOut.posL = mul( vertex.pos, vertex.InstWorld ); 
	vsOut.posH = mul( vsOut.posL, g_view ); 
	vsOut.posH = mul( vsOut.posH, g_proj ); 
	
	//Assign size so that it can be used in the gs 
	vsOut.Size = vertex.Size; 
	vsOut.InstWorld = vertex.InstWorld; 
	vsOut.tex0 = vertex.tex0; 
			 
	return vsOut; 
} 
			 		
[maxvertexcount(4)]  
void GS(point GS_Input input[1], inout TriangleStream<GS_Output> outputStream) 
{  
	//calculate the look at vector
	float3 lookVec = (float3)g_camPos - (float3)input[0].posL;
	lookVec = normalize(lookVec);
			
	//assign the up vec
	float3 upVec = float3(0.0f, 1.0f, 0.0f);
				
	//Calculate the right vector
	float3 rightVec = normalize(cross(upVec, lookVec));
				
	// To use so that the particle will rotate around its centre
	float halfSize = input[0].Size / 2.0f;
				
	//Get the up vector of the quad
	float3 quadUpVec = normalize(cross(lookVec, rightVec)); 

//Times it by  half the size to build quad from around the center
	quadUpVec = quadUpVec * halfSize; 
	rightVec = rightVec * halfSize;
				
	// Create the positions of the quad
	float3 position[4]; 
	//Top Left
	position[0] = (float3)input[0].posL - rightVec + quadUpVec;
	//Top Right
	position[1] = (float3)input[0].posL + rightVec + quadUpVec;
	//Bottom Left
	position[2] = (float3)input[0].posL - rightVec - quadUpVec;
	//Bottom Right
	position[3] = (float3)input[0].posL + rightVec - quadUpVec;
				
	float2 texcoords[4]; 
	texcoords[0] = float2(1.0f, 0.0f); 
	texcoords[1] = float2(1.0f, 1.0f); 
	texcoords[2] = float2(0.0f, 0.0f); 
	texcoords[3] = float2(0.0f, 1.0f); 
	
	GS_Output newVertex; 
	for(int k = 0; k < 4; k++) 
	{ 
		//Assign position 
		newVertex.Pos = mul(float4(position[k], 1.0f), input[0].InstWorld); 
		newVertex.Pos = mul(newVertex.Pos, g_view); 
		newVertex.Pos = mul(newVertex.Pos, g_proj); 
		newVertex.TexCoords = texcoords[k]; 
		
		outputStream.Append(newVertex); 
	} 
} 

Thanks 

 

TaintedGear ph34r.png

1

Share this post


Link to post
Share on other sites

UPDATE: I fixed the problem!

 

The warping was due to the fact that i was using a free look camera however setting an arbitrary up value with 1 in the Y. So it was not creating the correct right vector for the quad. And the other problem was because i was basically doubling up on its world matrix multiplication, as i was assigning the value already multiplied in the vertex shader to the new points of the quads and then multiplying it again before i append the new vertex.

 

Silly me tongue.png

2

Share this post


Link to post
Share on other sites

Hi GameDev.

 

Im currently having a problem with my geometry shader in which i want to billboard my particles to face the camera. Currently the bill boarding seems to work from most angles, however when i go to close to the particles they warp, and when at a certain position in which i look at the particles the bill board effect stops entirely until i have moved again.

 

Pictures to show, because my explanation skills are atrocious: 

http://s720.photobucket.com/user/jbshadow1993/media/HELP.png.html

http://s720.photobucket.com/user/jbshadow1993/media/HELP2-1.png.html

 

In my eyes the calculation of the vectors for bill boarding is correct. However im skeptical about the need to multiply the new position of each vertex by the world matrix, as that had already been done in the vertex shader and been assigned to each new vertex generated.

 

Here is both vertex shader and geometry shader, hopefully its something stupid that i have missed or not understood correctly.

Any help is greatly appreciated. biggrin.png

cbuffer cbNeverChanges : register( b0 ) 
{ 
	matrix g_view; 
}; 
 
cbuffer cbChangeOnResize : register( b1 ) 
{ 
	matrix g_proj; 
}; 
			
//Camera position to work out billboarding
cbuffer cbCameraPos : register( b2 )
{
	float4 g_camPos;
};
			 
struct VS_Input 
{ 
	float4 pos : POSITION; 
	float2 tex0 : TEXCOORD0; 
	float4x4 InstWorld : WORLD; 
	float Size : SIZE; 
	uint InstID : SV_InstanceID; 
}; 
			 
struct GS_Input 
{ 
	float4 posL : POSITION1; 
	float4 posH : POSITION2; 
	float2 tex0 : TEXCOORD0; 
	float4x4 InstWorld : WORLD; 
	float Size : SIZE; 
}; 
		
struct GS_Output  
{  
	float4 Pos : SV_POSITION;  
	float2 TexCoords : TEXCOORD0;  
};  
	
		
GS_Input VS( VS_Input vertex ) 
{ 
	GS_Input vsOut = ( GS_Input )0; 
	
	//Transform the vertex position
	vsOut.posL = mul( vertex.pos, vertex.InstWorld ); 
	vsOut.posH = mul( vsOut.posL, g_view ); 
	vsOut.posH = mul( vsOut.posH, g_proj ); 
	
	//Assign size so that it can be used in the gs 
	vsOut.Size = vertex.Size; 
	vsOut.InstWorld = vertex.InstWorld; 
	vsOut.tex0 = vertex.tex0; 
			 
	return vsOut; 
} 
			 		
[maxvertexcount(4)]  
void GS(point GS_Input input[1], inout TriangleStream<GS_Output> outputStream) 
{  
	//calculate the look at vector
	float3 lookVec = (float3)g_camPos - (float3)input[0].posL;
	lookVec = normalize(lookVec);
			
	//assign the up vec
	float3 upVec = float3(0.0f, 1.0f, 0.0f);
				
	//Calculate the right vector
	float3 rightVec = normalize(cross(upVec, lookVec));
				
	// To use so that the particle will rotate around its centre
	float halfSize = input[0].Size / 2.0f;
				
	//Get the up vector of the quad
	float3 quadUpVec = normalize(cross(lookVec, rightVec)); 

//Times it by  half the size to build quad from around the center
	quadUpVec = quadUpVec * halfSize; 
	rightVec = rightVec * halfSize;
				
	// Create the positions of the quad
	float3 position[4]; 
	//Top Left
	position[0] = (float3)input[0].posL - rightVec + quadUpVec;
	//Top Right
	position[1] = (float3)input[0].posL + rightVec + quadUpVec;
	//Bottom Left
	position[2] = (float3)input[0].posL - rightVec - quadUpVec;
	//Bottom Right
	position[3] = (float3)input[0].posL + rightVec - quadUpVec;
				
	float2 texcoords[4]; 
	texcoords[0] = float2(1.0f, 0.0f); 
	texcoords[1] = float2(1.0f, 1.0f); 
	texcoords[2] = float2(0.0f, 0.0f); 
	texcoords[3] = float2(0.0f, 1.0f); 
	
	GS_Output newVertex; 
	for(int k = 0; k < 4; k++) 
	{ 
		//Assign position 
		newVertex.Pos = mul(float4(position[k], 1.0f), input[0].InstWorld); 
		newVertex.Pos = mul(newVertex.Pos, g_view); 
		newVertex.Pos = mul(newVertex.Pos, g_proj); 
		newVertex.TexCoords = texcoords[k]; 
		
		outputStream.Append(newVertex); 
	} 
} 

Thanks 

 

TaintedGear ph34r.png

 

Inside my editor I have the default editor camera set to free camera - so it's not a real issue. You fixed it and that's awesome. You wanted the particle camera to always face the camera like a world of billboard trees or anywhere the camera is facing? Try this but if you decided not to it's okay.

//-- Calculate look at vector
float3 planeNormal = input[0].posL.xyz - g_camPos.xyz;
planeNormal.y = 0.0f; //-- This allows the particle to be aligned the Y Axis when moving around with free camera. 
planeNormal = normalize(planeNormal);
float3 upVector = float3(0,1,0);
float3 rightVector = normalize(cross(planeNormal, upVector);
rightVector = rightVector * 2.0f;

//-- Carry on with the rest of your geometry shader code when you append to output.

In your case the rightVector = rightVector * 2.0f will be just what you have in your shader code. The only thing mine will do is make sure it's always facing the camera but aligned on the Y axis. So, if I look go up or down then look at it - it will stay won't rotate on the Y Axis. You're may be different though because the effect you want. I got the billboard shader code from BrayzenSoft and thought you did too as well. Other than that if it works it works! I don't see how the free camera would mess up the calculation but more likely the doubling of the matrix when you output the geometry. I use to have my follow the camera and stretch in all weird funny positions. I'm glad you got it fixed though!

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