C++ 如何在UnrealEngine中对非2次方纹理进行下采样?

C++ 如何在UnrealEngine中对非2次方纹理进行下采样?,c++,image,unreal-engine4,C++,Image,Unreal Engine4,我以1920x1080的分辨率乘以过采样值(如4)渲染视口。现在我需要从渲染的分辨率7680中减少采样‬x4320返回1920x1080 有什么函数在虚幻中我可以使用吗?或者任何能很好地处理此问题的库(仅限windows)? 或者我自己写这篇文章的方式是什么 我们尝试实现下采样,但它仅在SnapshotScale为2时有效,当其高于2时,似乎对图像质量没有影响 UTexture2D* AAVESnapShotManager::DownsampleTexture(UTexture2D* Textu

我以1920x1080的分辨率乘以过采样值(如4)渲染视口。现在我需要从渲染的分辨率7680中减少采样‬x4320返回1920x1080

有什么函数在虚幻中我可以使用吗?或者任何能很好地处理此问题的库(仅限windows)? 或者我自己写这篇文章的方式是什么

我们尝试实现下采样,但它仅在SnapshotScale为2时有效,当其高于2时,似乎对图像质量没有影响

UTexture2D* AAVESnapShotManager::DownsampleTexture(UTexture2D* Texture)
{

    UTexture2D* Result = UTexture2D::CreateTransient(RenderSettings.imageWidth, RenderSettings.imageHeight, PF_B8G8R8A8);

    void* TextureDataVoid = Texture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_ONLY);

    void* ResultDataVoid = Result->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);

    FColor* TextureData = (FColor*)TextureDataVoid;
    FColor* ResultData = (FColor*)ResultDataVoid;

    int32 WindowSize = RenderSettings.resolutionScale / 2;

    for (int x = 0; x < Result->GetSizeX(); ++x)
    {
        for (int y = 0; y < Result->GetSizeY(); ++y)
        {
            const uint32 ResultIndex = y * Result->GetSizeX() + x;

            uint32_t R = 0, G = 0, B = 0, A = 0;

            int32 Samples = 0;

            for (int32 dx = -WindowSize; dx < WindowSize; ++dx)
            {
                for (int32 dy = -WindowSize; dy < WindowSize; ++dy)
                {

                    int32 PosX = (x * RenderSettings.resolutionScale + dx);
                    int32 PosY = (y * RenderSettings.resolutionScale + dy);

                    if (PosX < 0 || PosX >= Texture->GetSizeX() || PosY < 0 || PosY >= Texture->GetSizeY())
                    {
                        continue;
                    }

                    size_t TextureIndex = PosY * Texture->GetSizeX() + PosX;
                    FColor& Color = TextureData[TextureIndex];
                    R += Color.R;
                    G += Color.G;
                    B += Color.B;
                    A += Color.A;
                    ++Samples;
                }
            }

            ResultData[ResultIndex] = FColor(R / Samples, G / Samples, B / Samples, A / Samples);
        }
    }

    Texture->PlatformData->Mips[0].BulkData.Unlock();
    Result->PlatformData->Mips[0].BulkData.Unlock();

    Result->UpdateResource();

    return Result;

}
UTexture2D*AAVESnapShotManager::DownsampleTexture(UTexture2D*Texture)
{
UTexture2D*Result=UTexture2D::CreateTransient(RenderSettings.imageWidth、RenderSettings.imageHeight、PF_B8G8R8A8);
void*TextureDataVoid=Texture->PlatformData->Mips[0]。BulkData.Lock(Lock\u READ\u ONLY);
void*ResultDataVoid=Result->PlatformData->Mips[0].BulkData.Lock(Lock\u READ\u WRITE);
FColor*TextureData=(FColor*)TextureDataVoid;
FColor*ResultData=(FColor*)ResultData;
int32 WindowSize=RenderSettings.resolutionScale/2;
对于(int x=0;xGetSizeX();++x)
{
对于(int y=0;yGetSizeY();++y)
{
const uint32 ResultIndex=y*Result->GetSizeX()+x;
uint32_t R=0,G=0,B=0,A=0;
int32样本=0;
对于(int32 dx=-WindowsSize;dx=Texture->GetSizeX()| | PosY<0 | | PosY>=Texture->GetSizeY())
{
继续;
}
size\u t TextureIndex=PosY*Texture->GetSizeX()+PosX;
FColor&Color=TextureData[TextureIndex];
R+=Color.R;
G+=Color.G;
B+=颜色B;
A+=颜色。A;
++样品;
}
}
结果数据[ResultIndex]=FColor(R/样本,G/样本,B/样本,A/样本);
}
}
纹理->平台数据->Mips[0].BulkData.Unlock();
结果->平台数据->Mips[0]。BulkData.Unlock();
结果->更新资源();
返回结果;
}

我期望高质量的过采样纹理输出,在SnapshotScale中使用任何正的int值。

我有一个建议。这并不直接,但它不涉及编写图像过滤或导入库

  • 使用节点TextureObject->TextureSample->连接到Emissive制作未发光材质

  • 使用函数中开始的纹理在材质的动态材质实例上填充纹理对象

  • 使用“绘制材质以渲染目标”功能将材质实例动态绘制到使用目标分辨率预设的渲染目标


  • 我有一个建议。这并不直接,但它不涉及编写图像过滤或导入库

  • 使用节点TextureObject->TextureSample->连接到Emissive制作未发光材质

  • 使用函数中开始的纹理在材质的动态材质实例上填充纹理对象

  • 使用“绘制材质以渲染目标”功能将材质实例动态绘制到使用目标分辨率预设的渲染目标

  • 谢谢,但是“绘制材质到渲染目标”不会给出很好的下采样结果,即使我从2048到512。谢谢,但是“绘制材质到渲染目标”不会给出很好的下采样结果,即使我从2048到512。