// The goal of this script is to help maintenance of data that have already been produced but need to update to the latest shader code change.
// In case the shader code have change and the inspector have been update with new kind of keywords we need to regenerate the set of keywords use by the material.
// This script will remove all keyword of a material and trigger the inspector that will re-setup all the used keywords.
// It require that the inspector of the material have a static function call that update all keyword based on material properties.
[MenuItem("HDRenderPipeline/Reset all materials keywords")]
publicbooluseForwardRenderingOnly=false;// TODO: Currently there is no way to strip the extra forward shaders generated by the shaders compiler, so we can switch dynamically.
// TODO: This is the wrong way to handle resize/allocation. We can have several different camera here, mean that the loop on camera will allocate and deallocate
// the below buffer which is bad. Best is to have a set of buffer for each camera that is persistent and reallocate resource if need
// For now consider we have only one camera that go to this code, the main one.
m_SkyManager.Resize(camera.nearClipPlane,camera.farClipPlane);// TODO: Also a bad naming, here we just want to realloc texture if skyparameters change (usefull for lookdev)
layerUVMappingMask[layerIndex].colorValue=(layerIndex==0)?newColor(1.0f,0.0f,0.0f,0.0f):newColor(X,Y,Z,W);// Special case for Main Layer and Blend Mask, only UV0. As Layer0 is share by both here, need to force X to 1.0 in all case
layerUVMappingPlanar[layerIndex].floatValue=(layerUVBaseMapping==LayerUVBaseMapping.Planar)?1.0f:0.0f;// Planar have priority on UV0
layerUVMappingMask[i].colorValue=(i==0)?newColor(1.0f,0.0f,0.0f,0.0f):newColor(X,Y,Z,W);// Special case for Main Layer and Blend Mask, only UV0. As Layer0 is share by both here, need to force X to 1.0 in all case
layerUVMappingPlanar[i].floatValue=(layerUVBaseMapping==LayerUVBaseMapping.Planar)?1.0f:0.0f;// Planar have priority on UV0
publicstaticGUIContentalphaCutoffEnableText=newGUIContent("Alpha Cutoff Enable","Threshold for alpha cutoff");
publicstaticGUIContentalphaCutoffText=newGUIContent("Alpha Cutoff","Threshold for alpha cutoff");
publicstaticGUIContentdoubleSidedModeText=newGUIContent("Double Sided","This will render the two face of the objects (disable backface culling)");
publicstaticGUIContentdistortionEnableText=newGUIContent("Distortion","Enable distortion on this shader");
publicstaticGUIContentdistortionOnlyText=newGUIContent("Distortion Only","This shader will only be use to render distortion");
publicstaticGUIContentdistortionDepthTestText=newGUIContent("Distortion Depth Test","Enable the depth test for distortion");
publicstaticGUIContentdoubleSidedMirrorEnableText=newGUIContent("Mirror normal","This will mirror the normal with vertex normal plane if enabled, else flip the normal");
publicstaticGUIContenthorizonFadeText=newGUIContent("Horizon Fade (Spec occlusion)","horizon fade is use to control specular occlusion");
publicstaticGUIContentmaterialIDText=newGUIContent("Material type","Subsurface Scattering: enable for translucent materials such as skin, vegetation, fruit, marble, wax and milk.");
publicstaticGUIContentsmoothnessMapChannelText=newGUIContent("Smoothness Source","Smoothness texture and channel");
publicstaticGUIContentemissiveWarning=newGUIContent("Emissive value is animated but the material has not been configured to support emissive. Please make sure the material itself has some amount of emissive.");
publicstaticGUIContentemissiveColorWarning=newGUIContent("Ensure emissive color is non-black for emission to have effect.");
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","Tesselation displacement will take into account the object scale - Only work with uniform positive scale");
publicstaticGUIContentmaterialIDText=newGUIContent("Material type","Subsurface Scattering: enable for translucent materials such as skin, vegetation, fruit, marble, wax and milk.");
publicstaticGUIContentsubsurfaceProfileText=newGUIContent("Subsurface profile","A profile determines the shape of the blur filter.");
publicstaticGUIContentsubsurfaceRadiusText=newGUIContent("Subsurface radius","Determines the range of the blur.");
publicstaticGUIContentsubsurfaceRadiusMapText=newGUIContent("Subsurface radius map","Determines the range of the blur.");
publicstaticGUIContentthicknessText=newGUIContent("Thickness","If subsurface scattering is enabled, low values allow some light to be transmitted through the object.");
publicstaticGUIContentthicknessMapText=newGUIContent("Thickness map","If subsurface scattering is enabled, low values allow some light to be transmitted through the object.");
}
publicenumSurfaceType
{
Opaque,
Transparent
}
publicenumBlendMode
{
Lerp,
Add,
SoftAdd,
Multiply,
Premultiply
}
publicenumDoubleSidedMode
{
None,
DoubleSided,
DoubleSidedLightingFlip,
DoubleSidedLightingMirror,
publicstaticGUIContenttessellationObjectScaleText=newGUIContent("Enable object scale","Tessellation displacement will take into account the object scale - Only work with uniform positive scale");
FindCommonOptionProperties(props);// MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly
FindMaterialProperties(props);
m_MaterialEditor=materialEditor;
Materialmaterial=materialEditor.targetasMaterial;
ShaderPropertiesGUI(material);
}
// TODO: ? or remove
boolHasValidEmissiveKeyword(Materialmaterial)
{
/*
// Material animation might be out of sync with the material keyword.
// So if the emission support is disabled on the material, but the property blocks have a value that requires it, then we need to show a warning.
// (note: (Renderer MaterialPropertyBlock applies its values to emissionColorForRendering))
publicstaticGUIContentsubsurfaceProfileText=newGUIContent("Subsurface profile","A profile determines the shape of the blur filter.");
publicstaticGUIContentsubsurfaceRadiusText=newGUIContent("Subsurface radius","Determines the range of the blur.");
publicstaticGUIContentsubsurfaceRadiusMapText=newGUIContent("Subsurface radius map","Determines the range of the blur.");
publicstaticGUIContentthicknessText=newGUIContent("Thickness","If subsurface scattering is enabled, low values allow some light to be transmitted through the object.");
publicstaticGUIContentthicknessMapText=newGUIContent("Thickness map","If subsurface scattering is enabled, low values allow some light to be transmitted through the object.");
SetKeyword(material,"_NORMALMAP",material.GetTexture(kNormalMap)||material.GetTexture(kDetailMap));// With details map, we always use a normal map and Unity provide a default (0, 0, 1) normal map for ir
SetKeyword(material,"_NORMALMAP",material.GetTexture(kNormalMap)||material.GetTexture(kDetailMap));// With details map, we always use a normal map and Unity provide a default (0, 0, 1) normal map for ir
// Caution: C# code in BaseLitUI.cs call LightmapEmissionFlagsProperty() which assume that there is an existing "_EmissionColor"
// value that exist to identify if the GI emission need to be enabled.
// In our case we don't use such a mechanism but need to keep the code quiet. We declare the value and always enable it.
// TODO: Fix the code in legacy unity so we can customize the beahvior for GI
float3 _EmissionColor;
#ifndef LAYERED_LIT_SHADER
// Set of users variables
//TEXTURE2D(_CoatRoughnessMap);
//SAMPLER2D(sampler_CoatRoughnessMap);
TEXTURE2D(_DiffuseLightingMap);
SAMPLER2D(sampler_DiffuseLightingMap);
TEXTURE2D(_DistortionVectorMap);
SAMPLER2D(sampler_DistortionVectorMap);
float3 _EmissiveColor;
TEXTURE2D(_EmissiveColorMap);
SAMPLER2D(sampler_EmissiveColorMap);
float _EmissiveIntensity;
float _AlphaCutoff;
float _HorizonFade;
float _PPDMaxSamples;
float _PPDMinSamples;
float _PPDLodThreshold;
// sampler are share by texture type inside a layered material but we need to support that a particualr layer have no texture, so we take the first sampler of available texture as the share one
publicstaticGUIContentdoubleSidedModeText=newGUIContent("Double Sided","This will render the two face of the objects (disable backface culling)");
publicstaticGUIContentdoubleSidedEnableText=newGUIContent("Double Sided","This will render the two face of the objects (disable backface culling) and flip/mirror normal");
FindCommonOptionProperties(props);// MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly
m_MaterialEditor=materialEditor;
// We should always do this call at the beginning
m_MaterialEditor.serializedObject.Update();
// MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly
FindBaseMaterialProperties(props);
m_MaterialEditor=materialEditor;
}
// TODO: ? or remove
boolHasValidEmissiveKeyword(Materialmaterial)
{
/*
// Material animation might be out of sync with the material keyword.
// So if the emission support is disabled on the material, but the property blocks have a value that requires it, then we need to show a warning.
// (note: (Renderer MaterialPropertyBlock applies its values to emissionColorForRendering))
// Caution: C# code in BaseLitUI.cs call LightmapEmissionFlagsProperty() which assume that there is an existing "_EmissionColor"
// value that exist to identify if the GI emission need to be enabled.
// In our case we don't use such a mechanism but need to keep the code quiet. We declare the value and always enable it.
// TODO: Fix the code in legacy unity so we can customize the beahvior for GI
_EmissionColor("Color", Color) = (1, 1, 1)
}
HLSLINCLUDE
#pragma shader_feature _ALPHATEST_ON
#pragma shader_feature _DISTORTION_ON
#pragma shader_feature _ _DOUBLESIDED
// #pragma shader_feature _DOUBLESIDED_ON - We have no lighting, so no need to have this combination for shader, the option will just disable backface culling
publicreadonlyGUIContentsssProfileStdDev1=newGUIContent("SSS profile standard deviation #1","Determines the shape of the 1st Gaussian filter. Increases the strength and the radius of the blur of the corresponding color channel.");
publicreadonlyGUIContentsssProfileStdDev2=newGUIContent("SSS profile standard deviation #2","Determines the shape of the 2nd Gaussian filter. Increases the strength and the radius of the blur of the corresponding color channel.");
publicreadonlyGUIContentsssProfileLerpWeight=newGUIContent("SSS profile filter interpolation","Controls linear interpolation between the two Gaussian filters.");
publicreadonlyGUIContentprofilePreview=newGUIContent("Profile preview. Note that the intensity of the region in the center may be clamped.");
publicreadonlyGUIContentnumProfiles=newGUIContent("Number of profiles");
publicreadonlyGUIContentprofileStdDev1=newGUIContent("Standard deviation #1","Determines the shape of the 1st Gaussian filter. Increases the strength and the radius of the blur of the corresponding color channel.");
publicreadonlyGUIContentprofileStdDev2=newGUIContent("Standard deviation #2","Determines the shape of the 2nd Gaussian filter. Increases the strength and the radius of the blur of the corresponding color channel.");
publicreadonlyGUIContentprofileLerpWeight=newGUIContent("Filter interpolation","Controls linear interpolation between the two Gaussian filters.");
publicreadonlyGUIContentprofileTransmission=newGUIContent("Enable transmission","Toggles simulation of light passing through thin objects. Depends on the thickness of the material.");
publicreadonlyGUIContentprofileThicknessScale=newGUIContent("Thickness scale","Linearly scales the object thickness which affects the amount of transmitted lighting.");
// renderForCubemap: When rendering into a cube map, no depth buffer is available so user has to make sure not to use depth testing or the depth texture.