lm_bake.sl 982 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. surface lm_bake (float Ka = 0.2, Kd = 0.5, Ks = 0.5;
  2. string bakefile = "";
  3. float roughness = 0.1;
  4. )
  5. {
  6. normal Nn = normalize(N);
  7. vector V = normalize(-I);
  8. extern point P;
  9. color env = 0;
  10. color lambert = 0;
  11. color occ = 0;
  12. // ENV ILLUMINANCE LOOP
  13. illuminance( "env", P,Nn, PI/2 )
  14. {
  15. env += Cs * Cl * normalize(L).Nn;
  16. bake( concat(bakefile,"_env.bake&binary"), s, t, env );
  17. }
  18. // SUN ILLUMINANCE LOOP
  19. illuminance("sun", P, Nn, PI/2 )
  20. {
  21. lambert += Cl * normalize(L).Nn;
  22. bake( concat(bakefile,"_diff.bake&binary"), s, t, lambert );
  23. }
  24. illuminance("occlusion", P, Nn, PI/2 )
  25. {
  26. occ += Cl;
  27. bake( concat(bakefile,"_occ.bake&binary"), s, t, occ );
  28. }
  29. color spec = specular(Nn, V, roughness);
  30. bake( concat(bakefile,"_spec.bake&binary"), s, t, spec );
  31. bake( concat(bakefile,"_shading.bake&binary"), s, t, (Ka * env + Kd * lambert) );
  32. Ci = (Cs * (Ka * env + Kd * lambert) + 1 * Ks * spec);
  33. }