Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
Add Comment
Please, Sign In to add comment