Updating the environmental lighting

Now Andy should be lit from what looks like the brightest light source in the area. However, because we don't currently track changes in light direction, if you change rooms or the lighting changes, then the illusion is broken. Light tracking is difficult, and it's more difficult than tracking a user, except that we can put a simple hack in place to not track the lighting for as long as we do, which is currently forever, if you weren't paying attention. Follow along to put this simple hack in the code we just wrote:

  1. Open up the EnvrionmentalLight.cs script in your text editor of choice. If you forgot how to do this, just look back a few pages.
  2. Add the following line right after and before the lines identified:
var pi = Frame.LightEstimate.PixelIntensity; //after me
maxGlobal *= .98f;
if(pi > maxGlobal){ //before me
  1. That single line is a degrade function on the maxGlobal variable. Remember that maxGlobal is the value we identify as the strongest light source. This simple function, yep function, degrades this value over time. The value of .98f sets the speed of decay. A value of .98f represents a fairly quick decay rate, whereas a value of .9999f would represent a slow decay.
  2. Save the file, and yep, that's it.
  3. Go back to Unity. Connect and build and run the app. Now when you place an Andy, you should quickly see changes in what the app identifies as the strongest light source. Feel free to go back and change the decay rate or alter the function and use your own method; experiment.

What we put together is a simple way to track and estimate light direction. As we mentioned, this method works, but it's certainly not without its limitations. In any case, this should give the curious reader enough to continue and extend this further. We also completely avoided a proper discussion of shadows. Fortunately, we will have plenty of time to do that in Chapter 9Blending Light for Architectural Design, where we will allow the user to transform their own living space.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.237.246