ue-materials-rendering
Use when writing C++ for materials or rendering — dynamic material instances, material parameter collections, render targets, scene capture, post process, decals, Nanite, Lumen, MegaLights, Substrate. Also use when the user mentions 'MID', 'CreateDynamicMaterialInstance', 'SetScalarParameterValue', 'UMaterialInstanceDynamic', 'material parameter collection', 'UTextureRenderTarget2D', 'DrawMaterialToRenderTarget', 'scene capture', 'post process volume', 'FPostProcessSettings', 'bOverride_', 'blendable', 'decal', 'custom depth stencil', 'Nanite', 'Lumen' or 'global shader'. For Niagara materials, see ue-niagara-effects; for UMG materials, see ue-ui-umg-slate.
quodsoler · 已有静态检查记录
安装与使用
运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。
npx skills add quodsoler/unreal-engine-skills --skill ue-materials-rendering技能说明
name: ue-materials-rendering description: "Use when writing C++ for materials or rendering — dynamic material instances, material parameter collections, render targets, scene capture, post process, decals, Nanite, Lumen, MegaLights, Substrate. Also use when the user mentions 'MID', 'CreateDynamicMaterialInstance', 'SetScalarParameterValue', 'UMaterialInstanceDynamic', 'material parameter collection', 'UTextureRenderTarget2D', 'DrawMaterialToRenderTarget', 'scene capture', 'post process volume', 'FPostProcessSettings', 'bOverride_', 'blendable', 'decal', 'custom depth stencil', 'Nanite', 'Lumen' or 'global shader'. For Niagara materials, see ue-niagara-effects; for UMG materials, see ue-ui-umg-slate." metadata: version: "2.0.0" engine: "5.8"
UE Materials and Rendering
Target engine: UE 5.8. APIs below are verified against the 5.8 headers; older forms are listed under "Deprecated — do not use".
Runtime material and rendering C++: UMaterialInstanceDynamic, UMaterialParameterCollection, UTextureRenderTarget2D, USceneCaptureComponent2D, FPostProcessSettings, UDecalComponent, plus the 5.8 renderer features (Nanite, Lumen, MegaLights, Substrate, Virtual Shadow Maps, TSR). Material headers live in Runtime/Engine/Public/Materials; render targets, scene, post-process volumes in Runtime/Engine/Classes/Engine; Blueprint libraries in Runtime/Engine/Classes/Kismet. Build.cs: "Engine" covers everything above; add "RenderCore" and "RHI" only for EShaderPlatform, RDG and global shaders.
Context
Read .agents/ue-project-context.md if it exists (module names, conventions, enabled plugins, renderer settings). Do not stop if it is missing.
Identify the area from the request and the codebase. Ask only when two plausible readings would produce different code.
| Request is about… | Go to |
|---|---|
| Changing material parameters at runtime on a mesh | Dynamic Material Instances |
| One value driving many materials (weather, time of day) | Material Parameter Collections |
| Minimap, mirror, security camera, runtime texture painting | Render Targets / Scene Capture |
| Bloom, exposure, DOF, color grading, Lumen quality knobs | Post Process |
| Full-screen effect authored as a material | Post-Process Materials |
| Bullet holes, blood, projected textures | Decals |
| Nanite mesh/material compatibility, WPO, Nanite override material | Nanite |
| GI, reflections, many shadowed lights | Lumen and MegaLights |
| Layered/multi-BSDF material system | Substrate |
| Outlines, X-ray, stencil masks, shadow/AA settings | Shadows, Anti-Aliasing and Custom Depth |
An API wants EShaderPlatform but you have a feature level | Feature Level and Shader Platform |
| Writing an actual HLSL shader pass from C++ | Global Shaders and Render Graph |
Full signature tables live in material-parameter-reference.md; the FPostProcessSettings field tables live in post-process-settings.md; global shader and RDG code lives in global-shaders-rdg.md.
Dynamic Material Instances
A MID is a per-instance parameter override on top of a parent material. Three ways to make one:
| Need | Call |
|---|---|
| Standalone MID not bound to a slot | UMaterialInstanceDynamic::Create(Parent, Outer, Name) |
| MID assigned to a component's material slot | UPrimitiveComponent::CreateDynamicMaterialInstance(ElementIndex, SourceMaterial, OptionalName) |
| MID from Blueprint-facing library code | UKismetMaterialLibrary::CreateDynamicMaterialInstance(WorldContextObject, Parent, OptionalName, CreationFlags) |
Verbatim signatures:
// Materials/MaterialInstanceDynamic.h
static UMaterialInstanceDynamic* Create(class UMaterialInterface* ParentMaterial, class UObject* InOuter, FName Name = NAME_None);
// Components/PrimitiveComponent.h
virtual class UMaterialInstanceDynamic* CreateDynamicMaterialInstance(int32 ElementIndex, class UMaterialInterface* SourceMaterial = NULL, FName OptionalName = NAME_None);
// Kismet/KismetMaterialLibrary.h
static class UMaterialInstanceDynamic* CreateDynamicMaterialInstance(UObject* WorldContextObject, class UMaterialInterface* Parent, FName OptionalName = NAME_None, EMIDCreationFlags CreationFlags = EMIDCreationFlags::None);
Create once, cache in a UPROPERTY, update in Tick or on an event:
// MyGlowActor.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "MyGlowActor.generated.h"
class UMaterialInstanceDynamic;
class UStaticMeshComponent;
UCLASS()
class MYGAME_API AMyGlowActor : public AActor
{
GENERATED_BODY()
public:
AMyGlowActor();
virtual void BeginPlay() override;
protected:
UPROPERTY(VisibleAnywhere, Category = "Rendering")
TObjectPtr<UStaticMeshComponent> Mesh;
UPROPERTY(Transient)
TObjectPtr<UMaterialInstanceDynamic> GlowMID;
};
// MyGlowActor.cpp
#include "MyGlowActor.h"
#include "Components/StaticMeshComponent.h"
#include "Materials/MaterialInstanceDynamic.h"
AMyGlowActor::AMyGlowActor()
{
Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
SetRootComponent(Mesh);
}
void AMyGlowActor::BeginPlay()
{
Super::BeginPlay();
GlowMID = Mesh->CreateDynamicMaterialInstance(0);
if (GlowMID)
{
GlowMID->SetVectorParameterValue(TEXT("GlowColor"), FLinearColor(1.f, 0.4f, 0.1f, 1.f));
GlowMID->SetScalarParameterValue(TEXT("GlowStrength"), 1.f);
}
}
When dozens of parameters change per frame, swap the name lookup for the index API — InitializeScalarParameterAndGetIndex o