Skip to content

Commit 3458645

Browse files
authored
Merge pull request #381 from EvgeniiG/master
Add additional shader passes + clean-up
2 parents 3111b53 + eed0d4f commit 3458645

7 files changed

Lines changed: 23 additions & 13 deletions

File tree

Assets/ScriptableRenderPipeline/Core/ShaderLibrary/Common.hlsl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -553,16 +553,21 @@ float3 ComputeViewSpacePosition(float2 positionSS, float depthRaw, float4x4 invP
553553
return positionVS.xyz / positionVS.w;
554554
}
555555

556+
float3 ComputeWorldSpacePosition(float2 positionSS, float depthRaw, float4x4 invViewProjMatrix)
557+
{
558+
float4 positionCS = ComputeClipSpacePosition(positionSS, depthRaw);
559+
float4 hpositionWS = mul(invViewProjMatrix, positionCS);
560+
return hpositionWS.xyz / hpositionWS.w;
561+
}
562+
556563
// From deferred or compute shader
557564
// depth must be the depth from the raw depth buffer. This allow to handle all kind of depth automatically with the inverse view projection matrix.
558565
// For information. In Unity Depth is always in range 0..1 (even on OpenGL) but can be reversed.
559566
void UpdatePositionInput(float depthRaw, float4x4 invViewProjMatrix, float4x4 viewProjMatrix, inout PositionInputs posInput)
560567
{
561568
posInput.depthRaw = depthRaw;
562569

563-
float4 positionCS = ComputeClipSpacePosition(posInput.positionSS, depthRaw);
564-
float4 hpositionWS = mul(invViewProjMatrix, positionCS);
565-
posInput.positionWS = hpositionWS.xyz / hpositionWS.w;
570+
posInput.positionWS = ComputeWorldSpacePosition(posInput.positionSS, depthRaw, invViewProjMatrix);
566571

567572
// The compiler should optimize this (less expensive than reconstruct depth VS from depth buffer)
568573
posInput.depthVS = mul(viewProjMatrix, float4(posInput.positionWS, 1.0)).w;

Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/Deferred.compute

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
// deferred material must replace the old one here. If in the future we want to support multiple layout (cause a lot of consistency problem),
8585
// the deferred shader will require to use multicompile.
8686
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl
87-
#include "../../ShaderConfig.cs.hlsl"
8887
#include "../../ShaderVariables.hlsl"
8988
#include "../../Lighting/Lighting.hlsl" // This include Material.hlsl
9089

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,20 +189,20 @@ void FillMaterialIdSSSData(float3 baseColor, int subsurfaceProfile, float subsur
189189

190190
bool performPostScatterTexturing = IsBitSet(_TexturingModeFlags, subsurfaceProfile);
191191

192-
bool enableSssAndTransmission = true;
193-
194192
#if defined(SHADERPASS) && (SHADERPASS == SHADERPASS_LIGHT_TRANSPORT) // In case of GI pass don't modify the diffuseColor
195-
enableSssAndTransmission = false;
196-
#elif (SSS_PASS == 0)
197-
enableSssAndTransmission = _EnableSSSAndTransmission != 0;
193+
bool enableSssAndTransmission = false;
194+
#elif defined(SHADERPASS) && (SHADERPASS == SHADERPASS_SUBSURFACE_SCATTERING)
195+
bool enableSssAndTransmission = true;
196+
#else
197+
bool enableSssAndTransmission = _EnableSSSAndTransmission != 0;
198198
#endif
199199

200200
if (enableSssAndTransmission) // If we globally disable SSS effect, don't modify diffuseColor
201201
{
202202
// We modify the albedo here as this code is used by all lighting (including light maps and GI).
203203
if (performPostScatterTexturing)
204204
{
205-
#ifndef SSS_PASS
205+
#if !defined(SHADERPASS) || (SHADERPASS != SHADERPASS_SUBSURFACE_SCATTERING)
206206
bsdfData.diffuseColor = float3(1.0, 1.0, 1.0);
207207
#endif
208208
}

Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/SubsurfaceScattering.compute

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
#define SSS_DEBUG_NORMAL_VS 0
1818

1919
// Do not modify these.
20-
#define SSS_PASS 1
20+
#include "../../../ShaderPass/ShaderPass.cs.hlsl"
21+
#define SHADERPASS SHADERPASS_SUBSURFACE_SCATTERING
2122
#define MILLIMETERS_PER_METER 1000
2223
#define CENTIMETERS_PER_METER 100
2324
#define GROUP_SIZE_1D 16

Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/SubsurfaceScattering.shader

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ Shader "Hidden/HDRenderPipeline/SubsurfaceScattering"
3232
#pragma multi_compile _ SSS_FILTER_HORIZONTAL_AND_COMBINE
3333

3434
// Do not modify these.
35-
#define SSS_PASS 1
35+
#include "../../../ShaderPass/ShaderPass.cs.hlsl"
36+
#define SHADERPASS SHADERPASS_SUBSURFACE_SCATTERING
3637
#define MILLIMETERS_PER_METER 1000
3738
#define CENTIMETERS_PER_METER 100
3839

Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPass.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public enum ShaderPass
1717
Velocity,
1818
Distortion,
1919
LightTransport,
20-
Shadows
20+
Shadows,
21+
SubsurfaceScattering,
22+
VolumetricLighting
2123
}
2224
}

Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/ShaderPass.cs.hlsl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#define SHADERPASS_DISTORTION (5)
1616
#define SHADERPASS_LIGHT_TRANSPORT (6)
1717
#define SHADERPASS_SHADOWS (7)
18+
#define SHADERPASS_SUBSURFACE_SCATTERING (8)
19+
#define SHADERPASS_VOLUMETRIC_LIGHTING (9)
1820

1921

2022
#endif

0 commit comments

Comments
 (0)