Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
Visigoth
19
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 5th Jan 2008 07:04
I searched and searched, and never found anything regarding this, so, I am going to post what I learned about point sprites.
In case you don't know, point sprites are 3D sprites. It is one of the primitives that DX allows. Point sprites are like regular 2d sprites, except they can be positioned in 3D space. If we were writing code in c++, we would be able to define a custom vertex buffer, and we would be able to define the primitive that that vertex buffer represents. In DBPro, we only have one primitive to work with, and that is triangle strip, which is probably the most versatile of all the primitives. So you know the others, they are point, line, triangle strip, triangle list, and triangle fan. Alot of you guys who have worked with memblock meshes have probably wished you had access to other primitives. I know I did, and am officially petitioning TGC to add this feature to DBPro. But until this ever happens, I am going to show you how you can have POINT SPRITES in DBPro. You will need a video card that supports point sprites (most modern ones do). And this will require a shader, that I wrote in RenderMonkey.
Visigoth
19
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 5th Jan 2008 07:13
First,what is a point sprite? For every vertice of an object, you can actually have an image, that automatically positions itself to point at the viewer, if you set if up right. This is basically billboarding. But in DBPro, we have been limited to billboarding one image to one quad type object. One quad, in DBPro, is 2 triangles, or 6 verts. Say you wanted to paste 100 trees. You would normally make a quad, texture it with your tree, and instance it 99 more times. Then, you have to position your quad to point at your camera. I've tested this. Load 100 quads with textures. Watch what happens. What if I told you you could have 1,000 of those trees, with little to no effect on your framerate? There is a way...
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 5th Jan 2008 07:17
Indeed such a feature would be beneficial. But I wouldn't hold out any hope it will get added .

Visigoth
19
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 5th Jan 2008 07:27
100 quads is 3x3 verts, or 9 verts per quad, or 2 polys per quad. Either way, its one image for for 2 polys. Point sprites can create one image for each vert. so, for each poly, thats 3 images. for one quad, thats 6 images. There are some limitations, however. Pointsprites are hardware based. They are supposed to be supported in software, but, I'm not going there, not in DBPro. NVidea cards support larger point sprites than ATI cards (boo hoo, I have ATI). So, consider this when doing this techinque.

I've tried this on all the primitives in DBPro. You can add this shader effect to spheres, cubes, boxes, plains, it doesn't matter. But, if you want to get real gas out of this, you only need an object with an FVF of 2. That's just postion data, 12 bytes per vertex. It can't get any smaller than that.
Visigoth
19
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 5th Jan 2008 07:33
So, what does it do?
The shader takes your object, whatever it is, and by way of a render state setting, makes it a point sprite. Instead of filling the polygon with color, for every vertice, it will point a texture of a certain size at the camera, and will keep it pointed at the camera. This pointing feature is a built in feature of point sprites, and I doubt it can be changed.

How can it be used?
Lots of ways. Pretty much unlimiited grass on a terrain, with a good texture.

simulate snow or rain

birds flying out of a field of grass

You have to play with it to come up with ideas.
Visigoth
19
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 5th Jan 2008 07:57 Edited at: 5th Jan 2008 09:09
this demo is a real simple one. Its just 500 triangles, with the same texture for each vertice.(point sprite). I was getting about 500 fps on average. I've had 6,000 and still got better than 100 fps. I'm still trying to figure out if the texture size has anything to do with frame rate, which I'm sure it does. I could, and can, move all these sprites wherever I want, in 3D space. I'll post more later.
For now, this is my grass solution. All I have to do is apply a decent texture, and position the vertices to match my terrain.

EDIT:
Thats 1500 images, 3 per triangle. Try 1500 quads. See what happens.

Attachments

Login to view attachments
Visigoth
19
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 5th Jan 2008 08:33
here is a demo that shows how you can move a bunch of sprites in 3D.

Attachments

Login to view attachments
Visigoth
19
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 5th Jan 2008 08:40 Edited at: 5th Jan 2008 21:04
oh, and BTW, I wrote the shader in RenderMonkey.

Attachments

Login to view attachments
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 5th Jan 2008 14:20 Edited at: 5th Jan 2008 22:48
Well now that I've become aware of this feature I've just written a shader and example based on this page: http://www.gamedev.net/reference/articles/article2002.asp.

[Edit]

the correct reference is:
http://xna-uk.net/files/folders/randomchaos/entry1511.aspx

Attached below



Attachments

Login to view attachments
Agent Dink
20
Years of Service
User Offline
Joined: 30th Mar 2004
Location:
Posted: 5th Jan 2008 14:29
Quote: "Could you please use the edit function instead of posting 5 times in a row?"


Wow, don't be an idiot. Did you even read what his post is about? Actually I kinda liked the broken up posts. Made reading such a big article seem less daunting.

Anyhow, nice info here Trying out your demo now...

Looks real nice Runs pretty well too. I'll have to see about using this on one of my projects.

TinTin
17
Years of Service
User Offline
Joined: 16th May 2006
Location: BORG Drone Ship - Being Assimilated near Roda Beta (28)
Posted: 5th Jan 2008 15:17
It should have been posted in the Codebase also.. but it is usefull knowledge anyway. well done Visigoth.

Cyberspace was becoming overcrowded and slummy so I decided to move. These nice chaps gave me a lift.
wildbill
18
Years of Service
User Offline
Joined: 14th Apr 2006
Location:
Posted: 5th Jan 2008 16:31
Who really cares where its posted or how its posted. I'm just happy to read it. Since dark coder posted the link to a tutorial and the tutorial is in visual basic its pretty simple to follow.
Visigoth
19
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 5th Jan 2008 20:46
@Windowskiller
yeah, sorry about that.

@Darkcoder
yeah, your shader is pretty much identical to mine. You even have the EXACT same formula for calculating the scaling. Looks good.
jason p sage
16
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 5th Jan 2008 21:07
He only does that on his threads when he first starts them - usually to post files - I don't think its a big deal I don't wish to detract from what this little demo does though - WAY cool!

That is a very very good efficient way for grass and stuff! I wish I knew how to do it!

dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 5th Jan 2008 22:26 Edited at: 5th Jan 2008 22:49
Quote: "You even have the EXACT same formula for calculating the scaling."


Yes I saw your shader code, however I copied the line from the .fx files found in the examples on the Gamdev.net article, as that was written in '03 I figured you studied that too.

[Edit] I got the wrong tab, the reference for the shader code I used was this: http://xna-uk.net/files/folders/randomchaos/entry1511.aspx

Visigoth
19
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 5th Jan 2008 23:11
@DarkCoder

yeah, that was the answer right there. I had it kind of working initially, but the sprites would only scale when I rotated the camera, not zoom in and out, so, found that article, and realized that it needed to be manually calculated. In fact, no reason to set the sprite scale enable flag in the render state, because the scaling is done with that formula.

Login to post a reply

Server time is: 2024-05-02 08:12:14
Your offset time is: 2024-05-02 08:12:14