15 protected bool firstTimeApply =
true;
36 protected MaterialProperty
gloss;
63 protected MaterialProperty
zTest;
67 public override void OnGUI(MaterialEditor matEditor, MaterialProperty[] props)
70 CacheMainProperties(props);
71 CacheOutputConfigurationProperties(props);
77 firstTimeApply =
false;
80 EditorGUIUtility.labelWidth = 0f;
82 EditorGUI.BeginChangeCheck();
84 ShowMainGUI(matEditor);
85 ShowOutputConfigurationGUI(matEditor);
87 var mode = (
BlendMode)blendMode.floatValue;
90 matEditor.RenderQueueField();
93 if (EditorGUI.EndChangeCheck())
95 foreach (var obj
in blendMode.targets)
97 var mat = obj as Material;
98 SetMaterialBlendMode(mat, (
BlendMode)blendMode.floatValue);
99 SetMaterialAutoPropertiesAndKeywords(mat);
106 ShowBlendModeGUI(matEditor);
108 var mode = (
BlendMode)blendMode.floatValue;
109 var mat = matEditor.target as Material;
118 mainColorEnabled, mainColor,
119 textureScaleAndOffset);
136 EditorGUI.BeginDisabledGroup(MaterialNeedsPerPixel(mat));
138 EditorGUI.EndDisabledGroup();
142 if (specularLightingEnabled.floatValue != 0.0f)
147 matEditor.TexturePropertySingleLine(
Styles.
specular, specularMap, specular);
148 matEditor.TexturePropertySingleLine(
Styles.
gloss, glossMap, gloss);
157 if (rimLightingEnabled.floatValue != 0.0f)
167 if (reflectionsEnabled.floatValue != 0.0f)
169 matEditor.TexturePropertySingleLine(
Styles.
cubeMap, cubeMap);
203 EditorGUI.showMixedValue = blendMode.hasMixedValue;
204 var mode = (
BlendMode)blendMode.floatValue;
206 EditorGUI.BeginChangeCheck();
208 if (EditorGUI.EndChangeCheck())
210 matEditor.RegisterPropertyChangeUndo(
"Rendering Mode");
211 blendMode.floatValue = (float)mode;
214 EditorGUI.showMixedValue =
false;
219 var mode = (
BlendMode)blendMode.floatValue;
236 if (mat.HasProperty(
"_Emission"))
238 mat.SetColor(
"_EmissionColor", mat.GetColor(
"_Emission"));
241 base.AssignNewShaderToMaterial(mat, oldShader, newShader);
243 if (oldShader == null)
250 bool standard = oldShader.name.Contains(
"Standard");
251 bool legacy = oldShader.name.Contains(
"Legacy Shaders/");
252 bool mobile = oldShader.name.Contains(
"Mobile/");
254 bool transparent = oldShader.name.Contains(
"Transparent/");
255 bool cutout = oldShader.name.Contains(
"Transparent/Cutout/");
256 bool unlit = oldShader.name.Contains(
"Unlit");
257 bool directionalLightOnly = oldShader.name.Contains(
"DirectionalLight");
258 bool vertexLit = oldShader.name.Contains(
"VertexLit");
259 bool spec = !oldShader.name.Contains(
"Diffuse");
265 else if (mobile || legacy)
271 else if (transparent)
278 SetMaterialLighting(mat,
false,
false,
false,
false,
false);
283 SetMaterialLighting(mat,
true,
true, spec, !directionalLightOnly, vertexLit);
286 SetMaterialBlendMode(mat, blendMode);
290 protected virtual void SetMaterialLighting(Material mat,
bool ambient,
bool diffuse,
bool specular,
bool additional,
bool perPixel)
292 mat.SetFloat(
"_UseAmbient", ambient ? 1.0f : 0.0f);
293 mat.SetFloat(
"_UseDiffuse", diffuse ? 1.0f : 0.0f);
294 mat.SetFloat(
"_SpecularHighlights", specular ? 1.0f : 0.0f);
295 mat.SetFloat(
"_Shade4", additional ? 1.0f : 0.0f);
297 mat.SetFloat(
"_ForcePerPixel", perPixel ? 1.0f : 0.0f);
305 mat.SetOverrideTag(
"RenderType",
"");
306 mat.SetInt(
"_SrcBlend", (
int)
UnityEngine.Rendering.BlendMode.One);
307 mat.SetInt(
"_DstBlend", (
int)
UnityEngine.Rendering.BlendMode.Zero);
308 mat.SetInt(
"_ZWrite", 1);
310 mat.renderQueue = -1;
313 mat.SetOverrideTag(
"RenderType",
"TransparentCutout");
314 mat.SetInt(
"_SrcBlend", (
int)
UnityEngine.Rendering.BlendMode.One);
315 mat.SetInt(
"_DstBlend", (
int)
UnityEngine.Rendering.BlendMode.Zero);
316 mat.SetInt(
"_ZWrite", 1);
318 mat.renderQueue = (int)
UnityEngine.Rendering.RenderQueue.AlphaTest;
321 mat.SetOverrideTag(
"RenderType",
"Transparent");
323 mat.SetInt(
"_SrcBlend", (
int)
UnityEngine.Rendering.BlendMode.SrcAlpha);
324 mat.SetInt(
"_DstBlend", (
int)
UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
325 mat.SetInt(
"_ZWrite", 1);
327 mat.renderQueue = (int)
UnityEngine.Rendering.RenderQueue.Transparent;
337 bool usesBumpMap = mat.GetTexture(
"_BumpMap");
338 bool usesSpecMap = mat.GetTexture(
"_SpecularMap");
339 bool usesGlossMap = mat.GetTexture(
"_GlossMap");
340 bool usesEmissionMap = mat.GetTexture(
"_EmissionMap");
342 return (usesBumpMap || usesSpecMap || usesGlossMap || usesEmissionMap);
350 bool usesBumpMap = mat.GetTexture(
"_BumpMap");
351 bool usesSpecMap = mat.GetTexture(
"_SpecularMap");
352 bool usesGlossMap = mat.GetTexture(
"_GlossMap");
353 bool usesEmissionMap = mat.GetTexture(
"_EmissionMap");
361 if (usesBumpMap || usesSpecMap || usesGlossMap || usesEmissionMap)
363 mat.SetFloat(
"_ForcePerPixel", 1.0f);
366 var texScaleOffset = mat.GetVector(
"_TextureScaleOffset");
367 bool usesScale = texScaleOffset.x != 1.0f || texScaleOffset.y != 1.0f;
368 bool usesOffset = texScaleOffset.z != 0.0f || texScaleOffset.w != 0.0f;
376 blendMode = FindProperty(
"_Mode", props);
378 vertexColorEnabled = FindProperty(
"_UseVertexColor", props);
379 mainColorEnabled = FindProperty(
"_UseMainColor", props);
380 mainColor = FindProperty(
"_Color", props);
381 mainTexture = FindProperty(
"_MainTex", props);
382 alphaCutoff = FindProperty(
"_Cutoff", props);
384 occlusionMap = FindProperty(
"_OcclusionMap", props);
386 ambientLightingEnabled = FindProperty(
"_UseAmbient", props);
387 diffuseLightingEnabled = FindProperty(
"_UseDiffuse", props);
388 useAdditionalLightingData = FindProperty(
"_Shade4", props);
389 perPixelLighting = FindProperty(
"_ForcePerPixel", props);
391 specularLightingEnabled = FindProperty(
"_SpecularHighlights", props);
392 specularColor = FindProperty(
"_SpecColor", props);
393 specular = FindProperty(
"_Specular", props);
394 specularMap = FindProperty(
"_SpecularMap", props);
396 gloss = FindProperty(
"_Gloss", props);
397 glossMap = FindProperty(
"_GlossMap", props);
399 normalMap = FindProperty(
"_BumpMap", props);
401 reflectionsEnabled = FindProperty(
"_UseReflections", props);
402 cubeMap = FindProperty(
"_CubeMap", props);
403 reflectionScale = FindProperty(
"_ReflectionScale", props);
404 calibrationSpaceReflections = FindProperty(
"_CalibrationSpaceReflections", props);
406 rimLightingEnabled = FindProperty(
"_UseRimLighting", props);
407 rimPower = FindProperty(
"_RimPower", props);
408 rimColor = FindProperty(
"_RimColor", props);
410 emissionColorEnabled = FindProperty(
"_UseEmissionColor", props);
411 emissionColor = FindProperty(
"_EmissionColor", props);
412 emissionMap = FindProperty(
"_EmissionMap", props);
414 textureScaleAndOffset = FindProperty(
"_TextureScaleOffset", props);
416 srcBlend = FindProperty(
"_SrcBlend", props);
417 dstBlend = FindProperty(
"_DstBlend", props);
418 blendOp = FindProperty(
"_BlendOp", props);
423 cullMode = FindProperty(
"_Cull", props);
424 zTest = FindProperty(
"_ZTest", props);
425 zWrite = FindProperty(
"_ZWrite", props);
426 colorWriteMask = FindProperty(
"_ColorWriteMask", props);
431 public static string renderingMode =
"Rendering Mode";
432 public static readonly
string[] blendNames = Enum.GetNames(typeof(
BlendMode));
434 public static GUIContent vertexColorEnabled =
new GUIContent(
"Vertex Color",
"Utilize vertex color from the model?");
435 public static GUIContent main =
new GUIContent(
"Albedo",
"Albedo (RGB) and Transparency (A)");
436 public static GUIContent alphaCutoffText =
new GUIContent(
"Alpha Cutoff",
"Threshold for alpha cutoff");
438 public static GUIContent occlusionMap =
new GUIContent(
"Occlusion Map",
"Additional texture to be overlaid on the main texture");
440 public static GUIContent ambientLightingEnabled =
new GUIContent(
"Ambient",
"Scene ambient lighting");
441 public static GUIContent diffuseLightingEnabled =
new GUIContent(
"Diffuse",
"Diffuse (lambertian) lighting from directional lights");
442 public static GUIContent useAdditionalLighingData =
new GUIContent(
"Point and Spot",
"Apply lighting from point and spot lights (expensive)");
443 public static GUIContent perPixelLighting =
new GUIContent(
"Per-Pixel lighting",
"Light objects per-pixel instead of per-vertex - using any lighting affecting map will force this on");
445 public static GUIContent specularLightingEnabled =
new GUIContent(
"Specular Highlights",
"Specular (blinn-phong) lighting from directional lights");
446 public static GUIContent specularColor =
new GUIContent(
" Color",
"Tint to apply to specular highlights");
447 public static GUIContent specular =
new GUIContent(
"Power",
"Specular Power - using a map will turn on per-pixel lighting");
448 public static GUIContent gloss =
new GUIContent(
"Gloss",
"Specular Scale - using a map will turn on per-pixel lighting");
450 public static GUIContent normalMap =
new GUIContent(
"Normal Map",
"Normal Map - will turn on per-pixel lighting");
452 public static GUIContent reflectionsEnabled =
new GUIContent(
"Reflections",
"Cube map based reflections");
453 public static GUIContent cubeMap =
new GUIContent(
"Cube Map",
"Cube map lookup for reflections");
454 public static GUIContent reflectionScale =
new GUIContent(
"Scale",
"Reflection strength");
455 public static GUIContent calibrationSpaceReflections =
new GUIContent(
"In calibration space",
"Keeps reflections consistent across different calibrations");
457 public static GUIContent rimLightingEnabled =
new GUIContent(
"Rim Lighting",
"Side lighting");
458 public static GUIContent rimPower =
new GUIContent(
"Power",
"Power of rim lighting");
459 public static GUIContent rimColor =
new GUIContent(
"Color",
"Color of rim lighting");
461 public static GUIContent emission =
new GUIContent(
"Emission",
"Emission (RGB)");
463 public static GUIContent textureScaleAndOffset =
new GUIContent(
"Texture Scale and Offset",
"Applies to all textures");
465 public static GUIContent srcBlend =
new GUIContent(
"Source Blend",
"Blend factor for transparency, etc.");
466 public static GUIContent dstBlend =
new GUIContent(
"Destination Blend",
"Blend factor for transparency, etc.");
467 public static GUIContent blendOp =
new GUIContent(
"Blend Operation",
"Blend operation for transparency, etc.");
469 public static GUIContent cullMode =
new GUIContent(
"Culling Mode",
"Type of culling to apply to polygons - typically this is set to backfacing");
470 public static GUIContent zTest =
new GUIContent(
"Z Test",
"Depth buffer check type - output is not written if this is false");
471 public static GUIContent zWrite =
new GUIContent(
"Z Write",
"When to write to the depth buffer");
472 public static GUIContent colorWriteMask =
new GUIContent(
"Color Write Mask",
"Restricts output to specified color channels only");