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

Billboarding

3 posts in this topic

I been long searching hard for the right code to do proper billboarding regardless of camera angle used. I tried a few samples but found that they either don't seem to work right in certain camera angles, or only billboard for me when I translate the camera around the world with camera angles not having any affect on them billboardwise, cause when I rotate the camera it still rotates the polygon when its not suppose to, Then finally I found some useful code over on this site [url="http://www.mvps.org/directx/articles/view_oriented_billboards.htm"]http://www.mvps.org/..._billboards.htm[/url] . This works flawlessly regardless of camera angle and position. However there is just one problem. I do not like the fact I'm stuck having to work with a diamond shaped polygon. I tried making it just a regular square but everything I tried fails. Even tried rotating the poly itself by its Z axis 45 degrees but then I end up losing the billboard effect. Is there anyway I can use this technique and work with regular squares / rectangles rather than the "diamond" that microsoft was using? Thanks in advance.
0

Share this post


Link to post
Share on other sites
I found a simple solution to this. Here is how I build the 4 vertices of each quad when I fill an array of particles:
[CODE]
#region setting up verts
int si = i * 4;
float age = pData[i + offset].age;
int z = nDrawn & 1;
float rev = ( z == 1 ) ? -1f : 1f;
Matrix rotm = Matrix.CreateRotationZ(age * 5f * rev);
// point sprite style rendering - use the first 2 points of the normal to encode the coordinates,
// relative to the Position, of each of the 4 verts
// use the 3rd component of the normal to encode the age, for shaders to apply their own age dependent logic
StaticBuffer[si].Position = pData[i + offset].pos;
StaticBuffer[si].TextureCoordinate.X = 0;
StaticBuffer[si].TextureCoordinate.Y = 0;
StaticBuffer[si].Normal.X = -0.5f;
StaticBuffer[si].Normal.Y = -0.5f;
StaticBuffer[si].Normal.Z = age;
si++;
StaticBuffer[si].Position = pData[i + offset].pos;
StaticBuffer[si].TextureCoordinate.X = 1;
StaticBuffer[si].TextureCoordinate.Y = 0;
StaticBuffer[si].Normal.X = 0.5f;
StaticBuffer[si].Normal.Y = -0.5f;
StaticBuffer[si].Normal.Z = age;
si++;
StaticBuffer[si].Position = pData[i + offset].pos;
StaticBuffer[si].TextureCoordinate.X = 1;
StaticBuffer[si].TextureCoordinate.Y = 1;
StaticBuffer[si].Normal.X = 0.5f;
StaticBuffer[si].Normal.Y = 0.5f;
StaticBuffer[si].Normal.Z = age;
si++;
StaticBuffer[si].Position = pData[i + offset].pos;
StaticBuffer[si].TextureCoordinate.X = 0;
StaticBuffer[si].TextureCoordinate.Y = 1;
StaticBuffer[si].Normal.X = -0.5f;
StaticBuffer[si].Normal.Y = 0.5f;
StaticBuffer[si].Normal.Z = age;
#endregion
[/CODE]

See how I am encoding the distance from the centre of the billboard into the X and Y of its normal. If I came up with my own vertex format this wouldnt be necessary, and there are other ways.

My shader is very simple; only the vertex shader has anything notable in it:

[CODE]
output.Position = mul( mul( mul(input.Position, matWorld) , matView), matProjection) + float4(input.Normal.xy * input.Normal.z, 0, 0);
[/CODE]

Now, there are other ways to do this; you could use the texcoords to achieve the same effect, or instead you could use a single index which picks from an array within a shader, but I implemented this in a hurry.
1

Share this post


Link to post
Share on other sites
Inverse of camera's rotation matrix (3x3 part) will negate camera's rotation effect and your quad will always face camera.

Setup generic quad:
[CODE]
struct QuadPoint {
D3DXVECTOR3 xyz;
D3DXVECTOR2 tex;
} points[4];
points[0].xyz = D3DXVECTOR3(-0.05, -0.05, 0);
points[0].tex = D3DXVECTOR2(0, 0);
points[1].xyz = D3DXVECTOR3(-0.05, 0.05, 0);
points[1].tex = D3DXVECTOR2(0, 1);
points[2].xyz = D3DXVECTOR3(0.05, -0.05, 0);
points[2].tex = D3DXVECTOR2(1, 0);
points[3].xyz = D3DXVECTOR3(0.05, 0.05, 0);
points[3].tex = D3DXVECTOR2(1, 1);
[/CODE]
You can duplicate this quad into many quads and then add positions of particles, but personally I used this quad as base mesh and instanced particle positions.

Then get inverse of view:
[CODE]
ViewInverse = *camera.GetViewMatrix();
D3DXMatrixInverse(&ViewInverse, 0, &ViewInverse);
ViewInverse._41 = 0;
ViewInverse._42 = 0;
ViewInverse._43 = 0;
[/CODE]
Last 3 lines remove camera's translation part.

Then in shader it's simple: OutPosition = QuadVertex.Position * ViewInverse * View * Proj;
I used instancing, so for me it was OutPosition = (QuadVertex.Position * ViewInverse + QuadInstancedPosition) * View * Proj;
1

Share this post


Link to post
Share on other sites
I managed to pull it off. And I think the technique I was looking for is called View Oriented Billboarding. I ran into this site here: [url="http://www.toymaker.info/Games/html/direct3d_faq.html#D3D10"]http://www.toymaker...._faq.html#D3D10[/url] but it was missing something big cause it seemed incomplete. It needed to multiply the matrix "result" by the vertices you have for your polgon.Here is the solution to my problem:

[code]
Private Sub D3DXMatrixMultiplyByVertex(VOut As D3DVECTOR, M As D3DMATRIX, V As D3DVECTOR)

VOut.X = (V.X * M.m11) + (V.Y * M.m21) + (V.Z * M.m31)
VOut.Y = (V.X * M.m12) + (V.Y * M.m22) + (V.Z * M.m32)
VOut.Z = (V.X * M.m13) + (V.Y * M.m23) + (V.Z * M.m33)

End Sub

Private Sub Draw_Billboard_Polygon()

Dim Vertex(3) As D3DVECTOR
Dim Camera_Inverse As D3DMATRIX
Dim Result As D3DMATRIX
Dim Temp As D3DMATRIX
Dim Billboard_Vertex(3) As D3DVECTOR

Device.GetTransform D3DTS_VIEW, Camera_Matrix
D3DXMatrixInverse Camera_Inverse, 0, Camera_Matrix

Camera_Inverse.m41 = 0
Camera_Inverse.m42 = 0
Camera_Inverse.m43 = 0

D3DXMatrixIdentity Temp
D3DXMatrixMultiply Result, Temp, Camera_Inverse

Result.m41 = Position.X
Result.m42 = Position.Y
Result.m43 = Position.Z

Device.SetTransform D3DTS_WORLD, World_Matrix

Vertex(0).X = -50: Vertex(0).Y = 50: Vertex(0).Z = 0
Vertex(1).X = 50: Vertex(1).Y = 50: Vertex(1).Z = 0
Vertex(2).X = -50: Vertex(2).Y = -50: Vertex(2).Z = 0
Vertex(3).X = 50: Vertex(3).Y = -50: Vertex(3).Z = 0

D3DXMatrixMultiplyByVertex Billboard_Vertex(0), Result, Vertex(0)
D3DXMatrixMultiplyByVertex Billboard_Vertex(1), Result, Vertex(1)
D3DXMatrixMultiplyByVertex Billboard_Vertex(2), Result, Vertex(2)
D3DXMatrixMultiplyByVertex Billboard_Vertex(3), Result, Vertex(3)

Vertex_List(0) = Create_Custom_Vertex(Billboard_Vertex(0).X, Billboard_Vertex(0).Y, Billboard_Vertex(0).Z, D3DColorRGBA(255, 255, 255, 255), 0, 0)
Vertex_List(1) = Create_Custom_Vertex(Billboard_Vertex(1).X, Billboard_Vertex(1).Y, Billboard_Vertex(1).Z, D3DColorRGBA(255, 255, 255, 255), 1, 0)
Vertex_List(2) = Create_Custom_Vertex(Billboard_Vertex(2).X, Billboard_Vertex(2).Y, Billboard_Vertex(2).Z, D3DColorRGBA(255, 255, 255, 255), 0, 1)
Vertex_List(3) = Create_Custom_Vertex(Billboard_Vertex(3).X, Billboard_Vertex(3).Y, Billboard_Vertex(3).Z, D3DColorRGBA(255, 255, 255, 255), 1, 1)

Device.SetVertexShader CUSTOM_VERTEX_FORMAT
Device.SetTexture 0, Texture
Device.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Vertex_List(0), Len(Vertex_List(0))

End Sub
[/code]

You are now no longer limited to "diamonds" as microsoft had and can make the shape pretty much anything you want whether its a triangle, rectangle, square, etc. and it'll always face the user. I can't believe that after a ton of samples I attempted, some of which are horrible, didn't even do it right. Out of curiosity I heard there are many other Billboarding techniques out there such as these in this site[url="http://www.flipcode.com/archives/Billboarding-Excerpt_From_iReal-Time_Renderingi_2E.shtml"]http://www.flipcode....eringi_2E.shtml[/url] along with spherical billboarding and cylindrical billboarding. Where can I find how to these different techniques with source code examples? Would be interesting to learn how.
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