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.
68 lines
3.8 KiB
68 lines
3.8 KiB
using UnityEngine; |
|
using UnityEngine.Rendering; |
|
|
|
namespace UnityEditor.Rendering.Universal.ShaderGUI |
|
{ |
|
internal class LitDetailGUI |
|
{ |
|
public static class Styles |
|
{ |
|
public static readonly GUIContent detailInputs = EditorGUIUtility.TrTextContent("Detail Inputs", |
|
"These settings define the surface details by tiling and overlaying additional maps on the surface."); |
|
|
|
public static readonly GUIContent detailMaskText = EditorGUIUtility.TrTextContent("Mask", |
|
"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."); |
|
|
|
public static readonly GUIContent detailAlbedoMapText = EditorGUIUtility.TrTextContent("Base Map", |
|
"Select the surface detail texture.The alpha of your texture determines surface hue and intensity."); |
|
|
|
public static readonly GUIContent detailNormalMapText = EditorGUIUtility.TrTextContent("Normal Map", |
|
"Designates a Normal Map to create the illusion of bumps and dents in the details of this Material's surface."); |
|
|
|
public static readonly GUIContent detailAlbedoMapScaleInfo = EditorGUIUtility.TrTextContent("Setting the scaling factor to a value other than 1 results in a less performant shader variant."); |
|
} |
|
|
|
public struct LitProperties |
|
{ |
|
public MaterialProperty detailMask; |
|
public MaterialProperty detailAlbedoMapScale; |
|
public MaterialProperty detailAlbedoMap; |
|
public MaterialProperty detailNormalMapScale; |
|
public MaterialProperty detailNormalMap; |
|
|
|
public LitProperties(MaterialProperty[] properties) |
|
{ |
|
detailMask = BaseShaderGUI.FindProperty("_DetailMask", properties, false); |
|
detailAlbedoMapScale = BaseShaderGUI.FindProperty("_DetailAlbedoMapScale", properties, false); |
|
detailAlbedoMap = BaseShaderGUI.FindProperty("_DetailAlbedoMap", properties, false); |
|
detailNormalMapScale = BaseShaderGUI.FindProperty("_DetailNormalMapScale", properties, false); |
|
detailNormalMap = BaseShaderGUI.FindProperty("_DetailNormalMap", properties, false); |
|
} |
|
} |
|
|
|
public static void DoDetailArea(LitProperties properties, MaterialEditor materialEditor) |
|
{ |
|
materialEditor.TexturePropertySingleLine(Styles.detailMaskText, properties.detailMask); |
|
materialEditor.TexturePropertySingleLine(Styles.detailAlbedoMapText, properties.detailAlbedoMap, |
|
properties.detailAlbedoMap.textureValue != null ? properties.detailAlbedoMapScale : null); |
|
if (properties.detailAlbedoMapScale.floatValue != 1.0f) |
|
{ |
|
EditorGUILayout.HelpBox(Styles.detailAlbedoMapScaleInfo.text, MessageType.Info, true); |
|
} |
|
materialEditor.TexturePropertySingleLine(Styles.detailNormalMapText, properties.detailNormalMap, |
|
properties.detailNormalMap.textureValue != null ? properties.detailNormalMapScale : null); |
|
materialEditor.TextureScaleOffsetProperty(properties.detailAlbedoMap); |
|
} |
|
|
|
public static void SetMaterialKeywords(Material material) |
|
{ |
|
if (material.HasProperty("_DetailAlbedoMap") && material.HasProperty("_DetailNormalMap") && material.HasProperty("_DetailAlbedoMapScale")) |
|
{ |
|
bool isScaled = material.GetFloat("_DetailAlbedoMapScale") != 1.0f; |
|
bool hasDetailMap = material.GetTexture("_DetailAlbedoMap") || material.GetTexture("_DetailNormalMap"); |
|
CoreUtils.SetKeyword(material, "_DETAIL_MULX2", !isScaled && hasDetailMap); |
|
CoreUtils.SetKeyword(material, "_DETAIL_SCALED", isScaled && hasDetailMap); |
|
} |
|
} |
|
} |
|
}
|
|
|