Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 6986de75f6e996835c622ea8eafbf38c > files > 51

Pixie-docs-2.2.6-4.fc15.i686.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<meta name="robots" content="noindex,follow" />
		<meta name="keywords" content="Tutorials/BakeToTexture" />
		<link rel="shortcut icon" href="../favicon.ico" />
		<link rel="search" type="application/opensearchdescription+xml" href="/pixiewiki_install/opensearch_desc.php" title="PixieWiki (English)" />
		<title>Tutorials/BakeToTexture - PixieWiki</title>
		<style type="text/css" media="screen,projection">/*<![CDATA[*/ @import "../css/main.css?63"; /*]]>*/</style>
		<link rel="stylesheet" type="text/css"  href="../css/commonPrint.css?63" />
		<link rel="stylesheet" type="text/css" media="handheld" href="../css/handheld.css?63" />
		<!--[if lt IE 5.5000]><style type="text/css">@import "../css/IE50Fixes.css?63";</style><![endif]-->
		<!--[if IE 5.5000]><style type="text/css">@import "../css/IE55Fixes.css?63";</style><![endif]-->
		<!--[if IE 6]><style type="text/css">@import "../css/IE60Fixes.css?63";</style><![endif]-->
		<!--[if IE 7]><style type="text/css">@import "../css/IE70Fixes.css?63";</style><![endif]-->
		<!--[if lt IE 7]><script type="text/javascript" src="../css/IEFixes.js?63"></script>
		<meta http-equiv="imagetoolbar" content="no" /><![endif]-->
		
		<script type= "text/javascript">/*<![CDATA[*/
var skin = "monobook";
var stylepath = "../css/";
var wgArticlePath = "/pixiewiki/$1";
var wgScriptPath = "/pixiewiki_install";
var wgServer = "http://www.george-graphics.co.uk";
var wgCanonicalNamespace = "";
var wgCanonicalSpecialPageName = false;
var wgNamespaceNumber = 0;
var wgPageName = "Tutorials/BakeToTexture";
var wgTitle = "Tutorials/BakeToTexture";
var wgAction = "view";
var wgArticleId = "1646";
var wgIsArticle = true;
var wgUserName = null;
var wgUserGroups = null;
var wgUserLanguage = "en";
var wgContentLanguage = "en";
var wgBreakFrames = false;
var wgCurRevisionId = "2809";
/*]]>*/</script>
                
		<script type="text/javascript" src="../css/wikibits.js?63"><!-- wikibits js --></script>
		<script type="text/javascript" src="../css/WikiExtraJs.js"><!-- site js --></script>
		<style type="text/css">/*<![CDATA[*/
@import "../css/MediaWiki_Common.css";
@import "../css/MediaWiki_Monobook.css";
@import "../css/WikiExtraCss.css";
/*]]>*/</style>
		<!-- Head Scripts -->
	</head>
<body  class="mediawiki ns-0 ltr page-Tutorials_BakeToTexture">
 <div id="titleBar"></div>
	<div id="globalWrapper">
		<div id="column-content">
	<div id="content">
		<a name="contentTop" id="top"></a>
				<h1 class="firstHeading">Tutorials/BakeToTexture</h1>
		<div id="bodyContent">
			<h3 id="siteSub">From PixieWiki</h3>
			<div id="contentSub"><span class="subpages">&lt; <a href="../Tutorials.html" title="Tutorials">Tutorials</a></span></div>
									<div id="jump-to-nav">Jump to: <a href="#column-one">navigation</a>, <a href="#searchInput">search</a></div>			<!-- start content -->
			<p>The new 3D Baking support in Pixie can be leveraged to produce traditional textures - you can bake the results of a Pixie render back into a texture.
</p><p>In order to do this, your object must have a valid <tt>s,t</tt> mapping (ie a UV mapping from your modelling package).  This is especially important for polygon and subdivision surface meshes.
</p><p>Baking works in the following way:
</p>
<ul><li> The surface shader for each object you wish to bake is augmented with a <tt>bake3d()</tt> call to save out the result of shading.
</li><li> This produces a point cloud
</li><li> This point cloud is used in a second render to produce the texture
</li><li> You can optionally prepare a brickmap / 3d texture from the point cloud to speed the texture production, and allow more agressive blurring.
</li></ul>
<a name="Augmenting_your_shader_to_bake"></a><h1><span class="editsection">[<a href="/pixiewiki_install/index.php?title=Tutorials/BakeToTexture&amp;action=edit&amp;section=1" title="Edit section: Augmenting your shader to bake">edit</a>]</span> <span class="mw-headline"> Augmenting your shader to bake </span></h1>
<p>In this example, the standard mirror shader is modified to support baking.  The concept however can be applied to any shader.  Basically there are two modifications:
</p>
<ul><li> Add a parameter to specify the name of the pointcloud to bake the result to
</li><li> Add the <tt>bake3d()</tt> shadeop to the shader.
</li></ul>
<p>Original shader:
</p>
<pre>surface mirror(float Ka=1,Ks=1,Kr=1,roughness=.1,samples=1,blur=0; string texname="raytrace") {
    normal Nf;

    N = normalize(N);
    I = normalize(I);

    Nf = faceforward(N,I);

	// raytrace will convert to worldspace, but non-raytrace
	// environments should be looked up in world space
	vector R = reflect(I,Nf);
	if( texname&nbsp;!= "raytrace" ) R = ntransform("world",R);
	
    Oi = Os;
    Ci = Os * (Cs * ( Ka*ambient() + Ks*specular(Nf,-I,roughness) ) +
              Kr*environment(texname,R,"samples",samples,"blur",blur));
}
</pre>
<p>Modified shader:
</p>
<pre>surface mirror<b>_bake</b>(float Ka=1,Ks=1,Kr=1,roughness=.1,samples=1,blur=0; string texname="raytrace";
   <b>string pointcloudname = "";</b>
 ) {
    normal Nf;

    N = normalize(N);
    I = normalize(I);

    Nf = faceforward(N,I);

	// raytrace will convert to worldspace, but non-raytrace
	// environments should be looked up in world space
	vector R = reflect(I,Nf);
	if( texname&nbsp;!= "raytrace" ) R = ntransform("world",R);
	
    Oi = Os;
    Ci = Os * (Cs * ( Ka*ambient() + Ks*specular(Nf,-I,roughness) ) +
              Kr*environment(texname,R,"samples",samples,"blur",blur));

    <b>point Pbake = point(s,t,0);
    bake3d(pointcloudname, "BakeCol", Pbake, normal(0), "coordsystem", "current",  "BakeCol", Ci);</b>
}
</pre>
<p>Here, we are preparing the point to bake as <tt>point(s,t,0)</tt>.  This is important, as it means that we store the shading points in a space which matches your UV mapping.  Normally, you would simply use <tt>P</tt> here, but we want to be able to unwrap the mapping.
</p><p>The data is baked with no normal (as volume data) - which we specify with the <tt>normal(0)</tt> parameter to <tt>bake3d()</tt>.  We do this to avoid some of the points facing away from the surface which we later use to reconstruct the texture.
</p><p>Finally, and very importantly, the bake is done into the <tt>"current"</tt> coordinate system, as specified by adding <tt>..."coordsystem", "current"...</tt> before the data parameters to <tt>bake3d</tt>.  Normally we would bake into the default world coordinate system (or perhaps the object coordinate system), but this would require that the system matches when we read back the point cloud.  For the technique shown here, the coordinate systems will not match, so we must bake the data with no transform at all - as specified by the "current" coordinate system.
</p>
<a name="Preparing_your_baking_RIB"></a><h1><span class="editsection">[<a href="/pixiewiki_install/index.php?title=Tutorials/BakeToTexture&amp;action=edit&amp;section=2" title="Edit section: Preparing your baking RIB">edit</a>]</span> <span class="mw-headline"> Preparing your baking RIB </span></h1>
<p>For baking to work your rib must include a definition of the channel used for baking (<tt>BakeCol</tt> in this example).  The following line is added before WorldBegin:
</p>
<pre>DisplayChannel "varying color BakeCol"
</pre>
<p>The objects you wish to bake must have a number of attributes set, and and the augmented shader assigned
</p>
<pre>Surface "mirror_bake" "pointcloudname" "myobject.ptc"
 
Attribute "dice" "rasterorient" 0
Attribute "cull" "backfacing" 0
Attribute "cull" "hidden" 0
Attribute "dice" "binary" 1
ShadingRate 0.5
</pre>
<p>The attributes we set have important roles for baking:
</p>
<ul><li> <tt>Attribute "dice" "rasterorient" 0</tt> means that dicing of the grids is done in a view-independant manner, meaning that the grid size is more even for your baked object
</li><li> <tt>Attribute "cull" "backfacing" 0</tt> means that we draw the reverse faces of objects with respect to the camera - otherwise they are not shaded, and we do not get baked data for them
</li><li> <tt>Attribute "cull" "hidden" 0</tt> tells Pixie not to cull hidden (occluded) parts of your object, allowing them to be shaded, and the data baked
</li></ul>
<p>The shading rate is increased from the default to illustrate that you can increase the accuracy of the baking (by increasing the density of the point cloud) without moving the camera.
</p><p>When this render completes, "myobject.ptc" is saved out.  It will contain a 'flat' pointcloud.  Here is such a point cloud for another render:
</p>
<div class="center"><div class="floatnone"><span><a href="images/Bake2DPointCloud.png" class="image" title="Baked '2D' point cloud as shown by show"><img alt="Baked '2D' point cloud as shown by show" longdesc="images/Bake2DPointCloud.png" src="../images/Bake2DPointCloud.png" width="606" height="444" /></a></span></div></div>
<a name="Creating_a_Texture"></a><h1><span class="editsection">[<a href="/pixiewiki_install/index.php?title=Tutorials/BakeToTexture&amp;action=edit&amp;section=3" title="Edit section: Creating a Texture">edit</a>]</span> <span class="mw-headline"> Creating a Texture </span></h1>
<p>The trick to creating a texture from this is to use Pixie to render a flat polygon over the whole of the view.  The polygon will have a special shader attached to read the point cloud back.
</p><p>Here is an outline rib:
</p>
<pre>FrameBegin 1

DisplayChannel "varying color Col1"
Display "2DBake.tif" "file" "rgb"
Display "+2DBake.tif" "framebuffer" "rgba"

Format 1024 1024 1					# Set the size of the produced texture

PixelSamples 2 2						# Set the image filtering
PixelFilter "gaussian" 2 2
ShadingInterpolation "smooth"

Projection "orthographic"
	WorldBegin
	Sides 2
	AttributeBegin
	Color [ 1 1 1 ]
	Surface "read2dbm"			# The  read-back shader
	   "pointcloudname" "myobject.ptc"	# change this to the object's baked pointcloud
	   "bluramt" 0.3				# allows blurring to be controlled
				
	Translate 0 0 0.02
	Polygon "P" [ -1 -1 0   1 -1 0   1 1 0  -1 1 0 ]
		"st" [ 0 0  1 0  1 1  0 1  ]
    AttributeEnd
  WorldEnd
FrameEnd
</pre>
<p>The <tt>read3dbm</tt> shader is very simple.  It looks like this:
</p><p><br />
</p>
<pre> surface read2dbm(string pointcloudname = "ii.ptc"; float bluramt = 0)
   {
       point Pbake = point(s,t,0);
       texture3d(pointcloudname, Pbake, normal(0),"coordsystem", "current", "radiusscale",1+bluramt, "BakeCol", Ci);
		
        Oi = Os;
    }
</pre>
<p>Here, we simply read back the pointcloud - or brickmap if you had converted it to one (which you would want to to if large blurs were needed).  The result is used to directly color the polygon (no lighting is used).
</p><p>Here is a baked texture which is from a modified paintedplastic shader (so it includes lighting).
</p>
<div class="center"><div class="floatnone"><span><a href="images/2DBake.png" class="image" title="Baked image with artifacts"><img alt="Baked image with artifacts" longdesc="images/2DBake.png" src="../images/2DBake.png" width="512" height="512" /></a></span></div></div>
<p>Note that there are some illustrative artifacts in this example.  The texture was baked from a nurbs sphere, which means it has extreme pinching at the poles.  These gaps can be removed by increasing the shading rate (making it a smaller number).  The come from places in the <tt>st</tt> space that Pixie did not need to shade.  There are also some artifacts where the normal flips due to the use of <tt>faceforward</tt> in the shader.  These are things to bear in mind when writing a shader for baking.
</p><p>A slightly higher shading rate and fractionally more blur gives better results:
</p>
<div class="center"><div class="floatnone"><span><a href="images/2DBakeBetter.png" class="image" title="Better results"><img alt="Better results" longdesc="images/2DBakeBetter.png" src="../images/2DBakeBetter.png" width="512" height="512" /></a></span></div></div>

<!-- Saved in parser cache with key georgeg_pixiewikidb:pcache:idhash:1646-0!1!0!!en!2 and timestamp 20071121222943 -->
<div class="printfooter">
Retrieved from "<a href="http://www.george-graphics.co.uk/pixiewiki/Tutorials/BakeToTexture">http://www.george-graphics.co.uk/pixiewiki/Tutorials/BakeToTexture</a>"</div>
						<!-- end content -->
			<div class="visualClear"></div>
		</div>
	</div>
		</div>
		<div id="column-one">
	<div id="p-cactions" class="portlet">
		<h5>Views</h5>
		<div class="pBody">
			<ul>
					 <li id="ca-nstab-main" class="selected"><a href="../Tutorials/BakeToTexture.html" title="View the content page [c]" accesskey="c">Article</a></li>
					 <li id="ca-talk" class="new"><a href="/pixiewiki_install/index.php?title=Talk:Tutorials/BakeToTexture&amp;action=edit" title="Discussion about the content page [t]" accesskey="t">Discussion</a></li>
					 <li id="ca-edit"><a href="/pixiewiki_install/index.php?title=Tutorials/BakeToTexture&amp;action=edit" title="You can edit this page. Please use the preview button before saving. [e]" accesskey="e">Edit</a></li>
					 <li id="ca-history"><a href="/pixiewiki_install/index.php?title=Tutorials/BakeToTexture&amp;action=history" title="Past versions of this page. [h]" accesskey="h">History</a></li>
				</ul>
		</div>
	</div>
	<div class="portlet" id="p-personal">
		<h5>Personal tools</h5>
		<div class="pBody">
			<ul>
				<li id="pt-login"><a href="/pixiewiki_install/index.php?title=Special:Userlogin&amp;returnto=Tutorials/BakeToTexture" title="You are encouraged to log in, it is not mandatory however. [o]" accesskey="o">Log in / create account</a></li>
			</ul>
		</div>
	</div>
	<div class="portlet" id="p-logo">
		<a style="background-image: url(/pixiewiki_install/skins/common/images/wiki.png);" href="../NotIncludedStatic.html" title="Visit the Main Page [z]" accesskey="z"></a>
	</div>
	<script type="text/javascript"> if (window.isMSIE55) fixalpha(); </script>
		<div class='portlet' id='p-navigation'>
		<h5>Navigation</h5>
		<div class='pBody'>
			<ul>
				<li id="n-mainpage"><a href="../NotIncludedStatic.html" title="Visit the Main Page [z]" accesskey="z">Main Page</a></li>
				<li id="n-Documentation"><a href="../Documentation.html">Documentation</a></li>
				<li id="n-Examples"><a href="../NotIncludedStatic.html">Examples</a></li>
				<li id="n-Tutorials"><a href="../Tutorials.html">Tutorials</a></li>
				<li id="n-Sourceforge"><a href="http://pixie.sourceforge.net">Sourceforge</a></li>
				<li id="n-recentchanges"><a href="../NotSupportedStatic.html" title="The list of recent changes in the wiki. [r]" accesskey="r">Recent changes</a></li>
				<li id="n-help"><a href="../NotSupportedStatic.html" title="The place to find out.">Help</a></li>
			</ul>
		</div>
	</div>
		<div id="p-search" class="portlet">
		<h5><label for="searchInput">Search</label></h5>
		<div id="searchBody" class="pBody">
			<form action="../NotSupportedStatic.html" id="searchform"><div>
				<input id="searchInput" name="search" type="text" title="Search PixieWiki [f]" accesskey="f" value="" />
				<input type='submit' name="go" class="searchButton" id="searchGoButton"	value="Go" />&nbsp;
				<input type='submit' name="fulltext" class="searchButton" id="mw-searchButton" value="Search" />
			</div></form>
		</div>
	</div>
	<div class="portlet" id="p-tb">
		<h5>Toolbox</h5>
		<div class="pBody">
			<ul>
				<li id="t-whatlinkshere"><a href="../NotSupportedStatic.html" title="List of all wiki pages that link here [j]" accesskey="j">What links here</a></li>
				<li id="t-recentchangeslinked"><a href="../NotSupportedStatic.html" title="Recent changes in pages linked from this page [k]" accesskey="k">Related changes</a></li>
<li id="t-upload"><a href="../NotSupportedStatic.html" title="Upload images or media files [u]" accesskey="u">Upload file</a></li>
<li id="t-specialpages"><a href="../NotSupportedStatic.html" title="List of all special pages [q]" accesskey="q">Special pages</a></li>
				<li id="t-print"><a href="/pixiewiki_install/index.php?title=Tutorials/BakeToTexture&amp;printable=yes&amp;printable=yes">Printable version</a></li>				<li id="t-permalink"><a href="/pixiewiki_install/index.php?title=Tutorials/BakeToTexture&amp;oldid=2809">Permanent link</a></li>			</ul>
		</div>
	</div>
		</div><!-- end of the left (by default at least) column -->
			<div class="visualClear"></div>
			<div id="footer">
				<div id="f-poweredbyico"><a href="http://www.mediawiki.org/"><img src="../css/images/poweredby_mediawiki_88x31.png" alt="Powered by MediaWiki" /></a></div>
			<ul id="f-list">
				<li id="f-lastmod"> This page was last modified 11:07, 6 April 2007.</li>
				<li id="f-viewcount">This page has been accessed 2,381 times.</li>
				<li id="f-privacy"><a href="../NotSupportedStatic.html" title="PixieWiki:Privacy policy">Privacy policy</a></li>
				<li id="f-about"><a href="../NotSupportedStatic.html" title="PixieWiki:About">About PixieWiki</a></li>
				<li id="f-disclaimer"><a href="../NotSupportedStatic.html" title="PixieWiki:General disclaimer">Disclaimers</a></li>
			</ul>
		</div>
		
	
		<script type="text/javascript">if (window.runOnloadHook) runOnloadHook();</script>
</div>
<!-- Served by mercury.svr9-speedyservers.com in 0.346 secs. --></body></html>