Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/eevee/shaders/ltc_lib.glsl
| /** | /** | ||||
| * Adapted from : | * Adapted from : | ||||
| * Real-Time Polygonal-Light Shading with Linearly Transformed Cosines. | * Real-Time Polygonal-Light Shading with Linearly Transformed Cosines. | ||||
| * Eric Heitz, Jonathan Dupuy, Stephen Hill and David Neubelt. | * Eric Heitz, Jonathan Dupuy, Stephen Hill and David Neubelt. | ||||
| * ACM Transactions on Graphics (Proceedings of ACM SIGGRAPH 2016) 35(4), 2016. | * ACM Transactions on Graphics (Proceedings of ACM SIGGRAPH 2016) 35(4), 2016. | ||||
| * Project page: https://eheitzresearch.wordpress.com/415-2/ | * Project page: https://eheitzresearch.wordpress.com/415-2/ | ||||
| */ | */ | ||||
| /* Ensure common_utiltex_lib is included first. */ | |||||
| #pragma BLENDER_REQUIRE(common_utiltex_lib.glsl) | |||||
| #define USE_LTC | #define USE_LTC | ||||
| /* Diffuse *clipped* sphere integral. */ | /* Diffuse *clipped* sphere integral. */ | ||||
| float diffuse_sphere_integral(float avg_dir_z, float form_factor) | float diffuse_sphere_integral(float avg_dir_z, float form_factor) | ||||
| { | { | ||||
| #if 1 | #if 1 | ||||
| /* use tabulated horizon-clipped sphere */ | /* use tabulated horizon-clipped sphere */ | ||||
| vec2 uv = vec2(avg_dir_z * 0.5 + 0.5, form_factor); | vec2 uv = vec2(avg_dir_z * 0.5 + 0.5, form_factor); | ||||
| ▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | |||||
| mat3 ltc_matrix(vec4 lut) | mat3 ltc_matrix(vec4 lut) | ||||
| { | { | ||||
| /* load inverse matrix */ | /* load inverse matrix */ | ||||
| mat3 Minv = mat3(vec3(lut.x, 0, lut.y), vec3(0, 1, 0), vec3(lut.z, 0, lut.w)); | mat3 Minv = mat3(vec3(lut.x, 0, lut.y), vec3(0, 1, 0), vec3(lut.z, 0, lut.w)); | ||||
| return Minv; | return Minv; | ||||
| } | } | ||||
| #ifdef GPU_METAL | |||||
| void ltc_transform_quad(vec3 N, vec3 V, mat3 Minv, thread vec3 *corners) | |||||
| #else | |||||
| void ltc_transform_quad(vec3 N, vec3 V, mat3 Minv, inout vec3 corners[4]) | void ltc_transform_quad(vec3 N, vec3 V, mat3 Minv, inout vec3 corners[4]) | ||||
| #endif | |||||
| { | { | ||||
| /* Avoid dot(N, V) == 1 in ortho mode, leading T1 normalize to fail. */ | /* Avoid dot(N, V) == 1 in ortho mode, leading T1 normalize to fail. */ | ||||
| V = normalize(V + 1e-8); | V = normalize(V + 1e-8); | ||||
| /* construct orthonormal basis around N */ | /* construct orthonormal basis around N */ | ||||
| vec3 T1, T2; | vec3 T1, T2; | ||||
| T1 = normalize(V - N * dot(N, V)); | T1 = normalize(V - N * dot(N, V)); | ||||
| T2 = cross(N, T1); | T2 = cross(N, T1); | ||||
| ▲ Show 20 Lines • Show All 150 Lines • Show Last 20 Lines | |||||