浏览代码

first compile version

/feature-ReflectionProbeFit
Sebastien Lagarde 7 年前
当前提交
c514f914
共有 9 个文件被更改,包括 60 次插入95 次删除
  1. 15
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Lit/LitUI.cs
  2. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.cs
  3. 50
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.cs.hlsl
  4. 65
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl
  5. 3
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.shader
  6. 8
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitDataIndividualLayer.hlsl
  7. 3
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitProperties.hlsl
  8. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitReference.hlsl
  9. 3
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitTessellation.shader

15
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Material/Lit/LitUI.cs


public static GUIContent thicknessRemapText = new GUIContent("Thickness Remap", "Remaps values of the thickness map from [0, 1] to the specified range.");
// Clear Coat
public static GUIContent coatCoverageText = new GUIContent("Coat Coverage", "Percentage of clear coat coverage");
public static GUIContent coatIORText = new GUIContent("Coat IOR", "IOR of clear coat, value is [0..1] + 1.0. i.e 0.5 is IOR 1.5");
public static GUIContent coatMaskText = new GUIContent("Coat Mask", "attenuate the coating effect (similar to change to IOR of 1");
// Specular color
public static GUIContent specularColorText = new GUIContent("Specular Color", "Specular color (RGB)");

protected MaterialProperty anisotropyMap = null;
protected const string kAnisotropyMap = "_AnisotropyMap";
protected MaterialProperty coatCoverage = null;
protected const string kCoatCoverage = "_CoatCoverage";
protected MaterialProperty coatIOR = null;
protected const string kCoatIOR = "_CoatIOR";
protected MaterialProperty coatMask = null;
protected const string kCoatMask = "_CoatMask";
protected MaterialProperty emissiveColorMode = null;
protected const string kEmissiveColorMode = "_EmissiveColorMode";

anisotropyMap = FindProperty(kAnisotropyMap, props);
// clear coat
coatCoverage = FindProperty(kCoatCoverage, props);
coatIOR = FindProperty(kCoatIOR, props);
coatMask = FindProperty(kCoatMask, props);
// Transparency
refractionMode = FindProperty(kRefractionMode, props, false);

protected void ShaderClearCoatInputGUI()
{
m_MaterialEditor.ShaderProperty(coatCoverage, Styles.coatCoverageText);
m_MaterialEditor.ShaderProperty(coatIOR, Styles.coatIORText);
m_MaterialEditor.ShaderProperty(coatMask, Styles.coatMaskText);
}
protected void ShaderAnisoInputGUI()

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.cs


// fold into fresnel0
// ClearCoat
public Vector3 coatNormalWS;
public float coatCoverage;
public float coatIOR; // CoatIOR is in range[1..2] it is surfaceData + 1
public float coatMask;
// Only in forward
// Transparency

50
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.cs.hlsl


#define DEBUGVIEW_LIT_SURFACEDATA_THICKNESS (1010)
#define DEBUGVIEW_LIT_SURFACEDATA_SUBSURFACE_PROFILE (1011)
#define DEBUGVIEW_LIT_SURFACEDATA_SPECULAR_COLOR (1012)
#define DEBUGVIEW_LIT_SURFACEDATA_COAT_NORMAL_WS (1013)
#define DEBUGVIEW_LIT_SURFACEDATA_COAT_COVERAGE (1014)
#define DEBUGVIEW_LIT_SURFACEDATA_COAT_IOR (1015)
#define DEBUGVIEW_LIT_SURFACEDATA_IOR (1016)
#define DEBUGVIEW_LIT_SURFACEDATA_TRANSMITTANCE_COLOR (1017)
#define DEBUGVIEW_LIT_SURFACEDATA_AT_DISTANCE (1018)
#define DEBUGVIEW_LIT_SURFACEDATA_TRANSMITTANCE_MASK (1019)
#define DEBUGVIEW_LIT_SURFACEDATA_COAT_MASK (1013)
#define DEBUGVIEW_LIT_SURFACEDATA_IOR (1014)
#define DEBUGVIEW_LIT_SURFACEDATA_TRANSMITTANCE_COLOR (1015)
#define DEBUGVIEW_LIT_SURFACEDATA_AT_DISTANCE (1016)
#define DEBUGVIEW_LIT_SURFACEDATA_TRANSMITTANCE_MASK (1017)
//
// UnityEngine.Experimental.Rendering.HDPipeline.Lit+BSDFData: static fields

#define DEBUGVIEW_LIT_BSDFDATA_ENABLE_TRANSMISSION (1044)
#define DEBUGVIEW_LIT_BSDFDATA_USE_THICK_OBJECT_MODE (1045)
#define DEBUGVIEW_LIT_BSDFDATA_TRANSMITTANCE (1046)
#define DEBUGVIEW_LIT_BSDFDATA_COAT_NORMAL_WS (1047)
#define DEBUGVIEW_LIT_BSDFDATA_COAT_COVERAGE (1048)
#define DEBUGVIEW_LIT_BSDFDATA_COAT_IOR (1049)
#define DEBUGVIEW_LIT_BSDFDATA_IOR (1050)
#define DEBUGVIEW_LIT_BSDFDATA_ABSORPTION_COEFFICIENT (1051)
#define DEBUGVIEW_LIT_BSDFDATA_TRANSMITTANCE_MASK (1052)
#define DEBUGVIEW_LIT_BSDFDATA_COAT_MASK (1047)
#define DEBUGVIEW_LIT_BSDFDATA_IOR (1048)
#define DEBUGVIEW_LIT_BSDFDATA_ABSORPTION_COEFFICIENT (1049)
#define DEBUGVIEW_LIT_BSDFDATA_TRANSMITTANCE_MASK (1050)
//
// UnityEngine.Experimental.Rendering.HDPipeline.Lit+GBufferMaterial: static fields

float thickness;
int subsurfaceProfile;
float3 specularColor;
float3 coatNormalWS;
float coatCoverage;
float coatIOR;
float coatMask;
float ior;
float3 transmittanceColor;
float atDistance;

bool enableTransmission;
bool useThickObjectMode;
float3 transmittance;
float3 coatNormalWS;
float coatCoverage;
float coatIOR;
float coatMask;
float ior;
float3 absorptionCoefficient;
float transmittanceMask;

result = surfacedata.specularColor;
needLinearToSRGB = true;
break;
case DEBUGVIEW_LIT_SURFACEDATA_COAT_NORMAL_WS:
result = surfacedata.coatNormalWS * 0.5 + 0.5;
break;
case DEBUGVIEW_LIT_SURFACEDATA_COAT_COVERAGE:
result = surfacedata.coatCoverage.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_COAT_IOR:
result = surfacedata.coatIOR.xxx;
case DEBUGVIEW_LIT_SURFACEDATA_COAT_MASK:
result = surfacedata.coatMask.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_IOR:
result = surfacedata.ior.xxx;

case DEBUGVIEW_LIT_BSDFDATA_TRANSMITTANCE:
result = bsdfdata.transmittance;
break;
case DEBUGVIEW_LIT_BSDFDATA_COAT_NORMAL_WS:
result = bsdfdata.coatNormalWS;
break;
case DEBUGVIEW_LIT_BSDFDATA_COAT_COVERAGE:
result = bsdfdata.coatCoverage.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_COAT_IOR:
result = bsdfdata.coatIOR.xxx;
case DEBUGVIEW_LIT_BSDFDATA_COAT_MASK:
result = bsdfdata.coatMask.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_IOR:
result = bsdfdata.ior.xxx;

65
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl


// Same as MATERIALID_LIT_STANDARD + coatMask
bsdfData.diffuseColor = ComputeDiffuseColor(surfaceData.baseColor, surfaceData.metallic);
bsdfData.fresnel0 = ComputeFresnel0(surfaceData.baseColor, surfaceData.metallic, DEFAULT_SPECULAR_VALUE);
bsdfData.coatMask = coatMask;
bsdfData.coatMask = surfaceData.coatMask;
}
#if HAS_REFRACTION

float clampRoughnessT; // Clamped version of bsdfData.roughnessT for analytic light
float clampRoughnessB; // Clamped version of bsdfData.roughnessB for analytic light
// Clear coat
float ccIEta;
float3 ccRefractV; // The view vector refracted through clear coat interface
float ccRoughness;
float ccPartLambdaV;
float3 iblDirWS; // Dominant specular direction, used for IBL in EvaluateBSDF_Env()
float3 iblR; // Dominant specular direction, used for IBL in EvaluateBSDF_Env()
// IBL clear coat
float3 coatIblDirWS;
float3 specularFGD; // Store preconvoled BRDF for both specular and diffuse
float diffuseFGD;

float ltcMagnitudeDiffuse;
float3 ltcMagnitudeFresnel;
// Clear coat
float coatIEta;
float3 coatRefractV; // The view vector refracted through clear coat interface
float coatRoughness;
float coatPartLambdaV;
float3 coatIblR;
// Refraction
float3 transmissionRefractV; // refracted view vector after exiting the shape
float3 transmissionPositionWS; // start of the refracted ray after exiting the shape

// Modify V for following calculation
// Note: coatMask should be just a scale of the IOR to 1. However this only work correctly with true Fresnel equation,
// so in the code we also multiply F_Schlick by bsdfData.coatMask as an approximation
preLightData.ccIEta = lerp(1.0, CLEAR_COAT_IETA, bsdfData.coatMask);
preLightData.ccRefractV = RefractNoTIR(V, N, preLightData.ccIEta);
preLightData.ccRoughness = CLEAR_COAT_ROUGHNESS; // This can be modify in punctual light evaluation in case of minRoughness usage
preLightData.ccPartLambdaV = GetSmithJointGGXPartLambdaV(NdotV, CLEAR_COAT_ROUGHNESS); // This will not take into account the modification by minRoughness but we are ok with this
preLightData.coatIEta = lerp(1.0, CLEAR_COAT_IETA, bsdfData.coatMask);
preLightData.coatRefractV = RefractNoTIR(V, N, preLightData.coatIEta);
preLightData.coatRoughness = CLEAR_COAT_ROUGHNESS; // This can be modify in punctual light evaluation in case of minRoughness usage
preLightData.coatPartLambdaV = GetSmithJointGGXPartLambdaV(NdotV, CLEAR_COAT_ROUGHNESS); // This will not take into account the modification by minRoughness but we are ok with this
float ccRoughnessScale = Sq(preLightData.ccIEta) * (NdotV / dot(bsdfData.normalWS, preLightData.ccRefractV));
float coatRoughnessScale = Sq(preLightData.coatIEta) * (NdotV / dot(N, preLightData.coatRefractV));
preLightData.clampRoughnessT = varianceToRoughness(sigmaT * ccRoughnessScale);
preLightData.clampRoughnessT = varianceToRoughness(sigmaT * coatRoughnessScale);
preLightData.clampRoughnessB = varianceToRoughness(sigmaB * ccRoughnessScale);
preLightData.clampRoughnessB = varianceToRoughness(sigmaB * coatRoughnessScale);
preLightData.coatIblR = reflect(-V, N);
preLightData.iblPerceptualRoughness = RoughnessToPerceptualRoughness(varianceToRoughness(sigmaPR * ccRoughnessScale));
preLightData.iblPerceptualRoughness = RoughnessToPerceptualRoughness(varianceToRoughness(sigmaPR * coatRoughnessScale));
V = preLightData.ccRefractV;
V = preLightData.coatRefractV;
NdotV = saturate(dot(N, V));
}
else

iblR = reflect(-V, iblN);
float iblRoughness = PerceptualRoughnessToRoughness(preLightData.iblPerceptualRoughness);
// Corretion of reflected direction for better handling of rough material
preLightData.iblDirWS = GetSpecularDominantDir(N, iblR, iblRoughness, NdotV);
preLightData.iblR = GetSpecularDominantDir(N, iblR, iblRoughness, NdotV);
// Handle IBL + multiscattering
float reflectivity;

float NdotH = saturate((NdotL + NdotV) * invLenLV);
float LdotH = saturate(invLenLV * LdotV + invLenLV);
F = F_Schlick(CLEAR_COAT_FRESNEL0, LdotH) * bsdfData.coatMask;
// Caution: as ccRoughness can be affect by minRoughness, we don't really know the value here and need to calculate the BRDF
F = F_Schlick(CLEAR_COAT_F0, LdotH) * bsdfData.coatMask;
// Caution: as coatRoughness can be affect by minRoughness, we don't really know the value here and need to calculate the BRDF
float DV = DV_SmithJointGGX(NdotH, NdotL, NdotV, preLightData.ccRoughness, preLightData.ccPartLambdaV);
float DV = DV_SmithJointGGX(NdotH, NdotL, NdotV, preLightData.coatRoughness, preLightData.coatPartLambdaV);
specularLighting += F * DV * NdotL;
// Change the Fresnel term to account for transmission through Clear Coat

// Change the Light and View direction to account for IOR change
// Update the half vector accordingly
V = preLightData.refractV;
L = RefractNoTIR(L, N, preLightData.ccIEta);
V = preLightData.coatRefractV;
L = RefractNoTIR(L, N, preLightData.coatIEta);
NdotV = saturate(dot(N, V));
}

// same result) but we don't care as it is a hack anyway
if (bsdfData.materialId == MATERIALID_LIT_CLEAR_COAT && HasMaterialFeatureFlag(MATERIALFEATUREFLAGS_LIT_CLEAR_COAT))
{
preLightData.ccRoughness = max(bsdfData.ccRoughness, lightData.minRoughness);
preLightData.coatRoughness = max(preLightData.coatRoughness, lightData.minRoughness);
}
preLightData.clampRoughnessT = max(preLightData.clampRoughnessT, lightData.minRoughness);

// modify matL value based on Fresnel transmission
// matL = mul(matL, preLightData.ltcCoatT);
// V = preLightData.refractV;
// V = preLightData.coatRefractV;
}
// Evaluate the specular part

// Users can also chose to not have any projection, in this case we use the property minProjectionDistance to minimize code change. minProjectionDistance is set to huge number
// that simulate effect of no shape projection
float3 R = preLightData.iblDirWS;
float3 coatR = preLightData.coatIblDirWS;
float3 R = preLightData.iblR;
float3 coatR = preLightData.coatIblR;
if (GPUImageBasedLightingType == GPUIMAGEBASEDLIGHTINGTYPE_REFRACTION)
{

// Evaluate the Clear Coat component if needed
if (bsdfData.materialId == MATERIALID_LIT_CLEAR_COAT && HasMaterialFeatureFlag(MATERIALFEATUREFLAGS_LIT_CLEAR_COAT))
{
F = F_Schlick(CLEAR_COAT_FRESNEL0, preLightData.clampNdotV) * bsdfData.coatMask;
F = F_Schlick(CLEAR_COAT_F0, preLightData.clampNdotV) * bsdfData.coatMask;
// Evaluate the Clear Coat color
float4 preLD = SampleEnv(lightLoopContext, lightData.envIndex, coatR, 0.0);

// 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.iblDirWS, saturate(smoothstep(0, 1, roughness * roughness)));
float roughness = PerceptualRoughnessToRoughness(preLightData.iblPerceptualRoughness);
R = lerp(R, preLightData.iblR, saturate(smoothstep(0, 1, roughness * roughness)));
F *= preLightData.specularFGD;
float iblMipLevel = PerceptualRoughnessToMipmapLevel(preLightData.iblPerceptualRoughness);

3
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.shader


_ThicknessMap("Thickness Map", 2D) = "white" {}
_ThicknessRemap("Thickness Remap", Vector) = (0, 1, 0, 0)
_CoatCoverage("Coat Coverage", Range(0.0, 1.0)) = 1.0
_CoatIOR("Coat IOR", Range(0.0, 1.0)) = 0.5
_CoatMask("Coat Mask", Range(0.0, 1.0)) = 1.0
_SpecularColor("SpecularColor", Color) = (1, 1, 1, 1)
_SpecularColorMap("SpecularColorMap", 2D) = "white" {}

8
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitDataIndividualLayer.hlsl


surfaceData.transmittanceMask = 0.0;
#endif
surfaceData.coatNormalWS = input.worldToTangent[2].xyz; // Assign vertex normal
surfaceData.coatCoverage = _CoatCoverage;
surfaceData.coatIOR = _CoatIOR;
surfaceData.coatMask = _CoatMask;
#else // #if !defined(LAYERED_LIT_SHADER)

surfaceData.tangentWS = float3(0.0, 0.0, 0.0);
surfaceData.anisotropy = 0.0;
surfaceData.specularColor = float3(0.0, 0.0, 0.0);
surfaceData.coatNormalWS = float3(0.0, 0.0, 0.0);
surfaceData.coatCoverage = 0.0f;
surfaceData.coatIOR = 0.5;
surfaceData.coatMask = 0.0f;
// Transparency
surfaceData.ior = 1.0;

3
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitProperties.hlsl


float _Thickness;
float4 _ThicknessRemap;
float _CoatCoverage;
float _CoatIOR;
float _CoatMask;
float4 _SpecularColor;

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitReference.hlsl


uint sampleCount = 4096)
{
float3x3 localToWorld = float3x3(bsdfData.tangentWS, bsdfData.bitangentWS, bsdfData.normalWS);
float NdotV = preLightData.NdotV;
float NdotV = preLightData.clampNdotV;
float3 acc = float3(0.0, 0.0, 0.0);
// Add some jittering on Hammersley2d

localToWorld = GetLocalFrame(bsdfData.normalWS);
}
float NdotV = preLightData.NdotV;
float NdotV = preLightData.clampNdotV;
float3 acc = float3(0.0, 0.0, 0.0);
// Add some jittering on Hammersley2d

3
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitTessellation.shader


_ThicknessMap("Thickness Map", 2D) = "white" {}
_ThicknessRemap("Thickness Remap", Vector) = (0, 1, 0, 0)
_CoatCoverage("Coat Coverage", Range(0.0, 1.0)) = 1.0
_CoatIOR("Coat IOR", Range(0.0, 1.0)) = 0.5
_CoatMask("Coat Mask", Range(0.0, 1.0)) = 1.0
_SpecularColor("SpecularColor", Color) = (1, 1, 1, 1)
_SpecularColorMap("SpecularColorMap", 2D) = "white" {}

正在加载...
取消
保存