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.

DarkBASIC Professional Discussion / Point Sprite Particle Texturing

Author
Message
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 16th Aug 2013 16:05
Hi Guys, for one of the render types for my particle system I'm using point sprites but I've encountered a problem when it comes to texturing. Because the way there set up via a memblock, all the particles can only have one texture and because of the nature of my particle system which is flow graph/script based the texture can change on the fly, I'd have to make a new memblock object for every texture on the fly. So how could I get round this?

"Get in the Van!" - Van B
thenerd
17
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 16th Aug 2013 16:18
I don't know how point sprites work, but is it possible for you to alter the UV coordinates of individual particles? you could use a texture atlas if that was the case. The "texture change" node in your flow graph could internally store the UV offset of the texture.

That could be a problem if you wanted to fade between textures, but it seems like all you need is the ability to change textures without setting up a memblock object. But again, this is just speculation because i'm not sure if you can edit the UV data.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Aug 2013 22:18
I can't see why you can't reuse the same memblock and just make different textures from it.

I'm not sure what you're doing exactly though.



Powered by Free Banners
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 16th Aug 2013 22:59 Edited at: 16th Aug 2013 23:01
Well using an example by Dark Coder he uses a memblock to create points, and turns it into an object. Since its one entire object whatever texture you apply to it is the only texture you can have on it. There's no way to set a few of the points with another texture. So you have to create another point object for a different object.

This would be okay is I was using a fixed amount of particles but the particles are incredibly varied.

Look here to find the example:
http://forum.thegamecreators.com/?m=forum_view&t=121302&b=1

"Get in the Van!" - Van B
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 16th Aug 2013 23:30
Quote: "There's no way to set a few of the points with another texture."

Texture atlas you need.

"Just because you’re unique, doesn’t mean you’re useful"

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 16th Aug 2013 23:35
Aha, but here's the problem, you can't rotate point sprites, you have to rotate the texture, so texture atlas won't work, plus I'm using complex materials, animated textures and extra so I have to use single textures.

"Get in the Van!" - Van B
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 17th Aug 2013 00:43
Quote: "you can't rotate point sprites"

sin and cos UV in vertex shader may help. or not

"Just because you’re unique, doesn’t mean you’re useful"

Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 17th Aug 2013 07:42
Yes as mr Handy stated, you can use the cos-sine maths. All coordinates can be rotated; including UV coordinates.

I am unable to understand your point about being limited to one texture however, I can't see how that is possible; since you have full control over the texturing and full control over the memblock.

Could you perhaps post an example of what you mean?

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 17th Aug 2013 22:33 Edited at: 17th Aug 2013 22:37
Point sprites don't rotate. Point sprites are always window-aligned squares or if it is possible it would be very difficult and very far beyond my knowledge.

This is the example created by dark coder
https://forumfiles.thegamecreators.com/download/1393163

Note: More advanced systems use float point textures to store particle data. I'm not sure if texturing would be among this data.

"Get in the Van!" - Van B
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 17th Aug 2013 22:58
Do you use a texture to store vertex positions?

Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 18th Aug 2013 00:59 Edited at: 18th Aug 2013 01:11
Looking at your project makes things crystal clear now.

Your shader is multiplying vertex colours by the texture colour. I was wondering what the issue was all about; you just need to make use of additional textures and mix them in the shader. Instead of baking a diffuse colour into the mesh, draw the base colour from a texture; select a random UV coordinate in the vertex shader function.

It seems you understand your stuff so no reason to explain what needs to happen with the shader.

It's a nice little technique actually; simple, the way I like it.

Quote: "Point sprites don't rotate. Point sprites are always window-aligned squares or if it is possible it would be very difficult and very far beyond my knowledge."


I was talking about the UV coordinates.

Actually I am not sure why we are even talking about rotation? You do not need to rotate the UV coordinates to make use of texture atlases.

Duke E
17
Years of Service
User Offline
Joined: 10th Mar 2009
Location:
Posted: 19th Aug 2013 17:30
I made a pretty extensive particle system using a combo of Dark coder and GG's shader particles POC's.

The nature of this method to produce particles includes a vertex cloud made up of an object created in a memblock (or other way).

In the shader each vertex is "decoupled" to produce it's own (internal to the gfx card) plane that is aligned to the camera.

The UV coordinates of the object used are irrelevant in the Vertexshader when it comes to positioning the texture on the "internal" camera aligned plane(s).

To rotate and/or atlasanimate the texture it has to be done in the Pixelshader.

Have to say the pointsprite method is now pretty arcane and i recommend not using it due to both the problems with different graphics card drivers making it hard to get a consistent result. And that the gfx optimizations making the six vertex plane/particle now render as fast as the pointsprite planes.

Elaborating on the (dire) gfx driver issues. When i was full up in this project i noticed from one day to another particles behaving very strange indeed. What had happened was the NVidia drivers update i installed had changed the internal check of the vertex positions close to the cameras XYZ (0,0,0) position. Particles that should go past and behind the camera "slided" 90 degrees past the camera. I then had to make my own clipplane in the shader.

However this method is pretty efficient as I could run over one million atlasanimated and rotating sprites with only a couple percent CPU usage, the 9800 gfx card i had managed ~100fps but it was at max utilization.

This post I made in the Shader thread shows the shader I used (this is a older version, i later made the rotation transformations in the VS):
http://forum.thegamecreators.com/?m=forum_view&t=91453&b=1&msg=2162382#m2162382

In the PS you'll see how the rotation is done with the TEXCOORD0 output UV's.

You have to keep in mind that each object you use should be considered one particle emitter. You could have multiple texture stages to the object and have a emitter with different particles but i only used one texture per emitter.
I used a internal shader loop to enable fifty simultaneous emitter (objects) to be used with one shader. Don't even think of loading one shader per object.

One thing i never finished though is the overlap in a texture atlas when rotating.
Imagine rotating a square 45 degrees over another square, the corners of the rotated square will overlap outside the edges of the nonrotated square. What will happen is the texture image corners in the adjacent tiles in the atlas will show up on the one displayed. I solved it quicks and dirty by shrinking each separate image on the atlas by sqrt(1) before combining the sequences to a complete atlas image.

Regards
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Aug 2013 18:19
Interesting, thanks.

Quote: "by shrinking each separate image on the atlas by sqrt(1)"


Typo?



Powered by Free Banners
Duke E
17
Years of Service
User Offline
Joined: 10th Mar 2009
Location:
Posted: 20th Aug 2013 00:25 Edited at: 20th Aug 2013 10:29
Quote: "Typo?"


Indeed, should have been:
UV /= sqrt(2);



Edit: I shrank each separate atlas image on the texture so i got the necessary edge around it and then zoom in the UV when displaying the image the shader by doing UV /= sqrt(2);.

Regards
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 21st Aug 2013 20:36
Okay lets make this alittle more difficult cause I already know how to set up texture altas. I want to do this with single textures just like nearly all the engines I've encountered that are using point sprites.

Thanks for the information so far guys, it's all going to good use

"Get in the Van!" - Van B
Duke E
17
Years of Service
User Offline
Joined: 10th Mar 2009
Location:
Posted: 22nd Aug 2013 14:00
So if you want an explosion to change the particles texture from say a fire texture to a smokepuff texture during the lifetime. I'd go with two textures. Texturing the first texture stage of the emitter object with the fire texture and the second stage with smoke. Then - according to particle lifetime - blend the second smoke stage over the fire texture in the shader.

Then you only have to make one memblock to object conversion/texturing. Then hide and reuse the object. The majority of CPU time use is dealing with memblock to object conversions.

Login to post a reply

Server time is: 2026-07-07 00:09:05
Your offset time is: 2026-07-07 00:09:05