Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
4.5 KiB

  1. Creating terrains with Amplify Shader Editor is really quick and easy. We will give you a brief explanation on how you can start creating terrain shaders with ASE in no time.
  2. A standard unity terrain is a regular surface shader using properties with a specific naming.
  3. Besides these properties, a small configuration is necessary.
  4. [Create Shader]
  5. As with any other ASE shaders, right-click on the Project view, select Create > Amplify Shader > Surface Shader and name it as you like. We advise you to have 'First-Pass' included on the shader name since it performs what is called a first pass over the terrain.
  6. [Queue Index]
  7. Set the Queue Index to -100 on the Output Node Properties General tab.
  8. [Render Type]
  9. By default a created shader already comes with the Opaque shader type selected, which is required by the terrain, but please go to the Blend Mode tab and check that Opaque is the selected option.
  10. [Specify Base Shader]
  11. A Base shader must be specified. This shader will be responsible to render the terrain when over a certain distance specified at the Base Map Distance on the terrain settings. Beyond this distance, a lower resolution composite image will be used with this shader for efficiency reasons.
  12. We already have a base shader created and ready to be used, so you only need to:
  13. - Go to your Dependencies Tab on the Output Node Properties
  14. - Click on the Add Button to add a new entry
  15. - Write BaseMapShader into the Name textfield
  16. - Write ASESampleShaders/SimpleTerrainBase on the Value textfield
  17. Feel free to open the ASESampleShaders/SimpleTerrainBase shader located at AmplifyShaderEditor > Examples > Official > SimpleTerrain > SimpleTerrainBase.shader and check what is being done. Please note that property naming in the base shader is very strict and property names must be maintained.
  18. [Specify Splat Count]
  19. ASE only supports up to four splats (single-pass) for now, this needs to be specified into the shader through a custom tag.
  20. In order to do that:
  21. - Go to Custom SubShader Tags tab on the Output Node Properties
  22. - Click on the Add Button to add a new entry
  23. - Write SplatCount into the Name textfield
  24. - Write 4 into the Value textfield
  25. Future versions will introduce multi-pass support for more complex effects.
  26. [Create Properties]
  27. This is the meat of how the terrain shader will behave.
  28. We already have a shader function, Four Splats First Pass Terrain, which replicates Unity standard terrain and should be used as starting point on creating your own shader.
  29. [[Diffuse]]
  30. Each splat can be accessed via their properties, having yet again strict naming to be maintained.
  31. The splat diffuse colors are accessed through the sampler variables _Splat0 through _Splat3, so in your shader you must create four Texture Sampler nodes with the names Splat 0 through Splat 3 as the _ is automatically placed and the empty spaces are also automatically removed from the created variable name.
  32. [[Normal]]
  33. The same goes to normal maps, they are accessed through the sampler variables _Normal0 through _Normal3 so, like with diffuse, in your shader you must create four Texture Sampler nodes with the names Normal 0 through Normal 3. One detail to take into account is that Unpack Normal Map should be turned off for each one of the nodes and an Unpack Scale Normal node should be applied after their values are combined.
  34. [[Smoothness + Metallic]]
  35. Smoothness and Metallic values must also have specific variable names, _Smoothness0 through _Smoothness3 and _Metallic0 through _Metallic3 respectively.
  36. These variables however are Float properties, so to access them you need to create Float nodes, set them to Properties with the names Smoothness 0 through Smoothness 3 and Metallic 0 through Metallic 3 respectively.
  37. To maintain consistency with the Unity terrain shader, you should add the Gamma attribute to the Metallic property nodes.
  38. [[Combining Maps]]
  39. The weight of each layer is given by yet another sampler variable. The _Control sampler variable contains, in each of its channels, the contribution each layer/splat have on the final result.
  40. To get access to it, simply create a Texture Sampler node in your shader with its name being Control.
  41. This Control texture is dynamically created when you paint your terrain with the Terrain tools and can be inspected by selecting the terrain asset on the Project view.
  42. Again, we invite you to check the Four Splats First Pass Terrain shader function located at AmplifyShaderEditor > Plugins > EditorResources > ShaderFunctions > Four Splats First Pass Terrain for a more in-depth view on how the Control texture is used.