浏览代码

Merge branch 'master'

/RenderPassXR_Sandbox
Evgenii Golubev 7 年前
当前提交
c092103a
共有 8 个文件被更改,包括 55 次插入17 次删除
  1. 6
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  2. 7
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Deferred.shader
  3. 11
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/LitUI.cs
  4. 7
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/CombineSubsurfaceScattering.shader
  5. 2
      Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipeline.shader
  6. 33
      Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineCore.cginc
  7. 2
      Assets/ScriptableRenderPipeline/ShaderLibrary/Common.hlsl
  8. 4
      Assets/ScriptableRenderPipeline/ShaderLibrary/Shadow/ShadowSampling.hlsl

6
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


Shader.SetGlobalInt( "_TexturingModeFlags", (int)sssParameters.texturingModeFlags);
Shader.SetGlobalInt( "_TransmissionFlags", (int)sssParameters.transmissionFlags);
cmd.SetGlobalFloatArray( "_ThicknessRemaps", sssParameters.thicknessRemaps);
// We use the Disney transmission code with the parameters of Jimenez in order not to add an extra shader variant.
// We are currently supporting two different SSS mode: Jimenez (with 2-Gaussian profile) and Disney
// We have added the ability to switch between each other for subsurface scattering, but for transmittance this is more tricky as we need to add
// shader variant for forward, gbuffer and deferred shader. We want to avoid this.
// So for transmittance we use Disney profile formulation (that we know is more correct) in both case, and in the case of Jimenez we hack the parameters with 2-Gaussian parameters (Ideally we should fit but haven't find good fit) so it approximately match.
// Note: Jimenez SSS is in cm unit whereas Disney is in mm unit making an inconsistency here to compare model side by side
cmd.SetGlobalVectorArray("_ShapeParams", sssParameters.useDisneySSS ? sssParameters.shapeParams : sssParameters.halfRcpWeightedVariances);
cmd.SetGlobalVectorArray("_TransmissionTints", sssParameters.transmissionTints);

7
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Deferred.shader


outputs.specularLighting = float4(specularLighting, 1.0);
outputs.diffuseLighting = diffuseLighting;
#if defined(LIGHTLOOP_TILE_INDIRECT) || defined(LIGHTLOOP_TILE_ALL)
// Force non-0 indirect lighting to avoid SSS artifacts.
outputs.diffuseLighting.r = max(outputs.diffuseLighting.r, 0.000001);
// We SSSSS is enabled with use split lighting.
// SSSSS algorithm need to know which pixels contribute to SSS and which doesn't. We could use the stencil for that but it mean that it will increase the cost of SSSSS
// A simpler solution is to add a slight contribution here that isn't visible (here we chose fp16 min (which is also fp11 and fp10 min).
// The SSSSS algorithm will check if diffuse lighting is black and discard the pixel if it is the case
outputs.diffuseLighting.r = max(outputs.diffuseLighting.r, HFLT_MIN);
#endif
#else
outputs.combinedLighting = float4(diffuseLighting + specularLighting, 1.0);

11
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/LitUI.cs


// Subsurface
public static GUIContent subsurfaceProfileText = new GUIContent("Subsurface profile", "A profile determines the shape of the blur filter.");
public static GUIContent subsurfaceRadiusText = new GUIContent("Subsurface radius", "Determines the range of the blur.");
public static GUIContent subsurfaceRadiusMapText = new GUIContent("Subsurface radius map", "Determines the range of the blur.");
public static GUIContent subsurfaceRadiusMapText = new GUIContent("Subsurface radius map (R)", "Determines the range of the blur.");
public static GUIContent thicknessMapText = new GUIContent("Thickness map", "If subsurface scattering is enabled, low values allow some light to be transmitted through the object.");
public static GUIContent thicknessMapText = new GUIContent("Thickness map (R)", "If subsurface scattering is enabled, low values allow some light to be transmitted through the object.");
// Specular color
public static GUIContent specularColorText = new GUIContent("Specular Color", "Specular color (RGB)");

EditorGUI.indentLevel++;
m_MaterialEditor.TexturePropertySingleLine(Styles.baseColorText, baseColorMap, baseColor);
m_MaterialEditor.ShaderProperty(metallic, Styles.metallicText);
if ((Lit.MaterialId)materialID.floatValue == Lit.MaterialId.LitStandard)
{
m_MaterialEditor.ShaderProperty(metallic, Styles.metallicText);
}
m_MaterialEditor.ShaderProperty(smoothness, Styles.smoothnessText);
if (useEmissiveMask)

7
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/CombineSubsurfaceScattering.shader


/* Our blur is energy-preserving, so 'centerWeight' should be set to 0. */ \
/* We do not terminate the loop since we want to gather the contribution */ \
/* of the remaining samples (e.g. in case of hair covering skin). */ \
/* Note: See comment in the output of deferred.shader */ \
/*************************************************************************/ \
} \
}

// Compute the filtering direction.
#ifdef SSS_FILTER_HORIZONTAL_AND_COMBINE
float2 unitDir = float2(1, 0);
float2 unitDirection = float2(1, 0);
float2 unitDir = float2(0, 1);
float2 unitDirection = float2(0, 1);
float2 scaledDirection = pixelsPerCm * unitDir;
float2 scaledDirection = pixelsPerCm * unitDirection;
float phi = 0; // Random rotation; unused for now
float2x2 rotationMatrix = float2x2(cos(phi), -sin(phi), sin(phi), cos(phi));
float2 rotatedDirection = mul(rotationMatrix, scaledDirection);

2
Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipeline.shader


half4 frag(v2f i) : SV_Target
{
half4 diffuseAlpha = tex2D(_MainTex, i.uv01.xy);
half4 diffuseAlpha = Tex2DLinearRGBA(_MainTex, i.uv01.xy);
half3 diffuse = diffuseAlpha.rgb * _Color.rgb;
half alpha = diffuseAlpha.a * _Color.a;

33
Assets/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineCore.cginc


#define _SHADOW_CASCADES
#endif
#if (defined(UNITY_COLORSPACE_GAMMA) || SHADER_TARGET < 30) && defined(LIGHTWEIGHT_FORCE_LINEAR)
// Ideally we want an approximation of gamma curve 2.0 to save ALU on GPU but as off now it won't match the GammaToLinear conversion of props in engine
//#define LIGHTWEIGHT_GAMMA_TO_LINEAR(gammaColor) gammaColor * gammaColor
//#define LIGHTWEIGHT_LINEAR_TO_GAMMA(linColor) sqrt(color)
#define LIGHTWEIGHT_GAMMA_TO_LINEAR(sRGB) sRGB * (sRGB * (sRGB * 0.305306011h + 0.682171111h) + 0.012522878h)
#define LIGHTWEIGHT_LINEAR_TO_GAMMA(linRGB) max(1.055h * pow(max(linRGB, 0.h), 0.416666667h) - 0.055h, 0.h)
#else
#define LIGHTWEIGHT_GAMMA_TO_LINEAR(color) color
#define LIGHTWEIGHT_LINEAR_TO_GAMMA(color) color
#endif
struct LightInput
{
half4 pos;

#include "LightweightPipelineShadows.cginc"
#endif
inline half3 Tex2DLinearRGB(sampler2D s, half2 uv)
{
return LIGHTWEIGHT_GAMMA_TO_LINEAR(tex2D(s, uv).rgb);
}
inline half4 Tex2DLinearRGBA(sampler2D s, half2 uv)
{
half4 color = tex2D(s, uv);
return half4(LIGHTWEIGHT_GAMMA_TO_LINEAR(color.rgb), color.a);
}
inline void NormalMap(v2f i, out half3 normal)
{
#if _NORMALMAP

inline void SpecularGloss(half2 uv, half alpha, out half4 specularGloss)
{
#ifdef _SPECGLOSSMAP
specularGloss = tex2D(_SpecGlossMap, uv) * _SpecColor;
specularGloss = Tex2DLinearRGBA(_SpecGlossMap, uv) * _SpecColor;
specularGloss = tex2D(_SpecGlossMap, uv) * _SpecColor;
specularGloss = Tex2DLinearRGBA(_SpecGlossMap, uv) * _SpecColor;
specularGloss.a = alpha;
#else
specularGloss = _SpecColor;

inline void Emission(half2 uv, inout half3 color)
{
#ifdef _EMISSION
color += tex2D(_EmissionMap, uv) * _EmissionColor;
color += Tex2DLinearRGB(_EmissionMap, uv) * _EmissionColor;
#else
color += _EmissionColor;
#endif

{
#ifdef _ALPHABLEND_ON
return half4(color, alpha);
return LIGHTWEIGHT_LINEAR_TO_GAMMA(half4(color, alpha));
return half4(color, 1);
return half4(LIGHTWEIGHT_LINEAR_TO_GAMMA(color), 1);
#endif
}

2
Assets/ScriptableRenderPipeline/ShaderLibrary/Common.hlsl


#define FLT_MIN 1.175494351e-38 // Minimum representable positive floating-point number
#define FLT_MAX 3.402823466e+38 // Maximum representable floating-point number
#define HFLT_MIN 0.00006103515625 // 2^14 it is the same for 10, 11 and 16bit float. ref: https://www.khronos.org/opengl/wiki/Small_Float_Formats
float DegToRad(float deg)
{
return deg * PI / 180.0;

4
Assets/ScriptableRenderPipeline/ShaderLibrary/Shadow/ShadowSampling.hlsl


float depthBias = params.z;
float bpp16 = params.w;
#if UNITY_REVERSED_Z
float depth = (1.0 - tcs.z) + depthBias;
float depth = (1.0 - tcs.z) - depthBias;
#else
float depth = tcs.z + depthBias;
#endif

float depthBias = params.z;
float bpp16 = params.w;
#if UNITY_REVERSED_Z
float depth = (1.0 - tcs.z) + depthBias;
float depth = (1.0 - tcs.z) - depthBias;
#else
float depth = tcs.z + depthBias;
#endif

正在加载...
取消
保存