Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/eevee/shaders/common_utiltex_lib.glsl
| #pragma BLENDER_REQUIRE(bsdf_common_lib.glsl) | #pragma BLENDER_REQUIRE(bsdf_common_lib.glsl) | ||||
| /* ---------------------------------------------------------------------- */ | /* ---------------------------------------------------------------------- */ | ||||
| /** \name Utiltex | /** \name Utiltex | ||||
| * | * | ||||
| * Utiltex is a sampler2DArray that stores a number of useful small utilitary textures and lookup | * Utiltex is a sampler2DArray that stores a number of useful small utilitary textures and lookup | ||||
| * tables. | * tables. | ||||
| * \{ */ | * \{ */ | ||||
| uniform sampler2DArray utilTex; | uniform sampler2DArray utilTex; | ||||
| #define LUT_SIZE 64 | #define LUT_SIZE 64 | ||||
| #define texelfetch_noise_tex(coord) texelFetch(utilTex, ivec3(ivec2(coord) % LUT_SIZE, 2.0), 0) | #define LTC_MAT_LAYER 0 | ||||
| #define LTC_BRDF_LAYER 1 | |||||
| #define BRDF_LUT_LAYER 1 | |||||
| #define NOISE_LAYER 2 | |||||
| #define LTC_DISK_LAYER 3 /* UNUSED */ | |||||
| /* Layers 4 to 20 are for BTDF Lut. */ | |||||
| #define texelfetch_noise_tex(coord) \ | |||||
| texelFetch(utilTex, ivec3(ivec2(coord) % LUT_SIZE, NOISE_LAYER), 0) | |||||
| /* Return texture coordinates to sample Surface LUT */ | /* Return texture coordinates to sample Surface LUT */ | ||||
| vec2 lut_coords(float cosTheta, float roughness) | vec2 lut_coords(float cosTheta, float roughness) | ||||
| { | { | ||||
| /* TODO(fclem) Ugly Acos here. Get rid ot this. Should use same mapping as lut_coords_ltc. */ | |||||
| float theta = acos(cosTheta); | float theta = acos(cosTheta); | ||||
| vec2 coords = vec2(roughness, theta / M_PI_2); | vec2 coords = vec2(roughness, theta / M_PI_2); | ||||
| /* scale and bias coordinates, for correct filtered lookup */ | /* scale and bias coordinates, for correct filtered lookup */ | ||||
| return coords * (LUT_SIZE - 1.0) / LUT_SIZE + 0.5 / LUT_SIZE; | return coords * (LUT_SIZE - 1.0) / LUT_SIZE + 0.5 / LUT_SIZE; | ||||
| } | } | ||||
| vec2 lut_coords_ltc(float cosTheta, float roughness) | vec2 lut_coords_ltc(float cosTheta, float roughness) | ||||
| { | { | ||||
| vec2 coords = vec2(roughness, sqrt(1.0 - cosTheta)); | vec2 coords = vec2(roughness, sqrt(1.0 - cosTheta)); | ||||
| /* scale and bias coordinates, for correct filtered lookup */ | /* scale and bias coordinates, for correct filtered lookup */ | ||||
| return coords * (LUT_SIZE - 1.0) / LUT_SIZE + 0.5 / LUT_SIZE; | return coords * (LUT_SIZE - 1.0) / LUT_SIZE + 0.5 / LUT_SIZE; | ||||
| } | } | ||||
| vec2 brdf_lut(float cosTheta, float roughness) | |||||
| { | |||||
| return textureLod(utilTex, vec3(lut_coords(cosTheta, roughness), BRDF_LUT_LAYER), 0.0).rg; | |||||
| } | |||||
| float get_btdf_lut(float NV, float roughness, float ior) | float get_btdf_lut(float NV, float roughness, float ior) | ||||
| { | { | ||||
| const vec3 lut_scale_bias_texel_size = vec3((LUT_SIZE - 1.0), 0.5, 1.5) / LUT_SIZE; | const vec3 lut_scale_bias_texel_size = vec3((LUT_SIZE - 1.0), 0.5, 1.5) / LUT_SIZE; | ||||
| vec3 coords; | vec3 coords; | ||||
| /* Try to compensate for the low resolution and interpolation error. */ | /* Try to compensate for the low resolution and interpolation error. */ | ||||
| coords.x = (ior > 1.0) ? (0.9 + lut_scale_bias_texel_size.z) + | coords.x = (ior > 1.0) ? (0.9 + lut_scale_bias_texel_size.z) + | ||||
| (0.1 - lut_scale_bias_texel_size.z) * f0_from_ior(ior) : | (0.1 - lut_scale_bias_texel_size.z) * f0_from_ior(ior) : | ||||
| Show All 23 Lines | |||||