2
0

Viewport.Pathtracer.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { WebGLPathTracer } from 'three-gpu-pathtracer';
  2. function ViewportPathtracer( renderer ) {
  3. let pathTracer = null;
  4. function init( scene, camera ) {
  5. if ( pathTracer === null ) {
  6. pathTracer = new WebGLPathTracer( renderer );
  7. pathTracer.filterGlossyFactor = 0.5;
  8. }
  9. pathTracer.setScene( scene, camera );
  10. }
  11. function setSize( /* width, height */ ) {
  12. if ( pathTracer === null ) return;
  13. // path tracer size automatically updates based on the canvas
  14. pathTracer.updateCamera();
  15. }
  16. function setBackground( /* background, blurriness */ ) {
  17. if ( pathTracer === null ) return;
  18. // update environment settings based on initialized scene fields
  19. pathTracer.updateEnvironment();
  20. }
  21. function updateMaterials() {
  22. if ( pathTracer === null ) return;
  23. pathTracer.updateMaterials();
  24. }
  25. function setEnvironment( /* environment */ ) {
  26. if ( pathTracer === null ) return;
  27. pathTracer.updateEnvironment();
  28. }
  29. function update() {
  30. if ( pathTracer === null ) return;
  31. pathTracer.renderSample();
  32. }
  33. function reset() {
  34. if ( pathTracer === null ) return;
  35. pathTracer.updateCamera();
  36. }
  37. function getSamples() {
  38. if ( pathTracer === null ) return;
  39. return pathTracer.samples;
  40. }
  41. return {
  42. init: init,
  43. setSize: setSize,
  44. setBackground: setBackground,
  45. setEnvironment: setEnvironment,
  46. updateMaterials: updateMaterials,
  47. update: update,
  48. reset: reset,
  49. getSamples: getSamples
  50. };
  51. }
  52. export { ViewportPathtracer };