TextureBlender.cs 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System;
  5. namespace DigitalOpus.MB.Core
  6. {
  7. /// <summary>
  8. /// A TextureBlender will attempt to blend non-texture properties with textures so that the result material looks the same as source material.
  9. /// </summary>
  10. public interface TextureBlender
  11. {
  12. /// <summary>
  13. /// The shader name that must be matched on the result material in order for this TextureBlender to be used. This should return something like "Legacy/Bumped Difuse"
  14. /// </summary>
  15. bool DoesShaderNameMatch(string shaderName);
  16. /// <summary>
  17. /// This is called to prepare the TextureBlender before any calls to OnBlendTexturePixel
  18. /// Use this to grab the non-texture property values from the material that will be used to alter the Pixel color in the texture.
  19. /// Note that the sourceMat may not use a shader matching ShaderName. It may not have expected properties. Check that properties exist
  20. /// before grabing them.
  21. /// </summary>
  22. void OnBeforeTintTexture(Material sourceMat, string shaderTexturePropertyName);
  23. /// <summary>
  24. /// Called once for each pixel in the texture to alter the pixel color. For efficiency don't check shaderPropertyName every call. Instead use OnBeforeTintTexture
  25. /// to prepare this textrure blender for a batch of OnBlendTexturePixel calls.
  26. /// </summary>
  27. Color OnBlendTexturePixel(string shaderPropertyName, Color pixelColor);
  28. /// <summary>
  29. /// Material a & b may have the same set of textures but different non-texture properties (colorTint etc...)
  30. /// If so then they need to be put into separate rectangels in the atlas. This method should check the non-texture properties
  31. /// and return false if they are different. Note that material a and b may use a different shader than GetShaderName so your code
  32. /// should handle the case where properties do not exist.
  33. /// </summary>
  34. bool NonTexturePropertiesAreEqual(Material a, Material b);
  35. /// <summary>
  36. /// Sets the non texture properties on the result materail after textures have been baked. If for example _Color has been blended with
  37. /// the _Albedo textures then the _Color property on the result material should probably be set to white.
  38. /// </summary>
  39. void SetNonTexturePropertyValuesOnResultMaterial(Material resultMaterial);
  40. /// <summary>
  41. /// Some textures may not be assigned for a material. This method should return a color that will used to create a small solid color texture
  42. /// to be used in these cases. Note that this small solid color texture will later be blended using OnBlendTexturePixel. If the texturePropertyname is _mainTex
  43. /// then the the returned color should probably be white so it looks correct when OnBlendTexturePixel blends the _Color.
  44. ///
  45. /// This is also used to determine if an atlas needs to be generated for a texture property. If all the source materials are missing the texture for
  46. /// texPropertyName property (eg. _MainTex), but some of the source materials return different value for:
  47. /// OnBlendTexturePixel(texturePropertyName, GetColorIfNoTexture(sourceMat, texturePropertyName))
  48. /// Then an atlas will be generated with the different colors.
  49. ///
  50. /// This method can also be used to collect the value of non texture properties and cache them for each source material. This information can be useful
  51. /// for setting values on the result material.
  52. /// </summary>
  53. Color GetColorIfNoTexture(Material m, ShaderTextureProperty texPropertyName);
  54. }
  55. }