
Per vertex lighting At the corner of a square. The per-fragment version shows a nice highlight in comparison. This is because each of the four points of the front face are more or less equidistant from the light, and the low light intensity at each of these four points is simply interpolated across the two triangles that make up the front face. In the per-vertex lighting in the left image, the front face of the cube appears as if flat-shaded, and there is no evidence of a light nearby. Per fragment lighting centered between four vertices of a square. Per vertex lighting centered between four vertices of a square.

Take a look at the following screen captures:

Ensure you have a proper balance between quality and speed.Ī significant difference between the two types of lighting can be seen in certain situations. For “soft” lighting such as terrain, per-vertex lighting may be good enough. Mobile GPUs are getting faster and faster, but performance is still a concern. Although I have referred to this type of lighting as per-pixel, in OpenGL ES we actually work with fragments, and several fragments can contribute to the final value of a pixel. In this lesson, we’re going to look at the same lighting code for a per-vertex solution and a per-fragment solution. Moving from per-vertex to per-fragment lighting With shaders, a lot of these calculations can now be offloaded to the GPU, which allows for many more effects to be done in real-time. Lightmaps can give a very nice result and can sometimes give even better results than shaders alone as expensive light calculations can be precomputed, but the downside is that they take up a lot of memory and doing dynamic lighting with them is limited to simple calculations. Many famous old games such as the original Half Life were developed before the time of shaders and featured mainly static lighting, with some tricks for simulating dynamic lighting using either per-vertex (otherwise known as Gouraud shading) lights or other techniques, such as dynamic lightmaps. Per-pixel lighting is a relatively new phenomenon in gaming with the advent of the use of shaders. Android Lesson Two: Ambient and Diffuse Lighting.Here are the previous lessons in the series: This lesson is an extension of lesson two, so please be sure to review that lesson before continuing on. Assumptions and prerequisitesĮach lesson in this series builds on the lesson before it. We will be able to see the difference, even when using standard diffuse lighting with simple cubes. Welcome to the the third tutorial for Android! In this lesson, we’re going to take everything we learned in lesson two and learn how to apply the same lighting technique on a per-pixel basis. Per fragment lighting At the corner of a square.
