Archived

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

Scotto1001

Gun Scope

Recommended Posts

Scotto1001    122
Does anyone have an Idea on how to one put a mask on the camera and two make it zoom in like a gunscope, I am trying to make a sniper in my game. -Scotto Gingerbread Men

Share this post


Link to post
Share on other sites
hplus0603    11347
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
Xgkkp    122
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
circlesoft    1178
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
aker_jus    122
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
hplus0603    11347
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