summary refs log tree commit diff
diff options
context:
space:
mode:
authoriurii <[email protected]>2024-09-07 14:27:01 +0200
committeriurii <[email protected]>2024-09-07 14:27:01 +0200
commite4e90e53f02f6a431422c7790a7df34d396a3c6a (patch)
tree448dc3a12af3d25a63d030976adb41dff37f55d2
parentc5bf2b9de1504e60c007d3a166beb45c1eab64e9 (diff)
downloadfunhalla-e4e90e53f02f6a431422c7790a7df34d396a3c6a.tar.gz
specular mapping
-rw-r--r--res/images/container_specular.pngbin0 -> 144081 bytes
-rw-r--r--res/shaders/colors.fs4
-rw-r--r--src/main.odin14
3 files changed, 9 insertions, 9 deletions
diff --git a/res/images/container_specular.png b/res/images/container_specular.png
new file mode 100644
index 0000000..681bf6e
--- /dev/null
+++ b/res/images/container_specular.png
Binary files differdiff --git a/res/shaders/colors.fs b/res/shaders/colors.fs
index a486a92..6a42cbd 100644
--- a/res/shaders/colors.fs
+++ b/res/shaders/colors.fs
@@ -4,7 +4,7 @@ out vec4 FragColor;
 
 struct Material {
   sampler2D diffuse;
-  vec3 specular;
+  sampler2D specular;
   float shininess;
 };
 
@@ -39,7 +39,7 @@ void main() {
   vec3 view_dir = normalize(view_position - FragPos);
   vec3 reflect_dir = reflect(-light_dir, norm);
   float spec = pow(max(dot(view_dir, reflect_dir), 0.0), material.shininess);
-  vec3 specular = light.specular * (spec * material.specular);
+  vec3 specular = light.specular * spec * texture(material.specular, TexCoords).rgb;
 
   vec3 result = ambient + diffuse + specular;
   FragColor = vec4(result, 1.0);
diff --git a/src/main.odin b/src/main.odin
index e261abf..80080e4 100644
--- a/src/main.odin
+++ b/src/main.odin
@@ -191,6 +191,7 @@ main :: proc() {
 	defer gl.DeleteVertexArrays(1, &cube_vao)
 	defer gl.DeleteBuffers(1, &vbo)
   diffuse_map := load_texture("res/images/container.png")
+  specular_map := load_texture("res/images/container_specular.png")
 
   if diffuse_map == 0 {
     fmt.eprintln("could not load texture: exiting...")
@@ -216,6 +217,7 @@ main :: proc() {
 
   shader_use(lighting_shader)
   shader_set_i32(lighting_shader, "material.diffuse", 0)
+  shader_set_i32(lighting_shader, "material.specular", 1)
 	//gl.PolygonMode(gl.FRONT_AND_BACK, gl.LINE)
 
 	gl.Enable(gl.DEPTH_TEST)
@@ -233,19 +235,14 @@ main :: proc() {
 
 		shader_use(lighting_shader)
 
-		light_color := Vec3 {
-			cast(f32)math.sin(glfw.GetTime() * 2.0),
-			cast(f32)math.sin(glfw.GetTime() * 0.7),
-			cast(f32)math.sin(glfw.GetTime() * 1.3),
-		}
 		material_ambient := Vec3{1.0, 0.5, 0.31}
 		material_specular := Vec3{0.5, 0.5, 0.5}
 		shader_set_vec3(lighting_shader, cstring("material.ambient"), &material_ambient)
 		shader_set_vec3(lighting_shader, cstring("material.specular"), &material_specular)
 		shader_set_f32(lighting_shader, cstring("material.shininess"), 32.0)
 
-		light_diffuse := light_color * Vec3{0.5, 0.5, 0.05}
-		light_ambient := light_diffuse * Vec3{0.2, 0.2, 0.2}
+		light_diffuse := Vec3{0.5, 0.5, 0.05}
+		light_ambient :=  Vec3{0.2, 0.2, 0.2}
 		light_specular := Vec3{1.0, 1.0, 1.0}
 		shader_set_vec3(lighting_shader, cstring("light.ambient"), &light_ambient)
 		shader_set_vec3(lighting_shader, cstring("light.diffuse"), &light_diffuse)
@@ -276,6 +273,9 @@ main :: proc() {
     gl.ActiveTexture(gl.TEXTURE0)
     gl.BindTexture(gl.TEXTURE_2D, diffuse_map)
 
+    gl.ActiveTexture(gl.TEXTURE1)
+    gl.BindTexture(gl.TEXTURE_2D, specular_map)
+
 		gl.BindVertexArray(cube_vao)
 		gl.DrawArrays(gl.TRIANGLES, 0, 36)