This is achieved by sending corresponding texture coordinates for each vertex to the fragement shader. A new function called setupTextures()
is added to setup the corresponding textures for each model. In the fragmetn shader, texture2D
is used to obtain the required texture color to draw.
References:
A new uniform is defined in the fragment shader that represents one of three lighting modes according to which a different lighting formula is used. One of three possible values that can be sent to fragment shader is toggled when "B" is pressed.
References:
Another uniform is defined in the fragment shader that represents the alpha value of the material. This is used while setting gl_FragColor
according to the currently set lighting mode. In renderModels()
, the opaque models (alpha == 1.0) are rendered first and then the transparent models.
In renderModels()
, all the opaque models are rendered as before. Then, all transparent models (triangles and ellipsoids) are sorted by z-value and rendered in order.