Guest User

Untitled

a guest
Apr 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. def specularIllumination(h: Hit, l: LightSource): Color3f = {
  2. val direction = getLightDirection (h.location , l )
  3.  
  4. val reflected = reflectedVector (direction , h.normal )
  5. val vrn = pow (reflected.dot(direction).toFloat , h.material.kn).toFloat;
  6. // val temp = (new Color3f(1,1,1)).scale (h.material.ks)
  7. val specular = vrn * h.material.ks
  8. val color = ***(l.color, h.material.pigment)
  9. color.scale (specular)
  10. return color
  11. // var diffuse = (new Vector3d(direction)).dot(h.normal).toFloat
  12. // diffuse = if (diffuse <= 0) 0 else diffuse
  13. // val color = ***(l.color, h.material.pigment)
  14. // println(diffuse)
  15. // color.scale(diffuse)
  16. // color.scale(h.material.kd)
  17. }
  18.  
  19. def diffuseIllumination(h: Hit, l: LightSource): Color3f = {
  20. val direction = getLightDirection(h.location, l)
  21. var diffuse = (new Vector3d(direction)).dot(h.normal).toFloat
  22. diffuse = if (diffuse <= 0) 0 else diffuse
  23. val color = ***(l.color, h.material.pigment)
  24. // println(diffuse)
  25. color.scale(diffuse)
  26. color.scale(h.material.kd)
  27. return color
  28. }
  29.  
  30.  
  31. def calculateColor (h: Hit): Color3f = {
  32. val mat = h.material
  33. val color = mat.pigment
  34. val amb = ***(color, ambient)
  35. amb.scale(mat.ka)
  36. val total = new Color3f()
  37. lights foreach ((l:LightSource) => total.add(diffuseIllumination(h, l))) // All diffuse
  38. lights foreach ((l:LightSource) => total.add(specularIllumination(h, l))) // All specular
  39. total.add(amb) // Ambient
  40. total.clamp(0,1)
  41. return total;
  42. }
Add Comment
Please, Sign In to add comment