Skip to content

Commit

Permalink
feat: Enable transparent background rendering in sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
HaiyiMei committed Aug 14, 2024
1 parent 8f8f2e0 commit 87a3736
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/XRFeitoriaUnreal/Content/Python/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class AntiAliasSetting:
console_variables: Dict[str, float] = field(default_factory=dict)
anti_aliasing: AntiAliasSetting = AntiAliasSetting()
export_audio: bool = False
export_transparent: bool = False

def __post_init__(self):
self.render_passes = [RenderPass(**rp) for rp in self.render_passes]
Expand Down
7 changes: 5 additions & 2 deletions src/XRFeitoriaUnreal/Content/Python/custom_movie_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def set_export_audio(movie_preset: unreal.MoviePipelineMasterConfig) -> None:
def add_render_passes(
movie_preset: unreal.MoviePipelineMasterConfig,
render_passes: List[RenderPass],
accumulator_includes_alpha: bool = True,
accumulator_includes_alpha: bool = False,
) -> None:
"""Add render passes to a movie preset.
Expand Down Expand Up @@ -271,6 +271,7 @@ def create_movie_preset(
anti_alias: RenderJobUnreal.AntiAliasSetting = RenderJobUnreal.AntiAliasSetting(),
console_variables: Dict[str, float] = {'r.MotionBlurQuality': 0.0},
export_audio: bool = False,
export_transparent: bool = False,
) -> unreal.MoviePipelineMasterConfig:
"""
Create a movie preset from args.
Expand All @@ -288,14 +289,15 @@ def create_movie_preset(
anti_alias (dict): Anti-alias settings.
console_variables (bool): Console variables.
export_audio (bool): Whether to export audio.
export_transparent (bool): Whether to render with transparent background.
Returns:
unreal.MoviePipelineMasterConfig: The created movie preset.
"""

movie_preset = unreal.MoviePipelineMasterConfig()

cls.add_render_passes(movie_preset, render_passes)
cls.add_render_passes(movie_preset, render_passes, accumulator_includes_alpha=export_transparent)
cls.add_output_config(movie_preset, resolution, file_name_format, output_path)
cls.add_anti_alias(movie_preset, anti_alias)
cls.add_console_command(movie_preset, console_variables)
Expand Down Expand Up @@ -387,6 +389,7 @@ def add_job_to_queue(cls, job: RenderJobUnreal) -> bool:
anti_alias=job.anti_aliasing,
console_variables=job.console_variables,
export_audio=job.export_audio,
export_transparent=job.export_transparent,
)
new_job.set_configuration(movie_preset)
unreal.log(f'Added new job ({new_job.job_name}) to queue')
Expand Down
1 change: 1 addition & 0 deletions tests/unreal/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def new_seq(xf_runner: XRFeitoriaUnreal, level_path: str, seq_name: str):
render_passes=[RenderPass('img', 'png'), RenderPass('flow', 'exr'), RenderPass('lineart', 'png')],
export_vertices=True,
export_skeleton=True,
export_transparent=True,
)

xf_runner.utils.save_current_level()
Expand Down
4 changes: 4 additions & 0 deletions xrfeitoria/data_structure/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ class AntiAliasSetting(BaseModel):
default=AntiAliasSetting(), description='Anti aliasing setting of the render job.'
)
export_audio: bool = Field(default=False, description='Whether to export audio of the render job.')
export_transparent: bool = Field(
default=False,
description='Whether to export transparent images of the render job. When enabled, it will reduce the performance.',
)

class Config:
use_enum_values = True
Expand Down
3 changes: 3 additions & 0 deletions xrfeitoria/renderer/renderer_unreal.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def add_job(
console_variables: Dict[str, float] = {'r.MotionBlurQuality': 0},
anti_aliasing: 'Optional[RenderJob.AntiAliasSetting]' = None,
export_audio: bool = False,
export_transparent: bool = False,
) -> None:
"""Add a rendering job to the renderer queue.
Expand All @@ -56,6 +57,7 @@ def add_job(
Ref to :ref:`FAQ-console-variables` for details.
anti_aliasing (Optional[RenderJobUnreal.AntiAliasSetting], optional): Anti aliasing setting. Defaults to None.
export_audio (bool, optional): Whether to export audio. Defaults to False.
export_transparent (bool, optional): Whether to export transparent images. Defaults to False. When enabled, it will reduce the performance.
Note:
The motion blur is turned off by default. If you want to turn it on, please set ``r.MotionBlurQuality`` to a non-zero value in ``console_variables``.
Expand All @@ -81,6 +83,7 @@ def add_job(
console_variables=console_variables,
anti_aliasing=anti_aliasing,
export_audio=export_audio,
export_transparent=export_transparent,
)
cls._add_job_in_engine(job.model_dump(mode='json'))
cls.render_queue.append(job)
Expand Down
3 changes: 3 additions & 0 deletions xrfeitoria/sequence/sequence_unreal.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def add_to_renderer(
export_vertices: bool = False,
export_skeleton: bool = False,
export_audio: bool = False,
export_transparent: bool = False,
) -> None:
"""Add the sequence to the renderer's job queue. Can only be called after the
sequence is instantiated using
Expand All @@ -90,6 +91,7 @@ def add_to_renderer(
export_vertices (bool, optional): Whether to export vertices. Defaults to False.
export_skeleton (bool, optional): Whether to export the skeleton. Defaults to False.
export_audio (bool, optional): Whether to export audio. Defaults to False.
export_transparent (bool, optional): Whether to export transparent images. Defaults to False. When enabled, it will reduce the performance.
Examples:
>>> import xrfeitoria as xf
Expand Down Expand Up @@ -125,6 +127,7 @@ def add_to_renderer(
console_variables=console_variables,
anti_aliasing=anti_aliasing,
export_audio=export_audio,
export_transparent=export_transparent,
)

logger.info(
Expand Down
1 change: 1 addition & 0 deletions xrfeitoria/sequence/sequence_unreal.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class SequenceUnreal(SequenceBase):
export_vertices: bool = False,
export_skeleton: bool = False,
export_audio: bool = False,
export_transparent: bool = False,
) -> None: ...
@classmethod
def spawn_actor(
Expand Down

0 comments on commit 87a3736

Please sign in to comment.