10
$\begingroup$

I understand I could render out the view my camera and then just that as an image texture, however, I want to try and achieve this effect in real-time.

The idea is derived from an effect present in a handful of first-person shooters:

Example 1 Example 2 Example 3

I'm not concerned with making different objects appearing in different colours within the view, I can figure that part out myself. But is there any way to make what the camera can see projected onto an object in real-time? Essentially, making the camera's view an image texture, but in real-time

UPDATE

I tried using the solution provided in this question: Zoom windows magnification

It definitely achieves the effect I'm looking for, in the sense that it picks up the surrounding environment and 'displays' it on the specified object.

However, due to it being reliant on a refraction node and some complex vector maths that I don't quite comprehend, the screen just picks up on the rifle's mesh. This occurs as the true normal of the plane picks up on the mesh in front of it, and ignores the generated normal (an in-depth explanation is present in the 'Zoom windows' solution)

I will upload images of my results later in the day

EDIT

I don't mind by what means this effect is achieved, provided I can do it using only one computer and can be done in real-time

$\endgroup$
8
  • 1
    $\begingroup$ You cannot have the output of a scene or camera be the texture of another material. You could Use a UV pass and do it in post, but you'll have to use a dupe scene with camera placed at the scope front or a separate output node from the current scene. either way it won't be real time. It has been solved in the past as a geometry Optical hack however, by distorting a lens mounted in the scene and using a very high IOR. $\endgroup$
    – 3pointedit
    Aug 9, 2018 at 8:44
  • $\begingroup$ Could you possibly link me to the solutions you are regarding? $\endgroup$ Aug 9, 2018 at 8:49
  • 3
    $\begingroup$ Here ya go: blender.stackexchange.com/questions/79749/… $\endgroup$
    – 3pointedit
    Aug 9, 2018 at 9:11
  • $\begingroup$ Or you could go nuts and have a separate machine rending the "other" view and dynamically updating the texture in the "main" view. But you would have to keep them in sync. That might be as simple as just tracking the camera or as complicated as updating everything property of every object. $\endgroup$
    – rob
    Aug 9, 2018 at 10:28
  • $\begingroup$ Have you tried taking a look at this article? blender.stackexchange.com/questions/48132/… $\endgroup$ Aug 10, 2018 at 10:51

1 Answer 1

17
+100
$\begingroup$

As has already been mentioned, the same techniques as used in Zoom Windows Magnification can be used here - but this is very dependent on getting the vector maths correct, which is also critically dependent on getting the geometry and orientation correct, so I'll try and explain the set up in an as easy to replicate method as possible.

For the geometry, we need to have two parallel faces with specific orientations so that we can use the coordinates to generate the correct normal for the 'lens' at the front of the 'scope' - this allows the image to be zoomed to the correct magnification. The simplest start point is for a cube. Note that the orientation of the faces is significant (since the X/Y coordinates will be used for the lens - therefore, if you later rotate the cube do not 'Apply Scale' as this will upset the coordinates.

Create your cube. The uppermost face will become the 'screen' of the scope, the bottom face will become the 'lens'. In Edit mode (Tab) select the uppermost face and assign a new material ('Scope.Screen'), select the bottom face and assign a new material ('Scope.Lens'). You can optionally assign a material to the rest of the mesh for the body ('Scope.Body').

The direction of the Normal is also significant. Select the uppermost face ('Scope.Screen') and the bottom face ('Scope.Lens') and select Mesh/Normals/Flip Normals. This should result in the following :

materials and normals

Note the flipped normals. Different materials assigned to the 'body', 'screen' (top face) and 'lens' (bottom face).

For the 'Screen', setup the material as follows :

screen material

Note the IOR of zero - this, combined with the flipped normal, results in all rays being directed along the normal (ie, directly towards the opposite (lens) face).

For the 'Lens', setup the material as follows :

lens material

This material uses the Refraction shader with a Normal generated based on the X and Y coordinates (it's critical that the mesh is orientated so that the bottom face is flat to the X and Y planes). The X and Y is combined into a vector along with a fixed 'Z' and this is converted to a Normal via the Vector Transform node (to convert from Object to World space). Adjust the Z length and IOR to adjust the focal length (strength) of the lens.

Once the mesh and materials are configured you can rotate and scale the mesh as desired - but ensure you do not 'apply rotation' (as this will upset the X/Y coordinates used to generate the lens) and only scale along the object's local axes (otherwise it will skew the opposing faces and result in the screen no longer being aligned to the lens). If you do 'apply scale' then this will affect the focal length (as the Z value will be relative to the new scale) which may need to be re-adjusted.

Here's the final result :

final result

Blend file included

Just for completeness, here's a very rough animation of this in action :

animated

And here animating the IOR in order to dynamically 'zoom' :

animated zoom

$\endgroup$
5
  • $\begingroup$ Cool, Can you change the field of view by distorting the front capture plane like a lens? $\endgroup$
    – 3pointedit
    Aug 12, 2018 at 0:27
  • 1
    $\begingroup$ @3pointedit Sure - you can adjust the field of view by either adjusting the Z component of the Combine XYZ mode to make the 'lens' more or less curved or by simply adjusting the IOR of the lens material. I've added an additional animated GIF to demonstrate varying the IOR betweem 1.050 and 2.150 for a 'zoom' effect. $\endgroup$ Aug 12, 2018 at 6:21
  • 1
    $\begingroup$ Super smart! I think that there are more applications for this. I wonder if the light path can bend, as in finer optics? $\endgroup$
    – 3pointedit
    Aug 12, 2018 at 8:43
  • 1
    $\begingroup$ @3pointedit It would certainly be feasible to chain multiple faces together to bend light around corners - although as with ‘real’ optics the trick would be to prevent distortions at each interaction. It’s feasible that you could include custom normals at each stage to adjust for any such distortions, I guess. $\endgroup$ Aug 12, 2018 at 9:22
  • 1
    $\begingroup$ You could model the glass physics to have the scope work, but I think the vector math would be easier. $\endgroup$ Aug 12, 2018 at 23:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .