설명 없음
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.

LitDetailGUI.cs 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using UnityEngine;
  2. using UnityEngine.Rendering;
  3. using UnityEngine.Experimental.Rendering;
  4. namespace UnityEditor.Rendering.Universal.ShaderGUI
  5. {
  6. internal class LitDetailGUI
  7. {
  8. internal static class Styles
  9. {
  10. public static readonly GUIContent detailInputs = EditorGUIUtility.TrTextContent("Detail Inputs",
  11. "These settings define the surface details by tiling and overlaying additional maps on the surface.");
  12. public static readonly GUIContent detailMaskText = EditorGUIUtility.TrTextContent("Mask",
  13. "Select a mask for the Detail map. The mask uses the alpha channel of the selected texture. The Tiling and Offset settings have no effect on the mask.");
  14. public static readonly GUIContent detailAlbedoMapText = EditorGUIUtility.TrTextContent("Base Map",
  15. "Select the surface detail texture.The alpha of your texture determines surface hue and intensity.");
  16. public static readonly GUIContent detailNormalMapText = EditorGUIUtility.TrTextContent("Normal Map",
  17. "Designates a Normal Map to create the illusion of bumps and dents in the details of this Material's surface.");
  18. public static readonly GUIContent detailAlbedoMapScaleInfo = EditorGUIUtility.TrTextContent("Setting the scaling factor to a value other than 1 results in a less performant shader variant.");
  19. public static readonly GUIContent detailAlbedoMapFormatError = EditorGUIUtility.TrTextContent("This texture is not in linear space.");
  20. }
  21. public struct LitProperties
  22. {
  23. public MaterialProperty detailMask;
  24. public MaterialProperty detailAlbedoMapScale;
  25. public MaterialProperty detailAlbedoMap;
  26. public MaterialProperty detailNormalMapScale;
  27. public MaterialProperty detailNormalMap;
  28. public LitProperties(MaterialProperty[] properties)
  29. {
  30. detailMask = BaseShaderGUI.FindProperty("_DetailMask", properties, false);
  31. detailAlbedoMapScale = BaseShaderGUI.FindProperty("_DetailAlbedoMapScale", properties, false);
  32. detailAlbedoMap = BaseShaderGUI.FindProperty("_DetailAlbedoMap", properties, false);
  33. detailNormalMapScale = BaseShaderGUI.FindProperty("_DetailNormalMapScale", properties, false);
  34. detailNormalMap = BaseShaderGUI.FindProperty("_DetailNormalMap", properties, false);
  35. }
  36. }
  37. public static void DoDetailArea(LitProperties properties, MaterialEditor materialEditor)
  38. {
  39. materialEditor.TexturePropertySingleLine(Styles.detailMaskText, properties.detailMask);
  40. materialEditor.TexturePropertySingleLine(Styles.detailAlbedoMapText, properties.detailAlbedoMap,
  41. properties.detailAlbedoMap.textureValue != null ? properties.detailAlbedoMapScale : null);
  42. if (properties.detailAlbedoMapScale.floatValue != 1.0f)
  43. {
  44. EditorGUILayout.HelpBox(Styles.detailAlbedoMapScaleInfo.text, MessageType.Info, true);
  45. }
  46. var detailAlbedoTexture = properties.detailAlbedoMap.textureValue as Texture2D;
  47. if (detailAlbedoTexture != null && GraphicsFormatUtility.IsSRGBFormat(detailAlbedoTexture.graphicsFormat))
  48. {
  49. EditorGUILayout.HelpBox(Styles.detailAlbedoMapFormatError.text, MessageType.Warning, true);
  50. }
  51. materialEditor.TexturePropertySingleLine(Styles.detailNormalMapText, properties.detailNormalMap,
  52. properties.detailNormalMap.textureValue != null ? properties.detailNormalMapScale : null);
  53. materialEditor.TextureScaleOffsetProperty(properties.detailAlbedoMap);
  54. }
  55. public static void SetMaterialKeywords(Material material)
  56. {
  57. if (material.HasProperty("_DetailAlbedoMap") && material.HasProperty("_DetailNormalMap") && material.HasProperty("_DetailAlbedoMapScale"))
  58. {
  59. bool isScaled = material.GetFloat("_DetailAlbedoMapScale") != 1.0f;
  60. bool hasDetailMap = material.GetTexture("_DetailAlbedoMap") || material.GetTexture("_DetailNormalMap");
  61. CoreUtils.SetKeyword(material, "_DETAIL_MULX2", !isScaled && hasDetailMap);
  62. CoreUtils.SetKeyword(material, "_DETAIL_SCALED", isScaled && hasDetailMap);
  63. }
  64. }
  65. }
  66. }