浏览代码

Added 4 tap shadowmap filtering.

/vr_sandbox
Felipe Lira 8 年前
当前提交
94d1068c
共有 16 个文件被更改,包括 4265 次插入20 次删除
  1. 1
      Assets/LowEndRenderLoop/LowEndPipeline.asset
  2. 53
      Assets/LowEndRenderLoop/LowEndRenderLoopShader.shader
  3. 39
      Assets/LowEndRenderLoop/LowEndRenderPipeline.cs
  4. 3
      Assets/ScriptableRenderLoop/RenderPasses/ShadowRenderPass.cs
  5. 9
      Assets/LowEndRenderLoop/LowEndRenderLoopVikingVillage.meta
  6. 1001
      Assets/LowEndRenderLoop/LowEndRenderLoopVikingVillage.unity
  7. 8
      Assets/LowEndRenderLoop/LowEndRenderLoopVikingVillage.unity.meta
  8. 11
      Assets/LowEndRenderLoop/SetResolutionScript.cs
  9. 12
      Assets/LowEndRenderLoop/SetResolutionScript.cs.meta
  10. 1001
      Assets/LowEndRenderLoop/LowEndRenderLoopVikingVillage/LightingData.asset
  11. 8
      Assets/LowEndRenderLoop/LowEndRenderLoopVikingVillage/LightingData.asset.meta
  12. 1001
      Assets/LowEndRenderLoop/LowEndRenderLoopVikingVillage/Lightmap-0_comp_light.exr
  13. 68
      Assets/LowEndRenderLoop/LowEndRenderLoopVikingVillage/Lightmap-0_comp_light.exr.meta
  14. 1001
      Assets/LowEndRenderLoop/LowEndRenderLoopVikingVillage/ReflectionProbe-0.exr
  15. 69
      Assets/LowEndRenderLoop/LowEndRenderLoopVikingVillage/ReflectionProbe-0.exr.meta

1
Assets/LowEndRenderLoop/LowEndPipeline.asset


m_SupportsVertexLight: 0
m_EnableLightmaps: 1
m_EnableAmbientProbe: 1
m_EnableShadowFiltering: 1
m_ShadowAtlasResolution: 2048

53
Assets/LowEndRenderLoop/LowEndRenderLoopShader.shader


#pragma shader_feature _NORMALMAP
#pragma multi_compile _ LIGHTMAP_ON
#pragma multi_compile _ SHADOWS_DEPTH
#pragma multi_compile _ SHADOWS_FILTERING
//#pragma enable_d3d11_debug_symbols
#pragma enable_d3d11_debug_symbols
#include "UnityCG.cginc"
#include "UnityStandardBRDF.cginc"

int4 globalLightCount; // x: pixelLightCount, y = totalLightCount (pixel + vert)
sampler2D g_tShadowBuffer;
float _PCFKernel[8];
half4 _PSSMDistances;
half4 _PSSMDistancesAndShadowResolution; // xyz: PSSM Distance for 4 cascades, w: 1 / shadowmap resolution. Used for filtering
struct LightInput
{

half4 spotDir;
};
inline int ComputeCascadeIndex(half eyeZ)
inline half ComputeCascadeIndex(half eyeZ)
half3 cascadeCompare = step(_PSSMDistances, half3(eyeZ, eyeZ, eyeZ));
half3 cascadeCompare = step(_PSSMDistancesAndShadowResolution.xyz, half3(eyeZ, eyeZ, eyeZ));
inline half ShadowAttenuation(half2 shadowCoord, half shadowCoordDepth)
{
half depth = tex2D(g_tShadowBuffer, shadowCoord).r;
#if defined(UNITY_REVERSED_Z)
return step(depth, shadowCoordDepth);
#else
return step(shadowCoordDepth, depth);
#endif
}
inline half ShadowFilteredAttenuation(half4 shadowCoord)
{
// GPU Gems 4x4 kernel with 4 taps.
half2 offset = (float)(frac(shadowCoord.xy * 0.5) > 0.25); // mod
offset.y += offset.x; // y ^= x in floating point
offset *= _PSSMDistancesAndShadowResolution.w;
half attenuation = ShadowAttenuation(shadowCoord.xy + half2(_PCFKernel[0], _PCFKernel[1]) + offset, shadowCoord.z) +
ShadowAttenuation(shadowCoord.xy + half2(_PCFKernel[2], _PCFKernel[3]) + offset, shadowCoord.z) +
ShadowAttenuation(shadowCoord.xy + half2(_PCFKernel[4], _PCFKernel[5]) + offset, shadowCoord.z) +
ShadowAttenuation(shadowCoord.xy + half2(_PCFKernel[6], _PCFKernel[7]) + offset, shadowCoord.z);
return attenuation * 0.25;
}
inline half3 EvaluateOneLight(LightInput lightInput, half3 diffuseColor, half3 specularColor, half3 normal, float3 posWorld, half3 viewDir)
{
float3 posToLight = lightInput.pos.xyz;

inline half3 EvaluateMainLight(LightInput lightInput, half3 diffuseColor, half3 specularColor, half3 normal, float4 posWorld, half3 viewDir)
{
int cascadeIndex = ComputeCascadeIndex(posWorld.w);
float3 shadowCoord = mul(_WorldToShadow[cascadeIndex], float4(posWorld.xyz, 1.0));
float4 shadowCoord = mul(_WorldToShadow[cascadeIndex], float4(posWorld.xyz, 1.0));
half shadowDepth = tex2D(g_tShadowBuffer, shadowCoord.xy).r;
half shadowAttenuation = 1.0;
#if defined(UNITY_REVERSED_Z)
shadowAttenuation = step(shadowDepth, shadowCoord.z);
#ifdef SHADOWS_FILTERING
half shadowAttenuation = ShadowFilteredAttenuation(shadowCoord);
shadowAttenuation = step(shadowCoord.z, shadowDepth);
half shadowAttenuation = ShadowAttenuation(shadowCoord.xy, shadowCoord.z);
#endif
#if DEBUG_CASCADES

half3 color = EvaluateOneLight(lightInput, diffuseColor, specularColor, normal, posWorld, viewDir);
#ifdef SHADOWS_DEPTH
#else
return color;
#endif
}
struct LowendVertexInput

39
Assets/LowEndRenderLoop/LowEndRenderPipeline.cs


float shadowFrustumDepth = shadowFar - shadowNear;
Vector3 shadowSplitRatio = m_ShadowSettings.directionalLightCascades;
ShadowSliceData[] shadowSlices = shadowOutput.shadowSlices;
if (shadowSlices == null)
return;
Mathf.Infinity);
ShadowSliceData[] shadowSlices = shadowOutput.shadowSlices;
if (shadowSlices == null)
return;
1.0f / shadowSlices[0].shadowResolution);
int shadowSliceCount = shadowSlices.Length;
const int maxShadowCascades = 4;

// TODO: shadow resolution per cascade in case cascades endup being supported.
float invShadowResolution = 1.0f / shadowSlices[0].shadowResolution;
float[] pcfKernel = {-1.5f * invShadowResolution, 0.5f * invShadowResolution,
0.5f * invShadowResolution, 0.5f * invShadowResolution,
-1.5f * invShadowResolution, -0.5f * invShadowResolution,
0.5f * invShadowResolution, -0.5f * invShadowResolution };
SetShadowKeywords(setupShadow);
setupShadow.SetGlobalVector("_PSSMDistances", PSSMDistances);
setupShadow.SetGlobalVector("_PSSMDistancesAndShadowResolution", PSSMDistances);
setupShadow.SetGlobalFloatArray("_PCFKernel", pcfKernel);
}
void SetShadowKeywords(CommandBuffer cmd)
{
if (QualitySettings.shadows == ShadowQuality.Disable)
cmd.DisableShaderKeyword("SHADOWS_DEPTH");
else
cmd.EnableShaderKeyword("SHADOWS_DEPTH");
if (m_Asset.EnableShadowFiltering)
cmd.EnableShaderKeyword("SHADOWS_FILTERING");
else
cmd.DisableShaderKeyword("SHADOWS_FILTERING");
}
#endregion
}

public bool m_SupportsVertexLight = true;
public bool m_EnableLightmaps = true;
public bool m_EnableAmbientProbe = true;
public bool m_EnableShadowFiltering = false;
public int m_ShadowAtlasResolution = 1024;
public bool SupportsVertexLight { get { return m_SupportsVertexLight;} private set { m_SupportsVertexLight = value; } }

public bool EnableAmbientProbe { get { return m_EnableAmbientProbe;} private set { m_EnableAmbientProbe = value; } }
public bool EnableAmbientProbe { get { return m_EnableAmbientProbe; } private set { m_EnableAmbientProbe = value; } }
public bool EnableShadowFiltering { get { return m_EnableShadowFiltering; } private set { m_EnableShadowFiltering = value; } }
public int ShadowAtlasResolution { get { return m_ShadowAtlasResolution; } private set { m_ShadowAtlasResolution = value; } }
#endregion

3
Assets/ScriptableRenderLoop/RenderPasses/ShadowRenderPass.cs


AdditionalLightData additionalLight = lights[i].light.GetComponent<AdditionalLightData>();
int shadowResolution;
if (additionalLight != null)
if (settings.shadowType != ShadowSettings.ShadowType.LIGHTSPACE)
shadowResolution = AdditionalLightData.GetShadowResolution(additionalLight);
else
shadowResolution = GetMaxTileResolutionInAtlas(settings.shadowAtlasWidth, settings.shadowAtlasHeight, settings.directionalLightCascadeCount);

9
Assets/LowEndRenderLoop/LowEndRenderLoopVikingVillage.meta


fileFormatVersion: 2
guid: f5d2527b6ab9ac44fae5ddb09815a06c
folderAsset: yes
timeCreated: 1485351913
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

1001
Assets/LowEndRenderLoop/LowEndRenderLoopVikingVillage.unity
文件差异内容过多而无法显示
查看文件

8
Assets/LowEndRenderLoop/LowEndRenderLoopVikingVillage.unity.meta


fileFormatVersion: 2
guid: 222d58b393f3d49449c563db79a5eda0
timeCreated: 1474278095
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

11
Assets/LowEndRenderLoop/SetResolutionScript.cs


using UnityEngine;
public class SetResolutionScript : MonoBehaviour
{
void Awake()
{
#if UNITY_ANDROID
Screen.SetResolution(1280, 720, true);
#endif
}
}

12
Assets/LowEndRenderLoop/SetResolutionScript.cs.meta


fileFormatVersion: 2
guid: e3642bf3eb34e934ba331a4d6ffc75ad
timeCreated: 1484915612
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

1001
Assets/LowEndRenderLoop/LowEndRenderLoopVikingVillage/LightingData.asset
文件差异内容过多而无法显示
查看文件

8
Assets/LowEndRenderLoop/LowEndRenderLoopVikingVillage/LightingData.asset.meta


fileFormatVersion: 2
guid: 8964f843d8f1330418cbd7ae5166468f
timeCreated: 1485353234
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

1001
Assets/LowEndRenderLoop/LowEndRenderLoopVikingVillage/Lightmap-0_comp_light.exr
文件差异内容过多而无法显示
查看文件

68
Assets/LowEndRenderLoop/LowEndRenderLoopVikingVillage/Lightmap-0_comp_light.exr.meta


fileFormatVersion: 2
guid: 14d1fbf0126a7714e902a309b22a8261
timeCreated: 1485353218
licenseType: Pro
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
filterMode: 1
aniso: 3
mipBias: 0
wrapMode: 1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaUsage: 0
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 6
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:

1001
Assets/LowEndRenderLoop/LowEndRenderLoopVikingVillage/ReflectionProbe-0.exr
文件差异内容过多而无法显示
查看文件

69
Assets/LowEndRenderLoop/LowEndRenderLoopVikingVillage/ReflectionProbe-0.exr.meta


fileFormatVersion: 2
guid: c951fbe54fa631144a45d6aea2bc237f
timeCreated: 1485353234
licenseType: Pro
TextureImporter:
fileIDToRecycleName:
8900000: generatedCubemap
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 1
seamlessCubemap: 1
textureFormat: 1
maxTextureSize: 2048
textureSettings:
filterMode: 2
aniso: 0
mipBias: 0
wrapMode: 1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 2
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
textureFormat: -1
textureCompression: 1
compressionQuality: 100
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存