1. Jason McKesson
  2. gltut

Commits

Jason McKesson  committed 0bcbd7f

All Tutorial 10 images complete.

  • Participants
  • Parent commits 6bd0e78
  • Branches default

Comments (0)

Files changed (12)

File Documents/Illumination/Blinn Lighting.png

  • Ignore whitespace
Added
New image

File Documents/Illumination/Blinn vs Phong Compare.png

  • Ignore whitespace
Added
New image

File Documents/Illumination/Gaussian Small Highlight.png

  • Ignore whitespace
Added
New image

File Documents/Illumination/GaussianPlot.svg

View file
  • Ignore whitespace
Added
New image

File Documents/Illumination/GenGaussianPlot.lua

View file
  • Ignore whitespace
+require "SvgWriter"
+require "vmath"
+require "Viewport"
+require "SubImage"
+require "GridAxis"
+require "_utils"
+
+local subImages = SubImage.SubImage(1, 1, 600, 300, 0, 0);
+
+local coordWidth = 20;
+
+local vp = Viewport.Viewport({600, 300}, {0, 4}, coordWidth)
+local trans2 = Viewport.Transform2D()
+vp:SetTransform(trans2);
+
+
+local vectorColor = "black";
+local vectorSumColor = "red";
+local pointSize = 15;
+
+local styleLib = SvgWriter.StyleLibrary();
+
+styleLib:AddStyle(nil, "std_normal",
+	SvgWriter.Style():stroke("red"):fill("none"));
+
+styleLib:AddStyle(nil, "tall",
+	SvgWriter.Style():stroke("blue"):fill("none"));
+
+styleLib:AddStyle(nil, "short",
+	SvgWriter.Style():stroke("orange"):fill("none"));
+
+styleLib:AddStyle(nil, "label",
+	SvgWriter.Style():stroke("none"):fill(vectorColor):font_size("14pt"):font_family("monospace"):font_weight("bold"):text_anchor("middle") );
+
+styleLib:AddStyle(nil, "legend_text",
+	SvgWriter.Style():stroke("none"):fill(vectorColor):font_size("14pt"):font_family("monospace"):font_weight("bold") );
+
+styleLib:AddStyle(nil, "vertex", SvgWriter.Style():stroke("none"):fill("black"));
+
+--Generate axis data.
+local axisData = GridAxis.GridAxis2D(vp, nil, styleLib, true, nil);
+
+
+local plotScale = vmath.vec2(0.5, 8);
+
+local function MakeGaussianPath(sigmaSqr)
+	local path = SvgWriter.Path();
+	
+	local variance = 2 * sigmaSqr;
+	local constant = 1 / math.sqrt(variance * math.pi);
+	
+	local maxValue = 0;
+	
+	local function ComputeGauss(x)
+		x = plotScale[1] * x;
+		local x2 = x*x;
+		local expTerm = math.exp(-x2 / variance);
+		
+		if(maxValue < plotScale[2] * (constant * expTerm)) then
+			maxValue = plotScale[2] * (constant * expTerm);
+		end
+		return plotScale[2] * (constant * expTerm);
+	end
+	
+	local bFirst = true;
+	
+	for i = -coordWidth, coordWidth, 0.25 do
+		if(bFirst) then
+			path:M(vp:Transform(vmath.vec2(i, ComputeGauss(i))))
+			bFirst = false;
+		else
+			path:L(vp:Transform(vmath.vec2(i, ComputeGauss(i))))
+		end
+	end
+	
+	return path;
+end
+
+local distributions =
+{
+	{1, "std_normal"},
+	{0.2, "tall"},
+	{5, "short"},
+}
+
+local paths = {};
+for i=1, #distributions do
+	paths[i] = MakeGaussianPath(distributions[i][1]);
+end
+
+--Labels
+local horizontalLabels =
+{
+	{8, vmath.vec2(0, 20)},
+	{-8, vmath.vec2(0, 20)},
+	{16, vmath.vec2(0, 20)},
+	{-16, vmath.vec2(0, 20)},
+}
+
+local verticalLabels =
+{
+	{1.0, vmath.vec2(20, 5);}
+}
+
+--Legend
+local legendStart = vp:Transform(vmath.vec2(4.7, 7.5));
+local legendLineWidth = 35;
+local legendItemHeight = 30;
+local legendTextSpace = 10;
+local legendTextVertOffset = 5;
+
+local pointRadius = 4;
+local radiusPt = vmath.vec2(pointRadius, pointRadius);
+
+local writer = SvgWriter.SvgWriter(ConstructSVGName(arg[0]), {subImages:Size().x .."px", subImages:Size().y .. "px"});
+	writer:StyleLibrary(styleLib);
+	axisData:AddDefinitions(writer, "g_axes");
+	writer:BeginDefinitions();
+		writer:BeginGroup(nil, "g_point");
+			writer:Circle(vmath.vec2(0, 0), pointRadius, {"vertex"});
+		writer:EndGroup();
+	writer:EndDefinitions();
+
+
+	writer:Use("g_axes", subImages:Offset(1, 1), subImages:SubSize());
+	
+	for i=1, #distributions do
+		writer:Path(paths[i], {distributions[i][2]});
+	end
+	
+	for i=1, #horizontalLabels do
+		local point = vmath.vec2(horizontalLabels[i][1], 0);
+		point = point * plotScale;
+		point = vp:Transform(point);
+		writer:Use("g_point", point, radiusPt * 2);
+		writer:Text(tostring(horizontalLabels[i][1]), point + horizontalLabels[i][2], {"label"});
+	end
+	
+	for i=1, #verticalLabels do
+		local point = vmath.vec2(0, verticalLabels[i][1] * plotScale[2]);
+		point = vp:Transform(point);
+		writer:Use("g_point", point, radiusPt * 2);
+		writer:Text(tostring(verticalLabels[i][1]), point + verticalLabels[i][2], {"label"});
+	end
+	
+	for i=1, #distributions do
+		local point = legendStart + vmath.vec2(0, (i-1) * legendItemHeight);
+		writer:Line(point, point + vmath.vec2(legendLineWidth, 0), distributions[i][2]);
+		point = point + vmath.vec2(legendLineWidth + legendTextSpace, legendTextVertOffset);
+		writer:Text("&#x03C3; = ".. tostring(distributions[i][1]), point, {"legend_text"});
+	end
+	
+writer:Close();

File Documents/Illumination/Phong Clipping.png

  • Ignore whitespace
Added
New image

File Documents/Illumination/Phong Dark Diffuse.png

  • Ignore whitespace
Added
New image

File Documents/Illumination/Phong Distortion.png

  • Ignore whitespace
Added
New image

File Documents/Illumination/Phong Lighting.png

  • Ignore whitespace
Added
New image

File Documents/Illumination/Tutorial 10.xml

View file
  • Ignore whitespace
             <title>Drawing Phong</title>
             <para>The <phrase role="propername">Phong Lighting</phrase> tutorial demonstrates the
                 Phong specular model.</para>
-            <!--TODO: Show a picture of the tutorial.-->
+            <figure>
+                <title>Phong Lighting</title>
+                <mediaobject>
+                    <imageobject>
+                        <imagedata fileref="Phong%20Lighting.png"/>
+                    </imageobject>
+                </mediaobject>
+            </figure>
             <para>The tutorial is controlled similarly to previous lighting tutorials. The
                     <keycap>W</keycap>, <keycap>A</keycap>, <keycap>S</keycap>, and
                     <keycap>D</keycap> keys control the orientation of the cylinder. Pressing the
                 reasonable.</para>
             <para>In particular, it is interesting to note what happens when you use a very dark
                 diffuse color. You can activate this by pressing the <keycap>G</keycap> key.</para>
-            <!--TODO: Show dark diffuse color from the tutorial.-->
-            <para>If there was no specular term at all, you would a virtually scene. The specular
+            <figure>
+                <title>Phong with Dark Diffuse</title>
+                <mediaobject>
+                    <imageobject>
+                        <imagedata fileref="Phong%20Dark%20Diffuse.png"/>
+                    </imageobject>
+                </mediaobject>
+            </figure>
+            <para>If there was no specular term at all, you would see very little.. The specular
                 highlight, even with the fairly weak specular reflection of 0.25, is strong enough
                 to give some definition to the object when seen from various angles. This more
                 accurately shows what a black plastic object might look like.</para>
             <para>One thing you may notice is that, if you bring the light close to the surface, the
                 specular area tends to have very sharp edges.</para>
-            <!--TODO: Show a picture of the Phong clipping.-->
+            <figure>
+                <title>Phong Clipping</title>
+                <mediaobject>
+                    <imageobject>
+                        <imagedata fileref="Phong%20Clipping.png"/>
+                    </imageobject>
+                </mediaobject>
+            </figure>
             <para>This is part of the nature of specular reflections. If the light is almost
                 perpendicular to the surface, the specular reflection will shine brightest when the
                 light is almost eclipsed by the surface. This creates a strong discontinuity at the
                 having small exponents.</para>
             <para>If you drop the exponent down to the minimum value the code will allow, you will
                 see something like this:</para>
-            <!--TODO: show a picture of the Phong distortion.-->
+            <figure>
+                <title>Phong Distortion</title>
+                <mediaobject>
+                    <imageobject>
+                        <imagedata fileref="Phong%20Distortion.png"/>
+                    </imageobject>
+                </mediaobject>
+            </figure>
             <para>This ring area shows one of the main limitations of the Phong model. When trying
                 to depict a surface that is rough but still has specular highlights, the Phong model
                 starts to break down. It will not allow any specular contribution from areas outside
             So the Blinn specular model produces similar results to the Phong model, but without
             some of Phong's problems. This is demonstrated in the <phrase role="propername">Blinn vs
                 Phong Lighting</phrase> tutorial.</para>
-        <!--TODO: Show an image of Blinn from the tutorial.-->
+        <figure>
+            <title>Blinn Lighting</title>
+            <mediaobject>
+                <imageobject>
+                    <imagedata fileref="Blinn%20Lighting.png"/>
+                </imageobject>
+            </mediaobject>
+        </figure>
         <para>The controls are similar to the last tutorial. Pressing the <keycap>H</keycap> key
             will switch between Blinn and Phong specular. Pressing <keycombo>
                 <keycap>Shift</keycap>
             view direction vectors. As before, we take the dot product between that and the surface
             normal, clamp, then raise the result to a power.</para>
         <para>Blinn specular solves the Phong problem with the reflection direction.</para>
-        <!--TODO: Picture comparing Phong and Blinn with same light positions and low shininess.-->
+        <figure>
+            <title>Blinn vs. Phong Lighting</title>
+            <mediaobject>
+                <imageobject>
+                    <imagedata fileref="Blinn%20vs%20Phong%20Compare.png"/>
+                </imageobject>
+            </mediaobject>
+        </figure>
+        <para>The Blinn version is on the left, with the Phong version on the right.</para>
         <para>The Blinn specular exponent does not mean quite the same thing as the Phong exponent.
             In general, to produce a highlight the same size as a Phong one, you will need a larger
             Blinn exponent. Play around with the different exponents, to get a feel for what Blinn
                 </imageobject>
             </mediaobject>
         </equation>
-        <!--TODO: Picture of Gaussian curve.-->
+        <figure>
+            <title>Gaussian Probability Distribution Curves</title>
+            <mediaobject>
+                <imageobject>
+                    <imagedata fileref="GaussianPlot.svg" format="SVG"/>
+                </imageobject>
+            </mediaobject>
+        </figure>
         <para>This represents the percentage of the items in the distribution that satisfy the
             property that the X in the distribution is trying to model. The <literal>e</literal> in
             this equation is a common mathematical constant, equivalent to ~2.718. The value of
             <para>If you play around with the controls, you can see how much the Gaussian
                 distribution offers over Phong and Blinn. For example, set the Gaussian smoothness
                 value to 0.05.</para>
-            <!--TODO: Show a picture of a Gaussian highlight with smoothness at 0.05-->
+            <figure>
+                <title>Gaussian with Sharp Highlight</title>
+                <mediaobject>
+                    <imageobject>
+                        <imagedata fileref="Gaussian%20Small%20Highlight.png"/>
+                    </imageobject>
+                </mediaobject>
+            </figure>
             <para>It requires very large exponents, well in excess of 100, to match the small size
                 and focus of that specular highlight with Phong or Blinn. It takes even larger
                 exponents to match the Gaussian value of 0.02.</para>

File Documents/Tools/GridAxis.lua

View file
  • Ignore whitespace
 	writer:EndDefinitions();
 end
 
-function GridAxis2D(vp, axisStyle, styleLib, bGrid, gridStyle)
+function GridAxis2D(vp, axisStyle, styleLib, bGrid, gridStyle, gridScale)
 	assert(styleLib);
 	assert(vp);
 	
 	axisStyle = axisStyle or SvgWriter.Style():stroke("black"):fill("none"):stroke_width("2px");
 	gridStyle = gridStyle or SvgWriter.Style():stroke("#CCC"):fill("none"):stroke_width("1px");
+	gridScale = gridScale or 1.0;
 	
 	local axisGridObj = {};
 	axisGridObj.axisIndex = axisIndex;
 	arrowheadPath:M{10, 4}:L{0, 0}:L{0, 8}:Z();
 	axisGridObj.arrowheadPath = arrowheadPath;
 	
+	local viewportScale = vmath.vec2(vp:Size());
+	
 	--Create grid path, if needed.
 	if(bGrid) then
 		styleLib:AddStyle(nil, gridStyleName .. axisGridObj.axisIndex, gridStyle);
 		local gridPath = SvgWriter.Path();
 
 		--Vertical lines.
-		for i = lowerBound[1], upperBound[1] do
+		for i = lowerBound[1], upperBound[1], gridScale do
 			local points =
 			{
 				vmath.vec2(i, lowerBound[2]);
 		end
 
 		--Horizontal lines.
-		for i = lowerBound[2], upperBound[2] do
+		for i = lowerBound[2], upperBound[2], gridScale do
 			local points =
 			{
 				vmath.vec2(lowerBound[1], i);

File Documents/Tools/Viewport.lua

View file
  • Ignore whitespace
 	viewport.pixelSize = vmath.vec2(pixelSize);
 	viewport.vpOrigin = vmath.vec2(vpOrigin);
 	viewport.pxCenter = viewport.pixelSize / 2;
-	if(type(vpSize) == "number") then vpSize = vmath.vec2(vpSize, vpSize) end;
+	if(type(vpSize) == "number") then
+		vpSize = vmath.vec2(vpSize, vpSize * (pixelSize[2] / pixelSize[1]))
+	end;
 	viewport.vpSize = vmath.vec2(vpSize);
 	
 	local trans = Transform2D();