6920 lines
287 KiB
GLSL
6920 lines
287 KiB
GLSL
Shader /*ase_name*/ "Hidden/HDRP/Hair" /*end*/
|
|
{
|
|
Properties
|
|
{
|
|
/*ase_props*/
|
|
|
|
[HideInInspector] _EmissionColor("Color", Color) = (1, 1, 1)
|
|
[HideInInspector] _RenderQueueType("Render Queue Type", Float) = 4
|
|
|
|
[HideInInspector][ToggleUI] _AddPrecomputedVelocity("Add Precomputed Velocity", Float) = 1
|
|
[HideInInspector][ToggleUI] _DepthOffsetEnable("Boolean", Float) = 1
|
|
[HideInInspector][ToggleUI] _ConservativeDepthOffsetEnable("Boolean", Float) = 1
|
|
[HideInInspector][ToggleUI] _TransparentWritingMotionVec("Transparent Writing MotionVec", Float) = 1
|
|
[HideInInspector][ToggleUI] _AlphaCutoffEnable("Alpha Cutoff Enable", Float) = 1
|
|
[HideInInspector] _TransparentSortPriority("Transparent Sort Priority", Float) = 0
|
|
[HideInInspector][ToggleUI] _UseShadowThreshold("Use Shadow Threshold", Float) = 1
|
|
[HideInInspector][ToggleUI] _DoubleSidedEnable("Double Sided Enable", Float) = 0
|
|
[HideInInspector][Enum(Flip, 0, Mirror, 1, None, 2)] _DoubleSidedNormalMode("Double Sided Normal Mode", Float) = 2
|
|
[HideInInspector] _DoubleSidedConstants("DoubleSidedConstants", Vector) = ( 1, 1, -1, 0 )
|
|
[HideInInspector][Enum(Auto, 0, On, 1, Off, 2)] _DoubleSidedGIMode("Double sided GI mode", Float) = 0
|
|
[HideInInspector][ToggleUI] _TransparentDepthPrepassEnable("Boolean", Float) = 1
|
|
[HideInInspector][ToggleUI] _TransparentDepthPostpassEnable("Boolean", Float) = 1
|
|
[HideInInspector] _SurfaceType("Surface Type", Float) = 1
|
|
[HideInInspector] _BlendMode("Blend Mode", Float) = 0
|
|
[HideInInspector] _SrcBlend("Src Blend", Float) = 1
|
|
[HideInInspector] _DstBlend("Dst Blend", Float) = 0
|
|
[HideInInspector] _DstBlend2("__dst2", Float) = 0.0
|
|
[HideInInspector] _AlphaSrcBlend("Alpha Src Blend", Float) = 1
|
|
[HideInInspector] _AlphaDstBlend("Alpha Dst Blend", Float) = 0
|
|
[HideInInspector][ToggleUI] _ZWrite("ZWrite", Float) = 0
|
|
[HideInInspector][ToggleUI] _TransparentZWrite("Transparent ZWrite", Float) = 0
|
|
[HideInInspector] _CullMode("Cull Mode", Float) = 2
|
|
[HideInInspector][ToggleUI] _EnableFogOnTransparent("Enable Fog", Float) = 1
|
|
[HideInInspector] _CullModeForward("Cull Mode Forward", Float) = 2
|
|
[HideInInspector][Enum(UnityEngine.Rendering.HighDefinition.TransparentCullMode)] _TransparentCullMode("Transparent Cull Mode", Int) = 2
|
|
[HideInInspector][Enum(UnityEngine.Rendering.HighDefinition.OpaqueCullMode)] _OpaqueCullMode("Opaque Cull Mode", Int) = 2
|
|
[HideInInspector] _ZTestDepthEqualForOpaque("ZTest Depth Equal For Opaque", Int) = 4
|
|
[HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)] _ZTestTransparent("ZTest Transparent", Int) = 4
|
|
[HideInInspector][ToggleUI] _TransparentBackfaceEnable("Transparent Backface Enable", Float) = 1
|
|
[HideInInspector][ToggleUI] _RequireSplitLighting("Require Split Lighting", Float) = 0
|
|
[HideInInspector][ToggleUI] _ReceivesSSR("Receives SSR", Float) = 1
|
|
[HideInInspector][ToggleUI] _ReceivesSSRTransparent("Receives SSR Transparent", Float) = 1
|
|
[HideInInspector][ToggleUI] _EnableBlendModePreserveSpecularLighting("Enable Blend Mode Preserve Specular Lighting", Float) = 1
|
|
[HideInInspector][ToggleUI] _SupportDecals("Support Decals", Float) = 1
|
|
|
|
[HideInInspector][ToggleUI]_ExcludeFromTUAndAA("Boolean", Float) = 1
|
|
[HideInInspector] _StencilRef("Stencil Ref", Int) = 2
|
|
[HideInInspector] _StencilWriteMask("Stencil Write Mask", Int) = 6
|
|
[HideInInspector] _StencilRefDepth("Stencil Ref Depth", Int) = 10
|
|
[HideInInspector] _StencilWriteMaskDepth("Stencil Write Mask Depth", Int) = 11
|
|
|
|
[HideInInspector] _StencilRefMV("Stencil Ref MV", Int) = 40
|
|
[HideInInspector] _StencilWriteMaskMV("Stencil Write Mask MV", Int) = 40
|
|
[HideInInspector] _StencilRefDistortionVec("Stencil Ref Distortion Vec", Int) = 4
|
|
[HideInInspector] _StencilWriteMaskDistortionVec("Stencil Write Mask Distortion Vec", Int) = 4
|
|
|
|
[HideInInspector] _StencilWriteMaskGBuffer("Stencil Write Mask GBuffer", Int) = 14
|
|
[HideInInspector] _StencilRefGBuffer("Stencil Ref GBuffer", Int) = 10
|
|
[HideInInspector] _ZTestGBuffer("ZTest GBuffer", Int) = 4
|
|
|
|
[HideInInspector][ToggleUI] _AlphaToMask("Boolean", Float) = 0
|
|
[HideInInspector][ToggleUI] _AlphaToMaskInspectorValue("Boolean", Float) = 0
|
|
|
|
//_TessPhongStrength( "Tess Phong Strength", Range( 0, 1 ) ) = 0.5
|
|
//_TessValue( "Tess Max Tessellation", Range( 1, 32 ) ) = 16
|
|
//_TessMin( "Tess Min Distance", Float ) = 10
|
|
//_TessMax( "Tess Max Distance", Float ) = 25
|
|
//_TessEdgeLength ( "Tess Edge length", Range( 2, 50 ) ) = 16
|
|
//_TessMaxDisp( "Tess Max Displacement", Float ) = 25
|
|
|
|
[HideInInspector][NoScaleOffset] unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {}
|
|
[HideInInspector][NoScaleOffset] unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {}
|
|
[HideInInspector][NoScaleOffset] unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {}
|
|
|
|
}
|
|
|
|
SubShader
|
|
{
|
|
/*ase_subshader_options:Name=Additional Options
|
|
Port:ForwardOnly:Bent Normal
|
|
On:SetDefine:ASE_BENT_NORMAL 1
|
|
Port:ForwardOnly:Occlusion
|
|
On:SetDefine:_AMBIENT_OCCLUSION 1
|
|
Port:ForwardOnly:Baked GI
|
|
On:SetDefine:ASE_BAKEDGI 1
|
|
Port:ForwardOnly:Baked Back GI
|
|
On:SetDefine:ASE_BAKEDBACKGI 1
|
|
Port:ForwardOnly:Hair Strand Direction
|
|
On:SetDefine:ASE_HAIRDIRECTION 1
|
|
Port:ForwardOnly:Vertex Offset
|
|
On:SetDefine:HAVE_MESH_MODIFICATION
|
|
Option:Material Type:Approximate,Physical,PhysicalCinematic:Approximate
|
|
Approximate:SetDefine:_MATERIAL_FEATURE_HAIR_KAJIYA_KAY 1
|
|
Approximate,disable:RemoveDefine:_MATERIAL_FEATURE_HAIR_MARSCHNER 1
|
|
Approximate,disable:RemoveDefine:_MATERIAL_FEATURE_HAIR_MARSCHNER_CINEMATIC 1
|
|
Approximate:ShowPort:ForwardOnly:Transmittance
|
|
Approximate:ShowPort:ForwardOnly:Rim Transmission Intensity
|
|
Approximate:ShowPort:ForwardOnly:Specular Tint
|
|
Approximate:ShowPort:ForwardOnly:Specular Shift
|
|
Approximate:ShowPort:ForwardOnly:Secondary Specular Tint
|
|
Approximate:ShowPort:ForwardOnly:Secondary Smoothness
|
|
Approximate:ShowPort:ForwardOnly:Secondary Specular Shift
|
|
Approximate,disable:HidePort:ForwardOnly:Radial Smoothness
|
|
Approximate,disable:HidePort:ForwardOnly:Cuticle Angle Shift
|
|
Approximate,disable:HidePort:ForwardOnly:Strand Count Probe
|
|
Physical:SetDefine:_MATERIAL_FEATURE_HAIR_MARSCHNER 1
|
|
Physical,disable:RemoveDefine:_MATERIAL_FEATURE_HAIR_KAJIYA_KAY 1
|
|
Physical,disable:RemoveDefine:_MATERIAL_FEATURE_HAIR_MARSCHNER_CINEMATIC 1
|
|
Physical:ShowPort:ForwardOnly:Radial Smoothness
|
|
Physical:ShowPort:ForwardOnly:Cuticle Angle Shift
|
|
Physical,disable:HidePort:ForwardOnly:Transmittance
|
|
Physical,disable:HidePort:ForwardOnly:Rim Transmission Intensity
|
|
Physical,disable:HidePort:ForwardOnly:Specular Tint
|
|
Physical,disable:HidePort:ForwardOnly:Specular Shift
|
|
Physical,disable:HidePort:ForwardOnly:Secondary Specular Tint
|
|
Physical,disable:HidePort:ForwardOnly:Secondary Smoothness
|
|
Physical,disable:HidePort:ForwardOnly:Secondary Specular Shift
|
|
Physical,disable:HidePort:ForwardOnly:Strand Count Probe
|
|
Physical:SetOption:Geometry Type,0
|
|
Physical,disable:HideOption:Geometry Type
|
|
Physical:SetOption: Scattering Mode,0
|
|
Physical,disable:HideOption: Scattering Mode
|
|
Physical:SetOption: Multiple Scattering Visibility,1
|
|
Physical,disable:HideOption: Multiple Scattering Visibility
|
|
PhysicalCinematic:SetDefine:_MATERIAL_FEATURE_HAIR_MARSCHNER_CINEMATIC 1
|
|
PhysicalCinematic,disable:RemoveDefine:_MATERIAL_FEATURE_HAIR_KAJIYA_KAY 1
|
|
PhysicalCinematic,disable:RemoveDefine:_MATERIAL_FEATURE_HAIR_MARSCHNER 1
|
|
PhysicalCinematic:ShowPort:ForwardOnly:Radial Smoothness
|
|
PhysicalCinematic:ShowPort:ForwardOnly:Cuticle Angle Shift
|
|
PhysicalCinematic:ShowPort:ForwardOnly:Strand Count Probe
|
|
PhysicalCinematic,disable:HidePort:ForwardOnly:Transmittance
|
|
PhysicalCinematic,disable:HidePort:ForwardOnly:Rim Transmission Intensity
|
|
PhysicalCinematic,disable:HidePort:ForwardOnly:Specular Tint
|
|
PhysicalCinematic,disable:HidePort:ForwardOnly:Specular Shift
|
|
PhysicalCinematic,disable:HidePort:ForwardOnly:Secondary Specular Tint
|
|
PhysicalCinematic,disable:HidePort:ForwardOnly:Secondary Smoothness
|
|
PhysicalCinematic,disable:HidePort:ForwardOnly:Secondary Specular Shift
|
|
PhysicalCinematic:SetOption:Geometry Type,0
|
|
PhysicalCinematic,disable:HideOption:Geometry Type
|
|
PhysicalCinematic:SetOption: Scattering Mode,0
|
|
PhysicalCinematic,disable:HideOption: Scattering Mode
|
|
PhysicalCinematic:SetOption: Multiple Scattering Visibility,1
|
|
PhysicalCinematic,disable:HideOption: Multiple Scattering Visibility
|
|
Option:Surface Type:Opaque,Transparent:Opaque
|
|
Opaque:SetShaderProperty:_SurfaceType,0
|
|
Opaque:SetPropertyOnSubShader:RenderQueue,Geometry
|
|
Opaque:SetPropertyOnSubShader:ZWrite,On
|
|
Opaque:SetPropertyOnSubShader:BlendRGB,One,Zero
|
|
Opaque:SetDefine:ForwardOnly:pragma multi_compile USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST
|
|
Opaque:SetDefine:ForwardOnly:REMOVE_CLUSTERED_LIGHTLIST
|
|
Opaque:HideOption: Back Then Front Rendering
|
|
Opaque:HideOption: Transparent Depth Prepass
|
|
Opaque:HideOption: Transparent Depth Postpass
|
|
Opaque:HideOption: Preserve Specular Lighting
|
|
Opaque:HideOption: Depth Write
|
|
Opaque:HideOption: Depth Test
|
|
Opaque:HideOption:Receive SSR Transparent
|
|
Opaque:ShowOption:Receive SSR
|
|
Opaque:HideOption: Transparent Writes Motion Vectors
|
|
Transparent:SetShaderProperty:_SurfaceType,1
|
|
Transparent:SetPropertyOnSubShader:RenderType,Transparent
|
|
Transparent:SetPropertyOnSubShader:RenderQueue,Transparent
|
|
Transparent:SetPropertyOnSubShader:ZWrite,Off
|
|
Transparent:SetPropertyOnSubShader:BlendRGB,SrcAlpha,OneMinusSrcAlpha
|
|
Transparent:RemoveDefine:ForwardOnly:pragma multi_compile USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST
|
|
Transparent:RemoveDefine:ForwardOnly:REMOVE_CLUSTERED_LIGHTLIST
|
|
Transparent:ShowOption: Back Then Front Rendering
|
|
Transparent:ShowOption: Transparent Depth Prepass
|
|
Transparent:ShowOption: Transparent Depth Postpass
|
|
Transparent:ShowOption: Preserve Specular Lighting
|
|
Transparent:ShowOption: Depth Write
|
|
Transparent:ShowOption: Depth Test
|
|
Transparent:ShowOption:Receive SSR Transparent
|
|
Transparent:HideOption:Receive SSR
|
|
Transparent:ShowOption: Transparent Writes Motion Vectors
|
|
Option: Back Then Front Rendering:false,true:false
|
|
true:IncludePass:TransparentBackface
|
|
true:SetShaderProperty:_TransparentBackfaceEnable,1
|
|
false,disable:ExcludePass:TransparentBackface
|
|
Option: Transparent Depth Prepass:false,true:false
|
|
true:IncludePass:TransparentDepthPrepass
|
|
true:ShowPort:ForwardOnly:Alpha Clip Threshold Depth Prepass
|
|
false,disable:ExcludePass:TransparentDepthPrepass
|
|
false,disable:HidePort:ForwardOnly:Alpha Clip Threshold Depth Prepass
|
|
Option: Transparent Depth Postpass:false,true:false
|
|
true:IncludePass:TransparentDepthPostpass
|
|
true:ShowPort:ForwardOnly:Alpha Clip Threshold Depth Postpass
|
|
false,disable:ExcludePass:TransparentDepthPostpass
|
|
false,disable:HidePort:ForwardOnly:Alpha Clip Threshold Depth Postpass
|
|
Option: Transparent Writes Motion Vectors:false,true:false
|
|
true:SetShaderProperty:_TransparentWritingMotionVec,1
|
|
false:SetShaderProperty:_TransparentWritingMotionVec,0
|
|
Option: Preserve Specular Lighting:false,true:true
|
|
true:SetDefine:SUPPORT_BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1
|
|
false,disable:RemoveDefine:SUPPORT_BLENDMODE_PRESERVE_SPECULAR_LIGHTING 1
|
|
true:SetDefine:_ENERGY_CONSERVING_SPECULAR
|
|
false,disable:RemoveDefine:_ENERGY_CONSERVING_SPECULAR
|
|
Option: Depth Write:false,true:false
|
|
true:SetShaderProperty:_ZWrite,1
|
|
true:SetShaderProperty:_TransparentZWrite,1
|
|
false,disable:SetShaderProperty:_ZWrite,0
|
|
false,disable:SetShaderProperty:_TransparentZWrite,0
|
|
Option: Cull Mode:Back,Front:Back
|
|
Back,disable:SetShaderProperty:_TransparentCullMode,2
|
|
Front:SetShaderProperty:_TransparentCullMode,1
|
|
Option: Depth Test:Disabled,Never,Less,Equal,Less Equal,Greater,Not Equal,Greater Equal,Always:Less Equal
|
|
Never:SetShaderProperty:_ZTestTransparent,1
|
|
Less:SetShaderProperty:_ZTestTransparent,2
|
|
Equal:SetShaderProperty:_ZTestTransparent,3
|
|
Less Equal:SetShaderProperty:_ZTestTransparent,4
|
|
Greater:SetShaderProperty:_ZTestTransparent,5
|
|
Not Equal:SetShaderProperty:_ZTestTransparent,6
|
|
Greater Equal:SetShaderProperty:_ZTestTransparent,7
|
|
Always:SetShaderProperty:_ZTestTransparent,8
|
|
Option:Double-Sided:Disabled,Enabled,Flipped Normals,Mirrored Normals:Disabled
|
|
Disabled,Enabled,Flipped Normals,Mirrored Normals:SetDefine:ASE_NEED_CULLFACE 1
|
|
Disabled,Enabled,Flipped Normals,Mirrored Normals:SetDefine:pragma shader_feature_local _ _DOUBLESIDED_ON
|
|
Disabled:SetShaderProperty:_DoubleSidedEnable,0
|
|
Disabled:SetShaderProperty:_DoubleSidedNormalMode,2
|
|
Enabled:SetShaderProperty:_DoubleSidedEnable,1
|
|
Enabled:SetShaderProperty:_DoubleSidedNormalMode,2
|
|
Flipped Normals:SetShaderProperty:_DoubleSidedEnable,1
|
|
Flipped Normals:SetShaderProperty:_DoubleSidedNormalMode,0
|
|
Mirrored Normals:SetShaderProperty:_DoubleSidedEnable,1
|
|
Mirrored Normals:SetShaderProperty:_DoubleSidedNormalMode,1
|
|
Option:Alpha Clipping:false,true:false
|
|
true:ShowOption: Use Shadow Threshold
|
|
true:ShowPort:ForwardOnly:Alpha Clip Threshold
|
|
true:SetDefine:pragma shader_feature_local _ _ALPHATEST_ON
|
|
false:HideOption: Use Shadow Threshold
|
|
false:HidePort:ForwardOnly:Alpha Clip Threshold
|
|
false:RemoveDefine:pragma shader_feature_local _ _ALPHATEST_ON
|
|
Option: Use Shadow Threshold:false,true:false
|
|
true:SetDefine:_ALPHATEST_SHADOW_ON 1
|
|
true:ShowPort:ForwardOnly:Alpha Clip Threshold Shadow
|
|
true:SetShaderProperty:_UseShadowThreshold,1
|
|
false,disable:RemoveDefine:_ALPHATEST_SHADOW_ON 1
|
|
false,disable:HidePort:ForwardOnly:Alpha Clip Threshold Shadow
|
|
Option:Receive Decals:false,true:true
|
|
true:SetDefine:pragma shader_feature_local_fragment _ _DISABLE_DECALS
|
|
false:RemoveDefine:pragma shader_feature_local_fragment _ _DISABLE_DECALS
|
|
Option:Receive SSR:false,true:true
|
|
true:SetShaderProperty:_ReceivesSSR,1
|
|
true:RemoveDefine:pragma shader_feature_local_fragment _ _DISABLE_SSR
|
|
false:SetShaderProperty:_ReceivesSSR,1
|
|
false:SetDefine:pragma shader_feature_local_fragment _ _DISABLE_SSR
|
|
Option:Receive SSR Transparent:false,true:false
|
|
true:SetShaderProperty:_ReceivesSSRTransparent,1
|
|
true:RemoveDefine:pragma shader_feature_local_fragment _ _DISABLE_SSR_TRANSPARENT
|
|
true:SetOption: Transparent Depth Prepass,1
|
|
false:SetShaderProperty:_ReceivesSSRTransparent,0
|
|
false:SetDefine:pragma shader_feature_local_fragment _ _DISABLE_SSR_TRANSPARENT
|
|
false:SetOption: Transparent Depth Prepass,0
|
|
Option:Motion Vectors:false,true:true
|
|
true:SetShaderProperty:_AddPrecomputedVelocity,[HideInInspector][ToggleUI] _AddPrecomputedVelocity("Add Precomputed Velocity", Float) = 1
|
|
false:SetShaderProperty:_AddPrecomputedVelocity,//[HideInInspector][ToggleUI] _AddPrecomputedVelocity("Add Precomputed Velocity", Float) = 1
|
|
true:ShowOption: Add Precomputed Velocity
|
|
false:HideOption: Add Precomputed Velocity
|
|
true:IncludePass:MotionVectors
|
|
false:ExcludePass:MotionVectors
|
|
true:SetOption:Tessellation,0
|
|
Option: Add Precomputed Velocity:false,true:false
|
|
false,disable:RemoveDefine:pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY
|
|
true:SetDefine:pragma shader_feature_local _ _ADD_PRECOMPUTED_VELOCITY
|
|
true:SetShaderProperty:_AddPrecomputedVelocity,1
|
|
Option:Geometric Specular AA:false,true:false
|
|
true:SetDefine:shader_feature_local_fragment _ENABLE_GEOMETRIC_SPECULAR_AA
|
|
true:ShowPort:ForwardOnly:Specular AA Screen Space Variance
|
|
true:ShowPort:ForwardOnly:Specular AA Threshold
|
|
false:RemoveDefine:shader_feature_local_fragment _ENABLE_GEOMETRIC_SPECULAR_AA
|
|
false:HidePort:ForwardOnly:Specular AA Screen Space Variance
|
|
false:HidePort:ForwardOnly:Specular AA Threshold
|
|
Option:Specular Occlusion Mode:Off,From AO,From AO And Bent Normal,Custom:From AO
|
|
Off:RemoveDefine:_SPECULAR_OCCLUSION_FROM_AO 1
|
|
Off:RemoveDefine:_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1
|
|
Off:RemoveDefine:_SPECULAR_OCCLUSION_CUSTOM 1
|
|
Off:HidePort:ForwardOnly:Specular Occlusion
|
|
From AO:SetDefine:_SPECULAR_OCCLUSION_FROM_AO 1
|
|
From AO:RemoveDefine:_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1
|
|
From AO:RemoveDefine:_SPECULAR_OCCLUSION_CUSTOM 1
|
|
From AO:HidePort:ForwardOnly:Specular Occlusion
|
|
From AO And Bent Normal:RemoveDefine:_SPECULAR_OCCLUSION_FROM_AO 1
|
|
From AO And Bent Normal:SetDefine:_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1
|
|
From AO And Bent Normal:RemoveDefine:_SPECULAR_OCCLUSION_CUSTOM 1
|
|
From AO And Bent Normal:HidePort:ForwardOnly:Specular Occlusion
|
|
Custom:RemoveDefine:_SPECULAR_OCCLUSION_FROM_AO 1
|
|
Custom:RemoveDefine:_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1
|
|
Custom:SetDefine:_SPECULAR_OCCLUSION_CUSTOM 1
|
|
Custom:ShowPort:ForwardOnly:Specular Occlusion
|
|
Option:Override Baked GI:false,true:false
|
|
true:ShowPort:ForwardOnly:Baked GI
|
|
true:ShowPort:ForwardOnly:Baked Back GI
|
|
false:HidePort:ForwardOnly:Baked GI
|
|
false:HidePort:ForwardOnly:Baked Back GI
|
|
Option:Depth Offset:false,true:false
|
|
true:SetDefine:_DEPTHOFFSET_ON 1
|
|
true:SetDefine:pragma shader_feature_local_fragment _ _DEPTHOFFSET_ON
|
|
true:ShowPort:ForwardOnly:Depth Offset
|
|
false:RemoveDefine:_DEPTHOFFSET_ON 1
|
|
false:RemoveDefine:pragma shader_feature_local_fragment _ _DEPTHOFFSET_ON
|
|
false:HidePort:ForwardOnly:Depth Offset
|
|
true:ShowOption: Conserative
|
|
false:HideOption: Conserative
|
|
false:RemoveDefine:pragma shader_feature_local_fragment _ _CONSERVATIVE_DEPTH_OFFSET
|
|
Option: Conserative:false,true:true
|
|
true:SetDefine:pragma shader_feature_local_fragment _ _CONSERVATIVE_DEPTH_OFFSET
|
|
false:RemoveDefine:pragma shader_feature_local_fragment _ _CONSERVATIVE_DEPTH_OFFSET
|
|
Option:Exclude From Temporal Upscalers and Anti Aliasing:false,true:true
|
|
true:SetShaderProperty:_ExcludeFromTUAndAA,1
|
|
false:SetShaderProperty:_ExcludeFromTUAndAA,0
|
|
true:SetShaderProperty:_StencilRef,2
|
|
false:SetShaderProperty:_StencilRef,0
|
|
true:SetShaderProperty:_StencilRefDepth,10
|
|
false:SetShaderProperty:_StencilRefDepth,8
|
|
true:SetShaderProperty:_StencilWriteMaskDepth,11
|
|
false:SetShaderProperty:_StencilWriteMaskDepth,9
|
|
Option:GPU Instancing:false,true:true
|
|
true:SetDefine:pragma multi_compile_instancing
|
|
true:SetDefine:pragma instancing_options renderinglayer
|
|
false:RemoveDefine:pragma multi_compile_instancing
|
|
false:RemoveDefine:pragma instancing_options renderinglayer
|
|
Option:LOD CrossFade:false,true:false
|
|
true:SetDefine:pragma multi_compile _ LOD_FADE_CROSSFADE
|
|
false:RemoveDefine:pragma multi_compile _ LOD_FADE_CROSSFADE
|
|
Option:Tessellation:false,true:false
|
|
true:SetDefine:ASE_TESSELLATION 1
|
|
true:SetDefine:pragma require tessellation tessHW
|
|
true:SetDefine:pragma hull HullFunction
|
|
true:SetDefine:pragma domain DomainFunction
|
|
true:ShowOption: Phong
|
|
true:ShowOption: Type
|
|
false,disable:RemoveDefine:ASE_TESSELLATION 1
|
|
false,disable:RemoveDefine:pragma require tessellation tessHW
|
|
false,disable:RemoveDefine:pragma hull HullFunction
|
|
false,disable:RemoveDefine:pragma domain DomainFunction
|
|
false,disable:HideOption: Phong
|
|
false,disable:HideOption: Type
|
|
true:SetOption:Motion Vectors,0
|
|
Option: Phong:false,true:false
|
|
true:SetDefine:ASE_PHONG_TESSELLATION
|
|
false,disable:RemoveDefine:ASE_PHONG_TESSELLATION
|
|
true:ShowOption: Strength
|
|
false,disable:HideOption: Strength
|
|
Field: Strength:Float:0.5:0:1:_TessPhongStrength
|
|
Change:SetMaterialProperty:_TessPhongStrength
|
|
Change:SetShaderProperty:_TessPhongStrength,_TessPhongStrength( "Phong Tess Strength", Range( 0, 1 ) ) = 0.5
|
|
Inline,disable:SetShaderProperty:_TessPhongStrength,//_TessPhongStrength( "Phong Tess Strength", Range( 0, 1 ) ) = 0.5
|
|
Option: Type:Fixed,Distance Based,Edge Length,Edge Length Cull:Fixed
|
|
Fixed:SetDefine:ASE_FIXED_TESSELLATION
|
|
Fixed,Distance Based:ShowOption: Tess
|
|
Distance Based:SetDefine:ASE_DISTANCE_TESSELLATION
|
|
Distance Based:ShowOption: Min
|
|
Distance Based:ShowOption: Max
|
|
Edge Length:SetDefine:ASE_LENGTH_TESSELLATION
|
|
Edge Length,Edge Length Cull:ShowOption: Edge Length
|
|
Edge Length Cull:SetDefine:ASE_LENGTH_CULL_TESSELLATION
|
|
Edge Length Cull:ShowOption: Max Displacement
|
|
disable,Distance Based,Edge Length,Edge Length Cull:RemoveDefine:ASE_FIXED_TESSELLATION
|
|
disable,Fixed,Edge Length,Edge Length Cull:RemoveDefine:ASE_DISTANCE_TESSELLATION
|
|
disable,Fixed,Distance Based,Edge Length Cull:RemoveDefine:ASE_LENGTH_TESSELLATION
|
|
disable,Fixed,Distance Based,Edge Length:RemoveDefine:ASE_LENGTH_CULL_TESSELLATION
|
|
disable,Edge Length,Edge Length Cull:HideOption: Tess
|
|
disable,Fixed,Edge Length,Edge Length Cull:HideOption: Min
|
|
disable,Fixed,Edge Length,Edge Length Cull:HideOption: Max
|
|
disable,Fixed,Distance Based:HideOption: Edge Length
|
|
disable,Fixed,Distance Based,Edge Length:HideOption: Max Displacement
|
|
Field: Tess:Float:16:1:32:_TessValue
|
|
Change:SetMaterialProperty:_TessValue
|
|
Change:SetShaderProperty:_TessValue,_TessValue( "Max Tessellation", Range( 1, 32 ) ) = 16
|
|
Inline,disable:SetShaderProperty:_TessValue,//_TessValue( "Max Tessellation", Range( 1, 32 ) ) = 16
|
|
Field: Min:Float:10:_TessMin
|
|
Change:SetMaterialProperty:_TessMin
|
|
Change:SetShaderProperty:_TessMin,_TessMin( "Tess Min Distance", Float ) = 10
|
|
Inline,disable:SetShaderProperty:_TessMin,//_TessMin( "Tess Min Distance", Float ) = 10
|
|
Field: Max:Float:25:_TessMax
|
|
Change:SetMaterialProperty:_TessMax
|
|
Change:SetShaderProperty:_TessMax,_TessMax( "Tess Max Distance", Float ) = 25
|
|
Inline,disable:SetShaderProperty:_TessMax,//_TessMax( "Tess Max Distance", Float ) = 25
|
|
Field: Edge Length:Float:16:2:50:_TessEdgeLength
|
|
Change:SetMaterialProperty:_TessEdgeLength
|
|
Change:SetShaderProperty:_TessEdgeLength,_TessEdgeLength ( "Edge length", Range( 2, 50 ) ) = 16
|
|
Inline,disable:SetShaderProperty:_TessEdgeLength,//_TessEdgeLength ( "Edge length", Range( 2, 50 ) ) = 16
|
|
Field: Max Displacement:Float:25:_TessMaxDisp
|
|
Change:SetMaterialProperty:_TessMaxDisp
|
|
Change:SetShaderProperty:_TessMaxDisp,_TessMaxDisp( "Max Displacement", Float ) = 25
|
|
Inline,disable:SetShaderProperty:_TessMaxDisp,//_TessMaxDisp( "Max Displacement", Float ) = 25
|
|
Option:Vertex Position:Absolute,Relative:Relative
|
|
Absolute:SetDefine:ASE_ABSOLUTE_VERTEX_POS 1
|
|
Absolute:SetPortName:ForwardOnly:24,Vertex Position
|
|
Relative:RemoveDefine:ASE_ABSOLUTE_VERTEX_POS 1
|
|
Relative:SetPortName:ForwardOnly:24,Vertex Offset
|
|
Option:Geometry Type:Card,Strands:Card
|
|
Card:RemoveDefine:_USE_LIGHT_FACING_NORMAL 1
|
|
Card:RemoveDefine:_USE_SPLINE_VISIBILITY_FOR_MULTIPLE_SCATTERING 1
|
|
Card:RemoveDefine:_USE_ADVANCED_MULTIPLE_SCATTERING 1
|
|
Card,disable:HideOption: Scattering Mode
|
|
Card,disable:HideOption: Multiple Scattering Visibility
|
|
Card:HidePort:ForwardOnly:Strand Count Probe
|
|
Card:HidePort:ForwardOnly:Strand Shadow Bias
|
|
Strands:SetDefine:_USE_LIGHT_FACING_NORMAL 1
|
|
Strands:ShowOption: Scattering Mode
|
|
Option: Scattering Mode:Approximate,Physical:Approximate
|
|
Approximate,disable:HideOption: Multiple Scattering Visibility
|
|
Approximate:RemoveDefine:_USE_SPLINE_VISIBILITY_FOR_MULTIPLE_SCATTERING 1
|
|
Approximate:RemoveDefine:_USE_ADVANCED_MULTIPLE_SCATTERING 1
|
|
Approximate:HidePort:ForwardOnly:Strand Count Probe
|
|
Approximate:HidePort:ForwardOnly:Strand Shadow Bias
|
|
Physical:ShowOption: Multiple Scattering Visibility
|
|
Physical:ShowPort:ForwardOnly:Strand Count Probe
|
|
Physical:ShowPort:ForwardOnly:Strand Shadow Bias
|
|
Physical:SetDefine:_USE_SPLINE_VISIBILITY_FOR_MULTIPLE_SCATTERING 1
|
|
Option: Multiple Scattering Visibility:Shadowmap,StrandProbe:Shadowmap
|
|
Shadowmap:SetDefine:_USE_ADVANCED_MULTIPLE_SCATTERING 1
|
|
StrandProbe:RemoveDefine:_USE_ADVANCED_MULTIPLE_SCATTERING 1
|
|
|
|
*/
|
|
|
|
Tags
|
|
{
|
|
"RenderPipeline"="HDRenderPipeline"
|
|
"RenderType"="HDLitShader"
|
|
"Queue"="Geometry+0"
|
|
}
|
|
|
|
HLSLINCLUDE
|
|
#pragma target 4.5
|
|
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
|
|
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Filtering.hlsl"
|
|
|
|
struct GlobalSurfaceDescription //ForwardOnly
|
|
{
|
|
float3 BaseColor;
|
|
float3 Normal;
|
|
float3 BentNormal;
|
|
float3 HairStrandDirection;
|
|
float3 Emission;
|
|
float Smoothness;
|
|
float Occlusion;
|
|
float Alpha;
|
|
float AlphaClipThreshold;
|
|
float AlphaClipThresholdShadow;
|
|
float AlphaClipThresholdDepthPrepass;
|
|
float AlphaClipThresholdDepthPostpass;
|
|
float SpecularOcclusion;
|
|
float SpecularAAScreenSpaceVariance;
|
|
float SpecularAAThreshold;
|
|
float3 Transmittance;
|
|
float RimTransmissionIntensity;
|
|
float3 SpecularTint;
|
|
float SpecularShift;
|
|
float3 SecondarySpecularTint;
|
|
float SecondarySmoothness;
|
|
float SecondarySpecularShift;
|
|
float RadialSmoothness;
|
|
float CuticleAngle;
|
|
float4 StrandCountProbe;
|
|
float StrandShadowBias;
|
|
float3 BakedGI;
|
|
float3 BakedBackGI;
|
|
float DepthOffset;
|
|
float4 VTPackedFeedback;
|
|
};
|
|
|
|
struct AlphaSurfaceDescription // ShadowCaster
|
|
{
|
|
float3 HairStrandDirection;
|
|
float3 Emission;
|
|
float Alpha;
|
|
float AlphaClipThreshold;
|
|
float AlphaClipThresholdShadow;
|
|
float3 BakedGI;
|
|
float3 BakedBackGI;
|
|
float DepthOffset;
|
|
float4 VTPackedFeedback;
|
|
};
|
|
|
|
struct SceneSurfaceDescription // SceneSelection
|
|
{
|
|
float3 HairStrandDirection;
|
|
float3 Emission;
|
|
float Alpha;
|
|
float AlphaClipThreshold;
|
|
float AlphaClipThresholdShadow;
|
|
float3 BakedGI;
|
|
float3 BakedBackGI;
|
|
float DepthOffset;
|
|
float4 VTPackedFeedback;
|
|
};
|
|
|
|
struct PrePassSurfaceDescription //TransparentDepthPrepass
|
|
{
|
|
float3 Normal;
|
|
float3 HairStrandDirection;
|
|
float3 Emission;
|
|
float Smoothness;
|
|
float Alpha;
|
|
float AlphaClipThreshold;
|
|
float AlphaClipThresholdShadow;
|
|
float AlphaClipThresholdDepthPrepass;
|
|
float3 BakedGI;
|
|
float3 BakedBackGI;
|
|
float DepthOffset;
|
|
float4 VTPackedFeedback;
|
|
};
|
|
|
|
struct PostPassSurfaceDescription //TransparentDepthPostpass
|
|
{
|
|
float3 Emission;
|
|
float3 HairStrandDirection;
|
|
float Alpha;
|
|
float AlphaClipThreshold;
|
|
float AlphaClipThresholdShadow;
|
|
float AlphaClipThresholdDepthPostpass;
|
|
float3 BakedGI;
|
|
float3 BakedBackGI;
|
|
float DepthOffset;
|
|
float4 VTPackedFeedback;
|
|
};
|
|
|
|
struct SmoothSurfaceDescription //DepthForwardOnly MotionVectors
|
|
{
|
|
float3 Normal;
|
|
float3 HairStrandDirection;
|
|
float3 Emission;
|
|
float Smoothness;
|
|
float Alpha;
|
|
float AlphaClipThreshold;
|
|
float AlphaClipThresholdShadow;
|
|
float3 BakedGI;
|
|
float3 BakedBackGI;
|
|
float DepthOffset;
|
|
float4 VTPackedFeedback;
|
|
};
|
|
|
|
#ifndef ASE_TESS_FUNCS
|
|
#define ASE_TESS_FUNCS
|
|
float4 FixedTess( float tessValue )
|
|
{
|
|
return tessValue;
|
|
}
|
|
|
|
float CalcDistanceTessFactor (float4 vertex, float minDist, float maxDist, float tess, float4x4 o2w, float3 cameraPos )
|
|
{
|
|
float3 wpos = mul(o2w,vertex).xyz;
|
|
float dist = distance (wpos, cameraPos);
|
|
float f = clamp(1.0 - (dist - minDist) / (maxDist - minDist), 0.01, 1.0) * tess;
|
|
return f;
|
|
}
|
|
|
|
float4 CalcTriEdgeTessFactors (float3 triVertexFactors)
|
|
{
|
|
float4 tess;
|
|
tess.x = 0.5 * (triVertexFactors.y + triVertexFactors.z);
|
|
tess.y = 0.5 * (triVertexFactors.x + triVertexFactors.z);
|
|
tess.z = 0.5 * (triVertexFactors.x + triVertexFactors.y);
|
|
tess.w = (triVertexFactors.x + triVertexFactors.y + triVertexFactors.z) / 3.0f;
|
|
return tess;
|
|
}
|
|
|
|
float CalcEdgeTessFactor (float3 wpos0, float3 wpos1, float edgeLen, float3 cameraPos, float4 scParams )
|
|
{
|
|
float dist = distance (0.5 * (wpos0+wpos1), cameraPos);
|
|
float len = distance(wpos0, wpos1);
|
|
float f = max(len * scParams.y / (edgeLen * dist), 1.0);
|
|
return f;
|
|
}
|
|
|
|
float DistanceFromPlaneASE (float3 pos, float4 plane)
|
|
{
|
|
return dot (float4(pos,1.0f), plane);
|
|
}
|
|
|
|
bool WorldViewFrustumCull (float3 wpos0, float3 wpos1, float3 wpos2, float cullEps, float4 planes[6] )
|
|
{
|
|
float4 planeTest;
|
|
planeTest.x = (( DistanceFromPlaneASE(wpos0, planes[0]) > -cullEps) ? 1.0f : 0.0f ) +
|
|
(( DistanceFromPlaneASE(wpos1, planes[0]) > -cullEps) ? 1.0f : 0.0f ) +
|
|
(( DistanceFromPlaneASE(wpos2, planes[0]) > -cullEps) ? 1.0f : 0.0f );
|
|
planeTest.y = (( DistanceFromPlaneASE(wpos0, planes[1]) > -cullEps) ? 1.0f : 0.0f ) +
|
|
(( DistanceFromPlaneASE(wpos1, planes[1]) > -cullEps) ? 1.0f : 0.0f ) +
|
|
(( DistanceFromPlaneASE(wpos2, planes[1]) > -cullEps) ? 1.0f : 0.0f );
|
|
planeTest.z = (( DistanceFromPlaneASE(wpos0, planes[2]) > -cullEps) ? 1.0f : 0.0f ) +
|
|
(( DistanceFromPlaneASE(wpos1, planes[2]) > -cullEps) ? 1.0f : 0.0f ) +
|
|
(( DistanceFromPlaneASE(wpos2, planes[2]) > -cullEps) ? 1.0f : 0.0f );
|
|
planeTest.w = (( DistanceFromPlaneASE(wpos0, planes[3]) > -cullEps) ? 1.0f : 0.0f ) +
|
|
(( DistanceFromPlaneASE(wpos1, planes[3]) > -cullEps) ? 1.0f : 0.0f ) +
|
|
(( DistanceFromPlaneASE(wpos2, planes[3]) > -cullEps) ? 1.0f : 0.0f );
|
|
return !all (planeTest);
|
|
}
|
|
|
|
float4 DistanceBasedTess( float4 v0, float4 v1, float4 v2, float tess, float minDist, float maxDist, float4x4 o2w, float3 cameraPos )
|
|
{
|
|
float3 f;
|
|
f.x = CalcDistanceTessFactor (v0,minDist,maxDist,tess,o2w,cameraPos);
|
|
f.y = CalcDistanceTessFactor (v1,minDist,maxDist,tess,o2w,cameraPos);
|
|
f.z = CalcDistanceTessFactor (v2,minDist,maxDist,tess,o2w,cameraPos);
|
|
|
|
return CalcTriEdgeTessFactors (f);
|
|
}
|
|
|
|
float4 EdgeLengthBasedTess( float4 v0, float4 v1, float4 v2, float edgeLength, float4x4 o2w, float3 cameraPos, float4 scParams )
|
|
{
|
|
float3 pos0 = mul(o2w,v0).xyz;
|
|
float3 pos1 = mul(o2w,v1).xyz;
|
|
float3 pos2 = mul(o2w,v2).xyz;
|
|
float4 tess;
|
|
tess.x = CalcEdgeTessFactor (pos1, pos2, edgeLength, cameraPos, scParams);
|
|
tess.y = CalcEdgeTessFactor (pos2, pos0, edgeLength, cameraPos, scParams);
|
|
tess.z = CalcEdgeTessFactor (pos0, pos1, edgeLength, cameraPos, scParams);
|
|
tess.w = (tess.x + tess.y + tess.z) / 3.0f;
|
|
return tess;
|
|
}
|
|
|
|
float4 EdgeLengthBasedTessCull( float4 v0, float4 v1, float4 v2, float edgeLength, float maxDisplacement, float4x4 o2w, float3 cameraPos, float4 scParams, float4 planes[6] )
|
|
{
|
|
float3 pos0 = mul(o2w,v0).xyz;
|
|
float3 pos1 = mul(o2w,v1).xyz;
|
|
float3 pos2 = mul(o2w,v2).xyz;
|
|
float4 tess;
|
|
|
|
if (WorldViewFrustumCull(pos0, pos1, pos2, maxDisplacement, planes))
|
|
{
|
|
tess = 0.0f;
|
|
}
|
|
else
|
|
{
|
|
tess.x = CalcEdgeTessFactor (pos1, pos2, edgeLength, cameraPos, scParams);
|
|
tess.y = CalcEdgeTessFactor (pos2, pos0, edgeLength, cameraPos, scParams);
|
|
tess.z = CalcEdgeTessFactor (pos0, pos1, edgeLength, cameraPos, scParams);
|
|
tess.w = (tess.x + tess.y + tess.z) / 3.0f;
|
|
}
|
|
return tess;
|
|
}
|
|
#endif //ASE_TESS_FUNCS
|
|
ENDHLSL
|
|
|
|
/*ase_pass*/
|
|
Pass
|
|
{
|
|
/*ase_main_pass*/
|
|
Name "ForwardOnly"
|
|
Tags
|
|
{
|
|
"LightMode" = "ForwardOnly"
|
|
}
|
|
|
|
Blend [_SrcBlend] [_DstBlend], [_AlphaSrcBlend] [_AlphaDstBlend]
|
|
Blend 1 One OneMinusSrcAlpha
|
|
Blend 2 One [_DstBlend2]
|
|
Blend 3 One [_DstBlend2]
|
|
Blend 4 One OneMinusSrcAlpha
|
|
|
|
Cull [_CullModeForward]
|
|
ZTest [_ZTestDepthEqualForOpaque]
|
|
ZWrite [_ZWrite]
|
|
|
|
Stencil
|
|
{
|
|
WriteMask [_StencilWriteMask]
|
|
Ref [_StencilRef]
|
|
CompFront Always
|
|
PassFront Replace
|
|
CompBack Always
|
|
PassBack Replace
|
|
}
|
|
|
|
ColorMask [_ColorMaskTransparentVelOne] 1
|
|
ColorMask [_ColorMaskTransparentVelTwo] 2
|
|
|
|
HLSLPROGRAM
|
|
#pragma multi_compile _ DOTS_INSTANCING_ON
|
|
|
|
#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT
|
|
#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC _TRANSPARENT_REFRACTIVE_SORT
|
|
#pragma shader_feature_local_fragment _ _ENABLE_FOG_ON_TRANSPARENT
|
|
|
|
#pragma multi_compile_fragment _ SHADOWS_SHADOWMASK
|
|
#pragma multi_compile_fragment PUNCTUAL_SHADOW_LOW PUNCTUAL_SHADOW_MEDIUM PUNCTUAL_SHADOW_HIGH
|
|
#pragma multi_compile_fragment DIRECTIONAL_SHADOW_LOW DIRECTIONAL_SHADOW_MEDIUM DIRECTIONAL_SHADOW_HIGH
|
|
#pragma multi_compile_fragment AREA_SHADOW_MEDIUM AREA_SHADOW_HIGH
|
|
#pragma multi_compile_fragment _ PROBE_VOLUMES_L1 PROBE_VOLUMES_L2
|
|
#pragma multi_compile_fragment SCREEN_SPACE_SHADOWS_OFF SCREEN_SPACE_SHADOWS_ON
|
|
|
|
#pragma multi_compile _ DEBUG_DISPLAY
|
|
#pragma multi_compile _ LIGHTMAP_ON
|
|
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
|
|
#pragma multi_compile _ DYNAMICLIGHTMAP_ON
|
|
#pragma multi_compile_fragment DECALS_OFF DECALS_3RT DECALS_4RT
|
|
#pragma multi_compile_fragment _ DECAL_SURFACE_GRADIENT
|
|
#pragma multi_compile _ USE_LEGACY_LIGHTMAPS
|
|
|
|
// RayTracing
|
|
//#pragma shader_feature_local_raytracing _ _DISABLE_DECALS
|
|
//#pragma shader_feature_local_raytracing _ _DISABLE_SSR
|
|
//#pragma shader_feature_local_raytracing _ _DISABLE_SSR_TRANSPARENT
|
|
//#pragma multi_compile_raytracing PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2
|
|
//#pragma multi_compile_raytracing _ SHADOWS_SHADOWMASK
|
|
|
|
#pragma vertex Vert
|
|
#pragma fragment Frag
|
|
|
|
#define SHADERPASS SHADERPASS_FORWARD
|
|
#define HAS_LIGHTLOOP 1
|
|
#define _ABSORPTION_FROM_COLOR 1
|
|
#define SUPPORT_GLOBAL_MIP_BIAS 1
|
|
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl"
|
|
#include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl"
|
|
|
|
//#if !defined(SHADER_STAGE_RAY_TRACING) && SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER && SHADERPASS != SHADERPASS_FULL_SCREEN_DEBUG
|
|
//#define FRAG_INPUTS_ENABLE_STRIPPING
|
|
//#endif
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
|
|
|
|
#ifdef RAYTRACING_SHADER_GRAPH_DEFAULT
|
|
#define RAYTRACING_SHADER_GRAPH_HIGH
|
|
#endif
|
|
|
|
#ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED
|
|
#define RAYTRACING_SHADER_GRAPH_LOW
|
|
#endif
|
|
|
|
#ifndef SHADER_UNLIT
|
|
#if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE)
|
|
#define VARYINGS_NEED_CULLFACE
|
|
#endif
|
|
#endif
|
|
|
|
#if defined(_DOUBLESIDED_ON) && !defined(ASE_NEED_CULLFACE)
|
|
#define ASE_NEED_CULLFACE 1
|
|
#endif
|
|
|
|
#if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
|
|
#if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT)
|
|
#define WRITE_NORMAL_BUFFER
|
|
#endif
|
|
#endif
|
|
|
|
#if SHADERPASS == SHADERPASS_MOTION_VECTORS && defined(WRITE_DECAL_BUFFER_AND_RENDERING_LAYER)
|
|
#define WRITE_DECAL_BUFFER
|
|
#endif
|
|
|
|
#ifndef DEBUG_DISPLAY
|
|
#if !defined(_SURFACE_TYPE_TRANSPARENT)
|
|
#if SHADERPASS == SHADERPASS_FORWARD
|
|
#define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
|
|
#elif SHADERPASS == SHADERPASS_GBUFFER
|
|
#define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST
|
|
#endif
|
|
#endif
|
|
#endif
|
|
|
|
#if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT)
|
|
#define _DEFERRED_CAPABLE_MATERIAL
|
|
#endif
|
|
|
|
#if (defined(_TRANSPARENT_WRITES_MOTION_VEC) || defined(_TRANSPARENT_REFRACTIVE_SORT)) && defined(_SURFACE_TYPE_TRANSPARENT)
|
|
#define _WRITE_TRANSPARENT_MOTION_VECTOR
|
|
#endif
|
|
|
|
CBUFFER_START( UnityPerMaterial )
|
|
float4 _EmissionColor;
|
|
float _AlphaCutoff;
|
|
float _RenderQueueType;
|
|
#ifdef _ADD_PRECOMPUTED_VELOCITY
|
|
float _AddPrecomputedVelocity;
|
|
#endif
|
|
float _ExcludeFromTUAndAA;
|
|
float _StencilRef;
|
|
float _StencilWriteMask;
|
|
float _StencilRefDepth;
|
|
float _StencilWriteMaskDepth;
|
|
float _StencilRefMV;
|
|
float _StencilWriteMaskMV;
|
|
float _StencilRefDistortionVec;
|
|
float _StencilWriteMaskDistortionVec;
|
|
float _StencilWriteMaskGBuffer;
|
|
float _StencilRefGBuffer;
|
|
float _ZTestGBuffer;
|
|
float _RequireSplitLighting;
|
|
float _ReceivesSSR;
|
|
float _SurfaceType;
|
|
float _BlendMode;
|
|
#ifdef SUPPORT_BLENDMODE_PRESERVE_SPECULAR_LIGHTING
|
|
float _EnableBlendModePreserveSpecularLighting;
|
|
#endif
|
|
float _SrcBlend;
|
|
float _DstBlend;
|
|
float _DstBlend2;
|
|
float _AlphaSrcBlend;
|
|
float _AlphaDstBlend;
|
|
float _ZWrite;
|
|
float _TransparentZWrite;
|
|
float _CullMode;
|
|
float _TransparentSortPriority;
|
|
float _EnableFogOnTransparent;
|
|
float _CullModeForward;
|
|
float _TransparentCullMode;
|
|
float _ZTestDepthEqualForOpaque;
|
|
float _ZTestTransparent;
|
|
float _TransparentBackfaceEnable;
|
|
float _AlphaCutoffEnable;
|
|
float _UseShadowThreshold;
|
|
float _DoubleSidedEnable;
|
|
float _DoubleSidedNormalMode;
|
|
float4 _DoubleSidedConstants;
|
|
#ifdef ASE_TESSELLATION
|
|
float _TessPhongStrength;
|
|
float _TessValue;
|
|
float _TessMin;
|
|
float _TessMax;
|
|
float _TessEdgeLength;
|
|
float _TessMaxDisp;
|
|
#endif
|
|
UNITY_TEXTURE_STREAMING_DEBUG_VARS;
|
|
CBUFFER_END
|
|
|
|
#ifdef SCENEPICKINGPASS
|
|
float4 _SelectionID;
|
|
#endif
|
|
|
|
#ifdef SCENESELECTIONPASS
|
|
int _ObjectId;
|
|
int _PassValue;
|
|
#endif
|
|
|
|
/*ase_globals*/
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
|
|
#endif
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Hair/Hair.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl"
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl"
|
|
|
|
#ifdef HAVE_VFX_MODIFICATION
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/VisualEffectVertex.hlsl"
|
|
#endif
|
|
|
|
/*ase_pragma*/
|
|
|
|
struct AttributesMesh
|
|
{
|
|
float3 positionOS : POSITION;
|
|
float3 normalOS : NORMAL;
|
|
float4 tangentOS : TANGENT;
|
|
float4 uv1 : TEXCOORD1;
|
|
float4 uv2 : TEXCOORD2;
|
|
float3 previousPositionOS : TEXCOORD4;
|
|
float3 precomputedVelocity : TEXCOORD5;
|
|
/*ase_vdata:p=p;n=n;t=t;uv1=tc1;uv2=tc2;uv4=tc4;uv5=tc5*/
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
struct PackedVaryingsMeshToPS
|
|
{
|
|
SV_POSITION_QUALIFIERS float4 positionCS : SV_Position;
|
|
float3 positionRWS : TEXCOORD0;
|
|
float3 normalWS : TEXCOORD1;
|
|
float4 tangentWS : TEXCOORD2;
|
|
float4 uv1 : TEXCOORD3;
|
|
float4 uv2 : TEXCOORD4;
|
|
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
|
|
float3 vpassPositionCS : TEXCOORD5;
|
|
float3 vpassPreviousPositionCS : TEXCOORD6;
|
|
#endif
|
|
/*ase_interp(7,):sp=sp.xyzw;rwp=tc0;wn=tc1;wt=tc2;uv1=tc3;uv2=tc4*/
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
UNITY_VERTEX_OUTPUT_STEREO
|
|
#if defined(SHADER_STAGE_FRAGMENT) && defined(ASE_NEED_CULLFACE)
|
|
FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
|
|
#endif
|
|
};
|
|
|
|
/*ase_funcs*/
|
|
|
|
//Build Surface Data (Decal)
|
|
void ApplyDecalToSurfaceDataNoNormal(DecalSurfaceData decalSurfaceData, inout SurfaceData surfaceData)
|
|
{
|
|
surfaceData.diffuseColor.xyz = surfaceData.diffuseColor.xyz * decalSurfaceData.baseColor.w + decalSurfaceData.baseColor.xyz;
|
|
|
|
#ifdef DECALS_4RT
|
|
surfaceData.ambientOcclusion = surfaceData.ambientOcclusion * decalSurfaceData.MAOSBlend.y + decalSurfaceData.mask.y;
|
|
#endif
|
|
|
|
surfaceData.perceptualSmoothness = surfaceData.perceptualSmoothness * decalSurfaceData.mask.w + decalSurfaceData.mask.z;
|
|
}
|
|
|
|
void BuildSurfaceData(FragInputs fragInputs, inout GlobalSurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS)
|
|
{
|
|
ZERO_INITIALIZE(SurfaceData, surfaceData);
|
|
surfaceData.specularOcclusion = 1.0;
|
|
|
|
surfaceData.diffuseColor = surfaceDescription.BaseColor;
|
|
surfaceData.perceptualSmoothness = surfaceDescription.Smoothness;
|
|
surfaceData.ambientOcclusion = surfaceDescription.Occlusion;
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_KAJIYA_KAY
|
|
surfaceData.transmittance = surfaceDescription.Transmittance;
|
|
surfaceData.rimTransmissionIntensity = surfaceDescription.RimTransmissionIntensity;
|
|
surfaceData.specularTint = surfaceDescription.SpecularTint;
|
|
surfaceData.specularShift = surfaceDescription.SpecularShift;
|
|
surfaceData.secondaryPerceptualSmoothness = surfaceDescription.SecondarySmoothness;
|
|
surfaceData.secondarySpecularTint = surfaceDescription.SecondarySpecularTint;
|
|
surfaceData.secondarySpecularShift = surfaceDescription.SecondarySpecularShift;
|
|
#endif
|
|
|
|
//#ifdef _MATERIAL_FEATURE_HAIR_MARSCHNER
|
|
surfaceData.perceptualRadialSmoothness = surfaceDescription.RadialSmoothness;
|
|
surfaceData.cuticleAngle = surfaceDescription.CuticleAngle;
|
|
//#endif
|
|
|
|
surfaceData.strandCountProbe = surfaceDescription.StrandCountProbe;
|
|
|
|
#ifdef _USE_SPLINE_VISIBILITY_FOR_MULTIPLE_SCATTERING
|
|
surfaceData.strandShadowBias = surfaceDescription.StrandShadowBias;
|
|
#endif
|
|
|
|
#ifdef _SPECULAR_OCCLUSION_CUSTOM
|
|
surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion;
|
|
#endif
|
|
|
|
#ifdef ASE_BAKEDGI
|
|
builtinData.bakeDiffuseLighting = surfaceDescription.BakedGI;
|
|
#endif
|
|
|
|
#ifdef ASE_BAKEDBACKGI
|
|
builtinData.backBakeDiffuseLighting = surfaceDescription.BakedBackGI;
|
|
#endif
|
|
|
|
surfaceData.materialFeatures = 0;
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_KAJIYA_KAY
|
|
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_HAIR_KAJIYA_KAY;
|
|
#endif
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_MARSCHNER
|
|
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_HAIR_MARSCHNER;
|
|
#endif
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_MARSCHNER_CINEMATIC
|
|
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_HAIR_MARSCHNER_CINEMATIC;
|
|
#endif
|
|
|
|
#ifdef _DOUBLESIDED_ON
|
|
float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
|
|
#else
|
|
float3 doubleSidedConstants = float3( 1.0, 1.0, 1.0 );
|
|
#endif
|
|
|
|
float3 normalTS = float3(0.0f, 0.0f, 1.0f);
|
|
normalTS = surfaceDescription.Normal;
|
|
|
|
#ifdef DECAL_NORMAL_BLENDING
|
|
normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]);
|
|
|
|
#if HAVE_DECALS
|
|
if (_EnableDecals)
|
|
{
|
|
float alpha = 1.0;
|
|
alpha = surfaceDescription.Alpha;
|
|
|
|
DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
|
|
ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS);
|
|
ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData);
|
|
}
|
|
#endif
|
|
|
|
GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants);
|
|
#else
|
|
GetNormalWS(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants);
|
|
|
|
#if HAVE_DECALS
|
|
if (_EnableDecals)
|
|
{
|
|
float alpha = 1.0;
|
|
alpha = surfaceDescription.Alpha;
|
|
|
|
DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
|
|
ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz);
|
|
ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData);
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];
|
|
surfaceData.hairStrandDirectionWS = -fragInputs.tangentToWorld[1].xyz;
|
|
surfaceData.hairStrandDirectionWS = normalize(surfaceData.hairStrandDirectionWS);
|
|
|
|
#ifdef ASE_HAIRDIRECTION
|
|
surfaceData.hairStrandDirectionWS = TransformTangentToWorld(surfaceDescription.HairStrandDirection, fragInputs.tangentToWorld);
|
|
#endif
|
|
|
|
#if (_USE_LIGHT_FACING_NORMAL)
|
|
float3 viewFacingNormalWS = ComputeViewFacingNormal(V, surfaceData.hairStrandDirectionWS);
|
|
float3 N = viewFacingNormalWS;
|
|
#else
|
|
float3 N = surfaceData.normalWS;
|
|
#endif
|
|
|
|
bentNormalWS = surfaceData.normalWS;
|
|
|
|
#ifdef ASE_BENT_NORMAL
|
|
GetNormalWS( fragInputs, surfaceDescription.BentNormal, bentNormalWS, doubleSidedConstants );
|
|
#endif
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
#if !defined(SHADER_STAGE_RAY_TRACING)
|
|
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
|
|
{
|
|
#ifdef FRAG_INPUTS_USE_TEXCOORD0
|
|
surfaceData.diffuseColor = GET_TEXTURE_STREAMING_DEBUG(posInput.positionSS, fragInputs.texCoord0);
|
|
#else
|
|
surfaceData.diffuseColor = GET_TEXTURE_STREAMING_DEBUG_NO_UV(posInput.positionSS);
|
|
#endif
|
|
}
|
|
#endif
|
|
ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData);
|
|
#endif
|
|
|
|
#if defined(_SPECULAR_OCCLUSION_CUSTOM)
|
|
#elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL)
|
|
surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness));
|
|
#elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO)
|
|
surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness));
|
|
#endif
|
|
|
|
#ifdef _ENABLE_GEOMETRIC_SPECULAR_AA
|
|
surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold);
|
|
#endif
|
|
}
|
|
|
|
// Get Surface And BuiltinData
|
|
void GetSurfaceAndBuiltinData(GlobalSurfaceDescription surfaceDescription, FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData)
|
|
{
|
|
#ifdef LOD_FADE_CROSSFADE
|
|
LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x);
|
|
#endif
|
|
|
|
#ifdef _DOUBLESIDED_ON
|
|
float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
|
|
#else
|
|
float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
|
|
#endif
|
|
ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants);
|
|
|
|
#ifdef _ALPHATEST_ON
|
|
DoAlphaTest( surfaceDescription.Alpha, surfaceDescription.AlphaClipThreshold );
|
|
#endif
|
|
|
|
#ifdef _ALPHATEST_SHADOW_ON
|
|
DoAlphaTest( surfaceDescription.Alpha, surfaceDescription.AlphaClipThresholdShadow);
|
|
#endif
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput);
|
|
#endif
|
|
|
|
float3 bentNormalWS;
|
|
BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS);
|
|
InitBuiltinData(posInput, surfaceDescription.Alpha, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData);
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
builtinData.depthOffset = surfaceDescription.DepthOffset;
|
|
#endif
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
|
|
{
|
|
surfaceDescription.Alpha = 1.0f;
|
|
}
|
|
#endif
|
|
|
|
#ifdef _ALPHATEST_ON
|
|
builtinData.alphaClipTreshold = surfaceDescription.AlphaClipThreshold;
|
|
#endif
|
|
|
|
#ifdef UNITY_VIRTUAL_TEXTURING
|
|
builtinData.vtPackedFeedback = surfaceDescription.VTPackedFeedback;
|
|
#endif
|
|
|
|
#ifdef ASE_BAKEDGI
|
|
builtinData.bakeDiffuseLighting = surfaceDescription.BakedGI;
|
|
#endif
|
|
|
|
#ifdef ASE_BAKEDBACKGI
|
|
builtinData.backBakeDiffuseLighting = surfaceDescription.BakedBackGI;
|
|
#endif
|
|
|
|
builtinData.emissiveColor = surfaceDescription.Emission;
|
|
|
|
PostInitBuiltinData(V, posInput, surfaceData, builtinData);
|
|
}
|
|
|
|
AttributesMesh ApplyMeshModification(AttributesMesh inputMesh, float3 timeParameters, inout PackedVaryingsMeshToPS outputPackedVaryingsMeshToPS/*ase_vert_input*/ )
|
|
{
|
|
_TimeParameters.xyz = timeParameters;
|
|
/*ase_vert_code:inputMesh=AttributesMesh;outputPackedVaryingsMeshToPS=PackedVaryingsMeshToPS*/
|
|
|
|
#ifdef ASE_ABSOLUTE_VERTEX_POS
|
|
float3 defaultVertexValue = inputMesh.positionOS.xyz;
|
|
#else
|
|
float3 defaultVertexValue = float3( 0, 0, 0 );
|
|
#endif
|
|
float3 vertexValue = /*ase_vert_out:Vertex Offset;Float3;24;-1;_VertexOffset*/defaultVertexValue/*end*/;
|
|
|
|
#ifdef ASE_ABSOLUTE_VERTEX_POS
|
|
inputMesh.positionOS.xyz = vertexValue;
|
|
#else
|
|
inputMesh.positionOS.xyz += vertexValue;
|
|
#endif
|
|
inputMesh.normalOS = /*ase_vert_out:Vertex Normal;Float3;25;-1;_VertexNormal*/inputMesh.normalOS/*end*/;
|
|
inputMesh.tangentOS = /*ase_vert_out:Vertex Tangent;Float4;26;-1;_VertexTangent*/inputMesh.tangentOS/*end*/;
|
|
return inputMesh;
|
|
}
|
|
|
|
PackedVaryingsMeshToPS VertexFunction(AttributesMesh inputMesh)
|
|
{
|
|
PackedVaryingsMeshToPS outputPackedVaryingsMeshToPS = (PackedVaryingsMeshToPS)0;
|
|
AttributesMesh defaultMesh = inputMesh;
|
|
|
|
UNITY_SETUP_INSTANCE_ID(inputMesh);
|
|
UNITY_TRANSFER_INSTANCE_ID(inputMesh, outputPackedVaryingsMeshToPS);
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO( outputPackedVaryingsMeshToPS );
|
|
|
|
inputMesh = ApplyMeshModification( inputMesh, _TimeParameters.xyz, outputPackedVaryingsMeshToPS);
|
|
|
|
float3 positionRWS = TransformObjectToWorld(inputMesh.positionOS);
|
|
float3 normalWS = TransformObjectToWorldNormal(inputMesh.normalOS);
|
|
float4 tangentWS = float4(TransformObjectToWorldDir(inputMesh.tangentOS.xyz), inputMesh.tangentOS.w);
|
|
|
|
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
|
|
float4 VPASSpreviousPositionCS;
|
|
float4 VPASSpositionCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS, 1.0));
|
|
|
|
bool forceNoMotion = unity_MotionVectorsParams.y == 0.0;
|
|
if (forceNoMotion)
|
|
{
|
|
VPASSpreviousPositionCS = float4(0.0, 0.0, 0.0, 1.0);
|
|
}
|
|
else
|
|
{
|
|
bool hasDeformation = unity_MotionVectorsParams.x > 0.0;
|
|
float3 effectivePositionOS = (hasDeformation ? inputMesh.previousPositionOS : defaultMesh.positionOS);
|
|
#if defined(_ADD_PRECOMPUTED_VELOCITY)
|
|
effectivePositionOS -= inputMesh.precomputedVelocity;
|
|
#endif
|
|
|
|
#if defined(HAVE_MESH_MODIFICATION)
|
|
AttributesMesh previousMesh = defaultMesh;
|
|
previousMesh.positionOS = effectivePositionOS ;
|
|
PackedVaryingsMeshToPS test = (PackedVaryingsMeshToPS)0;
|
|
float3 curTime = _TimeParameters.xyz;
|
|
previousMesh = ApplyMeshModification(previousMesh, _LastTimeParameters.xyz, test);
|
|
_TimeParameters.xyz = curTime;
|
|
float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.positionOS);
|
|
#else
|
|
float3 previousPositionRWS = TransformPreviousObjectToWorld(effectivePositionOS);
|
|
#endif
|
|
|
|
#ifdef ATTRIBUTES_NEED_NORMAL
|
|
float3 normalWS = TransformPreviousObjectToWorldNormal(defaultMesh.normalOS);
|
|
#else
|
|
float3 normalWS = float3(0.0, 0.0, 0.0);
|
|
#endif
|
|
|
|
#if defined(HAVE_VERTEX_MODIFICATION)
|
|
ApplyVertexModification(inputMesh, normalWS, previousPositionRWS, _LastTimeParameters.xyz);
|
|
#endif
|
|
|
|
VPASSpreviousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0));
|
|
}
|
|
#endif
|
|
|
|
outputPackedVaryingsMeshToPS.positionCS = TransformWorldToHClip(positionRWS);
|
|
outputPackedVaryingsMeshToPS.positionRWS.xyz = positionRWS;
|
|
outputPackedVaryingsMeshToPS.normalWS.xyz = normalWS;
|
|
outputPackedVaryingsMeshToPS.tangentWS.xyzw = tangentWS;
|
|
outputPackedVaryingsMeshToPS.uv1.xyzw = inputMesh.uv1;
|
|
outputPackedVaryingsMeshToPS.uv2.xyzw = inputMesh.uv2;
|
|
|
|
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
|
|
outputPackedVaryingsMeshToPS.vpassPositionCS = float3(VPASSpositionCS.xyw);
|
|
outputPackedVaryingsMeshToPS.vpassPreviousPositionCS = float3(VPASSpreviousPositionCS.xyw);
|
|
#endif
|
|
return outputPackedVaryingsMeshToPS;
|
|
}
|
|
|
|
#if defined(ASE_TESSELLATION)
|
|
struct VertexControl
|
|
{
|
|
float3 positionOS : INTERNALTESSPOS;
|
|
float3 normalOS : NORMAL;
|
|
float4 tangentOS : TANGENT;
|
|
float4 uv1 : TEXCOORD1;
|
|
float4 uv2 : TEXCOORD2;
|
|
/*ase_vcontrol*/
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
struct TessellationFactors
|
|
{
|
|
float edge[3] : SV_TessFactor;
|
|
float inside : SV_InsideTessFactor;
|
|
};
|
|
|
|
VertexControl Vert ( AttributesMesh v )
|
|
{
|
|
VertexControl o;
|
|
UNITY_SETUP_INSTANCE_ID(v);
|
|
UNITY_TRANSFER_INSTANCE_ID(v, o);
|
|
o.positionOS = v.positionOS;
|
|
o.normalOS = v.normalOS;
|
|
o.tangentOS = v.tangentOS;
|
|
o.uv1 = v.uv1;
|
|
o.uv2 = v.uv2;
|
|
/*ase_control_code:v=AttributesMesh;o=VertexControl*/
|
|
return o;
|
|
}
|
|
|
|
TessellationFactors TessellationFunction (InputPatch<VertexControl,3> v)
|
|
{
|
|
TessellationFactors o;
|
|
float4 tf = 1;
|
|
float tessValue = /*ase_inline_begin*/_TessValue/*ase_inline_end*/; float tessMin = /*ase_inline_begin*/_TessMin/*ase_inline_end*/; float tessMax = /*ase_inline_begin*/_TessMax/*ase_inline_end*/;
|
|
float edgeLength = /*ase_inline_begin*/_TessEdgeLength/*ase_inline_end*/; float tessMaxDisp = /*ase_inline_begin*/_TessMaxDisp/*ase_inline_end*/;
|
|
#if (SHADEROPTIONS_CAMERA_RELATIVE_RENDERING != 0)
|
|
float3 cameraPos = 0;
|
|
#else
|
|
float3 cameraPos = _WorldSpaceCameraPos;
|
|
#endif
|
|
#if defined(ASE_FIXED_TESSELLATION)
|
|
tf = FixedTess( tessValue );
|
|
#elif defined(ASE_DISTANCE_TESSELLATION)
|
|
tf = DistanceBasedTess(float4(v[0].positionOS,1), float4(v[1].positionOS,1), float4(v[2].positionOS,1), tessValue, tessMin, tessMax, GetObjectToWorldMatrix(), cameraPos );
|
|
#elif defined(ASE_LENGTH_TESSELLATION)
|
|
tf = EdgeLengthBasedTess(float4(v[0].positionOS,1), float4(v[1].positionOS,1), float4(v[2].positionOS,1), edgeLength, GetObjectToWorldMatrix(), cameraPos, _ScreenParams );
|
|
#elif defined(ASE_LENGTH_CULL_TESSELLATION)
|
|
tf = EdgeLengthBasedTessCull(float4(v[0].positionOS,1), float4(v[1].positionOS,1), float4(v[2].positionOS,1), edgeLength, tessMaxDisp, GetObjectToWorldMatrix(), cameraPos, _ScreenParams, _FrustumPlanes );
|
|
#endif
|
|
o.edge[0] = tf.x; o.edge[1] = tf.y; o.edge[2] = tf.z; o.inside = tf.w;
|
|
return o;
|
|
}
|
|
|
|
[domain("tri")]
|
|
[partitioning("fractional_odd")]
|
|
[outputtopology("triangle_cw")]
|
|
[patchconstantfunc("TessellationFunction")]
|
|
[outputcontrolpoints(3)]
|
|
VertexControl HullFunction(InputPatch<VertexControl, 3> patch, uint id : SV_OutputControlPointID)
|
|
{
|
|
return patch[id];
|
|
}
|
|
|
|
[domain("tri")]
|
|
PackedVaryingsMeshToPS DomainFunction(TessellationFactors factors, OutputPatch<VertexControl, 3> patch, float3 bary : SV_DomainLocation)
|
|
{
|
|
AttributesMesh o = (AttributesMesh) 0;
|
|
o.positionOS = patch[0].positionOS * bary.x + patch[1].positionOS * bary.y + patch[2].positionOS * bary.z;
|
|
o.normalOS = patch[0].normalOS * bary.x + patch[1].normalOS * bary.y + patch[2].normalOS * bary.z;
|
|
o.tangentOS = patch[0].tangentOS * bary.x + patch[1].tangentOS * bary.y + patch[2].tangentOS * bary.z;
|
|
o.uv1 = patch[0].uv1 * bary.x + patch[1].uv1 * bary.y + patch[2].uv1 * bary.z;
|
|
o.uv2 = patch[0].uv2 * bary.x + patch[1].uv2 * bary.y + patch[2].uv2 * bary.z;
|
|
/*ase_domain_code:patch=VertexControl;o=AttributesMesh;bary=SV_DomainLocation*/
|
|
#if defined(ASE_PHONG_TESSELLATION)
|
|
float3 pp[3];
|
|
for (int i = 0; i < 3; ++i)
|
|
pp[i] = o.positionOS.xyz - patch[i].normalOS * (dot(o.positionOS.xyz, patch[i].normalOS) - dot(patch[i].positionOS.xyz, patch[i].normalOS));
|
|
float phongStrength = /*ase_inline_begin*/_TessPhongStrength/*ase_inline_end*/;
|
|
o.positionOS.xyz = phongStrength * (pp[0]*bary.x + pp[1]*bary.y + pp[2]*bary.z) + (1.0f-phongStrength) * o.positionOS.xyz;
|
|
#endif
|
|
UNITY_TRANSFER_INSTANCE_ID(patch[0], o);
|
|
return VertexFunction(o);
|
|
}
|
|
#else
|
|
PackedVaryingsMeshToPS Vert ( AttributesMesh v )
|
|
{
|
|
return VertexFunction( v );
|
|
}
|
|
#endif
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplayMaterial.hlsl"
|
|
|
|
#if defined(_TRANSPARENT_REFRACTIVE_SORT) || defined(_ENABLE_FOG_ON_TRANSPARENT)
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Water/Shaders/UnderWaterUtilities.hlsl"
|
|
#endif
|
|
|
|
#ifdef UNITY_VIRTUAL_TEXTURING
|
|
#ifdef OUTPUT_SPLIT_LIGHTING
|
|
#define DIFFUSE_LIGHTING_TARGET SV_Target2
|
|
#define SSS_BUFFER_TARGET SV_Target3
|
|
#elif defined(_WRITE_TRANSPARENT_MOTION_VECTOR)
|
|
#define MOTION_VECTOR_TARGET SV_Target2
|
|
#ifdef _TRANSPARENT_REFRACTIVE_SORT
|
|
#define BEFORE_REFRACTION_TARGET SV_Target3
|
|
#define BEFORE_REFRACTION_ALPHA_TARGET SV_Target4
|
|
#endif
|
|
#endif
|
|
#if defined(SHADER_API_PSSL)
|
|
#pragma PSSL_target_output_format(target 1 FMT_32_ABGR)
|
|
#endif
|
|
#else
|
|
#ifdef OUTPUT_SPLIT_LIGHTING
|
|
#define DIFFUSE_LIGHTING_TARGET SV_Target1
|
|
#define SSS_BUFFER_TARGET SV_Target2
|
|
#elif defined(_WRITE_TRANSPARENT_MOTION_VECTOR)
|
|
#define MOTION_VECTOR_TARGET SV_Target1
|
|
#ifdef _TRANSPARENT_REFRACTIVE_SORT
|
|
#define BEFORE_REFRACTION_TARGET SV_Target2
|
|
#define BEFORE_REFRACTION_ALPHA_TARGET SV_Target3
|
|
#endif
|
|
#endif
|
|
#endif
|
|
|
|
void Frag(PackedVaryingsMeshToPS packedInput
|
|
, out float4 outColor:SV_Target0
|
|
#ifdef UNITY_VIRTUAL_TEXTURING
|
|
, out float4 outVTFeedback : SV_Target1
|
|
#endif
|
|
#ifdef OUTPUT_SPLIT_LIGHTING
|
|
, out float4 outDiffuseLighting : DIFFUSE_LIGHTING_TARGET
|
|
, OUTPUT_SSSBUFFER(outSSSBuffer) : SSS_BUFFER_TARGET
|
|
#elif defined(_WRITE_TRANSPARENT_MOTION_VECTOR)
|
|
, out float4 outMotionVec : MOTION_VECTOR_TARGET
|
|
#ifdef _TRANSPARENT_REFRACTIVE_SORT
|
|
, out float4 outBeforeRefractionColor : BEFORE_REFRACTION_TARGET
|
|
, out float4 outBeforeRefractionAlpha : BEFORE_REFRACTION_ALPHA_TARGET
|
|
#endif
|
|
#endif
|
|
#ifdef _DEPTHOFFSET_ON
|
|
, out float outputDepth : DEPTH_OFFSET_SEMANTIC
|
|
#endif
|
|
/*ase_frag_input*/
|
|
)
|
|
{
|
|
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
|
|
outMotionVec = float4(2.0, 0.0, 0.0, 1.0);
|
|
#endif
|
|
|
|
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX( packedInput );
|
|
UNITY_SETUP_INSTANCE_ID( packedInput );
|
|
/*ase_local_var:rwp*/float3 positionRWS = packedInput.positionRWS.xyz;
|
|
/*ase_local_var:wn*/float3 normalWS = packedInput.normalWS.xyz;
|
|
/*ase_local_var:wt*/float4 tangentWS = packedInput.tangentWS.xyzw;
|
|
|
|
FragInputs input;
|
|
ZERO_INITIALIZE(FragInputs, input);
|
|
input.tangentToWorld = k_identity3x3;
|
|
input.positionSS = packedInput.positionCS;
|
|
input.positionRWS = positionRWS;
|
|
input.tangentToWorld = BuildTangentToWorld(tangentWS, normalWS);
|
|
input.texCoord1 = packedInput.uv1.xyzw;
|
|
input.texCoord2 = packedInput.uv2.xyzw;
|
|
|
|
#if _DOUBLESIDED_ON && SHADER_STAGE_FRAGMENT
|
|
input.isFrontFace = IS_FRONT_VFACE( packedInput.cullFace, true, false);
|
|
#elif SHADER_STAGE_FRAGMENT
|
|
#if defined(ASE_NEED_CULLFACE)
|
|
input.isFrontFace = IS_FRONT_VFACE(packedInput.cullFace, true, false);
|
|
#endif
|
|
#endif
|
|
/*ase_local_var:vf*/half isFrontFace = input.isFrontFace;
|
|
|
|
AdjustFragInputsToOffScreenRendering(input, _OffScreenRendering > 0, _OffScreenDownsampleFactor);
|
|
uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize ();
|
|
|
|
PositionInputs posInput = GetPositionInput( input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex );
|
|
|
|
/*ase_local_var:wvd*/float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
|
|
|
|
GlobalSurfaceDescription surfaceDescription = (GlobalSurfaceDescription)0;
|
|
/*ase_frag_code:packedInput=PackedVaryingsMeshToPS*/
|
|
surfaceDescription.BaseColor = /*ase_frag_out:Base Color;Float3;0;-1;_BaseColor*/float3( 0.7353569, 0.7353569, 0.7353569 )/*end*/;
|
|
surfaceDescription.Normal = /*ase_frag_out:Normal;Float3;1;-1;_Normal*/float3( 0, 0, 1 )/*end*/;
|
|
surfaceDescription.BentNormal = /*ase_frag_out:Bent Normal;Float3;2;-1;_BentNormal*/float3( 0, 0, 1 )/*end*/;
|
|
surfaceDescription.HairStrandDirection = /*ase_frag_out:Hair Strand Direction;Float3;7;-1;_HairStrandDirection*/float3(0,-1,0)/*end*/;
|
|
surfaceDescription.Emission = /*ase_frag_out:Emission;Float3;45;-1;_Emission*/float3(0,0,0)/*end*/;
|
|
surfaceDescription.Smoothness = /*ase_frag_out:Smoothness;Float;3;-1;_Smoothness*/0.5/*end*/;
|
|
surfaceDescription.Occlusion = /*ase_frag_out:Occlusion;Float;4;-1;_Occlusion*/1/*end*/;
|
|
|
|
surfaceDescription.Alpha = /*ase_frag_out:Alpha;Float;8;-1;_Alpha*/1/*end*/;
|
|
|
|
#ifdef _ALPHATEST_ON
|
|
surfaceDescription.AlphaClipThreshold = /*ase_frag_out:Alpha Clip Threshold;Float;9;-1;_AlphaClip*/_AlphaCutoff/*end*/;
|
|
#endif
|
|
|
|
#ifdef _ALPHATEST_SHADOW_ON
|
|
surfaceDescription.AlphaClipThresholdShadow = /*ase_frag_out:Alpha Clip Threshold Shadow;Float;10;-1;_AlphaClipShadow*/0.5/*end*/;
|
|
#endif
|
|
|
|
surfaceDescription.AlphaClipThresholdDepthPrepass = /*ase_frag_out:Alpha Clip Threshold Depth Prepass;Float;11;-1;_AlphaClipDepthPrepass*/0.5/*end*/;
|
|
surfaceDescription.AlphaClipThresholdDepthPostpass = /*ase_frag_out:Alpha Clip Threshold Depth Postpass;Float;12;-1;_AlphaClipDepthPostpass*/0.5/*end*/;
|
|
|
|
#ifdef _SPECULAR_OCCLUSION_CUSTOM
|
|
surfaceDescription.SpecularOcclusion = /*ase_frag_out:Specular Occlusion;Float;13;-1;_SpecularOcclusion*/1/*end*/;
|
|
#endif
|
|
|
|
#ifdef _ENABLE_GEOMETRIC_SPECULAR_AA
|
|
surfaceDescription.SpecularAAScreenSpaceVariance = /*ase_frag_out:Specular AA Screen Space Variance;Float;14;-1;_SpecularAAScreenSpaceVariance*/0.1/*end*/;
|
|
surfaceDescription.SpecularAAThreshold = /*ase_frag_out:Specular AA Threshold;Float;15;-1;_SpecularAAThreshold*/0.2/*end*/;
|
|
#endif
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_KAJIYA_KAY
|
|
surfaceDescription.Transmittance = /*ase_frag_out:Transmittance;Float3;5;-1;_Transmittance*/float3(0.3,0.195,0.09)/*end*/;
|
|
surfaceDescription.RimTransmissionIntensity = /*ase_frag_out:Rim Transmission Intensity;Float;6;-1;_RimTransmissionIntensity*/0.2/*end*/;
|
|
surfaceDescription.SpecularTint = /*ase_frag_out:Specular Tint;Float3;16;-1;_SpecularTint*/float3(1,1,1)/*end*/;
|
|
surfaceDescription.SpecularShift = /*ase_frag_out:Specular Shift;Float;17;-1;_SpecularShift*/0.1/*end*/;
|
|
surfaceDescription.SecondarySpecularTint = /*ase_frag_out:Secondary Specular Tint;Float3;18;-1;_SecondarySpecularTint*/float3(0.5,0.5,0.5)/*end*/;
|
|
surfaceDescription.SecondarySmoothness = /*ase_frag_out:Secondary Smoothness;Float;19;-1;_SecondarySmoothness*/0.5/*end*/;
|
|
surfaceDescription.SecondarySpecularShift = /*ase_frag_out:Secondary Specular Shift;Float;20;-1;_SecondarySpecularShift*/-0.1/*end*/;
|
|
#endif
|
|
|
|
//#ifdef _MATERIAL_FEATURE_HAIR_MARSCHNER
|
|
surfaceDescription.RadialSmoothness = /*ase_frag_out:Radial Smoothness;Float;41;-1;_RadialSmoothness*/0.7/*end*/;
|
|
surfaceDescription.CuticleAngle = /*ase_frag_out:Cuticle Angle Shift;Float;42;-1;_CuticleAngle*/-0.1/*end*/;
|
|
//#endif
|
|
|
|
surfaceDescription.StrandCountProbe = /*ase_frag_out:Strand Count Probe;Float4;43;-1;_StrandCountProbe*/float4(0,0,0,0)/*end*/;
|
|
|
|
#ifdef _USE_SPLINE_VISIBILITY_FOR_MULTIPLE_SCATTERING
|
|
surfaceDescription.StrandShadowBias = /*ase_frag_out:Strand Shadow Bias;Float;44;-1;_StrandShadowBias*/0/*end*/;
|
|
#endif
|
|
|
|
#ifdef ASE_BAKEDGI
|
|
surfaceDescription.BakedGI = /*ase_frag_out:Baked GI;Float3;21;-1;_BakedGI*/float3(0,0,0)/*end*/;
|
|
#endif
|
|
|
|
#ifdef ASE_BAKEDBACKGI
|
|
surfaceDescription.BakedBackGI = /*ase_frag_out:Baked Back GI;Float3;22;-1;_BakedBackGI*/float3(0,0,0)/*end*/;
|
|
#endif
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
surfaceDescription.DepthOffset = /*ase_frag_out:Depth Offset;Float;23;-1;_DepthOffset*/0/*end*/;
|
|
#endif
|
|
|
|
#ifdef UNITY_VIRTUAL_TEXTURING
|
|
surfaceDescription.VTPackedFeedback = float4(1.0f,1.0f,1.0f,1.0f);
|
|
#endif
|
|
|
|
SurfaceData surfaceData;
|
|
BuiltinData builtinData;
|
|
GetSurfaceAndBuiltinData(surfaceDescription,input, V, posInput, surfaceData, builtinData);
|
|
|
|
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData);
|
|
|
|
PreLightData preLightData = GetPreLightData(V, posInput, bsdfData);
|
|
|
|
outColor = float4(0.0, 0.0, 0.0, 0.0);
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
#ifdef OUTPUT_SPLIT_LIGHTING
|
|
outDiffuseLighting = float4(0, 0, 0, 1);
|
|
ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer);
|
|
#endif
|
|
|
|
bool viewMaterial = GetMaterialDebugColor(outColor, input, builtinData, posInput, surfaceData, bsdfData);
|
|
|
|
if (!viewMaterial)
|
|
{
|
|
if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_DIFFUSE_COLOR || _DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_SPECULAR_COLOR)
|
|
{
|
|
float3 result = float3(0.0, 0.0, 0.0);
|
|
GetPBRValidatorDebug(surfaceData, result);
|
|
outColor = float4(result, 1.0f);
|
|
}
|
|
else if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_TRANSPARENCY_OVERDRAW)
|
|
{
|
|
float4 result = _DebugTransparencyOverdrawWeight * float4(TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_A);
|
|
outColor = result;
|
|
}
|
|
else
|
|
#endif
|
|
{
|
|
#ifdef _SURFACE_TYPE_TRANSPARENT
|
|
uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_TRANSPARENT;
|
|
#else
|
|
uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_OPAQUE;
|
|
#endif
|
|
LightLoopOutput lightLoopOutput;
|
|
LightLoop(V, posInput, preLightData, bsdfData, builtinData, featureFlags, lightLoopOutput);
|
|
|
|
// Alias
|
|
float3 diffuseLighting = lightLoopOutput.diffuseLighting;
|
|
float3 specularLighting = lightLoopOutput.specularLighting;
|
|
|
|
diffuseLighting *= GetCurrentExposureMultiplier();
|
|
specularLighting *= GetCurrentExposureMultiplier();
|
|
|
|
#ifdef OUTPUT_SPLIT_LIGHTING
|
|
if (_EnableSubsurfaceScattering != 0 && ShouldOutputSplitLighting(bsdfData))
|
|
{
|
|
outColor = float4(specularLighting, 1.0);
|
|
outDiffuseLighting = float4(TagLightingForSSS(diffuseLighting), 1.0);
|
|
}
|
|
else
|
|
{
|
|
outColor = float4(diffuseLighting + specularLighting, 1.0);
|
|
outDiffuseLighting = float4(0, 0, 0, 1);
|
|
}
|
|
ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer);
|
|
#else
|
|
outColor = ApplyBlendMode(diffuseLighting, specularLighting, builtinData.opacity);
|
|
|
|
#ifdef _ENABLE_FOG_ON_TRANSPARENT
|
|
outColor = EvaluateAtmosphericScattering(posInput, V, outColor);
|
|
#endif
|
|
|
|
#ifdef _TRANSPARENT_REFRACTIVE_SORT
|
|
ComputeRefractionSplitColor(posInput, outColor, outBeforeRefractionColor, outBeforeRefractionAlpha);
|
|
#endif
|
|
#endif
|
|
|
|
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
|
|
float4 VPASSpositionCS = float4(packedInput.vpassPositionCS.xy, 0.0, packedInput.vpassPositionCS.z);
|
|
float4 VPASSpreviousPositionCS = float4(packedInput.vpassPreviousPositionCS.xy, 0.0, packedInput.vpassPreviousPositionCS.z);
|
|
bool forceNoMotion = any(unity_MotionVectorsParams.yw == 0.0);
|
|
#if defined(HAVE_VFX_MODIFICATION) && !VFX_FEATURE_MOTION_VECTORS
|
|
forceNoMotion = true;
|
|
#endif
|
|
if (!forceNoMotion)
|
|
{
|
|
float2 motionVec = CalculateMotionVector(VPASSpositionCS, VPASSpreviousPositionCS);
|
|
EncodeMotionVector(motionVec * 0.5, outMotionVec);
|
|
outMotionVec.zw = 1.0;
|
|
}
|
|
#endif
|
|
}
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
}
|
|
#endif
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
outputDepth = posInput.deviceDepth;
|
|
#endif
|
|
|
|
#ifdef UNITY_VIRTUAL_TEXTURING
|
|
float vtAlphaValue = builtinData.opacity;
|
|
#if defined(HAS_REFRACTION) && HAS_REFRACTION
|
|
vtAlphaValue = 1.0f - bsdfData.transmittanceMask;
|
|
#endif
|
|
outVTFeedback = PackVTFeedbackWithAlpha(builtinData.vtPackedFeedback, input.positionSS.xy, vtAlphaValue);
|
|
outVTFeedback.rgb *= outVTFeedback.a; // premuliplied alpha
|
|
#endif
|
|
|
|
}
|
|
ENDHLSL
|
|
}
|
|
|
|
/*ase_pass*/
|
|
Pass
|
|
{
|
|
/*ase_hide_pass*/
|
|
Name "DepthForwardOnly"
|
|
Tags
|
|
{
|
|
"LightMode" = "DepthForwardOnly"
|
|
}
|
|
|
|
Cull [_CullMode]
|
|
ZWrite On
|
|
|
|
Stencil
|
|
{
|
|
WriteMask [_StencilWriteMaskDepth]
|
|
Ref [_StencilRefDepth]
|
|
CompFront Always
|
|
PassFront Replace
|
|
CompBack Always
|
|
PassBack Replace
|
|
}
|
|
AlphaToMask [_AlphaCutoffEnable]
|
|
|
|
HLSLPROGRAM
|
|
#pragma multi_compile _ DOTS_INSTANCING_ON
|
|
|
|
#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT
|
|
#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC _TRANSPARENT_REFRACTIVE_SORT
|
|
#pragma shader_feature_local_fragment _ _ENABLE_FOG_ON_TRANSPARENT
|
|
|
|
#pragma multi_compile _ WRITE_NORMAL_BUFFER
|
|
#pragma multi_compile_fragment _ WRITE_MSAA_DEPTH
|
|
#pragma multi_compile_fragment _ WRITE_DECAL_BUFFER WRITE_RENDERING_LAYER
|
|
|
|
// RayTracing
|
|
//#pragma shader_feature_local_raytracing _ _DISABLE_DECALS
|
|
//#pragma shader_feature_local_raytracing _ _DISABLE_SSR
|
|
//#pragma shader_feature_local_raytracing _ _DISABLE_SSR_TRANSPARENT
|
|
|
|
#pragma vertex Vert
|
|
#pragma fragment Frag
|
|
|
|
#define SHADERPASS SHADERPASS_DEPTH_ONLY
|
|
#define WRITE_NORMAL_BUFFER 1
|
|
#define _ABSORPTION_FROM_COLOR 1
|
|
#define SUPPORT_GLOBAL_MIP_BIAS 1
|
|
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl"
|
|
#include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl"
|
|
|
|
//#if !defined(SHADER_STAGE_RAY_TRACING) && SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER && SHADERPASS != SHADERPASS_FULL_SCREEN_DEBUG
|
|
//#define FRAG_INPUTS_ENABLE_STRIPPING
|
|
//#endif
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
|
|
|
|
#ifdef RAYTRACING_SHADER_GRAPH_DEFAULT
|
|
#define RAYTRACING_SHADER_GRAPH_HIGH
|
|
#endif
|
|
|
|
#ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED
|
|
#define RAYTRACING_SHADER_GRAPH_LOW
|
|
#endif
|
|
|
|
#ifndef SHADER_UNLIT
|
|
#if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE)
|
|
#define VARYINGS_NEED_CULLFACE
|
|
#endif
|
|
#endif
|
|
|
|
#if defined(_DOUBLESIDED_ON) && !defined(ASE_NEED_CULLFACE)
|
|
#define ASE_NEED_CULLFACE 1
|
|
#endif
|
|
|
|
#if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
|
|
#if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT)
|
|
#define WRITE_NORMAL_BUFFER
|
|
#endif
|
|
#endif
|
|
|
|
#if SHADERPASS == SHADERPASS_MOTION_VECTORS && defined(WRITE_DECAL_BUFFER_AND_RENDERING_LAYER)
|
|
#define WRITE_DECAL_BUFFER
|
|
#endif
|
|
|
|
#ifndef DEBUG_DISPLAY
|
|
#if !defined(_SURFACE_TYPE_TRANSPARENT)
|
|
#if SHADERPASS == SHADERPASS_FORWARD
|
|
#define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
|
|
#elif SHADERPASS == SHADERPASS_GBUFFER
|
|
#define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST
|
|
#endif
|
|
#endif
|
|
#endif
|
|
|
|
#if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT)
|
|
#define _DEFERRED_CAPABLE_MATERIAL
|
|
#endif
|
|
|
|
#if (defined(_TRANSPARENT_WRITES_MOTION_VEC) || defined(_TRANSPARENT_REFRACTIVE_SORT)) && defined(_SURFACE_TYPE_TRANSPARENT)
|
|
#define _WRITE_TRANSPARENT_MOTION_VECTOR
|
|
#endif
|
|
|
|
CBUFFER_START( UnityPerMaterial )
|
|
float4 _EmissionColor;
|
|
float _AlphaCutoff;
|
|
float _RenderQueueType;
|
|
#ifdef _ADD_PRECOMPUTED_VELOCITY
|
|
float _AddPrecomputedVelocity;
|
|
#endif
|
|
float _ExcludeFromTUAndAA;
|
|
float _StencilRef;
|
|
float _StencilWriteMask;
|
|
float _StencilRefDepth;
|
|
float _StencilWriteMaskDepth;
|
|
float _StencilRefMV;
|
|
float _StencilWriteMaskMV;
|
|
float _StencilRefDistortionVec;
|
|
float _StencilWriteMaskDistortionVec;
|
|
float _StencilWriteMaskGBuffer;
|
|
float _StencilRefGBuffer;
|
|
float _ZTestGBuffer;
|
|
float _RequireSplitLighting;
|
|
float _ReceivesSSR;
|
|
float _SurfaceType;
|
|
float _BlendMode;
|
|
#ifdef SUPPORT_BLENDMODE_PRESERVE_SPECULAR_LIGHTING
|
|
float _EnableBlendModePreserveSpecularLighting;
|
|
#endif
|
|
float _SrcBlend;
|
|
float _DstBlend;
|
|
float _DstBlend2;
|
|
float _AlphaSrcBlend;
|
|
float _AlphaDstBlend;
|
|
float _ZWrite;
|
|
float _TransparentZWrite;
|
|
float _CullMode;
|
|
float _TransparentSortPriority;
|
|
float _EnableFogOnTransparent;
|
|
float _CullModeForward;
|
|
float _TransparentCullMode;
|
|
float _ZTestDepthEqualForOpaque;
|
|
float _ZTestTransparent;
|
|
float _TransparentBackfaceEnable;
|
|
float _AlphaCutoffEnable;
|
|
float _UseShadowThreshold;
|
|
float _DoubleSidedEnable;
|
|
float _DoubleSidedNormalMode;
|
|
float4 _DoubleSidedConstants;
|
|
#ifdef ASE_TESSELLATION
|
|
float _TessPhongStrength;
|
|
float _TessValue;
|
|
float _TessMin;
|
|
float _TessMax;
|
|
float _TessEdgeLength;
|
|
float _TessMaxDisp;
|
|
#endif
|
|
UNITY_TEXTURE_STREAMING_DEBUG_VARS;
|
|
CBUFFER_END
|
|
|
|
#ifdef SCENEPICKINGPASS
|
|
float4 _SelectionID;
|
|
#endif
|
|
|
|
#ifdef SCENESELECTIONPASS
|
|
int _ObjectId;
|
|
int _PassValue;
|
|
#endif
|
|
|
|
/*ase_globals*/
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
|
|
#endif
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Hair/Hair.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl"
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl"
|
|
|
|
#if (defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS)) || defined(WRITE_RENDERING_LAYER)
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl"
|
|
#endif
|
|
|
|
#ifdef HAVE_VFX_MODIFICATION
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/VisualEffectVertex.hlsl"
|
|
#endif
|
|
|
|
/*ase_pragma*/
|
|
|
|
struct AttributesMesh
|
|
{
|
|
float3 positionOS : POSITION;
|
|
float3 normalOS : NORMAL;
|
|
float4 tangentOS : TANGENT;
|
|
/*ase_vdata:p=p;n=n;t=t*/
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
struct PackedVaryingsMeshToPS
|
|
{
|
|
SV_POSITION_QUALIFIERS float4 positionCS : SV_Position;
|
|
float3 positionRWS : TEXCOORD0;
|
|
float3 normalWS : TEXCOORD1;
|
|
float4 tangentWS : TEXCOORD2;
|
|
/*ase_interp(3,):sp=sp.xyzw;rwp=tc0;wn=tc1;wt=tc2*/
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
UNITY_VERTEX_OUTPUT_STEREO
|
|
#if defined(SHADER_STAGE_FRAGMENT) && defined(ASE_NEED_CULLFACE)
|
|
FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
|
|
#endif
|
|
};
|
|
|
|
/*ase_funcs*/
|
|
|
|
//Build Surface Data (Decal)
|
|
void ApplyDecalToSurfaceDataNoNormal(DecalSurfaceData decalSurfaceData, inout SurfaceData surfaceData)
|
|
{
|
|
surfaceData.diffuseColor.xyz = surfaceData.diffuseColor.xyz * decalSurfaceData.baseColor.w + decalSurfaceData.baseColor.xyz;
|
|
|
|
#ifdef DECALS_4RT
|
|
surfaceData.ambientOcclusion = surfaceData.ambientOcclusion * decalSurfaceData.MAOSBlend.y + decalSurfaceData.mask.y;
|
|
#endif
|
|
|
|
surfaceData.perceptualSmoothness = surfaceData.perceptualSmoothness * decalSurfaceData.mask.w + decalSurfaceData.mask.z;
|
|
}
|
|
|
|
void BuildSurfaceData(FragInputs fragInputs, inout SmoothSurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS)
|
|
{
|
|
ZERO_INITIALIZE(SurfaceData, surfaceData);
|
|
|
|
surfaceData.specularOcclusion = 1.0;
|
|
surfaceData.perceptualSmoothness = surfaceDescription.Smoothness;
|
|
surfaceData.materialFeatures = 0;
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_KAJIYA_KAY
|
|
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_HAIR_KAJIYA_KAY;
|
|
#endif
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_MARSCHNER
|
|
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_HAIR_MARSCHNER;
|
|
#endif
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_MARSCHNER_CINEMATIC
|
|
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_HAIR_MARSCHNER_CINEMATIC;
|
|
#endif
|
|
|
|
#ifdef _DOUBLESIDED_ON
|
|
float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
|
|
#else
|
|
float3 doubleSidedConstants = float3( 1.0, 1.0, 1.0 );
|
|
#endif
|
|
|
|
float3 normalTS = float3(0.0f, 0.0f, 1.0f);
|
|
normalTS = surfaceDescription.Normal;
|
|
|
|
#ifdef DECAL_NORMAL_BLENDING
|
|
normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]);
|
|
|
|
#if HAVE_DECALS
|
|
if (_EnableDecals)
|
|
{
|
|
float alpha = 1.0;
|
|
alpha = surfaceDescription.Alpha;
|
|
|
|
DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
|
|
ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS);
|
|
ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData);
|
|
}
|
|
#endif
|
|
|
|
GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants);
|
|
#else
|
|
GetNormalWS(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants);
|
|
|
|
#if HAVE_DECALS
|
|
if (_EnableDecals)
|
|
{
|
|
float alpha = 1.0;
|
|
alpha = surfaceDescription.Alpha;
|
|
|
|
DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
|
|
ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz);
|
|
ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData);
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];
|
|
surfaceData.hairStrandDirectionWS = -fragInputs.tangentToWorld[1].xyz;
|
|
surfaceData.hairStrandDirectionWS = normalize(surfaceData.hairStrandDirectionWS);
|
|
|
|
#ifdef ASE_HAIRDIRECTION
|
|
surfaceData.hairStrandDirectionWS = TransformTangentToWorld(surfaceDescription.HairStrandDirection, fragInputs.tangentToWorld);
|
|
#endif
|
|
|
|
#if (_USE_LIGHT_FACING_NORMAL)
|
|
float3 viewFacingNormalWS = ComputeViewFacingNormal(V, surfaceData.hairStrandDirectionWS);
|
|
float3 N = viewFacingNormalWS;
|
|
#else
|
|
float3 N = surfaceData.normalWS;
|
|
#endif
|
|
|
|
bentNormalWS = surfaceData.normalWS;
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
#if !defined(SHADER_STAGE_RAY_TRACING)
|
|
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
|
|
{
|
|
#ifdef FRAG_INPUTS_USE_TEXCOORD0
|
|
surfaceData.diffuseColor = GET_TEXTURE_STREAMING_DEBUG(posInput.positionSS, fragInputs.texCoord0);
|
|
#else
|
|
surfaceData.diffuseColor = GET_TEXTURE_STREAMING_DEBUG_NO_UV(posInput.positionSS);
|
|
#endif
|
|
}
|
|
#endif
|
|
ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData);
|
|
#endif
|
|
|
|
#if defined(_SPECULAR_OCCLUSION_CUSTOM)
|
|
#elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL)
|
|
surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness));
|
|
#elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO)
|
|
surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness));
|
|
#endif
|
|
|
|
#ifdef _ENABLE_GEOMETRIC_SPECULAR_AA
|
|
surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold);
|
|
#endif
|
|
}
|
|
|
|
// Get Surface And BuiltinData
|
|
void GetSurfaceAndBuiltinData(SmoothSurfaceDescription surfaceDescription, FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData)
|
|
{
|
|
#ifdef LOD_FADE_CROSSFADE
|
|
LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x);
|
|
#endif
|
|
|
|
#ifdef _DOUBLESIDED_ON
|
|
float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
|
|
#else
|
|
float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
|
|
#endif
|
|
ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants);
|
|
|
|
#ifdef _ALPHATEST_ON
|
|
DoAlphaTest( surfaceDescription.Alpha, surfaceDescription.AlphaClipThreshold );
|
|
#endif
|
|
|
|
#ifdef _ALPHATEST_SHADOW_ON
|
|
DoAlphaTest( surfaceDescription.Alpha, surfaceDescription.AlphaClipThresholdShadow);
|
|
#endif
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput);
|
|
#endif
|
|
|
|
float3 bentNormalWS;
|
|
BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS);
|
|
InitBuiltinData(posInput, surfaceDescription.Alpha, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData);
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
builtinData.depthOffset = surfaceDescription.DepthOffset;
|
|
#endif
|
|
|
|
#ifdef _ALPHATEST_ON
|
|
builtinData.alphaClipTreshold = surfaceDescription.AlphaClipThreshold;
|
|
#endif
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
|
|
{
|
|
surfaceDescription.Alpha = 1.0f;
|
|
}
|
|
#endif
|
|
|
|
#ifdef UNITY_VIRTUAL_TEXTURING
|
|
builtinData.vtPackedFeedback = surfaceDescription.VTPackedFeedback;
|
|
#endif
|
|
|
|
#ifdef ASE_BAKEDGI
|
|
builtinData.bakeDiffuseLighting = surfaceDescription.BakedGI;
|
|
#endif
|
|
|
|
#ifdef ASE_BAKEDBACKGI
|
|
builtinData.backBakeDiffuseLighting = surfaceDescription.BakedBackGI;
|
|
#endif
|
|
|
|
builtinData.emissiveColor = surfaceDescription.Emission;
|
|
|
|
PostInitBuiltinData(V, posInput, surfaceData, builtinData);
|
|
}
|
|
|
|
#if (defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS)) || defined(WRITE_RENDERING_LAYER)
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl"
|
|
#endif
|
|
|
|
PackedVaryingsMeshToPS VertexFunction(AttributesMesh inputMesh /*ase_vert_input*/)
|
|
{
|
|
PackedVaryingsMeshToPS outputPackedVaryingsMeshToPS;
|
|
|
|
UNITY_SETUP_INSTANCE_ID(inputMesh);
|
|
UNITY_TRANSFER_INSTANCE_ID(inputMesh, outputPackedVaryingsMeshToPS);
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO( outputPackedVaryingsMeshToPS );
|
|
|
|
/*ase_vert_code:inputMesh=AttributesMesh;outputPackedVaryingsMeshToPS=PackedVaryingsMeshToPS*/
|
|
|
|
#ifdef ASE_ABSOLUTE_VERTEX_POS
|
|
float3 defaultVertexValue = inputMesh.positionOS.xyz;
|
|
#else
|
|
float3 defaultVertexValue = float3( 0, 0, 0 );
|
|
#endif
|
|
float3 vertexValue = /*ase_vert_out:Vertex Offset;Float3;5;-1;_VertexOffset*/ defaultVertexValue /*end*/;
|
|
|
|
#ifdef ASE_ABSOLUTE_VERTEX_POS
|
|
inputMesh.positionOS.xyz = vertexValue;
|
|
#else
|
|
inputMesh.positionOS.xyz += vertexValue;
|
|
#endif
|
|
|
|
inputMesh.normalOS = /*ase_vert_out:Vertex Normal;Float3;6;-1;_VertexNormal*/ inputMesh.normalOS /*end*/;
|
|
inputMesh.tangentOS = /*ase_vert_out:Vertex Tangent;Float4;7;-1;_VertexTangent*/ inputMesh.tangentOS /*end*/;
|
|
|
|
float3 positionRWS = TransformObjectToWorld(inputMesh.positionOS);
|
|
float3 normalWS = TransformObjectToWorldNormal(inputMesh.normalOS);
|
|
float4 tangentWS = float4(TransformObjectToWorldDir(inputMesh.tangentOS.xyz), inputMesh.tangentOS.w);
|
|
|
|
outputPackedVaryingsMeshToPS.positionCS = TransformWorldToHClip(positionRWS);
|
|
outputPackedVaryingsMeshToPS.positionRWS.xyz = positionRWS;
|
|
outputPackedVaryingsMeshToPS.normalWS.xyz = normalWS;
|
|
outputPackedVaryingsMeshToPS.tangentWS.xyzw = tangentWS;
|
|
return outputPackedVaryingsMeshToPS;
|
|
}
|
|
|
|
#if defined(ASE_TESSELLATION)
|
|
struct VertexControl
|
|
{
|
|
float3 positionOS : INTERNALTESSPOS;
|
|
float3 normalOS : NORMAL;
|
|
float4 tangentOS : TANGENT;
|
|
/*ase_vcontrol*/
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
struct TessellationFactors
|
|
{
|
|
float edge[3] : SV_TessFactor;
|
|
float inside : SV_InsideTessFactor;
|
|
};
|
|
|
|
VertexControl Vert ( AttributesMesh v )
|
|
{
|
|
VertexControl o;
|
|
UNITY_SETUP_INSTANCE_ID(v);
|
|
UNITY_TRANSFER_INSTANCE_ID(v, o);
|
|
o.positionOS = v.positionOS;
|
|
o.normalOS = v.normalOS;
|
|
o.tangentOS = v.tangentOS;
|
|
/*ase_control_code:v=AttributesMesh;o=VertexControl*/
|
|
return o;
|
|
}
|
|
|
|
TessellationFactors TessellationFunction (InputPatch<VertexControl,3> v)
|
|
{
|
|
TessellationFactors o;
|
|
float4 tf = 1;
|
|
float tessValue = /*ase_inline_begin*/_TessValue/*ase_inline_end*/; float tessMin = /*ase_inline_begin*/_TessMin/*ase_inline_end*/; float tessMax = /*ase_inline_begin*/_TessMax/*ase_inline_end*/;
|
|
float edgeLength = /*ase_inline_begin*/_TessEdgeLength/*ase_inline_end*/; float tessMaxDisp = /*ase_inline_begin*/_TessMaxDisp/*ase_inline_end*/;
|
|
#if (SHADEROPTIONS_CAMERA_RELATIVE_RENDERING != 0)
|
|
float3 cameraPos = 0;
|
|
#else
|
|
float3 cameraPos = _WorldSpaceCameraPos;
|
|
#endif
|
|
#if defined(ASE_FIXED_TESSELLATION)
|
|
tf = FixedTess( tessValue );
|
|
#elif defined(ASE_DISTANCE_TESSELLATION)
|
|
tf = DistanceBasedTess(float4(v[0].positionOS,1), float4(v[1].positionOS,1), float4(v[2].positionOS,1), tessValue, tessMin, tessMax, GetObjectToWorldMatrix(), cameraPos );
|
|
#elif defined(ASE_LENGTH_TESSELLATION)
|
|
tf = EdgeLengthBasedTess(float4(v[0].positionOS,1), float4(v[1].positionOS,1), float4(v[2].positionOS,1), edgeLength, GetObjectToWorldMatrix(), cameraPos, _ScreenParams );
|
|
#elif defined(ASE_LENGTH_CULL_TESSELLATION)
|
|
tf = EdgeLengthBasedTessCull(float4(v[0].positionOS,1), float4(v[1].positionOS,1), float4(v[2].positionOS,1), edgeLength, tessMaxDisp, GetObjectToWorldMatrix(), cameraPos, _ScreenParams, _FrustumPlanes );
|
|
#endif
|
|
o.edge[0] = tf.x; o.edge[1] = tf.y; o.edge[2] = tf.z; o.inside = tf.w;
|
|
return o;
|
|
}
|
|
|
|
[domain("tri")]
|
|
[partitioning("fractional_odd")]
|
|
[outputtopology("triangle_cw")]
|
|
[patchconstantfunc("TessellationFunction")]
|
|
[outputcontrolpoints(3)]
|
|
VertexControl HullFunction(InputPatch<VertexControl, 3> patch, uint id : SV_OutputControlPointID)
|
|
{
|
|
return patch[id];
|
|
}
|
|
|
|
[domain("tri")]
|
|
PackedVaryingsMeshToPS DomainFunction(TessellationFactors factors, OutputPatch<VertexControl, 3> patch, float3 bary : SV_DomainLocation)
|
|
{
|
|
AttributesMesh o = (AttributesMesh) 0;
|
|
o.positionOS = patch[0].positionOS * bary.x + patch[1].positionOS * bary.y + patch[2].positionOS * bary.z;
|
|
o.normalOS = patch[0].normalOS * bary.x + patch[1].normalOS * bary.y + patch[2].normalOS * bary.z;
|
|
o.tangentOS = patch[0].tangentOS * bary.x + patch[1].tangentOS * bary.y + patch[2].tangentOS * bary.z;
|
|
/*ase_domain_code:patch=VertexControl;o=AttributesMesh;bary=SV_DomainLocation*/
|
|
#if defined(ASE_PHONG_TESSELLATION)
|
|
float3 pp[3];
|
|
for (int i = 0; i < 3; ++i)
|
|
pp[i] = o.positionOS.xyz - patch[i].normalOS * (dot(o.positionOS.xyz, patch[i].normalOS) - dot(patch[i].positionOS.xyz, patch[i].normalOS));
|
|
float phongStrength = /*ase_inline_begin*/_TessPhongStrength/*ase_inline_end*/;
|
|
o.positionOS.xyz = phongStrength * (pp[0]*bary.x + pp[1]*bary.y + pp[2]*bary.z) + (1.0f-phongStrength) * o.positionOS.xyz;
|
|
#endif
|
|
UNITY_TRANSFER_INSTANCE_ID(patch[0], o);
|
|
return VertexFunction(o);
|
|
}
|
|
#else
|
|
PackedVaryingsMeshToPS Vert ( AttributesMesh v )
|
|
{
|
|
return VertexFunction( v );
|
|
}
|
|
#endif
|
|
|
|
#if defined(WRITE_NORMAL_BUFFER) && defined(WRITE_MSAA_DEPTH)
|
|
#define SV_TARGET_DECAL SV_Target2
|
|
#elif defined(WRITE_NORMAL_BUFFER) || defined(WRITE_MSAA_DEPTH)
|
|
#define SV_TARGET_DECAL SV_Target1
|
|
#else
|
|
#define SV_TARGET_DECAL SV_Target0
|
|
#endif
|
|
|
|
void Frag( PackedVaryingsMeshToPS packedInput
|
|
#if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS)
|
|
, out float4 outColor : SV_Target0
|
|
#else
|
|
#ifdef WRITE_MSAA_DEPTH
|
|
, out float4 depthColor : SV_Target0
|
|
#ifdef WRITE_NORMAL_BUFFER
|
|
, out float4 outNormalBuffer : SV_Target1
|
|
#endif
|
|
#else
|
|
#ifdef WRITE_NORMAL_BUFFER
|
|
, out float4 outNormalBuffer : SV_Target0
|
|
#endif
|
|
#endif
|
|
|
|
#if (defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS)) || defined(WRITE_RENDERING_LAYER)
|
|
, out float4 outDecalBuffer : SV_TARGET_DECAL
|
|
#endif
|
|
#endif
|
|
|
|
#if defined(_DEPTHOFFSET_ON) && !defined(SCENEPICKINGPASS)
|
|
, out float outputDepth : DEPTH_OFFSET_SEMANTIC
|
|
#endif
|
|
/*ase_frag_input*/
|
|
)
|
|
{
|
|
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput);
|
|
UNITY_SETUP_INSTANCE_ID(packedInput);
|
|
|
|
/*ase_local_var:rwp*/float3 positionRWS = packedInput.positionRWS.xyz;
|
|
/*ase_local_var:wn*/float3 normalWS = packedInput.normalWS.xyz;
|
|
/*ase_local_var:wt*/float4 tangentWS = packedInput.tangentWS.xyzw;
|
|
|
|
FragInputs input;
|
|
ZERO_INITIALIZE(FragInputs, input);
|
|
|
|
input.tangentToWorld = k_identity3x3;
|
|
input.positionSS = packedInput.positionCS;
|
|
|
|
input.positionRWS = positionRWS;
|
|
input.tangentToWorld = BuildTangentToWorld(tangentWS, normalWS);
|
|
|
|
#if _DOUBLESIDED_ON && SHADER_STAGE_FRAGMENT
|
|
input.isFrontFace = IS_FRONT_VFACE( packedInput.cullFace, true, false);
|
|
#elif SHADER_STAGE_FRAGMENT
|
|
#if defined(ASE_NEED_CULLFACE)
|
|
input.isFrontFace = IS_FRONT_VFACE( packedInput.cullFace, true, false );
|
|
#endif
|
|
#endif
|
|
/*ase_local_var:vf*/half isFrontFace = input.isFrontFace;
|
|
|
|
PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS);
|
|
|
|
/*ase_local_var:wvd*/float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
|
|
|
|
SmoothSurfaceDescription surfaceDescription = (SmoothSurfaceDescription)0;
|
|
/*ase_frag_code:packedInput=PackedVaryingsMeshToPS*/
|
|
surfaceDescription.Normal = /*ase_frag_out:Normal;Float3;0;-1;_Normal*/float3( 0, 0, 1 )/*end*/;
|
|
surfaceDescription.Smoothness = /*ase_frag_out:Smoothness;Float;1;-1;_Smoothness*/0.5/*end*/;
|
|
surfaceDescription.Alpha = /*ase_frag_out:Alpha;Float;2;-1;_Alpha*/1/*end*/;
|
|
|
|
#ifdef _ALPHATEST_ON
|
|
surfaceDescription.AlphaClipThreshold = /*ase_frag_out:Alpha Clip Threshold;Float;3;-1;_AlphaClip*/_AlphaCutoff/*end*/;
|
|
#endif
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
surfaceDescription.DepthOffset = /*ase_frag_out:Depth Offset;Float;4;-1;_DepthOffset*/0/*end*/;
|
|
#endif
|
|
|
|
SurfaceData surfaceData;
|
|
BuiltinData builtinData;
|
|
GetSurfaceAndBuiltinData(surfaceDescription, input, V, posInput, surfaceData, builtinData);
|
|
|
|
#if defined(_DEPTHOFFSET_ON) && !defined(SCENEPICKINGPASS)
|
|
outputDepth = posInput.deviceDepth;
|
|
#endif
|
|
|
|
#if SHADERPASS == SHADERPASS_SHADOWS
|
|
float bias = max(abs(ddx(posInput.deviceDepth)), abs(ddy(posInput.deviceDepth))) * _SlopeScaleDepthBias;
|
|
outputDepth += bias;
|
|
#endif
|
|
|
|
#ifdef SCENESELECTIONPASS
|
|
outColor = float4(_ObjectId, _PassValue, 1.0, 1.0);
|
|
#elif defined(SCENEPICKINGPASS)
|
|
outColor = unity_SelectionID;
|
|
#else
|
|
#ifdef WRITE_MSAA_DEPTH
|
|
depthColor = packedInput.positionCS.z;
|
|
depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold);
|
|
#endif
|
|
|
|
#if defined(WRITE_NORMAL_BUFFER)
|
|
EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer);
|
|
#endif
|
|
|
|
#if (defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS)) || defined(WRITE_RENDERING_LAYER)
|
|
DecalPrepassData decalPrepassData;
|
|
#ifdef _DISABLE_DECALS
|
|
ZERO_INITIALIZE(DecalPrepassData, decalPrepassData);
|
|
#else
|
|
decalPrepassData.geomNormalWS = surfaceData.geomNormalWS;
|
|
#endif
|
|
decalPrepassData.renderingLayerMask = GetMeshRenderingLayerMask();
|
|
EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer);
|
|
#endif
|
|
|
|
#endif // SCENESELECTIONPASS
|
|
|
|
}
|
|
|
|
ENDHLSL
|
|
}
|
|
|
|
/*ase_pass*/
|
|
Pass
|
|
{
|
|
/*ase_hide_pass*/
|
|
Name "SceneSelectionPass"
|
|
Tags
|
|
{
|
|
"LightMode" = "SceneSelectionPass"
|
|
}
|
|
|
|
Cull Off
|
|
|
|
HLSLPROGRAM
|
|
#pragma editor_sync_compilation
|
|
#pragma multi_compile _ DOTS_INSTANCING_ON
|
|
|
|
#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT
|
|
#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC _TRANSPARENT_REFRACTIVE_SORT
|
|
#pragma shader_feature_local_fragment _ _ENABLE_FOG_ON_TRANSPARENT
|
|
|
|
// RayTracing
|
|
//#pragma shader_feature_local_raytracing _ _DISABLE_DECALS
|
|
//#pragma shader_feature_local_raytracing _ _DISABLE_SSR
|
|
//#pragma shader_feature_local_raytracing _ _DISABLE_SSR_TRANSPARENT
|
|
|
|
#pragma vertex Vert
|
|
#pragma fragment Frag
|
|
|
|
#define SHADERPASS SHADERPASS_DEPTH_ONLY
|
|
#define SCENESELECTIONPASS 1
|
|
#define _ABSORPTION_FROM_COLOR 1
|
|
#define SUPPORT_GLOBAL_MIP_BIAS 1
|
|
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl"
|
|
#include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl"
|
|
|
|
//#if !defined(SHADER_STAGE_RAY_TRACING) && SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER && SHADERPASS != SHADERPASS_FULL_SCREEN_DEBUG
|
|
//#define FRAG_INPUTS_ENABLE_STRIPPING
|
|
//#endif
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
|
|
|
|
#ifdef RAYTRACING_SHADER_GRAPH_DEFAULT
|
|
#define RAYTRACING_SHADER_GRAPH_HIGH
|
|
#endif
|
|
|
|
#ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED
|
|
#define RAYTRACING_SHADER_GRAPH_LOW
|
|
#endif
|
|
|
|
#ifndef SHADER_UNLIT
|
|
#if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE)
|
|
#define VARYINGS_NEED_CULLFACE
|
|
#endif
|
|
#endif
|
|
|
|
#if defined(_DOUBLESIDED_ON) && !defined(ASE_NEED_CULLFACE)
|
|
#define ASE_NEED_CULLFACE 1
|
|
#endif
|
|
|
|
#if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
|
|
#if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT)
|
|
#define WRITE_NORMAL_BUFFER
|
|
#endif
|
|
#endif
|
|
|
|
#if SHADERPASS == SHADERPASS_MOTION_VECTORS && defined(WRITE_DECAL_BUFFER_AND_RENDERING_LAYER)
|
|
#define WRITE_DECAL_BUFFER
|
|
#endif
|
|
|
|
#ifndef DEBUG_DISPLAY
|
|
#if !defined(_SURFACE_TYPE_TRANSPARENT)
|
|
#if SHADERPASS == SHADERPASS_FORWARD
|
|
#define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
|
|
#elif SHADERPASS == SHADERPASS_GBUFFER
|
|
#define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST
|
|
#endif
|
|
#endif
|
|
#endif
|
|
|
|
#if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT)
|
|
#define _DEFERRED_CAPABLE_MATERIAL
|
|
#endif
|
|
|
|
#if (defined(_TRANSPARENT_WRITES_MOTION_VEC) || defined(_TRANSPARENT_REFRACTIVE_SORT)) && defined(_SURFACE_TYPE_TRANSPARENT)
|
|
#define _WRITE_TRANSPARENT_MOTION_VECTOR
|
|
#endif
|
|
|
|
CBUFFER_START( UnityPerMaterial )
|
|
float4 _EmissionColor;
|
|
float _AlphaCutoff;
|
|
float _RenderQueueType;
|
|
#ifdef _ADD_PRECOMPUTED_VELOCITY
|
|
float _AddPrecomputedVelocity;
|
|
#endif
|
|
float _ExcludeFromTUAndAA;
|
|
float _StencilRef;
|
|
float _StencilWriteMask;
|
|
float _StencilRefDepth;
|
|
float _StencilWriteMaskDepth;
|
|
float _StencilRefMV;
|
|
float _StencilWriteMaskMV;
|
|
float _StencilRefDistortionVec;
|
|
float _StencilWriteMaskDistortionVec;
|
|
float _StencilWriteMaskGBuffer;
|
|
float _StencilRefGBuffer;
|
|
float _ZTestGBuffer;
|
|
float _RequireSplitLighting;
|
|
float _ReceivesSSR;
|
|
float _SurfaceType;
|
|
float _BlendMode;
|
|
#ifdef SUPPORT_BLENDMODE_PRESERVE_SPECULAR_LIGHTING
|
|
float _EnableBlendModePreserveSpecularLighting;
|
|
#endif
|
|
float _SrcBlend;
|
|
float _DstBlend;
|
|
float _DstBlend2;
|
|
float _AlphaSrcBlend;
|
|
float _AlphaDstBlend;
|
|
float _ZWrite;
|
|
float _TransparentZWrite;
|
|
float _CullMode;
|
|
float _TransparentSortPriority;
|
|
float _EnableFogOnTransparent;
|
|
float _CullModeForward;
|
|
float _TransparentCullMode;
|
|
float _ZTestDepthEqualForOpaque;
|
|
float _ZTestTransparent;
|
|
float _TransparentBackfaceEnable;
|
|
float _AlphaCutoffEnable;
|
|
float _UseShadowThreshold;
|
|
float _DoubleSidedEnable;
|
|
float _DoubleSidedNormalMode;
|
|
float4 _DoubleSidedConstants;
|
|
#ifdef ASE_TESSELLATION
|
|
float _TessPhongStrength;
|
|
float _TessValue;
|
|
float _TessMin;
|
|
float _TessMax;
|
|
float _TessEdgeLength;
|
|
float _TessMaxDisp;
|
|
#endif
|
|
UNITY_TEXTURE_STREAMING_DEBUG_VARS;
|
|
CBUFFER_END
|
|
|
|
#ifdef SCENEPICKINGPASS
|
|
float4 _SelectionID;
|
|
#endif
|
|
|
|
#ifdef SCENESELECTIONPASS
|
|
int _ObjectId;
|
|
int _PassValue;
|
|
#endif
|
|
|
|
/*ase_globals*/
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
|
|
#endif
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Hair/Hair.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl"
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl"
|
|
|
|
#ifdef HAVE_VFX_MODIFICATION
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/VisualEffectVertex.hlsl"
|
|
#endif
|
|
|
|
/*ase_pragma*/
|
|
|
|
struct AttributesMesh
|
|
{
|
|
float3 positionOS : POSITION;
|
|
float3 normalOS : NORMAL;
|
|
float4 tangentOS : TANGENT;
|
|
/*ase_vdata:p=p;n=n;t=t*/
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
struct PackedVaryingsMeshToPS
|
|
{
|
|
SV_POSITION_QUALIFIERS float4 positionCS : SV_Position;
|
|
float3 positionRWS : TEXCOORD0;
|
|
/*ase_interp(1,):sp=sp.xyzw;rwp=tc0*/
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
UNITY_VERTEX_OUTPUT_STEREO
|
|
#if defined(SHADER_STAGE_FRAGMENT) && defined(ASE_NEED_CULLFACE)
|
|
FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
|
|
#endif
|
|
};
|
|
|
|
/*ase_funcs*/
|
|
|
|
//Build Surface Data (Decal)
|
|
void ApplyDecalToSurfaceDataNoNormal(DecalSurfaceData decalSurfaceData, inout SurfaceData surfaceData)
|
|
{
|
|
surfaceData.diffuseColor.xyz = surfaceData.diffuseColor.xyz * decalSurfaceData.baseColor.w + decalSurfaceData.baseColor.xyz;
|
|
|
|
#ifdef DECALS_4RT
|
|
surfaceData.ambientOcclusion = surfaceData.ambientOcclusion * decalSurfaceData.MAOSBlend.y + decalSurfaceData.mask.y;
|
|
#endif
|
|
|
|
surfaceData.perceptualSmoothness = surfaceData.perceptualSmoothness * decalSurfaceData.mask.w + decalSurfaceData.mask.z;
|
|
}
|
|
|
|
void BuildSurfaceData(FragInputs fragInputs, inout SceneSurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS)
|
|
{
|
|
ZERO_INITIALIZE(SurfaceData, surfaceData);
|
|
|
|
surfaceData.specularOcclusion = 1.0;
|
|
surfaceData.materialFeatures = 0;
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_KAJIYA_KAY
|
|
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_HAIR_KAJIYA_KAY;
|
|
#endif
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_MARSCHNER
|
|
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_HAIR_MARSCHNER;
|
|
#endif
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_MARSCHNER_CINEMATIC
|
|
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_HAIR_MARSCHNER_CINEMATIC;
|
|
#endif
|
|
|
|
#ifdef _DOUBLESIDED_ON
|
|
float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
|
|
#else
|
|
float3 doubleSidedConstants = float3( 1.0, 1.0, 1.0 );
|
|
#endif
|
|
|
|
float3 normalTS = float3(0.0f, 0.0f, 1.0f);
|
|
|
|
#ifdef DECAL_NORMAL_BLENDING
|
|
normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]);
|
|
|
|
#if HAVE_DECALS
|
|
if (_EnableDecals)
|
|
{
|
|
float alpha = 1.0;
|
|
alpha = surfaceDescription.Alpha;
|
|
|
|
DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
|
|
ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS);
|
|
ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData);
|
|
}
|
|
#endif
|
|
|
|
GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants);
|
|
#else
|
|
GetNormalWS(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants);
|
|
|
|
#if HAVE_DECALS
|
|
if (_EnableDecals)
|
|
{
|
|
float alpha = 1.0;
|
|
alpha = surfaceDescription.Alpha;
|
|
|
|
DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
|
|
ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz);
|
|
ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData);
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];
|
|
surfaceData.hairStrandDirectionWS = -fragInputs.tangentToWorld[1].xyz;
|
|
surfaceData.hairStrandDirectionWS = normalize(surfaceData.hairStrandDirectionWS);
|
|
|
|
#ifdef ASE_HAIRDIRECTION
|
|
surfaceData.hairStrandDirectionWS = TransformTangentToWorld(surfaceDescription.HairStrandDirection, fragInputs.tangentToWorld);
|
|
#endif
|
|
|
|
#if (_USE_LIGHT_FACING_NORMAL)
|
|
float3 viewFacingNormalWS = ComputeViewFacingNormal(V, surfaceData.hairStrandDirectionWS);
|
|
float3 N = viewFacingNormalWS;
|
|
#else
|
|
float3 N = surfaceData.normalWS;
|
|
#endif
|
|
|
|
bentNormalWS = surfaceData.normalWS;
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
#if !defined(SHADER_STAGE_RAY_TRACING)
|
|
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
|
|
{
|
|
#ifdef FRAG_INPUTS_USE_TEXCOORD0
|
|
surfaceData.diffuseColor = GET_TEXTURE_STREAMING_DEBUG(posInput.positionSS, fragInputs.texCoord0);
|
|
#else
|
|
surfaceData.diffuseColor = GET_TEXTURE_STREAMING_DEBUG_NO_UV(posInput.positionSS);
|
|
#endif
|
|
}
|
|
#endif
|
|
ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData);
|
|
#endif
|
|
|
|
#if defined(_SPECULAR_OCCLUSION_CUSTOM)
|
|
#elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL)
|
|
surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness));
|
|
#elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO)
|
|
surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness));
|
|
#endif
|
|
|
|
#ifdef _ENABLE_GEOMETRIC_SPECULAR_AA
|
|
surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold);
|
|
#endif
|
|
}
|
|
|
|
// Get Surface And BuiltinData
|
|
void GetSurfaceAndBuiltinData(SceneSurfaceDescription surfaceDescription, FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData)
|
|
{
|
|
#ifdef LOD_FADE_CROSSFADE
|
|
LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x);
|
|
#endif
|
|
|
|
#ifdef _DOUBLESIDED_ON
|
|
float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
|
|
#else
|
|
float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
|
|
#endif
|
|
ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants);
|
|
|
|
#ifdef _ALPHATEST_ON
|
|
DoAlphaTest( surfaceDescription.Alpha, surfaceDescription.AlphaClipThreshold );
|
|
#endif
|
|
|
|
#ifdef _ALPHATEST_SHADOW_ON
|
|
DoAlphaTest( surfaceDescription.Alpha, surfaceDescription.AlphaClipThresholdShadow);
|
|
#endif
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput);
|
|
#endif
|
|
|
|
float3 bentNormalWS;
|
|
BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS);
|
|
InitBuiltinData(posInput, surfaceDescription.Alpha, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData);
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
builtinData.depthOffset = surfaceDescription.DepthOffset;
|
|
#endif
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
|
|
{
|
|
surfaceDescription.Alpha = 1.0f;
|
|
}
|
|
#endif
|
|
|
|
#ifdef _ALPHATEST_ON
|
|
builtinData.alphaClipTreshold = surfaceDescription.AlphaClipThreshold;
|
|
#endif
|
|
|
|
#ifdef UNITY_VIRTUAL_TEXTURING
|
|
builtinData.vtPackedFeedback = surfaceDescription.VTPackedFeedback;
|
|
#endif
|
|
|
|
#ifdef ASE_BAKEDGI
|
|
builtinData.bakeDiffuseLighting = surfaceDescription.BakedGI;
|
|
#endif
|
|
|
|
#ifdef ASE_BAKEDBACKGI
|
|
builtinData.backBakeDiffuseLighting = surfaceDescription.BakedBackGI;
|
|
#endif
|
|
|
|
builtinData.emissiveColor = surfaceDescription.Emission;
|
|
|
|
PostInitBuiltinData(V, posInput, surfaceData, builtinData);
|
|
}
|
|
|
|
PackedVaryingsMeshToPS VertexFunction(AttributesMesh inputMesh/*ase_vert_input*/)
|
|
{
|
|
PackedVaryingsMeshToPS outputPackedVaryingsMeshToPS;
|
|
UNITY_SETUP_INSTANCE_ID(inputMesh);
|
|
UNITY_TRANSFER_INSTANCE_ID(inputMesh, outputPackedVaryingsMeshToPS);
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO( outputPackedVaryingsMeshToPS );
|
|
|
|
/*ase_vert_code:inputMesh=AttributesMesh;outputPackedVaryingsMeshToPS=PackedVaryingsMeshToPS*/
|
|
|
|
#ifdef ASE_ABSOLUTE_VERTEX_POS
|
|
float3 defaultVertexValue = inputMesh.positionOS.xyz;
|
|
#else
|
|
float3 defaultVertexValue = float3( 0, 0, 0 );
|
|
#endif
|
|
float3 vertexValue = /*ase_vert_out:Vertex Offset;Float3;3;-1;_VertexOffset*/ defaultVertexValue /*end*/;
|
|
|
|
#ifdef ASE_ABSOLUTE_VERTEX_POS
|
|
inputMesh.positionOS.xyz = vertexValue;
|
|
#else
|
|
inputMesh.positionOS.xyz += vertexValue;
|
|
#endif
|
|
|
|
inputMesh.normalOS = /*ase_vert_out:Vertex Normal;Float3;4;-1;_VertexNormal*/ inputMesh.normalOS /*end*/;
|
|
inputMesh.tangentOS = /*ase_vert_out:Vertex Tangent;Float4;5;-1;_VertexTangent*/ inputMesh.tangentOS /*end*/;
|
|
|
|
float3 positionRWS = TransformObjectToWorld(inputMesh.positionOS);
|
|
outputPackedVaryingsMeshToPS.positionCS = TransformWorldToHClip(positionRWS);
|
|
outputPackedVaryingsMeshToPS.positionRWS.xyz = positionRWS;
|
|
return outputPackedVaryingsMeshToPS;
|
|
}
|
|
|
|
#if defined(ASE_TESSELLATION)
|
|
struct VertexControl
|
|
{
|
|
float3 positionOS : INTERNALTESSPOS;
|
|
float3 normalOS : NORMAL;
|
|
float4 tangentOS : TANGENT;
|
|
/*ase_vcontrol*/
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
struct TessellationFactors
|
|
{
|
|
float edge[3] : SV_TessFactor;
|
|
float inside : SV_InsideTessFactor;
|
|
};
|
|
|
|
VertexControl Vert ( AttributesMesh v )
|
|
{
|
|
VertexControl o;
|
|
UNITY_SETUP_INSTANCE_ID(v);
|
|
UNITY_TRANSFER_INSTANCE_ID(v, o);
|
|
o.positionOS = v.positionOS;
|
|
o.normalOS = v.normalOS;
|
|
o.tangentOS = v.tangentOS;
|
|
/*ase_control_code:v=AttributesMesh;o=VertexControl*/
|
|
return o;
|
|
}
|
|
|
|
TessellationFactors TessellationFunction (InputPatch<VertexControl,3> v)
|
|
{
|
|
TessellationFactors o;
|
|
float4 tf = 1;
|
|
float tessValue = /*ase_inline_begin*/_TessValue/*ase_inline_end*/; float tessMin = /*ase_inline_begin*/_TessMin/*ase_inline_end*/; float tessMax = /*ase_inline_begin*/_TessMax/*ase_inline_end*/;
|
|
float edgeLength = /*ase_inline_begin*/_TessEdgeLength/*ase_inline_end*/; float tessMaxDisp = /*ase_inline_begin*/_TessMaxDisp/*ase_inline_end*/;
|
|
#if (SHADEROPTIONS_CAMERA_RELATIVE_RENDERING != 0)
|
|
float3 cameraPos = 0;
|
|
#else
|
|
float3 cameraPos = _WorldSpaceCameraPos;
|
|
#endif
|
|
#if defined(ASE_FIXED_TESSELLATION)
|
|
tf = FixedTess( tessValue );
|
|
#elif defined(ASE_DISTANCE_TESSELLATION)
|
|
tf = DistanceBasedTess(float4(v[0].positionOS,1), float4(v[1].positionOS,1), float4(v[2].positionOS,1), tessValue, tessMin, tessMax, GetObjectToWorldMatrix(), cameraPos );
|
|
#elif defined(ASE_LENGTH_TESSELLATION)
|
|
tf = EdgeLengthBasedTess(float4(v[0].positionOS,1), float4(v[1].positionOS,1), float4(v[2].positionOS,1), edgeLength, GetObjectToWorldMatrix(), cameraPos, _ScreenParams );
|
|
#elif defined(ASE_LENGTH_CULL_TESSELLATION)
|
|
tf = EdgeLengthBasedTessCull(float4(v[0].positionOS,1), float4(v[1].positionOS,1), float4(v[2].positionOS,1), edgeLength, tessMaxDisp, GetObjectToWorldMatrix(), cameraPos, _ScreenParams, _FrustumPlanes );
|
|
#endif
|
|
o.edge[0] = tf.x; o.edge[1] = tf.y; o.edge[2] = tf.z; o.inside = tf.w;
|
|
return o;
|
|
}
|
|
|
|
[domain("tri")]
|
|
[partitioning("fractional_odd")]
|
|
[outputtopology("triangle_cw")]
|
|
[patchconstantfunc("TessellationFunction")]
|
|
[outputcontrolpoints(3)]
|
|
VertexControl HullFunction(InputPatch<VertexControl, 3> patch, uint id : SV_OutputControlPointID)
|
|
{
|
|
return patch[id];
|
|
}
|
|
|
|
[domain("tri")]
|
|
PackedVaryingsMeshToPS DomainFunction(TessellationFactors factors, OutputPatch<VertexControl, 3> patch, float3 bary : SV_DomainLocation)
|
|
{
|
|
AttributesMesh o = (AttributesMesh) 0;
|
|
o.positionOS = patch[0].positionOS * bary.x + patch[1].positionOS * bary.y + patch[2].positionOS * bary.z;
|
|
o.normalOS = patch[0].normalOS * bary.x + patch[1].normalOS * bary.y + patch[2].normalOS * bary.z;
|
|
o.tangentOS = patch[0].tangentOS * bary.x + patch[1].tangentOS * bary.y + patch[2].tangentOS * bary.z;
|
|
/*ase_domain_code:patch=VertexControl;o=AttributesMesh;bary=SV_DomainLocation*/
|
|
#if defined(ASE_PHONG_TESSELLATION)
|
|
float3 pp[3];
|
|
for (int i = 0; i < 3; ++i)
|
|
pp[i] = o.positionOS.xyz - patch[i].normalOS * (dot(o.positionOS.xyz, patch[i].normalOS) - dot(patch[i].positionOS.xyz, patch[i].normalOS));
|
|
float phongStrength = /*ase_inline_begin*/_TessPhongStrength/*ase_inline_end*/;
|
|
o.positionOS.xyz = phongStrength * (pp[0]*bary.x + pp[1]*bary.y + pp[2]*bary.z) + (1.0f-phongStrength) * o.positionOS.xyz;
|
|
#endif
|
|
UNITY_TRANSFER_INSTANCE_ID(patch[0], o);
|
|
return VertexFunction(o);
|
|
}
|
|
#else
|
|
PackedVaryingsMeshToPS Vert ( AttributesMesh v )
|
|
{
|
|
return VertexFunction( v );
|
|
}
|
|
#endif
|
|
|
|
#if defined(WRITE_NORMAL_BUFFER) && defined(WRITE_MSAA_DEPTH)
|
|
#define SV_TARGET_DECAL SV_Target2
|
|
#elif defined(WRITE_NORMAL_BUFFER) || defined(WRITE_MSAA_DEPTH)
|
|
#define SV_TARGET_DECAL SV_Target1
|
|
#else
|
|
#define SV_TARGET_DECAL SV_Target0
|
|
#endif
|
|
|
|
void Frag( PackedVaryingsMeshToPS packedInput
|
|
, out float4 outColor : SV_Target0
|
|
#if defined(_DEPTHOFFSET_ON) && !defined(SCENEPICKINGPASS)
|
|
, out float outputDepth : DEPTH_OFFSET_SEMANTIC
|
|
#endif
|
|
/*ase_frag_input*/
|
|
)
|
|
{
|
|
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX( packedInput );
|
|
UNITY_SETUP_INSTANCE_ID( packedInput );
|
|
|
|
/*ase_local_var:rwp*/float3 positionRWS = packedInput.positionRWS.xyz;
|
|
|
|
FragInputs input;
|
|
ZERO_INITIALIZE(FragInputs, input);
|
|
|
|
input.tangentToWorld = k_identity3x3;
|
|
input.positionSS = packedInput.positionCS;
|
|
|
|
input.positionRWS = positionRWS;
|
|
|
|
#if _DOUBLESIDED_ON && SHADER_STAGE_FRAGMENT
|
|
input.isFrontFace = IS_FRONT_VFACE( packedInput.cullFace, true, false);
|
|
#elif SHADER_STAGE_FRAGMENT
|
|
#if defined(ASE_NEED_CULLFACE)
|
|
input.isFrontFace = IS_FRONT_VFACE( packedInput.cullFace, true, false );
|
|
#endif
|
|
#endif
|
|
/*ase_local_var:vf*/half isFrontFace = input.isFrontFace;
|
|
|
|
PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS);
|
|
|
|
/*ase_local_var:wvd*/float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
|
|
|
|
SceneSurfaceDescription surfaceDescription = (SceneSurfaceDescription)0;
|
|
/*ase_frag_code:packedInput=PackedVaryingsMeshToPS*/
|
|
surfaceDescription.Alpha = /*ase_frag_out:Alpha;Float;0;-1;_Alpha*/1/*end*/;
|
|
|
|
#ifdef _ALPHATEST_ON
|
|
surfaceDescription.AlphaClipThreshold = /*ase_frag_out:Alpha Clip Threshold;Float;1;-1;_AlphaClip*/_AlphaCutoff/*end*/;
|
|
#endif
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
surfaceDescription.DepthOffset = /*ase_frag_out:Depth Offset;Float;2;-1;_DepthOffset*/0/*end*/;
|
|
#endif
|
|
|
|
SurfaceData surfaceData;
|
|
BuiltinData builtinData;
|
|
GetSurfaceAndBuiltinData(surfaceDescription, input, V, posInput, surfaceData, builtinData);
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
outputDepth = posInput.deviceDepth;
|
|
#endif
|
|
|
|
outColor = float4( _ObjectId, _PassValue, 1.0, 1.0 );
|
|
}
|
|
ENDHLSL
|
|
}
|
|
|
|
/*ase_pass*/
|
|
Pass
|
|
{
|
|
/*ase_hide_pass*/
|
|
Name "ShadowCaster"
|
|
Tags
|
|
{
|
|
"LightMode" = "ShadowCaster"
|
|
}
|
|
|
|
Blend One Zero
|
|
Cull [_CullMode]
|
|
ZWrite On
|
|
ZClip [_ZClip]
|
|
ColorMask 0
|
|
|
|
HLSLPROGRAM
|
|
#pragma multi_compile _ DOTS_INSTANCING_ON
|
|
|
|
#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT
|
|
#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC _TRANSPARENT_REFRACTIVE_SORT
|
|
#pragma shader_feature_local_fragment _ _ENABLE_FOG_ON_TRANSPARENT
|
|
|
|
#pragma multi_compile_fragment _ SHADOWS_SHADOWMASK
|
|
|
|
//RayTracing
|
|
//#pragma shader_feature_local_raytracing _ _DISABLE_DECALS
|
|
//#pragma shader_feature_local_raytracing _ _DISABLE_SSR
|
|
//#pragma shader_feature_local_raytracing _ _DISABLE_SSR_TRANSPARENT
|
|
|
|
#pragma vertex Vert
|
|
#pragma fragment Frag
|
|
|
|
#define SHADERPASS SHADERPASS_SHADOWS
|
|
#define _ABSORPTION_FROM_COLOR 1
|
|
#define SUPPORT_GLOBAL_MIP_BIAS 1
|
|
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl"
|
|
#include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl"
|
|
|
|
//#if !defined(SHADER_STAGE_RAY_TRACING) && SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER && SHADERPASS != SHADERPASS_FULL_SCREEN_DEBUG
|
|
//#define FRAG_INPUTS_ENABLE_STRIPPING
|
|
//#endif
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
|
|
|
|
#ifdef RAYTRACING_SHADER_GRAPH_DEFAULT
|
|
#define RAYTRACING_SHADER_GRAPH_HIGH
|
|
#endif
|
|
|
|
#ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED
|
|
#define RAYTRACING_SHADER_GRAPH_LOW
|
|
#endif
|
|
|
|
#ifndef SHADER_UNLIT
|
|
#if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE)
|
|
#define VARYINGS_NEED_CULLFACE
|
|
#endif
|
|
#endif
|
|
|
|
#if defined(_DOUBLESIDED_ON) && !defined(ASE_NEED_CULLFACE)
|
|
#define ASE_NEED_CULLFACE 1
|
|
#endif
|
|
|
|
#if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
|
|
#if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT)
|
|
#define WRITE_NORMAL_BUFFER
|
|
#endif
|
|
#endif
|
|
|
|
#if SHADERPASS == SHADERPASS_MOTION_VECTORS && defined(WRITE_DECAL_BUFFER_AND_RENDERING_LAYER)
|
|
#define WRITE_DECAL_BUFFER
|
|
#endif
|
|
|
|
#ifndef DEBUG_DISPLAY
|
|
#if !defined(_SURFACE_TYPE_TRANSPARENT)
|
|
#if SHADERPASS == SHADERPASS_FORWARD
|
|
#define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
|
|
#elif SHADERPASS == SHADERPASS_GBUFFER
|
|
#define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST
|
|
#endif
|
|
#endif
|
|
#endif
|
|
|
|
#if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT)
|
|
#define _DEFERRED_CAPABLE_MATERIAL
|
|
#endif
|
|
|
|
#if (defined(_TRANSPARENT_WRITES_MOTION_VEC) || defined(_TRANSPARENT_REFRACTIVE_SORT)) && defined(_SURFACE_TYPE_TRANSPARENT)
|
|
#define _WRITE_TRANSPARENT_MOTION_VECTOR
|
|
#endif
|
|
|
|
CBUFFER_START( UnityPerMaterial )
|
|
float4 _EmissionColor;
|
|
float _AlphaCutoff;
|
|
float _RenderQueueType;
|
|
#ifdef _ADD_PRECOMPUTED_VELOCITY
|
|
float _AddPrecomputedVelocity;
|
|
#endif
|
|
float _ExcludeFromTUAndAA;
|
|
float _StencilRef;
|
|
float _StencilWriteMask;
|
|
float _StencilRefDepth;
|
|
float _StencilWriteMaskDepth;
|
|
float _StencilRefMV;
|
|
float _StencilWriteMaskMV;
|
|
float _StencilRefDistortionVec;
|
|
float _StencilWriteMaskDistortionVec;
|
|
float _StencilWriteMaskGBuffer;
|
|
float _StencilRefGBuffer;
|
|
float _ZTestGBuffer;
|
|
float _RequireSplitLighting;
|
|
float _ReceivesSSR;
|
|
float _SurfaceType;
|
|
float _BlendMode;
|
|
#ifdef SUPPORT_BLENDMODE_PRESERVE_SPECULAR_LIGHTING
|
|
float _EnableBlendModePreserveSpecularLighting;
|
|
#endif
|
|
float _SrcBlend;
|
|
float _DstBlend;
|
|
float _DstBlend2;
|
|
float _AlphaSrcBlend;
|
|
float _AlphaDstBlend;
|
|
float _ZWrite;
|
|
float _TransparentZWrite;
|
|
float _CullMode;
|
|
float _TransparentSortPriority;
|
|
float _EnableFogOnTransparent;
|
|
float _CullModeForward;
|
|
float _TransparentCullMode;
|
|
float _ZTestDepthEqualForOpaque;
|
|
float _ZTestTransparent;
|
|
float _TransparentBackfaceEnable;
|
|
float _AlphaCutoffEnable;
|
|
float _UseShadowThreshold;
|
|
float _DoubleSidedEnable;
|
|
float _DoubleSidedNormalMode;
|
|
float4 _DoubleSidedConstants;
|
|
#ifdef ASE_TESSELLATION
|
|
float _TessPhongStrength;
|
|
float _TessValue;
|
|
float _TessMin;
|
|
float _TessMax;
|
|
float _TessEdgeLength;
|
|
float _TessMaxDisp;
|
|
#endif
|
|
UNITY_TEXTURE_STREAMING_DEBUG_VARS;
|
|
CBUFFER_END
|
|
|
|
#ifdef SCENEPICKINGPASS
|
|
float4 _SelectionID;
|
|
#endif
|
|
|
|
#ifdef SCENESELECTIONPASS
|
|
int _ObjectId;
|
|
int _PassValue;
|
|
#endif
|
|
|
|
/*ase_globals*/
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
|
|
#endif
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Hair/Hair.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl"
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl"
|
|
|
|
#ifdef HAVE_VFX_MODIFICATION
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/VisualEffectVertex.hlsl"
|
|
#endif
|
|
|
|
/*ase_pragma*/
|
|
|
|
struct AttributesMesh
|
|
{
|
|
float3 positionOS : POSITION;
|
|
float3 normalOS : NORMAL;
|
|
float4 tangentOS : TANGENT;
|
|
/*ase_vdata:p=p;n=n;t=t*/
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
struct PackedVaryingsMeshToPS
|
|
{
|
|
SV_POSITION_QUALIFIERS float4 positionCS : SV_Position;
|
|
float3 positionRWS : TEXCOORD0;
|
|
/*ase_interp(1,):sp=sp.xyzw;rwp=tc0*/
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
UNITY_VERTEX_OUTPUT_STEREO
|
|
#if defined(SHADER_STAGE_FRAGMENT) && defined(ASE_NEED_CULLFACE)
|
|
FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
|
|
#endif
|
|
};
|
|
|
|
/*ase_funcs*/
|
|
|
|
//Build Surface Data (Decal)
|
|
void ApplyDecalToSurfaceDataNoNormal(DecalSurfaceData decalSurfaceData, inout SurfaceData surfaceData)
|
|
{
|
|
surfaceData.diffuseColor.xyz = surfaceData.diffuseColor.xyz * decalSurfaceData.baseColor.w + decalSurfaceData.baseColor.xyz;
|
|
|
|
#ifdef DECALS_4RT
|
|
surfaceData.ambientOcclusion = surfaceData.ambientOcclusion * decalSurfaceData.MAOSBlend.y + decalSurfaceData.mask.y;
|
|
#endif
|
|
|
|
surfaceData.perceptualSmoothness = surfaceData.perceptualSmoothness * decalSurfaceData.mask.w + decalSurfaceData.mask.z;
|
|
}
|
|
|
|
void BuildSurfaceData(FragInputs fragInputs, inout AlphaSurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS)
|
|
{
|
|
ZERO_INITIALIZE(SurfaceData, surfaceData);
|
|
|
|
surfaceData.specularOcclusion = 1.0;
|
|
surfaceData.materialFeatures = 0;
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_KAJIYA_KAY
|
|
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_HAIR_KAJIYA_KAY;
|
|
#endif
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_MARSCHNER
|
|
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_HAIR_MARSCHNER;
|
|
#endif
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_MARSCHNER_CINEMATIC
|
|
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_HAIR_MARSCHNER_CINEMATIC;
|
|
#endif
|
|
|
|
#ifdef _DOUBLESIDED_ON
|
|
float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
|
|
#else
|
|
float3 doubleSidedConstants = float3( 1.0, 1.0, 1.0 );
|
|
#endif
|
|
|
|
float3 normalTS = float3(0.0f, 0.0f, 1.0f);
|
|
|
|
#ifdef DECAL_NORMAL_BLENDING
|
|
normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]);
|
|
|
|
#if HAVE_DECALS
|
|
if (_EnableDecals)
|
|
{
|
|
float alpha = 1.0;
|
|
alpha = surfaceDescription.Alpha;
|
|
|
|
DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
|
|
ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS);
|
|
ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData);
|
|
}
|
|
#endif
|
|
|
|
GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants);
|
|
#else
|
|
GetNormalWS(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants);
|
|
|
|
#if HAVE_DECALS
|
|
if (_EnableDecals)
|
|
{
|
|
float alpha = 1.0;
|
|
alpha = surfaceDescription.Alpha;
|
|
|
|
DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
|
|
ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz);
|
|
ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData);
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];
|
|
surfaceData.hairStrandDirectionWS = -fragInputs.tangentToWorld[1].xyz;
|
|
surfaceData.hairStrandDirectionWS = normalize(surfaceData.hairStrandDirectionWS);
|
|
|
|
#if (_USE_LIGHT_FACING_NORMAL)
|
|
float3 viewFacingNormalWS = ComputeViewFacingNormal(V, surfaceData.hairStrandDirectionWS);
|
|
float3 N = viewFacingNormalWS;
|
|
#else
|
|
float3 N = surfaceData.normalWS;
|
|
#endif
|
|
|
|
bentNormalWS = surfaceData.normalWS;
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
#if !defined(SHADER_STAGE_RAY_TRACING)
|
|
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
|
|
{
|
|
#ifdef FRAG_INPUTS_USE_TEXCOORD0
|
|
surfaceData.diffuseColor = GET_TEXTURE_STREAMING_DEBUG(posInput.positionSS, fragInputs.texCoord0);
|
|
#else
|
|
surfaceData.diffuseColor = GET_TEXTURE_STREAMING_DEBUG_NO_UV(posInput.positionSS);
|
|
#endif
|
|
}
|
|
#endif
|
|
ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData);
|
|
#endif
|
|
|
|
#if defined(_SPECULAR_OCCLUSION_CUSTOM)
|
|
#elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL)
|
|
surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness));
|
|
#elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO)
|
|
surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness));
|
|
#endif
|
|
|
|
#ifdef _ENABLE_GEOMETRIC_SPECULAR_AA
|
|
surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold);
|
|
#endif
|
|
}
|
|
|
|
// Get Surface And BuiltinData
|
|
void GetSurfaceAndBuiltinData(AlphaSurfaceDescription surfaceDescription, FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData)
|
|
{
|
|
#ifdef LOD_FADE_CROSSFADE
|
|
LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x);
|
|
#endif
|
|
|
|
#ifdef _DOUBLESIDED_ON
|
|
float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
|
|
#else
|
|
float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
|
|
#endif
|
|
ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants);
|
|
|
|
#ifdef _ALPHATEST_ON
|
|
DoAlphaTest( surfaceDescription.Alpha, surfaceDescription.AlphaClipThreshold );
|
|
#endif
|
|
|
|
#ifdef _ALPHATEST_SHADOW_ON
|
|
DoAlphaTest( surfaceDescription.Alpha, surfaceDescription.AlphaClipThresholdShadow);
|
|
#endif
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput);
|
|
#endif
|
|
|
|
float3 bentNormalWS;
|
|
BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS);
|
|
InitBuiltinData(posInput, surfaceDescription.Alpha, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData);
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
builtinData.depthOffset = surfaceDescription.DepthOffset;
|
|
#endif
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
|
|
{
|
|
surfaceDescription.Alpha = 1.0f;
|
|
}
|
|
#endif
|
|
|
|
#ifdef _ALPHATEST_ON
|
|
builtinData.alphaClipTreshold = surfaceDescription.AlphaClipThreshold;
|
|
#endif
|
|
|
|
#ifdef UNITY_VIRTUAL_TEXTURING
|
|
builtinData.vtPackedFeedback = surfaceDescription.VTPackedFeedback;
|
|
#endif
|
|
|
|
#ifdef ASE_BAKEDGI
|
|
builtinData.bakeDiffuseLighting = surfaceDescription.BakedGI;
|
|
#endif
|
|
|
|
#ifdef ASE_BAKEDBACKGI
|
|
builtinData.backBakeDiffuseLighting = surfaceDescription.BakedBackGI;
|
|
#endif
|
|
|
|
builtinData.emissiveColor = surfaceDescription.Emission;
|
|
|
|
PostInitBuiltinData(V, posInput, surfaceData, builtinData);
|
|
}
|
|
|
|
PackedVaryingsMeshToPS VertexFunction(AttributesMesh inputMesh /*ase_vert_input*/)
|
|
{
|
|
PackedVaryingsMeshToPS outputPackedVaryingsMeshToPS;
|
|
UNITY_SETUP_INSTANCE_ID(inputMesh);
|
|
UNITY_TRANSFER_INSTANCE_ID(inputMesh, outputPackedVaryingsMeshToPS);
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO( outputPackedVaryingsMeshToPS );
|
|
|
|
/*ase_vert_code:inputMesh=AttributesMesh;outputPackedVaryingsMeshToPS=PackedVaryingsMeshToPS*/
|
|
|
|
#ifdef ASE_ABSOLUTE_VERTEX_POS
|
|
float3 defaultVertexValue = inputMesh.positionOS.xyz;
|
|
#else
|
|
float3 defaultVertexValue = float3( 0, 0, 0 );
|
|
#endif
|
|
float3 vertexValue = /*ase_vert_out:Vertex Offset;Float3;4;-1;_VertexOffset*/ defaultVertexValue /*end*/;
|
|
#ifdef ASE_ABSOLUTE_VERTEX_POS
|
|
inputMesh.positionOS.xyz = vertexValue;
|
|
#else
|
|
inputMesh.positionOS.xyz += vertexValue;
|
|
#endif
|
|
|
|
inputMesh.normalOS = /*ase_vert_out:Vertex Normal;Float3;5;-1;_VertexNormal*/ inputMesh.normalOS /*end*/;
|
|
inputMesh.tangentOS = /*ase_vert_out:Vertex Tangent;Float4;6;-1;_VertexTangent*/ inputMesh.tangentOS /*end*/;
|
|
|
|
float3 positionRWS = TransformObjectToWorld(inputMesh.positionOS);
|
|
outputPackedVaryingsMeshToPS.positionCS = TransformWorldToHClip(positionRWS);
|
|
outputPackedVaryingsMeshToPS.positionRWS.xyz = positionRWS;
|
|
return outputPackedVaryingsMeshToPS;
|
|
}
|
|
|
|
#if defined(ASE_TESSELLATION)
|
|
struct VertexControl
|
|
{
|
|
float3 positionOS : INTERNALTESSPOS;
|
|
float3 normalOS : NORMAL;
|
|
float4 tangentOS : TANGENT;
|
|
/*ase_vcontrol*/
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
struct TessellationFactors
|
|
{
|
|
float edge[3] : SV_TessFactor;
|
|
float inside : SV_InsideTessFactor;
|
|
};
|
|
|
|
VertexControl Vert ( AttributesMesh v )
|
|
{
|
|
VertexControl o;
|
|
UNITY_SETUP_INSTANCE_ID(v);
|
|
UNITY_TRANSFER_INSTANCE_ID(v, o);
|
|
o.positionOS = v.positionOS;
|
|
o.normalOS = v.normalOS;
|
|
o.tangentOS = v.tangentOS;
|
|
/*ase_control_code:v=AttributesMesh;o=VertexControl*/
|
|
return o;
|
|
}
|
|
|
|
TessellationFactors TessellationFunction (InputPatch<VertexControl,3> v)
|
|
{
|
|
TessellationFactors o;
|
|
float4 tf = 1;
|
|
float tessValue = /*ase_inline_begin*/_TessValue/*ase_inline_end*/; float tessMin = /*ase_inline_begin*/_TessMin/*ase_inline_end*/; float tessMax = /*ase_inline_begin*/_TessMax/*ase_inline_end*/;
|
|
float edgeLength = /*ase_inline_begin*/_TessEdgeLength/*ase_inline_end*/; float tessMaxDisp = /*ase_inline_begin*/_TessMaxDisp/*ase_inline_end*/;
|
|
#if (SHADEROPTIONS_CAMERA_RELATIVE_RENDERING != 0)
|
|
float3 cameraPos = 0;
|
|
#else
|
|
float3 cameraPos = _WorldSpaceCameraPos;
|
|
#endif
|
|
#if defined(ASE_FIXED_TESSELLATION)
|
|
tf = FixedTess( tessValue );
|
|
#elif defined(ASE_DISTANCE_TESSELLATION)
|
|
tf = DistanceBasedTess(float4(v[0].positionOS,1), float4(v[1].positionOS,1), float4(v[2].positionOS,1), tessValue, tessMin, tessMax, GetObjectToWorldMatrix(), cameraPos );
|
|
#elif defined(ASE_LENGTH_TESSELLATION)
|
|
tf = EdgeLengthBasedTess(float4(v[0].positionOS,1), float4(v[1].positionOS,1), float4(v[2].positionOS,1), edgeLength, GetObjectToWorldMatrix(), cameraPos, _ScreenParams );
|
|
#elif defined(ASE_LENGTH_CULL_TESSELLATION)
|
|
tf = EdgeLengthBasedTessCull(float4(v[0].positionOS,1), float4(v[1].positionOS,1), float4(v[2].positionOS,1), edgeLength, tessMaxDisp, GetObjectToWorldMatrix(), cameraPos, _ScreenParams, _FrustumPlanes );
|
|
#endif
|
|
o.edge[0] = tf.x; o.edge[1] = tf.y; o.edge[2] = tf.z; o.inside = tf.w;
|
|
return o;
|
|
}
|
|
|
|
[domain("tri")]
|
|
[partitioning("fractional_odd")]
|
|
[outputtopology("triangle_cw")]
|
|
[patchconstantfunc("TessellationFunction")]
|
|
[outputcontrolpoints(3)]
|
|
VertexControl HullFunction(InputPatch<VertexControl, 3> patch, uint id : SV_OutputControlPointID)
|
|
{
|
|
return patch[id];
|
|
}
|
|
|
|
[domain("tri")]
|
|
PackedVaryingsMeshToPS DomainFunction(TessellationFactors factors, OutputPatch<VertexControl, 3> patch, float3 bary : SV_DomainLocation)
|
|
{
|
|
AttributesMesh o = (AttributesMesh) 0;
|
|
o.positionOS = patch[0].positionOS * bary.x + patch[1].positionOS * bary.y + patch[2].positionOS * bary.z;
|
|
o.normalOS = patch[0].normalOS * bary.x + patch[1].normalOS * bary.y + patch[2].normalOS * bary.z;
|
|
o.tangentOS = patch[0].tangentOS * bary.x + patch[1].tangentOS * bary.y + patch[2].tangentOS * bary.z;
|
|
/*ase_domain_code:patch=VertexControl;o=AttributesMesh;bary=SV_DomainLocation*/
|
|
#if defined(ASE_PHONG_TESSELLATION)
|
|
float3 pp[3];
|
|
for (int i = 0; i < 3; ++i)
|
|
pp[i] = o.positionOS.xyz - patch[i].normalOS * (dot(o.positionOS.xyz, patch[i].normalOS) - dot(patch[i].positionOS.xyz, patch[i].normalOS));
|
|
float phongStrength = /*ase_inline_begin*/_TessPhongStrength/*ase_inline_end*/;
|
|
o.positionOS.xyz = phongStrength * (pp[0]*bary.x + pp[1]*bary.y + pp[2]*bary.z) + (1.0f-phongStrength) * o.positionOS.xyz;
|
|
#endif
|
|
UNITY_TRANSFER_INSTANCE_ID(patch[0], o);
|
|
return VertexFunction(o);
|
|
}
|
|
#else
|
|
PackedVaryingsMeshToPS Vert ( AttributesMesh v )
|
|
{
|
|
return VertexFunction( v );
|
|
}
|
|
#endif
|
|
|
|
#if defined(WRITE_NORMAL_BUFFER) && defined(WRITE_MSAA_DEPTH)
|
|
#define SV_TARGET_DECAL SV_Target2
|
|
#elif defined(WRITE_NORMAL_BUFFER) || defined(WRITE_MSAA_DEPTH)
|
|
#define SV_TARGET_DECAL SV_Target1
|
|
#else
|
|
#define SV_TARGET_DECAL SV_Target0
|
|
#endif
|
|
|
|
void Frag( PackedVaryingsMeshToPS packedInput
|
|
#if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS)
|
|
, out float4 outColor : SV_Target0
|
|
#else
|
|
#ifdef WRITE_MSAA_DEPTH
|
|
, out float4 depthColor : SV_Target0
|
|
#ifdef WRITE_NORMAL_BUFFER
|
|
, out float4 outNormalBuffer : SV_Target1
|
|
#endif
|
|
#else
|
|
#ifdef WRITE_NORMAL_BUFFER
|
|
, out float4 outNormalBuffer : SV_Target0
|
|
#endif
|
|
#endif
|
|
|
|
#if (defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS)) || defined(WRITE_RENDERING_LAYER)
|
|
, out float4 outDecalBuffer : SV_TARGET_DECAL
|
|
#endif
|
|
#endif
|
|
|
|
#if defined(_DEPTHOFFSET_ON) && !defined(SCENEPICKINGPASS)
|
|
, out float outputDepth : DEPTH_OFFSET_SEMANTIC
|
|
#endif
|
|
/*ase_frag_input*/
|
|
)
|
|
{
|
|
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput);
|
|
UNITY_SETUP_INSTANCE_ID(packedInput);
|
|
|
|
/*ase_local_var:rwp*/float3 positionRWS = packedInput.positionRWS.xyz;
|
|
|
|
FragInputs input;
|
|
ZERO_INITIALIZE(FragInputs, input);
|
|
|
|
input.tangentToWorld = k_identity3x3;
|
|
input.positionSS = packedInput.positionCS;
|
|
|
|
input.positionRWS = positionRWS;
|
|
|
|
#if _DOUBLESIDED_ON && SHADER_STAGE_FRAGMENT
|
|
input.isFrontFace = IS_FRONT_VFACE( packedInput.cullFace, true, false);
|
|
#elif SHADER_STAGE_FRAGMENT
|
|
#if defined(ASE_NEED_CULLFACE)
|
|
input.isFrontFace = IS_FRONT_VFACE( packedInput.cullFace, true, false );
|
|
#endif
|
|
#endif
|
|
/*ase_local_var:vf*/half isFrontFace = input.isFrontFace;
|
|
|
|
PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS);
|
|
|
|
/*ase_local_var:wvd*/float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
|
|
|
|
AlphaSurfaceDescription surfaceDescription = (AlphaSurfaceDescription)0;
|
|
/*ase_frag_code:packedInput=PackedVaryingsMeshToPS*/
|
|
surfaceDescription.Alpha = /*ase_frag_out:Alpha;Float;0;-1;_Alpha*/1/*end*/;
|
|
|
|
#ifdef _ALPHATEST_ON
|
|
surfaceDescription.AlphaClipThreshold = /*ase_frag_out:Alpha Clip Threshold;Float;1;-1;_AlphaClip*/_AlphaCutoff/*end*/;
|
|
#endif
|
|
|
|
#ifdef _ALPHATEST_SHADOW_ON
|
|
surfaceDescription.AlphaClipThresholdShadow = /*ase_frag_out:Alpha Clip Threshold Shadow;Float;2;-1;_AlphaClipShadow*/0.5/*end*/;
|
|
#endif
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
surfaceDescription.DepthOffset = /*ase_frag_out:Depth Offset;Float;3;-1;_DepthOffset*/0/*end*/;
|
|
#endif
|
|
|
|
SurfaceData surfaceData;
|
|
BuiltinData builtinData;
|
|
GetSurfaceAndBuiltinData(surfaceDescription, input, V, posInput, surfaceData, builtinData);
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
outputDepth = posInput.deviceDepth;
|
|
float bias = max(abs(ddx(posInput.deviceDepth)), abs(ddy(posInput.deviceDepth))) * _SlopeScaleDepthBias;
|
|
outputDepth += bias;
|
|
#endif
|
|
|
|
#ifdef WRITE_MSAA_DEPTH
|
|
depthColor = packedInput.vmesh.positionCS.z;
|
|
depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold);
|
|
#endif
|
|
|
|
#if defined(WRITE_NORMAL_BUFFER)
|
|
EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer);
|
|
#endif
|
|
|
|
#if (defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS)) || defined(WRITE_RENDERING_LAYER)
|
|
DecalPrepassData decalPrepassData;
|
|
#ifdef _DISABLE_DECALS
|
|
ZERO_INITIALIZE(DecalPrepassData, decalPrepassData);
|
|
#else
|
|
decalPrepassData.geomNormalWS = surfaceData.geomNormalWS;
|
|
#endif
|
|
decalPrepassData.renderingLayerMask = GetMeshRenderingLayerMask();
|
|
EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer);
|
|
#endif
|
|
}
|
|
ENDHLSL
|
|
}
|
|
|
|
/*ase_pass*/
|
|
Pass
|
|
{
|
|
/*ase_hide_pass*/
|
|
Name "META"
|
|
Tags
|
|
{
|
|
"LightMode" = "Meta"
|
|
}
|
|
|
|
Cull Off
|
|
|
|
HLSLPROGRAM
|
|
#pragma shader_feature _ EDITOR_VISUALIZATION
|
|
#pragma multi_compile _ DOTS_INSTANCING_ON
|
|
|
|
#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT
|
|
#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC _TRANSPARENT_REFRACTIVE_SORT
|
|
#pragma shader_feature_local_fragment _ _ENABLE_FOG_ON_TRANSPARENT
|
|
|
|
//RayTracing
|
|
//#pragma shader_feature_local_raytracing _ _DISABLE_DECALS
|
|
//#pragma shader_feature_local_raytracing _ _DISABLE_SSR
|
|
//#pragma shader_feature_local_raytracing _ _DISABLE_SSR_TRANSPARENT
|
|
|
|
#pragma vertex Vert
|
|
#pragma fragment Frag
|
|
|
|
#define SHADERPASS SHADERPASS_LIGHT_TRANSPORT
|
|
#define SCENEPICKINGPASS 1
|
|
#define _ABSORPTION_FROM_COLOR 1
|
|
#define SUPPORT_GLOBAL_MIP_BIAS 1
|
|
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl"
|
|
#include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl"
|
|
|
|
//#if !defined(SHADER_STAGE_RAY_TRACING) && SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER && SHADERPASS != SHADERPASS_FULL_SCREEN_DEBUG
|
|
//#define FRAG_INPUTS_ENABLE_STRIPPING
|
|
//#endif
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl"
|
|
|
|
#ifdef RAYTRACING_SHADER_GRAPH_DEFAULT
|
|
#define RAYTRACING_SHADER_GRAPH_HIGH
|
|
#endif
|
|
|
|
#ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED
|
|
#define RAYTRACING_SHADER_GRAPH_LOW
|
|
#endif
|
|
|
|
#ifndef SHADER_UNLIT
|
|
#if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE)
|
|
#define VARYINGS_NEED_CULLFACE
|
|
#endif
|
|
#endif
|
|
|
|
#if defined(_DOUBLESIDED_ON) && !defined(ASE_NEED_CULLFACE)
|
|
#define ASE_NEED_CULLFACE 1
|
|
#endif
|
|
|
|
#if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
|
|
#if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT)
|
|
#define WRITE_NORMAL_BUFFER
|
|
#endif
|
|
#endif
|
|
|
|
#if SHADERPASS == SHADERPASS_MOTION_VECTORS && defined(WRITE_DECAL_BUFFER_AND_RENDERING_LAYER)
|
|
#define WRITE_DECAL_BUFFER
|
|
#endif
|
|
|
|
#ifndef DEBUG_DISPLAY
|
|
#if !defined(_SURFACE_TYPE_TRANSPARENT)
|
|
#if SHADERPASS == SHADERPASS_FORWARD
|
|
#define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
|
|
#elif SHADERPASS == SHADERPASS_GBUFFER
|
|
#define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST
|
|
#endif
|
|
#endif
|
|
#endif
|
|
|
|
#if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT)
|
|
#define _DEFERRED_CAPABLE_MATERIAL
|
|
#endif
|
|
|
|
#if (defined(_TRANSPARENT_WRITES_MOTION_VEC) || defined(_TRANSPARENT_REFRACTIVE_SORT)) && defined(_SURFACE_TYPE_TRANSPARENT)
|
|
#define _WRITE_TRANSPARENT_MOTION_VECTOR
|
|
#endif
|
|
|
|
CBUFFER_START( UnityPerMaterial )
|
|
float4 _EmissionColor;
|
|
float _AlphaCutoff;
|
|
float _RenderQueueType;
|
|
#ifdef _ADD_PRECOMPUTED_VELOCITY
|
|
float _AddPrecomputedVelocity;
|
|
#endif
|
|
float _ExcludeFromTUAndAA;
|
|
float _StencilRef;
|
|
float _StencilWriteMask;
|
|
float _StencilRefDepth;
|
|
float _StencilWriteMaskDepth;
|
|
float _StencilRefMV;
|
|
float _StencilWriteMaskMV;
|
|
float _StencilRefDistortionVec;
|
|
float _StencilWriteMaskDistortionVec;
|
|
float _StencilWriteMaskGBuffer;
|
|
float _StencilRefGBuffer;
|
|
float _ZTestGBuffer;
|
|
float _RequireSplitLighting;
|
|
float _ReceivesSSR;
|
|
float _SurfaceType;
|
|
float _BlendMode;
|
|
#ifdef SUPPORT_BLENDMODE_PRESERVE_SPECULAR_LIGHTING
|
|
float _EnableBlendModePreserveSpecularLighting;
|
|
#endif
|
|
float _SrcBlend;
|
|
float _DstBlend;
|
|
float _DstBlend2;
|
|
float _AlphaSrcBlend;
|
|
float _AlphaDstBlend;
|
|
float _ZWrite;
|
|
float _TransparentZWrite;
|
|
float _CullMode;
|
|
float _TransparentSortPriority;
|
|
float _EnableFogOnTransparent;
|
|
float _CullModeForward;
|
|
float _TransparentCullMode;
|
|
float _ZTestDepthEqualForOpaque;
|
|
float _ZTestTransparent;
|
|
float _TransparentBackfaceEnable;
|
|
float _AlphaCutoffEnable;
|
|
float _UseShadowThreshold;
|
|
float _DoubleSidedEnable;
|
|
float _DoubleSidedNormalMode;
|
|
float4 _DoubleSidedConstants;
|
|
#ifdef ASE_TESSELLATION
|
|
float _TessPhongStrength;
|
|
float _TessValue;
|
|
float _TessMin;
|
|
float _TessMax;
|
|
float _TessEdgeLength;
|
|
float _TessMaxDisp;
|
|
#endif
|
|
UNITY_TEXTURE_STREAMING_DEBUG_VARS;
|
|
CBUFFER_END
|
|
|
|
#ifdef SCENEPICKINGPASS
|
|
float4 _SelectionID;
|
|
#endif
|
|
|
|
#ifdef SCENESELECTIONPASS
|
|
int _ObjectId;
|
|
int _PassValue;
|
|
#endif
|
|
|
|
/*ase_globals*/
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
|
|
#endif
|
|
|
|
#if SHADERPASS == SHADERPASS_LIGHT_TRANSPORT
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/PickingSpaceTransforms.hlsl"
|
|
#endif
|
|
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/MetaPass.hlsl"
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Hair/Hair.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl"
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl"
|
|
|
|
#ifdef HAVE_VFX_MODIFICATION
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/VisualEffectVertex.hlsl"
|
|
#endif
|
|
|
|
/*ase_pragma*/
|
|
|
|
struct AttributesMesh
|
|
{
|
|
float3 positionOS : POSITION;
|
|
float3 normalOS : NORMAL;
|
|
float4 tangentOS : TANGENT;
|
|
float4 uv0 : TEXCOORD0;
|
|
float4 uv1 : TEXCOORD1;
|
|
float4 uv2 : TEXCOORD2;
|
|
float4 uv3 : TEXCOORD3;
|
|
/*ase_vdata:p=p;n=n;t=t;uv0=tc0;uv1=tc1;uv2=tc2;uv3=tc3*/
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
struct PackedVaryingsMeshToPS
|
|
{
|
|
SV_POSITION_QUALIFIERS float4 positionCS : SV_Position;
|
|
#ifdef EDITOR_VISUALIZATION
|
|
float2 VizUV : TEXCOORD0;
|
|
float4 LightCoord : TEXCOORD1;
|
|
#endif
|
|
/*ase_interp(2,):sp=sp.xyzw*/
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
#if defined(SHADER_STAGE_FRAGMENT) && defined(ASE_NEED_CULLFACE)
|
|
FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
|
|
#endif
|
|
};
|
|
|
|
/*ase_funcs*/
|
|
|
|
//Build Surface Data (Decal)
|
|
void ApplyDecalToSurfaceDataNoNormal(DecalSurfaceData decalSurfaceData, inout SurfaceData surfaceData)
|
|
{
|
|
surfaceData.diffuseColor.xyz = surfaceData.diffuseColor.xyz * decalSurfaceData.baseColor.w + decalSurfaceData.baseColor.xyz;
|
|
|
|
#ifdef DECALS_4RT
|
|
surfaceData.ambientOcclusion = surfaceData.ambientOcclusion * decalSurfaceData.MAOSBlend.y + decalSurfaceData.mask.y;
|
|
#endif
|
|
|
|
surfaceData.perceptualSmoothness = surfaceData.perceptualSmoothness * decalSurfaceData.mask.w + decalSurfaceData.mask.z;
|
|
}
|
|
|
|
void BuildSurfaceData(FragInputs fragInputs, inout GlobalSurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS)
|
|
{
|
|
ZERO_INITIALIZE(SurfaceData, surfaceData);
|
|
|
|
surfaceData.specularOcclusion = 1.0;
|
|
|
|
surfaceData.diffuseColor = surfaceDescription.BaseColor;
|
|
surfaceData.perceptualSmoothness = surfaceDescription.Smoothness;
|
|
surfaceData.ambientOcclusion = surfaceDescription.Occlusion;
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_KAJIYA_KAY
|
|
surfaceData.transmittance = surfaceDescription.Transmittance;
|
|
surfaceData.rimTransmissionIntensity = surfaceDescription.RimTransmissionIntensity;
|
|
surfaceData.specularTint = surfaceDescription.SpecularTint;
|
|
surfaceData.specularShift = surfaceDescription.SpecularShift;
|
|
surfaceData.secondaryPerceptualSmoothness = surfaceDescription.SecondarySmoothness;
|
|
surfaceData.secondarySpecularTint = surfaceDescription.SecondarySpecularTint;
|
|
surfaceData.secondarySpecularShift = surfaceDescription.SecondarySpecularShift;
|
|
#endif
|
|
|
|
//#ifdef _MATERIAL_FEATURE_HAIR_MARSCHNER
|
|
surfaceData.perceptualRadialSmoothness = surfaceDescription.RadialSmoothness;
|
|
surfaceData.cuticleAngle = surfaceDescription.CuticleAngle;
|
|
//#endif
|
|
|
|
surfaceData.strandCountProbe = surfaceDescription.StrandCountProbe;
|
|
|
|
#ifdef _USE_SPLINE_VISIBILITY_FOR_MULTIPLE_SCATTERING
|
|
surfaceData.strandShadowBias = surfaceDescription.StrandShadowBias;
|
|
#endif
|
|
|
|
#ifdef _SPECULAR_OCCLUSION_CUSTOM
|
|
surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion;
|
|
#endif
|
|
|
|
surfaceData.materialFeatures = 0;
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_KAJIYA_KAY
|
|
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_HAIR_KAJIYA_KAY;
|
|
#endif
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_MARSCHNER
|
|
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_HAIR_MARSCHNER;
|
|
#endif
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_MARSCHNER_CINEMATIC
|
|
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_HAIR_MARSCHNER_CINEMATIC;
|
|
#endif
|
|
|
|
#ifdef _DOUBLESIDED_ON
|
|
float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
|
|
#else
|
|
float3 doubleSidedConstants = float3( 1.0, 1.0, 1.0 );
|
|
#endif
|
|
|
|
float3 normalTS = float3(0.0f, 0.0f, 1.0f);
|
|
normalTS = surfaceDescription.Normal;
|
|
|
|
#ifdef DECAL_NORMAL_BLENDING
|
|
normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]);
|
|
|
|
#if HAVE_DECALS
|
|
if (_EnableDecals)
|
|
{
|
|
float alpha = 1.0;
|
|
alpha = surfaceDescription.Alpha;
|
|
|
|
DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
|
|
ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS);
|
|
ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData);
|
|
}
|
|
#endif
|
|
|
|
GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants);
|
|
#else
|
|
GetNormalWS(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants);
|
|
|
|
#if HAVE_DECALS
|
|
if (_EnableDecals)
|
|
{
|
|
float alpha = 1.0;
|
|
alpha = surfaceDescription.Alpha;
|
|
|
|
DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
|
|
ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz);
|
|
ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData);
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];
|
|
surfaceData.hairStrandDirectionWS = -fragInputs.tangentToWorld[1].xyz;
|
|
surfaceData.hairStrandDirectionWS = normalize(surfaceData.hairStrandDirectionWS);
|
|
|
|
#ifdef ASE_HAIRDIRECTION
|
|
surfaceData.hairStrandDirectionWS = TransformTangentToWorld(surfaceDescription.HairStrandDirection, fragInputs.tangentToWorld);
|
|
#endif
|
|
|
|
#if (_USE_LIGHT_FACING_NORMAL)
|
|
float3 viewFacingNormalWS = ComputeViewFacingNormal(V, surfaceData.hairStrandDirectionWS);
|
|
float3 N = viewFacingNormalWS;
|
|
#else
|
|
float3 N = surfaceData.normalWS;
|
|
#endif
|
|
|
|
bentNormalWS = surfaceData.normalWS;
|
|
|
|
#ifdef ASE_BENT_NORMAL
|
|
GetNormalWS( fragInputs, surfaceDescription.BentNormal, bentNormalWS, doubleSidedConstants );
|
|
#endif
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
#if !defined(SHADER_STAGE_RAY_TRACING)
|
|
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
|
|
{
|
|
#ifdef FRAG_INPUTS_USE_TEXCOORD0
|
|
surfaceData.diffuseColor = GET_TEXTURE_STREAMING_DEBUG(posInput.positionSS, fragInputs.texCoord0);
|
|
#else
|
|
surfaceData.diffuseColor = GET_TEXTURE_STREAMING_DEBUG_NO_UV(posInput.positionSS);
|
|
#endif
|
|
}
|
|
#endif
|
|
ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData);
|
|
#endif
|
|
|
|
#if defined(_SPECULAR_OCCLUSION_CUSTOM)
|
|
#elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL)
|
|
surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness));
|
|
#elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO)
|
|
surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness));
|
|
#endif
|
|
|
|
#ifdef _ENABLE_GEOMETRIC_SPECULAR_AA
|
|
surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold);
|
|
#endif
|
|
}
|
|
|
|
// Get Surface And BuiltinData
|
|
void GetSurfaceAndBuiltinData(GlobalSurfaceDescription surfaceDescription, FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData)
|
|
{
|
|
#ifdef LOD_FADE_CROSSFADE
|
|
LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x);
|
|
#endif
|
|
|
|
#ifdef _DOUBLESIDED_ON
|
|
float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
|
|
#else
|
|
float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
|
|
#endif
|
|
ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants);
|
|
|
|
#ifdef _ALPHATEST_ON
|
|
DoAlphaTest( surfaceDescription.Alpha, surfaceDescription.AlphaClipThreshold );
|
|
#endif
|
|
|
|
#ifdef _ALPHATEST_SHADOW_ON
|
|
DoAlphaTest( surfaceDescription.Alpha, surfaceDescription.AlphaClipThresholdShadow);
|
|
#endif
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput);
|
|
#endif
|
|
|
|
float3 bentNormalWS;
|
|
BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS);
|
|
InitBuiltinData(posInput, surfaceDescription.Alpha, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData);
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
builtinData.depthOffset = surfaceDescription.DepthOffset;
|
|
#endif
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
|
|
{
|
|
surfaceDescription.Alpha = 1.0f;
|
|
}
|
|
#endif
|
|
|
|
#ifdef _ALPHATEST_ON
|
|
builtinData.alphaClipTreshold = surfaceDescription.AlphaClipThreshold;
|
|
#endif
|
|
|
|
#ifdef UNITY_VIRTUAL_TEXTURING
|
|
builtinData.vtPackedFeedback = surfaceDescription.VTPackedFeedback;
|
|
#endif
|
|
|
|
#ifdef ASE_BAKEDGI
|
|
builtinData.bakeDiffuseLighting = surfaceDescription.BakedGI;
|
|
#endif
|
|
|
|
#ifdef ASE_BAKEDBACKGI
|
|
builtinData.backBakeDiffuseLighting = surfaceDescription.BakedBackGI;
|
|
#endif
|
|
|
|
builtinData.emissiveColor = surfaceDescription.Emission;
|
|
|
|
PostInitBuiltinData(V, posInput, surfaceData, builtinData);
|
|
}
|
|
|
|
PackedVaryingsMeshToPS VertexFunction(AttributesMesh inputMesh /*ase_vert_input*/ )
|
|
{
|
|
PackedVaryingsMeshToPS outputPackedVaryingsMeshToPS;
|
|
|
|
UNITY_SETUP_INSTANCE_ID(inputMesh);
|
|
UNITY_TRANSFER_INSTANCE_ID(inputMesh, outputPackedVaryingsMeshToPS);
|
|
|
|
/*ase_vert_code:inputMesh=AttributesMesh;outputPackedVaryingsMeshToPS=PackedVaryingsMeshToPS*/
|
|
|
|
#ifdef ASE_ABSOLUTE_VERTEX_POS
|
|
float3 defaultVertexValue = inputMesh.positionOS.xyz;
|
|
#else
|
|
float3 defaultVertexValue = float3( 0, 0, 0 );
|
|
#endif
|
|
float3 vertexValue = /*ase_vert_out:Vertex Offset;Float3;18;-1;_VertexOffset*/defaultVertexValue/*end*/;
|
|
#ifdef ASE_ABSOLUTE_VERTEX_POS
|
|
inputMesh.positionOS.xyz = vertexValue;
|
|
#else
|
|
inputMesh.positionOS.xyz += vertexValue;
|
|
#endif
|
|
|
|
inputMesh.normalOS = /*ase_vert_out:Vertex Normal;Float3;19;-1;_VertexNormal*/inputMesh.normalOS/*end*/;
|
|
inputMesh.tangentOS = /*ase_vert_out:Vertex Tangent;Float4;20;-1;_VertexTangent*/inputMesh.tangentOS/*end*/;
|
|
|
|
outputPackedVaryingsMeshToPS.positionCS = UnityMetaVertexPosition(inputMesh.positionOS, inputMesh.uv1.xy, inputMesh.uv2.xy, unity_LightmapST, unity_DynamicLightmapST);
|
|
|
|
#ifdef EDITOR_VISUALIZATION
|
|
float2 vizUV = 0;
|
|
float4 lightCoord = 0;
|
|
UnityEditorVizData(inputMesh.positionOS.xyz, inputMesh.uv0.xy, inputMesh.uv1.xy, inputMesh.uv2.xy, vizUV, lightCoord);
|
|
|
|
outputPackedVaryingsMeshToPS.VizUV.xy = vizUV;
|
|
outputPackedVaryingsMeshToPS.LightCoord = lightCoord;
|
|
#endif
|
|
|
|
return outputPackedVaryingsMeshToPS;
|
|
}
|
|
|
|
#if defined(ASE_TESSELLATION)
|
|
struct VertexControl
|
|
{
|
|
float3 positionOS : INTERNALTESSPOS;
|
|
float3 normalOS : NORMAL;
|
|
float4 tangentOS : TANGENT;
|
|
float4 uv0 : TEXCOORD0;
|
|
float4 uv1 : TEXCOORD1;
|
|
float4 uv2 : TEXCOORD2;
|
|
float4 uv3 : TEXCOORD3;
|
|
/*ase_vcontrol*/
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
struct TessellationFactors
|
|
{
|
|
float edge[3] : SV_TessFactor;
|
|
float inside : SV_InsideTessFactor;
|
|
};
|
|
|
|
VertexControl Vert ( AttributesMesh v )
|
|
{
|
|
VertexControl o;
|
|
UNITY_SETUP_INSTANCE_ID(v);
|
|
UNITY_TRANSFER_INSTANCE_ID(v, o);
|
|
o.positionOS = v.positionOS;
|
|
o.normalOS = v.normalOS;
|
|
o.tangentOS = v.tangentOS;
|
|
o.uv0 = v.uv0;
|
|
o.uv1 = v.uv1;
|
|
o.uv2 = v.uv2;
|
|
o.uv3 = v.uv3;
|
|
/*ase_control_code:v=AttributesMesh;o=VertexControl*/
|
|
return o;
|
|
}
|
|
|
|
TessellationFactors TessellationFunction (InputPatch<VertexControl,3> v)
|
|
{
|
|
TessellationFactors o;
|
|
float4 tf = 1;
|
|
float tessValue = /*ase_inline_begin*/_TessValue/*ase_inline_end*/; float tessMin = /*ase_inline_begin*/_TessMin/*ase_inline_end*/; float tessMax = /*ase_inline_begin*/_TessMax/*ase_inline_end*/;
|
|
float edgeLength = /*ase_inline_begin*/_TessEdgeLength/*ase_inline_end*/; float tessMaxDisp = /*ase_inline_begin*/_TessMaxDisp/*ase_inline_end*/;
|
|
#if (SHADEROPTIONS_CAMERA_RELATIVE_RENDERING != 0)
|
|
float3 cameraPos = 0;
|
|
#else
|
|
float3 cameraPos = _WorldSpaceCameraPos;
|
|
#endif
|
|
#if defined(ASE_FIXED_TESSELLATION)
|
|
tf = FixedTess( tessValue );
|
|
#elif defined(ASE_DISTANCE_TESSELLATION)
|
|
tf = DistanceBasedTess(float4(v[0].positionOS,1), float4(v[1].positionOS,1), float4(v[2].positionOS,1), tessValue, tessMin, tessMax, GetObjectToWorldMatrix(), cameraPos );
|
|
#elif defined(ASE_LENGTH_TESSELLATION)
|
|
tf = EdgeLengthBasedTess(float4(v[0].positionOS,1), float4(v[1].positionOS,1), float4(v[2].positionOS,1), edgeLength, GetObjectToWorldMatrix(), cameraPos, _ScreenParams );
|
|
#elif defined(ASE_LENGTH_CULL_TESSELLATION)
|
|
tf = EdgeLengthBasedTessCull(float4(v[0].positionOS,1), float4(v[1].positionOS,1), float4(v[2].positionOS,1), edgeLength, tessMaxDisp, GetObjectToWorldMatrix(), cameraPos, _ScreenParams, _FrustumPlanes );
|
|
#endif
|
|
o.edge[0] = tf.x; o.edge[1] = tf.y; o.edge[2] = tf.z; o.inside = tf.w;
|
|
return o;
|
|
}
|
|
|
|
[domain("tri")]
|
|
[partitioning("fractional_odd")]
|
|
[outputtopology("triangle_cw")]
|
|
[patchconstantfunc("TessellationFunction")]
|
|
[outputcontrolpoints(3)]
|
|
VertexControl HullFunction(InputPatch<VertexControl, 3> patch, uint id : SV_OutputControlPointID)
|
|
{
|
|
return patch[id];
|
|
}
|
|
|
|
[domain("tri")]
|
|
PackedVaryingsMeshToPS DomainFunction(TessellationFactors factors, OutputPatch<VertexControl, 3> patch, float3 bary : SV_DomainLocation)
|
|
{
|
|
AttributesMesh o = (AttributesMesh) 0;
|
|
o.positionOS = patch[0].positionOS * bary.x + patch[1].positionOS * bary.y + patch[2].positionOS * bary.z;
|
|
o.normalOS = patch[0].normalOS * bary.x + patch[1].normalOS * bary.y + patch[2].normalOS * bary.z;
|
|
o.tangentOS = patch[0].tangentOS * bary.x + patch[1].tangentOS * bary.y + patch[2].tangentOS * bary.z;
|
|
o.uv0 = patch[0].uv0 * bary.x + patch[1].uv0 * bary.y + patch[2].uv0 * bary.z;
|
|
o.uv1 = patch[0].uv1 * bary.x + patch[1].uv1 * bary.y + patch[2].uv1 * bary.z;
|
|
o.uv2 = patch[0].uv2 * bary.x + patch[1].uv2 * bary.y + patch[2].uv2 * bary.z;
|
|
o.uv3 = patch[0].uv3 * bary.x + patch[1].uv3 * bary.y + patch[2].uv3 * bary.z;
|
|
/*ase_domain_code:patch=VertexControl;o=AttributesMesh;bary=SV_DomainLocation*/
|
|
#if defined(ASE_PHONG_TESSELLATION)
|
|
float3 pp[3];
|
|
for (int i = 0; i < 3; ++i)
|
|
pp[i] = o.positionOS.xyz - patch[i].normalOS * (dot(o.positionOS.xyz, patch[i].normalOS) - dot(patch[i].positionOS.xyz, patch[i].normalOS));
|
|
float phongStrength = /*ase_inline_begin*/_TessPhongStrength/*ase_inline_end*/;
|
|
o.positionOS.xyz = phongStrength * (pp[0]*bary.x + pp[1]*bary.y + pp[2]*bary.z) + (1.0f-phongStrength) * o.positionOS.xyz;
|
|
#endif
|
|
UNITY_TRANSFER_INSTANCE_ID(patch[0], o);
|
|
return VertexFunction(o);
|
|
}
|
|
#else
|
|
PackedVaryingsMeshToPS Vert ( AttributesMesh v )
|
|
{
|
|
return VertexFunction( v );
|
|
}
|
|
#endif
|
|
|
|
float4 Frag(PackedVaryingsMeshToPS packedInput /*ase_frag_input*/ ) : SV_Target
|
|
{
|
|
UNITY_SETUP_INSTANCE_ID( packedInput );
|
|
FragInputs input;
|
|
ZERO_INITIALIZE(FragInputs, input);
|
|
input.tangentToWorld = k_identity3x3;
|
|
input.positionSS = packedInput.positionCS;
|
|
|
|
#if _DOUBLESIDED_ON && SHADER_STAGE_FRAGMENT
|
|
input.isFrontFace = IS_FRONT_VFACE( packedInput.cullFace, true, false);
|
|
#elif SHADER_STAGE_FRAGMENT
|
|
#if defined(ASE_NEED_CULLFACE)
|
|
input.isFrontFace = IS_FRONT_VFACE(packedInput.cullFace, true, false);
|
|
#endif
|
|
#endif
|
|
/*ase_local_var:vf*/half isFrontFace = input.isFrontFace;
|
|
|
|
PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS);
|
|
float3 V = float3(1.0, 1.0, 1.0);
|
|
|
|
SurfaceData surfaceData;
|
|
BuiltinData builtinData;
|
|
GlobalSurfaceDescription surfaceDescription = (GlobalSurfaceDescription)0;
|
|
/*ase_frag_code:packedInput=PackedVaryingsMeshToPS*/
|
|
surfaceDescription.BaseColor = /*ase_frag_out:Base Color;Float3;0;-1;_BaseColor*/float3( 0.7353569, 0.7353569, 0.7353569 )/*end*/;
|
|
surfaceDescription.Normal = /*ase_frag_out:Normal;Float3;1;-1;_Normal*/float3( 0, 0, 1 )/*end*/;
|
|
surfaceDescription.BentNormal = /*ase_frag_out:Bent Normal;Float3;2;-1;_BentNormal*/float3( 0, 0, 1 )/*end*/;
|
|
surfaceDescription.HairStrandDirection = /*ase_frag_out:Hair Strand Direction;Float3;7;-1;_HairStrandDirection*/float3(0,-1,0)/*end*/;
|
|
surfaceDescription.Emission = /*ase_frag_out:Emission;Float3;45;-1;_Emission*/float3(0,0,0)/*end*/;
|
|
surfaceDescription.Smoothness = /*ase_frag_out:Smoothness;Float;3;-1;_Smoothness*/0.5/*end*/;
|
|
surfaceDescription.Occlusion = /*ase_frag_out:Occlusion;Float;4;-1;_Occlusion*/1/*end*/;
|
|
|
|
surfaceDescription.Alpha = /*ase_frag_out:Alpha;Float;8;-1;_Alpha*/1/*end*/;
|
|
|
|
#ifdef _ALPHATEST_ON
|
|
surfaceDescription.AlphaClipThreshold = /*ase_frag_out:Alpha Clip Threshold;Float;9;-1;_AlphaClip*/_AlphaCutoff/*end*/;
|
|
#endif
|
|
|
|
#ifdef _ENABLE_GEOMETRIC_SPECULAR_AA
|
|
surfaceDescription.SpecularAAScreenSpaceVariance = /*ase_frag_out:Specular AA Screen Space Variance;Float;11;-1;_SpecularAAScreenSpaceVariance*/0.1/*end*/;
|
|
surfaceDescription.SpecularAAThreshold = /*ase_frag_out:Specular AA Threshold;Float;12;-1;_SpecularAAThreshold*/0.2/*end*/;
|
|
#endif
|
|
|
|
#ifdef _SPECULAR_OCCLUSION_CUSTOM
|
|
surfaceDescription.SpecularOcclusion = /*ase_frag_out:Specular Occlusion;Float;10;-1;_SpecularOcclusion*/1/*end*/;
|
|
#endif
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_KAJIYA_KAY
|
|
surfaceDescription.Transmittance = /*ase_frag_out:Transmittance;Float3;5;-1;_Transmittance*/float3(0.3,0.195,0.09)/*end*/;
|
|
surfaceDescription.RimTransmissionIntensity = /*ase_frag_out:Rim Transmission Intensity;Float;6;-1;_RimTransmissionIntensity*/0.2/*end*/;
|
|
surfaceDescription.SpecularTint = /*ase_frag_out:Specular Tint;Float3;13;-1;_SpecularTint*/float3(1,1,1)/*end*/;
|
|
surfaceDescription.SpecularShift = /*ase_frag_out:Specular Shift;Float;14;-1;_SpecularShift*/0.1/*end*/;
|
|
surfaceDescription.SecondarySpecularTint = /*ase_frag_out:Secondary Specular Tint;Float3;15;-1;_SecondarySpecularTint*/float3(0.5,0.5,0.5)/*end*/;
|
|
surfaceDescription.SecondarySmoothness = /*ase_frag_out:Secondary Smoothness;Float;16;-1;_SecondarySmoothness*/0.5/*end*/;
|
|
surfaceDescription.SecondarySpecularShift = /*ase_frag_out:Secondary Specular Shift;Float;17;-1;_SecondarySpecularShift*/-0.1/*end*/;
|
|
#endif
|
|
|
|
//#ifdef _MATERIAL_FEATURE_HAIR_MARSCHNER
|
|
surfaceDescription.RadialSmoothness = /*ase_frag_out:Radial Smoothness;Float;41;-1;_RadialSmoothness*/0.7/*end*/;
|
|
surfaceDescription.CuticleAngle = /*ase_frag_out:Cuticle Angle Shift;Float;42;-1;_CuticleAngle*/-0.1/*end*/;
|
|
//#endif
|
|
|
|
surfaceDescription.StrandCountProbe = /*ase_frag_out:Strand Count Probe;Float4;43;-1;_StrandCountProbe*/float4(0,0,0,0)/*end*/;
|
|
|
|
#ifdef _USE_SPLINE_VISIBILITY_FOR_MULTIPLE_SCATTERING
|
|
surfaceDescription.StrandShadowBias = /*ase_frag_out:Strand Shadow Bias;Float;44;-1;_StrandShadowBias*/0/*end*/;
|
|
#endif
|
|
|
|
GetSurfaceAndBuiltinData(surfaceDescription,input, V, posInput, surfaceData, builtinData);
|
|
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData);
|
|
LightTransportData lightTransportData = GetLightTransportData(surfaceData, builtinData, bsdfData);
|
|
|
|
float4 res = float4( 0.0, 0.0, 0.0, 1.0 );
|
|
UnityMetaInput metaInput;
|
|
metaInput.Albedo = lightTransportData.diffuseColor.rgb;
|
|
metaInput.Emission = lightTransportData.emissiveColor;
|
|
|
|
#ifdef EDITOR_VISUALIZATION
|
|
metaInput.VizUV = packedInput.VizUV;
|
|
metaInput.LightCoord = packedInput.LightCoord;
|
|
#endif
|
|
res = UnityMetaFragment(metaInput);
|
|
|
|
return res;
|
|
}
|
|
|
|
ENDHLSL
|
|
}
|
|
|
|
/*ase_pass*/
|
|
Pass
|
|
{
|
|
/*ase_hide_pass*/
|
|
Name "TransparentBackface"
|
|
Tags
|
|
{
|
|
"LightMode" = "TransparentBackface"
|
|
}
|
|
|
|
Blend [_SrcBlend] [_DstBlend], [_AlphaSrcBlend] [_AlphaDstBlend]
|
|
Blend 1 One OneMinusSrcAlpha
|
|
Blend 2 One OneMinusSrcAlpha
|
|
Blend 3 One OneMinusSrcAlpha
|
|
Blend 4 One OneMinusSrcAlpha
|
|
|
|
Cull Front
|
|
ZTest [_ZTestTransparent]
|
|
ZWrite [_ZWrite]
|
|
|
|
ColorMask [_ColorMaskTransparentVelOne] 1
|
|
ColorMask [_ColorMaskTransparentVelTwo] 2
|
|
|
|
HLSLPROGRAM
|
|
#pragma multi_compile _ DOTS_INSTANCING_ON
|
|
|
|
#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT
|
|
#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC _TRANSPARENT_REFRACTIVE_SORT
|
|
#pragma shader_feature_local_fragment _ _ENABLE_FOG_ON_TRANSPARENT
|
|
|
|
#pragma multi_compile_fragment _ SHADOWS_SHADOWMASK
|
|
#pragma multi_compile_fragment PUNCTUAL_SHADOW_LOW PUNCTUAL_SHADOW_MEDIUM PUNCTUAL_SHADOW_HIGH
|
|
#pragma multi_compile_fragment DIRECTIONAL_SHADOW_LOW DIRECTIONAL_SHADOW_MEDIUM DIRECTIONAL_SHADOW_HIGH
|
|
#pragma multi_compile_fragment AREA_SHADOW_MEDIUM AREA_SHADOW_HIGH
|
|
#pragma multi_compile_fragment _ PROBE_VOLUMES_L1 PROBE_VOLUMES_L2
|
|
#pragma multi_compile_fragment SCREEN_SPACE_SHADOWS_OFF SCREEN_SPACE_SHADOWS_ON
|
|
|
|
#pragma multi_compile _ DEBUG_DISPLAY
|
|
#pragma multi_compile _ LIGHTMAP_ON
|
|
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
|
|
#pragma multi_compile _ DYNAMICLIGHTMAP_ON
|
|
#pragma multi_compile_fragment DECALS_OFF DECALS_3RT DECALS_4RT
|
|
#pragma multi_compile_fragment _ DECAL_SURFACE_GRADIENT
|
|
#pragma multi_compile _ USE_LEGACY_LIGHTMAPS
|
|
|
|
#ifndef SHADER_STAGE_FRAGMENT
|
|
#define SHADOW_LOW
|
|
#define USE_FPTL_LIGHTLIST
|
|
#endif
|
|
|
|
//RayTracing
|
|
//#pragma shader_feature_local_raytracing _ _DISABLE_DECALS
|
|
//#pragma shader_feature_local_raytracing _ _DISABLE_SSR
|
|
//#pragma shader_feature_local_raytracing _ _DISABLE_SSR_TRANSPARENT
|
|
//#pragma multi_compile_raytracing PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2
|
|
//#pragma multi_compile_raytracing _ SHADOWS_SHADOWMASK
|
|
|
|
#if !defined(REMOVE_CLUSTERED_LIGHTLIST)
|
|
#define USE_CLUSTERED_LIGHTLIST
|
|
#endif
|
|
|
|
#pragma vertex Vert
|
|
#pragma fragment Frag
|
|
|
|
#define SHADERPASS SHADERPASS_FORWARD
|
|
#define HAS_LIGHTLOOP 1
|
|
#define USE_CLUSTERED_LIGHTLIST
|
|
#define _ABSORPTION_FROM_COLOR 1
|
|
#define SUPPORT_GLOBAL_MIP_BIAS 1
|
|
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl"
|
|
#include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl"
|
|
|
|
//#if !defined(SHADER_STAGE_RAY_TRACING) && SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER && SHADERPASS != SHADERPASS_FULL_SCREEN_DEBUG
|
|
//#define FRAG_INPUTS_ENABLE_STRIPPING
|
|
//#endif
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
|
|
|
|
#ifdef RAYTRACING_SHADER_GRAPH_DEFAULT
|
|
#define RAYTRACING_SHADER_GRAPH_HIGH
|
|
#endif
|
|
|
|
#ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED
|
|
#define RAYTRACING_SHADER_GRAPH_LOW
|
|
#endif
|
|
|
|
#ifndef SHADER_UNLIT
|
|
#if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE)
|
|
#define VARYINGS_NEED_CULLFACE
|
|
#endif
|
|
#endif
|
|
|
|
#if defined(_DOUBLESIDED_ON) && !defined(ASE_NEED_CULLFACE)
|
|
#define ASE_NEED_CULLFACE 1
|
|
#endif
|
|
|
|
#if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
|
|
#if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT)
|
|
#define WRITE_NORMAL_BUFFER
|
|
#endif
|
|
#endif
|
|
|
|
#if SHADERPASS == SHADERPASS_MOTION_VECTORS && defined(WRITE_DECAL_BUFFER_AND_RENDERING_LAYER)
|
|
#define WRITE_DECAL_BUFFER
|
|
#endif
|
|
|
|
#ifndef DEBUG_DISPLAY
|
|
#if !defined(_SURFACE_TYPE_TRANSPARENT)
|
|
#if SHADERPASS == SHADERPASS_FORWARD
|
|
#define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
|
|
#elif SHADERPASS == SHADERPASS_GBUFFER
|
|
#define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST
|
|
#endif
|
|
#endif
|
|
#endif
|
|
|
|
#if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT)
|
|
#define _DEFERRED_CAPABLE_MATERIAL
|
|
#endif
|
|
|
|
#if (defined(_TRANSPARENT_WRITES_MOTION_VEC) || defined(_TRANSPARENT_REFRACTIVE_SORT)) && defined(_SURFACE_TYPE_TRANSPARENT)
|
|
#define _WRITE_TRANSPARENT_MOTION_VECTOR
|
|
#endif
|
|
|
|
CBUFFER_START( UnityPerMaterial )
|
|
float4 _EmissionColor;
|
|
float _AlphaCutoff;
|
|
float _RenderQueueType;
|
|
#ifdef _ADD_PRECOMPUTED_VELOCITY
|
|
float _AddPrecomputedVelocity;
|
|
#endif
|
|
float _ExcludeFromTUAndAA;
|
|
float _StencilRef;
|
|
float _StencilWriteMask;
|
|
float _StencilRefDepth;
|
|
float _StencilWriteMaskDepth;
|
|
float _StencilRefMV;
|
|
float _StencilWriteMaskMV;
|
|
float _StencilRefDistortionVec;
|
|
float _StencilWriteMaskDistortionVec;
|
|
float _StencilWriteMaskGBuffer;
|
|
float _StencilRefGBuffer;
|
|
float _ZTestGBuffer;
|
|
float _RequireSplitLighting;
|
|
float _ReceivesSSR;
|
|
float _SurfaceType;
|
|
float _BlendMode;
|
|
#ifdef SUPPORT_BLENDMODE_PRESERVE_SPECULAR_LIGHTING
|
|
float _EnableBlendModePreserveSpecularLighting;
|
|
#endif
|
|
float _SrcBlend;
|
|
float _DstBlend;
|
|
float _DstBlend2;
|
|
float _AlphaSrcBlend;
|
|
float _AlphaDstBlend;
|
|
float _ZWrite;
|
|
float _TransparentZWrite;
|
|
float _CullMode;
|
|
float _TransparentSortPriority;
|
|
float _EnableFogOnTransparent;
|
|
float _CullModeForward;
|
|
float _TransparentCullMode;
|
|
float _ZTestDepthEqualForOpaque;
|
|
float _ZTestTransparent;
|
|
float _TransparentBackfaceEnable;
|
|
float _AlphaCutoffEnable;
|
|
float _UseShadowThreshold;
|
|
float _DoubleSidedEnable;
|
|
float _DoubleSidedNormalMode;
|
|
float4 _DoubleSidedConstants;
|
|
#ifdef ASE_TESSELLATION
|
|
float _TessPhongStrength;
|
|
float _TessValue;
|
|
float _TessMin;
|
|
float _TessMax;
|
|
float _TessEdgeLength;
|
|
float _TessMaxDisp;
|
|
#endif
|
|
UNITY_TEXTURE_STREAMING_DEBUG_VARS;
|
|
CBUFFER_END
|
|
|
|
#ifdef SCENEPICKINGPASS
|
|
float4 _SelectionID;
|
|
#endif
|
|
|
|
#ifdef SCENESELECTIONPASS
|
|
int _ObjectId;
|
|
int _PassValue;
|
|
#endif
|
|
|
|
/*ase_globals*/
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
|
|
#endif
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Hair/Hair.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl"
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl"
|
|
|
|
#ifdef HAVE_VFX_MODIFICATION
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/VisualEffectVertex.hlsl"
|
|
#endif
|
|
|
|
/*ase_pragma*/
|
|
|
|
struct AttributesMesh
|
|
{
|
|
float3 positionOS : POSITION;
|
|
float3 normalOS : NORMAL;
|
|
float4 tangentOS : TANGENT;
|
|
float4 uv1 : TEXCOORD1;
|
|
float4 uv2 : TEXCOORD2;
|
|
float3 previousPositionOS : TEXCOORD4;
|
|
float3 precomputedVelocity : TEXCOORD5;
|
|
/*ase_vdata:p=p;n=n;t=t;uv1=tc1;uv2=tc2;uv4=tc4;uv5=tc5*/
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
struct PackedVaryingsMeshToPS
|
|
{
|
|
SV_POSITION_QUALIFIERS float4 positionCS : SV_Position;
|
|
float3 positionRWS : TEXCOORD0;
|
|
float3 normalWS : TEXCOORD1;
|
|
float4 tangentWS : TEXCOORD2;
|
|
float4 uv1 : TEXCOORD3;
|
|
float4 uv2 : TEXCOORD4;
|
|
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
|
|
float3 vpassPositionCS : TEXCOORD5;
|
|
float3 vpassPreviousPositionCS : TEXCOORD6;
|
|
#endif
|
|
/*ase_interp(7,):sp=sp.xyzw;rwp=tc0;wn=tc1;wt=tc2;uv1=tc3;uv2=tc4*/
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
UNITY_VERTEX_OUTPUT_STEREO
|
|
#if defined(SHADER_STAGE_FRAGMENT) && defined(ASE_NEED_CULLFACE)
|
|
FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
|
|
#endif
|
|
};
|
|
|
|
/*ase_funcs*/
|
|
|
|
//Build Surface Data (Decal)
|
|
void ApplyDecalToSurfaceDataNoNormal(DecalSurfaceData decalSurfaceData, inout SurfaceData surfaceData)
|
|
{
|
|
surfaceData.diffuseColor.xyz = surfaceData.diffuseColor.xyz * decalSurfaceData.baseColor.w + decalSurfaceData.baseColor.xyz;
|
|
|
|
#ifdef DECALS_4RT
|
|
surfaceData.ambientOcclusion = surfaceData.ambientOcclusion * decalSurfaceData.MAOSBlend.y + decalSurfaceData.mask.y;
|
|
#endif
|
|
|
|
surfaceData.perceptualSmoothness = surfaceData.perceptualSmoothness * decalSurfaceData.mask.w + decalSurfaceData.mask.z;
|
|
}
|
|
|
|
void BuildSurfaceData(FragInputs fragInputs, inout GlobalSurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS)
|
|
{
|
|
ZERO_INITIALIZE(SurfaceData, surfaceData);
|
|
|
|
surfaceData.specularOcclusion = 1.0;
|
|
|
|
surfaceData.diffuseColor = surfaceDescription.BaseColor;
|
|
surfaceData.perceptualSmoothness = surfaceDescription.Smoothness;
|
|
surfaceData.ambientOcclusion = surfaceDescription.Occlusion;
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_KAJIYA_KAY
|
|
surfaceData.transmittance = surfaceDescription.Transmittance;
|
|
surfaceData.rimTransmissionIntensity = surfaceDescription.RimTransmissionIntensity;
|
|
surfaceData.specularTint = surfaceDescription.SpecularTint;
|
|
surfaceData.specularShift = surfaceDescription.SpecularShift;
|
|
surfaceData.secondaryPerceptualSmoothness = surfaceDescription.SecondarySmoothness;
|
|
surfaceData.secondarySpecularTint = surfaceDescription.SecondarySpecularTint;
|
|
surfaceData.secondarySpecularShift = surfaceDescription.SecondarySpecularShift;
|
|
#endif
|
|
|
|
//#ifdef _MATERIAL_FEATURE_HAIR_MARSCHNER
|
|
surfaceData.perceptualRadialSmoothness = surfaceDescription.RadialSmoothness;
|
|
surfaceData.cuticleAngle = surfaceDescription.CuticleAngle;
|
|
//#endif
|
|
|
|
|
|
surfaceData.strandCountProbe = surfaceDescription.StrandCountProbe;
|
|
#ifdef _USE_SPLINE_VISIBILITY_FOR_MULTIPLE_SCATTERING
|
|
surfaceData.strandShadowBias = surfaceDescription.StrandShadowBias;
|
|
#endif
|
|
|
|
#ifdef _SPECULAR_OCCLUSION_CUSTOM
|
|
surfaceData.specularOcclusion = surfaceDescription.SpecularOcclusion;
|
|
#endif
|
|
|
|
surfaceData.materialFeatures = 0;
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_KAJIYA_KAY
|
|
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_HAIR_KAJIYA_KAY;
|
|
#endif
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_MARSCHNER
|
|
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_HAIR_MARSCHNER;
|
|
#endif
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_MARSCHNER_CINEMATIC
|
|
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_HAIR_MARSCHNER_CINEMATIC;
|
|
#endif
|
|
|
|
#ifdef _DOUBLESIDED_ON
|
|
float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
|
|
#else
|
|
float3 doubleSidedConstants = float3( 1.0, 1.0, 1.0 );
|
|
#endif
|
|
|
|
float3 normalTS = float3(0.0f, 0.0f, 1.0f);
|
|
normalTS = surfaceDescription.Normal;
|
|
|
|
#ifdef DECAL_NORMAL_BLENDING
|
|
normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]);
|
|
|
|
#if HAVE_DECALS
|
|
if (_EnableDecals)
|
|
{
|
|
float alpha = 1.0;
|
|
alpha = surfaceDescription.Alpha;
|
|
|
|
DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
|
|
ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS);
|
|
ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData);
|
|
}
|
|
#endif
|
|
|
|
GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants);
|
|
#else
|
|
GetNormalWS(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants);
|
|
|
|
#if HAVE_DECALS
|
|
if (_EnableDecals)
|
|
{
|
|
float alpha = 1.0;
|
|
alpha = surfaceDescription.Alpha;
|
|
|
|
DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
|
|
ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz);
|
|
ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData);
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];
|
|
surfaceData.hairStrandDirectionWS = -fragInputs.tangentToWorld[1].xyz;
|
|
surfaceData.hairStrandDirectionWS = normalize(surfaceData.hairStrandDirectionWS);
|
|
|
|
#ifdef ASE_HAIRDIRECTION
|
|
surfaceData.hairStrandDirectionWS = TransformTangentToWorld(surfaceDescription.HairStrandDirection, fragInputs.tangentToWorld);
|
|
#endif
|
|
|
|
#if (_USE_LIGHT_FACING_NORMAL)
|
|
float3 viewFacingNormalWS = ComputeViewFacingNormal(V, surfaceData.hairStrandDirectionWS);
|
|
float3 N = viewFacingNormalWS;
|
|
#else
|
|
float3 N = surfaceData.normalWS;
|
|
#endif
|
|
|
|
bentNormalWS = surfaceData.normalWS;
|
|
|
|
#ifdef ASE_BENT_NORMAL
|
|
GetNormalWS( fragInputs, surfaceDescription.BentNormal, bentNormalWS, doubleSidedConstants );
|
|
#endif
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
#if !defined(SHADER_STAGE_RAY_TRACING)
|
|
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
|
|
{
|
|
#ifdef FRAG_INPUTS_USE_TEXCOORD0
|
|
surfaceData.diffuseColor = GET_TEXTURE_STREAMING_DEBUG(posInput.positionSS, fragInputs.texCoord0);
|
|
#else
|
|
surfaceData.diffuseColor = GET_TEXTURE_STREAMING_DEBUG_NO_UV(posInput.positionSS);
|
|
#endif
|
|
}
|
|
#endif
|
|
ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData);
|
|
#endif
|
|
|
|
#if defined(_SPECULAR_OCCLUSION_CUSTOM)
|
|
#elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL)
|
|
surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness));
|
|
#elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO)
|
|
surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness));
|
|
#endif
|
|
|
|
#ifdef _ENABLE_GEOMETRIC_SPECULAR_AA
|
|
surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold);
|
|
#endif
|
|
}
|
|
|
|
// Get Surface And BuiltinData
|
|
void GetSurfaceAndBuiltinData(GlobalSurfaceDescription surfaceDescription, FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData)
|
|
{
|
|
#ifdef LOD_FADE_CROSSFADE
|
|
LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x);
|
|
#endif
|
|
|
|
#ifdef _DOUBLESIDED_ON
|
|
float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
|
|
#else
|
|
float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
|
|
#endif
|
|
ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants);
|
|
|
|
#ifdef _ALPHATEST_ON
|
|
DoAlphaTest( surfaceDescription.Alpha, surfaceDescription.AlphaClipThreshold );
|
|
#endif
|
|
|
|
#ifdef _ALPHATEST_SHADOW_ON
|
|
DoAlphaTest( surfaceDescription.Alpha, surfaceDescription.AlphaClipThresholdShadow);
|
|
#endif
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput);
|
|
#endif
|
|
|
|
float3 bentNormalWS;
|
|
BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS);
|
|
InitBuiltinData(posInput, surfaceDescription.Alpha, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData);
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
builtinData.depthOffset = surfaceDescription.DepthOffset;
|
|
#endif
|
|
|
|
#ifdef _ALPHATEST_ON
|
|
builtinData.alphaClipTreshold = surfaceDescription.AlphaClipThreshold;
|
|
#endif
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
|
|
{
|
|
surfaceDescription.Alpha = 1.0f;
|
|
}
|
|
#endif
|
|
|
|
#ifdef UNITY_VIRTUAL_TEXTURING
|
|
builtinData.vtPackedFeedback = surfaceDescription.VTPackedFeedback;
|
|
#endif
|
|
|
|
#ifdef ASE_BAKEDGI
|
|
builtinData.bakeDiffuseLighting = surfaceDescription.BakedGI;
|
|
#endif
|
|
|
|
#ifdef ASE_BAKEDBACKGI
|
|
builtinData.backBakeDiffuseLighting = surfaceDescription.BakedBackGI;
|
|
#endif
|
|
|
|
builtinData.emissiveColor = surfaceDescription.Emission;
|
|
|
|
PostInitBuiltinData(V, posInput, surfaceData, builtinData);
|
|
}
|
|
|
|
AttributesMesh ApplyMeshModification(AttributesMesh inputMesh, float3 timeParameters, inout PackedVaryingsMeshToPS outputPackedVaryingsMeshToPS/*ase_vert_input*/ )
|
|
{
|
|
_TimeParameters.xyz = timeParameters;
|
|
/*ase_vert_code:inputMesh=AttributesMesh;outputPackedVaryingsMeshToPS=PackedVaryingsMeshToPS*/
|
|
|
|
#ifdef ASE_ABSOLUTE_VERTEX_POS
|
|
float3 defaultVertexValue = inputMesh.positionOS.xyz;
|
|
#else
|
|
float3 defaultVertexValue = float3( 0, 0, 0 );
|
|
#endif
|
|
float3 vertexValue = /*ase_vert_out:Vertex Offset;Float3;22;-1;_VertexOffset*/defaultVertexValue/*end*/;
|
|
|
|
#ifdef ASE_ABSOLUTE_VERTEX_POS
|
|
inputMesh.positionOS.xyz = vertexValue;
|
|
#else
|
|
inputMesh.positionOS.xyz += vertexValue;
|
|
#endif
|
|
inputMesh.normalOS = /*ase_vert_out:Vertex Normal;Float3;23;-1;_VertexNormal*/inputMesh.normalOS/*end*/;
|
|
inputMesh.tangentOS = /*ase_vert_out:Vertex Tangent;Float4;24;-1;_VertexTangent*/inputMesh.tangentOS/*end*/;
|
|
return inputMesh;
|
|
}
|
|
|
|
PackedVaryingsMeshToPS VertexFunction(AttributesMesh inputMesh)
|
|
{
|
|
PackedVaryingsMeshToPS outputPackedVaryingsMeshToPS = (PackedVaryingsMeshToPS)0;
|
|
AttributesMesh defaultMesh = inputMesh;
|
|
|
|
UNITY_SETUP_INSTANCE_ID(inputMesh);
|
|
UNITY_TRANSFER_INSTANCE_ID(inputMesh, outputPackedVaryingsMeshToPS);
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO( outputPackedVaryingsMeshToPS );
|
|
|
|
inputMesh = ApplyMeshModification( inputMesh, _TimeParameters.xyz, outputPackedVaryingsMeshToPS);
|
|
|
|
float3 positionRWS = TransformObjectToWorld(inputMesh.positionOS);
|
|
float3 normalWS = TransformObjectToWorldNormal(inputMesh.normalOS);
|
|
float4 tangentWS = float4(TransformObjectToWorldDir(inputMesh.tangentOS.xyz), inputMesh.tangentOS.w);
|
|
|
|
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
|
|
float4 VPASSpreviousPositionCS;
|
|
float4 VPASSpositionCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(positionRWS, 1.0));
|
|
|
|
bool forceNoMotion = unity_MotionVectorsParams.y == 0.0;
|
|
if (forceNoMotion)
|
|
{
|
|
VPASSpreviousPositionCS = float4(0.0, 0.0, 0.0, 1.0);
|
|
}
|
|
else
|
|
{
|
|
bool hasDeformation = unity_MotionVectorsParams.x > 0.0;
|
|
float3 effectivePositionOS = (hasDeformation ? inputMesh.previousPositionOS : defaultMesh.positionOS);
|
|
#if defined(_ADD_PRECOMPUTED_VELOCITY)
|
|
effectivePositionOS -= inputMesh.precomputedVelocity;
|
|
#endif
|
|
|
|
#if defined(HAVE_MESH_MODIFICATION)
|
|
AttributesMesh previousMesh = defaultMesh;
|
|
previousMesh.positionOS = effectivePositionOS ;
|
|
PackedVaryingsMeshToPS test = (PackedVaryingsMeshToPS)0;
|
|
float3 curTime = _TimeParameters.xyz;
|
|
previousMesh = ApplyMeshModification(previousMesh, _LastTimeParameters.xyz, test);
|
|
_TimeParameters.xyz = curTime;
|
|
float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.positionOS);
|
|
#else
|
|
float3 previousPositionRWS = TransformPreviousObjectToWorld(effectivePositionOS);
|
|
#endif
|
|
|
|
#ifdef ATTRIBUTES_NEED_NORMAL
|
|
float3 normalWS = TransformPreviousObjectToWorldNormal(defaultMesh.normalOS);
|
|
#else
|
|
float3 normalWS = float3(0.0, 0.0, 0.0);
|
|
#endif
|
|
|
|
#if defined(HAVE_VERTEX_MODIFICATION)
|
|
ApplyVertexModification(inputMesh, normalWS, previousPositionRWS, _LastTimeParameters.xyz);
|
|
#endif
|
|
|
|
VPASSpreviousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0));
|
|
}
|
|
#endif
|
|
|
|
outputPackedVaryingsMeshToPS.positionCS = TransformWorldToHClip(positionRWS);
|
|
outputPackedVaryingsMeshToPS.positionRWS.xyz = positionRWS;
|
|
outputPackedVaryingsMeshToPS.normalWS.xyz = normalWS;
|
|
outputPackedVaryingsMeshToPS.tangentWS.xyzw = tangentWS;
|
|
outputPackedVaryingsMeshToPS.uv1.xyzw = inputMesh.uv1;
|
|
outputPackedVaryingsMeshToPS.uv2.xyzw = inputMesh.uv2;
|
|
|
|
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
|
|
outputPackedVaryingsMeshToPS.vpassPositionCS = float3(VPASSpositionCS.xyw);
|
|
outputPackedVaryingsMeshToPS.vpassPreviousPositionCS = float3(VPASSpreviousPositionCS.xyw);
|
|
#endif
|
|
return outputPackedVaryingsMeshToPS;
|
|
}
|
|
|
|
#if defined(ASE_TESSELLATION)
|
|
struct VertexControl
|
|
{
|
|
float3 positionOS : INTERNALTESSPOS;
|
|
float3 normalOS : NORMAL;
|
|
float4 tangentOS : TANGENT;
|
|
float4 uv1 : TEXCOORD1;
|
|
float4 uv2 : TEXCOORD2;
|
|
/*ase_vcontrol*/
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
struct TessellationFactors
|
|
{
|
|
float edge[3] : SV_TessFactor;
|
|
float inside : SV_InsideTessFactor;
|
|
};
|
|
|
|
VertexControl Vert ( AttributesMesh v )
|
|
{
|
|
VertexControl o;
|
|
UNITY_SETUP_INSTANCE_ID(v);
|
|
UNITY_TRANSFER_INSTANCE_ID(v, o);
|
|
o.positionOS = v.positionOS;
|
|
o.normalOS = v.normalOS;
|
|
o.tangentOS = v.tangentOS;
|
|
o.uv1 = v.uv1;
|
|
o.uv2 = v.uv2;
|
|
/*ase_control_code:v=AttributesMesh;o=VertexControl*/
|
|
return o;
|
|
}
|
|
|
|
TessellationFactors TessellationFunction (InputPatch<VertexControl,3> v)
|
|
{
|
|
TessellationFactors o;
|
|
float4 tf = 1;
|
|
float tessValue = /*ase_inline_begin*/_TessValue/*ase_inline_end*/; float tessMin = /*ase_inline_begin*/_TessMin/*ase_inline_end*/; float tessMax = /*ase_inline_begin*/_TessMax/*ase_inline_end*/;
|
|
float edgeLength = /*ase_inline_begin*/_TessEdgeLength/*ase_inline_end*/; float tessMaxDisp = /*ase_inline_begin*/_TessMaxDisp/*ase_inline_end*/;
|
|
#if (SHADEROPTIONS_CAMERA_RELATIVE_RENDERING != 0)
|
|
float3 cameraPos = 0;
|
|
#else
|
|
float3 cameraPos = _WorldSpaceCameraPos;
|
|
#endif
|
|
#if defined(ASE_FIXED_TESSELLATION)
|
|
tf = FixedTess( tessValue );
|
|
#elif defined(ASE_DISTANCE_TESSELLATION)
|
|
tf = DistanceBasedTess(float4(v[0].positionOS,1), float4(v[1].positionOS,1), float4(v[2].positionOS,1), tessValue, tessMin, tessMax, GetObjectToWorldMatrix(), cameraPos );
|
|
#elif defined(ASE_LENGTH_TESSELLATION)
|
|
tf = EdgeLengthBasedTess(float4(v[0].positionOS,1), float4(v[1].positionOS,1), float4(v[2].positionOS,1), edgeLength, GetObjectToWorldMatrix(), cameraPos, _ScreenParams );
|
|
#elif defined(ASE_LENGTH_CULL_TESSELLATION)
|
|
tf = EdgeLengthBasedTessCull(float4(v[0].positionOS,1), float4(v[1].positionOS,1), float4(v[2].positionOS,1), edgeLength, tessMaxDisp, GetObjectToWorldMatrix(), cameraPos, _ScreenParams, _FrustumPlanes );
|
|
#endif
|
|
o.edge[0] = tf.x; o.edge[1] = tf.y; o.edge[2] = tf.z; o.inside = tf.w;
|
|
return o;
|
|
}
|
|
|
|
[domain("tri")]
|
|
[partitioning("fractional_odd")]
|
|
[outputtopology("triangle_cw")]
|
|
[patchconstantfunc("TessellationFunction")]
|
|
[outputcontrolpoints(3)]
|
|
VertexControl HullFunction(InputPatch<VertexControl, 3> patch, uint id : SV_OutputControlPointID)
|
|
{
|
|
return patch[id];
|
|
}
|
|
|
|
[domain("tri")]
|
|
PackedVaryingsMeshToPS DomainFunction(TessellationFactors factors, OutputPatch<VertexControl, 3> patch, float3 bary : SV_DomainLocation)
|
|
{
|
|
AttributesMesh o = (AttributesMesh) 0;
|
|
o.positionOS = patch[0].positionOS * bary.x + patch[1].positionOS * bary.y + patch[2].positionOS * bary.z;
|
|
o.normalOS = patch[0].normalOS * bary.x + patch[1].normalOS * bary.y + patch[2].normalOS * bary.z;
|
|
o.tangentOS = patch[0].tangentOS * bary.x + patch[1].tangentOS * bary.y + patch[2].tangentOS * bary.z;
|
|
o.uv1 = patch[0].uv1 * bary.x + patch[1].uv1 * bary.y + patch[2].uv1 * bary.z;
|
|
o.uv2 = patch[0].uv2 * bary.x + patch[1].uv2 * bary.y + patch[2].uv2 * bary.z;
|
|
/*ase_domain_code:patch=VertexControl;o=AttributesMesh;bary=SV_DomainLocation*/
|
|
#if defined(ASE_PHONG_TESSELLATION)
|
|
float3 pp[3];
|
|
for (int i = 0; i < 3; ++i)
|
|
pp[i] = o.positionOS.xyz - patch[i].normalOS * (dot(o.positionOS.xyz, patch[i].normalOS) - dot(patch[i].positionOS.xyz, patch[i].normalOS));
|
|
float phongStrength = /*ase_inline_begin*/_TessPhongStrength/*ase_inline_end*/;
|
|
o.positionOS.xyz = phongStrength * (pp[0]*bary.x + pp[1]*bary.y + pp[2]*bary.z) + (1.0f-phongStrength) * o.positionOS.xyz;
|
|
#endif
|
|
UNITY_TRANSFER_INSTANCE_ID(patch[0], o);
|
|
return VertexFunction(o);
|
|
}
|
|
#else
|
|
PackedVaryingsMeshToPS Vert ( AttributesMesh v )
|
|
{
|
|
return VertexFunction( v );
|
|
}
|
|
#endif
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplayMaterial.hlsl"
|
|
|
|
#if defined(_TRANSPARENT_REFRACTIVE_SORT) || defined(_ENABLE_FOG_ON_TRANSPARENT)
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Water/Shaders/UnderWaterUtilities.hlsl"
|
|
#endif
|
|
|
|
#ifdef UNITY_VIRTUAL_TEXTURING
|
|
#ifdef OUTPUT_SPLIT_LIGHTING
|
|
#define DIFFUSE_LIGHTING_TARGET SV_Target2
|
|
#define SSS_BUFFER_TARGET SV_Target3
|
|
#elif defined(_WRITE_TRANSPARENT_MOTION_VECTOR)
|
|
#define MOTION_VECTOR_TARGET SV_Target2
|
|
#ifdef _TRANSPARENT_REFRACTIVE_SORT
|
|
#define BEFORE_REFRACTION_TARGET SV_Target3
|
|
#define BEFORE_REFRACTION_ALPHA_TARGET SV_Target4
|
|
#endif
|
|
#endif
|
|
#if defined(SHADER_API_PSSL)
|
|
#pragma PSSL_target_output_format(target 1 FMT_32_ABGR)
|
|
#endif
|
|
#else
|
|
#ifdef OUTPUT_SPLIT_LIGHTING
|
|
#define DIFFUSE_LIGHTING_TARGET SV_Target1
|
|
#define SSS_BUFFER_TARGET SV_Target2
|
|
#elif defined(_WRITE_TRANSPARENT_MOTION_VECTOR)
|
|
#define MOTION_VECTOR_TARGET SV_Target1
|
|
#ifdef _TRANSPARENT_REFRACTIVE_SORT
|
|
#define BEFORE_REFRACTION_TARGET SV_Target2
|
|
#define BEFORE_REFRACTION_ALPHA_TARGET SV_Target3
|
|
#endif
|
|
#endif
|
|
#endif
|
|
|
|
void Frag(PackedVaryingsMeshToPS packedInput
|
|
, out float4 outColor:SV_Target0
|
|
#ifdef UNITY_VIRTUAL_TEXTURING
|
|
, out float4 outVTFeedback : SV_Target1
|
|
#endif
|
|
#ifdef OUTPUT_SPLIT_LIGHTING
|
|
, out float4 outDiffuseLighting : DIFFUSE_LIGHTING_TARGET
|
|
, OUTPUT_SSSBUFFER(outSSSBuffer) : SSS_BUFFER_TARGET
|
|
#elif defined(_WRITE_TRANSPARENT_MOTION_VECTOR)
|
|
, out float4 outMotionVec : MOTION_VECTOR_TARGET
|
|
#ifdef _TRANSPARENT_REFRACTIVE_SORT
|
|
, out float4 outBeforeRefractionColor : BEFORE_REFRACTION_TARGET
|
|
, out float4 outBeforeRefractionAlpha : BEFORE_REFRACTION_ALPHA_TARGET
|
|
#endif
|
|
#endif
|
|
#ifdef _DEPTHOFFSET_ON
|
|
, out float outputDepth : DEPTH_OFFSET_SEMANTIC
|
|
#endif
|
|
/*ase_frag_input*/
|
|
)
|
|
{
|
|
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
|
|
outMotionVec = float4(2.0, 0.0, 0.0, 1.0);
|
|
#endif
|
|
|
|
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX( packedInput );
|
|
UNITY_SETUP_INSTANCE_ID( packedInput );
|
|
/*ase_local_var:rwp*/float3 positionRWS = packedInput.positionRWS.xyz;
|
|
/*ase_local_var:wn*/float3 normalWS = packedInput.normalWS.xyz;
|
|
/*ase_local_var:wt*/float4 tangentWS = packedInput.tangentWS.xyzw;
|
|
|
|
FragInputs input;
|
|
ZERO_INITIALIZE(FragInputs, input);
|
|
input.tangentToWorld = k_identity3x3;
|
|
input.positionSS = packedInput.positionCS;
|
|
input.positionRWS = positionRWS;
|
|
input.tangentToWorld = BuildTangentToWorld(tangentWS, normalWS);
|
|
input.texCoord1 = packedInput.uv1.xyzw;
|
|
input.texCoord2 = packedInput.uv2.xyzw;
|
|
|
|
#if _DOUBLESIDED_ON && SHADER_STAGE_FRAGMENT
|
|
input.isFrontFace = IS_FRONT_VFACE( packedInput.cullFace, true, false);
|
|
#elif SHADER_STAGE_FRAGMENT
|
|
#if defined(ASE_NEED_CULLFACE)
|
|
input.isFrontFace = IS_FRONT_VFACE(packedInput.cullFace, true, false);
|
|
#endif
|
|
#endif
|
|
/*ase_local_var:vf*/half isFrontFace = input.isFrontFace;
|
|
|
|
AdjustFragInputsToOffScreenRendering(input, _OffScreenRendering > 0, _OffScreenDownsampleFactor);
|
|
uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize ();
|
|
|
|
PositionInputs posInput = GetPositionInput( input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex );
|
|
|
|
/*ase_local_var:wvd*/float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
|
|
|
|
GlobalSurfaceDescription surfaceDescription = (GlobalSurfaceDescription)0;
|
|
/*ase_frag_code:packedInput=PackedVaryingsMeshToPS*/
|
|
surfaceDescription.BaseColor = /*ase_frag_out:Base Color;Float3;0;-1;_BaseColor*/float3( 0.7353569, 0.7353569, 0.7353569 )/*end*/;
|
|
surfaceDescription.Normal = /*ase_frag_out:Normal;Float3;1;-1;_Normal*/float3( 0, 0, 1 )/*end*/;
|
|
surfaceDescription.BentNormal = /*ase_frag_out:Bent Normal;Float3;2;-1;_BentNormal*/float3( 0, 0, 1 )/*end*/;
|
|
surfaceDescription.HairStrandDirection = /*ase_frag_out:Hair Strand Direction;Float3;7;-1;_HairStrandDirection*/float3(0,-1,0)/*end*/;
|
|
surfaceDescription.Emission = /*ase_frag_out:Emission;Float3;45;-1;_Emission*/float3(0,0,0)/*end*/;
|
|
surfaceDescription.Smoothness = /*ase_frag_out:Smoothness;Float;3;-1;_Smoothness*/0.5/*end*/;
|
|
surfaceDescription.Occlusion = /*ase_frag_out:Occlusion;Float;4;-1;_Occlusion*/1/*end*/;
|
|
|
|
surfaceDescription.Alpha = /*ase_frag_out:Alpha;Float;8;-1;_Alpha*/1/*end*/;
|
|
|
|
#ifdef _ALPHATEST_ON
|
|
surfaceDescription.AlphaClipThreshold = /*ase_frag_out:Alpha Clip Threshold;Float;9;-1;_AlphaClip*/_AlphaCutoff/*end*/;
|
|
#endif
|
|
|
|
#ifdef _ALPHATEST_SHADOW_ON
|
|
surfaceDescription.AlphaClipThresholdShadow = /*ase_frag_out:Alpha Clip Threshold Shadow;Float;10;-1;_AlphaClipShadow*/0.5/*end*/;
|
|
#endif
|
|
|
|
surfaceDescription.AlphaClipThresholdDepthPrepass = /*ase_frag_out:Alpha Clip Threshold Depth Prepass;Float;11;-1;_AlphaClipDepthPrepass*/0.5/*end*/;
|
|
surfaceDescription.AlphaClipThresholdDepthPostpass = /*ase_frag_out:Alpha Clip Threshold Depth Postpass;Float;12;-1;_AlphaClipDepthPostpass*/0.5/*end*/;
|
|
|
|
#ifdef _SPECULAR_OCCLUSION_CUSTOM
|
|
surfaceDescription.SpecularOcclusion = /*ase_frag_out:Specular Occlusion;Float;13;-1;_SpecularOcclusion*/1/*end*/;
|
|
#endif
|
|
|
|
#ifdef _ENABLE_GEOMETRIC_SPECULAR_AA
|
|
surfaceDescription.SpecularAAScreenSpaceVariance = /*ase_frag_out:Specular AA Screen Space Variance;Float;14;-1;_SpecularAAScreenSpaceVariance*/0.1/*end*/;
|
|
surfaceDescription.SpecularAAThreshold = /*ase_frag_out:Specular AA Threshold;Float;15;-1;_SpecularAAThreshold*/0.2/*end*/;
|
|
#endif
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_KAJIYA_KAY
|
|
surfaceDescription.Transmittance = /*ase_frag_out:Transmittance;Float3;5;-1;_Transmittance*/float3(0.3,0.195,0.09)/*end*/;
|
|
surfaceDescription.RimTransmissionIntensity = /*ase_frag_out:Rim Transmission Intensity;Float;6;-1;_RimTransmissionIntensity*/0.2/*end*/;
|
|
surfaceDescription.SpecularTint = /*ase_frag_out:Specular Tint;Float3;16;-1;_SpecularTint*/float3(1,1,1)/*end*/;
|
|
surfaceDescription.SpecularShift = /*ase_frag_out:Specular Shift;Float;17;-1;_SpecularShift*/0.1/*end*/;
|
|
surfaceDescription.SecondarySpecularTint = /*ase_frag_out:Secondary Specular Tint;Float3;18;-1;_SecondarySpecularTint*/float3(0.5,0.5,0.5)/*end*/;
|
|
surfaceDescription.SecondarySmoothness = /*ase_frag_out:Secondary Smoothness;Float;19;-1;_SecondarySmoothness*/0.5/*end*/;
|
|
surfaceDescription.SecondarySpecularShift = /*ase_frag_out:Secondary Specular Shift;Float;20;-1;_SecondarySpecularShift*/-0.1/*end*/;
|
|
#endif
|
|
|
|
//#ifdef _MATERIAL_FEATURE_HAIR_MARSCHNER
|
|
surfaceDescription.RadialSmoothness = /*ase_frag_out:Radial Smoothness;Float;41;-1;_RadialSmoothness*/0.7/*end*/;
|
|
surfaceDescription.CuticleAngle = /*ase_frag_out:Cuticle Angle Shift;Float;42;-1;_CuticleAngle*/-0.1/*end*/;
|
|
//#endif
|
|
|
|
surfaceDescription.StrandCountProbe = /*ase_frag_out:Strand Count Probe;Float4;43;-1;_StrandCountProbe*/float4(0,0,0,0)/*end*/;
|
|
|
|
#ifdef _USE_SPLINE_VISIBILITY_FOR_MULTIPLE_SCATTERING
|
|
surfaceDescription.StrandShadowBias = /*ase_frag_out:Strand Shadow Bias;Float;44;-1;_StrandShadowBias*/0/*end*/;
|
|
#endif
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
surfaceDescription.DepthOffset = /*ase_frag_out:Depth Offset;Float;21;-1;_DepthOffset*/0/*end*/;
|
|
#endif
|
|
|
|
#ifdef UNITY_VIRTUAL_TEXTURING
|
|
surfaceDescription.VTPackedFeedback = float4(1.0f,1.0f,1.0f,1.0f);
|
|
#endif
|
|
|
|
SurfaceData surfaceData;
|
|
BuiltinData builtinData;
|
|
GetSurfaceAndBuiltinData(surfaceDescription,input, V, posInput, surfaceData, builtinData);
|
|
|
|
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData);
|
|
|
|
PreLightData preLightData = GetPreLightData(V, posInput, bsdfData);
|
|
|
|
outColor = float4(0.0, 0.0, 0.0, 0.0);
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
#ifdef OUTPUT_SPLIT_LIGHTING
|
|
outDiffuseLighting = float4(0, 0, 0, 1);
|
|
ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer);
|
|
#endif
|
|
|
|
bool viewMaterial = GetMaterialDebugColor(outColor, input, builtinData, posInput, surfaceData, bsdfData);
|
|
|
|
if (!viewMaterial)
|
|
{
|
|
if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_DIFFUSE_COLOR || _DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_SPECULAR_COLOR)
|
|
{
|
|
float3 result = float3(0.0, 0.0, 0.0);
|
|
GetPBRValidatorDebug(surfaceData, result);
|
|
outColor = float4(result, 1.0f);
|
|
}
|
|
else if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_TRANSPARENCY_OVERDRAW)
|
|
{
|
|
float4 result = _DebugTransparencyOverdrawWeight * float4(TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_A);
|
|
outColor = result;
|
|
}
|
|
else
|
|
#endif
|
|
{
|
|
#ifdef _SURFACE_TYPE_TRANSPARENT
|
|
uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_TRANSPARENT;
|
|
#else
|
|
uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_OPAQUE;
|
|
#endif
|
|
LightLoopOutput lightLoopOutput;
|
|
LightLoop(V, posInput, preLightData, bsdfData, builtinData, featureFlags, lightLoopOutput);
|
|
|
|
// Alias
|
|
float3 diffuseLighting = lightLoopOutput.diffuseLighting;
|
|
float3 specularLighting = lightLoopOutput.specularLighting;
|
|
|
|
diffuseLighting *= GetCurrentExposureMultiplier();
|
|
specularLighting *= GetCurrentExposureMultiplier();
|
|
|
|
#ifdef OUTPUT_SPLIT_LIGHTING
|
|
if (_EnableSubsurfaceScattering != 0 && ShouldOutputSplitLighting(bsdfData))
|
|
{
|
|
outColor = float4(specularLighting, 1.0);
|
|
outDiffuseLighting = float4(TagLightingForSSS(diffuseLighting), 1.0);
|
|
}
|
|
else
|
|
{
|
|
outColor = float4(diffuseLighting + specularLighting, 1.0);
|
|
outDiffuseLighting = float4(0, 0, 0, 1);
|
|
}
|
|
ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer);
|
|
#else
|
|
outColor = ApplyBlendMode(diffuseLighting, specularLighting, builtinData.opacity);
|
|
|
|
#ifdef _ENABLE_FOG_ON_TRANSPARENT
|
|
outColor = EvaluateAtmosphericScattering(posInput, V, outColor);
|
|
#endif
|
|
|
|
#ifdef _TRANSPARENT_REFRACTIVE_SORT
|
|
ComputeRefractionSplitColor(posInput, outColor, outBeforeRefractionColor, outBeforeRefractionAlpha);
|
|
#endif
|
|
#endif
|
|
|
|
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
|
|
float4 VPASSpositionCS = float4(packedInput.vpassPositionCS.xy, 0.0, packedInput.vpassPositionCS.z);
|
|
float4 VPASSpreviousPositionCS = float4(packedInput.vpassPreviousPositionCS.xy, 0.0, packedInput.vpassPreviousPositionCS.z);
|
|
bool forceNoMotion = any(unity_MotionVectorsParams.yw == 0.0);
|
|
#if defined(HAVE_VFX_MODIFICATION) && !VFX_FEATURE_MOTION_VECTORS
|
|
forceNoMotion = true;
|
|
#endif
|
|
if (!forceNoMotion)
|
|
{
|
|
float2 motionVec = CalculateMotionVector(VPASSpositionCS, VPASSpreviousPositionCS);
|
|
EncodeMotionVector(motionVec * 0.5, outMotionVec);
|
|
outMotionVec.zw = 1.0;
|
|
}
|
|
#endif
|
|
}
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
}
|
|
#endif
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
outputDepth = posInput.deviceDepth;
|
|
#endif
|
|
|
|
#ifdef UNITY_VIRTUAL_TEXTURING
|
|
float vtAlphaValue = builtinData.opacity;
|
|
#if defined(HAS_REFRACTION) && HAS_REFRACTION
|
|
vtAlphaValue = 1.0f - bsdfData.transmittanceMask;
|
|
#endif
|
|
outVTFeedback = PackVTFeedbackWithAlpha(builtinData.vtPackedFeedback, input.positionSS.xy, vtAlphaValue);
|
|
outVTFeedback.rgb *= outVTFeedback.a; // premuliplied alpha
|
|
#endif
|
|
|
|
}
|
|
ENDHLSL
|
|
}
|
|
|
|
/*ase_pass*/
|
|
Pass
|
|
{
|
|
/*ase_hide_pass*/
|
|
Name "TransparentDepthPrepass"
|
|
Tags
|
|
{
|
|
"LightMode" = "TransparentDepthPrepass"
|
|
}
|
|
|
|
Cull [_CullMode]
|
|
Blend One Zero
|
|
ZWrite On
|
|
|
|
Stencil
|
|
{
|
|
WriteMask [_StencilWriteMaskDepth]
|
|
Ref [_StencilRefDepth]
|
|
CompFront Always
|
|
PassFront Replace
|
|
CompBack Always
|
|
PassBack Replace
|
|
}
|
|
|
|
HLSLPROGRAM
|
|
#pragma multi_compile _ DOTS_INSTANCING_ON
|
|
|
|
#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT
|
|
#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC _TRANSPARENT_REFRACTIVE_SORT
|
|
#pragma shader_feature_local_fragment _ _ENABLE_FOG_ON_TRANSPARENT
|
|
|
|
//RayTracing
|
|
//#pragma shader_feature_local_raytracing _ _DISABLE_DECALS
|
|
//#pragma shader_feature_local_raytracing _ _DISABLE_SSR
|
|
//#pragma shader_feature_local_raytracing _ _DISABLE_SSR_TRANSPARENT
|
|
|
|
#pragma vertex Vert
|
|
#pragma fragment Frag
|
|
|
|
#define SHADERPASS SHADERPASS_TRANSPARENT_DEPTH_PREPASS
|
|
#define CUTOFF_TRANSPARENT_DEPTH_PREPASS
|
|
#define _ABSORPTION_FROM_COLOR 1
|
|
#define SUPPORT_GLOBAL_MIP_BIAS 1
|
|
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl"
|
|
#include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl"
|
|
|
|
//#if !defined(SHADER_STAGE_RAY_TRACING) && SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER && SHADERPASS != SHADERPASS_FULL_SCREEN_DEBUG
|
|
//#define FRAG_INPUTS_ENABLE_STRIPPING
|
|
//#endif
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
|
|
|
|
#ifdef RAYTRACING_SHADER_GRAPH_DEFAULT
|
|
#define RAYTRACING_SHADER_GRAPH_HIGH
|
|
#endif
|
|
|
|
#ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED
|
|
#define RAYTRACING_SHADER_GRAPH_LOW
|
|
#endif
|
|
|
|
#ifndef SHADER_UNLIT
|
|
#if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE)
|
|
#define VARYINGS_NEED_CULLFACE
|
|
#endif
|
|
#endif
|
|
|
|
#if defined(_DOUBLESIDED_ON) && !defined(ASE_NEED_CULLFACE)
|
|
#define ASE_NEED_CULLFACE 1
|
|
#endif
|
|
|
|
#if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
|
|
#if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT)
|
|
#define WRITE_NORMAL_BUFFER
|
|
#endif
|
|
#endif
|
|
|
|
#if SHADERPASS == SHADERPASS_MOTION_VECTORS && defined(WRITE_DECAL_BUFFER_AND_RENDERING_LAYER)
|
|
#define WRITE_DECAL_BUFFER
|
|
#endif
|
|
|
|
#ifndef DEBUG_DISPLAY
|
|
#if !defined(_SURFACE_TYPE_TRANSPARENT)
|
|
#if SHADERPASS == SHADERPASS_FORWARD
|
|
#define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
|
|
#elif SHADERPASS == SHADERPASS_GBUFFER
|
|
#define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST
|
|
#endif
|
|
#endif
|
|
#endif
|
|
|
|
#if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT)
|
|
#define _DEFERRED_CAPABLE_MATERIAL
|
|
#endif
|
|
|
|
#if (defined(_TRANSPARENT_WRITES_MOTION_VEC) || defined(_TRANSPARENT_REFRACTIVE_SORT)) && defined(_SURFACE_TYPE_TRANSPARENT)
|
|
#define _WRITE_TRANSPARENT_MOTION_VECTOR
|
|
#endif
|
|
|
|
CBUFFER_START( UnityPerMaterial )
|
|
float4 _EmissionColor;
|
|
float _AlphaCutoff;
|
|
float _RenderQueueType;
|
|
#ifdef _ADD_PRECOMPUTED_VELOCITY
|
|
float _AddPrecomputedVelocity;
|
|
#endif
|
|
float _ExcludeFromTUAndAA;
|
|
float _StencilRef;
|
|
float _StencilWriteMask;
|
|
float _StencilRefDepth;
|
|
float _StencilWriteMaskDepth;
|
|
float _StencilRefMV;
|
|
float _StencilWriteMaskMV;
|
|
float _StencilRefDistortionVec;
|
|
float _StencilWriteMaskDistortionVec;
|
|
float _StencilWriteMaskGBuffer;
|
|
float _StencilRefGBuffer;
|
|
float _ZTestGBuffer;
|
|
float _RequireSplitLighting;
|
|
float _ReceivesSSR;
|
|
float _SurfaceType;
|
|
float _BlendMode;
|
|
#ifdef SUPPORT_BLENDMODE_PRESERVE_SPECULAR_LIGHTING
|
|
float _EnableBlendModePreserveSpecularLighting;
|
|
#endif
|
|
float _SrcBlend;
|
|
float _DstBlend;
|
|
float _DstBlend2;
|
|
float _AlphaSrcBlend;
|
|
float _AlphaDstBlend;
|
|
float _ZWrite;
|
|
float _TransparentZWrite;
|
|
float _CullMode;
|
|
float _TransparentSortPriority;
|
|
float _EnableFogOnTransparent;
|
|
float _CullModeForward;
|
|
float _TransparentCullMode;
|
|
float _ZTestDepthEqualForOpaque;
|
|
float _ZTestTransparent;
|
|
float _TransparentBackfaceEnable;
|
|
float _AlphaCutoffEnable;
|
|
float _UseShadowThreshold;
|
|
float _DoubleSidedEnable;
|
|
float _DoubleSidedNormalMode;
|
|
float4 _DoubleSidedConstants;
|
|
#ifdef ASE_TESSELLATION
|
|
float _TessPhongStrength;
|
|
float _TessValue;
|
|
float _TessMin;
|
|
float _TessMax;
|
|
float _TessEdgeLength;
|
|
float _TessMaxDisp;
|
|
#endif
|
|
UNITY_TEXTURE_STREAMING_DEBUG_VARS;
|
|
CBUFFER_END
|
|
|
|
#ifdef SCENEPICKINGPASS
|
|
float4 _SelectionID;
|
|
#endif
|
|
|
|
#ifdef SCENESELECTIONPASS
|
|
int _ObjectId;
|
|
int _PassValue;
|
|
#endif
|
|
|
|
/*ase_globals*/
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
|
|
#endif
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Hair/Hair.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl"
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl"
|
|
|
|
#if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS)
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl"
|
|
#endif
|
|
|
|
#ifdef HAVE_VFX_MODIFICATION
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/VisualEffectVertex.hlsl"
|
|
#endif
|
|
|
|
/*ase_pragma*/
|
|
|
|
struct AttributesMesh
|
|
{
|
|
float3 positionOS : POSITION;
|
|
float3 normalOS : NORMAL;
|
|
float4 tangentOS : TANGENT;
|
|
/*ase_vdata:p=p;n=n;t=t*/
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
struct PackedVaryingsMeshToPS
|
|
{
|
|
SV_POSITION_QUALIFIERS float4 positionCS : SV_Position;
|
|
float3 positionRWS : TEXCOORD0;
|
|
float3 normalWS : TEXCOORD1;
|
|
float4 tangentWS : TEXCOORD2;
|
|
/*ase_interp(3,):sp=sp.xyzw;rwp=tc0;wn=tc1;wt=tc2*/
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
UNITY_VERTEX_OUTPUT_STEREO
|
|
#if defined(SHADER_STAGE_FRAGMENT) && defined(ASE_NEED_CULLFACE)
|
|
FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
|
|
#endif
|
|
};
|
|
|
|
/*ase_funcs*/
|
|
|
|
//Build Surface Data (Decal)
|
|
void ApplyDecalToSurfaceDataNoNormal(DecalSurfaceData decalSurfaceData, inout SurfaceData surfaceData)
|
|
{
|
|
surfaceData.diffuseColor.xyz = surfaceData.diffuseColor.xyz * decalSurfaceData.baseColor.w + decalSurfaceData.baseColor.xyz;
|
|
|
|
#ifdef DECALS_4RT
|
|
surfaceData.ambientOcclusion = surfaceData.ambientOcclusion * decalSurfaceData.MAOSBlend.y + decalSurfaceData.mask.y;
|
|
#endif
|
|
|
|
surfaceData.perceptualSmoothness = surfaceData.perceptualSmoothness * decalSurfaceData.mask.w + decalSurfaceData.mask.z;
|
|
}
|
|
|
|
void BuildSurfaceData(FragInputs fragInputs, inout PrePassSurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS)
|
|
{
|
|
ZERO_INITIALIZE(SurfaceData, surfaceData);
|
|
|
|
surfaceData.specularOcclusion = 1.0;
|
|
surfaceData.materialFeatures = 0;
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_KAJIYA_KAY
|
|
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_HAIR_KAJIYA_KAY;
|
|
#endif
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_MARSCHNER
|
|
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_HAIR_MARSCHNER;
|
|
#endif
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_MARSCHNER_CINEMATIC
|
|
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_HAIR_MARSCHNER_CINEMATIC;
|
|
#endif
|
|
|
|
#ifdef _DOUBLESIDED_ON
|
|
float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
|
|
#else
|
|
float3 doubleSidedConstants = float3( 1.0, 1.0, 1.0 );
|
|
#endif
|
|
|
|
float3 normalTS = float3(0.0f, 0.0f, 1.0f);
|
|
normalTS = surfaceDescription.Normal;
|
|
|
|
#ifdef DECAL_NORMAL_BLENDING
|
|
normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]);
|
|
|
|
#if HAVE_DECALS
|
|
if (_EnableDecals)
|
|
{
|
|
float alpha = 1.0;
|
|
alpha = surfaceDescription.Alpha;
|
|
|
|
DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
|
|
ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS);
|
|
ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData);
|
|
}
|
|
#endif
|
|
|
|
GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants);
|
|
#else
|
|
GetNormalWS(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants);
|
|
|
|
#if HAVE_DECALS
|
|
if (_EnableDecals)
|
|
{
|
|
float alpha = 1.0;
|
|
alpha = surfaceDescription.Alpha;
|
|
|
|
DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
|
|
ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz);
|
|
ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData);
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];
|
|
surfaceData.hairStrandDirectionWS = -fragInputs.tangentToWorld[1].xyz;
|
|
surfaceData.hairStrandDirectionWS = normalize(surfaceData.hairStrandDirectionWS);
|
|
|
|
#if (_USE_LIGHT_FACING_NORMAL)
|
|
float3 viewFacingNormalWS = ComputeViewFacingNormal(V, surfaceData.hairStrandDirectionWS);
|
|
float3 N = viewFacingNormalWS;
|
|
#else
|
|
float3 N = surfaceData.normalWS;
|
|
#endif
|
|
|
|
bentNormalWS = surfaceData.normalWS;
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
#if !defined(SHADER_STAGE_RAY_TRACING)
|
|
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
|
|
{
|
|
#ifdef FRAG_INPUTS_USE_TEXCOORD0
|
|
surfaceData.diffuseColor = GET_TEXTURE_STREAMING_DEBUG(posInput.positionSS, fragInputs.texCoord0);
|
|
#else
|
|
surfaceData.diffuseColor = GET_TEXTURE_STREAMING_DEBUG_NO_UV(posInput.positionSS);
|
|
#endif
|
|
}
|
|
#endif
|
|
ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData);
|
|
#endif
|
|
|
|
#if defined(_SPECULAR_OCCLUSION_CUSTOM)
|
|
#elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL)
|
|
surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness));
|
|
#elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO)
|
|
surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness));
|
|
#endif
|
|
|
|
#ifdef _ENABLE_GEOMETRIC_SPECULAR_AA
|
|
surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold);
|
|
#endif
|
|
}
|
|
|
|
// Get Surface And BuiltinData
|
|
void GetSurfaceAndBuiltinData(PrePassSurfaceDescription surfaceDescription, FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData)
|
|
{
|
|
#ifdef LOD_FADE_CROSSFADE
|
|
LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x);
|
|
#endif
|
|
|
|
#ifdef _DOUBLESIDED_ON
|
|
float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
|
|
#else
|
|
float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
|
|
#endif
|
|
ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants);
|
|
|
|
#ifdef _ALPHATEST_ON
|
|
DoAlphaTest( surfaceDescription.Alpha, surfaceDescription.AlphaClipThreshold );
|
|
#endif
|
|
|
|
#ifdef _ALPHATEST_SHADOW_ON
|
|
DoAlphaTest( surfaceDescription.Alpha, surfaceDescription.AlphaClipThresholdShadow);
|
|
#endif
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput);
|
|
#endif
|
|
|
|
float3 bentNormalWS;
|
|
BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS);
|
|
InitBuiltinData(posInput, surfaceDescription.Alpha, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData);
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
builtinData.depthOffset = surfaceDescription.DepthOffset;
|
|
#endif
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
|
|
{
|
|
surfaceDescription.Alpha = 1.0f;
|
|
}
|
|
#endif
|
|
|
|
#ifdef _ALPHATEST_ON
|
|
builtinData.alphaClipTreshold = surfaceDescription.AlphaClipThreshold;
|
|
#endif
|
|
|
|
#ifdef UNITY_VIRTUAL_TEXTURING
|
|
builtinData.vtPackedFeedback = surfaceDescription.VTPackedFeedback;
|
|
#endif
|
|
|
|
#ifdef ASE_BAKEDGI
|
|
builtinData.bakeDiffuseLighting = surfaceDescription.BakedGI;
|
|
#endif
|
|
|
|
#ifdef ASE_BAKEDBACKGI
|
|
builtinData.backBakeDiffuseLighting = surfaceDescription.BakedBackGI;
|
|
#endif
|
|
|
|
builtinData.emissiveColor = surfaceDescription.Emission;
|
|
|
|
PostInitBuiltinData(V, posInput, surfaceData, builtinData);
|
|
}
|
|
|
|
PackedVaryingsMeshToPS VertexFunction(AttributesMesh inputMesh /*ase_vert_input*/)
|
|
{
|
|
PackedVaryingsMeshToPS outputPackedVaryingsMeshToPS;
|
|
UNITY_SETUP_INSTANCE_ID(inputMesh);
|
|
UNITY_TRANSFER_INSTANCE_ID(inputMesh, outputPackedVaryingsMeshToPS);
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO( outputPackedVaryingsMeshToPS );
|
|
|
|
/*ase_vert_code:inputMesh=AttributesMesh;outputPackedVaryingsMeshToPS=PackedVaryingsMeshToPS*/
|
|
|
|
#ifdef ASE_ABSOLUTE_VERTEX_POS
|
|
float3 defaultVertexValue = inputMesh.positionOS.xyz;
|
|
#else
|
|
float3 defaultVertexValue = float3( 0, 0, 0 );
|
|
#endif
|
|
float3 vertexValue = /*ase_vert_out:Vertex Offset;Float3;3;-1;_VertexOffset*/ defaultVertexValue /*end*/;
|
|
|
|
#ifdef ASE_ABSOLUTE_VERTEX_POS
|
|
inputMesh.positionOS.xyz = vertexValue;
|
|
#else
|
|
inputMesh.positionOS.xyz += vertexValue;
|
|
#endif
|
|
|
|
inputMesh.normalOS = /*ase_vert_out:Vertex Normal;Float3;4;-1;_VertexNormal*/ inputMesh.normalOS /*end*/;
|
|
inputMesh.tangentOS = /*ase_vert_out:Vertex Tangent;Float4;5;-1;_VertexTangent*/ inputMesh.tangentOS /*end*/;
|
|
|
|
float3 positionRWS = TransformObjectToWorld(inputMesh.positionOS);
|
|
float3 normalWS = TransformObjectToWorldNormal(inputMesh.normalOS);
|
|
float4 tangentWS = float4(TransformObjectToWorldDir(inputMesh.tangentOS.xyz), inputMesh.tangentOS.w);
|
|
|
|
outputPackedVaryingsMeshToPS.positionCS = TransformWorldToHClip(positionRWS);
|
|
outputPackedVaryingsMeshToPS.positionRWS.xyz = positionRWS;
|
|
outputPackedVaryingsMeshToPS.normalWS.xyz = normalWS;
|
|
outputPackedVaryingsMeshToPS.tangentWS.xyzw = tangentWS;
|
|
return outputPackedVaryingsMeshToPS;
|
|
}
|
|
|
|
#if defined(ASE_TESSELLATION)
|
|
struct VertexControl
|
|
{
|
|
float3 positionOS : INTERNALTESSPOS;
|
|
float3 normalOS : NORMAL;
|
|
float4 tangentOS : TANGENT;
|
|
/*ase_vcontrol*/
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
struct TessellationFactors
|
|
{
|
|
float edge[3] : SV_TessFactor;
|
|
float inside : SV_InsideTessFactor;
|
|
};
|
|
|
|
VertexControl Vert ( AttributesMesh v )
|
|
{
|
|
VertexControl o;
|
|
UNITY_SETUP_INSTANCE_ID(v);
|
|
UNITY_TRANSFER_INSTANCE_ID(v, o);
|
|
o.positionOS = v.positionOS;
|
|
o.normalOS = v.normalOS;
|
|
o.tangentOS = v.tangentOS;
|
|
/*ase_control_code:v=AttributesMesh;o=VertexControl*/
|
|
return o;
|
|
}
|
|
|
|
TessellationFactors TessellationFunction (InputPatch<VertexControl,3> v)
|
|
{
|
|
TessellationFactors o;
|
|
float4 tf = 1;
|
|
float tessValue = /*ase_inline_begin*/_TessValue/*ase_inline_end*/; float tessMin = /*ase_inline_begin*/_TessMin/*ase_inline_end*/; float tessMax = /*ase_inline_begin*/_TessMax/*ase_inline_end*/;
|
|
float edgeLength = /*ase_inline_begin*/_TessEdgeLength/*ase_inline_end*/; float tessMaxDisp = /*ase_inline_begin*/_TessMaxDisp/*ase_inline_end*/;
|
|
#if (SHADEROPTIONS_CAMERA_RELATIVE_RENDERING != 0)
|
|
float3 cameraPos = 0;
|
|
#else
|
|
float3 cameraPos = _WorldSpaceCameraPos;
|
|
#endif
|
|
#if defined(ASE_FIXED_TESSELLATION)
|
|
tf = FixedTess( tessValue );
|
|
#elif defined(ASE_DISTANCE_TESSELLATION)
|
|
tf = DistanceBasedTess(float4(v[0].positionOS,1), float4(v[1].positionOS,1), float4(v[2].positionOS,1), tessValue, tessMin, tessMax, GetObjectToWorldMatrix(), cameraPos );
|
|
#elif defined(ASE_LENGTH_TESSELLATION)
|
|
tf = EdgeLengthBasedTess(float4(v[0].positionOS,1), float4(v[1].positionOS,1), float4(v[2].positionOS,1), edgeLength, GetObjectToWorldMatrix(), cameraPos, _ScreenParams );
|
|
#elif defined(ASE_LENGTH_CULL_TESSELLATION)
|
|
tf = EdgeLengthBasedTessCull(float4(v[0].positionOS,1), float4(v[1].positionOS,1), float4(v[2].positionOS,1), edgeLength, tessMaxDisp, GetObjectToWorldMatrix(), cameraPos, _ScreenParams, _FrustumPlanes );
|
|
#endif
|
|
o.edge[0] = tf.x; o.edge[1] = tf.y; o.edge[2] = tf.z; o.inside = tf.w;
|
|
return o;
|
|
}
|
|
|
|
[domain("tri")]
|
|
[partitioning("fractional_odd")]
|
|
[outputtopology("triangle_cw")]
|
|
[patchconstantfunc("TessellationFunction")]
|
|
[outputcontrolpoints(3)]
|
|
VertexControl HullFunction(InputPatch<VertexControl, 3> patch, uint id : SV_OutputControlPointID)
|
|
{
|
|
return patch[id];
|
|
}
|
|
|
|
[domain("tri")]
|
|
PackedVaryingsMeshToPS DomainFunction(TessellationFactors factors, OutputPatch<VertexControl, 3> patch, float3 bary : SV_DomainLocation)
|
|
{
|
|
AttributesMesh o = (AttributesMesh)0;
|
|
o.positionOS = patch[0].positionOS * bary.x + patch[1].positionOS * bary.y + patch[2].positionOS * bary.z;
|
|
o.normalOS = patch[0].normalOS * bary.x + patch[1].normalOS * bary.y + patch[2].normalOS * bary.z;
|
|
o.tangentOS = patch[0].tangentOS * bary.x + patch[1].tangentOS * bary.y + patch[2].tangentOS * bary.z;
|
|
/*ase_domain_code:patch=VertexControl;o=AttributesMesh;bary=SV_DomainLocation*/
|
|
#if defined(ASE_PHONG_TESSELLATION)
|
|
float3 pp[3];
|
|
for (int i = 0; i < 3; ++i)
|
|
pp[i] = o.positionOS.xyz - patch[i].normalOS * (dot(o.positionOS.xyz, patch[i].normalOS) - dot(patch[i].positionOS.xyz, patch[i].normalOS));
|
|
float phongStrength = /*ase_inline_begin*/_TessPhongStrength/*ase_inline_end*/;
|
|
o.positionOS.xyz = phongStrength * (pp[0] * bary.x + pp[1] * bary.y + pp[2] * bary.z) + (1.0f - phongStrength) * o.positionOS.xyz;
|
|
#endif
|
|
UNITY_TRANSFER_INSTANCE_ID(patch[0], o);
|
|
return VertexFunction(o);
|
|
}
|
|
#else
|
|
PackedVaryingsMeshToPS Vert(AttributesMesh v)
|
|
{
|
|
return VertexFunction(v);
|
|
}
|
|
#endif
|
|
|
|
#if (defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS)) || defined(WRITE_RENDERING_LAYER)
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl"
|
|
#endif
|
|
|
|
#if defined(WRITE_NORMAL_BUFFER) && defined(WRITE_MSAA_DEPTH)
|
|
#define SV_TARGET_DECAL SV_Target2
|
|
#elif defined(WRITE_NORMAL_BUFFER) || defined(WRITE_MSAA_DEPTH)
|
|
#define SV_TARGET_DECAL SV_Target1
|
|
#else
|
|
#define SV_TARGET_DECAL SV_Target0
|
|
#endif
|
|
|
|
void Frag( PackedVaryingsMeshToPS packedInput
|
|
#if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS)
|
|
, out float4 outColor : SV_Target0
|
|
#else
|
|
#ifdef WRITE_MSAA_DEPTH
|
|
, out float4 depthColor : SV_Target0
|
|
#ifdef WRITE_NORMAL_BUFFER
|
|
, out float4 outNormalBuffer : SV_Target1
|
|
#endif
|
|
#else
|
|
#ifdef WRITE_NORMAL_BUFFER
|
|
, out float4 outNormalBuffer : SV_Target0
|
|
#endif
|
|
#endif
|
|
|
|
#if (defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS)) || defined(WRITE_RENDERING_LAYER)
|
|
, out float4 outDecalBuffer : SV_TARGET_DECAL
|
|
#endif
|
|
#endif
|
|
|
|
#if defined(_DEPTHOFFSET_ON) && !defined(SCENEPICKINGPASS)
|
|
, out float outputDepth : DEPTH_OFFSET_SEMANTIC
|
|
#endif
|
|
/*ase_frag_input*/
|
|
)
|
|
{
|
|
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput);
|
|
UNITY_SETUP_INSTANCE_ID(packedInput);
|
|
|
|
/*ase_local_var:rwp*/float3 positionRWS = packedInput.positionRWS.xyz;
|
|
/*ase_local_var:wn*/float3 normalWS = packedInput.normalWS.xyz;
|
|
/*ase_local_var:wt*/float4 tangentWS = packedInput.tangentWS.xyzw;
|
|
|
|
FragInputs input;
|
|
ZERO_INITIALIZE(FragInputs, input);
|
|
|
|
input.tangentToWorld = k_identity3x3;
|
|
input.positionSS = packedInput.positionCS;
|
|
|
|
input.positionRWS = positionRWS;
|
|
input.tangentToWorld = BuildTangentToWorld(tangentWS, normalWS);
|
|
|
|
#if _DOUBLESIDED_ON && SHADER_STAGE_FRAGMENT
|
|
input.isFrontFace = IS_FRONT_VFACE(packedInput.cullFace, true, false);
|
|
#elif SHADER_STAGE_FRAGMENT
|
|
#if defined(ASE_NEED_CULLFACE)
|
|
input.isFrontFace = IS_FRONT_VFACE(packedInput.cullFace, true, false);
|
|
#endif
|
|
#endif
|
|
/*ase_local_var:vf*/half isFrontFace = input.isFrontFace;
|
|
|
|
PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS);
|
|
|
|
/*ase_local_var:wvd*/float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
|
|
|
|
PrePassSurfaceDescription surfaceDescription = (PrePassSurfaceDescription)0;
|
|
/*ase_frag_code:packedInput=PackedVaryingsMeshToPS*/
|
|
surfaceDescription.Alpha = /*ase_frag_out:Alpha;Float;0;-1;_Alpha*/1/*end*/;
|
|
|
|
surfaceDescription.AlphaClipThresholdDepthPrepass = /*ase_frag_out:Alpha Clip Threshold Depth Prepass;Float;1;-1;_AlphaClipDepthPrepass*/0.5/*end*/;
|
|
surfaceDescription.Smoothness = /*ase_frag_out:Smoothness;Float;55;-1;_Smoothness*/1/*end*/;
|
|
surfaceDescription.Normal = /*ase_frag_out:Normal;Float3;56;-1;_Normal*/float3(0, 0, 1)/*end*/;
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
surfaceDescription.DepthOffset = /*ase_frag_out:Depth Offset;Float;2;-1;_DepthOffset*/0/*end*/;
|
|
#endif
|
|
|
|
SurfaceData surfaceData;
|
|
BuiltinData builtinData;
|
|
GetSurfaceAndBuiltinData(surfaceDescription, input, V, posInput, surfaceData, builtinData);
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
outputDepth = posInput.deviceDepth;
|
|
#endif
|
|
|
|
#ifdef WRITE_MSAA_DEPTH
|
|
depthColor = packedInput.positionCS.z;
|
|
depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold);
|
|
#endif
|
|
|
|
#if defined(WRITE_NORMAL_BUFFER)
|
|
EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer);
|
|
#endif
|
|
|
|
#if (defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS)) || defined(WRITE_RENDERING_LAYER)
|
|
DecalPrepassData decalPrepassData;
|
|
#ifdef _DISABLE_DECALS
|
|
ZERO_INITIALIZE(DecalPrepassData, decalPrepassData);
|
|
#else
|
|
decalPrepassData.geomNormalWS = surfaceData.geomNormalWS;
|
|
#endif
|
|
decalPrepassData.renderingLayerMask = GetMeshRenderingLayerMask();
|
|
EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer);
|
|
#endif
|
|
|
|
}
|
|
ENDHLSL
|
|
}
|
|
|
|
/*ase_pass*/
|
|
Pass
|
|
{
|
|
/*ase_hide_pass*/
|
|
Name "TransparentDepthPostpass"
|
|
Tags
|
|
{
|
|
"LightMode" = "TransparentDepthPostpass"
|
|
}
|
|
|
|
Blend One Zero
|
|
Cull [_CullMode]
|
|
ZTest LEqual
|
|
ZWrite On
|
|
ColorMask 0
|
|
|
|
HLSLPROGRAM
|
|
#pragma multi_compile _ DOTS_INSTANCING_ON
|
|
|
|
#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT
|
|
#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC _TRANSPARENT_REFRACTIVE_SORT
|
|
#pragma shader_feature_local_fragment _ _ENABLE_FOG_ON_TRANSPARENT
|
|
|
|
//RayTracing
|
|
//#pragma shader_feature_local_raytracing _ _DISABLE_DECALS
|
|
//#pragma shader_feature_local_raytracing _ _DISABLE_SSR
|
|
//#pragma shader_feature_local_raytracing _ _DISABLE_SSR_TRANSPARENT
|
|
|
|
#pragma vertex Vert
|
|
#pragma fragment Frag
|
|
|
|
#define SHADERPASS SHADERPASS_TRANSPARENT_DEPTH_POSTPASS
|
|
#define CUTOFF_TRANSPARENT_DEPTH_POSTPASS
|
|
#define _ABSORPTION_FROM_COLOR 1
|
|
#define SUPPORT_GLOBAL_MIP_BIAS 1
|
|
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl"
|
|
#include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl"
|
|
|
|
//#if !defined(SHADER_STAGE_RAY_TRACING) && SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER && SHADERPASS != SHADERPASS_FULL_SCREEN_DEBUG
|
|
//#define FRAG_INPUTS_ENABLE_STRIPPING
|
|
//#endif
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
|
|
|
|
#ifdef RAYTRACING_SHADER_GRAPH_DEFAULT
|
|
#define RAYTRACING_SHADER_GRAPH_HIGH
|
|
#endif
|
|
|
|
#ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED
|
|
#define RAYTRACING_SHADER_GRAPH_LOW
|
|
#endif
|
|
|
|
#ifndef SHADER_UNLIT
|
|
#if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE)
|
|
#define VARYINGS_NEED_CULLFACE
|
|
#endif
|
|
#endif
|
|
|
|
#if defined(_DOUBLESIDED_ON) && !defined(ASE_NEED_CULLFACE)
|
|
#define ASE_NEED_CULLFACE 1
|
|
#endif
|
|
|
|
#if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
|
|
#if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT)
|
|
#define WRITE_NORMAL_BUFFER
|
|
#endif
|
|
#endif
|
|
|
|
#if SHADERPASS == SHADERPASS_MOTION_VECTORS && defined(WRITE_DECAL_BUFFER_AND_RENDERING_LAYER)
|
|
#define WRITE_DECAL_BUFFER
|
|
#endif
|
|
|
|
#ifndef DEBUG_DISPLAY
|
|
#if !defined(_SURFACE_TYPE_TRANSPARENT)
|
|
#if SHADERPASS == SHADERPASS_FORWARD
|
|
#define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
|
|
#elif SHADERPASS == SHADERPASS_GBUFFER
|
|
#define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST
|
|
#endif
|
|
#endif
|
|
#endif
|
|
|
|
#if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT)
|
|
#define _DEFERRED_CAPABLE_MATERIAL
|
|
#endif
|
|
|
|
#if (defined(_TRANSPARENT_WRITES_MOTION_VEC) || defined(_TRANSPARENT_REFRACTIVE_SORT)) && defined(_SURFACE_TYPE_TRANSPARENT)
|
|
#define _WRITE_TRANSPARENT_MOTION_VECTOR
|
|
#endif
|
|
|
|
CBUFFER_START( UnityPerMaterial )
|
|
float4 _EmissionColor;
|
|
float _AlphaCutoff;
|
|
float _RenderQueueType;
|
|
#ifdef _ADD_PRECOMPUTED_VELOCITY
|
|
float _AddPrecomputedVelocity;
|
|
#endif
|
|
float _ExcludeFromTUAndAA;
|
|
float _StencilRef;
|
|
float _StencilWriteMask;
|
|
float _StencilRefDepth;
|
|
float _StencilWriteMaskDepth;
|
|
float _StencilRefMV;
|
|
float _StencilWriteMaskMV;
|
|
float _StencilRefDistortionVec;
|
|
float _StencilWriteMaskDistortionVec;
|
|
float _StencilWriteMaskGBuffer;
|
|
float _StencilRefGBuffer;
|
|
float _ZTestGBuffer;
|
|
float _RequireSplitLighting;
|
|
float _ReceivesSSR;
|
|
float _SurfaceType;
|
|
float _BlendMode;
|
|
#ifdef SUPPORT_BLENDMODE_PRESERVE_SPECULAR_LIGHTING
|
|
float _EnableBlendModePreserveSpecularLighting;
|
|
#endif
|
|
float _SrcBlend;
|
|
float _DstBlend;
|
|
float _DstBlend2;
|
|
float _AlphaSrcBlend;
|
|
float _AlphaDstBlend;
|
|
float _ZWrite;
|
|
float _TransparentZWrite;
|
|
float _CullMode;
|
|
float _TransparentSortPriority;
|
|
float _EnableFogOnTransparent;
|
|
float _CullModeForward;
|
|
float _TransparentCullMode;
|
|
float _ZTestDepthEqualForOpaque;
|
|
float _ZTestTransparent;
|
|
float _TransparentBackfaceEnable;
|
|
float _AlphaCutoffEnable;
|
|
float _UseShadowThreshold;
|
|
float _DoubleSidedEnable;
|
|
float _DoubleSidedNormalMode;
|
|
float4 _DoubleSidedConstants;
|
|
#ifdef ASE_TESSELLATION
|
|
float _TessPhongStrength;
|
|
float _TessValue;
|
|
float _TessMin;
|
|
float _TessMax;
|
|
float _TessEdgeLength;
|
|
float _TessMaxDisp;
|
|
#endif
|
|
UNITY_TEXTURE_STREAMING_DEBUG_VARS;
|
|
CBUFFER_END
|
|
|
|
#ifdef SCENEPICKINGPASS
|
|
float4 _SelectionID;
|
|
#endif
|
|
|
|
#ifdef SCENESELECTIONPASS
|
|
int _ObjectId;
|
|
int _PassValue;
|
|
#endif
|
|
|
|
/*ase_globals*/
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
|
|
#endif
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Hair/Hair.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl"
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl"
|
|
|
|
#if (defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS)) || defined(WRITE_RENDERING_LAYER)
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl"
|
|
#endif
|
|
|
|
#ifdef HAVE_VFX_MODIFICATION
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/VisualEffectVertex.hlsl"
|
|
#endif
|
|
|
|
/*ase_pragma*/
|
|
|
|
struct AttributesMesh
|
|
{
|
|
float3 positionOS : POSITION;
|
|
float3 normalOS : NORMAL;
|
|
float4 tangentOS : TANGENT;
|
|
/*ase_vdata:p=p;n=n;t=t*/
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
struct PackedVaryingsMeshToPS
|
|
{
|
|
SV_POSITION_QUALIFIERS float4 positionCS : SV_Position;
|
|
float3 positionRWS : TEXCOORD0;
|
|
/*ase_interp(1,):sp=sp.xyzw;rwp=tc0*/
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
UNITY_VERTEX_OUTPUT_STEREO
|
|
#if defined(SHADER_STAGE_FRAGMENT) && defined(ASE_NEED_CULLFACE)
|
|
FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
|
|
#endif
|
|
};
|
|
|
|
/*ase_funcs*/
|
|
|
|
//Build Surface Data (Decal)
|
|
void ApplyDecalToSurfaceDataNoNormal(DecalSurfaceData decalSurfaceData, inout SurfaceData surfaceData)
|
|
{
|
|
surfaceData.diffuseColor.xyz = surfaceData.diffuseColor.xyz * decalSurfaceData.baseColor.w + decalSurfaceData.baseColor.xyz;
|
|
|
|
#ifdef DECALS_4RT
|
|
surfaceData.ambientOcclusion = surfaceData.ambientOcclusion * decalSurfaceData.MAOSBlend.y + decalSurfaceData.mask.y;
|
|
#endif
|
|
|
|
surfaceData.perceptualSmoothness = surfaceData.perceptualSmoothness * decalSurfaceData.mask.w + decalSurfaceData.mask.z;
|
|
}
|
|
|
|
void BuildSurfaceData(FragInputs fragInputs, inout PostPassSurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS)
|
|
{
|
|
ZERO_INITIALIZE(SurfaceData, surfaceData);
|
|
|
|
surfaceData.specularOcclusion = 1.0;
|
|
surfaceData.materialFeatures = 0;
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_KAJIYA_KAY
|
|
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_HAIR_KAJIYA_KAY;
|
|
#endif
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_MARSCHNER
|
|
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_HAIR_MARSCHNER;
|
|
#endif
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_MARSCHNER_CINEMATIC
|
|
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_HAIR_MARSCHNER_CINEMATIC;
|
|
#endif
|
|
|
|
#ifdef _DOUBLESIDED_ON
|
|
float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
|
|
#else
|
|
float3 doubleSidedConstants = float3( 1.0, 1.0, 1.0 );
|
|
#endif
|
|
|
|
float3 normalTS = float3(0.0f, 0.0f, 1.0f);
|
|
|
|
#ifdef DECAL_NORMAL_BLENDING
|
|
normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]);
|
|
|
|
#if HAVE_DECALS
|
|
if (_EnableDecals)
|
|
{
|
|
float alpha = 1.0;
|
|
alpha = surfaceDescription.Alpha;
|
|
|
|
DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
|
|
ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS);
|
|
ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData);
|
|
}
|
|
#endif
|
|
|
|
GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants);
|
|
#else
|
|
GetNormalWS(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants);
|
|
|
|
#if HAVE_DECALS
|
|
if (_EnableDecals)
|
|
{
|
|
float alpha = 1.0;
|
|
alpha = surfaceDescription.Alpha;
|
|
|
|
DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
|
|
ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz);
|
|
ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData);
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];
|
|
surfaceData.hairStrandDirectionWS = -fragInputs.tangentToWorld[1].xyz;
|
|
surfaceData.hairStrandDirectionWS = normalize(surfaceData.hairStrandDirectionWS);
|
|
|
|
#if (_USE_LIGHT_FACING_NORMAL)
|
|
float3 viewFacingNormalWS = ComputeViewFacingNormal(V, surfaceData.hairStrandDirectionWS);
|
|
float3 N = viewFacingNormalWS;
|
|
#else
|
|
float3 N = surfaceData.normalWS;
|
|
#endif
|
|
|
|
bentNormalWS = surfaceData.normalWS;
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
#if !defined(SHADER_STAGE_RAY_TRACING)
|
|
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
|
|
{
|
|
#ifdef FRAG_INPUTS_USE_TEXCOORD0
|
|
surfaceData.diffuseColor = GET_TEXTURE_STREAMING_DEBUG(posInput.positionSS, fragInputs.texCoord0);
|
|
#else
|
|
surfaceData.diffuseColor = GET_TEXTURE_STREAMING_DEBUG_NO_UV(posInput.positionSS);
|
|
#endif
|
|
}
|
|
#endif
|
|
ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData);
|
|
#endif
|
|
|
|
#if defined(_SPECULAR_OCCLUSION_CUSTOM)
|
|
#elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL)
|
|
surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness));
|
|
#elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO)
|
|
surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness));
|
|
#endif
|
|
|
|
#ifdef _ENABLE_GEOMETRIC_SPECULAR_AA
|
|
surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold);
|
|
#endif
|
|
}
|
|
|
|
// Get Surface And BuiltinData
|
|
void GetSurfaceAndBuiltinData(PostPassSurfaceDescription surfaceDescription, FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData)
|
|
{
|
|
#ifdef LOD_FADE_CROSSFADE
|
|
LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x);
|
|
#endif
|
|
|
|
#ifdef _DOUBLESIDED_ON
|
|
float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
|
|
#else
|
|
float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
|
|
#endif
|
|
ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants);
|
|
|
|
#ifdef _ALPHATEST_ON
|
|
DoAlphaTest( surfaceDescription.Alpha, surfaceDescription.AlphaClipThreshold );
|
|
#endif
|
|
|
|
#ifdef _ALPHATEST_SHADOW_ON
|
|
DoAlphaTest( surfaceDescription.Alpha, surfaceDescription.AlphaClipThresholdShadow);
|
|
#endif
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput);
|
|
#endif
|
|
|
|
float3 bentNormalWS;
|
|
BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS);
|
|
InitBuiltinData(posInput, surfaceDescription.Alpha, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData);
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
builtinData.depthOffset = surfaceDescription.DepthOffset;
|
|
#endif
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
|
|
{
|
|
surfaceDescription.Alpha = 1.0f;
|
|
}
|
|
#endif
|
|
|
|
#ifdef _ALPHATEST_ON
|
|
builtinData.alphaClipTreshold = surfaceDescription.AlphaClipThreshold;
|
|
#endif
|
|
|
|
#ifdef UNITY_VIRTUAL_TEXTURING
|
|
builtinData.vtPackedFeedback = surfaceDescription.VTPackedFeedback;
|
|
#endif
|
|
|
|
#ifdef ASE_BAKEDGI
|
|
builtinData.bakeDiffuseLighting = surfaceDescription.BakedGI;
|
|
#endif
|
|
|
|
#ifdef ASE_BAKEDBACKGI
|
|
builtinData.backBakeDiffuseLighting = surfaceDescription.BakedBackGI;
|
|
#endif
|
|
|
|
builtinData.emissiveColor = surfaceDescription.Emission;
|
|
|
|
PostInitBuiltinData(V, posInput, surfaceData, builtinData);
|
|
}
|
|
|
|
PackedVaryingsMeshToPS VertexFunction(AttributesMesh inputMesh /*ase_vert_input*/)
|
|
{
|
|
PackedVaryingsMeshToPS outputPackedVaryingsMeshToPS;
|
|
UNITY_SETUP_INSTANCE_ID(inputMesh);
|
|
UNITY_TRANSFER_INSTANCE_ID(inputMesh, outputPackedVaryingsMeshToPS);
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO( outputPackedVaryingsMeshToPS );
|
|
|
|
/*ase_vert_code:inputMesh=AttributesMesh;outputPackedVaryingsMeshToPS=PackedVaryingsMeshToPS*/
|
|
|
|
#ifdef ASE_ABSOLUTE_VERTEX_POS
|
|
float3 defaultVertexValue = inputMesh.positionOS.xyz;
|
|
#else
|
|
float3 defaultVertexValue = float3( 0, 0, 0 );
|
|
#endif
|
|
float3 vertexValue = /*ase_vert_out:Vertex Offset;Float3;3;-1;_VertexOffset*/ defaultVertexValue /*end*/;
|
|
|
|
#ifdef ASE_ABSOLUTE_VERTEX_POS
|
|
inputMesh.positionOS.xyz = vertexValue;
|
|
#else
|
|
inputMesh.positionOS.xyz += vertexValue;
|
|
#endif
|
|
|
|
inputMesh.normalOS = /*ase_vert_out:Vertex Normal;Float3;4;-1;_VertexNormal*/ inputMesh.normalOS /*end*/;
|
|
inputMesh.tangentOS = /*ase_vert_out:Vertex Tangent;Float4;5;-1;_VertexTangent*/ inputMesh.tangentOS /*end*/;
|
|
|
|
float3 positionRWS = TransformObjectToWorld(inputMesh.positionOS);
|
|
outputPackedVaryingsMeshToPS.positionCS = TransformWorldToHClip(positionRWS);
|
|
outputPackedVaryingsMeshToPS.positionRWS.xyz = positionRWS;
|
|
return outputPackedVaryingsMeshToPS;
|
|
}
|
|
|
|
#if defined(ASE_TESSELLATION)
|
|
struct VertexControl
|
|
{
|
|
float3 positionOS : INTERNALTESSPOS;
|
|
float3 normalOS : NORMAL;
|
|
float4 tangentOS : TANGENT;
|
|
/*ase_vcontrol*/
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
struct TessellationFactors
|
|
{
|
|
float edge[3] : SV_TessFactor;
|
|
float inside : SV_InsideTessFactor;
|
|
};
|
|
|
|
VertexControl Vert ( AttributesMesh v )
|
|
{
|
|
VertexControl o;
|
|
UNITY_SETUP_INSTANCE_ID(v);
|
|
UNITY_TRANSFER_INSTANCE_ID(v, o);
|
|
o.positionOS = v.positionOS;
|
|
o.normalOS = v.normalOS;
|
|
o.tangentOS = v.tangentOS;
|
|
/*ase_control_code:v=AttributesMesh;o=VertexControl*/
|
|
return o;
|
|
}
|
|
|
|
TessellationFactors TessellationFunction (InputPatch<VertexControl,3> v)
|
|
{
|
|
TessellationFactors o;
|
|
float4 tf = 1;
|
|
float tessValue = /*ase_inline_begin*/_TessValue/*ase_inline_end*/; float tessMin = /*ase_inline_begin*/_TessMin/*ase_inline_end*/; float tessMax = /*ase_inline_begin*/_TessMax/*ase_inline_end*/;
|
|
float edgeLength = /*ase_inline_begin*/_TessEdgeLength/*ase_inline_end*/; float tessMaxDisp = /*ase_inline_begin*/_TessMaxDisp/*ase_inline_end*/;
|
|
#if (SHADEROPTIONS_CAMERA_RELATIVE_RENDERING != 0)
|
|
float3 cameraPos = 0;
|
|
#else
|
|
float3 cameraPos = _WorldSpaceCameraPos;
|
|
#endif
|
|
#if defined(ASE_FIXED_TESSELLATION)
|
|
tf = FixedTess( tessValue );
|
|
#elif defined(ASE_DISTANCE_TESSELLATION)
|
|
tf = DistanceBasedTess(float4(v[0].positionOS,1), float4(v[1].positionOS,1), float4(v[2].positionOS,1), tessValue, tessMin, tessMax, GetObjectToWorldMatrix(), cameraPos );
|
|
#elif defined(ASE_LENGTH_TESSELLATION)
|
|
tf = EdgeLengthBasedTess(float4(v[0].positionOS,1), float4(v[1].positionOS,1), float4(v[2].positionOS,1), edgeLength, GetObjectToWorldMatrix(), cameraPos, _ScreenParams );
|
|
#elif defined(ASE_LENGTH_CULL_TESSELLATION)
|
|
tf = EdgeLengthBasedTessCull(float4(v[0].positionOS,1), float4(v[1].positionOS,1), float4(v[2].positionOS,1), edgeLength, tessMaxDisp, GetObjectToWorldMatrix(), cameraPos, _ScreenParams, _FrustumPlanes );
|
|
#endif
|
|
o.edge[0] = tf.x; o.edge[1] = tf.y; o.edge[2] = tf.z; o.inside = tf.w;
|
|
return o;
|
|
}
|
|
|
|
[domain("tri")]
|
|
[partitioning("fractional_odd")]
|
|
[outputtopology("triangle_cw")]
|
|
[patchconstantfunc("TessellationFunction")]
|
|
[outputcontrolpoints(3)]
|
|
VertexControl HullFunction(InputPatch<VertexControl, 3> patch, uint id : SV_OutputControlPointID)
|
|
{
|
|
return patch[id];
|
|
}
|
|
|
|
[domain("tri")]
|
|
PackedVaryingsMeshToPS DomainFunction(TessellationFactors factors, OutputPatch<VertexControl, 3> patch, float3 bary : SV_DomainLocation)
|
|
{
|
|
AttributesMesh o = (AttributesMesh) 0;
|
|
o.positionOS = patch[0].positionOS * bary.x + patch[1].positionOS * bary.y + patch[2].positionOS * bary.z;
|
|
o.normalOS = patch[0].normalOS * bary.x + patch[1].normalOS * bary.y + patch[2].normalOS * bary.z;
|
|
o.tangentOS = patch[0].tangentOS * bary.x + patch[1].tangentOS * bary.y + patch[2].tangentOS * bary.z;
|
|
/*ase_domain_code:patch=VertexControl;o=AttributesMesh;bary=SV_DomainLocation*/
|
|
#if defined(ASE_PHONG_TESSELLATION)
|
|
float3 pp[3];
|
|
for (int i = 0; i < 3; ++i)
|
|
pp[i] = o.positionOS.xyz - patch[i].normalOS * (dot(o.positionOS.xyz, patch[i].normalOS) - dot(patch[i].positionOS.xyz, patch[i].normalOS));
|
|
float phongStrength = /*ase_inline_begin*/_TessPhongStrength/*ase_inline_end*/;
|
|
o.positionOS.xyz = phongStrength * (pp[0]*bary.x + pp[1]*bary.y + pp[2]*bary.z) + (1.0f-phongStrength) * o.positionOS.xyz;
|
|
#endif
|
|
UNITY_TRANSFER_INSTANCE_ID(patch[0], o);
|
|
return VertexFunction(o);
|
|
}
|
|
#else
|
|
PackedVaryingsMeshToPS Vert ( AttributesMesh v )
|
|
{
|
|
return VertexFunction( v );
|
|
}
|
|
#endif
|
|
|
|
#if defined(WRITE_NORMAL_BUFFER) && defined(WRITE_MSAA_DEPTH)
|
|
#define SV_TARGET_DECAL SV_Target2
|
|
#elif defined(WRITE_NORMAL_BUFFER) || defined(WRITE_MSAA_DEPTH)
|
|
#define SV_TARGET_DECAL SV_Target1
|
|
#else
|
|
#define SV_TARGET_DECAL SV_Target0
|
|
#endif
|
|
|
|
void Frag( PackedVaryingsMeshToPS packedInput
|
|
#if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS)
|
|
, out float4 outColor : SV_Target0
|
|
#else
|
|
#ifdef WRITE_MSAA_DEPTH
|
|
, out float4 depthColor : SV_Target0
|
|
#ifdef WRITE_NORMAL_BUFFER
|
|
, out float4 outNormalBuffer : SV_Target1
|
|
#endif
|
|
#else
|
|
#ifdef WRITE_NORMAL_BUFFER
|
|
, out float4 outNormalBuffer : SV_Target0
|
|
#endif
|
|
#endif
|
|
|
|
#if (defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS)) || defined(WRITE_RENDERING_LAYER)
|
|
, out float4 outDecalBuffer : SV_TARGET_DECAL
|
|
#endif
|
|
#endif
|
|
|
|
#if defined(_DEPTHOFFSET_ON) && !defined(SCENEPICKINGPASS)
|
|
, out float outputDepth : DEPTH_OFFSET_SEMANTIC
|
|
#endif
|
|
/*ase_frag_input*/
|
|
)
|
|
{
|
|
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput);
|
|
UNITY_SETUP_INSTANCE_ID(packedInput);
|
|
|
|
/*ase_local_var:rwp*/float3 positionRWS = packedInput.positionRWS.xyz;
|
|
|
|
FragInputs input;
|
|
ZERO_INITIALIZE(FragInputs, input);
|
|
|
|
input.tangentToWorld = k_identity3x3;
|
|
input.positionSS = packedInput.positionCS;
|
|
|
|
input.positionRWS = positionRWS;
|
|
|
|
#if _DOUBLESIDED_ON && SHADER_STAGE_FRAGMENT
|
|
input.isFrontFace = IS_FRONT_VFACE( packedInput.cullFace, true, false);
|
|
#elif SHADER_STAGE_FRAGMENT
|
|
#if defined(ASE_NEED_CULLFACE)
|
|
input.isFrontFace = IS_FRONT_VFACE( packedInput.cullFace, true, false );
|
|
#endif
|
|
#endif
|
|
/*ase_local_var:vf*/half isFrontFace = input.isFrontFace;
|
|
|
|
PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS);
|
|
|
|
/*ase_local_var:wvd*/float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
|
|
|
|
PostPassSurfaceDescription surfaceDescription = (PostPassSurfaceDescription)0;
|
|
/*ase_frag_code:packedInput=PackedVaryingsMeshToPS*/
|
|
surfaceDescription.Alpha = /*ase_frag_out:Alpha;Float;0;-1;_Alpha*/1/*end*/;
|
|
|
|
surfaceDescription.AlphaClipThresholdDepthPostpass = /*ase_frag_out:Alpha Clip Threshold Depth Postpass;Float;1;-1;_AlphaClipDepthPostpass*/0.5/*end*/;
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
surfaceDescription.DepthOffset = /*ase_frag_out:Depth Offset;Float;2;-1;_DepthOffset*/0/*end*/;
|
|
#endif
|
|
|
|
SurfaceData surfaceData;
|
|
BuiltinData builtinData;
|
|
GetSurfaceAndBuiltinData(surfaceDescription, input, V, posInput, surfaceData, builtinData);
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
outputDepth = posInput.deviceDepth;
|
|
#endif
|
|
|
|
#ifdef WRITE_MSAA_DEPTH
|
|
depthColor = packedInput.positionCS.z;
|
|
depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold);
|
|
#endif
|
|
|
|
#if defined(WRITE_NORMAL_BUFFER)
|
|
EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer);
|
|
#endif
|
|
|
|
#if (defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS)) || defined(WRITE_RENDERING_LAYER)
|
|
DecalPrepassData decalPrepassData;
|
|
#ifdef _DISABLE_DECALS
|
|
ZERO_INITIALIZE(DecalPrepassData, decalPrepassData);
|
|
#else
|
|
decalPrepassData.geomNormalWS = surfaceData.geomNormalWS;
|
|
#endif
|
|
decalPrepassData.renderingLayerMask = GetMeshRenderingLayerMask();
|
|
EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer);
|
|
#endif
|
|
}
|
|
ENDHLSL
|
|
}
|
|
|
|
/*ase_pass*/
|
|
Pass
|
|
{
|
|
/*ase_hide_pass*/
|
|
Name "MotionVectors"
|
|
Tags
|
|
{
|
|
"LightMode" = "MotionVectors"
|
|
}
|
|
|
|
Cull [_CullMode]
|
|
ZWrite On
|
|
|
|
Stencil
|
|
{
|
|
WriteMask [_StencilWriteMaskMV]
|
|
Ref [_StencilRefMV]
|
|
CompFront Always
|
|
PassFront Replace
|
|
CompBack Always
|
|
PassBack Replace
|
|
}
|
|
AlphaToMask [_AlphaCutoffEnable]
|
|
|
|
HLSLPROGRAM
|
|
#pragma multi_compile _ DOTS_INSTANCING_ON
|
|
|
|
#pragma shader_feature _ _SURFACE_TYPE_TRANSPARENT
|
|
#pragma shader_feature_local _ _TRANSPARENT_WRITES_MOTION_VEC _TRANSPARENT_REFRACTIVE_SORT
|
|
#pragma shader_feature_local_fragment _ _ENABLE_FOG_ON_TRANSPARENT
|
|
|
|
#pragma multi_compile _ WRITE_NORMAL_BUFFER
|
|
#pragma multi_compile_fragment _ WRITE_MSAA_DEPTH
|
|
#pragma multi_compile_fragment _ WRITE_DECAL_BUFFER_AND_RENDERING_LAYER
|
|
|
|
#ifdef WRITE_DECAL_BUFFER_AND_RENDERING_LAYER
|
|
#define WRITE_DECAL_BUFFER
|
|
#endif
|
|
|
|
//RayTracing
|
|
//#pragma shader_feature_local_raytracing _ _DISABLE_DECALS
|
|
//#pragma shader_feature_local_raytracing _ _DISABLE_SSR
|
|
//#pragma shader_feature_local_raytracing _ _DISABLE_SSR_TRANSPARENT
|
|
|
|
|
|
#pragma vertex Vert
|
|
#pragma fragment Frag
|
|
|
|
#define SHADERPASS SHADERPASS_MOTION_VECTORS
|
|
#define WRITE_NORMAL_BUFFER 1
|
|
#define _ABSORPTION_FROM_COLOR 1
|
|
#define SUPPORT_GLOBAL_MIP_BIAS 1
|
|
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/GeometricTools.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Tessellation.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPass.cs.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DebugMipmapStreamingMacros.hlsl"
|
|
#include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl"
|
|
|
|
//#if !defined(SHADER_STAGE_RAY_TRACING) && SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER && SHADERPASS != SHADERPASS_FULL_SCREEN_DEBUG
|
|
//#define FRAG_INPUTS_ENABLE_STRIPPING
|
|
//#endif
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/FragInputs.hlsl"
|
|
|
|
#ifdef RAYTRACING_SHADER_GRAPH_DEFAULT
|
|
#define RAYTRACING_SHADER_GRAPH_HIGH
|
|
#endif
|
|
|
|
#ifdef RAYTRACING_SHADER_GRAPH_RAYTRACED
|
|
#define RAYTRACING_SHADER_GRAPH_LOW
|
|
#endif
|
|
|
|
#ifndef SHADER_UNLIT
|
|
#if defined(_DOUBLESIDED_ON) && !defined(VARYINGS_NEED_CULLFACE)
|
|
#define VARYINGS_NEED_CULLFACE
|
|
#endif
|
|
#endif
|
|
|
|
#if defined(_DOUBLESIDED_ON) && !defined(ASE_NEED_CULLFACE)
|
|
#define ASE_NEED_CULLFACE 1
|
|
#endif
|
|
|
|
#if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
|
|
#if !defined(_DISABLE_SSR_TRANSPARENT) && !defined(SHADER_UNLIT)
|
|
#define WRITE_NORMAL_BUFFER
|
|
#endif
|
|
#endif
|
|
|
|
#if SHADERPASS == SHADERPASS_MOTION_VECTORS && defined(WRITE_DECAL_BUFFER_AND_RENDERING_LAYER)
|
|
#define WRITE_DECAL_BUFFER
|
|
#endif
|
|
|
|
#ifndef DEBUG_DISPLAY
|
|
#if !defined(_SURFACE_TYPE_TRANSPARENT)
|
|
#if SHADERPASS == SHADERPASS_FORWARD
|
|
#define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
|
|
#elif SHADERPASS == SHADERPASS_GBUFFER
|
|
#define SHADERPASS_GBUFFER_BYPASS_ALPHA_TEST
|
|
#endif
|
|
#endif
|
|
#endif
|
|
|
|
#if defined(SHADER_LIT) && !defined(_SURFACE_TYPE_TRANSPARENT)
|
|
#define _DEFERRED_CAPABLE_MATERIAL
|
|
#endif
|
|
|
|
#if (defined(_TRANSPARENT_WRITES_MOTION_VEC) || defined(_TRANSPARENT_REFRACTIVE_SORT)) && defined(_SURFACE_TYPE_TRANSPARENT)
|
|
#define _WRITE_TRANSPARENT_MOTION_VECTOR
|
|
#endif
|
|
|
|
CBUFFER_START( UnityPerMaterial )
|
|
float4 _EmissionColor;
|
|
float _AlphaCutoff;
|
|
float _RenderQueueType;
|
|
#ifdef _ADD_PRECOMPUTED_VELOCITY
|
|
float _AddPrecomputedVelocity;
|
|
#endif
|
|
#ifdef _ENABLE_SHADOW_MATTE
|
|
float _ShadowMatteFilter;
|
|
#endif
|
|
float _ExcludeFromTUAndAA;
|
|
float _StencilRef;
|
|
float _StencilWriteMask;
|
|
float _StencilRefDepth;
|
|
float _StencilWriteMaskDepth;
|
|
float _StencilRefMV;
|
|
float _StencilWriteMaskMV;
|
|
float _StencilRefDistortionVec;
|
|
float _StencilWriteMaskDistortionVec;
|
|
float _StencilWriteMaskGBuffer;
|
|
float _StencilRefGBuffer;
|
|
float _ZTestGBuffer;
|
|
float _RequireSplitLighting;
|
|
float _ReceivesSSR;
|
|
float _SurfaceType;
|
|
float _BlendMode;
|
|
#ifdef SUPPORT_BLENDMODE_PRESERVE_SPECULAR_LIGHTING
|
|
float _EnableBlendModePreserveSpecularLighting;
|
|
#endif
|
|
float _SrcBlend;
|
|
float _DstBlend;
|
|
float _DstBlend2;
|
|
float _AlphaSrcBlend;
|
|
float _AlphaDstBlend;
|
|
float _ZWrite;
|
|
float _TransparentZWrite;
|
|
float _CullMode;
|
|
float _TransparentSortPriority;
|
|
float _EnableFogOnTransparent;
|
|
float _CullModeForward;
|
|
float _TransparentCullMode;
|
|
float _ZTestDepthEqualForOpaque;
|
|
float _ZTestTransparent;
|
|
float _TransparentBackfaceEnable;
|
|
float _AlphaCutoffEnable;
|
|
float _UseShadowThreshold;
|
|
float _DoubleSidedEnable;
|
|
float _DoubleSidedNormalMode;
|
|
float4 _DoubleSidedConstants;
|
|
#ifdef ASE_TESSELLATION
|
|
float _TessPhongStrength;
|
|
float _TessValue;
|
|
float _TessMin;
|
|
float _TessMax;
|
|
float _TessEdgeLength;
|
|
float _TessMaxDisp;
|
|
#endif
|
|
UNITY_TEXTURE_STREAMING_DEBUG_VARS;
|
|
CBUFFER_END
|
|
|
|
#ifdef SCENEPICKINGPASS
|
|
float4 _SelectionID;
|
|
#endif
|
|
|
|
#ifdef SCENESELECTIONPASS
|
|
int _ObjectId;
|
|
int _PassValue;
|
|
#endif
|
|
|
|
/*ase_globals*/
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
|
|
#endif
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Hair/Hair.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/MaterialUtilities.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl"
|
|
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl"
|
|
|
|
#if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS)
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl"
|
|
#endif
|
|
|
|
#ifdef HAVE_VFX_MODIFICATION
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/VisualEffectVertex.hlsl"
|
|
#endif
|
|
|
|
/*ase_pragma*/
|
|
|
|
struct AttributesMesh
|
|
{
|
|
float3 positionOS : POSITION;
|
|
float3 normalOS : NORMAL;
|
|
float4 tangentOS : TANGENT;
|
|
float3 previousPositionOS : TEXCOORD4;
|
|
float3 precomputedVelocity : TEXCOORD5;
|
|
/*ase_vdata:p=p;n=n;t=t;uv4=tc4;uv5=tc5*/
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
struct PackedVaryingsMeshToPS
|
|
{
|
|
SV_POSITION_QUALIFIERS float4 vmeshPositionCS : SV_Position;
|
|
float3 vmeshInterp00 : TEXCOORD0;
|
|
float3 vpassInterpolators0 : TEXCOORD1; //interpolators0
|
|
float3 vpassInterpolators1 : TEXCOORD2; //interpolators1
|
|
/*ase_interp(3,):sp=sp.xyzw*/
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
UNITY_VERTEX_OUTPUT_STEREO
|
|
#if defined(SHADER_STAGE_FRAGMENT) && defined(ASE_NEED_CULLFACE)
|
|
FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
|
|
#endif
|
|
};
|
|
|
|
/*ase_funcs*/
|
|
|
|
//Build Surface Data (Decal)
|
|
void ApplyDecalToSurfaceDataNoNormal(DecalSurfaceData decalSurfaceData, inout SurfaceData surfaceData)
|
|
{
|
|
surfaceData.diffuseColor.xyz = surfaceData.diffuseColor.xyz * decalSurfaceData.baseColor.w + decalSurfaceData.baseColor.xyz;
|
|
|
|
#ifdef DECALS_4RT
|
|
surfaceData.ambientOcclusion = surfaceData.ambientOcclusion * decalSurfaceData.MAOSBlend.y + decalSurfaceData.mask.y;
|
|
#endif
|
|
|
|
surfaceData.perceptualSmoothness = surfaceData.perceptualSmoothness * decalSurfaceData.mask.w + decalSurfaceData.mask.z;
|
|
}
|
|
|
|
void BuildSurfaceData(FragInputs fragInputs, inout SmoothSurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData, out float3 bentNormalWS)
|
|
{
|
|
ZERO_INITIALIZE(SurfaceData, surfaceData);
|
|
|
|
surfaceData.specularOcclusion = 1.0;
|
|
surfaceData.perceptualSmoothness = surfaceDescription.Smoothness;
|
|
surfaceData.materialFeatures = 0;
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_KAJIYA_KAY
|
|
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_HAIR_KAJIYA_KAY;
|
|
#endif
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_MARSCHNER
|
|
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_HAIR_MARSCHNER;
|
|
#endif
|
|
|
|
#ifdef _MATERIAL_FEATURE_HAIR_MARSCHNER_CINEMATIC
|
|
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_HAIR_MARSCHNER_CINEMATIC;
|
|
#endif
|
|
|
|
#ifdef _DOUBLESIDED_ON
|
|
float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
|
|
#else
|
|
float3 doubleSidedConstants = float3( 1.0, 1.0, 1.0 );
|
|
#endif
|
|
|
|
float3 normalTS = float3(0.0f, 0.0f, 1.0f);
|
|
normalTS = surfaceDescription.Normal;
|
|
|
|
#ifdef DECAL_NORMAL_BLENDING
|
|
normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS, fragInputs.tangentToWorld[0], fragInputs.tangentToWorld[1]);
|
|
|
|
#if HAVE_DECALS
|
|
if (_EnableDecals)
|
|
{
|
|
float alpha = 1.0;
|
|
alpha = surfaceDescription.Alpha;
|
|
|
|
DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
|
|
ApplyDecalToSurfaceNormal(decalSurfaceData, fragInputs.tangentToWorld[2], normalTS);
|
|
ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData);
|
|
}
|
|
#endif
|
|
|
|
GetNormalWS_SG(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants);
|
|
#else
|
|
GetNormalWS(fragInputs, normalTS, surfaceData.normalWS, doubleSidedConstants);
|
|
|
|
#if HAVE_DECALS
|
|
if (_EnableDecals)
|
|
{
|
|
float alpha = 1.0;
|
|
alpha = surfaceDescription.Alpha;
|
|
|
|
DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, fragInputs, alpha);
|
|
ApplyDecalToSurfaceNormal(decalSurfaceData, surfaceData.normalWS.xyz);
|
|
ApplyDecalToSurfaceDataNoNormal(decalSurfaceData, surfaceData);
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
surfaceData.geomNormalWS = fragInputs.tangentToWorld[2];
|
|
surfaceData.hairStrandDirectionWS = -fragInputs.tangentToWorld[1].xyz;
|
|
surfaceData.hairStrandDirectionWS = normalize(surfaceData.hairStrandDirectionWS);
|
|
|
|
#ifdef ASE_HAIRDIRECTION
|
|
surfaceData.hairStrandDirectionWS = TransformTangentToWorld(surfaceDescription.HairStrandDirection, fragInputs.tangentToWorld);
|
|
#endif
|
|
|
|
#if (_USE_LIGHT_FACING_NORMAL)
|
|
float3 viewFacingNormalWS = ComputeViewFacingNormal(V, surfaceData.hairStrandDirectionWS);
|
|
float3 N = viewFacingNormalWS;
|
|
#else
|
|
float3 N = surfaceData.normalWS;
|
|
#endif
|
|
|
|
bentNormalWS = surfaceData.normalWS;
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
#if !defined(SHADER_STAGE_RAY_TRACING)
|
|
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
|
|
{
|
|
#ifdef FRAG_INPUTS_USE_TEXCOORD0
|
|
surfaceData.diffuseColor = GET_TEXTURE_STREAMING_DEBUG(posInput.positionSS, fragInputs.texCoord0);
|
|
#else
|
|
surfaceData.diffuseColor = GET_TEXTURE_STREAMING_DEBUG_NO_UV(posInput.positionSS);
|
|
#endif
|
|
}
|
|
#endif
|
|
ApplyDebugToSurfaceData(fragInputs.tangentToWorld, surfaceData);
|
|
#endif
|
|
|
|
#if defined(_SPECULAR_OCCLUSION_CUSTOM)
|
|
#elif defined(_SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL)
|
|
surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness));
|
|
#elif defined(_AMBIENT_OCCLUSION) && defined(_SPECULAR_OCCLUSION_FROM_AO)
|
|
surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness));
|
|
#endif
|
|
|
|
#ifdef _ENABLE_GEOMETRIC_SPECULAR_AA
|
|
surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, fragInputs.tangentToWorld[2], surfaceDescription.SpecularAAScreenSpaceVariance, surfaceDescription.SpecularAAThreshold);
|
|
#endif
|
|
}
|
|
|
|
// Get Surface And BuiltinData
|
|
void GetSurfaceAndBuiltinData(SmoothSurfaceDescription surfaceDescription, FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData)
|
|
{
|
|
#ifdef LOD_FADE_CROSSFADE
|
|
LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x);
|
|
#endif
|
|
|
|
#ifdef _DOUBLESIDED_ON
|
|
float3 doubleSidedConstants = _DoubleSidedConstants.xyz;
|
|
#else
|
|
float3 doubleSidedConstants = float3(1.0, 1.0, 1.0);
|
|
#endif
|
|
ApplyDoubleSidedFlipOrMirror(fragInputs, doubleSidedConstants);
|
|
|
|
#ifdef _ALPHATEST_ON
|
|
DoAlphaTest( surfaceDescription.Alpha, surfaceDescription.AlphaClipThreshold );
|
|
#endif
|
|
|
|
#ifdef _ALPHATEST_SHADOW_ON
|
|
DoAlphaTest( surfaceDescription.Alpha, surfaceDescription.AlphaClipThresholdShadow);
|
|
#endif
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput);
|
|
#endif
|
|
|
|
float3 bentNormalWS;
|
|
BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData, bentNormalWS);
|
|
InitBuiltinData(posInput, surfaceDescription.Alpha, bentNormalWS, -fragInputs.tangentToWorld[2], fragInputs.texCoord1, fragInputs.texCoord2, builtinData);
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
builtinData.depthOffset = surfaceDescription.DepthOffset;
|
|
#endif
|
|
|
|
#ifdef DEBUG_DISPLAY
|
|
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
|
|
{
|
|
surfaceDescription.Alpha = 1.0f;
|
|
}
|
|
#endif
|
|
|
|
#ifdef _ALPHATEST_ON
|
|
builtinData.alphaClipTreshold = surfaceDescription.AlphaClipThreshold;
|
|
#endif
|
|
|
|
#ifdef UNITY_VIRTUAL_TEXTURING
|
|
builtinData.vtPackedFeedback = surfaceDescription.VTPackedFeedback;
|
|
#endif
|
|
|
|
#ifdef ASE_BAKEDGI
|
|
builtinData.bakeDiffuseLighting = surfaceDescription.BakedGI;
|
|
#endif
|
|
|
|
#ifdef ASE_BAKEDBACKGI
|
|
builtinData.backBakeDiffuseLighting = surfaceDescription.BakedBackGI;
|
|
#endif
|
|
|
|
builtinData.emissiveColor = surfaceDescription.Emission;
|
|
|
|
PostInitBuiltinData(V, posInput, surfaceData, builtinData);
|
|
}
|
|
|
|
AttributesMesh ApplyMeshModification(AttributesMesh inputMesh, float3 timeParameters, inout PackedVaryingsMeshToPS outputPackedVaryingsMeshToPS/*ase_vert_input*/ )
|
|
{
|
|
_TimeParameters.xyz = timeParameters;
|
|
/*ase_vert_code:inputMesh=AttributesMesh;outputPackedVaryingsMeshToPS=PackedVaryingsMeshToPS*/
|
|
|
|
#ifdef ASE_ABSOLUTE_VERTEX_POS
|
|
float3 defaultVertexValue = inputMesh.positionOS.xyz;
|
|
#else
|
|
float3 defaultVertexValue = float3( 0, 0, 0 );
|
|
#endif
|
|
float3 vertexValue = /*ase_vert_out:Vertex Offset;Float3;5;-1;_VertexOffset*/defaultVertexValue/*end*/;
|
|
|
|
#ifdef ASE_ABSOLUTE_VERTEX_POS
|
|
inputMesh.positionOS.xyz = vertexValue;
|
|
#else
|
|
inputMesh.positionOS.xyz += vertexValue;
|
|
#endif
|
|
inputMesh.normalOS = /*ase_vert_out:Vertex Normal;Float3;6;-1;_VertexNormal*/inputMesh.normalOS/*end*/;
|
|
inputMesh.tangentOS = /*ase_vert_out:Vertex Tangent;Float4;7;-1;_VertexTangent*/inputMesh.tangentOS/*end*/;
|
|
return inputMesh;
|
|
}
|
|
|
|
PackedVaryingsMeshToPS VertexFunction(AttributesMesh inputMesh)
|
|
{
|
|
PackedVaryingsMeshToPS outputPackedVaryingsMeshToPS = (PackedVaryingsMeshToPS)0;
|
|
AttributesMesh defaultMesh = inputMesh;
|
|
|
|
UNITY_SETUP_INSTANCE_ID(inputMesh);
|
|
UNITY_TRANSFER_INSTANCE_ID(inputMesh, outputPackedVaryingsMeshToPS);
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO( outputPackedVaryingsMeshToPS );
|
|
|
|
inputMesh = ApplyMeshModification( inputMesh, _TimeParameters.xyz, outputPackedVaryingsMeshToPS);
|
|
|
|
float3 positionRWS = TransformObjectToWorld(inputMesh.positionOS);
|
|
float3 normalWS = TransformObjectToWorldNormal(inputMesh.normalOS);
|
|
|
|
float3 VMESHpositionRWS = positionRWS;
|
|
float4 VMESHpositionCS = TransformWorldToHClip(positionRWS);
|
|
|
|
float4 VPASSpreviousPositionCS;
|
|
float4 VPASSpositionCS = mul(UNITY_MATRIX_UNJITTERED_VP, float4(VMESHpositionRWS, 1.0));
|
|
|
|
bool forceNoMotion = unity_MotionVectorsParams.y == 0.0;
|
|
if (forceNoMotion)
|
|
{
|
|
VPASSpreviousPositionCS = float4(0.0, 0.0, 0.0, 1.0);
|
|
}
|
|
else
|
|
{
|
|
bool hasDeformation = unity_MotionVectorsParams.x > 0.0;
|
|
float3 effectivePositionOS = (hasDeformation ? inputMesh.previousPositionOS : defaultMesh.positionOS);
|
|
#if defined(_ADD_PRECOMPUTED_VELOCITY)
|
|
effectivePositionOS -= inputMesh.precomputedVelocity;
|
|
#endif
|
|
|
|
#if defined(HAVE_MESH_MODIFICATION)
|
|
AttributesMesh previousMesh = defaultMesh;
|
|
previousMesh.positionOS = effectivePositionOS ;
|
|
PackedVaryingsMeshToPS test = (PackedVaryingsMeshToPS)0;
|
|
float3 curTime = _TimeParameters.xyz;
|
|
previousMesh = ApplyMeshModification(previousMesh, _LastTimeParameters.xyz, test);
|
|
_TimeParameters.xyz = curTime;
|
|
float3 previousPositionRWS = TransformPreviousObjectToWorld(previousMesh.positionOS);
|
|
#else
|
|
float3 previousPositionRWS = TransformPreviousObjectToWorld(effectivePositionOS);
|
|
#endif
|
|
|
|
#ifdef ATTRIBUTES_NEED_NORMAL
|
|
float3 normalWS = TransformPreviousObjectToWorldNormal(defaultMesh.normalOS);
|
|
#else
|
|
float3 normalWS = float3(0.0, 0.0, 0.0);
|
|
#endif
|
|
|
|
#if defined(HAVE_VERTEX_MODIFICATION)
|
|
ApplyVertexModification(inputMesh, normalWS, previousPositionRWS, _LastTimeParameters.xyz);
|
|
#endif
|
|
|
|
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
|
|
if (_TransparentCameraOnlyMotionVectors > 0)
|
|
{
|
|
previousPositionRWS = VMESHpositionRWS.xyz;
|
|
}
|
|
#endif
|
|
|
|
VPASSpreviousPositionCS = mul(UNITY_MATRIX_PREV_VP, float4(previousPositionRWS, 1.0));
|
|
}
|
|
|
|
outputPackedVaryingsMeshToPS.vmeshPositionCS = VMESHpositionCS;
|
|
outputPackedVaryingsMeshToPS.vmeshInterp00.xyz = VMESHpositionRWS;
|
|
|
|
outputPackedVaryingsMeshToPS.vpassInterpolators0 = float3(VPASSpositionCS.xyw);
|
|
outputPackedVaryingsMeshToPS.vpassInterpolators1 = float3(VPASSpreviousPositionCS.xyw);
|
|
return outputPackedVaryingsMeshToPS;
|
|
}
|
|
|
|
#if (defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS)) || defined(WRITE_RENDERING_LAYER)
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalPrepassBuffer.hlsl"
|
|
#endif
|
|
|
|
#if ( 0 ) // TEMPORARY: defined(ASE_TESSELLATION)
|
|
struct VertexControl
|
|
{
|
|
float3 positionOS : INTERNALTESSPOS;
|
|
float3 normalOS : NORMAL;
|
|
float4 tangentOS : TANGENT;
|
|
float3 previousPositionOS : TEXCOORD4;
|
|
float3 precomputedVelocity : TEXCOORD5;
|
|
/*ase_vcontrol*/
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
struct TessellationFactors
|
|
{
|
|
float edge[3] : SV_TessFactor;
|
|
float inside : SV_InsideTessFactor;
|
|
};
|
|
|
|
VertexControl Vert ( AttributesMesh v )
|
|
{
|
|
VertexControl o;
|
|
UNITY_SETUP_INSTANCE_ID(v);
|
|
UNITY_TRANSFER_INSTANCE_ID(v, o);
|
|
o.positionOS = v.positionOS;
|
|
o.normalOS = v.normalOS;
|
|
o.tangentOS = v.tangentOS;
|
|
o.previousPositionOS = v.previousPositionOS;
|
|
#if defined (_ADD_PRECOMPUTED_VELOCITY)
|
|
o.precomputedVelocity = v.precomputedVelocity;
|
|
#endif
|
|
/*ase_control_code:v=AttributesMesh;o=VertexControl*/
|
|
return o;
|
|
}
|
|
|
|
TessellationFactors TessellationFunction (InputPatch<VertexControl,3> v)
|
|
{
|
|
TessellationFactors o;
|
|
float4 tf = 1;
|
|
float tessValue = /*ase_inline_begin*/_TessValue/*ase_inline_end*/; float tessMin = /*ase_inline_begin*/_TessMin/*ase_inline_end*/; float tessMax = /*ase_inline_begin*/_TessMax/*ase_inline_end*/;
|
|
float edgeLength = /*ase_inline_begin*/_TessEdgeLength/*ase_inline_end*/; float tessMaxDisp = /*ase_inline_begin*/_TessMaxDisp/*ase_inline_end*/;
|
|
#if (SHADEROPTIONS_CAMERA_RELATIVE_RENDERING != 0)
|
|
float3 cameraPos = 0;
|
|
#else
|
|
float3 cameraPos = _WorldSpaceCameraPos;
|
|
#endif
|
|
#if defined(ASE_FIXED_TESSELLATION)
|
|
tf = FixedTess( tessValue );
|
|
#elif defined(ASE_DISTANCE_TESSELLATION)
|
|
tf = DistanceBasedTess(float4(v[0].positionOS,1), float4(v[1].positionOS,1), float4(v[2].positionOS,1), tessValue, tessMin, tessMax, GetObjectToWorldMatrix(), cameraPos );
|
|
#elif defined(ASE_LENGTH_TESSELLATION)
|
|
tf = EdgeLengthBasedTess(float4(v[0].positionOS,1), float4(v[1].positionOS,1), float4(v[2].positionOS,1), edgeLength, GetObjectToWorldMatrix(), cameraPos, _ScreenParams );
|
|
#elif defined(ASE_LENGTH_CULL_TESSELLATION)
|
|
tf = EdgeLengthBasedTessCull(float4(v[0].positionOS,1), float4(v[1].positionOS,1), float4(v[2].positionOS,1), edgeLength, tessMaxDisp, GetObjectToWorldMatrix(), cameraPos, _ScreenParams, _FrustumPlanes );
|
|
#endif
|
|
o.edge[0] = tf.x; o.edge[1] = tf.y; o.edge[2] = tf.z; o.inside = tf.w;
|
|
return o;
|
|
}
|
|
|
|
[domain("tri")]
|
|
[partitioning("fractional_odd")]
|
|
[outputtopology("triangle_cw")]
|
|
[patchconstantfunc("TessellationFunction")]
|
|
[outputcontrolpoints(3)]
|
|
VertexControl HullFunction(InputPatch<VertexControl, 3> patch, uint id : SV_OutputControlPointID)
|
|
{
|
|
return patch[id];
|
|
}
|
|
|
|
[domain("tri")]
|
|
PackedVaryingsMeshToPS DomainFunction(TessellationFactors factors, OutputPatch<VertexControl, 3> patch, float3 bary : SV_DomainLocation)
|
|
{
|
|
AttributesMesh o = (AttributesMesh) 0;
|
|
o.positionOS = patch[0].positionOS * bary.x + patch[1].positionOS * bary.y + patch[2].positionOS * bary.z;
|
|
o.normalOS = patch[0].normalOS * bary.x + patch[1].normalOS * bary.y + patch[2].normalOS * bary.z;
|
|
o.tangentOS = patch[0].tangentOS * bary.x + patch[1].tangentOS * bary.y + patch[2].tangentOS * bary.z;
|
|
o.previousPositionOS = patch[0].previousPositionOS * bary.x + patch[1].previousPositionOS * bary.y + patch[2].previousPositionOS * bary.z;
|
|
#if defined (_ADD_PRECOMPUTED_VELOCITY)
|
|
o.precomputedVelocity = patch[0].precomputedVelocity * bary.x + patch[1].precomputedVelocity * bary.y + patch[2].precomputedVelocity * bary.z;
|
|
#endif
|
|
/*ase_domain_code:patch=VertexControl;o=AttributesMesh;bary=SV_DomainLocation*/
|
|
#if defined(ASE_PHONG_TESSELLATION)
|
|
float3 pp[3];
|
|
for (int i = 0; i < 3; ++i)
|
|
pp[i] = o.positionOS.xyz - patch[i].normalOS * (dot(o.positionOS.xyz, patch[i].normalOS) - dot(patch[i].positionOS.xyz, patch[i].normalOS));
|
|
float phongStrength = /*ase_inline_begin*/_TessPhongStrength/*ase_inline_end*/;
|
|
o.positionOS.xyz = phongStrength * (pp[0]*bary.x + pp[1]*bary.y + pp[2]*bary.z) + (1.0f-phongStrength) * o.positionOS.xyz;
|
|
#endif
|
|
UNITY_TRANSFER_INSTANCE_ID(patch[0], o);
|
|
return VertexFunction(o);
|
|
}
|
|
#else
|
|
PackedVaryingsMeshToPS Vert ( AttributesMesh v )
|
|
{
|
|
return VertexFunction( v );
|
|
}
|
|
#endif
|
|
|
|
#if defined(WRITE_DECAL_BUFFER) && defined(WRITE_MSAA_DEPTH)
|
|
#define SV_TARGET_NORMAL SV_Target3
|
|
#elif defined(WRITE_DECAL_BUFFER) || defined(WRITE_MSAA_DEPTH)
|
|
#define SV_TARGET_NORMAL SV_Target2
|
|
#else
|
|
#define SV_TARGET_NORMAL SV_Target1
|
|
#endif
|
|
|
|
void Frag( PackedVaryingsMeshToPS packedInput
|
|
#ifdef WRITE_MSAA_DEPTH
|
|
, out float4 depthColor : SV_Target0
|
|
, out float4 outMotionVector : SV_Target1
|
|
#ifdef WRITE_DECAL_BUFFER
|
|
, out float4 outDecalBuffer : SV_Target2
|
|
#endif
|
|
#else
|
|
, out float4 outMotionVector : SV_Target0
|
|
#ifdef WRITE_DECAL_BUFFER
|
|
, out float4 outDecalBuffer : SV_Target1
|
|
#endif
|
|
#endif
|
|
|
|
#ifdef WRITE_NORMAL_BUFFER
|
|
, out float4 outNormalBuffer : SV_TARGET_NORMAL
|
|
#endif
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
, out float outputDepth : DEPTH_OFFSET_SEMANTIC
|
|
#endif
|
|
/*ase_frag_input*/
|
|
)
|
|
{
|
|
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX( packedInput );
|
|
UNITY_SETUP_INSTANCE_ID( packedInput );
|
|
FragInputs input;
|
|
ZERO_INITIALIZE(FragInputs, input);
|
|
input.tangentToWorld = k_identity3x3;
|
|
input.positionSS = packedInput.vmeshPositionCS;
|
|
input.positionRWS = packedInput.vmeshInterp00.xyz;
|
|
|
|
PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS);
|
|
|
|
/*ase_local_var:wvd*/float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
|
|
|
|
SurfaceData surfaceData;
|
|
BuiltinData builtinData;
|
|
|
|
SmoothSurfaceDescription surfaceDescription = (SmoothSurfaceDescription)0;
|
|
/*ase_frag_code:packedInput=PackedVaryingsMeshToPS*/
|
|
surfaceDescription.Normal = /*ase_frag_out:Normal;Float3;0;-1;_Normal*/float3( 0, 0, 1 )/*end*/;
|
|
surfaceDescription.Smoothness = /*ase_frag_out:Smoothness;Float;1;-1;_Smoothness*/1/*end*/;
|
|
surfaceDescription.Alpha = /*ase_frag_out:Alpha;Float;2;-1;_Alpha*/1/*end*/;
|
|
|
|
#ifdef _ALPHATEST_ON
|
|
surfaceDescription.AlphaClipThreshold = /*ase_frag_out:Alpha Clip Threshold;Float;3;-1;_AlphaClip*/_AlphaCutoff/*end*/;
|
|
#endif
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
surfaceDescription.DepthOffset = /*ase_frag_out:Depth Offset;Float;4;-1;_DepthOffset*/0/*end*/;
|
|
#endif
|
|
|
|
GetSurfaceAndBuiltinData(surfaceDescription, input, V, posInput, surfaceData, builtinData);
|
|
|
|
float4 VPASSpositionCS = float4(packedInput.vpassInterpolators0.xy, 0.0, packedInput.vpassInterpolators0.z);
|
|
float4 VPASSpreviousPositionCS = float4(packedInput.vpassInterpolators1.xy, 0.0, packedInput.vpassInterpolators1.z);
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
VPASSpositionCS.w += builtinData.depthOffset;
|
|
VPASSpreviousPositionCS.w += builtinData.depthOffset;
|
|
#endif
|
|
|
|
float2 motionVector = CalculateMotionVector( VPASSpositionCS, VPASSpreviousPositionCS );
|
|
EncodeMotionVector( motionVector * 0.5, outMotionVector );
|
|
|
|
bool forceNoMotion = unity_MotionVectorsParams.y == 0.0;
|
|
if( forceNoMotion )
|
|
outMotionVector = float4( 2.0, 0.0, 0.0, 0.0 );
|
|
|
|
#ifdef WRITE_MSAA_DEPTH
|
|
depthColor = packedInput.vmeshPositionCS.z;
|
|
depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold);
|
|
#endif
|
|
|
|
#if defined(WRITE_NORMAL_BUFFER)
|
|
EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer);
|
|
#endif
|
|
|
|
#if defined(WRITE_DECAL_BUFFER)
|
|
DecalPrepassData decalPrepassData;
|
|
#ifdef _DISABLE_DECALS
|
|
ZERO_INITIALIZE(DecalPrepassData, decalPrepassData);
|
|
#else
|
|
decalPrepassData.geomNormalWS = surfaceData.geomNormalWS;
|
|
#endif
|
|
decalPrepassData.renderingLayerMask = GetMeshRenderingLayerMask();
|
|
EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer);
|
|
#endif
|
|
|
|
#ifdef _DEPTHOFFSET_ON
|
|
outputDepth = posInput.deviceDepth;
|
|
#endif
|
|
}
|
|
|
|
ENDHLSL
|
|
}
|
|
/*ase_pass_end*/
|
|
}
|
|
CustomEditor "Rendering.HighDefinition.LightingShaderGraphGUI"
|
|
FallBack "Hidden/Shader Graph/FallbackError"
|
|
}
|