Upload
others
View
6
Download
0
Embed Size (px)
Citation preview
Ambient and Diffuse LightLecture 16
Robb T. Koether
Hampden-Sydney College
Wed, Oct 2, 2019
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 1 / 15
Outline
1 Lighting
2 Ambient Light
3 Diffuse Light
4 Programming the ShadersAmbient Lighting ModelDiffuse Lighting Model
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 2 / 15
Outline
1 Lighting
2 Ambient Light
3 Diffuse Light
4 Programming the ShadersAmbient Lighting ModelDiffuse Lighting Model
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 3 / 15
Lighting
The lighting model includes three “kinds” of light.
Ambient lightSource is from all directions.Independent of the surface’s orientation.Reflected equally in all directions.
Diffuse lightSource is from a specific direction.Dependent on the surface’s orientation.Reflected equally in all directions.
Specular lightSource is from a specific directionDependent on the surface’s orientation.Reflected more in some directions than in others.
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 4 / 15
Lighting
The lighting model includes three “kinds” of light.Ambient light
Source is from all directions.Independent of the surface’s orientation.Reflected equally in all directions.
Diffuse lightSource is from a specific direction.Dependent on the surface’s orientation.Reflected equally in all directions.
Specular lightSource is from a specific directionDependent on the surface’s orientation.Reflected more in some directions than in others.
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 4 / 15
Lighting
The lighting model includes three “kinds” of light.Ambient light
Source is from all directions.Independent of the surface’s orientation.Reflected equally in all directions.
Diffuse lightSource is from a specific direction.Dependent on the surface’s orientation.Reflected equally in all directions.
Specular lightSource is from a specific directionDependent on the surface’s orientation.Reflected more in some directions than in others.
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 4 / 15
Lighting
The lighting model includes three “kinds” of light.Ambient light
Source is from all directions.Independent of the surface’s orientation.Reflected equally in all directions.
Diffuse lightSource is from a specific direction.Dependent on the surface’s orientation.Reflected equally in all directions.
Specular lightSource is from a specific directionDependent on the surface’s orientation.Reflected more in some directions than in others.
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 4 / 15
Outline
1 Lighting
2 Ambient Light
3 Diffuse Light
4 Programming the ShadersAmbient Lighting ModelDiffuse Lighting Model
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 5 / 15
Ambient Light
Definition (Ambient Light)Ambient light has no specific source. It illuminates all surfaces equally.The intensity of the reflected light is independent of the angle ofincidence and the angle of reflection.
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 6 / 15
Ambient Light
Regardless of the orientation of the surface, the strength of therelection is the same.
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 7 / 15
Outline
1 Lighting
2 Ambient Light
3 Diffuse Light
4 Programming the ShadersAmbient Lighting ModelDiffuse Lighting Model
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 8 / 15
Diffuse Light
Definition (Diffuse Light)Diffuse light is reflected equally in all directions, but it depends thedirection of the light source. The intensity of the reflection depends onthe angle of incidence, but does not depend on the angle of reflection.
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 9 / 15
Diffuse Light
The angle of incidence varies over a curved surface.The more the light direction deviates from the normal, the weakerthe reflection.
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 10 / 15
Outline
1 Lighting
2 Ambient Light
3 Diffuse Light
4 Programming the ShadersAmbient Lighting ModelDiffuse Lighting Model
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 11 / 15
Outline
1 Lighting
2 Ambient Light
3 Diffuse Light
4 Programming the ShadersAmbient Lighting ModelDiffuse Lighting Model
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 12 / 15
Ambient Lighting Model
Let color be an RGB vector that represents the surface’sinherent color.Let ambient be an RGB vector that represents the intensity ofthe ambient light.The ambient reflection is computed as
color*ambient
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 13 / 15
Outline
1 Lighting
2 Ambient Light
3 Diffuse Light
4 Programming the ShadersAmbient Lighting ModelDiffuse Lighting Model
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 14 / 15
Diffuse Lighting Model
Letdiffuse be an RGB vector that represents the intensity of thediffuse light.light_dir be a unit vector indicating the direction of the lightsource.norm be a unit vector normal to the surface.
The diffuse reflection is computed ascolor*diffuse*dot(light_dir, norm)
If dot(light_dir, norm) < 0, then the diffuse contribution is0.Why?
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 15 / 15
Diffuse Lighting Model
Letdiffuse be an RGB vector that represents the intensity of thediffuse light.light_dir be a unit vector indicating the direction of the lightsource.norm be a unit vector normal to the surface.
The diffuse reflection is computed ascolor*diffuse*dot(light_dir, norm)
If dot(light_dir, norm) < 0, then the diffuse contribution is0.
Why?
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 15 / 15
Diffuse Lighting Model
Letdiffuse be an RGB vector that represents the intensity of thediffuse light.light_dir be a unit vector indicating the direction of the lightsource.norm be a unit vector normal to the surface.
The diffuse reflection is computed ascolor*diffuse*dot(light_dir, norm)
If dot(light_dir, norm) < 0, then the diffuse contribution is0.Why?
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 15 / 15
Outline
1 Lighting
2 Ambient Light
3 Diffuse Light
4 Programming the ShadersAmbient Lighting ModelDiffuse Lighting Model
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 16 / 15
Coordinate Systems
Computing ambient shading is simple, but we must be very carefulwhen computing diffuse shading.
When computing the dot product L · N of the light vector L and thenormal N, we must be sure that they are in the same coordinatesystem.The light vector is initially in world coordinate system.The normal vector is initially in model coordinates, so it must betransformed to world coordinates.
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 17 / 15
Coordinate Systems
Computing ambient shading is simple, but we must be very carefulwhen computing diffuse shading.When computing the dot product L · N of the light vector L and thenormal N, we must be sure that they are in the same coordinatesystem.
The light vector is initially in world coordinate system.The normal vector is initially in model coordinates, so it must betransformed to world coordinates.
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 17 / 15
Coordinate Systems
Computing ambient shading is simple, but we must be very carefulwhen computing diffuse shading.When computing the dot product L · N of the light vector L and thenormal N, we must be sure that they are in the same coordinatesystem.The light vector is initially in world coordinate system.
The normal vector is initially in model coordinates, so it must betransformed to world coordinates.
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 17 / 15
Coordinate Systems
Computing ambient shading is simple, but we must be very carefulwhen computing diffuse shading.When computing the dot product L · N of the light vector L and thenormal N, we must be sure that they are in the same coordinatesystem.The light vector is initially in world coordinate system.The normal vector is initially in model coordinates, so it must betransformed to world coordinates.
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 17 / 15
Coordinate Systems
To make the vectors compatible, we must transform N into worldcoordinates, using the model matrix.However, vectors do not transform in the same way as vertices.
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 18 / 15
Coordinate Systems
Let n be a vector and v = B − A be a vector from a point B on asurface to a point A on the surface.Let M1 be the model matrix and let M2 be the transformationmatrix for the normal vector.In model coordinates, we have nTv = 0, because n ⊥ v.Therefore, we need to have (M2n)T M1v = 0 as well.
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 19 / 15
Coordinate Systems
We have
(M2n)T M1v =(
nTMT2
)M1v
= nT(
MT2M1
)v
If MT2M1 is the identity matrix, then
nT(
MT2M1
)v = nTIv
= nTv= 0.
Therefore, M2n ⊥ M1v.
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 20 / 15
Coordinate Systems
Therefore, M2n ⊥ M1v provided that
M2 =(
MT1
)−1.
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 21 / 15
Coordinate Systems
It so happens that for any translation matrix T and for any rotationmatrix R, (
TT)−1
= T,(RT
)−1= R.
However, for scaling matrices S, in general(ST
)−16= S.
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 22 / 15
The ModelStack Class
The ModelStack Classvoid setModelLoc(GLuint m_loc);void setNormalLoc(GLuint n_loc);
The function setModelLoc() will store the uniform location ofthe model matrix (returned by glGetUniformLocation()) inthe ModelStack class.In the setNormalLoc() will store the uniform location of thenormal matrix (also returned by glGetUniformLocation()) inthe ModelStack class.
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 23 / 15
The ModelStack Class
The ModelStack ClassGLfloat* invtrans(mat4 m);void toShader();
The function invtrans() (private) will take a 4× 4 matrix m andreturn a pointer to 3× 3 matrix that is the inverse transpose of theupper-left 3× 3 submatrix of m.The function toShader() will transfer the model matrix to theshaders. If setNormalLoc() was called, then it will also transferthe inverse transpose of the normal matrix to the shaders.
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 24 / 15
The ModelStack Class
The ModelStack Functionmodel_stack.toShader();
The above function call is typical of what we should use whenusing the model stack or programming the lighting model.
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 25 / 15
Outline
1 Lighting
2 Ambient Light
3 Diffuse Light
4 Programming the ShadersAmbient Lighting ModelDiffuse Lighting Model
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 26 / 15
Assignment
AssignmentRead pp. 359 - 368, Classic Lighting Model.
Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Wed, Oct 2, 2019 27 / 15