Anis Benyoub
6 年前
当前提交
cd8cac28
共有 44 个文件被更改,包括 1230 次插入 和 81 次删除
-
10com.unity.render-pipelines.core/CoreRP/ShaderLibrary/BSDF.hlsl
-
10com.unity.render-pipelines.core/CoreRP/ShaderLibrary/ImageBasedLighting.hlsl
-
9com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Lit/BaseLitUI.cs
-
25com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Fabric/FabricUI.cs
-
2com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/HDAssetFactory.cs
-
2com.unity.render-pipelines.high-definition/HDRP/Editor/RenderPipeline/HDEditorUtils.cs
-
2com.unity.render-pipelines.high-definition/HDRP/Editor/Upgraders/UpgradeMenuItem.cs
-
4com.unity.render-pipelines.high-definition/HDRP/Material/Material.hlsl
-
12com.unity.render-pipelines.high-definition/HDRP/Material/PreIntegratedFGD/PreIntegratedFGD.cs
-
10com.unity.render-pipelines.high-definition/HDRP/Material/PreIntegratedFGD/PreIntegratedFGD.hlsl
-
4com.unity.render-pipelines.high-definition/HDRP/Material/PreIntegratedFGD/preIntegratedFGD_CharlieFabricLambert.shader
-
2com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDStringConstants.cs
-
2com.unity.render-pipelines.high-definition/HDRP/RenderPipelineResources/RenderPipelineResources.cs
-
31com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/Fabric.cs
-
1com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/FabricProperties.hlsl
-
8com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Fabric.meta
-
8com.unity.render-pipelines.high-definition/HDRP/Material/Fabric.meta
-
217com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/Fabric.cs.hlsl
-
621com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/Fabric.hlsl
-
280com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/Fabric.shader
-
35com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/FabricData.hlsl
-
8com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Cloth.meta
-
8com.unity.render-pipelines.high-definition/HDRP/Material/Cloth.meta
-
0/com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Fabric
-
0/com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Fabric/FabricUI.cs.meta
-
0/com.unity.render-pipelines.high-definition/HDRP/Editor/Material/Fabric/FabricUI.cs
-
0/com.unity.render-pipelines.high-definition/HDRP/Material/PreIntegratedFGD/preIntegratedFGD_CharlieFabricLambert.shader.meta
-
0/com.unity.render-pipelines.high-definition/HDRP/Material/PreIntegratedFGD/preIntegratedFGD_CharlieFabricLambert.shader
-
0/com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/Fabric.cs
-
0/com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/Fabric.cs.hlsl.meta
-
0/com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/Fabric.cs.meta
-
0/com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/Fabric.hlsl.meta
-
0/com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/Fabric.shader.meta
-
0/com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/FabricData.hlsl.meta
-
0/com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/FabricProperties.hlsl.meta
-
0/com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/ShaderPass.meta
-
0/com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/ShaderPass
-
0/com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/ShaderPass/FabricDepthPass.hlsl
-
0/com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/ShaderPass/FabricDepthPass.hlsl.meta
-
0/com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/ShaderPass/FabricSharePass.hlsl
-
0/com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/ShaderPass/FabricSharePass.hlsl.meta
-
0/com.unity.render-pipelines.high-definition/HDRP/Material/Fabric/FabricProperties.hlsl
|
|||
fileFormatVersion: 2 |
|||
guid: 553571484746b1f4d8e16c85a45f34fe |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: c42133a75ba128147bd0bb2259c8fcd8 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
// |
|||
// This file was automatically generated. Please don't edit by hand. |
|||
// |
|||
|
|||
#ifndef FABRIC_CS_HLSL |
|||
#define FABRIC_CS_HLSL |
|||
// |
|||
// UnityEngine.Experimental.Rendering.HDPipeline.Fabric+MaterialFeatureFlags: static fields |
|||
// |
|||
#define MATERIALFEATUREFLAGS_FABRIC_COTTON_WOOL (1) |
|||
#define MATERIALFEATUREFLAGS_FABRIC_SILK (2) |
|||
#define MATERIALFEATUREFLAGS_FABRIC_SUBSURFACE_SCATTERING (4) |
|||
#define MATERIALFEATUREFLAGS_FABRIC_TRANSMISSION (8) |
|||
|
|||
// |
|||
// UnityEngine.Experimental.Rendering.HDPipeline.Fabric+SurfaceData: static fields |
|||
// |
|||
#define DEBUGVIEW_FABRIC_SURFACEDATA_MATERIAL_FEATURES (1300) |
|||
#define DEBUGVIEW_FABRIC_SURFACEDATA_BASE_COLOR (1301) |
|||
#define DEBUGVIEW_FABRIC_SURFACEDATA_SPECULAR_OCCLUSION (1302) |
|||
#define DEBUGVIEW_FABRIC_SURFACEDATA_NORMAL (1303) |
|||
#define DEBUGVIEW_FABRIC_SURFACEDATA_NORMAL_VIEW_SPACE (1304) |
|||
#define DEBUGVIEW_FABRIC_SURFACEDATA_SMOOTHNESS (1305) |
|||
#define DEBUGVIEW_FABRIC_SURFACEDATA_AMBIENT_OCCLUSION (1306) |
|||
#define DEBUGVIEW_FABRIC_SURFACEDATA_FUZZ_TINT (1307) |
|||
#define DEBUGVIEW_FABRIC_SURFACEDATA_DIFFUSION_PROFILE (1308) |
|||
#define DEBUGVIEW_FABRIC_SURFACEDATA_SUBSURFACE_MASK (1309) |
|||
#define DEBUGVIEW_FABRIC_SURFACEDATA_THICKNESS (1310) |
|||
#define DEBUGVIEW_FABRIC_SURFACEDATA_TANGENT (1311) |
|||
#define DEBUGVIEW_FABRIC_SURFACEDATA_ANISOTROPY (1312) |
|||
|
|||
// |
|||
// UnityEngine.Experimental.Rendering.HDPipeline.Fabric+BSDFData: static fields |
|||
// |
|||
#define DEBUGVIEW_FABRIC_BSDFDATA_MATERIAL_FEATURES (1350) |
|||
#define DEBUGVIEW_FABRIC_BSDFDATA_DIFFUSE_COLOR (1351) |
|||
#define DEBUGVIEW_FABRIC_BSDFDATA_FRESNEL0 (1352) |
|||
#define DEBUGVIEW_FABRIC_BSDFDATA_AMBIENT_OCCLUSION (1353) |
|||
#define DEBUGVIEW_FABRIC_BSDFDATA_SPECULAR_OCCLUSION (1354) |
|||
#define DEBUGVIEW_FABRIC_BSDFDATA_FUZZ_TINT (1355) |
|||
#define DEBUGVIEW_FABRIC_BSDFDATA_NORMAL_WS (1356) |
|||
#define DEBUGVIEW_FABRIC_BSDFDATA_NORMAL_VIEW_SPACE (1357) |
|||
#define DEBUGVIEW_FABRIC_BSDFDATA_PERCEPTUAL_ROUGHNESS (1358) |
|||
#define DEBUGVIEW_FABRIC_BSDFDATA_DIFFUSION_PROFILE (1359) |
|||
#define DEBUGVIEW_FABRIC_BSDFDATA_SUBSURFACE_MASK (1360) |
|||
#define DEBUGVIEW_FABRIC_BSDFDATA_THICKNESS (1361) |
|||
#define DEBUGVIEW_FABRIC_BSDFDATA_USE_THICK_OBJECT_MODE (1362) |
|||
#define DEBUGVIEW_FABRIC_BSDFDATA_TRANSMITTANCE (1363) |
|||
#define DEBUGVIEW_FABRIC_BSDFDATA_TANGENT_WS (1364) |
|||
#define DEBUGVIEW_FABRIC_BSDFDATA_BITANGENT_WS (1365) |
|||
#define DEBUGVIEW_FABRIC_BSDFDATA_ROUGHNESS_T (1366) |
|||
#define DEBUGVIEW_FABRIC_BSDFDATA_ROUGHNESS_B (1367) |
|||
#define DEBUGVIEW_FABRIC_BSDFDATA_ANISOTROPY (1368) |
|||
|
|||
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.Fabric+SurfaceData |
|||
// PackingRules = Exact |
|||
struct SurfaceData |
|||
{ |
|||
uint materialFeatures; |
|||
float3 baseColor; |
|||
float specularOcclusion; |
|||
float3 normalWS; |
|||
float perceptualSmoothness; |
|||
float ambientOcclusion; |
|||
float3 fuzzTint; |
|||
uint diffusionProfile; |
|||
float subsurfaceMask; |
|||
float thickness; |
|||
float3 tangentWS; |
|||
float anisotropy; |
|||
}; |
|||
|
|||
// Generated from UnityEngine.Experimental.Rendering.HDPipeline.Fabric+BSDFData |
|||
// PackingRules = Exact |
|||
struct BSDFData |
|||
{ |
|||
uint materialFeatures; |
|||
float3 diffuseColor; |
|||
float3 fresnel0; |
|||
float ambientOcclusion; |
|||
float specularOcclusion; |
|||
float3 fuzzTint; |
|||
float3 normalWS; |
|||
float perceptualRoughness; |
|||
uint diffusionProfile; |
|||
float subsurfaceMask; |
|||
float thickness; |
|||
bool useThickObjectMode; |
|||
float3 transmittance; |
|||
float3 tangentWS; |
|||
float3 bitangentWS; |
|||
float roughnessT; |
|||
float roughnessB; |
|||
float anisotropy; |
|||
}; |
|||
|
|||
// |
|||
// Debug functions |
|||
// |
|||
void GetGeneratedSurfaceDataDebug(uint paramId, SurfaceData surfacedata, inout float3 result, inout bool needLinearToSRGB) |
|||
{ |
|||
switch (paramId) |
|||
{ |
|||
case DEBUGVIEW_FABRIC_SURFACEDATA_MATERIAL_FEATURES: |
|||
result = GetIndexColor(surfacedata.materialFeatures); |
|||
break; |
|||
case DEBUGVIEW_FABRIC_SURFACEDATA_BASE_COLOR: |
|||
result = surfacedata.baseColor; |
|||
needLinearToSRGB = true; |
|||
break; |
|||
case DEBUGVIEW_FABRIC_SURFACEDATA_SPECULAR_OCCLUSION: |
|||
result = surfacedata.specularOcclusion.xxx; |
|||
break; |
|||
case DEBUGVIEW_FABRIC_SURFACEDATA_NORMAL: |
|||
result = surfacedata.normalWS * 0.5 + 0.5; |
|||
break; |
|||
case DEBUGVIEW_FABRIC_SURFACEDATA_NORMAL_VIEW_SPACE: |
|||
result = surfacedata.normalWS * 0.5 + 0.5; |
|||
break; |
|||
case DEBUGVIEW_FABRIC_SURFACEDATA_SMOOTHNESS: |
|||
result = surfacedata.perceptualSmoothness.xxx; |
|||
break; |
|||
case DEBUGVIEW_FABRIC_SURFACEDATA_AMBIENT_OCCLUSION: |
|||
result = surfacedata.ambientOcclusion.xxx; |
|||
break; |
|||
case DEBUGVIEW_FABRIC_SURFACEDATA_FUZZ_TINT: |
|||
result = surfacedata.fuzzTint; |
|||
needLinearToSRGB = true; |
|||
break; |
|||
case DEBUGVIEW_FABRIC_SURFACEDATA_DIFFUSION_PROFILE: |
|||
result = GetIndexColor(surfacedata.diffusionProfile); |
|||
break; |
|||
case DEBUGVIEW_FABRIC_SURFACEDATA_SUBSURFACE_MASK: |
|||
result = surfacedata.subsurfaceMask.xxx; |
|||
break; |
|||
case DEBUGVIEW_FABRIC_SURFACEDATA_THICKNESS: |
|||
result = surfacedata.thickness.xxx; |
|||
break; |
|||
case DEBUGVIEW_FABRIC_SURFACEDATA_TANGENT: |
|||
result = surfacedata.tangentWS * 0.5 + 0.5; |
|||
break; |
|||
case DEBUGVIEW_FABRIC_SURFACEDATA_ANISOTROPY: |
|||
result = surfacedata.anisotropy.xxx; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
// |
|||
// Debug functions |
|||
// |
|||
void GetGeneratedBSDFDataDebug(uint paramId, BSDFData bsdfdata, inout float3 result, inout bool needLinearToSRGB) |
|||
{ |
|||
switch (paramId) |
|||
{ |
|||
case DEBUGVIEW_FABRIC_BSDFDATA_MATERIAL_FEATURES: |
|||
result = GetIndexColor(bsdfdata.materialFeatures); |
|||
break; |
|||
case DEBUGVIEW_FABRIC_BSDFDATA_DIFFUSE_COLOR: |
|||
result = bsdfdata.diffuseColor; |
|||
needLinearToSRGB = true; |
|||
break; |
|||
case DEBUGVIEW_FABRIC_BSDFDATA_FRESNEL0: |
|||
result = bsdfdata.fresnel0; |
|||
break; |
|||
case DEBUGVIEW_FABRIC_BSDFDATA_AMBIENT_OCCLUSION: |
|||
result = bsdfdata.ambientOcclusion.xxx; |
|||
break; |
|||
case DEBUGVIEW_FABRIC_BSDFDATA_SPECULAR_OCCLUSION: |
|||
result = bsdfdata.specularOcclusion.xxx; |
|||
break; |
|||
case DEBUGVIEW_FABRIC_BSDFDATA_FUZZ_TINT: |
|||
result = bsdfdata.fuzzTint; |
|||
break; |
|||
case DEBUGVIEW_FABRIC_BSDFDATA_NORMAL_WS: |
|||
result = bsdfdata.normalWS * 0.5 + 0.5; |
|||
break; |
|||
case DEBUGVIEW_FABRIC_BSDFDATA_NORMAL_VIEW_SPACE: |
|||
result = bsdfdata.normalWS * 0.5 + 0.5; |
|||
break; |
|||
case DEBUGVIEW_FABRIC_BSDFDATA_PERCEPTUAL_ROUGHNESS: |
|||
result = bsdfdata.perceptualRoughness.xxx; |
|||
break; |
|||
case DEBUGVIEW_FABRIC_BSDFDATA_DIFFUSION_PROFILE: |
|||
result = GetIndexColor(bsdfdata.diffusionProfile); |
|||
break; |
|||
case DEBUGVIEW_FABRIC_BSDFDATA_SUBSURFACE_MASK: |
|||
result = bsdfdata.subsurfaceMask.xxx; |
|||
break; |
|||
case DEBUGVIEW_FABRIC_BSDFDATA_THICKNESS: |
|||
result = bsdfdata.thickness.xxx; |
|||
break; |
|||
case DEBUGVIEW_FABRIC_BSDFDATA_USE_THICK_OBJECT_MODE: |
|||
result = (bsdfdata.useThickObjectMode) ? float3(1.0, 1.0, 1.0) : float3(0.0, 0.0, 0.0); |
|||
break; |
|||
case DEBUGVIEW_FABRIC_BSDFDATA_TRANSMITTANCE: |
|||
result = bsdfdata.transmittance; |
|||
break; |
|||
case DEBUGVIEW_FABRIC_BSDFDATA_TANGENT_WS: |
|||
result = bsdfdata.tangentWS * 0.5 + 0.5; |
|||
break; |
|||
case DEBUGVIEW_FABRIC_BSDFDATA_BITANGENT_WS: |
|||
result = bsdfdata.bitangentWS * 0.5 + 0.5; |
|||
break; |
|||
case DEBUGVIEW_FABRIC_BSDFDATA_ROUGHNESS_T: |
|||
result = bsdfdata.roughnessT.xxx; |
|||
break; |
|||
case DEBUGVIEW_FABRIC_BSDFDATA_ROUGHNESS_B: |
|||
result = bsdfdata.roughnessB.xxx; |
|||
break; |
|||
case DEBUGVIEW_FABRIC_BSDFDATA_ANISOTROPY: |
|||
result = bsdfdata.anisotropy.xxx; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
|
|||
#endif |
|
|||
//----------------------------------------------------------------------------- |
|||
// SurfaceData and BSDFData |
|||
//----------------------------------------------------------------------------- |
|||
// SurfaceData is defined in Fabric.cs which generates Fabric.cs.hlsl |
|||
#include "Fabric.cs.hlsl" |
|||
// Those define allow to include desired SSS/Transmission functions |
|||
#define MATERIAL_INCLUDE_SUBSURFACESCATTERING |
|||
#define MATERIAL_INCLUDE_TRANSMISSION |
|||
#include "HDRP/Material/SubsurfaceScattering/SubsurfaceScattering.hlsl" |
|||
#include "HDRP/Material/NormalBuffer.hlsl" |
|||
#include "CoreRP/ShaderLibrary/VolumeRendering.hlsl" |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// Texture and constant buffer declaration |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
#include "HDRP/Material/LTCAreaLight/LTCAreaLight.hlsl" |
|||
#include "HDRP/Material/PreIntegratedFGD/PreIntegratedFGD.hlsl" |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// Helper functions/variable specific to this material |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
// Assume bsdfData.normalWS is init |
|||
void FillMaterialAnisotropy(float anisotropy, float3 tangentWS, float3 bitangentWS, inout BSDFData bsdfData) |
|||
{ |
|||
bsdfData.anisotropy = anisotropy; |
|||
bsdfData.tangentWS = tangentWS; |
|||
bsdfData.bitangentWS = bitangentWS; |
|||
} |
|||
|
|||
// This function is use to help with debugging and must be implemented by any lit material |
|||
// Implementer must take into account what are the current override component and |
|||
// adjust SurfaceData properties accordingdly |
|||
void ApplyDebugToSurfaceData(float3x3 worldToTangent, inout SurfaceData surfaceData) |
|||
{ |
|||
#ifdef DEBUG_DISPLAY |
|||
// NOTE: THe _Debug* uniforms come from /HDRP/Debug/DebugDisplay.hlsl |
|||
|
|||
// Override value if requested by user |
|||
// this can be use also in case of debug lighting mode like diffuse only |
|||
bool overrideAlbedo = _DebugLightingAlbedo.x != 0.0; |
|||
bool overrideSmoothness = _DebugLightingSmoothness.x != 0.0; |
|||
bool overrideNormal = _DebugLightingNormal.x != 0.0; |
|||
|
|||
if (overrideAlbedo) |
|||
{ |
|||
float3 overrideAlbedoValue = _DebugLightingAlbedo.yzw; |
|||
surfaceData.baseColor = overrideAlbedoValue; |
|||
} |
|||
|
|||
if (overrideSmoothness) |
|||
{ |
|||
float overrideSmoothnessValue = _DebugLightingSmoothness.y; |
|||
surfaceData.perceptualSmoothness = overrideSmoothnessValue; |
|||
} |
|||
|
|||
if (overrideNormal) |
|||
{ |
|||
surfaceData.normalWS = worldToTangent[2]; |
|||
} |
|||
#endif |
|||
} |
|||
|
|||
// This function is similar to ApplyDebugToSurfaceData but for BSDFData |
|||
// Note: This will be available and used in ShaderPassForward.hlsl since in Fabric.shader, |
|||
// just before including the core code of the pass (ShaderPassForward.hlsl) we include |
|||
// Material.hlsl (or Lighting.hlsl which includes it) which in turn includes us, |
|||
// Fabric.shader, via the #if defined(UNITY_MATERIAL_*) glue mechanism. |
|||
void ApplyDebugToBSDFData(inout BSDFData bsdfData) |
|||
{ |
|||
#ifdef DEBUG_DISPLAY |
|||
// Override value if requested by user |
|||
// this can be use also in case of debug lighting mode like specular only |
|||
bool overrideSpecularColor = _DebugLightingSpecularColor.x != 0.0; |
|||
|
|||
if (overrideSpecularColor) |
|||
{ |
|||
float3 overrideSpecularColor = _DebugLightingSpecularColor.yzw; |
|||
bsdfData.fresnel0 = overrideSpecularColor; |
|||
} |
|||
#endif |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// conversion function for forward |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
BSDFData ConvertSurfaceDataToBSDFData(uint2 positionSS, SurfaceData surfaceData) |
|||
{ |
|||
BSDFData bsdfData; |
|||
ZERO_INITIALIZE(BSDFData, bsdfData); |
|||
|
|||
// IMPORTANT: In case of foward or gbuffer pass all enable flags are statically know at compile time, so the compiler can do compile time optimization |
|||
bsdfData.materialFeatures = surfaceData.materialFeatures; |
|||
|
|||
bsdfData.diffuseColor = surfaceData.baseColor; |
|||
bsdfData.specularOcclusion = surfaceData.specularOcclusion; |
|||
bsdfData.normalWS = surfaceData.normalWS; |
|||
bsdfData.perceptualRoughness = PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness); |
|||
|
|||
bsdfData.ambientOcclusion = surfaceData.ambientOcclusion; |
|||
bsdfData.fuzzTint = surfaceData.fuzzTint; |
|||
|
|||
// Note: we have ZERO_INITIALIZE the struct so bsdfData.anisotropy == 0.0 |
|||
// Note: DIFFUSION_PROFILE_NEUTRAL_ID is 0 |
|||
|
|||
// In forward everything is statically know and we could theorically cumulate all the material features. So the code reflect it. |
|||
// However in practice we keep parity between deferred and forward, so we should constrain the various features. |
|||
// The UI is in charge of setuping the constrain, not the code. So if users is forward only and want unleash power, it is easy to unleash by some UI change |
|||
|
|||
if (HasFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_FABRIC_SUBSURFACE_SCATTERING)) |
|||
{ |
|||
// Assign profile id and overwrite fresnel0 |
|||
FillMaterialSSS(surfaceData.diffusionProfile, surfaceData.subsurfaceMask, bsdfData); |
|||
} |
|||
|
|||
if (HasFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_FABRIC_TRANSMISSION)) |
|||
{ |
|||
// Assign profile id and overwrite fresnel0 |
|||
FillMaterialTransmission(surfaceData.diffusionProfile, surfaceData.thickness, bsdfData); |
|||
} |
|||
|
|||
if (HasFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_FABRIC_SILK)) |
|||
{ |
|||
FillMaterialAnisotropy(surfaceData.anisotropy, surfaceData.tangentWS, cross(surfaceData.normalWS, surfaceData.tangentWS), bsdfData); |
|||
} |
|||
|
|||
// roughnessT and roughnessB are clamped, and are meant to be used with punctual and directional lights. |
|||
// perceptualRoughness is not clamped, and is meant to be used for IBL. |
|||
// perceptualRoughness can be modify by FillMaterialClearCoatData, so ConvertAnisotropyToClampRoughness must be call after |
|||
ConvertAnisotropyToClampRoughness(bsdfData.perceptualRoughness, bsdfData.anisotropy, bsdfData.roughnessT, bsdfData.roughnessB); |
|||
|
|||
ApplyDebugToBSDFData(bsdfData); |
|||
|
|||
return bsdfData; |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// Debug method (use to display values) |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
// This function call the generated debug function and allow to override the debug output if needed |
|||
void GetSurfaceDataDebug(uint paramId, SurfaceData surfaceData, inout float3 result, inout bool needLinearToSRGB) |
|||
{ |
|||
GetGeneratedSurfaceDataDebug(paramId, surfaceData, result, needLinearToSRGB); |
|||
} |
|||
|
|||
// This function call the generated debug function and allow to override the debug output if needed |
|||
void GetBSDFDataDebug(uint paramId, BSDFData bsdfData, inout float3 result, inout bool needLinearToSRGB) |
|||
{ |
|||
GetGeneratedBSDFDataDebug(paramId, bsdfData, result, needLinearToSRGB); |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// PreLightData |
|||
// |
|||
// Make sure we respect naming conventions to reuse ShaderPassForward as is, |
|||
// ie struct (even if opaque to the ShaderPassForward) name is PreLightData, |
|||
// GetPreLightData prototype. |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
// Precomputed lighting data to send to the various lighting functions |
|||
struct PreLightData |
|||
{ |
|||
float NdotV; // Could be negative due to normal mapping, use ClampNdotV() |
|||
float partLambdaV; |
|||
|
|||
// IBL |
|||
float3 iblR; // Reflected specular direction, used for IBL in EvaluateBSDF_Env() |
|||
float iblPerceptualRoughness; |
|||
|
|||
float3 specularFGD; // Store preintegrated BSDF for both specular and diffuse |
|||
float diffuseFGD; |
|||
}; |
|||
|
|||
// This function is call to precompute heavy calculation before lightloop |
|||
PreLightData GetPreLightData(float3 V, PositionInputs posInput, inout BSDFData bsdfData) |
|||
{ |
|||
PreLightData preLightData; |
|||
// Don't init to zero to allow to track warning about uninitialized data |
|||
|
|||
float3 N = bsdfData.normalWS; |
|||
preLightData.NdotV = dot(N, V); |
|||
preLightData.iblPerceptualRoughness = bsdfData.perceptualRoughness; |
|||
|
|||
float NdotV = ClampNdotV(preLightData.NdotV); |
|||
|
|||
float unused; |
|||
float3 iblN; |
|||
|
|||
// Reminder: This is a static if resolve at compile time |
|||
if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_FABRIC_SILK)) |
|||
{ |
|||
GetPreIntegratedFGDGGXAndDisneyDiffuse(NdotV, preLightData.iblPerceptualRoughness, bsdfData.fresnel0, preLightData.specularFGD, preLightData.diffuseFGD, unused); |
|||
|
|||
float TdotV = dot(bsdfData.tangentWS, V); |
|||
float BdotV = dot(bsdfData.bitangentWS, V); |
|||
|
|||
preLightData.partLambdaV = GetSmithJointGGXAnisoPartLambdaV(TdotV, BdotV, NdotV, bsdfData.roughnessT, bsdfData.roughnessB); |
|||
|
|||
// perceptualRoughness is use as input and output here |
|||
GetGGXAnisotropicModifiedNormalAndRoughness(bsdfData.bitangentWS, bsdfData.tangentWS, N, V, bsdfData.anisotropy, preLightData.iblPerceptualRoughness, iblN, preLightData.iblPerceptualRoughness); |
|||
} |
|||
else |
|||
{ |
|||
preLightData.partLambdaV = 0.0; |
|||
iblN = N; |
|||
|
|||
GetPreIntegratedFGDCharlieAndFabricLambert(NdotV, preLightData.iblPerceptualRoughness, bsdfData.fresnel0, preLightData.specularFGD, preLightData.diffuseFGD, unused); |
|||
} |
|||
|
|||
preLightData.iblR = reflect(-V, iblN); |
|||
|
|||
return preLightData; |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// bake lighting function |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
// This define allow to say that we implement a ModifyBakedDiffuseLighting function to be call in PostInitBuiltinData |
|||
#define MODIFY_BAKED_DIFFUSE_LIGHTING |
|||
|
|||
void ModifyBakedDiffuseLighting(float3 V, PositionInputs posInput, SurfaceData surfaceData, inout BuiltinData builtinData) |
|||
{ |
|||
// To get the data we need to do the whole process - compiler should optimize everything |
|||
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(posInput.positionSS, surfaceData); |
|||
PreLightData preLightData = GetPreLightData(V, posInput, bsdfData); |
|||
|
|||
// Add GI transmission contribution to bakeDiffuseLighting, we then drop backBakeDiffuseLighting (i.e it is not used anymore, this save VGPR) |
|||
if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_FABRIC_TRANSMISSION)) |
|||
{ |
|||
builtinData.bakeDiffuseLighting += builtinData.backBakeDiffuseLighting * bsdfData.transmittance; |
|||
} |
|||
|
|||
// For SSS we need to take into account the state of diffuseColor |
|||
if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_FABRIC_SUBSURFACE_SCATTERING)) |
|||
{ |
|||
bsdfData.diffuseColor = GetModifiedDiffuseColorForSSS(bsdfData); |
|||
} |
|||
|
|||
// Premultiply (back) bake diffuse lighting information with diffuse pre-integration |
|||
builtinData.bakeDiffuseLighting *= preLightData.diffuseFGD * bsdfData.diffuseColor; |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// light transport functions |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
LightTransportData GetLightTransportData(SurfaceData surfaceData, BuiltinData builtinData, BSDFData bsdfData) |
|||
{ |
|||
LightTransportData lightTransportData; |
|||
|
|||
// DiffuseColor for lightmapping |
|||
lightTransportData.diffuseColor = bsdfData.diffuseColor; |
|||
lightTransportData.emissiveColor = builtinData.emissiveColor; |
|||
|
|||
return lightTransportData; |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// LightLoop related function (Only include if required) |
|||
// HAS_LIGHTLOOP is define in Lighting.hlsl |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
#ifdef HAS_LIGHTLOOP |
|||
|
|||
#ifndef _SURFACE_TYPE_TRANSPARENT |
|||
// For /Lighting/LightEvaluation.hlsl: |
|||
#define USE_DEFERRED_DIRECTIONAL_SHADOWS // Deferred shadows are always enabled for opaque objects |
|||
#endif |
|||
|
|||
#include "HDRP/Material/MaterialEvaluation.hlsl" |
|||
#include "HDRP/Lighting/LightEvaluation.hlsl" |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// BSDF share between directional light, punctual light and area light (reference) |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
// Ref: https://www.slideshare.net/jalnaga/custom-fabric-shader-for-unreal-engine-4 |
|||
// For Fabric we have two type of BRDF |
|||
// Non-Metal: Cotton, deim, flax and common fabrics |
|||
// Cotton: Roughness of 1.0 (unless wet) - Fuzz rim - specular color is white but is looked like desaturated. |
|||
// Metal: Silk, satin, velvet, nylon and polyester |
|||
// Silk: Roughness 0.3 - 0.7 - anisotropic - varying specular color |
|||
|
|||
// This function apply BSDF. Assumes that NdotL is positive. |
|||
void BSDF( float3 V, float3 L, float NdotL, float3 positionWS, PreLightData preLightData, BSDFData bsdfData, |
|||
out float3 diffuseLighting, |
|||
out float3 specularLighting) |
|||
{ |
|||
float LdotV, NdotH, LdotH, NdotV, invLenLV; |
|||
GetBSDFAngle(V, L, NdotL, preLightData.NdotV, LdotV, NdotH, LdotH, NdotV, invLenLV); |
|||
|
|||
// Fabric are dieletric but we simulate forward scattering effect with colored specular (fuzz tint term) |
|||
float3 F = F_Schlick(bsdfData.fresnel0, LdotH); |
|||
|
|||
if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_FABRIC_COTTON_WOOL)) |
|||
{ |
|||
float D = D_Charlie(NdotH, bsdfData.roughnessT); |
|||
// V_Charlie is expensive, use approx with V_Ashikhmin instead |
|||
// float Vis = V_Charlie(NdotL, NdotV, bsdfData.roughness); |
|||
float Vis = V_Ashikhmin(NdotL, NdotV); |
|||
|
|||
specularLighting = F * Vis * D; |
|||
|
|||
// Note: diffuseLighting is multiply by color in PostEvaluateBSDF |
|||
diffuseLighting = FabricLambert(bsdfData.roughnessT); |
|||
} |
|||
else // MATERIALFEATUREFLAGS_FABRIC_SILK |
|||
{ |
|||
// For silk we just use a tinted anisotropy |
|||
float3 H = (L + V) * invLenLV; |
|||
|
|||
// For anisotropy we must not saturate these values |
|||
float TdotH = dot(bsdfData.tangentWS, H); |
|||
float TdotL = dot(bsdfData.tangentWS, L); |
|||
float BdotH = dot(bsdfData.bitangentWS, H); |
|||
float BdotL = dot(bsdfData.bitangentWS, L); |
|||
|
|||
// TODO: Do comparison between this correct version and the one from isotropic and see if there is any visual difference |
|||
float DV = DV_SmithJointGGXAniso( TdotH, BdotH, NdotH, NdotV, TdotL, BdotL, NdotL, |
|||
bsdfData.roughnessT, bsdfData.roughnessB, preLightData.partLambdaV); |
|||
|
|||
specularLighting = F * DV; |
|||
|
|||
// Note: diffuseLighting is multiply by color in PostEvaluateBSDF |
|||
diffuseLighting = DisneyDiffuse(NdotV, NdotL, LdotV, bsdfData.perceptualRoughness); |
|||
} |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// EvaluateBSDF_Directional |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
DirectLighting EvaluateBSDF_Directional(LightLoopContext lightLoopContext, |
|||
float3 V, PositionInputs posInput, PreLightData preLightData, |
|||
DirectionalLightData lightData, BSDFData bsdfData, |
|||
BuiltinData builtinData) |
|||
{ |
|||
DirectLighting lighting; |
|||
ZERO_INITIALIZE(DirectLighting, lighting); |
|||
|
|||
float3 L = -lightData.forward; |
|||
float3 N = bsdfData.normalWS; |
|||
float NdotL = dot(N, L); |
|||
|
|||
float3 transmittance = float3(0.0, 0.0, 0.0); |
|||
if (HasFlag(bsdfData.materialFeatures, MATERIAL_FEATURE_FLAGS_TRANSMISSION_MODE_THIN_THICKNESS)) |
|||
{ |
|||
// Caution: This function modify N and contactShadowIndex |
|||
transmittance = PreEvaluateDirectionalLightTransmission(NdotL, lightData, bsdfData, N, lightData.contactShadowIndex); // contactShadowIndex is only modify for the code of this function |
|||
} |
|||
|
|||
float3 color; |
|||
float attenuation; |
|||
EvaluateLight_Directional(lightLoopContext, posInput, lightData, builtinData, N, L, color, attenuation); |
|||
|
|||
float intensity = max(0, attenuation * NdotL); // Warning: attenuation can be greater than 1 due to the inverse square attenuation (when position is close to light) |
|||
|
|||
UNITY_BRANCH if (intensity > 0.0) |
|||
{ |
|||
BSDF(V, L, NdotL, posInput.positionWS, preLightData, bsdfData, lighting.diffuse, lighting.specular); |
|||
|
|||
lighting.diffuse *= intensity * lightData.diffuseScale; |
|||
lighting.specular *= intensity * lightData.specularScale; |
|||
} |
|||
|
|||
// The mixed thickness mode is not supported by directional lights due to poor quality and high performance impact. |
|||
if (HasFlag(bsdfData.materialFeatures, MATERIAL_FEATURE_FLAGS_TRANSMISSION_MODE_THIN_THICKNESS)) |
|||
{ |
|||
float NdotV = ClampNdotV(preLightData.NdotV); |
|||
float LdotV = dot(L, V); |
|||
// We use diffuse lighting for accumulation since it is going to be blurred during the SSS pass. |
|||
lighting.diffuse += EvaluateTransmission(bsdfData, transmittance, NdotL, NdotV, LdotV, attenuation * lightData.diffuseScale); |
|||
} |
|||
|
|||
// Save ALU by applying light and cookie colors only once. |
|||
lighting.diffuse *= color; |
|||
lighting.specular *= color; |
|||
|
|||
#ifdef DEBUG_DISPLAY |
|||
if (_DebugLightingMode == DEBUGLIGHTINGMODE_LUX_METER) |
|||
{ |
|||
// Only lighting, not BSDF |
|||
lighting.diffuse = color * intensity * lightData.diffuseScale; |
|||
} |
|||
#endif |
|||
|
|||
return lighting; |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// EvaluateBSDF_Punctual (supports spot, point and projector lights) |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
DirectLighting EvaluateBSDF_Punctual(LightLoopContext lightLoopContext, |
|||
float3 V, PositionInputs posInput, |
|||
PreLightData preLightData, LightData lightData, BSDFData bsdfData, BuiltinData builtinData) |
|||
{ |
|||
DirectLighting lighting; |
|||
ZERO_INITIALIZE(DirectLighting, lighting); |
|||
|
|||
float3 L; |
|||
float3 lightToSample; |
|||
float4 distances; // {d, d^2, 1/d, d_proj} |
|||
GetPunctualLightVectors(posInput.positionWS, lightData, L, lightToSample, distances); |
|||
|
|||
float3 N = bsdfData.normalWS; |
|||
float NdotL = dot(N, L); |
|||
|
|||
float3 transmittance = float3(0.0, 0.0, 0.0); |
|||
if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_FABRIC_TRANSMISSION)) |
|||
{ |
|||
// Caution: This function modify N and lightData.contactShadowIndex |
|||
transmittance = PreEvaluatePunctualLightTransmission(lightLoopContext, posInput, distances.x, NdotL, L, bsdfData, N, lightData); |
|||
} |
|||
|
|||
float3 color; |
|||
float attenuation; |
|||
EvaluateLight_Punctual(lightLoopContext, posInput, lightData, builtinData, N, L, |
|||
lightToSample, distances, color, attenuation); |
|||
|
|||
float intensity = max(0, attenuation * NdotL); // Warning: attenuation can be greater than 1 due to the inverse square attenuation (when position is close to light) |
|||
|
|||
UNITY_BRANCH if (intensity > 0.0) |
|||
{ |
|||
// Simulate a sphere light with this hack |
|||
// Note that it is not correct with our pre-computation of PartLambdaV (mean if we disable the optimization we will not have the |
|||
// same result) but we don't care as it is a hack anyway |
|||
bsdfData.roughnessT = max(bsdfData.roughnessT, lightData.minRoughness); |
|||
bsdfData.roughnessB = max(bsdfData.roughnessB, lightData.minRoughness); |
|||
|
|||
BSDF(V, L, NdotL, posInput.positionWS, preLightData, bsdfData, lighting.diffuse, lighting.specular); |
|||
|
|||
lighting.diffuse *= intensity * lightData.diffuseScale; |
|||
lighting.specular *= intensity * lightData.specularScale; |
|||
} |
|||
|
|||
// Save ALU by applying light and cookie colors only once. |
|||
lighting.diffuse *= color; |
|||
lighting.specular *= color; |
|||
|
|||
if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_FABRIC_TRANSMISSION)) |
|||
{ |
|||
float NdotV = ClampNdotV(preLightData.NdotV); |
|||
float LdotV = dot(L, V); |
|||
// We use diffuse lighting for accumulation since it is going to be blurred during the SSS pass. |
|||
lighting.diffuse += EvaluateTransmission(bsdfData, transmittance, NdotL, NdotV, LdotV, attenuation * lightData.diffuseScale); |
|||
} |
|||
|
|||
#ifdef DEBUG_DISPLAY |
|||
if (_DebugLightingMode == DEBUGLIGHTINGMODE_LUX_METER) |
|||
{ |
|||
// Only lighting, not BSDF |
|||
lighting.diffuse = color * intensity * lightData.diffuseScale; |
|||
} |
|||
#endif |
|||
|
|||
return lighting; |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// EvaluateBSDF_Line |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
DirectLighting EvaluateBSDF_Line( LightLoopContext lightLoopContext, |
|||
float3 V, PositionInputs posInput, |
|||
PreLightData preLightData, LightData lightData, BSDFData bsdfData, BuiltinData builtinData) |
|||
{ |
|||
DirectLighting lighting; |
|||
ZERO_INITIALIZE(DirectLighting, lighting); |
|||
|
|||
// TODO |
|||
|
|||
return lighting; |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// EvaluateBSDF_Rect |
|||
//----------------------------------------------------------------------------- |
|||
|
|||
DirectLighting EvaluateBSDF_Rect( LightLoopContext lightLoopContext, |
|||
float3 V, PositionInputs posInput, |
|||
PreLightData preLightData, LightData lightData, BSDFData bsdfData, BuiltinData builtinData) |
|||
{ |
|||
DirectLighting lighting; |
|||
ZERO_INITIALIZE(DirectLighting, lighting); |
|||
|
|||
// TODO |
|||
|
|||
return lighting; |
|||
} |
|||
|
|||
DirectLighting EvaluateBSDF_Area(LightLoopContext lightLoopContext, |
|||
float3 V, PositionInputs posInput, |
|||
PreLightData preLightData, LightData lightData, |
|||
BSDFData bsdfData, BuiltinData builtinData) |
|||
{ |
|||
if (lightData.lightType == GPULIGHTTYPE_LINE) |
|||
{ |
|||
return EvaluateBSDF_Line(lightLoopContext, V, posInput, preLightData, lightData, bsdfData, builtinData); |
|||
} |
|||
else |
|||
{ |
|||
return EvaluateBSDF_Rect(lightLoopContext, V, posInput, preLightData, lightData, bsdfData, builtinData); |
|||
} |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// EvaluateBSDF_SSLighting for screen space lighting |
|||
// ---------------------------------------------------------------------------- |
|||
|
|||
IndirectLighting EvaluateBSDF_SSLighting(LightLoopContext lightLoopContext, |
|||
float3 V, PositionInputs posInput, |
|||
PreLightData preLightData, BSDFData bsdfData, |
|||
EnvLightData envLightData, |
|||
int GPUImageBasedLightingType, |
|||
inout float hierarchyWeight) |
|||
{ |
|||
IndirectLighting lighting; |
|||
ZERO_INITIALIZE(IndirectLighting, lighting); |
|||
|
|||
// TODO |
|||
|
|||
return lighting; |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// EvaluateBSDF_Env |
|||
// ---------------------------------------------------------------------------- |
|||
|
|||
// _preIntegratedFGD and _CubemapLD are unique for each BRDF |
|||
IndirectLighting EvaluateBSDF_Env( LightLoopContext lightLoopContext, |
|||
float3 V, PositionInputs posInput, |
|||
PreLightData preLightData, EnvLightData lightData, BSDFData bsdfData, |
|||
int influenceShapeType, int GPUImageBasedLightingType, |
|||
inout float hierarchyWeight) |
|||
{ |
|||
IndirectLighting lighting; |
|||
ZERO_INITIALIZE(IndirectLighting, lighting); |
|||
|
|||
if (GPUImageBasedLightingType == GPUIMAGEBASEDLIGHTINGTYPE_REFRACTION) |
|||
return lighting; |
|||
|
|||
float3 envLighting; |
|||
float3 positionWS = posInput.positionWS; |
|||
float weight = 1.0; |
|||
|
|||
float3 R = preLightData.iblR; |
|||
|
|||
if ((lightData.envIndex & 1) == ENVCACHETYPE_CUBEMAP) |
|||
{ |
|||
R = GetSpecularDominantDir(bsdfData.normalWS, R, preLightData.iblPerceptualRoughness, ClampNdotV(preLightData.NdotV)); |
|||
// When we are rough, we tend to see outward shifting of the reflection when at the boundary of the projection volume |
|||
// Also it appear like more sharp. To avoid these artifact and at the same time get better match to reference we lerp to original unmodified reflection. |
|||
// Formula is empirical. |
|||
float roughness = PerceptualRoughnessToRoughness(preLightData.iblPerceptualRoughness); |
|||
R = lerp(R, preLightData.iblR, saturate(smoothstep(0, 1, roughness * roughness))); |
|||
} |
|||
|
|||
// Note: using influenceShapeType and projectionShapeType instead of (lightData|proxyData).shapeType allow to make compiler optimization in case the type is know (like for sky) |
|||
EvaluateLight_EnvIntersection(positionWS, bsdfData.normalWS, lightData, influenceShapeType, R, weight); |
|||
|
|||
float iblMipLevel; |
|||
// TODO: We need to match the PerceptualRoughnessToMipmapLevel formula for planar, so we don't do this test (which is specific to our current lightloop) |
|||
// Specific case for Texture2Ds, their convolution is a gaussian one and not a GGX one - So we use another roughness mip mapping. |
|||
#if !defined(SHADER_API_METAL) |
|||
if (IsEnvIndexTexture2D(lightData.envIndex)) |
|||
{ |
|||
// Empirical remapping |
|||
iblMipLevel = PositivePow(preLightData.iblPerceptualRoughness, 0.8) * uint(max(_ColorPyramidScale.z - 1, 0)); |
|||
} |
|||
else |
|||
#endif |
|||
{ |
|||
iblMipLevel = PerceptualRoughnessToMipmapLevel(preLightData.iblPerceptualRoughness); |
|||
} |
|||
|
|||
float4 preLD = SampleEnv(lightLoopContext, lightData.envIndex, R, iblMipLevel); |
|||
weight *= preLD.a; // Used by planar reflection to discard pixel |
|||
|
|||
envLighting = preLightData.specularFGD * preLD.rgb; |
|||
|
|||
UpdateLightingHierarchyWeights(hierarchyWeight, weight); |
|||
envLighting *= weight * lightData.multiplier; |
|||
lighting.specularReflected = envLighting; |
|||
|
|||
return lighting; |
|||
} |
|||
|
|||
//----------------------------------------------------------------------------- |
|||
// PostEvaluateBSDF |
|||
// ---------------------------------------------------------------------------- |
|||
|
|||
void PostEvaluateBSDF( LightLoopContext lightLoopContext, |
|||
float3 V, PositionInputs posInput, |
|||
PreLightData preLightData, BSDFData bsdfData, BuiltinData builtinData, AggregateLighting lighting, |
|||
out float3 diffuseLighting, out float3 specularLighting) |
|||
{ |
|||
AmbientOcclusionFactor aoFactor; |
|||
GetScreenSpaceAmbientOcclusionMultibounce(posInput.positionSS, preLightData.NdotV, bsdfData.perceptualRoughness, bsdfData.ambientOcclusion, bsdfData.specularOcclusion, bsdfData.diffuseColor, bsdfData.fresnel0, aoFactor); |
|||
ApplyAmbientOcclusionFactor(aoFactor, builtinData, lighting); |
|||
|
|||
// Subsurface scattering mode |
|||
float3 modifiedDiffuseColor = GetModifiedDiffuseColorForSSS(bsdfData); |
|||
|
|||
// Apply the albedo to the direct diffuse lighting (only once). The indirect (baked) |
|||
// diffuse lighting has already multiply the albedo in ModifyBakedDiffuseLighting(). |
|||
diffuseLighting = modifiedDiffuseColor * lighting.direct.diffuse + builtinData.bakeDiffuseLighting + builtinData.emissiveColor; |
|||
specularLighting = lighting.direct.specular + lighting.indirect.specularReflected; |
|||
|
|||
// TODO: Multiscattering for cloth? |
|||
|
|||
#ifdef DEBUG_DISPLAY |
|||
PostEvaluateBSDFDebugDisplay(aoFactor, builtinData, lighting, bsdfData.diffuseColor, diffuseLighting, specularLighting); |
|||
#endif |
|||
} |
|||
|
|||
#endif // #ifdef HAS_LIGHTLOOP |
|
|||
Shader "HDRenderPipeline/Fabric" |
|||
{ |
|||
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 |
|||
// Be careful, do not change the name here to _Color. It will conflict with the "fake" parameters (see end of properties) required for GI. |
|||
_BaseColor("BaseColor", Color) = (1,1,1,1) |
|||
_BaseColorMap("BaseColorMap", 2D) = "white" {} |
|||
|
|||
_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 |
|||
_NormalScale("_NormalScale", Range(0.0, 2.0)) = 1 |
|||
|
|||
_BentNormalMap("_BentNormalMap", 2D) = "bump" {} |
|||
|
|||
_FuzzTint("FuzzTint", Color) = (1.0, 1.0, 1.0) |
|||
[Enum(Silk, 0, CottonWool, 1)] _FabricType("Fabric Type", Float) = 0 |
|||
|
|||
_DetailMap("DetailMap", 2D) = "black" {} |
|||
_DetailMask("DetailMask", 2D) = "white" {} |
|||
_DetailFuzz1("_DetailFuzz1", Range(0.0, 1.0)) = 1 |
|||
_DetailAOScale("_DetailAOScale", Range(0.0, 2.0)) = 1 |
|||
_DetailNormalScale("_DetailNormalScale", Range(0.0, 2.0)) = 1 |
|||
_DetailSmoothnessScale("_DetailSmoothnessScale", Range(0.0, 2.0)) = 1 |
|||
|
|||
[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 |
|||
|
|||
_TangentMap("TangentMap", 2D) = "bump" {} |
|||
_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) |
|||
|
|||
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3)] _UVBase("UV Set for base", Float) = 0 |
|||
[HideInInspector] _UVMappingMask("_UVMappingMask", Color) = (1, 0, 0, 0) |
|||
|
|||
[ToggleUI] _EnableSpecularOcclusion("Enable specular occlusion", Float) = 0.0 |
|||
|
|||
[ToggleUI] _EnableSubsurfaceScattering("_EnableSubsurfaceScattering", Float) = 0.0 |
|||
[ToggleUI] _EnableTransmission("_EnableTransmission", Float) = 0.0 |
|||
|
|||
// Transparency |
|||
[ToggleUI] _PreRefractionPass("PreRefractionPass", Float) = 0.0 |
|||
|
|||
[ToggleUI] _AlphaCutoffEnable("Alpha Cutoff Enable", Float) = 0.0 |
|||
_AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5 |
|||
_TransparentSortPriority("_TransparentSortPriority", Float) = 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] _ZTestDepthEqualForOpaque("_ZTestDepthEqualForOpaque", Int) = 4 // Less equal |
|||
|
|||
[ToggleUI] _EnableFogOnTransparent("Enable Fog", Float) = 1.0 |
|||
[ToggleUI] _EnableBlendModePreserveSpecularLighting("Enable Blend Mode Preserve Specular Lighting", Float) = 1.0 |
|||
|
|||
// 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 |
|||
} |
|||
|
|||
HLSLINCLUDE |
|||
|
|||
#pragma target 4.5 |
|||
#pragma only_renderers d3d11 ps4 xboxone vulkan metal |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Variant |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#pragma shader_feature _ALPHATEST_ON |
|||
|
|||
#pragma shader_feature _NORMALMAP |
|||
#pragma shader_feature _MASKMAP |
|||
#pragma shader_feature _BENTNORMALMAP |
|||
#pragma shader_feature _ENABLESPECULAROCCLUSION |
|||
#pragma shader_feature _TANGENTMAP |
|||
#pragma shader_feature _ANISOTROPYMAP |
|||
#pragma shader_feature _DETAIL_MAP |
|||
#pragma shader_feature _SUBSURFACE_MASK_MAP |
|||
#pragma shader_feature _THICKNESSMAP |
|||
|
|||
// 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 // Anisotropy is for Silk |
|||
|
|||
//enable GPU instancing support |
|||
#pragma multi_compile_instancing |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Define |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#define UNITY_MATERIAL_FABRIC // Need to be define before including Material.hlsl |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// Include |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#include "CoreRP/ShaderLibrary/Common.hlsl" |
|||
#include "HDRP/ShaderPass/FragInputs.hlsl" |
|||
#include "HDRP/ShaderPass/ShaderPass.cs.hlsl" |
|||
|
|||
//------------------------------------------------------------------------------------- |
|||
// variable declaration |
|||
//------------------------------------------------------------------------------------- |
|||
|
|||
#include "HDRP/Material/Fabric/FabricProperties.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" = "HDFabricShader" } |
|||
|
|||
// Caution: The outline selection in the editor use the vertex shader/hull/domain shader of the first pass declare. So it should not be the meta pass. |
|||
|
|||
Pass |
|||
{ |
|||
Name "Depth prepass" |
|||
Tags{ "LightMode" = "DepthForwardOnly" } |
|||
|
|||
Cull[_CullMode] |
|||
|
|||
ZWrite On |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#define SHADERPASS SHADERPASS_DEPTH_ONLY |
|||
#include "HDRP/ShaderVariables.hlsl" |
|||
#include "HDRP/Material/Material.hlsl" |
|||
#include "ShaderPass/FabricDepthPass.hlsl" |
|||
#include "FabricData.hlsl" |
|||
#include "HDRP/ShaderPass/ShaderPassDepthOnly.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
// Extracts information for lightmapping, GI (emission, albedo, ...) |
|||
// This pass it not used during regular rendering. |
|||
Pass |
|||
{ |
|||
Name "META" |
|||
Tags{ "LightMode" = "Meta" } |
|||
|
|||
Cull Off |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
// Lightmap memo |
|||
// DYNAMICLIGHTMAP_ON is used when we have an "enlighten lightmap" ie a lightmap updated at runtime by enlighten.This lightmap contain indirect lighting from realtime lights and realtime emissive material.Offline baked lighting(from baked material / light, |
|||
// both direct and indirect lighting) will hand up in the "regular" lightmap->LIGHTMAP_ON. |
|||
|
|||
#define SHADERPASS SHADERPASS_LIGHT_TRANSPORT |
|||
#include "HDRP/ShaderVariables.hlsl" |
|||
#include "HDRP/Material/Material.hlsl" |
|||
#include "ShaderPass/FabricSharePass.hlsl" |
|||
#include "FabricData.hlsl" |
|||
#include "HDRP/ShaderPass/ShaderPassLightTransport.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
Pass |
|||
{ |
|||
Name "ShadowCaster" |
|||
Tags{ "LightMode" = "ShadowCaster" } |
|||
|
|||
Cull[_CullMode] |
|||
|
|||
ZClip [_ZClip] |
|||
ZWrite On |
|||
ZTest LEqual |
|||
|
|||
ColorMask 0 |
|||
|
|||
HLSLPROGRAM |
|||
|
|||
#define SHADERPASS SHADERPASS_SHADOWS |
|||
#define USE_LEGACY_UNITY_MATRIX_VARIABLES |
|||
#include "HDRP/ShaderVariables.hlsl" |
|||
#include "HDRP/Material/Material.hlsl" |
|||
|
|||
#include "ShaderPass/FabricDepthPass.hlsl" |
|||
#include "FabricData.hlsl" |
|||
#include "HDRP/ShaderPass/ShaderPassDepthOnly.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
// Fabric shader always render in forward |
|||
Pass |
|||
{ |
|||
Name "Forward" // Name is not used |
|||
Tags { "LightMode" = "ForwardOnly" } |
|||
|
|||
Stencil |
|||
{ |
|||
WriteMask [_StencilWriteMask] |
|||
Ref [_StencilRef] |
|||
Comp Always |
|||
Pass Replace |
|||
} |
|||
|
|||
Blend [_SrcBlend] [_DstBlend] |
|||
// In case of forward we want to have depth equal for opaque alpha tested mesh |
|||
ZTest [_ZTestDepthEqualForOpaque] |
|||
ZWrite [_ZWrite] |
|||
|
|||
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 |
|||
|
|||
// #include "HDRP/Lighting/Forward.hlsl" : nothing left in there. |
|||
//#pragma multi_compile LIGHTLOOP_SINGLE_PASS LIGHTLOOP_TILE_PASS |
|||
#define LIGHTLOOP_TILE_PASS |
|||
#pragma multi_compile USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST |
|||
|
|||
#define SHADERPASS SHADERPASS_FORWARD |
|||
#include "HDRP/ShaderVariables.hlsl" |
|||
#ifdef DEBUG_DISPLAY |
|||
#include "HDRP/Debug/DebugDisplay.hlsl" |
|||
#endif |
|||
#include "HDRP/Lighting/Lighting.hlsl" |
|||
//...this will include #include "HDRP/Material/Material.hlsl" but also LightLoop which the forward pass directly uses. |
|||
|
|||
#include "ShaderPass/FabricSharePass.hlsl" |
|||
#include "FabricData.hlsl" |
|||
#include "HDRP/ShaderPass/ShaderPassForward.hlsl" |
|||
|
|||
ENDHLSL |
|||
} |
|||
|
|||
} |
|||
|
|||
CustomEditor "Experimental.Rendering.HDPipeline.FabricGUI" |
|||
} |
|
|||
//------------------------------------------------------------------------------------- |
|||
// Fill SurfaceData/Builtin data function |
|||
//------------------------------------------------------------------------------------- |
|||
#include "HDRP/Material/MaterialUtilities.hlsl" |
|||
|
|||
void GetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData) |
|||
{ |
|||
// TODO: Remove this zero initialize once we have written all the code |
|||
ZERO_INITIALIZE(SurfaceData, surfaceData); |
|||
|
|||
surfaceData.normalWS = input.worldToTangent[2].xyz; |
|||
|
|||
float2 baseColorMapUv = TRANSFORM_TEX(input.texCoord0, _BaseColorMap); |
|||
surfaceData.baseColor = SAMPLE_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, baseColorMapUv).rgb * _BaseColor.rgb; |
|||
float alpha = SAMPLE_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, baseColorMapUv).a * _BaseColor.a; |
|||
|
|||
#ifdef _ALPHATEST_ON |
|||
DoAlphaTest(alpha, _AlphaCutoff); |
|||
#endif |
|||
|
|||
#if defined(DEBUG_DISPLAY) |
|||
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) |
|||
{ |
|||
surfaceData.baseColor = GetTextureDataDebug(_DebugMipMapMode, baseColorMapUv, _BaseColorMap, _BaseColorMap_TexelSize, _BaseColorMap_MipInfo, surfaceData.baseColor); |
|||
} |
|||
#endif |
|||
|
|||
// ------------------------------------------------------------- |
|||
// Builtin Data |
|||
// ------------------------------------------------------------- |
|||
|
|||
// For back lighting we use the oposite vertex normal |
|||
InitBuiltinData(alpha, surfaceData.normalWS, -input.worldToTangent[2], input.positionRWS, input.texCoord1, input.texCoord2, builtinData); |
|||
PostInitBuiltinData(V, posInput, surfaceData, builtinData); |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7f4bd5fb4bd314640b06d4e3b54a9a4b |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 831a16854a7b1024dae2c848b1ccddd9 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue