├── .clang-format ├── .gitattributes ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Krakatoa ├── CMakeLists.txt ├── build.py ├── conanfile.py ├── krakatoa │ ├── atmosphere_impl.hpp │ ├── atmosphere_interface.hpp │ ├── birth_channel_gen.hpp │ ├── camera_manager.hpp │ ├── channel_render_element.hpp │ ├── collection_interface.hpp │ ├── diffuse_render_element.hpp │ ├── emission_render_element.hpp │ ├── fumefx │ │ └── fumefx_ext_interface.hpp │ ├── geometry_renderer.hpp │ ├── light_object.hpp │ ├── light_render_element.hpp │ ├── lighting_data.hpp │ ├── magma_render_element.hpp │ ├── matte_zdepth_render_element.hpp │ ├── mblur_data.hpp │ ├── min_color6f.hpp │ ├── normal_render_element.hpp │ ├── occluded_layer_render_element.hpp │ ├── openvdb_overloads.hpp │ ├── particle_render_element_interface.hpp │ ├── particle_repopulation.hpp │ ├── particle_volume.hpp │ ├── prt_maker.hpp │ ├── prt_stream_builder.hpp │ ├── raytrace_renderer │ │ ├── openvdb_renderer.hpp │ │ └── raytrace_renderer.hpp │ ├── render_element.hpp │ ├── render_element_impl.hpp │ ├── render_element_interface.hpp │ ├── renderer.hpp │ ├── scene_context.hpp │ ├── shader_functions.hpp │ ├── shader_render_element.hpp │ ├── shaders.hpp │ ├── shared_object.hpp │ ├── specular_render_element.hpp │ ├── splat_renderer │ │ ├── default_light_traits.hpp │ │ ├── filter2f.hpp │ │ ├── omni_light_traits.hpp │ │ ├── parallel_progress.hpp │ │ ├── splat_lighting.hpp │ │ └── splat_renderer.hpp │ ├── sticky_channel_particle_istream.hpp │ ├── tangent_render_element.hpp │ ├── threading_functions.hpp │ ├── triangle_rasterizer.hpp │ ├── velocity_render_element.hpp │ ├── voxel_renderer │ │ ├── data_source.hpp │ │ ├── default_filter2f.hpp │ │ ├── default_filter3f.hpp │ │ ├── default_radial_filter3f.hpp │ │ ├── filter2f.hpp │ │ ├── filter3f.hpp │ │ ├── image_wrapper.hpp │ │ ├── particle_data_source.hpp │ │ ├── sample.hpp │ │ ├── slice_container.hpp │ │ ├── slice_container_impl.hpp │ │ ├── slice_coordsys.hpp │ │ ├── slice_coordsys_impl.hpp │ │ └── voxel_renderer.hpp │ ├── watermark.hpp │ └── zdepth_render_element.hpp ├── src │ ├── birth_channel_gen.cpp │ ├── camera_manager.cpp │ ├── channel_render_element.cpp │ ├── diffuse_render_element.cpp │ ├── emission_render_element.cpp │ ├── geometry_renderer.cpp │ ├── light_object.cpp │ ├── light_render_element.cpp │ ├── magma_render_element.cpp │ ├── matte_zdepth_render_element.cpp │ ├── normal_render_element.cpp │ ├── occluded_layer_render_element.cpp │ ├── particle_repopulation.cpp │ ├── particle_volume.cpp │ ├── prt_stream_builder.cpp │ ├── raytrace_renderer │ │ ├── openvdb_renderer.cpp │ │ └── raytrace_renderer.cpp │ ├── renderer.cpp │ ├── shader_functions.cpp │ ├── shader_render_element .cpp │ ├── shared_object.cpp │ ├── specular_render_element.cpp │ ├── splat_renderer │ │ ├── filter2f.cpp │ │ ├── splat_cube_renderer.cpp │ │ ├── splat_lighting.cpp │ │ └── splat_renderer.cpp │ ├── sticky_channel_particle_istream.cpp │ ├── tangent_render_element.cpp │ ├── threading_functions.cpp │ ├── velocity_render_element.cpp │ ├── voxel_renderer │ │ ├── default_filter2f.cpp │ │ ├── default_filter3f.cpp │ │ ├── default_radial_filter3f.cpp │ │ ├── particle_data_source.cpp │ │ ├── slice_container_impl.cpp │ │ ├── slice_coordsys_impl.cpp │ │ └── voxel_renderer.cpp │ ├── watermark.cpp │ └── zdepth_render_element.cpp ├── stdafx.cpp └── stdafx.h ├── KrakatoaSR ├── CMakeLists.txt ├── Example │ ├── CMakeLists.txt │ ├── example01.cpp │ ├── example02.cpp │ ├── example03.cpp │ ├── example04.cpp │ ├── example05.cpp │ ├── example06.cpp │ ├── example07.cpp │ ├── example08.cpp │ ├── example09.cpp │ ├── example10.cpp │ ├── example11.cpp │ ├── example12.cpp │ ├── example13.cpp │ ├── example14.cpp │ ├── example15.cpp │ ├── example16.cpp │ ├── example17.cpp │ ├── example18.cpp │ └── example19.cpp ├── KrakatoaSR.exp ├── KrakatoaSR.map ├── build.py ├── conanfile.py ├── include │ ├── doxygen │ │ ├── Doxyfile │ │ ├── documentation.html │ │ └── title_image.png │ ├── krakatoasr_datatypes.hpp │ ├── krakatoasr_light.hpp │ ├── krakatoasr_mesh.hpp │ ├── krakatoasr_particles.hpp │ ├── krakatoasr_progress.hpp │ ├── krakatoasr_render_saving.hpp │ ├── krakatoasr_renderer.hpp │ ├── krakatoasr_renderer │ │ ├── image_writer.hpp │ │ ├── params.hpp │ │ ├── progress_logger.hpp │ │ └── renderer.hpp │ ├── krakatoasr_shader.hpp │ ├── krakatoasr_transformation.hpp │ └── mainpage.dox ├── src │ ├── cstandardout.cpp │ ├── dllmain.cpp │ ├── krakatoasr_light.cpp │ ├── krakatoasr_mesh.cpp │ ├── krakatoasr_particles.cpp │ ├── krakatoasr_progress.cpp │ ├── krakatoasr_render_saving.cpp │ ├── krakatoasr_renderer.cpp │ ├── krakatoasr_renderer │ │ ├── image_writer.cpp │ │ ├── params.cpp │ │ └── renderer.cpp │ ├── krakatoasr_shader.cpp │ └── krakatoasr_transformation.cpp ├── stdafx.cpp └── stdafx.h ├── LICENSE.txt ├── NOTICE.txt └── README.md /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: LLVM 2 | Standard: c++17 3 | UseTab: Never 4 | ColumnLimit: 120 5 | IndentWidth: 4 6 | BreakBeforeBraces: Attach 7 | NamespaceIndentation: None 8 | AlwaysBreakTemplateDeclarations: true 9 | SpacesInParentheses: true 10 | SpaceBeforeParens: Never 11 | BreakConstructorInitializersBeforeComma: true 12 | PointerAlignment: Left 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Krakatoa/build 2 | KrakatoaSR/build 3 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 4 | opensource-codeofconduct@amazon.com with any additional questions or comments. 5 | -------------------------------------------------------------------------------- /Krakatoa/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | # SPDX-License-Identifier: Apache-2.0 3 | cmake_minimum_required( VERSION 3.15 FATAL_ERROR ) 4 | 5 | project( Krakatoa ) 6 | 7 | find_package( thinkboxcmlibrary REQUIRED ) 8 | include( PrecompiledHeader ) 9 | include( ThinkboxCMLibrary ) 10 | 11 | add_library( krakatoa STATIC ) 12 | 13 | set_property( TARGET krakatoa PROPERTY CXX_STANDARD 17 ) 14 | 15 | target_include_directories( krakatoa PUBLIC 16 | $ 17 | $ 18 | ) 19 | 20 | file( GLOB_RECURSE H_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 21 | "krakatoa/*.h" 22 | "krakatoa/*.hpp" 23 | ) 24 | 25 | file( GLOB_RECURSE CXX_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 26 | "src/*.cpp" 27 | ) 28 | 29 | target_sources( krakatoa PRIVATE 30 | stdafx.cpp 31 | stdafx.h 32 | ${H_FILES} 33 | ${CXX_FILES} 34 | ) 35 | 36 | # The Conan version of Boost was built with this, and it changes the library names. 37 | # As a result, we need to set this to tell Boost to look for the right libraries to 38 | # link against. 39 | target_compile_definitions( krakatoa PUBLIC BOOST_AUTO_LINK_SYSTEM ) 40 | 41 | set_target_properties( krakatoa PROPERTIES PROJECT_LABEL "Krakatoa" ) 42 | 43 | find_package( thinkboxlibrary REQUIRED ) 44 | find_package( Boost REQUIRED ) 45 | find_package( OpenEXR REQUIRED ) 46 | find_package( tinyxml2 REQUIRED ) 47 | find_package( ZLIB REQUIRED ) 48 | find_package( TBB REQUIRED ) 49 | 50 | target_include_directories( krakatoa PUBLIC ${thinkboxlibrary_INCLUDE_DIRS} ) 51 | target_include_directories( krakatoa PUBLIC ${Boost_INCLUDE_DIRS} ) 52 | target_include_directories( krakatoa PUBLIC ${OpenEXR_INCLUDE_DIRS} ) 53 | target_include_directories( krakatoa PUBLIC ${tinyxml2_INCLUDE_DIRS} ) 54 | target_include_directories( krakatoa PUBLIC ${ZLIB_INCLUDE_DIRS} ) 55 | target_include_directories( krakatoa PUBLIC ${TBB_INCLUDE_DIRS} ) 56 | 57 | target_link_libraries( krakatoa INTERFACE thinkboxlibrary::thinkboxlibrary ) 58 | target_link_libraries( krakatoa INTERFACE Boost::Boost ) 59 | target_link_libraries( krakatoa INTERFACE OpenEXR::OpenEXR ) 60 | target_link_libraries( krakatoa INTERFACE tinyxml2::tinyxml2 ) 61 | target_link_libraries( krakatoa INTERFACE ZLIB::ZLIB ) 62 | target_link_libraries( krakatoa INTERFACE TBB::tbb ) 63 | 64 | frantic_default_source_groups( krakatoa HEADERDIR krakatoa SOURCEDIR src ) 65 | frantic_common_platform_setup( krakatoa ) 66 | 67 | add_precompiled_header( krakatoa stdafx.h SOURCE_CXX stdafx.cpp ) 68 | 69 | # Disable optimization for the RelWithDebInfo configuration on Windows. 70 | # This allows breakpoints to be hit reliably when debugging in Visual Studio. 71 | if( WIN32 ) 72 | target_compile_options( krakatoa PRIVATE "$<$:/O2>$<$:/Od>" ) 73 | endif() 74 | 75 | install( DIRECTORY krakatoa 76 | DESTINATION include 77 | FILES_MATCHING PATTERN "*.hpp" 78 | ) 79 | install( TARGETS krakatoa 80 | RUNTIME DESTINATION bin 81 | LIBRARY DESTINATION lib 82 | ARCHIVE DESTINATION lib 83 | ) 84 | -------------------------------------------------------------------------------- /Krakatoa/build.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | # SPDX-License-Identifier: Apache-2.0 3 | from __future__ import annotations 4 | from typing import Any 5 | from cpt.packager import ConanMultiPackager 6 | 7 | import argparse 8 | import platform 9 | import pprint 10 | 11 | 12 | COMMON_PACKAGER_ARGS: dict[str, Any] = { 13 | 'build_types': ['Release'], 14 | 'archs': ['x86_64'], 15 | 'build_policy': 'missing' 16 | } 17 | 18 | WINDOWS_PACKAGER_ARGS: dict[str, Any] = { 19 | 'visual_versions': ['15', '16'], 20 | 'visual_runtimes': ['MD'] 21 | } 22 | 23 | LINUX_PACKAGER_ARGS: dict[str, Any] = { 24 | 'gcc_versions': ['7'] 25 | } 26 | 27 | MACOS_PACKAGER_ARGS: dict[str, Any] = { 28 | 'apple_clang_versions': ['10'] 29 | } 30 | 31 | 32 | def parse_arguments() -> argparse.Namespace: 33 | parser = argparse.ArgumentParser() 34 | parser.add_argument('-u', '--username', default=None, help='The Conan username to use for the built package.') 35 | parser.add_argument('-c', '--channel', default=None, help='The Conan channel to use for the built package.') 36 | parser.add_argument('-o', '--option', action='append', dest='options', help='Specify package options to be used by the build.') 37 | parser.add_argument('--dry-run', action='store_true', help='Print the configurations that would be built without actually building them.') 38 | return parser.parse_args() 39 | 40 | def main() -> None: 41 | args = parse_arguments() 42 | 43 | packager_args = { 44 | 'username': args.username, 45 | 'channel': args.channel, 46 | 'options': args.options 47 | } 48 | packager_args.update(COMMON_PACKAGER_ARGS) 49 | 50 | if platform.system() == 'Windows': 51 | packager_args.update(WINDOWS_PACKAGER_ARGS) 52 | elif platform.system() == 'Linux': 53 | packager_args.update(LINUX_PACKAGER_ARGS) 54 | elif platform.system() == 'Darwin': 55 | packager_args.update(MACOS_PACKAGER_ARGS) 56 | else: 57 | raise Exception('Platform not supported.') 58 | 59 | builder = ConanMultiPackager(**packager_args) 60 | builder.add_common_builds(pure_c=False) 61 | 62 | # Remove the legacy libstdc++ build. 63 | if platform.system() == 'Linux': 64 | builder.remove_build_if(lambda build: build.settings['compiler.libcxx'] == 'libstdc++') 65 | 66 | if args.dry_run: 67 | pprint.pprint(builder.builds, indent=4) 68 | else: 69 | builder.run() 70 | 71 | 72 | if __name__ == '__main__': 73 | main() 74 | -------------------------------------------------------------------------------- /Krakatoa/conanfile.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | # SPDX-License-Identifier: Apache-2.0 3 | import os 4 | from conans import ConanFile, CMake 5 | 6 | SETTINGS: list[str] = [ 7 | 'os', 8 | 'compiler', 9 | 'build_type', 10 | 'arch' 11 | ] 12 | 13 | TOOL_REQUIRES: list[str] = [ 14 | 'cmake/3.24.1', 15 | 'thinkboxcmlibrary/1.0.0' 16 | ] 17 | 18 | REQUIRES: list[str] = [ 19 | 'thinkboxlibrary/1.0.0', 20 | 'tinyxml2/9.0.0' 21 | ] 22 | 23 | class KrakatoaConan(ConanFile): 24 | name: str = 'krakatoa' 25 | version: str = '1.0.0' 26 | license: str = 'Apache-2.0' 27 | description: str = 'The Krakatoa renderer code.' 28 | settings: list[str] = SETTINGS 29 | tool_requires: list[str] = TOOL_REQUIRES 30 | requires: list[str] = REQUIRES 31 | generators: str | list[str] = 'cmake_find_package' 32 | 33 | def build(self) -> None: 34 | cmake = CMake(self) 35 | cmake.configure() 36 | cmake.build() 37 | 38 | def export_sources(self) -> None: 39 | self.copy('**.h', src='', dst='') 40 | self.copy('**.hpp', src='', dst='') 41 | self.copy('**.cpp', src='', dst='') 42 | self.copy('CMakeLists.txt', src='', dst='') 43 | self.copy('../NOTICE.txt', src='', dst='') 44 | self.copy('../LICENSE.txt', src='', dst='') 45 | 46 | def package(self) -> None: 47 | cmake = CMake(self) 48 | cmake.install() 49 | 50 | with open(os.path.join(self.source_folder, 'NOTICE.txt'), 'r', encoding='utf8') as notice_file: 51 | notice_contents = notice_file.readlines() 52 | with open(os.path.join(self.source_folder, 'LICENSE.txt'), 'r', encoding='utf8') as license_file: 53 | license_contents = license_file.readlines() 54 | os.makedirs(os.path.join(self.package_folder, 'licenses'), exist_ok=True) 55 | with open(os.path.join(self.package_folder, 'licenses', 'LICENSE'), 'w', encoding='utf8') as cat_license_file: 56 | cat_license_file.writelines(notice_contents) 57 | cat_license_file.writelines(license_contents) 58 | 59 | def deploy(self) -> None: 60 | self.copy("*", dst="lib", src="lib") 61 | self.copy("*", dst="include", src="include") 62 | 63 | def package_info(self) -> None: 64 | self.cpp_info.libs = ["krakatoa"] 65 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/atmosphere_impl.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | 9 | namespace krakatoa { 10 | 11 | class atmosphere_impl : public atmosphere_interface { 12 | typedef frantic::geometry::volume_collection volume_type; 13 | typedef boost::shared_ptr volume_ptr; 14 | 15 | frantic::graphics::color3f m_extinction; 16 | volume_ptr m_volume; 17 | 18 | public: 19 | inline atmosphere_impl(); 20 | 21 | inline virtual ~atmosphere_impl(); 22 | 23 | inline void set_volume( volume_ptr pVol ); 24 | 25 | inline void set_extinction( const frantic::graphics::color3f& extinction ); 26 | 27 | inline virtual void apply_atomsphere( frantic::graphics::color3f& inoutLight, 28 | const frantic::graphics::vector3f& from, 29 | const frantic::graphics::vector3f& to ) const; 30 | }; 31 | 32 | atmosphere_impl::atmosphere_impl() {} 33 | 34 | atmosphere_impl::~atmosphere_impl() {} 35 | 36 | void atmosphere_impl::set_volume( volume_ptr pVol ) { m_volume = pVol; } 37 | 38 | void atmosphere_impl::set_extinction( const frantic::graphics::color3f& extinction ) { m_extinction = extinction; } 39 | 40 | void atmosphere_impl::apply_atomsphere( frantic::graphics::color3f& inoutLight, const frantic::graphics::vector3f& from, 41 | const frantic::graphics::vector3f& to ) const { 42 | float distance; 43 | if( !m_volume ) { 44 | distance = frantic::graphics::vector3f::distance( from, to ); 45 | } else { 46 | distance = m_volume->get_segment_distance_in_volume( from, to ); 47 | } 48 | 49 | inoutLight.r *= std::exp( -( distance * m_extinction.r ) ); 50 | inoutLight.g *= std::exp( -( distance * m_extinction.g ) ); 51 | inoutLight.b *= std::exp( -( distance * m_extinction.b ) ); 52 | } 53 | 54 | } // namespace krakatoa 55 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/atmosphere_interface.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | namespace krakatoa { 9 | 10 | /** 11 | * Interface for applying some sort of particpating media (also known as an atmosphere). Typically used for fog, or an 12 | * underwater effect. 13 | */ 14 | class atmosphere_interface { 15 | public: 16 | typedef boost::shared_ptr ptr_type; 17 | 18 | public: 19 | virtual ~atmosphere_interface() {} 20 | 21 | /** 22 | * Applies the effects of the atmosphere along the line segment from 'from' to 'to' to 'inoutLight'. 23 | * @param inoutLight Before the call, this is the amount of light reaching 'to' from 'from'. Afterwards it is 24 | * affected by the atmosphere. 25 | * @param from The point where the light is originating. 26 | * @param to The point where the light is being evaluated. 27 | */ 28 | virtual void apply_atomsphere( frantic::graphics::color3f& inoutLight, const frantic::graphics::vector3f& from, 29 | const frantic::graphics::vector3f& to ) const = 0; 30 | }; 31 | 32 | typedef atmosphere_interface::ptr_type atmosphere_interface_ptr; 33 | 34 | } // namespace krakatoa 35 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/birth_channel_gen.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | namespace birth_channel_gen { 14 | namespace scope_answer { 15 | enum scope_answer { ask, yes, no, yes_all, no_all }; 16 | } 17 | 18 | struct options { 19 | frantic::tstring m_inSequence; 20 | frantic::tstring m_outSequence; 21 | frantic::tstring m_inChannel; 22 | frantic::tstring m_outChannel; 23 | frantic::tstring m_idChannel; 24 | double m_startFrame; 25 | bool m_ignoreError; 26 | scope_answer::scope_answer m_overwriteChannel; 27 | scope_answer::scope_answer m_overwriteFile; 28 | 29 | options() 30 | : m_inChannel( _T( "Position" ) ) 31 | , m_outChannel( _T( "BirthPosition" ) ) 32 | , m_idChannel( _T( "ID" ) ) 33 | , m_startFrame( 0.0 ) 34 | , m_ignoreError( false ) 35 | , m_overwriteChannel( scope_answer::ask ) 36 | , m_overwriteFile( scope_answer::ask ) {} 37 | }; 38 | 39 | class gen_exception : public std::runtime_error { 40 | public: 41 | gen_exception( const frantic::tstring& msg ) 42 | : std::runtime_error( frantic::strings::to_string( msg ) ) {} 43 | }; 44 | 45 | void generate_sticky_channels( const birth_channel_gen::options& opts ); 46 | 47 | namespace detail { 48 | void generate_sticky_channels_frame( const birth_channel_gen::options& opts, double currentFrame, 49 | const frantic::files::filename_sequence& inputFileSequence, 50 | const frantic::files::filename_sequence& outputFileSequence, 51 | std::map>& birthValues, 52 | scope_answer::scope_answer& overwriteChannels, 53 | scope_answer::scope_answer& overwriteFiles ); 54 | 55 | scope_answer::scope_answer yes_no_all( const frantic::tstring& question ); 56 | 57 | void handle_error( const birth_channel_gen::options& opts, const frantic::tstring& error ); 58 | } // namespace detail 59 | } // namespace birth_channel_gen -------------------------------------------------------------------------------- /Krakatoa/krakatoa/camera_manager.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | 9 | namespace krakatoa { 10 | 11 | class camera_manager { 12 | public: 13 | typedef boost::shared_ptr ptr_type; 14 | 15 | private: 16 | std::vector> m_cameras; 17 | 18 | public: 19 | camera_manager(); 20 | camera_manager( const frantic::graphics::camera& camera ); 21 | camera_manager( const std::vector>& cameraList ); 22 | 23 | frantic::graphics::camera& get_current_camera(); 24 | const frantic::graphics::camera& get_current_camera() const; 25 | }; 26 | 27 | typedef camera_manager::ptr_type camera_manager_ptr; 28 | 29 | } // namespace krakatoa 30 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/channel_render_element.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | namespace krakatoa { 9 | 10 | class channel_render_element : public render_element { 11 | frantic::tstring m_channelName; 12 | frantic::channels::data_type_t m_type; 13 | std::size_t m_arity; 14 | bool m_antiAlias; 15 | frantic::channels::channel_const_cvt_accessor m_accessor; 16 | frantic::graphics::color3f m_default; 17 | frantic::channels::channel_map m_outputMap; 18 | 19 | public: 20 | channel_render_element( bool antiAlias, const frantic::tstring& m_channelName, frantic::channels::data_type_t type, 21 | std::size_t arity, const frantic::graphics::color3f& def ); 22 | 23 | virtual ~channel_render_element(); 24 | 25 | virtual render_element_interface* clone(); 26 | 27 | virtual draw_type get_drawing_type() const; 28 | 29 | virtual void set_channel_map( const frantic::channels::channel_map& pcm ); 30 | 31 | virtual void add_required_channels( frantic::channels::channel_map& pcm ); 32 | 33 | virtual frantic::graphics::color3f evaluate( const char* particle ); 34 | }; 35 | } // namespace krakatoa -------------------------------------------------------------------------------- /Krakatoa/krakatoa/collection_interface.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace krakatoa { 8 | 9 | namespace detail { 10 | template 11 | class collection_interface_traits { 12 | public: 13 | typedef T& return_type; 14 | typedef const T& const_return_type; 15 | }; 16 | } // namespace detail 17 | 18 | template > 19 | class collection_interface { 20 | protected: 21 | typedef Traits traits_type; 22 | 23 | public: 24 | typedef typename traits_type::return_type return_type; 25 | typedef typename traits_type::const_return_type const_return_type; 26 | 27 | public: 28 | virtual ~collection_interface() {} 29 | 30 | virtual std::size_t size() const = 0; 31 | 32 | virtual return_type get( int index ) = 0; 33 | 34 | virtual const_return_type get( int index ) const = 0; 35 | }; 36 | 37 | template class Container, class Allocator = std::allocator> 38 | class collection_wrapper : public Container, public collection_interface { 39 | public: 40 | virtual ~collection_wrapper() {} 41 | 42 | virtual std::size_t size() const { return static_cast*>( this )->size(); } 43 | 44 | virtual typename collection_interface::return_type get( int index ) { 45 | return ( *static_cast*>( this ) )[index]; 46 | } 47 | 48 | virtual typename collection_interface::const_return_type get( int index ) const { 49 | return ( *static_cast*>( this ) )[index]; 50 | } 51 | }; 52 | 53 | } // namespace krakatoa 54 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/diffuse_render_element.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace krakatoa { 11 | 12 | class diffuse_render_element : public render_element { 13 | frantic::channels::channel_const_cvt_accessor m_accessor; 14 | 15 | public: 16 | diffuse_render_element(); 17 | virtual ~diffuse_render_element(); 18 | 19 | /** 20 | * see render_element_interface::clone() 21 | */ 22 | virtual render_element_interface* clone(); 23 | 24 | /** 25 | * see particle_render_element_interface::get_drawing_type() 26 | */ 27 | virtual draw_type get_drawing_type() const; 28 | 29 | /** 30 | * see particle_render_element_interface::set_channel_map() 31 | */ 32 | virtual void set_channel_map( const frantic::channels::channel_map& pcm ); 33 | 34 | /** 35 | * see particle_render_element_interface::add_required_channels() 36 | */ 37 | virtual void add_required_channels( frantic::channels::channel_map& pcm ); 38 | 39 | /** 40 | * see particle_render_element_interface::evaluate() 41 | */ 42 | virtual frantic::graphics::color3f evaluate( const char* particle ); 43 | }; 44 | 45 | } // namespace krakatoa 46 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/emission_render_element.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace krakatoa { 11 | 12 | class emission_render_element : public render_element { 13 | frantic::channels::channel_const_cvt_accessor m_accessor; 14 | 15 | public: 16 | emission_render_element(); 17 | virtual ~emission_render_element(); 18 | 19 | /** 20 | * see render_element_interface::clone() 21 | */ 22 | virtual render_element_interface* clone(); 23 | 24 | /** 25 | * see particle_render_element_interface::get_drawing_type() 26 | */ 27 | virtual draw_type get_drawing_type() const; 28 | 29 | /** 30 | * see particle_render_element_interface::set_channel_map() 31 | */ 32 | virtual void set_channel_map( const frantic::channels::channel_map& pcm ); 33 | 34 | /** 35 | * see particle_render_element_interface::add_required_channels() 36 | */ 37 | virtual void add_required_channels( frantic::channels::channel_map& pcm ); 38 | 39 | /** 40 | * see particle_render_element_interface::evaluate() 41 | */ 42 | virtual frantic::graphics::color3f evaluate( const char* particle ); 43 | }; 44 | 45 | } // namespace krakatoa 46 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/fumefx/fumefx_ext_interface.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace krakatoa { 10 | namespace fumefx { 11 | 12 | /** 13 | * This abstract interface is used to communicate with Krakatoa's FumeFX extension DLLs. 14 | * 15 | * @note This interface must never be changed! It can only be extended via subclassing. If you need to add 16 | * entirely new functionality, you must try and dynamic_cast this object to the more featured subclass. 17 | */ 18 | class fumefx_ext_interface { 19 | protected: 20 | virtual ~fumefx_ext_interface() {} 21 | 22 | public: 23 | /** 24 | * This function must be called when you are finished using this object. You do not directly call delete on this 25 | * object. 26 | */ 27 | virtual void release() = 0; 28 | 29 | /** 30 | * Returns the version number of FumeFX that this was expect to work for. 31 | */ 32 | // virtual __int64 get_fumefx_version() = 0; 33 | 34 | /** 35 | * Returns the value of PARTICLE_ISTREAM_INTERFACE_VERSION when this extension was created. Before calling 36 | * this->create_stream() you must verify that get_particle_istream_version() == PARTICLE_ISTREAM_INTERFACE_VERSION; 37 | */ 38 | virtual __int64 get_particle_istream_version() { return PARTICLE_ISTREAM_INTERFACE_VERSION; } 39 | 40 | /** 41 | * Creates a new particle_istream object that reads from the FumeFX simulation stored at the given path. 42 | */ 43 | virtual frantic::particles::streams::particle_istream* 44 | create_stream( const std::string& srcName, const std::string& simPath, int frameNumber, 45 | const frantic::channels::channel_map& pcm, 46 | frantic::volumetrics::voxel_sampler_interface_ptr pSampleGen, int disabledChannels, float minDensity, 47 | float minFire ) = 0; 48 | }; 49 | 50 | } // namespace fumefx 51 | } // namespace krakatoa 52 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/light_object.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace krakatoa { 16 | 17 | class shadow_map_generator; 18 | typedef boost::shared_ptr shadow_map_generator_ptr; 19 | 20 | class scene_context; 21 | typedef boost::intrusive_ptr scene_context_ptr; 22 | 23 | class light_object { 24 | public: 25 | typedef frantic::graphics::color3f light_type; 26 | typedef boost::shared_ptr ptr_type; 27 | 28 | public: 29 | static ptr_type create( boost::shared_ptr lightObj ); 30 | 31 | virtual ~light_object() {} 32 | 33 | virtual frantic::rendering::lights::lightinterface& get_light_impl() = 0; 34 | 35 | virtual const frantic::rendering::lights::lightinterface& get_light_impl() const = 0; 36 | 37 | virtual void set_atmosphere( atmosphere_interface_ptr atmosphere ) = 0; 38 | 39 | virtual void set_shadow_map_generator( shadow_map_generator_ptr shadowMapGen ) = 0; 40 | 41 | virtual void begin( const scene_context_ptr context ) = 0; 42 | 43 | virtual void update( float mblurTime /*, bool isCanonicalTime = false*/ ) = 0; 44 | 45 | virtual void end() = 0; 46 | 47 | virtual light_type eval_lighting( const frantic::graphics::vector3f& worldPos, 48 | frantic::graphics::vector3f* outLocalPos = NULL ) = 0; 49 | }; 50 | 51 | typedef light_object::ptr_type light_object_ptr; 52 | // typedef directional_light_interface::ptr_type directional_light_interface_ptr; 53 | 54 | class shadow_map_generator { 55 | matte_interface_ptr m_matteInterface; 56 | 57 | public: 58 | shadow_map_generator( matte_interface_ptr matteInterface ) 59 | : m_matteInterface( matteInterface ) {} 60 | virtual ~shadow_map_generator() {} 61 | 62 | virtual void generate_shadow_map( const light_object& light, const scene_context_ptr context, float mblurTime, 63 | frantic::graphics2d::framebuffer& outDepthImg ) { 64 | m_matteInterface->generate_depth_map( 65 | static_cast( light.get_light_impl() ) 66 | .get_camera(), 67 | mblurTime, outDepthImg, true ); 68 | } 69 | 70 | virtual void generate_shadow_map( const light_object& light, const scene_context_ptr context, float mblurTime, 71 | frantic::rendering::framebuffer_cubeface& outDepthImg ) { 72 | using namespace frantic::graphics; 73 | using namespace frantic::graphics2d; 74 | transform4f renderTM = light.get_light_impl().transform_matrix( mblurTime ); 75 | for( int i = 0; i < 6; ++i ) { 76 | camera cubeCamera = 77 | camera::from_cube_face( renderTM, static_cast( i ) ); 78 | framebuffer& cubeSideBuffer = outDepthImg.get_cubeface_framebuffer( i ); 79 | cubeCamera.set_output_size( size2( cubeSideBuffer.size() ) ); 80 | m_matteInterface->generate_depth_map( cubeCamera, mblurTime, cubeSideBuffer, true ); 81 | } 82 | } 83 | }; 84 | 85 | } // namespace krakatoa 86 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/light_render_element.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace krakatoa { 12 | 13 | class light_render_element : public render_element { 14 | frantic::channels::channel_const_cvt_accessor m_accessor; 15 | frantic::tstring m_lightName; 16 | frantic::tstring m_internalName; 17 | 18 | public: 19 | typedef boost::shared_ptr ptr_type; 20 | 21 | public: 22 | light_render_element( const frantic::tstring& lightName, const frantic::tstring& internalName ); 23 | virtual ~light_render_element(); 24 | 25 | /** 26 | * Returns the name of the light that this render element is associated with. 27 | */ 28 | const frantic::tstring& get_light_name() const; 29 | 30 | /** 31 | * Returns the name of the particle channel that this render element is associated with. 32 | */ 33 | const frantic::tstring& get_channel_name() const; 34 | 35 | /** 36 | * see render_element_interface::clone() 37 | */ 38 | virtual render_element_interface* clone(); 39 | 40 | /** 41 | * see render_element_interface::commit() 42 | */ 43 | virtual void commit(); 44 | 45 | /** 46 | * see particle_render_element_interface::get_drawing_type() 47 | */ 48 | virtual draw_type get_drawing_type() const; 49 | 50 | /** 51 | * see particle_render_element_interface::set_channel_map() 52 | */ 53 | virtual void set_channel_map( const frantic::channels::channel_map& pcm ); 54 | 55 | /** 56 | * see particle_render_element_interface::add_required_channels() 57 | */ 58 | virtual void add_required_channels( frantic::channels::channel_map& pcm ); 59 | 60 | /** 61 | * see particle_render_element_interface::evaluate() 62 | */ 63 | virtual frantic::graphics::color3f evaluate( const char* particle ); 64 | }; 65 | 66 | typedef light_render_element::ptr_type light_render_element_ptr; 67 | 68 | } // namespace krakatoa 69 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/lighting_data.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | namespace krakatoa { 9 | 10 | struct lighting_data { 11 | const frantic::graphics::color3f& m_emission; 12 | const frantic::graphics::color3f& m_lighting; 13 | const frantic::graphics::vector3f& m_normal; 14 | const frantic::graphics::vector3f& m_position; 15 | 16 | lighting_data( const frantic::graphics::color3f& emission, const frantic::graphics::color3f& lighting, 17 | const frantic::graphics::vector3f& normal, const frantic::graphics::vector3f& position ) 18 | : m_emission( emission ) 19 | , m_lighting( lighting ) 20 | , m_normal( normal ) 21 | , m_position( position ) {} 22 | }; 23 | } // namespace krakatoa -------------------------------------------------------------------------------- /Krakatoa/krakatoa/magma_render_element.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | /** 4 | * This file is obsolete. Do not use anything from here. I realized later too that putting a magma element here doesn't 5 | * make a ton of sense due to the extra dependency, and that most host applications (ie. MaxKrakatoa) will have custom 6 | * Magma stuff that krakatoa base can't know about. 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | namespace krakatoa { 18 | 19 | class magma_render_element : public render_element { 20 | frantic::channels::channel_map m_outputMap; 21 | frantic::channels::channel_const_cvt_accessor m_accessor; 22 | 23 | std::vector m_exprTree; 24 | boost::shared_ptr m_pCompiledExpr; 25 | 26 | bool m_doAntialias; 27 | 28 | private: 29 | magma_render_element( bool doAntialias ); 30 | 31 | public: 32 | magma_render_element( bool doAntialias, const std::vector& exprTree ); 33 | virtual ~magma_render_element(); 34 | 35 | /** 36 | * see render_element_interface::clone() 37 | */ 38 | virtual render_element_interface* clone(); 39 | 40 | /** 41 | * see particle_render_element_interface::get_drawing_type() 42 | */ 43 | virtual draw_type get_drawing_type() const; 44 | 45 | /** 46 | * see particle_render_element_interface::set_channel_map() 47 | */ 48 | virtual void set_channel_map( const frantic::channels::channel_map& pcm ); 49 | 50 | /** 51 | * see particle_render_element_interface::add_required_channels() 52 | */ 53 | virtual void add_required_channels( frantic::channels::channel_map& pcm ); 54 | 55 | /** 56 | * see particle_render_element_interface::evaluate() 57 | */ 58 | virtual frantic::graphics::color3f evaluate( const char* particle ); 59 | }; 60 | 61 | } // namespace krakatoa 62 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/matte_zdepth_render_element.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace krakatoa { 11 | 12 | class matte_zdepth_render_element : public render_element { 13 | frantic::rendering::depthbuffer_singleface m_depthBuffer; 14 | 15 | bool m_applyDepthRange; 16 | float m_minDepth; 17 | float m_maxDepth; 18 | 19 | public: 20 | matte_zdepth_render_element( bool applyDepthRange, float minDepth, float maxDepth ); 21 | virtual ~matte_zdepth_render_element(); 22 | 23 | /** 24 | * The depth buffer is better suited to matte_zdepth_render_element, so we provide this buffer for writing to 25 | * instead of the normal get_framebuffer() from render_element_interface. 26 | */ 27 | virtual frantic::rendering::depthbuffer_singleface& get_depthbuffer(); 28 | 29 | /** 30 | * Do not use! 31 | */ 32 | virtual frantic::graphics2d::framebuffer& get_framebuffer(); 33 | 34 | /** 35 | * see render_element_interface::clone() 36 | */ 37 | virtual render_element_interface* clone(); 38 | 39 | /** 40 | * see render_element_interface::initialize() 41 | */ 42 | virtual void initialize(); 43 | 44 | /** 45 | * see render_element_interface::commit() 46 | */ 47 | virtual void commit(); 48 | }; 49 | 50 | } // namespace krakatoa 51 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/mblur_data.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | 9 | namespace krakatoa { 10 | 11 | struct mblur_data { 12 | typedef const frantic::graphics2d::image_channel& out_image_t; 13 | typedef const std::vector& render_elements_t; 14 | typedef std::vector::const_iterator render_element_iterator_t; 15 | 16 | const float m_mblurTime; 17 | const out_image_t m_outImage; 18 | const boost::optional m_behindMatteRenderElement; 19 | const render_elements_t m_renderElements; 20 | const std::size_t m_numPasses; 21 | 22 | mblur_data( float mblurTime, const out_image_t outImage, boost::optional behindMatte, 23 | render_elements_t renderElements, std::size_t numPasses ) 24 | : m_mblurTime( mblurTime ) 25 | , m_outImage( outImage ) 26 | , m_behindMatteRenderElement( behindMatte ) 27 | , m_renderElements( renderElements ) 28 | , m_numPasses( numPasses ) {} 29 | 30 | mblur_data( const mblur_data& other ) 31 | : m_mblurTime( other.m_mblurTime ) 32 | , m_outImage( other.m_outImage ) 33 | , m_behindMatteRenderElement( other.m_behindMatteRenderElement ) 34 | , m_renderElements( other.m_renderElements ) 35 | , m_numPasses( other.m_numPasses ) {} 36 | }; 37 | } // namespace krakatoa -------------------------------------------------------------------------------- /Krakatoa/krakatoa/min_color6f.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace krakatoa { 8 | 9 | struct min_color6f { 10 | static inline float max_if_zero( float in ) { return in <= 0.f ? std::numeric_limits::max() : in; } 11 | 12 | frantic::graphics::color6f operator()( const frantic::graphics::color6f& original, 13 | const frantic::graphics::color6f& other ) const { 14 | return frantic::graphics::color6f( 15 | frantic::graphics::color3f( std::min( max_if_zero( original.c.r ), max_if_zero( other.c.r ) ), 16 | std::min( max_if_zero( original.c.g ), max_if_zero( other.c.g ) ), 17 | std::min( max_if_zero( original.c.b ), max_if_zero( other.c.b ) ) ), 18 | frantic::graphics::alpha3f( std::min( max_if_zero( original.a.ar ), max_if_zero( other.a.ar ) ), 19 | std::min( max_if_zero( original.a.ag ), max_if_zero( other.a.ag ) ), 20 | std::min( max_if_zero( original.a.ab ), max_if_zero( other.a.ab ) ) ) ); 21 | } 22 | }; 23 | 24 | } // namespace krakatoa 25 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/normal_render_element.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace krakatoa { 12 | 13 | class normal_render_element : public render_element { 14 | scene_context_ptr m_context; 15 | 16 | frantic::channels::channel_const_cvt_accessor m_accessor; 17 | 18 | bool m_doAntialiasing; 19 | bool m_doScaling; 20 | 21 | public: 22 | normal_render_element( scene_context_ptr context, bool doAntialiasing, bool doScaling ); 23 | virtual ~normal_render_element(); 24 | 25 | /** 26 | * see render_element_interface::clone() 27 | */ 28 | virtual render_element_interface* clone(); 29 | 30 | /** 31 | * see particle_render_element_interface::get_drawing_type() 32 | */ 33 | virtual draw_type get_drawing_type() const; 34 | 35 | /** 36 | * see particle_render_element_interface::set_channel_map() 37 | */ 38 | virtual void set_channel_map( const frantic::channels::channel_map& pcm ); 39 | 40 | /** 41 | * see particle_render_element_interface::add_required_channels() 42 | */ 43 | virtual void add_required_channels( frantic::channels::channel_map& pcm ); 44 | 45 | /** 46 | * see particle_render_element_interface::evaluate() 47 | */ 48 | virtual frantic::graphics::color3f evaluate( const char* particle ); 49 | }; 50 | 51 | } // namespace krakatoa 52 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/occluded_layer_render_element.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace krakatoa { 11 | 12 | class occluded_layer_render_element : public render_element { 13 | public: 14 | occluded_layer_render_element(); 15 | virtual ~occluded_layer_render_element(); 16 | 17 | /** 18 | * see render_element_interface::clone() 19 | */ 20 | virtual render_element_interface* clone(); 21 | }; 22 | 23 | } // namespace krakatoa 24 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/particle_render_element_interface.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace krakatoa { 11 | 12 | class particle_render_element_interface : public render_element_interface { 13 | public: 14 | typedef boost::shared_ptr ptr_type; 15 | 16 | public: 17 | enum draw_type { 18 | // Draw each particle as if the output of the render element was the Emission channel. The particle's Color and 19 | // Absorption 20 | // contribute to the alpha, as well as affecting the final drawing color. 21 | draw_type_normal, 22 | 23 | // Draw each particle exactly like draw_type_normal, except don't divide out the density. Use this for light 24 | // reflecting off a particle.k 25 | draw_type_shader, 26 | 27 | // Draw each particle as an antialiased splat. The particle's Color and Absorption are ignored and alpha is 28 | // [1,1,1] before filtering. 29 | draw_type_antialias, 30 | 31 | // Draw each particle as a solid rectangle covering the specified filter radius. Each pixel in the 1x2, 2x2 or 32 | // 3x3 box gets alpha [1,1,1]. 33 | draw_type_solid 34 | }; 35 | 36 | public: 37 | virtual ~particle_render_element_interface() {} 38 | 39 | virtual draw_type get_drawing_type() const = 0; 40 | 41 | /** 42 | * Called exactly after the layput of particles has been determined. All particles passed to evaluate() 43 | * will have the layout described by 'pcm'. 44 | * @note this MUST be called after set_camera() since it may require information from the camera. 45 | */ 46 | virtual void set_channel_map( const frantic::channels::channel_map& pcm ) = 0; 47 | 48 | /** 49 | * Called to add channels required by this render element to the channel map. This will be called before 50 | * set_channel_map() is called with the completed channel map. 51 | */ 52 | virtual void add_required_channels( frantic::channels::channel_map& pcm ) = 0; 53 | 54 | /** 55 | * Called on each particle to determine the color it should contribute to this render element. 56 | */ 57 | virtual frantic::graphics::color3f evaluate( const char* particle ) = 0; 58 | }; 59 | 60 | typedef particle_render_element_interface::ptr_type particle_render_element_interface_ptr; 61 | 62 | } // namespace krakatoa 63 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/particle_repopulation.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | namespace krakatoa { 9 | 10 | /** 11 | * Creates a particle repopulation stream from an existing particle stream. 12 | * When called, it will fully exhaust the pin stream. 13 | * It is based on creating a metaballs implicit surface around the existing particles, then using seeding particles from 14 | * the resulting voxel field. 15 | * 16 | * @param pin Original particles to be "multiplied". 17 | * @param fillRadius The radius around each particle to seed new particles. 18 | * @param fillRadiusSubdivs The number of seeding subdivisions. Increasing this number will exponentially increase 19 | * output particle count. 20 | * @param numParticlesPerSubdiv The number of particles placed in each subdivision. Increasing this number will linearly 21 | * increase output particle count. 22 | * @param densityFalloffStart A value between zero and one that defines the start (between the center and outter radius) 23 | * of the linear falloff of density. zero being no falloff, one being a linear falloff from the center of the original 24 | * particle to the outter radius. 25 | * @param useSignedDistanceDensityFalloff Base the falloff on a more accurate, but slower signed distance calcuation. 26 | * This is experimental. 27 | * @param logger The progress logger. Passing in a logger will possibly result in cancel exceptions to be thrown on user 28 | * cancel events. 29 | */ 30 | boost::shared_ptr 31 | create_particle_repopulation_istream( boost::shared_ptr pin, 32 | float fillRadius, int fillRadiusSubdivs, int numParticlesPerSubdiv, 33 | float densityFalloffStart, unsigned randomSeed, 34 | frantic::logging::progress_logger& logger ); 35 | 36 | } // namespace krakatoa 37 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/prt_stream_builder.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace krakatoa { 13 | 14 | namespace render { 15 | enum RENDER_LOAD_PARTICLE_MODE { 16 | PARTICLELOAD_EVENLY_DISTRIBUTE = 1, 17 | PARTICLELOAD_FIRST_N, 18 | PARTICLELOAD_EVENLY_DISTRIBUTE_IDS, 19 | }; 20 | } 21 | 22 | namespace viewport { 23 | enum RENDER_LOAD_PARTICLE_MODE { 24 | PARTICLELOAD_USE_RENDER_SETTING = 1, 25 | PARTICLELOAD_EVENLY_DISTRIBUTE, 26 | PARTICLELOAD_FIRST_N, 27 | PARTICLELOAD_EVENLY_DISTRIBUTE_IDS 28 | }; 29 | } 30 | 31 | namespace clamp_mode { 32 | enum clamp_mode_enum { hold = 1, blank }; 33 | } 34 | 35 | namespace enabled_mode { 36 | enum enabled_mode_enum { 37 | viewport = ( 1 << 0 ), 38 | render = ( 1 << 1 ), 39 | all = ( 1 << 0 ) | ( 1 << 1 ), 40 | }; 41 | } 42 | 43 | // converts viewport load mode to render load mode 44 | render::RENDER_LOAD_PARTICLE_MODE get_as_render_mode( viewport::RENDER_LOAD_PARTICLE_MODE loadMode ); 45 | 46 | // pre-calculates the fractional particle count given by 'get_reduced_particle_stream' 47 | boost::int64_t get_fractional_particle_count( boost::int64_t rawNumParticles, double fraction, boost::int64_t limit ); 48 | 49 | // stream builder that takes a set of input files, and gives back a concatenated stream of all requested files 50 | class prt_stream_builder { 51 | public: 52 | prt_stream_builder(); 53 | ~prt_stream_builder(); 54 | 55 | void reset_to_defaults(); 56 | boost::shared_ptr generate_stream(); 57 | 58 | size_t num_errors(); 59 | void get_error( size_t index, frantic::tstring& outError ); 60 | void clear_errors(); 61 | 62 | private: 63 | void get_files_at_frame( int currentFrame, std::vector& outFiles ); 64 | void handle_error( const std::exception& error ); 65 | void error_message( const frantic::tstring& error ); 66 | 67 | public: 68 | // operational flags 69 | bool m_throwOnError; 70 | bool m_cacheErrors; 71 | bool m_logErrors; 72 | bool m_threadingSupport; 73 | 74 | // times are to be expressed in _frames_ 75 | double m_currentTime; 76 | double m_framesPerSecond; 77 | double m_timeDerivative; 78 | 79 | // timing controls 80 | int m_frameOffset; 81 | bool m_interpolateSubFrames; 82 | bool m_keepVelocityChannel; 83 | 84 | // load fraction control 85 | double m_loadFraction; 86 | boost::int64_t m_loadLimit; 87 | render::RENDER_LOAD_PARTICLE_MODE m_loadMode; 88 | 89 | // range control 90 | int m_rangeStart; 91 | int m_rangeEnd; 92 | clamp_mode::clamp_mode_enum m_rangeStartClampMode; 93 | clamp_mode::clamp_mode_enum m_rangeEndClampMode; 94 | 95 | // input filenames 96 | std::vector m_fileSequences; 97 | std::vector m_singleFiles; 98 | 99 | // misc 100 | frantic::graphics::coordinate_system::option m_coordinateSystem; 101 | double m_scaleToMeters; 102 | 103 | private: 104 | std::vector m_errorMessages; 105 | }; 106 | 107 | } // namespace krakatoa 108 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/raytrace_renderer/raytrace_renderer.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | namespace krakatoa { 12 | namespace raytrace_renderer { 13 | 14 | class raytrace_renderer : public renderer { 15 | protected: 16 | frantic::volumetrics::voxel_coord_system m_vcs; 17 | float m_minStepSize, m_maxStepSize; 18 | 19 | color_type m_ambientLight; 20 | 21 | splat_renderer::filter2f_ptr m_splatFilter; 22 | splat_renderer::splat_lighting_ptr m_lightingEngine; 23 | 24 | public: 25 | typedef boost::shared_ptr ptr_type; 26 | 27 | public: 28 | static ptr_type create_instance( bool useOpenVDB = false ); 29 | 30 | public: 31 | raytrace_renderer() 32 | : m_vcs( frantic::graphics::vector3f(), 1.f ) 33 | , m_minStepSize( 1.f ) 34 | , m_maxStepSize( 1.f ) {} 35 | 36 | virtual ~raytrace_renderer() {} 37 | 38 | void set_voxel_length( float voxelLength ) { m_vcs.set_voxel_length( voxelLength ); } 39 | 40 | void set_raymarch_stepsize( float minStep, float maxStep ) { 41 | m_minStepSize = minStep; 42 | m_maxStepSize = maxStep; 43 | } 44 | 45 | void set_ambient_light( const color_type& ambientLight ) { m_ambientLight = ambientLight; } 46 | 47 | /** 48 | * For ray-tracers that use splatting during the `precompute_lighting` stage, set the splat filter. This has no 49 | * effect for ray-tracers that don't splat. 50 | */ 51 | virtual void set_splat_filter( splat_renderer::filter2f_ptr filter ) { m_splatFilter = filter; } 52 | 53 | /** 54 | * For ray-tracers that use splatting during the `precompute_lighting` stage, set the lighting engine. The lighting 55 | * engine fills the "Lighting" channel of the particles. This has no effect for ray-tracers that don't splat. 56 | */ 57 | virtual void set_lighting_engine( splat_renderer::splat_lighting_ptr lightingEngine ) { 58 | m_lightingEngine = lightingEngine; 59 | } 60 | 61 | virtual void add_render_element( krakatoa::render_element_interface_ptr renderElement ) = 0; 62 | 63 | virtual void precompute_lighting() = 0; 64 | 65 | virtual void initialize() = 0; 66 | 67 | virtual void raymarch( const frantic::graphics::ray3f& r, double t0, double t1, color_type& accum, 68 | alpha_type& accumAlpha ) = 0; 69 | 70 | virtual void raymarch( const frantic::graphics::ray3f& r, double t0, double t1, color_type& accum, 71 | alpha_type& accumAlpha, float& nearestDepth, float alphaThreshold = 1e-4f ) = 0; 72 | 73 | virtual void raymarch_opacity( const frantic::graphics::ray3f& r, double t0, double t1, 74 | alpha_type& accumAlpha ) = 0; 75 | 76 | virtual void render( image_type& outImage ) = 0; 77 | }; 78 | 79 | typedef raytrace_renderer::ptr_type raytrace_renderer_ptr; 80 | 81 | } // namespace raytrace_renderer 82 | } // namespace krakatoa 83 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/render_element.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | /** 13 | * @note Make sure to #include after including this file. If you 14 | * are getting linker errors in this file, it likely means you forgot to include render_element_impl.hpp in the 15 | * .cpp of client classes. 16 | */ 17 | 18 | #pragma warning( push ) 19 | #pragma warning( disable : 4505 ) 20 | 21 | namespace krakatoa { 22 | 23 | template 24 | class render_element : public BaseClass { 25 | frantic::graphics2d::framebuffer m_framebuffer; 26 | std::vector> m_callbackFunctions; 27 | 28 | public: 29 | virtual ~render_element(); 30 | 31 | /** 32 | * Access to the render element's framebuffer 33 | */ 34 | virtual frantic::graphics2d::framebuffer& get_framebuffer(); 35 | 36 | /** 37 | * Use this to register a callback method when this render element is commited 38 | */ 39 | virtual void register_commit_callback( const boost::function& callbackFn ); 40 | 41 | /** 42 | * Called exactly once on a render element after all properties have been set, but before the first drawing to 43 | * its framebuffer 44 | */ 45 | virtual void initialize(); 46 | 47 | /** 48 | * Called to combine the results of cloned elements backed together. To be called in the same order the elements 49 | * were cloned from the original. 50 | */ 51 | virtual void combine( render_element_interface* rhs ); 52 | 53 | /** 54 | * Called exactly once on a render element after all drawing to its framebuffer has completed. 55 | */ 56 | virtual void commit(); 57 | 58 | /** 59 | * When compositing multiple images (eg. for motion blur), the minimum value should be used. 60 | * This is required for compositing z-depth. 61 | */ 62 | virtual inline bool use_minimize_compositing() { return false; } 63 | }; 64 | 65 | } // namespace krakatoa 66 | 67 | #pragma warning( pop ) 68 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/render_element_impl.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | namespace krakatoa { 6 | 7 | template 8 | render_element::~render_element() {} 9 | 10 | template 11 | frantic::graphics2d::framebuffer& render_element::get_framebuffer() { 12 | return m_framebuffer; 13 | } 14 | 15 | template 16 | void render_element::register_commit_callback( 17 | const boost::function& callbackFn ) { 18 | m_callbackFunctions.push_back( callbackFn ); 19 | } 20 | 21 | template 22 | void render_element::initialize() {} 23 | 24 | template 25 | void render_element::combine( render_element_interface* rhs ) { 26 | get_framebuffer().blend_over( rhs->get_framebuffer() ); 27 | } 28 | 29 | template 30 | void render_element::commit() { 31 | // Eval them in reverse order so that it behaves like a LiFo queue. 32 | std::vector>::reverse_iterator it = m_callbackFunctions.rbegin(), 33 | itEnd = 34 | m_callbackFunctions.rend(); 35 | for( ; it != itEnd; ++it ) 36 | ( *it )( *this ); 37 | } 38 | 39 | } // namespace krakatoa 40 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/render_element_interface.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | namespace krakatoa { 12 | 13 | class render_element_interface { 14 | public: 15 | typedef boost::shared_ptr ptr_type; 16 | 17 | public: 18 | virtual ~render_element_interface() {} 19 | 20 | /** 21 | * Access to the render element's framebuffer 22 | */ 23 | virtual frantic::graphics2d::framebuffer& get_framebuffer() = 0; 24 | 25 | /** 26 | * Use this to register a callback method when this render element is commited 27 | */ 28 | virtual void register_commit_callback( const boost::function& callbackFn ) = 0; 29 | 30 | /** 31 | * Clones this render element. This can be used to have multiple render elements with the same function drawing 32 | * to different framebuffers. This is useful for achieving multipass effects or splitting processing of elements 33 | * into threads. 34 | */ 35 | virtual render_element_interface* clone() = 0; 36 | 37 | /** 38 | * Called exactly once on a render element after all properties have been set, but before the first drawing to 39 | * its framebuffer 40 | */ 41 | virtual void initialize() = 0; 42 | 43 | /** 44 | * Called to combine the results of cloned elements backed together. To be called in the same order the elements 45 | * were cloned from the original. 46 | */ 47 | virtual void combine( render_element_interface* rhs ) = 0; 48 | 49 | /** 50 | * Called exactly once when the render element is finished rendering. Fires callbacks registered with 51 | * register_commit_callback() 52 | */ 53 | virtual void commit() = 0; 54 | 55 | /** 56 | * When compositing multiple images (eg. for motion blur), the minimum value should be used. 57 | * This is required for compositing z-depth. 58 | */ 59 | virtual bool use_minimize_compositing() = 0; 60 | }; 61 | 62 | typedef render_element_interface::ptr_type render_element_interface_ptr; 63 | 64 | } // namespace krakatoa 65 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/scene_context.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace krakatoa { 13 | 14 | /** 15 | * This interface exists to provide the various disparate parts of krakatoa access to information about the 16 | * currently rendered scene. I intend this interface tobe a replacement for frantic::max3d::shaders::renderInformation 17 | * which has been used in similar situations. And used poorly I might add. 18 | */ 19 | class scene_context : public shared_object { 20 | public: 21 | typedef boost::intrusive_ptr ptr_type; /**Use this type when storing a scene_context. Never create 22 | one on the stack, or hold a scene_context*. Please.*/ 23 | 24 | typedef collection_interface 25 | matte_collection; /**The interface exposed for accessing geometry objects*/ 26 | 27 | typedef collection_interface 28 | light_collection; /**The interface exposed for accessing light objects*/ 29 | 30 | /** 31 | * @return the current scene time in seconds. In 3ds Max this can be converted to ticks via the macro SecToTicks() 32 | */ 33 | virtual double get_time() const = 0; 34 | 35 | /** 36 | * @param time The new scene time, in seconds. 37 | */ 38 | virtual void set_time( double time ) = 0; 39 | 40 | /** 41 | * @return The active camera the scene is being viewed from. 42 | */ 43 | virtual const frantic::graphics::camera& get_camera() const = 0; 44 | 45 | /** 46 | * @overload 47 | */ 48 | virtual frantic::graphics::camera& get_camera() = 0; 49 | 50 | /** 51 | * @param cam The new camera to associate with this scene_context 52 | */ 53 | virtual void set_camera( const frantic::graphics::camera& cam ) = 0; 54 | 55 | /** 56 | * @param cams The list of cameras to associate with this scene_context 57 | */ 58 | virtual void set_camera( const std::vector>& cams ) = 0; 59 | 60 | /** 61 | * @return A read-only interface to the collection of geometry objects in the scene. 62 | */ 63 | virtual const matte_collection& get_matte_objects() const = 0; 64 | 65 | /** 66 | * @return A read-only interface to the collection of light objects in the scene. 67 | */ 68 | virtual const light_collection& get_light_objects() const = 0; 69 | }; 70 | 71 | // Use this type for storing all scene_context objects. 72 | typedef scene_context::ptr_type scene_context_ptr; 73 | 74 | } // namespace krakatoa 75 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/shader_render_element.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace krakatoa { 11 | 12 | class shader_render_element : public render_element { 13 | frantic::tstring m_elementName; 14 | frantic::channels::channel_const_cvt_accessor m_accessor; 15 | 16 | public: 17 | shader_render_element( const frantic::tstring& elementName ); 18 | virtual ~shader_render_element(); 19 | 20 | /** 21 | * see render_element_interface::clone() 22 | */ 23 | virtual render_element_interface* clone(); 24 | 25 | /** 26 | * see particle_render_element_interface::get_drawing_type() 27 | */ 28 | virtual draw_type get_drawing_type() const; 29 | 30 | /** 31 | * see particle_render_element_interface::set_channel_map() 32 | */ 33 | virtual void set_channel_map( const frantic::channels::channel_map& pcm ); 34 | 35 | /** 36 | * see particle_render_element_interface::add_required_channels() 37 | */ 38 | virtual void add_required_channels( frantic::channels::channel_map& pcm ); 39 | 40 | /** 41 | * see particle_render_element_interface::evaluate() 42 | */ 43 | virtual frantic::graphics::color3f evaluate( const char* particle ); 44 | 45 | /** 46 | * Retreives the name of the shader component that this render element captures 47 | */ 48 | const frantic::tstring& get_element_name() const { return m_elementName; } 49 | }; 50 | 51 | } // namespace krakatoa 52 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/shared_object.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace krakatoa { 8 | 9 | class shared_object { 10 | private: 11 | int m_refCount; 12 | 13 | friend void intrusive_ptr_add_ref( shared_object* pObj ); 14 | friend void intrusive_ptr_release( shared_object* pObj ); 15 | 16 | public: 17 | shared_object(); 18 | virtual ~shared_object(); 19 | }; 20 | 21 | void intrusive_ptr_add_ref( shared_object* pObj ); 22 | void intrusive_ptr_release( shared_object* pObj ); 23 | 24 | } // namespace krakatoa 25 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/specular_render_element.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace krakatoa { 11 | 12 | class specular_render_element : public render_element { 13 | frantic::channels::channel_const_cvt_accessor m_accessor; 14 | 15 | public: 16 | specular_render_element(); 17 | virtual ~specular_render_element(); 18 | 19 | /** 20 | * see render_element_interface::clone() 21 | */ 22 | virtual render_element_interface* clone(); 23 | 24 | /** 25 | * see particle_render_element_interface::get_drawing_type() 26 | */ 27 | virtual draw_type get_drawing_type() const; 28 | 29 | /** 30 | * see particle_render_element_interface::set_channel_map() 31 | */ 32 | virtual void set_channel_map( const frantic::channels::channel_map& pcm ); 33 | 34 | /** 35 | * see particle_render_element_interface::add_required_channels() 36 | */ 37 | virtual void add_required_channels( frantic::channels::channel_map& pcm ); 38 | 39 | /** 40 | * see particle_render_element_interface::evaluate() 41 | */ 42 | virtual frantic::graphics::color3f evaluate( const char* particle ); 43 | }; 44 | 45 | } // namespace krakatoa 46 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/splat_renderer/default_light_traits.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | 15 | extern int g_filterRadius; 16 | 17 | namespace krakatoa { 18 | namespace splat_renderer { 19 | 20 | class default_light_traits { 21 | public: 22 | typedef frantic::graphics2d::vector2f screen_space_type; 23 | typedef frantic::graphics2d::framebuffer attenuation_buffer_type; 24 | typedef frantic::rendering::depthbuffer_singleface shadow_map_type; 25 | typedef frantic::graphics::alpha3f pixel_type; 26 | 27 | inline static bool get_screen_pos( const frantic::rendering::lights::lightinterface& light, 28 | const frantic::graphics::vector3f& lightSpacePos, 29 | screen_space_type& outScreenSpacePos ) { 30 | bool isValid = true; 31 | outScreenSpacePos = static_cast( light ) 32 | .get_camera() 33 | .from_cameraspace_position( lightSpacePos, isValid ); 34 | 35 | return isValid; 36 | } 37 | 38 | inline static float get_density_scale( const frantic::rendering::lights::lightinterface& light, 39 | const frantic::graphics::vector3f& lightSpacePos ) { 40 | return light.shadow_density() * static_cast( light ) 41 | .get_camera() 42 | .area_differential_from_cameraspace_position( lightSpacePos ); 43 | } 44 | 45 | inline static void draw_attenuation( const frantic::graphics::alpha3f& attenSample, 46 | const screen_space_type& screenPos, attenuation_buffer_type& buffer ) { 47 | // TODO: Replace with a filter2f 48 | buffer.draw_point( screenPos, attenSample ); 49 | } 50 | 51 | inline static void draw_attenuation( const frantic::graphics::alpha3f& attenSample, 52 | const screen_space_type& screenPos, attenuation_buffer_type& buffer, 53 | const filter2f_ptr& filter ) { 54 | // TODO: Replace with a filter2f 55 | // buffer.draw_point( screenPos, attenSample ); 56 | 57 | int width = filter->get_width(); 58 | int size = width * width; 59 | 60 | float* weights = (float*)alloca( sizeof( float ) * size ); 61 | 62 | frantic::graphics2d::vector2 pixelPos; 63 | filter->do_filter( screenPos, pixelPos, weights ); 64 | 65 | for( int y = 0; y < width; ++y, weights += width ) { 66 | int py = pixelPos.y + y; 67 | if( (unsigned)py < (unsigned)buffer.height() ) { 68 | for( int x = 0; x < width; ++x ) { 69 | int px = pixelPos.x + x; 70 | if( (unsigned)px < (unsigned)buffer.width() ) 71 | buffer.blend_under( px, py, weights[x] * attenSample ); 72 | } 73 | } 74 | } 75 | } 76 | 77 | inline static void add_deep_attenuation_sample( const frantic::graphics::alpha3f& attenSample, 78 | const screen_space_type& screenPos, float z, 79 | boost::shared_ptr attenSaver ) { 80 | // Replace with a filter2f? 81 | if( attenSaver && !attenSaver->is_cubeface() ) { 82 | frantic::rendering::singleface_atten_saver* singlefaceAttenSaver = 83 | static_cast( attenSaver.get() ); 84 | singlefaceAttenSaver->add_sample_bilinear( screenPos.x, screenPos.y, z, attenSample ); 85 | } 86 | } 87 | }; 88 | 89 | } // namespace splat_renderer 90 | } // namespace krakatoa 91 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/splat_renderer/filter2f.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace krakatoa { 12 | namespace splat_renderer { 13 | 14 | /** 15 | * Abstract interface for a two dimensional filter. 16 | */ 17 | class filter2f { 18 | public: 19 | typedef boost::shared_ptr ptr_type; 20 | 21 | public: 22 | static ptr_type create_instance( const frantic::tstring& name ); 23 | 24 | public: 25 | virtual ~filter2f() {} 26 | 27 | virtual int get_width() const = 0; 28 | 29 | virtual void do_filter( frantic::graphics2d::vector2f screenPt, frantic::graphics2d::vector2& outPixel, 30 | float outWeights[] ) = 0; 31 | }; 32 | 33 | typedef filter2f::ptr_type filter2f_ptr; 34 | 35 | } // namespace splat_renderer 36 | } // namespace krakatoa 37 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/splat_renderer/omni_light_traits.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | //#include "LightingEngineBase.hpp" 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace krakatoa { 12 | namespace splat_renderer { 13 | 14 | class omni_light_traits { 15 | public: 16 | typedef frantic::graphics::vector3f screen_space_type; 17 | typedef frantic::rendering::framebuffer_cubeface attenuation_buffer_type; 18 | typedef frantic::rendering::depthbuffer_cubeface shadow_map_type; 19 | typedef frantic::graphics::alpha3f pixel_type[6]; 20 | 21 | inline static bool get_screen_pos( const frantic::rendering::lights::lightinterface& /*light*/, 22 | const frantic::graphics::vector3f& lightSpacePos, 23 | screen_space_type& outScreenSpacePos ) { 24 | outScreenSpacePos = lightSpacePos; 25 | return true; 26 | } 27 | 28 | inline static float get_density_scale( const frantic::rendering::lights::lightinterface& light, 29 | const frantic::graphics::vector3f& lightSpacePos ) { 30 | // Stolen from famebuffer_cubeface: 31 | // The area of a voxel on screen at a distance d from the camera is (w/(2*d*tan(fov/2))^2. In the case of a 90 32 | // degree field of view, the tangent term is 1. This value is calculated at the center of the cube faces. 33 | // 34 | // float draw_point_scaling_constant() const { 35 | // return m_size * m_size / 4.f; 36 | // } 37 | 38 | return light.shadow_density() * (float)frantic::math::square( light.shadow_map_size().xsize ) / 39 | ( 4.f * lightSpacePos.get_magnitude_squared() ); 40 | } 41 | 42 | inline static void draw_attenuation( const frantic::graphics::alpha3f& attenSample, 43 | const screen_space_type& screenPos, attenuation_buffer_type& buffer ) { 44 | // TODO: Replace with a filter2f 45 | buffer.draw_point( screenPos, attenSample ); 46 | } 47 | 48 | inline static void draw_attenuation( const frantic::graphics::alpha3f& attenSample, 49 | const screen_space_type& screenPos, attenuation_buffer_type& buffer, 50 | const filter2f_ptr& /*filter*/ 51 | ) { 52 | // TODO: Replace with a filter2f 53 | buffer.draw_point( screenPos, attenSample ); 54 | } 55 | 56 | inline static void add_deep_attenuation_sample( const frantic::graphics::alpha3f& attenSample, 57 | const screen_space_type& screenPos, float /*z*/, 58 | boost::shared_ptr attenSaver ) { 59 | // Replace with a filter2f? 60 | if( attenSaver && attenSaver->is_cubeface() ) { 61 | frantic::rendering::cubeface_atten_saver* cubefaceAttenSaver = 62 | static_cast( attenSaver.get() ); 63 | cubefaceAttenSaver->add_sample_bilinear( screenPos, attenSample ); 64 | } 65 | } 66 | }; 67 | 68 | } // namespace splat_renderer 69 | } // namespace krakatoa 70 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/splat_renderer/parallel_progress.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace krakatoa { 11 | namespace splat_renderer { 12 | 13 | class parallel_render_progress_logger_master { 14 | tbb::tbb_thread::id m_loggingThreadId; 15 | tbb::atomic m_curTicks; 16 | 17 | boost::shared_ptr m_delegateLogger; 18 | 19 | std::size_t m_totalTicks; 20 | std::size_t m_imageOrdering; 21 | 22 | typedef boost::function& )> watermark_type; 23 | 24 | watermark_type m_watermark; 25 | 26 | public: 27 | friend class parallel_render_progress_logger; 28 | 29 | void update_progress( std::size_t tickCount ) { 30 | std::size_t curTicks = tickCount + m_curTicks.fetch_and_add( tickCount ); 31 | 32 | if( tbb::this_tbb_thread::get_id() == m_loggingThreadId ) 33 | m_delegateLogger->update_progress( (long long)curTicks, (long long)m_totalTicks ); 34 | } 35 | 36 | void update_progress_and_image( std::size_t tickCount, 37 | frantic::graphics2d::framebuffer& framebuffer, 38 | std::size_t relativeOrdering ) { 39 | update_progress( tickCount ); 40 | 41 | if( tbb::this_tbb_thread::get_id() == m_loggingThreadId && relativeOrdering <= m_imageOrdering ) { 42 | m_imageOrdering = relativeOrdering; 43 | 44 | if( m_watermark ) 45 | m_watermark( framebuffer ); 46 | 47 | m_delegateLogger->update_frame_buffer( framebuffer ); 48 | } 49 | } 50 | 51 | public: 52 | parallel_render_progress_logger_master( boost::shared_ptr delegateLogger, 53 | std::size_t totalTicks, const watermark_type& watermark ) 54 | : m_delegateLogger( delegateLogger ) 55 | , m_loggingThreadId( tbb::this_tbb_thread::get_id() ) 56 | , m_totalTicks( totalTicks ) 57 | , m_imageOrdering( std::numeric_limits::max() ) 58 | , m_watermark( watermark ) { 59 | m_curTicks = 0; 60 | } 61 | }; 62 | 63 | class parallel_render_progress_logger { 64 | std::size_t m_tickCount; 65 | std::size_t m_updateTickCount; 66 | parallel_render_progress_logger_master* m_master; 67 | 68 | public: 69 | parallel_render_progress_logger( parallel_render_progress_logger_master& master, std::size_t updateTickCount ) 70 | : m_master( &master ) 71 | , m_tickCount( 0 ) 72 | , m_updateTickCount( updateTickCount ) {} 73 | 74 | void tick() { 75 | if( ++m_tickCount >= m_updateTickCount ) { 76 | m_master->update_progress( m_tickCount ); 77 | m_tickCount = 0; 78 | } 79 | } 80 | 81 | void update_image( frantic::graphics2d::framebuffer& image, 82 | std::size_t relativeOrdering ) { 83 | m_master->update_progress_and_image( m_tickCount, image, relativeOrdering ); 84 | m_tickCount = 0; 85 | } 86 | }; 87 | 88 | } // namespace splat_renderer 89 | } // namespace krakatoa 90 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/tangent_render_element.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace krakatoa { 12 | 13 | class tangent_render_element : public render_element { 14 | scene_context_ptr m_context; 15 | 16 | frantic::channels::channel_const_cvt_accessor m_accessor; 17 | 18 | bool m_doAntialiasing; 19 | 20 | public: 21 | tangent_render_element( scene_context_ptr context, bool doAntialiasing ); 22 | virtual ~tangent_render_element(); 23 | 24 | /** 25 | * see render_element_interface::clone() 26 | */ 27 | virtual render_element_interface* clone(); 28 | 29 | /** 30 | * see particle_render_element_interface::get_drawing_type() 31 | */ 32 | virtual draw_type get_drawing_type() const; 33 | 34 | /** 35 | * see particle_render_element_interface::set_channel_map() 36 | */ 37 | virtual void set_channel_map( const frantic::channels::channel_map& pcm ); 38 | 39 | /** 40 | * see particle_render_element_interface::add_required_channels() 41 | */ 42 | virtual void add_required_channels( frantic::channels::channel_map& pcm ); 43 | 44 | /** 45 | * see particle_render_element_interface::evaluate() 46 | */ 47 | virtual frantic::graphics::color3f evaluate( const char* particle ); 48 | }; 49 | 50 | } // namespace krakatoa 51 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/threading_functions.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace krakatoa { 8 | 9 | /** 10 | * Gets the total number of threads that Krakatoa should be allowed to use for particle rendering. 11 | * Since we must allocated a separate frame buffer for each thread, the size of a single frame buffer is calculated 12 | * and then the number of frame buffers that can fit into a fraction of total system memory (minus the size of the 13 | *particle buffer) is returned as the number of threads that can be used. 14 | * @param width the width of the frame buffer 15 | * @param height the height of the frame buffer 16 | * @param numOutputImages the number of output images (channels) 17 | * @param particleSizeInMemory the total number of bytes the particle buffer takes up in memory 18 | * @param pixelSize the number of bytes an individual pixel takes up in memory for one 19 | *output image 20 | * @param threadCap the maximum number of threads that can be used in the render. -1 21 | *will set this to the size of the TBB thread pool 22 | * @return the optimal number of threads to be used in the render 23 | */ 24 | std::size_t get_max_threads( std::size_t width, std::size_t height, std::size_t numOutputImages, 25 | std::size_t particleSizeInMemory, std::size_t pixelSize, float availPhysMemoryFraction, 26 | int threadCap ); 27 | 28 | // gets the total physical memory size in bytes. 29 | std::size_t get_total_physical_memory(); 30 | 31 | // Gets the available physical memory size in bytes. 32 | // On OS X the returned value is an estimate. 33 | std::size_t get_available_physical_memory(); 34 | } // namespace krakatoa -------------------------------------------------------------------------------- /Krakatoa/krakatoa/velocity_render_element.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace krakatoa { 12 | 13 | class velocity_render_element : public render_element { 14 | scene_context_ptr m_context; 15 | frantic::graphics::transform4f m_worldToCameraDeriv; 16 | 17 | frantic::channels::channel_const_cvt_accessor m_accessor; 18 | 19 | bool m_doAntialiasing; 20 | bool m_applyMaxVelocity; 21 | float m_maxVelocity; 22 | float m_frameRate; 23 | 24 | public: 25 | velocity_render_element( scene_context_ptr context, bool doAntialiasing, float frameRate, bool applyMaxVelocity, 26 | float maxVelocity ); 27 | virtual ~velocity_render_element(); 28 | 29 | /** 30 | * Sets a constant derivative for world-to-camera matrix. 31 | * This is sort of a hack to add camera motion to the render element. 32 | * The reason this can't be derived from the camera in the scene context is because a) we don't know the motion blur 33 | * duration, b) in cases of no motion blur, there is a zero motion blur duration, and no animation. 34 | */ 35 | void set_world_to_camera_deriv( const frantic::graphics::transform4f& worldToCameraDeriv ); 36 | 37 | /** 38 | * see render_element_interface::clone() 39 | */ 40 | virtual render_element_interface* clone(); 41 | 42 | /** 43 | * see particle_render_element_interface::get_drawing_type() 44 | */ 45 | virtual draw_type get_drawing_type() const; 46 | 47 | /** 48 | * see particle_render_element_interface::set_channel_map() 49 | */ 50 | virtual void set_channel_map( const frantic::channels::channel_map& pcm ); 51 | 52 | /** 53 | * see particle_render_element_interface::add_required_channels() 54 | */ 55 | virtual void add_required_channels( frantic::channels::channel_map& pcm ); 56 | 57 | /** 58 | * see particle_render_element_interface::evaluate() 59 | */ 60 | virtual frantic::graphics::color3f evaluate( const char* particle ); 61 | }; 62 | 63 | } // namespace krakatoa 64 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/voxel_renderer/data_source.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace frantic { 8 | namespace channels { 9 | class channel_map; 10 | } 11 | 12 | namespace logging { 13 | class progress_logger; 14 | } 15 | } // namespace frantic 16 | 17 | namespace krakatoa { 18 | namespace voxel_renderer { 19 | 20 | class slice_coordsys; 21 | class slice_container; 22 | 23 | /** 24 | * Abstract class defining the interface for producing a slice of a voxel field. 25 | */ 26 | class data_source { 27 | public: 28 | typedef boost::shared_ptr coordsys_ptr; 29 | typedef boost::shared_ptr data_ptr; 30 | typedef boost::shared_ptr progress_logger_ptr; 31 | 32 | protected: 33 | progress_logger_ptr m_progressLogger; 34 | 35 | public: 36 | virtual void set_progress_logger( progress_logger_ptr progressLogger ) { m_progressLogger = progressLogger; } 37 | 38 | /** 39 | * @return A reference to the channels available from this object. 40 | */ 41 | virtual const frantic::channels::channel_map& get_channel_map() const = 0; 42 | 43 | /** 44 | * Resets the data source, a provides a new coordinate system in which to produce data. 45 | * @return The min and max slice coordinates for the data contained in this object. 46 | */ 47 | virtual std::pair reset( coordsys_ptr coordSys ) = 0; 48 | 49 | /** 50 | * Fills the supplied container with the data for the current slice of the slice_coordsys provided to the 51 | * last call to reset(). 52 | * @param dataSlice A container to fill with the data stored in this object. 53 | * @return False iff no data was written to the container. True otherwise. 54 | */ 55 | virtual bool do_step( data_ptr dataSlice ) = 0; 56 | }; 57 | 58 | } // namespace voxel_renderer 59 | } // namespace krakatoa 60 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/voxel_renderer/default_filter2f.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace krakatoa { 8 | namespace voxel_renderer { 9 | 10 | /** 11 | * A default two dimensional filter that applies a tensor product of two tent filters of the specified size. 12 | */ 13 | class default_filter2f : public filter2f { 14 | public: 15 | default_filter2f(); 16 | 17 | virtual ~default_filter2f(); 18 | 19 | virtual int get_radius() const; 20 | 21 | virtual void do_filter( frantic::graphics2d::vector2f offset, float outWeights[] ); 22 | }; 23 | 24 | } // namespace voxel_renderer 25 | } // namespace krakatoa 26 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/voxel_renderer/default_filter3f.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace krakatoa { 8 | namespace voxel_renderer { 9 | 10 | /** 11 | * A default three dimensional filter that applies a tensor product of three tent filters of the specified size. 12 | */ 13 | class default_filter3f : public filter3f { 14 | int m_intRadius; 15 | float m_radius; 16 | 17 | public: 18 | default_filter3f( float radius ); 19 | 20 | virtual ~default_filter3f(); 21 | 22 | virtual int get_radius() const; 23 | 24 | virtual void get_weights( frantic::graphics::vector3f offset, float outWeights[] ); 25 | }; 26 | 27 | } // namespace voxel_renderer 28 | } // namespace krakatoa 29 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/voxel_renderer/default_radial_filter3f.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace krakatoa { 8 | namespace voxel_renderer { 9 | 10 | /** 11 | * A three dimensional filter that applies a tent filter to the radial distance from the center of the filter. 12 | */ 13 | class default_radial_filter3f : public filter3f { 14 | int m_intRadius; 15 | float m_radius; 16 | 17 | public: 18 | default_radial_filter3f( float radius ); 19 | 20 | virtual ~default_radial_filter3f(); 21 | 22 | virtual int get_radius() const; 23 | 24 | virtual void get_weights( frantic::graphics::vector3f offset, float outWeights[] ); 25 | }; 26 | 27 | } // namespace voxel_renderer 28 | } // namespace krakatoa 29 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/voxel_renderer/filter2f.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace krakatoa { 8 | namespace voxel_renderer { 9 | 10 | /** 11 | * Abstract interface for a two dimensional filter. 12 | */ 13 | class filter2f { 14 | public: 15 | virtual ~filter2f() {} 16 | 17 | virtual int get_radius() const = 0; 18 | 19 | virtual void do_filter( frantic::graphics2d::vector2f offset, float outWeights[] ) = 0; 20 | }; 21 | 22 | } // namespace voxel_renderer 23 | } // namespace krakatoa 24 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/voxel_renderer/filter3f.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace krakatoa { 8 | namespace voxel_renderer { 9 | 10 | /** 11 | * Abstract interface for a three dimensional filter. 12 | */ 13 | class filter3f { 14 | public: 15 | virtual ~filter3f() {} 16 | 17 | virtual int get_radius() const = 0; 18 | 19 | virtual void get_weights( frantic::graphics::vector3f offset, float outWeights[] ) = 0; 20 | }; 21 | 22 | } // namespace voxel_renderer 23 | } // namespace krakatoa 24 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/voxel_renderer/image_wrapper.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | namespace krakatoa { 6 | namespace voxel_renderer { 7 | 8 | template 9 | class image_wrapper { 10 | frantic::graphics2d::size2 m_size; 11 | PixelType* m_pData; 12 | bool m_ownsData; 13 | 14 | private: 15 | void reset( const frantic::graphics2d::size2 imageSize ) { 16 | if( m_ownsData ) 17 | delete m_pData; 18 | m_size = imageSize; 19 | m_ownsData = true; 20 | m_pData = new PixelType[imageSize.get_area()]; 21 | 22 | // for( int i = 0, iEnd = imageSize.get_area(); i < iEnd; ++i ) 23 | // m_pData[i] = PixelType(); 24 | } 25 | 26 | public: 27 | image_wrapper( const frantic::graphics2d::size2 imageSize ) 28 | : m_ownsData( false ) 29 | , m_pData( NULL ) { 30 | reset( imageSize ); 31 | } 32 | 33 | template 34 | explicit image_wrapper( ImageType& fb ) 35 | : m_size( fb.size() ) 36 | , m_pData( &fb.data()[0] ) 37 | , m_ownsData( false ) {} 38 | 39 | ~image_wrapper() { 40 | if( m_ownsData ) 41 | delete m_pData; 42 | } 43 | 44 | void swap( image_wrapper& rhs ) { 45 | std::swap( m_size, rhs.m_size ); 46 | std::swap( m_pData, rhs.m_pData ); 47 | std::swap( m_ownsData, rhs.m_ownsData ); 48 | } 49 | 50 | frantic::graphics2d::size2 size() const { return m_size; } 51 | int width() const { return m_size.xsize; } 52 | int height() const { return m_size.ysize; } 53 | 54 | void set_pixel( int x, int y, const PixelType& p ) { m_pData[x + m_size.xsize * y] = p; } 55 | 56 | const PixelType& get_pixel( int x, int y ) const { return m_pData[x + m_size.xsize * y]; } 57 | 58 | void blend_over( int x, int y, const PixelType& p ) { m_pData[x + m_size.xsize * y].blend_over( p ); } 59 | 60 | void blend_under( int x, int y, const PixelType& p ) { m_pData[x + m_size.xsize * y].blend_under( p ); } 61 | 62 | void blend_over( const image_wrapper& rhs ) { 63 | for( int i = 0, iEnd = m_size.get_area(); i < iEnd; ++i ) 64 | m_pData[i].blend_over( rhs.m_pData[i] ); 65 | } 66 | 67 | void blend_under( const image_wrapper& rhs ) { 68 | for( int i = 0, iEnd = m_size.get_area(); i < iEnd; ++i ) 69 | m_pData[i].blend_under( rhs.m_pData[i] ); 70 | } 71 | }; 72 | 73 | } // namespace voxel_renderer 74 | } // namespace krakatoa 75 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/voxel_renderer/particle_data_source.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace krakatoa { 9 | namespace voxel_renderer { 10 | 11 | /** 12 | * Implementation of the data_source interface that filters particles onto a voxel field. 13 | */ 14 | class particle_data_source : public data_source { 15 | public: 16 | typedef renderer::particle_container_type particle_type; 17 | 18 | particle_type* m_particles; 19 | particle_type::const_iterator m_curIt, m_endIt; 20 | 21 | boost::shared_ptr m_drawFilter; 22 | 23 | coordsys_ptr m_coordSys; 24 | 25 | bool m_disableThreading; 26 | 27 | float m_mblurTimeSeconds; 28 | 29 | public: 30 | particle_data_source( particle_type& particles, bool disableThreading ); 31 | 32 | void set_draw_filter( filter3f* drawFilter ) { m_drawFilter.reset( drawFilter ); } 33 | 34 | void set_draw_filter( boost::shared_ptr drawFilter ) { m_drawFilter = drawFilter; } 35 | 36 | virtual ~particle_data_source(); 37 | 38 | virtual const frantic::channels::channel_map& get_channel_map() const; 39 | 40 | virtual void set_motion_blur_time( float mblurTimeIntervalCenterSeconds, float mblurTimeIntervalWidthSeconds, 41 | int seed = 42 ); 42 | 43 | virtual std::pair reset( coordsys_ptr coordSys ); 44 | 45 | virtual bool do_step( data_ptr dataSlice ); 46 | }; 47 | 48 | } // namespace voxel_renderer 49 | } // namespace krakatoa 50 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/voxel_renderer/sample.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | // This makes us need to include tbbmalloc.dll with produced binaries. That's not ideal. 8 | //#include 9 | 10 | namespace krakatoa { 11 | namespace voxel_renderer { 12 | 13 | class sample { 14 | const frantic::channels::channel_map* m_pMap; 15 | char* m_data; 16 | 17 | public: 18 | sample() 19 | : m_pMap( NULL ) 20 | , m_data( NULL ) {} 21 | 22 | ~sample() { 23 | if( m_data ) 24 | delete m_data; 25 | // scalable_free( m_data ); 26 | } 27 | 28 | void clear() { memset( m_data, 0, m_pMap->structure_size() ); } 29 | 30 | void reset( const frantic::channels::channel_map& pcm ) { 31 | if( m_data ) 32 | delete m_data; 33 | // scalable_free( m_data ); 34 | m_pMap = &pcm; 35 | m_data = new char[m_pMap->structure_size()]; 36 | // m_data = (char*)scalable_malloc( m_pMap->structure_size() ); 37 | } 38 | 39 | const frantic::channels::channel_map& get_channel_map() const { return *m_pMap; } 40 | 41 | char* get_raw_buffer() { return m_data; } 42 | 43 | const char* get_raw_buffer() const { return m_data; } 44 | 45 | bool has_property( const frantic::tstring& propertyName ) const { return m_pMap->has_channel( propertyName ); } 46 | 47 | template 48 | T& get( const frantic::tstring& propertyName ) { 49 | return m_pMap->get_accessor( propertyName ).get( m_data ); 50 | } 51 | }; 52 | 53 | } // namespace voxel_renderer 54 | } // namespace krakatoa 55 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/voxel_renderer/slice_container_impl.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | namespace krakatoa { 14 | namespace voxel_renderer { 15 | 16 | class slice_container_impl : public slice_container { 17 | frantic::volumetrics::tree_voxel_field2d<5> m_data; 18 | frantic::channels::channel_accessor m_densityAccessor; 19 | frantic::channels::channel_accessor m_emissionAccessor; 20 | frantic::channels::channel_accessor m_bokehBlendInfluenceAccessor; 21 | 22 | boost::scoped_ptr m_newVoxelCallback; 23 | 24 | std::vector> m_copyBlocks; 25 | 26 | public: 27 | slice_container_impl(); 28 | 29 | virtual ~slice_container_impl(); 30 | 31 | virtual void set_new_voxel_callback( new_voxel_callback_interface* newVoxelCallback ); 32 | 33 | virtual void clear(); 34 | 35 | virtual void reset( const frantic::channels::channel_map& dataLayout ); 36 | 37 | virtual bool is_empty() const; 38 | 39 | virtual void construct_sample( frantic::channels::property_map& outSampleStruct ) const; 40 | 41 | virtual void construct_sample( sample& outSampleStruct ) const; 42 | 43 | virtual void get_voxel_indices_for_write( int x, int y, unsigned width, int outIndices[] ); 44 | 45 | virtual void add_to_voxel_by_weight( int index, const frantic::channels::property_map& dataStruct, float weight ); 46 | 47 | virtual bool get_sample( frantic::graphics2d::vector2f pos, sample& outSample ) const; 48 | 49 | virtual void get_voxels_as_particles( frantic::particles::particle_array& outParticles, 50 | const slice_coordsys& coordSys ) const; 51 | }; 52 | 53 | } // namespace voxel_renderer 54 | } // namespace krakatoa 55 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/voxel_renderer/slice_coordsys.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | namespace krakatoa { 9 | namespace voxel_renderer { 10 | 11 | /** 12 | * Abstract class that defines the interface of a coordinate system for a slice of a voxel field. 13 | */ 14 | class slice_coordsys { 15 | public: 16 | /** 17 | * Virtual destructor to support polymorphic deletion 18 | */ 19 | virtual ~slice_coordsys() {} 20 | 21 | /** 22 | * Resets the coordsys to be aligned with the specified camera, and having the specified voxel size. 23 | * @param cameraTM The transformation matrix of the camera object to align the slice_coordsys with. 24 | * @param voxelSize The spacing between voxels in world units. 25 | * @return The slice coordinate of the camera. 26 | */ 27 | virtual int reset( const frantic::graphics::transform4f& cameraTM, float voxelSize ) = 0; 28 | 29 | /** 30 | * Resets the coordsys to be aligned such that a slice maximizes the angle between rays from a camera with 31 | * transformation matrix cameraTM and and a light with the specified TM. 32 | * @param cameraTM The transformation matrix of the camera object to align the slice_coordsys with. 33 | * @param lightTM The transformation matrix of the light object to align the slice_coordsys with. 34 | * @param voxelSize The spacing between voxels in world units. 35 | * @return The slice coordinates of the camera and light respectively. 36 | */ 37 | virtual std::pair reset( const frantic::graphics::transform4f& cameraTM, 38 | const frantic::graphics::transform4f& lightTM, float voxelSize ) = 0; 39 | 40 | /** 41 | * @return True iff the slice_coordsys marches away from the camera with each increase to set_slice_index(). 42 | */ 43 | virtual bool is_forward() const = 0; 44 | 45 | /** 46 | * @param index The slice coordinate to use when transforming to worldspace and vice-versa. 47 | */ 48 | virtual void set_slice_index( int index ) = 0; 49 | 50 | /** 51 | * @return The current slice coordinate 52 | */ 53 | virtual int get_slice_index() const = 0; 54 | 55 | /** 56 | * Intersects a world-space ray with the current slice. 57 | * @param ray The world-space ray to intersect with the slice. 58 | * @return The ray's t-value of the intersection, and the t-value of the ray's intersection with the previous slice. 59 | */ 60 | virtual std::pair intersect_ray_with_slice( const frantic::graphics::ray3f& ray ) const = 0; 61 | 62 | /** 63 | * @return The given point in worldspace, transformed into the slice_coordsys's space. An output Z-coordinate of 0 64 | * is exactly on the slice plane. 65 | */ 66 | virtual frantic::graphics::vector3f transform_from_world( frantic::graphics::vector3f p ) const = 0; 67 | 68 | /** 69 | * @return The given point in slice_coordsys's space, transformed into worldspace. An input Z-coordinate of 0 is 70 | * exactly on the slice plane. 71 | */ 72 | virtual frantic::graphics::vector3f transform_to_world( frantic::graphics::vector3f p ) const = 0; 73 | 74 | /** 75 | * @return The given direction vector in worldspace, transformed into the slice_coordsys's space. 76 | */ 77 | virtual frantic::graphics::vector3f transform_vector_from_world( frantic::graphics::vector3f p ) const = 0; 78 | 79 | /** 80 | * @return The given direction vector in slice_coordsys's space, transformed into worldspace. 81 | */ 82 | virtual frantic::graphics::vector3f transform_vector_to_world( frantic::graphics::vector3f p ) const = 0; 83 | }; 84 | 85 | } // namespace voxel_renderer 86 | } // namespace krakatoa 87 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/voxel_renderer/slice_coordsys_impl.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace krakatoa { 8 | namespace voxel_renderer { 9 | 10 | class slice_coordsys_impl : public slice_coordsys { 11 | frantic::graphics::vector3f m_sliceToWorldAxes[3]; 12 | float m_voxelSize; 13 | int m_currentSlice; 14 | 15 | bool m_isForward; 16 | 17 | public: 18 | slice_coordsys_impl(); 19 | 20 | virtual ~slice_coordsys_impl(); 21 | 22 | virtual int reset( const frantic::graphics::transform4f& cameraTM, float voxelSize ); 23 | 24 | virtual std::pair reset( const frantic::graphics::transform4f& cameraTM, 25 | const frantic::graphics::transform4f& lightTM, float voxelSize ); 26 | 27 | virtual bool is_forward() const; 28 | 29 | virtual void set_slice_index( int index ); 30 | 31 | virtual int get_slice_index() const; 32 | 33 | virtual std::pair intersect_ray_with_slice( const frantic::graphics::ray3f& ray ) const; 34 | 35 | virtual frantic::graphics::vector3f transform_from_world( frantic::graphics::vector3f p ) const; 36 | 37 | virtual frantic::graphics::vector3f transform_to_world( frantic::graphics::vector3f p ) const; 38 | 39 | virtual frantic::graphics::vector3f transform_vector_from_world( frantic::graphics::vector3f p ) const; 40 | 41 | virtual frantic::graphics::vector3f transform_vector_to_world( frantic::graphics::vector3f p ) const; 42 | }; 43 | 44 | } // namespace voxel_renderer 45 | } // namespace krakatoa 46 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/voxel_renderer/voxel_renderer.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | namespace krakatoa { 9 | namespace voxel_renderer { 10 | 11 | // HACK: Compatibility for now. 12 | namespace renderer_mode { 13 | typedef krakatoa::renderer::mode_type::enum_t mode_type; 14 | } 15 | 16 | /** 17 | * A pure virtual class that creates the interface for clients using a krakatoa voxel renderer. 18 | */ 19 | class voxel_renderer : public renderer { 20 | public: 21 | typedef boost::shared_ptr ptr_type; 22 | 23 | protected: 24 | boost::shared_ptr m_particleFilter; 25 | 26 | // Spacing between voxel samples in world units. 27 | float m_voxelSize; 28 | 29 | // Current time in [0,1] within the motion blur sample period. 30 | float m_mblurTime; 31 | 32 | // Width of current sample range for motion [0,1]. Used with jittered motion blur to give a range of times to 33 | // particles. 34 | float m_mblurRange; 35 | 36 | // Flag for enabling depth of field approximation. 37 | bool m_doDOF; 38 | 39 | public: 40 | /** 41 | * Factory function for creating a concrete instance of this interface class. 42 | * @return a new instance of a class implementing this interface. 43 | */ 44 | static voxel_renderer* create_instance(); 45 | 46 | /** 47 | * Default constructor. Sets defaults for various POD members. 48 | */ 49 | voxel_renderer() { 50 | m_voxelSize = 1.f; 51 | m_mblurTime = 0.5f; 52 | m_mblurRange = 0; 53 | m_doDOF = false; 54 | } 55 | 56 | /** 57 | * Virtual destructor to enable polymorphic deletion. 58 | */ 59 | virtual ~voxel_renderer() {} 60 | 61 | void set_particle_filter( boost::shared_ptr theFilter ) { m_particleFilter = theFilter; } 62 | 63 | /** 64 | * @param voxelSize The new size to use for spacing between voxels. 65 | */ 66 | void set_voxel_size( float voxelSize ) { m_voxelSize = voxelSize; } 67 | 68 | /** 69 | * @param renderElement Currently ignored. 70 | */ 71 | virtual void add_render_element( render_element_interface_ptr renderElement ) = 0; 72 | 73 | /** 74 | * Does nothing 75 | */ 76 | virtual void precompute_lighting() = 0; 77 | 78 | /** 79 | * This is the main rendering function. Will use the state specified by all calls to set_XXXX() to render an image 80 | * of the described particles and scene. 81 | * @note You must call at least set_particles() before calling this. 82 | * @param outImage The image to draw the particles to. 83 | */ 84 | virtual void render( renderer::image_type& outImage ) = 0; 85 | }; 86 | 87 | typedef voxel_renderer::ptr_type voxel_renderer_ptr; 88 | 89 | } // namespace voxel_renderer 90 | } // namespace krakatoa 91 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/watermark.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | namespace krakatoa { 9 | 10 | /** 11 | * Function for watermarking output bitmaps 12 | */ 13 | void apply_krakatoa_watermark( frantic::graphics2d::framebuffer& framebuffer, 14 | const frantic::graphics::color3f& watermarkColor ); 15 | 16 | /** 17 | * NULL function passed to renderer for not watermarking bitmaps 18 | */ 19 | inline void null_watermark( frantic::graphics2d::framebuffer& /*framebuffer*/ ) { return; } 20 | 21 | /** 22 | * Checks for a common hacking technique that cut out the code that added the watermark. 23 | * This function checks if the watermark function has been removed using the same binary hack. 24 | * There was a crack on cgpersia released on July 26, 2013 that cut out the watermark function. 25 | * All versions of Krakatoa should run this function to ensure that that crack can no longer be used. 26 | * @return If it has been hacked. 27 | */ 28 | bool check_for_watermark_crack(); 29 | 30 | } // namespace krakatoa 31 | -------------------------------------------------------------------------------- /Krakatoa/krakatoa/zdepth_render_element.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace krakatoa { 12 | 13 | class zdepth_render_element : public render_element { 14 | scene_context_ptr m_context; 15 | 16 | frantic::channels::channel_const_cvt_accessor m_accessor; 17 | 18 | bool m_doAntialiasing; 19 | bool m_applyDepthRange; 20 | float m_minDepth; 21 | float m_maxDepth; 22 | 23 | public: 24 | zdepth_render_element( scene_context_ptr context, bool doAntialiasing, bool applyDepthRange, float minDepth, 25 | float maxDepth ); 26 | virtual ~zdepth_render_element(); 27 | 28 | /** 29 | * see render_element_interface::clone() 30 | */ 31 | virtual render_element_interface* clone(); 32 | 33 | /** 34 | * see render_element_interface::commit() 35 | */ 36 | virtual void commit(); 37 | 38 | /** 39 | * see particle_render_element_interface::get_drawing_type() 40 | */ 41 | virtual draw_type get_drawing_type() const; 42 | 43 | /** 44 | * see particle_render_element_interface::set_channel_map() 45 | */ 46 | virtual void set_channel_map( const frantic::channels::channel_map& pcm ); 47 | 48 | /** 49 | * see particle_render_element_interface::add_required_channels() 50 | */ 51 | virtual void add_required_channels( frantic::channels::channel_map& pcm ); 52 | 53 | /** 54 | * see particle_render_element_interface::evaluate() 55 | */ 56 | virtual frantic::graphics::color3f evaluate( const char* particle ); 57 | 58 | /** 59 | * When compositing multiple images (eg. for motion blur), the minimum value should be used. 60 | * This is required for compositing z-depth. 61 | */ 62 | virtual inline bool use_minimize_compositing() { return true; } 63 | 64 | virtual void combine( render_element_interface* rhs ); 65 | }; 66 | 67 | } // namespace krakatoa 68 | -------------------------------------------------------------------------------- /Krakatoa/src/camera_manager.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #include "stdafx.h" 4 | 5 | #include 6 | 7 | namespace krakatoa { 8 | 9 | camera_manager::camera_manager() 10 | : m_cameras( 1 ) {} 11 | 12 | camera_manager::camera_manager( const frantic::graphics::camera& camera ) { m_cameras.push_back( camera ); } 13 | 14 | camera_manager::camera_manager( const std::vector>& cameraList ) { 15 | m_cameras = cameraList; 16 | } 17 | 18 | frantic::graphics::camera& camera_manager::get_current_camera() { return m_cameras.at( 0 ); } 19 | 20 | const frantic::graphics::camera& camera_manager::get_current_camera() const { return m_cameras.at( 0 ); } 21 | 22 | } // namespace krakatoa 23 | -------------------------------------------------------------------------------- /Krakatoa/src/channel_render_element.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #include "stdafx.h" 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | using namespace frantic::graphics; 12 | using namespace krakatoa; 13 | 14 | channel_render_element::channel_render_element( bool antiAlias, const frantic::tstring& channelName, 15 | frantic::channels::data_type_t type, std::size_t arity, 16 | const frantic::graphics::color3f& def ) 17 | : m_antiAlias( antiAlias ) 18 | , m_channelName( channelName ) 19 | , m_type( type ) 20 | , m_arity( arity ) 21 | , m_default( def ) {} 22 | 23 | channel_render_element::~channel_render_element() {} 24 | 25 | render_element_interface* channel_render_element::clone() { 26 | std::unique_ptr pResult( 27 | new channel_render_element( m_antiAlias, m_channelName, m_type, m_arity, m_default ) ); 28 | 29 | pResult->m_accessor = m_accessor; 30 | pResult->m_outputMap = m_outputMap; 31 | 32 | pResult->get_framebuffer().set_size( get_framebuffer().size() ); 33 | pResult->get_framebuffer().fill( frantic::graphics::color6f( 0.f ) ); 34 | 35 | return pResult.release(); 36 | } 37 | 38 | krakatoa::particle_render_element_interface::draw_type channel_render_element::get_drawing_type() const { 39 | if( m_antiAlias ) { 40 | return draw_type_antialias; 41 | } else { 42 | return draw_type_solid; 43 | } 44 | } 45 | 46 | void channel_render_element::set_channel_map( const frantic::channels::channel_map& pcm ) { 47 | m_outputMap = pcm; 48 | if( m_outputMap.has_channel( m_channelName ) ) { 49 | m_accessor = pcm.get_const_cvt_accessor( m_channelName ); 50 | } else { 51 | m_accessor = frantic::channels::channel_const_cvt_accessor( m_default ); 52 | } 53 | } 54 | 55 | void channel_render_element::add_required_channels( frantic::channels::channel_map& pcm ) { 56 | if( !pcm.has_channel( m_channelName ) ) { 57 | pcm.define_channel( m_channelName, m_arity, m_type ); 58 | } 59 | } 60 | 61 | frantic::graphics::color3f channel_render_element::evaluate( const char* particle ) { 62 | return m_accessor.get( particle ); 63 | } -------------------------------------------------------------------------------- /Krakatoa/src/diffuse_render_element.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #include "stdafx.h" 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | namespace krakatoa { 12 | 13 | diffuse_render_element::diffuse_render_element() {} 14 | 15 | diffuse_render_element::~diffuse_render_element() {} 16 | 17 | render_element_interface* diffuse_render_element::clone() { 18 | std::unique_ptr pResult( new diffuse_render_element ); 19 | pResult->get_framebuffer().set_size( get_framebuffer().size() ); 20 | pResult->m_accessor = m_accessor; 21 | 22 | return pResult.release(); 23 | } 24 | 25 | // From particle_render_element_interface 26 | 27 | diffuse_render_element::draw_type diffuse_render_element::get_drawing_type() const { return draw_type_shader; } 28 | 29 | void diffuse_render_element::set_channel_map( const frantic::channels::channel_map& pcm ) { 30 | m_accessor = pcm.get_const_cvt_accessor( _T("__Element_Diffuse") ); 31 | } 32 | 33 | void diffuse_render_element::add_required_channels( frantic::channels::channel_map& pcm ) { 34 | if( !pcm.has_channel( _T("__Element_Diffuse") ) ) 35 | pcm.define_channel( _T("__Element_Diffuse") ); 36 | } 37 | 38 | frantic::graphics::color3f diffuse_render_element::evaluate( const char* particle ) { 39 | return m_accessor.get( particle ); 40 | } 41 | 42 | } // namespace krakatoa 43 | -------------------------------------------------------------------------------- /Krakatoa/src/emission_render_element.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #include "stdafx.h" 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | namespace krakatoa { 12 | 13 | emission_render_element::emission_render_element() {} 14 | 15 | emission_render_element::~emission_render_element() {} 16 | 17 | render_element_interface* emission_render_element::clone() { 18 | std::unique_ptr pResult( new emission_render_element ); 19 | pResult->get_framebuffer().set_size( get_framebuffer().size() ); 20 | pResult->m_accessor = m_accessor; 21 | 22 | return pResult.release(); 23 | } 24 | 25 | // From particle_render_element_interface 26 | 27 | emission_render_element::draw_type emission_render_element::get_drawing_type() const { return draw_type_normal; } 28 | 29 | void emission_render_element::set_channel_map( const frantic::channels::channel_map& pcm ) { 30 | m_accessor = pcm.get_const_cvt_accessor( _T("Emission") ); 31 | } 32 | 33 | void emission_render_element::add_required_channels( frantic::channels::channel_map& pcm ) { 34 | if( !pcm.has_channel( _T("Emission") ) ) 35 | pcm.define_channel( _T("Emission") ); 36 | } 37 | 38 | frantic::graphics::color3f emission_render_element::evaluate( const char* particle ) { 39 | return m_accessor.get( particle ); 40 | } 41 | 42 | } // namespace krakatoa 43 | -------------------------------------------------------------------------------- /Krakatoa/src/light_render_element.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #include "stdafx.h" 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | namespace krakatoa { 12 | 13 | light_render_element::light_render_element( const frantic::tstring& lightName, const frantic::tstring& internalName ) 14 | : m_lightName( lightName ) 15 | , m_internalName( _T("__Element_") + internalName ) {} 16 | 17 | light_render_element::~light_render_element() {} 18 | 19 | const frantic::tstring& light_render_element::get_light_name() const { return m_lightName; } 20 | 21 | const frantic::tstring& light_render_element::get_channel_name() const { return m_internalName; } 22 | 23 | render_element_interface* light_render_element::clone() { 24 | std::unique_ptr pResult( new light_render_element( m_lightName, m_internalName ) ); 25 | pResult->get_framebuffer().set_size( get_framebuffer().size() ); 26 | pResult->m_accessor = m_accessor; 27 | 28 | return pResult.release(); 29 | } 30 | 31 | void light_render_element::commit() { render_element::commit(); } 32 | 33 | // From particle_render_element_interface 34 | 35 | light_render_element::draw_type light_render_element::get_drawing_type() const { return draw_type_shader; } 36 | 37 | void light_render_element::set_channel_map( const frantic::channels::channel_map& pcm ) { 38 | m_accessor = pcm.get_const_cvt_accessor( m_internalName ); 39 | } 40 | 41 | void light_render_element::add_required_channels( frantic::channels::channel_map& pcm ) { 42 | if( !pcm.has_channel( m_internalName ) ) 43 | pcm.define_channel( m_internalName, 3, frantic::channels::data_type_float16 ); 44 | } 45 | 46 | frantic::graphics::color3f light_render_element::evaluate( const char* particle ) { return m_accessor.get( particle ); } 47 | 48 | } // namespace krakatoa 49 | -------------------------------------------------------------------------------- /Krakatoa/src/matte_zdepth_render_element.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #include "stdafx.h" 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | namespace krakatoa { 12 | 13 | matte_zdepth_render_element::matte_zdepth_render_element( bool applyDepthRange, float minDepth, float maxDepth ) 14 | : m_applyDepthRange( applyDepthRange ) 15 | , m_minDepth( minDepth ) 16 | , m_maxDepth( maxDepth ) {} 17 | 18 | matte_zdepth_render_element::~matte_zdepth_render_element() {} 19 | 20 | frantic::rendering::depthbuffer_singleface& matte_zdepth_render_element::get_depthbuffer() { return m_depthBuffer; } 21 | 22 | frantic::graphics2d::framebuffer& matte_zdepth_render_element::get_framebuffer() { 23 | throw std::runtime_error( "MatteZDepth render elements do not have a color6f framebuffer" ); 24 | } 25 | 26 | render_element_interface* matte_zdepth_render_element::clone() { 27 | std::unique_ptr pResult( 28 | new matte_zdepth_render_element( m_applyDepthRange, m_minDepth, m_maxDepth ) ); 29 | pResult->get_depthbuffer().set_size( get_depthbuffer().size() ); 30 | 31 | return pResult.release(); 32 | } 33 | 34 | void matte_zdepth_render_element::initialize() { get_depthbuffer().clear(); } 35 | 36 | void matte_zdepth_render_element::commit() { 37 | if( m_applyDepthRange ) 38 | get_depthbuffer().normalize_values( m_minDepth, m_maxDepth ); 39 | 40 | render_element::commit(); 41 | } 42 | 43 | } // namespace krakatoa 44 | -------------------------------------------------------------------------------- /Krakatoa/src/normal_render_element.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #include "stdafx.h" 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | namespace krakatoa { 12 | 13 | normal_render_element::normal_render_element( scene_context_ptr context, bool doAntialiasing, bool doScaling ) 14 | : m_doAntialiasing( doAntialiasing ) 15 | , m_context( context ) 16 | , m_doScaling( doScaling ) {} 17 | 18 | normal_render_element::~normal_render_element() {} 19 | 20 | render_element_interface* normal_render_element::clone() { 21 | std::unique_ptr pResult( 22 | new normal_render_element( m_context, m_doAntialiasing, m_doScaling ) ); 23 | pResult->get_framebuffer().set_size( get_framebuffer().size() ); 24 | pResult->m_accessor = m_accessor; 25 | 26 | return pResult.release(); 27 | } 28 | 29 | // From particle_render_element_interface 30 | 31 | normal_render_element::draw_type normal_render_element::get_drawing_type() const { 32 | if( m_doAntialiasing ) 33 | return draw_type_antialias; 34 | else 35 | return draw_type_solid; 36 | } 37 | 38 | void normal_render_element::set_channel_map( const frantic::channels::channel_map& pcm ) { 39 | m_accessor = pcm.get_const_cvt_accessor( _T("Normal") ); 40 | } 41 | 42 | void normal_render_element::add_required_channels( frantic::channels::channel_map& pcm ) { 43 | if( !pcm.has_channel( _T("Normal") ) ) 44 | pcm.define_channel( _T("Normal"), 3, frantic::channels::data_type_float16 ); 45 | } 46 | 47 | frantic::graphics::color3f normal_render_element::evaluate( const char* particle ) { 48 | frantic::graphics::vector3f camSpaceNorm = m_accessor.get( particle ); 49 | camSpaceNorm = frantic::graphics::vector3f::normalize( camSpaceNorm ); 50 | // camSpaceNorm = m_context->get_camera().world_transform().transpose_transform_no_translation( camSpaceNorm ); 51 | 52 | if( m_doScaling ) { 53 | // Scale the normal into viewable range [0,1] from the range [-1,1]. 54 | camSpaceNorm.x = frantic::math::clamp( camSpaceNorm.x * 0.5f + 0.5f, 0.f, 1.f ); 55 | camSpaceNorm.y = frantic::math::clamp( camSpaceNorm.y * 0.5f + 0.5f, 0.f, 1.f ); 56 | camSpaceNorm.z = frantic::math::clamp( camSpaceNorm.z * 0.5f + 0.5f, 0.f, 1.f ); 57 | } 58 | 59 | return frantic::graphics::color3f( camSpaceNorm.x, camSpaceNorm.y, camSpaceNorm.z ); 60 | } 61 | 62 | } // namespace krakatoa 63 | -------------------------------------------------------------------------------- /Krakatoa/src/occluded_layer_render_element.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #include "stdafx.h" 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | namespace krakatoa { 12 | 13 | occluded_layer_render_element::occluded_layer_render_element() {} 14 | 15 | occluded_layer_render_element::~occluded_layer_render_element() {} 16 | 17 | render_element_interface* occluded_layer_render_element::clone() { 18 | std::unique_ptr pResult( new occluded_layer_render_element ); 19 | pResult->get_framebuffer().set_size( get_framebuffer().size() ); 20 | 21 | return pResult.release(); 22 | } 23 | 24 | } // namespace krakatoa 25 | -------------------------------------------------------------------------------- /Krakatoa/src/shader_render_element .cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #include "stdafx.h" 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | namespace krakatoa { 12 | 13 | shader_render_element::shader_render_element( const frantic::tstring& elementName ) 14 | : m_elementName( elementName ) {} 15 | 16 | shader_render_element::~shader_render_element() {} 17 | 18 | render_element_interface* shader_render_element::clone() { 19 | std::unique_ptr pResult( new shader_render_element( m_elementName ) ); 20 | pResult->get_framebuffer().set_size( get_framebuffer().size() ); 21 | pResult->m_accessor = m_accessor; 22 | 23 | return pResult.release(); 24 | } 25 | 26 | // From particle_render_element_interface 27 | 28 | shader_render_element::draw_type shader_render_element::get_drawing_type() const { return draw_type_shader; } 29 | 30 | void shader_render_element::set_channel_map( const frantic::channels::channel_map& pcm ) { 31 | m_accessor = pcm.get_const_cvt_accessor( _T("__Element_") + m_elementName ); 32 | } 33 | 34 | void shader_render_element::add_required_channels( frantic::channels::channel_map& pcm ) { 35 | if( !pcm.has_channel( _T("__Element_") + m_elementName ) ) 36 | pcm.define_channel( _T("__Element_") + m_elementName ); 37 | } 38 | 39 | frantic::graphics::color3f shader_render_element::evaluate( const char* particle ) { 40 | return m_accessor.get( particle ); 41 | } 42 | 43 | } // namespace krakatoa 44 | -------------------------------------------------------------------------------- /Krakatoa/src/shared_object.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #include "stdafx.h" 4 | 5 | #include 6 | 7 | namespace krakatoa { 8 | 9 | shared_object::shared_object() 10 | : m_refCount( 0 ) {} 11 | 12 | shared_object::~shared_object() {} 13 | 14 | void intrusive_ptr_add_ref( shared_object* pObj ) { ++pObj->m_refCount; } 15 | 16 | void intrusive_ptr_release( shared_object* pObj ) { 17 | if( --pObj->m_refCount == 0 ) 18 | delete pObj; 19 | } 20 | 21 | } // namespace krakatoa 22 | -------------------------------------------------------------------------------- /Krakatoa/src/specular_render_element.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #include "stdafx.h" 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | namespace krakatoa { 12 | 13 | specular_render_element::specular_render_element() {} 14 | 15 | specular_render_element::~specular_render_element() {} 16 | 17 | render_element_interface* specular_render_element::clone() { 18 | std::unique_ptr pResult( new specular_render_element ); 19 | pResult->get_framebuffer().set_size( get_framebuffer().size() ); 20 | pResult->m_accessor = m_accessor; 21 | 22 | return pResult.release(); 23 | } 24 | 25 | // From particle_render_element_interface 26 | 27 | specular_render_element::draw_type specular_render_element::get_drawing_type() const { return draw_type_shader; } 28 | 29 | void specular_render_element::set_channel_map( const frantic::channels::channel_map& pcm ) { 30 | m_accessor = pcm.get_const_cvt_accessor( _T("__Element_Specular") ); 31 | } 32 | 33 | void specular_render_element::add_required_channels( frantic::channels::channel_map& pcm ) { 34 | if( !pcm.has_channel( _T("__Element_Specular") ) ) 35 | pcm.define_channel( _T("__Element_Specular") ); 36 | } 37 | 38 | frantic::graphics::color3f specular_render_element::evaluate( const char* particle ) { 39 | return m_accessor.get( particle ); 40 | } 41 | 42 | } // namespace krakatoa 43 | -------------------------------------------------------------------------------- /Krakatoa/src/tangent_render_element.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #include "stdafx.h" 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | namespace krakatoa { 12 | 13 | tangent_render_element::tangent_render_element( scene_context_ptr context, bool doAntialiasing ) 14 | : m_doAntialiasing( doAntialiasing ) 15 | , m_context( context ) {} 16 | 17 | tangent_render_element::~tangent_render_element() {} 18 | 19 | render_element_interface* tangent_render_element::clone() { 20 | std::unique_ptr pResult( new tangent_render_element( m_context, m_doAntialiasing ) ); 21 | pResult->get_framebuffer().set_size( get_framebuffer().size() ); 22 | pResult->m_accessor = m_accessor; 23 | 24 | return pResult.release(); 25 | } 26 | 27 | // From particle_render_element_interface 28 | 29 | tangent_render_element::draw_type tangent_render_element::get_drawing_type() const { 30 | if( m_doAntialiasing ) 31 | return draw_type_antialias; 32 | else 33 | return draw_type_solid; 34 | } 35 | 36 | void tangent_render_element::set_channel_map( const frantic::channels::channel_map& pcm ) { 37 | m_accessor = pcm.get_const_cvt_accessor( _T("Tangent") ); 38 | } 39 | 40 | void tangent_render_element::add_required_channels( frantic::channels::channel_map& pcm ) { 41 | if( !pcm.has_channel( _T("Tangent") ) ) 42 | pcm.define_channel( _T("Tangent") ); 43 | } 44 | 45 | frantic::graphics::color3f tangent_render_element::evaluate( const char* particle ) { 46 | frantic::graphics::vector3f camSpaceTangent = m_accessor.get( particle ); 47 | camSpaceTangent = frantic::graphics::vector3f::normalize( camSpaceTangent ); 48 | camSpaceTangent = m_context->get_camera().world_transform().transpose_transform_no_translation( camSpaceTangent ); 49 | 50 | // Scale the normal into viewable range [0,1] from the range [-1,1]. 51 | camSpaceTangent.x = frantic::math::clamp( camSpaceTangent.x * 0.5f + 0.5f, 0.f, 1.f ); 52 | camSpaceTangent.y = frantic::math::clamp( camSpaceTangent.y * 0.5f + 0.5f, 0.f, 1.f ); 53 | camSpaceTangent.z = frantic::math::clamp( camSpaceTangent.z * 0.5f + 0.5f, 0.f, 1.f ); 54 | 55 | return frantic::graphics::color3f( camSpaceTangent.x, camSpaceTangent.y, camSpaceTangent.z ); 56 | } 57 | 58 | } // namespace krakatoa 59 | -------------------------------------------------------------------------------- /Krakatoa/src/velocity_render_element.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #include "stdafx.h" 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | namespace krakatoa { 12 | 13 | velocity_render_element::velocity_render_element( scene_context_ptr context, bool doAntialiasing, float frameRate, 14 | bool applyMaxVelocity, float maxVelocity ) 15 | : m_doAntialiasing( doAntialiasing ) 16 | , m_frameRate( frameRate ) 17 | , m_applyMaxVelocity( applyMaxVelocity ) 18 | , m_maxVelocity( maxVelocity ) 19 | , m_context( context ) { 20 | m_worldToCameraDeriv.set_to_zero(); 21 | } 22 | 23 | velocity_render_element::~velocity_render_element() {} 24 | 25 | void velocity_render_element::set_world_to_camera_deriv( const frantic::graphics::transform4f& worldToCameraDeriv ) { 26 | m_worldToCameraDeriv = worldToCameraDeriv; 27 | } 28 | 29 | render_element_interface* velocity_render_element::clone() { 30 | std::unique_ptr pResult( 31 | new velocity_render_element( m_context, m_doAntialiasing, m_frameRate, m_applyMaxVelocity, m_maxVelocity ) ); 32 | pResult->get_framebuffer().set_size( get_framebuffer().size() ); 33 | pResult->m_accessor = m_accessor; 34 | 35 | return pResult.release(); 36 | } 37 | 38 | // From particle_render_element_interface 39 | 40 | velocity_render_element::draw_type velocity_render_element::get_drawing_type() const { 41 | if( m_doAntialiasing ) 42 | return draw_type_antialias; 43 | else 44 | return draw_type_solid; 45 | } 46 | 47 | void velocity_render_element::set_channel_map( const frantic::channels::channel_map& pcm ) { 48 | m_accessor = pcm.get_const_cvt_accessor( _T("Velocity") ); 49 | } 50 | 51 | void velocity_render_element::add_required_channels( frantic::channels::channel_map& pcm ) { 52 | if( !pcm.has_channel( _T("Velocity") ) ) 53 | pcm.define_channel( _T("Velocity") ); 54 | } 55 | 56 | frantic::graphics::color3f velocity_render_element::evaluate( const char* particle ) { 57 | frantic::graphics::vector3f camSpaceVel = 58 | m_context->get_camera().world_transform_inverse().transform_no_translation( m_accessor.get( particle ) ); 59 | camSpaceVel += m_worldToCameraDeriv * camSpaceVel; 60 | 61 | // Convert from units/second to units/frame 62 | camSpaceVel /= m_frameRate; 63 | 64 | // If we have a max velocity assigned we can adjust the velocity into a visible color range ie. [0,1]. 65 | if( m_applyMaxVelocity ) { 66 | float maxVelocityRange = 2.f * m_maxVelocity; 67 | camSpaceVel.x = frantic::math::clamp( camSpaceVel.x / maxVelocityRange + 0.5f, 0.f, 1.f ); 68 | camSpaceVel.y = frantic::math::clamp( camSpaceVel.y / maxVelocityRange + 0.5f, 0.f, 1.f ); 69 | camSpaceVel.z = frantic::math::clamp( camSpaceVel.z / maxVelocityRange + 0.5f, 0.f, 1.f ); 70 | } 71 | 72 | return frantic::graphics::color3f( camSpaceVel.x, camSpaceVel.y, camSpaceVel.z ); 73 | } 74 | 75 | } // namespace krakatoa 76 | -------------------------------------------------------------------------------- /Krakatoa/src/voxel_renderer/default_filter2f.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #include "stdafx.h" 4 | 5 | #include 6 | 7 | namespace krakatoa { 8 | namespace voxel_renderer { 9 | 10 | default_filter2f::default_filter2f() {} 11 | 12 | default_filter2f::~default_filter2f() {} 13 | 14 | int default_filter2f::get_radius() const { return 1; } 15 | 16 | void default_filter2f::do_filter( frantic::graphics2d::vector2f offset, float outWeights[] ) { 17 | float prod = offset.x * offset.y; 18 | 19 | outWeights[0] = 1.f - offset.x - offset.y + prod; 20 | outWeights[1] = offset.x - prod; 21 | outWeights[2] = offset.y - prod; 22 | outWeights[3] = prod; 23 | 24 | /* 25 | outWeights[0] = (1.f - offset.x) * (1.f - offset.y); 26 | outWeights[1] = offset.x * (1.f - offset.y); 27 | outWeights[2] = (1.f - offset.x) * offset.y; 28 | outWeights[3] = offset.x * offset.y; 29 | */ 30 | } 31 | 32 | } // namespace voxel_renderer 33 | } // namespace krakatoa 34 | -------------------------------------------------------------------------------- /Krakatoa/src/voxel_renderer/default_filter3f.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #include "stdafx.h" 4 | 5 | #include 6 | 7 | namespace krakatoa { 8 | namespace voxel_renderer { 9 | 10 | default_filter3f::default_filter3f( float radius ) { 11 | m_radius = radius; 12 | m_intRadius = (int)ceilf( m_radius ); 13 | } 14 | 15 | default_filter3f::~default_filter3f() {} 16 | 17 | int default_filter3f::get_radius() const { return m_intRadius; } 18 | 19 | void default_filter3f::get_weights( frantic::graphics::vector3f offset, float outWeights[] ) { 20 | float* weights = outWeights; 21 | float weightZ = m_radius - fabsf( offset.z ); 22 | 23 | // Compensate to ensure total weight == 1.0 24 | // int(-r,r){r - |x-a|}dx = int(-r,0){r+x-a}dx + int(0,r){r-x+a}dx 25 | // = (rx+xx/2-ax)|-r,0 + (rx-xx/2+ax)|0,r 26 | // = rr-rr/2-ar + rr-rr/2+ar 27 | // = rr 28 | float denom = m_radius * m_radius; 29 | denom *= denom * denom; 30 | 31 | for( int y = -m_intRadius + 1; y <= m_intRadius; ++y ) { 32 | float weightYZ = ( m_radius - fabsf( (float)y - offset.y ) ) * weightZ; 33 | 34 | for( int x = -m_intRadius + 1; x <= m_intRadius; ++x, ++weights ) { 35 | float weightXYZ = ( m_radius - fabsf( (float)x - offset.x ) ) * weightYZ; 36 | 37 | *weights = weightXYZ / denom; 38 | } 39 | } 40 | } 41 | 42 | } // namespace voxel_renderer 43 | } // namespace krakatoa 44 | -------------------------------------------------------------------------------- /Krakatoa/src/voxel_renderer/default_radial_filter3f.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #include "stdafx.h" 4 | 5 | #include 6 | 7 | namespace krakatoa { 8 | namespace voxel_renderer { 9 | 10 | default_radial_filter3f::default_radial_filter3f( float radius ) { 11 | m_radius = radius; 12 | m_intRadius = (int)ceilf( m_radius ); 13 | } 14 | 15 | default_radial_filter3f::~default_radial_filter3f() {} 16 | 17 | int default_radial_filter3f::get_radius() const { return m_intRadius; } 18 | 19 | void default_radial_filter3f::get_weights( frantic::graphics::vector3f offset, float outWeights[] ) { 20 | float* weights = outWeights; 21 | 22 | float distZ2 = offset.z * offset.z; 23 | float denom = m_radius * m_radius; 24 | 25 | for( int y = -m_intRadius + 1; y <= m_intRadius; ++y ) { 26 | 27 | float distY = (float)y - offset.y; 28 | float distY2 = distY * distY; 29 | 30 | for( int x = -m_intRadius + 1; x <= m_intRadius; ++x, ++weights ) { 31 | 32 | float distX = (float)x - offset.x; 33 | float distX2 = distX * distX; 34 | 35 | float d = m_radius - sqrtf( distX2 + distY2 + distZ2 ); 36 | if( d > 0 ) 37 | *weights = d / denom; 38 | else 39 | *weights = 0; 40 | } 41 | } 42 | } 43 | 44 | } // namespace voxel_renderer 45 | } // namespace krakatoa 46 | -------------------------------------------------------------------------------- /Krakatoa/src/zdepth_render_element.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #include "stdafx.h" 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | namespace krakatoa { 13 | 14 | zdepth_render_element::zdepth_render_element( scene_context_ptr context, bool doAntialiasing, bool applyDepthRange, 15 | float minDepth, float maxDepth ) 16 | : m_doAntialiasing( doAntialiasing ) 17 | , m_applyDepthRange( applyDepthRange ) 18 | , m_minDepth( minDepth ) 19 | , m_maxDepth( maxDepth ) 20 | , m_context( context ) {} 21 | 22 | zdepth_render_element::~zdepth_render_element() {} 23 | 24 | render_element_interface* zdepth_render_element::clone() { 25 | std::unique_ptr pResult( 26 | new zdepth_render_element( m_context, m_doAntialiasing, m_applyDepthRange, m_minDepth, m_maxDepth ) ); 27 | pResult->get_framebuffer().set_size( get_framebuffer().size() ); 28 | pResult->m_accessor = m_accessor; 29 | 30 | return pResult.release(); 31 | } 32 | 33 | void zdepth_render_element::commit() { 34 | if( !m_applyDepthRange ) { 35 | const float epsilon = 0.000001f; 36 | const float oneMinusEpsilon = 1.0f - epsilon; 37 | 38 | // This is a work-around for a numeric instability issues when trying to apply float::max to alpha blending 39 | // It simply sets any non-opaque pixels' depth to float::max, rather than trying to blend the values together 40 | for( size_t i = 0; i < get_framebuffer().data().size(); ++i ) { 41 | frantic::graphics::color6f currentColor = get_framebuffer().data()[i]; 42 | if( currentColor.alpha().ar < oneMinusEpsilon || currentColor.alpha().ag < oneMinusEpsilon || 43 | currentColor.alpha().ab < oneMinusEpsilon ) { 44 | get_framebuffer().data()[i].color() = frantic::graphics::color3f( std::numeric_limits::max() ); 45 | } 46 | } 47 | } else { 48 | get_framebuffer().fill_under( frantic::graphics::color6f( 1.f ) ); 49 | } 50 | 51 | render_element::commit(); 52 | } 53 | 54 | // From particle_render_element_interface 55 | 56 | zdepth_render_element::draw_type zdepth_render_element::get_drawing_type() const { 57 | if( m_doAntialiasing ) 58 | return draw_type_antialias; 59 | else 60 | return draw_type_solid; 61 | } 62 | 63 | void zdepth_render_element::set_channel_map( const frantic::channels::channel_map& pcm ) { 64 | m_accessor = pcm.get_const_cvt_accessor( _T("Position") ); 65 | } 66 | 67 | void zdepth_render_element::add_required_channels( frantic::channels::channel_map& pcm ) { 68 | if( !pcm.has_channel( _T("Position") ) ) 69 | pcm.define_channel( _T("Position") ); 70 | } 71 | 72 | frantic::graphics::color3f zdepth_render_element::evaluate( const char* particle ) { 73 | float zDepth = -( ( m_context->get_camera().world_transform_inverse() * m_accessor.get( particle ) ).z ); 74 | 75 | if( m_applyDepthRange ) { 76 | if( zDepth < m_minDepth ) 77 | zDepth = m_minDepth; 78 | else if( zDepth > m_maxDepth ) 79 | zDepth = m_maxDepth; 80 | 81 | zDepth = ( zDepth - m_minDepth ) / ( m_maxDepth - m_minDepth ); 82 | } 83 | 84 | return frantic::graphics::color3f( zDepth ); 85 | } 86 | 87 | void zdepth_render_element::combine( render_element_interface* rhs ) { 88 | get_framebuffer().apply_function( rhs->get_framebuffer(), min_color6f() ); 89 | } 90 | 91 | } // namespace krakatoa 92 | -------------------------------------------------------------------------------- /Krakatoa/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // stdafx.cpp : source file that includes just the standard includes 4 | // Krakatoa.pch will be the pre-compiled header 5 | // stdafx.obj will contain the pre-compiled type information 6 | 7 | #include "stdafx.h" 8 | 9 | // TODO: reference any additional headers you need in STDAFX.H 10 | // and not in this file 11 | -------------------------------------------------------------------------------- /Krakatoa/stdafx.h: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // stdafx.h : include file for standard system include files, 4 | // or project specific include files that are used frequently, but 5 | // are changed infrequently 6 | // 7 | 8 | #pragma once 9 | 10 | #ifdef _WIN32 11 | 12 | #ifndef WIN32_LEAN_AND_MEAN 13 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 14 | #endif 15 | #ifndef NOMINMAX 16 | #define NOMINMAX 17 | #endif 18 | 19 | #include 20 | 21 | #endif 22 | 23 | // TODO: reference additional headers your program requires here 24 | -------------------------------------------------------------------------------- /KrakatoaSR/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | # SPDX-License-Identifier: Apache-2.0 3 | cmake_minimum_required( VERSION 3.15 FATAL_ERROR ) 4 | 5 | project( KrakatoaSR ) 6 | 7 | find_package( thinkboxcmlibrary REQUIRED ) 8 | include( PrecompiledHeader ) 9 | include( ThinkboxCMLibrary ) 10 | 11 | option( LIBRARY_TYPE "Either SHARED or STATIC" SHARED ) 12 | option( BUILD_EXAMPLES "Build the KrakatoaSR examples" OFF ) 13 | 14 | add_library( krakatoasr ${LIBRARY_TYPE} ) 15 | 16 | set_property( TARGET krakatoasr PROPERTY CXX_STANDARD 17 ) 17 | 18 | target_include_directories( krakatoasr PUBLIC 19 | $ 20 | $ 21 | ) 22 | 23 | file( GLOB_RECURSE H_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 24 | "include/*.h" 25 | "include/*.hpp" 26 | ) 27 | 28 | file( GLOB_RECURSE CXX_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 29 | "src/*.cpp" 30 | ) 31 | 32 | target_sources( krakatoasr PRIVATE 33 | stdafx.cpp 34 | stdafx.h 35 | ${H_FILES} 36 | ${CXX_FILES} 37 | ) 38 | 39 | if( ${LIBRARY_TYPE} STREQUAL "STATIC" ) 40 | target_compile_definitions( krakatoasr PUBLIC KSR_STATIC ) 41 | else() 42 | # The Conan version of Boost was built with this, and it changes the library names. 43 | # As a result, we need to set this to tell Boost to look for the right libraries to 44 | # link against. 45 | target_compile_definitions( krakatoasr PUBLIC BOOST_AUTO_LINK_SYSTEM ) 46 | if( APPLE ) 47 | set( PLATFORM_LINK_FLAGS "-Wl,-exported_symbols_list ${PROJECT_SOURCE_DIR}/KrakatoaSR.exp" ) 48 | target_link_libraries( krakatoasr "-framework CoreServices" ) 49 | target_link_libraries( krakatoasr "-framework CoreFoundation" ) 50 | target_link_libraries( krakatoasr "-framework IOKit" ) 51 | elseif( LINUX ) 52 | set( PLATFORM_LINK_FLAGS "-Wl,--version-script=${PROJECT_SOURCE_DIR}/KrakatoaSR.map -s" ) 53 | endif() 54 | endif() 55 | 56 | find_package( thinkboxlibrary REQUIRED ) 57 | find_package( krakatoa REQUIRED ) 58 | find_package( Boost REQUIRED ) 59 | find_package( OpenEXR REQUIRED ) 60 | find_package( ZLIB REQUIRED ) 61 | find_package( TBB REQUIRED ) 62 | find_package( xxHash REQUIRED ) 63 | find_package( OpenImageIO REQUIRED ) 64 | 65 | target_include_directories( krakatoasr PUBLIC ${thinkboxlibrary_INCLUDE_DIRS} ) 66 | target_include_directories( krakatoasr PUBLIC ${krakatoa_INCLUDE_DIRS} ) 67 | target_include_directories( krakatoasr PUBLIC ${Boost_INCLUDE_DIRS} ) 68 | target_include_directories( krakatoasr PUBLIC ${OpenEXR_INCLUDE_DIRS} ) 69 | target_include_directories( krakatoasr PUBLIC ${ZLIB_INCLUDE_DIRS} ) 70 | target_include_directories( krakatoasr PUBLIC ${TBB_INCLUDE_DIRS} ) 71 | target_include_directories( krakatoasr PUBLIC ${xxHash_INCLUDE_DIRS} ) 72 | target_include_directories( krakatoasr PUBLIC ${OpenImageIO_INCLUDE_DIRS} ) 73 | 74 | target_link_libraries( krakatoasr PUBLIC thinkboxlibrary::thinkboxlibrary ) 75 | target_link_libraries( krakatoasr PUBLIC krakatoa::krakatoa ) 76 | target_link_libraries( krakatoasr PUBLIC Boost::Boost ) 77 | target_link_libraries( krakatoasr PUBLIC OpenEXR::OpenEXR ) 78 | target_link_libraries( krakatoasr PUBLIC ZLIB::ZLIB ) 79 | target_link_libraries( krakatoasr PUBLIC TBB::tbb ) 80 | target_link_libraries( krakatoasr PUBLIC xxHash::xxHash ) 81 | target_link_libraries( krakatoasr PUBLIC OpenImageIO::OpenImageIO ) 82 | 83 | frantic_common_platform_setup( krakatoasr ) 84 | frantic_default_source_groups( krakatoasr HEADERDIR include SOURCEDIR src ) 85 | 86 | add_precompiled_header( krakatoasr stdafx.h SOURCE_CXX stdafx.cpp ) 87 | 88 | # Disable optimization for the RelWithDebInfo configuration on Windows. 89 | # This allows breakpoints to be hit reliably when debugging in Visual Studio. 90 | if( WIN32 ) 91 | target_compile_options( krakatoasr PRIVATE "$<$:/O2>$<$:/Od>" ) 92 | endif() 93 | 94 | if( BUILD_EXAMPLES ) 95 | add_subdirectory( Example ) 96 | endif() 97 | 98 | install( DIRECTORY include 99 | DESTINATION "include/.." 100 | FILES_MATCHING PATTERN "*.hpp" 101 | ) 102 | install( TARGETS krakatoasr 103 | RUNTIME DESTINATION bin 104 | LIBRARY DESTINATION lib 105 | ARCHIVE DESTINATION lib 106 | ) 107 | -------------------------------------------------------------------------------- /KrakatoaSR/Example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | # SPDX-License-Identifier: Apache-2.0 3 | cmake_minimum_required( VERSION 3.15 FATAL_ERROR ) 4 | 5 | project( KrakatoaSRExamples ) 6 | 7 | foreach( EXAMPLE_INDEX RANGE 1 19 ) 8 | set( TARGET_NAME "example${EXAMPLE_INDEX}" ) 9 | if( EXAMPLE_INDEX LESS 10 ) 10 | set( TARGET_NAME "example0${EXAMPLE_INDEX}" ) 11 | endif() 12 | 13 | add_executable( ${TARGET_NAME} "${TARGET_NAME}.cpp" ) 14 | target_link_libraries( ${TARGET_NAME} krakatoasr ) 15 | set_target_properties( ${TARGET_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${KrakatoaSR_BINARY_DIR} ) 16 | endforeach() 17 | -------------------------------------------------------------------------------- /KrakatoaSR/Example/example02.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | /* 4 | Krakatoa SR API example file. 5 | Note, the examples are somewhat disorganized at the moment. 6 | 7 | EXAMPLE 2 8 | -Uses teapot.prt particles 9 | -Uses 3 different light types 10 | -Sets the shader 11 | -exr output 12 | */ 13 | 14 | #include 15 | #include 16 | 17 | int main( void ) { 18 | try { 19 | // In this example we are taking a prt file of a teapot, which has an emission channel, and adding it to a scene 20 | // and having the particles self illuminate 21 | 22 | // To start we create the renderer object 23 | krakatoasr::krakatoa_renderer renderer; 24 | // We then set the render resolution. Since this is the default it is not necessary however is normally 25 | // included. 26 | renderer.set_render_resolution( 640, 480 ); 27 | 28 | // here we are creating a transform that we will be applying to the camera to move it 10 units in the z 29 | // direction 30 | krakatoasr::animated_transform cameraTransform = 31 | krakatoasr::animated_transform( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 10, 1 ); 32 | // we now apply the transform to the camera 33 | renderer.set_camera_tm( cameraTransform ); 34 | 35 | // here we are creating a particle stream using the prt file smallTeapot.prt 36 | krakatoasr::particle_stream particleStream = krakatoasr::particle_stream::create_from_file( "smallTeapot.prt" ); 37 | // we are now moving the translating the particle stream down 1 unit so that it fits better in the end render 38 | particleStream.set_transform( 39 | krakatoasr::animated_transform( 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, -1, 0, 1 ) ); 40 | // we now add the particle stream to the renderer 41 | renderer.add_particle_stream( particleStream ); 42 | // we now turn on emission so that the particles will self illuminate 43 | renderer.use_emission( true ); 44 | // we are now turning down the emission strength so that the particles are not washed out to much 45 | renderer.set_emission_strength( 5.0 ); 46 | renderer.set_emission_strength_exponent( -3 ); 47 | // create a file saver object so that we can save the results 48 | krakatoasr::file_saver fileSaver = krakatoasr::file_saver( "example02.exr" ); 49 | // Add the file saver to the renderer 50 | renderer.set_render_save_callback( &fileSaver ); 51 | // Begin the Render 52 | renderer.render(); 53 | } catch( std::exception& e ) { 54 | std::cerr << e.what() << std::endl; 55 | return 1; 56 | } 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /KrakatoaSR/Example/example05.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | /* 4 | Krakatoa SR API example file. 5 | 6 | EXAMPLE 5 7 | -Loads a mesh from a .obj file 8 | -Fill it with particles 9 | -Adds a direct light 10 | -exr output 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | int main( void ) { 17 | try { 18 | // In this example we are creating a mesh object from a file and then filling it with particles, we are then 19 | // illuminating those particles wit a light 20 | 21 | // To start we create the renderer object 22 | krakatoasr::krakatoa_renderer renderer; 23 | // We then set the render resolution. Since this is the default it is not necessary however is normally 24 | // included. 25 | renderer.set_render_resolution( 640, 480 ); 26 | // here we are creating a transform that we will be applying to the camera to move it 10 units in the z 27 | // direction 28 | krakatoasr::animated_transform cameraTransform = 29 | krakatoasr::animated_transform( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 10, 1 ); 30 | // we now apply the transform to the camera 31 | renderer.set_camera_tm( cameraTransform ); 32 | // create the triangle mesh object 33 | krakatoasr::triangle_mesh mesh; 34 | // set the mesh by loading in the file boxmesh.obj, the first parameter is which mesh object you want to fill 35 | mesh.load_from_file( mesh, "boxmesh.obj" ); 36 | // create the particle stream from the mesh with voxel spacing of 0.1, 1 subdivision, jittered particles and 2 37 | // particles per jitter 38 | krakatoasr::particle_stream stream = 39 | krakatoasr::particle_stream::create_from_mesh_volume( mesh, .1, 1, true, 2 ); 40 | // add the particle stream to the renderer 41 | renderer.add_particle_stream( stream ); 42 | 43 | // Create a direct light to illuminate the particles originaly starts at the origin 44 | krakatoasr::direct_light dLight = krakatoasr::direct_light(); 45 | // change the flux of the light, normal is 12,12,12 which is white light we are using yellow light 46 | dLight.set_flux( 20, 20, 0 ); 47 | // add the light and specify that we want it 4 units from the origin 48 | renderer.add_light( &dLight, krakatoasr::animated_transform( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 4, 1 ) ); 49 | 50 | // we now create a file saver to let krakatoa know where we want our results to go 51 | krakatoasr::file_saver fileSaver = krakatoasr::file_saver( "example05.exr" ); 52 | // add the file saver to the renderer 53 | renderer.set_render_save_callback( &fileSaver ); 54 | // and finally start the render 55 | renderer.render(); 56 | } catch( std::exception& e ) { 57 | std::cerr << e.what() << std::endl; 58 | return 1; 59 | } 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /KrakatoaSR/Example/example06.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | /* 4 | Krakatoa SR API example file. 5 | 6 | EXAMPLE 6 7 | -Adds fractals with animated transformation matrix 8 | -Set the motion blur shutter, and motion blur parameters 9 | -exr output 10 | */ 11 | 12 | #include 13 | #include 14 | 15 | int main( void ) { 16 | try { 17 | // in this example we are taking a fractal and adding an animated transform onto it with motion blur 18 | 19 | // create a renderer object that will do the majority of the work 20 | krakatoasr::krakatoa_renderer renderer; 21 | // Set the resolution of the final render. Since this the default resolution it does not have to be called. 22 | renderer.set_render_resolution( 640, 480 ); 23 | // here we are creating a transform that we will be applying to the camera to move it 10 units in the z 24 | // direction 25 | krakatoasr::animated_transform cameraTransform = 26 | krakatoasr::animated_transform( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 10, 1 ); 27 | // we now apply the transform to the camera 28 | renderer.set_camera_tm( cameraTransform ); 29 | // Here we are setting the density of the particles in the final render. 30 | // after this change the end density will be 9*10^-1 31 | renderer.set_density_per_particle( 9 ); 32 | // change the exponent on the final render particle density 33 | // after this change the end density will be 9*10^-3 34 | renderer.set_density_exponent( -3 ); 35 | 36 | // we are enabling motion blur to simulate motion 37 | renderer.enable_motion_blur( true ); 38 | // for the motion blur we are blurring it from time -1 to 1 taking 10 samples between that time and we are using 39 | // jittered motion blur 40 | renderer.set_motion_blur( -1, 1, 10, true ); 41 | 42 | // we are now creating the parameters that will be used for the fractals 43 | krakatoasr::fractal_parameters fractalParams; 44 | // we are setting these parameters from a random generator using 5 affine transformations and 4 different colors 45 | // being used 46 | fractalParams.set_from_random( 5, 3, 46 ); 47 | // we now create the particle stream from the fractal parameters from last step with a total particle count of 48 | // 5,000,000 49 | krakatoasr::particle_stream particleStream = 50 | krakatoasr::particle_stream::create_from_fractals( 1000000, fractalParams ); 51 | 52 | // for the blur we start with a basic animated transform then add 1 transformation at each step in our case the 53 | // 2 end points and the time at which they happen 54 | krakatoasr::animated_transform fractalTransform = krakatoasr::animated_transform(); 55 | fractalTransform.add_transform( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, -1 ); 56 | fractalTransform.add_transform( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, -1, 0, 1, 1 ); 57 | // we then add this to the particle stream 58 | particleStream.set_transform( fractalTransform ); 59 | // we now add the particle stream to the renderer 60 | renderer.add_particle_stream( particleStream ); 61 | // since we are using emission instead of lights we must tell the renderer that. 62 | renderer.use_emission( true ); 63 | // for the emission we want to lower the strength so that all of the pixels are do not have there color washed 64 | // out in this example I am using 1*10^-2 65 | renderer.set_emission_strength( 1.0 ); 66 | renderer.set_emission_strength_exponent( -2 ); 67 | // we now create a file saver to let krakatoa know where we want our results to go 68 | krakatoasr::file_saver fileSaver = krakatoasr::file_saver( "example06.exr" ); 69 | // add the file saver to the renderer 70 | renderer.set_render_save_callback( &fileSaver ); 71 | // and finally start the render 72 | renderer.render(); 73 | } catch( std::exception& e ) { 74 | std::cerr << e.what() << std::endl; 75 | return 1; 76 | } 77 | return 0; 78 | } 79 | -------------------------------------------------------------------------------- /KrakatoaSR/Example/example07.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | /* 4 | Krakatoa SR API example file. 5 | 6 | EXAMPLE 7 7 | -Uses an animated moving_teapot.prt (self-illuminated) 8 | -Set the motion blur shutter 9 | -exr output 10 | */ 11 | 12 | #include 13 | #include 14 | 15 | int main( void ) { 16 | try { 17 | // In this example we are taking a prt file that has a velocity channel and applying motion blur to it 18 | 19 | // create a renderer object that will do the majority of the work 20 | krakatoasr::krakatoa_renderer renderer; 21 | // Set the resolution of the final render. Since this the default resolution it does not have to be called. 22 | renderer.set_render_resolution( 640, 480 ); 23 | // here we are creating a transform that we will be applying to the camera to move it 10 units in the z 24 | // direction 25 | krakatoasr::animated_transform cameraTransform = 26 | krakatoasr::animated_transform( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 10, 1 ); 27 | // we now apply the transform to the camera 28 | renderer.set_camera_tm( cameraTransform ); 29 | // Here we are setting the density of the particles in the final render. 30 | // after this change the end density will be 9*10^-1 31 | renderer.set_density_per_particle( 9 ); 32 | // change the exponent on the final render particle density 33 | // after this change the end density will be 9*10^-3 34 | renderer.set_density_exponent( -3 ); 35 | 36 | // we are enabling motion blur to simulate motion 37 | renderer.enable_motion_blur( true ); 38 | // for the motion blur we are blurring it from time -1 to 1 taking 10 samples between that time and we are using 39 | // jittered motion blur 40 | renderer.set_motion_blur( 2.4, 2.6, 10, true ); 41 | 42 | // here we are creating a particle stream using the prt file smallTeapot.prt 43 | krakatoasr::particle_stream particleStream = 44 | krakatoasr::particle_stream::create_from_file( "moving_teapot.prt" ); 45 | // we are now moving the translating the particle stream down 1 unit so that it fits better in the end render 46 | particleStream.set_transform( 47 | krakatoasr::animated_transform( 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, -1, 0, 1 ) ); 48 | // we now add the particle stream to the renderer 49 | renderer.add_particle_stream( particleStream ); 50 | 51 | // since we are using emission instead of lights we must tell the renderer that. 52 | renderer.use_emission( true ); 53 | // for the emission we want to lower the strength so that all of the pixels are do not have there color washed 54 | // out in this example I am using 1*10^-2 55 | renderer.set_emission_strength( 1.0 ); 56 | renderer.set_emission_strength_exponent( -2 ); 57 | // we now create a file saver to let krakatoa know where we want our results to go 58 | krakatoasr::file_saver fileSaver = krakatoasr::file_saver( "example07.exr" ); 59 | // add the file saver to the renderer 60 | renderer.set_render_save_callback( &fileSaver ); 61 | // and finally start the render 62 | renderer.render(); 63 | } catch( std::exception& e ) { 64 | std::cerr << e.what() << std::endl; 65 | return 1; 66 | } 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /KrakatoaSR/Example/example08.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | /* 4 | Krakatoa SR API example file. 5 | 6 | EXAMPLE 8 7 | -Generates fractals 8 | -Uses an animated mesh .obj file (loaded using the function that takes two obj files) 9 | -Uses moving_sphere_1.obj and moving_sphere_2.obj as an occlusion 10 | -Set the motion blur shutter 11 | -exr output 12 | */ 13 | 14 | #include 15 | #include 16 | 17 | int main( void ) { 18 | try { 19 | // In this example we take a crate a mesh with a velocity channel use it to occlude the fractals that we created 20 | // in example 1 the resultsare similar to example 4 except with a moving sphere instead of a stationary box 21 | 22 | // To start we create the renderer object 23 | krakatoasr::krakatoa_renderer renderer; 24 | // We then set the render resolution. Since this is the default it is not necessary however is normally 25 | // included. 26 | renderer.set_render_resolution( 640, 480 ); 27 | 28 | // create a triangle mesh object 29 | krakatoasr::triangle_mesh mesh; 30 | mesh.load_from_files_with_velocities( mesh, "sphere1.obj", "sphere2.obj", 1 ); 31 | renderer.add_mesh( &mesh, krakatoasr::animated_transform( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 2, 1 ) ); 32 | 33 | // we are enabling motion blur to simulate motion 34 | renderer.enable_motion_blur( true ); 35 | // for the motion blur we are blurring it from time -1 to 1 taking 10 samples between that time and we are using 36 | // jittered motion blur 37 | renderer.set_motion_blur( 0, 1, 10, true ); 38 | 39 | // here we are creating a transform that we will be applying to the camera to move it 10 units in the z 40 | // direction 41 | krakatoasr::animated_transform cameraTransform = 42 | krakatoasr::animated_transform( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 10, 1 ); 43 | // we now apply the transform to the camera 44 | renderer.set_camera_tm( cameraTransform ); 45 | 46 | // Here we are setting the density of the particles in the final render. 47 | // after this change the end density will be 9*10^-1 48 | renderer.set_density_per_particle( 9 ); 49 | // change the exponent on the final render particle density 50 | // after this change the end density will be 9*10^-3 51 | renderer.set_density_exponent( -3 ); 52 | // we are now creating the parameters that will be used for the fractals 53 | krakatoasr::fractal_parameters fractalParams; 54 | // we are setting these parameters from a random generator using 5 affine transformations and 4 different colors 55 | // being used 56 | fractalParams.set_from_random( 5, 3, 46 ); 57 | // we now create the particle stream from the fractal parameters from last step with a total particle count of 58 | // 5,000,000 59 | krakatoasr::particle_stream particleStream = 60 | krakatoasr::particle_stream::create_from_fractals( 5000000, fractalParams ); 61 | // we now add the particle stream to the renderer 62 | renderer.add_particle_stream( particleStream ); 63 | // since we are using emission instead of lights we must tell the renderer that. 64 | renderer.use_emission( true ); 65 | // for the emission we want to lower the strength so that all of the pixels are do not have there color washed 66 | // out in this example I am using 1*10^-2 67 | renderer.set_emission_strength( 1.0 ); 68 | renderer.set_emission_strength_exponent( -2 ); 69 | // we now create a file saver to let krakatoa know where we want our results to go 70 | krakatoasr::file_saver fileSaver = krakatoasr::file_saver( "example08.exr" ); 71 | // add the file saver to the renderer 72 | renderer.set_render_save_callback( &fileSaver ); 73 | // and finally start the render 74 | renderer.render(); 75 | } catch( std::exception& e ) { 76 | std::cerr << e.what() << std::endl; 77 | return 1; 78 | } 79 | return 0; 80 | } 81 | -------------------------------------------------------------------------------- /KrakatoaSR/Example/example09.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | /* 4 | Krakatoa SR API example file. 5 | 6 | EXAMPLE 9 7 | -Uses moving_teapot.prt which has velocities 8 | -Self illuminated 9 | -Render element enabled: velocity, z depth, normal. 10 | -exr output as multi-channel exr (use multi_channel_exr_file_saver class) 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | int main( void ) { 17 | try { 18 | // create a renderer object that will do the majority of the work 19 | krakatoasr::krakatoa_renderer renderer; 20 | // Set the resolution of the final render. Since this the default resolution it does not have to be called. 21 | renderer.set_render_resolution( 640, 480 ); 22 | // here we are creating a transform that we will be applying to the camera to move it 10 units in the z 23 | // direction 24 | krakatoasr::animated_transform cameraTransform = 25 | krakatoasr::animated_transform( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 10, 1 ); 26 | // we now apply the transform to the camera 27 | renderer.set_camera_tm( cameraTransform ); 28 | // Here we are setting the density of the particles in the final render. 29 | // after this change the end density will be 9*10^-1 30 | renderer.set_density_per_particle( 9 ); 31 | // change the exponent on the final render particle density 32 | // after this change the end density will be 9*10^-3 33 | renderer.set_density_exponent( -3 ); 34 | 35 | // here we are creating a particle stream using the prt file smallTeapot.prt 36 | krakatoasr::particle_stream particleStream = 37 | krakatoasr::particle_stream::create_from_file( "moving_teapot.prt" ); 38 | // we are now moving the translating the particle stream down 1 unit so that it fits better in the end render 39 | particleStream.set_transform( 40 | krakatoasr::animated_transform( 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, -1, 0, 1 ) ); 41 | // we now add the particle stream to the renderer 42 | renderer.add_particle_stream( particleStream ); 43 | 44 | renderer.enable_normal_render( true ); 45 | renderer.enable_velocity_render( true ); 46 | renderer.enable_z_depth_render( true ); 47 | 48 | // since we are using emission instead of lights we must tell the renderer that. 49 | renderer.use_emission( true ); 50 | // for the emission we want to lower the strength so that all of the pixels are do not have there color washed 51 | // out in this example I am using 1*10^-2 52 | renderer.set_emission_strength( 1.0 ); 53 | renderer.set_emission_strength_exponent( -2 ); 54 | // we now create a file saver to let krakatoa know where we want our results to go 55 | krakatoasr::multi_channel_exr_file_saver multichannelFileSaver = 56 | krakatoasr::multi_channel_exr_file_saver( "example09.exr" ); 57 | // add the file saver to the renderer 58 | renderer.set_render_save_callback( &multichannelFileSaver ); 59 | // and finally start the render 60 | renderer.render(); 61 | } catch( std::exception& e ) { 62 | std::cerr << e.what() << std::endl; 63 | return 1; 64 | } 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /KrakatoaSR/Example/example10.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | /* 4 | Krakatoa SR API example file. 5 | 6 | EXAMPLE 10 7 | -Uses moving_teapot.prt 8 | -Self illuminated 9 | -Render element enabled: velocity, z depth, normal. 10 | -Multiple exr outputs as single-channel RGBA files (use file_saver class) 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | int main( void ) { 17 | try { 18 | // create a renderer object that will do the majority of the work 19 | krakatoasr::krakatoa_renderer renderer; 20 | // Set the resolution of the final render. Since this the default resolution it does not have to be called. 21 | renderer.set_render_resolution( 640, 480 ); 22 | // here we are creating a transform that we will be applying to the camera to move it 10 units in the z 23 | // direction 24 | krakatoasr::animated_transform cameraTransform = 25 | krakatoasr::animated_transform( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 10, 1 ); 26 | // we now apply the transform to the camera 27 | renderer.set_camera_tm( cameraTransform ); 28 | // Here we are setting the density of the particles in the final render. 29 | // after this change the end density will be 9*10^-1 30 | renderer.set_density_per_particle( 9 ); 31 | // change the exponent on the final render particle density 32 | // after this change the end density will be 9*10^-3 33 | renderer.set_density_exponent( -3 ); 34 | 35 | // here we are creating a particle stream using the prt file smallTeapot.prt 36 | krakatoasr::particle_stream particleStream = 37 | krakatoasr::particle_stream::create_from_file( "moving_teapot.prt" ); 38 | // we are now moving the translating the particle stream down 1 unit so that it fits better in the end render 39 | particleStream.set_transform( 40 | krakatoasr::animated_transform( 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, -1, 0, 1 ) ); 41 | // we now add the particle stream to the renderer 42 | renderer.add_particle_stream( particleStream ); 43 | 44 | renderer.enable_normal_render( true ); 45 | renderer.enable_velocity_render( true ); 46 | renderer.enable_z_depth_render( true ); 47 | 48 | // since we are using emission instead of lights we must tell the renderer that. 49 | renderer.use_emission( true ); 50 | // for the emission we want to lower the strength so that all of the pixels are do not have there color washed 51 | // out in this example I am using 1*10^-2 52 | renderer.set_emission_strength( 1.0 ); 53 | renderer.set_emission_strength_exponent( -2 ); 54 | // we now create a file saver to let krakatoa know where we want our results to go 55 | krakatoasr::file_saver fileSaver = krakatoasr::file_saver( "example10.exr", "example10_Z.exr", 56 | "example10_normal.exr", "example10_velocity.exr" ); 57 | // add the file saver to the renderer 58 | renderer.set_render_save_callback( &fileSaver ); 59 | // and finally start the render 60 | renderer.render(); 61 | } catch( std::exception& e ) { 62 | std::cerr << e.what() << std::endl; 63 | return 1; 64 | } 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /KrakatoaSR/Example/example11.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | /* 4 | Krakatoa SR API example file. 5 | 6 | EXAMPLE 11 7 | -Generates fractals 8 | -Uses a mesh boxmesh.obj 9 | -Render elements: occluded, z depth 10 | -exr output as multi-channel exr 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | int main( void ) { 17 | try { 18 | // To start we create the renderer object 19 | krakatoasr::krakatoa_renderer renderer; 20 | // We then set the render resolution. Since this is the default it is not necessary however is normally 21 | // included. 22 | renderer.set_render_resolution( 640, 480 ); 23 | // here we are creating a transform that we will be applying to the camera to move it 10 units in the z 24 | // direction 25 | krakatoasr::animated_transform cameraTransform = 26 | krakatoasr::animated_transform( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 10, 1 ); 27 | // we now apply the transform to the camera 28 | renderer.set_camera_tm( cameraTransform ); 29 | // create the triangle mesh object 30 | krakatoasr::triangle_mesh mesh; 31 | // set the mesh by loading in the file boxmesh.obj, the first parameter is which mesh object you want to fill 32 | mesh.load_from_file( mesh, "boxmesh.obj" ); 33 | renderer.add_mesh( &mesh, krakatoasr::animated_transform( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 2, 1 ) ); 34 | 35 | // we are now creating the parameters that will be used for the fractals 36 | krakatoasr::fractal_parameters fractalParams; 37 | // we are setting these parameters from a random generator using 5 affine transformations and 4 different colors 38 | // being used 39 | fractalParams.set_from_random( 5, 3, 46 ); 40 | // we now create the particle stream from the fractal parameters from last step with a total particle count of 41 | // 5,000,000 42 | krakatoasr::particle_stream particleStream = 43 | krakatoasr::particle_stream::create_from_fractals( 5000000, fractalParams ); 44 | // add the particle stream to the renderer 45 | renderer.add_particle_stream( particleStream ); 46 | 47 | renderer.enable_occluded_rgba_render( true ); 48 | renderer.enable_z_depth_render( true ); 49 | 50 | // Create a direct light to illuminate the particles originaly starts at the origin 51 | krakatoasr::direct_light dLight = krakatoasr::direct_light(); 52 | // change the flux of the light, normal is 12,12,12 which is white light we are using yellow light 53 | dLight.set_flux( 20, 20, 0 ); 54 | // add the light and specify that we want it 4 units from the origin 55 | renderer.add_light( &dLight, krakatoasr::animated_transform( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 4, 1 ) ); 56 | 57 | // we now create a file saver to let krakatoa know where we want our results to go 58 | krakatoasr::multi_channel_exr_file_saver multichannelFileSaver = 59 | krakatoasr::multi_channel_exr_file_saver( "example11.exr" ); 60 | // add the file saver to the renderer 61 | renderer.set_render_save_callback( &multichannelFileSaver ); 62 | // and finally start the render 63 | renderer.render(); 64 | } catch( std::exception& e ) { 65 | std::cerr << e.what() << std::endl; 66 | return 1; 67 | } 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /KrakatoaSR/Example/example14.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | /* 4 | Krakatoa SR API example file. 5 | 6 | EXAMPLE 14 7 | -Writing out a PRT file. 8 | -Saving particles from multiple PRT files into a single PRT file. 9 | */ 10 | 11 | #include 12 | #include 13 | 14 | int main( void ) { 15 | try { 16 | // this example create 3 particle streams from a mesh and then saves them all into a new prt 17 | 18 | // To start we create the renderer object 19 | krakatoasr::krakatoa_renderer renderer; 20 | // create the triangle mesh object 21 | krakatoasr::triangle_mesh mesh; 22 | // set the mesh by loading in the file boxmesh.obj, the first parameter is which mesh object you want to fill 23 | mesh.load_from_file( mesh, "boxmesh.obj" ); 24 | // create the particle stream from the mesh with voxel spacing of 0.1, 1 subdivision, jittered particles and 2 25 | // particles per jitter 26 | krakatoasr::particle_stream stream_one = 27 | krakatoasr::particle_stream::create_from_mesh_volume( mesh, .25, 1, true, 2 ); 28 | // add the particle stream to the renderer 29 | renderer.add_particle_stream( stream_one ); 30 | 31 | // create the particle stream from the mesh with voxel spacing of 0.1, 1 subdivision, jittered particles and 2 32 | // particles per jitter 33 | krakatoasr::particle_stream stream_two = 34 | krakatoasr::particle_stream::create_from_mesh_volume( mesh, .25, 1, true, 2 ); 35 | stream_two.set_transform( krakatoasr::animated_transform( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 3, 0, 0, 1 ) ); 36 | // add the particle stream to the renderer 37 | renderer.add_particle_stream( stream_two ); 38 | 39 | // create the particle stream from the mesh with voxel spacing of 0.1, 1 subdivision, jittered particles and 2 40 | // particles per jitter 41 | krakatoasr::particle_stream stream_three = 42 | krakatoasr::particle_stream::create_from_mesh_volume( mesh, .25, 1, true, 2 ); 43 | stream_three.set_transform( krakatoasr::animated_transform( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, -3, 0, 0, 1 ) ); 44 | // add the particle stream to the renderer 45 | renderer.add_particle_stream( stream_three ); 46 | // tell the renderer we want to save the output to a prt file 47 | renderer.save_output_prt( "example14.prt", false ); 48 | // and finally start the render 49 | renderer.render(); 50 | } catch( std::exception& e ) { 51 | std::cerr << e.what() << std::endl; 52 | return 1; 53 | } 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /KrakatoaSR/Example/example15.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | /* 4 | Krakatoa SR API example file. 5 | 6 | EXAMPLE 15 7 | -Writing out a PRT file. 8 | -Saving out particles generated from "Particle Multiplication". 9 | */ 10 | 11 | #include 12 | #include 13 | 14 | int main( void ) { 15 | try { 16 | // In this example we are creating a particle stream from a mesh we are then adding a particle multiplication to 17 | // that particle stream to multiply the particles into the millions 18 | 19 | krakatoasr::set_global_logging_level( krakatoasr::LOG_DEBUG ); 20 | // To start we create the renderer object 21 | krakatoasr::krakatoa_renderer renderer; 22 | // create the triangle mesh object 23 | // create the particle stream from the mesh with voxel spacing of 0.1, 1 subdivision, jittered particles and 2 24 | // particles per jitter 25 | // Breaks the code somewhere not sure where 26 | krakatoasr::triangle_mesh mesh; 27 | // set the mesh by loading in the file boxmesh.obj, the first parameter is which mesh object you want to fill 28 | krakatoasr::triangle_mesh::load_from_file( mesh, "boxmesh.obj" ); 29 | // create the particle stream from the mesh with voxel spacing of 0.1, 1 subdivision, jittered particles and 2 30 | // particles per jitter 31 | krakatoasr::particle_stream stream = 32 | krakatoasr::particle_stream::create_from_mesh_volume( mesh, .1, 1, true, 1 ); 33 | // add the particle multiplication to the particle stream we can have thousands more 34 | // krakatoasr::add_particle_multiplication( stream, 3.0f, 2,1); 35 | // add the particle stream to the renderer 36 | renderer.add_particle_stream( stream ); 37 | 38 | // tell krakatoa that you want to save the results to a prt 39 | renderer.save_output_prt( "example15.prt", false ); 40 | // and finally start the render 41 | renderer.render(); 42 | } catch( std::exception& e ) { 43 | std::cerr << e.what() << std::endl; 44 | return 1; 45 | } 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /KrakatoaSR/Example/example16.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | /* 4 | Krakatoa SR API example file. 5 | 6 | EXAMPLE 16 7 | -Writing out a PRT file. 8 | -Writing out a particle set with a computed "Lighting" channel. 9 | */ 10 | 11 | #include 12 | #include 13 | 14 | int main( void ) { 15 | try { 16 | // in this example we are taking a particle stream adding multiple lights to shine on it and then saving it out 17 | // to a prt this way the particles have a built in lighting channel 18 | 19 | krakatoasr::krakatoa_renderer renderer; 20 | // add several lights to r 21 | // Create a direct light to illuminate the particles originaly starts at the origin 22 | krakatoasr::direct_light dLight = krakatoasr::direct_light(); 23 | // change the flux of the light, normal is 12,12,12 which is white light we are using yellow light 24 | dLight.set_flux( 20, 20, 0 ); 25 | // add the light and specify that we want it 4 units from the origin 26 | renderer.add_light( &dLight, krakatoasr::animated_transform( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 4, 1 ) ); 27 | 28 | // Create a direct light to illuminate the particles originaly starts at the origin 29 | krakatoasr::point_light pLight = krakatoasr::point_light(); 30 | // change the flux of the light, normal is 12,12,12 which is white light 31 | dLight.set_flux( 10, 20, 20 ); 32 | // add the light and specify that we want it 5 units above the teapot 33 | renderer.add_light( &dLight, krakatoasr::animated_transform( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 5, 0, 1 ) ); 34 | // add the teapot to the renderer 35 | krakatoasr::particle_stream myStream = krakatoasr::particle_stream::create_from_file( "smallTeapot.prt" ); 36 | renderer.add_particle_stream( myStream ); 37 | 38 | // tell the renderer we want to save the output to a prt file 39 | renderer.save_output_prt( "example16.prt", false ); 40 | // and finally start the render 41 | renderer.render(); 42 | } catch( std::exception& e ) { 43 | std::cerr << e.what() << std::endl; 44 | return 1; 45 | } 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /KrakatoaSR/Example/example17.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | /* 4 | Krakatoa SR API example file. 5 | 6 | EXAMPLE 17 7 | -Writing out a PRT file. 8 | -Reducing a PRT file size by only saving "Position" and "Velocity" channels. 9 | */ 10 | 11 | #include 12 | #include 13 | 14 | int main( void ) { 15 | try { 16 | // in this example we are saving a prt file that includes a velocity channel out to another prt with only the 17 | // channels we choose 18 | 19 | // create the renderer object 20 | krakatoasr::krakatoa_renderer renderer; 21 | // add the prt file to the renderer 22 | krakatoasr::particle_stream myStream = krakatoasr::particle_stream::create_from_file( "moving_teapot.prt" ); 23 | renderer.add_particle_stream( myStream ); 24 | // tell the renderer that we are going to save the results to a prt file, and that we are not going to use the 25 | // default channels 26 | renderer.save_output_prt( "example17.prt", false, false ); // set useDefaultChannels to false 27 | // append the channels that we would like onto the output file 28 | // in this case we are getting the position and velocity channels 29 | renderer.append_output_prt_channel( "Position", krakatoasr::DATA_TYPE_FLOAT32, 3 ); 30 | renderer.append_output_prt_channel( "Velocity", krakatoasr::DATA_TYPE_FLOAT16, 3 ); 31 | // Start up the render 32 | renderer.render(); 33 | } catch( std::exception& e ) { 34 | std::cerr << e.what() << std::endl; 35 | return 1; 36 | } 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /KrakatoaSR/Example/example18.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | /* 4 | Krakatoa SR API example file. 5 | 6 | EXAMPLE 18 7 | -Uses channel operation "Copy" to copy "Position" channel into "Emission" channel. 8 | -Uses channel operation "Scale" to scale down the "Color" channel so a nice gradient appears around the origin. 9 | */ 10 | 11 | #include 12 | #include 13 | 14 | int main( void ) { 15 | try { 16 | // This example creates a self illuminating fractal it then copies the position channels of each particle into 17 | // that particles emission channel and scales the color channel 18 | 19 | krakatoasr::krakatoa_renderer renderer; 20 | // here we are creating a transform that we will be applying to the camera to move it 10 units in the z 21 | // direction 22 | krakatoasr::animated_transform cameraTransform = 23 | krakatoasr::animated_transform( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 10, 1 ); 24 | // we now apply the transform to the camera 25 | renderer.set_camera_tm( cameraTransform ); 26 | // Here we are setting the density of the particles in the final render. 27 | // after this change the end density will be 9*10^-1 28 | renderer.set_density_per_particle( 5 ); 29 | // change the exponent on the final render particle density 30 | // after this change the end density will be 9*10^-3 31 | renderer.set_density_exponent( -6 ); 32 | // we are now creating the parameters that will be used for the fractals 33 | krakatoasr::fractal_parameters fractalParams; 34 | // we are setting these parameters from a random generator using 5 affine transformations and 4 different colors 35 | // being used 36 | fractalParams.set_from_random( 5, 3, 46 ); 37 | // we now create the particle stream from the fractal parameters from last step with a total particle count of 38 | // 5,000,000 39 | krakatoasr::particle_stream particleStream = 40 | krakatoasr::particle_stream::create_from_fractals( 5000000, fractalParams ); 41 | // We now copy the position channel to the emission channel 42 | // Note that the destination channel is before the source channel 43 | krakatoasr::channelop_copy( particleStream, "Emission", "Position" ); 44 | // we then scale the Color channel of the particle stream by a factor of 400 45 | krakatoasr::channelop_scale( particleStream, "Color", 400 ); 46 | // we now add the particle stream to the renderer 47 | renderer.add_particle_stream( particleStream ); 48 | // since we are using emission instead of lights we must tell the renderer that. 49 | renderer.use_emission( true ); 50 | // for the emission we want to lower the strength so that all of the pixels are do not have there color washed 51 | // out in this example I am using 1*10^-2 52 | renderer.set_emission_strength( 7.0 ); 53 | renderer.set_emission_strength_exponent( -6 ); 54 | // we now create a file saver to let krakatoa know where we want our results to go 55 | krakatoasr::file_saver fileSaver = krakatoasr::file_saver( "example20.exr" ); 56 | // add the file saver to the renderer 57 | renderer.set_render_save_callback( &fileSaver ); 58 | // and finally start the render 59 | renderer.render(); 60 | } catch( std::exception& e ) { 61 | std::cerr << e.what() << std::endl; 62 | return 1; 63 | } 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /KrakatoaSR/Example/example19.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | /* 4 | Krakatoa SR API example file. 5 | 6 | EXAMPLE 19 7 | -Adds two teapot.prt to the scene side-by-side. 8 | -Uses "add_particle_multiplication" to ONE of the teapot to turn it into several million of particles. 9 | */ 10 | 11 | #include 12 | #include 13 | 14 | int main( void ) { 15 | try { 16 | // This example creates 2 particles streams from the same prt file and then adds a particle multiplication to 17 | // one of them. 18 | 19 | // To start we create the renderer object 20 | krakatoasr::krakatoa_renderer renderer; 21 | // We then set the render resolution. Since this is the default it is not necessary however is normally 22 | // included. 23 | renderer.set_render_resolution( 640, 480 ); 24 | 25 | // here we are creating a transform that we will be applying to the camera to move it 10 units in the z 26 | // direction 27 | krakatoasr::animated_transform cameraTransform = 28 | krakatoasr::animated_transform( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 10, 1 ); 29 | // we now apply the transform to the camera 30 | renderer.set_camera_tm( cameraTransform ); 31 | 32 | // here we are creating a particle stream using the prt file smallTeapot.prt 33 | krakatoasr::particle_stream particleStream1 = 34 | krakatoasr::particle_stream::create_from_file( "smallTeapot.prt" ); 35 | // we are now moving the translating the particle stream down 1 unit so that it fits better in the end render 36 | // we are also moving it to the right so that we can see both teapots 37 | particleStream1.set_transform( 38 | krakatoasr::animated_transform( 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 3, -1, 0, 1 ) ); 39 | // we now add the particle stream to the renderer 40 | renderer.add_particle_stream( particleStream1 ); 41 | 42 | // Here we are creating a second particle stream in the same way as the first 43 | krakatoasr::particle_stream particleStream2 = 44 | krakatoasr::particle_stream::create_from_file( "smallTeapot.prt" ); 45 | // we are now moving the translating the particle stream down 1 unit so that it fits better in the end render 46 | // we are also moving it to the left 3 units so that we can see both teapots 47 | particleStream2.set_transform( 48 | krakatoasr::animated_transform( 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, -3, -1, 0, 1 ) ); 49 | // add the particle multiplication to this stream, filling a radius of 0.5 with 3 subdivisions for each and 50 | // putting 1 particle in each subdivision krakatoasr::add_particle_multiplication( particleStream2, .5f, 3, 1); 51 | // we now turn on emission so that the particles will self illuminate 52 | renderer.add_particle_stream( particleStream2 ); 53 | renderer.use_emission( true ); 54 | // we are now turning down the emission strength so that the particles are not washed out to much 55 | renderer.set_emission_strength( 5.0 ); 56 | renderer.set_emission_strength_exponent( -3 ); 57 | // create a file saver object so that we can save the results 58 | krakatoasr::file_saver fileSaver = krakatoasr::file_saver( "example21.exr" ); 59 | // Add the file saver to the renderer 60 | renderer.set_render_save_callback( &fileSaver ); 61 | // Begin the Render 62 | renderer.render(); 63 | } catch( std::exception& e ) { 64 | std::cerr << e.what() << std::endl; 65 | return 1; 66 | } 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /KrakatoaSR/KrakatoaSR.exp: -------------------------------------------------------------------------------- 1 | *krakatoasr* 2 | -------------------------------------------------------------------------------- /KrakatoaSR/KrakatoaSR.map: -------------------------------------------------------------------------------- 1 | { 2 | global: 3 | krakatoasr::*; 4 | extern "C++" { 5 | *krakatoasr::*; 6 | }; 7 | local: 8 | *; 9 | }; 10 | -------------------------------------------------------------------------------- /KrakatoaSR/build.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | # SPDX-License-Identifier: Apache-2.0 3 | from __future__ import annotations 4 | from typing import Any 5 | from cpt.packager import ConanMultiPackager 6 | 7 | import argparse 8 | import platform 9 | import pprint 10 | 11 | 12 | COMMON_PACKAGER_ARGS: dict[str, Any] = { 13 | 'build_types': ['Release'], 14 | 'archs': ['x86_64'], 15 | 'build_policy': 'missing' 16 | } 17 | 18 | WINDOWS_PACKAGER_ARGS: dict[str, Any] = { 19 | 'visual_versions': ['15', '16'], 20 | 'visual_runtimes': ['MD'] 21 | } 22 | 23 | LINUX_PACKAGER_ARGS: dict[str, Any] = { 24 | 'gcc_versions': ['7'] 25 | } 26 | 27 | MACOS_PACKAGER_ARGS: dict[str, Any] = { 28 | 'apple_clang_versions': ['10'] 29 | } 30 | 31 | 32 | def parse_arguments() -> argparse.Namespace: 33 | parser = argparse.ArgumentParser() 34 | parser.add_argument('-u', '--username', default=None, help='The Conan username to use for the built package.') 35 | parser.add_argument('-c', '--channel', default=None, help='The Conan channel to use for the built package.') 36 | parser.add_argument('-o', '--option', action='append', dest='options', help='Specify package options to be used by the build.') 37 | parser.add_argument('--dry-run', action='store_true', help='Print the configurations that would be built without actually building them.') 38 | return parser.parse_args() 39 | 40 | def main() -> None: 41 | args = parse_arguments() 42 | 43 | packager_args = { 44 | 'username': args.username, 45 | 'channel': args.channel, 46 | 'options': args.options 47 | } 48 | packager_args.update(COMMON_PACKAGER_ARGS) 49 | 50 | if platform.system() == 'Windows': 51 | packager_args.update(WINDOWS_PACKAGER_ARGS) 52 | elif platform.system() == 'Linux': 53 | packager_args.update(LINUX_PACKAGER_ARGS) 54 | elif platform.system() == 'Darwin': 55 | packager_args.update(MACOS_PACKAGER_ARGS) 56 | else: 57 | raise Exception('Platform not supported.') 58 | 59 | builder = ConanMultiPackager(**packager_args) 60 | builder.add_common_builds(pure_c=False, build_all_options_values=['shared']) 61 | 62 | # Remove the legacy libstdc++ build. 63 | if platform.system() == 'Linux': 64 | builder.remove_build_if(lambda build: build.settings['compiler.libcxx'] == 'libstdc++') 65 | 66 | if args.dry_run: 67 | pprint.pprint(builder.builds, indent=4) 68 | else: 69 | builder.run() 70 | 71 | 72 | if __name__ == '__main__': 73 | main() 74 | -------------------------------------------------------------------------------- /KrakatoaSR/conanfile.py: -------------------------------------------------------------------------------- 1 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | # SPDX-License-Identifier: Apache-2.0 3 | import os 4 | from typing import Any 5 | from conans import ConanFile, CMake 6 | 7 | 8 | SETTINGS: list[str] = [ 9 | 'os', 10 | 'compiler', 11 | 'build_type', 12 | 'arch' 13 | ] 14 | 15 | TOOL_REQUIRES: list[str] = [ 16 | 'cmake/3.24.1', 17 | 'thinkboxcmlibrary/1.0.0', 18 | ] 19 | 20 | REQUIRES: list[str] = [ 21 | 'boost/1.78.0', 22 | 'zlib/1.2.12', 23 | 'thinkboxlibrary/1.0.0', 24 | 'krakatoa/1.0.0', 25 | 'openimageio/2.3.7.2' 26 | ] 27 | 28 | 29 | class KrakatoaSRConan(ConanFile): 30 | name: str = 'krakatoasr' 31 | version: str = '1.0.0' 32 | license: str = 'Apache-2.0' 33 | settings: list[str] = SETTINGS 34 | tool_requires: list[str] = TOOL_REQUIRES 35 | requires: list[str] = REQUIRES 36 | generators: str | list[str] = 'cmake_find_package' 37 | options: dict[str, Any] = { 38 | 'shared': [True, False], 39 | 'build_examples': [True, False] 40 | } 41 | default_options: dict[str, Any] = { 42 | 'shared': False, 43 | 'build_examples': False, 44 | 'openimageio:with_libjpeg': 'libjpeg', 45 | 'openimageio:with_libpng': True, 46 | 'openimageio:with_freetype': False, 47 | 'openimageio:with_hdf5': False, 48 | 'openimageio:with_opencolorio': False, 49 | 'openimageio:with_opencv': False, 50 | 'openimageio:with_tbb': False, 51 | 'openimageio:with_dicom': False, 52 | 'openimageio:with_ffmpeg': False, 53 | 'openimageio:with_giflib': False, 54 | 'openimageio:with_libheif': False, 55 | 'openimageio:with_raw': False, 56 | 'openimageio:with_openjpeg': False, 57 | 'openimageio:with_openvdb': False, 58 | 'openimageio:with_ptex': False, 59 | 'openimageio:with_libwebp': False, 60 | 'libtiff:lzma': False, 61 | 'libtiff:jpeg': 'libjpeg', 62 | 'libtiff:zlib': True, 63 | 'libtiff:libdeflate': False, 64 | 'libtiff:zstd': False, 65 | 'libtiff:jbig': False, 66 | 'libtiff:webp': False 67 | } 68 | 69 | def build(self) -> None: 70 | cmake = CMake(self) 71 | cmake.configure(defs={ 72 | 'LIBRARY_TYPE': 'SHARED' if self.options.shared else 'STATIC', 73 | 'BUILD_EXAMPLES': 'ON' if self.options.build_examples else 'OFF' 74 | }) 75 | cmake.build() 76 | 77 | def export_sources(self) -> None: 78 | self.copy('**.h', src='', dst='') 79 | self.copy('**.hpp', src='', dst='') 80 | self.copy('**.cpp', src='', dst='') 81 | self.copy('KrakatoaSR.exp', src='', dst='') 82 | self.copy('KrakatoaSR.map', src='', dst='') 83 | self.copy('CMakeLists.txt', src='', dst='') 84 | self.copy('../NOTICE.txt', src='', dst='') 85 | self.copy('../LICENSE.txt', src='', dst='') 86 | 87 | def imports(self) -> None: 88 | # Copy DLLs to the Example binary directory 89 | self.copy('*.dll', dst='Release', src='bin') 90 | 91 | def package(self) -> None: 92 | cmake = CMake(self) 93 | cmake.install() 94 | 95 | with open(os.path.join(self.source_folder, 'NOTICE.txt'), 'r', encoding='utf8') as notice_file: 96 | notice_contents = notice_file.readlines() 97 | with open(os.path.join(self.source_folder, 'LICENSE.txt'), 'r', encoding='utf8') as license_file: 98 | license_contents = license_file.readlines() 99 | os.makedirs(os.path.join(self.package_folder, 'licenses'), exist_ok=True) 100 | with open(os.path.join(self.package_folder, 'licenses', 'LICENSE'), 'w', encoding='utf8') as cat_license_file: 101 | cat_license_file.writelines(notice_contents) 102 | cat_license_file.writelines(license_contents) 103 | 104 | def deploy(self) -> None: 105 | self.copy("*", dst="bin", src="bin") 106 | self.copy("*", dst="lib", src="lib") 107 | self.copy("*", dst="include", src="include") 108 | 109 | def package_info(self) -> None: 110 | self.cpp_info.libs = ["krakatoasr"] 111 | -------------------------------------------------------------------------------- /KrakatoaSR/include/doxygen/documentation.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /KrakatoaSR/include/doxygen/title_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws/thinkbox-krakatoa/c879c8099f9340a48ecf70141242994301dcb7f9/KrakatoaSR/include/doxygen/title_image.png -------------------------------------------------------------------------------- /KrakatoaSR/include/krakatoasr_datatypes.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #ifndef __KRAKATOASR_DATATYPES__ 4 | #define __KRAKATOASR_DATATYPES__ 5 | 6 | #if defined( KSR_STATIC ) 7 | #define FCNEXPORT 8 | #define CLSEXPORT 9 | #elif defined( _WIN32 ) 10 | #define FCNEXPORT extern "C" __declspec( dllexport ) 11 | #define CLSEXPORT __declspec( dllexport ) 12 | #elif HAVE_VISIBILITY 13 | #define FCNEXPORT __attribute__( ( __visibility__( "default" ) ) ) 14 | #define CLSEXPORT __attribute__( ( __visibility__( "default" ) ) ) 15 | #else 16 | #define FCNEXPORT 17 | #define CLSEXPORT 18 | #endif 19 | 20 | /** 21 | * Krakatoa SR 22 | */ 23 | namespace krakatoasr { 24 | 25 | #if defined( WIN32 ) 26 | typedef __int64 INT64; 27 | #elif defined( __APPLE__ ) 28 | typedef long long INT64; 29 | #else 30 | typedef long long INT64; 31 | #endif 32 | 33 | enum logging_level_t { LOG_NONE = 0, LOG_ERRORS, LOG_WARNINGS, LOG_PROGRESS, LOG_STATS, LOG_DEBUG, LOG_CUSTOM = -1 }; 34 | 35 | enum output_type_t { 36 | OUTPUT_RGBA, 37 | OUTPUT_Z, 38 | OUTPUT_NORMAL, 39 | OUTPUT_VELOCITY, 40 | OUTPUT_RGBA_OCCLUDED, 41 | OUTPUT_EMISSION, 42 | OUTPUT_SPECULAR, 43 | OUTPUT_SPECULAR2, 44 | OUTPUT_CUSTOM 45 | }; 46 | 47 | enum rendering_method_t { METHOD_PARTICLE, METHOD_VOXEL }; 48 | 49 | enum filter_t { 50 | FILTER_BILINEAR, // when using bilinear, also specify a filter "size" (default to 1) 51 | FILTER_BICUBIC, 52 | FILTER_NEAREST_NEIGHBOR 53 | }; 54 | 55 | enum camera_type_t { CAMERA_PERSPECTIVE, CAMERA_ORTHOGRAPHIC }; 56 | 57 | enum light_shape_t { SHAPE_SQUARE, SHAPE_ROUND }; 58 | 59 | enum data_type_t { 60 | DATA_TYPE_INVALID, 61 | DATA_TYPE_INT8, 62 | DATA_TYPE_INT16, 63 | DATA_TYPE_INT32, 64 | DATA_TYPE_INT64, 65 | DATA_TYPE_UINT8, 66 | DATA_TYPE_UINT16, 67 | DATA_TYPE_UINT32, 68 | DATA_TYPE_UINT64, 69 | DATA_TYPE_FLOAT16, 70 | DATA_TYPE_FLOAT32, 71 | DATA_TYPE_FLOAT64 72 | }; 73 | 74 | enum coordinate_system_type_t { 75 | COORDINATE_SYSTEM_UNSPECIFIED, 76 | COORDINATE_SYSTEM_RIGHT_HANDED_YUP, 77 | COORDINATE_SYSTEM_RIGHT_HANDED_ZUP, 78 | COORDINATE_SYSTEM_LEFT_HANDED_YUP, 79 | COORDINATE_SYSTEM_LEFT_HANDED_ZUP, 80 | COORDINATE_SYSTEM_INVALID 81 | }; 82 | 83 | enum exr_compression_t { // this has to exact matches Imf::Compression 84 | COMPRESSION_NONE, // no compression 85 | COMPRESSION_RLE, // run length encoding 86 | COMPRESSION_ZIPS, // zlib compression, one scan line at a time 87 | COMPRESSION_ZIP, // zlib compression, in blocks of 16 scan lines 88 | COMPRESSION_PIZ, // piz-based wavelet compression 89 | COMPRESSION_PXR24, // lossy 24-bit float compression 90 | COMPRESSION_B44, // lossy 4-by-4 pixel block compression, fixed compression rate 91 | COMPRESSION_B44A, // lossy 4-by-4 pixel block compression, flat fields are compressed more 92 | }; 93 | 94 | enum exr_bit_depth_t { 95 | BIT_DEPTH_UINT, // using usigned int 96 | BIT_DEPTH_HALF, // using 16 bits float 97 | BIT_DEPTH_FLOAT, // using 32 bits float 98 | }; 99 | 100 | struct animated_transform_params; 101 | struct triangle_mesh_params; 102 | struct shader_params; 103 | struct light_params; 104 | struct particle_stream_data; 105 | struct particle_stream_interface_data; 106 | struct fractal_parameters_data; 107 | struct multi_channel_exr_file_saver_data; 108 | struct file_saver_data; 109 | struct krakatoa_renderer_params; 110 | struct texture_data; 111 | 112 | class progress_logger_interface; 113 | class frame_buffer_interface; 114 | class cancel_render_interface; 115 | class render_save_interface; 116 | class fractal_parameters; 117 | class particle_stream_interface; 118 | 119 | /** 120 | * Data layout used by frame_buffer_interface and render_save_interface. 121 | */ 122 | struct frame_buffer_pixel_data { 123 | float r; 124 | float g; 125 | float b; 126 | float r_alpha; 127 | float g_alpha; 128 | float b_alpha; 129 | }; 130 | 131 | } // namespace krakatoasr 132 | 133 | #endif 134 | -------------------------------------------------------------------------------- /KrakatoaSR/include/krakatoasr_renderer/image_writer.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace krakatoasr { 8 | /// saves a list of images to a multi-channel exr file. 9 | void save_multi_channel_exr_file( const multi_channel_exr_file_saver_data& saverData, int width, int height, 10 | int imageCount, const output_type_t* listOfTypes, 11 | const frame_buffer_pixel_data* const* listOfImages ); 12 | void save_tiled_multi_channel_exr_file( const multi_channel_exr_file_saver_data& saverData, int width, int height, 13 | int imageCount, const output_type_t* listOfTypes, 14 | const frame_buffer_pixel_data* const* listOfImages, int tileWidth, 15 | int tileHeight, const std::vector& listOfCustomChannelNames ); 16 | /// saves a list of images to separate rbga image files. 17 | void save_image_file( const file_saver_data& saverData, int width, int height, int imageCount, 18 | const output_type_t* listOfTypes, const frame_buffer_pixel_data* const* listOfImages ); 19 | /// loads a depth map file 20 | /// @param depthFormat Can be "cameraSpace", "normalized", or "invertedNormalized" that represents the data in the file 21 | /// that is being loaded. 22 | void load_depth_map_file( const std::string& filename, std::vector& outBuffer, 23 | frantic::graphics2d::size2& outSize, const std::string& depthFormat, float zNear = 0.0f, 24 | float zFar = 0.0f ); 25 | } // namespace krakatoasr 26 | -------------------------------------------------------------------------------- /KrakatoaSR/include/krakatoasr_renderer/progress_logger.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace krakatoasr { 13 | 14 | class krakatoasr_progress_logger : public frantic::logging::render_progress_logger { 15 | private: 16 | progress_logger_interface* m_progressLoggerUpdater; 17 | frame_buffer_interface* m_frameBufferUpdater; 18 | cancel_render_interface* m_cancelRenderCheck; 19 | time_t m_lastProgressUpdateTime; 20 | time_t m_lastFrameBufferUpdateTime; 21 | 22 | public: 23 | krakatoasr_progress_logger( progress_logger_interface* progressLoggerUpdater, 24 | frame_buffer_interface* frameBufferUpdater, cancel_render_interface* cancelRenderCheck ) 25 | : m_progressLoggerUpdater( progressLoggerUpdater ) 26 | , m_frameBufferUpdater( frameBufferUpdater ) 27 | , m_cancelRenderCheck( cancelRenderCheck ) 28 | , m_lastProgressUpdateTime( 0 ) 29 | , m_lastFrameBufferUpdateTime( 0 ) {} 30 | virtual ~krakatoasr_progress_logger() {} 31 | void set_title( const frantic::strings::tstring& title ) { 32 | if( m_progressLoggerUpdater ) 33 | m_progressLoggerUpdater->set_title( frantic::strings::to_string( title.c_str() ).c_str() ); 34 | } 35 | void update_progress( long long completed, long long maximum ) { 36 | update_progress( (float)completed * 100.f / maximum ); 37 | } 38 | void update_progress( float progressPercent ) { 39 | if( !m_progressLoggerUpdater && !m_cancelRenderCheck ) 40 | return; 41 | time_t currentTime = time( NULL ); // is doing a clock call more efficient than calling update? it is if update 42 | // does a console print, but it's tough to tell. 43 | if( currentTime > m_lastProgressUpdateTime ) { // only call update once a second 44 | m_lastProgressUpdateTime = currentTime; 45 | check_for_abort(); // this is here because check_for_abort doesn't get called much by Krakatoa. 46 | if( m_progressLoggerUpdater ) { 47 | float totalProgress = get_adjusted_progress( progressPercent ); 48 | m_progressLoggerUpdater->set_progress( totalProgress * 0.01f ); 49 | } 50 | } 51 | } 52 | virtual void update_frame_buffer( frantic::graphics2d::framebuffer& buffer ) { 53 | if( !m_frameBufferUpdater ) 54 | return; 55 | 56 | // At least one second must pass before currentTime is greater than m_lastFrameBufferUpdateTime 57 | // If this is called at 100% completion, we will also display a frame to ensure the last frame is shown. This is 58 | // a little hacky, but in KSR, we're being sure to set the progress to 100% prior to displaying the last frame 59 | // buffer. 60 | time_t currentTime = time( NULL ); 61 | if( currentTime > m_lastFrameBufferUpdateTime || m_progressEnd > 99.999f ) { 62 | m_lastFrameBufferUpdateTime = currentTime; 63 | 64 | // NOTE: this call assumes color6f has the same memory layout as frame_buffer_pixel_data. Which is does. but 65 | // if that changes, we're boned. 66 | const std::vector& vectorBuffer = buffer.data(); 67 | const frantic::graphics::color6f* rawBuffer = &vectorBuffer[0]; 68 | 69 | m_frameBufferUpdater->set_frame_buffer( buffer.width(), buffer.height(), 70 | (const frame_buffer_pixel_data*)rawBuffer ); 71 | } 72 | } 73 | 74 | virtual void check_for_abort() { 75 | if( m_cancelRenderCheck && m_cancelRenderCheck->is_cancelled() ) { 76 | throw frantic::logging::progress_cancel_exception( 77 | frantic::strings::to_string( "Operation cancelled by user." ) ); 78 | } 79 | } 80 | }; 81 | 82 | } // namespace krakatoasr 83 | -------------------------------------------------------------------------------- /KrakatoaSR/include/krakatoasr_renderer/renderer.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #pragma once 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | namespace krakatoasr { 12 | 13 | /** 14 | * Decides if krakatoa needs to check out a license before rendering. 15 | * This function can be called prior to render_scene to determine if a license is needed. 16 | * This will return true if the image is larger than 640x480, and there is some form of output. 17 | * It will also always return true if params.errorOnMissingLicense is set. 18 | */ 19 | bool needs_license_to_render( const krakatoa_renderer_params& params ); 20 | 21 | /** 22 | * Renders a scene. 23 | * After this call returns, all particle streams are cleared from the params. 24 | * @param params The scene rendering is based entirely on this parameter object. 25 | * @param licenseEnforcer The licenser object that will request a license (if not already checked out). 26 | * @param licenseRequiredForPRTExport If this is false, then an "export" job (no image output) will not actually require 27 | * a license to exist. 28 | * @return true if the render completed successfully, false otherwise 29 | */ 30 | bool render_scene( krakatoa_renderer_params& params ); 31 | 32 | boost::shared_ptr 33 | setup_raytrace_renderer( krakatoa_renderer_params& params, 34 | krakatoa::renderer::particle_container_type& particleBuffer ); 35 | 36 | } // namespace krakatoasr 37 | -------------------------------------------------------------------------------- /KrakatoaSR/include/krakatoasr_transformation.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #ifndef __KRAKATOASR_TRANSFORMATION__ 4 | #define __KRAKATOASR_TRANSFORMATION__ 5 | 6 | #include 7 | 8 | namespace krakatoasr { 9 | 10 | /** 11 | * Transformation matrix. 12 | * This is a helper class for the renderer. It represents an animated or unanimated transformation matrix. 13 | */ 14 | class CLSEXPORT animated_transform { 15 | private: 16 | animated_transform_params* m_data; 17 | 18 | public: 19 | /** 20 | * Default constructor. 21 | * Use this constructor if you want to create animated transformations. 22 | * To set the matrix to non-identity, the user will want to call "add_transform" one or more times. 23 | * If the user does not call "add_transform", it will default to the identity matrix. 24 | */ 25 | animated_transform(); 26 | 27 | /** 28 | * Unanimated matrix constructor from element array. 29 | * When using this constructor, the matrix will be unanimated. 30 | * @param elements An array of 16 floating point elements representing a 4x4 transformation matrix. 31 | */ 32 | animated_transform( const float* elements ); 33 | 34 | /** 35 | * Unanimated matrix constructor from list of elements. 36 | * When using this constructor, the matrix will be unanimated. 37 | * @param "eXY" the "X" and "Y" elements of the 4x4 transformation matrix. 38 | */ 39 | animated_transform( float e11, float e21, float e31, float e41, float e12, float e22, float e32, float e42, 40 | float e13, float e23, float e33, float e43, float e14, float e24, float e34, 41 | float e44 ); // unanimated 42 | 43 | ~animated_transform(); 44 | animated_transform( const animated_transform& t ); 45 | animated_transform& operator=( const animated_transform& t ); 46 | const animated_transform_params* get_data() const; 47 | animated_transform_params* get_data(); 48 | 49 | /** 50 | * Adds a transformation from element array at a specific shutter time. 51 | * Used for constructing animated transformations. This function can be called multiple times for different shutter 52 | * times. 53 | * @param elements An array of 16 floating point elements representing a 4x4 transformation matrix. 54 | * @param shutterTime The shutter time in seconds of this matrix. 55 | */ 56 | void add_transform( const float* elements, float shutterTime ); 57 | 58 | /** 59 | * Adds a transformation from element array at a specific shutter time. 60 | * Used for constructing animated transformations. This function can be called multiple times for different shutter 61 | * times. 62 | * @param "eXY" the "X" and "Y" elements of the 4x4 transformation matrix. 63 | * @param shutterTime The shutter time in seconds of this matrix. 64 | */ 65 | void add_transform( float e11, float e21, float e31, float e41, float e12, float e22, float e32, float e42, 66 | float e13, float e23, float e33, float e43, float e14, float e24, float e34, float e44, 67 | float shutterTime ); 68 | 69 | /** 70 | * Retrieves a transformation matrix at a given shutter time. 71 | * When the transformation matrix is animated, it will use linear interpolation to create a transformation at the 72 | * given shutter time. 73 | * @param outElements The user must pass in a 16 element float array. The resulting transformation matrix will be 74 | * placed in this array. 75 | * @param shutterTime The desired matrix's shutter time in seconds. If it is unanimated, this parameter will not be 76 | * used. 77 | */ 78 | void get_transform( float* outElements, float shutterTime = 0.0f ) const; 79 | 80 | /** 81 | * Test to see if this matrix is animated. 82 | * @return True if the matrix is animated. 83 | */ 84 | bool is_animated() const; 85 | 86 | /** 87 | * Test if the matrix is the identity matrix. 88 | * @return True if the matrix is always the identity matrix. 89 | */ 90 | bool is_identity() const; 91 | }; 92 | 93 | } // namespace krakatoasr 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /KrakatoaSR/include/mainpage.dox: -------------------------------------------------------------------------------- 1 | /** 2 | \mainpage Krakatoa SR C++ API 3 | 4 | @section overview_section Overview 5 | 6 | @par 7 | Krakatoa is Thinkbox Software's production-proven volumetric particle renderer. The Krakatoa SR C++ API allows programmers to write their own interface to Krakatoa. 8 | 9 | @par 10 | The API provides all of Krakatoa's engine functionality. It allows the users to input particles and meshes directly, and provides callbacks for progress and image display. 11 | 12 | @section getting_started_section Getting Started 13 | 14 | @par 15 | The easist way to begin your project is to browse the C++ files included in the "examples" directory. These samples demonstrate how to perform simple renders and how to use the various features of the API. 16 | 17 | @par 18 | The krakatoa_renderer class is the principal class in the API. It collects all the render data and performs the final render. Every project that uses the API will contain a krakatoa_renderer object.
19 | See krakatoasr::krakatoa_renderer 20 | 21 | @section support_section Support 22 | 23 | @par 24 | All technical support is conducted though our forums:
25 | http://forums.thinkboxsoftware.com/ 26 | 27 | @par 28 | For licensing or other inquiries, please contact:
29 | support@thinkboxsoftware.com 30 | 31 | */ -------------------------------------------------------------------------------- /KrakatoaSR/src/cstandardout.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | #include "stdafx.h" 4 | 5 | #include 6 | 7 | // This can be removed when we get a version of Flex which supports Visual Studio 2015 8 | #if defined( THINKBOX_DEF_STDIO ) && defined( _WIN32 ) && _MSC_VER >= 1900 9 | extern "C" { 10 | FILE __iob_func[3] = { *stdin, *stdout, *stderr }; 11 | } 12 | #endif -------------------------------------------------------------------------------- /KrakatoaSR/src/dllmain.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // dllmain.cpp : Defines the entry point for the DLL application. 4 | #include "stdafx.h" 5 | 6 | #if defined( WIN32 ) 7 | BOOL APIENTRY DllMain( HMODULE /*hModule*/, DWORD ul_reason_for_call, LPVOID /*lpReserved*/ 8 | ) { 9 | switch( ul_reason_for_call ) { 10 | case DLL_PROCESS_ATTACH: 11 | case DLL_THREAD_ATTACH: 12 | case DLL_THREAD_DETACH: 13 | case DLL_PROCESS_DETACH: 14 | break; 15 | } 16 | return TRUE; 17 | } 18 | #endif 19 | -------------------------------------------------------------------------------- /KrakatoaSR/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // stdafx.cpp : source file that includes just the standard includes 4 | // KrakatoaSR_vs2010.pch will be the pre-compiled header 5 | // stdafx.obj will contain the pre-compiled type information 6 | 7 | #include "stdafx.h" 8 | 9 | // TODO: reference any additional headers you need in STDAFX.H 10 | // and not in this file 11 | -------------------------------------------------------------------------------- /KrakatoaSR/stdafx.h: -------------------------------------------------------------------------------- 1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | // SPDX-License-Identifier: Apache-2.0 3 | // stdafx.h : include file for standard system include files, 4 | // or project specific include files that are used frequently, but 5 | // are changed infrequently 6 | // 7 | 8 | #pragma once 9 | 10 | #ifndef _USE_MATH_DEFINES 11 | #define _USE_MATH_DEFINES 12 | #endif 13 | 14 | #include 15 | 16 | #ifdef WIN32 17 | 18 | // Including SDKDDKVer.h defines the highest available Windows platform. 19 | 20 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 21 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 22 | //#include 23 | 24 | // Specify a requirement for Win2K. See http://msdn.microsoft.com/en-us/library/aa383745(VS.85).aspx 25 | #define _WIN32_WINNT 0x0501 26 | 27 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 28 | #define NOMINMAX 29 | 30 | // Windows Header Files: 31 | #include 32 | 33 | #endif 34 | 35 | // TODO: reference additional headers your program requires here 36 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | Krakatoa 2 | Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Krakatoa 2 | 3 | ## Overview 4 | 5 | Krakatoa is a fast particle renderer for use in visual effects applications. More information can be found [here](https://aws.amazon.com/thinkbox-krakatoa/). 6 | 7 | This repository contains subdirectories with two different projects. The `Krakatoa` subdirectory contains the underlying code for the Krakatoa renderer itself. The `KrakatoaSR` subdirectory contains a C++ API for interacting with Krakatoa. 8 | 9 | ## Table of Contents 10 | 11 | - [Reporting Bugs/Feature Requests](#reporting-bugs/feature-requests) 12 | - [Security issue notifications](#security-issue-notifications) 13 | - [Contributing](#contributing) 14 | - [Code of Conduct](#code-of-conduct) 15 | - [Licensing](#licensing) 16 | 17 | ## Reporting Bugs/Feature Requests 18 | 19 | We welcome you to use the GitHub issue tracker to report bugs or suggest features. 20 | 21 | When filing an issue, please check existing open, or recently closed, issues to make sure somebody else hasn't already 22 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: 23 | 24 | - A reproducible test case or series of steps 25 | - The version of our code being used 26 | - Any modifications you've made relevant to the bug 27 | - Anything unusual about your environment or deployment 28 | 29 | ## Security issue notifications 30 | 31 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. 32 | 33 | ## Contributing 34 | 35 | Contributions to Krakatoa are encouraged. If you want to fix a problem, or want to enhance the library in any way, then 36 | we are happy to accept your contribution. Information on contributing to Krakatoa can be found 37 | [in CONTRIBUTING.md](CONTRIBUTING.md). 38 | 39 | ## Code of Conduct 40 | 41 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 42 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 43 | opensource-codeofconduct@amazon.com with any additional questions or comments. 44 | 45 | ## Licensing 46 | 47 | See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. 48 | 49 | We may ask you to sign a [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes. 50 | --------------------------------------------------------------------------------