Skip to content

Commit

Permalink
Merge branch 'next' into autodiff
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-Leo-Smith committed Dec 8, 2023
2 parents 5eb5795 + fb0bbfd commit 423a28a
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 49 deletions.
47 changes: 19 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ set(CMAKE_POLICY_DEFAULT_CMP0072 NEW)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

project(LuisaRender LANGUAGES C CXX VERSION 0.1)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_C_STANDARD_REQUIRED ON)
Expand All @@ -20,6 +18,8 @@ set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_CXX_EXTENSIONS OFF)
set(BUILD_SHARED_LIBS ON)

project(LuisaRender LANGUAGES C CXX VERSION 0.1)

if (NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
message(FATAL_ERROR "LuisaRender only supports 64-bit platforms")
endif ()
Expand All @@ -32,37 +32,28 @@ if (NOT DEFINED LUISA_RENDER_MASTER_PROJECT)
endif ()
endif ()

if (NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
option(LUISA_RENDER_ENABLE_SCCACHE "Enable sccache to speed up compilation" ON)
if (LUISA_RENDER_ENABLE_SCCACHE)
find_program(SCCACHE_EXE sccache)
if (SCCACHE_EXE)
message(STATUS "Build with sccache: ${SCCACHE_EXE}")
set(CMAKE_C_COMPILER_LAUNCHER ${SCCACHE_EXE})
set(CMAKE_CXX_COMPILER_LAUNCHER ${SCCACHE_EXE})
set(CMAKE_OBJC_COMPILER_LAUNCHER ${SCCACHE_EXE})
set(CMAKE_OBJCXX_COMPILER_LAUNCHER ${SCCACHE_EXE})
else ()
message(STATUS "Could not find sccache")
endif ()
endif ()
endif ()

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15.0)
add_compile_options(-Wno-deprecated-builtins)
endif ()

option(LUISA_RENDER_BUILD_TESTS "Build tests for LuisaRender" ${LUISA_RENDER_MASTER_PROJECT})
option(LUISA_RENDER_ENABLE_UNITY_BUILD "Enable unity build to speed up compilation" OFF)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
foreach (CONFIG ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${CONFIG} CONFIG_UPPER)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${CONFIG_UPPER} "${CMAKE_BINARY_DIR}/${CONFIG}/bin")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${CONFIG_UPPER} "${CMAKE_BINARY_DIR}/${CONFIG}/bin")
endforeach ()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")

get_cmake_property(LUISA_RENDERIS_MULTI_CONFIG GENERATOR_IS_MULTI_CONFIG)
if (LUISA_RENDERIS_MULTI_CONFIG)
foreach (config ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${config} CONFIG_UPPER)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${CONFIG_UPPER} "${CMAKE_BINARY_DIR}/bin/${config}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${CONFIG_UPPER} "${CMAKE_BINARY_DIR}/bin/${config}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${CONFIG_UPPER} "${CMAKE_BINARY_DIR}/lib/${config}")
set(CMAKE_PDB_OUTPUT_DIRECTORY_${CONFIG_UPPER} "${CMAKE_BINARY_DIR}/lib/${config}")
endforeach ()
else ()
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif ()
endif ()

set(CMAKE_FIND_PACKAGE_SORT_ORDER NATURAL)
set(CMAKE_FIND_PACKAGE_SORT_DIRECTION DEC)
Expand Down
6 changes: 6 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ if (WIN32)
endif ()
endif ()

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15.0)
add_compile_options(-Wno-deprecated-builtins)
endif ()

add_subdirectory(ext)

add_library(luisa-render-include INTERFACE)
Expand All @@ -23,6 +28,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
/Zc:preprocessor)
endif ()

set(LUISA_COMPUTE_ENABLE_LTO OFF CACHE BOOL "" FORCE)
set(LUISA_COMPUTE_ENABLE_PYTHON OFF CACHE BOOL "" FORCE)
set(LUISA_COMPUTE_ENABLE_UNITY_BUILD ${LUISA_RENDER_ENABLE_UNITY_BUILD} CACHE BOOL "" FORCE)
add_subdirectory(compute)
Expand Down
2 changes: 1 addition & 1 deletion src/compute
Submodule compute updated 427 files
2 changes: 1 addition & 1 deletion src/util/imageio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <tinyexr.h>
#include <stb/stb_image.h>
#include <stb/stb_image_write.h>
#include <stb/stb_image_resize.h>
#include <stb/stb_image_resize2.h>

#include <core/logging.h>
#include <util/imageio.h>
Expand Down
75 changes: 56 additions & 19 deletions tools/tungsten2luisa.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,11 @@ def convert_material(out_file, material: dict, alpha=""):
convert_material(out_file, base_material, aa)
elif impl == "null":
convert_null_material(out_file, material)
elif impl == "thinsheet":
# TODO: Implement thinsheet, here we just use glass
convert_glass_material(out_file, material)
else:
print(material)
print(f'Unsupported material {material}')
print(f'''
Surface mat_{material["name"]} : Matte {{
Kd : Constant {{
Expand All @@ -196,19 +199,42 @@ def convert_materials(out_file, materials):


def rotateXYZ(R):
return glm.rotate(R.z, (0, 0, 1)) * glm.rotate(R.y, (0, 1, 0)) * glm.rotate(R.x, (1, 0, 0))
c = glm.cos(R)
s = glm.sin(R)
return glm.transpose(glm.mat3(
c[1] * c[2], -c[0] * s[2] + s[0] * s[1] * c[2], s[0] * s[2] + c[0] * s[1] * c[2],
c[1] * s[2], c[0] * c[2] + s[0] * s[1] * s[2], -s[0] * c[2] + c[0] * s[1] * s[2],
-s[1], s[0] * c[1], c[0] * c[1]))


def rotateYXZ(R):
return glm.rotate(R.y, (0, 1, 0)) * glm.rotate(R.x, (1, 0, 0)) * glm.rotate(R.z, (0, 0, 1))
c = glm.cos(R)
s = glm.sin(R)
return glm.transpose(glm.mat3(
c[1] * c[2] - s[1] * s[0] * s[2], -c[1] * s[2] - s[1] * s[0] * c[2], -s[1] * c[0],
c[0] * s[2], c[0] * c[2], -s[0],
s[1] * c[2] + c[1] * s[0] * s[2], -s[1] * s[2] + c[1] * s[0] * c[2], c[1] * c[0]))


def convert_transform(S, R, T):
return glm.translate(T) * rotateYXZ(R) * glm.scale(S)
x = glm.vec3(1, 0, 0)
y = glm.vec3(0, 1, 0)
z = glm.vec3(0, 0, 1)
x = S.x * x
y = S.y * y
z = S.z * z
R = rotateYXZ(glm.vec3(R.x, R.y, R.z))
x = R * x
y = R * y
z = R * z
return glm.mat4(glm.vec4(x, 0),
glm.vec4(y, 0),
glm.vec4(z, 0),
glm.vec4(T, 1))


def convert_shape(out_file, index, shape: dict, materials: dict):
#Caution: Tungsten load from rotYXZ
# Caution: Tungsten load from rotYXZ
transform = shape["transform"]
T = glm.vec3(transform.get("position", 0))
R = glm.radians(glm.vec3(transform.get("rotation", 0)))
Expand Down Expand Up @@ -261,37 +287,48 @@ def convert_shape(out_file, index, shape: dict, materials: dict):
print(f"Warning: Skydome is not supported: {shape}")
else:
power_scale = 100 * glm.pi()
impl_name = "Mesh"
alpha = ""
if impl == "mesh":
file = shape["file"]
assert file.endswith(".wo3")
file = f"{file[:-4]}.obj"
prop = f'file {{ "{file[:-4]}.obj" }}'
elif impl == "quad":
file = "models/square.obj"
M = M * rotateXYZ(glm.radians(glm.vec3(-90, 0, 0))
) * glm.scale(glm.vec3(.5))
power_scale=S[0]*S[2]*glm.pi()
impl_name = "InlineMesh"
prop = f"""positions {{ 1, 1, 0, -1, 1, 0, -1, -1, 0, 1, -1, 0 }}
indices {{ 0, 1, 2, 0, 2, 3 }}"""
# file = "models/square.obj"
# M = M * rotateXYZ(glm.radians(glm.vec3(-90, 0, 0))
# ) * glm.scale(glm.vec3(.5))
power_scale = S[0] * S[2] * glm.pi()
M = M * glm.mat4(rotateXYZ(glm.vec3(glm.radians(-90), 0, 0))) * glm.scale(glm.vec3(.5))
elif impl == "cube":
file = "models/cube.obj"
prop = 'file { "models/cube.obj" }'
M = M * rotateXYZ(glm.radians(glm.vec3(-90, 0, 0))) * glm.scale(glm.vec3(.5))
elif impl == "disk":
file = "models/disk.obj"
prop = 'file { "models/disk.obj" }'
elif impl == "sphere":
file = "models/sphere.obj"
prop = 'file { "models/sphere.obj" }'
elif impl == "curves":
return
assert False
else:
print(f"Unsupported shape: {shape}")
raise NotImplementedError()
material = shape["bsdf"]
if not isinstance(material, str):
material = "Null"
material = dict(material)
if material["type"] == "null":
material = "Null"
else:
material["name"] = f"shape_{index}"
convert_material(out_file, material)
material = material["name"]
print(material)
M0 = ", ".join(str(x) for x in glm.transpose(M)[0])
M1 = ", ".join(str(x) for x in glm.transpose(M)[1])
M2 = ", ".join(str(x) for x in glm.transpose(M)[2])
M3 = ", ".join(str(x) for x in glm.transpose(M)[3])

emission = glm.vec3(shape.get("emission", glm.vec3(
shape.get("power", 0)) / power_scale))
if emission.x == emission.y == emission.z == 0:
Expand All @@ -304,8 +341,8 @@ def convert_shape(out_file, index, shape: dict, materials: dict):
}}
}}'''
print(f'''
Shape shape_{index} : Mesh {{
file {{ "{file}" }}
Shape shape_{index} : {impl_name} {{
{prop}
surface {{ @mat_{material} }}{light}{alpha}
transform : Matrix {{
m {{
Expand All @@ -327,7 +364,7 @@ def convert_camera(out_file, camera: dict, spp):
resolution = glm.vec2(camera["resolution"])
fov = glm.radians(camera["fov"])
fov = glm.degrees(2 * glm.atan(resolution.y *
glm.tan(0.5 * fov) / resolution.x))
glm.tan(0.5 * fov) / resolution.x))
transform = camera["transform"]
position = glm.vec3(transform["position"])
look_at = glm.vec3(transform["look_at"])
Expand Down

0 comments on commit 423a28a

Please sign in to comment.