Remy
7 年前
当前提交
d2dab3d0
共有 6 个文件被更改,包括 1025 次插入 和 0 次删除
-
337ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/SurfaceLit.shader
-
9ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/SurfaceLit.shader.meta
-
240ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/SurfaceLitData.hlsl
-
9ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/SurfaceLitData.hlsl.meta
-
420ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/SurfaceLitDataIDX.hlsl
-
10ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/SurfaceLitDataIDX.hlsl.meta
|
|||
Shader "HDRenderPipeline/Custom/SurfaceLit" |
|||
{ |
|||
Properties |
|||
{ |
|||
// Following set of parameters represent the parameters node inside the MaterialGraph. |
|||
// They are use to fill a SurfaceData. With a MaterialGraph this should not exist. |
|||
|
|||
// Reminder. Color here are in linear but the UI (color picker) do the conversion sRGB to linear |
|||
_BaseColor("BaseColor", Color) = (1,1,1,1) |
|||
_BaseColorMap("BaseColorMap", 2D) = "white" {} |
|||
|
|||
_Metallic("_Metallic", Range(0.0, 1.0)) = 0 |
|||
_Smoothness("Smoothness", Range(0.0, 1.0)) = 1.0 |
|||
_MaskMap("MaskMap", 2D) = "white" {} |
|||
_SmoothnessRemapMin("SmoothnessRemapMin", Float) = 0.0 |
|||
_SmoothnessRemapMax("SmoothnessRemapMax", Float) = 1.0 |
|||
_AORemapMin("AORemapMin", Float) = 0.0 |
|||
_AORemapMax("AORemapMax", Float) = 1.0 |
|||
|
|||
_NormalMap("NormalMap", 2D) = "bump" {} // Tangent space normal map |
|||
_NormalMapOS("NormalMapOS", 2D) = "white" {} // Object space normal map - no good default value |
|||
_NormalScale("_NormalScale", Range(0.0, 2.0)) = 1 |
|||
|
|||
_BentNormalMap("_BentNormalMap", 2D) = "bump" {} |
|||
_BentNormalMapOS("_BentNormalMapOS", 2D) = "white" {} |
|||
|
|||
_HeightMap("HeightMap", 2D) = "black" {} |
|||
// Caution: Default value of _HeightAmplitude must be (_HeightMax - _HeightMin) * 0.01 |
|||
// Those two properties are computed from the ones exposed in the UI and depends on the displaement mode so they are separate because we don't want to lose information upon displacement mode change. |
|||
[HideInInspector] _HeightAmplitude("Height Amplitude", Float) = 0.02 // In world units. This will be computed in the UI. |
|||
[HideInInspector] _HeightCenter("Height Center", Range(0.0, 1.0)) = 0.5 // In texture space |
|||
|
|||
[Enum(MinMax, 0, Amplitude, 1)] _HeightMapParametrization("Heightmap Parametrization", Int) = 0 |
|||
// These parameters are for vertex displacement/Tessellation |
|||
_HeightOffset("Height Offset", Float) = 0 |
|||
// MinMax mode |
|||
_HeightMin("Heightmap Min", Float) = -1 |
|||
_HeightMax("Heightmap Max", Float) = 1 |
|||
// Amplitude mode |
|||
_HeightTessAmplitude("Amplitude", Float) = 2.0 // in Centimeters |
|||
_HeightTessCenter("Height Center", Range(0.0, 1.0)) = 0.5 // In texture space |
|||
|
|||
// These parameters are for pixel displacement |
|||
_HeightPoMAmplitude("Height Amplitude", Float) = 2.0 // In centimeters |
|||
|
|||
_DetailMap("DetailMap", 2D) = "black" {} |
|||
_DetailAlbedoScale("_DetailAlbedoScale", Range(0.0, 2.0)) = 1 |
|||
_DetailNormalScale("_DetailNormalScale", Range(0.0, 2.0)) = 1 |
|||
_DetailSmoothnessScale("_DetailSmoothnessScale", Range(0.0, 2.0)) = 1 |
|||
|
|||
_TangentMap("TangentMap", 2D) = "bump" {} |
|||
_TangentMapOS("TangentMapOS", 2D) = "white" {} |
|||
_Anisotropy("Anisotropy", Range(-1.0, 1.0)) = 0 |
|||
_AnisotropyMap("AnisotropyMap", 2D) = "white" {} |
|||
|
|||
_DiffusionProfile("Diffusion Profile", Int) = 0 |
|||
_SubsurfaceMask("Subsurface Radius", Range(0.0, 1.0)) = 1.0 |
|||
_SubsurfaceMaskMap("Subsurface Radius Map", 2D) = "white" {} |
|||
_Thickness("Thickness", Range(0.0, 1.0)) = 1.0 |
|||
_ThicknessMap("Thickness Map", 2D) = "white" {} |
|||
_ThicknessRemap("Thickness Remap", Vector) = (0, 1, 0, 0) |
|||
|
|||
_IridescenceThickness("Iridescence Thickness", Range(0.0, 1.0)) = 1.0 |
|||
_IridescenceThicknessMap("Iridescence Thickness Map", 2D) = "white" {} |
|||
_IridescenceThicknessRemap("Iridescence Thickness Remap", Vector) = (0, 1, 0, 0) |
|||
_IridescenceMask("Iridescence Mask", Range(0.0, 1.0)) = 1.0 |
|||
_IridescenceMaskMap("Iridescence Mask Map", 2D) = "white" {} |
|||
|
|||
_CoatMask("Coat Mask", Range(0.0, 1.0)) = 0.0 |
|||
_CoatMaskMap("CoatMaskMap", 2D) = "white" {} |
|||
|
|||
[ToggleUI] _EnergyConservingSpecularColor("_EnergyConservingSpecularColor", Float) = 1.0 |
|||
_SpecularColor("SpecularColor", Color) = (1, 1, 1, 1) |
|||
_SpecularColorMap("SpecularColorMap", 2D) = "white" {} |
|||
|
|||
// Following options are for the GUI inspector and different from the input parameters above |
|||
// These option below will cause different compilation flag. |
|||
[ToggleUI] _EnableSpecularOcclusion("Enable specular occlusion", Float) = 0.0 |
|||
|
|||
_EmissiveColor("EmissiveColor", Color) = (1, 1, 1) |
|||
_EmissiveColorMap("EmissiveColorMap", 2D) = "white" {} |
|||
_EmissiveIntensity("EmissiveIntensity", Float) = 0 |
|||
[ToggleUI] _AlbedoAffectEmissive("Albedo Affect Emissive", Float) = 0.0 |
|||
|
|||
_DistortionVectorMap("DistortionVectorMap", 2D) = "black" {} |
|||
[ToggleUI] _DistortionEnable("Enable Distortion", Float) = 0.0 |
|||
[ToggleUI] _DistortionDepthTest("Distortion Depth Test Enable", Float) = 1.0 |
|||
[Enum(Add, 0, Multiply, 1)] _DistortionBlendMode("Distortion Blend Mode", Int) = 0 |
|||
[HideInInspector] _DistortionSrcBlend("Distortion Blend Src", Int) = 0 |
|||
[HideInInspector] _DistortionDstBlend("Distortion Blend Dst", Int) = 0 |
|||
[HideInInspector] _DistortionBlurSrcBlend("Distortion Blur Blend Src", Int) = 0 |
|||
[HideInInspector] _DistortionBlurDstBlend("Distortion Blur Blend Dst", Int) = 0 |
|||
[HideInInspector] _DistortionBlurBlendMode("Distortion Blur Blend Mode", Int) = 0 |
|||
_DistortionScale("Distortion Scale", Float) = 1 |
|||
_DistortionVectorScale("Distortion Vector Scale", Float) = 2 |
|||
_DistortionVectorBias("Distortion Vector Bias", Float) = -1 |
|||
_DistortionBlurScale("Distortion Blur Scale", Float) = 1 |
|||
_DistortionBlurRemapMin("DistortionBlurRemapMin", Float) = 0.0 |
|||
_DistortionBlurRemapMax("DistortionBlurRemapMax", Float) = 1.0 |
|||
|
|||
[ToggleUI] _AlphaCutoffEnable("Alpha Cutoff Enable", Float) = 0.0 |
|||
_AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5 |
|||
_AlphaCutoffPrepass("_AlphaCutoffPrepass", Range(0.0, 1.0)) = 0.5 |
|||
_AlphaCutoffPostpass("_AlphaCutoffPostpass", Range(0.0, 1.0)) = 0.5 |
|||
[ToggleUI] _TransparentDepthPrepassEnable("_TransparentDepthPrepassEnable", Float) = 0.0 |
|||
[ToggleUI] _TransparentBackfaceEnable("_TransparentBackfaceEnable", Float) = 0.0 |
|||
[ToggleUI] _TransparentDepthPostpassEnable("_TransparentDepthPostpassEnable", Float) = 0.0 |
|||
_TransparentSortPriority("_TransparentSortPriority", Float) = 0 |
|||
|
|||
// Transparency |
|||
[Enum(None, 0, Plane, 1, Sphere, 2)]_RefractionMode("Refraction Mode", Int) = 0 |
|||
_Ior("Index Of Refraction", Range(1.0, 2.5)) = 1.0 |
|||
_ThicknessMultiplier("Thickness Multiplier", Float) = 1.0 |
|||
_TransmittanceColor("Transmittance Color", Color) = (1.0, 1.0, 1.0) |
|||
_TransmittanceColorMap("TransmittanceColorMap", 2D) = "white" {} |
|||
_ATDistance("Transmittance Absorption Distance", Float) = 1.0 |
|||
[ToggleUI] _PreRefractionPass("PreRefractionPass", Float) = 0.0 |
|||
|
|||
// Stencil state |
|||
[HideInInspector] _StencilRef("_StencilRef", Int) = 2 // StencilLightingUsage.RegularLighting (fixed at compile time) |
|||
[HideInInspector] _StencilWriteMask("_StencilWriteMask", Int) = 7 // StencilMask.Lighting (fixed at compile time) |
|||
[HideInInspector] _StencilRefMV("_StencilRefMV", Int) = 128 // StencilLightingUsage.RegularLighting (fixed at compile time) |
|||
[HideInInspector] _StencilWriteMaskMV("_StencilWriteMaskMV", Int) = 128 // StencilMask.ObjectsVelocity (fixed at compile time) |
|||
|
|||
// Blending state |
|||
[HideInInspector] _SurfaceType("__surfacetype", Float) = 0.0 |
|||
[HideInInspector] _BlendMode("__blendmode", Float) = 0.0 |
|||
[HideInInspector] _SrcBlend("__src", Float) = 1.0 |
|||
[HideInInspector] _DstBlend("__dst", Float) = 0.0 |
|||
[HideInInspector] _ZWrite("__zw", Float) = 1.0 |
|||
[HideInInspector] _CullMode("__cullmode", Float) = 2.0 |
|||
[HideInInspector] _CullModeForward("__cullmodeForward", Float) = 2.0 // This mode is dedicated to Forward to correctly handle backface then front face rendering thin transparent |
|||
[HideInInspector] _ZTestDepthEqualForOpaque("_ZTestDepthEqualForOpaque", Int) = 4 // Less equal |
|||
[HideInInspector] _ZTestModeDistortion("_ZTestModeDistortion", Int) = 8 |
|||
|
|||
[ToggleUI] _EnableFogOnTransparent("Enable Fog", Float) = 1.0 |
|||
[ToggleUI] _EnableBlendModePreserveSpecularLighting("Enable Blend Mode Preserve Specular Lighting", Float) = 1.0 |
|||
|
|||
[ToggleUI] _DoubleSidedEnable("Double sided enable", Float) = 0.0 |
|||
[Enum(Flip, 0, Mirror, 1, None, 2)] _DoubleSidedNormalMode("Double sided normal mode", Float) = 1 |
|||
[HideInInspector] _DoubleSidedConstants("_DoubleSidedConstants", Vector) = (1, 1, -1, 0) |
|||
|
|||
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3, Planar, 4, Triplanar, 5)] _UVBase("UV Set for base", Float) = 0 |
|||
_TexWorldScale("Scale to apply on world coordinate", Float) = 1.0 |
|||
[HideInInspector] _InvTilingScale("Inverse tiling scale = 2 / (abs(_BaseColorMap_ST.x) + abs(_BaseColorMap_ST.y))", Float) = 1 |
|||
[HideInInspector] _UVMappingMask("_UVMappingMask", Color) = (1, 0, 0, 0) |
|||
[Enum(TangentSpace, 0, ObjectSpace, 1)] _NormalMapSpace("NormalMap space", Float) = 0 |
|||
|
|||
// Following enum should be material feature flags (i.e bitfield), however due to Gbuffer encoding constrain many combination exclude each other |
|||
// so we use this enum as "material ID" which can be interpreted as preset of bitfield of material feature |
|||
// The only material feature flag that can be added in all cases is clear coat |
|||
[Enum(Subsurface Scattering, 0, Standard, 1, Anisotropy, 2, Iridescence, 3, Specular Color, 4, Translucent, 5)] _MaterialID("MaterialId", Int) = 1 // MaterialId.Standard |
|||
[ToggleUI] _TransmissionEnable("_TransmissionEnable", Float) = 1.0 |
|||
|
|||
[Enum(None, 0, Vertex displacement, 1, Pixel displacement, 2)] _DisplacementMode("DisplacementMode", Int) = 0 |
|||
[ToggleUI] _DisplacementLockObjectScale("displacement lock object scale", Float) = 1.0 |
|||
[ToggleUI] _DisplacementLockTilingScale("displacement lock tiling scale", Float) = 1.0 |
|||
[ToggleUI] _DepthOffsetEnable("Depth Offset View space", Float) = 0.0 |
|||
|
|||
[ToggleUI] _EnableMotionVectorForVertexAnimation("EnableMotionVectorForVertexAnimation", Float) = 0.0 |
|||
|
|||
_PPDMinSamples("Min sample for POM", Range(1.0, 64.0)) = 5 |
|||
_PPDMaxSamples("Max sample for POM", Range(1.0, 64.0)) = 15 |
|||
_PPDLodThreshold("Start lod to fade out the POM effect", Range(0.0, 16.0)) = 5 |
|||
_PPDPrimitiveLength("Primitive length for POM", Float) = 1 |
|||
_PPDPrimitiveWidth("Primitive width for POM", Float) = 1 |
|||
[HideInInspector] _InvPrimScale("Inverse primitive scale for non-planar POM", Vector) = (1, 1, 0, 0) |
|||
|
|||
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3)] _UVDetail("UV Set for detail", Float) = 0 |
|||
[HideInInspector] _UVDetailsMappingMask("_UVDetailsMappingMask", Color) = (1, 0, 0, 0) |
|||
[ToggleUI] _LinkDetailsWithBase("LinkDetailsWithBase", Float) = 1.0 |
|||
|
|||
[Enum(Use Emissive Color, 0, Use Emissive Mask, 1)] _EmissiveColorMode("Emissive color mode", Float) = 1 |
|||
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3, Planar, 4, Triplanar, 5)] _UVEmissive("UV Set for emissive", Float) = 0 |
|||
_TexWorldScaleEmissive("Scale to apply on world coordinate", Float) = 1.0 |
|||
[HideInInspector] _UVMappingMaskEmissive("_UVMappingMaskEmissive", Color) = (1, 0, 0, 0) |
|||
|
|||
// Wind |
|||
[ToggleUI] _EnableWind("Enable Wind", Float) = 0.0 |
|||
_InitialBend("Initial Bend", float) = 1.0 |
|||
_Stiffness("Stiffness", float) = 1.0 |
|||
_Drag("Drag", float) = 1.0 |
|||
_ShiverDrag("Shiver Drag", float) = 0.2 |
|||
_ShiverDirectionality("Shiver Directionality", Range(0.0, 1.0)) = 0.5 |
|||
|
|||
// Caution: C# code in BaseLitUI.cs call LightmapEmissionFlagsProperty() which assume that there is an existing "_EmissionColor" |
|||
// value that exist to identify if the GI emission need to be enabled. |
|||
// In our case we don't use such a mechanism but need to keep the code quiet. We declare the value and always enable it. |
|||
// TODO: Fix the code in legacy unity so we can customize the beahvior for GI |
|||
_EmissionColor("Color", Color) = (1, 1, 1) |
|||
|
|||
// HACK: GI Baking system relies on some properties existing in the shader ("_MainTex", "_Cutoff" and "_Color") for opacity handling, so we need to store our version of those parameters in the hard-coded name the GI baking system recognizes. |
|||
_MainTex("Albedo", 2D) = "white" {} |
|||
_Color("Color", Color) = (1,1,1,1) |
|||
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5 |
|||
|
|||
[ToggleUI] _SupportDBuffer("Support DBuffer", Float) = 1.0 |
|||
} |
|||
|
|||
HLSLINCLUDE |
|||
|
|||
#pragma target 4.5 |
|||
#pragma only_renderers d3d11 ps4 xboxone vulkan metal |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Variant |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#pragma shader_feature _ALPHATEST_ON |
|||
#pragma shader_feature _DEPTHOFFSET_ON |
|||
#pragma shader_feature _DOUBLESIDED_ON |
|||
#pragma shader_feature _ _VERTEX_DISPLACEMENT _PIXEL_DISPLACEMENT |
|||
#pragma shader_feature _VERTEX_DISPLACEMENT_LOCK_OBJECT_SCALE |
|||
#pragma shader_feature _DISPLACEMENT_LOCK_TILING_SCALE |
|||
#pragma shader_feature _PIXEL_DISPLACEMENT_LOCK_OBJECT_SCALE |
|||
#pragma shader_feature _VERTEX_WIND |
|||
#pragma shader_feature _ _REFRACTION_PLANE _REFRACTION_SPHERE |
|||
|
|||
#pragma shader_feature _ _EMISSIVE_MAPPING_PLANAR _EMISSIVE_MAPPING_TRIPLANAR |
|||
#pragma shader_feature _ _MAPPING_PLANAR _MAPPING_TRIPLANAR |
|||
#pragma shader_feature _NORMALMAP_TANGENT_SPACE |
|||
#pragma shader_feature _ _REQUIRE_UV2 _REQUIRE_UV3 |
|||
|
|||
#pragma shader_feature _NORMALMAP |
|||
#pragma shader_feature _MASKMAP |
|||
#pragma shader_feature _BENTNORMALMAP |
|||
#pragma shader_feature _EMISSIVE_COLOR_MAP |
|||
#pragma shader_feature _ENABLESPECULAROCCLUSION |
|||
#pragma shader_feature _HEIGHTMAP |
|||
#pragma shader_feature _TANGENTMAP |
|||
#pragma shader_feature _ANISOTROPYMAP |
|||
#pragma shader_feature _DETAIL_MAP |
|||
#pragma shader_feature _SUBSURFACE_MASK_MAP |
|||
#pragma shader_feature _THICKNESSMAP |
|||
#pragma shader_feature _IRIDESCENCE_THICKNESSMAP |
|||
#pragma shader_feature _SPECULARCOLORMAP |
|||
#pragma shader_feature _TRANSMITTANCECOLORMAP |
|||
|
|||
#pragma shader_feature _DISABLE_DBUFFER |
|||
|
|||
// Keyword for transparent |
|||
#pragma shader_feature _SURFACE_TYPE_TRANSPARENT |
|||
#pragma shader_feature _ _BLENDMODE_ALPHA _BLENDMODE_ADD _BLENDMODE_PRE_MULTIPLY |
|||
#pragma shader_feature _BLENDMODE_PRESERVE_SPECULAR_LIGHTING |
|||
#pragma shader_feature _ENABLE_FOG_ON_TRANSPARENT |
|||
|
|||
// MaterialFeature are used as shader feature to allow compiler to optimize properly |
|||
#pragma shader_feature _MATERIAL_FEATURE_SUBSURFACE_SCATTERING |
|||
#pragma shader_feature _MATERIAL_FEATURE_TRANSMISSION |
|||
#pragma shader_feature _MATERIAL_FEATURE_ANISOTROPY |
|||
#pragma shader_feature _MATERIAL_FEATURE_CLEAR_COAT |
|||
#pragma shader_feature _MATERIAL_FEATURE_IRIDESCENCE |
|||
#pragma shader_feature _MATERIAL_FEATURE_SPECULAR_COLOR |
|||
|
|||
// enable dithering LOD crossfade |
|||
#pragma multi_compile _ LOD_FADE_CROSSFADE |
|||
|
|||
//enable GPU instancing support |
|||
#pragma multi_compile_instancing |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Define |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl |
|||
// Use surface gradient normal mapping as it handle correctly triplanar normal mapping and multiple UVSet |
|||
#define SURFACE_GRADIENT |
|||
// This shader support vertex modification |
|||
#define HAVE_VERTEX_MODIFICATION |
|||
|
|||
// If we use subsurface scattering, enable output split lighting (for forward pass) |
|||
#if defined(_MATERIAL_FEATURE_SUBSURFACE_SCATTERING) && !defined(_SURFACE_TYPE_TRANSPARENT) |
|||
#define OUTPUT_SPLIT_LIGHTING |
|||
#endif |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Include |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#include "CoreRP/ShaderLibrary/Common.hlsl" |
|||
#include "../../ShaderPass/FragInputs.hlsl" |
|||
#include "../../ShaderPass/ShaderPass.cs.hlsl" |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// variable declaration |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#include "../../Material/Lit/LitProperties.hlsl" |
|||
|
|||
// All our shaders use same name for entry point |
|||
#pragma vertex Vert |
|||
#pragma fragment Frag |
|||
ENDHLSL |
|||
|
|||
SubShader |
|||
{ |
|||
// This tags allow to use the shader replacement features |
|||
Tags{ "RenderPipeline" = "HDRenderPipeline" "RenderType" = "HDLitShader" } |
|||
|
|||
// Caution: The outline selection in the editor use the vertex shader/hull/domain shader of the first pass declare. So it should not bethe meta pass. |
|||
Pass |
|||
{ |
|||
Name "GBuffer" // Name is not used |
|||
Tags{ "LightMode" = "GBuffer" } // This will be only for opaque object based on the RenderQueue index |
|||
|
|||
Cull[_CullMode] |
|||
|
|||
Stencil |
|||
{ |
|||
WriteMask[_StencilWriteMask] |
|||
Ref[_StencilRef] |
|||
Comp Always |
|||
Pass Replace |
|||
} |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#pragma multi_compile _ DEBUG_DISPLAY |
|||
#pragma multi_compile _ LIGHTMAP_ON |
|||
#pragma multi_compile _ DIRLIGHTMAP_COMBINED |
|||
#pragma multi_compile _ DYNAMICLIGHTMAP_ON |
|||
#pragma multi_compile _ SHADOWS_SHADOWMASK |
|||
|
|||
#define SHADERPASS SHADERPASS_GBUFFER |
|||
#include "../../ShaderVariables.hlsl" |
|||
#ifdef DEBUG_DISPLAY |
|||
#include "../../Debug/DebugDisplay.hlsl" |
|||
#endif |
|||
#include "../../Material/Material.hlsl" |
|||
#include "ShaderPass/LitSharePass.hlsl" |
|||
#include "SurfaceLitData.hlsl" |
|||
#include "../../ShaderPass/ShaderPassGBuffer.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 634b604aca541794cb49107aa7a42248 |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
//------------------------------------------------------------------------------------- |
|||
// Fill SurfaceData/Builtin data function |
|||
//------------------------------------------------------------------------------------- |
|||
#include "CoreRP/ShaderLibrary/Sampling/SampleUVMapping.hlsl" |
|||
#include "../MaterialUtilities.hlsl" |
|||
#include "../Decal/DecalUtilities.hlsl" |
|||
|
|||
// TODO: move this function to commonLighting.hlsl once validated it work correctly |
|||
float GetSpecularOcclusionFromBentAO(float3 V, float3 bentNormalWS, SurfaceData surfaceData) |
|||
{ |
|||
// Retrieve cone angle |
|||
// Ambient occlusion is cosine weighted, thus use following equation. See slide 129 |
|||
float cosAv = sqrt(1.0 - surfaceData.ambientOcclusion); |
|||
float roughness = max(PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness), 0.01); // Clamp to 0.01 to avoid edge cases |
|||
float cosAs = exp2((-log(10.0)/log(2.0)) * Sq(roughness)); |
|||
float cosB = dot(bentNormalWS, reflect(-V, surfaceData.normalWS)); |
|||
|
|||
return SphericalCapIntersectionSolidArea(cosAv, cosAs, cosB) / (TWO_PI * (1.0 - cosAs)); |
|||
} |
|||
|
|||
// Struct that gather UVMapping info of all layers + common calculation |
|||
// This is use to abstract the mapping that can differ on layers |
|||
struct LayerTexCoord |
|||
{ |
|||
#ifndef LAYERED_LIT_SHADER |
|||
UVMapping base; |
|||
UVMapping details; |
|||
#else |
|||
// Regular texcoord |
|||
UVMapping base0; |
|||
UVMapping base1; |
|||
UVMapping base2; |
|||
UVMapping base3; |
|||
|
|||
UVMapping details0; |
|||
UVMapping details1; |
|||
UVMapping details2; |
|||
UVMapping details3; |
|||
|
|||
// Dedicated for blend mask |
|||
UVMapping blendMask; |
|||
#endif |
|||
|
|||
// Store information that will be share by all UVMapping |
|||
float3 vertexNormalWS; // TODO: store also object normal map for object triplanar |
|||
float3 triplanarWeights; |
|||
|
|||
#ifdef SURFACE_GRADIENT |
|||
// tangent basis for each UVSet - up to 4 for now |
|||
float3 vertexTangentWS0, vertexBitangentWS0; |
|||
float3 vertexTangentWS1, vertexBitangentWS1; |
|||
float3 vertexTangentWS2, vertexBitangentWS2; |
|||
float3 vertexTangentWS3, vertexBitangentWS3; |
|||
#endif |
|||
}; |
|||
|
|||
#ifdef SURFACE_GRADIENT |
|||
void GenerateLayerTexCoordBasisTB(FragInputs input, inout LayerTexCoord layerTexCoord) |
|||
{ |
|||
float3 vertexNormalWS = input.worldToTangent[2]; |
|||
|
|||
layerTexCoord.vertexTangentWS0 = input.worldToTangent[0]; |
|||
layerTexCoord.vertexBitangentWS0 = input.worldToTangent[1]; |
|||
|
|||
// TODO: We should use relative camera position here - This will be automatic when we will move to camera relative space. |
|||
float3 dPdx = ddx_fine(input.positionWS); |
|||
float3 dPdy = ddy_fine(input.positionWS); |
|||
|
|||
float3 sigmaX = dPdx - dot(dPdx, vertexNormalWS) * vertexNormalWS; |
|||
float3 sigmaY = dPdy - dot(dPdy, vertexNormalWS) * vertexNormalWS; |
|||
//float flipSign = dot(sigmaY, cross(vertexNormalWS, sigmaX) ) ? -1.0 : 1.0; |
|||
float flipSign = dot(dPdy, cross(vertexNormalWS, dPdx)) < 0.0 ? -1.0 : 1.0; // gives same as the commented out line above |
|||
|
|||
// TODO: Optimize! The compiler will not be able to remove the tangent space that are not use because it can't know due to our UVMapping constant we use for both base and details |
|||
// To solve this we should track which UVSet is use for normal mapping... Maybe not as simple as it sounds |
|||
SurfaceGradientGenBasisTB(vertexNormalWS, sigmaX, sigmaY, flipSign, input.texCoord1, layerTexCoord.vertexTangentWS1, layerTexCoord.vertexBitangentWS1); |
|||
#if defined(_REQUIRE_UV2) || defined(_REQUIRE_UV3) |
|||
SurfaceGradientGenBasisTB(vertexNormalWS, sigmaX, sigmaY, flipSign, input.texCoord2, layerTexCoord.vertexTangentWS2, layerTexCoord.vertexBitangentWS2); |
|||
#endif |
|||
#if defined(_REQUIRE_UV3) |
|||
SurfaceGradientGenBasisTB(vertexNormalWS, sigmaX, sigmaY, flipSign, input.texCoord3, layerTexCoord.vertexTangentWS3, layerTexCoord.vertexBitangentWS3); |
|||
#endif |
|||
} |
|||
#endif |
|||
|
|||
#ifndef LAYERED_LIT_SHADER |
|||
|
|||
// Want to use only one sampler for normalmap/bentnormalmap either we use OS or TS. And either we have normal map or bent normal or both. |
|||
#ifdef _NORMALMAP_TANGENT_SPACE |
|||
#if defined(_NORMALMAP) |
|||
#define SAMPLER_NORMALMAP_IDX sampler_NormalMap |
|||
#elif defined(_BENTNORMALMAP) |
|||
#define SAMPLER_NORMALMAP_IDX sampler_BentNormalMap |
|||
#endif |
|||
#else |
|||
#if defined(_NORMALMAP) |
|||
#define SAMPLER_NORMALMAP_IDX sampler_NormalMapOS |
|||
#elif defined(_BENTNORMALMAP) |
|||
#define SAMPLER_NORMALMAP_IDX sampler_BentNormalMapOS |
|||
#endif |
|||
#endif |
|||
|
|||
#define SAMPLER_DETAILMAP_IDX sampler_DetailMap |
|||
#define SAMPLER_MASKMAP_IDX sampler_MaskMap |
|||
#define SAMPLER_HEIGHTMAP_IDX sampler_HeightMap |
|||
|
|||
#define SAMPLER_SUBSURFACE_MASKMAP_IDX sampler_SubsurfaceMaskMap |
|||
#define SAMPLER_THICKNESSMAP_IDX sampler_ThicknessMap |
|||
|
|||
// include LitDataIndividualLayer to define GetSurfaceData |
|||
#define LAYER_INDEX 0 |
|||
#define ADD_IDX(Name) Name |
|||
#define ADD_ZERO_IDX(Name) Name |
|||
#ifdef _NORMALMAP |
|||
#define _NORMALMAP_IDX |
|||
#endif |
|||
#ifdef _NORMALMAP_TANGENT_SPACE |
|||
#define _NORMALMAP_TANGENT_SPACE_IDX |
|||
#endif |
|||
#ifdef _DETAIL_MAP |
|||
#define _DETAIL_MAP_IDX |
|||
#endif |
|||
#ifdef _SUBSURFACE_MASK_MAP |
|||
#define _SUBSURFACE_MASK_MAP_IDX |
|||
#endif |
|||
#ifdef _THICKNESSMAP |
|||
#define _THICKNESSMAP_IDX |
|||
#endif |
|||
#ifdef _MASKMAP |
|||
#define _MASKMAP_IDX |
|||
#endif |
|||
#ifdef _BENTNORMALMAP |
|||
#define _BENTNORMALMAP_IDX |
|||
#endif |
|||
#include "SurfaceLitDataIDX.hlsl" |
|||
|
|||
// This maybe call directly by tessellation (domain) shader, thus all part regarding surface gradient must be done |
|||
// in function with FragInputs input as parameters |
|||
// layerTexCoord must have been initialize to 0 outside of this function |
|||
void GetLayerTexCoord(float2 texCoord0, float2 texCoord1, float2 texCoord2, float2 texCoord3, |
|||
float3 positionWS, float3 vertexNormalWS, inout LayerTexCoord layerTexCoord) |
|||
{ |
|||
layerTexCoord.vertexNormalWS = vertexNormalWS; |
|||
layerTexCoord.triplanarWeights = ComputeTriplanarWeights(vertexNormalWS); |
|||
|
|||
int mappingType = UV_MAPPING_UVSET; |
|||
#if defined(_MAPPING_PLANAR) |
|||
mappingType = UV_MAPPING_PLANAR; |
|||
#elif defined(_MAPPING_TRIPLANAR) |
|||
mappingType = UV_MAPPING_TRIPLANAR; |
|||
#endif |
|||
|
|||
// Be sure that the compiler is aware that we don't use UV1 to UV3 for main layer so it can optimize code |
|||
ComputeLayerTexCoord( texCoord0, texCoord1, texCoord2, texCoord3, _UVMappingMask, _UVDetailsMappingMask, |
|||
_BaseColorMap_ST.xy, _BaseColorMap_ST.zw, _DetailMap_ST.xy, _DetailMap_ST.zw, 1.0, _LinkDetailsWithBase, |
|||
positionWS, _TexWorldScale, |
|||
mappingType, layerTexCoord); |
|||
} |
|||
|
|||
// This is call only in this file |
|||
// layerTexCoord must have been initialize to 0 outside of this function |
|||
void GetLayerTexCoord(FragInputs input, inout LayerTexCoord layerTexCoord) |
|||
{ |
|||
#ifdef SURFACE_GRADIENT |
|||
GenerateLayerTexCoordBasisTB(input, layerTexCoord); |
|||
#endif |
|||
|
|||
GetLayerTexCoord( input.texCoord0, input.texCoord1, input.texCoord2, input.texCoord3, |
|||
input.positionWS, input.worldToTangent[2].xyz, layerTexCoord); |
|||
} |
|||
|
|||
#include "LitDataDisplacement.hlsl" |
|||
#include "LitBuiltinData.hlsl" |
|||
|
|||
void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData) |
|||
{ |
|||
#ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group |
|||
LODDitheringTransition(posInput.positionSS, unity_LODFade.x); |
|||
#endif |
|||
|
|||
ApplyDoubleSidedFlipOrMirror(input); // Apply double sided flip on the vertex normal |
|||
|
|||
LayerTexCoord layerTexCoord; |
|||
ZERO_INITIALIZE(LayerTexCoord, layerTexCoord); |
|||
GetLayerTexCoord(input, layerTexCoord); |
|||
|
|||
float depthOffset = ApplyPerPixelDisplacement(input, V, layerTexCoord); |
|||
|
|||
#ifdef _DEPTHOFFSET_ON |
|||
ApplyDepthOffsetPositionInput(V, depthOffset, GetWorldToHClipMatrix(), posInput); |
|||
#endif |
|||
|
|||
// We perform the conversion to world of the normalTS outside of the GetSurfaceData |
|||
// so it allow us to correctly deal with detail normal map and optimize the code for the layered shaders |
|||
float3 normalTS; |
|||
float3 bentNormalTS; |
|||
float3 bentNormalWS; |
|||
float alpha = GetSurfaceData(input, layerTexCoord, surfaceData, normalTS, bentNormalTS); |
|||
GetNormalWS(input, V, normalTS, surfaceData.normalWS); |
|||
|
|||
// Use bent normal to sample GI if available |
|||
#ifdef _BENTNORMALMAP |
|||
GetNormalWS(input, V, bentNormalTS, bentNormalWS); |
|||
#else |
|||
bentNormalWS = surfaceData.normalWS; |
|||
#endif |
|||
|
|||
// By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion. |
|||
// If user provide bent normal then we process a better term |
|||
#if defined(_BENTNORMALMAP) && defined(_ENABLESPECULAROCCLUSION) |
|||
// If we have bent normal and ambient occlusion, process a specular occlusion |
|||
surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData); |
|||
#elif defined(_MASKMAP) |
|||
surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness)); |
|||
#else |
|||
surfaceData.specularOcclusion = 1.0; |
|||
#endif |
|||
|
|||
// This is use with anisotropic material |
|||
surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS); |
|||
|
|||
#ifndef _DISABLE_DBUFFER |
|||
AddDecalContribution(posInput, surfaceData); |
|||
#endif |
|||
|
|||
#if defined(DEBUG_DISPLAY) |
|||
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) |
|||
{ |
|||
surfaceData.baseColor = GetTextureDataDebug(_DebugMipMapMode, layerTexCoord.base.uv, _BaseColorMap, _BaseColorMap_TexelSize, _BaseColorMap_MipInfo, surfaceData.baseColor); |
|||
surfaceData.metallic = 0; |
|||
} |
|||
#endif |
|||
|
|||
// Caution: surfaceData must be fully initialize before calling GetBuiltinData |
|||
GetBuiltinData(input, surfaceData, alpha, bentNormalWS, depthOffset, builtinData); |
|||
} |
|||
|
|||
#include "LitDataMeshModification.hlsl" |
|||
|
|||
#endif // #ifndef LAYERED_LIT_SHADER |
|
|||
fileFormatVersion: 2 |
|||
guid: 9495a6d08c5cdc349a9add974321f3b5 |
|||
timeCreated: 1477003836 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
void ADD_IDX(ComputeLayerTexCoord)( // Uv related parameters |
|||
float2 texCoord0, float2 texCoord1, float2 texCoord2, float2 texCoord3, float4 uvMappingMask, float4 uvMappingMaskDetails, |
|||
// scale and bias for base and detail + global tiling factor (for layered lit only) |
|||
float2 texScale, float2 texBias, float2 texScaleDetails, float2 texBiasDetails, float additionalTiling, float linkDetailsWithBase, |
|||
// parameter for planar/triplanar |
|||
float3 positionWS, float worldScale, |
|||
// mapping type and output |
|||
int mappingType, inout LayerTexCoord layerTexCoord) |
|||
{ |
|||
// Handle uv0, uv1, uv2, uv3 based on _UVMappingMask weight (exclusif 0..1) |
|||
float2 uvBase = uvMappingMask.x * texCoord0 + |
|||
uvMappingMask.y * texCoord1 + |
|||
uvMappingMask.z * texCoord2 + |
|||
uvMappingMask.w * texCoord3; |
|||
|
|||
// Only used with layered, allow to have additional tiling |
|||
uvBase *= additionalTiling.xx; |
|||
|
|||
|
|||
float2 uvDetails = uvMappingMaskDetails.x * texCoord0 + |
|||
uvMappingMaskDetails.y * texCoord1 + |
|||
uvMappingMaskDetails.z * texCoord2 + |
|||
uvMappingMaskDetails.w * texCoord3; |
|||
|
|||
uvDetails *= additionalTiling.xx; |
|||
|
|||
// If base is planar/triplanar then detail map is forced to be planar/triplanar |
|||
ADD_IDX(layerTexCoord.details).mappingType = ADD_IDX(layerTexCoord.base).mappingType = mappingType; |
|||
ADD_IDX(layerTexCoord.details).normalWS = ADD_IDX(layerTexCoord.base).normalWS = layerTexCoord.vertexNormalWS; |
|||
// Copy data for the uvmapping |
|||
ADD_IDX(layerTexCoord.details).triplanarWeights = ADD_IDX(layerTexCoord.base).triplanarWeights = layerTexCoord.triplanarWeights; |
|||
|
|||
// TODO: Currently we only handle world planar/triplanar but we may want local planar/triplanar. |
|||
// In this case both position and normal need to be convert to object space. |
|||
|
|||
// planar/triplanar |
|||
float2 uvXZ; |
|||
float2 uvXY; |
|||
float2 uvZY; |
|||
|
|||
GetTriplanarCoordinate(GetAbsolutePositionWS(positionWS) * worldScale, uvXZ, uvXY, uvZY); |
|||
|
|||
// Planar is just XZ of triplanar |
|||
if (mappingType == UV_MAPPING_PLANAR) |
|||
{ |
|||
uvBase = uvDetails = uvXZ; |
|||
} |
|||
|
|||
// Apply tiling options |
|||
ADD_IDX(layerTexCoord.base).uv = uvBase * texScale + texBias; |
|||
// Detail map tiling option inherit from the tiling of the base |
|||
ADD_IDX(layerTexCoord.details).uv = uvDetails * texScaleDetails + texBiasDetails; |
|||
if (linkDetailsWithBase > 0.0) |
|||
{ |
|||
ADD_IDX(layerTexCoord.details).uv = ADD_IDX(layerTexCoord.details).uv * texScale + texBias; |
|||
} |
|||
|
|||
ADD_IDX(layerTexCoord.base).uvXZ = uvXZ * texScale + texBias; |
|||
ADD_IDX(layerTexCoord.base).uvXY = uvXY * texScale + texBias; |
|||
ADD_IDX(layerTexCoord.base).uvZY = uvZY * texScale + texBias; |
|||
|
|||
ADD_IDX(layerTexCoord.details).uvXZ = uvXZ * texScaleDetails + texBiasDetails; |
|||
ADD_IDX(layerTexCoord.details).uvXY = uvXY * texScaleDetails + texBiasDetails; |
|||
ADD_IDX(layerTexCoord.details).uvZY = uvZY * texScaleDetails + texBiasDetails; |
|||
|
|||
if (linkDetailsWithBase > 0.0) |
|||
{ |
|||
ADD_IDX(layerTexCoord.details).uvXZ = ADD_IDX(layerTexCoord.details).uvXZ * texScale + texBias; |
|||
ADD_IDX(layerTexCoord.details).uvXY = ADD_IDX(layerTexCoord.details).uvXY * texScale + texBias; |
|||
ADD_IDX(layerTexCoord.details).uvZY = ADD_IDX(layerTexCoord.details).uvZY * texScale + texBias; |
|||
} |
|||
|
|||
|
|||
#ifdef SURFACE_GRADIENT |
|||
// This part is only relevant for normal mapping with UV_MAPPING_UVSET |
|||
// Note: This code work only in pixel shader (as we rely on ddx), it should not be use in other context |
|||
ADD_IDX(layerTexCoord.base).tangentWS = uvMappingMask.x * layerTexCoord.vertexTangentWS0 + |
|||
uvMappingMask.y * layerTexCoord.vertexTangentWS1 + |
|||
uvMappingMask.z * layerTexCoord.vertexTangentWS2 + |
|||
uvMappingMask.w * layerTexCoord.vertexTangentWS3; |
|||
|
|||
ADD_IDX(layerTexCoord.base).bitangentWS = uvMappingMask.x * layerTexCoord.vertexBitangentWS0 + |
|||
uvMappingMask.y * layerTexCoord.vertexBitangentWS1 + |
|||
uvMappingMask.z * layerTexCoord.vertexBitangentWS2 + |
|||
uvMappingMask.w * layerTexCoord.vertexBitangentWS3; |
|||
|
|||
ADD_IDX(layerTexCoord.details).tangentWS = uvMappingMaskDetails.x * layerTexCoord.vertexTangentWS0 + |
|||
uvMappingMaskDetails.y * layerTexCoord.vertexTangentWS1 + |
|||
uvMappingMaskDetails.z * layerTexCoord.vertexTangentWS2 + |
|||
uvMappingMaskDetails.w * layerTexCoord.vertexTangentWS3; |
|||
|
|||
ADD_IDX(layerTexCoord.details).bitangentWS = uvMappingMaskDetails.x * layerTexCoord.vertexBitangentWS0 + |
|||
uvMappingMaskDetails.y * layerTexCoord.vertexBitangentWS1 + |
|||
uvMappingMaskDetails.z * layerTexCoord.vertexBitangentWS2 + |
|||
uvMappingMaskDetails.w * layerTexCoord.vertexBitangentWS3; |
|||
#endif |
|||
} |
|||
|
|||
// Caution: Duplicate from GetBentNormalTS - keep in sync! |
|||
float3 ADD_IDX(GetNormalTS)(FragInputs input, LayerTexCoord layerTexCoord, float3 detailNormalTS, float detailMask) |
|||
{ |
|||
float3 normalTS; |
|||
|
|||
#ifdef _NORMALMAP_IDX |
|||
#ifdef _NORMALMAP_TANGENT_SPACE_IDX |
|||
normalTS = SAMPLE_UVMAPPING_NORMALMAP(ADD_IDX(_NormalMap), SAMPLER_NORMALMAP_IDX, ADD_IDX(layerTexCoord.base), ADD_IDX(_NormalScale)); |
|||
#else // Object space |
|||
// We forbid scale in case of object space as it make no sense |
|||
// To be able to combine object space normal with detail map then later we will re-transform it to world space. |
|||
// Note: There is no such a thing like triplanar with object space normal, so we call directly 2D function |
|||
#ifdef SURFACE_GRADIENT |
|||
// /We need to decompress the normal ourselve here as UnpackNormalRGB will return a surface gradient |
|||
float3 normalOS = SAMPLE_TEXTURE2D(ADD_IDX(_NormalMapOS), SAMPLER_NORMALMAP_IDX, ADD_IDX(layerTexCoord.base).uv).xyz * 2.0 - 1.0; |
|||
// no need to renormalize normalOS for SurfaceGradientFromPerturbedNormal |
|||
normalTS = SurfaceGradientFromPerturbedNormal(input.worldToTangent[2], TransformObjectToWorldDir(normalOS)); |
|||
#else |
|||
float3 normalOS = UnpackNormalRGB(SAMPLE_TEXTURE2D(ADD_IDX(_NormalMapOS), SAMPLER_NORMALMAP_IDX, ADD_IDX(layerTexCoord.base).uv), 1.0); |
|||
normalTS = TransformObjectToTangent(normalOS, input.worldToTangent); |
|||
#endif |
|||
#endif |
|||
|
|||
#ifdef _DETAIL_MAP_IDX |
|||
#ifdef SURFACE_GRADIENT |
|||
normalTS += detailNormalTS * detailMask; |
|||
#else |
|||
normalTS = lerp(normalTS, BlendNormalRNM(normalTS, detailNormalTS), detailMask); |
|||
#endif |
|||
#endif |
|||
#else |
|||
#ifdef SURFACE_GRADIENT |
|||
normalTS = float3(0.0, 0.0, 0.0); // No gradient |
|||
#else |
|||
normalTS = float3(0.0, 0.0, 1.0); |
|||
#endif |
|||
#endif |
|||
|
|||
return normalTS; |
|||
} |
|||
|
|||
// Caution: Duplicate from GetNormalTS - keep in sync! |
|||
float3 ADD_IDX(GetBentNormalTS)(FragInputs input, LayerTexCoord layerTexCoord, float3 normalTS, float3 detailNormalTS, float detailMask) |
|||
{ |
|||
float3 bentNormalTS; |
|||
|
|||
#ifdef _BENTNORMALMAP_IDX |
|||
#ifdef _NORMALMAP_TANGENT_SPACE_IDX |
|||
bentNormalTS = SAMPLE_UVMAPPING_NORMALMAP(ADD_IDX(_BentNormalMap), SAMPLER_NORMALMAP_IDX, ADD_IDX(layerTexCoord.base), ADD_IDX(_NormalScale)); |
|||
#else // Object space |
|||
// We forbid scale in case of object space as it make no sense |
|||
// To be able to combine object space normal with detail map then later we will re-transform it to world space. |
|||
// Note: There is no such a thing like triplanar with object space normal, so we call directly 2D function |
|||
#ifdef SURFACE_GRADIENT |
|||
// /We need to decompress the normal ourselve here as UnpackNormalRGB will return a surface gradient |
|||
float3 normalOS = SAMPLE_TEXTURE2D(ADD_IDX(_BentNormalMapOS), SAMPLER_NORMALMAP_IDX, ADD_IDX(layerTexCoord.base).uv).xyz * 2.0 - 1.0; |
|||
// no need to renormalize normalOS for SurfaceGradientFromPerturbedNormal |
|||
bentNormalTS = SurfaceGradientFromPerturbedNormal(input.worldToTangent[2], TransformObjectToWorldDir(normalOS)); |
|||
#else |
|||
float3 normalOS = UnpackNormalRGB(SAMPLE_TEXTURE2D(ADD_IDX(_BentNormalMapOS), SAMPLER_NORMALMAP_IDX, ADD_IDX(layerTexCoord.base).uv), 1.0); |
|||
bentNormalTS = TransformObjectToTangent(normalOS, input.worldToTangent); |
|||
#endif |
|||
#endif |
|||
|
|||
#ifdef _DETAIL_MAP_IDX |
|||
#ifdef SURFACE_GRADIENT |
|||
bentNormalTS += detailNormalTS * detailMask; |
|||
#else |
|||
bentNormalTS = lerp(bentNormalTS, BlendNormalRNM(bentNormalTS, detailNormalTS), detailMask); |
|||
#endif |
|||
#endif |
|||
#else |
|||
// If there is no bent normal map provided, fallback on regular normal map |
|||
bentNormalTS = normalTS; |
|||
#endif |
|||
|
|||
return bentNormalTS; |
|||
} |
|||
|
|||
// Return opacity |
|||
float ADD_IDX(GetSurfaceData)(FragInputs input, LayerTexCoord layerTexCoord, out SurfaceData surfaceData, out float3 normalTS, out float3 bentNormalTS) |
|||
{ |
|||
float alpha = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_BaseColorMap), ADD_ZERO_IDX(sampler_BaseColorMap), ADD_IDX(layerTexCoord.base)).a * ADD_IDX(_BaseColor).a; |
|||
|
|||
// Perform alha test very early to save performance (a killed pixel will not sample textures) |
|||
#if defined(_ALPHATEST_ON) && !defined(LAYERED_LIT_SHADER) |
|||
float alphaCutoff = _AlphaCutoff; |
|||
#ifdef CUTOFF_TRANSPARENT_DEPTH_PREPASS |
|||
alphaCutoff = _AlphaCutoffPrepass; |
|||
#elif defined(CUTOFF_TRANSPARENT_DEPTH_POSTPASS) |
|||
alphaCutoff = _AlphaCutoffPostpass; |
|||
#endif |
|||
DoAlphaTest(alpha, alphaCutoff); |
|||
#endif |
|||
|
|||
float3 detailNormalTS = float3(0.0, 0.0, 0.0); |
|||
float detailMask = 0.0; |
|||
#ifdef _DETAIL_MAP_IDX |
|||
detailMask = 1.0; |
|||
#ifdef _MASKMAP_IDX |
|||
detailMask = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_MaskMap), SAMPLER_MASKMAP_IDX, ADD_IDX(layerTexCoord.base)).b; |
|||
#endif |
|||
float2 detailAlbedoAndSmoothness = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_DetailMap), SAMPLER_DETAILMAP_IDX, ADD_IDX(layerTexCoord.details)).rb; |
|||
float detailAlbedo = detailAlbedoAndSmoothness.r; |
|||
float detailSmoothness = detailAlbedoAndSmoothness.g; |
|||
// Resample the detail map but this time for the normal map. This call should be optimize by the compiler |
|||
// We split both call due to trilinear mapping |
|||
detailNormalTS = SAMPLE_UVMAPPING_NORMALMAP_AG(ADD_IDX(_DetailMap), SAMPLER_DETAILMAP_IDX, ADD_IDX(layerTexCoord.details), ADD_IDX(_DetailNormalScale)); |
|||
#endif |
|||
|
|||
surfaceData.baseColor = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_BaseColorMap), ADD_ZERO_IDX(sampler_BaseColorMap), ADD_IDX(layerTexCoord.base)).rgb * ADD_IDX(_BaseColor).rgb; |
|||
#ifdef _DETAIL_MAP_IDX |
|||
// Use overlay blend mode for detail abledo: (base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend))) |
|||
float3 baseColorOverlay = (detailAlbedo < 0.5) ? |
|||
surfaceData.baseColor * PositivePow(2.0 * detailAlbedo, ADD_IDX(_DetailAlbedoScale)) : |
|||
1.0 - (1.0 - surfaceData.baseColor) * PositivePow(2.0 * (1.0 - detailAlbedo), ADD_IDX(_DetailAlbedoScale)); |
|||
// Lerp with details mask |
|||
surfaceData.baseColor = lerp(surfaceData.baseColor, saturate(baseColorOverlay), detailMask); |
|||
#endif |
|||
|
|||
surfaceData.specularOcclusion = 1.0; // Will be setup outside of this function |
|||
|
|||
surfaceData.normalWS = float3(0.0, 0.0, 0.0); // Need to init this to keep quiet the compiler, but this is overriden later (0, 0, 0) so if we forget to override the compiler may comply. |
|||
|
|||
normalTS = ADD_IDX(GetNormalTS)(input, layerTexCoord, detailNormalTS, detailMask); |
|||
bentNormalTS = ADD_IDX(GetBentNormalTS)(input, layerTexCoord, normalTS, detailNormalTS, detailMask); |
|||
|
|||
#if defined(_MASKMAP_IDX) |
|||
surfaceData.perceptualSmoothness = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_MaskMap), SAMPLER_MASKMAP_IDX, ADD_IDX(layerTexCoord.base)).a; |
|||
surfaceData.perceptualSmoothness = lerp(ADD_IDX(_SmoothnessRemapMin), ADD_IDX(_SmoothnessRemapMax), surfaceData.perceptualSmoothness); |
|||
#else |
|||
surfaceData.perceptualSmoothness = ADD_IDX(_Smoothness); |
|||
#endif |
|||
|
|||
#ifdef _DETAIL_MAP_IDX |
|||
// Use overlay blend mode for detail abledo: (base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend))) |
|||
float smoothnessOverlay = (detailSmoothness < 0.5) ? |
|||
surfaceData.perceptualSmoothness * PositivePow(2.0 * detailSmoothness, ADD_IDX(_DetailSmoothnessScale)) : |
|||
1.0 - (1.0 - surfaceData.perceptualSmoothness) * PositivePow(2.0 * (1.0 - detailSmoothness), ADD_IDX(_DetailSmoothnessScale)); |
|||
// Lerp with details mask |
|||
surfaceData.perceptualSmoothness = lerp(surfaceData.perceptualSmoothness, saturate(smoothnessOverlay), detailMask); |
|||
#endif |
|||
|
|||
// MaskMap is RGBA: Metallic, Ambient Occlusion (Optional), detail Mask (Optional), Smoothness |
|||
#ifdef _MASKMAP_IDX |
|||
surfaceData.metallic = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_MaskMap), SAMPLER_MASKMAP_IDX, ADD_IDX(layerTexCoord.base)).r; |
|||
surfaceData.ambientOcclusion = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_MaskMap), SAMPLER_MASKMAP_IDX, ADD_IDX(layerTexCoord.base)).g; |
|||
surfaceData.ambientOcclusion = lerp(ADD_IDX(_AORemapMin), ADD_IDX(_AORemapMax), surfaceData.ambientOcclusion); |
|||
#else |
|||
surfaceData.metallic = 1.0; |
|||
surfaceData.ambientOcclusion = 1.0; |
|||
#endif |
|||
surfaceData.metallic *= ADD_IDX(_Metallic); |
|||
|
|||
surfaceData.diffusionProfile = ADD_IDX(_DiffusionProfile); |
|||
surfaceData.subsurfaceMask = ADD_IDX(_SubsurfaceMask); |
|||
|
|||
#ifdef _SUBSURFACE_MASK_MAP_IDX |
|||
surfaceData.subsurfaceMask *= SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_SubsurfaceMaskMap), SAMPLER_SUBSURFACE_MASKMAP_IDX, ADD_IDX(layerTexCoord.base)).r; |
|||
#endif |
|||
|
|||
#ifdef _THICKNESSMAP_IDX |
|||
surfaceData.thickness = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_ThicknessMap), SAMPLER_THICKNESSMAP_IDX, ADD_IDX(layerTexCoord.base)).r; |
|||
surfaceData.thickness = ADD_IDX(_ThicknessRemap).x + ADD_IDX(_ThicknessRemap).y * surfaceData.thickness; |
|||
#else |
|||
surfaceData.thickness = ADD_IDX(_Thickness); |
|||
#endif |
|||
|
|||
// This part of the code is not used in case of layered shader but we keep the same macro system for simplicity |
|||
#if !defined(LAYERED_LIT_SHADER) |
|||
|
|||
// These static material feature allow compile time optimization |
|||
surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD; |
|||
|
|||
#ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING |
|||
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING; |
|||
#endif |
|||
#ifdef _MATERIAL_FEATURE_TRANSMISSION |
|||
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION; |
|||
#endif |
|||
#ifdef _MATERIAL_FEATURE_ANISOTROPY |
|||
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY; |
|||
#endif |
|||
#ifdef _MATERIAL_FEATURE_CLEAR_COAT |
|||
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; |
|||
#endif |
|||
#ifdef _MATERIAL_FEATURE_IRIDESCENCE |
|||
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE; |
|||
#endif |
|||
#ifdef _MATERIAL_FEATURE_SPECULAR_COLOR |
|||
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; |
|||
#endif |
|||
|
|||
#ifdef _TANGENTMAP |
|||
#ifdef _NORMALMAP_TANGENT_SPACE_IDX // Normal and tangent use same space |
|||
float3 tangentTS = SAMPLE_UVMAPPING_NORMALMAP(_TangentMap, sampler_TangentMap, layerTexCoord.base, 1.0); |
|||
surfaceData.tangentWS = TransformTangentToWorld(tangentTS, input.worldToTangent); |
|||
#else // Object space |
|||
// Note: There is no such a thing like triplanar with object space normal, so we call directly 2D function |
|||
float3 tangentOS = UnpackNormalRGB(SAMPLE_TEXTURE2D(_TangentMapOS, sampler_TangentMapOS, layerTexCoord.base.uv), 1.0); |
|||
surfaceData.tangentWS = TransformObjectToWorldDir(tangentOS); |
|||
#endif |
|||
#else |
|||
surfaceData.tangentWS = normalize(input.worldToTangent[0].xyz); // The tangent is not normalize in worldToTangent for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT |
|||
#endif |
|||
|
|||
#ifdef _ANISOTROPYMAP |
|||
surfaceData.anisotropy = SAMPLE_UVMAPPING_TEXTURE2D(_AnisotropyMap, sampler_AnisotropyMap, layerTexCoord.base).r; |
|||
#else |
|||
surfaceData.anisotropy = 1.0; |
|||
#endif |
|||
surfaceData.anisotropy *= ADD_IDX(_Anisotropy); |
|||
|
|||
surfaceData.specularColor = _SpecularColor.rgb; |
|||
#ifdef _SPECULARCOLORMAP |
|||
surfaceData.specularColor *= SAMPLE_UVMAPPING_TEXTURE2D(_SpecularColorMap, sampler_SpecularColorMap, layerTexCoord.base).rgb; |
|||
#endif |
|||
#ifdef _MATERIAL_FEATURE_SPECULAR_COLOR |
|||
// Require to have setup baseColor |
|||
// Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it |
|||
surfaceData.baseColor *= _EnergyConservingSpecularColor > 0.0 ? (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)) : 1.0; |
|||
#endif |
|||
|
|||
#if HAS_REFRACTION |
|||
surfaceData.ior = _Ior; |
|||
surfaceData.transmittanceColor = _TransmittanceColor; |
|||
#ifdef _TRANSMITTANCECOLORMAP |
|||
surfaceData.transmittanceColor *= SAMPLE_UVMAPPING_TEXTURE2D(_TransmittanceColorMap, sampler_TransmittanceColorMap, ADD_IDX(layerTexCoord.base)).rgb; |
|||
#endif |
|||
|
|||
surfaceData.atDistance = _ATDistance; |
|||
// Thickness already defined with SSS (from both thickness and thicknessMap) |
|||
surfaceData.thickness *= _ThicknessMultiplier; |
|||
// Rough refraction don't use opacity. Instead we use opacity as a transmittance mask. |
|||
surfaceData.transmittanceMask = 1.0 - alpha; |
|||
alpha = 1.0; |
|||
#else |
|||
surfaceData.ior = 1.0; |
|||
surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); |
|||
surfaceData.atDistance = 1.0; |
|||
surfaceData.transmittanceMask = 0.0; |
|||
#endif |
|||
|
|||
#ifdef _MATERIAL_FEATURE_CLEAR_COAT |
|||
surfaceData.coatMask = _CoatMask; |
|||
// To shader feature for keyword to limit the variant |
|||
surfaceData.coatMask *= SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_CoatMaskMap), ADD_ZERO_IDX(sampler_CoatMaskMap), ADD_IDX(layerTexCoord.base)).r; |
|||
#else |
|||
surfaceData.coatMask = 0.0; |
|||
#endif |
|||
|
|||
#ifdef _MATERIAL_FEATURE_IRIDESCENCE |
|||
#ifdef _IRIDESCENCE_THICKNESSMAP |
|||
surfaceData.iridescenceThickness = SAMPLE_UVMAPPING_TEXTURE2D(_IridescenceThicknessMap, sampler_IridescenceThicknessMap, layerTexCoord.base).r; |
|||
surfaceData.iridescenceThickness = _IridescenceThicknessRemap.x + _IridescenceThicknessRemap.y * surfaceData.iridescenceThickness; |
|||
#else |
|||
surfaceData.iridescenceThickness = _IridescenceThickness; |
|||
#endif |
|||
surfaceData.iridescenceMask = _IridescenceMask; |
|||
surfaceData.iridescenceMask *= SAMPLE_UVMAPPING_TEXTURE2D(_IridescenceMaskMap, sampler_IridescenceMaskMap, layerTexCoord.base).r; |
|||
#else |
|||
surfaceData.iridescenceThickness = 0.0; |
|||
surfaceData.iridescenceMask = 0.0; |
|||
#endif |
|||
|
|||
#else // #if !defined(LAYERED_LIT_SHADER) |
|||
|
|||
// Mandatory to setup value to keep compiler quiet |
|||
|
|||
// Layered shader material feature are define outside of this call |
|||
surfaceData.materialFeatures = 0; |
|||
|
|||
// All these parameters are ignore as they are re-setup outside of the layers function |
|||
// Note: any parameters set here must also be set in GetSurfaceAndBuiltinData() layer version |
|||
surfaceData.tangentWS = float3(0.0, 0.0, 0.0); |
|||
surfaceData.anisotropy = 0.0; |
|||
surfaceData.specularColor = float3(0.0, 0.0, 0.0); |
|||
surfaceData.iridescenceThickness = 0.0; |
|||
surfaceData.iridescenceMask = 0.0; |
|||
surfaceData.coatMask = 0.0; |
|||
|
|||
// Transparency |
|||
surfaceData.ior = 1.0; |
|||
surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0); |
|||
surfaceData.atDistance = 1000000.0; |
|||
surfaceData.transmittanceMask = 0.0; |
|||
|
|||
#endif // #if !defined(LAYERED_LIT_SHADER) |
|||
|
|||
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.Lit+SurfaceData |
|||
// PackingRules = Exact |
|||
/* |
|||
struct SurfaceData |
|||
{ |
|||
uint materialFeatures; |
|||
float3 baseColor; |
|||
float specularOcclusion; |
|||
float3 normalWS; |
|||
float perceptualSmoothness; |
|||
float ambientOcclusion; |
|||
float metallic; |
|||
float coatMask; |
|||
float3 specularColor; |
|||
uint diffusionProfile; |
|||
float subsurfaceMask; |
|||
float thickness; |
|||
float3 tangentWS; |
|||
float anisotropy; |
|||
float iridescenceThickness; |
|||
float iridescenceMask; |
|||
float ior; |
|||
float3 transmittanceColor; |
|||
float atDistance; |
|||
float transmittanceMask; |
|||
}; |
|||
*/ |
|||
|
|||
surfaceData.baseColor = float3(1, 0, 0); |
|||
surfaceData.normalWS = float3(1, 0, 0); |
|||
|
|||
return alpha; |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: feeb5b09716aa2943a71f5e8f9d66822 |
|||
timeCreated: 1508947139 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue