Created
November 3, 2009 03:08
-
-
Save abuiles/224744 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def specularIllumination(h: Hit, l: LightSource): Color3f = { | |
val direction = getLightDirection (h.location , l ) | |
val reflected = reflectedVector (direction , h.normal ) | |
val vrn = pow (reflected.dot(direction).toFloat , h.material.kn).toFloat; | |
// val temp = (new Color3f(1,1,1)).scale (h.material.ks) | |
val specular = vrn * h.material.ks | |
val color = ***(l.color, h.material.pigment) | |
color.scale (specular) | |
return color | |
// var diffuse = (new Vector3d(direction)).dot(h.normal).toFloat | |
// diffuse = if (diffuse <= 0) 0 else diffuse | |
// val color = ***(l.color, h.material.pigment) | |
// println(diffuse) | |
// color.scale(diffuse) | |
// color.scale(h.material.kd) | |
} | |
def diffuseIllumination(h: Hit, l: LightSource): Color3f = { | |
val direction = getLightDirection(h.location, l) | |
var diffuse = (new Vector3d(direction)).dot(h.normal).toFloat | |
diffuse = if (diffuse <= 0) 0 else diffuse | |
val color = ***(l.color, h.material.pigment) | |
// println(diffuse) | |
color.scale(diffuse) | |
color.scale(h.material.kd) | |
return color | |
} | |
def calculateColor (h: Hit): Color3f = { | |
val mat = h.material | |
val color = mat.pigment | |
val amb = ***(color, ambient) | |
amb.scale(mat.ka) | |
val total = new Color3f() | |
lights foreach ((l:LightSource) => total.add(diffuseIllumination(h, l))) // All diffuse | |
lights foreach ((l:LightSource) => total.add(specularIllumination(h, l))) // All specular | |
total.add(amb) // Ambient | |
total.clamp(0,1) | |
return total; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment