| 54 | /////////////////////////////////////////// |
| 55 | |
| 56 | void sh_add(spherical_harmonics_t &to, vec3 light_dir, vec3 light_color) { |
| 57 | light_dir = { -light_dir.x, -light_dir.y, light_dir.z }; |
| 58 | |
| 59 | // From DirectXMath's XMSHEvalDirectionalLight. See: |
| 60 | // https://github.com/microsoft/DirectXMath/blob/master/SHMath/DirectXSH.cpp#L4476 |
| 61 | |
| 62 | // CosWtInt |
| 63 | const float fCW0 = 0.25f; |
| 64 | const float fCW1 = 0.5f; |
| 65 | const float fRet = MATH_PI / (fCW0 + fCW1); |
| 66 | light_color = light_color * fRet; |
| 67 | |
| 68 | // The rest is a mix of XMSHEvalDirectionalLight, XMSHEvalDirection, and |
| 69 | // sh_eval_basis_2 |
| 70 | const float z2 = light_dir.z*light_dir.z; |
| 71 | const float s1 = light_dir.y; |
| 72 | const float c1 = light_dir.x; |
| 73 | const float s2 = light_dir.x*s1 + light_dir.y*c1; |
| 74 | const float c2 = light_dir.x*c1 - light_dir.y*s1; |
| 75 | |
| 76 | to.coefficients[0] += light_color * 0.282094791773878140f; |
| 77 | to.coefficients[2] += light_color * 0.488602511902919920f*light_dir.z; |
| 78 | to.coefficients[6] += light_color * (0.946174695757560080f*z2 + -0.315391565252520050f); |
| 79 | to.coefficients[1] += light_color * -0.488602511902919920f*s1; |
| 80 | to.coefficients[3] += light_color * -0.488602511902919920f*c1; |
| 81 | const float p_2_1 = -1.092548430592079200f*light_dir.z; |
| 82 | to.coefficients[5] += light_color * p_2_1*s1; |
| 83 | to.coefficients[7] += light_color * p_2_1*c1; |
| 84 | to.coefficients[4] += light_color * 0.546274215296039590f*s2; |
| 85 | to.coefficients[8] += light_color * 0.546274215296039590f*c2; |
| 86 | } |
| 87 | |
| 88 | /////////////////////////////////////////// |
| 89 |
no outgoing calls
no test coverage detected