Backport rendering fixes from https://github.com/RomanZhu/FlaxEngine
This commit is contained in:
Binary file not shown.
@@ -1272,7 +1272,7 @@ bool GlobalSurfaceAtlasPass::Render(RenderContext& renderContext, GPUContext* co
|
||||
// Init constants
|
||||
result.Constants.ViewPos = renderContext.View.Position;
|
||||
result.Constants.Resolution = (float)resolution;
|
||||
result.Constants.ChunkSize = distance / (float)GLOBAL_SURFACE_ATLAS_CHUNKS_RESOLUTION;
|
||||
result.Constants.ChunkSize = distance * 2.0f / (float)GLOBAL_SURFACE_ATLAS_CHUNKS_RESOLUTION;
|
||||
result.Constants.ObjectsCount = surfaceAtlasData.Objects.Count();
|
||||
|
||||
// If we don't know the culled objects buffer capacity then we shouldn't use atlas results as many objects are still missing (see CulledObjectsCounterIndex usage)
|
||||
|
||||
@@ -271,11 +271,12 @@ void CS_CullObjects(uint3 DispatchThreadId : SV_DispatchThreadID, uint3 GroupId
|
||||
}
|
||||
}
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
uint culledObjectsCount = min(SharedCulledObjectsCount, GLOBAL_SURFACE_ATLAS_SHARED_CULL_SIZE);
|
||||
|
||||
// Cull objects from the shared buffer against active thread's chunk
|
||||
uint objectsCount = 0;
|
||||
LOOP
|
||||
for (uint i = 0; i < SharedCulledObjectsCount; i++)
|
||||
for (uint i = 0; i < culledObjectsCount; i++)
|
||||
{
|
||||
uint objectAddress = SharedCulledObjects[i];
|
||||
float4 objectBounds = LoadGlobalSurfaceAtlasObjectBounds(GlobalSurfaceAtlasObjects, objectAddress);
|
||||
@@ -310,7 +311,7 @@ void CS_CullObjects(uint3 DispatchThreadId : SV_DispatchThreadID, uint3 GroupId
|
||||
|
||||
// Copy objects data in this chunk (cull from the shared buffer)
|
||||
LOOP
|
||||
for (uint i = 0; i < SharedCulledObjectsCount; i++)
|
||||
for (uint i = 0; i < culledObjectsCount; i++)
|
||||
{
|
||||
uint objectAddress = SharedCulledObjects[i];
|
||||
float4 objectBounds = LoadGlobalSurfaceAtlasObjectBounds(GlobalSurfaceAtlasObjects, objectAddress);
|
||||
|
||||
@@ -134,10 +134,10 @@ float SampleGlobalSDF(const GlobalSDFData data, Texture3D<snorm float> tex, floa
|
||||
float voxelSize = data.CascadeVoxelSize[cascade];
|
||||
float chunkMargin = voxelSize * (GLOBAL_SDF_CHUNK_MARGIN_SCALE * GLOBAL_SDF_RASTERIZE_CHUNK_MARGIN);
|
||||
float maxDistanceTex = data.CascadeMaxDistanceTex[cascade];
|
||||
float distanceTex = tex.SampleLevel(GLOBAL_SDF_SAMPLER, textureUV, 0);
|
||||
float distanceTex = tex.SampleLevel(GLOBAL_SDF_SAMPLER, textureUV, 0) * maxDistanceTex;
|
||||
if (distanceTex < chunkMargin && all(cascadeUV > 0) && all(cascadeUV < 1))
|
||||
{
|
||||
distance = distanceTex * maxDistanceTex;
|
||||
distance = distanceTex;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -159,10 +159,10 @@ float SampleGlobalSDF(const GlobalSDFData data, Texture3D<snorm float> tex, Text
|
||||
float chunkSize = voxelSize * GLOBAL_SDF_RASTERIZE_CHUNK_SIZE;
|
||||
float chunkMargin = voxelSize * (GLOBAL_SDF_CHUNK_MARGIN_SCALE * GLOBAL_SDF_RASTERIZE_CHUNK_MARGIN);
|
||||
float maxDistanceMip = data.CascadeMaxDistanceMip[cascade];
|
||||
float distanceMip = mip.SampleLevel(GLOBAL_SDF_SAMPLER, textureMipUV, 0);
|
||||
float distanceMip = mip.SampleLevel(GLOBAL_SDF_SAMPLER, textureMipUV, 0) * maxDistanceMip;
|
||||
if (distanceMip < chunkSize && all(cascadeUV > 0) && all(cascadeUV < 1))
|
||||
{
|
||||
distance = distanceMip * maxDistanceMip;
|
||||
distance = distanceMip;
|
||||
float maxDistanceTex = data.CascadeMaxDistanceTex[cascade];
|
||||
float distanceTex = tex.SampleLevel(GLOBAL_SDF_SAMPLER, textureUV, 0) * maxDistanceTex;
|
||||
if (distanceTex < chunkMargin)
|
||||
@@ -188,7 +188,7 @@ float3 SampleGlobalSDFGradient(const GlobalSDFData data, Texture3D<snorm float>
|
||||
float voxelSize = data.CascadeVoxelSize[cascade];
|
||||
float chunkMargin = voxelSize * (GLOBAL_SDF_CHUNK_MARGIN_SCALE * GLOBAL_SDF_RASTERIZE_CHUNK_MARGIN);
|
||||
float maxDistanceTex = data.CascadeMaxDistanceTex[cascade];
|
||||
float distanceTex = tex.SampleLevel(GLOBAL_SDF_SAMPLER, textureUV, 0);
|
||||
float distanceTex = tex.SampleLevel(GLOBAL_SDF_SAMPLER, textureUV, 0) * maxDistanceTex;
|
||||
if (distanceTex < chunkMargin && all(cascadeUV > 0) && all(cascadeUV < 1))
|
||||
{
|
||||
float texelOffset = 1.0f / data.Resolution;
|
||||
@@ -200,7 +200,7 @@ float3 SampleGlobalSDFGradient(const GlobalSDFData data, Texture3D<snorm float>
|
||||
float zp = tex.SampleLevel(GLOBAL_SDF_SAMPLER, float3(textureUV.x, textureUV.y, textureUV.z + texelOffset), 0).x;
|
||||
float zn = tex.SampleLevel(GLOBAL_SDF_SAMPLER, float3(textureUV.x, textureUV.y, textureUV.z - texelOffset), 0).x;
|
||||
gradient = float3(xp - xn, yp - yn, zp - zn) * maxDistanceTex;
|
||||
distance = distanceTex * maxDistanceTex;
|
||||
distance = distanceTex;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user