DirectX 12: Chapter 8 Exercise 1: Pulsing Red Light

This is my answer to Frank Luna’s “Introduction to 3D Game Programming with Direct X 12”, Chapter 8 “Lighting”, Exercise 1: “Modify the lighting demo of this chapter so that the directional light only emits mostly red light. In addition, make the strength of the light oscillate as a function of time using the sine function so that the light appears to pulse. Using colored and pulsing lights can be useful for different game moods; for example, a pulsing red light might be used to signify emergency situations.”

This is easy. Here is our Light code:

Which is part of the per-frame constant buffer object, the “Pass Constants”:

Which we bind to the rendering pipeline via this root signature in the shader:

Hence we just need to change the “strength parameter”, which we can use with our provided game timer object. I have provided an odd looking automatically allocated parameter for pulse frequency, which changes the speed of the pulse, this should really be a global constant variable (or better yet a meta-data exposed variable, assuming an appropriate framework):

Leave a Reply

Your email address will not be published. Required fields are marked *