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

Problem with Billboarding Instanced Particles

2 posts in this topic

Hello,

I am having a hard time billboarding my particles. I am following this tutorial:
[url="http://xnauk-randomchaosblogarchive.blogspot.de/2012/07/3d-billboard-particles-tutorial-vi.html"]http://xnauk-randomc...utorial-vi.html[/url]

The instancing is not a problem and works. I understand the formulas for billboarding given in the link, but when I implement them, the particles disappear. The difference in my implementation is that I represent the particles by a position only, while the tutorial uses world matrices.

Here is the relevant shader code:

[source lang="cpp"]
struct InstanceData
{
float4 Position : TEXCOORD1;
float4 Velocity : TEXCOORD2;
float4 Acceleration : TEXCOORD3;
float T0 : FOG0;
float T1 : FOG1;
};

struct VSInput
{
float4 Position : POSITION0;
float2 TextureCoordinate : TEXCOORD0;
};

struct VSOutput
{
float4 Position : POSITION0;
float2 TextureCoordinate : TEXCOORD0;
float Alpha : FOG0;
};

VSOutput InstancingVS(VSInput input, InstanceData instance)
{

VSOutput output = (VSOutput)0;

// Calculate the particle's position
float dt = T - instance.T0;
input.Position += instance.Position;
input.Position += dt * instance.Velocity;
input.Position += 0.5 * dt * dt * instance.Acceleration;

// start using float3 because we need cross products
float3 center = mul(input.Position, World); // looks fishy since input.Position is float4, but it works in the tutorial
float3 eyeVector = center - CameraPosition;

float3 pos = center;
float3 sideVector;
float3 upVector;
sideVector = normalize(cross(eyeVector, (float3)(0, 1, 0)));
upVector = normalize(cross(sideVector, eyeVector));


// Billboarding offset
pos += (input.TextureCoordinate.x - 0.5) * sideVector;
pos += (0.5 - input.TextureCoordinate.y) * upVector;

// pack into float4
float4 pos4 = (float4)(pos, 1);

pos4 = mul(pos4, View);
pos4 = mul(pos4, Projection);

output.Position = pos4;
output.TextureCoordinate = input.TextureCoordinate;
output.Alpha = (instance.T1 - T) / (instance.T1 - instance.T0);

return output;

}

float4 InstancingPS(VSOutput input) : COLOR0
{

float4 color = tex2D(TextureSampler, input.TextureCoordinate);

color.a = color.a * input.Alpha;

return color;

}
[/source]

Now, I suspect there is something wrong with float3/float4 mixture. For example, If I change line 50 to

[source lang="cpp"]
float4 pos4 = input.Position;
[/source]

the particles are drawn correctly, but without billboarding, which is expected. However, if I try

[source lang="cpp"]
float4 pos4 = (float4)(input.Position.xyz, 1);
[/source]

which I assumed to do basically the same thing, I see nothing.
Can somebody explain this? I don't see the difference between the these two lines (except for the w-compenent, which shouldn't matter, should it?). I have been fiddling with those conversions for two days now and I am very much lost.

Appreciating any help. Edited by FromShadow
0

Share this post


Link to post
Share on other sites
How about :

float4 pos4 = float4(input.Position.xyz, 1); //just to verify that it isn't question of syntax.

the w-component needs to 1 for the projection matrix multiplication to work correctly. If the w component is 0 then the result will be 0 too which isn't good.

By the standard, if your position is defined as 3-component vector from the program side and float4 in the shader side, the 4th component is automatically given value of 1.0.

float3 center = mul(input.Position, World); // There is nothing fishy here. The input.Position is multiplied by the 4x4 world matrix which doesn't affect the w-component typically. The cast of float4 to float3 works as intended ie. the xyz components are copied.

Cheers! Edited by kauna
0

Share this post


Link to post
Share on other sites
Feeling like a total scrub now. Your correction works.
The particles are visible now and do turn (arround some wrong axis, though).
I think I can safely work from here. ^^

Thanks a lot, and sorry for this stupidity.

Edit:
Here is the new shader with a workarround using the View matrix for the billdboard orientation.
This way I don't need to use float3 at all.

[source lang="cpp"]
VSOutput ParticleVS(VSInput input, InstanceData instance)
{

VSOutput output = (VSOutput)0;

float lifeTimeFactor = (instance.T1 - T) / (instance.T1 - instance.T0);
input.Position *= instance.Size * lifeTimeFactor;

// transform to Screenspace
float4x4 transform = transpose(View);
transform[3] = 0;
input.Position = mul(input.Position, transform);

// Calculate the particle's position
float dt = T - instance.T0;
input.Position += instance.Position;
input.Position += dt * instance.Velocity;
input.Position += 0.5 * dt * dt * instance.Acceleration;

float4 pos4 = mul(input.Position, World);
pos4.w = 1;
pos4 = mul(pos4, View);
pos4 = mul(pos4, Projection);

output.Position = pos4;
output.TextureCoordinate = input.TextureCoordinate;
output.Alpha = lifeTimeFactor;

return output;
}[/source]
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