Archived

This topic is now archived and is closed to further replies.

Gun Scope

This topic is 5012 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

To zoom, control the "fov" factor of your perspective matrix. Smaller fov == more zoom.

To show a "scope" I would render a big black texture with a transparent hole in the middle, and some scope-like cross-hairs in the middle, using alpha testing (or blending). I would render this in orthographic mode (screen space) after rendering the entire scene. If you know what the size of the scope aperture is, you can do frustum culling to the size of the scope hole, instead of the entire screen, which may save you a few mesh draws.

Share this post


Link to post
Share on other sites
quote:
Original post by hplus0603
To zoom, control the "fov" factor of your perspective matrix. Smaller fov == more zoom.

To show a "scope" I would render a big black texture with a transparent hole in the middle, and some scope-like cross-hairs in the middle, using alpha testing (or blending). I would render this in orthographic mode (screen space) after rendering the entire scene. If you know what the size of the scope aperture is, you can do frustum culling to the size of the scope hole, instead of the entire screen, which may save you a few mesh draws.


Why not just use pre-transformed vertices?

Share this post


Link to post
Share on other sites
What if he wanted to add a nightvision scope, where everything is in a green tint? The brighter the object, the brighter the shade of green it is. I''m thinking you''d have to use a whole other pixel shader for it, but it would be pretty cool. A thermal/IR scope would be even cooler...


Dustin Franklin
Mircrosoft DirectX MVP

Share this post


Link to post
Share on other sites
For the thermal vision, you will need texture lookup tables and pixel shading. But for the night vision, a simple texture with animated small noise and additive blending and some other tweaks would do the trick, I suppose.

Plus, you would turn on only green/alpha writes and disable the rest while rendering your "night mask"

Share this post


Link to post
Share on other sites
Yes, pre-transformed vertices would work, too. I just do all my 2D stuff using ortho, for consistency (and the ability to easily rotate 2D overlay items, etc).

Regarding night scope, you''d either do this with a pixel shader, or by setting your material and/or light and/or vertex colors to green (or green-ish) -- that will give you a very green-tinted look.

The pixel shader looks something like: (using ARB_fragment_program-like semantics -- should translate easily to whatever):


DP4_SAT out.color.r, in.color, regs.colorMatrix[0];
DP4_SAT out.color.g, in.color, regs.colorMatrix[1];
DP4_SAT out.color.b, in.color, regs.colorMatrix[2];


The colorMatrix[] probably looks something like:


0.6, 0.6, 0.2, -0.4,
0.4, 1.0, 0.4, 0,
0.2, 0.6, 0.6, -0.4,


This gives a vague coloring and green over-exposure. It expects alpha to be 1 for all the input colors. Experiment with other values to get the balance you want. Dependent texture reads are not necessary.

Share this post


Link to post
Share on other sites