DOC PREVIEW
UCSD CSE 125 - Lighting

This preview shows page 1-2-15-16-31-32 out of 32 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 32 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 32 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 32 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 32 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 32 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 32 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 32 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Project6 – Lighting – per-pixel shading and optimizations for Direct3D 8 Author: Michal Valient ([email protected]) Conversion (with some corrections) from the HTML article written in November 2002 6.0 Abstract (2004 update) This article starts with description of the Phong lighting equation. It continues with various implementations of this equation on the programmable graphics hardware. Some parts of this article are available in my master thesis. Also when we refer to the vertex shader we refer to the version 1.1. When we refer to the pixel shader, we refer to the version 1.4 6.1 Introduction Light is a very important effect in the computer games. Together with the shadows it “describes” the visual atmosphere of a scene and gives us the feel of third dimension on a monitor. Computer generated 3D images will be flat, hard to orient and hard to believe-in without the lights (computed in any way and rendered in any form). Success of the computer game relies on the user's believe to what he sees. This makes lighting is very important. High quality dynamic lighting of the scenes is even more crucial with new hardware. This article presents lighting and shading methods on the modern hardware. Let us start with some definitions: Material is a set of properties that describe visual appearance of a surface. The properties can include a texture, various light coefficients or a color. We use the term Lighting to describe the interaction of a light and a surface (with the material applied onto it). Lighting models have to be simple enough to be computed fast in the real-time graphics and should still produce acceptable results. Phong lighting model described in this text can be divided into the three parts: ambient, diffuse and specular. Some other models are for example Cook-Torrance's model [6.2] (can be used for metallic surfaces), He's model [6.3], Oren-Nayar's model [6.4]. Shading is a process of performing the lighting computations and determining the colors of the pixels. We know three major types of shading: flat, Gouraud and Phong. The flat shading computes light intensity once per triangle. Intensity is then applied onto the whole triangle. This type of shading cannot produce very good results for low polygon models. On the other hand, it’s fast and sometimes used in games for objects with sharp edges and flat faces. Gouraud shading (also called per-vertex shading) and Phong shading (in fact its extension used in the computer games is named per-pixel shading) will be described later in text.6.2 Light model equation The lighting equation (commonly used in real-time graphics) is combined from three parts - ambient, diffuse and specular in this fashion: itotal = iambient + idiffuse + ispecular (6.1)Where itotal is the final color value, iambient is the ambient color, idiffuse is the diffuse color and ispecular is the specular color for given pixel Image shows the visualization of a lighting computation. 6.2.1 Diffuse component The diffuse component is based on a law of physics called Lambert's law and has the biggest base in the real world (and the interaction of photons and surfaces). The Lambert's law says that the reflected light intensity is determined by cosine of the angle a between the surface normal n and the light vector l (heading from a surface point to the light) for totally matte (diffuse) surfaces. Both vectors are normalized. This lighting component is independent of viewer’s position, because of the fact that for a perfectly diffuse surface the probability of a new reflection direction is equal for every direction. Image shows diffuse lighting intensity components. The diffuse light intensity (idiffuse) computation has the form: idiffuse = cos(a) = n.l (6.2) We extend the equation 6.2 to take into account the surface color mdiffuse at current pixel, light color ldiffuse and the fact, that the angle between light and normal has to be less than π/2 to this form (normal is faced away from the light for greater angles and the pixel is not being lit and a dot product is less than zero in this case): idiffuse = max(n.l, 0) * mdiffuse * ldiffuse (6.3)Image shows the diffuse lighting computation. The normal and light vectors are visualized with x axis assigned to the red channel y to the green cannel and z to the blue channel. Very good explanation of diffuse lighting (with a connection to the Lambert's law) can be found in [6.1] at page 71 and 72 or in [6.5] in the chapter two. 6.2.2 Specular component We use the specular part of lighting equation to simulate shiny surfaces with the highlights. A very popular model is called the Phong reflection model [6.6] and it computes light intensity as a cosine of the angle a between the normalized light vector reflected around the point normal - r - and normalized vector from the point to the position of a viewer - v - powered by the shininess value that specifies amount of reflection. This equation has little to do with the real world illumination but it looks good under most conditions and is easy to compute. Image shows specular lighting intensity components. Phong's specular equation then is: r = 2*(n.l)*n - l (6.4)ispecular = cos(a)shininess = (r . v)shininess (6.5)Image shows geometric interpretation of the equation 6.4. If a dot product of n and v is less than zero (angle is greater than π/2) then a pixel is facing away from the light and lighting should not be computed. We extend the equation 6.5 to take into account the material specular intensity modifier mspecular (in real-time graphics commonly called the gloss map) and the light color lspecular to this form: ispecular = (r.v)shininess * mspecular * lspecular (6.6) Image shows specular lighting computation. Normal, light, reflection and view vectors are visualized with x axis assigned to the red channel y to the green cannel and z to the blue channel. Image shows effect of the shininess parameter. The greater it is, the narrower is the area of highlight. Shininess parameter on image has values 1,2,4,8,16,32,64,128There are several variations of Phong's equation. Commonly used is the Blinn's equation [6.7]. It uses normalized half vector h between l and v. Resulting intensity is then a dot product of h and n. In general it is faster to compute it in real-time. h = (l + v) / ||l + v|| (6.7)ispecular = (h . n)shininess (6.8)Relation between Phong's and Blinn's equation: (h . n) 4*shininess is approximately equal to (r . v)shininess


View Full Document

UCSD CSE 125 - Lighting

Download Lighting
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lighting and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lighting 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?