浏览代码

change perceptualSmoothness - perceptualRoughness

/main
sebastienlagarde 6 年前
当前提交
03a88ecd
共有 3 个文件被更改,包括 17 次插入17 次删除
  1. 24
      com.unity.render-pipelines.high-definition/HDRP/Material/Lit/Lit.hlsl
  2. 6
      com.unity.render-pipelines.high-definition/HDRP/Material/NormalBuffer.hlsl
  3. 4
      com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.hlsl

24
com.unity.render-pipelines.high-definition/HDRP/Material/Lit/Lit.hlsl


// Note: We can't handle clear coat material here, we have only one slot to store smoothness
// and the buffer is the GBuffer1.
normalData.normalWS = surfaceData.normalWS;
normalData.perceptualSmoothness = surfaceData.perceptualSmoothness;
normalData.perceptualRoughness = PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness);
void UpdateSurfaceDataFromNormalData(uint2 positionSS, inout SurfaceData surfaceData)
void UpdateSurfaceDataFromNormalData(uint2 positionSS, inout BSDFData bsdfData)
surfaceData.normalWS = normalData.normalWS;
surfaceData.perceptualSmoothness = normalData.perceptualSmoothness;
bsdfData.normalWS = normalData.normalWS;
bsdfData.perceptualRoughness = normalData.perceptualRoughness;
}
//-----------------------------------------------------------------------------

BSDFData bsdfData;
ZERO_INITIALIZE(BSDFData, bsdfData);
// Check if we read value of normal and roughness from buffer. This is a tradeoff
#ifdef FORWARD_MATERIAL_READ_FROM_WRITTEN_NORMAL_BUFFER
#if (SHADERPASS == SHADERPASS_FORWARD) && !defined(_SURFACE_TYPE_TRANSPARENT)
UpdateSurfaceDataFromNormalData(positionSS, surfaceData);
#endif
#endif
// 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.perceptualRoughness = PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness);
// Check if we read value of normal and roughness from buffer. This is a tradeoff
#ifdef FORWARD_MATERIAL_READ_FROM_WRITTEN_NORMAL_BUFFER
#if (SHADERPASS == SHADERPASS_FORWARD) && !defined(_SURFACE_TYPE_TRANSPARENT)
UpdateSurfaceDataFromNormalData(positionSS, bsdfData);
#endif
#endif
// There is no metallic with SSS and specular color mode
float metallic = HasFeatureFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR | MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING | MATERIALFEATUREFLAGS_LIT_TRANSMISSION) ? 0.0 : surfaceData.metallic;

NormalData normalData;
DecodeFromNormalBuffer(inGBuffer1, positionSS, normalData);
bsdfData.normalWS = normalData.normalWS;
bsdfData.perceptualRoughness = PerceptualSmoothnessToPerceptualRoughness(normalData.perceptualSmoothness);
bsdfData.perceptualRoughness = normalData.perceptualRoughness;
bakeDiffuseLighting = inGBuffer3.rgb;

6
com.unity.render-pipelines.high-definition/HDRP/Material/NormalBuffer.hlsl


struct NormalData
{
float3 normalWS;
float perceptualSmoothness;
float perceptualRoughness;
};
#define NormalBufferType0 float4 // Must match GBufferType1 in deferred

float2 octNormalWS = PackNormalOctQuadEncode(normalData.normalWS);
float3 packNormalWS = PackFloat2To888(saturate(octNormalWS * 0.5 + 0.5));
// We store perceptualRoughness instead of roughness because it is perceptually linear.
outNormalBuffer0 = float4(packNormalWS, normalData.perceptualSmoothness);
outNormalBuffer0 = float4(packNormalWS, normalData.perceptualRoughness);
}
void DecodeFromNormalBuffer(float4 normalBuffer, uint2 positionSS, out NormalData normalData)

normalData.normalWS = UnpackNormalOctQuadEncode(octNormalWS * 2.0 - 1.0);
normalData.perceptualSmoothness = normalBuffer.a;
normalData.perceptualRoughness = normalBuffer.a;
}
void DecodeFromNormalBuffer(uint2 positionSS, out NormalData normalData)

4
com.unity.render-pipelines.high-definition/HDRP/Material/StackLit/StackLit.hlsl


if (HasFeatureFlag(surfaceData.materialFeatures, MATERIALFEATUREFLAGS_STACK_LIT_COAT))
{
normalData.normalWS = surfaceData.coatNormalWS;
normalData.perceptualSmoothness = surfaceData.coatPerceptualSmoothness;
normalData.perceptualRoughness = surfaceData.coatPerceptualSmoothness;
normalData.perceptualSmoothness = lerp(surfaceData.perceptualSmoothnessA, surfaceData.perceptualSmoothnessB, surfaceData.lobeMix);
normalData.perceptualRoughness = PerceptualSmoothnessToPerceptualRoughness(lerp(surfaceData.perceptualSmoothnessA, surfaceData.perceptualSmoothnessB, surfaceData.lobeMix));
}
return normalData;

正在加载...
取消
保存