GL Tools Quad Strip Texture Coords and Normals

toneburst's picture

I wonder if it would be possible to fix the texture coords to allow meaningful texturing of a GL Quad-Strip. Currently, if you pipe an image into the Image port, you just get the colour of the first pixel of the image, as far as I can tell.

Also, would it be possible to generate normals for the quad strip, so it can be lit? Or, have the option of generating normals, since I imagine calculating them would slow things down a bit.

The above probably applies to the Triangle Structure patch too, but I haven't tried that one yet.

a|x

cwright's picture
Re: GL Tools Quad Strip Texture Coords and Normals

Set the U and V values, and you get texture mapping (there's a sample composition that does something with this I think -- subtractive blending perhaps?)

I don't recall if we support normals or not -- manually calculating them will give faceted lighting, and then people will want smooth lighting, and that's tricky (and part of kineme3d...)

toneburst's picture
Re: GL Tools Quad Strip Texture Coords and Normals

cwright wrote:
Set the U and V values, and you get texture mapping (there's a sample composition that does something with this I think -- subtractive blending perhaps?)

Hmm.. how do you do that, then?

Quote:
I don't recall if we support normals or not -- manually calculating them will give faceted lighting, and then people will want smooth lighting, and that's tricky (and part of kineme3d...)

I see, slippery slope, and all that. To be honest, I just stuck the Quad Strip inside a Lighting patch, and lighting didn't appear to work. I guess there could be other reasons for that, too...

a|x

cwright's picture
Re: GL Tools Quad Strip Texture Coords and Normals

toneburst wrote:
Hmm.. how do you do that, then?

depends on how you're making the structure. Wherever you set the X and Y members, add a U and V for the texture coords.

toneburst wrote:
I see, slippery slope, and all that. To be honest, I just stuck the Quad Strip inside a Lighting patch, and lighting didn't appear to work. I guess there could be other reasons for that, too...

You're dead-on with why it doesn't work -- GL lighting requires normals, otherwise you just get unlit polys.

toneburst's picture
Re: GL Tools Quad Strip Texture Coords and Normals

cwright wrote:
You're dead-on with why it doesn't work -- GL lighting requires normals, otherwise you just get unlit polys.

OK, so let's assume you're not calculating normals, then...

I'll have a go at calculating UVs too. Not sure how that's going to go, though... Thinking about it, it's going to be a bit tricky....

a|x

toneburst's picture
Re: GL Tools Quad Strip Texture Coords and Normals

cwright][quote=toneburst wrote:
Wherever you set the X and Y members, add a U and V for the texture coords.

Hmm.. not quite sure how this should work. I tried, as a test, adding the X and Y coords of each vertex onto the end of the array for each point (X, Y, Z, U(same as X), V(same as Y))

I know QC coords are centered on 0, so I'd kinda expect to see the input image tile across the quad-strip, as if projected onto it, or something. I can't completely get my head around the geometry, but I think I should anyway be getting something other than the exact same colour across the entire strip.

I've included a simple test QTZ. I know it's reinventing the wheel (or more precisely, toby*spark's SPK Caligraphy plugin), but I thought I'd try and implement something similar in JS, just as a test of the GL Quad Structure plugin.

If you could have a really quick look, I'd be really grateful. It's probably user error on my part.

a|x

PreviewAttachmentSize
tb_Strokething.qtz9.39 KB

toneburst's picture
Re: GL Tools Quad Strip Texture Coords and Normals

cwright wrote:
manually calculating them will give faceted lighting, and then people will want smooth lighting, and that's tricky (and part of kineme3d...)

Hang on, doesn't OpenGL automatically interpolate normals, if they're specified for each vertex?

It's a while since I looked into OpenGL, but I thought that was the deal.

a|x

jersmi's picture
Re: GL Tools Quad Strip Texture Coords and Normals

Any more info on how the U and V variables work with the Kineme GL patches would be hugely appreciated.

cwright's picture
Re: GL Tools Quad Strip Texture Coords and Normals

Try this in the JS part:

      // Stroke record to points array
         // Append array of mouse X/Y and def. Z value to points array
         point = new Object();
         pointsList[pointsList.length] = point;
         point.X = MouseX - StrokeWidth;
         point.Y = MouseY - StrokeWidth;
         point.U = 0.5 + (MouseX - StrokeWidth)/2;
         point.V = 0.5 + (MouseY - StrokeWidth)/2;
         point = new Object();
         pointsList[pointsList.length] = point;
         point.X = MouseX + StrokeWidth;
         point.Y = MouseY + StrokeWidth;
         point.U = 0.5 + (MouseX + StrokeWidth)/2;
         point.V = 0.5 + (MouseY + StrokeWidth)/2;

For textures (and possibly normals, if they're supported), it requires names, not indices. Your method was just pumping out "0"-"5", while this needs "X", "Y", "U", "V" etc (I trashed your Z stuff, but I figured you at least get the idea from this).

The 0.5 + (blah) / 2 is to turn QC coordinates (-1 to +1) into UV tex coords (0 to 1)

cwright's picture
Re: GL Tools Quad Strip Texture Coords and Normals

It interpolates.

But when one "calculates the normal" of a primitive (a triangle, typically), you get a vector (the normal) -- all vertices of the triangle will have the exact same normal, so GL interpolating the normal won't do anything interesting. To make a curved surface, you need to bend the normals, and finding out how much to bend the normal requires smoothing. GL does Not smooth for you (as that's a big huge problem that isn't well defined)

cwright's picture
Re: GL Tools Quad Strip Texture Coords and Normals

U and V are "Texture Coordinates". In other words, they tell GL how to map a texture to a shape.

In GL, a texture generally goes from 0 to 1, on 2 axes. These are labeled U and V in GLTools, and S and T in GL documentation. 0,0 is the bottom left corner, 1,1 is the top right.

toneburst's picture
Re: GL Tools Quad Strip Texture Coords and Normals

cwright wrote:
it requires names, not indices. Your method was just pumping out "0"-"5", while this needs "X", "Y", "U", "V" etc.

Ah, OK. It mentioned in the description that a simple array could be used, rather than an associative array/object.

Quote:
The 0.5 + (blah) / 2 is to turn QC coordinates (-1 to +1) into UV tex coords (0 to 1)

yep, I knew that was going to be necessary.

Now it works!! Nice one cwright!

I did this fun variation.

a|x

PreviewAttachmentSize
tb_Strokething_2.qtz12.53 KB
tb_Strokething_2_02.png
tb_Strokething_2_02.png114.47 KB
tb_Strokething_2_04.png
tb_Strokething_2_04.png130.91 KB

gtoledo3's picture
Re: GL Tools Quad Strip Texture Coords and Normals

That's pretty cool there TB.

I much prefer it because of the way that the kineme GL Tools blend modes work. I'm going to have to see if it is possible to make it take a right click before it clears the line, so that you can make line gaps, and multiple lines...

Do you get a debug when it opens, b/c the javascript doesn't have a point list? I know I do... Somewhat trivial really.

cwright's picture
Re: GL Tools Quad Strip Texture Coords and Normals

toneburst wrote:
Ah, OK. It mentioned in the description that a simple array could be used, rather than an associative array/object.

Oops, guess that's incomplete -- as you've no doubt noticed, it's happy to do basic x/y/z points from a simple array, but it doesn't do that for other stuff. It could, but we didn't bother adding it in for whatever reason (traversing structures is ugly enough as it is, perhaps?). Sorry about the confusion :(

toneburst's picture
Re: GL Tools Quad Strip Texture Coords and Normals

gtoledo3]That's pretty cool there TB.</p> <p>I much prefer it because of the way that the kineme GL Tools blend modes work. I'm going to have to see if it is possible to make it take a right click before it clears the line, so that you can make line gaps, and multiple lines...[quote]</p> <p>You'd been to setup some kind of Iterator setup to do that. I guess you'd store the strokes as an array or arrays in the JS patch, then have each stroke rendered by a Quad Structure patch inside an Iterator</p> <p>[quote wrote:
Do you get a debug when it opens, b/c the javascript doesn't have a point list? I know I do... Somewhat trivial really.

Ah, no, I don't get that. pointsList should probably be initialised outside the main loop of the JS patch though.

adding

// Variable to hold mousebutton state from previous frame
var oldMouseDown;
var pointsList = Array();
 
function   (   __structure Points)
         main
      (   __number MouseX, __number MouseY, __boolean MouseDown,
         __number StrokeWidth, __number ZValue)
{
   if(!_testMode) {
 
      if(MouseDown &! oldMouseDown) {
      // First mouse-press of stroke clears old stroke
         // Init array of points
         pointsList = Array();
      } else if (MouseDown) {
      // Stroke record to points array
         // Append array of mouse X/Y and def. Z value to points array
         point = new Object();
         pointsList[pointsList.length] = point;
         point.X = MouseX - StrokeWidth;
         point.Y = MouseY - StrokeWidth;
         point.Z = ZValue;
         point.U = 0.0;//0.5 + (MouseX - StrokeWidth)/2;
         point.V = 0.5 + (MouseY - StrokeWidth)/2;
         point = new Object();
         point.X = MouseX + StrokeWidth;
         point.Y = MouseY + StrokeWidth;
         point.Z = ZValue;
         point.U = 1.0;//0.5 + (MouseX + StrokeWidth)/2;
         point.V = 0.5 + (MouseY + StrokeWidth)/2;
 
         pointsList.push(point);
      } else {
      // Retain stroke array
         pointsList = pointsList;
      }
 
      // Update old mousebutton state with current value
      oldMouseDown = MouseDown;
 
      // Initialise output object, set and return values
      var result = new Object();
      result.Points = pointsList;
      return result;
 
   }
}

seems to work.

a|x

gtoledo3's picture
Re: GL Tools Quad Strip Texture Coords and Normals

Haven't had time to look at that yet, and I've been barking up my own trees as far as QC ideas go, but that makes sense on the pointsList, I bet that's exactly it... will check...

Yeah, your proposed concept of the arrays/iterator seems to make perfect sense as well.

The first time I saw this thing (the tobyspark version), it looked much like one of the tools in the eMotion thing to me.

I will be interested at some point to get into taking the structure and manipulating it to "do stuff" after you have "written". That seems like it would be a fun route.