Skip to content

Commit cd845dc

Browse files
committed
[Patch] decouple internal color from drawable. Fixed render graph
1 parent a206a5d commit cd845dc

43 files changed

Lines changed: 856 additions & 303 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Sources/CShaderTypes/ShaderTypes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,10 @@ typedef enum{
409409
gaussianRenderViewPortIndex,
410410
}GaussianRenderBufferIndices;
411411

412+
typedef enum{
413+
outputTransformPassEncodingModeIndex
414+
}OutputTransformBufferIndices;
415+
412416
//Ray tracing structs
413417
#define GEOMETRY_MASK_TRIANGLE 1
414418
#define GEOMETRY_MASK_SPHERE 2
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
2+
//
3+
// ColorPipelineConfig.swift
4+
// UntoldEngine
5+
//
6+
// Copyright (C) Untold Engine Studios
7+
// Licensed under the GNU LGPL v3.0 or later.
8+
// See the LICENSE file or <https://www.gnu.org/licenses/> for details.
9+
//
10+
11+
import Foundation
12+
import Metal
13+
import MetalKit
14+
15+
public enum OutputEncodingMode: Int32 {
16+
case hardwareSRGB = 0
17+
case manualSRGBOETF = 1
18+
case hdrPassthrough = 2
19+
}
20+
21+
public struct WorkingColorFormats {
22+
public var gBufferAlbedo: MTLPixelFormat
23+
public var gBufferNormal: MTLPixelFormat
24+
public var gBufferPosition: MTLPixelFormat
25+
public var gBufferMaterial: MTLPixelFormat
26+
public var gBufferEmissive: MTLPixelFormat
27+
28+
public var sceneColor: MTLPixelFormat
29+
public var postProcess: MTLPixelFormat
30+
public var sceneComposite: MTLPixelFormat
31+
public var lookOutput: MTLPixelFormat
32+
33+
public var environment: MTLPixelFormat
34+
public var gaussian: MTLPixelFormat
35+
public var gizmo: MTLPixelFormat
36+
public var ibl: MTLPixelFormat
37+
38+
public static let standard = WorkingColorFormats(
39+
gBufferAlbedo: .rgba8Unorm_srgb,
40+
gBufferNormal: .rgba16Float,
41+
gBufferPosition: .rgba16Float,
42+
gBufferMaterial: .rgba8Unorm,
43+
gBufferEmissive: .rgba16Float,
44+
sceneColor: .rgba16Float,
45+
postProcess: .rgba16Float,
46+
sceneComposite: .rgba16Float,
47+
lookOutput: .rgba16Float,
48+
environment: .rgba16Float,
49+
gaussian: .rgba16Float,
50+
gizmo: .rgba16Float,
51+
ibl: .rgba16Float
52+
)
53+
}
54+
55+
public struct PresentOutputConfig {
56+
public var pixelFormat: MTLPixelFormat
57+
public var encodingMode: OutputEncodingMode
58+
59+
public init(pixelFormat: MTLPixelFormat) {
60+
self.pixelFormat = pixelFormat
61+
if pixelFormat.isSRGBFormat {
62+
encodingMode = .hardwareSRGB
63+
} else {
64+
encodingMode = .manualSRGBOETF
65+
}
66+
}
67+
}
68+
69+
public struct ColorPipelineConfig {
70+
public var working: WorkingColorFormats
71+
public var present: PresentOutputConfig
72+
73+
public static func standard(presentFormat: MTLPixelFormat) -> ColorPipelineConfig {
74+
ColorPipelineConfig(
75+
working: .standard,
76+
present: .init(pixelFormat: presentFormat)
77+
)
78+
}
79+
}
80+
81+
public extension MTLPixelFormat {
82+
var isSRGBFormat: Bool {
83+
switch self {
84+
case .bgra8Unorm_srgb, .rgba8Unorm_srgb:
85+
return true
86+
default:
87+
return false
88+
}
89+
}
90+
}

Sources/UntoldEngine/Renderer/Pipelines/RenderPipeLines.swift

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,12 @@ public typealias RenderPipelineInitBlock = () -> RenderPipeline?
110110
// MARK: Grid pipeline
111111

112112
public func InitGridPipeline() -> RenderPipeline? {
113-
CreatePipeline(
113+
let wf = renderInfo.colorPipeline.working
114+
return CreatePipeline(
114115
vertexShader: "vertexGridShader",
115116
fragmentShader: "fragmentGridShader",
116117
vertexDescriptor: createGridVertexDescriptor(),
117-
colorFormats: [.bgra8Unorm_srgb],
118+
colorFormats: [wf.environment],
118119
depthFormat: renderInfo.depthPixelFormat,
119120
depthCompareFunction: MTLCompareFunction.less,
120121
depthEnabled: false,
@@ -139,12 +140,14 @@ public func InitShadowPipeline() -> RenderPipeline? {
139140

140141
// MARK: Model pipeline
141142

143+
private var wf: WorkingColorFormats { renderInfo.colorPipeline.working }
144+
142145
public func InitModelPipeline() -> RenderPipeline? {
143146
CreatePipeline(
144147
vertexShader: "vertexModelShader",
145148
fragmentShader: "fragmentModelShader",
146149
vertexDescriptor: createModelVertexDescriptor(),
147-
colorFormats: [renderInfo.colorPixelFormat, .rgba16Float, .rgba16Float, .rgba8Unorm, .rgba8Unorm],
150+
colorFormats: [wf.gBufferAlbedo, wf.gBufferNormal, wf.gBufferPosition, wf.gBufferMaterial, wf.gBufferEmissive],
148151
depthFormat: renderInfo.depthPixelFormat,
149152
name: "Model Pipeline"
150153
)
@@ -157,7 +160,7 @@ public func InitLightPipeline() -> RenderPipeline? {
157160
vertexShader: "vertexLightShader",
158161
fragmentShader: "fragmentLightShader",
159162
vertexDescriptor: createLightVertexDescriptor(),
160-
colorFormats: [renderInfo.colorPixelFormat],
163+
colorFormats: [wf.sceneColor],
161164
depthFormat: .invalid,
162165
depthEnabled: false,
163166
name: "Light Pipeline"
@@ -171,7 +174,7 @@ public func InitGeometryPipeline() -> RenderPipeline? {
171174
vertexShader: "vertexGeometryShader",
172175
fragmentShader: "fragmentGeometryShader",
173176
vertexDescriptor: createGeometryVertexDescriptor(),
174-
colorFormats: [renderInfo.colorPixelFormat, .rgba16Float, .rgba16Float],
177+
colorFormats: [wf.gizmo, .rgba16Float, .rgba16Float],
175178
depthFormat: renderInfo.depthPixelFormat,
176179
name: "Geometry Pipeline"
177180
)
@@ -184,7 +187,7 @@ public func InitHighlightPipeline() -> RenderPipeline? {
184187
vertexShader: "vertexGeometryShader",
185188
fragmentShader: "fragmentGeometryShader",
186189
vertexDescriptor: createGeometryVertexDescriptor(),
187-
colorFormats: [renderInfo.colorPixelFormat],
190+
colorFormats: [wf.gizmo],
188191
depthFormat: renderInfo.depthPixelFormat,
189192
depthCompareFunction: .always,
190193
depthEnabled: false,
@@ -199,7 +202,7 @@ public func InitLightVisualPipeline() -> RenderPipeline? {
199202
vertexShader: "vertexLightVisualShader",
200203
fragmentShader: "fragmentLightVisualShader",
201204
vertexDescriptor: createLightVisualVertexDescriptor(),
202-
colorFormats: [renderInfo.colorPixelFormat],
205+
colorFormats: [wf.gizmo],
203206
depthFormat: renderInfo.depthPixelFormat,
204207
depthEnabled: true,
205208
name: "Light Visual Pipeline"
@@ -213,7 +216,7 @@ public func InitOutlinePipeline() -> RenderPipeline? {
213216
vertexShader: "vertexOutlineShader",
214217
fragmentShader: "fragmentOutlineShader",
215218
vertexDescriptor: createOutlineVertexDescriptor(),
216-
colorFormats: [renderInfo.colorPixelFormat, .rgba16Float, .rgba16Float],
219+
colorFormats: [wf.gizmo, .rgba16Float, .rgba16Float],
217220
depthFormat: renderInfo.depthPixelFormat,
218221
depthCompareFunction: .lessEqual,
219222
depthEnabled: true,
@@ -228,8 +231,8 @@ public func InitCompositePipeline() -> RenderPipeline? {
228231
vertexShader: "vertexCompositeShader",
229232
fragmentShader: "fragmentCompositeShader",
230233
vertexDescriptor: createCompositeVertexDescriptor(),
231-
colorFormats: [.bgra8Unorm_srgb],
232-
depthFormat: renderInfo.depthPixelFormat,
234+
colorFormats: [renderInfo.presentColorPixelFormat],
235+
depthFormat: renderInfo.presentDepthPixelFormat,
233236
depthEnabled: false,
234237
name: "Composite Pipeline"
235238
)
@@ -242,8 +245,8 @@ public func InitPreCompositePipeline() -> RenderPipeline? {
242245
vertexShader: "vertexPreCompositeShader",
243246
fragmentShader: "fragmentPreCompositeShader",
244247
vertexDescriptor: createPreCompositeVertexDescriptor(),
245-
colorFormats: [.bgra8Unorm_srgb],
246-
depthFormat: renderInfo.depthPixelFormat,
248+
colorFormats: [wf.sceneComposite],
249+
depthFormat: .invalid,
247250
depthEnabled: false,
248251
blendEnabled: true,
249252
name: "Pre-Composite Pipeline"
@@ -257,7 +260,7 @@ public func InitTonemappingPipeline() -> RenderPipeline? {
257260
vertexShader: "vertexTonemappingShader",
258261
fragmentShader: "fragmentTonemappingShader",
259262
vertexDescriptor: createPostProcessVertexDescriptor(),
260-
colorFormats: [renderInfo.colorPixelFormat],
263+
colorFormats: [wf.postProcess],
261264
depthFormat: renderInfo.depthPixelFormat,
262265
depthEnabled: false,
263266
name: "Tone-mapping Pipeline"
@@ -271,35 +274,21 @@ public func InitBlurPipeline() -> RenderPipeline? {
271274
vertexShader: "vertexBlurShader",
272275
fragmentShader: "fragmentBlurShader",
273276
vertexDescriptor: createPostProcessVertexDescriptor(),
274-
colorFormats: [renderInfo.colorPixelFormat],
277+
colorFormats: [wf.postProcess],
275278
depthFormat: renderInfo.depthPixelFormat,
276279
depthEnabled: false,
277280
name: "Blur Pipeline"
278281
)
279282
}
280283

281-
// MARK: Color grading pipeline
282-
283-
public func InitColorGradingPipeline() -> RenderPipeline? {
284-
CreatePipeline(
285-
vertexShader: "vertexColorGradingShader",
286-
fragmentShader: "fragmentColorGradingShader",
287-
vertexDescriptor: createPostProcessVertexDescriptor(),
288-
colorFormats: [renderInfo.colorPixelFormat],
289-
depthFormat: renderInfo.depthPixelFormat,
290-
depthEnabled: false,
291-
name: "ColorGrading Pipeline"
292-
)
293-
}
294-
295284
// MARK: Color correction pipeline
296285

297286
public func InitColorCorrectionPipeline() -> RenderPipeline? {
298287
CreatePipeline(
299288
vertexShader: "vertexColorCorrectionShader",
300289
fragmentShader: "fragmentColorCorrectionShader",
301290
vertexDescriptor: createPostProcessVertexDescriptor(),
302-
colorFormats: [renderInfo.colorPixelFormat],
291+
colorFormats: [wf.postProcess],
303292
depthFormat: renderInfo.depthPixelFormat,
304293
depthEnabled: false,
305294
name: "Color Correction Pipeline"
@@ -313,7 +302,7 @@ public func InitBloomThresholdPipeline() -> RenderPipeline? {
313302
vertexShader: "vertexBloomThresholdShader",
314303
fragmentShader: "fragmentBloomThresholdShader",
315304
vertexDescriptor: createPostProcessVertexDescriptor(),
316-
colorFormats: [renderInfo.colorPixelFormat],
305+
colorFormats: [wf.postProcess],
317306
depthFormat: renderInfo.depthPixelFormat,
318307
depthEnabled: false,
319308
name: "Bloom Threshold Pipeline"
@@ -327,7 +316,7 @@ public func InitBloomCompositePipeline() -> RenderPipeline? {
327316
vertexShader: "vertexBloomCompositeShader",
328317
fragmentShader: "fragmentBloomCompositeShader",
329318
vertexDescriptor: createPostProcessVertexDescriptor(),
330-
colorFormats: [renderInfo.colorPixelFormat],
319+
colorFormats: [wf.postProcess],
331320
depthFormat: renderInfo.depthPixelFormat,
332321
depthEnabled: false,
333322
blendEnabled: true,
@@ -342,7 +331,7 @@ public func InitVignettePipeline() -> RenderPipeline? {
342331
vertexShader: "vertexVignetteShader",
343332
fragmentShader: "fragmentVignetteShader",
344333
vertexDescriptor: createPostProcessVertexDescriptor(),
345-
colorFormats: [renderInfo.colorPixelFormat],
334+
colorFormats: [wf.postProcess],
346335
depthFormat: renderInfo.depthPixelFormat,
347336
depthEnabled: false,
348337
name: "Vignette Pipeline"
@@ -356,7 +345,7 @@ public func InitChromaticAberrationPipeline() -> RenderPipeline? {
356345
vertexShader: "vertexChromaticAberrationShader",
357346
fragmentShader: "fragmentChromaticAberrationShader",
358347
vertexDescriptor: createPostProcessVertexDescriptor(),
359-
colorFormats: [renderInfo.colorPixelFormat],
348+
colorFormats: [wf.postProcess],
360349
depthFormat: renderInfo.depthPixelFormat,
361350
depthEnabled: false,
362351
name: "Chromatic Aberration Pipeline"
@@ -370,7 +359,7 @@ public func InitDepthOfFieldPipeline() -> RenderPipeline? {
370359
vertexShader: "vertexDepthOfFieldShader",
371360
fragmentShader: "fragmentDepthOfFieldShader",
372361
vertexDescriptor: createPostProcessVertexDescriptor(),
373-
colorFormats: [renderInfo.colorPixelFormat],
362+
colorFormats: [wf.postProcess],
374363
depthFormat: renderInfo.depthPixelFormat,
375364
depthEnabled: false,
376365
name: "Depth of Field Pipeline"
@@ -447,7 +436,7 @@ public func InitGaussianPipeline() -> RenderPipeline? {
447436
vertexShader: "vertexGaussianShader",
448437
fragmentShader: "fragmentGaussianShader",
449438
vertexDescriptor: createGaussianVertexDescriptor(),
450-
colorFormats: [renderInfo.colorPixelFormat],
439+
colorFormats: [wf.gaussian],
451440
depthFormat: renderInfo.depthPixelFormat,
452441
depthEnabled: false,
453442
blendEnabled: false,
@@ -463,7 +452,7 @@ public func InitEnvironmentPipeline() -> RenderPipeline? {
463452
vertexShader: "vertexEnvironmentShader",
464453
fragmentShader: "fragmentEnvironmentShader",
465454
vertexDescriptor: createEnvironmentVertexDescriptor(),
466-
colorFormats: [.bgra8Unorm_srgb],
455+
colorFormats: [wf.environment],
467456
depthFormat: renderInfo.depthPixelFormat,
468457
depthEnabled: false,
469458
name: "Environment Pipeline"
@@ -529,14 +518,38 @@ public func InitIBLPreFilterPipeline() -> RenderPipeline? {
529518
vertexShader: "vertexIBLPreFilterShader",
530519
fragmentShader: "fragmentIBLPreFilterShader",
531520
vertexDescriptor: createIBLPreFilterVertexDescriptor(),
532-
colorFormats: [renderInfo.colorPixelFormat, renderInfo.colorPixelFormat, renderInfo.colorPixelFormat],
521+
colorFormats: [wf.ibl, wf.ibl, wf.ibl],
533522
depthFormat: .invalid,
534523
depthCompareFunction: .less,
535524
depthEnabled: false,
536525
name: "IBL-Pre Filer Pipeline"
537526
)
538527
}
539528

529+
public func InitLookPipeline() -> RenderPipeline? {
530+
CreatePipeline(
531+
vertexShader: "vertexLookShader",
532+
fragmentShader: "fragmentLookShader",
533+
vertexDescriptor: createPostProcessVertexDescriptor(),
534+
colorFormats: [wf.lookOutput],
535+
depthFormat: renderInfo.depthPixelFormat,
536+
depthEnabled: false,
537+
name: "Look Pipeline"
538+
)
539+
}
540+
541+
public func InitOutputTransformPipeline() -> RenderPipeline? {
542+
CreatePipeline(
543+
vertexShader: "vertexOutputTransformShader",
544+
fragmentShader: "fragmentOutputTransformShader",
545+
vertexDescriptor: createPostProcessVertexDescriptor(),
546+
colorFormats: [renderInfo.presentColorPixelFormat],
547+
depthFormat: renderInfo.presentDepthPixelFormat,
548+
depthEnabled: false,
549+
name: "Output Transform Pipeline"
550+
)
551+
}
552+
540553
public func DefaultPipeLines() -> [(RenderPipelineType, RenderPipelineInitBlock)] {
541554
[
542555
(.grid, InitGridPipeline),
@@ -551,7 +564,6 @@ public func DefaultPipeLines() -> [(RenderPipelineType, RenderPipelineInitBlock)
551564
(.preComposite, InitPreCompositePipeline),
552565
(.tonemapping, InitTonemappingPipeline),
553566
(.blur, InitBlurPipeline),
554-
(.colorGrading, InitColorGradingPipeline),
555567
(.colorCorrection, InitColorCorrectionPipeline),
556568
(.bloomThreshold, InitBloomThresholdPipeline),
557569
(.bloomComposite, InitBloomCompositePipeline),
@@ -565,6 +577,8 @@ public func DefaultPipeLines() -> [(RenderPipelineType, RenderPipelineInitBlock)
565577
(.environment, InitEnvironmentPipeline),
566578
(.iblPreFilter, InitIBLPreFilterPipeline),
567579
(.gaussian, InitGaussianPipeline),
580+
(.look, InitLookPipeline),
581+
(.outputTransform, InitOutputTransformPipeline),
568582
]
569583
}
570584

Sources/UntoldEngine/Renderer/Pipelines/RenderPipelineType.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public extension RenderPipelineType {
2727
static let preComposite: RenderPipelineType = "preComposite"
2828
static let tonemapping: RenderPipelineType = "tonemapping"
2929
static let blur: RenderPipelineType = "blur"
30-
static let colorGrading: RenderPipelineType = "colorGrading"
3130
static let colorCorrection: RenderPipelineType = "colorCorrection"
3231
static let bloomThreshold: RenderPipelineType = "bloomThreshold"
3332
static let bloomComposite: RenderPipelineType = "bloomComposite"
@@ -41,4 +40,6 @@ public extension RenderPipelineType {
4140
static let environment: RenderPipelineType = "environment"
4241
static let iblPreFilter: RenderPipelineType = "iblPreFilter"
4342
static let gaussian: RenderPipelineType = "gaussian"
43+
static let look: RenderPipelineType = "look"
44+
static let outputTransform: RenderPipelineType = "outputTransform"
4445
}

0 commit comments

Comments
 (0)