Титульная страница
ISO 9000 ISO 14000
GMP Consulting
 
Mastering 3D Studio MAX R3

Previous Table of Contents Next


Using Environment and Render Effects

You can adjust environment options and assign environment effects and render effects using MAXScript. Using environment options, you can create special effects and enhance your scenes, adding more realism.

Accessing Global Environment Variables

Global environment variables, such as background color and environment map, control the Common Parameters, displayed in the rollout in Figure 14.11.


FIGURE 14.11  Global environment parameters

Adding a Background to a Scene

There are two ways to add a background to a scene: using a plain background color or using a map. You can set both of them in MAXScript.

The BACKGROUNDCOLOR command sets the background color. For instance, backgroundcolor = [255,255,255] will set the background color to white.

Using ENVIRONMENTMAP allows you to place any map in the background. For this to happen, you need also to enable USEENVIRONMENTMAP. For instance:

 fname = selectsavebitmap()
 bmp = bitmaptexture filename:fname
 bmp.coords.mappingtype = 1
 bmp.coords.mapping = 4
 environmentmap = bmp
 useenvironmentmap = true

This will ask the user to select a bitmap to be used in the background. The bmp.coords.mappingtype and .mapping will set the mapping type to Screen.

Setting Illumination Parameters

AMBIENTCOLOR, LIGHTTINTCOLOR, and LIGHTLEVEL are the three parameters in the Common Parameters rollout that control the overall illumination of the scene.

AMBIENTCOLOR and LIGHTTINTCOLOR are color values, while LIGHTLEVEL is an integer.


WARNING Be careful when adjusting any of these values, because they can mess up all illumination in a scene.

Creating Environment Effects and Atmospheric Gizmos

To use certain environment effects you will need to create atmospheric helpers, also called atmospheric gizmos. They’re needed for Combustion and Volumetric Fog effects.

There are three gizmos, and they work exactly the same way:

 a = spheregizmo()
 b = cylgizmo()
 c = boxgizmo()

Since they’re sphere, cylinder, and box, they have the same basic options of the regular 3D objects, plus a Seed option, which is the number that will generate a unique, random volumetric effect.

Environment effects are similar to materials. You will first create the effect you want, and then you will add it to the Atmosphere Effects queue, shown in Figure 14.12.


FIGURE 14.12  Atmosphere effects

You have four built-in effects in MAX: Combustion, Fog, Volumetric Fog, and Volumetric Light. All of them are used the same way:

 eff = combustion explosion:1
 eff2 = volume_light density:10

eff is a Combustion, and the property that defines the explosion effect is on (explosion:1). eff2 creates a Volumetric Light and sets its density to 10%.

Once the effects are defined, you need to add them to the Atmosphere rollout, using addatmospheric effect. Using the examples above, you can add both effects to the atmospheric effects list:

 addatmospheric eff
 addatmospheric eff2

You’ve seen that you need the gizmos for the effects to work—or, for Volumetric Light, you need a light. But you also need to tell MAX which gizmo or light relates to which effect. This is done by APPENDGIZMO. This command will associate an object to an environment effect. For instance, let’s create a gizmo and a light, to be associated with the effects in the previous example:

 L = omnilight pos:[100,0,0] farattenend:50 farattenstart:0
 G = spheregizmo pos:[-100,0,0] seed:3413
 appendgizmo eff G
 appendgizmo eff2 L

NOTE You cannot associate a light to a combustion or a volumetric fog, and you cannot associate a gizmo to a volumetric light.

Each effect has a .numgizmos property that will list the number of gizmos associated to it. You can use GETGIZMO to retrieve any associated object for instance, getgizmo eff 1 will list the first gizmo associated to this effect. To remove any gismo you can use DELETEGIZMO.

Creating Render Effects

Render effects are post-processing filters applied to a rendered image. Several render effects can be applied, and you manipulate them the same way you manipulate environment effects.

You create a render effect the same way you do an environment effect. MAX has several render effects; let’s use the Brightness and Contrast render effect as an example:

 bc = brightness_and_contrast

You can list its parameters using SHOWPROPERTIES. Let’s change the brightness and contrast level:

 bc.brightness = 0.8
 bc.contrast = 0.6

Now, let’s add it to the render effects list, using ADDEFFECT:

 addeffect bc

Similarly to environment effects, you can use NUMEFFECTS to list the number of effects you have in your scene. You can use GETEFFECT to read an effect in the list and DELETEEFFECT to remove any of them.

Hands-On MAXScript: Creating an Explosion

Let’s create a script that will create an object explosion. This script will create a Particle Array object and a Combustion effect and will synchronize these effects for the explosion. All the user will need to enter is the start and end of the explosion.

To make this exercise easier to understand, first open the file on the CD-ROM named asteroid_explosion.max. This file consists of an animated asteroid, which will be exploded using the script you will now create.

Now create the script. Start a new script and type the commands shown in List-ing 14.4 (or access the code on the CD-ROM in the file named explosion_exercise.ms).


LISTING 14.4: The Asteroid Explosion script (explosion_exercise.ms)
 if selection.count == 0 then format “Select an object first.\n” else
 if selection.count > 1 then format “Please select a single object.\n” else
 (
 obj = $
 size = (distance obj.min obj.max)
 start = getkbvalue prompt:”Enter Explosion Start Time:”
 end = getkbvalue prompt:”Enter Explosion End Time:”
 p = parray emitter:obj wirecolor:obj.wirecolor
 p.particletype = 2
 p.fragmentmethod = 1
 p.fragchunkminimum = 30
 p.speed = 2
 p.Fragment_Thickness = size/8
 p.emitter_start = start
 p.life = (end - start)
 p.display_until = end
 g = spheregizmo pos:obj.pos radius:size
 g.parent = obj
 eff = combustion explosion:1 name:”Explosion”
 appendgizmo eff g
 addatmospheric eff
 st = animationrange.start
 ed = animationrange.end
 if end > ed then animationrange = (interval st end)
 with animate on
 (
 at time start eff.phase = 0
 at time end eff.phase = 300
 at time 0 obj.visibility = on
 at time start obj.visibility = on
 at time (start + 1) obj.visibility = off
 )
 )


Previous Table of Contents Next

© 2000, Frol (selection, edition, publication)

 
Rambler's Top100