Unreal Decal을 이용해 총알자국 생성하기

Unreal Decal을 이용해 총알자국 생성하기.

 

Unreal에서 Decal을 이용해서 총알자국을 생성하는 방법에 대한 글입니다.

간단한 예시지만 응용해서 텍스쳐를 바꾸면 혈흔, 화살표 등의 시각적 효과를 구현하는데 유용하게 사용할 수 있습니다.

현재 글에서 사용한 Bullet Hole Image는 아래 사이트에서 받았습니다.

https://opengameart.org/content/bullet-decal

 

Bullet Decal

A simple bullet hole decals. I have used it in my first-person shooter.

opengameart.org

Texture 설정.

다운받은 Decal로 사용할 Texture을 설정합니다.

저는 아래의 사진처럼 Sprite Actions->Apply Paper2D Texture Settings를 눌러 설정했습니다.

Material 설정.

메테리얼을 만들어줍니다.

Material Domain을 Deferred Decal로 설정하고 BlendMode 를 Translucent로 설정합니다.

방금 다운받은 Texture Image를 설정합니다.

Alpha를 Opcity에 연결합니다.

SpawnDecal CPP Code.

Texture Image와 Material은 끝났으니 이제 코드부분입니다.

블로그에 옮기면서 필요한 부분만 빼서 수정했습니다.

매개변수로 선언만하고 초기화도 안한 변수가 있긴한데 이거야 뭐..

아무튼 대충 이런식으로 쓰면 됩니다.

FHitResult Hit;
FVector Loc = ViewCamera->GetComponentLocation(); //ViewCamera는 Character에 생성한 UCameraComponent입니다.
FVector Rot = ViewCamera->GetForwardVector();
FCollisionQueryParams CollisionQueryParams(NAME_None, false, this);
TArray<AActor*> Ac;
Ac.Add(this);
if (GetWorld()->LineTraceSingleByChannel(Hit, Loc, Loc + (Rot * 10000), ECollisionChannel::ECC_Visibility, CollisionQueryParams)) { 
//if (UKismetSystemLibrary::LineTraceSingle(GetWorld(), Loc, (Rot * 10000) + Loc, ETraceTypeQuery::TraceTypeQuery1, false, Ac, EDrawDebugTrace::ForDuration, Hit, true)) {
	if (Hit.bBlockingHit) {
		//#include "Components/DecalComponent.h" 필요
		UMaterialInstance* DecalMaterial;
		float DecalLife = 10;
		UGameplayStatics::SpawnDecalAtLocation(GetWorld(), DecalMaterial, FVector(5, 5, 5), Hit.Location, Hit.ImpactNormal.Rotation(), DecalLife)->SetFadeScreenSize(0)
	}
}

실행결과.

실행 결과는 다음과 같습니다.

Designed by JB FACTORY