Draw overlay quad/shapes when background quad is zoomed in

Started by
13 comments, last by dave09cbank 7 years, 5 months ago

Hi,

I'm trying to draw an overlay quad/shape on top of another quad.

Now i could have my background quad zoomed in (using ortho camera) while i'm trying to draw my overlay object.

Thus, what i really want is to draw the overlay shape which takes into consideration how much i'v already zoomed in.

As currently it doesn't expand/enlarge when i zoom in and thus keeps the overlay shape of the same size.

Do i need to manually enlarge the shape and then draw or could it be all done in shader ?

Any suggestion how i could approach this.

Note: Using SharpDx & C# & Directx11

Advertisement

A picture of what you're trying to do might help.

But, if I'm picturing this in my head correctly, you could use a Scaling Matrix on the quad, in which the amount of scaling would be correlative to the difference between the last frames zoom value, and the current frames zoom value. (Really anything to use as a scalar for the scaling of the overlay)

Using a scaling matrix is pretty simple to. Something like this:


worldMatrix = scale() * rotation() * translation();

Marcus Hansen

Thanks for the reply @markypooch

I tried to upload some screenshots but for some reason they wont upload (no specific reason)

so i have uploaded them to my dropbox.

Screenshot 1 Link: Scenario where the overlay quad (in yellow) are drawn on background quad

Screenshot 2 Link: Scenario where i have zoomed in and then drawn my overlay (in yellow)

Also,

My quads are drawn using actual screen co-ordinates which are transformed to world space in the shader file.

All the quad i.e both background and overlay use the same matrices.

However, at this point I cant understand how would the scaling matrix fit as a solution ?

Would you kindly explain/elaborate.

Thanks

Well now that I see what you're trying to do. Than, yeah a scaling matrix isn't much of a solution. I was kinda going off this:

Thus, what i really want is to draw the overlay shape which takes into consideration how much i'v already zoomed in

As currently it doesn't expand/enlarge when i zoom in and thus keeps the overlay shape of the same size.

A scaling matrix will scale the quad by some magnitude of your choosing. This is, it can enlarge the quad itself the more you zoom up on the license plate. But, it all depends on what you're trying to do.

If your expecting an algorithm to run through all sorts of different pictures of cars with license plates, and occlude them, you may want to look into an image detection algorithm, which if that's the case, i'll pass this topic off to someone else who has more knowledge in this area.

Marcus Hansen

The way i zoom is i try to keep the point under the mouse at the same position by moving quad left/right/top/bottom if it needs to.

Also, i wasn't expecting an image detection algorithm. The background image used was from live camera feed.

Why not just render the image background image to an offscreen texture, add the yellow boxes, and then use this new image to zoom in on?

I haven't rendered to offscreen texture before but can look into it.

However that brings me to next question.
The yellow quads which I draw were simple example of quads filled with color as I do use different effects such as pixelated or blur the quad represented by yellow color.

Could they still be achieved when trying to render offscreen texture as per your suggestion ?

Currently how I render:
1. Draw background quad
2. Draw my yellow quads
3. Present the buffer or invalidate surface as using D3DImage part of WPF

In order to do render to offscreen texture:
1. Have 2 render targets
2. Draw background quad on texture render target which not my main back buffer
3. Draw my yellow quad as above
4. Convert the offscreen render target to shader resource view
5. Map this shader resource view to update my back buffer which my main render target
6. Present the back buffer or invalidate surface as above

Are my steps correct or am I approaching this completely in a wrong way.
Could they still be achieved when trying to render offscreen texture as per your suggestion ?

By and large, "offscreen" is simply another "surface" you can render to, just like the back buffer. There's a little work in setting it up, and copying it over to the back buffer, but that's about it.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

thanks for the update @Norman Barrows

Yes i agree as after researching & reading on it.

However from what i read rendering to texture can have performance issues.

If this is the case then whats the main reason/best case scenario for its usage ?

Also the confusion i still have :

1. As to how to copy it over to back buffer as in my case Invalidate the surface as using D3DImage (part of WPF) ?

2. How would my ortho camera work in this case.

Though i'm still investigating the above two points, since i've just started to implement it in code.

If this is the case then whats the main reason/best case scenario for its usage ?

when its the best / only way to achieve the desired effect, whatever the desired effect in question may be.

Often times its used to render to texture, where you render to an offscreen surface, then use that surface to create a texture, then use that texture in a subsequent draw call to texture a mesh. A rear view mirror in a car driving simulator would be an example of this. They create an offscreen surface, point the camera looking back, render the scene to the offscreen surface, then point the camera back forward again and render the scene, and use the offscreen surface as the texture for the rear view mirror. And Voila! you have real working rear view mirrors! Pretty cool huh?

But just from that brief description, you can see that its jumping through a number of hoops to do all that - thus the performance hit. Its usually an effect that is used sparingly.

As with everything , the proof is in the pudding, you won't know if it will work for you until you try it. All you can do is do your research, and become familiar with the methods available, and try those that look promising.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

This topic is closed to new replies.

Advertisement