Tuesday, May 10, 2016

Lighting without extra textures, and materials. Part II. The Blueprint

In the previous part I showed how to add an luminous bulb to the streetlight mesh. Now, we look how to create a switchable streetlight with blueprint. To minimize system requirement we use only static lighting.

The first ting is, select the mesh what you want to create a streetlight, press left click, select Asset Actions, and press right click on the Create Blueprint Using This... option.
In the popup windows select the folder what you want, and add a name for the Blueprint.

Now, open the Blueprint(Automatically open), click the Add Component menu, and select Spotlight.

Move and rotate the spotlight close to the bulb. Set mobility to static, intensity to 100 000, and visibility to false(important to the continue)

Go to Construction Script tab. Add a new Boolean variable(important! Not local variable) and set to public(eye icon)

Now, we start doing the script. First, add a Branch node, and assign the switch variable to it. The next step is add a Toggle Visibility function, and assign the Spot Light variable to it. The last step is compile and save.

Create a new map, add the Blueprint to it, and mark the switch variable on the Details panel(Right side)

To continue, we need a material instance, to set emission of the bulb. To make this, open the material from the first part, select the constant which set the strength of the bulb emission, press left click and select convert to parameter. Set the default value to 0, and the parameter name to Light_Strength or any same name. Save.
Now, go to material, press a left click, and select create material instance.

Now, go back to Blueprint editor, select viewport tab, select the streetlight mesh, go to Details panel Lighting section, and mark Use emissive for static lighting checkbook.

Now, go back to Construction Script tab, Add a Create Dynamic Material instance function for the front of the script, assign the mesh variable for it, and set the source material to the material instance that is before made. If you use LOD's, you must Create Dynamic Material instance function for all LOD's, and set element index. For example: you have one mesh with 3 LOD's. In this case you must create 3 "Create Dynamic Material instance function", with these element index: 0-1-2. If you use three LOD's, and two materials, and the emissive material the first one, In this case you must create 3 "Create Dynamic Material instance function", with these element index's: 0-2-4.

Add a local variable, and set type to Material Instance Dynamic.

Drag this variable to script editor, set to setter, and link it to the DMI function.
Now, add a Set scalar parameter value function to script, drag the DMI variable to it, and set to getter. Set the parameter name to Light_Strength, or what you use on the material. Set the value to 50. Now, compile, and save.

If you follow my instruction, you get same result.

No comments:

Post a Comment