Skip to content

Commit 313c702

Browse files
committed
Updated light directory
1 parent 525c656 commit 313c702

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

8-light/main.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,16 +334,15 @@ int main()
334334
// Unbind mesh from global state
335335
mesh.unbind();
336336

337-
GLuint texture;
337+
GLuint diffuseMap, specularMap;
338338
colorShader.use();
339339
// Load texture to "texture" variable
340-
colorShader.loadTexture(PWD + "/../../assets/container2.png", &texture, GL_TEXTURE_2D, GL_REPEAT, GL_LINEAR, 0, GL_RGBA, 0, GL_RGBA, GL_UNSIGNED_BYTE);
341-
// Set texture unit 0 active (unnecessary if we have only one texture, texture unit 0 is the default)
342-
glActiveTexture(GL_TEXTURE0);
343-
// Bind "texture" to texture unit 0
344-
glBindTexture(GL_TEXTURE0, texture);
340+
colorShader.loadTexture(PWD + "/../../assets/container2.png", &diffuseMap, GL_TEXTURE_2D, GL_REPEAT, GL_LINEAR, 0, GL_RGBA, 0, GL_RGBA, GL_UNSIGNED_BYTE);
345341
// Make material's sampler2D to point to our texture at texture unit 0
346342
colorShader.setInt("material.diffuse", 0);
343+
344+
colorShader.loadTexture(PWD + "/../../assets/container2_specular.png", &specularMap, GL_TEXTURE_2D, GL_REPEAT, GL_LINEAR, 0, GL_RGBA, 0, GL_RGBA, GL_UNSIGNED_BYTE);
345+
colorShader.setInt("material.specular", 1);
347346
colorShader.unbind();
348347

349348
// Create new Mesh object for light cube
@@ -438,6 +437,15 @@ int main()
438437
model = glm::rotate(model, glm::radians(angle), rotationVec);
439438
// Set changes made to model
440439
colorShader.setMatrix4fv("model", 1, GL_FALSE, glm::value_ptr(model));
440+
441+
// Set texture unit 0 active (unnecessary if we have only one texture, texture unit 0 is the default)
442+
glActiveTexture(GL_TEXTURE0);
443+
// Bind "diffuseMap" to texture unit 0
444+
glBindTexture(GL_TEXTURE_2D, diffuseMap);
445+
446+
glActiveTexture(GL_TEXTURE1);
447+
// Bind "specularMap" to texture unit 1
448+
glBindTexture(GL_TEXTURE_2D, specularMap);
441449
}
442450
// Render model
443451
mesh.render(GL_TRIANGLES, 36, GL_UNSIGNED_INT, nullptr);

8-light/shaders/color.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ uniform vec3 viewPosition;
1111
struct Material
1212
{
1313
sampler2D diffuse;
14-
vec3 specular;
14+
sampler2D specular;
1515
float shininess;
1616
};
1717

@@ -41,7 +41,7 @@ void main()
4141
vec3 viewDirection = normalize(viewPosition - fragPosition);
4242
vec3 reflectedLightDirection = reflect(-lightDirection, norm);
4343
float specular = pow(max(dot(viewDirection, reflectedLightDirection), 0.0), material.shininess);
44-
vec3 specularLight = (specular * material.specular) * material.shininess * light.specular;
44+
vec3 specularLight = specular * light.specular * material.shininess * texture(material.specular, textureCoordinates).rgb;
4545

4646
// By mixing different light components we get the Phong light model
4747
vec3 result = specularLight + diffuseLight + ambientLight;

assets/container2_specular.png

141 KB
Loading

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy