(* Content-type: application/vnd.wolfram.mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 10.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 158, 7] NotebookDataLength[ 31427, 694] NotebookOptionsPosition[ 30398, 655] NotebookOutlinePosition[ 30758, 671] CellTagsIndexPosition[ 30715, 668] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[TextData[{ StyleBox["Depth-to-Clusters Mapping", "Title"], "\n\nThis document defines a fomula to map depth to clusters (or froxels).\n\ This mapping step is necessary to implement Clustered Forward Rendering.\n\n\ It is important to note that the conversion relies on using a linear depth \ value.\nThis value can be either computed from the depth buffer (see the \ linearZ function),\nor come directly from an eye space position in the case \ of forward rendering." }], "Text", CellChangeTimes->{3.650734390378029*^9}], Cell[CellGroupData[{ Cell[TextData[{ "\n", StyleBox["Parameters and definitions", "Section"] }], "Subtitle", CellChangeTimes->{{3.650728032041154*^9, 3.650728054383952*^9}, { 3.6507280921050797`*^9, 3.65072809463174*^9}}], Cell[BoxData[ RowBox[{"ClearAll", "[", "\"\\"", "]"}]], "Input", CellChangeTimes->{3.650727340349822*^9}], Cell[BoxData[ RowBox[{ RowBox[{"(*", " ", RowBox[{"Near", " ", "plane"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"n", "=", "0.1"}], ";"}], "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"Far", " ", "plane"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"f", "=", "100.0"}], ";"}], "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"Max", " ", "cluster", " ", "index"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"maxIndex", "=", "16"}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"OpenGL", " ", "Z", " ", "linearization"}], ",", " ", RowBox[{ RowBox[{"see", " ", RowBox[{"http", ":"}]}], "//", RowBox[{ RowBox[{ RowBox[{ RowBox[{"www", ".", "humus", ".", "name"}], "/", "temp"}], "/", "Linearize"}], "%20", RowBox[{"depth", ".", "txt"}]}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "This", " ", "equation", " ", "assumes", " ", "Z", " ", "comes", " ", "from", " ", RowBox[{"gl_FragCoord", ".", "z"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{ "If", " ", "Z", " ", "comes", " ", "from", " ", "a", " ", "depth", " ", "texture"}], ",", " ", RowBox[{"c0", " ", "and", " ", "c1", " ", "are", " ", RowBox[{"different", ":"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"c0", "=", RowBox[{ RowBox[{"(", RowBox[{"1", "-", RowBox[{"f", "/", "n"}]}], ")"}], "/", "2"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"c1", "=", RowBox[{ RowBox[{"(", RowBox[{"1", "+", RowBox[{"f", "/", "n"}]}], ")"}], "/", "2"}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"c1", " ", "=", " ", RowBox[{"f", "/", "n"}]}], ";"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"c0", " ", "=", " ", RowBox[{"1.0", " ", "-", " ", "c1"}]}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "Computes", " ", "linear", " ", "z", " ", "from", " ", "depth", " ", "buffer"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ RowBox[{"This", " ", "can", " ", "be", " ", "optimized", " ", "to"}], " ", "-", RowBox[{ RowBox[{"Log2", "[", "]"}], " ", "under", " ", RowBox[{"Log2", "[", "]"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"linearZ", "[", "z_", "]"}], ":=", RowBox[{"1.0", "/", RowBox[{"(", RowBox[{ RowBox[{"c0", "*", "z"}], "+", "c1"}], ")"}]}]}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"Z", " ", "must", " ", "be", " ", "linear"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"zToCluster", "[", "z_", "]"}], ":=", RowBox[{ RowBox[{ RowBox[{"Log2", "[", "z", "]"}], "*", RowBox[{"(", RowBox[{"maxIndex", "/", RowBox[{"-", RowBox[{"Log2", "[", RowBox[{"n", "/", "f"}], "]"}]}]}], ")"}]}], "+", "maxIndex"}]}]}]}]], "Input", CellChangeTimes->{{3.650396375402903*^9, 3.650396481281419*^9}, { 3.650396564786338*^9, 3.650396596505126*^9}, {3.6503967973379583`*^9, 3.6503968023371983`*^9}, {3.650396946499518*^9, 3.650396947698139*^9}, { 3.650397398831441*^9, 3.650397468828425*^9}, {3.650397500375121*^9, 3.650397505894915*^9}, 3.650397553794248*^9, {3.650397734423705*^9, 3.650397831077795*^9}, {3.650397881677594*^9, 3.650397886309231*^9}, { 3.650397943488078*^9, 3.650398073036994*^9}, {3.65039812455151*^9, 3.650398128285982*^9}, {3.650398207021921*^9, 3.650398236996192*^9}, { 3.650398318709527*^9, 3.650398344395561*^9}, {3.65039852641225*^9, 3.650398527850202*^9}, {3.650398564987216*^9, 3.650398602123239*^9}, { 3.650398656299835*^9, 3.6503986564346333`*^9}, {3.650398790027649*^9, 3.650398849668439*^9}, {3.650398948723308*^9, 3.650398951409622*^9}, { 3.650398984570889*^9, 3.650399104409181*^9}, {3.6503991602286587`*^9, 3.6503991628172007`*^9}, {3.650399222593235*^9, 3.6503992361688633`*^9}, { 3.6503992801948023`*^9, 3.650399282920697*^9}, {3.6503993354133997`*^9, 3.6503993883393803`*^9}, {3.650399581785262*^9, 3.650399598456815*^9}, { 3.6503996327526207`*^9, 3.650399662743662*^9}, {3.650399715184883*^9, 3.650399722879245*^9}, {3.650399838328868*^9, 3.650399840088044*^9}, { 3.65040042042284*^9, 3.650400509253128*^9}, {3.650400545157927*^9, 3.650400577556995*^9}, {3.650400646053444*^9, 3.650400685052733*^9}, { 3.650400742192411*^9, 3.650400800750242*^9}, {3.650400834781745*^9, 3.650400836602578*^9}, {3.650400943565447*^9, 3.650400974205031*^9}, { 3.650402048212742*^9, 3.6504020507690887`*^9}, 3.65040224487603*^9, { 3.650402762497122*^9, 3.6504027630007133`*^9}, {3.650403899249236*^9, 3.650403930850663*^9}, {3.650722758515052*^9, 3.6507228005128517`*^9}, { 3.6507228549281673`*^9, 3.650722882745895*^9}, {3.6507230705669527`*^9, 3.650723145933608*^9}, {3.6507231876628523`*^9, 3.650723194662696*^9}, { 3.6507236248261843`*^9, 3.650723648680642*^9}, {3.6507237327225647`*^9, 3.650723751447606*^9}, {3.65072379843987*^9, 3.650723804160193*^9}, { 3.650723994781382*^9, 3.650724002581299*^9}, {3.650725088062682*^9, 3.6507251044851227`*^9}, {3.650725153173024*^9, 3.650725153436605*^9}, { 3.650725188109761*^9, 3.650725366456407*^9}, {3.6507254633045273`*^9, 3.6507254634676533`*^9}, {3.650727888995965*^9, 3.650727905730351*^9}, { 3.650728059761993*^9, 3.6507280761635227`*^9}, {3.650730007298497*^9, 3.650730008418108*^9}, {3.650730057492527*^9, 3.650730058121291*^9}, { 3.6507336445240307`*^9, 3.650733666333302*^9}, {3.650745487825314*^9, 3.650745497541481*^9}, {3.65074564314386*^9, 3.650745643389658*^9}, { 3.6507456766936617`*^9, 3.650745683503189*^9}, {3.65074603472771*^9, 3.650746034835597*^9}, {3.6507463588523293`*^9, 3.650746360467896*^9}, { 3.650826299868141*^9, 3.650826374853242*^9}, {3.651529514316169*^9, 3.651529598772925*^9}}] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "\n", StyleBox["Depth to cluster index", "Section"], "\n", StyleBox["\nThe graphics below shows the assignment of a cluster index to \ each depth value in the [near, far] range.", "Text"] }], "Subtitle", CellChangeTimes->{{3.650727993353105*^9, 3.650728016543971*^9}, { 3.650728159135438*^9, 3.650728275255884*^9}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{ RowBox[{"(*", " ", RowBox[{ RowBox[{ "This", " ", "assumes", " ", "Z", " ", "is", " ", "the", " ", "depth", " ", "position", " ", "in", " ", "eye", " ", "space"}], ",", " ", RowBox[{"use", " ", RowBox[{"linearZ", "[", "]"}], " ", "if", " ", "Z", " ", "comes", " ", "from", " ", RowBox[{"gl_FragCoord", ".", "z"}]}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"Plot", "[", RowBox[{ RowBox[{"Floor", "[", RowBox[{"Max", "[", RowBox[{ RowBox[{"zToCluster", "[", RowBox[{"z", "/", "f"}], "]"}], ",", "0"}], "]"}], "]"}], ",", " ", RowBox[{"{", RowBox[{"z", ",", "n", ",", "f"}], "}"}], ",", RowBox[{"ImageSize", "\[Rule]", "Full"}]}], "]"}]}]], "Input", CellChangeTimes->CompressedData[" 1:eJwdz1soQwEAxvFD7pfUDGkmspeVKLO5C1tDHmyULZeIvFgRalNKirxIiRPm sgd3RyRThlkoxWZFlpShVpStjKnZpDjfefj6PX79U1u7atoDCYJIoQd3tKoB gcBVKqkuG4JSfcEYHBWFayHra20TinQmxpNHmQH2yE3HsNPsPoMy1fY57CfZ N9DRy2Hc2Ui9g9RhxTPc9by/QUIocDE/Cfte6Fxu/IVKd2VENq0hxB8Nidnh RHhrHU6CXAtXDPc0ckZp0GQ59AdHNsKGLH8L1JG+NqjmbXfC1wnZNDTxOAsw XfKyCK8v1Gtw3KihIPXxdwkVad9WWJUxcwudZWH3cCTW8ggDplxPUH/6cyVE l+LOAeOr9Z/QzD/wwPpD+zdkifk+2MH2skW0E3V8DlwItNtgQ/PgA5y1Jcfl 0K4XCBiNK3mJ8FXdxDinDD3KRTdJncO+/EwzDKmNs8Io6RJZTBvTTU3DkqKT OXhFrs7DQouPggajYwv+A+qx674= "]], Cell[BoxData[ GraphicsBox[{{{}, {}, {RGBColor[0.368417, 0.506779, 0.709798], AbsoluteThickness[1.6], Opacity[ 1.], LineBox[{{3.1902564878899016`, 8.}, {3.2234727618279546`, 8.}, { 3.2566890357660077`, 8.}, {3.3231215836421133`, 8.}, {3.389554131518219, 8.}, {3.5224192272704307`, 8.}, {3.6552843230226424`, 8.}, { 3.921014514527066, 8.}, {4.186744706031489, 8.}, {4.859481802647827, 8.}}], LineBox[{{6.171710320833357, 9.}, {6.658217438062804, 9.}, { 7.1447245552922505`, 9.}, {7.266351334599612, 9.}, {7.387978113906973, 9.}, {7.418384808733814, 9.}, {7.4487915035606544`, 9.}, { 7.479198198387495, 9.}, {7.483220816674667, 9.}}], LineBox[{{7.514663369974464, 10.}, {7.570418282868015, 10.}, { 7.631231672521697, 10.}, {7.87448523113642, 10.}, {8.117738789751144, 10.}, {9.173223222617434, 10.}, {10.228707655483724`, 10.}, { 10.721230892608489`, 10.}, {11.213754129733255`, 10.}, { 11.336884939014446`, 10.}, {11.460015748295639`, 10.}, { 11.490798450615937`, 10.}, {11.521581152936236`, 10.}, { 11.5235889156987, 10.}}], LineBox[{{11.572050778090478`, 11.}, {11.58314655757683, 11.}, { 11.644711962217425`, 11.}, {11.706277366858021`, 11.}, { 11.952538985420404`, 11.}, {12.198800603982786`, 11.}, { 13.266317276639715`, 11.}, {14.333833949296642`, 11.}, { 15.38188204901153, 11.}, {16.429930148726417`, 11.}, { 16.918735219275483`, 11.}, {17.407540289824546`, 11.}, { 17.52974155746181, 11.}, {17.651942825099077`, 11.}, {17.71304345891771, 11.}, {17.750938233042298`, 11.}}], LineBox[CompressedData[" 1:eJxTTMoPSmViYGAQBmIQ7SJb+azngqEDAxhoOJzYajDz0lUE/+L2kn1L7iL4 t3bueFz2FMFXOnWDl0PFCM7PuvXDfGYSgl+heW7Jr0JjOL+tYrFgTKMJnH/0 2JxKvhozOJ/v5VqJkzkWcL5CR7eOc5UlnG+snumwt90Kzv+TorV95jEE/8ii 17plrNZw/gpHn8wnKgh+74M1S4JcEHw3jlZjPR8En8Eg9hBnCIJ/scTpj1EU gg8AWO5K1Q== "]], LineBox[CompressedData[" 1:eJxTTMoPSmViYGAQAWIQ3Rx2OrUpy9qBAQy0HJ6c2/u3vBjBD5PLk9ZvRvBf zPzA8YLBBs6vEi3+tqAOwe+WOjtVv98Wzp8jr266b74dnP+0rvJqYbQDnM97 rC38T4gjnK8k/XLu4mQnON/zRNFqpwRnOP+yatIUhZcIfmxzYO2/Qhc4f4nO mgq9rQj+q6tsJXE/EHxh7aLiIwyucL5Nw90iLU4E/4LW5KJYXgQ/5apH0QRB BP/3x2v2i5H4ANo+Ti0= "]], LineBox[CompressedData[" 1:eJxTTMoPSmViYGAQB2IQ3au1pfCbpKsDAxjoONy70lVwSAvBN6hPzO+zRvAv X+bLVYtF8Ms09mTtq0PwedRZXaX+IPgLVf3kyyrd4PydBqYzvDrd4fzHk51v iLV7wPlCD+8aP6/3hPP1bM4GX+n1gvNj3j+22tnpDeeXb/B/tmuWD5w/I9p9 7YFlvnD+qbg0630L/OD8qPQFKd4a/nD+y/xbvTfWI/hmXo4isu8RfEehkLMG 4gFw/pUTb98xqiP46fXtApfNEHyrbbtMzlog+Ku+eX1gsELwAcqZWiE= "]], LineBox[CompressedData[" 1:eJxTTMoPSmViYGCQBGIQLaa/9pSIXYADAxjoOWyIClm4G4kfemLXy/VOCP4v U0WjJW4Ivovgu0M9fgh+75tdwaVhCH7UQZaHVVMQfI1pfnkNlxD8ncd4XktG BsL5wYvjvNdfQ/CfsN3mvRwXBOfXir3e/Okugi8pfTB9SlQwnL9m2cHaIw8R fPd7oeUf4kPg/JtzRC6veoHg5wXMtHmeFwrn82zY2Cn/BsFfMO2LxbPiMDjf VvP06RWfEPy7G9Jz3uaFw/nF+/XyD3xF8IWqOkP7iyMQ6nXrlh3fieCveFj0 /f9/BB8A/Q1sUQ== "]]}, {}}, {{}, {}, {}}}, AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], Axes->{True, True}, AxesLabel->{None, None}, AxesOrigin->{0, 7.2}, DisplayFunction->Identity, Frame->{{False, False}, {False, False}}, FrameLabel->{{None, None}, {None, None}}, FrameTicks->{{Automatic, Automatic}, {Automatic, Automatic}}, GridLines->{None, None}, GridLinesStyle->Directive[ GrayLevel[0.5, 0.4]], ImageSize->Full, Method->{"DefaultBoundaryStyle" -> Automatic, "ScalingFunctions" -> None}, PlotRange->{{0.1, 100.}, {7.5, 15.}}, PlotRangeClipping->True, PlotRangePadding->{{ Scaled[0.02], Scaled[0.02]}, { Scaled[0.05], Scaled[0.05]}}, Ticks->{Automatic, Automatic}]], "Output", CellChangeTimes->{{3.650745622998098*^9, 3.650745640753529*^9}, { 3.650745711888585*^9, 3.6507457160808973`*^9}, 3.650746037713381*^9}] }, Open ]], Cell[TextData[{ StyleBox["Range loss", "Subsection"], StyleBox["\n", "Subsubtitle"], "\nBecause the distribution is exponential, a large number of clusters is \ assigned to the first few meters of the depth range.\nBy plotting the \ assignments in the range [near, 7m], we can see that almost half of our \ clusters are already assigned.\nThis problem is similar to the one observed \ by Avalanche Studios in ", ButtonBox["Practical Cluster Shading", BaseStyle->"Hyperlink", ButtonData->{ URL["http://www.humus.name/Articles/PracticalClusteredShading.pdf"], None}, ButtonNote-> "http://www.humus.name/Articles/PracticalClusteredShading.pdf"], "." }], "Text", CellChangeTimes->{{3.6507283367537193`*^9, 3.650728458430543*^9}, { 3.650728503265861*^9, 3.650728546782392*^9}, {3.650728601510634*^9, 3.650728602574113*^9}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"Plot", "[", RowBox[{ RowBox[{"Floor", "[", RowBox[{"Max", "[", RowBox[{ RowBox[{"zToCluster", "[", RowBox[{"z", "/", "f"}], "]"}], ",", "0"}], "]"}], "]"}], ",", " ", RowBox[{"{", RowBox[{"z", ",", "n", ",", "7"}], "}"}], ",", RowBox[{"ImageSize", "\[Rule]", "Full"}]}], "]"}]], "Input", CellChangeTimes->{{3.650728360017872*^9, 3.650728367511367*^9}, { 3.650730022932716*^9, 3.6507300364334707`*^9}, 3.650733637853883*^9}], Cell[BoxData[ GraphicsBox[{{{}, {}, {RGBColor[0.368417, 0.506779, 0.709798], AbsoluteThickness[1.6], Opacity[ 1.], LineBox[{{0.10000014081632654`, 0.}, {0.1021163535654854, 0.}, { 0.10423256631464425`, 0.}, {0.10846499181296199`, 0.}, { 0.11692984280959742`, 0.}, {0.11904605555875628`, 0.}, { 0.12116226830791514`, 0.}, {0.12539469380623286`, 0.}, { 0.1338595448028683, 0.}, {0.13597575755202718`, 0.}, { 0.13809197030118603`, 0.}, {0.14232439579950373`, 0.}, { 0.14444060854866259`, 0.}, {0.14655682129782144`, 0.}, { 0.1486730340469803, 0.}, {0.15078924679613917`, 0.}, { 0.15290545954529805`, 0.}, {0.15366980300797317`, 0.}}], LineBox[{{0.1550216722944569, 1.}, {0.15713788504361575`, 1.}, { 0.1592540977927746, 1.}, {0.1634865232910923, 1.}, { 0.16771894878941004`, 1.}, {0.20157835277595182`, 1.}, { 0.23543775676249357`, 1.}, {0.23664214968783887`, 1.}}], LineBox[{{0.36620813253662987`, 3.}, {0.36850234965547435`, 3.}, { 0.3707965667743188, 3.}, {0.3730907838931633, 3.}, {0.3776792181308523, 3.}, {0.3822676523685413, 3.}, {0.45081751594278, 3.}, { 0.5193673795170187, 3.}, {0.5361686763582758, 3.}, {0.552969973199533, 3.}, {0.5571702974098474, 3.}, {0.5611571486519892, 3.}}], LineBox[CompressedData[" 1:eJxTTMoPSmViYGAQBmIQvTSBZ1EaxyN7BjAQcJCRqbXVkETwL3/LmxmjheB3 XUz4OsEawU+10UhNakDwHZa/v2J8FMFfE8Q7pfLGYzhf/J9W8P7XT+D8icn6 tV8cnsP53CeNl2tOewnnqyxVt21QfAXn2zZKX762BsH3yheVa/qE4IfF8mfq WryG82NCeviYoxH8JG/OLTdqEfynx463Ofcj+BlObZHrFiD4ZXZ/ZostR/AB CqZPwQ== "]], LineBox[{{0.867782123569836, 5.}, {0.9016347730862898, 5.}, { 0.9356528945693817, 5.}, {1.0093852773655059`, 5.}, {1.08311766016163, 5.}, {1.1555053667485442`, 5.}, {1.2278930733354583`, 5.}, { 1.261654384514523, 5.}, {1.2954156956935874`, 5.}, {1.3122963512831196`, 5.}, {1.3291770068726518`, 5.}, {1.3312870888213433`, 5.}, { 1.3313211770612838`, 5.}}], LineBox[CompressedData[" 1:eJxTTMoPSmViYGAQAWIQ3XfWdIts/Fd7BjCQcBCJ1M9/mIbgH5E9N0OrAsEv fZRzqLgTwb+WvUqUbQ2Cb/H1ecaMcwj+tOM7btT/+gbnf5nZ6ZGu9gPOn+X5 LTQ67Becn856I9W7+g+cPz9rrbPE0r9w/vXzTYpPz/2D8/VcH9y+Evkfzm/Z ZTvtyBMEf4bVNks5UQYHGP/ddF+NW+YI/ky3mfIWngi+y9cnYtOikOTPdAm5 JiP4Av3G32QyEXwAKp9W1A== "]], LineBox[CompressedData[" 1:eJxTTMoPSmViYGAQA2IQHXF7nYRCEYMDAxjIOLhUX+NcXILgv0tb2f6rAsGf GVTDGlSL4M/gPqP1RpgRzp9+RDqgbRWCv3LP19kWl5jgfAOrrXV/nzLD+Vz2 kebigqxwfsTJR23OGmxw/o9bAWuOhLHD+ZfUltq7vEbw1xT9vHS4ngPO//Yz xonjKILv0Hhgow8XJ5wvlDzz7FxpBP+pS9HLdzoI/rmtceXTTRH8HWrerA52 CL5OvKPPFCcEf+F088kv3BB8o61zVl5zR/ABEQNQfg== "]], LineBox[CompressedData[" 1:eJxTTMoPSmViYGAQA2IQXcUoceZmAKcDAxgoOBicuRphXITgX+1vn3B1CoIv 9MjhFoc2F5zvZ/JL2eYggm8bF+S39SY3nG/P97RyzRseOH+ya0z1DzE+OD+G aadwuC4/nG+j/NehVVcAzg/h2P1j7kEEX23D69/7vQXh/IWz+bJ6HiL41zyX KCflCsH5ZYf2NrzZiOCLWl+/W/YNwffvUFi+TFoYzu+8mllwzQHBV6vhC80L RvAPK222ZEtD8IXKWHWC8hH8NdYTY70rEHwAByhN+Q== "]], LineBox[CompressedData[" 1:eJxTTMoPSmViYGAQB2IQfeHhuXdnaoQdGMBAyYH9c4O4Sy2Cf6tdVGR6PYK/ TmaVwKtGBD/M7TLnhDYE/2/+HyazbgT/XLaH9awLCP789CnF/0RF4PxXi+T8 C9cg+B8WSJe9tRCF8xkebZ274hCCvyPNyYAvQgzO117nyFf7GMF3tzQOn1Yl DufnsB9a8I5PAs73mXHYNGAmgn81Z7tpjL4knC/BItdYuBvBT72nePaoixSc H/1HvOXITQSf+25D25kUaThf9UqbXdomBN/+dM+3//8RfADtMFb2 "]], LineBox[{{0.23773197388133807`, 2.}, {0.24002619100018258`, 2.}, { 0.24232040811902705`, 2.}, {0.24461462523787156`, 2.}, { 0.24920305947556054`, 2.}, {0.25379149371324955`, 2.}, { 0.2629683621886275, 2.}, {0.27214523066400553`, 2.}, { 0.29049896761476146`, 2.}, {0.30885270456551744`, 2.}, { 0.3272064415162734, 2.}, {0.34556017846702936`, 2.}, { 0.3547370469424074, 2.}, {0.36391391541778534`, 2.}, { 0.36440773469872334`, 2.}}]}, {}}, {{}, {}, {}}}, AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], Axes->{True, True}, AxesLabel->{None, None}, AxesOrigin->{0, 0}, DisplayFunction->Identity, Frame->{{False, False}, {False, False}}, FrameLabel->{{None, None}, {None, None}}, FrameTicks->{{Automatic, Automatic}, {Automatic, Automatic}}, GridLines->{None, None}, GridLinesStyle->Directive[ GrayLevel[0.5, 0.4]], ImageSize->Full, Method->{"DefaultBoundaryStyle" -> Automatic, "ScalingFunctions" -> None}, PlotRange->{{0.1, 7}, {0., 9.}}, PlotRangeClipping->True, PlotRangePadding->{{ Scaled[0.02], Scaled[0.02]}, { Scaled[0.05], Scaled[0.05]}}, Ticks->{Automatic, Automatic}]], "Output", CellChangeTimes->{ 3.6507283682377462`*^9, {3.650730014280918*^9, 3.650730062690531*^9}, 3.650733638578546*^9, 3.650733680317855*^9, 3.650745597758737*^9, 3.650746042122489*^9}] }, Open ]], Cell[TextData[{ StyleBox["Fixing the range loss", "Subsection"], "\n\nThe solution proposed by Avalanche Studios is to create a special \ cluster at the near plane and to redistribute\nthe clusters over the \ remaining depth range. The far bound of this special cluster depends on the \ types of scenes\nthat will be lit using the Clustered Forward Rendering \ technique.\n\nIn the example below, we used the special cluster [near, 5m]. \ To implement the special cluster, we simply need to\nreplace the near plane \ in the original formula with a new near value (in this case, 5). We also need \ to reduce the\nclusters indices range by 0 (maxIndex - 1).\n\nWe can observe \ that the new range presents a better distribution.\n" }], "Text", CellChangeTimes->{{3.650728712160707*^9, 3.6507289648687696`*^9}, { 3.650734238168865*^9, 3.650734344223527*^9}}], Cell[CellGroupData[{ Cell[BoxData[{ RowBox[{"specialNear", "=", " ", "5"}], "\[IndentingNewLine]", RowBox[{ RowBox[{"zToClusterSpecial", "[", "z_", "]"}], ":=", RowBox[{ RowBox[{ RowBox[{"Log2", "[", "z", "]"}], "*", RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{"maxIndex", "-", "1"}], ")"}], "/", RowBox[{"-", RowBox[{"Log2", "[", RowBox[{"specialNear", "/", "f"}], "]"}]}]}], ")"}]}], "+", "maxIndex"}]}], "\[IndentingNewLine]", RowBox[{"Plot", "[", RowBox[{ RowBox[{"Floor", "[", RowBox[{"Max", "[", RowBox[{ RowBox[{"zToClusterSpecial", "[", RowBox[{"z", "/", "f"}], "]"}], ",", "0"}], "]"}], "]"}], ",", " ", RowBox[{"{", RowBox[{"z", ",", "n", ",", "f"}], "}"}], ",", RowBox[{"ImageSize", "\[Rule]", "Full"}]}], "]"}]}], "Input", CellChangeTimes->{{3.650729116464319*^9, 3.650729158620058*^9}, { 3.650729198568322*^9, 3.6507292010598907`*^9}, {3.650729291653813*^9, 3.650729387886808*^9}, {3.650729420166993*^9, 3.6507294270991783`*^9}, { 3.650729460788136*^9, 3.6507295322915297`*^9}, {3.6507297133177977`*^9, 3.650729766786379*^9}, {3.650729805066984*^9, 3.650729854140778*^9}, { 3.650733688933605*^9, 3.650733948106715*^9}, {3.6507342499298*^9, 3.6507342585133743`*^9}, {3.650745941902185*^9, 3.650745966443899*^9}, { 3.6507462393810387`*^9, 3.650746300844221*^9}, 3.6507468052266283`*^9, { 3.650826381594051*^9, 3.6508264245560827`*^9}}], Cell[BoxData["5"], "Output", CellChangeTimes->{{3.650729312570847*^9, 3.6507293890811872`*^9}, { 3.650729427482403*^9, 3.650729532836125*^9}, {3.650729713879979*^9, 3.6507297672811193`*^9}, {3.650729806147242*^9, 3.650729854839425*^9}, { 3.6507336908451567`*^9, 3.6507339485688887`*^9}, 3.650734259050721*^9, 3.6507458714074173`*^9, {3.650745942791009*^9, 3.650745966768341*^9}, 3.650746045272848*^9, {3.650746240080187*^9, 3.650746301193458*^9}, 3.650746805978116*^9, {3.650826398635215*^9, 3.650826425926552*^9}}], Cell[BoxData[ GraphicsBox[{{{}, {}, {RGBColor[0.368417, 0.506779, 0.709798], AbsoluteThickness[1.6], Opacity[ 1.], LineBox[CompressedData[" 1:eJxTTMoPSmViYGAQAWIQffuX0LndM3faM0DBlcxrSjd3HIDzrcIWx11ZcgTO Z9e3vXaq5gycH1Cw41G02DU4/6vAtwyVx4/gfPeHIms6PD/C+QWeS87uqmFw gPE3RZdtOngAwf+S6zH9BAsjnF8+6U3CtR4Ev+62yZePc5jg/J7co1Kae1ng /OUTn6VP/8sB579YvMNnniMnnK+1rctwaSuCv+6W3u9NvFxw/hbl8r5zstxw /qGt7FtZ7Xjh/KbTP/wrHQTgfAAyBk4B "]], LineBox[{{4.186744706031489, 0.}, {4.217759793762768, 0.}, { 4.2487748814940485`, 0.}, {4.310805056956607, 0.}, {4.434865407881723, 0.}, {4.4658804956130025`, 0.}, {4.496895583344282, 0.}, { 4.55892575880684, 0.}, {4.6829861097319565`, 0.}, {4.714001197463236, 0.}, {4.745016285194515, 0.}, {4.807046460657073, 0.}, { 4.838061548388352, 0.}, {4.869076636119631, 0.}, {4.93110681158219, 0.}, {4.962121899313469, 0.}, {4.993136987044748, 0.}, { 4.995786464618594, 0.}}], LineBox[{{6.110524605819178, 2.}, {6.140695233102078, 2.}, { 6.171710320833357, 2.}, {6.658217438062804, 2.}, {7.1447245552922505`, 2.}, {7.266351334599612, 2.}, {7.387978113906973, 2.}, { 7.418384808733814, 2.}, {7.4487915035606544`, 2.}, {7.4487915035606544`, 2.}}], LineBox[{{7.479198198387495, 3.}, {7.509604893214335, 3.}, { 7.570418282868015, 3.}, {7.631231672521697, 3.}, {7.87448523113642, 3.}, {8.117738789751144, 3.}, {9.098423020441599, 3.}}], LineBox[{{10.228707655483724`, 4.}, {11.105471641034562`, 4.}}], LineBox[{{12.198800603982786`, 5.}, {12.73255894031125, 5.}, { 13.266317276639715`, 5.}, {13.39975686072183, 5.}, {13.533196444803947`, 5.}, {13.566556340824476`, 5.}, {13.566556340824476`, 5.}}], LineBox[{{13.599916236845004`, 6.}, {13.633276132865534`, 6.}, { 13.666636028886064`, 6.}, {13.733355820927121`, 6.}, { 13.800075612968179`, 6.}, {14.06695478113241, 6.}, {14.333833949296642`, 6.}, {15.38188204901153, 6.}, {16.429930148726417`, 6.}, { 16.491030782545053`, 6.}, {16.552131416363686`, 6.}, { 16.558071284247795`, 6.}}], LineBox[CompressedData[" 1:eJxTTMoPSmViYGAQAWIQPYXd+rLSNAMHBjCQcUhImXDszxwEPzPtyutzSxD8 ogwJwYVrEPxpBRrLXp5G8HdVWFgbvUbwmTojUg9rGsL5XjMr+kMyEPxbO3c8 LnuK4Gfd+mE+M8kIzv/YmPzO8xWCX6F5bsmvQmM436aWmeHyVgT//wWL6NU/ EfwPqmxFC7lM4PwHVZc7pksj+BGqVlOEVBD8i+cXzO/VQfC9qthXc5gi+M0v IzIemCP4AI3yTsQ= "]], LineBox[{{20.253048508697805`, 8.}, {20.37280106749553, 8.}, { 20.50531110993372, 8.}, {21.49495349082249, 8.}, {22.484595871711253`, 8.}, {23.45476967965798, 8.}, {24.4249434876047, 8.}, { 24.556523988398965`, 8.}, {24.687571230015422`, 8.}}], LineBox[{{24.730144218345174`, 9.}, {24.75389473959036, 9.}, { 24.78678986478893, 9.}, {24.819684989987493`, 9.}, {24.88547524038463, 9.}, {24.95126549078176, 9.}, {25.214426492370293`, 9.}, { 25.477587493958822`, 9.}, {26.003909497135886`, 9.}, { 26.530231500312947`, 9.}, {27.512437548050308`, 9.}, {28.49464359578767, 9.}, {29.02698171886005, 9.}, {29.55931984193243, 9.}, { 29.825488903468624`, 9.}, {30.091657965004813`, 9.}, { 30.124929097696835`, 9.}, {30.144953442658483`, 9.}}], LineBox[{{30.196809922793143`, 10.}, {30.224742495772908`, 10.}, { 30.291284761156955`, 10.}, {30.357827026541003`, 10.}, { 30.490911557309097`, 10.}, {30.62399608807719, 10.}, { 31.669203761279913`, 10.}, {32.714411434482635`, 10.}, { 34.663950863654556`, 10.}, {35.721190776647916`, 10.}, { 36.77843068964127, 10.}, {36.80851113996225, 10.}}], LineBox[{{36.8721188328455, 11.}, {36.90178093393834, 11.}, { 36.96345605608688, 11.}, {37.02513117823542, 11.}, {37.1484814225325, 11.}, {37.27183166682957, 11.}, {37.51853215542372, 11.}, { 37.76523264401787, 11.}, {38.25863362120617, 11.}, {38.75203459839447, 11.}, {39.82130675117846, 11.}, {40.89057890396246, 11.}, { 42.99018606364636, 11.}, {43.96955168487156, 11.}, {44.94891730609675, 11.}, {44.95220600296015, 11.}}], LineBox[CompressedData[" 1:eJxTTMoPSmViYGCQBGIQ7RC8cjpnk5sDAxhoOKj9+iFi0obgB027k1bcheCv PreY69MkBJ+FPXtdwWwEf1v5z6+5axD89Bftttl7EfxTJ5ecSb2P4OuuPhid wOgO53/O/V0Z6org7zQwneHVieD7JdnsMODwgPMfT3a+IdaO4As9vGv8vN4T zl/Qd/XwXTYvOF/P5mzwlV4E/9eLSb1nzyD4R6dGHD/G7Q3na+VYpzhrI/gT nOQYD3gh+IfX9vvXRSH43yQY59lkIckXzzXUyUPSf87yqHQRgl+ls2PvViQ+ AF0fZFQ= "]], LineBox[{{54.95988303265281, 13.}, {55.01446767674089, 13.}, { 55.07596527223242, 13.}, {56.14239699850425, 13.}, {57.208828724776076`, 13.}, {59.30275503143565, 13.}, {61.255805420861705`, 13.}, { 63.37379620710255, 13.}, {64.36235364160622, 13.}, {65.35091107610988, 13.}, {65.8354555068907, 13.}, {66.3199999376715, 13.}, { 66.56227215306191, 13.}, {66.80454436845231, 13.}, {66.9256804761475, 13.}, {67.03830282510518, 13.}}], LineBox[CompressedData[" 1:eJxTTMoPSmViYGAQAWIQndAsnNF+LMCBAQx0HBz3XUi+j8R/wWM94fwJBL8v eume/acQ/Ns/KkUXnEPwNab55TVcQvAL1q3VOSsaCOfvPMbzWjISwQ9eHOe9 /hqC/4TtNu/luCA4v1bs9eZPdxF8SemD6VOiguH8NcsO1h55iOBXHequuqUQ Aue73wst/xCP4BucEpStyUDwpbadPcReiOCLbLRZo1WM4POtWT3VtxTBTxCb YxdSjuADABYhUsc= "]], LineBox[{{81.9282286151385, 15.}, {81.9663837920815, 15.}, { 82.03314549248142, 15.}, {82.30019229408114, 15.}, {82.56723909568086, 15.}, {83.1013326988803, 15.}, {83.63542630207975, 15.}, { 84.68414493553661, 15.}, {85.73286356899345, 15.}, {87.68942491867364, 15.}, {89.81092666516861, 15.}, {91.79155249443006, 15.}, { 93.73324117780744, 15.}, {95.8398702579996, 15.}, {97.80562342095826, 15.}, {98.90281069109137, 15.}, {99.9999979612245, 15.}}], LineBox[{{5.024152074776027, 1.}, {5.055167162507306, 1.}, { 5.1171973379698645`, 1.}, {5.179227513432423, 1.}, {5.427348215282656, 1.}, {5.67546891713289, 1.}, {5.7995292680580075`, 1.}, { 5.923589618983124, 1.}, {5.985619794445682, 1.}, {6.047649969908241, 1.}, {6.07866505763952, 1.}, {6.1000283948564995`, 1.}}]}, {}}, {{}, {}, {}}}, AspectRatio->NCache[GoldenRatio^(-1), 0.6180339887498948], Axes->{True, True}, AxesLabel->{None, None}, AxesOrigin->{0, 0}, DisplayFunction->Identity, Frame->{{False, False}, {False, False}}, FrameLabel->{{None, None}, {None, None}}, FrameTicks->{{Automatic, Automatic}, {Automatic, Automatic}}, GridLines->{None, None}, GridLinesStyle->Directive[ GrayLevel[0.5, 0.4]], ImageSize->Full, Method->{"DefaultBoundaryStyle" -> Automatic, "ScalingFunctions" -> None}, PlotRange->{{0.1, 100.}, {0., 15.}}, PlotRangeClipping->True, PlotRangePadding->{{ Scaled[0.02], Scaled[0.02]}, { Scaled[0.05], Scaled[0.05]}}, Ticks->{Automatic, Automatic}]], "Output", CellChangeTimes->{{3.650729312570847*^9, 3.6507293890811872`*^9}, { 3.650729427482403*^9, 3.650729532836125*^9}, {3.650729713879979*^9, 3.6507297672811193`*^9}, {3.650729806147242*^9, 3.650729854839425*^9}, { 3.6507336908451567`*^9, 3.6507339485688887`*^9}, 3.650734259050721*^9, 3.6507458714074173`*^9, {3.650745942791009*^9, 3.650745966768341*^9}, 3.650746045272848*^9, {3.650746240080187*^9, 3.650746301193458*^9}, 3.650746805978116*^9, {3.650826398635215*^9, 3.650826425959436*^9}}] }, Open ]], Cell[TextData[{ StyleBox["\nCluster index to depth\n", "Section"], "\nIt is simply the inverse function:" }], "Text", CellChangeTimes->{{3.650826446987648*^9, 3.650826496224813*^9}}], Cell[BoxData[ RowBox[{ RowBox[{ RowBox[{"clusterToZ", "[", "c_", "]"}], ":=", RowBox[{"2", "^", RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{"c", " ", "-", " ", "maxIndex"}], ")"}], " ", "/", " ", RowBox[{"(", RowBox[{ RowBox[{"(", RowBox[{"maxIndex", "-", "1"}], ")"}], "/", RowBox[{"-", RowBox[{"Log2", "[", RowBox[{"specialNear", "/", "f"}], "]"}]}]}], ")"}]}], ")"}]}]}], "\[IndentingNewLine]"}]], "Input", CellChangeTimes->{{3.650826437483921*^9, 3.650826439513567*^9}, { 3.650826503273473*^9, 3.650826510339241*^9}}] }, Open ]] }, WindowSize->{1156, 1502}, WindowMargins->{{Automatic, 549}, {Automatic, 0}}, FrontEndVersion->"10.0 for Mac OS X x86 (32-bit, 64-bit Kernel) (September 9, \ 2014)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[558, 20, 528, 9, 199, "Text"], Cell[CellGroupData[{ Cell[1111, 33, 205, 5, 86, "Subtitle"], Cell[1319, 40, 118, 2, 28, "Input"], Cell[1440, 44, 6288, 135, 369, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[7765, 184, 338, 8, 124, "Subtitle"], Cell[CellGroupData[{ Cell[8128, 196, 1338, 32, 46, "Input"], Cell[9469, 230, 3802, 74, 663, "Output"] }, Open ]], Cell[13286, 307, 842, 18, 114, "Text"], Cell[CellGroupData[{ Cell[14153, 329, 495, 12, 28, "Input"], Cell[14651, 343, 4696, 92, 655, "Output"] }, Open ]], Cell[19362, 438, 860, 13, 247, "Text"], Cell[CellGroupData[{ Cell[20247, 455, 1466, 33, 63, "Input"], Cell[21716, 490, 538, 7, 28, "Output"], Cell[22257, 499, 7298, 126, 656, "Output"] }, Open ]], Cell[29570, 628, 185, 4, 120, "Text"], Cell[29758, 634, 624, 18, 46, "Input"] }, Open ]] } ] *) (* End of internal cache information *)