123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- /*
- Copyright (c) 2006 soho vfx inc.
- Copyright (c) 2006 The 3Delight Team.
- */
- #ifndef _global_illumination_h
- #define _global_illumination_h
- #define NO_EFFECT 0
- #define OCCLUSION 1
- #define FAST_IBL 2
- #define FULL_GI 3
- float
- getGiEffect()
- {
- uniform float effect = 0;
- option( "user:_3dfm_gi_effect", effect );
-
- return effect;
- }
- float getGiAddToFinalMix()
- {
- uniform float add_to_final_mix = 0;
- option( "user:_3dfm_gi_add_to_final_mix", add_to_final_mix );
-
- return add_to_final_mix;
- }
- // Retrieves all global illumination effect variables
- color
- getGlobalIlluminationComponents(
- varying normal i_N;
- varying float i_roughness;
- varying color i_gi_weight;
- output varying color o_visibility;
- output varying color o_env_diffuse;
- output varying color o_color_bleeding;)
- {
- extern point P;
- extern vector I;
- vector V = -(normalize(I));
-
- shader gi_shader = getshader( "maya_gi_shader" );
- if( gi_shader != null )
- {
- uniform float effect = 0;
- getvar( gi_shader, "effect", effect );
- if( effect != 0 )
- {
- varying color gi = gi_shader->ComputeGI( P, i_N, V, i_roughness, i_gi_weight );
- getvar( gi_shader, "out_visibility", o_visibility );
- getvar( gi_shader, "out_environment_diffuse", o_env_diffuse );
- getvar( gi_shader, "out_color_bleeding", o_color_bleeding );
- return gi;
- }
- }
- o_visibility = 1;
- o_env_diffuse = 0;
- o_color_bleeding = 0;
- return color(0);
- }
- color
- computeIndirectDiffuseAndGIAOVs(
- color i_diffuse_factor;
- color i_surface_color;
- color i_surface_transparency;
- normal i_N )
- {
- color gi_weight = i_surface_color * i_diffuse_factor;
- color visibility;
- color env_diffuse;
- color color_bleeding;
- color gi = getGlobalIlluminationComponents(
- i_N, 0, gi_weight,
- visibility, env_diffuse, color_bleeding );
- #ifdef USE_AOV_aov_gi
- extern varying color aov_gi;
- extern color __transparency;
- aov_gi += __transparency * i_surface_color * i_diffuse_factor * gi;
- #endif
- #ifdef USE_AOV_aov_occlusion
- extern varying color aov_occlusion;
- extern color __transparency;
- aov_occlusion += __transparency *
- visibility * (1.0 - i_surface_transparency);
- #endif
- #ifdef USE_AOV_aov_env_diffuse
- extern varying color aov_env_diffuse;
- extern color __transparency;
- aov_env_diffuse += __transparency *
- i_surface_color * i_diffuse_factor * env_diffuse;
- #endif
- #ifdef USE_AOV_aov_indirect
- extern varying color aov_indirect;
- extern color __transparency;
- aov_indirect += __transparency *
- i_surface_color * i_diffuse_factor * color_bleeding;
- #endif
- return i_diffuse_factor * gi;
- }
- float
- getGiEnvironmentMapParameters(
- output uniform string envmap;
- output uniform string envspace;)
- {
- envmap = "";
- envspace = "";
-
- uniform float envmap_found =
- option( "user:_3dfm_gi_environment_map", envmap );
- option( "user:_3dfm_gi_environment_space", envspace );
-
- return envmap_found;
- }
- float
- getGiEnvironmentParameters(
- output uniform string envmap;
- output uniform string envspace;
- output uniform float env_intensity;
- output uniform color env_color_gain;
- output uniform color env_color_offset;
- output uniform float env_specularity; )
- {
- envmap = "";
- envspace = "";
- env_intensity = 1.0;
- env_color_gain = 1.0;
- env_color_offset = 0.0;
- env_specularity = 0;
- uniform float envmap_found = getGiEnvironmentMapParameters( envmap, envspace );
- if( envmap_found )
- {
- option( "user:_3dfm_gi_environment_intensity", env_intensity );
- option( "user:_3dfm_gi_environment_color_gain", env_color_gain );
- option( "user:_3dfm_gi_environment_color_offset", env_color_offset );
- option( "user:_3dfm_gi_environment_specularity", env_specularity );
- }
-
- return envmap_found;
- }
- // Computes the reflections caused by the IBL options of the
- // Global Illumination options of the render pass.
- //
- color getGiEnvironmentSpecular(
- vector i_dir;
- float i_samples;
- float i_blur)
- {
- color env_color = 0;
-
- uniform string envmap = "";
- uniform string envspace = "";
- uniform float env_intensity = 1.0;
- uniform color env_color_gain = 1.0;
- uniform color env_color_offset = 0.0;
- uniform float env_specularity = 0;
- uniform float envmap_found = getGiEnvironmentParameters( envmap, envspace,
- env_intensity, env_color_gain, env_color_offset, env_specularity );
- if( envmap_found != 0 && env_specularity > 0 )
- {
- vector dir = i_dir;
-
- if( envspace != "" )
- dir = transform( envspace, i_dir );
-
- env_color = environment(
- envmap, dir, dir, dir, dir,
- "samples", i_samples, "blur", i_blur);
- env_color = env_color * env_color_gain + env_color_offset;
- env_color *= env_intensity * env_specularity;
- }
- return env_color;
- }
- #endif
|