Sebastien Lagarde
7 年前
当前提交
128f5158
共有 30 个文件被更改,包括 393 次插入 和 105 次删除
-
99SampleScenes/HDTest/ShadowsTest.unity
-
4ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Random.hlsl
-
14ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Shadow/Shadow.hlsl
-
44ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Shadow/ShadowAlgorithms.hlsl
-
12ScriptableRenderPipeline/Core/CoreRP/Shadow/AdditionalShadowData.cs
-
2ScriptableRenderPipeline/Core/package.json
-
16ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugColorPicker.shader
-
8ScriptableRenderPipeline/HDRenderPipeline/HDRP/Debug/DebugDisplay.hlsl
-
7ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/HDLightEditor.Styles.cs
-
33ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/HDLightEditor.cs
-
1ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/RenderLoopSettings/FrameSettingsUI.cs
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/RenderLoopSettings/SerializedFrameSettings.cs
-
4ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
-
8ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipelineAsset.asset
-
3ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs
-
122ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/DeferredDirectionalShadow.compute
-
3ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightEvaluation.hlsl
-
30ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs
-
12ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/Shadow.hlsl
-
7ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipeline/FrameSettings.cs
-
23ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderVariablesFunctions.hlsl
-
4ScriptableRenderPipeline/HDRenderPipeline/package.json
-
2ScriptableRenderPipeline/LightweightPipeline/LWRP/Editor/LightweightShaderIncludePaths.cs
-
8ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Input.hlsl
-
13ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/InputBuiltin.hlsl
-
2ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/InputSurface.hlsl
-
6ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Lighting.hlsl
-
3ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassMeta.hlsl
-
4ScriptableRenderPipeline/LightweightPipeline/package.json
-
2ScriptableRenderPipeline/master-package.json
|
|||
{ |
|||
"name": "com.unity.render-pipelines.core", |
|||
"description": "Core library for Unity render pipelines.", |
|||
"version": "0.1.23", |
|||
"version": "0.1.24", |
|||
"unity": "2018.1", |
|||
"dependencies": { |
|||
"com.unity.postprocessing": "0.1.7" |
|
|||
// Each #kernel tells which function to compile; you can have many kernels |
|||
#pragma kernel DeferredDirectionalShadow |
|||
#pragma kernel DeferredDirectionalShadow DEFERRED_DIRECTIONAL=DeferredDirectionalShadow |
|||
#pragma kernel DeferredDirectionalShadow_Contact DEFERRED_DIRECTIONAL=DeferredDirectionalShadow_Contact ENABLE_CONTACT_SHADOWS |
|||
//#pragma enable_d3d11_debug_symbols |
|||
|
|||
float _DirectionalShadowIndex; |
|||
|
|||
CBUFFER_START(DeferredShadowParameters) |
|||
float _DirectionalShadowIndex; |
|||
float3 _LightDirection; |
|||
float4 _ScreenSpaceShadowsParameters; |
|||
uint _SampleCount; |
|||
CBUFFER_END |
|||
|
|||
#define _ContactShadowLength _ScreenSpaceShadowsParameters.x |
|||
#define _ContactShadowDistanceScaleFactor _ScreenSpaceShadowsParameters.y |
|||
#define _ContactShadowFadeEnd _ScreenSpaceShadowsParameters.z |
|||
#define _ContactShadowFadeOneOverRange _ScreenSpaceShadowsParameters.w |
|||
// Return 1.0 if occluded 0.0 if not |
|||
float4 ScreenSpaceShadowRayCast(float3 positionWS, float3 rayDirection, float rayLength) |
|||
{ |
|||
uint3 hashInput = uint3(abs(GetAbsolutePositionWS(positionWS)) * 1000); |
|||
// Dither pattern is shifted by 0.5 because we want to jitter the ray starting position backward and forward (so we need values between -0.5 and 0.5) |
|||
float ditherBias = 0.5; |
|||
float dither = GenerateHashedRandomFloat(hashInput) - ditherBias; |
|||
|
|||
float3 rayStartWS = positionWS; |
|||
float3 rayEndWS = rayStartWS + rayDirection * rayLength; |
|||
|
|||
float4 rayStartCS = TransformWorldToHClip(rayStartWS); |
|||
float4 rayEndCS = TransformWorldToHClip(rayEndWS); |
|||
|
|||
// Here we compute a ray perpendicular to view space. This is the ray we use to compute the threshold for rejecting samples. |
|||
// This is done this way so that the threshold is less dependent of ray slope. |
|||
float4 rayOrthoViewSpace = rayStartCS + mul(GetViewToHClipMatrix(), float4(0, 0, rayLength, 0)); |
|||
rayOrthoViewSpace = rayOrthoViewSpace / rayOrthoViewSpace.w; |
|||
|
|||
rayStartCS.xyz = rayStartCS.xyz / rayStartCS.w; |
|||
rayEndCS.xyz = rayEndCS.xyz / rayEndCS.w; |
|||
|
|||
// Pixel to light ray in clip space. |
|||
float3 rayCS = rayEndCS.xyz - rayStartCS.xyz; |
|||
|
|||
// Depth at the start of the ray |
|||
float startDepth = rayStartCS.z; |
|||
// Depth range of the ray |
|||
float rayDepth = rayCS.z; |
|||
|
|||
// Starting UV of the sampling loop |
|||
float2 startUV = rayStartCS.xy * 0.5f + 0.5f; |
|||
startUV.y = 1.0 - startUV.y; |
|||
|
|||
// Pixel to light ray in |
|||
float2 rayUV = rayCS.xy * 0.5f; |
|||
rayUV.y = -rayUV.y; |
|||
|
|||
float step = 1.0 / _SampleCount; |
|||
float compareThreshold = abs(rayOrthoViewSpace.z - rayStartCS.z) * step; |
|||
|
|||
float occluded = 0.0f; |
|||
|
|||
for (int i = 0; i < _SampleCount; i++) |
|||
{ |
|||
// Step for this sample |
|||
float sampleStep = ((i + 1) * step + step * dither); |
|||
|
|||
// UVs for the current sample |
|||
float2 sampleUV = startUV + rayUV * sampleStep; |
|||
// Ray depth for this sample |
|||
float raySampleDepth = startDepth + rayDepth * sampleStep; |
|||
|
|||
// Depth buffer depth for this sample |
|||
float sampleDepth = SAMPLE_TEXTURE2D_LOD(_MainDepthTexture, sampler_MainDepthTexture, sampleUV, 0.0).x; |
|||
|
|||
bool Hit = false; |
|||
float depthDiff = sampleDepth - raySampleDepth; |
|||
Hit = depthDiff < compareThreshold && depthDiff > 0.0;// 1e-4; |
|||
|
|||
if (Hit) |
|||
occluded = 1.0f; |
|||
} |
|||
|
|||
// Off screen masking |
|||
// We remove the occlusion if the ray is occluded and only if direction steps out of the screen |
|||
float2 vignette = max(6.0 * abs(rayStartCS.xy + rayCS.xy * occluded * 0.5) - 5.0, 0.0); |
|||
occluded *= saturate( 1.0 - dot(vignette, vignette) ); |
|||
|
|||
return occluded; |
|||
} |
|||
|
|||
void DeferredDirectionalShadow(uint2 groupThreadId : SV_GroupThreadID, uint2 groupId : SV_GroupID) |
|||
void DEFERRED_DIRECTIONAL(uint2 groupThreadId : SV_GroupThreadID, uint2 groupId : SV_GroupID) |
|||
uint2 pixelCoord = groupId * DEFERRED_SHADOW_TILE_SIZE + groupThreadId; |
|||
uint2 tileCoord = groupId; |
|||
uint2 pixelCoord = groupId * DEFERRED_SHADOW_TILE_SIZE + groupThreadId; |
|||
uint2 tileCoord = groupId; |
|||
PositionInputs posInput = GetPositionInput(pixelCoord.xy, _ScreenSize.zw, tileCoord); |
|||
PositionInputs posInput = GetPositionInput(pixelCoord.xy, _ScreenSize.zw, tileCoord); |
|||
float depth = LOAD_TEXTURE2D(_MainDepthTexture, posInput.positionSS).x; |
|||
UpdatePositionInput(depth, UNITY_MATRIX_I_VP, UNITY_MATRIX_VP, posInput); |
|||
float depth = LOAD_TEXTURE2D(_MainDepthTexture, posInput.positionSS).x; |
|||
ShadowContext shadowContext = InitShadowContext(); |
|||
float shadow = GetDirectionalShadowAttenuation(shadowContext, posInput.positionWS, float3(0.0, 0.0, 0.0), (uint)_DirectionalShadowIndex, float3(0.0, 0.0, 0.0)); |
|||
if (depth == UNITY_RAW_FAR_CLIP_VALUE) |
|||
return; |
|||
_DeferredShadowTextureUAV[pixelCoord] = float4(shadow.xxx, 0.0); |
|||
UpdatePositionInput(depth, UNITY_MATRIX_I_VP, UNITY_MATRIX_VP, posInput); |
|||
|
|||
ShadowContext shadowContext = InitShadowContext(); |
|||
float shadow = GetDirectionalShadowAttenuation(shadowContext, posInput.positionWS, float3(0.0, 0.0, 0.0), (uint)_DirectionalShadowIndex, float3(0.0, 0.0, 0.0)); |
|||
|
|||
#ifdef ENABLE_CONTACT_SHADOWS |
|||
float contactShadow = 1.0f; |
|||
if (_ContactShadowLength > 0.0f) |
|||
{ |
|||
float4 result = ScreenSpaceShadowRayCast(posInput.positionWS, normalize(_LightDirection), _ContactShadowLength * max(0.5, posInput.linearDepth * _ContactShadowDistanceScaleFactor)); |
|||
contactShadow = 1.0 - result.x * saturate((_ContactShadowFadeEnd - posInput.linearDepth) * _ContactShadowFadeOneOverRange); |
|||
shadow *= contactShadow; |
|||
} |
|||
#endif |
|||
|
|||
_DeferredShadowTextureUAV[pixelCoord] = float4(shadow, 0.0, 0.0, 0.0); |
|||
} |
|
|||
{ |
|||
"name": "com.unity.render-pipelines.high-definition", |
|||
"description": "HD Render Pipeline for Unity.", |
|||
"version": "0.1.23", |
|||
"version": "0.1.24", |
|||
"com.unity.render-pipelines.core": "0.1.23" |
|||
"com.unity.render-pipelines.core": "0.1.24" |
|||
} |
|||
} |
|
|||
{ |
|||
"name": "com.unity.render-pipelines.lightweight", |
|||
"description": "Lightweight Render Pipeline for Unity.", |
|||
"version": "0.1.23", |
|||
"version": "0.1.24", |
|||
"com.unity.render-pipelines.core": "0.1.23" |
|||
"com.unity.render-pipelines.core": "0.1.24" |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue