lm_bake.sl 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "shading_utils.h"
  2. surface lm_bake (float Ka = 0.2, Kd = 0.5, Ks = 0.5;
  3. string bakefile = "";
  4. float roughness = 0.1;
  5. )
  6. {
  7. normal Nn = normalize(N);
  8. vector V = normalize(-I);
  9. extern point P;
  10. color env = 0;
  11. color lambert = 0;
  12. color occ = 0;
  13. color shadowfactor = 0;
  14. //float shadow;
  15. // ENV ILLUMINANCE LOOP
  16. illuminance( "env", P,Nn, PI/2 )
  17. {
  18. env += Cs * Cl * normalize(L).Nn;
  19. bake( concat(bakefile,"_env.bake&binary"), s, t, env );
  20. }
  21. // SUN ILLUMINANCE LOOP
  22. illuminance("sun", P, Nn, PI/2 )
  23. {
  24. lambert += Cl * normalize(L).Nn;
  25. bake( concat(bakefile,"_diff.bake&binary"), s, t, lambert );
  26. }
  27. // OCCLUSION ILLUMINANCE LOOP
  28. illuminance("occlusion", P, Nn, PI/2 )
  29. {
  30. occ += Cl;
  31. bake( concat(bakefile,"_occ.bake&binary"), s, t, occ );
  32. }
  33. // SHADOW ILLUMINANCE LOOP
  34. illuminance("sun", P, Nn, PI/2 )
  35. {
  36. shadowfactor += Cl;
  37. bake( concat(bakefile,"_shadow.bake&binary"), s, t, shadowfactor );
  38. }
  39. color spec = specular(Nn, V, roughness);
  40. bake( concat(bakefile,"_spec.bake&binary"), s, t, spec );
  41. bake( concat(bakefile,"_shading.bake&binary"), s, t, (Ka * env + Kd * lambert) );
  42. //float aov_shadow = computeShadowValue(N);
  43. //bake( concat(bakefile,"_shadow.bake&binary"), s, t, aov_shadow );
  44. Ci = (Cs * (Ka * env + Kd * lambert) + 1 * Ks * spec);
  45. }