Skip to content

Commit

Permalink
Fix dilation, mesh cutout and change default normals to be flat
Browse files Browse the repository at this point in the history
  • Loading branch information
Erlandys committed Mar 14, 2024
1 parent 50682f0 commit f84ab0a
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 14 deletions.
Binary file not shown.
Binary file not shown.
Binary file modified Content/ImpostorBaker/Materials/Generation/M_Sample_Frame.uasset
Binary file not shown.
Binary file modified Content/ImpostorBaker/Materials/M_Billboard.uasset
Binary file not shown.
Binary file modified Content/ImpostorBaker/Materials/M_Billboard_TwoSided.uasset
Binary file not shown.
9 changes: 6 additions & 3 deletions Source/ImpostorBakerEditor/Private/ImpostorData.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,13 @@ class UImpostorData : public UObject
UPROPERTY(EditAnywhere, Category = "Material")
float PixelDepthOffset = 0.f;

UPROPERTY(EditAnywhere, Category = "Material", meta = (ClampMin = "0", ClampMax = "1"))
float Dilation = 0.f;
UPROPERTY(EditAnywhere, Category = "Material")
bool bEnableDilation = false;

UPROPERTY(EditAnywhere, Category = "Material", meta = (EditCondition = "bEnableDilation"))
bool bOverrideDilationSteps = false;

UPROPERTY(EditAnywhere, Category = "Material", meta = (ClampMin = "1"))
UPROPERTY(EditAnywhere, Category = "Material", meta = (EditCondition = "bEnableDilation && bOverrideDilationSteps", ClampMin = "1"))
int32 DilationMaxSteps = 64;

UPROPERTY(EditAnywhere, Category = "Custom Lighting")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,31 @@ UMaterialInstanceDynamic* UImpostorMaterialsManager::GetSampleMaterial(const EIm

SampleFrameMaterial->SetScalarParameterValue("UseSRGBBaseColor", TargetMap == EImpostorBakeMapType::BaseColor ? 1.f : 0.f);

if (ImpostorData->bUseDistanceFieldAlpha &&
(TargetMap == EImpostorBakeMapType::BaseColor))
if (TargetMap == EImpostorBakeMapType::BaseColor)
{
SampleFrameMaterial->SetScalarParameterValue("UseDistanceField", 1.f);
if (ImpostorData->bUseDistanceFieldAlpha)
{
SampleFrameMaterial->SetScalarParameterValue("UseDistanceField", 1.f);
}
else
{
SampleFrameMaterial->SetScalarParameterValue("UseDistanceField", 0.f);
}

SampleFrameMaterial->SetScalarParameterValue(FName("Dilation"), ImpostorData->bEnableDilation ? 1.f : 0.f);
if (ImpostorData->bOverrideDilationSteps)
{
SampleFrameMaterial->SetScalarParameterValue(FName("DilationMaxSteps"), ImpostorData->DilationMaxSteps);
}
else
{
const int32 DilationSteps = 1 << FMath::Max(int32(FMath::CeilLogTwo(ImpostorData->FrameSize)) - 7, 0);
SampleFrameMaterial->SetScalarParameterValue(FName("DilationMaxSteps"), DilationSteps);
}
}
else
{
SampleFrameMaterial->SetScalarParameterValue(FName("Dilation"), 0.f);
SampleFrameMaterial->SetScalarParameterValue("UseDistanceField", 0.f);
}

Expand Down Expand Up @@ -307,8 +325,6 @@ void UImpostorMaterialsManager::UpdateSampleFrameMaterial() const
SampleFrameMaterial->SetTextureParameterValue(FName("Alpha"), GetManager<UImpostorRenderTargetsManager>()->SceneCaptureMipChain[0]);
SampleFrameMaterial->SetTextureParameterValue(FName("MipAlpha"), GetManager<UImpostorRenderTargetsManager>()->SceneCaptureMipChain[FMath::Min(GetManager<UImpostorRenderTargetsManager>()->SceneCaptureMipChain.Num() - 1, ImpostorData->DFMipTarget)]);
SampleFrameMaterial->SetScalarParameterValue(FName("TextureSize"), ImpostorData->SceneCaptureResolution);
SampleFrameMaterial->SetScalarParameterValue(FName("Dilation"), ImpostorData->Dilation);
SampleFrameMaterial->SetScalarParameterValue(FName("DilationMaxSteps"), ImpostorData->DilationMaxSteps);
}

void UImpostorMaterialsManager::UpdateAddAlphasMaterial() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,14 +476,18 @@ void UImpostorRenderTargetsManager::CaptureImposterGrid()
SceneWorld->SendAllEndOfFrameUpdates();
SceneCaptureComponent2D->UpdateSceneCaptureContents(SceneWorld->Scene);

if (ImpostorData->bUseDistanceFieldAlpha &&
CurrentMap == EImpostorBakeMapType::BaseColor &&
bCapturingFinalColor)
// Lower mips are necessary for distance field alpha and mesh cutouts
if (ImpostorData->bUseDistanceFieldAlpha ||
ImpostorData->bUseMeshCutout)
{
for (int32 MipIndex = 1; MipIndex < SceneCaptureMipChain.Num(); MipIndex++)
if (CurrentMap == EImpostorBakeMapType::BaseColor &&
bCapturingFinalColor)
{
UKismetRenderingLibrary::ClearRenderTarget2D(SceneWorld, SceneCaptureMipChain[MipIndex], FLinearColor::Black);
ResampleRenderTarget(SceneCaptureMipChain[MipIndex - 1], SceneCaptureMipChain[MipIndex]);
for (int32 MipIndex = 1; MipIndex < SceneCaptureMipChain.Num(); MipIndex++)
{
UKismetRenderingLibrary::ClearRenderTarget2D(SceneWorld, SceneCaptureMipChain[MipIndex], FLinearColor::Black);
ResampleRenderTarget(SceneCaptureMipChain[MipIndex - 1], SceneCaptureMipChain[MipIndex]);
}
}
}

Expand Down

0 comments on commit f84ab0a

Please sign in to comment.