refactor(rendering): split managed SRP layers and namespaces

This commit is contained in:
2026-04-19 02:38:48 +08:00
parent 612e3ba0b3
commit 7429f22fb1
46 changed files with 629 additions and 351 deletions

View File

@@ -0,0 +1,112 @@
using XCEngine;
namespace XCEngine.Rendering
{
public sealed class CameraData
{
internal static readonly CameraData Default =
new CameraData(
Matrix4x4.Identity,
Matrix4x4.Identity,
Matrix4x4.Identity,
new Vector3(0.0f, 0.0f, 0.0f),
new Vector3(1.0f, 0.0f, 0.0f),
new Vector3(0.0f, 1.0f, 0.0f),
new Vector3(0.0f, 0.0f, 1.0f),
new Color(0.0f, 0.0f, 0.0f, 1.0f),
RenderClearFlags.All,
true,
60.0f * 0.017453292519943295f,
5.0f,
1.0f,
0.1f,
1000.0f,
0,
0);
internal CameraData(
Matrix4x4 view,
Matrix4x4 projection,
Matrix4x4 viewProjection,
Vector3 worldPosition,
Vector3 worldRight,
Vector3 worldUp,
Vector3 worldForward,
Color clearColor,
RenderClearFlags clearFlags,
bool perspectiveProjection,
float verticalFovRadians,
float orthographicSize,
float aspectRatio,
float nearClipPlane,
float farClipPlane,
int viewportWidth,
int viewportHeight)
{
this.view = view;
this.projection = projection;
this.viewProjection = viewProjection;
this.worldPosition = worldPosition;
this.worldRight = worldRight;
this.worldUp = worldUp;
this.worldForward = worldForward;
this.clearColor = clearColor;
this.clearFlags = clearFlags;
this.perspectiveProjection = perspectiveProjection;
this.verticalFovRadians = verticalFovRadians;
this.orthographicSize = orthographicSize;
this.aspectRatio = aspectRatio;
this.nearClipPlane = nearClipPlane;
this.farClipPlane = farClipPlane;
this.viewportWidth = viewportWidth;
this.viewportHeight = viewportHeight;
}
public Matrix4x4 view { get; }
public Matrix4x4 projection { get; }
public Matrix4x4 viewProjection { get; }
public Vector3 worldPosition { get; }
public Vector3 worldRight { get; }
public Vector3 worldUp { get; }
public Vector3 worldForward { get; }
public Color clearColor { get; }
public RenderClearFlags clearFlags { get; }
public bool perspectiveProjection { get; }
public bool isPerspectiveProjection =>
perspectiveProjection;
public bool isOrthographicProjection =>
!perspectiveProjection;
public bool clearsColor =>
(clearFlags & RenderClearFlags.Color) != 0;
public bool clearsDepth =>
(clearFlags & RenderClearFlags.Depth) != 0;
public float verticalFovRadians { get; }
public float orthographicSize { get; }
public float aspectRatio { get; }
public float nearClipPlane { get; }
public float farClipPlane { get; }
public int viewportWidth { get; }
public int viewportHeight { get; }
}
}

View File

@@ -0,0 +1,43 @@
using XCEngine;
namespace XCEngine.Rendering
{
public sealed class DirectionalLightData
{
internal static readonly DirectionalLightData Default =
new DirectionalLightData(
false,
false,
new Vector3(0.0f, 0.0f, -1.0f),
new Color(1.0f, 1.0f, 1.0f, 1.0f),
1.0f);
internal DirectionalLightData(
bool enabled,
bool castsShadows,
Vector3 direction,
Color color,
float intensity)
{
this.enabled = enabled;
this.castsShadows = castsShadows;
this.direction = direction;
this.color = color;
this.intensity = intensity;
}
public bool enabled { get; }
public bool castsShadows { get; }
public Vector3 direction { get; }
public Color color { get; }
public float intensity { get; }
public bool isValid =>
enabled;
}
}

View File

@@ -0,0 +1,86 @@
using XCEngine;
namespace XCEngine.Rendering
{
public sealed class DirectionalShadowData
{
internal static readonly DirectionalShadowData Default =
new DirectionalShadowData(
false,
Matrix4x4.Identity,
0.0f,
0.1f,
0.0f,
0,
0,
0.0f,
0.0f,
0.0f,
0.0f,
0.0f,
0);
internal DirectionalShadowData(
bool enabled,
Matrix4x4 viewProjection,
float orthographicHalfExtent,
float nearClipPlane,
float farClipPlane,
int mapWidth,
int mapHeight,
float worldTexelSize,
float receiverDepthBias,
float normalBiasScale,
float shadowStrength,
float depthBiasFactor,
int depthBiasUnits)
{
this.enabled = enabled;
this.viewProjection = viewProjection;
this.orthographicHalfExtent =
orthographicHalfExtent;
this.nearClipPlane = nearClipPlane;
this.farClipPlane = farClipPlane;
this.mapWidth = mapWidth;
this.mapHeight = mapHeight;
this.worldTexelSize = worldTexelSize;
this.receiverDepthBias = receiverDepthBias;
this.normalBiasScale = normalBiasScale;
this.shadowStrength = shadowStrength;
this.depthBiasFactor = depthBiasFactor;
this.depthBiasUnits = depthBiasUnits;
}
public bool enabled { get; }
public Matrix4x4 viewProjection { get; }
public float orthographicHalfExtent { get; }
public float nearClipPlane { get; }
public float farClipPlane { get; }
public int mapWidth { get; }
public int mapHeight { get; }
public float worldTexelSize { get; }
public float receiverDepthBias { get; }
public float normalBiasScale { get; }
public float shadowStrength { get; }
public float depthBiasFactor { get; }
public int depthBiasUnits { get; }
public bool hasShadowMap =>
enabled &&
mapWidth > 0 &&
mapHeight > 0;
}
}

View File

@@ -0,0 +1,44 @@
using XCEngine;
namespace XCEngine.Rendering
{
public sealed class EnvironmentData
{
internal static readonly EnvironmentData Default =
new EnvironmentData(
RenderEnvironmentMode.None,
new Color(0.18f, 0.36f, 0.74f, 1.0f),
new Color(0.78f, 0.84f, 0.92f, 1.0f),
new Color(0.92f, 0.93f, 0.95f, 1.0f));
internal EnvironmentData(
RenderEnvironmentMode mode,
Color skyboxTopColor,
Color skyboxHorizonColor,
Color skyboxBottomColor)
{
this.mode = mode;
this.skyboxTopColor = skyboxTopColor;
this.skyboxHorizonColor = skyboxHorizonColor;
this.skyboxBottomColor = skyboxBottomColor;
}
public RenderEnvironmentMode mode { get; }
public Color skyboxTopColor { get; }
public Color skyboxHorizonColor { get; }
public Color skyboxBottomColor { get; }
public bool hasProceduralSkybox =>
mode == RenderEnvironmentMode.ProceduralSkybox;
public bool hasMaterialSkybox =>
mode == RenderEnvironmentMode.MaterialSkybox;
public bool hasSkybox =>
hasProceduralSkybox || hasMaterialSkybox;
}
}

View File

@@ -0,0 +1,42 @@
using XCEngine;
namespace XCEngine.Rendering
{
public sealed class FinalColorData
{
internal static readonly FinalColorData Default =
new FinalColorData(
FinalColorSettings.CreateDefault(),
false,
false);
internal FinalColorData(
FinalColorSettings settings,
bool hasPipelineDefaults,
bool hasCameraOverrides)
{
this.settings = settings;
this.hasPipelineDefaults = hasPipelineDefaults;
this.hasCameraOverrides = hasCameraOverrides;
}
public FinalColorSettings settings { get; }
public bool hasPipelineDefaults { get; }
public bool hasCameraOverrides { get; }
public bool requiresProcessing =>
settings.outputTransferMode !=
FinalColorOutputTransferMode.Disabled ||
settings.exposureMode !=
FinalColorExposureMode.Disabled ||
settings.toneMappingMode !=
FinalColorToneMappingMode.Disabled ||
settings.finalColorScale.x != 1.0f ||
settings.finalColorScale.y != 1.0f ||
settings.finalColorScale.z != 1.0f ||
settings.finalColorScale.w != 1.0f;
}
}

View File

@@ -0,0 +1,38 @@
using XCEngine;
namespace XCEngine.Rendering
{
public sealed class LightingData
{
internal static readonly LightingData Default =
new LightingData(
DirectionalLightData.Default,
false,
0);
internal LightingData(
DirectionalLightData mainDirectionalLight,
bool hasMainDirectionalShadow,
int additionalLightCount)
{
this.mainDirectionalLight =
mainDirectionalLight ?? DirectionalLightData.Default;
this.hasMainDirectionalShadow =
hasMainDirectionalShadow;
this.additionalLightCount = additionalLightCount;
}
public DirectionalLightData mainDirectionalLight { get; }
public bool hasMainDirectionalShadow { get; }
public int additionalLightCount { get; }
public bool hasMainDirectionalLight =>
mainDirectionalLight.enabled;
public bool hasAdditionalLights =>
additionalLightCount > 0;
}
}

View File

@@ -0,0 +1,15 @@
using System;
using XCEngine;
namespace XCEngine.Rendering
{
[Flags]
public enum RenderClearFlags
{
None = 0,
Color = 1 << 0,
Depth = 1 << 1,
All = Color | Depth
}
}

View File

@@ -0,0 +1,12 @@
using XCEngine;
namespace XCEngine.Rendering
{
public enum RenderEnvironmentMode
{
None = 0,
ProceduralSkybox = 1,
MaterialSkybox = 2
}
}

View File

@@ -0,0 +1,92 @@
using XCEngine;
namespace XCEngine.Rendering
{
public sealed class RenderingData
{
internal RenderingData(CameraFrameStage stage)
: this(
stage,
CameraData.Default,
LightingData.Default,
ShadowData.Default,
EnvironmentData.Default,
FinalColorData.Default,
StageColorData.Default)
{
}
internal RenderingData(ScriptableRenderContext context)
: this(
context != null
? context.stage
: CameraFrameStage.MainScene,
context != null
? context.cameraData
: CameraData.Default,
context != null
? context.lightingData
: LightingData.Default,
context != null
? context.shadowData
: ShadowData.Default,
context != null
? context.environmentData
: EnvironmentData.Default,
context != null
? context.finalColorData
: FinalColorData.Default,
context != null
? context.stageColorData
: StageColorData.Default)
{
}
private RenderingData(
CameraFrameStage stage,
CameraData cameraData,
LightingData lightingData,
ShadowData shadowData,
EnvironmentData environmentData,
FinalColorData finalColorData,
StageColorData stageColorData)
{
this.stage = stage;
this.cameraData = cameraData ?? CameraData.Default;
this.lightingData =
lightingData ?? LightingData.Default;
this.shadowData =
shadowData ?? ShadowData.Default;
this.environmentData =
environmentData ?? EnvironmentData.Default;
this.finalColorData =
finalColorData ?? FinalColorData.Default;
this.stageColorData =
stageColorData ?? StageColorData.Default;
}
public CameraFrameStage stage { get; }
public CameraData cameraData { get; }
public LightingData lightingData { get; }
public ShadowData shadowData { get; }
public EnvironmentData environmentData { get; }
public FinalColorData finalColorData { get; }
public StageColorData stageColorData { get; }
public bool isMainSceneStage =>
stage == CameraFrameStage.MainScene;
public bool isPostProcessStage =>
stage == CameraFrameStage.PostProcess;
public bool isFinalOutputStage =>
stage == CameraFrameStage.FinalOutput;
}
}

View File

@@ -0,0 +1,25 @@
using XCEngine;
namespace XCEngine.Rendering
{
public sealed class ShadowData
{
internal static readonly ShadowData Default =
new ShadowData(
DirectionalShadowData.Default);
internal ShadowData(
DirectionalShadowData mainDirectionalShadow)
{
this.mainDirectionalShadow =
mainDirectionalShadow ??
DirectionalShadowData.Default;
}
public DirectionalShadowData mainDirectionalShadow { get; }
public bool hasMainDirectionalShadow =>
mainDirectionalShadow.enabled;
}
}

View File

@@ -0,0 +1,29 @@
using XCEngine;
namespace XCEngine.Rendering
{
public sealed class StageColorData
{
internal static readonly StageColorData Default =
new StageColorData(
CameraFrameColorSource.ExplicitSurface,
false);
internal StageColorData(
CameraFrameColorSource source,
bool usesGraphManagedOutputColor)
{
this.source = source;
this.usesGraphManagedOutputColor =
usesGraphManagedOutputColor;
}
public CameraFrameColorSource source { get; }
public bool usesGraphManagedSourceColor =>
source != CameraFrameColorSource.ExplicitSurface;
public bool usesGraphManagedOutputColor { get; }
}
}