publicreadonlyGUIContentvertexColorModeText=newGUIContent("Vertex Color Mode","Mode multiply: vertex color is multiply with the mask. Mode additive: vertex color values are remapped between -1 and 1 and added to the mask (neutral at 0.5 vertex color).");
publicreadonlyGUIContentlayerCountText=newGUIContent("Layer Count","Number of layers.");
publicreadonlyGUIContentlayerTilingBlendMaskText=newGUIContent("Tiling","Tiling for the blend mask.");
publicreadonlyGUIContentobjectScaleAffectTileText=newGUIContent("Tiling 0123 follow object Scale","Tiling will be affected by the object scale.");
publicreadonlyGUIContentobjectScaleAffectTileText2=newGUIContent("Tiling 123 follow object Scale","Tiling will be affected by the object scale.");
publicreadonlyGUIContentobjectScaleAffectTileText=newGUIContent("Lock layers tiling and object Scale","Tiling of each layers will be affected by the object scale.");
publicreadonlyGUIContentobjectScaleAffectTileText2=newGUIContent("Lock influenced layers tiling and object Scale","Tiling of each influenced layers (all except main layer) will be affected by the object scale.");
publicreadonlyGUIContentlayerTexWorldScaleText=newGUIContent("World Scale","Tiling factor applied to Planar/Trilinear mapping");
publicreadonlyGUIContentUVBlendMaskText=newGUIContent("BlendMask UV Mapping","Base UV Mapping mode of the layer.");
publicstaticGUIContenthorizonFadeText=newGUIContent("Horizon Fade (Spec occlusion)","horizon fade is use to control specular occlusion");
// Per pixel displacement
publicstaticGUIContentenablePerPixelDisplacementText=newGUIContent("Enable Per Pixel Displacement","");
publicstaticGUIContentppdMinSamplesText=newGUIContent("Minimum samples","Minimum samples to use with per pixel displacement mapping");
publicstaticGUIContentppdMaxSamplesText=newGUIContent("Maximum samples","Maximum samples to use with per pixel displacement mapping");
publicstaticGUIContentppdLodThresholdText=newGUIContent("Fading LOD start","Starting Lod where the parallax occlusion mapping effect start to disappear");
publicstaticGUIContentenablePerPixelDisplacementText=newGUIContent("Enable Per Pixel Displacement","Per pixel displacement work best with flat surfaces. This is an expensive features and should be enable wisely. Typical use case is paved road.");
publicstaticGUIContentppdMinSamplesText=newGUIContent("Minimum steps","Minimum steps (texture sample) to use with per pixel displacement mapping");
publicstaticGUIContentppdMaxSamplesText=newGUIContent("Maximum steps","Maximum steps (texture sample) to use with per pixel displacement mapping");
publicstaticGUIContentppdLodThresholdText=newGUIContent("Fading mip level start","Starting heightmap mipmap lod number where the parallax occlusion mapping effect start to disappear");
publicstaticGUIContenttessellationFactorTriangleSizeText=newGUIContent("Triangle size","Desired screen space sized of triangle (in pixel). Smaller value mean smaller triangle.");
publicstaticGUIContenttessellationShapeFactorText=newGUIContent("Shape factor","Strength of Phong tessellation shape (lerp factor)");
publicstaticGUIContenttessellationBackFaceCullEpsilonText=newGUIContent("Triangle culling Epsilon","If -1.0 back face culling is enabled for tessellation, higher number mean more aggressive culling and better performance");
publicstaticGUIContenttessellationObjectScaleText=newGUIContent("Enable object scale","Tessellation displacement will take into account the object scale - Only work with uniform positive scale");
publicstaticGUIContenttessellationTilingScaleText=newGUIContent("Enable tiling scale","Tessellation displacement will take into account the tiling scale - Only work with uniform positive scale");
publicstaticGUIContenttessellationObjectScaleText=newGUIContent("Lock with object scale","Tessellation displacement will take into account the object scale - Only work with uniform positive scale");
publicstaticGUIContenttessellationTilingScaleText=newGUIContent("Lock with heightmap tiling","Tessellation displacement will take into account the tiling scale - Only work with uniform positive scale");
// The epsilon here also has to be bigger than the epsilon in the next computation.
float transition = max(_HeightTransition, 1e-5);
// The goal here is to have all but the heighest layer at negative heights, then we add the transition so that if the next heighest layer is near transition it will have a positive value.
// Then we clamp this to zero and normalize everything so that heighest layer has a value of 1.
// The goal here is to have all but the highest layer at negative heights, then we add the transition so that if the next highest layer is near transition it will have a positive value.
// Then we clamp this to zero and normalize everything so that highest layer has a value of 1.
maskedHeights = maskedHeights - maxHeight.xxxx;
// We need to add an epsilon here for active layers (hence the blendMask again) so that at least a layer shows up if everything's too low.
float4 opacityAsDensity = saturate((inputAlphaMask - (float4(1.0, 1.0, 1.0, 1.0) - blendMasks.argb)) * 20.0); // 20.0 is the number of steps in inputAlphaMask (Density mask. We decided 20 empirically)