UE4 Decal实现简介

Decal 是游戏中常见的一个东西,经常被用在 显示弹痕,地面叠加花纹等。

在这里插入图片描述
在这里插入图片描述

Decal 绘制流程

Decal可以认为是,将一个面的画面沿Decal的Box的X轴方向投影到物体表面。
在这里插入图片描述

Decal的绘制实际只有一个Box绘制。

RHICmdList.DrawIndexedPrimitive(GetUnitCubeIndexBuffer(), 0, 0, 8, 0, UE_ARRAY_COUNT(GCubeIndices) / 3, 1);

为什么不用一个平面来绘制呢?这样做主要是为了,覆盖不同视角,裁剪也变得简单。

Decal Pass是在Base Pass之后,Translucency Pass之前,Decal只能投射在非透明物体上。

Vertex过程

// from component to clip space (for decal frustum)
float4x4 FrustumComponentToClip;

// decal vertex shader
void MainVS(
    in float4 InPosition : ATTRIBUTE0,
    out float4 OutPosition : SV_POSITION
    )
{
    OutPosition = mul(InPosition, FrustumComponentToClip);
}

Vertex Shader只是乘以FrustumComponentToClip变换矩阵,变换到Clip空间。

FMatrix FDecalRendering::ComputeComponentToClipMatrix(const FViewInfo& View, const FMatrix& DecalComponentToWorld)
{
	FMatrix ComponentToWorldMatrixTrans = DecalComponentToWorld.ConcatTranslation(View.ViewMatrices.GetPreViewTranslation());
	return ComponentToWorldMatrixTrans * View.ViewMatrices.GetTranslatedViewProjectionMatrix();
}

FrustumComponentToClip实际就是WorldViewProjection 组合变换矩阵(包含了DecalSize)

	FTransform GetTransformIncludingDecalSize() const
	{
   
		FTransform Ret = GetComponentToWorld();
		Ret.SetScale3D(Ret.GetScale3D(
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值