Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
e228530
testing for RPR
spenceau Jun 20, 2024
b50bdac
fixed ps1 script and granularity
spenceau Jun 21, 2024
5a6b02c
Delete cmd_tools/README.md
spenceau Jun 21, 2024
d3da51c
Delete cmd_tools/cmd_script.py
spenceau Jun 21, 2024
48615b2
Delete cmd_tools/compare_render.py
spenceau Jun 21, 2024
29bdf8c
Delete cmd_tools/render_script.py
spenceau Jun 21, 2024
acf0381
Delete cmd_tools/test_commands.sh
spenceau Jun 21, 2024
1eae3cf
Delete cmd_tools/viewport_render.py
spenceau Jun 21, 2024
366f97a
Delete cmd_tools/test_script.sh
spenceau Jun 21, 2024
e97aa7d
Delete cmd_tools/test_script.ps1
spenceau Jun 21, 2024
f673c39
Delete cmd_tools/.gitignore
spenceau Jun 21, 2024
1639222
Merge pull request #1 from spenceau/spenceau-patch-1
spenceau Jun 21, 2024
97a20bf
Update README.md
spenceau Jun 21, 2024
4a0ad86
Viewport Render Flag
spenceau Jun 29, 2024
d6502d2
gwef
spenceau Jul 2, 2024
e848737
Issues with pyrprwrap
spenceau Jul 3, 2024
4903b62
update render_test.ps1
spenceau Jul 11, 2024
da9a45e
rpr.register() path stuff
spenceau Jul 16, 2024
f41f501
Squashed commit of the following:
spenceau Jul 17, 2024
d9cd24c
src_path fix
spenceau Jul 19, 2024
b92b43a
Merge branch 'GPUOpen-LibrariesAndSDKs:master' into master
spenceau Jul 19, 2024
93c9545
Added RadeonProRenderSDK submodule
spenceau Jul 19, 2024
60611d1
RPR.register() works
spenceau Jul 19, 2024
3f85107
pep8 rules
spenceau Jul 22, 2024
3648634
register() with Build Artifact Works
spenceau Jul 26, 2024
42ba1b4
Update .gitignore
spenceau Jul 26, 2024
96218f8
fixed .gitignore and README
spenceau Jul 26, 2024
7f1d697
RPRNAS double zip fixed
spenceau Jul 26, 2024
1f52a1c
Updated to adjust scripts via bpy
spenceau Jul 31, 2024
6f7afc1
py -3.11 change
spenceau Jul 31, 2024
47689ce
Update cmd_render.py
spenceau Jul 31, 2024
38e2a3a
organizational changes
spenceau Aug 1, 2024
14bb68a
slight changes
spenceau Aug 1, 2024
f49bd95
Update cmd_render.py
spenceau Aug 1, 2024
1a60c5e
Changes to Work on Ubuntu/Linux
spenceau Aug 1, 2024
599b879
Changes
spenceau Aug 2, 2024
2516279
slight fixes to error log pulling on Ubuntu
spenceau Aug 7, 2024
a3ecb2e
Update build.cmd
spenceau Aug 8, 2024
caa67be
Update run_blender_with_rpr.cmd
spenceau Aug 8, 2024
b93db61
Update run_blender_with_rpr.cmd
spenceau Aug 8, 2024
9fe7218
Update run_blender_with_rpr.cmd
spenceau Aug 8, 2024
82c41c2
Update run_blender_with_rpr.cmd
spenceau Aug 8, 2024
37c353d
rollback for non testscript stuff
spenceau Aug 9, 2024
043683b
delete src/.vs
spenceau Aug 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,14 @@ vscode/
/tmp

/src/rprblender/utils/athena.bin

# test_script
blender_files
ground_truth
cmd_tools/test_script/.env
cmd_tools/test_script/old
cmd_tools/test_script/Render_Output
cmd_tools/test_script/addon/modules/rprblender
*.vscode
src/.vs/
test_render.cmd
7 changes: 7 additions & 0 deletions cmd_tools/test_script/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[flake8]
ignore = E501, W293
exclude =
.git,
__pycache__,
build,
dist
6 changes: 6 additions & 0 deletions cmd_tools/test_script/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.blend

blender_files
ground_truth

RENDER_OUTPUT
28 changes: 28 additions & 0 deletions cmd_tools/test_script/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## .ENV Variables
SCENE_PATH={directory containing blend files to be tested}
GROUND_TRUTH={dir containing rendered image to compare to for MSE and SSIM (assumes the image is called {scene}_actual)}
VIEWPORT_FLAG={0 for no viewport rendering, 1 for viewport}

PLUGIN={name of the relative directory where the plugin will be unzipped to}
RENDER_OUTPUT_DIR={name fo the directory where the output and comparison txt will be put}

SCENE_NAME={name of scene}
BLENDER_PATH=C:\Program Files\Blender Foundation\Blender {VERSION}
ADDON_ZIP={where build artifact zip is located}


## Run Instructions
Set .env Variables

Run with `./run_render.cmd` on Windows
Run with `./run_render.sh` on Ubuntu/Linux

Renders the scene alongside a txt with MSE/SSIM at {RENDER_OUTPUT_DIR}/{ADDON_ZIP}/{BLENDER_PATH_VERSION}/{SCENE}_final.png

Assumes that the ground truth files to compare against are called {SCENE}_actual.png
Should have Python 3.11 installed from official Python Site

## Resources
[Python 3.11.9 Installation](https://www.python.org/downloads/release/python-3119/)


32 changes: 32 additions & 0 deletions cmd_tools/test_script/add_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os
import bpy
import sys


def print_script_directories():
script_dirs = bpy.context.preferences.filepaths.script_directories
for i, path in enumerate(script_dirs):
print(f"Script Path {i + 1}: {path}")

print(dir(bpy.context.preferences.filepaths.script_directories))
help(bpy.context.preferences.filepaths.script_directories)


def add_script_path(plugin_folder):
abs_plugin_folder = os.path.abspath(plugin_folder)

# add the script directory
bpy.ops.preferences.script_directory_add(directory=abs_plugin_folder)
print(f"Added script path: {abs_plugin_folder}")

# change name of the script directory entry
for script_dir in bpy.context.preferences.filepaths.script_directories:
if script_dir.directory == abs_plugin_folder:
script_dir.name = plugin_folder
break

bpy.ops.wm.save_userpref()


plugin_folder = sys.argv[4]
add_script_path(plugin_folder)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
152 changes: 152 additions & 0 deletions cmd_tools/test_script/cmd_render.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import importlib
# clear cache
importlib.invalidate_caches()

import os
import subprocess
import shutil
import sys
from dotenv import load_dotenv
import zipfile
import platform

# wrapper function to call bpy


def ensure_plugin_structure(plugin_folder):
required_dirs = ['addons', 'modules', 'startup']
for dir in required_dirs:
path = os.path.join(plugin_folder, dir)
if not os.path.exists(path):
os.makedirs(path)


# unzips addon into the target directory
# RPRNAS seems to have double zips
def extract_addon_to_module(target_dir):
# Extract the ZIP file to the target directory
with zipfile.ZipFile(addon, 'r') as zip_ref:
zip_ref.extractall(target_dir)

print(f"Addon extracted to {target_dir}")

# check for double zips as in the case of rprnas
for root, dirs, files in os.walk(target_dir):
for file in files:
if file.endswith('.zip'):
zip_path = os.path.join(root, file)
with zipfile.ZipFile(zip_path, 'r') as inner_zip_ref:
inner_zip_ref.extractall(target_dir)
print(f"Extracted inner ZIP: {zip_path}")
os.remove(zip_path) # delete zip


def remove_rprblender(target_dir, plugin_dir):
try:
addon = os.path.join(target_dir, "rprblender")
shutil.rmtree(addon, ignore_errors=True)
shutil.rmtree(plugin_dir, ignore_errors=True)
print(f"rprblender removed successfully from {target_dir}.")
except Exception as e:
print(f"Error removing rprblender: {e}")


def print_sys_path():
print("SYS.PATH FOR cmd_render.py")
for i, path in enumerate(sys.path):
print(f"{i}: {path}")


if __name__ == "__main__":

load_dotenv()

#sys.path.append("./rprblender")
script = sys.argv[1]
blender_path = os.getenv('BLENDER_PATH')
#print(f"BLENDER PATH: {blender_path}")
blender_version = blender_version = " ".join(os.path.basename(blender_path).split()[-2:])
#print(f"BLENDER VERSION: {blender_version}")
if platform.system() == 'Windows':
blender_exe = os.path.join(blender_path, "blender.exe")
python = 'python'
else:
# assumes platform is Ubuntu/Linux
blender_exe = os.path.join(blender_path, "blender")
python = 'python3.11'

addon = os.getenv('ADDON_ZIP')
blender_files = os.getenv('SCENE_PATH')
scene = os.getenv('SCENE_NAME')
build = os.path.basename(addon)

output_dir = os.path.join(os.getenv('RENDER_OUTPUT_DIR'), os.path.basename(addon), blender_version)
plugin_folder = os.getenv('PLUGIN')

ground_truth = os.getenv('GROUND_TRUTH')
viewport_flag = os.getenv('VIEWPORT_FLAG')

print(f"Scene name: {scene}")

# creates dir with 3 necessary subdir to extract build zip into
ensure_plugin_structure(plugin_folder)
target_dir = os.path.join(os.getcwd(), plugin_folder, "modules")

# extract zip file to blender's modules subdir in scripts
extract_addon_to_module(target_dir)

# run add_script.py to add the directory to Blender's scripts and then "restart" Blender

cwd = os.getcwd()
subprocess.run([
blender_exe,
'--background',
'--python', os.path.join(cwd, "add_script.py"),
plugin_folder
])

# Always run final_render.py
final_render_command = [
blender_exe,
'--background',
'--python', script,
blender_files,
scene,
output_dir,
]
subprocess.run(final_render_command)

# need to run remove_script.py since a failed render seems to kick out of final_render.py
cwd = os.getcwd()
subprocess.run([
blender_exe,
'--background',
'--python', os.path.join(cwd, "remove_script.py"),
plugin_folder,
output_dir,
scene
])

# Always run compare_render.py after final_render.py
compare_render_command = [
python, 'compare_render.py',
'--ground-truth-dir', ground_truth,
'--output-dir', output_dir,
'--scene-name', scene
]
subprocess.run(compare_render_command)

# Conditionally run viewport render
# TODO: this hasn't been changed to reflect pulling from zip; probably unnecessary as this isn't going to be used per Sho
viewport_render_command = [
blender_path,
'--python', 'viewport_render.py',
'--',
'--scene-path', blender_files,
'--scene-name', scene,
'--addon-zip', addon
]
if viewport_flag == 1:
subprocess.check_call(viewport_render_command)

remove_rprblender(target_dir, plugin_folder)
54 changes: 54 additions & 0 deletions cmd_tools/test_script/compare_render.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import os
import cv2
import numpy as np
import argparse
from skimage.metrics import structural_similarity as ssim


class ImageComparer:
def __init__(self, ground_truth_dir, output_dir, scene_name):
self.ground_truth_path = os.path.join(ground_truth_dir, f"{scene_name}_actual.png")
self.render_path = os.path.join(output_dir, f"{scene_name}_final.png")
self.scene_name = scene_name
self.output_dir = output_dir

def mse(self, imageA, imageB):
err = np.sum((imageA.astype("float") - imageB.astype("float")) ** 2)
err /= float(imageA.shape[0] * imageA.shape[1])
return err

def compare_images(self):
# Load the images
image1 = cv2.imread(self.ground_truth_path)
image2 = cv2.imread(self.render_path)

if image1 is None or image2 is None:
print("Error: One of the images could not be loaded.")
return

# Compare the images
mse_value = self.mse(image1, image2)
ssim_value = ssim(image1, image2, win_size=7, multichannel=True, channel_axis=2)

# Print the results
print(f"Scene: {self.scene_name}")
print(f"Mean Squared Error (MSE): {mse_value:.2f}")
print(f"Structural Similarity Index (SSIM): {ssim_value:.2f}")

# Write results to a text file
with open(f"{self.output_dir}/{self.scene_name}_comparison.txt", 'w') as txt_file:
txt_file.write(f"Scene: {self.scene_name}\n")
txt_file.write(f"Mean Squared Error (MSE): {mse_value:.2f}\n")
txt_file.write(f"Structural Similarity Index (SSIM): {ssim_value:.2f}\n")


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Compare rendered images with ground truth images.")
parser.add_argument('--ground-truth-dir', required=True, help='Directory of ground truth images')
parser.add_argument('--output-dir', required=True, help='Directory where the rendered images are saved')
parser.add_argument('--scene-name', required=True, help='Name of the scene to compare')

args = parser.parse_args()

comparer = ImageComparer(args.ground_truth_dir, args.output_dir, args.scene_name)
comparer.compare_images()
86 changes: 86 additions & 0 deletions cmd_tools/test_script/final_render.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import os
from pathlib import Path
import sys
import bpy
import shutil
import platform


def print_sys_path():
print("SYS.PATH FOR final_render.py")
for i, path in enumerate(sys.path):
print(f"{i}: {path}")


def create_output_dir(addon_name):
output_dir = os.path.abspath(addon_name)

if not os.path.exists(output_dir):
os.makedirs(output_dir)

return output_dir


def clear_crash_log(scene):
if platform.system() == 'Windows':
crash_log_path = os.path.join(os.getenv('LOCALAPPDATA'), 'Temp', f"{scene}.crash.txt")
if os.path.exists(crash_log_path):
os.remove(crash_log_path)
print(f"Cleared existing crash log: {crash_log_path}")
else:
print(f"{crash_log_path} does not exist")

# TODO: implement pulling from Ubuntu; need a render that will fail for sure to test?
# prob in var/log/


def render_final_image(blender_files, scene, output_dir):
clear_crash_log(scene)

# this try-catch seems to be unnecessary since copying the error log accomplishes the same thing
# plus it doesnt seem to "function" correctly since a failed render doesnt hit the catch
#try:
bpy.context.scene.render.engine = 'RPR'
temp_path = os.path.join(blender_files, scene + ".blend")
scene_path = os.path.abspath(temp_path)

bpy.ops.wm.open_mainfile(filepath=scene_path)
bpy.context.scene.rpr.final_render_mode = 'FULL2' # Set Render Mode to Final
bpy.context.scene.render.filepath = os.path.join(output_dir, scene + "_final.png")
bpy.ops.render.render(write_still=True)
print(f"{scene} rendered successfully at {output_dir}")
# except Exception as e:
# error_log_path = os.path.join(output_dir, f"{scene}_error_log.txt")
# with open(error_log_path, 'w') as error_log_file:
# error_log_file.write(str(e))
# print(f"Error when trying to render: {e}. Check {error_log_path} for details.")


def install_and_enable_addon():
# Set up the addon paths
src_path = str((Path(__file__).parent.parent.parent/'src').resolve())

#import sys
if src_path not in sys.path:
sys.path.append(src_path)

import rprblender
rprblender.register()


def main():

blender_files = sys.argv[4]
scene = sys.argv[5]
addon_name = sys.argv[6]

import rprblender
rprblender.register()

output_dir = create_output_dir(addon_name)
render_final_image(blender_files, scene, output_dir)


if __name__ == "__main__":

main()
Loading