[
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2018 SebH\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# HLSL-Spherical-Harmonics\n\n## Description\n\nA collection of HLSL functions one can include to use spherical harmonics in shaders.\nThis is practical when generating and consuming SH on the GPU. \n\nUsing Git, this repository can be integrated in your project as a _submodule_.\n\nFiles description:\n* SphericalHarmonics.hlsl: the HLSL file containing all the SH functions.\n* sh2.nb : A Mathematica notebook to verify and visualize SH functions correctness.\n* sh2.pdf: A compiled pdf to simply read sh2.nb.\n\n## Examples\n\n<a href=\"https://twitter.com/SebHillaire/status/1054010642523480064\" target=\"blank\">Precomputed occlusion as SH</a> for cloud ambient lighting. Result as <a href=\"https://twitter.com/SebHillaire/status/1054358976043892736\" target=\"blank\">video</a> and as images (1st image: directional occlusion as SH, 2nd image: final cloud render):\n\n<img src=\"https://pbs.twimg.com/media/DqCYBNTX0AEFlF_.jpg\" alt=\"cloud\" width=\"346px\"/>\n<img src=\"https://pbs.twimg.com/media/DqCYHtYXcAELUkR.jpg\" alt=\"cloud\" width=\"400px\"/>   \n\n## Future\n\n* As of today, only 2nd order SH functions are provided. 3rd order SH could be added.\n* Do not hesitate to send suggestions or improvements."
  },
  {
    "path": "SphericalHarmonics.hlsl",
    "content": "\n// SphericalHarmonics.hlsl from https://github.com/sebh/HLSL-Spherical-Harmonics\n\n// Great documents about spherical harmonics: \n// [1]  http://www.cse.chalmers.se/~uffe/xjobb/Readings/GlobalIllumination/Spherical%20Harmonic%20Lighting%20-%20the%20gritty%20details.pdf\n// [2]  https://www.ppsloan.org/publications/StupidSH36.pdf\n// [3]  https://cseweb.ucsd.edu/~ravir/papers/envmap/envmap.pdf\n// [4]  https://d3cw3dd2w32x2b.cloudfront.net/wp-content/uploads/2011/06/10-14.pdf\n// [5]  https://github.com/kayru/Probulator\n// [6]  https://www.ppsloan.org/publications/SHJCGT.pdf\n// [7]  http://www.patapom.com/blog/SHPortal/\n// [8]  https://grahamhazel.com/blog/2017/12/22/converting-sh-radiance-to-irradiance/\n// [9]  http://www.ppsloan.org/publications/shdering.pdf\n// [10] http://limbicsoft.com/volker/prosem_paper.pdf\n// [11] https://bartwronski.files.wordpress.com/2014/08/bwronski_volumetric_fog_siggraph2014.pdf\n//\n\n//\n// Provided functions are commented. A \"SH function\" means a \"spherical function represented as spherical harmonics\".\n// You can also find a FAQ below.\n//\n//**** HOW TO PROJECT RADIANCE FROM A SPHERE INTO SH?\n// \n//\t\t// Initialise sh to 0\n//\t\tsh2 shR = shZero();\n//\t\tsh2 shG = shZero();\n//\t\tsh2 shB = shZero();\n//\t\t\n//\t\t// Accumulate coefficients according to surounding direction/color tuples.\n//\t\tfor (float az = 0.5f; az < axisSampleCount; az += 1.0f)\n//\t\t\tfor (float ze = 0.5f; ze < axisSampleCount; ze += 1.0f)\n//\t\t\t{\n//\t\t\t\tfloat3 rayDir = shGetUniformSphereSample(az / axisSampleCount, ze / axisSampleCount);\n//\t\t\t\tfloat3 color = [...];\n//\t\t\n//\t\t\t\tsh2 sh = shEvaluate(rayDir);\n//\t\t\t\tshR = shAdd(shR, shScale(sh, color.r));\n//\t\t\t\tshG = shAdd(shG, shScale(sh, color.g));\n//\t\t\t\tshB = shAdd(shB, shScale(sh, color.b));\n//\t\t\t}\n//\t\t\n//\t\t// integrating over a sphere so each sample has a weight of 4*PI/samplecount (uniform solid angle, for each sample)\n//\t\tfloat shFactor = 4.0 * shPI / (axisSampleCount * axisSampleCount);\n//\t\tshR = shScale(shR, shFactor );\n//\t\tshG = shScale(shG, shFactor );\n//\t\tshB = shScale(shB, shFactor );\n//\n//\n//**** HOW TO VIZUALISE A SPHERICAL FUNCTION REPRESENTED AS SH?\n//\n//\t\tsh2 shR = fromSomewhere.Load(...);\n//\t\tsh2 shG = fromSomewhere.Load(...);\n//\t\tsh2 shB = fromSomewhere.Load(...);\n//\t\tfloat3 rayDir = compute(...);\t\t\t\t\t\t\t\t\t\t// the direction for which you want to know the color\n//\t\tfloat3 rgbColor = max(0.0f, shUnproject(shR, shG, shB, rayDir));\t// A \"max\" is usually recomended to avoid negative values (can happen with SH)\n//\n\n\n\n#ifndef SPHERICAL_HARMONICS_HLSL\n#define SPHERICAL_HARMONICS_HLSL\n\n\n\n#define shPI 3.1415926536f\n\n\n\n// Generates a uniform distribution of directions over a unit sphere. \n// Adapted from http://www.pbr-book.org/3ed-2018/Monte_Carlo_Integration/2D_Sampling_with_Multidimensional_Transformations.html#fragment-SamplingFunctionDefinitions-6\n// azimuthX and zenithY are both in [0, 1]. You can use random value, stratified, etc.\n// Top and bottom sphere pole (+-zenith) are along the Y axis.\nfloat3 shGetUniformSphereSample(float azimuthX, float zenithY)\n{\n\tfloat phi = 2.0f * shPI * azimuthX;\n\tfloat z = 1.0f - 2.0f * zenithY;\n\tfloat r = sqrt(max(0.0f, 1.0f - z * z));\n\treturn float3(r * cos(phi), z, r * sin(phi));\n}\n\n\n\n#define sh2 float4\n// TODO sh3\n\nsh2 shZero()\n{\n\treturn float4(0.0f, 0.0f, 0.0f, 0.0f);\n}\n\n// Evaluates spherical harmonics basis for a direction dir.\n// This follows [2] Appendix A2 order when storing in x, y, z and w.\n// (evaluating the associated Legendre polynomials using the polynomial forms)\nsh2 shEvaluate(float3 dir)\n{\n\tsh2 result;\n\tresult.x = 0.28209479177387814347403972578039f;\t\t\t// L=0 , M= 0\n\tresult.y =-0.48860251190291992158638462283836f * dir.y;\t// L=1 , M=-1\n\tresult.z = 0.48860251190291992158638462283836f * dir.z;\t// L=1 , M= 0\n\tresult.w =-0.48860251190291992158638462283836f * dir.x;\t// L=1 , M= 1\n\treturn result;\n}\n\n// Recovers the value of a SH function in the direction dir.\nfloat shUnproject(sh2 functionSh, float3 dir)\n{\n\tsh2 sh = shEvaluate(dir);\n\treturn dot(functionSh, sh);\n}\nfloat3 shUnproject(sh2 functionShX, sh2 functionShY, sh2 functionShZ, float3 dir)\n{\n\tsh2 sh = shEvaluate(dir);\n\treturn float3(dot(functionShX, sh), dot(functionShY, sh), dot(functionShZ, sh));\n}\n\n// Projects a cosine lobe function, with peak value in direction dir, into SH. (from [4])\n// The integral over the unit sphere of the SH representation is PI.\nsh2 shEvaluateCosineLobe(float3 dir)\n{\n\tsh2 result;\n\tresult.x = 0.8862269254527580137f;\t\t\t// L=0 , M= 0\n\tresult.y =-1.0233267079464884885f * dir.y;\t// L=1 , M=-1\n\tresult.z = 1.0233267079464884885f * dir.z;\t// L=1 , M= 0\n\tresult.w =-1.0233267079464884885f * dir.x;\t// L=1 , M= 1\n\treturn result;\n}\n\n// Projects a Henyey-Greenstein phase function, with peak value in direction dir, into SH. (from [11])\n// The integral over the unit sphere of the SH representation is 1.\nsh2 shEvaluatePhaseHG(float3 dir, float g)\n{\n\tsh2 result;\n\tconst float factor = 0.48860251190291992158638462283836 * g;\n\tresult.x = 0.28209479177387814347403972578039;\t// L=0 , M= 0\n\tresult.y =-factor * dir.y;\t\t\t\t\t\t// L=1 , M=-1\n\tresult.z = factor * dir.z;\t\t\t\t\t\t// L=1 , M= 0\n\tresult.w =-factor * dir.x;\t\t\t\t\t\t// L=1 , M= 1\n\treturn result;\n}\n\n// Adds two SH functions together.\nsh2 shAdd(sh2 shL, sh2 shR)\n{\n\treturn shL + shR;\n}\n\n// Scales a SH function uniformly by v.\nsh2 shScale(sh2 sh, float v)\n{\n\treturn sh * v;\n}\n\n// Operates a rotation of a SH function.\nsh2 shRotate(sh2 sh, float3x3 rotation)\n{\n\t// TODO verify and optimize\n\tsh2 result;\n\tresult.x = sh.x;\n\tfloat3 tmp = float3(sh.w, sh.y, sh.z);\t\t// undo direction component shuffle to match source/function space\n\tresult.yzw = mul(tmp, rotation).yzx;\t\t// apply rotation and re-shuffle\n\treturn result;\n}\n\n// Integrates the product of two SH functions over the unit sphere.\nfloat shFuncProductIntegral(sh2 shL, sh2 shR)\n{\n\treturn dot(shL, shR);\n}\n\n// Computes the SH coefficients of a SH function representing the result of the multiplication of two SH functions. (from [4])\n// If sources have N bands, this product will result in 2N*1 bands as signal multiplication can add frequencies (think about two lobes intersecting).\n// To avoid that, the result can be truncated to N bands. It will just have a lower frequency, i.e. less details. (from [2], SH Products p.7)\n// Note: - the code from [4] has been adapted to match the mapping from [2] we use. \n//\t\t - !!! Be aware that this code has note yet be tested !!!\nsh2 shProduct(sh2 shL, sh2 shR)\n{\n\tconst float factor = 1.0f / (2.0f * sqrt(shPI));\n\treturn factor * sh2(\n\t\tdot(shL, shR),\n\t\tshL.y*shR.w + shL.w*shR.y,\n\t\tshL.z*shR.w + shL.w*shR.z,\n\t\tshL.w*shR.w + shL.w*shR.w\n\t);\n}\n\n// Convolves a SH function using a Hanning filtering. This helps reducing ringing and negative values. (from [2], Windowing p.16)\n// A lower value of w will reduce ringing (like the frequency of a filter)\nsh2 shHanningConvolution( sh2 sh, float w ) \n{\n\tsh2 result = sh;\n\tfloat invW = 1.0 / w;\n\tfloat factorBand1 =(1.0 + cos( shPI * invW )) / 2.0f;\n\tresult.y *= factorBand1;\n\tresult.z *= factorBand1;\n\tresult.w *= factorBand1;\n\treturn result;\n}\n\n// Convolves a SH function using a cosine lob. This is tipically used to transform radiance to irradiance. (from [3], eq.7 & eq.8)\nsh2 shDiffuseConvolution(sh2 sh)\n{\n\tsh2 result = sh;\n\t// L0\n\tresult.x   *= shPI;\n\t// L1\n\tresult.yzw *= 2.0943951023931954923f;\n\treturn result;\n}\n\n\n\n#endif // SPHERICAL_HARMONICS_HLSL\n\n\n"
  },
  {
    "path": "sh2.nb",
    "content": "(* Content-type: application/vnd.wolfram.mathematica *)\n\n(*** Wolfram Notebook File ***)\n(* http://www.wolfram.com/nb *)\n\n(* CreatedBy='Mathematica 9.0' *)\n\n(*CacheID: 234*)\n(* Internal cache information:\nNotebookFileLineBreakTest\nNotebookFileLineBreakTest\nNotebookDataPosition[       157,          7]\nNotebookDataLength[     27072,        697]\nNotebookOptionsPosition[     26205,        667]\nNotebookOutlinePosition[     26839,        690]\nCellTagsIndexPosition[     26796,        687]\nWindowFrame->Normal*)\n\n(* Beginning of Notebook Content *)\nNotebook[{\nCell[BoxData[\n RowBox[{\"(*\", \"\\[IndentingNewLine]\", \"   \", \n  RowBox[{\n   RowBox[{\"This\", \" \", \"files\", \" \", \"presents\", \" \", \"2\", \" \", \"bands\", \" \", \n    RowBox[{\"(\", \n     RowBox[{\n      RowBox[{\"a\", \".\", \"k\", \".\", \"a\", \".\", \" \", \"order\"}], \" \", \"2\"}], \")\"}],\n     \" \", \"spherical\", \" \", \"harmonics\", \" \", \n    RowBox[{\"results\", \".\", \"\\[IndentingNewLine]\", \"It\"}], \" \", \"comes\", \" \", \n    \"from\", \" \", \n    RowBox[{\"https\", \":\"}]}], \"//\", \n   RowBox[{\n    RowBox[{\n     RowBox[{\n      RowBox[{\"github\", \".\", \"com\"}], \"/\", \"sebh\"}], \"/\", \"HLSL\"}], \"-\", \n    \"Spherical\", \"-\", \"Harmonics\"}]}], \"\\[IndentingNewLine]\", \"*)\"}]], \"Input\"],\n\nCell[BoxData[\n RowBox[{\"(*\", \n  RowBox[{\"Restart\", \" \", \"the\", \" \", \"kernel\", \" \", \n   RowBox[{\"(\", \n    RowBox[{\n    \"helps\", \" \", \"removes\", \" \", \"all\", \" \", \"definitions\", \" \", \"for\", \" \", \n     \"instance\"}], \")\"}], \"\\[IndentingNewLine]\", \"Quit\"}], \"*)\"}]], \"Input\"],\n\nCell[BoxData[\n RowBox[{\n  RowBox[{\"(*\", \"\\[IndentingNewLine]\", \"    \", \n   RowBox[{\n    RowBox[{\"aToD\", \":\", \" \", \n     RowBox[{\n     \"transformation\", \" \", \"from\", \" \", \"azimuth\", \" \", \"and\", \" \", \"zenith\",\n       \" \", \"angle\", \" \", \"to\", \" \", \n      RowBox[{\n       RowBox[{\"(\", \n        RowBox[{\"x\", \",\", \"y\", \",\", \"z\"}], \")\"}], \".\", \" \", \n       \"\\[IndentingNewLine]\", \" \", \"evalSh2\"}]}], \":\", \" \", \n     RowBox[{\n     \"evaluate\", \" \", \"SH2\", \" \", \"for\", \" \", \"a\", \" \", \"direction\", \n      \"\\[IndentingNewLine]\", \"  \", \n      RowBox[{\"unprojSh2\", \":\", \" \", \n       RowBox[{\n       \"unproject\", \" \", \"a\", \" \", \"SH2\", \" \", \"encoded\", \" \", \n        \"function\"}]}]}]}], \",\", \" \", \n    RowBox[{\"giving\", \" \", \"its\", \" \", \"value\", \" \", \"along\", \" \", \n     RowBox[{\"(\", \n      RowBox[{\"\\[Theta]\", \",\", \"\\[Phi]\"}], \")\"}]}]}], \"\\[IndentingNewLine]\", \n   \"*)\"}], \"\\[IndentingNewLine]\", \"\\[IndentingNewLine]\", \n  RowBox[{\n   RowBox[{\n    RowBox[{\"aToD\", \"[\", \n     RowBox[{\"\\[Theta]_\", \",\", \"\\[Phi]_\"}], \"]\"}], \" \", \":=\", \n    \"\\[IndentingNewLine]\", \n    RowBox[{\"{\", \"\\[IndentingNewLine]\", \" \", \n     RowBox[{\n      RowBox[{\n       RowBox[{\"Cos\", \"[\", \"\\[Phi]\", \"]\"}], \n       RowBox[{\"Sin\", \"[\", \"\\[Theta]\", \"]\"}]}], \",\", \n      RowBox[{\n       RowBox[{\"Sin\", \"[\", \"\\[Phi]\", \"]\"}], \n       RowBox[{\"Sin\", \"[\", \"\\[Theta]\", \"]\"}]}], \",\", \n      RowBox[{\"Cos\", \"[\", \"\\[Theta]\", \"]\"}]}], \"\\[IndentingNewLine]\", \"}\"}]}],\n    \"\\[IndentingNewLine]\", \"\\[IndentingNewLine]\", \n   RowBox[{\n    RowBox[{\"evalSh2\", \"[\", \n     RowBox[{\"\\[Theta]_\", \",\", \"\\[Phi]_\"}], \"]\"}], \":=\", \n    RowBox[{\"{\", \"\\[IndentingNewLine]\", \n     RowBox[{\n      RowBox[{\n       RowBox[{\"d\", \" \", \"=\", \" \", \n        RowBox[{\"aToD\", \"[\", \n         RowBox[{\"\\[Theta]\", \",\", \"\\[Phi]\"}], \"]\"}]}], \" \", \";\", \n       \"\\[IndentingNewLine]\", \"0.28209479177387814347403972578039\"}], \",\", \n      \"\\[IndentingNewLine]\", \n      RowBox[{\n       RowBox[{\"-\", \"0.48860251190291992158638462283836\"}], \"*\", \n       RowBox[{\"d\", \"[\", \n        RowBox[{\"[\", \"2\", \"]\"}], \"]\"}]}], \",\", \"\\[IndentingNewLine]\", \n      RowBox[{\"0.48860251190291992158638462283836\", \"*\", \n       RowBox[{\"d\", \"[\", \n        RowBox[{\"[\", \"3\", \"]\"}], \"]\"}]}], \",\", \"\\[IndentingNewLine]\", \n      RowBox[{\n       RowBox[{\"-\", \"0.48860251190291992158638462283836\"}], \"*\", \n       RowBox[{\"d\", \"[\", \n        RowBox[{\"[\", \"1\", \"]\"}], \"]\"}]}]}], \"\\[IndentingNewLine]\", \"}\"}]}], \n   \"\\[IndentingNewLine]\", \"\\[IndentingNewLine]\", \n   RowBox[{\n    RowBox[{\"unprojSh2\", \"[\", \n     RowBox[{\"shIn_\", \",\", \"\\[Theta]_\", \",\", \"\\[Phi]_\"}], \"]\"}], \":=\", \n    RowBox[{\n     RowBox[{\"{\", \"\\[IndentingNewLine]\", \n      RowBox[{\n       RowBox[{\"sh\", \" \", \"=\", \" \", \n        RowBox[{\"evalSh2\", \"[\", \n         RowBox[{\"\\[Theta]\", \",\", \"\\[Phi]\"}], \"]\"}]}], \";\", \n       \"\\[IndentingNewLine]\", \n       RowBox[{\n        RowBox[{\n         RowBox[{\"sh\", \"[\", \n          RowBox[{\"[\", \"1\", \"]\"}], \"]\"}], \"*\", \n         RowBox[{\"shIn\", \"[\", \n          RowBox[{\"[\", \"1\", \"]\"}], \"]\"}]}], \" \", \"+\", \" \", \n        RowBox[{\n         RowBox[{\"sh\", \"[\", \n          RowBox[{\"[\", \"2\", \"]\"}], \"]\"}], \"*\", \n         RowBox[{\"shIn\", \"[\", \n          RowBox[{\"[\", \"2\", \"]\"}], \"]\"}]}], \" \", \"+\", \" \", \n        RowBox[{\n         RowBox[{\"sh\", \"[\", \n          RowBox[{\"[\", \"3\", \"]\"}], \"]\"}], \"*\", \n         RowBox[{\"shIn\", \"[\", \n          RowBox[{\"[\", \"3\", \"]\"}], \"]\"}]}], \" \", \"+\", \" \", \n        RowBox[{\n         RowBox[{\"sh\", \"[\", \n          RowBox[{\"[\", \"4\", \"]\"}], \"]\"}], \"*\", \n         RowBox[{\"shIn\", \"[\", \n          RowBox[{\"[\", \"4\", \"]\"}], \"]\"}]}]}]}], \" \", \"\\[IndentingNewLine]\", \n      \"}\"}], \"[\", \n     RowBox[{\"[\", \"1\", \"]\"}], \"]\"}]}], \"\\[IndentingNewLine]\", \n   \"\\[IndentingNewLine]\", \"\\[IndentingNewLine]\", \n   RowBox[{\"Print\", \"[\", \"\\\"\\<A few debug prints:\\>\\\"\", \"]\"}], \n   \"\\[IndentingNewLine]\", \n   RowBox[{\"aToD\", \"[\", \n    RowBox[{\"0\", \",\", \"0\"}], \"]\"}], \"\\[IndentingNewLine]\", \n   RowBox[{\"test\", \" \", \"=\", \" \", \n    RowBox[{\"evalSh2\", \"[\", \n     RowBox[{\"0\", \",\", \"0\"}], \"]\"}]}], \"\\[IndentingNewLine]\", \n   RowBox[{\"unprojSh2\", \"[\", \n    RowBox[{\"test\", \",\", \"1\", \",\", \"2\"}], \"]\"}], \n   \"\\[IndentingNewLine]\"}]}]], \"Input\"],\n\nCell[BoxData[\n RowBox[{\n  RowBox[{\"(*\", \" \", \"\\[IndentingNewLine]\", \"    \", \n   RowBox[{\n    RowBox[{\n     RowBox[{\"From\", \" \", \n      RowBox[{\"https\", \":\"}]}], \"//\", \n     RowBox[{\n      RowBox[{\n       RowBox[{\"d3cw3dd2w32x2b\", \".\", \"cloudfront\", \".\", \"net\"}], \"/\", \"wp\"}],\n       \"-\", \n      RowBox[{\n       RowBox[{\n        RowBox[{\n         RowBox[{\"content\", \"/\", \"uploads\"}], \"/\", \"2011\"}], \"/\", \"06\"}], \"/\",\n        \"10\"}], \"-\", \n      RowBox[{\"14.\", \n       RowBox[{\"pdf\", \".\", \"\\[IndentingNewLine]\", \"A\"}], \" \", \"cosine\", \" \", \n       \"lob\", \" \", \"with\", \" \", \"peak\", \" \", \"in\", \" \", \"a\", \" \", \"specified\",\n        \" \", \n       RowBox[{\"(\", \n        RowBox[{\"\\[Theta]\", \",\", \"\\[Phi]\"}], \")\"}], \" \", \n       RowBox[{\"direction\", \".\", \"\\[IndentingNewLine]\", \"The\"}], \" \", \n       \"integration\", \" \", \"over\", \" \", \"the\", \" \", \"unit\", \" \", \"sphere\", \n       \" \", \"is\", \" \", \"\\[Pi]\"}]}]}], \",\", \" \", \n    RowBox[{\"and\", \" \", \"this\", \" \", \"is\", \" \", \n     RowBox[{\"correct\", \".\", \"\\[IndentingNewLine]\", \"  \", \n      RowBox[{\"(\", \n       RowBox[{\n       \"even\", \" \", \"though\", \" \", \"it\", \" \", \"does\", \" \", \"have\", \" \", \"a\", \n        \" \", \"negative\", \" \", \"values\", \" \", \"in\", \" \", \"the\", \" \", \n        \"opposite\", \" \", \"directin\", \" \", \"from\", \" \", \"the\", \" \", \"lobe\"}], \n       \")\"}], \".\"}]}]}], \"\\[IndentingNewLine]\", \"*)\"}], \"\\[IndentingNewLine]\",\n   \"\\[IndentingNewLine]\", \n  RowBox[{\n   RowBox[{\n    RowBox[{\"cosLobeDir\", \" \", \"=\", \" \", \n     RowBox[{\"{\", \n      RowBox[{\"1\", \",\", \"0\", \",\", \"0\"}], \"}\"}]}], \";\"}], \n   \"\\[IndentingNewLine]\", \n   RowBox[{\n    RowBox[{\"shCosLobe\", \" \", \"=\", \" \", \n     RowBox[{\"{\", \n      RowBox[{\n       RowBox[{\n        RowBox[{\"Sqrt\", \"[\", \"\\[Pi]\", \"]\"}], \"/\", \"2\"}], \",\", \n       \"\\[IndentingNewLine]\", \n       RowBox[{\n        RowBox[{\"-\", \n         RowBox[{\"Sqrt\", \"[\", \n          RowBox[{\"\\[Pi]\", \"/\", \"3\"}], \"]\"}]}], \"*\", \n        RowBox[{\"cosLobeDir\", \"[\", \n         RowBox[{\"[\", \"2\", \"]\"}], \"]\"}]}], \",\", \"\\[IndentingNewLine]\", \n       RowBox[{\n        RowBox[{\"Sqrt\", \"[\", \n         RowBox[{\"\\[Pi]\", \"/\", \"3\"}], \"]\"}], \"*\", \n        RowBox[{\"cosLobeDir\", \"[\", \n         RowBox[{\"[\", \"3\", \"]\"}], \"]\"}]}], \",\", \"\\[IndentingNewLine]\", \n       RowBox[{\n        RowBox[{\"-\", \n         RowBox[{\"Sqrt\", \"[\", \n          RowBox[{\"\\[Pi]\", \"/\", \"3\"}], \"]\"}]}], \"*\", \n        RowBox[{\"cosLobeDir\", \"[\", \n         RowBox[{\"[\", \"1\", \"]\"}], \"]\"}]}]}], \"}\"}]}], \";\"}], \n   \"\\[IndentingNewLine]\", \"\\[IndentingNewLine]\", \n   RowBox[{\"SphericalPlot3D\", \"[\", \"\\[IndentingNewLine]\", \n    RowBox[{\n     RowBox[{\"unprojSh2\", \"[\", \n      RowBox[{\"shCosLobe\", \",\", \"\\[Theta]\", \",\", \"\\[Phi]\"}], \"]\"}], \",\", \n     \"\\[IndentingNewLine]\", \n     RowBox[{\"{\", \n      RowBox[{\"\\[Theta]\", \",\", \"0\", \",\", \"\\[Pi]\"}], \"}\"}], \",\", \n     RowBox[{\"{\", \n      RowBox[{\"\\[Phi]\", \",\", \"0\", \",\", \n       RowBox[{\"2\", \" \", \"\\[Pi]\"}]}], \"}\"}], \",\", \n     RowBox[{\"PlotRange\", \"\\[Rule]\", \n      RowBox[{\"{\", \n       RowBox[{\n        RowBox[{\"-\", \"1\"}], \",\", \"1\"}], \"}\"}]}], \",\", \"\\[IndentingNewLine]\", \n     RowBox[{\"ColorFunction\", \"\\[Rule]\", \n      RowBox[{\"(\", \n       RowBox[{\n        RowBox[{\n         RowBox[{\"ColorData\", \"[\", \"\\\"\\<Rainbow\\>\\\"\", \"]\"}], \"[\", \"#6\", \"]\"}],\n         \"&\"}], \")\"}]}], \",\", \"\\[IndentingNewLine]\", \n     RowBox[{\"PlotStyle\", \"\\[Rule]\", \n      RowBox[{\"Directive\", \"[\", \n       RowBox[{\"Opacity\", \"[\", \"0.5\", \"]\"}], \"]\"}]}], \",\", \n     \"\\[IndentingNewLine]\", \n     RowBox[{\"Axes\", \"\\[Rule]\", \"True\"}], \" \", \",\", \" \", \n     RowBox[{\"AxesStyle\", \"\\[Rule]\", \n      RowBox[{\"{\", \n       RowBox[{\"Red\", \",\", \"Green\", \",\", \"Blue\"}], \"}\"}]}]}], \n    \"\\[IndentingNewLine]\", \"]\"}], \"\\[IndentingNewLine]\", \n   \"\\[IndentingNewLine]\", \"\\[IndentingNewLine]\", \n   RowBox[{\"Print\", \"[\", \"\\\"\\<Integral over the unit sphere:\\>\\\"\", \"]\"}], \n   \"\\[IndentingNewLine]\", \n   RowBox[{\"Integrate\", \"[\", \"\\[IndentingNewLine]\", \n    RowBox[{\n     RowBox[{\"1\", \"*\", \n      RowBox[{\"Abs\", \"[\", \n       RowBox[{\"Sin\", \"[\", \"\\[Theta]\", \"]\"}], \"]\"}]}], \"\\[IndentingNewLine]\", \n     \",\", \n     RowBox[{\"{\", \n      RowBox[{\"\\[Theta]\", \",\", \"0\", \",\", \"\\[Pi]\"}], \"}\"}], \",\", \n     RowBox[{\"{\", \n      RowBox[{\"\\[Phi]\", \",\", \"0\", \",\", \n       RowBox[{\"2\", \"\\[Pi]\"}]}], \"}\"}]}], \"]\"}], \"\\[IndentingNewLine]\", \n   RowBox[{\n   \"Print\", \"[\", \n    \"\\\"\\<Integral over the unit sphere of cosine lobe (as SH):\\>\\\"\", \"]\"}], \n   \"\\[IndentingNewLine]\", \n   RowBox[{\"Integrate\", \"[\", \"\\[IndentingNewLine]\", \n    RowBox[{\n     RowBox[{\n      RowBox[{\"unprojSh2\", \"[\", \n       RowBox[{\"shCosLobe\", \",\", \"\\[Theta]\", \",\", \"\\[Phi]\"}], \"]\"}], \"*\", \n      RowBox[{\"Sin\", \"[\", \"\\[Theta]\", \"]\"}]}], \"\\[IndentingNewLine]\", \",\", \n     RowBox[{\"{\", \n      RowBox[{\"\\[Theta]\", \",\", \"0\", \",\", \"\\[Pi]\"}], \"}\"}], \",\", \n     RowBox[{\"{\", \n      RowBox[{\"\\[Phi]\", \",\", \"0\", \",\", \n       RowBox[{\"2\", \"\\[Pi]\"}]}], \"}\"}]}], \"]\"}]}]}]], \"Input\"],\n\nCell[\"\", \"PageBreak\",\n PageBreakBelow->True],\n\nCell[\"\", \"PageBreak\",\n PageBreakBelow->True],\n\nCell[BoxData[\n RowBox[{\n  RowBox[{\"(*\", \" \", \"\\[IndentingNewLine]\", \"    \", \n   RowBox[{\n    RowBox[{\"Definition\", \" \", \"of\", \" \", \"a\", \" \", \"few\", \" \", \"phase\", \" \", \n     RowBox[{\"functions\", \":\", \" \", \n      RowBox[{\n       RowBox[{\"(\", \"1\", \")\"}], \" \", \"schlick\", \" \", \"approximation\"}]}]}], \n    \",\", \" \", \n    RowBox[{\n     RowBox[{\n      RowBox[{\"(\", \"2\", \")\"}], \" \", \"Henyey\"}], \"-\", \n     RowBox[{\"Greenstein\", \" \", \"and\"}]}], \",\", \" \", \n    RowBox[{\n     RowBox[{\n      RowBox[{\"(\", \"3\", \")\"}], \" \", \"Cornette\"}], \"-\", \n     RowBox[{\n     \"Shanks\", \"\\[IndentingNewLine]\", \"  \", \"Integrale\", \" \", \"of\", \" \", \n      \"phase\", \" \", \"function\", \" \", \"over\", \" \", \"the\", \" \", \"unit\", \" \", \n      \"sphere\", \" \", \"should\", \" \", \"be\", \" \", \"1\", \" \", \n      RowBox[{\n       RowBox[{\"(\", \n        RowBox[{\"it\", \" \", \"is\", \" \", \"a\", \" \", \"unitless\", \" \", \"function\"}],\n         \")\"}], \".\"}]}]}]}], \"\\[IndentingNewLine]\", \"*)\"}], \n  \"\\[IndentingNewLine]\", \"\\[IndentingNewLine]\", \n  RowBox[{\n   RowBox[{\n    RowBox[{\"phaseFuncSchlick\", \"[\", \n     RowBox[{\"G_\", \",\", \" \", \"A_\"}], \"]\"}], \" \", \":=\", \"\\[IndentingNewLine]\", \n    RowBox[{\n     RowBox[{\"{\", \"\\[IndentingNewLine]\", \n      RowBox[{\n       RowBox[{\"k\", \" \", \"=\", \" \", \n        RowBox[{\n         RowBox[{\"1.55\", \"*\", \"G\"}], \" \", \"-\", \" \", \n         RowBox[{\"0.55\", \"*\", \"G\", \"*\", \"G\", \"*\", \"G\"}]}]}], \";\", \n       \"\\[IndentingNewLine]\", \n       RowBox[{\"tmp\", \" \", \"=\", \" \", \n        RowBox[{\"1.0\", \" \", \"+\", \" \", \n         RowBox[{\"k\", \"*\", \n          RowBox[{\"Cos\", \"[\", \"A\", \"]\"}]}]}]}], \";\", \"\\[IndentingNewLine]\", \n       RowBox[{\n        RowBox[{\"(\", \n         RowBox[{\"1\", \"-\", \n          RowBox[{\"k\", \"*\", \"k\"}]}], \")\"}], \"/\", \n        RowBox[{\"(\", \n         RowBox[{\"(\", \n          RowBox[{\"4.0\", \"*\", \"\\[Pi]\", \"*\", \"tmp\", \"*\", \"tmp\"}], \")\"}], \n         \")\"}]}]}], \"\\[IndentingNewLine]\", \"}\"}], \"[\", \n     RowBox[{\"[\", \"1\", \"]\"}], \"]\"}]}], \"\\[IndentingNewLine]\", \n   RowBox[{\n    RowBox[{\"phaseHG\", \"[\", \n     RowBox[{\"G_\", \",\", \" \", \"A_\"}], \"]\"}], \" \", \":=\", \"\\[IndentingNewLine]\", \n    RowBox[{\n     RowBox[{\"{\", \"\\[IndentingNewLine]\", \n      RowBox[{\n       RowBox[{\"(\", \n        RowBox[{\"1\", \"-\", \n         RowBox[{\"G\", \"*\", \"G\"}]}], \")\"}], \"/\", \n       RowBox[{\"(\", \n        RowBox[{\"4.0\", \"*\", \"Pi\", \"*\", \n         RowBox[{\n          RowBox[{\"(\", \n           RowBox[{\"1\", \"+\", \n            RowBox[{\"G\", \"*\", \"G\"}], \"-\", \n            RowBox[{\"2\", \"*\", \"G\", \"*\", \n             RowBox[{\"Cos\", \"[\", \"A\", \"]\"}]}]}], \")\"}], \"^\", \"1.5\"}]}], \n        \")\"}]}], \"\\[IndentingNewLine]\", \"}\"}], \"[\", \n     RowBox[{\"[\", \"1\", \"]\"}], \"]\"}]}], \"\\[IndentingNewLine]\", \n   RowBox[{\"(*\", \n    RowBox[{\n     RowBox[{\"Cornette\", \"-\", \n      RowBox[{\"Shanks\", \" \", \"phase\", \" \", \"function\", \" \", \n       RowBox[{\"http\", \":\"}]}]}], \"//\", \n     RowBox[{\n      RowBox[{\n       RowBox[{\n        RowBox[{\"www\", \".\", \"csroc\", \".\", \"org\", \".\", \"tw\"}], \"/\", \n        \"journal\"}], \"/\", \"JOC25\"}], \"-\", \n      RowBox[{\"3\", \"/\", \"JOC25\"}], \"-\", \"3\", \"-\", \n      RowBox[{\"2.\", \"pdf\"}]}]}], \"*)\"}], \"\\[IndentingNewLine]\", \n   RowBox[{\n    RowBox[{\"phaseCS\", \"[\", \n     RowBox[{\"G_\", \",\", \" \", \"A_\"}], \"]\"}], \" \", \":=\", \"\\[IndentingNewLine]\", \n    RowBox[{\n     RowBox[{\"{\", \"\\[IndentingNewLine]\", \n      RowBox[{\n       RowBox[{\"(\", \n        RowBox[{\"3\", \"*\", \n         RowBox[{\"(\", \n          RowBox[{\"1\", \"-\", \n           RowBox[{\"G\", \"*\", \"G\"}]}], \")\"}], \"*\", \n         RowBox[{\"(\", \n          RowBox[{\"1\", \"+\", \n           RowBox[{\n            RowBox[{\"Cos\", \"[\", \"A\", \"]\"}], \"*\", \n            RowBox[{\"Cos\", \"[\", \"A\", \"]\"}]}]}], \")\"}]}], \")\"}], \"/\", \n       RowBox[{\"(\", \n        RowBox[{\"4.0\", \"*\", \"\\[Pi]\", \"*\", \"2\", \"*\", \n         RowBox[{\"(\", \n          RowBox[{\"2\", \"+\", \n           RowBox[{\"G\", \"*\", \"G\"}]}], \")\"}], \"*\", \n         RowBox[{\"(\", \n          RowBox[{\n           RowBox[{\"(\", \n            RowBox[{\"1\", \"+\", \n             RowBox[{\"G\", \"*\", \"G\"}], \"-\", \n             RowBox[{\"2\", \"*\", \"G\", \"*\", \n              RowBox[{\"Cos\", \"[\", \"A\", \"]\"}]}]}], \")\"}], \"^\", \"1.5\"}], \n          \")\"}]}], \")\"}]}], \"\\[IndentingNewLine]\", \"}\"}], \"[\", \n     RowBox[{\"[\", \"1\", \"]\"}], \"]\"}]}], \"\\[IndentingNewLine]\", \n   \"\\[IndentingNewLine]\", \"\\[IndentingNewLine]\", \n   RowBox[{\n   \"Print\", \"[\", \n    \"\\\"\\<Integral over the unit sphere of multiple phase function:\\>\\\"\", \n    \"]\"}], \"\\[IndentingNewLine]\", \n   RowBox[{\"Integrate\", \"[\", \"\\[IndentingNewLine]\", \n    RowBox[{\n     RowBox[{\n      RowBox[{\"phaseHG\", \"[\", \n       RowBox[{\"0.0\", \",\", \" \", \"\\[Theta]\"}], \"]\"}], \" \", \"*\", \n      RowBox[{\"Sin\", \"[\", \"\\[Theta]\", \"]\"}]}], \"\\[IndentingNewLine]\", \",\", \n     RowBox[{\"{\", \n      RowBox[{\"\\[Theta]\", \",\", \"0\", \",\", \"\\[Pi]\"}], \"}\"}], \",\", \n     RowBox[{\"{\", \n      RowBox[{\"\\[Phi]\", \",\", \"0\", \",\", \n       RowBox[{\"2\", \" \", \"Pi\"}]}], \"}\"}]}], \"]\"}], \"\\[IndentingNewLine]\", \n   RowBox[{\"Integrate\", \"[\", \"\\[IndentingNewLine]\", \n    RowBox[{\n     RowBox[{\n      RowBox[{\"phaseHG\", \"[\", \n       RowBox[{\"0.9\", \",\", \" \", \"\\[Theta]\"}], \"]\"}], \" \", \"*\", \n      RowBox[{\"Sin\", \"[\", \"\\[Theta]\", \"]\"}]}], \"\\[IndentingNewLine]\", \",\", \n     RowBox[{\"{\", \n      RowBox[{\"\\[Theta]\", \",\", \"0\", \",\", \"\\[Pi]\"}], \"}\"}], \",\", \n     RowBox[{\"{\", \n      RowBox[{\"\\[Phi]\", \",\", \"0\", \",\", \n       RowBox[{\"2\", \" \", \"Pi\"}]}], \"}\"}]}], \"]\"}], \"\\[IndentingNewLine]\", \n   RowBox[{\"Integrate\", \"[\", \"\\[IndentingNewLine]\", \n    RowBox[{\n     RowBox[{\n      RowBox[{\"phaseFuncSchlick\", \"[\", \n       RowBox[{\"0.0\", \",\", \" \", \"\\[Theta]\"}], \"]\"}], \" \", \"*\", \n      RowBox[{\"Sin\", \"[\", \"\\[Theta]\", \"]\"}]}], \"\\[IndentingNewLine]\", \",\", \n     RowBox[{\"{\", \n      RowBox[{\"\\[Theta]\", \",\", \"0\", \",\", \"\\[Pi]\"}], \"}\"}], \",\", \n     RowBox[{\"{\", \n      RowBox[{\"\\[Phi]\", \",\", \"0\", \",\", \n       RowBox[{\"2\", \" \", \"Pi\"}]}], \"}\"}]}], \"]\"}], \"\\[IndentingNewLine]\", \n   RowBox[{\"Integrate\", \"[\", \"\\[IndentingNewLine]\", \n    RowBox[{\n     RowBox[{\n      RowBox[{\"phaseFuncSchlick\", \"[\", \n       RowBox[{\"0.9\", \",\", \" \", \"\\[Theta]\"}], \"]\"}], \" \", \"*\", \n      RowBox[{\"Sin\", \"[\", \"\\[Theta]\", \"]\"}]}], \"\\[IndentingNewLine]\", \",\", \n     RowBox[{\"{\", \n      RowBox[{\"\\[Theta]\", \",\", \"0\", \",\", \"\\[Pi]\"}], \"}\"}], \",\", \n     RowBox[{\"{\", \n      RowBox[{\"\\[Phi]\", \",\", \"0\", \",\", \n       RowBox[{\"2\", \" \", \"Pi\"}]}], \"}\"}]}], \"]\"}], \"\\[IndentingNewLine]\", \n   RowBox[{\"Integrate\", \"[\", \"\\[IndentingNewLine]\", \n    RowBox[{\n     RowBox[{\n      RowBox[{\"phaseCS\", \"[\", \n       RowBox[{\"0.0\", \",\", \" \", \"\\[Theta]\"}], \"]\"}], \" \", \"*\", \n      RowBox[{\"Sin\", \"[\", \"\\[Theta]\", \"]\"}]}], \"\\[IndentingNewLine]\", \",\", \n     RowBox[{\"{\", \n      RowBox[{\"\\[Theta]\", \",\", \"0\", \",\", \"\\[Pi]\"}], \"}\"}], \",\", \n     RowBox[{\"{\", \n      RowBox[{\"\\[Phi]\", \",\", \"0\", \",\", \n       RowBox[{\"2\", \" \", \"Pi\"}]}], \"}\"}]}], \"]\"}], \"\\[IndentingNewLine]\", \n   RowBox[{\"Integrate\", \"[\", \"\\[IndentingNewLine]\", \n    RowBox[{\n     RowBox[{\n      RowBox[{\"phaseCS\", \"[\", \n       RowBox[{\"0.9\", \",\", \" \", \"\\[Theta]\"}], \"]\"}], \" \", \"*\", \n      RowBox[{\"Sin\", \"[\", \"\\[Theta]\", \"]\"}]}], \"\\[IndentingNewLine]\", \",\", \n     RowBox[{\"{\", \n      RowBox[{\"\\[Theta]\", \",\", \"0\", \",\", \"\\[Pi]\"}], \"}\"}], \",\", \n     RowBox[{\"{\", \n      RowBox[{\"\\[Phi]\", \",\", \"0\", \",\", \n       RowBox[{\"2\", \" \", \"Pi\"}]}], \"}\"}]}], \"]\"}]}]}]], \"Input\"],\n\nCell[BoxData[\n RowBox[{\n  RowBox[{\"(*\", \" \", \"\\[IndentingNewLine]\", \"    \", \n   RowBox[{\n    RowBox[{\n     RowBox[{\n     \"Plot\", \" \", \"of\", \" \", \"the\", \" \", \"different\", \" \", \"phase\", \" \", \n      \"functions\", \" \", \"as\", \" \", \"well\", \" \", \"as\", \" \", \"the\", \" \", \"SH2\", \n      \" \", \"approximation\", \"    \", \"presented\", \" \", \"in\", \" \", \n      RowBox[{\"https\", \":\"}]}], \"//\", \n     RowBox[{\n      RowBox[{\n       RowBox[{\n        RowBox[{\n         RowBox[{\"bartwronski\", \".\", \"files\", \".\", \"wordpress\", \".\", \"com\"}], \n         \"/\", \"2014\"}], \"/\", \"08\"}], \"/\", \"bwronski_volumetric\"}], \"_fog\", \n      RowBox[{\n      \"_siggraph2014\", \".\", \"pdf\", \".\", \"\\[IndentingNewLine]\", \" \", \"The\"}], \n      \" \", \"integral\", \" \", \"of\", \" \", \"all\", \" \", \"the\", \" \", \"phase\", \" \", \n      \"functions\"}]}], \",\", \" \", \n    RowBox[{\n    \"as\", \" \", \"well\", \" \", \"as\", \" \", \"the\", \" \", \"SH\", \" \", \n     \"approximation\"}], \",\", \" \", \n    RowBox[{\"is\", \" \", \"1\", \" \", \"as\", \" \", \"expected\", \" \", \n     RowBox[{\n      RowBox[{\"(\", \n       RowBox[{\"unitless\", \" \", \"function\"}], \")\"}], \".\"}]}]}], \n   \"\\[IndentingNewLine]\", \"*)\"}], \"\\[IndentingNewLine]\", \n  \"\\[IndentingNewLine]\", \n  RowBox[{\n   RowBox[{\n    RowBox[{\"g\", \" \", \"=\", \" \", \"0.3\"}], \";\"}], \"\\[IndentingNewLine]\", \n   RowBox[{\n    RowBox[{\"phaseDir\", \" \", \"=\", \" \", \n     RowBox[{\"{\", \n      RowBox[{\"1\", \",\", \"0\", \",\", \"0\"}], \"}\"}]}], \";\"}], \n   \"\\[IndentingNewLine]\", \"\\[IndentingNewLine]\", \n   RowBox[{\n    RowBox[{\"shPhaseLobe\", \"[\", \n     RowBox[{\"g_\", \",\", \"d_\"}], \"]\"}], \":=\", \n    RowBox[{\"{\", \"\\[IndentingNewLine]\", \n     RowBox[{\"0.28209479177387814347403972578039\", \",\", \"\\[IndentingNewLine]\", \n      RowBox[{\n       RowBox[{\"-\", \"0.48860251190291992158638462283836\"}], \"*\", \"g\", \"*\", \n       RowBox[{\"d\", \"[\", \n        RowBox[{\"[\", \"2\", \"]\"}], \"]\"}]}], \",\", \"\\[IndentingNewLine]\", \n      RowBox[{\"0.48860251190291992158638462283836\", \"*\", \"g\", \"*\", \n       RowBox[{\"d\", \"[\", \n        RowBox[{\"[\", \"3\", \"]\"}], \"]\"}]}], \",\", \"\\[IndentingNewLine]\", \n      RowBox[{\n       RowBox[{\"-\", \"0.48860251190291992158638462283836\"}], \"*\", \"g\", \"*\", \n       RowBox[{\"d\", \"[\", \n        RowBox[{\"[\", \"1\", \"]\"}], \"]\"}]}]}], \"\\[IndentingNewLine]\", \"}\"}]}], \n   \"\\[IndentingNewLine]\", \n   RowBox[{\n    RowBox[{\"shPhase\", \" \", \"=\", \" \", \n     RowBox[{\"shPhaseLobe\", \"[\", \n      RowBox[{\"g\", \",\", \" \", \"phaseDir\"}], \"]\"}]}], \";\"}], \n   \"\\[IndentingNewLine]\", \"\\[IndentingNewLine]\", \n   RowBox[{\n   \"Print\", \"[\", \n    \"\\\"\\<HG, CS and SH2 approximation for different g values.\\>\\\"\", \"]\"}], \n   \"\\[IndentingNewLine]\", \n   RowBox[{\"Table\", \"[\", \"\\[IndentingNewLine]\", \n    RowBox[{\n     RowBox[{\"{\", \"\\[IndentingNewLine]\", \n      RowBox[{\n       RowBox[{\"SphericalPlot3D\", \"[\", \"\\[IndentingNewLine]\", \n        RowBox[{\n         RowBox[{\"phaseHG\", \"[\", \n          RowBox[{\"g\", \" \", \",\", \" \", \n           RowBox[{\"ArcCos\", \"[\", \n            RowBox[{\"Dot\", \"[\", \n             RowBox[{\n              RowBox[{\"aToD\", \"[\", \n               RowBox[{\"\\[Theta]\", \",\", \"\\[Phi]\"}], \"]\"}], \",\", \"phaseDir\"}], \n             \"]\"}], \"]\"}]}], \"]\"}], \",\", \"\\[IndentingNewLine]\", \n         RowBox[{\"{\", \n          RowBox[{\"\\[Theta]\", \",\", \"0\", \",\", \"\\[Pi]\"}], \"}\"}], \",\", \n         RowBox[{\"{\", \n          RowBox[{\"\\[Phi]\", \",\", \"0\", \",\", \n           RowBox[{\"2\", \" \", \"\\[Pi]\"}]}], \"}\"}], \",\", \n         RowBox[{\"PlotRange\", \"\\[Rule]\", \n          RowBox[{\"{\", \n           RowBox[{\n            RowBox[{\"-\", \"0.35\"}], \",\", \"0.35\"}], \"}\"}]}], \",\", \n         \"\\[IndentingNewLine]\", \n         RowBox[{\"ColorFunction\", \"\\[Rule]\", \n          RowBox[{\"(\", \n           RowBox[{\n            RowBox[{\n             RowBox[{\"ColorData\", \"[\", \"\\\"\\<Rainbow\\>\\\"\", \"]\"}], \"[\", \"#6\", \n             \"]\"}], \"&\"}], \")\"}]}], \",\", \"\\[IndentingNewLine]\", \n         RowBox[{\"PlotStyle\", \"\\[Rule]\", \n          RowBox[{\"Directive\", \"[\", \n           RowBox[{\"Opacity\", \"[\", \"0.5\", \"]\"}], \"]\"}]}], \",\", \n         \"\\[IndentingNewLine]\", \n         RowBox[{\"Axes\", \"\\[Rule]\", \"True\"}], \" \", \",\", \" \", \n         RowBox[{\"AxesStyle\", \"\\[Rule]\", \n          RowBox[{\"{\", \n           RowBox[{\"Red\", \",\", \"Green\", \",\", \"Blue\"}], \"}\"}]}], \",\", \" \", \n         RowBox[{\"ImageSize\", \"\\[Rule]\", \"170\"}]}], \"\\[IndentingNewLine]\", \n        \"]\"}], \",\", \"\\[IndentingNewLine]\", \n       RowBox[{\"SphericalPlot3D\", \"[\", \"\\[IndentingNewLine]\", \n        RowBox[{\n         RowBox[{\"phaseCS\", \"[\", \n          RowBox[{\"g\", \" \", \",\", \" \", \n           RowBox[{\"ArcCos\", \"[\", \n            RowBox[{\"Dot\", \"[\", \n             RowBox[{\n              RowBox[{\"aToD\", \"[\", \n               RowBox[{\"\\[Theta]\", \",\", \"\\[Phi]\"}], \"]\"}], \",\", \"phaseDir\"}], \n             \"]\"}], \"]\"}]}], \"]\"}], \",\", \"\\[IndentingNewLine]\", \n         RowBox[{\"{\", \n          RowBox[{\"\\[Theta]\", \",\", \"0\", \",\", \"\\[Pi]\"}], \"}\"}], \",\", \n         RowBox[{\"{\", \n          RowBox[{\"\\[Phi]\", \",\", \"0\", \",\", \n           RowBox[{\"2\", \" \", \"\\[Pi]\"}]}], \"}\"}], \",\", \n         RowBox[{\"PlotRange\", \"\\[Rule]\", \n          RowBox[{\"{\", \n           RowBox[{\n            RowBox[{\"-\", \"0.35\"}], \",\", \"0.35\"}], \"}\"}]}], \",\", \n         \"\\[IndentingNewLine]\", \n         RowBox[{\"ColorFunction\", \"\\[Rule]\", \n          RowBox[{\"(\", \n           RowBox[{\n            RowBox[{\n             RowBox[{\"ColorData\", \"[\", \"\\\"\\<Rainbow\\>\\\"\", \"]\"}], \"[\", \"#6\", \n             \"]\"}], \"&\"}], \")\"}]}], \",\", \"\\[IndentingNewLine]\", \n         RowBox[{\"PlotStyle\", \"\\[Rule]\", \n          RowBox[{\"Directive\", \"[\", \n           RowBox[{\"Opacity\", \"[\", \"0.5\", \"]\"}], \"]\"}]}], \",\", \n         \"\\[IndentingNewLine]\", \n         RowBox[{\"Axes\", \"\\[Rule]\", \"True\"}], \" \", \",\", \" \", \n         RowBox[{\"AxesStyle\", \"\\[Rule]\", \n          RowBox[{\"{\", \n           RowBox[{\"Red\", \",\", \"Green\", \",\", \"Blue\"}], \"}\"}]}], \",\", \" \", \n         RowBox[{\"ImageSize\", \"\\[Rule]\", \"170\"}]}], \"\\[IndentingNewLine]\", \n        \"]\"}], \",\", \"\\[IndentingNewLine]\", \n       RowBox[{\"SphericalPlot3D\", \"[\", \"\\[IndentingNewLine]\", \n        RowBox[{\n         RowBox[{\n          RowBox[{\"shPhase\", \" \", \"=\", \" \", \n           RowBox[{\"shPhaseLobe\", \"[\", \n            RowBox[{\"g\", \",\", \" \", \"phaseDir\"}], \"]\"}]}], \";\", \n          \"\\[IndentingNewLine]\", \n          RowBox[{\"unprojSh2\", \"[\", \n           RowBox[{\"shPhase\", \",\", \"\\[Theta]\", \",\", \"\\[Phi]\"}], \"]\"}]}], \",\", \n         \"\\[IndentingNewLine]\", \n         RowBox[{\"{\", \n          RowBox[{\"\\[Theta]\", \",\", \"0\", \",\", \"\\[Pi]\"}], \"}\"}], \",\", \n         RowBox[{\"{\", \n          RowBox[{\"\\[Phi]\", \",\", \"0\", \",\", \n           RowBox[{\"2\", \" \", \"\\[Pi]\"}]}], \"}\"}], \",\", \n         RowBox[{\"PlotRange\", \"\\[Rule]\", \n          RowBox[{\"{\", \n           RowBox[{\n            RowBox[{\"-\", \"0.35\"}], \",\", \"0.35\"}], \"}\"}]}], \",\", \n         \"\\[IndentingNewLine]\", \n         RowBox[{\"ColorFunction\", \"\\[Rule]\", \n          RowBox[{\"(\", \n           RowBox[{\n            RowBox[{\n             RowBox[{\"ColorData\", \"[\", \"\\\"\\<Rainbow\\>\\\"\", \"]\"}], \"[\", \"#6\", \n             \"]\"}], \"&\"}], \")\"}]}], \",\", \"\\[IndentingNewLine]\", \n         RowBox[{\"PlotStyle\", \"\\[Rule]\", \n          RowBox[{\"Directive\", \"[\", \n           RowBox[{\"Opacity\", \"[\", \"0.5\", \"]\"}], \"]\"}]}], \",\", \n         \"\\[IndentingNewLine]\", \n         RowBox[{\"Axes\", \"\\[Rule]\", \"True\"}], \" \", \",\", \" \", \n         RowBox[{\"AxesStyle\", \"\\[Rule]\", \n          RowBox[{\"{\", \n           RowBox[{\"Red\", \",\", \"Green\", \",\", \"Blue\"}], \"}\"}]}], \",\", \" \", \n         RowBox[{\"ImageSize\", \"\\[Rule]\", \"170\"}]}], \"\\[IndentingNewLine]\", \n        \"]\"}]}], \"\\[IndentingNewLine]\", \"}\"}], \"\\[IndentingNewLine]\", \n     RowBox[{\"(*\", \n      RowBox[{\n      \"phaseCS\", \" \", \"could\", \" \", \"be\", \" \", \"approximated\", \" \", \"nicely\", \n       \" \", \"with\", \" \", \"two\", \" \", \"sh2\", \" \", \n       RowBox[{\"lob\", \"?\"}]}], \"*)\"}], \"\\[IndentingNewLine]\", \",\", \n     \"\\[IndentingNewLine]\", \n     RowBox[{\"{\", \n      RowBox[{\"g\", \",\", \n       RowBox[{\"{\", \n        RowBox[{\"0.0\", \",\", \"0.1\", \",\", \"0.5\", \",\", \"0.9\"}], \"}\"}]}], \"}\"}]}],\n     \"\\[IndentingNewLine]\", \"]\"}], \"\\[IndentingNewLine]\", \n   \"\\[IndentingNewLine]\", \"\\[IndentingNewLine]\", \n   RowBox[{\"Print\", \"[\", \n    RowBox[{\"\\\"\\<Integral of SH2 approximation for g=\\>\\\"\", \",\", \"g\"}], \"]\"}],\n    \"\\[IndentingNewLine]\", \n   RowBox[{\"Integrate\", \"[\", \"\\[IndentingNewLine]\", \n    RowBox[{\n     RowBox[{\n      RowBox[{\"unprojSh2\", \"[\", \n       RowBox[{\"shPhase\", \",\", \"\\[Theta]\", \",\", \"\\[Phi]\"}], \"]\"}], \"*\", \n      RowBox[{\"Sin\", \"[\", \"\\[Theta]\", \"]\"}]}], \"\\[IndentingNewLine]\", \",\", \n     RowBox[{\"{\", \n      RowBox[{\"\\[Theta]\", \",\", \"0\", \",\", \"\\[Pi]\"}], \"}\"}], \",\", \n     RowBox[{\"{\", \n      RowBox[{\"\\[Phi]\", \",\", \"0\", \",\", \n       RowBox[{\"2\", \"\\[Pi]\"}]}], \"}\"}]}], \"]\"}], \n   \"\\[IndentingNewLine]\"}]}]], \"Input\"]\n},\nWindowSize->{858, 943},\nWindowMargins->{{0, Automatic}, {Automatic, 0}},\nPrintingCopies->1,\nPrintingPageRange->{32000, 32000},\nPrintingOptions->{\"Magnification\"->1.,\n\"PaperOrientation\"->\"Portrait\",\n\"PaperSize\"->{612, 792}},\nTrackCellChangeTimes->False,\nMagnification->1.100000023841858,\nFrontEndVersion->\"9.0 for Microsoft Windows (64-bit) (November 20, 2012)\",\nStyleDefinitions->FrontEnd`FileName[{\"Report\"}, \"StandardReport.nb\", \n  CharacterEncoding -> \"WindowsANSI\"]\n]\n(* End of Notebook Content *)\n\n(* Internal cache information *)\n(*CellTagsOutline\nCellTagsIndex->{}\n*)\n(*CellTagsIndex\nCellTagsIndex->{}\n*)\n(*NotebookFileOutline\nNotebook[{\nCell[557, 20, 635, 15, 103, \"Input\"],\nCell[1195, 37, 269, 6, 63, \"Input\"],\nCell[1467, 45, 4110, 104, 623, \"Input\"],\nCell[5580, 151, 4810, 122, 623, \"Input\"],\nCell[10393, 275, 44, 1, 1, \"PageBreak\",\n PageBreakBelow->True],\nCell[10440, 278, 44, 1, 4, \"PageBreak\",\n PageBreakBelow->True],\nCell[10487, 281, 7158, 181, 883, \"Input\"],\nCell[17648, 464, 8553, 201, 1146, \"Input\"]\n}\n]\n*)\n\n(* End of internal cache information *)\n"
  }
]