diff --git a/Editor/XSStyles.cs b/Editor/XSStyles.cs index 639e16c..0076320 100644 --- a/Editor/XSStyles.cs +++ b/Editor/XSStyles.cs @@ -6,7 +6,7 @@ [InitializeOnLoad] public class XSStyles : MonoBehaviour { - public static string ver = "2.2.2"; + public static string ver = "2.2.3"; //Help URLs public static string mainURL = "https://docs.google.com/document/d/1xJ4PID_nwqVm_UCsO2c2gEdiEoWoCGeM_GDK_L8-aZE/edit#bookmark=id.xh0nk8x7ws1g"; diff --git a/Editor/XSToonInspector.cs b/Editor/XSToonInspector.cs index 2882f19..ca55133 100644 --- a/Editor/XSToonInspector.cs +++ b/Editor/XSToonInspector.cs @@ -169,272 +169,318 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro materialEditor.ShaderProperty(_Culling, new GUIContent("Culling Mode", "Changes the culling mode. 'Off' will result in a two sided material, while 'Front' and 'Back' will cull those sides respectively")); materialEditor.ShaderProperty(_TilingMode, new GUIContent("Tiling Mode", "Setting this to Merged will tile and offset all textures based on the Main texture's Tiling/Offset.")); - showMainSettings = XSStyles.ShurikenFoldout("Main Settings", showMainSettings); - if (showMainSettings) + DrawMainSettings(materialEditor); + DrawShadowSettings(materialEditor, material); + DrawOutlineSettings(materialEditor); + DrawNormalSettings(materialEditor); + DrawSpecularSettings(materialEditor); + DrawReflectionsSettings(materialEditor, material); + DrawEmissionSettings(materialEditor); + DrawRimlightSettings(materialEditor); + DrawTransmissionSettings(materialEditor); + DrawAdvancedSettings(materialEditor); + DrawPatreonSettings(materialEditor); + XSStyles.DoFooter(); + } + } + + private void DrawMainSettings(MaterialEditor materialEditor) + { + showMainSettings = XSStyles.ShurikenFoldout("Main Settings", showMainSettings); + if (showMainSettings) + { + materialEditor.TexturePropertySingleLine(new GUIContent("Main Texture", "The main Albedo texture."), _MainTex, _Color); + if (isCutout) { - materialEditor.TexturePropertySingleLine(new GUIContent("Main Texture", "The main Albedo texture."), _MainTex, _Color); - if (isCutout) - { - materialEditor.ShaderProperty(_Cutoff, new GUIContent("Cutoff", "The Cutoff Amount"), 2); - } - if(isCutoutMasked) - { - materialEditor.TexturePropertySingleLine(new GUIContent("Dissolve Mask", "Black and white cutout mask"), _CutoutMask); - materialEditor.ShaderProperty(_Cutoff, new GUIContent("Dissolve Progress", "The Cutoff Amount"), 2); - } - materialEditor.ShaderProperty(_UVSetAlbedo, new GUIContent("UV Set", "The UV set to use for the Albedo Texture."), 2); - materialEditor.TextureScaleOffsetProperty(_MainTex); - materialEditor.ShaderProperty(_Saturation, new GUIContent("Saturation", "Controls saturation of the final output from the shader.")); + materialEditor.ShaderProperty(_Cutoff, new GUIContent("Cutoff", "The Cutoff Amount"), 2); + } + if(isCutoutMasked) + { + materialEditor.TexturePropertySingleLine(new GUIContent("Dissolve Mask", "Black and white cutout mask"), _CutoutMask); + materialEditor.ShaderProperty(_Cutoff, new GUIContent("Dissolve Progress", "The Cutoff Amount"), 2); + } + materialEditor.ShaderProperty(_UVSetAlbedo, new GUIContent("UV Set", "The UV set to use for the Albedo Texture."), 2); + materialEditor.TextureScaleOffsetProperty(_MainTex); + materialEditor.ShaderProperty(_Saturation, new GUIContent("Saturation", "Controls saturation of the final output from the shader.")); - if(isDithered) - { - //Dither Fading - materialEditor.TexturePropertySingleLine(new GUIContent("Dissolve Mask", "Black and white mask to control dithering."), _CutoutMask); - materialEditor.ShaderProperty(_FadeDither, new GUIContent("Use Distance Fading", "Make the shader dither out based on the distance to the camera."), 2); - materialEditor.ShaderProperty(_FadeDitherDistance, new GUIContent("Fade Distance", "The distance at which the fading starts happening."), 2); - } + if(isDithered) + { + //Dither Fading + materialEditor.TexturePropertySingleLine(new GUIContent("Dissolve Mask", "Black and white mask to control dithering."), _CutoutMask); + materialEditor.ShaderProperty(_FadeDither, new GUIContent("Use Distance Fading", "Make the shader dither out based on the distance to the camera."), 2); + materialEditor.ShaderProperty(_FadeDitherDistance, new GUIContent("Fade Distance", "The distance at which the fading starts happening."), 2); } + } + } - showShadows = XSStyles.ShurikenFoldout("Shadows", showShadows); - if (showShadows) + private void DrawShadowSettings(MaterialEditor materialEditor, Material material) + { + showShadows = XSStyles.ShurikenFoldout("Shadows", showShadows); + if (showShadows) + { + materialEditor.TexturePropertySingleLine(new GUIContent("Ramp Selection Mask", "A black to white mask that determins how far up on the multi ramp to sample. 0 for bottom, 1 for top, 0.5 for middle, 0.25, and 0.75 for mid bottom and mid top respectively."), _RampSelectionMask); + + XSStyles.SeparatorThin(); + if (_RampSelectionMask.textureValue != null) { - materialEditor.TexturePropertySingleLine(new GUIContent("Ramp Selection Mask", "A black to white mask that determins how far up on the multi ramp to sample. 0 for bottom, 1 for top, 0.5 for middle, 0.25, and 0.75 for mid bottom and mid top respectively."), _RampSelectionMask); - - XSStyles.SeparatorThin(); - if (_RampSelectionMask.textureValue != null) + string rampMaskPath = AssetDatabase.GetAssetPath(_RampSelectionMask.textureValue); + TextureImporter ti = (TextureImporter)TextureImporter.GetAtPath(rampMaskPath); + if (ti.sRGBTexture) { - string rampMaskPath = AssetDatabase.GetAssetPath(_RampSelectionMask.textureValue); - TextureImporter ti = (TextureImporter)TextureImporter.GetAtPath(rampMaskPath); - if (ti.sRGBTexture) - { - if (XSStyles.HelpBoxWithButton(new GUIContent("This texture is not marked as Linear.", "This is recommended for the mask"), new GUIContent("Fix Now"))) { - ti.sRGBTexture = false; - AssetDatabase.ImportAsset(rampMaskPath, ImportAssetOptions.ForceUpdate); - AssetDatabase.Refresh(); - } + if (XSStyles.HelpBoxWithButton(new GUIContent("This texture is not marked as Linear.", "This is recommended for the mask"), new GUIContent("Fix Now"))) { + ti.sRGBTexture = false; + AssetDatabase.ImportAsset(rampMaskPath, ImportAssetOptions.ForceUpdate); + AssetDatabase.Refresh(); } } - - materialEditor.TexturePropertySingleLine(new GUIContent("Shadow Ramp", "Shadow Ramp, Dark to Light should be Left to Right"), _Ramp); - materialEditor.ShaderProperty(_ShadowSharpness, new GUIContent("Shadow Sharpness", "Controls the sharpness of recieved shadows, as well as the sharpness of 'shadows' from Vertex Lighting.")); - - XSStyles.SeparatorThin(); - materialEditor.TexturePropertySingleLine(new GUIContent("Occlusion Map", "Occlusion Map, used to darken areas on the model artifically."), _OcclusionMap); - XSStyles.constrainedShaderProperty(materialEditor, _OcclusionColor, new GUIContent("Occlusion Tint", "Occlusion shadow tint."), 2); - materialEditor.ShaderProperty(_UVSetOcclusion, new GUIContent("UV Set", "The UV set to use for the Occlusion Texture"), 2); - materialEditor.TextureScaleOffsetProperty(_OcclusionMap); - - XSStyles.SeparatorThin(); - XSStyles.constrainedShaderProperty(materialEditor, _ShadowRim, new GUIContent("Shadow Rim", "Shadow Rim Color. Set to white to disable."), 0); - materialEditor.ShaderProperty(_ShadowRimAlbedoTint, new GUIContent("Shadow Rim Albedo Tint", "How much the Albedo texture should effect the Shadow Rim color.")); - materialEditor.ShaderProperty(_ShadowRimRange, new GUIContent("Range", "Range of the Shadow Rim"), 2); - materialEditor.ShaderProperty(_ShadowRimThreshold, new GUIContent("Threshold", "Threshold of the Shadow Rim"), 2); - materialEditor.ShaderProperty(_ShadowRimSharpness, new GUIContent("Sharpness", "Sharpness of the Shadow Rim"), 2); - XSStyles.callGradientEditor(material); } + + materialEditor.TexturePropertySingleLine(new GUIContent("Shadow Ramp", "Shadow Ramp, Dark to Light should be Left to Right"), _Ramp); + materialEditor.ShaderProperty(_ShadowSharpness, new GUIContent("Shadow Sharpness", "Controls the sharpness of recieved shadows, as well as the sharpness of 'shadows' from Vertex Lighting.")); + + XSStyles.SeparatorThin(); + materialEditor.TexturePropertySingleLine(new GUIContent("Occlusion Map", "Occlusion Map, used to darken areas on the model artifically."), _OcclusionMap); + XSStyles.constrainedShaderProperty(materialEditor, _OcclusionColor, new GUIContent("Occlusion Tint", "Occlusion shadow tint."), 2); + materialEditor.ShaderProperty(_UVSetOcclusion, new GUIContent("UV Set", "The UV set to use for the Occlusion Texture"), 2); + materialEditor.TextureScaleOffsetProperty(_OcclusionMap); + + XSStyles.SeparatorThin(); + XSStyles.constrainedShaderProperty(materialEditor, _ShadowRim, new GUIContent("Shadow Rim", "Shadow Rim Color. Set to white to disable."), 0); + materialEditor.ShaderProperty(_ShadowRimAlbedoTint, new GUIContent("Shadow Rim Albedo Tint", "How much the Albedo texture should effect the Shadow Rim color.")); + materialEditor.ShaderProperty(_ShadowRimRange, new GUIContent("Range", "Range of the Shadow Rim"), 2); + materialEditor.ShaderProperty(_ShadowRimThreshold, new GUIContent("Threshold", "Threshold of the Shadow Rim"), 2); + materialEditor.ShaderProperty(_ShadowRimSharpness, new GUIContent("Sharpness", "Sharpness of the Shadow Rim"), 2); + XSStyles.callGradientEditor(material); + } + } - if (isOutlined) + private void DrawOutlineSettings(MaterialEditor materialEditor) + { + if (isOutlined) + { + showOutlines = XSStyles.ShurikenFoldout("Outlines", showOutlines); + if (showOutlines) { - showOutlines = XSStyles.ShurikenFoldout("Outlines", showOutlines); - if (showOutlines) - { - materialEditor.ShaderProperty(_OutlineLighting, new GUIContent("Outline Lighting", "Makes outlines respect the lighting, or be emissive.")); - materialEditor.ShaderProperty(_OutlineAlbedoTint, new GUIContent("Outline Albedo Tint", "Includes the color of the Albedo Texture in the calculation for the color of the outline.")); - materialEditor.TexturePropertySingleLine(new GUIContent("Outline Mask", "Outline width mask, black will make the outline minimum width."), _OutlineMask); - materialEditor.ShaderProperty(_OutlineWidth, new GUIContent("Outline Width", "Width of the Outlines")); - XSStyles.constrainedShaderProperty(materialEditor, _OutlineColor, new GUIContent("Outline Color", "Color of the outlines"), 0); - } + materialEditor.ShaderProperty(_OutlineLighting, new GUIContent("Outline Lighting", "Makes outlines respect the lighting, or be emissive.")); + materialEditor.ShaderProperty(_OutlineAlbedoTint, new GUIContent("Outline Albedo Tint", "Includes the color of the Albedo Texture in the calculation for the color of the outline.")); + materialEditor.TexturePropertySingleLine(new GUIContent("Outline Mask", "Outline width mask, black will make the outline minimum width."), _OutlineMask); + materialEditor.ShaderProperty(_OutlineWidth, new GUIContent("Outline Width", "Width of the Outlines")); + XSStyles.constrainedShaderProperty(materialEditor, _OutlineColor, new GUIContent("Outline Color", "Color of the outlines"), 0); } + } + } + + private void DrawNormalSettings(MaterialEditor materialEditor) + { + showNormalMapSettings = XSStyles.ShurikenFoldout("Normal Maps", showNormalMapSettings); + if (showNormalMapSettings) + { + + materialEditor.TexturePropertySingleLine(new GUIContent("Normal Map", "Normal Map"), _BumpMap); + materialEditor.ShaderProperty(_BumpScale, new GUIContent("Normal Strength", "Strength of the main Normal Map"), 2); + materialEditor.ShaderProperty(_UVSetNormal, new GUIContent("UV Set", "The UV set to use for the Normal Map"), 2); + materialEditor.TextureScaleOffsetProperty(_BumpMap); + + XSStyles.SeparatorThin(); + materialEditor.TexturePropertySingleLine(new GUIContent("Detail Normal Map", "Detail Normal Map"), _DetailNormalMap); + materialEditor.ShaderProperty(_DetailNormalMapScale, new GUIContent("Detail Normal Strength", "Strength of the detail Normal Map"), 2); + materialEditor.ShaderProperty(_UVSetDetNormal, new GUIContent("UV Set", "The UV set to use for the Detail Normal Map"), 2); + materialEditor.TextureScaleOffsetProperty(_DetailNormalMap); + + XSStyles.SeparatorThin(); + materialEditor.TexturePropertySingleLine(new GUIContent("Detail Mask", "Mask for Detail Maps"), _DetailMask); + materialEditor.ShaderProperty(_UVSetDetMask, new GUIContent("UV Set", "The UV set to use for the Detail Mask"), 2); + materialEditor.TextureScaleOffsetProperty(_DetailMask); + + } + } - showNormalMapSettings = XSStyles.ShurikenFoldout("Normal Maps", showNormalMapSettings); - if (showNormalMapSettings) + private void DrawSpecularSettings(MaterialEditor materialEditor) + { + showSpecular = XSStyles.ShurikenFoldout("Specular", showSpecular); + if (showSpecular) + { + materialEditor.ShaderProperty(_SpecMode, new GUIContent("Specular Mode", "Specular Mode.")); + materialEditor.ShaderProperty(_SpecularStyle, new GUIContent("Specular Style", "Specular Style.")); + + XSStyles.SeparatorThin(); + materialEditor.TexturePropertySingleLine(new GUIContent("Specular Map(R,G,B)", "Specular Map. Red channel controls Intensity, Green controls how much specular is tinted by Albedo, and Blue controls Smoothness (Only for Blinn-Phong, and GGX)."), _SpecularMap); + materialEditor.TextureScaleOffsetProperty(_SpecularMap); + materialEditor.ShaderProperty(_UVSetSpecular, new GUIContent("UV Set", "The UV set to use for the Specular Map"), 2); + materialEditor.ShaderProperty(_SpecularIntensity, new GUIContent("Specular Intensity", "Specular Intensity."), 2); + materialEditor.ShaderProperty(_SpecularAlbedoTint, new GUIContent("Specular Albedo Tint", "How much the specular highlight should derive color from the albedo of the object."), 2); + if (_SpecMode.floatValue == 0 || _SpecMode.floatValue == 2) { + materialEditor.ShaderProperty(_SpecularArea, new GUIContent("Specular Area", "Specular Area."), 2); + } + else + { + materialEditor.ShaderProperty(_AnisotropicAX, new GUIContent("Anisotropic Width", "Anisotropic Width, makes anistropic relfections more horizontal"), 2); + materialEditor.ShaderProperty(_AnisotropicAY, new GUIContent("Anisotropic Height", "Anisotropic Height, makes anistropic relfections more vertical"), 2); + } + } + } - materialEditor.TexturePropertySingleLine(new GUIContent("Normal Map", "Normal Map"), _BumpMap); - materialEditor.ShaderProperty(_BumpScale, new GUIContent("Normal Strength", "Strength of the main Normal Map"), 2); - materialEditor.ShaderProperty(_UVSetNormal, new GUIContent("UV Set", "The UV set to use for the Normal Map"), 2); - materialEditor.TextureScaleOffsetProperty(_BumpMap); + private void DrawReflectionsSettings(MaterialEditor materialEditor, Material material) + { + showReflection = XSStyles.ShurikenFoldout("Reflections", showReflection); + if (showReflection) + { + materialEditor.ShaderProperty(_ReflectionMode, new GUIContent("Reflection Mode", "Reflection Mode.")); + if (_ReflectionMode.floatValue == 0) // PBR + { + materialEditor.ShaderProperty(_ReflectionBlendMode, new GUIContent("Reflection Blend Mode", "Blend mode for reflection. Additive is Color + reflection, Multiply is Color * reflection, and subtractive is Color - reflection")); + materialEditor.ShaderProperty(_ClearCoat, new GUIContent("Clearcoat", "Clearcoat")); + XSStyles.SeparatorThin(); - materialEditor.TexturePropertySingleLine(new GUIContent("Detail Normal Map", "Detail Normal Map"), _DetailNormalMap); - materialEditor.ShaderProperty(_DetailNormalMapScale, new GUIContent("Detail Normal Strength", "Strength of the detail Normal Map"), 2); - materialEditor.ShaderProperty(_UVSetDetNormal, new GUIContent("UV Set", "The UV set to use for the Detail Normal Map"), 2); - materialEditor.TextureScaleOffsetProperty(_DetailNormalMap); - + materialEditor.TexturePropertySingleLine(new GUIContent("Fallback Cubemap", " Used as fallback in 'Unity' reflection mode if reflection probe is black."), _BakedCubemap); + XSStyles.SeparatorThin(); - materialEditor.TexturePropertySingleLine(new GUIContent("Detail Mask", "Mask for Detail Maps"), _DetailMask); - materialEditor.ShaderProperty(_UVSetDetMask, new GUIContent("UV Set", "The UV set to use for the Detail Mask"), 2); - materialEditor.TextureScaleOffsetProperty(_DetailMask); - + materialEditor.TexturePropertySingleLine(new GUIContent("Metallic Map", "Metallic Map, Metallic on Red Channel, Smoothness on Alpha Channel. \nIf Clearcoat is enabled, Clearcoat Smoothness on Green Channel, Clearcoat Reflectivity on Blue Channel."), _MetallicGlossMap); + materialEditor.TextureScaleOffsetProperty(_MetallicGlossMap); + materialEditor.ShaderProperty(_UVSetMetallic, new GUIContent("UV Set", "The UV set to use for the Metallic Smoothness Map"), 2); + materialEditor.ShaderProperty(_Metallic, new GUIContent("Metallic", "Metallic, set to 1 if using metallic map"), 2); + materialEditor.ShaderProperty(_Glossiness, new GUIContent("Smoothness", "Smoothness, set to 1 if using metallic map"), 2); + materialEditor.ShaderProperty(_ClearcoatSmoothness, new GUIContent("Clearcoat Smoothness", "Smoothness of the clearcoat."), 2); + materialEditor.ShaderProperty(_ClearcoatStrength, new GUIContent("Clearcoat Reflectivity", "The strength of the clearcoat reflection."), 2); } - - showSpecular = XSStyles.ShurikenFoldout("Specular", showSpecular); - if (showSpecular) + else if (_ReflectionMode.floatValue == 1) //Baked cube { - materialEditor.ShaderProperty(_SpecMode, new GUIContent("Specular Mode", "Specular Mode.")); - materialEditor.ShaderProperty(_SpecularStyle, new GUIContent("Specular Style", "Specular Style.")); + materialEditor.ShaderProperty(_ReflectionBlendMode, new GUIContent("Reflection Blend Mode", "Blend mode for reflection. Additive is Color + reflection, Multiply is Color * reflection, and subtractive is Color - reflection")); + materialEditor.ShaderProperty(_ClearCoat, new GUIContent("Clearcoat", "Clearcoat")); XSStyles.SeparatorThin(); - materialEditor.TexturePropertySingleLine(new GUIContent("Specular Map(R,G,B)", "Specular Map. Red channel controls Intensity, Green controls how much specular is tinted by Albedo, and Blue controls Smoothness (Only for Blinn-Phong, and GGX)."), _SpecularMap); - materialEditor.TextureScaleOffsetProperty(_SpecularMap); - materialEditor.ShaderProperty(_UVSetSpecular, new GUIContent("UV Set", "The UV set to use for the Specular Map"), 2); - materialEditor.ShaderProperty(_SpecularIntensity, new GUIContent("Specular Intensity", "Specular Intensity."), 2); - materialEditor.ShaderProperty(_SpecularAlbedoTint, new GUIContent("Specular Albedo Tint", "How much the specular highlight should derive color from the albedo of the object."), 2); - if (_SpecMode.floatValue == 0 || _SpecMode.floatValue == 2) - { - materialEditor.ShaderProperty(_SpecularArea, new GUIContent("Specular Area", "Specular Area."), 2); - } - else - { - materialEditor.ShaderProperty(_AnisotropicAX, new GUIContent("Anisotropic Width", "Anisotropic Width, makes anistropic relfections more horizontal"), 2); - materialEditor.ShaderProperty(_AnisotropicAY, new GUIContent("Anisotropic Height", "Anisotropic Height, makes anistropic relfections more vertical"), 2); - } + materialEditor.TexturePropertySingleLine(new GUIContent("Baked Cubemap", "Baked cubemap."), _BakedCubemap); + + XSStyles.SeparatorThin(); + materialEditor.TexturePropertySingleLine(new GUIContent("Metallic Map", "Metallic Map, Metallic on Red Channel, Smoothness on Alpha Channel. \nIf Clearcoat is enabled, Clearcoat Smoothness on Green Channel, Clearcoat Reflectivity on Blue Channel."), _MetallicGlossMap); + materialEditor.TextureScaleOffsetProperty(_MetallicGlossMap); + materialEditor.ShaderProperty(_UVSetMetallic, new GUIContent("UV Set", "The UV set to use for the MetallicSmoothness Map"), 2); + materialEditor.ShaderProperty(_Metallic, new GUIContent("Metallic", "Metallic, set to 1 if using metallic map"), 2); + materialEditor.ShaderProperty(_Glossiness, new GUIContent("Smoothness", "Smoothness, set to 1 if using metallic map"), 2); + materialEditor.ShaderProperty(_ClearcoatSmoothness, new GUIContent("Clearcoat Smoothness", "Smoothness of the clearcoat."), 2); + materialEditor.ShaderProperty(_ClearcoatStrength, new GUIContent("Clearcoat Reflectivity", "The strength of the clearcoat reflection."), 2); } - - showReflection = XSStyles.ShurikenFoldout("Reflections", showReflection); - if (showReflection) + else if (_ReflectionMode.floatValue == 2) //Matcap { - materialEditor.ShaderProperty(_ReflectionMode, new GUIContent("Reflection Mode", "Reflection Mode.")); - - if (_ReflectionMode.floatValue == 0) // PBR - { - materialEditor.ShaderProperty(_ReflectionBlendMode, new GUIContent("Reflection Blend Mode", "Blend mode for reflection. Additive is Color + reflection, Multiply is Color * reflection, and subtractive is Color - reflection")); - materialEditor.ShaderProperty(_ClearCoat, new GUIContent("Clearcoat", "Clearcoat")); - - XSStyles.SeparatorThin(); - materialEditor.TexturePropertySingleLine(new GUIContent("Fallback Cubemap", " Used as fallback in 'Unity' reflection mode if reflection probe is black."), _BakedCubemap); - - XSStyles.SeparatorThin(); - materialEditor.TexturePropertySingleLine(new GUIContent("Metallic Map", "Metallic Map, Metallic on Red Channel, Smoothness on Alpha Channel. \nIf Clearcoat is enabled, Clearcoat Smoothness on Green Channel, Clearcoat Reflectivity on Blue Channel."), _MetallicGlossMap); - materialEditor.TextureScaleOffsetProperty(_MetallicGlossMap); - materialEditor.ShaderProperty(_UVSetMetallic, new GUIContent("UV Set", "The UV set to use for the Metallic Smoothness Map"), 2); - materialEditor.ShaderProperty(_Metallic, new GUIContent("Metallic", "Metallic, set to 1 if using metallic map"), 2); - materialEditor.ShaderProperty(_Glossiness, new GUIContent("Smoothness", "Smoothness, set to 1 if using metallic map"), 2); - materialEditor.ShaderProperty(_ClearcoatSmoothness, new GUIContent("Clearcoat Smoothness", "Smoothness of the clearcoat."), 2); - materialEditor.ShaderProperty(_ClearcoatStrength, new GUIContent("Clearcoat Reflectivity", "The strength of the clearcoat reflection."), 2); - } - else if (_ReflectionMode.floatValue == 1) //Baked cube - { - materialEditor.ShaderProperty(_ReflectionBlendMode, new GUIContent("Reflection Blend Mode", "Blend mode for reflection. Additive is Color + reflection, Multiply is Color * reflection, and subtractive is Color - reflection")); - materialEditor.ShaderProperty(_ClearCoat, new GUIContent("Clearcoat", "Clearcoat")); - - XSStyles.SeparatorThin(); - materialEditor.TexturePropertySingleLine(new GUIContent("Baked Cubemap", "Baked cubemap."), _BakedCubemap); - - XSStyles.SeparatorThin(); - materialEditor.TexturePropertySingleLine(new GUIContent("Metallic Map", "Metallic Map, Metallic on Red Channel, Smoothness on Alpha Channel. \nIf Clearcoat is enabled, Clearcoat Smoothness on Green Channel, Clearcoat Reflectivity on Blue Channel."), _MetallicGlossMap); - materialEditor.TextureScaleOffsetProperty(_MetallicGlossMap); - materialEditor.ShaderProperty(_UVSetMetallic, new GUIContent("UV Set", "The UV set to use for the MetallicSmoothness Map"), 2); - materialEditor.ShaderProperty(_Metallic, new GUIContent("Metallic", "Metallic, set to 1 if using metallic map"), 2); - materialEditor.ShaderProperty(_Glossiness, new GUIContent("Smoothness", "Smoothness, set to 1 if using metallic map"), 2); - materialEditor.ShaderProperty(_ClearcoatSmoothness, new GUIContent("Clearcoat Smoothness", "Smoothness of the clearcoat."), 2); - materialEditor.ShaderProperty(_ClearcoatStrength, new GUIContent("Clearcoat Reflectivity", "The strength of the clearcoat reflection."), 2); - } - else if (_ReflectionMode.floatValue == 2) //Matcap - { - materialEditor.ShaderProperty(_ReflectionBlendMode, new GUIContent("Reflection Blend Mode", "Blend mode for reflection. Additive is Color + reflection, Multiply is Color * reflection, and subtractive is Color - reflection")); - - XSStyles.SeparatorThin(); - materialEditor.TexturePropertySingleLine(new GUIContent("Matcap", "Matcap Texture"), _Matcap, _MatcapTint); - materialEditor.ShaderProperty(_Glossiness, new GUIContent("Matcap Blur", "Matcap blur, blurs the Matcap, set to 1 for full clarity"), 2); - material.SetFloat("_Metallic", 0); - material.SetFloat("_ClearCoat", 0); - material.SetTexture("_MetallicGlossMap", null); - } - if (_ReflectionMode.floatValue != 3) - { - XSStyles.SeparatorThin(); - materialEditor.TexturePropertySingleLine(new GUIContent("Reflectivity Mask", "Mask for reflections."), _ReflectivityMask); - materialEditor.TextureScaleOffsetProperty(_ReflectivityMask); - materialEditor.ShaderProperty(_UVSetReflectivity, new GUIContent("UV Set", "The UV set to use for the Reflectivity Mask"), 2); - materialEditor.ShaderProperty(_Reflectivity, new GUIContent("Reflectivity", "The strength of the reflections."), 2); - } - if(_ReflectionMode.floatValue == 3) - { - material.SetFloat("_Metallic", 0); - material.SetFloat("_ReflectionBlendMode", 0); - material.SetFloat("_ClearCoat", 0); - } + materialEditor.ShaderProperty(_ReflectionBlendMode, new GUIContent("Reflection Blend Mode", "Blend mode for reflection. Additive is Color + reflection, Multiply is Color * reflection, and subtractive is Color - reflection")); + + XSStyles.SeparatorThin(); + materialEditor.TexturePropertySingleLine(new GUIContent("Matcap", "Matcap Texture"), _Matcap, _MatcapTint); + materialEditor.ShaderProperty(_Glossiness, new GUIContent("Matcap Blur", "Matcap blur, blurs the Matcap, set to 1 for full clarity"), 2); + material.SetFloat("_Metallic", 0); + material.SetFloat("_ClearCoat", 0); + material.SetTexture("_MetallicGlossMap", null); } - - showEmission = XSStyles.ShurikenFoldout("Emission", showEmission); - if (showEmission) + if (_ReflectionMode.floatValue != 3) { - materialEditor.TexturePropertySingleLine(new GUIContent("Emission Map", "Emissive map. White to black, unless you want multiple colors."), _EmissionMap, _EmissionColor); - materialEditor.TextureScaleOffsetProperty(_EmissionMap); - materialEditor.ShaderProperty(_UVSetEmission, new GUIContent("UV Set", "The UV set to use for the Emission Map"), 2); - materialEditor.ShaderProperty(_EmissionToDiffuse, new GUIContent("Tint To Diffuse", "Tints the emission to the Diffuse Color"), 2); - XSStyles.SeparatorThin(); - materialEditor.ShaderProperty(_ScaleWithLight, new GUIContent("Scale w/ Light", "Scales the emission intensity based on how dark or bright the environment is.")); - if(_ScaleWithLight.floatValue == 0) - materialEditor.ShaderProperty(_ScaleWithLightSensitivity, new GUIContent("Scaling Sensitivity", "How agressively the emission should scale with the light.")); + materialEditor.TexturePropertySingleLine(new GUIContent("Reflectivity Mask", "Mask for reflections."), _ReflectivityMask); + materialEditor.TextureScaleOffsetProperty(_ReflectivityMask); + materialEditor.ShaderProperty(_UVSetReflectivity, new GUIContent("UV Set", "The UV set to use for the Reflectivity Mask"), 2); + materialEditor.ShaderProperty(_Reflectivity, new GUIContent("Reflectivity", "The strength of the reflections."), 2); } - - showRimlight = XSStyles.ShurikenFoldout("Rimlight", showRimlight); - if (showRimlight) + if(_ReflectionMode.floatValue == 3) { - materialEditor.ShaderProperty(_RimColor, new GUIContent("Rimlight Tint", "The Tint of the Rimlight.")); - materialEditor.ShaderProperty(_RimAlbedoTint, new GUIContent("Rim Albedo Tint", "How much the Albedo texture should effect the rimlight color.")); - materialEditor.ShaderProperty(_RimCubemapTint, new GUIContent("Rim Environment Tint", "How much the Environment cubemap should effect the rimlight color.")); - materialEditor.ShaderProperty(_RimAttenEffect, new GUIContent("Rim Attenuation Effect","How much should realtime shadows mask out the rimlight?")); - materialEditor.ShaderProperty(_RimIntensity, new GUIContent("Rimlight Intensity", "Strength of the Rimlight.")); - materialEditor.ShaderProperty(_RimRange, new GUIContent("Range", "Range of the Rim"), 2); - materialEditor.ShaderProperty(_RimThreshold, new GUIContent("Threshold", "Threshold of the Rim"), 2); - materialEditor.ShaderProperty(_RimSharpness, new GUIContent("Sharpness", "Sharpness of the Rim"), 2); + material.SetFloat("_Metallic", 0); + material.SetFloat("_ReflectionBlendMode", 0); + material.SetFloat("_ClearCoat", 0); } + } + } - showSubsurface = XSStyles.ShurikenFoldout("Subsurface Scattering", showSubsurface); - if (showSubsurface) - { - materialEditor.TexturePropertySingleLine(new GUIContent("Thickness Map", "Thickness Map, used to mask areas where subsurface can happen"), _ThicknessMap); - materialEditor.TextureScaleOffsetProperty(_ThicknessMap); - materialEditor.ShaderProperty(_UVSetThickness, new GUIContent("UV Set", "The UV set to use for the Thickness Map"), 2); - XSStyles.constrainedShaderProperty(materialEditor, _SSColor, new GUIContent("Subsurface Color", "Subsurface Scattering Color"), 2); - materialEditor.ShaderProperty(_SSDistortion, new GUIContent("Subsurface Distortion", "How much the subsurface should follow the normals of the mesh and/or normal map."), 2); - materialEditor.ShaderProperty(_SSPower, new GUIContent("Subsurface Power", "Subsurface Power"), 2); - materialEditor.ShaderProperty(_SSScale, new GUIContent("Subsurface Scale", "Subsurface Scale"), 2); - } + private void DrawEmissionSettings(MaterialEditor materialEditor) + { + showEmission = XSStyles.ShurikenFoldout("Emission", showEmission); + if (showEmission) + { + materialEditor.TexturePropertySingleLine(new GUIContent("Emission Map", "Emissive map. White to black, unless you want multiple colors."), _EmissionMap, _EmissionColor); + materialEditor.TextureScaleOffsetProperty(_EmissionMap); + materialEditor.ShaderProperty(_UVSetEmission, new GUIContent("UV Set", "The UV set to use for the Emission Map"), 2); + materialEditor.ShaderProperty(_EmissionToDiffuse, new GUIContent("Tint To Diffuse", "Tints the emission to the Diffuse Color"), 2); + + XSStyles.SeparatorThin(); + materialEditor.ShaderProperty(_ScaleWithLight, new GUIContent("Scale w/ Light", "Scales the emission intensity based on how dark or bright the environment is.")); + if(_ScaleWithLight.floatValue == 0) + materialEditor.ShaderProperty(_ScaleWithLightSensitivity, new GUIContent("Scaling Sensitivity", "How agressively the emission should scale with the light.")); + } + } + + private void DrawRimlightSettings(MaterialEditor materialEditor) + { + showRimlight = XSStyles.ShurikenFoldout("Rimlight", showRimlight); + if (showRimlight) + { + materialEditor.ShaderProperty(_RimColor, new GUIContent("Rimlight Tint", "The Tint of the Rimlight.")); + materialEditor.ShaderProperty(_RimAlbedoTint, new GUIContent("Rim Albedo Tint", "How much the Albedo texture should effect the rimlight color.")); + materialEditor.ShaderProperty(_RimCubemapTint, new GUIContent("Rim Environment Tint", "How much the Environment cubemap should effect the rimlight color.")); + materialEditor.ShaderProperty(_RimAttenEffect, new GUIContent("Rim Attenuation Effect","How much should realtime shadows mask out the rimlight?")); + materialEditor.ShaderProperty(_RimIntensity, new GUIContent("Rimlight Intensity", "Strength of the Rimlight.")); + materialEditor.ShaderProperty(_RimRange, new GUIContent("Range", "Range of the Rim"), 2); + materialEditor.ShaderProperty(_RimThreshold, new GUIContent("Threshold", "Threshold of the Rim"), 2); + materialEditor.ShaderProperty(_RimSharpness, new GUIContent("Sharpness", "Sharpness of the Rim"), 2); + } + } + + private void DrawTransmissionSettings(MaterialEditor materialEditor) + { + showSubsurface = XSStyles.ShurikenFoldout("Transmission", showSubsurface); + if (showSubsurface) + { + materialEditor.TexturePropertySingleLine(new GUIContent("Thickness Map", "Thickness Map, used to mask areas where transmission can happen"), _ThicknessMap); + materialEditor.TextureScaleOffsetProperty(_ThicknessMap); + materialEditor.ShaderProperty(_UVSetThickness, new GUIContent("UV Set", "The UV set to use for the Thickness Map"), 2); + XSStyles.constrainedShaderProperty(materialEditor, _SSColor, new GUIContent("Transmission Color", "Transmission Color"), 2); + materialEditor.ShaderProperty(_SSDistortion, new GUIContent("Transmission Distortion", "How much the Transmission should follow the normals of the mesh and/or normal map."), 2); + materialEditor.ShaderProperty(_SSPower, new GUIContent("Transmission Power", "Subsurface Power"), 2); + materialEditor.ShaderProperty(_SSScale, new GUIContent("Transmission Scale", "Subsurface Scale"), 2); + } + } - if (_AdvMode.floatValue == 1) + private void DrawAdvancedSettings(MaterialEditor materialEditor) + { + if (_AdvMode.floatValue == 1) + { + showAdvanced = XSStyles.ShurikenFoldout("Advanced Settings", showAdvanced); + if (showAdvanced) { - showAdvanced = XSStyles.ShurikenFoldout("Advanced Settings", showAdvanced); - if (showAdvanced) - { - materialEditor.ShaderProperty(_VertexColorAlbedo, new GUIContent("Vertex Color Albedo", "Multiplies the vertex color of the mesh by the Albedo texture to derive the final Albedo color.")); - materialEditor.ShaderProperty(_Stencil, _Stencil.displayName); - materialEditor.ShaderProperty(_StencilComp, _StencilComp.displayName); - materialEditor.ShaderProperty(_StencilOp, _StencilOp.displayName); - } + materialEditor.ShaderProperty(_VertexColorAlbedo, new GUIContent("Vertex Color Albedo", "Multiplies the vertex color of the mesh by the Albedo texture to derive the final Albedo color.")); + materialEditor.ShaderProperty(_Stencil, _Stencil.displayName); + materialEditor.ShaderProperty(_StencilComp, _StencilComp.displayName); + materialEditor.ShaderProperty(_StencilOp, _StencilOp.displayName); + + materialEditor.RenderQueueField(); } + } + } - //Plugins for Patreon releases - if(isPatreonShader) + private void DrawPatreonSettings(MaterialEditor materialEditor) + { + //Plugins for Patreon releases + if(isPatreonShader) + { + if(isEyeTracking) { - if(isEyeTracking) + showEyeTracking = XSStyles.ShurikenFoldout("Eye Tracking Settings", showEyeTracking); + if(showEyeTracking) { - showEyeTracking = XSStyles.ShurikenFoldout("Eye Tracking Settings", showEyeTracking); - if(showEyeTracking) - { - materialEditor.ShaderProperty(_LeftRightPan, new GUIContent("Left Right Adj.", "Adjusts the eyes manually left or right.")); - materialEditor.ShaderProperty(_UpDownPan, new GUIContent("Up Down Adj.", "Adjusts the eyes manually up or down.")); - - XSStyles.SeparatorThin(); - materialEditor.ShaderProperty(_AttentionSpan, new GUIContent("Attention Span", "How often should the eyes look at the target; 0 = never, 1 = always, 0.5 = half of the time.")); - materialEditor.ShaderProperty(_FollowPower, new GUIContent("Follow Power", "The influence the target has on the eye")); - materialEditor.ShaderProperty(_LookSpeed, new GUIContent("Look Speed","How fast the eye transitions to looking at the target")); - materialEditor.ShaderProperty(_Twitchyness, new GUIContent("Refocus Frequency", "How much should the eyes look around near the target?")); - - XSStyles.SeparatorThin(); - materialEditor.ShaderProperty(_IrisSize, new GUIContent("Iris Size", "Size of the iris")); - materialEditor.ShaderProperty(_FollowLimit, new GUIContent("Follow Limit", "Limits the angle from the front of the face on how far the eyes can track/rotate.")); - materialEditor.ShaderProperty(_EyeOffsetLimit, new GUIContent("Offset Limit", "Limit for how far the eyes can turn")); - } + materialEditor.ShaderProperty(_LeftRightPan, new GUIContent("Left Right Adj.", "Adjusts the eyes manually left or right.")); + materialEditor.ShaderProperty(_UpDownPan, new GUIContent("Up Down Adj.", "Adjusts the eyes manually up or down.")); + + XSStyles.SeparatorThin(); + materialEditor.ShaderProperty(_AttentionSpan, new GUIContent("Attention Span", "How often should the eyes look at the target; 0 = never, 1 = always, 0.5 = half of the time.")); + materialEditor.ShaderProperty(_FollowPower, new GUIContent("Follow Power", "The influence the target has on the eye")); + materialEditor.ShaderProperty(_LookSpeed, new GUIContent("Look Speed","How fast the eye transitions to looking at the target")); + materialEditor.ShaderProperty(_Twitchyness, new GUIContent("Refocus Frequency", "How much should the eyes look around near the target?")); + + XSStyles.SeparatorThin(); + materialEditor.ShaderProperty(_IrisSize, new GUIContent("Iris Size", "Size of the iris")); + materialEditor.ShaderProperty(_FollowLimit, new GUIContent("Follow Limit", "Limits the angle from the front of the face on how far the eyes can track/rotate.")); + materialEditor.ShaderProperty(_EyeOffsetLimit, new GUIContent("Offset Limit", "Limit for how far the eyes can turn")); } } - // - - XSStyles.DoFooter(); } + // } } \ No newline at end of file diff --git a/Main/CGIncludes/XSHelperFunctions.cginc b/Main/CGIncludes/XSHelperFunctions.cginc index b874044..192045c 100644 --- a/Main/CGIncludes/XSHelperFunctions.cginc +++ b/Main/CGIncludes/XSHelperFunctions.cginc @@ -227,6 +227,7 @@ void calcAlpha(inout XSLighting i) float d = distance(_WorldSpaceCameraPos, i.worldPos); d = smoothstep(_FadeDitherDistance, _FadeDitherDistance + 0.02, d); clip( ((1-i.cutoutMask.r) + d) - dither); + clip(i.albedo.a - dither); } else { diff --git a/Main/CGIncludes/XSShadowCaster.cginc b/Main/CGIncludes/XSShadowCaster.cginc index c3094cd..7df5c0e 100644 --- a/Main/CGIncludes/XSShadowCaster.cginc +++ b/Main/CGIncludes/XSShadowCaster.cginc @@ -17,7 +17,10 @@ uniform float4 _Color; uniform float _Cutoff; uniform sampler2D _MainTex; +uniform sampler2D _CutoutMask; uniform float4 _MainTex_ST; +uniform float _FadeDither; +uniform float _FadeDitherDistance; #ifdef UNITY_STANDARD_USE_DITHER_MASK uniform sampler3D _DitherMaskLOD; #endif @@ -39,9 +42,47 @@ struct VertexOutputShadowCaster #if defined(UNITY_STANDARD_USE_SHADOW_UVS) float2 tex : TEXCOORD1; #endif + + #if defined(Dithered) + float4 worldPos : TEXCOORD2; + float4 screenPos : TEXCOORD3; + #endif }; #endif +half2 calcScreenUVs(half4 screenPos) +{ + half2 uv = screenPos / (screenPos.w + 0.0000000001); //0.0x1 Stops division by 0 warning in console. + #if UNITY_SINGLE_PASS_STEREO + uv.xy *= half2(_ScreenParams.x * 2, _ScreenParams.y); + #else + uv.xy *= _ScreenParams.xy; + #endif + + return uv; +} + +inline half Dither8x8Bayer( int x, int y ) +{ + const half dither[ 64 ] = { + 1, 49, 13, 61, 4, 52, 16, 64, + 33, 17, 45, 29, 36, 20, 48, 32, + 9, 57, 5, 53, 12, 60, 8, 56, + 41, 25, 37, 21, 44, 28, 40, 24, + 3, 51, 15, 63, 2, 50, 14, 62, + 35, 19, 47, 31, 34, 18, 46, 30, + 11, 59, 7, 55, 10, 58, 6, 54, + 43, 27, 39, 23, 42, 26, 38, 22}; + int r = y * 8 + x; + return dither[r] / 64; +} + +half calcDither(half2 screenPos) +{ + half dither = Dither8x8Bayer(fmod(screenPos.x, 8), fmod(screenPos.y, 8)); + return dither; +} + // We have to do these dances of outputting SV_POSITION separately from the vertex shader, // and inputting VPOS in the pixel shader, since they both map to "POSITION" semantic on // some platforms, and then things don't go well. @@ -57,6 +98,11 @@ void vertShadowCaster(VertexInput v, #if defined(UNITY_STANDARD_USE_SHADOW_UVS) o.tex = TRANSFORM_TEX(v.uv0, _MainTex); #endif + + #if defined(Dithered) + o.worldPos = mul(unity_ObjectToWorld, v.vertex); + o.screenPos = ComputeScreenPos(opos); + #endif } @@ -73,7 +119,24 @@ half4 fragShadowCaster( half alpha = 1; #if defined(AlphaBlend) || defined(Dithered) || defined(AlphaToMask) || defined(Cutout) - alpha = tex2D(_MainTex, i.tex).a * _Color.a; + #if defined(Dithered) + if(_FadeDither) + { + float2 screenUV = calcScreenUVs(i.screenPos); + half dither = calcDither(screenUV.xy); + //half dither = tex3D(_DitherMaskLOD, float3(vpos.xy*0.25,alpha*0.9375)).a; + float d = distance(_WorldSpaceCameraPos, i.worldPos); + d = smoothstep(_FadeDitherDistance, _FadeDitherDistance + 0.02, d); + clip(((1-tex2D(_CutoutMask, i.tex).r) + d) - dither); + clip((tex2D(_MainTex, i.tex).a * _Color.a) - dither); + } + else + { + alpha = tex2D(_MainTex, i.tex).a * _Color.a; + } + #else + alpha = tex2D(_MainTex, i.tex).a * _Color.a; + #endif #else alpha = _Color.a; #endif diff --git a/Textures/CubeMaps/XSStudio_3Light.exr.meta b/Textures/CubeMaps/XSStudio_3Light.exr.meta index 9cc2d2a..523b0df 100644 --- a/Textures/CubeMaps/XSStudio_3Light.exr.meta +++ b/Textures/CubeMaps/XSStudio_3Light.exr.meta @@ -4,7 +4,7 @@ TextureImporter: fileIDToRecycleName: 8900000: generatedCubemap externalObjects: {} - serializedVersion: 4 + serializedVersion: 9 mipmaps: mipMapMode: 0 enableMipMap: 1 @@ -22,6 +22,8 @@ TextureImporter: heightScale: 0.25 normalMapFilter: 0 isReadable: 0 + streamingMipmaps: 1 + streamingMipmapsPriority: 0 grayScaleToAlpha: 0 generateCubemap: 6 cubemapConvolution: 1 @@ -32,7 +34,7 @@ TextureImporter: serializedVersion: 2 filterMode: 2 aniso: -1 - mipBias: -1 + mipBias: -100 wrapU: -1 wrapV: -1 wrapW: -1 @@ -52,11 +54,13 @@ TextureImporter: spriteTessellationDetail: -1 textureType: 0 textureShape: 2 + singleChannelComponent: 0 maxTextureSizeSet: 0 compressionQualitySet: 0 textureFormatSet: 0 platformSettings: - - buildTarget: DefaultTexturePlatform + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform maxTextureSize: 512 resizeAlgorithm: 0 textureFormat: -1 @@ -66,7 +70,8 @@ TextureImporter: allowsAlphaSplitting: 0 overridden: 0 androidETC2FallbackOverride: 0 - - buildTarget: Standalone + - serializedVersion: 2 + buildTarget: Standalone maxTextureSize: 512 resizeAlgorithm: 0 textureFormat: -1 @@ -81,7 +86,15 @@ TextureImporter: sprites: [] outline: [] physicsShape: [] + bones: [] + spriteID: + vertices: [] + indices: + edges: [] + weights: [] spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 userData: assetBundleName: assetBundleVariant: