sections.Add(colorSection=newUI.Material.Section(materialEditorIn,"COLOR",newGUIContent("Color","Controls for the base color of the water and transparency")));
sections.Add(underwaterSection=newUI.Material.Section(materialEditorIn,"UNDERWATER",newGUIContent("Underwater","Pertains the appearance of anything seen under the water surface. Not related to any actual underwater rendering")));
sections.Add(normalsSection=newUI.Material.Section(materialEditorIn,"NORMALS",newGUIContent("Normals","Normal maps represent the small-scale curvature of the water surface. This is used for lighting and reflections")));
sections.Add(reflectionSection=newUI.Material.Section(materialEditorIn,"REFLECTIONS",newGUIContent("Reflections","Sun specular reflection, and environment reflections (reflection probes and planar reflections)")));
sections.Add(intersectionSection=newUI.Material.Section(materialEditorIn,"INTERSECTION",newGUIContent("Intersection Foam","Draws a foam effects on opaque objects that are touching the water")));
sections.Add(wavesSection=newUI.Material.Section(materialEditorIn,"WAVES",newGUIContent("Waves","Parametric gerstner waves, which modify the surface curvature and animate the mesh's vertices")));
UI.DrawNotification(!UniversalRenderPipeline.asset,"Universal Render Pipeline is currently not active!","Show me",StylizedWaterEditor.OpenGraphicsSettings,MessageType.Error);
"Opaque texture is disabled, which is required for the material's current configuration",
"Enable",
StylizedWaterEditor.EnableOpaqueTexture,
MessageType.Error);
}
UI.DrawNotification(depthAfterTransparents&&_ZWrite.floatValue>0,"\nZWrite option (Rendering tab) is enabled & Depth Texture Mode is set to \'After Transparents\" on the default renderer\n\nWater can not render properly with this combination\n",MessageType.Error);
#if!UNITY_2023_1_OR_NEWER//OpenGLES 2.0 no longer supported at all
UI.DrawNotification("You are targeting the OpenGLES 2.0 graphics API, which is not supported. Shader will not compile on the device",MessageType.Error);
UI.DrawNotification(shaderMessages!=null,$"Shader has {shaderMessages.Length} compile errors.\n\nCheck the inspector to view them","View",()=>Selection.activeObject=targetMat.shader,MessageType.Error);
}
}
privatevoidDrawRenderFeatureNotification()
{
if(!renderFeature)
{
UI.DrawNotification(true,"The Stylized Water render feature hasn't been added to the default renderer."+
"\n\nFeatures such as Directional Caustics and Screen-space Reflections are unavailable.","Add",()=>
{
PipelineUtilities.ValidateRenderFeatureSetup<StylizedWaterRenderFeature>("Stylized Water 2");
DrawShaderProperty(_WorldSpaceUV,newGUIContent(_WorldSpaceUV.displayName,"Use either the mesh's UV or world-space position coordinates as a base for texture tiling"));
}
if(_RiverModeOn.floatValue>0)EditorGUILayout.HelpBox("Shader will use always the mesh's UV coordinates when River Mode is enabled.",MessageType.None);
UI.DrawNotification("The \"Always Refresh\" option is disabled in the scene view. Water surface animations will appear to be jumpy",messageType:MessageType.None);
DrawShaderProperty(_SlopeAngleThreshold,newGUIContent(_SlopeAngleThreshold.displayName,"Surface angle at which it is considered a slope for river-based shading"),1);
DrawShaderProperty(_SlopeAngleFalloff,newGUIContent(_SlopeAngleFalloff.displayName,"Surface angle over which the slope gradient should smoothly fade out over."),1);
EditorGUILayout.Space();
DrawShaderProperty(_SlopeStretching,newGUIContent("Slope stretching",null,"On slopes, stretches textures by this much. Creates the illusion of faster flowing water"),1);
DrawShaderProperty(_SlopeSpeed,newGUIContent("Slope speed",null,"On slopes, animation speed is multiplied by this value"),1);
UI.DrawNotification("Material must be on the Transparent render queue (2450-3500). Otherwise incurs rendering artefacts",MessageType.Error);
}
//materialEditor.DoubleSidedGIField();
EditorGUILayout.Space();
DrawShaderProperty(_Cull,newGUIContent(_Cull.displayName,"Controls which sides of the water mesh surface are rendered invisible (culled)"));
DrawShaderProperty(_ZWrite,newGUIContent("Depth writing (ZWrite)","Enable to have the water perform depth-based sorting on itself. Allows for intersecting transparent geometry. Advisable with high waves."+
"\n\nIf this is disabled, other transparent materials will either render behind or in front of the water, depending on their render queue/priority set in their materials"));
DrawShaderProperty(_ZClip,newGUIContent("Frustum clipping (ZClip)","Enable to clip the surface when it extends beyond the camera's far clipping plane. This is default for all shaders."+
"\n\nDisable to aid in creating water that expands towards the horizon."+
"\n\nNote: Effects such as edge fading and intersection foam still consider the camera's far clipping plane, this is normal."));
EditorGUILayout.Space();
DrawShaderProperty(_DisableDepthTexture,newGUIContent("Disable depth texture","Depth texture is made available by the render pipeline and is used to measure the distance between the water surface and opaque geometry behind/in front of it, as well as their position.\n\n"+
"This is used for a variety of effects, such as the color gradient, intersection effects, caustics and refraction."+
"\n\nDisable if targeting a bare bones rendering set up without a depth pre-pass present."));
EditorGUILayout.Space();
EditorGUI.BeginChangeCheck();
vartessellationTooltip="Dynamically subdivides the mesh's triangles to create denser topology near the camera."+
"\n\nThis allows for more detailed wave animations."+
"\n\nOnly supported on GPUs with Shader Model 4.6+ and the Metal graphics API on Mac/iOS. Should it fail, it will fall back to the non-tessellated shader automatically";
Debug.Log("Failed to find tessellation shader with name: "+newShaderName);
}
#endif
}
}
if(tesselationEnabled&&_TessValue!=null)
{
UI.DrawNotification(_FlatShadingOn.floatValue>0||_FlatShadingOn.hasMixedValue,"Flat shading is enabled, tessellation should not be used to achieve the desired effect",MessageType.Warning);
DrawShaderProperty(_LightingOn,newGUIContent("Enable lighting","Color from lights and ambient light (Flat/Gradient/Skybox) will affect the material. If using overall Unlit shaders in the scene, or fixed lighting, disable to skip lighting calculations."));
DrawShaderProperty(_FlatShadingOn,newGUIContent("Flat/low-poly shading","When enabled, normals are calculated per mesh face, resulting in a faceted appearance (low poly look). The mesh needs sufficient vertices to really sell the effect (eg. a quad mesh won't do)"));
UI.DrawNotification(_FlatShadingOn.floatValue>0&&tesselationEnabled,"Tessellation is enabled, it should not be used to achieve the desired effect",MessageType.Warning);
UI.DrawNotification(_FlatShadingOn.floatValue>0f&&_WavesOn.floatValue==0f,"Flat shading has little effect if waves are disabled",MessageType.Warning);
DrawShaderProperty(_ReceiveShadows,newGUIContent("Receive shadows","Allows the material to receive realtime shadows from other objects.\n\nAlso enables light-based effects such as reflections and caustics to hide themselves in shadows."));
DrawShaderProperty(_NormalStrength,newGUIContent("Diffuse lighting","Controls how much the curvature of the normal map affects directional lighting"));
DrawShaderProperty(_SparkleIntensity,newGUIContent("Intensity","The color/intensity of the main directional light is multiplied on top of this."));
DrawShaderProperty(_SparkleSize,"Size");
}
UI.DrawNotification(_NormalMapOn.floatValue==0f,"Sparkles require the normal map feature to be enabled",MessageType.None);
EditorGUILayout.Space();
DrawShaderProperty(_TranslucencyOn,newGUIContent("Translucency","Creates the appearance of sun light passing through the water and scattering.\n\nNote that this is mostly visible at grazing light angle"));
DrawShaderProperty(_TranslucencyStrength,newGUIContent("Intensity","Acts as a multiplier for the light's intensity"),1);
DrawShaderProperty(_TranslucencyExp,newGUIContent("Exponent","Essentially controls the width/scale of the effect"),1);
DrawShaderProperty(_TranslucencyCurvatureMask,newGUIContent("Curvature mask","Masks the effect by the orientation of the surface. Surfaces facing away from the sun will receive less of an effect. On sphere mesh, this would push the effect towards the edges/silhouette."),1);
EditorGUILayout.Space();
DrawShaderProperty(_TranslucencyStrengthDirect,newGUIContent("Direct Light Intensity","Simulate light scattering from direct sun light. Typically seen in glacial lakes."),1);
UI.Material.DrawColorField(_BaseColor,true,_BaseColor.displayName,"Base water color, alpha channel controls transparency");
UI.Material.DrawColorField(_ShallowColor,true,_ShallowColor.displayName,"Water color in shallow areas, alpha channel controls transparency. Note that the caustics effect is visible here, setting the alpha to 100% hides caustics");
DrawShaderProperty(_DepthVertical,newGUIContent("Distance Depth","Distance measured from the water surface, to the geometry behind it, along the camera's viewing angle. Water turns denser the more the camera looks along the water surface, and through it."));
DrawShaderProperty(_DepthHorizontal,newGUIContent("Vertical Depth","Density as measured from the water surface, straight down. This acts as a type of artificial height fog."));
DrawShaderProperty(_DepthExp,newGUIContent("Exponential",tooltip:"Exponential depth works best for shallow water and relatively flat shores"),1);
DrawShaderProperty(_ColorAbsorption,newGUIContent(_ColorAbsorption.displayName,"Darkens the underwater color, based on the water's depth. This is a particular physical property of water that contributes to a realistic appearance."));
}
if(_RefractionOn.floatValue==0)EditorGUILayout.HelpBox("Requires the Refraction feature to be enabled",MessageType.None);
EditorGUILayout.Space();
}
DrawShaderProperty(_VertexColorDepth,newGUIContent("Vertex color depth (G)","The Green vertex color channel subtracts (visual) depth from the water, making it appear shallow. When River Mode is enabled, this controls the complete opacity of the material instead"));
UI.Material.DrawFloatField(_EdgeFade,"Edge fading","Fades out the water where it intersects with opaque geometry.\n\nRequires the depth texture option to be enabled");
DrawShaderProperty(_NormalMapOn,newGUIContent("Enable","Normals add small-scale detail curvature to the water surface, which in turn is used in various lighting techniques"));
//UI.Material.DrawFloatTicker(_NormalTiling, tooltip:"Determines how often the texture repeats over the UV coordinates. Smaller values result in the texture being stretched larger, higher numbers means it becomes smaller");
UI.Material.DrawFloatTicker(_NormalSubTiling,"Sub-layer (multiplier)","The effect uses a 2nd texture sample, for variety. This value controls the speed of this layer");
EditorGUI.indentLevel--;
UI.Material.DrawFloatTicker(_NormalSpeed,tooltip:"[Multiplied by the animation speed set under the General tab]\n\nControls how fast the texture moves in the animation direction. A negative value (-) makes it move in the opposite direction",showReverse:true);
EditorGUI.indentLevel++;
UI.Material.DrawFloatTicker(_NormalSubSpeed,"Sub-layer (multiplier)",tooltip:"Multiplier for the 2nd texture sample.",showReverse:true);
DrawShaderProperty(_DistanceNormalsOn,newGUIContent("Distance normals","Resamples normals in the distance, at a larger scale. At the cost some additional shading calculations, tiling artifacts can be greatly reduced"));
UI.Material.DrawMinMaxSlider(_DistanceNormalsFadeDist,0f,500,"Blend distance range",tooltip:"Min/max distance range (from the camera) the effect should to blend in");
DrawShaderProperty(_CausticsOn,newGUIContent("Caustics","Caustics are normally a complex optical effect, created by light passing through a surface and refracting."+
"\n\nA static caustics texture can be used to approximate this effect by projecting it onto the opaque geometry behind the water surface."+
"\n\nIf Advanced shading is enabled, point- and spot lights also create this effect."));
UI.Material.DrawFloatField(_CausticsBrightness,"Brightness","The intensity of the incoming light controls how strongly the effect is visible. This parameter acts as a multiplier.");
UI.DrawNotification("Caustics project on the water surface itself, because the \"Disable depth texture\" option is enabled.",MessageType.None);
UI.DrawNotification(_VertexColorDepth.floatValue==0&&!_VertexColorDepth.hasMixedValue,"\nDepth texture is disabled, so water has no means of creating shallow water. Caustics will not seem visible.\n\nEnable the use of vertex color opacity to manually paint shallow water.\n","Enable",()=>_VertexColorDepth.floatValue=1);
}
EditorGUILayout.Space();
DrawShaderProperty(_RefractionOn,newGUIContent("Refraction","Simulates how the surface behind the water appears distorted, because the light passes through the water's curvy surface"));
UI.DrawNotification(UniversalRenderPipeline.asset.opaqueDownsampling!=Downsampling.None,"Opaque texture is rendering at a lower resolution, water may appear blurry");
UI.DrawNotification("Refraction will have little effect if normals and waves are disabled",MessageType.Warning);
}
DrawShaderProperty(_RefractionStrength,newGUIContent("Strength","Note: Distortion strength is influenced by the strength of the normal map texture"),1);
"Creates a prims-like rainbow effect where the refraction is the strongest. Controls the maximum offset, and is based on refraction strength (both the parameter and the context)\n\nCan create some discrepancies in the underwater fog!"));
}
}
else
{
if(underwaterRenderingInstalled)
{
UI.DrawNotification("[Underwater Rendering] It's recommended to keep refraction enabled.\n\n It is performed anyway for the underwater surface",MessageType.Warning);
DrawShaderProperty(_UnderwaterSurfaceSmoothness,newGUIContent("Surface Smoothness","Controls how distorted everything above the water appears from below"));
DrawShaderProperty(_UnderwaterRefractionOffset,newGUIContent("Refraction offset","Creates a wide \"circle\" of visible air above the camera. Pushes it further away from the camera"));
//UI.Material.DrawFloatTicker(_FoamTiling, tooltip:"Determines how often the texture repeats over the UV coordinates. Smaller values result in the texture being stretched larger, higher numbers means it becomes smaller");
UI.Material.DrawFloatTicker(_FoamSubTiling,"Sub-layer (multiplier)","The effect uses a 2nd texture sample, for variety. This value controls the speed of this layer");
EditorGUI.indentLevel--;
UI.Material.DrawFloatTicker(_FoamSpeed,tooltip:"[Multiplied by the animation speed set under the General tab]\n\nControls how fast the texture moves in the animation direction. A negative value (-) makes it move in the opposite direction",showReverse:true);
EditorGUI.indentLevel++;
UI.Material.DrawFloatTicker(_FoamSubSpeed,"Sub-layer (multiplier)",tooltip:"Multiplier for the 2nd texture sample.",showReverse:true);
UI.Material.DrawFloatTicker(_FoamTilingDynamic,tooltip:"Determines how often the texture repeats over the UV coordinates. Smaller values result in the texture being stretched larger, higher numbers means it becomes smaller");
EditorGUI.indentLevel++;
UI.Material.DrawFloatTicker(_FoamSubTilingDynamic,"Sub-layer (multiplier)","The effect uses a 2nd texture sample, for variety. This value controls the speed of this layer");
EditorGUI.indentLevel--;
UI.Material.DrawFloatTicker(_FoamSpeedDynamic,tooltip:"[Multiplied by the animation speed set under the General tab]\n\nControls how fast the texture moves in the animation direction. A negative value (-) makes it move in the opposite direction",showReverse:true);
EditorGUI.indentLevel++;
UI.Material.DrawFloatTicker(_FoamSubSpeedDynamic,"Sub-layer (multiplier)",tooltip:"Multiplier for the 2nd texture sample.",showReverse:true);
EditorGUI.indentLevel--;
}
EditorGUILayout.Space();
DrawShaderProperty(_FoamDistortion,newGUIContent(_FoamDistortion.displayName,"Distorts the foam by the amount of vertical displacement, such as that created by waves"));
DrawShaderProperty(_IntersectionSource,newGUIContent("Gradient source",null,"The effect requires a linear gradient to work with, something that represents the distance from the intersection point out towards the water."+
"\n\nThis parameter control what's being used as the source to approximate this information."));
DrawShaderProperty(_IntersectionClipping,newGUIContent(_IntersectionClipping.displayName,"Clips the effect based on the texture's gradient."));
UI.Material.DrawFloatTicker(_IntersectionRippleDist,_IntersectionRippleDist.displayName,"Distance between each ripples over the total intersection length");
DrawShaderProperty(_IntersectionRippleStrength,newGUIContent(_IntersectionRippleStrength.displayName,"Sets how much the ripples should be blended in with the effect"));
DrawShaderProperty(_SunReflectionSize,newGUIContent("Size","Determines how wide the reflection appears"));
DrawShaderProperty(_SunReflectionDistortion,newGUIContent("Distortion","Distortion is largely influenced by the strength of the normal map texture and wave curvature"));
DrawShaderProperty(_PointSpotLightReflectionSize,newGUIContent("Size","Specular reflection size for point/spot lights"));
DrawShaderProperty(_PointSpotLightReflectionDistortion,newGUIContent("Distortion","Distortion is largely influenced by the strength of the normal map texture and wave curvature"));
DrawShaderProperty(_EnvironmentReflectionsOn,newGUIContent("Enable","Enable reflections from the skybox, reflection probes, screen-space- and planar -reflections."));
UI.DrawNotification("Lighting settings: Environment reflections source is set to \"Custom\" without a cubemap assigned. No reflections may be visible",MessageType.Warning);
DrawShaderProperty(_ReflectionLighting,newGUIContent(_ReflectionLighting.displayName,"Technically, lighting shouldn't be applied to the reflected image. If reflections aren't updated in realtime, but lighting is, this is still beneficial.\n\nThis controls how much lighting affects the reflection"));
UI.DrawNotification("Reflection probes do not work with orthographic cameras until Unity 2021.2.0 (URP 12.0.0)",MessageType.Warning);
}
#endif
EditorGUILayout.Space();
DrawShaderProperty(_ReflectionFresnel,newGUIContent(_ReflectionFresnel.displayName,"Masks the reflection by the viewing angle in relationship to the surface (including wave curvature), which is more true to nature (known as fresnel)"));
DrawShaderProperty(_ReflectionDistortion,newGUIContent(_ReflectionDistortion.displayName,"Distorts the reflection by the wave normals and normal map"));
DrawShaderProperty(_ReflectionBlur,newGUIContent(_ReflectionBlur.displayName,"Blurs the reflection probe, this can be used for a more general reflection of colors"));
UI.DrawNotification(_RiverModeOn.floatValue>0||_RiverModeOn.hasMixedValue,"Waves are automatically disabled when River Mode is enabled",MessageType.Info);
DrawShaderProperty(_VertexColorWaveFlattening,newGUIContent("Vertex color flattening (B)",
"The Blue vertex color channel flattens waves\n\nNote: this does NOT affect buoyancy calculations!"));
DrawShaderProperty(_WaveHeight,newGUIContent(_WaveHeight.displayName,"Waves will always push the water up from its base height, meaning waves never have a negative height"));
UI.Material.DrawIntSlider(_WaveCount,
tooltip:
"Repeats the wave calculation X number of times, but with smaller waves each time");
DrawShaderProperty(_WaveDistance,newGUIContent(_WaveDistance.displayName,"Distance between waves"));
DrawShaderProperty(_WaveSteepness,newGUIContent(_WaveSteepness.displayName,"Sharpness, depending on other settings here, a too high value will causes vertices to overlap. This also creates horizontal movement"));
DrawShaderProperty(_WaveNormalStr,newGUIContent(_WaveNormalStr.displayName,"Normals affect how curved the surface is perceived for direct and ambient light. Without this, the water will appear flat"));
UI.Material.DrawMinMaxSlider(_WaveFadeDistance,0f,500f,"Fade Distance","Fades out the waves between the start- and end distance. This can avoid tiling artifacts in the distance");
if(EditorUtility.DisplayDialog(AssetInfo.ASSET_NAME,$"The selected water material needs to be updated to the format of v{AssetInfo.INSTALLED_VERSION}."+
"\n\nAfter this automatic process, the material UI will support multi-selection and the Material Variants feature introduced in Unity 2022.1","OK"))
{
//Ensure keyword states are synced with their float property counterpart