Debug.Log(string.Format("There's no upgrader to convert {0} shader to selected pipeline",material.shader.name));
Debug.Log(string.Format("{0} material was not upgraded. There's no upgrader to convert {1} shader to selected pipeline",material.name,material.shader.name));
if(!EditorUtility.DisplayDialog("Material Upgrader",string.Format("The upgrade will possibly overwrite all the {0} selected material settings",selection.Length)+
"Be sure to have a project backup before proceeding","Proceed","Cancel"))
if(!EditorUtility.DisplayDialog("Material Upgrader",string.Format("The upgrade will overwrite {0} selected material{1}. ",selection.Length,(selection.Length>1)?"s":"")+
#pragma only_renderers d3d11 ps4 vulkan metal // TEMP: until we go further in dev
#pragma only_renderers d3d11 ps4 xboxone vulkan metal
#pragma vertex Vert
#pragma fragment Frag
#include "ShaderLibrary/Common.hlsl"
#include "ShaderLibrary/Color.hlsl"
// CAUTION: In case deferred lighting need to support various lighting model statically, we will require to do multicompile with different define like UNITY_MATERIAL_LIT
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl
DebugMenuManager.instance.AddDebugItem<bool>("HDRP","Enable Big Tile",()=>m_Asset.tileSettings.enableBigTilePrepass,(value)=>m_Asset.tileSettings.enableBigTilePrepass=(bool)value,DebugItemFlag.RuntimeOnly);
DebugMenuManager.instance.AddDebugItem<bool>("HDRP","Enable Material Classification",()=>m_Asset.tileSettings.enableComputeMaterialVariants,(value)=>m_Asset.tileSettings.enableComputeMaterialVariants=(bool)value,DebugItemFlag.RuntimeOnly);
DebugMenuManager.instance.AddDebugItem<bool>("HDRP","Enable Big Tile",()=>m_Asset.lightLoopSettings.enableBigTilePrepass,(value)=>m_Asset.lightLoopSettings.enableBigTilePrepass=(bool)value,DebugItemFlag.RuntimeOnly);
DebugMenuManager.instance.AddDebugItem<bool>("HDRP","Enable Material Classification",()=>m_Asset.lightLoopSettings.enableComputeMaterialVariants,(value)=>m_Asset.lightLoopSettings.enableComputeMaterialVariants=(bool)value,DebugItemFlag.RuntimeOnly);
// Note: Legacy Unity behave like this for ShadowMask
// When you select ShadowMask in Lighting panel it recompile shaders on the fly with the SHADOW_MASK keyword.
// However there is no C# function that we can query to know what mode have been select in Lighting Panel and it will be wrong anyway. Lighting Panel setup what will be the next bake mode. But until light is bake, it is wrong.
// Currently to know if you need shadow mask you need to go through all visible lights (of CullResult), check the LightBakingOutput struct and look at lightmapBakeType/mixedLightingMode. If one light have shadow mask bake mode, then you need shadow mask features (i.e extra Gbuffer).
// It mean that when we build a standalone player, if we detect a light with bake shadow mask, we generate all shader variant (with and without shadow mask) and at runtime, when a bake shadow mask light is visible, we dynamically allocate an extra GBuffer and switch the shader.
// So the first thing to do is to go through all the light: PrepareLightsForGPU
// Note: Legacy Unity behave like this for ShadowMask
// When you select ShadowMask in Lighting panel it recompile shaders on the fly with the SHADOW_MASK keyword.
// However there is no C# function that we can query to know what mode have been select in Lighting Panel and it will be wrong anyway. Lighting Panel setup what will be the next bake mode. But until light is bake, it is wrong.
// Currently to know if you need shadow mask you need to go through all visible lights (of CullResult), check the LightBakingOutput struct and look at lightmapBakeType/mixedLightingMode. If one light have shadow mask bake mode, then you need shadow mask features (i.e extra Gbuffer).
// It mean that when we build a standalone player, if we detect a light with bake shadow mask, we generate all shader variant (with and without shadow mask) and at runtime, when a bake shadow mask light is visible, we dynamically allocate an extra GBuffer and switch the shader.
// So the first thing to do is to go through all the light: PrepareLightsForGPU
// In both forward and deferred, everything opaque should have been rendered at this point so we can safely copy the depth buffer for later processing.
// In both forward and deferred, everything opaque should have been rendered at this point so we can safely copy the depth buffer for later processing.
CopyDepthBufferIfNeeded(cmd);
// Required for the SSS and the shader feature classification pass.
// Caution: We require sun light here as some sky use the sun light to render, mean UpdateSkyEnvironment
// must be call after BuildGPULightLists.
// TODO: Try to arrange code so we can trigger this call earlier and use async compute here to run sky convolution during other passes (once we move convolution shader to compute).
UpdateSkyEnvironment(hdCamera,cmd);
// Render the volumetric lighting.
// The pass only requires the volume properties and the light list, and can run async.
// Caution: We require sun light here as some sky use the sun light to render, mean UpdateSkyEnvironment
// must be call after BuildGPULightLists.
// TODO: Try to arrange code so we can trigger this call earlier and use async compute here to run sky convolution during other passes (once we move convolution shader to compute).
RenderVelocity(m_CullResults,hdCamera,renderContext,cmd);// Note we may have to render velocity earlier if we do temporalAO, temporal volumetric etc... Mean we will not take into account forward opaque in case of deferred rendering ?
// Rendering distortion here have off course lot of artifact.
// But resolving at each objects that write in distortion is not possible (need to sort transparent, render those that do not distort, then resolve, then etc...)
// Instead we chose to apply distortion at the end after we cumulate distortion vector and desired blurriness.
// Make sure to unbind every render texture here because in the next iteration of the loop we might have to reallocate render texture (if the camera size is different)
RenderVelocity(m_CullResults,hdCamera,renderContext,cmd);// Note we may have to render velocity earlier if we do temporalAO, temporal volumetric etc... Mean we will not take into account forward opaque in case of deferred rendering ?
// Rendering distortion here have off course lot of artifact.
// But resolving at each objects that write in distortion is not possible (need to sort transparent, render those that do not distort, then resolve, then etc...)
// Instead we chose to apply distortion at the end after we cumulate distortion vector and desired blurriness.
// Make sure to unbind every render texture here because in the next iteration of the loop we might have to reallocate render texture (if the camera size is different)
// We still need to bind correctly default camera target with our depth buffer in case we are currently rendering scene view. It should be the last camera here
// We still need to bind correctly default camera target with our depth buffer in case we are currently rendering scene view. It should be the last camera here
// bind depth surface for editor grid/gizmo/selection rendering
// In case of deferred renderer, we can have forward opaque material. These materials need to be render in the depth buffer to correctly build the light list.
// And they will tag the stencil to not be lit during the deferred lighting pass.
// It must also have a "DepthForwardOnly" and no "DepthOnly" pass as forward material (either deferred or forward only rendering) have always a depth pass.
// In case of forward only rendering we have a depth prepass. In case of deferred renderer, it is optional
// We render first the opaque object as opaque alpha tested are more costly to render and could be reject by early-z (but not Hi-z as it is disable with clip instruction)
// This is handled automatically with the RenderQueue value (OpaqueAlphaTested have a different value and thus are sorted after Opaque)
// RenderGBuffer do the gbuffer pass. This is solely call with deferred. If we use a depth prepass, then the depth prepass will perform the alpha testing for opaque apha tested and we don't need to do it anymore
// during Gbuffer pass. This is handled in the shader and the depth test (equal and no depth write) is done here.
publicreadonlyGUIContentrange=newGUIContent("Range","Controls how far the light is emitted from the center of the object.");
publicreadonlyGUIContentcolor=newGUIContent("Color","Controls the color being emitted by the light.");
publicreadonlyGUIContentspotAngle=newGUIContent("Angle","Controls the angle in degrees at the base of a Spot light's cone.");
publicreadonlyGUIContentuseColorTemperature=newGUIContent("Use Color Temperature","Choose between RGB and temperature mode for light's color.");
publicreadonlyGUIContentcolorFilter=newGUIContent("Filter","A colored gel can be put in front of the light source to tint the light.");
publicreadonlyGUIContentcolorTemperature=newGUIContent("Temperature","Also known as CCT (Correlated color temperature). The color temperature of the electromagnetic radiation emitted from an ideal black body is defined as its surface temperature in Kelvin. White is 6500K");
publicreadonlyGUIContentintensity=newGUIContent("Intensity","Controls the brightness of the light. Light color is multiplied by this value.");
publicreadonlyGUIContentlightmappingMode=newGUIContent("Mode","Specifies the light mode used to determine if and how a light will be baked. Possible modes are Baked, Mixed, and Realtime.");
publicreadonlyGUIContentlightBounceIntensity=newGUIContent("Indirect Multiplier","Controls the intensity of indirect light being contributed to the scene. A value of 0 will cause Realtime lights to be removed from realtime global illumination and Baked and Mixed lights to no longer emit indirect lighting. Has no effect when both Realtime and Baked Global Illumination are disabled.");
publicreadonlyGUIContentcookie=newGUIContent("Cookie","Specifies the Texture mask to cast shadows, create silhouettes, or patterned illumination for the light.");
publicreadonlyGUIContentcookieSizeX=newGUIContent("Size X","Controls the size of the cookie mask currently assigned to the light.");
publicreadonlyGUIContentcookieSizeY=newGUIContent("Size Y","Controls the size of the cookie mask currently assigned to the light.");
publicreadonlyGUIContentshadowBias=newGUIContent("Bias","Controls the distance at which the shadows will be pushed away from the light. Useful for avoiding false self-shadowing artifacts.");
publicreadonlyGUIContentbakedShadowAngle=newGUIContent("Baked Shadow Angle","Controls the amount of artificial softening applied to the edges of shadows cast by directional lights.");
publicreadonlyGUIContentbakingWarning=newGUIContent("Light mode is currently overridden to Realtime mode. Enable Baked Global Illumination to use Mixed or Baked light modes.");
publicreadonlyGUIContentindirectBounceShadowWarning=newGUIContent("Realtime indirect bounce shadowing is not supported for Spot and Point lights.");
publicreadonlyGUIContentcookieWarning=newGUIContent("Cookie textures for spot lights should be set to clamp, not repeat, to avoid artifacts.");
// Additional light data
publicreadonlyGUIContentmaxSmoothness=newGUIContent("Max Smoothness","Very low cost way of faking spherical area lighting. This will modify the roughness of the material lit. This is useful when the specular highlight is too small or too sharp.");
m_TextureCache.UpdateSlice(cmd,sliceIndex,result,m_TextureCache.GetTextureUpdateCount(texture));// Be careful to provide the update count from the input texture, not the temporary one used for convolving.
m_TextureCache.UpdateSlice(cmd,sliceIndex,result,m_TextureCache.GetTextureHash(texture));// Be careful to provide the update count from the input texture, not the temporary one used for convolving.
if (UnpackByte(LOAD_TEXTURE2D(_StencilTexture, uCrd).r) != STENCILLIGHTINGUSAGE_NO_LIGHTING) // This test is we are the sky/background or not
// StencilTexture here contain the result of testing if we are not equal to stencil usage NoLighting. i.e (stencil value != NoLighting). The 1.0 mean true.
// This test if we are the sky/background or a forward opaque (which tag the stencil as NoLighting)
if (LOAD_TEXTURE2D(_StencilTexture, uCrd).r == 1.0)
//SetKeyword(material, "_MATID_STANDARD", materialId == Lit.MaterialId.LitStandard); // See comment in Lit.shader, it is the default, we don't define it
//CoreUtils.SetKeyword(material, "_MATID_STANDARD", materialId == Lit.MaterialId.LitStandard); // See comment in Lit.shader, it is the default, we don't define it
//SetKeyword(material, "_MATID_STANDARD", materialId == Lit.MaterialId.LitStandard); // See comment in Lit.shader, it is the default, we don't define it
//CoreUtils.SetKeyword(material, "_MATID_STANDARD", materialId == Lit.MaterialId.LitStandard); // See comment in Lit.shader, it is the default, we don't define it