Page 7 of 9

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

Posted: 21 Oct 2009, 11:19
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.

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

Posted: 21 Oct 2009, 11:53
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.)

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

Posted: 21 Oct 2009, 12:40
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.

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

Posted: 22 Oct 2009, 06:44
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.

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

Posted: 22 Oct 2009, 18:20
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

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

Posted: 22 Oct 2009, 18:57
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.

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

Posted: 22 Oct 2009, 21:59
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...

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

Posted: 23 Oct 2009, 01:26
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?

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

Posted: 23 Oct 2009, 02:48
by Argh
Big, fat nevermind... I screwed up my testing procedure. Damn.

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

Posted: 23 Oct 2009, 12:22
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.

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

Posted: 27 Oct 2009, 01:48
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.

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

Posted: 27 Oct 2009, 03:55
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.

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

Posted: 27 Oct 2009, 05:32
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...

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

Posted: 27 Oct 2009, 17:26
by Master-Athmos
Works... :-)

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

Posted: 27 Oct 2009, 21:09
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.

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

Posted: 28 Oct 2009, 00:51
by Falcrum
Image

Works :) Map - Mercury.

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

Posted: 01 Nov 2009, 10:31
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...

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

Posted: 02 Nov 2009, 23:21
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.

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

Posted: 05 Nov 2009, 21:16
by Argh
So, any big problems with it, other than it being medium-crude atm?

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

Posted: 05 Nov 2009, 22:11
by Forboding Angel
Doesn't work at all for me anymore: Nvidia 9600GT