| Helpdesk | Real 3D | Main area |
It isn't very hard making a laser like this, and you'll see how obvious it really is. However, some understanding about alphamapping techniques are preferrable. See Kelly Brocks alpha mapping tips for this. As not very much would happen using a constant turbulent fog (the light would glow all the time), I will use the RPL NOISE word to scope between foggy and clear gas. The gas will be moving upward inside a glass/plastic cage, and the end result will be that the laser beam is only visible where there is fog... Just like in the real world.
I take it that if you are reading this, you know how to build the object hierarchy just by seing it. I will not teach how to create an object level, or a light source. Also, it is required that a variable has been defined in the rpl/startup.rpl file. Also, please make sure that the infowindow is opened.
FVARIABLE fAlpha1
should be located in the top of the file just after the loading sections.
An object like this concists of a few basic parts:
Note: Making the beam actually glow using a post fx will not work, as the beam is inside another volume. Post fx will not show through an optically transparent object - or in reflective ones for that matter.
So, create the following hierarchy:
root
objects
laser
fog-case
case
fog
surface
background
Now, for the materials we will use. For the rather long lines of rpl code, just use copy&paste here. The long lines are divided, but they should fit into one RPL line in the material editor:
Material "fog":
sp=0, sb=0, br=100, tr=100, tu=0, ts=2, ri=100, fx=100
Smooth ON, like any other normal fog material.
Scope set to RPL handler:
relx FFETCH rely FFETCH relz FFETCH 0.5 VMUL 0.5 0.6 1.0 3 NOISE DROP DROP 20.0 F* tu FSTORE
rest values as default
Material "fogvalue":
sp=0, sb=0, br=100, tr=100, tu=0, ts=0, ri=100, fx=1 (maybe 2)
Smooth ON.
Scope set to RPL handler:
relx FFETCH rely FFETCH relz FFETCH 0.5 VMUL 0.5 0.6 1.0 3 NOISE DROP DROP 100.0 F* fAlpha1 FSTORE
Color handler set to replace color with white in the RGB boxes.
Material "laser":
sp=2, sb=0, br=0, tr=0, tu=0, ts=0, ri=100, fx=1 (maybe 2)
Unshaded ON, Smooth ON.
Scope set to RPL handler:
fAlpha1 FFETCH s FSTORE
Color handler set to replace color with lasercolor (red?) in the RGB boxes.
In the extras menu, set ambient to full white.
Material: "laseroff":
sp=0, sb=0, br=100, tr=100, tu=0, ts=0, ri=100, fx=1 (maybe 2)
Smooth ON, as any other nonreflective transparent materials.
Scope set to RPL handler:
100.0 fAlpha1 FFETCH F- s FSTORE
Color handler set to replace color with white in the RGB boxes.
Create the glassbox (transparent plastic is a lot faster), enviroment and ground material as you please, with textures connected to the last two.
Okay, lets start building. Enter the root/objects/laser level and
create a cylinder from the side view. This cylinder represents the laser beam.
Set the hotspot to the center of the circle. Now, switch to the front view
and create a parallell map, select laser material, from the top left corner of
the cylinder to the lower right corner. Do it again, this time with the laseroff
material.
Now, create another level named "moving_fogvalue", bring up the infowindow,
and activate the mapping switch. The level should appear as moving_fogvalue (T).
It is very important that this level is below the laser material, since this has
to be executed first. Otherwise, the value from the previously rendered pixel
would determine the laser scope value.
Enter this newly created level, and create a new parallell map from the side view. This time, select the "fogvalue" material, and draw it about twice as large as the lenght of the beam, keeping it somewhat square.
Create a PATH(PATH) animation method, enter it, and create a vertical line about the height of the parallell mapping primitive.
Go to the root/fog-case/case level, and create an 'open' case using a box as the floor, and a polyhedron as the sides. Add a default glasscase(T) map to this level. The case should be as thin as possible, to make it more clearer that the beam is triggered because of the fog. If there was a lot of fog in front of the beam, it would look like a rendering bug instead, because your eyes would still perceive it as the beam got inferferred with fog without producing the expected result. Another concern is that the larger the volume of fog, the higher material samplings should be used.
Make sure the hotspot is in the center of the rectangle from the front view. Go to the root/fog-case/fog level, and create a box inside the case. Create a new level inside here and call it "moving fog". Activate the mapping switch on this level. go inside here and a parallell map using the "fog" material. Create it in the excact way the "fogvalue" map was created, starting from the top left to the lower right corner. Copy and paste in here the PATH animation from the root/laser/ moving_fogvalue level.
From the root level, create a surface, a background, some lightsources, a beam lights representing the laser, maybe a rectangle, and a camera. Make sure to set the rendering type to shadowless or better, recursions to 5 (depending on your materials), and material sampling to at least 2 (4 or more goves better results). Hir the render button and watch the result. You should have something like this:
However, the formula used will give a gradient between laser and laseroff. A
normal laser has either on or off as it hits particles in its way. So, we need to
modify the formula so that the scope effect is either 0 or 100, not anywhere between.
Open the material window and get the "fogvalue" material. An easy way to do
this is to reduce the data to integer, either 0 or 1, before we scale it up. So the
line should now read:
relx FFETCH rely FFETCH relz FFETCH 0.5 VMUL 0.5 0.6 1.0 3 NOISE DROP DROP F>I 100 * I>F fAlpha1 FSTORE
Render again, and.... ooops... the laser dissappeard....????
Note: Open the infowindow if you haven't already.
Well, to find out what went
wrong, we can check the result by putting a
DUP F. just after the I>F word in
the line. Do this, and render again.
Now, when the window gets to the place
where the laser beam is, it will start to output the resulting value to the infowindow.
As you can see, the only result is 0, not a single 100. Why? Well, the solution is to
change the middlepoint of the NOISE function, which is currently located at 0.55
(middlepoint equals lowclip/2 + highclip/2). To get more tops in the resulting curve,
we need to reduce the clipvalues. So the line should now partly read:
0.5 VMUL 0.4 0.5
Test by rendering and see how there are a lot more numbers on 100 now. Delete the
output part of the function (DUP F.), do a render, and you should probably have something
like this:
Now this actually made the result worse, even if rendered to a larger picture. What is wrong? Well, A laser beam in real life would actually lit up the particle it hits, not the volume containing the particle. So what we need to do is to modulate the NOISE function, so that it appears that there is a dense concentration in the volume. To do that we need to multiply the result of the first NOISE word with the result of another one. See the numer in front of the VMUL word? It defines how 'big' the noise is, in respect to the mapping primitive. So, in the next function, this value is going to be a lot higher to add 'particles' to the volume. After the DROP DROP, there is only one parameter left on the stack, so here would be a natural place to put the other NOISE word. The resulting function could look like this:
relx FFETCH rely FFETCH relz FFETCH 0.5 VMUL 0.4 0.5 1.0 3 NOISE DROP DROP
relx FFETCH rely FFETCH relz FFETCH 100.0 VMUL 0.49 0.59 1.0 3 NOISE DROP DROP F*
F>I 100 * I>F fAlpha1 FSTORE
Note that we put the clipcenter higher (0.54) in order to make the particles appear smaller in size. This is only noticable with a broad beam very close to the camera. During normal render, a trick is to set supersampling to 2x2 or 3x3 for better results. Rendertime will increase dramatically though.
Now, we're almost done. If you render this image you'll notice that the beam
appears to be more broken. However, if we animate this, just moving the mapping
parameter upwards, the natural flickering of a laser beam would not appear, it would
just be on the move. So what we want to do is either move the second NOISE word
faster or in another direction as well to create some really flickering and randomness
without spoiling the apperance of where the volume is. We will add another movement
to the show, not just make it go faster. Thus, we choose the z axis of the mapping
plane, adding in a time factor to the relz parameter of the second NOISE word in the
function. After having done "relz FFETCH" the last thing you have on the stack is the
current relative position of the mapping plane for that pixel. We can make it appear
to move just by adding "t FFETCH 10.0 F* F+" to that part. This means that the number
of seconds in the animation (usually 0 to 1 seconds), multiplied by 10 is added to the
current z value used in the NOISE function. So, the final version should look like this:
relx FFETCH rely FFETCH relz FFETCH 0.5 VMUL 0.4 0.5 1.0 3 NOISE DROP DROP
relx FFETCH rely FFETCH relz FFETCH t FFETCH 10.0 F* F+ 100.0 VMUL
0.49 0.59 1.0 3 NOISE DROP DROP F* F>I 100 * I>F fAlpha1 FSTORE
If you have trouble noticing the flickering in the animation, try reducing the 100.0 to something less. The image below is a closeup of what is happening, how volume is defined and follows the fog, and how the 'particles' look.
You may have noticed that the kind of images we are producing now, can take quite a while to render. So, is there any way of making this faster? The answer is yes - of course. What I wanted you to learn, as you can see from this animation, is that the lightning parts of a laser beam can be controlled well using the RPL NOISE word. The laser beam itself renders pretty fast - it is the noisy fog that is time consuming. Normally, one wouldn't want just a case of fog, but global fog. For this material sampling just won't do the trick. In a situation like this the old "inverted sphere at the bottom of the hierarchy with fog material" trick is best. True, the fog patches will not show up, but this may not be that important. The beam itself will give the viewer a clue on where the foggy patches are - without showing the actual patch. Click here to download the object. Just make sure the fAlpha1 variable is defined in your rpl/startup.rpl file before use, or Real might crash.
By using this technique one will have total control over the amount of fog over time, which can be equally simulated in the NOISE word of the beam. Just add a timefactor to the first part of the word, not the modulating one. In the global fog material, add a timefactor to the formula controlling turbidity, and you're all set for a foggy experience.
If fogdynamics is not neccessary, even the global fog post effect will work, if the amount is not too high. If the amount is high it will be clearly visible that the post effect and transparent/brilliant object do not work well together.
If the laserbeam during the animation is kept at nearly the same direction, say forward, it is possible to prerender the mappings to a plane and use the outputted images as clipmaps. This is probably the fastest way of doing this.
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
| Helpdesk | Real 3D | Main area |