Unity Products:Amplify Impostors/Custom Baking and Unity Products:Amplify Impostors/Lightmap Baking: Difference between pages

From Amplify Creations Wiki
(Difference between pages)
Jump to navigation Jump to search
m (1 revision imported)
 
ampwiki>Kebrus
 
Line 2: Line 2:


== Introduction ==
== Introduction ==
The standard baker gathers the deferred GBuffer information that contains every material data for a typical PBR rendering. This, however, might not always be necessary or might not even be enough. In some cases the object you want to create the impostor for has some special realtime shader effect that a simple PBR rendering doesn't cover. In other cases you might just want to reduce the amount of data being generated because you have higher platform constraints (ie: mobile). The idea behind custom baking is allowing you to tell the tool what you want to bake and how you want to render it on a case by case scenario.


== Requirements ==
Due to high demand, as of version 0.9.5, you can now bake and render impostors with static Lightmap information. Be advise that, due to the static nature of lightmaps, doing this means all impostors sharing the same texture will also share the same light information. Making that light information different between similar impostor means baking different lightmaps to different objects which in turn increase the texture footprint of your application. If you use this feature it means you accept that trade-off when using multiple lightmapped impostors. This feature has some special uses cases, for instance, you might only want a impostor of a single static object that has baked lighting, or your multiple baked impostors might be sharing very similar lighting conditions in which case the different of objects would be neglectable.
Creating the shaders for this guide can become quite difficult so we have included in our package the necessary templates and node which can be used with Amplify Shader Editor plugin, making the process a lot easier and faster. If you are not familiar with it, Amplify Shader Editor is our own award winning shader editor in which you can create shaders in a node-based graph editor without knowing shader code. The guide assumes the use of Amplify Shader Editor so if you're interested in an intuitive node-based shader authoring tool feel free to check out its store page [https://assetstore.unity.com/packages/tools/visual-scripting/amplify-shader-editor-68570 here]. You can also know more about it in its wiki page [[Unity_Products:Amplify_Shader_Editor|here]].


You can find the files and samples of this guide in the package at <code>AmplifyImpostors/Examples/Scenes/CustomBaking</code>. If you are an advance user and you want to create the shaders manually you can still follow the guide by comparing the results with the given sample.
This is also a somewhat advance feature that uses custom baking to bake and render the lightmap information so we highly recommend you to first read the [[Unity_Products:Amplify_Impostors/Custom_Baking| custom baking tutorial here]] to understand the underlying concept.
 
As of version 0.9.5 you can now also use Unity's Shader Graph to create the baking shader. This should make the process of creating ''baking'' shaders for LWRP and HDRP that have been created with shader graph a lot easier. The process is very similar with the obvious differences between the two editors. Do note that you still need Amplify Shader Editor if you need to create a ''runtime'' impostor shader since that shader is the one that uses the Impostor node that knows how to use the baked textures.


== Description ==
== Description ==
This guide demonstrates the process of creating the same custom impostor found in the samples. The intention is to create the impostor for an object that contains a special dynamic shader. This shader adds a procedural layer of paint on top of the object. This layer of paint is procedural in the sense that it uses the object position to calculate a pseudo-random color for the paint. If we were to bake a regular impostor for this object we would lose this procedural behavior and end up with a static version instead.
http://wiki.amplify.pt/images/ImpostorsImages/Problem.gif
<br>''Notice how the left real object changes color while the right impostor stays a static red.''
To accomplish this two special shaders are needed. One is a shader that will be used instead of the original shader of your object material to bake the different texture maps. This shader contains the different outputs that will be used to generate the different textures and what their channels contain. We'll call this the ''"bake shader"''. The other shader will use the generated textures and render the impostor correctly with the intended custom effect you might be looking for. This is the shader you will use in your product that creates the impostor effect. We'll call this one the ''"runtime shader"''.
Finally we need to setup the outputs and link the shaders to them, we do this using a preset asset file that you can create and reference in the impostor component.
== Create Bake Shader ==
# Right click in your project and create a new Impostor Bake shader.<br>'''''NOTE''': If you can't see this entry make sure to import the Impostors package AFTER the shader editor and with a shader editor canvas open to detect changes.''<br><br><img class="responsive-img" src="http://wiki.amplify.pt/images/ImpostorsImages/NewBakeShader.png"><br><br><br>
# With the shader open in the editor start by placing the texture samplers and pack them to the chosen output and make sure the property names match the original shader.<br><br><img class="responsive-img" src="http://wiki.amplify.pt/images/ImpostorsImages/BakeShader1.jpg"><br><br><br>
# Then create the graph nodes and connections that correspond to the static parts that we can bake into maps, in our case that's everything except the procedural color part. Also, because we'll later need the special mask to recreate the final procedural effect and because we want to save some texture memory we will pack it alongside the remaining data and connect it to the same single output.<br><br><img class="responsive-img" src="http://wiki.amplify.pt/images/ImpostorsImages/BakeShader2.jpg"><br><br><br>
# Add the "Pack Normal Depth" shader function node which will transform the normals into the necessary space and create the depth information in the alpha channel.<br><br><img class="responsive-img" src="http://wiki.amplify.pt/images/ImpostorsImages/BakeShader3.jpg"><br><br><br>
# (optional) If your object shader uses a "Cutout" effect make sure to mimic it by subtracting the clip mask value and connecting it to the "Clip" output.<br><br><img class="responsive-img" src="http://wiki.amplify.pt/images/ImpostorsImages/BakeShader4.jpg">
== Create Runtime Shader ==
# Right click in your project and create a new Impostor Runtime shader.<br><br><img class="responsive-img" src="http://wiki.amplify.pt/images/ImpostorsImages/NewRuntimeShader.png"><br><br><br>
# In the editor add a new "Amplify Impostor node", connect the Albedo, World Normal and Alpha outputs to the available inputs in the master node. Hit the save button in the ASE canvas.<br>'''''NOTE''': Doing this should compile an Impostor compatible shader that uses the most important data from the bake, however we still need to customize it further to support the intended procedural effect.''<br><br><img class="responsive-img" src="http://wiki.amplify.pt/images/ImpostorsImages/RuntimeShader1.jpg"><br><br><br>
# In our case we want to fetch a custom map not available in the original outputs, we do this by selecting the Impostor node and changing the "Extra Samplers" field to the appropriate number (in our case 1) and connecting a Texture Object node with a name that you will later use to reference this map. In this case we call it "_Mask".<br><br><img class="responsive-img" src="http://wiki.amplify.pt/images/ImpostorsImages/RuntimeShader2.jpg"><br><br><br>
# We now need to create the procedural logic from the original shader which uses the object XZ position in a wave function to generate a color.<br><br><img class="responsive-img" src="http://wiki.amplify.pt/images/ImpostorsImages/RuntimeShader3.jpg"><br><br><br>
# Finally filter the procedural color to the mask from the extra output and connect the appropriate channels to their outputs. Save.<br><br><img class="responsive-img" src="http://wiki.amplify.pt/images/ImpostorsImages/RuntimeShader4.jpg">
== Create Bake Preset ==
# Create a new preset by going to "Assets > Create > Amplify Impostor Bake Preset" or hitting the "New" button in the impostor component. Select it in the chosen project location.<br><br><img class="responsive-img" src="http://wiki.amplify.pt/images/ImpostorsImages/NewBakePreset.png"><br><br><br>
# Assign the shaders to the preset and add or remove outputs until you have the same number of usable outputs from the shader created in [Step 2].<br><br><img class="responsive-img" src="http://wiki.amplify.pt/images/ImpostorsImages/Preset1.png"><br><br><br>
# Configure the outputs to represent the data they hold. In this case the first output holds albedo color data in RGB so we mark it as sRGB color space. Do make sure to mark the output that contains the alpha channel, in this case it's the first one so we leave the radio button as is.<br><br><img class="responsive-img" src="http://wiki.amplify.pt/images/ImpostorsImages/Preset2.png"><br><br><br>
# Now, simply select the new preset in the impostor component, override the fields if necessary and hit "Bake Impostor"<br><br><img class="responsive-img" src="http://wiki.amplify.pt/images/ImpostorsImages/Preset3.png">


== Final Result ==
You'll be creating a bake shader that outputs the lightmap in to a single RGBA texture and another that reads it. Because the light information can use higher values that single colors allow, unity packs the lightmap color RGB into a RGBM format where the M is a multiplier of RGB, this only means you'll need all four channels of a single texture and not just 3. You'll then need to create the runtime shader that reads that RGBA texture file and unpacks it into the original RGB information. While this might sound confusing at first its actually a matter of just adding an extra texture output and use it. We provide a shader function that automatically does the packing and the shader already unpacks the result without extra work.
This is the final result, notice how now the impostors on the right can now mimic the effect from the original objects and display the procedural colors as it was intended. Furthermore, these impostor only use three maps to achieve it and not 4 as the standard ones do.<br><br>
http://wiki.amplify.pt/images/ImpostorsImages/Final.jpg

Revision as of 15:58, 26 March 2019

Product Page - Manual - Custom Baking - Lightmap Baking - Roadmap

Introduction

Due to high demand, as of version 0.9.5, you can now bake and render impostors with static Lightmap information. Be advise that, due to the static nature of lightmaps, doing this means all impostors sharing the same texture will also share the same light information. Making that light information different between similar impostor means baking different lightmaps to different objects which in turn increase the texture footprint of your application. If you use this feature it means you accept that trade-off when using multiple lightmapped impostors. This feature has some special uses cases, for instance, you might only want a impostor of a single static object that has baked lighting, or your multiple baked impostors might be sharing very similar lighting conditions in which case the different of objects would be neglectable.

This is also a somewhat advance feature that uses custom baking to bake and render the lightmap information so we highly recommend you to first read the custom baking tutorial here to understand the underlying concept.

Description

You'll be creating a bake shader that outputs the lightmap in to a single RGBA texture and another that reads it. Because the light information can use higher values that single colors allow, unity packs the lightmap color RGB into a RGBM format where the M is a multiplier of RGB, this only means you'll need all four channels of a single texture and not just 3. You'll then need to create the runtime shader that reads that RGBA texture file and unpacks it into the original RGB information. While this might sound confusing at first its actually a matter of just adding an extra texture output and use it. We provide a shader function that automatically does the packing and the shader already unpacks the result without extra work.