Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
163cf75
Added shader quality setting to URP
Nzollner Mar 4, 2020
3a1f2a6
Updated changelog
Nzollner Mar 4, 2020
c25a9fb
Fixed Shader Quality settings
Nzollner Mar 4, 2020
fd6f87a
Added fading shadows to the shader quality
Nzollner Mar 16, 2020
443592b
Using cascades to calculate shadow fading
Nzollner Mar 18, 2020
b1e21e5
Refactored computations for shadow fading.
Nzollner Mar 23, 2020
54a1a6d
Shadow fading is now linked to the shader quality
Nzollner Mar 30, 2020
e98d545
Updated changelog
Nzollner Mar 30, 2020
af46ace
fixed testing to work with shadow fading
Nzollner Apr 6, 2020
911dcea
Update universalrp-asset.md
Nzollner Apr 8, 2020
ac83d52
Added stripping and made changes from PR comments
Nzollner Apr 15, 2020
97ee5ac
Changed api for shadow functions to match with previous api
Nzollner Apr 20, 2020
20be624
Removed debug line
Nzollner Apr 20, 2020
c7459e2
Added all shaders to use Shader qualities and added Shader Qualities …
Nzollner May 4, 2020
240b172
reverted TestProjects/* back before changes
Nzollner May 6, 2020
ddf9dda
updated shadow distance for test
Nzollner May 6, 2020
cd4f62e
updated referance image for test 35 because of previous texture displ…
Nzollner May 6, 2020
08d35e2
Added Test Scene
Nzollner May 11, 2020
98206c2
Added test to build steps
Nzollner May 11, 2020
c0fd4b5
Shrinked the shadow distance radius when rendering shadow cascades to…
Nzollner May 25, 2020
b01ddbd
added user pref. file to git ignore for the test folder, and removed …
Nzollner May 25, 2020
8aa226a
Added define flag for calculating positionWS when shadow fade is applied
Nzollner May 25, 2020
74be03c
DOC-1947 Edited the Shader Quality descriptions.
oleks-k May 25, 2020
8c9b64b
Updated tests to work with new shadow fading
Nzollner May 27, 2020
301b9a0
Added descriptions of ShaderQuality variables
Nzollner May 27, 2020
a316100
Merge branch 'universal/shader-quality' of https://github.com/Unity-T…
Nzollner May 27, 2020
fd200ad
Merged
Nzollner May 27, 2020
2b44056
Fixed code comments.
Nzollner Jun 3, 2020
4b9202e
Merged
Nzollner Jun 3, 2020
849287f
Updated test image to match new test case number
Nzollner Jun 3, 2020
8a3836a
Merged
Nzollner Jun 8, 2020
86cb9ea
Fixed minor errors
Nzollner Jun 8, 2020
adac653
merged
Nzollner Jun 17, 2020
35037b2
Merge branch 'master' of https://github.com/Unity-Technologies/Graphi…
Nzollner Jun 29, 2020
6630794
Made changes after a meeting with Nicolaj (request from Felipe).
oleks-k Jun 29, 2020
28e99df
Edited text and added shadow fade pictures
Nzollner Jun 30, 2020
95baf90
Updated Changelog
Nzollner Jul 3, 2020
e04e450
Removed the images until I edit them.
oleks-k Jul 6, 2020
c24e278
Merged
Nzollner Jul 13, 2020
1cc506f
merged
Nzollner Jul 20, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 23 additions & 27 deletions com.unity.render-pipelines.universal/Editor/ShaderPreprocessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ bool StripUnusedPass(ShaderFeatures features, ShaderSnippetData snippetData)

bool StripUnusedFeatures(ShaderFeatures features, Shader shader, ShaderCompilerData compilerData)
{
if (!CoreUtils.HasFlag(features, ShaderFeatures.ShaderQualityLow) &&
compilerData.shaderKeywordSet.IsEnabled(m_ShaderQualityLow))
return true;

if (!CoreUtils.HasFlag(features, ShaderFeatures.ShaderQualityMedium) &&
compilerData.shaderKeywordSet.IsEnabled(m_ShaderQualityMedium))
return true;

if (!CoreUtils.HasFlag(features, ShaderFeatures.ShaderQualityHigh) &&
compilerData.shaderKeywordSet.IsEnabled(m_ShaderQualityHigh))
return true;

// strip main light shadows and cascade variants
if (!CoreUtils.HasFlag(features, ShaderFeatures.MainLightShadows))
{
Expand All @@ -92,47 +104,31 @@ bool StripUnusedFeatures(ShaderFeatures features, Shader shader, ShaderCompilerD
bool isAdditionalLightPerPixel = compilerData.shaderKeywordSet.IsEnabled(m_AdditionalLightsPixel);
bool isAdditionalLightShadow = compilerData.shaderKeywordSet.IsEnabled(m_AdditionalLightShadows);

bool isShaderQualityLow = compilerData.shaderKeywordSet.IsEnabled(m_ShaderQualityLow);
bool isShaderQualityMedium = compilerData.shaderKeywordSet.IsEnabled(m_ShaderQualityMedium);
bool isShaderQualityHigh = compilerData.shaderKeywordSet.IsEnabled(m_ShaderQualityHigh);

// Additional light are shaded per-vertex. Strip additional lights per-pixel and shadow variants
if (CoreUtils.HasFlag(features, ShaderFeatures.VertexLighting) &&
(isAdditionalLightPerPixel || isAdditionalLightShadow))
if ((isAdditionalLightPerPixel || isAdditionalLightShadow) &&
CoreUtils.HasFlag(features, ShaderFeatures.VertexLighting))
return true;

// No additional lights
if (!CoreUtils.HasFlag(features, ShaderFeatures.AdditionalLights) &&
(isAdditionalLightPerPixel || isAdditionalLightPerVertex || isAdditionalLightShadow))
if ((isAdditionalLightPerPixel || isAdditionalLightPerVertex || isAdditionalLightShadow)&&
!CoreUtils.HasFlag(features, ShaderFeatures.AdditionalLights))
return true;

// No additional light shadows
if (!CoreUtils.HasFlag(features, ShaderFeatures.AdditionalLightShadows) && isAdditionalLightShadow)
if (isAdditionalLightShadow && !CoreUtils.HasFlag(features, ShaderFeatures.AdditionalLightShadows))
return true;

if (!CoreUtils.HasFlag(features, ShaderFeatures.SoftShadows) &&
compilerData.shaderKeywordSet.IsEnabled(m_SoftShadows))
return true;

if (compilerData.shaderKeywordSet.IsEnabled(m_MixedLightingSubtractive) &&
!CoreUtils.HasFlag(features, ShaderFeatures.MixedLighting))
if (!CoreUtils.HasFlag(features, ShaderFeatures.MixedLighting) &&
compilerData.shaderKeywordSet.IsEnabled(m_MixedLightingSubtractive))
return true;

bool isBuiltInTerrainLit = shader.name.Contains("Universal Render Pipeline/Terrain/Lit");
if (isBuiltInTerrainLit && compilerData.shaderKeywordSet.IsEnabled(m_AlphaTestOn) &&
!CoreUtils.HasFlag(features, ShaderFeatures.TerrainHoles))
return true;

if (!CoreUtils.HasFlag(features, ShaderFeatures.ShaderQualityLow) &&
compilerData.shaderKeywordSet.IsEnabled(m_ShaderQualityLow))
return true;

if (!CoreUtils.HasFlag(features, ShaderFeatures.ShaderQualityMedium) &&
compilerData.shaderKeywordSet.IsEnabled(m_ShaderQualityMedium))
return true;

if (!CoreUtils.HasFlag(features, ShaderFeatures.ShaderQualityHigh) &&
compilerData.shaderKeywordSet.IsEnabled(m_ShaderQualityHigh))
if (!CoreUtils.HasFlag(features, ShaderFeatures.TerrainHoles) &&
shader.name.Contains("Universal Render Pipeline/Terrain/Lit") &&
compilerData.shaderKeywordSet.IsEnabled(m_AlphaTestOn))
return true;

return false;
Expand Down Expand Up @@ -237,7 +233,7 @@ public void OnProcessShader(Shader shader, ShaderSnippetData snippetData, IList<


int prevVariantCount = compilerDataList.Count;

Debug.Log(ShaderBuildPreprocessor.supportedFeatures);
for (int i = 0; i < compilerDataList.Count; ++i)
{
if (StripUnused(ShaderBuildPreprocessor.supportedFeatures, shader, snippetData, compilerDataList[i]))
Expand Down
14 changes: 7 additions & 7 deletions com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,10 @@ Light GetMainLight()
return light;
}

Light GetMainLight(float3 positionWS, float4 shadowCoord)
Light GetMainLight(float4 shadowCoord)
{
Light light = GetMainLight();
#ifdef FADE_SHADOWS
light.shadowAttenuation = MainLightRealtimeShadow(positionWS, shadowCoord);
#else
light.shadowAttenuation = MainLightRealtimeShadow(shadowCoord);
#endif
return light;
}

Expand Down Expand Up @@ -604,7 +600,8 @@ half4 UniversalFragmentPBR(InputData inputData, half3 albedo, half metallic, hal
BRDFData brdfData;
InitializeBRDFData(albedo, metallic, specular, smoothness, alpha, brdfData);

Light mainLight = GetMainLight(inputData.positionWS, inputData.shadowCoord);
Light mainLight = GetMainLight(inputData.shadowCoord);
mainLight.shadowAttenuation = ApplyShadowFade(mainLight.shadowAttenuation, inputData.positionWS);
MixRealtimeAndBakedGI(mainLight, inputData.normalWS, inputData.bakedGI, half4(0, 0, 0, 0));

half3 color = GlobalIllumination(brdfData, inputData.bakedGI, occlusion, inputData.normalWS, inputData.viewDirectionWS);
Expand All @@ -615,6 +612,7 @@ half4 UniversalFragmentPBR(InputData inputData, half3 albedo, half metallic, hal
for (uint lightIndex = 0u; lightIndex < pixelLightCount; ++lightIndex)
{
Light light = GetAdditionalLight(lightIndex, inputData.positionWS);
light.shadowAttenuation = ApplyShadowFade(light.shadowAttenuation, inputData.positionWS);
color += LightingPhysicallyBased(brdfData, light, inputData.normalWS, inputData.viewDirectionWS);
}
#endif
Expand All @@ -629,7 +627,8 @@ half4 UniversalFragmentPBR(InputData inputData, half3 albedo, half metallic, hal

half4 UniversalFragmentBlinnPhong(InputData inputData, half3 diffuse, half4 specularGloss, half smoothness, half3 emission, half alpha)
{
Light mainLight = GetMainLight(inputData.positionWS, inputData.shadowCoord);
Light mainLight = GetMainLight(inputData.shadowCoord);
mainLight.shadowAttenuation = ApplyShadowFade(mainLight.shadowAttenuation, inputData.positionWS);
MixRealtimeAndBakedGI(mainLight, inputData.normalWS, inputData.bakedGI, half4(0, 0, 0, 0));

half3 attenuatedLightColor = mainLight.color * (mainLight.distanceAttenuation * mainLight.shadowAttenuation);
Expand All @@ -641,6 +640,7 @@ half4 UniversalFragmentBlinnPhong(InputData inputData, half3 diffuse, half4 spec
for (uint lightIndex = 0u; lightIndex < pixelLightCount; ++lightIndex)
{
Light light = GetAdditionalLight(lightIndex, inputData.positionWS);
light.shadowAttenuation = ApplyShadowFade(light.shadowAttenuation, inputData.positionWS);
half3 attenuatedLightColor = light.color * (light.distanceAttenuation * light.shadowAttenuation);
diffuseColor += LightingLambert(attenuatedLightColor, light.direction, inputData.normalWS);
specularColor += LightingSpecular(attenuatedLightColor, light.direction, inputData.normalWS, inputData.viewDirectionWS, specularGloss, smoothness);
Expand Down
37 changes: 14 additions & 23 deletions com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,6 @@ float4 TransformWorldToShadowCoord(float3 positionWS)
return mul(_MainLightWorldToShadow[cascadeIndex], float4(positionWS, 1.0));
}

half ComputeShadowFade(float3 positionWS, float shadowStrength)
{
#if FADE_SHADOWS
float3 fragToCamVec = _WorldSpaceCameraPos - positionWS;
float distanceFragToCam2 = dot(fragToCamVec, fragToCamVec);
float shadowDist = _MainLightShadowParams.z;
return shadowStrength * (1 - saturate((distanceFragToCam2 - shadowDist * 0.8) / (shadowDist - shadowDist * 0.8)));
#else
return shadowStrength;
#endif
}

half MainLightRealtimeShadow(float4 shadowCoord)
{
#if !defined(MAIN_LIGHT_CALCULATE_SHADOWS)
Expand All @@ -237,16 +225,6 @@ half MainLightRealtimeShadow(float4 shadowCoord)
return SampleShadowmap(TEXTURE2D_ARGS(_MainLightShadowmapTexture, sampler_MainLightShadowmapTexture), shadowCoord, shadowSamplingData, shadowParams, false);
}

half MainLightRealtimeShadow(float3 positionWS, float4 shadowCoord)
{
half4 shadowParams = GetMainLightShadowParams();
shadowParams.x = ComputeShadowFade(positionWS, shadowParams.x);
#if !defined(MAIN_LIGHT_CALCULATE_SHADOWS)
return 1.0h;
#endif
ShadowSamplingData shadowSamplingData = GetMainLightShadowSamplingData();
return SampleShadowmap(TEXTURE2D_ARGS(_MainLightShadowmapTexture, sampler_MainLightShadowmapTexture), shadowCoord, shadowSamplingData, shadowParams, false);
}
half AdditionalLightRealtimeShadow(int lightIndex, float3 positionWS)
{
#if !defined(ADDITIONAL_LIGHT_CALCULATE_SHADOWS)
Expand All @@ -270,7 +248,6 @@ half AdditionalLightRealtimeShadow(int lightIndex, float3 positionWS)
#endif

half4 shadowParams = GetAdditionalLightShadowParams(lightIndex);
shadowParams.x = ComputeShadowFade(positionWS, shadowParams.x);
return SampleShadowmap(TEXTURE2D_ARGS(_AdditionalLightsShadowmapTexture, sampler_AdditionalLightsShadowmapTexture), shadowCoord, shadowSamplingData, shadowParams, true);
}

Expand All @@ -290,6 +267,20 @@ float3 ApplyShadowBias(float3 positionWS, float3 normalWS, float3 lightDirection
return positionWS;
}

float ApplyShadowFade(float shadowAttenuation, float3 positionWS)
{
#if FADE_SHADOWS
float3 fragToCamVec = _WorldSpaceCameraPos - positionWS;
float distanceFragToCam2 = dot(fragToCamVec, fragToCamVec);
float shadowDist = _MainLightShadowParams.z;
float fade = saturate((distanceFragToCam2 - shadowDist * 0.8) / (shadowDist - shadowDist * 0.8));
return shadowAttenuation + (1 - shadowAttenuation) * fade;
#else
return shadowAttenuation;
#endif
}


///////////////////////////////////////////////////////////////////////////////
// Deprecated /
///////////////////////////////////////////////////////////////////////////////
Expand Down