diff options
Diffstat (limited to 'source/blender/draw/engines/workbench/shaders/workbench_world_light_lib.glsl')
-rw-r--r-- | source/blender/draw/engines/workbench/shaders/workbench_world_light_lib.glsl | 55 |
1 files changed, 24 insertions, 31 deletions
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_world_light_lib.glsl b/source/blender/draw/engines/workbench/shaders/workbench_world_light_lib.glsl index 82d0d1fcd02..3df3b7c78a0 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_world_light_lib.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_world_light_lib.glsl @@ -1,59 +1,52 @@ #define BLINN -vec3 spherical_harmonics(vec3 N, vec3 spherical_harmonics_coefs[STUDIOLIGHT_SPHERICAL_HARMONICS_MAX_COMPONENTS]) +vec3 spherical_harmonics(vec3 N, vec3 sh_coefs[STUDIOLIGHT_SH_MAX_COMPONENTS]) { - vec3 sh = vec3(0.0); + vec3 sh = 0.282095 * sh_coefs[0]; - sh += 0.282095 * spherical_harmonics_coefs[0]; - -#if STUDIOLIGHT_SPHERICAL_HARMONICS_LEVEL > 0 +#if STUDIOLIGHT_SH_BANDS > 1 float nx = N.x; float ny = N.y; float nz = N.z; - sh += -0.488603 * nz * spherical_harmonics_coefs[1]; - sh += 0.488603 * ny * spherical_harmonics_coefs[2]; - sh += -0.488603 * nx * spherical_harmonics_coefs[3]; + sh += -0.488603 * nz * sh_coefs[1]; + sh += 0.488603 * ny * sh_coefs[2]; + sh += -0.488603 * nx * sh_coefs[3]; #endif - -#if STUDIOLIGHT_SPHERICAL_HARMONICS_LEVEL > 1 +#if STUDIOLIGHT_SH_BANDS > 2 float nx2 = nx * nx; float ny2 = ny * ny; float nz2 = nz * nz; - - sh += 1.092548 * nx * nz * spherical_harmonics_coefs[4]; - sh += -1.092548 * nz * ny * spherical_harmonics_coefs[5]; - sh += 0.315392 * (3.0 * ny2 - 1.0) * spherical_harmonics_coefs[6]; - sh += -1.092548 * nx * ny * spherical_harmonics_coefs[7]; - sh += 0.546274 * (nx2 - nz2) * spherical_harmonics_coefs[8]; + sh += 1.092548 * nx * nz * sh_coefs[4]; + sh += -1.092548 * nz * ny * sh_coefs[5]; + sh += 0.315392 * (3.0 * ny2 - 1.0) * sh_coefs[6]; + sh += -1.092548 * nx * ny * sh_coefs[7]; + sh += 0.546274 * (nx2 - nz2) * sh_coefs[8]; #endif - -#if STUDIOLIGHT_SPHERICAL_HARMONICS_LEVEL > 3 +#if STUDIOLIGHT_SH_BANDS > 4 float nx4 = nx2 * nx2; float ny4 = ny2 * ny2; float nz4 = nz2 * nz2; - - sh += (2.5033429417967046 * nx * nz * (nx2 - nz2)) * spherical_harmonics_coefs[9]; - sh += (-1.7701307697799304 * nz * ny * (3.0 * nx2 - nz2)) * spherical_harmonics_coefs[10]; - sh += (0.9461746957575601 * nz * nx * (-1.0 +7.0*ny2)) * spherical_harmonics_coefs[11]; - sh += (-0.6690465435572892 * nz * ny * (-3.0 + 7.0 * ny2)) * spherical_harmonics_coefs[12]; - sh += ((105.0*ny4-90.0*ny2+9.0)/28.359261614) * spherical_harmonics_coefs[13]; - sh += (-0.6690465435572892 * nx * ny * (-3.0 + 7.0 * ny2)) * spherical_harmonics_coefs[14]; - sh += (0.9461746957575601 * (nx2 - nz2) * (-1.0 + 7.0 * ny2)) * spherical_harmonics_coefs[15]; - sh += (-1.7701307697799304 * nx * ny * (nx2 - 3.0 * nz2)) * spherical_harmonics_coefs[16]; - sh += (0.6258357354491761 * (nx4 - 6.0 * nz2 * nx2 + nz4)) * spherical_harmonics_coefs[17]; + sh += (2.5033429417967046 * nx * nz * (nx2 - nz2)) * sh_coefs[9]; + sh += (-1.7701307697799304 * nz * ny * (3.0 * nx2 - nz2)) * sh_coefs[10]; + sh += (0.9461746957575601 * nz * nx * (-1.0 +7.0*ny2)) * sh_coefs[11]; + sh += (-0.6690465435572892 * nz * ny * (-3.0 + 7.0 * ny2)) * sh_coefs[12]; + sh += ((105.0*ny4-90.0*ny2+9.0)/28.359261614) * sh_coefs[13]; + sh += (-0.6690465435572892 * nx * ny * (-3.0 + 7.0 * ny2)) * sh_coefs[14]; + sh += (0.9461746957575601 * (nx2 - nz2) * (-1.0 + 7.0 * ny2)) * sh_coefs[15]; + sh += (-1.7701307697799304 * nx * ny * (nx2 - 3.0 * nz2)) * sh_coefs[16]; + sh += (0.6258357354491761 * (nx4 - 6.0 * nz2 * nx2 + nz4)) * sh_coefs[17]; #endif - return sh; } vec3 get_world_diffuse_light(WorldData world_data, vec3 N) { - return (spherical_harmonics(vec3(N.x, N.y, -N.z), world_data.spherical_harmonics_coefs)); + return spherical_harmonics(N, world_data.spherical_harmonics_coefs); } vec3 get_camera_diffuse_light(WorldData world_data, vec3 N) { - return (spherical_harmonics(vec3(N.x, -N.z, -N.y), world_data.spherical_harmonics_coefs)); + return spherical_harmonics(vec3(N.x, -N.z, N.y), world_data.spherical_harmonics_coefs); } /* N And I are in View Space. */ |