• 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
Theodore Enderby

How to draw lots of billboard sprites

6 posts in this topic

Howdy first post!



So I have all these "gameSprites" that contain "BillboardSprites".

They are pngs that are chopped up

and billboarded to be in 3D space.

I'm using them as characters and other things and I'd like to be able to draw a ton of them.

 

http://www.youtube.com/watch?v=duSshpK5GtE

(video of game before adding a lot more sprites!)


They are drawn in there own buffers whith their own indices and vertices arrays.





This is very slow and reading suggests that the graphics card would prefer if I told it about all

the gamesprites in one buffer instead.



I can add all their vertices and indices together, and draw them all I'd imagine.

But they are also drawn with an effect file, and that is passed its world matrix(Scale and position etc),

plus the billboarding effect and textures.



So how would I keep my ability to individually change scaling,positioning,texture and other things

in each gamesprite while still being able to draw all of them in one batch?



I'm new so I don't know if my understanding of xna is that great but this is where I'm at!


If someone could just give me some ideas or theories or examples that would be great.


 


public void Draw(GraphicsDevice graphics, Camera camera)
        {
            setVertexBuffer(graphics);
            
            //Gets texture from sprite sheet for animation.
            StopAtCurrentFrame(graphics);
            //set previous states
            RasterizerState prevRasterizerState = graphics.RasterizerState;
            BlendState prevBlendState = graphics.BlendState;

            Matrix billboardMatrix = Matrix.CreateConstrainedBillboard(WorldMatrix.Translation, camera.Position, Vector3.Up, camera.Forward, Vector3.UnitZ);
            Matrix ScalePositionFix = Matrix.CreateTranslation(Position * -scale);
            Matrix YFix = Matrix.CreateTranslation(new Vector3(0, (HEIGHT / WIDTH) * 2, 0));
            Matrix AppliedWorldMatrix = WorldMatrix * ScalePositionFix * YFix;
            //First Pass:
            //Render the non-transparent pixels of the billboards and store their depths
            billBoardEffect.Parameters["world"].SetValue(billboardMatrix * AppliedWorldMatrix);
            billBoardEffect.Parameters["view"].SetValue(camera.View);
            billBoardEffect.Parameters["projection"].SetValue(camera.Projection);
            billBoardEffect.Parameters["billboardSize"].SetValue(0);
            billBoardEffect.Parameters["alphaTestDirection"].SetValue(1);
            billBoardEffect.Parameters["colorMap"].SetValue(texture);

            graphics.BlendState = BlendState.Opaque;
            graphics.DepthStencilState = DepthStencilState.Default;
            graphics.RasterizerState = RasterizerState.CullNone;
            foreach (EffectPass pass in billBoardEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                graphics.DrawIndexedPrimitives(PrimitiveType.TriangleList,
                                                     0,
                                                     0,
                                                     vertexBuffer.VertexCount,
                                                     0,
                                                     (int)(vertexBuffer.VertexCount * 0.5f));
            }
            graphics.Indices = null;
            graphics.SetVertexBuffer(null);

            //Second pass
            billBoardEffect.Parameters["alphaTestDirection"].SetValue(-1.0f);
            graphics.BlendState = BlendState.NonPremultiplied;
            graphics.DepthStencilState = DepthStencilState.DepthRead;
            //graphics.SamplerStates[0] = SamplerState.PointWrap;
            setVertexBuffer(graphics);

            foreach (EffectPass pass in billBoardEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                graphics.DrawIndexedPrimitives(PrimitiveType.TriangleList,
                                                     0,
                                                     0,
                                                     vertexBuffer.VertexCount,
                                                     0,
                                                     (int)(vertexBuffer.VertexCount * 0.5f));
            }


            graphics.SetVertexBuffer(null);
            graphics.Indices = null;
            //set previous states


            graphics.BlendState = prevBlendState;
            graphics.RasterizerState = prevRasterizerState;
            setBounds();

 


Here's my draw for the GameSprite code, excuse the mess, still new:

2

Share this post


Link to post
Share on other sites

Hey so I've successfully implemented instancing for my sprites and I can draw a ton of them, thank you.

Now I've got to figure out how to put back in billboarding and the alpha test.

 

In my effects file I can probably using the view and projection matrices to make the sprite face the camera, correct?

As for how to do the multipass aplha test I was using I have no idea.

So back google.

 

If anyone has any tips I'd be happy to hear them.

0

Share this post


Link to post
Share on other sites

For bilboarding in my instanced particles I use folowing code, works like a charm:

            if (this.style == OrientStyle.Yonly)
            {
                Matrix billboardWorld = Matrix.Identity;
                billboardWorld.Forward = Vector3.Normalize(camera.Position - this.Position);
                billboardWorld.Right = Vector3.Normalize(Vector3.Cross(billboardWorld.Forward, Vector3.Up));
                billboardWorld.Translation = this.Position;
                Transform = Matrix.CreateScale(this.size) * billboardWorld;
            }
            else
            {
                var billboardWorld = Matrix.Invert(camera.ViewMatrix);
                billboardWorld.Translation = this.Position;
                Transform = Matrix.CreateScale(size * (life / 3000.0f)) * billboardWorld;
            }


For transparecy I used inferred shading's 3 layered transparency, but I am curious about forward approaches too (I have no idea how I can efficiently sort back to front instanced geometry, so i believe OIT is a must).

1

Share this post


Link to post
Share on other sites

Wow your billboarding matrix works great. Way simpler than my attempts.

Could you explain more about your "inferred 3 layered shading" and "OIT", I'm unfamiliar with

these and I am having trouble finding docs on it.

0

Share this post


Link to post
Share on other sites
As for Inferred I believe You would have to rewrite your code if you use forward rendering (since inferred is different redering pipeline). OIT stands for order independent transparency. You could use depth peeling for instance. If you want to use perfect transparency just use clip(x) in pixel shader.
Partial transparency is very difficult task when it comes to real time rendering.

Some linkts for you:
http://www.eng.utah.edu/~cs5610/lectures/OrderIndependentTransparency.pdf
http://developer.download.nvidia.com/SDK/10/opengl/src/dual_depth_peeling/doc/DualDepthPeeling.pdf
http://mynameismjp.wordpress.com/2010/01/10/inferred-rendering/ Edited by Tasaq
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