From 30e5534447f267c2e6ecda3430e9b38121601c10 Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Thu, 19 Jan 2023 19:43:58 +0100 Subject: [PATCH] Fix specular lighting --- src/Ray.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Ray.kt b/src/Ray.kt index 1f7a689..9adc8d5 100644 --- a/src/Ray.kt +++ b/src/Ray.kt @@ -1,6 +1,5 @@ import java.io.File import java.lang.Float.max -import java.lang.Math.pow import kotlin.math.min import kotlin.math.pow import kotlin.math.sqrt @@ -57,7 +56,7 @@ fun main() { val ambient = MaterialColor(0.1f, 0.1f, 0.1f) val light = PointLight(Point(1000f, 1000f, -500f), color = MaterialColor(0.5f, 0.5f, 0.5f)) - val specular = 2.4f + val specular = 100f for (y in 0 until bmp.height) { for (x in 0 until bmp.width) { @@ -74,7 +73,7 @@ fun main() { val lambert = max(0f, dot(hit.normal, rayToLight.direction)) color += lambert * light.color - val h = (ray.direction + rayToLight.direction).normalized() + val h = (-ray.direction + rayToLight.direction).normalized() val intensity = dot(hit.normal, h).pow(specular)