Files
filament/docs/math/Cook-Torrance Visibility Term Approximation.nb
2018-08-03 10:38:22 -07:00

346 lines
13 KiB
Mathematica

(* 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[ 13434, 336]
NotebookOptionsPosition[ 12675, 306]
NotebookOutlinePosition[ 13036, 322]
CellTagsIndexPosition[ 12993, 319]
WindowFrame->Normal*)
(* Beginning of Notebook Content *)
Notebook[{
Cell[TextData[{
StyleBox["Visibility Term Approximation\n", "Title"],
StyleBox["\nThis document explores a possible approximation of the \
Visibility term in the Cook-Torrance specular BRDF. The approximation is \
based on the height-correlated Smith-GGX term, as described by Eric Heitz.\n",
"Text"]
}], "Text",
CellChangeTimes->{{3.6615351419804153`*^9, 3.6615352592223577`*^9}, {
3.6615353145525846`*^9, 3.661535317120723*^9}}],
Cell[TextData[StyleBox["Visibility terms", "Subtitle"]], "Text",
CellChangeTimes->{{3.66153530469643*^9, 3.6615353376561317`*^9}, {
3.661535367821847*^9, 3.661535396830717*^9}, 3.6615357854763317`*^9}],
Cell[CellGroupData[{
Cell["Original Smith-GGX", "Subsubsection",
CellChangeTimes->{{3.661535850009481*^9, 3.6615358622830143`*^9}}],
Cell[BoxData[
FormBox[
FractionBox["0.5",
RowBox[{
RowBox[{
RowBox[{"n", ".", "v"}], " ",
SqrtBox[
RowBox[{
SuperscriptBox["\[Alpha]", "2"], "+",
RowBox[{
RowBox[{"(",
RowBox[{"1", "-",
SuperscriptBox["\[Alpha]", "2"]}], ")"}], " ",
RowBox[{"n", ".",
SuperscriptBox["l", "2"]}]}]}]]}], "+",
RowBox[{
RowBox[{"n", ".", "l"}], " ",
SqrtBox[
RowBox[{
SuperscriptBox["\[Alpha]", "2"], "+",
RowBox[{
RowBox[{"(",
RowBox[{"1", "-",
SuperscriptBox["\[Alpha]", "2"]}], ")"}], " ",
RowBox[{"n", ".",
SuperscriptBox["v", "2"]}]}]}]]}]}]], TraditionalForm]], "Input",
CellChangeTimes->{{3.661535760198711*^9, 3.66153577060645*^9},
3.661535840346109*^9}],
Cell[BoxData[
RowBox[{
RowBox[{
RowBox[{"VSmithGGX", "[",
RowBox[{"NoV_", ",", " ", "NoL_", ",", " ", "Roughness_"}], "]"}], ":=",
RowBox[{
RowBox[{"{", "\[IndentingNewLine]",
RowBox[{
RowBox[{"alpha", "=",
RowBox[{"Roughness", "^", "2"}]}], ";", "\[IndentingNewLine]",
RowBox[{"GGXV", "=",
RowBox[{"NoL", "*",
RowBox[{"Sqrt", "[",
RowBox[{
RowBox[{"NoV", "*", "NoV", "*",
RowBox[{"(",
RowBox[{"1", "-", "alpha"}], ")"}]}], "+", "alpha"}], "]"}]}]}],
";", "\[IndentingNewLine]",
RowBox[{"GGXL", "=",
RowBox[{"NoV", "*",
RowBox[{"Sqrt", "[",
RowBox[{
RowBox[{"NoL", "*", "NoL", "*",
RowBox[{"(",
RowBox[{"1", "-", "alpha"}], ")"}]}], "+", "alpha"}], "]"}]}]}],
";", "\[IndentingNewLine]",
RowBox[{"0.5", "/",
RowBox[{"(",
RowBox[{"GGXV", "+", "GGXL"}], ")"}]}]}], "\[IndentingNewLine]",
"}"}], "[",
RowBox[{"[", "1", "]"}], "]"}]}], "\[IndentingNewLine]"}]], "Input",
CellChangeTimes->{{3.661313418094631*^9, 3.661313438222308*^9}, {
3.661313481408926*^9, 3.661313550251441*^9}, {3.661313590980237*^9,
3.6613137113129377`*^9}, {3.661313758940401*^9, 3.6613141017988863`*^9},
3.661314193782247*^9, {3.6613142962434*^9, 3.661314304866146*^9}, {
3.661314335797185*^9, 3.661314429452845*^9}, {3.661314669067534*^9,
3.6613147412618523`*^9}, {3.661314808465487*^9, 3.661314809192499*^9}, {
3.661314842741387*^9, 3.6613148684596577`*^9}, {3.66153512954902*^9,
3.661535130808758*^9}, 3.661535251895443*^9, 3.661535380694508*^9, {
3.661535570341879*^9, 3.66153558587108*^9}}]
}, Open ]],
Cell[CellGroupData[{
Cell["Approximated Smith-GGX", "Subsubsection",
CellChangeTimes->{{3.661535850009481*^9, 3.661535871258915*^9}}],
Cell[BoxData[
FormBox[
FractionBox["0.5",
RowBox[{
RowBox[{
RowBox[{"n", ".", "l"}], " ",
RowBox[{"(",
RowBox[{"\[Alpha]", "+",
RowBox[{
RowBox[{"(",
RowBox[{"1", "-", "\[Alpha]"}], ")"}], " ",
RowBox[{"n", ".", "v"}]}]}], ")"}]}], "+",
RowBox[{
RowBox[{"n", ".", "v"}], " ",
RowBox[{"(",
RowBox[{"\[Alpha]", "+",
RowBox[{
RowBox[{"(",
RowBox[{"1", "-", "\[Alpha]"}], ")"}], " ",
RowBox[{"n", ".", "l"}]}]}], ")"}]}]}]], TraditionalForm]], "Input",
CellChangeTimes->{{3.6615355932711077`*^9, 3.661535601491132*^9}, {
3.661535659503067*^9, 3.6615356612060738`*^9}}],
Cell[BoxData[
RowBox[{
RowBox[{"VSmithGGXApprox", "[",
RowBox[{"NoV_", ",", " ", "NoL_", ",", " ", "Roughness_"}], "]"}], ":=",
RowBox[{
RowBox[{"{", "\[IndentingNewLine]",
RowBox[{
RowBox[{"alpha", "=", "Roughness"}], ";", "\[IndentingNewLine]",
RowBox[{"GGXV", "=",
RowBox[{"NoL", "*",
RowBox[{"(",
RowBox[{
RowBox[{"NoV", "*",
RowBox[{"(",
RowBox[{"1", "-", "alpha"}], ")"}]}], "+", "alpha"}], ")"}]}]}],
";", "\[IndentingNewLine]",
RowBox[{"GGXL", "=",
RowBox[{"NoV", "*",
RowBox[{"(",
RowBox[{
RowBox[{"NoL", "*",
RowBox[{"(",
RowBox[{"1", "-", "alpha"}], ")"}]}], "+", "alpha"}], ")"}]}]}],
";", "\[IndentingNewLine]",
RowBox[{"0.5", "/",
RowBox[{"(",
RowBox[{"GGXV", "+", "GGXL"}], ")"}]}]}], "\[IndentingNewLine]", "}"}],
"[",
RowBox[{"[", "1", "]"}], "]"}]}]], "Input",
CellChangeTimes->{{3.661313418094631*^9, 3.661313438222308*^9}, {
3.661313481408926*^9, 3.661313550251441*^9}, {3.661313590980237*^9,
3.6613137113129377`*^9}, {3.661313758940401*^9, 3.6613141017988863`*^9},
3.661314193782247*^9, {3.6613142962434*^9, 3.661314304866146*^9}, {
3.661314335797185*^9, 3.661314429452845*^9}, {3.661314669067534*^9,
3.6613147412618523`*^9}, {3.661314808465487*^9, 3.661314809192499*^9}, {
3.661314842741387*^9, 3.6613148684596577`*^9}, {3.66153512954902*^9,
3.661535130808758*^9}, 3.661535251895443*^9, 3.661535380694508*^9, {
3.661535570341879*^9, 3.66153558587108*^9}}],
Cell[TextData[StyleBox["\nComparison", "Subtitle"]], "Text",
CellChangeTimes->{{3.66153530469643*^9, 3.6615353376561317`*^9}, {
3.661535367821847*^9, 3.661535406133431*^9}}],
Cell[CellGroupData[{
Cell[BoxData[
RowBox[{"Manipulate", "[", "\[IndentingNewLine]",
RowBox[{
RowBox[{"Plot3D", "[", "\[IndentingNewLine]",
RowBox[{
RowBox[{"{", "\[IndentingNewLine]",
RowBox[{
RowBox[{"VSmithGGXApprox", "[",
RowBox[{"NoV", ",", "NoL", ",", "Roughness"}], "]"}], ",",
"\[IndentingNewLine]",
RowBox[{"VSmithGGX", "[",
RowBox[{"NoV", ",", "NoL", ",", "Roughness"}], "]"}], ",",
"\[IndentingNewLine]",
RowBox[{"Abs", "[",
RowBox[{
RowBox[{"VSmithGGX", "[",
RowBox[{"NoV", ",", "NoL", ",", "Roughness"}], "]"}], "-",
RowBox[{"VSmithGGXApprox", "[",
RowBox[{"NoV", ",", "NoL", ",", "Roughness"}], "]"}]}], "]"}]}],
"\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", " ",
RowBox[{"{",
RowBox[{"NoV", ",", "1*^-5", ",", "1"}], "}"}], ",",
RowBox[{"{",
RowBox[{"Roughness", ",",
RowBox[{"0.045", "^", "2"}], ",", "1"}], "}"}], ",",
"\[IndentingNewLine]",
RowBox[{"PlotRange", "\[Rule]",
RowBox[{"{",
RowBox[{"0", ",", "5"}], "}"}]}], ",",
RowBox[{"AxesLabel", "\[Rule]",
RowBox[{"{",
RowBox[{
"\"\<View angle\>\"", ",", "\"\<Linear roughness\>\"", ",",
"\"\<Energy\>\""}], "}"}]}], ",", " ",
RowBox[{"ImageSize", "\[Rule]", "600"}], ",", "\[IndentingNewLine]",
RowBox[{"PlotLegends", "\[Rule]",
RowBox[{"{",
RowBox[{
"\"\<Approximation\>\"", ",", " ", "\"\<Smith-GGX\>\"", ",", " ",
"\"\<Difference\>\""}], "}"}]}], ",",
RowBox[{"PlotTheme", "->", "\"\<Scientific\>\""}]}],
"\[IndentingNewLine]", "]"}], ",", "\[IndentingNewLine]",
RowBox[{"{",
RowBox[{"NoL", ",", " ", "0", ",", " ", "1"}], "}"}]}],
"\[IndentingNewLine]", "]"}]], "Input",
CellChangeTimes->{{3.661313418094631*^9, 3.661313438222308*^9}, {
3.661313481408926*^9, 3.661313550251441*^9}, {3.661313590980237*^9,
3.6613137113129377`*^9}, {3.661313758940401*^9, 3.6613141017988863`*^9},
3.661314193782247*^9, {3.6613142962434*^9, 3.661314304866146*^9}, {
3.661314335797185*^9, 3.661314429452845*^9}, {3.661314669067534*^9,
3.6613147412618523`*^9}, {3.661314808465487*^9, 3.661314809192499*^9}, {
3.661314842741387*^9, 3.6613149461137123`*^9}, {3.661314983735495*^9,
3.661314998474061*^9}, {3.661315032162232*^9, 3.661315058873827*^9}, {
3.66131509242588*^9, 3.66131521136663*^9}, {3.661315276276545*^9,
3.6613152834032507`*^9}, {3.6613153216756268`*^9, 3.661315405369698*^9}, {
3.661315462698217*^9, 3.661315508264003*^9}, {3.661315554854945*^9,
3.6613155584131737`*^9}, 3.6613156820678*^9, 3.6613157292052097`*^9, {
3.66131586445359*^9, 3.6613158798440742`*^9}, {3.661315982085414*^9,
3.661316052040032*^9}, {3.6613161440483713`*^9, 3.661316182952342*^9}, {
3.661316240639305*^9, 3.661316384970601*^9}, {3.661316425867447*^9,
3.661316494985173*^9}, {3.6613165620665903`*^9, 3.661316607244238*^9}, {
3.661535063572671*^9, 3.661535076136299*^9}, {3.6615353928638372`*^9,
3.6615354108315*^9}}],
Cell[BoxData[
TagBox[
StyleBox[
DynamicModuleBox[{$CellContext`NoL$$ = 0.406, Typeset`show$$ = True,
Typeset`bookmarkList$$ = {}, Typeset`bookmarkMode$$ = "Menu",
Typeset`animator$$, Typeset`animvar$$ = 1, Typeset`name$$ =
"\"untitled\"", Typeset`specs$$ = {{
Hold[$CellContext`NoL$$], 0, 1}}, Typeset`size$$ = {717., {210., 214.}},
Typeset`update$$ = 0, Typeset`initDone$$, Typeset`skipInitDone$$ =
True, $CellContext`NoL$2891$$ = 0},
DynamicBox[Manipulate`ManipulateBoxes[
1, StandardForm, "Variables" :> {$CellContext`NoL$$ = 0},
"ControllerVariables" :> {
Hold[$CellContext`NoL$$, $CellContext`NoL$2891$$, 0]},
"OtherVariables" :> {
Typeset`show$$, Typeset`bookmarkList$$, Typeset`bookmarkMode$$,
Typeset`animator$$, Typeset`animvar$$, Typeset`name$$,
Typeset`specs$$, Typeset`size$$, Typeset`update$$, Typeset`initDone$$,
Typeset`skipInitDone$$}, "Body" :> Plot3D[{
$CellContext`VSmithGGXApprox[$CellContext`NoV, $CellContext`NoL$$, \
$CellContext`Roughness],
$CellContext`VSmithGGX[$CellContext`NoV, $CellContext`NoL$$, \
$CellContext`Roughness],
Abs[$CellContext`VSmithGGX[$CellContext`NoV, $CellContext`NoL$$, \
$CellContext`Roughness] - $CellContext`VSmithGGXApprox[$CellContext`NoV, \
$CellContext`NoL$$, $CellContext`Roughness]]}, {$CellContext`NoV,
Rational[1, 100000], 1}, {$CellContext`Roughness, 0.045^2, 1},
PlotRange -> {0, 5},
AxesLabel -> {"View angle", "Linear roughness", "Energy"}, ImageSize ->
600, PlotLegends -> {"Approximation", "Smith-GGX", "Difference"},
PlotTheme -> "Scientific"],
"Specifications" :> {{$CellContext`NoL$$, 0, 1}}, "Options" :> {},
"DefaultOptions" :> {}],
ImageSizeCache->{762., {254., 259.}},
SingleEvaluation->True],
Deinitialization:>None,
DynamicModuleValues:>{},
SynchronousInitialization->True,
UndoTrackedVariables:>{Typeset`show$$, Typeset`bookmarkMode$$},
UnsavedVariables:>{Typeset`initDone$$},
UntrackedVariables:>{Typeset`size$$}], "Manipulate",
Deployed->True,
StripOnInput->False],
Manipulate`InterpretManipulate[1]]], "Output",
CellChangeTimes->{
3.661314998979829*^9, {3.661315037748357*^9, 3.661315059190486*^9}, {
3.6613150929739847`*^9, 3.6613151380162363`*^9}, {3.661315182728285*^9,
3.661315211728109*^9}, {3.661315276891983*^9, 3.661315283875349*^9}, {
3.661315324531444*^9, 3.66131540607133*^9}, {3.661315465943255*^9,
3.661315508656872*^9}, 3.66131555949336*^9, 3.6613156832157793`*^9,
3.661315729729001*^9, {3.6613158689106073`*^9, 3.661315880440716*^9}, {
3.661316012665244*^9, 3.661316052430064*^9}, {3.661316151223015*^9,
3.661316183294506*^9}, {3.661316241994124*^9, 3.661316352510357*^9},
3.6613163857988253`*^9, {3.661316432423267*^9, 3.661316495658182*^9}, {
3.661316567903679*^9, 3.661316608424966*^9}, {3.661535058827959*^9,
3.661535076612762*^9}}]
}, Open ]]
}, Open ]]
},
WindowSize->{1054, 1348},
WindowMargins->{{Automatic, 709}, {Automatic, 64}},
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, 438, 8, 142, "Text"],
Cell[999, 30, 205, 2, 43, "Text"],
Cell[CellGroupData[{
Cell[1229, 36, 111, 1, 35, "Subsubsection"],
Cell[1343, 39, 823, 27, 62, "Input"],
Cell[2169, 68, 1720, 39, 131, "Input"]
}, Open ]],
Cell[CellGroupData[{
Cell[3926, 112, 113, 1, 35, "Subsubsection"],
Cell[4042, 115, 689, 21, 52, "Input"],
Cell[4734, 138, 1594, 37, 114, "Input"],
Cell[6331, 177, 176, 2, 75, "Text"],
Cell[CellGroupData[{
Cell[6532, 183, 3110, 62, 233, "Input"],
Cell[9645, 247, 3002, 55, 530, "Output"]
}, Open ]]
}, Open ]]
}
]
*)
(* End of internal cache information *)