Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shadowed sky light #1189

Open
mafiesto4 opened this issue Jun 19, 2023 · 2 comments · May be fixed by #2635
Open

Add shadowed sky light #1189

mafiesto4 opened this issue Jun 19, 2023 · 2 comments · May be fixed by #2635
Labels
graphics suggestion Idea or improvement suggestion

Comments

@mafiesto4
Copy link
Member

Add support for using Global SDF to render shadow for Sky Light. This should reduce sky-light leaking into interiors and improve ambient lighting.

Global SDF usage in shaders: https://docs.flaxengine.com/manual/graphics/models/sdf.html#shaders

Example of raytracing in Screen Space Reflections shader:

// Fallback to Global SDF and Global Surface Atlas tracing
#if USE_GLOBAL_SURFACE_ATLAS && CAN_USE_GLOBAL_SURFACE_ATLAS
GlobalSDFTrace sdfTrace;
float maxDistance = 100000;
float selfOcclusionBias = GlobalSDF.CascadeVoxelSize[0];
sdfTrace.Init(gBuffer.WorldPos + gBuffer.Normal * selfOcclusionBias, reflectWS, 0.0f, maxDistance);
GlobalSDFHit sdfHit = RayTraceGlobalSDF(GlobalSDF, GlobalSDFTex, GlobalSDFMip, sdfTrace);
if (sdfHit.IsHit())
{
float3 hitPosition = sdfHit.GetHitPosition(sdfTrace);
float surfaceThreshold = GetGlobalSurfaceAtlasThreshold(GlobalSDF, sdfHit);
float4 surfaceAtlas = SampleGlobalSurfaceAtlas(GlobalSurfaceAtlas, GlobalSurfaceAtlasChunks, RWGlobalSurfaceAtlasCulledObjects, GlobalSurfaceAtlasObjects, GlobalSurfaceAtlasDepth, GlobalSurfaceAtlasTex, hitPosition, -reflectWS, surfaceThreshold);
result = lerp(surfaceAtlas, float4(result.rgb, 1), result.a);
}
#endif

@mafiesto4 mafiesto4 added graphics suggestion Idea or improvement suggestion labels Jun 19, 2023
@HydrogenC
Copy link
Contributor

How is this meant to be implemented? I've tried to trace in the normal direction but it doesn't look good. It would be theoretically better to sample on the hemisphere but won't that be too computationally costly?

@mafiesto4
Copy link
Member Author

I think it would make sense to sample part of the hemisphere around the surface normal to account for ambient light diffusion. We use surface normal for skylight lighting (eg. to sample sky texture). This skylight shadowing is meant to be very ambient (eg. when lighting scene with single skylight with HDRI image for overcast day lighting scenario) so we could do it in low-res with upscaling and some temporal effect (noise filtered by temporal accumulation).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
graphics suggestion Idea or improvement suggestion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants