global_illumination.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. Copyright (c) 2006 soho vfx inc.
  3. Copyright (c) 2006 The 3Delight Team.
  4. */
  5. #ifndef _global_illumination_h
  6. #define _global_illumination_h
  7. #define NO_EFFECT 0
  8. #define OCCLUSION 1
  9. #define FAST_IBL 2
  10. #define FULL_GI 3
  11. float
  12. getGiEffect()
  13. {
  14. uniform float effect = 0;
  15. option( "user:_3dfm_gi_effect", effect );
  16. return effect;
  17. }
  18. float getGiAddToFinalMix()
  19. {
  20. uniform float add_to_final_mix = 0;
  21. option( "user:_3dfm_gi_add_to_final_mix", add_to_final_mix );
  22. return add_to_final_mix;
  23. }
  24. // Retrieves all global illumination effect variables
  25. color
  26. getGlobalIlluminationComponents(
  27. varying normal i_N;
  28. varying float i_roughness;
  29. varying color i_gi_weight;
  30. output varying color o_visibility;
  31. output varying color o_env_diffuse;
  32. output varying color o_color_bleeding;)
  33. {
  34. extern point P;
  35. extern vector I;
  36. vector V = -(normalize(I));
  37. shader gi_shader = getshader( "maya_gi_shader" );
  38. if( gi_shader != null )
  39. {
  40. uniform float effect = 0;
  41. getvar( gi_shader, "effect", effect );
  42. if( effect != 0 )
  43. {
  44. varying color gi = gi_shader->ComputeGI( P, i_N, V, i_roughness, i_gi_weight );
  45. getvar( gi_shader, "out_visibility", o_visibility );
  46. getvar( gi_shader, "out_environment_diffuse", o_env_diffuse );
  47. getvar( gi_shader, "out_color_bleeding", o_color_bleeding );
  48. return gi;
  49. }
  50. }
  51. o_visibility = 1;
  52. o_env_diffuse = 0;
  53. o_color_bleeding = 0;
  54. return color(0);
  55. }
  56. color
  57. computeIndirectDiffuseAndGIAOVs(
  58. color i_diffuse_factor;
  59. color i_surface_color;
  60. color i_surface_transparency;
  61. normal i_N )
  62. {
  63. color gi_weight = i_surface_color * i_diffuse_factor;
  64. color visibility;
  65. color env_diffuse;
  66. color color_bleeding;
  67. color gi = getGlobalIlluminationComponents(
  68. i_N, 0, gi_weight,
  69. visibility, env_diffuse, color_bleeding );
  70. #ifdef USE_AOV_aov_gi
  71. extern varying color aov_gi;
  72. extern color __transparency;
  73. aov_gi += __transparency * i_surface_color * i_diffuse_factor * gi;
  74. #endif
  75. #ifdef USE_AOV_aov_occlusion
  76. extern varying color aov_occlusion;
  77. extern color __transparency;
  78. aov_occlusion += __transparency *
  79. visibility * (1.0 - i_surface_transparency);
  80. #endif
  81. #ifdef USE_AOV_aov_env_diffuse
  82. extern varying color aov_env_diffuse;
  83. extern color __transparency;
  84. aov_env_diffuse += __transparency *
  85. i_surface_color * i_diffuse_factor * env_diffuse;
  86. #endif
  87. #ifdef USE_AOV_aov_indirect
  88. extern varying color aov_indirect;
  89. extern color __transparency;
  90. aov_indirect += __transparency *
  91. i_surface_color * i_diffuse_factor * color_bleeding;
  92. #endif
  93. return i_diffuse_factor * gi;
  94. }
  95. float
  96. getGiEnvironmentMapParameters(
  97. output uniform string envmap;
  98. output uniform string envspace;)
  99. {
  100. envmap = "";
  101. envspace = "";
  102. uniform float envmap_found =
  103. option( "user:_3dfm_gi_environment_map", envmap );
  104. option( "user:_3dfm_gi_environment_space", envspace );
  105. return envmap_found;
  106. }
  107. float
  108. getGiEnvironmentParameters(
  109. output uniform string envmap;
  110. output uniform string envspace;
  111. output uniform float env_intensity;
  112. output uniform color env_color_gain;
  113. output uniform color env_color_offset;
  114. output uniform float env_specularity; )
  115. {
  116. envmap = "";
  117. envspace = "";
  118. env_intensity = 1.0;
  119. env_color_gain = 1.0;
  120. env_color_offset = 0.0;
  121. env_specularity = 0;
  122. uniform float envmap_found = getGiEnvironmentMapParameters( envmap, envspace );
  123. if( envmap_found )
  124. {
  125. option( "user:_3dfm_gi_environment_intensity", env_intensity );
  126. option( "user:_3dfm_gi_environment_color_gain", env_color_gain );
  127. option( "user:_3dfm_gi_environment_color_offset", env_color_offset );
  128. option( "user:_3dfm_gi_environment_specularity", env_specularity );
  129. }
  130. return envmap_found;
  131. }
  132. // Computes the reflections caused by the IBL options of the
  133. // Global Illumination options of the render pass.
  134. //
  135. color getGiEnvironmentSpecular(
  136. vector i_dir;
  137. float i_samples;
  138. float i_blur)
  139. {
  140. color env_color = 0;
  141. uniform string envmap = "";
  142. uniform string envspace = "";
  143. uniform float env_intensity = 1.0;
  144. uniform color env_color_gain = 1.0;
  145. uniform color env_color_offset = 0.0;
  146. uniform float env_specularity = 0;
  147. uniform float envmap_found = getGiEnvironmentParameters( envmap, envspace,
  148. env_intensity, env_color_gain, env_color_offset, env_specularity );
  149. if( envmap_found != 0 && env_specularity > 0 )
  150. {
  151. vector dir = i_dir;
  152. if( envspace != "" )
  153. dir = transform( envspace, i_dir );
  154. env_color = environment(
  155. envmap, dir, dir, dir, dir,
  156. "samples", i_samples, "blur", i_blur);
  157. env_color = env_color * env_color_gain + env_color_offset;
  158. env_color *= env_intensity * env_specularity;
  159. }
  160. return env_color;
  161. }
  162. #endif