0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

チュートリアルの『プラグインとして新規グローバル シェーダーを作成する』を見る上での注意点

Posted at

自分へのメモも兼ねて、UEのグローバルシェーダを作成するチュートリアルページを見ていて、ハマった箇所があったので、メモを残しておきます。

検証環境

UnrealEngine5.3.2

どのチュートリアルか

プラグインとして新規グローバル シェーダーを作成するというページになります。
分かる人にはすぐに分かる問題かもしれません。
注意点は、ここからになります。

『Foo.uplugin』の『IsExperimentalVersion』を消さない

プラグインを作成した際に、デフォルトの『uplugin』には、IsExperimentalVersionというチュートリアルにはないパラメータがあります。これを消してしまうと、ビルドエラーになってしまいます。

{
	"FileVersion": 3,
	"Version": 1,
	"VersionName": "1.0",
	"FriendlyName": "Foo",
	"Description": "",
	"Category": "Other",
	"CreatedBy": "",
	"CreatedByURL": "",
	"DocsURL": "",
	"MarketplaceURL": "",
	"SupportURL": "",
	"CanContainContent": true,
	"IsBetaVersion": false,
	"IsExperimentalVersion": false,  ⇐ ココ消さないで
	"Installed": false,
	"Modules": [
		{
			"Name": "Foo",
			"Type": "Developer",
			"LoadingPhase": "PostConfigInit"
		}
	]
}

『Foo.Build.cs』で『ShaderCore』を入れない

リンクエラーが出て、ずっと困っていたのですが、ここをみると、『RenderCore』に統合されてしまったようで、『ShaderCoreモジュール』は無くなってしまったという事が分かりました。
また、IPluginManagerを使用する為、『Projectsモジュール』を追加する必要があります。

// Copyright Epic Games, Inc. All Rights Reserved.

using UnrealBuildTool;

public class Foo : ModuleRules
{
	public Foo(ReadOnlyTargetRules Target) : base(Target)
	{
		PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
		
		PublicIncludePaths.AddRange(
			new string[] {
				"Foo/Public"
			}
			);
				
		
		PrivateIncludePaths.AddRange(
			new string[] {
				"Foo/Private",
			}
			);
			
		
		PublicDependencyModuleNames.AddRange(
			new string[]
			{
				"Core",
				"Projects",    // ⇐コレ必要
				"RenderCore",
				// "ShaderCore",  // ⇐コレ不要
				"RHI",
			}
			);
			
		
		PrivateDependencyModuleNames.AddRange(
			new string[]
			{
				"CoreUObject",
				"Engine",
			}
			);
		
		
		DynamicallyLoadedModuleNames.AddRange(
			new string[]
			{
			}
			);
	}
}

Fooモジュールを設定する

// Copyright Epic Games, Inc. All Rights Reserved.

#include "Foo.h"
#include "Interfaces/IPluginManager.h"

#define LOCTEXT_NAMESPACE "FFooModule"

void FFooModule::StartupModule()
{
	// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
	FString PluginShaderDir = FPaths::Combine(IPluginManager::Get().FindPlugin(TEXT("Foo"))->GetBaseDir(), TEXT("Shaders"));
	AddShaderSourceDirectoryMapping(TEXT("/Plugin/Foo"), PluginShaderDir);
}

void FFooModule::ShutdownModule()
{
	// This function may be called during shutdown to clean up your module.  For modules that support dynamic reloading,
	// we call this function before unloading the module.
}

#undef LOCTEXT_NAMESPACE
	
IMPLEMENT_MODULE(FFooModule, Foo)

プラグインのモジュールの設定している記載がまるまるページに無いですが、追加プラグインで追加したデフォルトのままだと問題がある点だけ載せておきます。
Fooモジュールで、StartupModuleでシェーダのファイルをマッピングする必要があります。
これをやらないと、以下のメッセージのクラッシュが発生します。

スクリーンショット 2025-03-10 155457.png

④インプット入力を入れる

スクリーンショット 2025-03-10 161536.png

新規に作成したプロジェクトだと、入力が来ないので、有効にしてあげてください。

最後に

このチュートリアルページの厄介なところは、コードをコピーして貼り付けられるようになっている事です。
ですので、そのまま、コピー&ペーストすると、私と同じように『何故か動かないだー!』という事になってしまうかも知れません。
原因を探りつつ、正しい動作まで持って行くというのも、良い学習にはなると思いますが...。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?