Skip to content

Commit

Permalink
feat: skylighting (doodlum#312)
Browse files Browse the repository at this point in the history
* feat: semi-deferred rendering

* refactor: cleanup setting targets

* chore: ae hook

* feat: full albedo, improved snow shader support

* feat: deferred direct and ambient light

* feat: octahedron normal encoding

* fix: increased normal precision

* feat: normal mapping shadows

* feat: blur normal mapping shadows with groupshared

* feat: separated normal mapping shadows pass

* chore: optimised sampling and formats

* chore: further optimisation

* fix: depth distance

* fix: disabling CS ingame

* feat: use alpha channel of render targets

* fix: envmapping with deferred

* fix: output color

* feat: add initial VR support

* feat: moved screenspace shadows to deferred

* fix: fix VR hook for shadowmask (doodlum#229)

* chore: screenspace shadows performance tweaks

* feat: wip porting screen shadows to deferred

* feat: bend studios shadows

* feat: naive bilateral blur and optimisations

* Delete FilterCS2.hlsl

* fix: removed unused filtering

* fix: missing ae hook

* feat: fixed double sided mesh shading

* chore: more optimal wave size

* chore: halve kernel radius for performance

* chore: revise shadow settings

* chore: optimisations, cleanup and moved NMS out of Bindings

* chore: removed dirlight shadows from deferred

* fix: black horizon

* chore: cleanup cleaning up of bindings

* chore: optimised blur + fixes

* chore: optimise normal mapping shadows

* fix: black grass

* fix: tree lod normals

* fix: vegetation detection

* fix: ignore first-person

* chore: adjust default shadows settings

* fix: multi-layer parallax deferred

* feat: add ssgi and terrain occlusion (doodlum#255)

* build: fix compilation errors in terrainocclusion (doodlum#256)

* style: 🎨 apply clang-format changes

* fix: fix warning `Ternary error with non scalar` (doodlum#262)

* refactor: simplify VR code and structures (doodlum#261)

* revert: "fix: fix warning `Ternary error with non scalar`" (doodlum#265)

* fix: fix compilation errors

* refactor: use state version of render members

* fix: convert Albedo to Diffuse

* fix: fix compilation errors

* style: 🎨 apply clang-format changes

* feat: interior directional light

* fix: disable vertex fix on foliage

* fix: compiler warning with SSGI

* style: 🎨 apply clang-format changes

* feat: ported SSS to deferred

* style: 🎨 apply clang-format changes

* fix: consistent padding in shaders for older cards

* fix: foliage shadows

* style: 🎨 apply clang-format changes

* chore: update to latest CLIB-NG

* feat: variable rate shading (doodlum#270)

* feat: variable rate shading with nvapi extensions

* feat: FFR test

* feat: adaptive rate shading

* feat: motion VRS

* feat: finalising VRS

* style: 🎨 apply clang-format changes

* fix: VRS merge

* fix: fix vrs merge

* fix: foliage mask

* style: 🎨 apply clang-format changes

* fix: black tree LOD

* style: 🎨 apply clang-format changes

* fix: disable VRS on water

* fix: fix common VR includes

* refactor: Rename newly added hlsl without entry to hlsli

* fix: depth linearisation

* chore: soft shadow as per RDR2

* fix: remove cloud shadows macros from rungrass and distanttree

* fix: use GET_INSTANCE_MEMBER macro to get proper state runtime

* chore: rename to deferred, VRS in interiors only

* style: 🎨 apply clang-format changes

* fix: SSS blur direction

* chore: reduce VRS threshold

* chore: removed tree LOD lighting feature

* feat: port deferred DistantTree to VR

* feat: add deferred screen space shadows for VR

* fix: check for compute shader file existence (doodlum#280)

* fix: undo delete of ComputeShadingRate.hlsl

* fix: add back GetScreenDepth to RaymarchCS

* feat: grass lighting deferred support

* style: 🎨 apply clang-format changes

* feat: screenspace shadow VR support

* style: 🎨 apply clang-format changes

* fix: shader errors and warnings

* feat: effect shader deferred support

* style: 🎨 apply clang-format changes

* fix: effect shader compile issue

* feat: skylighting

* chore: blue noise attempt

* feat: spatiotemporal blue noise

* feat: cascades for skylighting

* chore: performance improvements

* feat: optimised PCF + cascade fix for skylighting

* fix: effect shader compile error

* feat: spatial filter for ssgi (doodlum#288)

* feat: bring back normal disocclusion

* feat: added spatial denoiser (blur)

* fix: correct frame accumulation

* feat: blur with geometry and normal weights

* feat: water VL and shadows

* fix: water vl raymarch (doodlum#290)

* feat: cloud shadow improvements

* feat: cascades for VL

* feat: physically based water scattering (doodlum#291)

* feat: physically based water scattering and opacity

* feat: clamping march distance

* chore: parameter tweaks

* chore: return to vanilla blending

* feat: add refraction to water vl

* chore: remove debug lines

* fix: refractionScreenPosition undefined (doodlum#292)

* fix: add ssgi dynamic resolution support (doodlum#293)

* feat: water shadows

* chore: experimental skylighting changes

* feat: occlusion map fixes

* chore: ssgi improvements (doodlum#295)

* fix: fix compilation error for upsample

* fix: fix VR terrain occlusion

* feat: enable TerrainOcclusion for VR

* fix: fix missing defines for cloudshadows

* fix: fix VR uv conversion in cloudshadows

* feat: enable utility shader in VR

* feat: add shadercache developer improvements (doodlum#302)

* feat: deferred dynamic cubemaps

* style: 🎨 apply clang-format changes

* refactor: use menu buffer viewer macros

* docs: add shader warnings to debug logs

* fix: fix VR ShadowData structures

* fix: fix utility ShadowMapProj for SHADOWMASKS

Fixes structure for RENDER_SHADOWMASKSPOT, RENDER_SHADOWMASKPB, and
RENDER_SHADOWMASKDPB.

* chore: swap between precipitation and skylighting rendering

* fix: occlusion when raining

* chore: cleanup unused code

* chore: optimised skylighting sampling

* chore: skylighting reflection improvements

* fix: rain particles

* chore: tweaked default shadow settings

* chore: disable water VL until it is fixed

* chore: improved grass shading

* chore: skylighting AE addresses

* chore: added missing ae addresses

* chore: occlusion toggle

* style: 🎨 apply clang-format changes

* chore: shadow and SSGI fixes

* style: 🎨 apply clang-format changes

* chore: adjusted grass sss texture

* fix: VR skylighting changes

* style: 🎨 apply clang-format changes

* chore: corrected regressions to deferredcomposite

* chore: non-deferred decals testing code

* chore: disabled bUse64bitsHDRRenderTargets automatically

* chore: skylighting shader fixes

* style: 🎨 apply clang-format changes

* chore: cleaned up lighting.hlsl

* fix: deferred sky with cloud shadows

* style: 🎨 apply clang-format changes

* chore: cleanup redundant cloud shadows code

* fix: black grass

* feat: parallax shadow mask and optimisations

* style: 🎨 apply clang-format changes

* feat: fix for objects glowing in shadow

* chore: optimisations

* style: 🎨 apply clang-format changes

* refactor: removed UtilityShaderFlags from State

* feat: skylighting for trees

* style: 🎨 apply clang-format changes

---------

Co-authored-by: Alan Tse <alandtse@gmail.com>
Co-authored-by: Alan Tse <alandtse@users.noreply.github.com>
Co-authored-by: C. S <76898260+Pentalimbed@users.noreply.github.com>
Co-authored-by: doodlum <doodlum@users.noreply.github.com>
Co-authored-by: Pentalimbed <pentalimbed@gmail.com>
Co-authored-by: FlayaN <hannes.feldt@gmail.com>
  • Loading branch information
7 people authored May 28, 2024
1 parent 5459d74 commit d6ae3bf
Show file tree
Hide file tree
Showing 46 changed files with 2,827 additions and 674 deletions.
8 changes: 2 additions & 6 deletions features/Cloud Shadows/Shaders/CloudShadows/output.cs.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,9 @@ float3 getCloudShadowMult(float3 rel_pos, float3 eye_to_sun)
[numthreads(32, 32, 1)] void main(uint2 dtid
: SV_DispatchThreadID) {
float2 uv = (dtid + .5) * RcpBufferDim;
#ifdef VR
const uint eyeIndex = uv > .5;
#else
const uint eyeIndex = 0;
#endif
uint eyeIndex = GetEyeIndexFromTexCoord(uv);

float3 ndc = float3(ConvertToStereoUV(uv, eyeIndex), 1);
float3 ndc = float3(ConvertFromStereoUV(uv, eyeIndex), 1);
ndc = ndc * 2 - 1;
ndc.y = -ndc.y;
ndc.z = TexDepth[dtid];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,26 @@ float3 GetDynamicCubemap(float2 uv, float3 N, float3 VN, float3 V, float roughne

float level = roughness * 9.0;

float3 specularIrradiance = specularTexture.SampleLevel(SampColorSampler, R, level).xyz;
specularIrradiance = sRGB2Lin(specularIrradiance);
diffuseColor = sRGB2Lin(diffuseColor);

float2 specularBRDF = EnvBRDFApprox(roughness, NoV);

// Horizon specular occlusion
// https://marmosetco.tumblr.com/post/81245981087
float horizon = min(1.0 + dot(R, VN), 1.0);
specularIrradiance *= horizon * horizon;
horizon *= horizon * horizon;

// Roughness dependent fresnel
// https://www.jcgt.org/published/0008/01/03/paper.pdf
float3 Fr = max(1.0.xxx - roughness.xxx, F0) - F0;
float3 S = Fr * pow(1.0 - NoV, 5.0);

# if defined(DEFERRED)
return horizon * ((F0 + S) * specularBRDF.x + specularBRDF.y);
# else
float3 specularIrradiance = specularTexture.SampleLevel(SampColorSampler, R, level).xyz;
specularIrradiance = sRGB2Lin(specularIrradiance);

return specularIrradiance * ((F0 + S) * specularBRDF.x + specularBRDF.y);
# endif
}

float3 GetDynamicCubemapFresnel(float2 uv, float3 N, float3 VN, float3 V, float roughness, float level, float3 diffuseColor, float distance)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
TextureCube<float4> EnvCaptureTexture : register(t0);
#if defined(REFLECTIONS)
TextureCube<float4> ReflectionsTexture : register(t1);
#else
TextureCube<float4> DefaultCubemap : register(t1);
#endif
TextureCube<float4> DefaultCubemap : register(t2);

RWTexture2DArray<float4> EnvInferredTexture : register(u0);

SamplerState LinearSampler : register(s0);
Expand Down Expand Up @@ -102,7 +100,7 @@ float3 Lin2sRGB(float3 color)
#if defined(REFLECTIONS)
color.rgb = lerp(color.rgb, sRGB2Lin(ReflectionsTexture.SampleLevel(LinearSampler, uv, 0)), saturate(mipLevel * (1.0 / 10.0)));
#else
color.rgb = lerp(color.rgb, color.rgb * sRGB2Lin(DefaultCubemap.SampleLevel(LinearSampler, uv, 0).x) * 10.0, saturate(mipLevel * (1.0 / 10.0)));
color.rgb = lerp(color.rgb, color.rgb * sRGB2Lin(DefaultCubemap.SampleLevel(LinearSampler, uv, 0).x), saturate(mipLevel * (1.0 / 10.0)));
#endif

color.rgb = Lin2sRGB(color.rgb);
Expand Down
15 changes: 8 additions & 7 deletions features/Grass Lighting/Shaders/RunGrass.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
if (!frontFace)
normal = -normal;

normal = normalize(lerp(normal, normalize(input.SphereNormal.xyz), input.SphereNormal.w));
normal = normalize(lerp(normal, normalize(input.SphereNormal.xyz), sqrt(input.SphereNormal.w)));

if (complex) {
float3 normalColor = TransformNormal(specColor.xyz);
Expand All @@ -367,12 +367,12 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace

float dirLightAngle = dot(normal, DirLightDirection.xyz);

float3 albedo = max(0, baseColor.xyz * input.VertexColor.xyz);

// Generated texture to simulate light transport.
// Numerous attempts were made to use a more interesting algorithm however they were mostly fruitless.
float3 subsurfaceColor = baseColor.xyz * sqrt(input.SphereNormal.w);
float3 subsurfaceColor = pow(lerp(RGBToLuminance(albedo.xyz), albedo.xyz, 2.0), 1.5) * input.SphereNormal.w;

// Applies lighting from the opposite direction. Does not account for normals perpendicular to the light source.
lightsDiffuseColor += subsurfaceColor * dirLightColor * saturate(-dirLightAngle) * SubsurfaceScatteringAmount;
float3 sss = dirLightColor * sqrt(-dirLightAngle * 0.5 + 0.5);

if (complex)
lightsSpecularColor += GetLightSpecularInput(DirLightDirection, viewDirection, normal, dirLightColor, Glossiness);
Expand Down Expand Up @@ -417,7 +417,8 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace

float3 lightDiffuseColor = lightColor * saturate(lightAngle.xxx);

lightDiffuseColor += subsurfaceColor * lightColor * saturate(-lightAngle) * SubsurfaceScatteringAmount;
sss += lightColor * sqrt(-lightAngle * 0.5 + 0.5);

lightsDiffuseColor += lightDiffuseColor * intensityMultiplier;

if (complex)
Expand All @@ -429,8 +430,8 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace

diffuseColor += lightsDiffuseColor;

float3 albedo = max(0, baseColor.xyz * input.VertexColor.xyz);
diffuseColor *= albedo;
diffuseColor += max(0, sss * subsurfaceColor * SubsurfaceScatteringAmount);

specularColor += lightsSpecularColor;
specularColor *= specColor.w * SpecularStrength;
Expand Down
94 changes: 94 additions & 0 deletions features/Screen Space GI/Shaders/ScreenSpaceGI/blur.cs.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// FAST DENOISING WITH SELF-STABILIZING RECURRENT BLURS
// https://developer.download.nvidia.com/video/gputechconf/gtc/2020/presentations/s22699-fast-denoising-with-self-stabilizing-recurrent-blurs.pdf

#include "../Common/FastMath.hlsli"
#include "../Common/GBuffer.hlsli"
#include "../Common/VR.hlsli"
#include "common.hlsli"

Texture2D<lpfloat4> srcGI : register(t0); // maybe half-res
Texture2D<unorm float> srcAccumFrames : register(t1); // maybe half-res
Texture2D<half> srcDepth : register(t2);
Texture2D<half4> srcNormal : register(t3);

RWTexture2D<lpfloat4> outGI : register(u0);
RWTexture2D<unorm float> outAccumFrames : register(u1);

// samples = 8, min distance = 0.5, average samples on radius = 2
static const float3 g_Poisson8[8] = {
float3(-0.4706069, -0.4427112, +0.6461146),
float3(-0.9057375, +0.3003471, +0.9542373),
float3(-0.3487388, +0.4037880, +0.5335386),
float3(+0.1023042, +0.6439373, +0.6520134),
float3(+0.5699277, +0.3513750, +0.6695386),
float3(+0.2939128, -0.1131226, +0.3149309),
float3(+0.7836658, -0.4208784, +0.8895339),
float3(+0.1564120, -0.8198990, +0.8346850)
};

float HistoryRadiusScaling(float accumFrames)
{
return lerp(1, 0.5, accumFrames / MaxAccumFrames);
};

[numthreads(8, 8, 1)] void main(const uint2 dtid
: SV_DispatchThreadID) {
const float srcScale = SrcFrameDim * RcpTexDim;
const float outScale = OutFrameDim * RcpTexDim;

float radius = BlurRadius;
#ifdef TEMPORAL_DENOISER
float accumFrames = srcAccumFrames[dtid];
radius *= HistoryRadiusScaling(accumFrames * 255);
radius = max(radius, 2);
#endif
const uint numSamples = 8;

const float2 uv = (dtid + .5) * RcpOutFrameDim;
uint eyeIndex = GET_EYE_IDX(uv);
const float2 screenPos = ConvertToStereoUV(uv, eyeIndex);

float depth = READ_DEPTH(srcDepth, dtid);
float3 pos = ScreenToViewPosition(screenPos, depth, eyeIndex);
float3 normal = DecodeNormal(FULLRES_LOAD(srcNormal, dtid, uv, samplerLinearClamp).xy);

lpfloat4 sum = srcGI[dtid];
#ifdef TEMPORAL_DENOISER
lpfloat4 fsum = accumFrames;
#endif
float4 wsum = 1;
for (uint i = 0; i < numSamples; i++) {
float w = g_Poisson8[i].z;

float2 pxOffset = radius * g_Poisson8[i].xy;
float2 pxSample = dtid + .5 + pxOffset;
float2 uvSample = pxSample * RcpOutFrameDim;
float2 screenPosSample = ConvertToStereoUV(uvSample, eyeIndex);

if (any(screenPosSample < 0) || any(screenPosSample > 1))
continue;

float depthSample = srcDepth.SampleLevel(samplerLinearClamp, uvSample * srcScale, 0);
float3 posSample = ScreenToViewPosition(screenPosSample, depthSample, eyeIndex);

float3 normalSample = DecodeNormal(srcNormal.SampleLevel(samplerLinearClamp, uvSample * srcScale, 0).xy);

// geometry weight
w *= saturate(1 - abs(dot(normal, posSample - pos)) * DistanceNormalisation);
// normal weight
w *= 1 - saturate(acosFast4(saturate(dot(normalSample, normal))) / fsl_HALF_PI * 2);

lpfloat4 gi = srcGI.SampleLevel(samplerLinearClamp, uvSample * outScale, 0);

sum += gi * w;
#ifdef TEMPORAL_DENOISER
fsum += srcAccumFrames.SampleLevel(samplerLinearClamp, uvSample * outScale, 0);
#endif
wsum += w;
}

outGI[dtid] = sum / wsum;
#ifdef TEMPORAL_DENOISER
outAccumFrames[dtid] = fsum / wsum;
#endif
}
25 changes: 17 additions & 8 deletions features/Screen Space GI/Shaders/ScreenSpaceGI/common.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@ cbuffer SSGICB : register(b1)
float4x4 PrevInvViewMat[2];
float4 NDCToViewMul;
float4 NDCToViewAdd;
float4 NDCToViewMul_x_PixelSize;

float2 FrameDim;
float2 RcpFrameDim;
float2 TexDim;
float2 RcpTexDim;
float2 SrcFrameDim;
float2 RcpSrcFrameDim;
float2 OutFrameDim;
float2 RcpOutFrameDim;

uint FrameIndex;

uint NumSlices;
Expand All @@ -79,24 +83,29 @@ cbuffer SSGICB : register(b1)
float GIStrength;

float DepthDisocclusion;
float NormalDisocclusion;
uint MaxAccumFrames;

float pad;
float BlurRadius;
float DistanceNormalisation;
float2 pad;
};

SamplerState samplerPointClamp : register(s0);
SamplerState samplerLinearClamp : register(s1);

///////////////////////////////////////////////////////////////////////////////

// screenPos - normalised position in FrameDim, one eye only
// uv - normalised position in FrameDim, both eye
// texCoord - texture coordinate

#ifdef HALF_RES
const static float res_scale = .5;
# define READ_DEPTH(tex, px) tex.Load(int3(px, 1))
# define FULLRES_LOAD(tex, px, uv, samp) tex.SampleLevel(samp, uv, 0)
# define FULLRES_LOAD(tex, px, texCoord, samp) tex.SampleLevel(samp, texCoord, 0)
#else
const static float res_scale = 1.;
# define READ_DEPTH(tex, px) tex[px]
# define FULLRES_LOAD(tex, px, uv, samp) tex[px]
# define FULLRES_LOAD(tex, px, texCoord, samp) tex[px]
#endif

#ifdef VR
Expand Down
Loading

0 comments on commit d6ae3bf

Please sign in to comment.