Fix specular lighting
This commit is contained in:
parent
c7d89dc55a
commit
30e5534447
1 changed files with 2 additions and 3 deletions
|
@ -1,6 +1,5 @@
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.lang.Float.max
|
import java.lang.Float.max
|
||||||
import java.lang.Math.pow
|
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
import kotlin.math.pow
|
import kotlin.math.pow
|
||||||
import kotlin.math.sqrt
|
import kotlin.math.sqrt
|
||||||
|
@ -57,7 +56,7 @@ fun main() {
|
||||||
val ambient = MaterialColor(0.1f, 0.1f, 0.1f)
|
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 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 (y in 0 until bmp.height) {
|
||||||
for (x in 0 until bmp.width) {
|
for (x in 0 until bmp.width) {
|
||||||
|
@ -74,7 +73,7 @@ fun main() {
|
||||||
val lambert = max(0f, dot(hit.normal, rayToLight.direction))
|
val lambert = max(0f, dot(hit.normal, rayToLight.direction))
|
||||||
color += lambert * light.color
|
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)
|
val intensity = dot(hit.normal, h).pow(specular)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue