티스토리 뷰

https://dev.epicgames.com/community/learning/tutorials/2R5x/unreal-engine-new-shading-models-and-changing-the-gbuffer

 

New shading models and changing the GBuffer | Community tutorial

Implementing a Celshading model directly into UE5.1 source. This celshading use a linear color curve atlas to drive all the values. Learn how to set you...

dev.epicgames.com

 

위의 가이드를 따라서 새로운 GBuffer을 추가하고 새로운 셰이더 모델을 개발하는 과정을 진행중!

그런데... 

언리얼 5.1 부터 새로운 셰이더를 추가하는 방법이 바뀌었다.

EngineTypes.h 내부에서 enum 타입을 추가하는 위치등이 조금씩 변경된 모양... 

EngineTypes.h 수정으로 인한 빌드 오류 문제가 계속 생겨서 엔진 버전을 바꾸거나 5.1 버전의 셰이더 추가 방법을 찾아 보기로 했다.

 

우선 "GBuffer 변경 HLSL" 파트까지는 완료했다. DeferredShadingCommon.ush 의 내부에 새로운 씬텍스처파라미터를 추가했고 FGBufferData 구조체에도 필요한 데이터를 추가해주었다.

// all values that are output by the forward rendering pass
struct FGBufferData
{
	// normalized
	half3 WorldNormal;
	// normalized, only valid if HAS_ANISOTROPY_MASK in SelectiveOutputMask
	half3 WorldTangent;
 
// [...]
 
	// 0..1, only needed by SHADINGMODELID_SUBSURFACE_PROFILE and SHADINGMODELID_EYE which apply BaseColor later
	half3 StoredBaseColor;
	// 0..1, only needed by SHADINGMODELID_SUBSURFACE_PROFILE and SHADINGMODELID_EYE which apply Specular later
	half StoredSpecular;
	// 0..1, only needed by SHADINGMODELID_EYE which encodes Iris Distance inside Metallic
	half StoredMetallic;
 
	// Curvature for mobile subsurface profile
	half Curvature;
 
	// 0..1, Celshading Lucas: Celshading values
	float4 Celshading;
};

 

SceneTexturesCommon.ush 파일 에는 정의를 추가.

#define SceneTexturesStruct_GBufferCelshadingTextureSampler SceneTexturesStruct.PointClampSampler // Celshading Lucas: another sampler for scene texture

 

마지막으로 지연된 데칼의 경우 FPixelShaderInOut_MainPS() 함수 내에 더미 값을 추가해준다.

DeferredDecal.usf 파일의 FPixelShaderInOut_MainPS에 셀셰이더에 대한 부분을 추가.

void FPixelShaderInOut_MainPS(inout FPixelShaderIn In, inout FPixelShaderOut Out)
{
// [...]
 
FGBufferData GBufferData;
	GBufferData.WorldNormal = MaterialParameters.WorldNormal;
	GBufferData.BaseColor = GetMaterialBaseColor(PixelMaterialInputs);
	GBufferData.Metallic = GetMaterialMetallic(PixelMaterialInputs);
	GBufferData.Specular = GetMaterialSpecular(PixelMaterialInputs);
	GBufferData.Roughness = GetMaterialRoughness(PixelMaterialInputs);
	GBufferData.CustomData = 0;
	GBufferData.IndirectIrradiance = 0;
	GBufferData.PrecomputedShadowFactors = 1;
	GBufferData.GBufferAO = GetMaterialAmbientOcclusion(PixelMaterialInputs);
	GBufferData.ShadingModelID = SHADINGMODELID_DEFAULT_LIT;
	GBufferData.SelectiveOutputMask = 0;
	GBufferData.PerObjectGBufferData = 1; 
	GBufferData.DiffuseIndirectSampleOcclusion = 0;
	GBufferData.Velocity = 0;
	GBufferData.Celshading = 0; // Celshading Lucas : dummy value for decals;
 
// [...]
}

 

마지막으로 레이트레이싱을 위해 RayTracingDeferredShadingCommon.ush 파일의 Decode 부분을 추가해줘야 한다.

FGBufferData GetGBufferDataFromSceneTexturesLoad(uint2 PixelCoord, bool bGetNormalizedNormal = true)
{
	float4 GBufferA = GBufferATexture.Load(int3(PixelCoord, 0));
	float4 GBufferB = GBufferBTexture.Load(int3(PixelCoord, 0));
	float4 GBufferC = GBufferCTexture.Load(int3(PixelCoord, 0));
	float4 GBufferD = GBufferDTexture.Load(int3(PixelCoord, 0));
	float4 GBufferE = GBufferETexture.Load(int3(PixelCoord, 0));
	float4 GBufferF = GBufferFTexture.Load(int3(PixelCoord, 0));
	// Celshading Lucas: sample the texture
	// 수정한 부분 !
	float4 GBufferCelshading = GBufferCelshadingTexture.Load(int3(PixelCoord, 0));

#if GBUFFER_HAS_VELOCITY
	float4 GBufferVelocity = GBufferVelocityTexture.Load(int3(PixelCoord, 0));
#else
	float4 GBufferVelocity = 0.0f;
#endif

	uint CustomStencil = 0;
	float CustomNativeDepth = 0;

	float DeviceZ = SceneDepthTexture.Load(int3(PixelCoord, 0)).r;;

	float SceneDepth = ConvertFromDeviceZ(DeviceZ);

	return DecodeGBufferData(GBufferA, GBufferB, GBufferC, GBufferD, GBufferE, GBufferF, GBufferVelocity, CustomNativeDepth, CustomStencil, SceneDepth, bGetNormalizedNormal, CheckerFromPixelPos(PixelCoord));
}

페이로드 부분에도 셀셰이딩에 대한 부분을 추가해준다.

FGBufferData GetGBufferDataFromPayload(in FMaterialClosestHitPayload Payload)
{
	FGBufferData GBufferData = (FGBufferData)0;
#if !STRATA_ENABLED
	GBufferData.Depth = 1.f; // Do not use depth
	GBufferData.WorldNormal = Payload.WorldNormal;
	GBufferData.BaseColor = Payload.BaseColor;
	GBufferData.Metallic = Payload.Metallic;
	GBufferData.Specular = Payload.Specular;
	GBufferData.Roughness = Payload.Roughness;
	GBufferData.CustomData = Payload.CustomData;
	GBufferData.GBufferAO = Payload.GBufferAO;
	GBufferData.IndirectIrradiance = (Payload.IndirectIrradiance.x + Payload.IndirectIrradiance.y + Payload.IndirectIrradiance.z) / 3.f;
	GBufferData.ShadingModelID = Payload.ShadingModelID;
	GBufferData.SpecularColor = Payload.SpecularColor;
	GBufferData.DiffuseColor = Payload.DiffuseColor;
	GBufferData.WorldTangent = Payload.WorldTangent;
	GBufferData.Anisotropy = Payload.Anisotropy;
	// Celshading Lucas: Add celshading from payload
	// 수정한 부분 !
	GBufferData.Celshading = float4(Payload.Celshading, 0,0,0); 
#endif
	return GBufferData;
}

 

DeferredShadingCommon.ush 파일 내부에 있는 DecodeGBufferData() 함수에도 다음과 같이 코드를 추가해 주어야 한다. 그런데 현재는 HLSL 오류로 인해 엔진코드에서는 아래 부분을 주석처리 해 두었다.

/** Populates FGBufferData */
// @param bChecker High frequency Checkerboard pattern computed with one of the CheckerFrom.. functions, todo: profile if float 0/1 would be better (need to make sure it's 100% the same)
FGBufferData DecodeGBufferData(
	float4 InGBufferA,
	float4 InGBufferB,
	float4 InGBufferC,
	float4 InGBufferD,
	float4 InGBufferE,
	float4 InGBufferF,
	float4 InGBufferVelocity,
	float CustomNativeDepth,
	uint CustomStencil,
	float SceneDepth,
	bool bGetNormalizedNormal,
	bool bChecker,
	float InGBufferCelshading) // Don't forget the new definition here
{
	FGBufferData GBuffer;
// [...]
	GBuffer.CustomData = HasCustomGBufferData(GBuffer.ShadingModelID) ? InGBufferD : 0;
	GBuffer.Celshading = IsCelShading(GBuffer.ShadingModelID) ? InGBufferCelshading : 0;
// [...]
}

자꾸 IsCelShading() 함수가 없다고 뜨는데 위에 있는걸 확인을 했다.

또 float InGBufferCelshading 파라미터 추가 또한 아직 적용을 시키지 않았다. 이 부분들에 대해서는 5.1 버전에 맞는 커스텀 셰이더를 만들어보면서 다시 도전해볼 생각이다.

 

그 외에 RayTracingCommon.ush 파일 내부에 있는 

struct FMaterialClosestHitPayload : FMinimalPayload 와 FPackedMaterialClosestHitPayload : FMinimalPayload  구조체에는 float Celshading; 에 대한 변수들도 추가되었다. DecodeGBufferData를 제외하고서는 HLSL 부분도 새로운 GBuffer를 위해 수정이 전부 이루어 졌다. 

이제... 새로운 셰이더에 대한 도전만 남았다 흑흑 파이팅

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
글 보관함