Ara you OK?
我看你是思想出现了偏差
哇!你认出了错别单词!恭喜你获得一次向我支付宝充值助我重返欧洲的机会!
这个页面管关不掉了,你自己看着办吧

UE4-笔记-通用功能实现逻辑/材质例子

UGameViewportClient记一些自己实现的通用功能的例子.备查

-----------------------------------------

 

Q.保持场景Actor相对于Screen的像素缩放比(例如Gizmos组件):

ref:参考UE源码的UnrealWidgetRender.cpp 里的Render_Rotate函数实现:

 

 

 如源码,第一步需要获得的是当前相机位的ViewMatrix 的视口矩阵

方式一:

直接重写UGameViewportClient::Draw 截获FSceneView Instance实现.(同Gizmos逻辑)

方式二:

从指定相机获取Info并计算相关Matrix

    UCameraComponent * _Camera = nullptr; /* your camera component */
    
    FMinimalViewInfo info;
    _Camera->GetCameraView(DeltaTime,info);
    FMatrix _ViewMatrix;
    FMatrix _ProjectionMatrix;
    FMatrix _ViewProjectionMatrix;
    UGameplayStatics::GetViewProjectionMatrix(info,_ViewMatrix, _ProjectionMatrix, _ViewProjectionMatrix);
    FVector2D _size; 
    GEngine->GameViewport->GetViewportSize(_size);
    float Scale = _ProjectionMatrix.TransformFVector4(this->GetActorLocation()).W * (4.0f / _size.X / _ProjectionMatrix.M[0][0]);
    FVector scaleV(Scale);

 

 

Q.双击模拟(应用于二段跳/双击W加速跑等):

推荐用C++实现的,BP不好维护 搜索定位=_,=

BP:

宏实现:

 

C++实现:

---------- 割割割 -----------

.h文件:

UENUM(BlueprintType)
enum class EM_ClickType : uint8
{
    EM_FisrtClick    UMETA(DisplayName = "FisrtClick"),
    EM_DoubleClick    UMETA(DisplayName = "DoubleClick")
};

UCLASS()
class UBPLibrary_CommonDemonstrate : public UBlueprintFunctionLibrary
{
    GENERATED_BODY()
public:
    UFUNCTION(BlueprintCallable)
        static EM_ClickType DoubleClick();
};

 

cpp文件:

EM_ClickType UCppBPLibrary_CommonDemonstrate::DoubleClick()
{
    static bool bReadyOnce = false;
    if (bReadyOnce)
    {
        bReadyOnce = false;
        return  EM_ClickType::EM_DoubleClick;// double click
    }
    else
    {
        bReadyOnce = true;
        TFuture<void> future = Async<void>(EAsyncExecution::TaskGraph, [=]
        {
            FPlatformProcess::Sleep(0.25);
            if (bReadyOnce)
            {
                bReadyOnce = false;
                return;
            }
        });

        return  EM_ClickType::EM_FisrtClick; // first click
    }
}

 

使用:

 

 

Q.UMG追踪Actor(3D方位转2D UMG坐标):

用于释放指向性道具等需要Actor和UMG联动的操作.

类似泡泡卡丁车的释放导弹追踪功能:

主要函数 BP:

  

 

Q.TA向-半透明材质剔除模型重复渲染区域+边缘高亮:

  记一下材质球和实现步骤,备复用

  目标mesh Component 需启用 RenderCustomDepthPass

  文档:https://docs.unrealengine.com/en-US/Engine/Rendering/PostProcessEffects/PostProcessMaterials/index.html

  移动端开启文档:https://docs.unrealengine.com/en-US/Platforms/Mobile/PostProcessEffects/index.html

 

 

 

Q.TA向-物化/像素化特效:

  来源:https://www.artstation.com/artwork/rRaNKO

 

 

 

 

 

 

Q.TA向-后期盒之边缘高亮实现:

  来着Youtube: https://www.youtube.com/watch?v=rL7VUeZzRyQ

  wait

 

Q.TA向-根据距离计算材质透明度:

 

 

Q.UE4-防抖动:

 

posted @ 2019-07-22 16:02  林清  阅读(1258)  评论(0编辑  收藏  举报