// There is two code here, by default the code corresponding for UNITY_GLOSS_MATCHES_MARMOSET_TOOLBAG2 was use for cloud reasons
// The other code (not marmoset) is not matching the shader code for cloud reasons.
// As none of this solution match BRDF 1 or 2, I let the Marmoset code to avoid to break current test. But ideally, all this should be rewrite to match BRDF1
if(true)
{
// from https://s3.amazonaws.com/docs.knaldtech.com/knald/1.0.0/lys_power_drops.html
// both R.L or N.H (cosine) are not linear and approach 1.0 very quickly
// since we want more resolution closer to where highlight is (close to 1)
// we warp LUT across horizontal axis
// NOTE: warp function ^4 or ^5 can be executed in the same instruction as Shlick fresnel approximation (handy for SM2.0 platforms with <=64 instr. limit)
// Ideally we want an approximation of gamma curve 2.0 to save ALU on GPU but as off now it won't match the GammaToLinear conversion of props in engine
publicstaticGUIContentmsaaContent=newGUIContent("Anti Aliasing","Controls the global anti aliasing quality. When set to disabled, MSAA will not be performed even if the camera allows it.");
// When USE_LEGACY_UNITY_MATRIX_VARIABLES is define GetWorldToViewMatrix is absolute (because it use legacy unity matrix), but if not define it use our own variable that is camera relative.
// TODO: We use GetAbsolutePositionWS(positionWS) to handle the camera relative case here but this should be part of the unity_ProbeVolumeWorldToObject matrix on C++ side (sadly we can't modify it for HDRenderPipeline...)
// This function convert the tangent space normal/tangent to world space and orthonormalize it + apply a correction of the normal if it is not pointing towards the near plane
// If there is no bent normal map provided, fallback on regular normal map
bentNormalTS = normalTS;
#endif
return bentNormalTS;
}
float ADD_IDX(GetSurfaceData)(FragInputs input, LayerTexCoord layerTexCoord, out SurfaceData surfaceData, out float3 normalTS)
float ADD_IDX(GetSurfaceData)(FragInputs input, LayerTexCoord layerTexCoord, out SurfaceData surfaceData, out float3 normalTS, out float3 bentNormalTS)
// PPD is affecting only one mapping at the same time, mean we need to execute it for each mapping (UV0, UV1, 3 times for triplanar etc..)
// We chose to not support all this case that are extremely hard to manage (for example mixing different mapping, mean it also require different tangent space that is not supported in Unity)
// 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)
// We will add smoothly the contribution of the normal map by using lower mips with help of bias sampling. InfluenceFactor must be [0..numMips] // Caution it cause banding...
// We will add smoothly the contribution of the normal map by lerping between vertex normal ( (0,0,1) in tangent space) and the actual normal from the main layer depending on the influence factor.
float maxMipBias = log2(max(_NormalMap0_TexelSize.z, _NormalMap0_TexelSize.w)); // don't do + 1 as it is for bias, not lod
return lerp(normalTS, BlendNormalRNM(normalTS, mainNormalTS), influenceFactor * inputMainLayerMask); // Multiply by inputMainLayerMask in order to avoid influence where main layer should never be present
float influenceFactor = BlendLayeredScalar(0.0, _InheritBaseColor1, _InheritBaseColor2, _InheritBaseColor3, weights) * influenceMask * inputMainLayerMask; // Multiply by inputMainLayerMask in order to avoid influence where main layer should never be present
// We want to calculate the mean color of the texture. For this we will sample a low mipmap
// Note: If per pixel displacement is enabled it mean we will fetch again the various heightmaps at the intersection location. Not sure the compiler can optimize.
// If any layer use a bent normal map, then bentNormalTS contain the interpolated result of bentnormal and normalmap (in case no bent normal are available)
// Note: the code in LitDataInternal ensure that we fallback on normal map for layer that have no bentnormal
publicstaticGUIContentbentNormalMapText=newGUIContent("Bent normal map","Use only with indirect diffuse lighting (Lightmap/lightprobe) - Cosine weighted Bent Normal Map (average unoccluded direction) (BC7/BC5/DXT5(nm))");
publicstaticGUIContentbentNormalMapOSText=newGUIContent("Bent normal map OS","Use only with indirect diffuse lighting (Lightmap/lightprobe) - Bent Normal Map (BC7/DXT1/RGB)");
publicstaticGUIContentheightMapAmplitudeText=newGUIContent("Height Map Amplitude","Height Map amplitude in world units.");
publicstaticGUIContentheightMapCenterText=newGUIContent("Height Map Center","Center of the heightmap in the texture (between 0 and 1)");
publicstaticGUIContentheightMapText=newGUIContent("Height Map (R)","Height Map.\nFor floating point textures, min, max and base value should be 0, 1 and 0.");
publicstaticGUIContentheightMapCenterText=newGUIContent("Height Map Base","Base of the heightmap in the texture (between 0 and 1)");
publicstaticGUIContentheightMapMinText=newGUIContent("Height Min (cm)","Minimum value in the heightmap (in centimeters)");
publicstaticGUIContentheightMapMaxText=newGUIContent("Height Max (cm)","Maximum value in the heightmap (in centimeters)");
publicstaticGUIContentspecularColorText=newGUIContent("Specular Color","Specular color (RGB)");
// Specular occlusion
publicstaticGUIContentenableSpecularOcclusionText=newGUIContent("Enable Specular Occlusion from Bent normal","Require cosine weighted bent normal and cosine weighted ambient occlusion. Specular occlusion for reflection probe");
publicstaticGUIContentspecularOcclusionWarning=newGUIContent("Require a cosine weighted bent normal and ambient occlusion maps");
publicstaticGUIContentemissiveColorModeText=newGUIContent("Emissive Color Usage","Use emissive color or emissive mask");
publicstaticGUIContentalbedoAffectEmissiveText=newGUIContent("Albedo Affect Emissive","Specifies whether or not the emissive color is multiplied by the albedo.");
publicstaticGUIContentnormalMapSpaceWarning=newGUIContent("Object space normal can't be use with triplanar mapping.");
publicstaticGUIContentmaterialIDText=newGUIContent("Material type","Subsurface Scattering: enable for translucent materials such as skin, vegetation, fruit, marble, wax and milk.");
publicstaticGUIContenthorizonFadeText=newGUIContent("Horizon Fade (Spec occlusion)","horizon fade is use to control specular occlusion");
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");
[Enum(UV0, 0, Planar, 4, Triplanar, 5)] _UVBase0("UV Set for base0", Float) = 0 // no UV1/2/3 for main layer (matching Lit.shader and for PPDisplacement restriction)
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3, Planar, 4, Triplanar, 5)] _UVBase0("UV Set for base0", Float) = 0 // no UV1/2/3 for main layer (matching Lit.shader and for PPDisplacement restriction)
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3, Planar, 4, Triplanar, 5)] _UVBase1("UV Set for base1", Float) = 0
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3, Planar, 4, Triplanar, 5)] _UVBase2("UV Set for base2", Float) = 0
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3, Planar, 4, Triplanar, 5)] _UVBase3("UV Set for base3", Float) = 0
[Enum(UV0, 0, Planar, 4, Triplanar, 5)] _UVBase0("UV Set for base0", Float) = 0 // no UV1/2/3 for main layer (matching Lit.shader and for PPDisplacement restriction)
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3, Planar, 4, Triplanar, 5)] _UVBase0("UV Set for base0", Float) = 0 // no UV1/2/3 for main layer (matching Lit.shader and for PPDisplacement restriction)
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3, Planar, 4, Triplanar, 5)] _UVBase1("UV Set for base1", Float) = 0
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3, Planar, 4, Triplanar, 5)] _UVBase2("UV Set for base2", Float) = 0
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3, Planar, 4, Triplanar, 5)] _UVBase3("UV Set for base3", Float) = 0
publicreadonlyGUIContentsyncButtonText=newGUIContent("Re-Synchronize Layers","Re-synchronize all layers's properties with the referenced Material");
publicreadonlyGUIContentsyncAllButtonText=newGUIContent("Re-Synchronize","Re-synchronize all layers material properties with the referenced Materials");
publicreadonlyGUIContentsyncAllButUVButtonText=newGUIContent("Re-Synchronize Without UV Mapping","Re-synchronize all but UV Mapping properties with the referenced Materials");
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 0123 tiling with object Scale","Tiling of each layers will be affected by the object scale.");
publicreadonlyGUIContentobjectScaleAffectTileText2=newGUIContent("Lock layers 123 tiling with 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.");
publicreadonlyGUIContentheightOffset=newGUIContent("Height Offset","Offset applied to the height before layering.");
publicreadonlyGUIContentheightTransition=newGUIContent("Height Transition","Size in world units of the smooth transition between layers.");
// Note: In case of IBL we are sorted from smaller to bigger projected solid angle bounds. We are not sorted by type so we can't do a 'while' approach like for area light.
for (i = 0; i < envLightCount && totalIblWeight < 1.0; ++i)
// Reflection probes are sorted by volume (in the increasing order).
// Note: In case of IBL we are sorted from smaller to bigger projected solid angle bounds. We are not sorted by type so we can't do a 'while' approach like for area light.
for (i = 0; i < envLightCount && totalIblWeight < 1.0; ++i)
// TODO: Don't know why but If we use Shader.GetGlobalTexture(HDShaderIDs._GBufferTexture0) instead of HDShaderIDs._GBufferTexture0 the screen start to flicker in SceneView...
// Need to investigate what is happening. But this may be unnecessary as development of SetGlobalTexture for compute shader have begin
// TEMP: As we are in development and have not all the setup pass we still clear the color in emissive buffer and gbuffer, but this will be removed later.
// Volume is store as 3D texture with 4 R, G, B, X set of 4 coefficient store atlas in same 3D texture. X is use for occlusion.
// TODO: the packing here is inefficient as we will fetch values far away from each other and they may not fit into the cache - Suggest we pack only RGB continuously
// TODO: The calcul of texcoord could be perform with a single matrix multicplication calcualted on C++ side that will fold probeVolumeMin and probeVolumeSizeInv into it and handle the identity case, no reasons to do it in C++ (ask Ionut about it)
// It should also handle the camera relative path (if the render pipeline use it)