P.O.P.S.- Demo 3.1 available! - Page 7

P.O.P.S.- Demo 3.1 available!

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: P.O.P.S.- Demo 2.e available!

Post by Argh »

Well, this is dreadful, but I'm still stuck.

Here's what I know.

1. I have to check if the vertex positions are coplanar with the view, and if they aren't, move them. I need to do this by using an imaginary center of each quad, and checking against that position. I am still not sure how to go about this.

2. jK has an example of billboarded quads in SimpleParticles, but it doesn't fit the case, and I'm not sure what parts of his equation I can drop. The math is here:

Code: Select all

           // calc particle attributes
           vec3 attrib = vec3(1.0) - pow(vec3(1.0 - life), abs(attributesExp));
         //if (attributesExp.x<0.0) attrib.x = 1.0 - attrib.x; // speed (no need for backward movement)
           if (attributesExp.y<0.0) attrib.y = 1.0 - attrib.y; // size
           if (attributesExp.z<0.0) attrib.z = 1.0 - attrib.z; // rot
           attrib.yz   = attributesStart.yz + attrib.yz * attributesEnd.yz; 

           // calc vertex position
           vec3 forceV = (1.0 - pow(1.0 - life, abs(forceExp))) * forceDir; //FIXME combine with other attribs!
           vec4 pos4   = vec4(posV + attrib.x * dirV + forceV, 1.0);
           gl_Position = gl_ModelViewMatrix * pos4;

           // calc particle rotation
           float alpha     = attrib.z;
           float ca        = cos(alpha);
           float sa        = sin(alpha);
           mat2 rotation   = mat2( ca , -sa, sa, ca );

           // offset vertex from center of the polygon
           gl_Position.xy += rotation * ( (gl_Vertex.xy - 0.5) * attrib.y );

           // end
           gl_Position       = gl_ProjectionMatrix * gl_Position;
           gl_TexCoord[0].st = gl_Vertex.xy;
My problem is that I'm not rotating the quads, other than final rotation to match the projection, and I'm not using the same inputs for velocity, etc.- that's already done, by the time I need to do this, or I need to do it as the first step after getting the texture coordinates.

All I need to do is to determine whether the given vertex is coplanar with the plane xy perpendicular with the camera that the center lies on, and if not, move it until it's coplanar. This could also be done at the beginning, before I move and scale the quad. I can define quads with vertex positions (-0.5,-0.5) --> (0.5,0.5) so that the center is (0,0), for simplicity's sake, but from there I get stuck on how I'm supposed to get the plane and alter the vertex positions to make them all coplanar.

I've read various things about it online, and have tried various chunks of GLSL, and none of it worked correctly- at best, I get a very distorted projection, and the quads end up doing all sorts of bizarre stuff. Very annoying, but that's where things stand today.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: P.O.P.S.- Demo 2.e available!

Post by jK »

the important lines are:

Code: Select all

// calc vertex position
gl_Position = gl_ModelViewMatrix * pos4;

// offset vertex from center of the polygon
gl_Position.xy += rotation * ( (gl_Vertex.xy - 0.5) * attrib.y );

// end
gl_Position       = gl_ProjectionMatrix * gl_Position;
pos4 is the center pos of the quad in modelview space
gl_Vertex.xy defines the edge of the quad (so it can be: {0,0},{1,0},{1,1},{0,1})
attrib.y is the size of quad
rotation is optional ('cuz: Rot(0)*v = E*v = v)

in pseudo code those lines do:
1. compute center pos of the quad in modelview space (so any translation in the xy-plane is camera-aligned/billboarded)
2. stretch the point to a quad by translating each edge into a diff direction
3. translate it into screen space (far stuff gets smaller etc.)
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: P.O.P.S.- Demo 2.e available!

Post by Argh »

Hrmm. Tried this:

Code: Select all

			gl_Position = gl_ModelViewMatrix * vec4(posData.xyz,0.0);

			// offset vertex from center of the polygon
			gl_Position.xy += (gl_Vertex.xy - 0.5) * finalSize;

			// end
			gl_Position = gl_ProjectionMatrix * gl_Position;
Where posData is my final position XYZ for the particle.

Nothing renders at all- I don't see anything, no matter what camera angle I use. I'll post the full current source here if that will help, but it's basically just the last revision with the gl_Position = ftransform(); removed and that code in its place. Gotta sleep now.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: P.O.P.S.- Demo 2.e available!

Post by Argh »

OK. Still don't know what's wrong with billboarded quads, and my brain's a bit worn out today, so after reading some stuff, here's another version using points, then it's time for bed.

I've read that HD ATi's are the main problem. So... I may write a simplistic workaround for now until I can get the quad billboards working, so I can get back to writing final logic.

Anyhow, this... may help with ATi, although after reading all of this, I'm really not sure.

The problem is that HD cards seem to lose their texture coordinates. I'm trying several things here to address that, including dodging using texcoord 0, and did some other fixes.
Attachments
BUBBLE_POPS25.sdz
(3.74 MiB) Downloaded 10 times
Master-Athmos
Posts: 916
Joined: 27 Jun 2009, 01:32

Re: P.O.P.S.- Demo 2.e available!

Post by Master-Athmos »

Well it sort of still works but I noticed several issues. The most striking:
Everything (i.e. the particles) flickers and seems to have no texture...
Flickering.zip
A small video capture showing the flickering. Framerate isn't too great though...
(480.38 KiB) Downloaded 21 times
Then with no anti-aliasing and "Draw smooth points" deactivated the circles turn into squares:
Flickering square.jpg
(184.8 KiB) Downloaded 34 times
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: P.O.P.S.- Demo 2.e available!

Post by Argh »

OK. Firstly, the video clearly shows something different than the picture. Is it anti-aliasing or point-smoothing that definitely causes the change in behavior?

My guess is point-smoothing... and my next guess is that it's due to the wrong point parameter being used as a default when point objects are built, because one of the things I did in this little experiment was to shut off invoking gl.PointSprite on the Lua side, and just letting it all ride on whatever the defaults are.

I read some confusing things about this, where there seem to be at least 3 different OpenGL extensions for dealing with points- two of which had such subtle differences in their described behavior that the details went past my brain cells. Perhaps using the right extension is key to obtaining correct behavior on HDs. Or maybe they're all fubar- from the amount of frustration 've read on this topic, much of it recent, it appears that trying to talk to ATi's devrel about these issues has been fruitless.
Master-Athmos
Posts: 916
Joined: 27 Jun 2009, 01:32

Re: P.O.P.S.- Demo 2.e available!

Post by Master-Athmos »

No point smoothing & no AA -> flickering squares
Point smoothing & no AA -> flickering circles
No point smoothing & AA -> flickering circles
Point smoothing & AA -> flickering circles

The number of AA samples doesn't matter just as "Draw smooth lines" seems has no effect on the particle rendering and the flickering is the same under all conditions. Maybe just drop a line at the opengl.org forum - maybe someone can give you some tips there...
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: P.O.P.S.- Demo 2.e available!

Post by Argh »

I'm going to contact them and see if I can get some help. I still don't know what's wrong with the billboarded quad version, I'll take another look at that tonight. Honestly, if I can just get that rotation working, that version's done.

In the meantime... here's a version where I use gl_FrontColor to sneak in the texture coordinates. Maybe that will work. And I also turned off the auto-generation of texture coordinates when invoking the point sprites. Again, that works... over here.

Hrmm, here's an article that describes what must be happening to the point sprites:

http://www.informit.com/articles/articl ... 9&seqNum=7

It appears to me that on ATi HD, the following:

glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_FALSE);

Must be getting set, or that:

glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);

Is being ignored, when we use gl.PointSprite(true,true) in Spring. I set it to false here, and yet (on nVidia) I do not see a single texel, I see a complete texture with the latest version.

Something odd's happening- is the engine overriding the point parameters perhaps?
Last edited by Argh on 23 Oct 2009, 03:25, edited 1 time in total.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: P.O.P.S.- Demo 2.e available!

Post by Argh »

Big, fat nevermind... I screwed up my testing procedure. Damn.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: P.O.P.S.- Demo 2.e available!

Post by Argh »

Still no closer to a real solution for the quads. I've had several things where it was vaguely like the right matrix, but then fell apart when tested.

I'm using a gl.Rect(-0.5,-0.5,0.5,0.5), so the center is *always* posData.xyz. It's not the data it's getting fed, it's the transform.

So, what's screwing it up? I've tried everything I can think of or that I've read about, including versions where you send an up dir from the camera and build the matrix manually. None of it has worked, or at best, it's resulted in bizarre behavior. I am assuming that this is because final positions (posData) is in world coordinates, not in modelview, but IDK how that is supposed to change the equation.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: P.O.P.S.- Demo 2.e available!

Post by Argh »

I got some help on the OpenGL boards, and I have working billboarded quads. Still fixing / optimizing a few things, but I should have a new (and hopefully final) technology test up soon.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: P.O.P.S.- Demo 2.e available!

Post by Argh »

Image

OK, here is a working version with quads. Still working on some final fixes, etc., and there are some mysteries about blending behaviors, but first things first- let's make sure that this finally runs on other people's hardware!

If it works, then the cleaned-up version should work- I'm just cleaning up relatively minor cruft, documenting the source a bit better, etc., so that hopefully it's readable by others.
Attachments
pops_bubbles.jpg
(99.32 KiB) Downloaded 211 times
BUBBLE_POPS28.sdz
(3.74 MiB) Downloaded 10 times
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: P.O.P.S.- Demo 2.e available!

Post by Argh »

Image
Various fixes:

Quads are fixed, blending is fixed, one last bug with LOS is fixed, reflections work, lots and lots and lots of comments added.

I don't think all of the cruft is removed yet- there are a few variables that no longer do anything useful, etc., which could trip people up. I'll clean that up thoroughly before finally showing the smoke / fire version, which now I have to rebuild (luckily, not anywhere near totally).

I think that the "bubble" demo is done... assuming that it works for Master-Athmos and other ATi people. Man, I hope so, this is almost as fast as points...
Attachments
BUBBLE_POPS29.sdz
(3.74 MiB) Downloaded 20 times
pops_bubbles2.jpg
(63.21 KiB) Downloaded 207 times
Master-Athmos
Posts: 916
Joined: 27 Jun 2009, 01:32

Re: P.O.P.S.- Demo 2.e available!

Post by Master-Athmos »

Works... :-)
Attachments
bubbles.jpg
(60.73 KiB) Downloaded 30 times
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: P.O.P.S.- Demo 2.e available!

Post by Argh »

Excellent! That means... <gasp> that the heavy engineering phase is finally over. Now it's time to put my utility code back in, so that people can communicate with it from sync-land, and show people how to use it.

If anybody has questions at this point, please hold off until I write the utility code (again), it will make it a lot easier to understand the flow.
User avatar
Falcrum
Posts: 149
Joined: 14 Nov 2007, 01:03

Re: P.O.P.S.- Demo 2.e available!

Post by Falcrum »

Image

Works :) Map - Mercury.
Master-Athmos
Posts: 916
Joined: 27 Jun 2009, 01:32

Re: P.O.P.S.- Demo 2.e available!

Post by Master-Athmos »

Just because I'm curious:
Did you test your system with Spring's multithreaded version too? Would be sad if it like LUPS won't like it...
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: P.O.P.S.- Demo 2.e available!

Post by Argh »

No, I haven't tested with MT Spring. Should work, I've been careful about where / when things are being done.

Oh, and here's where things are. I got the basics of the communication working, so... here's another demo, showing a very, very basic fire / smoke concept. It's not as cool as I'd like it to be, but I have been messing with model / graphics stuff the last few days, and I can't be in two places at once.

It's running slowly atm. Not sure why- my guess is that it's the projectile code, getting the positions, etc., but I haven't had time to puzzle it out yet.
Attachments
FIRE_POPS1.sdz
(3.74 MiB) Downloaded 20 times
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: P.O.P.S.- Demo 3 available!

Post by Argh »

So, any big problems with it, other than it being medium-crude atm?
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: P.O.P.S.- Demo 3 available!

Post by Forboding Angel »

Doesn't work at all for me anymore: Nvidia 9600GT
Post Reply

Return to “Lua Scripts”