Files
BlueRoseNote/03-UnrealEngine/卡通渲染相关资料/渲染功能/ARC/Gameplay/REDSceneContext.md

88 lines
2.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: REDSceneContext
date: 2026-05-03 00:00:00
excerpt: 全局 Shader 数据管线,提供 BGMultColor、灾害效果等 Shader 可访问数据
tags:
- ARC
- Gameplay
- Rendering
rating: ⭐
---
# REDSceneContext
返回 [[Gameplay]]
## 概述
`UREDSceneContext` 是 ARC 引擎的全局 Shader 数据管线,将游戏逻辑层的数据传递给 Shader 使用。它是一个 UObject可以在蓝图和 C++ 中设置参数,数据通过 `ViewUniformShaderParameters` 传入 GPU。
## 提供的数据
| 参数 | 类型 | 用途 |
|------|------|------|
| `BGMultColor` | FLinearColor | [[BGMultColor全局色调]]:场景颜色乘算 + 饱和度 |
| `DisasterPosition` | FVector | 灾害效果中心位置(场景破坏特效) |
| `DisasterWind` | FVector | 灾害风力方向和强度 |
| `DisasterQuake` | float | 灾害震动强度 |
| `GameTime` | float | 游戏时间(用于 Shader 动画) |
| `BGTime` | float | 背景时间(可独立于 GameTime |
## 数据流
```
游戏逻辑 (Blueprint/C++)
↓ 设置 UREDSceneContext 参数
REDSceneContext
↓ SceneRendering.cpp 读取
ViewUniformShaderParameters
↓ Upload to GPU
Shader (View.BGMultColor, View.DisasterPosition, ...)
```
## 灾害效果系统
`DisasterPosition``DisasterWind``DisasterQuake` 三个参数用于格斗游戏中的必杀技演出——场景因攻击而震动、风吹、变形等效果,由 Shader 读取这些参数来驱动场景顶点动画和粒子。
## 完整代码解析
```cpp
// REDSceneContext.h — 全局 Shader 数据管线
UCLASS()
class UREDSceneContext : public UObject
{
GENERATED_BODY()
public:
// 场景全局色调RGB=颜色乘数, A=饱和度)
UPROPERTY(EditAnywhere)
FLinearColor BGMultColor = FLinearColor(1,1,1,1);
// 灾害效果参数(必杀技演出用)
UPROPERTY(EditAnywhere)
FVector DisasterPosition; // 灾害中心位置
FVector DisasterWind; // 风力方向和强度
float DisasterQuake; // 震动强度
// 时间参数
float GameTime; // 游戏时间(可暂停)
float BGTime; // 背景时间(独立于游戏时间)
};
// SceneRendering.cpp — 数据传递到 ViewUniform
ViewUniformShaderParameters.BGMultColor = SceneContext->BGMultColor;
ViewUniformShaderParameters.DisasterPosition = SceneContext->DisasterPosition;
// ... Shader 中通过 View.BGMultColor 等访问
```
## 关联文档
- [[BGMultColor全局色调]] — 使用 `BGMultColor` 参数
- [[RED场景视图类型]] — 场景分层与 Context 配合
## 代码修改情况
| 文件路径 | 修改类型 | 修改内容 |
|---------|---------|---------|
| `Source/Runtime/Engine/Public/REDSceneContext.h` | **新增文件** | `UREDSceneContext`BGMultColor/Disaster/Time |
| `Source/Runtime/Renderer/Private/SceneRendering.cpp` | 修改 | 读取 Context 写入 `ViewUniformShaderParameters` |