pathtrace_ball.tcl 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # Script demonstrating Global illumination materials
  2. # using path tracing rendering engine in 3D view
  3. #Category: Visualization
  4. #Title: Path tracing - Ball
  5. set aBallPath [locate_data_file occ/Ball.brep]
  6. pload MODELING VISUALIZATION
  7. # Ray-Tracing doesn't work with Compatible Profile on macOS
  8. if { $::tcl_platform(os) == "Darwin" } { vcaps -core }
  9. # Setup 3D viewer
  10. vclear
  11. vinit name=View1 w=512 h=512
  12. vglinfo
  13. vvbo 0
  14. vsetdispmode 1
  15. # Setup view parameters
  16. vcamera -persp
  17. vviewparams -scale 18 -eye 44.49 -0.15 33.93 -at -14.20 -0.15 1.87 -up -0.48 0.00 0.88
  18. # Load the model from disk
  19. puts "Importing shape..."
  20. restore $aBallPath ball
  21. # Tessellate the model
  22. incmesh ball 0.01
  23. # Display the model and assign material
  24. vdisplay -noupdate ball
  25. vsetmaterial -noupdate ball glass
  26. # Create a sphere inside the model
  27. psphere s 8
  28. incmesh s 0.01
  29. vdisplay -noupdate s
  30. vsetlocation -noupdate s 0 0 13
  31. vsetmaterial -noupdate s plaster
  32. # Create chessboard-style floor
  33. box tile 10 10 0.1
  34. eval compound [lrepeat 144 tile] tiles
  35. explode tiles
  36. for {set i 0} {$i < 12} {incr i} {
  37. for {set j 1} {$j <= 12} {incr j} {
  38. ttranslate tiles_[expr 12 * $i + $j] [expr $i * 10 - 90] [expr $j * 10 - 70] -0.15
  39. vdisplay -noupdate tiles_[expr 12 * $i + $j]
  40. vsetmaterial -noupdate tiles_[expr 12 * $i + $j] plaster
  41. if {($i + $j) % 2 == 0} {
  42. vbsdf tiles_[expr 12 * $i + $j] -kd 0.85
  43. } else {
  44. vbsdf tiles_[expr 12 * $i + $j] -kd 0.45
  45. }
  46. }
  47. }
  48. # Configure light sources
  49. vlight -change 0 -headLight 0
  50. vlight -change 0 -direction -0.25 -1 -1
  51. vlight -change 0 -smoothAngle 17
  52. vlight -change 0 -intensity 10.0
  53. # Load environment map
  54. vtextureenv on 1
  55. puts "Trying path tracing mode..."
  56. vrenderparams -ray -gi -rayDepth 10
  57. # Start progressive refinement mode
  58. #vprogressive
  59. puts "Make several path tracing iterations to refine the picture, please wait..."
  60. vfps 100
  61. puts "Done. To improve the image further, or after view manipulations, give command:"
  62. puts "vfps \[nb_iteratons\] or vrepaint -continuous"