Skip to content

Commit e045c8e

Browse files
committed
fix: Fix the color tone for tile rendering.
Signed-off-by: Karthik Bekal Pattathana <133984042+karthikbekalp@users.noreply.github.com>
1 parent bc7b101 commit e045c8e

36 files changed

Lines changed: 588 additions & 41 deletions

src/deadline/cinema4d_adaptor/Cinema4DClient/tile_rendering.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,16 @@ def finalize_tile_render(
228228
render_data: The render data object (to restore output paths).
229229
frame: The current frame number.
230230
"""
231-
# Restore the OCIO bake flag to its original value
232-
if ctx.orig_bake_flag is not None:
233-
rd[c4d.RDATA_BAKE_OCIO_VIEW_TRANSFORM_RENDER] = ctx.orig_bake_flag
234-
235-
if ctx.requires_baking:
236-
baked = c4d.documents.BakeOcioViewToBitmap(bm, rd, c4d.SAVEBIT_NONE)
237-
bm = baked or bm
231+
try:
232+
if ctx.requires_baking:
233+
# setup_tile_render disabled the render-time bake. It must remain
234+
# disabled here or BakeOcioViewToBitmap assumes the bitmap was
235+
# already baked and returns None.
236+
baked = c4d.documents.BakeOcioViewToBitmap(bm, rd, c4d.SAVEBIT_NONE)
237+
bm = baked or bm
238+
finally:
239+
if ctx.orig_bake_flag is not None:
240+
rd[c4d.RDATA_BAKE_OCIO_VIEW_TRANSFORM_RENDER] = ctx.orig_bake_flag
238241

239242
if c4d.GetC4DVersion() >= C4D_VERSION_2025_2:
240243
bm.SetColorProfile(c4d.bitmaps.ColorProfile(), c4d.COLORPROFILE_INDEX_DISPLAYSPACE)

test/integ/ocio_scene.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
"""Shared Physical OCIO cube scene for Cinema 4D integration tests."""
3+
4+
import os
5+
6+
import c4d
7+
8+
ACES_DEFAULT_VIEW_TRANSFORM = 0
9+
ACES_UNTONE_MAPPED_VIEW_TRANSFORM = 3
10+
PHYSICAL_RENDERER_ID = 1023342
11+
12+
13+
def _add_sample_cube(doc) -> None:
14+
cube = c4d.BaseObject(c4d.Ocube)
15+
cube.SetName("OCIO sample cube")
16+
cube[c4d.PRIM_CUBE_LEN] = c4d.Vector(300, 300, 300)
17+
cube.SetAbsPos(c4d.Vector(0, 170, 170))
18+
doc.InsertObject(cube)
19+
20+
21+
def build_ocio_scene(
22+
output_dir: str,
23+
scene_name: str,
24+
view_transform: int,
25+
) -> None:
26+
"""Build and save the sample cube with the requested ACES view transform."""
27+
output_dir = os.path.abspath(output_dir)
28+
os.makedirs(output_dir, exist_ok=True)
29+
30+
doc = c4d.documents.GetActiveDocument()
31+
doc.Flush()
32+
doc[c4d.DOCUMENT_COLOR_MANAGEMENT] = c4d.DOCUMENT_COLOR_MANAGEMENT_OCIO
33+
doc[c4d.DOCUMENT_OCIO_PRESET] = c4d.DOCUMENT_OCIO_PRESET_ACES
34+
doc[c4d.DOCUMENT_OCIO_VIEW_TRANSFORM] = view_transform
35+
36+
_add_sample_cube(doc)
37+
38+
render_data = doc.GetActiveRenderData()
39+
render_data[c4d.RDATA_RENDERENGINE] = PHYSICAL_RENDERER_ID
40+
render_data[c4d.RDATA_FRAMEFROM] = c4d.BaseTime(1, doc.GetFps())
41+
render_data[c4d.RDATA_FRAMETO] = c4d.BaseTime(1, doc.GetFps())
42+
render_data[c4d.RDATA_FORMAT] = c4d.FILTER_PNG
43+
render_data[c4d.RDATA_FORMATDEPTH] = c4d.RDATA_FORMATDEPTH_8
44+
render_data[c4d.RDATA_ALPHACHANNEL] = False
45+
render_data[c4d.RDATA_MULTIPASS_SAVEIMAGE] = False
46+
if hasattr(c4d, "RDATA_BAKE_OCIO_VIEW_TRANSFORM_RENDER"):
47+
render_data.GetDataInstance()[c4d.RDATA_BAKE_OCIO_VIEW_TRANSFORM_RENDER] = True
48+
49+
render_data[c4d.RDATA_PATH] = "renders/$prj"
50+
51+
scene_path = os.path.join(output_dir, scene_name)
52+
doc.SetDocumentPath(output_dir)
53+
doc.SetDocumentName(scene_name)
54+
if not c4d.documents.SaveDocument(
55+
doc,
56+
scene_path,
57+
c4d.SAVEDOCUMENTFLAGS_0,
58+
c4d.FORMAT_C4DEXPORT,
59+
):
60+
raise RuntimeError(f"Failed to save integration scene: {scene_path}")
61+
c4d.EventAdd()
-342 Bytes
Loading
-15 Bytes
Loading
-15 Bytes
Loading
-15 Bytes
Loading
-29 Bytes
Loading
4 Bytes
Loading
-15 Bytes
Loading
-255 Bytes
Loading

0 commit comments

Comments
 (0)