浏览代码

Merge pull request #222 from EvgeniiG/master

Fix SSS in the player
/Branch_Batching2
GitHub 8 年前
当前提交
df06f984
共有 6 个文件被更改,包括 40 次插入39 次删除
  1. 10
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  2. 1
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl
  3. 1
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.shader
  4. 6
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl
  5. 1
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitTessellation.shader
  6. 60
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SubsurfaceScatteringProfile.cs

10
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


}
// Broadcast SSS parameters to all shaders.
Shader.SetGlobalInt("_EnableSSS", globalDebugSettings.renderingDebugSettings.enableSSS ? 1 : 0);
if (globalDebugSettings.renderingDebugSettings.enableSSS)
{
cmd.EnableShaderKeyword("_SUBSURFACE_SCATTERING");
}
else
{
cmd.DisableShaderKeyword("_SUBSURFACE_SCATTERING");
}
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();

1
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl


// SSS parameters
#define SSS_N_PROFILES 8
#define SSS_UNIT_CONVERSION (1.0 / 300.0) // From meters to 1/3 centimeters
uint _EnableSSS; // Globally toggles subsurface scattering on/off
uint _TransmissionFlags; // 1 bit/profile; 0 = inf. thick, 1 = supports transmission
uint _TexturingModeFlags; // 1 bit/profile; 0 = PreAndPostScatter, 1 = PostScatter
float _ThicknessRemaps[SSS_N_PROFILES][2]; // Remap: 0 = start, 1 = end - start

1
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.shader


#pragma shader_feature _DETAIL_MAP
#pragma shader_feature _SUBSURFACE_RADIUS_MAP
#pragma shader_feature _THICKNESS_MAP
#pragma shader_feature _SUBSURFACE_SCATTERING
#pragma shader_feature _VERTEX_WIND
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON

6
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitDataInternal.hlsl


// 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)
#ifdef _SUBSURFACE_SCATTERING
surfaceData.materialId = _MaterialID;
#else
surfaceData.materialId = (_MaterialID == MATERIALID_LIT_SSS) ? 0 : _MaterialID;
#endif
surfaceData.materialId = (_EnableSSS || _MaterialID != MATERIALID_LIT_SSS) ? _MaterialID : MATERIALID_LIT_STANDARD;
// TODO: think about using BC5
#ifdef _TANGENTMAP

1
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitTessellation.shader


#pragma shader_feature _DETAIL_MAP
#pragma shader_feature _SUBSURFACE_RADIUS_MAP
#pragma shader_feature _THICKNESS_MAP
#pragma shader_feature _SUBSURFACE_SCATTERING
#pragma shader_feature _VERTEX_WIND
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON

60
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SubsurfaceScatteringProfile.cs


}
[Serializable]
public class SubsurfaceScatteringSettings
public class SubsurfaceScatteringSettings : ISerializationCallbackReceiver
{
public const int maxNumProfiles = 8;
public const int neutralProfileID = 7;

halfRcpWeightedVariances = null;
filterKernels = null;
OnValidate(); // Perform initialization
UpdateCache();
}
public void OnValidate()

}
}
if (thicknessRemaps == null || thicknessRemaps.Length != (maxNumProfiles * 2))
{
thicknessRemaps = new float[maxNumProfiles * 2];
}
if (halfRcpVariancesAndLerpWeights == null || halfRcpVariancesAndLerpWeights.Length != (maxNumProfiles * 2))
{
halfRcpVariancesAndLerpWeights = new Vector4[maxNumProfiles * 2];
}
if (halfRcpWeightedVariances == null || halfRcpWeightedVariances.Length != maxNumProfiles)
{
halfRcpWeightedVariances = new Vector4[maxNumProfiles];
}
if (filterKernels == null || filterKernels.Length != (maxNumProfiles * SubsurfaceScatteringProfile.numSamples))
{
filterKernels = new Vector4[maxNumProfiles * SubsurfaceScatteringProfile.numSamples];
}
Color c = new Color();
for (int i = 0; i < numProfiles; i++)

profiles[i].UpdateKernelAndVarianceData();
}
UpdateCache();
}
public void UpdateCache()
{
// Use the updated data to fill the cache.
if (thicknessRemaps == null || thicknessRemaps.Length != (maxNumProfiles * 2))
{
thicknessRemaps = new float[maxNumProfiles * 2];
}
if (halfRcpVariancesAndLerpWeights == null || halfRcpVariancesAndLerpWeights.Length != (maxNumProfiles * 2))
{
halfRcpVariancesAndLerpWeights = new Vector4[maxNumProfiles * 2];
}
if (halfRcpWeightedVariances == null || halfRcpWeightedVariances.Length != maxNumProfiles)
{
halfRcpWeightedVariances = new Vector4[maxNumProfiles];
}
if (filterKernels == null || filterKernels.Length != (maxNumProfiles * SubsurfaceScatteringProfile.numSamples))
{
filterKernels = new Vector4[maxNumProfiles * SubsurfaceScatteringProfile.numSamples];
}
for (int i = 0; i < numProfiles; i++)
{
// Skip unassigned profiles.

filterKernels[n * i + j].w = 0.0f;
}
}
}
public void OnBeforeSerialize()
{
// No special action required.
}
public void OnAfterDeserialize()
{
UpdateCache();
}
}

正在加载...
取消
保存