Rectangle Selection lasso Created in the GEOMETRY SHADER

Started by
2 comments, last by ankhd 11 years, 9 months ago
Im trying to create the selection lasso like the one in windows vista(where you hold the left mouse down and drag it and a rectangle is drawn.
Im doing it on the Geometry shader (4) I can create the quad based on a topleft and the width and height, this all works good.

Now I want to put a border around the rectangle, so as google is my friend I hit, hit it hard for 3 days so many pages of crap(lol). I was searching for bordes around quads, not many things came up at all(google hates me)so I sort of remembered doing a toon shader(good old frank, Thumbs up)many years a go and they where using edge detection so of I go looking for shit on silhouette edges and thing related, theres a few thing about it. found a open gl and a dx10 tut(the gl one was written 10 times better then the dx10, shame that. cant understand gl me)any how I ended up finding a post on here about some one wanting to do edge detection and that(http://www.gamedev.net/topic/434729-silhouette-drawing/). In that post was when I desided to go with 4 quads for the border line.
So I create my first quad in the geometry shader of the first pass works ok.
I then create a new geometry shader for pass2 using 16 returned vertices, this here is where it went all wrong(one of the border lines renders over the whole quad),
if I create 12 vertices this = 3 quads they render fine works great but its only 3 border lines, So I thought I had the quads dimensions wrong.
but when I commented out quad 2 and put quad 4(bottom border) back it worked with 3 border lines.
so back to google find here talks about RestartStrip so now I define the top and bottom quads in the geometry shader then I call RestartStrip I then repeat for the left and right side borders and put a nother RestartStrip after the last quad. Now it works finerolleyes.gif .

My question is how should I be using RestartStrip and in my code snipit below how could I improve the code any help would be appreciated.


//--------------------------------------------------------------------------------------
// GEOMETRY SHADER for pas 2 it creates 4 quads around the main rectangle
//of thickness 0.002f// looks about a pixel wide line
//--------------------------------------------------------------------------------------
[maxvertexcount(16)]
void GSPass2( point SPRITE_INPUT sprite[1], inout TriangleStream<PS_INPUT> triStream )
{
PS_INPUT v;
v.opacity = sprite[0].opacity;

//create sprite quad
//--------------------------------------------
//Top quad
//bottom left
v.p = float4(sprite[0].topLeft[0],sprite[0].topLeft[1]-gvThickness,0,1);
v.t = float2(0,1);
triStream.Append(v);

//top left
v.p = float4(sprite[0].topLeft[0],sprite[0].topLeft[1],0,1);
v.t = float2(0,0);
triStream.Append(v);
//bottom right
v.p = float4(sprite[0].topLeft[0]+sprite[0].dimensions[0],sprite[0].topLeft[1]-gvThickness,0,1);
v.t = float2(1,1);
triStream.Append(v);
//top right
v.p = float4(sprite[0].topLeft[0]+sprite[0].dimensions[0],sprite[0].topLeft[1],0,1);
v.t = float2(1,0);
triStream.Append(v);
//triStream.RestartStrip();
//////////end quad top
//quad Bottom
//bottom left
v.p = float4(sprite[0].topLeft[0],sprite[0].topLeft[1]-sprite[0].dimensions[1],0,1);
v.t = float2(0,1);
triStream.Append(v);

//top left
v.p = float4(sprite[0].topLeft[0],sprite[0].topLeft[1]-sprite[0].dimensions[1] + gvThickness,0,1);
v.t = float2(0,0);
triStream.Append(v);
//bottom right
v.p = float4(sprite[0].topLeft[0]+sprite[0].dimensions[0],sprite[0].topLeft[1]-sprite[0].dimensions[1],0,1);
v.t = float2(1,1);
triStream.Append(v);
//top right
v.p = float4(sprite[0].topLeft[0]+sprite[0].dimensions[0],sprite[0].topLeft[1]-sprite[0].dimensions[1] +gvThickness,0,1);
v.t = float2(1,0);
triStream.Append(v);
triStream.RestartStrip();
//////////end quad Bottom
//quad Left side
//bottom left
v.p = float4(sprite[0].topLeft[0],sprite[0].topLeft[1]-sprite[0].dimensions[1],0,1);
v.t = float2(0,1);
triStream.Append(v);

//top left
v.p = float4(sprite[0].topLeft[0],sprite[0].topLeft[1],0,1);
v.t = float2(0,0);
triStream.Append(v);
//bottom right
v.p = float4(sprite[0].topLeft[0]+ghThickness,sprite[0].topLeft[1]-sprite[0].dimensions[1],0,1);
v.t = float2(1,1);
triStream.Append(v);
//top right
v.p = float4(sprite[0].topLeft[0]+ghThickness,sprite[0].topLeft[1],0,1);
v.t = float2(1,0);
triStream.Append(v);
triStream.RestartStrip();
//////////end quad Left

//quad Right side
//bottom left
v.p = float4(sprite[0].topLeft[0] + sprite[0].dimensions[0]- ghThickness ,sprite[0].topLeft[1]-sprite[0].dimensions[1],0,1);
v.t = float2(0,1);
triStream.Append(v);

//top left
v.p = float4(sprite[0].topLeft[0] + sprite[0].dimensions[0] - ghThickness,sprite[0].topLeft[1],0,1);
v.t = float2(0,0);
triStream.Append(v);
//bottom right
v.p = float4(sprite[0].topLeft[0]+sprite[0].dimensions[0],sprite[0].topLeft[1]-sprite[0].dimensions[1],0,1);
v.t = float2(1,1);
triStream.Append(v);
//top right
v.p = float4(sprite[0].topLeft[0]+sprite[0].dimensions[0],sprite[0].topLeft[1],0,1);
v.t = float2(1,0);
triStream.Append(v);
triStream.RestartStrip();
//////////end quad Right

}//end
///////////////////////////////////////////////////////////////////////////////////////////////////////////

Advertisement
The output of a geometry shader is usually a triangle strip. You can use RestartStrip() to simulate triangle lists by calling RestartStrip() after appending each 3 vertices.
So if your example is working that's because you're correctly outputting triangle strips so there is no need to use RestartStrip() more than you do.

Another approach you could use is to just output 2 quads (4 triangles) one of them a little bigger than the other (to create the border) and add an attribute to the vertices so in the pixel shader you know if you're drawing the border and output a different color.

One improvement to do in my example would be to output the smaller quad first, so hopefully (I'm not sure if the first triangles will be drawn first but maybe someone else does, or you can simply test) when the second quad is drawn the early depth test will reject the pixels of the smaller quad and no overdraw occurs.
Thanks for the reply.
sorry I forgot to say that the first quad(full size one) will be transparent.
Im exporting 4 quads out from the geometry shader each time but 4 verts per quad 16vertices all up it work.
I was just woundering if the way I did it is slow it takes 2.2 ms for a 1440 * 900 full screen quad with a border
Heres what it looks like when imported into a app with terrain RectangleLasso.jpg?psid=1

This topic is closed to new replies.

Advertisement