Permalink
Switch branches/tags
develop docs feature/add_atmospherics_ambient_to_deferred_shader feature/analytic_radiance_functions feature/ansiotropic_ggx feature/atmospherics_ambient feature/atmospherics_sky_scattering feature/atmospherics feature/basic_gui feature/better_diffuse_model_fitting_ggx feature/binary_voxelize feature/binding_set_pool_instances_deletion_queue feature/brdf_fitter feature/buffer_object_sparse_commitment_bitmap feature/bug_attributed_string_infinite_loop feature/camera_projection_model_update feature/cleanup_demo_scene feature/comments_doxygen feature/concurrent_gpu_data_structures feature/concurrent_vector feature/cone_tracing feature/correct_cpp_language_issues feature/correct_gbuffer_generation feature/cull_shadow_faces feature/depth_of_field feature/directional_lights feature/dof_bokeh_circle_of_confusion_handle_infinity feature/dual_quaternion_tranform feature/external_binding_sets_specialization_constants feature/fresnel_better_routines feature/fxaa feature/gbuffer_use_images feature/gcc_support feature/ggx_fittings_correct_integration feature/git_lfs feature/glsl_programs_pool feature/glsl_remove_nv_extensions feature/gpu_timer_query_and_performance_visualization feature/icc16_win_compilation feature/integrate_glsllang_spirv_compiler feature/integrate_graphics_modules_into_primary_renderer feature/inverted_depth_buffer feature/khr_dedicated_allocation feature/layered_surface_reflection feature/lights_merge_transformed_position feature/linearly_transformed_cosines feature/material_and_light_frameworks feature/material_correct_ior_probabilistic_approach feature/material_textures_storage feature/microfacet_energy_perservation_with_different_ior_layers feature/mipmap_depth_buffer feature/model_factory_support_displacement_and_normal_maps feature/more_info_on_debug_gui feature/multi_layered_materials feature/multiple_nonconsecutive_binding_sets feature/normalize_classes_and_objects_name_case feature/observable_resource_custom_resource_updater feature/octree_traversal feature/optimizations feature/optimizations2 feature/order_independant_trasnparency feature/organize_secondary_command_buffers feature/organize_shaders_function_parameters feature/pack_linked_light_list_element feature/pack_material_and_layer_descriptors feature/packed_gbuffer feature/pcf_shadow feature/per_pixel_linked_light_lists feature/polygonal_lights feature/projection_buffer_add_backbuffer_size feature/refactor_gpu_dispatchable feature/remove_oit_remove_gbuffer_ll feature/rendering_system feature/resource_loader feature/resource_storage feature/scene_and_objects feature/scene_frustum_cull feature/screen_space_soft_shadows feature/sequential_ordering_optimization_of_gpu_dispatch feature/shared_futex feature/signalling_storages_on_modification feature/small_allocator feature/ste_allocator feature/stohastic_light_culling_based_on_hdr_exposure feature/subsurface_scattering_multiple_scatters feature/subsurface_scattering feature/surface_block_readwrite_avx feature/surfaces feature/switch_models_and_materials_to_analytic_materials feature/task_dispatch_graph feature/task_future feature/task_scheduler_futures_execute_synchronously_when_applicable feature/tasks_cleanup feature/third_party feature/todo_hardware_destructive_interference_size feature/todo_pipeline_layout_exception_mention_variable_names feature/todo_strong_typed_common_types feature/translate_model_factory feature/uniform_distribution_light_integration feature/update_submodule_220916 feature/utility_buffer_image_host_read feature/volumetric_scattering_depth_aware_sampling feature/volumetric_scattering feature/volumetric_stratified_sampling feature/voxel_bricks_texture feature/voxels_data_and_interpolation feature/voxels_interpolate feature/vulkan_hdr_module feature/vulkan_objects_debug_name_markers feature/vulkan_primary_renderer feature/vulkan_sponza_gui_profiler feature/vulkan_text_engine feature/vulkan_translate_graphics_modules feature/vulkan master release/sponza_demo_022017 ssao_cone_trace
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
102 lines (84 sloc) 2.91 KB
#include <common.glsl>
#include <erf.glsl>
/*
* Evaluate Fresnel transmission using precomputed fitting for GGX NDF (v3)
*
* @param microfacet_transmission_fit_lut Look-up-table
* @param v Outbound vector (facing away from fragment to camera)
* @param n Normal
* @param roughness Material roughness
* @param refractive_ratio Ratio of refractive-indices, ior2/ior1
*/
float ggx_transmission_ratio_v3(sampler2DArray microfacet_transmission_fit_lut,
vec3 v,
vec3 n,
float roughness,
float refractive_ratio) {
const float Rmin = .2;
const float Rmax = 3.2;
float x = dot(v, n);
float ior_ratio = clamp((refractive_ratio - Rmin) / (Rmax - Rmin), .0f, 1.f);
vec2 uv = vec2(ior_ratio, roughness);
vec3 lut0 = texture(microfacet_transmission_fit_lut, vec3(uv, 0)).xyz;
vec3 lut1 = texture(microfacet_transmission_fit_lut, vec3(uv, 1)).xyz;
vec2 a = lut0.xy;
vec2 b = vec2(lut0.z, lut1.z);
vec2 c = lut1.xy;
vec2 t = (vec2(x) + b) * c;
vec2 gauss = a * exp(-(t * t));
return clamp(gauss.x + gauss.y, .0f, 1.f);
}
/*
* Evaluate Fresnel transmission using precomputed fitting for GGX NDF (v4)
*
* @param microfacet_transmission_fit_lut Look-up-table
* @param v Outbound vector (facing away from fragment to camera)
* @param n Normal
* @param roughness Material roughness
* @param refractive_ratio Ratio of refractive-indices, ior2/ior1
*/
float ggx_transmission_ratio_v4(sampler2DArray microfacet_transmission_fit_lut,
vec3 v,
vec3 n,
float roughness,
float refractive_ratio) {
const float Rmin = .2;
const float Rmax = 3.2;
float x = dot(v, n);
float ior_ratio = clamp((refractive_ratio - Rmin) / (Rmax - Rmin), .0f, 1.f);
vec2 uv = vec2(ior_ratio, roughness);
vec3 lut0 = texture(microfacet_transmission_fit_lut, vec3(uv, 0)).xyz;
vec3 lut1 = texture(microfacet_transmission_fit_lut, vec3(uv, 1)).xyz;
float a = lut0.x;
float b = lut0.y;
float c = lut0.z;
float d = lut1.x;
float m = lut1.y;
return clamp(m*((erf(a*x - b) + 1.f) + c*x) + d, .0f, 1.f);
}
/*
* Evaluate refracted vector using precomputed fitting for GGX NDF
*
* @param microfacet_refraction_fit_lut Look-up-table
* @param v Outbound vector (facing away from fragment to camera)
* @param n Normal
* @param roughness Material roughness
* @param refractive_ratio Ratio of refractive-indices, ior2/ior1
*/
vec3 ggx_refract(sampler2D microfacet_refraction_fit_lut,
vec3 v,
vec3 n,
float roughness,
float refractive_ratio) {
const float Rmin = .2;
const float Rmax = 3.2;
float x = dot(v, n);
float ior_ratio = clamp((refractive_ratio - Rmin) / (Rmax - Rmin), .0f, 1.f);
vec2 uv = vec2(ior_ratio, roughness);
vec4 lut = texture(microfacet_refraction_fit_lut, uv);
vec2 fit = lut.xz * exp(lut.yw * vec2(x));
float vx = -clamp(fit.x + fit.y, -1.f, 1.f);
vec3 w = normalize(cross(n,cross(n,v)));
vec3 t = vx * w - sqrt(1 - vx*vx) * n;
return t;
}