1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
|
<!-- This file copyright Persistence of Vision Raytracer Pty. Ltd. 2003-2004 -->
<html>
<head>
<!-- NOTE: In order to users to help find information about POV-Ray using -->
<!-- web search engines, we ask you to *not* let them index documentation -->
<!-- mirrors because effectively, when searching, users will get hundreds -->
<!-- of results containing the same information! For this reason, the two -->
<!-- meta tags below disable archiving and indexing of this page by all -->
<!-- search engines that support these meta tags. -->
<meta content="noarchive" name="robots">
<meta content="noindex" name="robots">
<meta content="no-cache" http-equiv="Pragma">
<meta content="0" http-equiv="expires">
<title>2.4.9 Smooth triangle artifact</title>
<link href="povray35.css" rel="stylesheet" type="text/css">
</head>
<body>
<table class="NavBar" width="100%">
<tr>
<td align="left" nowrap="" valign="middle" width="32">
<a href="s_84.html"><img alt="previous" border="0" src="prev.png"></a>
</td>
<td align="left" valign="middle" width="30%">
<a href="s_84.html">2.4.8 The shadow line artifact</a>
</td>
<td align="center" valign="middle">
<strong class="NavBar">POV-Ray 3.6 for UNIX documentation</strong><br> <strong>2.4.9
Smooth triangle artifact</strong>
</td>
<td align="right" valign="middle" width="30%">
<a href="s_86.html">2.5 Appendices</a>
</td>
<td align="right" nowrap="" valign="middle" width="32">
<a href="s_86.html"><img alt="next" border="0" src="next.png"></a>
</td>
</tr>
</table>
<h3><a name="s02_04_09">2.4.9 </a>Smooth triangle artifact</h3>
<h4><a name="s02_04_09_01">2.4.9.1 </a>What is the problem?</h4>
<p>
There is a peculiar problem with smooth triangles which shows as a lighting artifact in certain cases. This can
happen in individual smooth triangles, meshes with smooth triangles and smooth heightfields. The problem also
manifests itself when using the slope pattern in the same situation. This image shows the two cases:
</p>
<p>
<img alt="Lighting and slope pattern artifacts in a smooth triangle" src="images/tutorial/startifacts.png">
</p>
<p>
The source code of this image is the following:
</p>
<pre>
camera { right x*4 location <0,1,-5> look_at 0 angle 35 }
light_source { y*100, 1 }
light_source { -y*100, x }
smooth_triangle
{ <-.5,0,-1>,<-1,1,-1>, <.5,0,-1>,<1,1,-1>, <0,0,1>,<0,1,1>
pigment { rgb 1 }
translate -x*.6
}
smooth_triangle
{ <-.5,0,-1>,<-1,1,-1>, <.5,0,-1>,<1,1,-1>, <0,0,1>,<0,1,1>
pigment { slope y color_map { [0 rgb z][1 rgb x+y] } }
finish { ambient 1 }
translate x*.6
}
</pre>
<p>
The triangle at the left is a regular smooth triangle which is illuminated by a white light source from above.
There is also a red light source illuminating the triangle from below. As you can see, the farther part of the
triangle is wrongly illuminated as red. No part of the triangle should be illuminated by the red light source because
the upper side of the triangle is nowhere facing down.
</p>
<p>
The triangle at the right is the same smooth triangle with a slope pattern applied to it, which goes from blue (in
the negative y direction) to yellow (in the positive y direction). Lighting has been eliminated by specifying a high
ambient. As all the parts of the upper side of the triangle are pointing upwards, the whole triangle should be colored
with shades of yellow, but as you can see, the same farther part is wrongly colored blue.
</p>
<p>
(If you guessed that the problem happens when the normal vector of the triangle is pointing away from the camera,
then you guessed right.)
</p>
<h4><a name="s02_04_09_02">2.4.9.2 </a>What causes the problem?</h4>
<p>
The problem is caused by the rendering algorithm used in POV-Ray. The following text is quite technical, so if you
just want to read about possible solutions to this problem, you can skip to the next subsection.
</p>
<p>
The problem is that the rendering engine assumes that objects return the <em>true</em> normal vector for the given
point in their surface. For an object to render correctly, it <em>must</em> give the exact normal vector (ie. a vector
which is exactly perpendicular to the surface at that point).
</p>
<p>
Smooth meshes and heightfields do not do this. They return normal vectors which are not perpendicular to the actual
surface. This causes errors in the rendering.
</p>
<p>
What happens is that when the rendering engine shoots a ray and it hits the surface of an object, the engine asks
the object "what is the normal vector at this point in your surface?". Now, if the angle between the
returned normal vector and the ray vector is less than 90 degrees (that is, the normal vector points away from the
point of view of the starting point of the ray), then the engine reverses the returned normal vector. This is
essential for the lighting to work properly (if the normal is not reversed in this case, you would get all kind of
errors in lighting, ie. surfaces which are illuminated from behind when they should not, or surface which are not
illuminated even though they are facing a light source).
</p>
<p>
This assumes that the normal vector returned by the object is a <em>true</em> normal vector, and it works perfectly
when this is so.
</p>
<p>
However, if the object returns an erroneous normal vector, ie. a vector which is not perpendicular to the surface,
rendering errors can occur.
</p>
<p>
Smooth triangles and heightfields do this, and the price to pay are the artifacts in the lighting in certain
situations.
</p>
<p>
The artifact is produced when the true normal vector would have an angle larger than 90 degrees with the ray, but
the the actual vector returned by the object has an angle smaller than 90 degrees with the ray. In this case the
rendering engine reverses the normal vector even though it should not. This is because it assumes that it is the true
normal vector when in fact it is not.
</p>
<p>
This problem could be solved by making the decision of inverting the returned normal vector according to the true
normal vector of the surface instead of the returned vector. However, due to the internal implementation of the
rendering engine in the current POV-Ray 3.5, doing this is not trivial. It may be fixed in POV-Ray 4.0, where the
rendering engine will be written again and this kind of things can be taken into account from the very beginning.
</p>
<h4><a name="s02_04_09_03">2.4.9.3 </a>Can this problem be solved?</h4>
<p>
You can get rid of the lighting artifact by applying <code>double_illuminate</code> to the object in question. When
a surface is double illuminated, it does not matter which way its normal points - it will always be illuminated
regardless of which side the light source is. Of course it should not matter that the object is now illuminated from
both sides. If this is a problem, then the problem is not easily solvable.
</p>
<p>
Note that in the example given at the beginning of this section this solution does not work: It would illuminate
the whole triangle with both light sources! However, this solution works well with closed triangle meshes, where the
inner side of the mesh is shadowed by the mesh itself. However, if you are using <code>no_shadow</code> in the object
(for example to get rid of <a href="s_84.html#s02_04_08">shadow line artifacts</a>), new problems can arise in the
lighting (such as bright parts in places where there should not be any; these are all cause by this same problem).
</p>
<p>
The slope pattern is more problematic and there is no generic solution which will work in all cases. Fortunately
the most common use of the slope pattern is in heightfields, and there a solution is possible:
</p>
<p>
If you are having this problem in a smooth heightfield, the solution is to mirror the color_map (or whatever map
you are using) around 0.5. This way it does not matter if the normal is reversed. That is, if you had something like
this in a heightfield:
</p>
<pre>
slope y color_map
{ [0.50 rgb <.5,.5,.5>] // rock
[0.75 rgb <.8,.4,.1>] // ground
[1.00 rgb <.4,1,.4>] // grass
}
</pre>
<p>
you simply have to mirror the map around 0.5, ie. add the values from 0 to 0.5 in reverse order:
</p>
<pre>
slope y color_map
{ [0.00 rgb <.4,1,.4>] // grass
[0.25 rgb <.8,.4,.1>] // ground
[0.50 rgb <.5,.5,.5>] // rock
[0.75 rgb <.8,.4,.1>] // ground
[1.00 rgb <.4,1,.4>] // grass
}
</pre>
<p>
Besides this you should, of course, apply <code>double_illuminate</code> to the heightfield in order to get the
proper lighting.
</p>
<br>
<table class="NavBar" width="100%">
<tr>
<td align="left" nowrap="" valign="middle" width="32">
<a href="s_84.html"><img alt="previous" border="0" src="prev.png"></a>
</td>
<td align="left" valign="middle" width="30%">
<a href="s_84.html">2.4.8 The shadow line artifact</a>
</td>
<td align="center" valign="middle">
<strong>2.4.9 Smooth triangle artifact</strong>
</td>
<td align="right" valign="middle" width="30%">
<a href="s_86.html">2.5 Appendices</a>
</td>
<td align="right" nowrap="" valign="middle" width="32">
<a href="s_86.html"><img alt="next" border="0" src="next.png"></a>
</td>
</tr>
</table>
</body> </html>
|