diff --git a/.clang-format b/.clang-format index 2eb120c..fc66707 100644 --- a/.clang-format +++ b/.clang-format @@ -16,7 +16,6 @@ BreakBeforeBinaryOperators: false BreakBeforeBraces: Allman # brace on new line BreakBeforeTernaryOperators: true BreakConstructorInitializersBeforeComma: true -ColumnLimit: 120 ConstructorInitializerAllOnOneLineOrOnePerLine: false ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 @@ -37,7 +36,7 @@ PenaltyBreakString: 1000 PenaltyExcessCharacter: 1000000 PenaltyReturnTypeOnItsOwnLine: 200 PointerBindsToType: true -SortIncludes: false +SortIncludes: true SpaceAfterControlStatementKeyword: true SpaceBeforeAssignmentOperators: true SpaceBeforeParens: ControlStatements diff --git a/.travis.yml b/.travis.yml index 4264a78..79c1976 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,4 +39,6 @@ script: - mkdir build - cd build - ${DEPS_DIR}/cmake/bin/cmake .. && make - \ No newline at end of file + +services: + - docker diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b0d3bd..df7f728 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,18 @@ +# Copyright (c) 2011-2022, Cyrille Favreau +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + cmake_minimum_required(VERSION 3.5) set(PROJECT_NAME SolR) @@ -17,10 +32,13 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake) # Project # ================================================================================ +option(SOLR_RANDOM_DEVICE_ENABLED "Activate Random Device Generator" OFF) option(SOLR_KINECT_ENABLED "Activate Kinect" OFF) option(SOLR_OCULUS_ENABLED "Activate Oculus" OFF) option(SOLR_SIXENSE_ENABLED "Activate Sixense Controller" OFF) option(SOLR_LEAPMOTION_ENABLED "Activate Leap Motion Controller" OFF) +option(SOLR_DEFLECT_ENABLED "Activate Deflect streaming" OFF) +option(SOLR_BUILD_ANARI_DEVICE "Build Sol-R as ANARI library device" OFF) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release" CACHE STRING @@ -42,9 +60,7 @@ set_property(CACHE SOLR_LIBRARY_TYPE PROPERTY STRINGS STATIC SHARED) if(MSVC) add_compile_options(-D_USE_MATH_DEFINES -DNOMINMAX -std=c++11) else(MSVC) - # __STRICT_ANSI__ is required by OpenCL in order to access x,y,z.. member of - # cl_float2/3/.. data types. Took me a little while to find out... - add_compile_options(-std=c++11 -U__STRICT_ANSI__) + add_compile_options(-fPIC -std=c++11) if(APPLE) add_compile_options(-Wno-c++11-extensions -Wno-narrowing -Wno-deprecated-declarations -Wno-macro-redefined -Wno-shift-negative-value -Wno-comment) @@ -120,6 +136,15 @@ if (OPENMP_FOUND) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") endif(OPENMP_FOUND) +# ================================================================================ +# Random Generation device +# ================================================================================ +if(SOLR_RANDOM_DEVICE_ENABLED) + # TODO: Find package of random device library and add includes/libs + # include_directories(${ ... _INCLUDE_DIR}) + # list(APPEND FIND_PACKAGES_DEFINES USE_RANDOM_DEVICE) +endif(SOLR_RANDOM_DEVICE_ENABLED) + # ================================================================================ # KINECT 1.8 # ================================================================================ @@ -195,19 +220,53 @@ if(SOLR_LEAPMOTION_ENABLED) endif(LEAP_FOUND) endif(SOLR_LEAPMOTION_ENABLED) +# ================================================================================ +# Deflect +# ================================================================================ +if(SOLR_DEFLECT_ENABLED) + find_package(Deflect REQUIRED SYSTEM) + if (Deflect_FOUND) + message(STATUS "Deflect found and selected for build") + include_directories(${DEFLECT_INCLUDE_DIR}) + list(APPEND FIND_PACKAGES_DEFINES USE_DEFLECT) + else(Deflect_FOUND) + message(ERROR " Deflect not found!") + endif(Deflect_FOUND) +endif(SOLR_DEFLECT_ENABLED) + +# ================================================================================ +# ANARI SDK (optional) +# ================================================================================ +if(SOLR_BUILD_ANARI_DEVICE) + find_package(anari 0.15.0 REQUIRED) + if(anari_FOUND) + message(STATUS "ANARI SDK found and selected for ANARI device build") + list(APPEND FIND_PACKAGES_DEFINES USE_ANARI) + else() + message(ERROR "ANARI SDK not found. Cannot build ANARI device") + endif() +endif() + # ================================================================================ # Project # ================================================================================ add_subdirectory(solr) add_subdirectory(apps) +# ================================================================================ +# ANARI Device +# ================================================================================ +if(SOLR_BUILD_ANARI_DEVICE AND anari_FOUND) + add_subdirectory(devices) +endif() + # ================================================================================ # Write defines.h and options.cmake # ================================================================================ if(NOT OPTIONS_CMAKE) set(OPTIONS_CMAKE ${CMAKE_CURRENT_BINARY_DIR}/options.cmake) endif(NOT OPTIONS_CMAKE) -set(DEFINES_FILE "${PROJECT_SOURCE_DIR}/${PROJECT_INCLUDE_NAME}/generated/defines${SYSTEM}.h") +set(DEFINES_FILE "${PROJECT_SOURCE_DIR}/${PROJECT_INCLUDE_NAME}/generated/solr_defines.h") file(WRITE ${DEFINES_FILE} "// generated by CMake, do not edit.\n\n" "#ifndef ${PROJECT_NAME}_DEFINES_${SYSTEM}_H\n" diff --git a/DOCKER.md b/DOCKER.md new file mode 100644 index 0000000..cae12eb --- /dev/null +++ b/DOCKER.md @@ -0,0 +1,33 @@ +# Sol-R with Docker + +> Use [Docker](https://docs.docker.com) to run Sol-R as a service and avoid painful tooling setup. + +**NOTE**: This is work in progress. + +### Prerequisites +----------------- +Head over to [Docker](https://docs.docker.com/engine/installation/#supported-platforms) and install Docker for your own platform. + + +### Setup +--------- +First build the image (*it's necessary to do this step if you want to run Sol-R*): +```bash +docker build . -t Sol-R +``` + + +### Usage +--------- +By default, the entrypoint when running the image is `Sol-R`, but if you want to ssh into the container use: +```bash +docker run -ti --rm --entrypoint bash Sol-R +``` + +If you want to run Sol-R: +```bash +docker run -ti --rm Sol-R +``` + +**NOTE** If you are having trouble exiting the process after you run the container (with the above command), use `docker stop ` to stop the container. +`docker ps` will give you the current running process. diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3e80892 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,49 @@ +# Docker container for running Sol-R viewer +FROM ubuntu:xenial + +ENV DIST_PATH /app/dist +ENV BUILD_TOOLS build-essential cmake git wget freeglut3-dev + +# Set working dir and copy Sol-R assets +ENV SOLR_SRC /app/solr +WORKDIR /app +ADD . ${SOLR_SRC} + +# CUDA 8 +ENV PATH=/usr/local/cuda/bin:$PATH \ + LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH + +# Install Sol-R +# https://github.com/favreau/Sol-R +RUN apt-get update && \ + apt-get -y install ${BUILD_TOOLS} && \ + mkdir ${SOLR_SRC}/tmp && \ + cd ${SOLR_SRC}/tmp && \ + wget https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda_8.0.61_375.26_linux-run && \ + chmod +x cuda_*_linux-run && ${SOLR_SRC}/tmp/cuda_*_linux-run -extract=${SOLR_SRC}/tmp && \ + ${SOLR_SRC}/tmp/cuda-linux64-rel*.run -noprompt | cat > /dev/null && \ + cd ${SOLR_SRC} && \ + rm -rf tmp && \ + mkdir build && \ + cd build && \ + cmake .. \ + -DCMAKE_INSTALL_PREFIX=${DIST_PATH} \ + -DCMAKE_BUILD_TYPE=Release \ + -DSOLR_ENGINE=CUDA && \ + make -j8 install && \ + cd /app && \ + rm -rf ${SOLR_SRC}/build && \ + apt-get -y remove ${BUILD_TOOLS} && \ + apt-get clean + +# Add binaries from dist to the PATH +ENV LD_LIBRARY_PATH $LD_LIBRARY_PATH:${DIST_PATH}/lib +ENV PATH $PATH:${DIST_PATH}/bin + +# When running `docker run -ti --rm sol-r`, +# this will be the cmd that will be executed (+ the CLI options from CMD). +# To ssh into the container (or override the default entry) use: +# `docker run -ti --rm --entrypoint bash sol-r` +# See https://docs.docker.com/engine/reference/run/#entrypoint-default-command-to-execute-at-runtime +# for more docs +ENTRYPOINT ["solrViewer"] diff --git a/LGPL.txt b/LGPL.txt deleted file mode 100644 index 65c5ca8..0000000 --- a/LGPL.txt +++ /dev/null @@ -1,165 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. diff --git a/LICENSE.txt b/LICENSE.txt index 9681161..d159169 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,11 +1,339 @@ -Brayns is a minimalistic visualiser that can perform ray-traced rendering of neurons + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 -Brayns is licensed under the LGPL, unless noted otherwise, e.g., for external dependencies. See file LGPL.txt for the full license. External dependencies are either LGPL or BSD-licensed. See file ACKNOWLEDGEMENTS.txt and AUTHORS.txt for further details. + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. -Copyright (c) 2015-2016, EPFL/Blue Brain Project and AUTHORS.txt. + Preamble -This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. -This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. -You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/README.md b/README.md index 66d08ae..d0a0c08 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,54 @@ [![Build Status](https://travis-ci.org/favreau/Sol-R.svg?branch=master)](https://travis-ci.org/favreau/Sol-R) -### Introduction +# Welcome to Sol-R, the Speed Of Light Ray-tracer + +## Big news: Sol-R goes Quantum! + +Sol-R becomes Quantum of Sol-R, thanks to the use of a Quantum Physics based random generation device. Unfortunately, the API to access the random number generator is not open-source but if you buy the [ID Quantique QRng](https://www.idquantique.com/random-number-generation/overview/) device, you will simply need to modify the *_getFloats* implementation of the [RandomGenerator](./solr/engines/random/RandomGenerator.h) class, and I can tell you that it's pretty straight forward! You will also need to add set the _SOLR_RANDOM_DEVICE_ENABLED_ cmake option to _ON_ before configuring the project. + +![Sol-R_001](doc/images/Sol-R_001.png) + + +## Note about the Blue Brain BioExplorer, a Sol-R sequel + +If you like Sol-R, but you think it's now getting a bit old, you will love my new open-source, the [Blue Brain BioExplorer](https://github.com/BlueBrain/BioExplorer). Check-it out and star the GitHub Repository to support the project. + +## Introduction Sol-R is a CUDA/OpenCL-based realtime ray-tracer compatible with Oculus Rift DK1, Kinect, Razor Hydra and Leap Motion devices. -Sol-R was used by the Interactive Molecular Visualiser project (http://www.molecular-visualization.com) +Sol-R was used by the Interactive Molecular Visualizer project (http://www.molecular-visualization.com) -A number of videos can be found on my channel: https://www.youtube.com/user/CyrilleOnDrums +A number of videos can be found on my [Youtube channel](https://www.youtube.com/user/CyrilleOnDrums). Sol-R was written as a hobby project in order to understand and learn more about CUDA and OpenCL. Most of the code was written at night and during week-ends, meaning that it's probably not the best quality ever ;-) -The idea was to produce a Ray-Tracer that has its own "personality". Most of the code does not rely on any litterature about ray-tracing, but more on a naive approach of what rays could be used for. The idea was not to produce a physically based ray-tracer, but a simple engine that could produce cool images interactively. +The idea was to produce a Ray-Tracer that has its own "personality". Most of the code does not rely on any literature about ray-tracing, but more on a naive approach of what rays could be used for. A simple engine that could produce cool images interactively. Take it for what it is! Sol-R is a lot of fun to play with if you like coding computer generated images. -May the fun continue with your contributions! :-) +May the fun continue with your contributions! :) ``` usage: solrViewer ``` -### Prerequeries +![Sol-R_002](doc/images/Sol-R_002.png) + + +## Prerequeries -#### Mandatory +### Mandatory - CMake 3.5 - Glew 2.x - Glut 3.7 - Cuda 8.0 or OpenCL 1.2 -#### Optional +### Optional - Kinect SDK 1.8 - Oculus Rift DK1 SDK 0.2.5 - Sixense SDK - Leap SDK 3.2.0 -### Build +## Build from source ``` mkdir Build cd Build @@ -41,7 +57,7 @@ make install ``` Note that the installation process with deploy extra files that are needed by the Sol-R viewer. Typically, textures, environment maps and OpenCL kernels. Therefore, it is required to run the solrViewer application from the installation folder. -### Run +## Run ``` /bin/solrViewer ``` @@ -58,21 +74,9 @@ Optional dependencies can be activated using the following cmake options: cmake .. -DSOLR_KINECT_ENABLED=ON -DSOLR_OCULUS_ENABLED=ON -DSOLR_SIXENSE_ENABLED -DSOLR_LEAPMOTION_ENABLED=ON ``` -### Screenshots -![Sol-R_001](doc/images/Sol-R_001.png) -![Sol-R_002](doc/images/Sol-R_002.png) -![Sol-R_003](doc/images/Sol-R_003.png) -![Sol-R_004](doc/images/Sol-R_004.png) -![Sol-R_005](doc/images/Sol-R_005.png) -![Sol-R_006](doc/images/Sol-R_006.png) -![Sol-R_007](doc/images/Sol-R_007.png) -![Sol-R_008](doc/images/Sol-R_008.png) -![Sol-R_009](doc/images/Sol-R_009.png) -![Sol-R_009](doc/images/Sol-R_010.png) - ### Supported platforms Sol-R has currently been tested on: - Windows 7 with Visual Studio 2015 Community edition - Mac OS X Sierra 10.12.15 -- Ubuntu 16.04 +- Ubuntu 20.04 diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index 65c66e9..6f0036f 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -62,6 +62,10 @@ ADD_EXECUTABLE( scenes/science/ColumnScene.h scenes/science/MoleculeScene.cpp scenes/science/MoleculeScene.h + scenes/science/HypercubeScene.cpp + scenes/science/HypercubeScene.h + scenes/science/TesseractScene.cpp + scenes/science/TesseractScene.h ) diff --git a/apps/common/Types.h b/apps/common/Types.h index d59598a..df25884 100644 --- a/apps/common/Types.h +++ b/apps/common/Types.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once diff --git a/apps/common/Utils.cpp b/apps/common/Utils.cpp index b9a1a9a..e5d27bd 100644 --- a/apps/common/Utils.cpp +++ b/apps/common/Utils.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include "Utils.h" @@ -33,7 +30,8 @@ Strings getFilesFromFolder(const std::string& folder, const Strings& extensions) Strings filenames; #ifdef WIN32 // Textures - for (Strings::const_iterator it = extensions.begin(); it != extensions.end(); ++it) + for (Strings::const_iterator it = extensions.begin(); + it != extensions.end(); ++it) { std::string fullFilter(folder); fullFilter += "/*"; @@ -60,7 +58,8 @@ Strings getFilesFromFolder(const std::string& folder, const Strings& extensions) const std::string path = dirp->d_name; bool ok = false; - for (Strings::const_iterator it = extensions.begin(); !ok && it != extensions.end(); ++it) + for (Strings::const_iterator it = extensions.begin(); + !ok && it != extensions.end(); ++it) if (path.find(*it) != std::string::npos) ok = true; diff --git a/apps/common/Utils.h b/apps/common/Utils.h index 9a24df5..d67fda7 100644 --- a/apps/common/Utils.h +++ b/apps/common/Utils.h @@ -1,25 +1,23 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once #include "Types.h" -Strings getFilesFromFolder(const std::string& folder, const Strings& extensions = Strings()); +Strings getFilesFromFolder(const std::string& folder, + const Strings& extensions = Strings()); diff --git a/apps/scenes/Scene.cpp b/apps/scenes/Scene.cpp index 1639f1e..7ee4096 100644 --- a/apps/scenes/Scene.cpp +++ b/apps/scenes/Scene.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau - * - * This file is part of Sol-R +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ // Project @@ -58,8 +55,6 @@ #include #endif // USE_SIXENSE -using namespace solr; - const int gTotalPathTracingIterations = 2000; #ifdef USE_SIXENSE @@ -85,20 +80,24 @@ std::string controller_manager_text_string; // 3) Enables hemisphere tracking by calling the Sixense API call // sixenseAutoEnableHemisphereTracking. After this is completed full 360 degree // tracking is possible. -void controller_manager_setup_callback(sixenseUtils::ControllerManager::setup_step step) +void controller_manager_setup_callback( + sixenseUtils::ControllerManager::setup_step step) { if (sixenseUtils::getTheControllerManager()->isMenuVisible()) { - // Turn on the flag that tells the graphics system to draw the instruction - // screen instead of the controller information. The game + // Turn on the flag that tells the graphics system to draw the + // instruction screen instead of the controller information. The game // should be paused at this time. controller_manager_screen_visible = true; - // Ask the controller manager what the next instruction string should be. - controller_manager_text_string = sixenseUtils::getTheControllerManager()->getStepString(); + // Ask the controller manager what the next instruction string should + // be. + controller_manager_text_string = + sixenseUtils::getTheControllerManager()->getStepString(); // We could also load the supplied controllermanager textures using the - // filename: sixenseUtils::getTheControllerManager()->getTextureFileName(); + // filename: + // sixenseUtils::getTheControllerManager()->getTextureFileName(); } else { @@ -186,9 +185,11 @@ ________________________________________________________________________________ ________________________________________________________________________________ */ -void Scene::initialize(solr::GPUKernel *kernel, const int width, const int height) +void Scene::initialize(GPUKernel *kernel, const int width, const int height) { - LOG_INFO(1, "--------------------------------------------------------------------------------"); + LOG_INFO(1, + "-----------------------------------------------------------------" + "---------------"); LOG_INFO(1, "Scene...............: " << m_name); m_gpuKernel = kernel; @@ -200,7 +201,8 @@ void Scene::initialize(solr::GPUKernel *kernel, const int width, const int heigh // Scene sceneInfo.size.x = width; sceneInfo.size.y = height; - sceneInfo.graphicsLevel = (sceneInfo.cameraType == ctVolumeRendering) ? glNoShading : glFull; + sceneInfo.graphicsLevel = + (sceneInfo.cameraType == ctVolumeRendering) ? glNoShading : glFull; sceneInfo.nbRayIterations = 3; sceneInfo.transparentColor = 0.f; sceneInfo.viewDistance = 50000.f; @@ -224,7 +226,7 @@ void Scene::initialize(solr::GPUKernel *kernel, const int width, const int heigh sceneInfo.skyboxRadius = static_cast(sceneInfo.viewDistance * 0.9f); sceneInfo.skyboxMaterialId = SKYBOX_SPHERE_MATERIAL; sceneInfo.gradientBackground = 0; - sceneInfo.geometryEpsilon = 0.001f; + sceneInfo.geometryEpsilon = 0.05f; sceneInfo.rayEpsilon = 0.05f; // HDRI @@ -237,7 +239,8 @@ void Scene::initialize(solr::GPUKernel *kernel, const int width, const int heigh // Textures loadTextures(std::string(DEFAULT_MEDIA_FOLDER) + "/textures", filters); - LOG_INFO(1, "Material textures..: " << m_gpuKernel->getNbActiveTextures() - m_nbHDRI); + LOG_INFO(1, "Material textures..: " << m_gpuKernel->getNbActiveTextures() - + m_nbHDRI); // Materials createRandomMaterials(false, false); @@ -271,8 +274,10 @@ void Scene::initialize(solr::GPUKernel *kernel, const int width, const int heigh // Init the controller manager. This makes sure the controllers are present, // assigned to left and right hands, and that // the hemisphere calibration is complete. - sixenseUtils::getTheControllerManager()->setGameType(sixenseUtils::ControllerManager::ONE_PLAYER_TWO_CONTROLLER); - sixenseUtils::getTheControllerManager()->registerSetupCallback(controller_manager_setup_callback); + sixenseUtils::getTheControllerManager()->setGameType( + sixenseUtils::ControllerManager::ONE_PLAYER_TWO_CONTROLLER); + sixenseUtils::getTheControllerManager()->registerSetupCallback( + controller_manager_setup_callback); m_modelPosition.x = 0.f; m_modelPosition.y = 0.f; @@ -337,21 +342,26 @@ ________________________________________________________________________________ void Scene::loadTextures(const std::string &path, const Strings &filters) { const Strings textureFiles = getFilesFromFolder(path, filters); - for (std::vector::const_iterator it = textureFiles.begin(); it != textureFiles.end(); ++it) - if (m_gpuKernel->loadTextureFromFile(m_gpuKernel->getNbActiveTextures(), *it)) - LOG_INFO(3, "[Slot " << m_gpuKernel->getNbActiveTextures() - 1 << "] Texture " << *it + for (std::vector::const_iterator it = textureFiles.begin(); + it != textureFiles.end(); ++it) + if (m_gpuKernel->loadTextureFromFile(m_gpuKernel->getNbActiveTextures(), + *it)) + LOG_INFO(3, "[Slot " << m_gpuKernel->getNbActiveTextures() - 1 + << "] Texture " << *it << " successfully loaded"); } /* -________________________________________________________________________________ +___________________________________ +_____________________________________________ Create Random Materials ________________________________________________________________________________ */ void Scene::createRandomMaterials(bool update, bool lightsOnly) { - int nbMaterialTexturePacks = (m_gpuKernel->getNbActiveTextures() - m_nbHDRI) / 5; + int nbMaterialTexturePacks = + (m_gpuKernel->getNbActiveTextures() - m_nbHDRI) / 5; int start(0); int end(NB_MAX_MATERIALS); if (update) @@ -366,10 +376,16 @@ void Scene::createRandomMaterials(bool update, bool lightsOnly) specular.z = 0.f; specular.w = 0.f; + int refractionPower = 5; +#if 1 float reflection = 0.f; float refraction = 0.f; float transparency = 0.f; - int refractionPower = 5; +#else + float reflection = 0.1f + rand() % 500 / 1000.f; + float refraction = 1.01f + 0.1f * (rand() % refractionPower); + float transparency = (i % 10 == 0 ? 0.5f + rand() % 500 / 1000.f : 0.f); +#endif int diffuseTextureId = TEXTURE_NONE; int normalTextureId = TEXTURE_NONE; @@ -378,16 +394,17 @@ void Scene::createRandomMaterials(bool update, bool lightsOnly) int reflectionTextureId = TEXTURE_NONE; int transparencyTextureId = TEXTURE_NONE; int ambientOcclusionTextureId = TEXTURE_NONE; - vec4f innerIllumination = make_vec4f(0.f, m_gpuKernel->getSceneInfo().viewDistance * 10, - m_gpuKernel->getSceneInfo().viewDistance); + vec4f innerIllumination = + make_vec4f(0.f, m_gpuKernel->getSceneInfo().viewDistance * 10, + m_gpuKernel->getSceneInfo().viewDistance); bool procedural = false; bool wireframe = false; int wireframeDepth = 0; - float r, g, b, noise; + float r, g, b, gloss; r = 0.2f + rand() % 600 / 1000.f; g = 0.2f + rand() % 600 / 1000.f; b = 0.2f + rand() % 600 / 1000.f; - noise = 0.f; + gloss = 0.f; float opacity = 0.f; switch (i) @@ -426,14 +443,12 @@ void Scene::createRandomMaterials(bool update, bool lightsOnly) r = 0.5f; g = 0.5f; b = 0.5f; - noise = 0.f; reflection = 0.f; break; case 1099: r = 0.5f; g = 0.5f; b = 0.5f; - noise = 0.f; reflection = 0.1f; break; @@ -446,7 +461,8 @@ void Scene::createRandomMaterials(bool update, bool lightsOnly) reflection = 0.25f; transparency = 0.f; refraction = 0.f; - r = g = b = 0.5f; + r = g = b = 0.1f; + gloss = 0.2f; } break; @@ -631,6 +647,15 @@ void Scene::createRandomMaterials(bool update, bool lightsOnly) b = 1.f; innerIllumination.x = 2.f; break; + case METAL_MATERIAL: + r = 0.3f; + g = 0.3f; + b = 0.3f; + reflection = 0.5f; + specular.x = 1.f; + specular.y = 50.f; + gloss = 0.5f; + break; default: if (i >= RANDOM_MATERIALS_OFFSET) @@ -657,11 +682,13 @@ void Scene::createRandomMaterials(bool update, bool lightsOnly) { if (nbMaterialTexturePacks > 0) { - int index = m_nbHDRI + 5 * (rand() % nbMaterialTexturePacks); + int index = + m_nbHDRI + 5 * (rand() % nbMaterialTexturePacks); for (int t(0); t < 5; ++t) { int idx = index + t; - TextureInfo ti = m_gpuKernel->getTextureInformation(idx); + TextureInfo ti = + m_gpuKernel->getTextureInformation(idx); switch (ti.type) { case tex_bump: @@ -701,11 +728,16 @@ void Scene::createRandomMaterials(bool update, bool lightsOnly) else m_nbMaterials = m_gpuKernel->addMaterial(); - m_gpuKernel->setMaterial(m_nbMaterials, r, g, b, noise, reflection, refraction, procedural, wireframe, - wireframeDepth, transparency, opacity, diffuseTextureId, normalTextureId, - bumpTextureId, specularTextureId, reflectionTextureId, transparencyTextureId, - ambientOcclusionTextureId, specular.x, specular.y, specular.w, innerIllumination.x, - innerIllumination.y, innerIllumination.z, false); + m_gpuKernel->setMaterial(m_nbMaterials, r, g, b, gloss, reflection, + refraction, procedural, wireframe, + wireframeDepth, transparency, opacity, + diffuseTextureId, normalTextureId, + bumpTextureId, specularTextureId, + reflectionTextureId, transparencyTextureId, + ambientOcclusionTextureId, specular.x, + specular.y, specular.w, innerIllumination.x, + innerIllumination.y, innerIllumination.z, + false); } } @@ -747,7 +779,7 @@ void Scene::createMoleculeMaterials(bool update) int transparencyTextureId = TEXTURE_NONE; int ambientOcclusionTextureId = TEXTURE_NONE; float r, g, b; - float noise = 0.f; + float gloss = 0.f; bool procedural = false; r = 0.5f + rand() % 40 / 100.f; @@ -809,11 +841,15 @@ void Scene::createMoleculeMaterials(bool update) break; // V } m_nbMaterials = m_gpuKernel->addMaterial(); - m_gpuKernel->setMaterial(m_nbMaterials, r, g, b, noise, reflection, refraction, procedural, false, 0, - transparency, opacity, diffuseTextureId, normalTextureId, bumpTextureId, - specularTextureId, reflectionTextureId, transparencyTextureId, - ambientOcclusionTextureId, specular.x, specular.y, specular.w, innerIllumination.x, - innerIllumination.y, innerIllumination.z, fastTransparency); + m_gpuKernel->setMaterial(m_nbMaterials, r, g, b, gloss, reflection, + refraction, procedural, false, 0, transparency, + opacity, diffuseTextureId, normalTextureId, + bumpTextureId, specularTextureId, + reflectionTextureId, transparencyTextureId, + ambientOcclusionTextureId, specular.x, + specular.y, specular.w, innerIllumination.x, + innerIllumination.y, innerIllumination.z, + fastTransparency); } } @@ -824,7 +860,7 @@ ________________________________________________________________________________ */ void Scene::saveToFile() { - solr::FileMarshaller fm; + FileMarshaller fm; std::string filename(m_name); filename += ".irt"; fm.saveToFile(*m_gpuKernel, filename); @@ -837,7 +873,7 @@ ________________________________________________________________________________ */ void Scene::loadFromFile(const float scale) { - solr::FileMarshaller fm; + FileMarshaller fm; std::string filename(m_name); filename += ".irt"; fm.loadFromFile(*m_gpuKernel, filename, make_vec4f(), scale); @@ -848,9 +884,9 @@ void Scene::addCornellBox(int boxType) LOG_INFO(3, "Adding Cornell Box"); LOG_INFO(3, "Ground height = " << m_groundHeight); vec4f skyBoxSize = make_vec4f(20000.f, 20000.f, 20000.f); - const vec2f groundSize = make_vec2f(100000.f, 100000.f); + const vec2f groundSize = make_vec2f(10000.f, 10000.f); float groundHeight = m_groundHeight; - float repeats = 40.f; + float repeats = 10.f; switch (boxType) { @@ -1103,8 +1139,11 @@ void Scene::addCornellBox(int boxType) for (int i(0); i < 25; ++i) { m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, rand() % 20000 - 10000.f, rand() % 20000 - 10000.f, - rand() % 20000 - 10000.f, 500.f + rand() % 2000, 0.f, 0.f, 1000 + rand() % 30); + m_gpuKernel->setPrimitive(m_nbPrimitives, rand() % 20000 - 10000.f, + rand() % 20000 - 10000.f, + rand() % 20000 - 10000.f, + 500.f + rand() % 2000, 0.f, 0.f, + 1000 + rand() % 30); } break; } @@ -1112,43 +1151,55 @@ void Scene::addCornellBox(int boxType) { // Ground m_nbPrimitives = m_gpuKernel->addPrimitive(ptCheckboard); - m_gpuKernel->setPrimitive(m_nbPrimitives, 0.f, groundHeight, 0.f, groundSize.x / 4.f, 0.f, groundSize.y / 4, + m_gpuKernel->setPrimitive(m_nbPrimitives, 0.f, groundHeight, 0.f, + groundSize.x / 4.f, 0.f, groundSize.y / 4, RANDOM_MATERIALS_OFFSET); // Columns m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder); - m_gpuKernel->setPrimitive(m_nbPrimitives, -5000.f, groundHeight - 1000.f, 5000.f, -4000.f, 8000.f, 5000.f, - 2000.f, 0.f, 0.f, RANDOM_MATERIALS_OFFSET + 1); + m_gpuKernel->setPrimitive(m_nbPrimitives, -5000.f, + groundHeight - 1000.f, 5000.f, -4000.f, + 8000.f, 5000.f, 2000.f, 0.f, 0.f, + RANDOM_MATERIALS_OFFSET + 1); m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder); - m_gpuKernel->setPrimitive(m_nbPrimitives, 5000.f, groundHeight - 1000.f, 5000.f, 4000.f, 8000.f, 5000.f, 2000.f, - 0.f, 0.f, RANDOM_MATERIALS_OFFSET + 2); + m_gpuKernel->setPrimitive(m_nbPrimitives, 5000.f, groundHeight - 1000.f, + 5000.f, 4000.f, 8000.f, 5000.f, 2000.f, 0.f, + 0.f, RANDOM_MATERIALS_OFFSET + 2); m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); // Spheres m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, -5000.f, groundHeight + 1000.f, -5000.f, 1000.f, 0.f, 0.f, - RANDOM_MATERIALS_OFFSET + 3); + m_gpuKernel->setPrimitive(m_nbPrimitives, -5000.f, + groundHeight + 1000.f, -5000.f, 1000.f, 0.f, + 0.f, RANDOM_MATERIALS_OFFSET + 3); m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, 5000.f, groundHeight + 1000.f, -5000.f, 1000.f, 0.f, 0.f, + m_gpuKernel->setPrimitive(m_nbPrimitives, 5000.f, groundHeight + 1000.f, + -5000.f, 1000.f, 0.f, 0.f, RANDOM_MATERIALS_OFFSET + 4); m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); // Walls m_nbPrimitives = m_gpuKernel->addPrimitive(ptXYPlane); - m_gpuKernel->setPrimitive(m_nbPrimitives, 0.f, groundHeight + groundSize.y, groundSize.x, groundSize.x, - groundSize.y, 0.f, RANDOM_MATERIALS_OFFSET + 5); + m_gpuKernel->setPrimitive(m_nbPrimitives, 0.f, + groundHeight + groundSize.y, groundSize.x, + groundSize.x, groundSize.y, 0.f, + RANDOM_MATERIALS_OFFSET + 5); m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); m_nbPrimitives = m_gpuKernel->addPrimitive(ptYZPlane); - m_gpuKernel->setPrimitive(m_nbPrimitives, -groundSize.x, groundHeight + groundSize.y, 0.f, 0.f, groundSize.x, - groundSize.y, RANDOM_MATERIALS_OFFSET + 6); + m_gpuKernel->setPrimitive(m_nbPrimitives, -groundSize.x, + groundHeight + groundSize.y, 0.f, 0.f, + groundSize.x, groundSize.y, + RANDOM_MATERIALS_OFFSET + 6); m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); m_nbPrimitives = m_gpuKernel->addPrimitive(ptYZPlane); - m_gpuKernel->setPrimitive(m_nbPrimitives, groundSize.x, groundHeight + groundSize.y, 0.f, 0.f, groundSize.x, - groundSize.y, RANDOM_MATERIALS_OFFSET + 7); + m_gpuKernel->setPrimitive(m_nbPrimitives, groundSize.x, + groundHeight + groundSize.y, 0.f, 0.f, + groundSize.x, groundSize.y, + RANDOM_MATERIALS_OFFSET + 7); m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); break; @@ -1156,11 +1207,13 @@ void Scene::addCornellBox(int boxType) case 7: { m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, 0.f, 0.f, 0.f, skyBoxSize.x, 0.f, 0.f, SKYBOX_SPHERE_MATERIAL); + m_gpuKernel->setPrimitive(m_nbPrimitives, 0.f, 0.f, 0.f, skyBoxSize.x, + 0.f, 0.f, SKYBOX_SPHERE_MATERIAL); const vec2f vt0 = make_vec2f(0.f, 0.f); const vec2f vt1 = make_vec2f(1.f, 1.f); const vec2f vt2 = make_vec2f(0.f, 0.f); - m_gpuKernel->setPrimitiveTextureCoordinates(m_nbPrimitives, vt0, vt1, vt2); + m_gpuKernel->setPrimitiveTextureCoordinates(m_nbPrimitives, vt0, vt1, + vt2); m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); break; } @@ -1172,9 +1225,11 @@ void Scene::addCornellBox(int boxType) float radius = 700.f + float(rand() % 1000); int material = BASIC_REFLECTION_MATERIAL_002; m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, rand() % int(skyBoxSize.x) - skyBoxSize.x / 2, - m_groundHeight + radius, rand() % int(skyBoxSize.z) - skyBoxSize.z / 2, radius, - 0.f, 0.f, material); + m_gpuKernel->setPrimitive( + m_nbPrimitives, rand() % int(skyBoxSize.x) - skyBoxSize.x / 2, + m_groundHeight + radius, + rand() % int(skyBoxSize.z) - skyBoxSize.z / 2, radius, 0.f, 0.f, + material); m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); } break; @@ -1190,7 +1245,8 @@ void Scene::addCornellBox(int boxType) glBegin(GL_TRIANGLES); glVertex3f(skyBoxSize.x, ratio * groundHeight, skyBoxSize.z); glVertex3f(-skyBoxSize.x, ratio * groundHeight, skyBoxSize.z); - glVertex3f(-skyBoxSize.x, skyBoxSize.y * ratio * 2.f + groundHeight, skyBoxSize.z); + glVertex3f(-skyBoxSize.x, skyBoxSize.y * ratio * 2.f + groundHeight, + skyBoxSize.z); glNormal3f(0.f, 0.f, -1.f); glNormal3f(0.f, 0.f, -1.f); glNormal3f(0.f, 0.f, -1.f); @@ -1207,8 +1263,10 @@ void Scene::addCornellBox(int boxType) m_gpuKernel->setPrimitiveMaterial(m_nbPrimitives, material); m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); glBegin(GL_TRIANGLES); - glVertex3f(-skyBoxSize.x, 2.f * ratio * skyBoxSize.y + groundHeight, skyBoxSize.z); - glVertex3f(skyBoxSize.x, 2.f * ratio * skyBoxSize.y + groundHeight, skyBoxSize.z); + glVertex3f(-skyBoxSize.x, 2.f * ratio * skyBoxSize.y + groundHeight, + skyBoxSize.z); + glVertex3f(skyBoxSize.x, 2.f * ratio * skyBoxSize.y + groundHeight, + skyBoxSize.z); glVertex3f(skyBoxSize.x, groundHeight, skyBoxSize.z); glNormal3f(0.f, 0.f, -1.f); glNormal3f(0.f, 0.f, -1.f); @@ -1230,7 +1288,8 @@ void Scene::addCornellBox(int boxType) case 10: { m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, 0.f, groundHeight - 1000000, 0.f, 1000000.f, 0.f, 0.f, + m_gpuKernel->setPrimitive(m_nbPrimitives, 0.f, groundHeight - 1000000, + 0.f, 1000000.f, 0.f, 0.f, SKYBOX_GROUND_MATERIAL); } } @@ -1241,28 +1300,34 @@ void Scene::addCornellBox(int boxType) // Ground { m_nbPrimitives = m_gpuKernel->addPrimitive(ptTriangle); - m_gpuKernel->setPrimitive(m_nbPrimitives, -groundSize.x, groundHeight, -groundSize.y, groundSize.x, - groundHeight, -groundSize.y, groundSize.x, groundHeight, groundSize.y, 0.f, 0.f, - 0.f, material); + m_gpuKernel->setPrimitive(m_nbPrimitives, -groundSize.x, + groundHeight, -groundSize.y, groundSize.x, + groundHeight, -groundSize.y, groundSize.x, + groundHeight, groundSize.y, 0.f, 0.f, 0.f, + material); const vec3f n = make_vec3f(0.f, 1.f, 0.f); m_gpuKernel->setPrimitiveNormals(m_nbPrimitives, n, n, n); const vec2f vt0 = make_vec2f(); const vec2f vt1 = make_vec2f(repeats, 0.f); const vec2f vt2 = make_vec2f(repeats, repeats); - m_gpuKernel->setPrimitiveTextureCoordinates(m_nbPrimitives, vt0, vt1, vt2); + m_gpuKernel->setPrimitiveTextureCoordinates(m_nbPrimitives, vt0, + vt1, vt2); m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); } { m_nbPrimitives = m_gpuKernel->addPrimitive(ptTriangle); - m_gpuKernel->setPrimitive(m_nbPrimitives, groundSize.x, groundHeight, groundSize.y, -groundSize.x, - groundHeight, groundSize.y, -groundSize.x, groundHeight, -groundSize.y, 0.f, 0.f, + m_gpuKernel->setPrimitive(m_nbPrimitives, groundSize.x, + groundHeight, groundSize.y, -groundSize.x, + groundHeight, groundSize.y, -groundSize.x, + groundHeight, -groundSize.y, 0.f, 0.f, 0.f, material); const vec3f n = make_vec3f(0.f, 1.f, 0.f); m_gpuKernel->setPrimitiveNormals(m_nbPrimitives, n, n, n); const vec2f vt0 = make_vec2f(repeats, repeats); const vec2f vt1 = make_vec2f(0.f, repeats); const vec2f vt2 = make_vec2f(0.f, 0.f); - m_gpuKernel->setPrimitiveTextureCoordinates(m_nbPrimitives, vt0, vt1, vt2); + m_gpuKernel->setPrimitiveTextureCoordinates(m_nbPrimitives, vt0, + vt1, vt2); m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); } } @@ -1279,51 +1344,63 @@ void Scene::createWorm(const vec3f ¢er, int boxId, int material) { // Worm on the right hand side int m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x, center.y, center.z, 800.f, 0.f, 0.f, material); + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x, center.y, center.z, + 800.f, 0.f, 0.f, material); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); // Eyes - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x - 400.f, center.y + 500.f, center.z - 400.f, 150.f, 0.f, 0.f, - 12); + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x - 400.f, + center.y + 500.f, center.z - 400.f, 150.f, 0.f, + 0.f, 12); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x + 400.f, center.y + 500.f, center.z - 400.f, 150.f, 0.f, 0.f, - 12); + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x + 400.f, + center.y + 500.f, center.z - 400.f, 150.f, 0.f, + 0.f, 12); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x - 400.f, center.y + 500.f, center.z - 400.f, 200.f, 0.f, 0.f, - 13); + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x - 400.f, + center.y + 500.f, center.z - 400.f, 200.f, 0.f, + 0.f, 13); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x + 400.f, center.y + 500.f, center.z - 400.f, 200.f, 0.f, 0.f, - 13); + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x + 400.f, + center.y + 500.f, center.z - 400.f, 200.f, 0.f, + 0.f, 13); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x, center.y - 700.f, center.z, 600.f, 0.f, 0.f, material); + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x, center.y - 700.f, + center.z, 600.f, 0.f, 0.f, material); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x, center.y - 1200.f, center.z + 200.f, 600.f, 0.f, 0.f, material); + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x, center.y - 1200.f, + center.z + 200.f, 600.f, 0.f, 0.f, material); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x, center.y - 1500.f, center.z + 500.f, 600.f, 0.f, 0.f, material); + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x, center.y - 1500.f, + center.z + 500.f, 600.f, 0.f, 0.f, material); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x, center.y - 1500.f, center.z + 1000.f, 600.f, 0.f, 0.f, - material); + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x, center.y - 1500.f, + center.z + 1000.f, 600.f, 0.f, 0.f, material); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x, center.y - 1500.f, center.z + 1500.f, 600.f, 0.f, 0.f, - material); + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x, center.y - 1500.f, + center.z + 1500.f, 600.f, 0.f, 0.f, material); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x, center.y - 1300.f, center.z + 2000.f, 400.f, 0.f, 0.f, - material); + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x, center.y - 1300.f, + center.z + 2000.f, 400.f, 0.f, 0.f, material); // Arms m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x, center.y - 700.f, center.z, center.x - 500.f, center.y - 1200.f, + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x, center.y - 700.f, + center.z, center.x - 500.f, center.y - 1200.f, center.z - 1000.f, 100.f, 0.f, 0.f, material); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x - 500.f, center.y - 1200.f, center.z - 1000.f, 300.f, 0.f, 0.f, - material); + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x - 500.f, + center.y - 1200.f, center.z - 1000.f, 300.f, 0.f, + 0.f, material); m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x, center.y - 700.f, center.z, center.x + 500.f, center.y - 1200.f, + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x, center.y - 700.f, + center.z, center.x + 500.f, center.y - 1200.f, center.z - 1000.f, 100.f, 0.f, 0.f, material); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x + 500.f, center.y - 1200.f, center.z - 1000.f, 300.f, 0.f, 0.f, - material); + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x + 500.f, + center.y - 1200.f, center.z - 1000.f, 300.f, 0.f, + 0.f, material); } /* @@ -1336,65 +1413,76 @@ void Scene::createDog(const vec3f ¢er, int material, float size, int boxid) { // Body m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x - 1000, center.y, center.z, center.x + 1000, center.y, center.z, + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x - 1000, center.y, + center.z, center.x + 1000, center.y, center.z, size, 0, 0.f, material); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x - 1000, center.y, center.z, size, 0.f, 0.f, material); + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x - 1000, center.y, + center.z, size, 0.f, 0.f, material); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x + 1000, center.y, center.z, size, 0.f, 0.f, material); + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x + 1000, center.y, + center.z, size, 0.f, 0.f, material); // Legs m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x - 1500, center.y - 2000, center.z - 1000, center.x - 1000, - center.y, center.z, size, 0, 0.f, material); + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x - 1500, center.y - 2000, + center.z - 1000, center.x - 1000, center.y, + center.z, size, 0, 0.f, material); m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x - 1500, center.y - 2000, center.z + 1000, center.x - 1000, - center.y, center.z, size, 0, 0.f, material); + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x - 1500, center.y - 2000, + center.z + 1000, center.x - 1000, center.y, + center.z, size, 0, 0.f, material); m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x + 1500, center.y - 2000, center.z - 1000, center.x + 1000, - center.y, center.z, size, 0, 0.f, material); + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x + 1500, center.y - 2000, + center.z - 1000, center.x + 1000, center.y, + center.z, size, 0, 0.f, material); m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x + 1500, center.y - 2000, center.z + 1000, center.x + 1000, - center.y, center.z, size, 0, 0.f, material); + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x + 1500, center.y - 2000, + center.z + 1000, center.x + 1000, center.y, + center.z, size, 0, 0.f, material); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x - 1500, center.y - 2000, center.z - 1000, size, 0, 0.f, - material); + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x - 1500, center.y - 2000, + center.z - 1000, size, 0, 0.f, material); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x - 1500, center.y - 2000, center.z + 1000, size, 0, 0.f, - material); + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x - 1500, center.y - 2000, + center.z + 1000, size, 0, 0.f, material); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x + 1500, center.y - 2000, center.z - 1000, size, 0, 0.f, - material); + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x + 1500, center.y - 2000, + center.z - 1000, size, 0, 0.f, material); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x + 1500, center.y - 2000, center.z + 1000, size, 0, 0.f, - material); + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x + 1500, center.y - 2000, + center.z + 1000, size, 0, 0.f, material); // Tail m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x - 1500, center.y + 1000, center.z, center.x - 1000, center.y, - center.z, size * 0.8f, 0, 0.f, material); + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x - 1500, center.y + 1000, + center.z, center.x - 1000, center.y, center.z, + size * 0.8f, 0, 0.f, material); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x - 1500, center.y + 1000, center.z, size * 0.8f, 0, 0.f, - material); + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x - 1500, center.y + 1000, + center.z, size * 0.8f, 0, 0.f, material); // Head m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x + 1000.f, center.y, center.z, center.x + 1500.f, - center.y + 1000.f, center.z, size, 0.f, 0.f, material); + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x + 1000.f, center.y, + center.z, center.x + 1500.f, center.y + 1000.f, + center.z, size, 0.f, 0.f, material); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x + 1500.f, center.y + 1500.f, center.z, size * 2.f, 0.f, 0.f, + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x + 1500.f, + center.y + 1500.f, center.z, size * 2.f, 0.f, 0.f, material); m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x + 1500.f, center.y + 1500.f, center.z, center.x + 2500.f, - center.y + 1000.f, center.z, size * 2.f, 0.f, 0.f, material); + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x + 1500.f, + center.y + 1500.f, center.z, center.x + 2500.f, + center.y + 1000.f, center.z, size * 2.f, 0.f, 0.f, + material); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, center.x + 2500.f, center.y + 1000.f, center.z, size * 2.f, 0.f, 0.f, + m_gpuKernel->setPrimitive(m_nbPrimitives, center.x + 2500.f, + center.y + 1000.f, center.z, size * 2.f, 0.f, 0.f, material); } -void Scene::renderText() -{ -} +void Scene::renderText() {} SceneInfo &Scene::getSceneInfo() { @@ -1412,11 +1500,14 @@ void Scene::createSkeleton() vec4f skyBoxSize = {1600.f, 1200.f, 0.f}; vec4f skyBoxPosition = {3000.f, m_groundHeight - 450.f, 2500.f}; glBegin(GL_TRIANGLES); - glVertex3f(skyBoxPosition.x + skyBoxSize.x, skyBoxPosition.y - skyBoxSize.y - m_groundHeight, + glVertex3f(skyBoxPosition.x + skyBoxSize.x, + skyBoxPosition.y - skyBoxSize.y - m_groundHeight, skyBoxPosition.z + skyBoxSize.z); - glVertex3f(skyBoxPosition.x - skyBoxSize.x, skyBoxPosition.y - skyBoxSize.y - m_groundHeight, + glVertex3f(skyBoxPosition.x - skyBoxSize.x, + skyBoxPosition.y - skyBoxSize.y - m_groundHeight, skyBoxPosition.z + skyBoxSize.z); - glVertex3f(skyBoxPosition.x - skyBoxSize.x, skyBoxPosition.y + skyBoxSize.y - m_groundHeight, + glVertex3f(skyBoxPosition.x - skyBoxSize.x, + skyBoxPosition.y + skyBoxSize.y - m_groundHeight, skyBoxPosition.z + skyBoxSize.z); glNormal3f(0.f, 0.f, -1.f); glNormal3f(0.f, 0.f, -1.f); @@ -1429,11 +1520,14 @@ void Scene::createSkeleton() m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); glBegin(GL_TRIANGLES); - glVertex3f(skyBoxPosition.x - skyBoxSize.x, skyBoxPosition.y + skyBoxSize.y - m_groundHeight, + glVertex3f(skyBoxPosition.x - skyBoxSize.x, + skyBoxPosition.y + skyBoxSize.y - m_groundHeight, skyBoxPosition.z + skyBoxSize.z); - glVertex3f(skyBoxPosition.x + skyBoxSize.x, skyBoxPosition.y + skyBoxSize.y - m_groundHeight, + glVertex3f(skyBoxPosition.x + skyBoxSize.x, + skyBoxPosition.y + skyBoxSize.y - m_groundHeight, skyBoxPosition.z + skyBoxSize.z); - glVertex3f(skyBoxPosition.x + skyBoxSize.x, skyBoxPosition.y - skyBoxSize.y - m_groundHeight, + glVertex3f(skyBoxPosition.x + skyBoxSize.x, + skyBoxPosition.y - skyBoxSize.y - m_groundHeight, skyBoxPosition.z + skyBoxSize.z); glNormal3f(0.f, 0.f, -1.f); glNormal3f(0.f, 0.f, -1.f); @@ -1448,7 +1542,8 @@ void Scene::createSkeleton() for (int i(0); i < 20; ++i) { int primitive = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(primitive, 0.f, 0.f, 0.f, m_skeletonSize, 0.f, 0.f, 0); + m_gpuKernel->setPrimitive(primitive, 0.f, 0.f, 0.f, m_skeletonSize, 0.f, + 0.f, 0); if (i == 0) m_skeletonPrimitiveIndex = primitive; } @@ -1464,26 +1559,34 @@ void Scene::animateSkeleton() { #ifdef USE_KINECT m_skeletonPosition.y = m_groundHeight; - int hr = m_gpuKernel->updateSkeletons(m_skeletonPrimitiveIndex, - m_skeletonPosition, // Position - m_skeletonSize, // Skeleton size - m_skeletonThickness, 40, // Default material - m_skeletonThickness * 2.0f, 41, // Head size and material - m_skeletonThickness * 1.5f, 42, // Hands size and material - m_skeletonThickness * 1.8f, 43 // Feet size and material - ); + int hr = m_gpuKernel->updateSkeletons( + m_skeletonPrimitiveIndex, + m_skeletonPosition, // Position + m_skeletonSize, // Skeleton size + m_skeletonThickness, 40, // Default material + m_skeletonThickness * 2.0f, 41, // Head size and material + m_skeletonThickness * 1.5f, 42, // Hands size and material + m_skeletonThickness * 1.8f, 43 // Feet size and material + ); m_gpuKernel->getSceneInfo().pathTracingIteration = 0; if (hr == S_OK) { vec3f position; // Head - if (m_gpuKernel->getSkeletonPosition(NUI_SKELETON_POSITION_HEAD, position)) + if (m_gpuKernel->getSkeletonPosition(NUI_SKELETON_POSITION_HEAD, + position)) { vec4f amplitude; - amplitude.x = (position.x * m_skeletonKinectSize - m_gpuKernel->getViewPos().x) / 2.f; - amplitude.y = (position.y * m_skeletonKinectSize - m_gpuKernel->getViewPos().y) / 2.f; - amplitude.z = ((100.f + 200.f - position.z * m_skeletonKinectSize) - m_gpuKernel->getViewPos().z) / 2.f; + amplitude.x = (position.x * m_skeletonKinectSize - + m_gpuKernel->getViewPos().x) / + 2.f; + amplitude.y = (position.y * m_skeletonKinectSize - + m_gpuKernel->getViewPos().y) / + 2.f; + amplitude.z = ((100.f + 200.f - position.z * m_skeletonKinectSize) - + m_gpuKernel->getViewPos().z) / + 2.f; m_gpuKernel->getViewPos().x += amplitude.x; m_gpuKernel->getViewPos().y += amplitude.y; @@ -1528,19 +1631,26 @@ void Scene::animateSkeleton() // See if it's enabled if (sixenseIsControllerEnabled(cont)) { - LOG_INFO(3, "Controller " << cont << ", left=" << left_index << ", right=" << right_index); + LOG_INFO(3, "Controller " << cont << ", left=" << left_index + << ", right=" << right_index); if (cont == left_index) { // if this is the left controller vec4f angles; - angles.x = PI * (m_modelRotationAngle.x - acd.controllers[cont].rot_quat[0]); - angles.y = PI * (m_modelRotationAngle.y - acd.controllers[cont].rot_quat[1]); - angles.z = PI * (m_modelRotationAngle.z + acd.controllers[cont].rot_quat[2]); + angles.x = PI * (m_modelRotationAngle.x - + acd.controllers[cont].rot_quat[0]); + angles.y = PI * (m_modelRotationAngle.y - + acd.controllers[cont].rot_quat[1]); + angles.z = PI * (m_modelRotationAngle.z + + acd.controllers[cont].rot_quat[2]); vec3f translation; - translation.x = 10.f * (acd.controllers[cont].pos[0] - m_modelTranslation.x); - translation.y = 10.f * (acd.controllers[cont].pos[1] - m_modelTranslation.y); - translation.z = 10.f * (m_modelTranslation.z - acd.controllers[cont].pos[2]); + translation.x = 10.f * (acd.controllers[cont].pos[0] - + m_modelTranslation.x); + translation.y = 10.f * (acd.controllers[cont].pos[1] - + m_modelTranslation.y); + translation.z = 10.f * (m_modelTranslation.z - + acd.controllers[cont].pos[2]); m_gpuKernel->getSceneInfo().pathTracingIteration = 0; m_gpuKernel->rotatePrimitives(m_modelPosition, angles); @@ -1565,24 +1675,34 @@ void Scene::animateSkeleton() createRandomMaterials(true, false); if (left_states.buttonJustPressed(SIXENSE_BUTTON_3)) m_gpuKernel->getSceneInfo().graphicsLevel = - static_cast((m_gpuKernel->getSceneInfo().graphicsLevel + 1) % 5); + static_cast( + (m_gpuKernel->getSceneInfo().graphicsLevel + + 1) % + 5); if (left_states.buttonJustPressed(SIXENSE_BUTTON_4)) { m_gpuKernel->getPostProcessingInfo().type++; - m_gpuKernel->getPostProcessingInfo().type = m_gpuKernel->getPostProcessingInfo().type % 4; + m_gpuKernel->getPostProcessingInfo().type = + m_gpuKernel->getPostProcessingInfo().type % 4; } // Joystick / Camera - m_gpuKernel->getViewPos().x += 100.f * acd.controllers[cont].joystick_x; - m_gpuKernel->getViewDir().x += 100.f * acd.controllers[cont].joystick_x; - m_gpuKernel->getViewPos().z += 100.f * acd.controllers[cont].joystick_y; - m_gpuKernel->getViewDir().z += 100.f * acd.controllers[cont].joystick_y; + m_gpuKernel->getViewPos().x += + 100.f * acd.controllers[cont].joystick_x; + m_gpuKernel->getViewDir().x += + 100.f * acd.controllers[cont].joystick_x; + m_gpuKernel->getViewPos().z += + 100.f * acd.controllers[cont].joystick_y; + m_gpuKernel->getViewDir().z += + 100.f * acd.controllers[cont].joystick_y; } if (cont == right_index) { - m_gpuKernel->getSceneInfo().eyeSeparation += 50.f * acd.controllers[cont].joystick_x; - m_gpuKernel->getViewDir().z += 50.f * acd.controllers[cont].joystick_y; + m_gpuKernel->getSceneInfo().eyeSeparation += + 50.f * acd.controllers[cont].joystick_x; + m_gpuKernel->getViewDir().z += + 50.f * acd.controllers[cont].joystick_y; } } } diff --git a/apps/scenes/Scene.h b/apps/scenes/Scene.h index 27d8006..93e83d2 100644 --- a/apps/scenes/Scene.h +++ b/apps/scenes/Scene.h @@ -1,31 +1,31 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once #include +#include // Raytracer #include #include +using namespace solr; + class Scene { public: @@ -33,7 +33,7 @@ class Scene virtual ~Scene(void); public: - void initialize(solr::GPUKernel* kernel, const int width, const int height); + void initialize(GPUKernel* kernel, const int width, const int height); void animate(); void render(const bool& animate); @@ -58,7 +58,10 @@ class Scene std::string& getName(); int getCornellBox() { return m_cornellBoxType; } - void setCornellBoxType(int cornellBoxType) { m_cornellBoxType = cornellBoxType; } + void setCornellBoxType(int cornellBoxType) + { + m_cornellBoxType = cornellBoxType; + } float getGroundHeight() { return m_groundHeight; } void setGroundHeight(const float h) { m_groundHeight = h; } @@ -67,11 +70,14 @@ class Scene public: int getNbPrimitives() { return m_gpuKernel->getNbActivePrimitives(); } - solr::GPUKernel* getKernel() { return m_gpuKernel; } + GPUKernel* getKernel() { return m_gpuKernel; } int getNbHDRI() { return m_nbHDRI; } public: - void setCurrentModel(const int& currentModel) { m_currentModel = currentModel; } + void setCurrentModel(const int& currentModel) + { + m_currentModel = currentModel; + } protected: virtual void doInitialize() = 0; @@ -85,7 +91,7 @@ class Scene protected: std::string m_name; - solr::GPUKernel* m_gpuKernel; + GPUKernel* m_gpuKernel; // Textures int m_nbHDRI; diff --git a/apps/scenes/animation/AnimationScene.cpp b/apps/scenes/animation/AnimationScene.cpp index 77cd456..57735aa 100644 --- a/apps/scenes/animation/AnimationScene.cpp +++ b/apps/scenes/animation/AnimationScene.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include "AnimationScene.h" @@ -48,9 +45,7 @@ AnimationScene::AnimationScene(const std::string& name) m_forward = true; } -AnimationScene::~AnimationScene(void) -{ -} +AnimationScene::~AnimationScene(void) {} void AnimationScene::doInitialize() { @@ -82,13 +77,14 @@ void AnimationScene::doInitialize() m_gpuKernel->resetFrame(); solr::CPUBoundingBox aabb; solr::CPUBoundingBox inAABB; - objReader.loadModelFromFile(fileName, *m_gpuKernel, center, false, objectSize, (frame == 0), m, - false, true, aabb, false, inAABB); + objReader.loadModelFromFile(fileName, *m_gpuKernel, center, false, + objectSize, (frame == 0), m, false, true, + aabb, false, inAABB); // lights - m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, -10000.f, 10000.f, -10000.f, 100.f, 100.f, 100.f, - DEFAULT_LIGHT_MATERIAL); + m_nbPrimitives = m_gpuKernel->addPrimitive(solr::ptSphere); + m_gpuKernel->setPrimitive(m_nbPrimitives, -10000.f, 10000.f, -10000.f, + 100.f, 100.f, 100.f, DEFAULT_LIGHT_MATERIAL); m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); addCornellBox(m_cornellBoxType); @@ -108,6 +104,4 @@ void AnimationScene::doAnimate() m_currentFrame = m_currentFrame % nbFrames; } -void AnimationScene::doAddLights() -{ -} +void AnimationScene::doAddLights() {} diff --git a/apps/scenes/animation/AnimationScene.h b/apps/scenes/animation/AnimationScene.h index 72b1597..55c5dcb 100644 --- a/apps/scenes/animation/AnimationScene.h +++ b/apps/scenes/animation/AnimationScene.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once diff --git a/apps/scenes/animation/KinectFaceTrackingScene.cpp b/apps/scenes/animation/KinectFaceTrackingScene.cpp index 63c8196..9612463 100644 --- a/apps/scenes/animation/KinectFaceTrackingScene.cpp +++ b/apps/scenes/animation/KinectFaceTrackingScene.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include "KinectFaceTrackingScene.h" @@ -30,17 +27,13 @@ #pragma comment(lib, "FaceTrackLib.lib") -using namespace solr; - KinectFaceTrackingScene::KinectFaceTrackingScene(const std::string& name) : Scene(name) , m_faceTracker(nullptr) { } -KinectFaceTrackingScene::~KinectFaceTrackingScene(void) -{ -} +KinectFaceTrackingScene::~KinectFaceTrackingScene(void) {} void KinectFaceTrackingScene::doInitialize() { @@ -53,17 +46,22 @@ void KinectFaceTrackingScene::doAnimate() if (m_faceTracker) { // Video camera config with width, height, focal length in pixels - // NUI_CAMERA_COLOR_NOMINAL_FOCAL_LENGTH_IN_PIXELS focal length is computed for 640x480 resolution - // If you use different resolutions, multiply this focal length by the scaling factor - FT_CAMERA_CONFIG videoCameraConfig = {640, 480, NUI_CAMERA_COLOR_NOMINAL_FOCAL_LENGTH_IN_PIXELS}; + // NUI_CAMERA_COLOR_NOMINAL_FOCAL_LENGTH_IN_PIXELS focal length is + // computed for 640x480 resolution If you use different resolutions, + // multiply this focal length by the scaling factor + FT_CAMERA_CONFIG videoCameraConfig = { + 640, 480, NUI_CAMERA_COLOR_NOMINAL_FOCAL_LENGTH_IN_PIXELS}; // Depth camera config with width, height, focal length in pixels - // NUI_CAMERA_COLOR_NOMINAL_FOCAL_LENGTH_IN_PIXELS focal length is computed for 320x240 resolution - // If you use different resolutions, multiply this focal length by the scaling factor - FT_CAMERA_CONFIG depthCameraConfig = {320, 240, NUI_CAMERA_DEPTH_NOMINAL_FOCAL_LENGTH_IN_PIXELS}; + // NUI_CAMERA_COLOR_NOMINAL_FOCAL_LENGTH_IN_PIXELS focal length is + // computed for 320x240 resolution If you use different resolutions, + // multiply this focal length by the scaling factor + FT_CAMERA_CONFIG depthCameraConfig = { + 320, 240, NUI_CAMERA_DEPTH_NOMINAL_FOCAL_LENGTH_IN_PIXELS}; // Initialize the face tracker - HRESULT hr = m_faceTracker->Initialize(&videoCameraConfig, &depthCameraConfig, NULL, NULL); + HRESULT hr = m_faceTracker->Initialize(&videoCameraConfig, + &depthCameraConfig, NULL, NULL); if (FAILED(hr)) { // Handle errors @@ -97,14 +95,16 @@ void KinectFaceTrackingScene::doAnimate() FLOAT translation[3] = {0.f, 0.f, 0.f}; UINT vertexCount(0); FT_VECTOR3D* vertices(nullptr); - hr = model->Get3DShape(shapeUnits, suCount, animationUnits, auCount, scale, rotation, translation, - vertices, vertexCount); + hr = model->Get3DShape(shapeUnits, suCount, animationUnits, + auCount, scale, rotation, + translation, vertices, vertexCount); LOG_INFO(1, "Get3DShape: " << vertexCount << " vertices"); FT_TRIANGLE* triangles; UINT triangleCount; hr = model->GetTriangles(&triangles, &triangleCount); - LOG_INFO(1, "GetTriangles: " << triangleCount << " triangles"); + LOG_INFO(1, + "GetTriangles: " << triangleCount << " triangles"); if (FAILED(hr)) { // Handle errors @@ -114,11 +114,14 @@ void KinectFaceTrackingScene::doAnimate() for (UINT i(0); i < triangleCount; ++i) { glBegin(GL_TRIANGLES); - glVertex3f(vertices[triangles[i].i].x, vertices[triangles[i].i].y, + glVertex3f(vertices[triangles[i].i].x, + vertices[triangles[i].i].y, vertices[triangles[i].i].z); - glVertex3f(vertices[triangles[i].j].x, vertices[triangles[i].j].y, + glVertex3f(vertices[triangles[i].j].x, + vertices[triangles[i].j].y, vertices[triangles[i].j].z); - glVertex3f(vertices[triangles[i].k].x, vertices[triangles[i].k].y, + glVertex3f(vertices[triangles[i].k].x, + vertices[triangles[i].k].y, vertices[triangles[i].k].z); glNormal3f(0.f, 0.f, -1.f); glNormal3f(0.f, 0.f, -1.f); @@ -147,7 +150,8 @@ void KinectFaceTrackingScene::doAddLights() { LOG_INFO(3, "Adding sun light"); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, -5000.f, 5000.f, -5000.f, 10.f, 0.f, 0.f, DEFAULT_LIGHT_MATERIAL); + m_gpuKernel->setPrimitive(m_nbPrimitives, -5000.f, 5000.f, -5000.f, + 10.f, 0.f, 0.f, DEFAULT_LIGHT_MATERIAL); m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); } } diff --git a/apps/scenes/animation/KinectFaceTrackingScene.h b/apps/scenes/animation/KinectFaceTrackingScene.h index 7a4e6fc..74063fb 100644 --- a/apps/scenes/animation/KinectFaceTrackingScene.h +++ b/apps/scenes/animation/KinectFaceTrackingScene.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once diff --git a/apps/scenes/animation/MetaballsScene.cpp b/apps/scenes/animation/MetaballsScene.cpp index f8bb112..9381823 100644 --- a/apps/scenes/animation/MetaballsScene.cpp +++ b/apps/scenes/animation/MetaballsScene.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include "MetaballsScene.h" @@ -26,10 +23,8 @@ #include #endif // USE_LEAPMOTION -#include #include - -using namespace solr; +#include const int minGridSize = 40; float threshold = 1.0f; @@ -39,15 +34,19 @@ unsigned int gridSize = 60; unsigned int numMetaballs = 20; vec4f size = {numMetaballs * 10.f, numMetaballs * 10.f, numMetaballs * 10.f}; vec4f amplitude = {size.x / 5.f, size.y / 5.f, size.z / 5.f}; -vec4f scale = {2500.f / numMetaballs, 2500.f / numMetaballs, 2500.f / numMetaballs}; +vec4f scale = {2500.f / numMetaballs, 2500.f / numMetaballs, + 2500.f / numMetaballs}; #else unsigned int gridSize = 50; unsigned int numMetaballs = 50; const int gridScale = 3.f; -vec3f size = make_vec3f(static_cast(numMetaballs * gridScale), static_cast(numMetaballs* gridScale), - static_cast(numMetaballs* gridScale)); -const vec3f amplitude = make_vec3f(size.x / gridScale, size.y / gridScale, size.z / gridScale); -const vec3f scale = make_vec3f(2000.f / numMetaballs, 2000.f / numMetaballs, 2000.f / numMetaballs); +vec3f size = make_vec3f(static_cast(numMetaballs * gridScale), + static_cast(numMetaballs* gridScale), + static_cast(numMetaballs* gridScale)); +const vec3f amplitude = + make_vec3f(size.x / gridScale, size.y / gridScale, size.z / gridScale); +const vec3f scale = make_vec3f(2000.f / numMetaballs, 2000.f / numMetaballs, + 2000.f / numMetaballs); #endif // USE_KINECT METABALL metaballs[50]; @@ -62,7 +61,8 @@ MetaballsScene::MetaballsScene(const std::string& name) #endif // USE_LEAPMOTION { // initialise the metaBall_ size and positions - vertices = new CUBE_GRID_VERTEX[(maxGridSize + 1) * (maxGridSize + 1) * (maxGridSize + 1)]; + vertices = new CUBE_GRID_VERTEX[(maxGridSize + 1) * (maxGridSize + 1) * + (maxGridSize + 1)]; cubes = new CUBE_GRID_CUBE[maxGridSize * maxGridSize * maxGridSize]; } @@ -95,13 +95,20 @@ void MetaballsScene::Init() { for (unsigned int k = 0; k < gridSize + 1; k++) { - const size_t currentVertex = i * (gridSize + 1) * (gridSize + 1) + j * (gridSize + 1) + k; - vertices[currentVertex].position.x = (i * size.x) / (gridSize)-size.x / 2.f; - vertices[currentVertex].position.y = (j * size.y) / (gridSize)-size.y / 2.f; - vertices[currentVertex].position.z = (k * size.z) / (gridSize)-size.z / 2.f; - - vertices[currentVertex].textCoords.x = static_cast(i) / static_cast(gridSize); - vertices[currentVertex].textCoords.y = static_cast(j) / static_cast(gridSize); + const size_t currentVertex = + i * (gridSize + 1) * (gridSize + 1) + j * (gridSize + 1) + + k; + vertices[currentVertex].position.x = + (i * size.x) / (gridSize)-size.x / 2.f; + vertices[currentVertex].position.y = + (j * size.y) / (gridSize)-size.y / 2.f; + vertices[currentVertex].position.z = + (k * size.z) / (gridSize)-size.z / 2.f; + + vertices[currentVertex].textCoords.x = + static_cast(i) / static_cast(gridSize); + vertices[currentVertex].textCoords.y = + static_cast(j) / static_cast(gridSize); ; vertices[currentVertex].textCoords.z = 0.f; } @@ -118,16 +125,33 @@ void MetaballsScene::Init() { for (unsigned int k = 0; k < gridSize; k++) { - const size_t currentCube = i * gridSize * gridSize + j * gridSize + k; - cubes[currentCube].vertices[0] = &vertices[(i * (gridSize + 1) + j) * (gridSize + 1) + k]; - cubes[currentCube].vertices[1] = &vertices[(i * (gridSize + 1) + j) * (gridSize + 1) + k + 1]; - cubes[currentCube].vertices[2] = &vertices[(i * (gridSize + 1) + (j + 1)) * (gridSize + 1) + k + 1]; - cubes[currentCube].vertices[3] = &vertices[(i * (gridSize + 1) + (j + 1)) * (gridSize + 1) + k]; - cubes[currentCube].vertices[4] = &vertices[((i + 1) * (gridSize + 1) + j) * (gridSize + 1) + k]; - cubes[currentCube].vertices[5] = &vertices[((i + 1) * (gridSize + 1) + j) * (gridSize + 1) + k + 1]; + const size_t currentCube = + i * gridSize * gridSize + j * gridSize + k; + cubes[currentCube].vertices[0] = + &vertices[(i * (gridSize + 1) + j) * (gridSize + 1) + k]; + cubes[currentCube].vertices[1] = + &vertices[(i * (gridSize + 1) + j) * (gridSize + 1) + k + + 1]; + cubes[currentCube].vertices[2] = + &vertices[(i * (gridSize + 1) + (j + 1)) * (gridSize + 1) + + k + 1]; + cubes[currentCube].vertices[3] = + &vertices[(i * (gridSize + 1) + (j + 1)) * (gridSize + 1) + + k]; + cubes[currentCube].vertices[4] = + &vertices[((i + 1) * (gridSize + 1) + j) * (gridSize + 1) + + k]; + cubes[currentCube].vertices[5] = + &vertices[((i + 1) * (gridSize + 1) + j) * (gridSize + 1) + + k + 1]; cubes[currentCube].vertices[6] = - &vertices[((i + 1) * (gridSize + 1) + (j + 1)) * (gridSize + 1) + k + 1]; - cubes[currentCube].vertices[7] = &vertices[((i + 1) * (gridSize + 1) + (j + 1)) * (gridSize + 1) + k]; + &vertices[((i + 1) * (gridSize + 1) + (j + 1)) * + (gridSize + 1) + + k + 1]; + cubes[currentCube].vertices[7] = + &vertices[((i + 1) * (gridSize + 1) + (j + 1)) * + (gridSize + 1) + + k]; } } } @@ -181,12 +205,14 @@ void MetaballsScene::doAnimate() const auto finger = fingers[j]; for (int k = 0; k < 4; ++k) { - const auto bone = finger.bone(static_cast(k)); + const auto bone = + finger.bone(static_cast(k)); const auto v = bone.center(); metaballs[i].position.x = v.x / 2; metaballs[i].position.y = v.y / 2 - 40; metaballs[i].position.z = -v.z / 2 + 40; - metaballs[i].squaredRadius = finger.width() * finger.width() / 4; + metaballs[i].squaredRadius = + finger.width() * finger.width() / 4; ++i; } } @@ -216,28 +242,68 @@ void MetaballsScene::doAnimate() switch (i % 4) { case 0: - metaballs[i].position.x = center.x - ratio * amplitude.x * (float)cos(timer / (740 + i * numMetaballs)) - c; - metaballs[i].position.y = center.z + ratio * amplitude.y * (float)sin(timer / (620 + i * numMetaballs)) - c; - metaballs[i].position.z = center.y + fabs(ratio * amplitude.z * (float)sin(cos(timer / (500 + i))) - c); + metaballs[i].position.x = + center.x - + ratio * amplitude.x * + (float)cos(timer / (740 + i * numMetaballs)) - + c; + metaballs[i].position.y = + center.z + + ratio * amplitude.y * + (float)sin(timer / (620 + i * numMetaballs)) - + c; + metaballs[i].position.z = + center.y + fabs(ratio * amplitude.z * + (float)sin(cos(timer / (500 + i))) - + c); break; case 1: - metaballs[i].position.x = center.x + ratio * amplitude.x * (float)sin(timer / (420 + i * numMetaballs)) + c; - metaballs[i].position.y = center.z - ratio * amplitude.y * (float)cos(timer / (340 + i * numMetaballs)) - c; - metaballs[i].position.z = center.y + fabs(ratio * amplitude.z * (float)sin(cos(timer / (400 + i))) - c); + metaballs[i].position.x = + center.x + + ratio * amplitude.x * + (float)sin(timer / (420 + i * numMetaballs)) + + c; + metaballs[i].position.y = + center.z - + ratio * amplitude.y * + (float)cos(timer / (340 + i * numMetaballs)) - + c; + metaballs[i].position.z = + center.y + fabs(ratio * amplitude.z * + (float)sin(cos(timer / (400 + i))) - + c); break; case 2: - metaballs[i].position.x = center.x + ratio * amplitude.x * (float)cos(timer / (820 + numMetaballs)) - - 0.2f * (float)sin(timer / 600); - metaballs[i].position.y = center.z + ratio * amplitude.y * (float)sin(timer / (512 + numMetaballs)) - - 0.2f * (float)sin(timer / 400); - metaballs[i].position.z = center.y + fabs(ratio * amplitude.z * (float)sin(cos(timer / (450 + i))) - c); + metaballs[i].position.x = + center.x + + ratio * amplitude.x * + (float)cos(timer / (820 + numMetaballs)) - + 0.2f * (float)sin(timer / 600); + metaballs[i].position.y = + center.z + + ratio * amplitude.y * + (float)sin(timer / (512 + numMetaballs)) - + 0.2f * (float)sin(timer / 400); + metaballs[i].position.z = + center.y + fabs(ratio * amplitude.z * + (float)sin(cos(timer / (450 + i))) - + c); break; case 3: - metaballs[i].position.x = center.x + ratio * amplitude.x * (float)cos(timer / (1200 + numMetaballs)) - - 0.4f * (float)sin(timer / 1250); - metaballs[i].position.y = center.z + ratio * amplitude.y * (float)sin(timer / (2120 + numMetaballs)) - - 0.4f * (float)sin(timer / 640); - metaballs[i].position.z = center.y + fabs(ratio * amplitude.z * (float)sin(cos(timer / (450 + i))) - c); + metaballs[i].position.x = + center.x + + ratio * amplitude.x * + (float)cos(timer / (1200 + numMetaballs)) - + 0.4f * (float)sin(timer / 1250); + metaballs[i].position.y = + center.z + + ratio * amplitude.y * + (float)sin(timer / (2120 + numMetaballs)) - + 0.4f * (float)sin(timer / 640); + metaballs[i].position.z = + center.y + fabs(ratio * amplitude.z * + (float)sin(cos(timer / (450 + i))) - + c); break; } } @@ -279,8 +345,9 @@ void MetaballsScene::doAnimate() // get squared distance from ball to point // float squaredDistance=ballToPoint.GetSquaredLength(); - float squaredDistance = - ballToPoint.x * ballToPoint.x + ballToPoint.y * ballToPoint.y + ballToPoint.z * ballToPoint.z; + float squaredDistance = ballToPoint.x * ballToPoint.x + + ballToPoint.y * ballToPoint.y + + ballToPoint.z * ballToPoint.z; if (squaredDistance == 0.0f) squaredDistance = 0.0001f; @@ -323,7 +390,8 @@ void MetaballsScene::doAnimate() if (cubes[i].vertices[7]->value < threshold) cubeIndex |= 128; - // look this value up in the edge table to see which edges to interpolate along + // look this value up in the edge table to see which edges to + // interpolate along int usedEdges = edgeTable[cubeIndex]; // if the cube is entirely within/outside surface, no faces @@ -335,18 +403,32 @@ void MetaballsScene::doAnimate() { if (usedEdges & 1 << currentEdge) { - CUBE_GRID_VERTEX* v1 = cubes[i].vertices[verticesAtEndsOfEdges[currentEdge * 2]]; - CUBE_GRID_VERTEX* v2 = cubes[i].vertices[verticesAtEndsOfEdges[currentEdge * 2 + 1]]; - - float delta = (threshold - v1->value) / (v2->value - v1->value); - - edgeVertices[currentEdge].position.x = v1->position.x + delta * (v2->position.x - v1->position.x); - edgeVertices[currentEdge].position.y = v1->position.y + delta * (v2->position.y - v1->position.y); - edgeVertices[currentEdge].position.z = v1->position.z + delta * (v2->position.z - v1->position.z); - - edgeVertices[currentEdge].normal.x = v1->normal.x + delta * (v2->normal.x - v1->normal.x); - edgeVertices[currentEdge].normal.y = v1->normal.y + delta * (v2->normal.y - v1->normal.y); - edgeVertices[currentEdge].normal.z = v1->normal.z + delta * (v2->normal.z - v1->normal.z); + CUBE_GRID_VERTEX* v1 = + cubes[i] + .vertices[verticesAtEndsOfEdges[currentEdge * 2]]; + CUBE_GRID_VERTEX* v2 = + cubes[i].vertices + [verticesAtEndsOfEdges[currentEdge * 2 + 1]]; + + float delta = + (threshold - v1->value) / (v2->value - v1->value); + + edgeVertices[currentEdge].position.x = + v1->position.x + + delta * (v2->position.x - v1->position.x); + edgeVertices[currentEdge].position.y = + v1->position.y + + delta * (v2->position.y - v1->position.y); + edgeVertices[currentEdge].position.z = + v1->position.z + + delta * (v2->position.z - v1->position.z); + + edgeVertices[currentEdge].normal.x = + v1->normal.x + delta * (v2->normal.x - v1->normal.x); + edgeVertices[currentEdge].normal.y = + v1->normal.y + delta * (v2->normal.y - v1->normal.y); + edgeVertices[currentEdge].normal.z = + v1->normal.z + delta * (v2->normal.z - v1->normal.z); } } @@ -368,9 +450,12 @@ void MetaballsScene::doAnimate() v = edgeVertices[triTable[cubeIndex][k]].position; t = edgeVertices[triTable[cubeIndex][k]].texCoords; glNormal3f(n.x, n.y, n.z); - glTexCoord2f((v.x / minGridSize) + 1.5f, (v.z / minGridSize) + 1.5f); + glTexCoord2f((v.x / minGridSize) + 1.5f, + (v.z / minGridSize) + 1.5f); // glTexCoord2f(t.x,t.y); - glVertex3f(center.x + scale.x * v.x, center.y + scale.x * v.y, center.z + scale.z * v.z); + glVertex3f(center.x + scale.x * v.x, + center.y + scale.x * v.y, + center.z + scale.z * v.z); } { @@ -378,9 +463,12 @@ void MetaballsScene::doAnimate() v = edgeVertices[triTable[cubeIndex][k + 1]].position; t = edgeVertices[triTable[cubeIndex][k + 1]].texCoords; glNormal3f(n.x, n.y, n.z); - glTexCoord2f((v.x / minGridSize) + 1.5f, (v.z / minGridSize) + 1.5f); + glTexCoord2f((v.x / minGridSize) + 1.5f, + (v.z / minGridSize) + 1.5f); // glTexCoord2f(t.x,t.y); - glVertex3f(center.x + scale.x * v.x, center.y + scale.x * v.y, center.z + scale.z * v.z); + glVertex3f(center.x + scale.x * v.x, + center.y + scale.x * v.y, + center.z + scale.z * v.z); } { @@ -388,9 +476,12 @@ void MetaballsScene::doAnimate() v = edgeVertices[triTable[cubeIndex][k + 2]].position; t = edgeVertices[triTable[cubeIndex][k + 2]].texCoords; glNormal3f(n.x, n.y, n.z); - glTexCoord2f((v.x / minGridSize) + 1.5f, (v.z / minGridSize) + 1.5f); + glTexCoord2f((v.x / minGridSize) + 1.5f, + (v.z / minGridSize) + 1.5f); // glTexCoord2f(t.x,t.y); - glVertex3f(center.x + scale.x * v.x, center.y + scale.x * v.y, center.z + scale.z * v.z); + glVertex3f(center.x + scale.x * v.x, + center.y + scale.x * v.y, + center.z + scale.z * v.z); } glEnd(); @@ -405,11 +496,13 @@ void MetaballsScene::doAnimate() // Lamp #ifdef USE_KINECT m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, -8000.f, 8000.f, -8000.f, 500.f, 0.f, 0.f, DEFAULT_LIGHT_MATERIAL); + m_gpuKernel->setPrimitive(m_nbPrimitives, -8000.f, 8000.f, -8000.f, 500.f, + 0.f, 0.f, DEFAULT_LIGHT_MATERIAL); m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); #else m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, -10000.f, 10000.f, -10000.f, 500.f, 0.f, 0.f, DEFAULT_LIGHT_MATERIAL); + m_gpuKernel->setPrimitive(m_nbPrimitives, -10000.f, 10000.f, -10000.f, + 500.f, 0.f, 0.f, DEFAULT_LIGHT_MATERIAL); m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); #endif // USE_KINECT @@ -431,11 +524,20 @@ void MetaballsScene::initializeLeapMotion() m_leapMotionController = new Leap::Controller(); if (m_leapMotionController) { - LOG_INFO(1, "--------------------------------------------------------------------------------"); - LOG_INFO(1, " Leap Motion initialized! m(o_o)m"); - LOG_INFO(1, "--------------------------------------------------------------------------------"); - LOG_INFO(1, "Connected: " << (m_leapMotionController->isConnected() ? "Yes" : "No")); - LOG_INFO(1, "--------------------------------------------------------------------------------"); + LOG_INFO(1, + "---------------------------------------------------------" + "-----------------------"); + LOG_INFO(1, + " Leap Motion initialized! m(o_o)m"); + LOG_INFO(1, + "---------------------------------------------------------" + "-----------------------"); + LOG_INFO(1, "Connected: " << (m_leapMotionController->isConnected() + ? "Yes" + : "No")); + LOG_INFO(1, + "---------------------------------------------------------" + "-----------------------"); } } } diff --git a/apps/scenes/animation/MetaballsScene.h b/apps/scenes/animation/MetaballsScene.h index 0d0f4ee..59b9318 100644 --- a/apps/scenes/animation/MetaballsScene.h +++ b/apps/scenes/animation/MetaballsScene.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once @@ -97,284 +94,294 @@ class CUBE_GRID }; // gives the vertices at the end of each edge -const int verticesAtEndsOfEdges[24] = {0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7}; +const int verticesAtEndsOfEdges[24] = {0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, + 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7}; // gives the edges to interpolate along given vertex inside/outside const int edgeTable[256] = { - 0x0, 0x109, 0x203, 0x30a, 0x406, 0x50f, 0x605, 0x70c, 0x80c, 0x905, 0xa0f, 0xb06, 0xc0a, 0xd03, 0xe09, 0xf00, - 0x190, 0x99, 0x393, 0x29a, 0x596, 0x49f, 0x795, 0x69c, 0x99c, 0x895, 0xb9f, 0xa96, 0xd9a, 0xc93, 0xf99, 0xe90, - 0x230, 0x339, 0x33, 0x13a, 0x636, 0x73f, 0x435, 0x53c, 0xa3c, 0xb35, 0x83f, 0x936, 0xe3a, 0xf33, 0xc39, 0xd30, - 0x3a0, 0x2a9, 0x1a3, 0xaa, 0x7a6, 0x6af, 0x5a5, 0x4ac, 0xbac, 0xaa5, 0x9af, 0x8a6, 0xfaa, 0xea3, 0xda9, 0xca0, - 0x460, 0x569, 0x663, 0x76a, 0x66, 0x16f, 0x265, 0x36c, 0xc6c, 0xd65, 0xe6f, 0xf66, 0x86a, 0x963, 0xa69, 0xb60, - 0x5f0, 0x4f9, 0x7f3, 0x6fa, 0x1f6, 0xff, 0x3f5, 0x2fc, 0xdfc, 0xcf5, 0xfff, 0xef6, 0x9fa, 0x8f3, 0xbf9, 0xaf0, - 0x650, 0x759, 0x453, 0x55a, 0x256, 0x35f, 0x55, 0x15c, 0xe5c, 0xf55, 0xc5f, 0xd56, 0xa5a, 0xb53, 0x859, 0x950, - 0x7c0, 0x6c9, 0x5c3, 0x4ca, 0x3c6, 0x2cf, 0x1c5, 0xcc, 0xfcc, 0xec5, 0xdcf, 0xcc6, 0xbca, 0xac3, 0x9c9, 0x8c0, - 0x8c0, 0x9c9, 0xac3, 0xbca, 0xcc6, 0xdcf, 0xec5, 0xfcc, 0xcc, 0x1c5, 0x2cf, 0x3c6, 0x4ca, 0x5c3, 0x6c9, 0x7c0, - 0x950, 0x859, 0xb53, 0xa5a, 0xd56, 0xc5f, 0xf55, 0xe5c, 0x15c, 0x55, 0x35f, 0x256, 0x55a, 0x453, 0x759, 0x650, - 0xaf0, 0xbf9, 0x8f3, 0x9fa, 0xef6, 0xfff, 0xcf5, 0xdfc, 0x2fc, 0x3f5, 0xff, 0x1f6, 0x6fa, 0x7f3, 0x4f9, 0x5f0, - 0xb60, 0xa69, 0x963, 0x86a, 0xf66, 0xe6f, 0xd65, 0xc6c, 0x36c, 0x265, 0x16f, 0x66, 0x76a, 0x663, 0x569, 0x460, - 0xca0, 0xda9, 0xea3, 0xfaa, 0x8a6, 0x9af, 0xaa5, 0xbac, 0x4ac, 0x5a5, 0x6af, 0x7a6, 0xaa, 0x1a3, 0x2a9, 0x3a0, - 0xd30, 0xc39, 0xf33, 0xe3a, 0x936, 0x83f, 0xb35, 0xa3c, 0x53c, 0x435, 0x73f, 0x636, 0x13a, 0x33, 0x339, 0x230, - 0xe90, 0xf99, 0xc93, 0xd9a, 0xa96, 0xb9f, 0x895, 0x99c, 0x69c, 0x795, 0x49f, 0x596, 0x29a, 0x393, 0x99, 0x190, - 0xf00, 0xe09, 0xd03, 0xc0a, 0xb06, 0xa0f, 0x905, 0x80c, 0x70c, 0x605, 0x50f, 0x406, 0x30a, 0x203, 0x109, 0x0}; + 0x0, 0x109, 0x203, 0x30a, 0x406, 0x50f, 0x605, 0x70c, 0x80c, 0x905, 0xa0f, + 0xb06, 0xc0a, 0xd03, 0xe09, 0xf00, 0x190, 0x99, 0x393, 0x29a, 0x596, 0x49f, + 0x795, 0x69c, 0x99c, 0x895, 0xb9f, 0xa96, 0xd9a, 0xc93, 0xf99, 0xe90, 0x230, + 0x339, 0x33, 0x13a, 0x636, 0x73f, 0x435, 0x53c, 0xa3c, 0xb35, 0x83f, 0x936, + 0xe3a, 0xf33, 0xc39, 0xd30, 0x3a0, 0x2a9, 0x1a3, 0xaa, 0x7a6, 0x6af, 0x5a5, + 0x4ac, 0xbac, 0xaa5, 0x9af, 0x8a6, 0xfaa, 0xea3, 0xda9, 0xca0, 0x460, 0x569, + 0x663, 0x76a, 0x66, 0x16f, 0x265, 0x36c, 0xc6c, 0xd65, 0xe6f, 0xf66, 0x86a, + 0x963, 0xa69, 0xb60, 0x5f0, 0x4f9, 0x7f3, 0x6fa, 0x1f6, 0xff, 0x3f5, 0x2fc, + 0xdfc, 0xcf5, 0xfff, 0xef6, 0x9fa, 0x8f3, 0xbf9, 0xaf0, 0x650, 0x759, 0x453, + 0x55a, 0x256, 0x35f, 0x55, 0x15c, 0xe5c, 0xf55, 0xc5f, 0xd56, 0xa5a, 0xb53, + 0x859, 0x950, 0x7c0, 0x6c9, 0x5c3, 0x4ca, 0x3c6, 0x2cf, 0x1c5, 0xcc, 0xfcc, + 0xec5, 0xdcf, 0xcc6, 0xbca, 0xac3, 0x9c9, 0x8c0, 0x8c0, 0x9c9, 0xac3, 0xbca, + 0xcc6, 0xdcf, 0xec5, 0xfcc, 0xcc, 0x1c5, 0x2cf, 0x3c6, 0x4ca, 0x5c3, 0x6c9, + 0x7c0, 0x950, 0x859, 0xb53, 0xa5a, 0xd56, 0xc5f, 0xf55, 0xe5c, 0x15c, 0x55, + 0x35f, 0x256, 0x55a, 0x453, 0x759, 0x650, 0xaf0, 0xbf9, 0x8f3, 0x9fa, 0xef6, + 0xfff, 0xcf5, 0xdfc, 0x2fc, 0x3f5, 0xff, 0x1f6, 0x6fa, 0x7f3, 0x4f9, 0x5f0, + 0xb60, 0xa69, 0x963, 0x86a, 0xf66, 0xe6f, 0xd65, 0xc6c, 0x36c, 0x265, 0x16f, + 0x66, 0x76a, 0x663, 0x569, 0x460, 0xca0, 0xda9, 0xea3, 0xfaa, 0x8a6, 0x9af, + 0xaa5, 0xbac, 0x4ac, 0x5a5, 0x6af, 0x7a6, 0xaa, 0x1a3, 0x2a9, 0x3a0, 0xd30, + 0xc39, 0xf33, 0xe3a, 0x936, 0x83f, 0xb35, 0xa3c, 0x53c, 0x435, 0x73f, 0x636, + 0x13a, 0x33, 0x339, 0x230, 0xe90, 0xf99, 0xc93, 0xd9a, 0xa96, 0xb9f, 0x895, + 0x99c, 0x69c, 0x795, 0x49f, 0x596, 0x29a, 0x393, 0x99, 0x190, 0xf00, 0xe09, + 0xd03, 0xc0a, 0xb06, 0xa0f, 0x905, 0x80c, 0x70c, 0x605, 0x50f, 0x406, 0x30a, + 0x203, 0x109, 0x0}; // gives which vertices to join to form triangles for the surface -const int triTable[256][16] = {{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {0, 1, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {1, 8, 3, 9, 8, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {0, 8, 3, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {9, 2, 10, 0, 2, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {2, 8, 3, 2, 10, 8, 10, 9, 8, -1, -1, -1, -1, -1, -1, -1}, - {3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {0, 11, 2, 8, 11, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {1, 9, 0, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {1, 11, 2, 1, 9, 11, 9, 8, 11, -1, -1, -1, -1, -1, -1, -1}, - {3, 10, 1, 11, 10, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {0, 10, 1, 0, 8, 10, 8, 11, 10, -1, -1, -1, -1, -1, -1, -1}, - {3, 9, 0, 3, 11, 9, 11, 10, 9, -1, -1, -1, -1, -1, -1, -1}, - {9, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {4, 3, 0, 7, 3, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {0, 1, 9, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {4, 1, 9, 4, 7, 1, 7, 3, 1, -1, -1, -1, -1, -1, -1, -1}, - {1, 2, 10, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {3, 4, 7, 3, 0, 4, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1}, - {9, 2, 10, 9, 0, 2, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1}, - {2, 10, 9, 2, 9, 7, 2, 7, 3, 7, 9, 4, -1, -1, -1, -1}, - {8, 4, 7, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {11, 4, 7, 11, 2, 4, 2, 0, 4, -1, -1, -1, -1, -1, -1, -1}, - {9, 0, 1, 8, 4, 7, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1}, - {4, 7, 11, 9, 4, 11, 9, 11, 2, 9, 2, 1, -1, -1, -1, -1}, - {3, 10, 1, 3, 11, 10, 7, 8, 4, -1, -1, -1, -1, -1, -1, -1}, - {1, 11, 10, 1, 4, 11, 1, 0, 4, 7, 11, 4, -1, -1, -1, -1}, - {4, 7, 8, 9, 0, 11, 9, 11, 10, 11, 0, 3, -1, -1, -1, -1}, - {4, 7, 11, 4, 11, 9, 9, 11, 10, -1, -1, -1, -1, -1, -1, -1}, - {9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {9, 5, 4, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {0, 5, 4, 1, 5, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {8, 5, 4, 8, 3, 5, 3, 1, 5, -1, -1, -1, -1, -1, -1, -1}, - {1, 2, 10, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {3, 0, 8, 1, 2, 10, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1}, - {5, 2, 10, 5, 4, 2, 4, 0, 2, -1, -1, -1, -1, -1, -1, -1}, - {2, 10, 5, 3, 2, 5, 3, 5, 4, 3, 4, 8, -1, -1, -1, -1}, - {9, 5, 4, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {0, 11, 2, 0, 8, 11, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1}, - {0, 5, 4, 0, 1, 5, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1}, - {2, 1, 5, 2, 5, 8, 2, 8, 11, 4, 8, 5, -1, -1, -1, -1}, - {10, 3, 11, 10, 1, 3, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1}, - {4, 9, 5, 0, 8, 1, 8, 10, 1, 8, 11, 10, -1, -1, -1, -1}, - {5, 4, 0, 5, 0, 11, 5, 11, 10, 11, 0, 3, -1, -1, -1, -1}, - {5, 4, 8, 5, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1}, - {9, 7, 8, 5, 7, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {9, 3, 0, 9, 5, 3, 5, 7, 3, -1, -1, -1, -1, -1, -1, -1}, - {0, 7, 8, 0, 1, 7, 1, 5, 7, -1, -1, -1, -1, -1, -1, -1}, - {1, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {9, 7, 8, 9, 5, 7, 10, 1, 2, -1, -1, -1, -1, -1, -1, -1}, - {10, 1, 2, 9, 5, 0, 5, 3, 0, 5, 7, 3, -1, -1, -1, -1}, - {8, 0, 2, 8, 2, 5, 8, 5, 7, 10, 5, 2, -1, -1, -1, -1}, - {2, 10, 5, 2, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1}, - {7, 9, 5, 7, 8, 9, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1}, - {9, 5, 7, 9, 7, 2, 9, 2, 0, 2, 7, 11, -1, -1, -1, -1}, - {2, 3, 11, 0, 1, 8, 1, 7, 8, 1, 5, 7, -1, -1, -1, -1}, - {11, 2, 1, 11, 1, 7, 7, 1, 5, -1, -1, -1, -1, -1, -1, -1}, - {9, 5, 8, 8, 5, 7, 10, 1, 3, 10, 3, 11, -1, -1, -1, -1}, - {5, 7, 0, 5, 0, 9, 7, 11, 0, 1, 0, 10, 11, 10, 0, -1}, - {11, 10, 0, 11, 0, 3, 10, 5, 0, 8, 0, 7, 5, 7, 0, -1}, - {11, 10, 5, 7, 11, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {0, 8, 3, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {9, 0, 1, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {1, 8, 3, 1, 9, 8, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1}, - {1, 6, 5, 2, 6, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {1, 6, 5, 1, 2, 6, 3, 0, 8, -1, -1, -1, -1, -1, -1, -1}, - {9, 6, 5, 9, 0, 6, 0, 2, 6, -1, -1, -1, -1, -1, -1, -1}, - {5, 9, 8, 5, 8, 2, 5, 2, 6, 3, 2, 8, -1, -1, -1, -1}, - {2, 3, 11, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {11, 0, 8, 11, 2, 0, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1}, - {0, 1, 9, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1}, - {5, 10, 6, 1, 9, 2, 9, 11, 2, 9, 8, 11, -1, -1, -1, -1}, - {6, 3, 11, 6, 5, 3, 5, 1, 3, -1, -1, -1, -1, -1, -1, -1}, - {0, 8, 11, 0, 11, 5, 0, 5, 1, 5, 11, 6, -1, -1, -1, -1}, - {3, 11, 6, 0, 3, 6, 0, 6, 5, 0, 5, 9, -1, -1, -1, -1}, - {6, 5, 9, 6, 9, 11, 11, 9, 8, -1, -1, -1, -1, -1, -1, -1}, - {5, 10, 6, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {4, 3, 0, 4, 7, 3, 6, 5, 10, -1, -1, -1, -1, -1, -1, -1}, - {1, 9, 0, 5, 10, 6, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1}, - {10, 6, 5, 1, 9, 7, 1, 7, 3, 7, 9, 4, -1, -1, -1, -1}, - {6, 1, 2, 6, 5, 1, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1}, - {1, 2, 5, 5, 2, 6, 3, 0, 4, 3, 4, 7, -1, -1, -1, -1}, - {8, 4, 7, 9, 0, 5, 0, 6, 5, 0, 2, 6, -1, -1, -1, -1}, - {7, 3, 9, 7, 9, 4, 3, 2, 9, 5, 9, 6, 2, 6, 9, -1}, - {3, 11, 2, 7, 8, 4, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1}, - {5, 10, 6, 4, 7, 2, 4, 2, 0, 2, 7, 11, -1, -1, -1, -1}, - {0, 1, 9, 4, 7, 8, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1}, - {9, 2, 1, 9, 11, 2, 9, 4, 11, 7, 11, 4, 5, 10, 6, -1}, - {8, 4, 7, 3, 11, 5, 3, 5, 1, 5, 11, 6, -1, -1, -1, -1}, - {5, 1, 11, 5, 11, 6, 1, 0, 11, 7, 11, 4, 0, 4, 11, -1}, - {0, 5, 9, 0, 6, 5, 0, 3, 6, 11, 6, 3, 8, 4, 7, -1}, - {6, 5, 9, 6, 9, 11, 4, 7, 9, 7, 11, 9, -1, -1, -1, -1}, - {10, 4, 9, 6, 4, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {4, 10, 6, 4, 9, 10, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1}, - {10, 0, 1, 10, 6, 0, 6, 4, 0, -1, -1, -1, -1, -1, -1, -1}, - {8, 3, 1, 8, 1, 6, 8, 6, 4, 6, 1, 10, -1, -1, -1, -1}, - {1, 4, 9, 1, 2, 4, 2, 6, 4, -1, -1, -1, -1, -1, -1, -1}, - {3, 0, 8, 1, 2, 9, 2, 4, 9, 2, 6, 4, -1, -1, -1, -1}, - {0, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {8, 3, 2, 8, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1}, - {10, 4, 9, 10, 6, 4, 11, 2, 3, -1, -1, -1, -1, -1, -1, -1}, - {0, 8, 2, 2, 8, 11, 4, 9, 10, 4, 10, 6, -1, -1, -1, -1}, - {3, 11, 2, 0, 1, 6, 0, 6, 4, 6, 1, 10, -1, -1, -1, -1}, - {6, 4, 1, 6, 1, 10, 4, 8, 1, 2, 1, 11, 8, 11, 1, -1}, - {9, 6, 4, 9, 3, 6, 9, 1, 3, 11, 6, 3, -1, -1, -1, -1}, - {8, 11, 1, 8, 1, 0, 11, 6, 1, 9, 1, 4, 6, 4, 1, -1}, - {3, 11, 6, 3, 6, 0, 0, 6, 4, -1, -1, -1, -1, -1, -1, -1}, - {6, 4, 8, 11, 6, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {7, 10, 6, 7, 8, 10, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1}, - {0, 7, 3, 0, 10, 7, 0, 9, 10, 6, 7, 10, -1, -1, -1, -1}, - {10, 6, 7, 1, 10, 7, 1, 7, 8, 1, 8, 0, -1, -1, -1, -1}, - {10, 6, 7, 10, 7, 1, 1, 7, 3, -1, -1, -1, -1, -1, -1, -1}, - {1, 2, 6, 1, 6, 8, 1, 8, 9, 8, 6, 7, -1, -1, -1, -1}, - {2, 6, 9, 2, 9, 1, 6, 7, 9, 0, 9, 3, 7, 3, 9, -1}, - {7, 8, 0, 7, 0, 6, 6, 0, 2, -1, -1, -1, -1, -1, -1, -1}, - {7, 3, 2, 6, 7, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {2, 3, 11, 10, 6, 8, 10, 8, 9, 8, 6, 7, -1, -1, -1, -1}, - {2, 0, 7, 2, 7, 11, 0, 9, 7, 6, 7, 10, 9, 10, 7, -1}, - {1, 8, 0, 1, 7, 8, 1, 10, 7, 6, 7, 10, 2, 3, 11, -1}, - {11, 2, 1, 11, 1, 7, 10, 6, 1, 6, 7, 1, -1, -1, -1, -1}, - {8, 9, 6, 8, 6, 7, 9, 1, 6, 11, 6, 3, 1, 3, 6, -1}, - {0, 9, 1, 11, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {7, 8, 0, 7, 0, 6, 3, 11, 0, 11, 6, 0, -1, -1, -1, -1}, - {7, 11, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {3, 0, 8, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {0, 1, 9, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {8, 1, 9, 8, 3, 1, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1}, - {10, 1, 2, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {1, 2, 10, 3, 0, 8, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1}, - {2, 9, 0, 2, 10, 9, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1}, - {6, 11, 7, 2, 10, 3, 10, 8, 3, 10, 9, 8, -1, -1, -1, -1}, - {7, 2, 3, 6, 2, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {7, 0, 8, 7, 6, 0, 6, 2, 0, -1, -1, -1, -1, -1, -1, -1}, - {2, 7, 6, 2, 3, 7, 0, 1, 9, -1, -1, -1, -1, -1, -1, -1}, - {1, 6, 2, 1, 8, 6, 1, 9, 8, 8, 7, 6, -1, -1, -1, -1}, - {10, 7, 6, 10, 1, 7, 1, 3, 7, -1, -1, -1, -1, -1, -1, -1}, - {10, 7, 6, 1, 7, 10, 1, 8, 7, 1, 0, 8, -1, -1, -1, -1}, - {0, 3, 7, 0, 7, 10, 0, 10, 9, 6, 10, 7, -1, -1, -1, -1}, - {7, 6, 10, 7, 10, 8, 8, 10, 9, -1, -1, -1, -1, -1, -1, -1}, - {6, 8, 4, 11, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {3, 6, 11, 3, 0, 6, 0, 4, 6, -1, -1, -1, -1, -1, -1, -1}, - {8, 6, 11, 8, 4, 6, 9, 0, 1, -1, -1, -1, -1, -1, -1, -1}, - {9, 4, 6, 9, 6, 3, 9, 3, 1, 11, 3, 6, -1, -1, -1, -1}, - {6, 8, 4, 6, 11, 8, 2, 10, 1, -1, -1, -1, -1, -1, -1, -1}, - {1, 2, 10, 3, 0, 11, 0, 6, 11, 0, 4, 6, -1, -1, -1, -1}, - {4, 11, 8, 4, 6, 11, 0, 2, 9, 2, 10, 9, -1, -1, -1, -1}, - {10, 9, 3, 10, 3, 2, 9, 4, 3, 11, 3, 6, 4, 6, 3, -1}, - {8, 2, 3, 8, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1}, - {0, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {1, 9, 0, 2, 3, 4, 2, 4, 6, 4, 3, 8, -1, -1, -1, -1}, - {1, 9, 4, 1, 4, 2, 2, 4, 6, -1, -1, -1, -1, -1, -1, -1}, - {8, 1, 3, 8, 6, 1, 8, 4, 6, 6, 10, 1, -1, -1, -1, -1}, - {10, 1, 0, 10, 0, 6, 6, 0, 4, -1, -1, -1, -1, -1, -1, -1}, - {4, 6, 3, 4, 3, 8, 6, 10, 3, 0, 3, 9, 10, 9, 3, -1}, - {10, 9, 4, 6, 10, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {4, 9, 5, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {0, 8, 3, 4, 9, 5, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1}, - {5, 0, 1, 5, 4, 0, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1}, - {11, 7, 6, 8, 3, 4, 3, 5, 4, 3, 1, 5, -1, -1, -1, -1}, - {9, 5, 4, 10, 1, 2, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1}, - {6, 11, 7, 1, 2, 10, 0, 8, 3, 4, 9, 5, -1, -1, -1, -1}, - {7, 6, 11, 5, 4, 10, 4, 2, 10, 4, 0, 2, -1, -1, -1, -1}, - {3, 4, 8, 3, 5, 4, 3, 2, 5, 10, 5, 2, 11, 7, 6, -1}, - {7, 2, 3, 7, 6, 2, 5, 4, 9, -1, -1, -1, -1, -1, -1, -1}, - {9, 5, 4, 0, 8, 6, 0, 6, 2, 6, 8, 7, -1, -1, -1, -1}, - {3, 6, 2, 3, 7, 6, 1, 5, 0, 5, 4, 0, -1, -1, -1, -1}, - {6, 2, 8, 6, 8, 7, 2, 1, 8, 4, 8, 5, 1, 5, 8, -1}, - {9, 5, 4, 10, 1, 6, 1, 7, 6, 1, 3, 7, -1, -1, -1, -1}, - {1, 6, 10, 1, 7, 6, 1, 0, 7, 8, 7, 0, 9, 5, 4, -1}, - {4, 0, 10, 4, 10, 5, 0, 3, 10, 6, 10, 7, 3, 7, 10, -1}, - {7, 6, 10, 7, 10, 8, 5, 4, 10, 4, 8, 10, -1, -1, -1, -1}, - {6, 9, 5, 6, 11, 9, 11, 8, 9, -1, -1, -1, -1, -1, -1, -1}, - {3, 6, 11, 0, 6, 3, 0, 5, 6, 0, 9, 5, -1, -1, -1, -1}, - {0, 11, 8, 0, 5, 11, 0, 1, 5, 5, 6, 11, -1, -1, -1, -1}, - {6, 11, 3, 6, 3, 5, 5, 3, 1, -1, -1, -1, -1, -1, -1, -1}, - {1, 2, 10, 9, 5, 11, 9, 11, 8, 11, 5, 6, -1, -1, -1, -1}, - {0, 11, 3, 0, 6, 11, 0, 9, 6, 5, 6, 9, 1, 2, 10, -1}, - {11, 8, 5, 11, 5, 6, 8, 0, 5, 10, 5, 2, 0, 2, 5, -1}, - {6, 11, 3, 6, 3, 5, 2, 10, 3, 10, 5, 3, -1, -1, -1, -1}, - {5, 8, 9, 5, 2, 8, 5, 6, 2, 3, 8, 2, -1, -1, -1, -1}, - {9, 5, 6, 9, 6, 0, 0, 6, 2, -1, -1, -1, -1, -1, -1, -1}, - {1, 5, 8, 1, 8, 0, 5, 6, 8, 3, 8, 2, 6, 2, 8, -1}, - {1, 5, 6, 2, 1, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {1, 3, 6, 1, 6, 10, 3, 8, 6, 5, 6, 9, 8, 9, 6, -1}, - {10, 1, 0, 10, 0, 6, 9, 5, 0, 5, 6, 0, -1, -1, -1, -1}, - {0, 3, 8, 5, 6, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {10, 5, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {11, 5, 10, 7, 5, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {11, 5, 10, 11, 7, 5, 8, 3, 0, -1, -1, -1, -1, -1, -1, -1}, - {5, 11, 7, 5, 10, 11, 1, 9, 0, -1, -1, -1, -1, -1, -1, -1}, - {10, 7, 5, 10, 11, 7, 9, 8, 1, 8, 3, 1, -1, -1, -1, -1}, - {11, 1, 2, 11, 7, 1, 7, 5, 1, -1, -1, -1, -1, -1, -1, -1}, - {0, 8, 3, 1, 2, 7, 1, 7, 5, 7, 2, 11, -1, -1, -1, -1}, - {9, 7, 5, 9, 2, 7, 9, 0, 2, 2, 11, 7, -1, -1, -1, -1}, - {7, 5, 2, 7, 2, 11, 5, 9, 2, 3, 2, 8, 9, 8, 2, -1}, - {2, 5, 10, 2, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1}, - {8, 2, 0, 8, 5, 2, 8, 7, 5, 10, 2, 5, -1, -1, -1, -1}, - {9, 0, 1, 5, 10, 3, 5, 3, 7, 3, 10, 2, -1, -1, -1, -1}, - {9, 8, 2, 9, 2, 1, 8, 7, 2, 10, 2, 5, 7, 5, 2, -1}, - {1, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {0, 8, 7, 0, 7, 1, 1, 7, 5, -1, -1, -1, -1, -1, -1, -1}, - {9, 0, 3, 9, 3, 5, 5, 3, 7, -1, -1, -1, -1, -1, -1, -1}, - {9, 8, 7, 5, 9, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {5, 8, 4, 5, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1}, - {5, 0, 4, 5, 11, 0, 5, 10, 11, 11, 3, 0, -1, -1, -1, -1}, - {0, 1, 9, 8, 4, 10, 8, 10, 11, 10, 4, 5, -1, -1, -1, -1}, - {10, 11, 4, 10, 4, 5, 11, 3, 4, 9, 4, 1, 3, 1, 4, -1}, - {2, 5, 1, 2, 8, 5, 2, 11, 8, 4, 5, 8, -1, -1, -1, -1}, - {0, 4, 11, 0, 11, 3, 4, 5, 11, 2, 11, 1, 5, 1, 11, -1}, - {0, 2, 5, 0, 5, 9, 2, 11, 5, 4, 5, 8, 11, 8, 5, -1}, - {9, 4, 5, 2, 11, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {2, 5, 10, 3, 5, 2, 3, 4, 5, 3, 8, 4, -1, -1, -1, -1}, - {5, 10, 2, 5, 2, 4, 4, 2, 0, -1, -1, -1, -1, -1, -1, -1}, - {3, 10, 2, 3, 5, 10, 3, 8, 5, 4, 5, 8, 0, 1, 9, -1}, - {5, 10, 2, 5, 2, 4, 1, 9, 2, 9, 4, 2, -1, -1, -1, -1}, - {8, 4, 5, 8, 5, 3, 3, 5, 1, -1, -1, -1, -1, -1, -1, -1}, - {0, 4, 5, 1, 0, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {8, 4, 5, 8, 5, 3, 9, 0, 5, 0, 3, 5, -1, -1, -1, -1}, - {9, 4, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {4, 11, 7, 4, 9, 11, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1}, - {0, 8, 3, 4, 9, 7, 9, 11, 7, 9, 10, 11, -1, -1, -1, -1}, - {1, 10, 11, 1, 11, 4, 1, 4, 0, 7, 4, 11, -1, -1, -1, -1}, - {3, 1, 4, 3, 4, 8, 1, 10, 4, 7, 4, 11, 10, 11, 4, -1}, - {4, 11, 7, 9, 11, 4, 9, 2, 11, 9, 1, 2, -1, -1, -1, -1}, - {9, 7, 4, 9, 11, 7, 9, 1, 11, 2, 11, 1, 0, 8, 3, -1}, - {11, 7, 4, 11, 4, 2, 2, 4, 0, -1, -1, -1, -1, -1, -1, -1}, - {11, 7, 4, 11, 4, 2, 8, 3, 4, 3, 2, 4, -1, -1, -1, -1}, - {2, 9, 10, 2, 7, 9, 2, 3, 7, 7, 4, 9, -1, -1, -1, -1}, - {9, 10, 7, 9, 7, 4, 10, 2, 7, 8, 7, 0, 2, 0, 7, -1}, - {3, 7, 10, 3, 10, 2, 7, 4, 10, 1, 10, 0, 4, 0, 10, -1}, - {1, 10, 2, 8, 7, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {4, 9, 1, 4, 1, 7, 7, 1, 3, -1, -1, -1, -1, -1, -1, -1}, - {4, 9, 1, 4, 1, 7, 0, 8, 1, 8, 7, 1, -1, -1, -1, -1}, - {4, 0, 3, 7, 4, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {4, 8, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {9, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {3, 0, 9, 3, 9, 11, 11, 9, 10, -1, -1, -1, -1, -1, -1, -1}, - {0, 1, 10, 0, 10, 8, 8, 10, 11, -1, -1, -1, -1, -1, -1, -1}, - {3, 1, 10, 11, 3, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {1, 2, 11, 1, 11, 9, 9, 11, 8, -1, -1, -1, -1, -1, -1, -1}, - {3, 0, 9, 3, 9, 11, 1, 2, 9, 2, 11, 9, -1, -1, -1, -1}, - {0, 2, 11, 8, 0, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {3, 2, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {2, 3, 8, 2, 8, 10, 10, 8, 9, -1, -1, -1, -1, -1, -1, -1}, - {9, 10, 2, 0, 9, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {2, 3, 8, 2, 8, 10, 0, 1, 8, 1, 10, 8, -1, -1, -1, -1}, - {1, 10, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {1, 3, 8, 9, 1, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {0, 9, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {0, 3, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, - {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}}; +const int triTable[256][16] = { + {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {0, 1, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {1, 8, 3, 9, 8, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {0, 8, 3, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {9, 2, 10, 0, 2, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {2, 8, 3, 2, 10, 8, 10, 9, 8, -1, -1, -1, -1, -1, -1, -1}, + {3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {0, 11, 2, 8, 11, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {1, 9, 0, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {1, 11, 2, 1, 9, 11, 9, 8, 11, -1, -1, -1, -1, -1, -1, -1}, + {3, 10, 1, 11, 10, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {0, 10, 1, 0, 8, 10, 8, 11, 10, -1, -1, -1, -1, -1, -1, -1}, + {3, 9, 0, 3, 11, 9, 11, 10, 9, -1, -1, -1, -1, -1, -1, -1}, + {9, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {4, 3, 0, 7, 3, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {0, 1, 9, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {4, 1, 9, 4, 7, 1, 7, 3, 1, -1, -1, -1, -1, -1, -1, -1}, + {1, 2, 10, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {3, 4, 7, 3, 0, 4, 1, 2, 10, -1, -1, -1, -1, -1, -1, -1}, + {9, 2, 10, 9, 0, 2, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1}, + {2, 10, 9, 2, 9, 7, 2, 7, 3, 7, 9, 4, -1, -1, -1, -1}, + {8, 4, 7, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {11, 4, 7, 11, 2, 4, 2, 0, 4, -1, -1, -1, -1, -1, -1, -1}, + {9, 0, 1, 8, 4, 7, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1}, + {4, 7, 11, 9, 4, 11, 9, 11, 2, 9, 2, 1, -1, -1, -1, -1}, + {3, 10, 1, 3, 11, 10, 7, 8, 4, -1, -1, -1, -1, -1, -1, -1}, + {1, 11, 10, 1, 4, 11, 1, 0, 4, 7, 11, 4, -1, -1, -1, -1}, + {4, 7, 8, 9, 0, 11, 9, 11, 10, 11, 0, 3, -1, -1, -1, -1}, + {4, 7, 11, 4, 11, 9, 9, 11, 10, -1, -1, -1, -1, -1, -1, -1}, + {9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {9, 5, 4, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {0, 5, 4, 1, 5, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {8, 5, 4, 8, 3, 5, 3, 1, 5, -1, -1, -1, -1, -1, -1, -1}, + {1, 2, 10, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {3, 0, 8, 1, 2, 10, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1}, + {5, 2, 10, 5, 4, 2, 4, 0, 2, -1, -1, -1, -1, -1, -1, -1}, + {2, 10, 5, 3, 2, 5, 3, 5, 4, 3, 4, 8, -1, -1, -1, -1}, + {9, 5, 4, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {0, 11, 2, 0, 8, 11, 4, 9, 5, -1, -1, -1, -1, -1, -1, -1}, + {0, 5, 4, 0, 1, 5, 2, 3, 11, -1, -1, -1, -1, -1, -1, -1}, + {2, 1, 5, 2, 5, 8, 2, 8, 11, 4, 8, 5, -1, -1, -1, -1}, + {10, 3, 11, 10, 1, 3, 9, 5, 4, -1, -1, -1, -1, -1, -1, -1}, + {4, 9, 5, 0, 8, 1, 8, 10, 1, 8, 11, 10, -1, -1, -1, -1}, + {5, 4, 0, 5, 0, 11, 5, 11, 10, 11, 0, 3, -1, -1, -1, -1}, + {5, 4, 8, 5, 8, 10, 10, 8, 11, -1, -1, -1, -1, -1, -1, -1}, + {9, 7, 8, 5, 7, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {9, 3, 0, 9, 5, 3, 5, 7, 3, -1, -1, -1, -1, -1, -1, -1}, + {0, 7, 8, 0, 1, 7, 1, 5, 7, -1, -1, -1, -1, -1, -1, -1}, + {1, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {9, 7, 8, 9, 5, 7, 10, 1, 2, -1, -1, -1, -1, -1, -1, -1}, + {10, 1, 2, 9, 5, 0, 5, 3, 0, 5, 7, 3, -1, -1, -1, -1}, + {8, 0, 2, 8, 2, 5, 8, 5, 7, 10, 5, 2, -1, -1, -1, -1}, + {2, 10, 5, 2, 5, 3, 3, 5, 7, -1, -1, -1, -1, -1, -1, -1}, + {7, 9, 5, 7, 8, 9, 3, 11, 2, -1, -1, -1, -1, -1, -1, -1}, + {9, 5, 7, 9, 7, 2, 9, 2, 0, 2, 7, 11, -1, -1, -1, -1}, + {2, 3, 11, 0, 1, 8, 1, 7, 8, 1, 5, 7, -1, -1, -1, -1}, + {11, 2, 1, 11, 1, 7, 7, 1, 5, -1, -1, -1, -1, -1, -1, -1}, + {9, 5, 8, 8, 5, 7, 10, 1, 3, 10, 3, 11, -1, -1, -1, -1}, + {5, 7, 0, 5, 0, 9, 7, 11, 0, 1, 0, 10, 11, 10, 0, -1}, + {11, 10, 0, 11, 0, 3, 10, 5, 0, 8, 0, 7, 5, 7, 0, -1}, + {11, 10, 5, 7, 11, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {0, 8, 3, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {9, 0, 1, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {1, 8, 3, 1, 9, 8, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1}, + {1, 6, 5, 2, 6, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {1, 6, 5, 1, 2, 6, 3, 0, 8, -1, -1, -1, -1, -1, -1, -1}, + {9, 6, 5, 9, 0, 6, 0, 2, 6, -1, -1, -1, -1, -1, -1, -1}, + {5, 9, 8, 5, 8, 2, 5, 2, 6, 3, 2, 8, -1, -1, -1, -1}, + {2, 3, 11, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {11, 0, 8, 11, 2, 0, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1}, + {0, 1, 9, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1, -1, -1, -1}, + {5, 10, 6, 1, 9, 2, 9, 11, 2, 9, 8, 11, -1, -1, -1, -1}, + {6, 3, 11, 6, 5, 3, 5, 1, 3, -1, -1, -1, -1, -1, -1, -1}, + {0, 8, 11, 0, 11, 5, 0, 5, 1, 5, 11, 6, -1, -1, -1, -1}, + {3, 11, 6, 0, 3, 6, 0, 6, 5, 0, 5, 9, -1, -1, -1, -1}, + {6, 5, 9, 6, 9, 11, 11, 9, 8, -1, -1, -1, -1, -1, -1, -1}, + {5, 10, 6, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {4, 3, 0, 4, 7, 3, 6, 5, 10, -1, -1, -1, -1, -1, -1, -1}, + {1, 9, 0, 5, 10, 6, 8, 4, 7, -1, -1, -1, -1, -1, -1, -1}, + {10, 6, 5, 1, 9, 7, 1, 7, 3, 7, 9, 4, -1, -1, -1, -1}, + {6, 1, 2, 6, 5, 1, 4, 7, 8, -1, -1, -1, -1, -1, -1, -1}, + {1, 2, 5, 5, 2, 6, 3, 0, 4, 3, 4, 7, -1, -1, -1, -1}, + {8, 4, 7, 9, 0, 5, 0, 6, 5, 0, 2, 6, -1, -1, -1, -1}, + {7, 3, 9, 7, 9, 4, 3, 2, 9, 5, 9, 6, 2, 6, 9, -1}, + {3, 11, 2, 7, 8, 4, 10, 6, 5, -1, -1, -1, -1, -1, -1, -1}, + {5, 10, 6, 4, 7, 2, 4, 2, 0, 2, 7, 11, -1, -1, -1, -1}, + {0, 1, 9, 4, 7, 8, 2, 3, 11, 5, 10, 6, -1, -1, -1, -1}, + {9, 2, 1, 9, 11, 2, 9, 4, 11, 7, 11, 4, 5, 10, 6, -1}, + {8, 4, 7, 3, 11, 5, 3, 5, 1, 5, 11, 6, -1, -1, -1, -1}, + {5, 1, 11, 5, 11, 6, 1, 0, 11, 7, 11, 4, 0, 4, 11, -1}, + {0, 5, 9, 0, 6, 5, 0, 3, 6, 11, 6, 3, 8, 4, 7, -1}, + {6, 5, 9, 6, 9, 11, 4, 7, 9, 7, 11, 9, -1, -1, -1, -1}, + {10, 4, 9, 6, 4, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {4, 10, 6, 4, 9, 10, 0, 8, 3, -1, -1, -1, -1, -1, -1, -1}, + {10, 0, 1, 10, 6, 0, 6, 4, 0, -1, -1, -1, -1, -1, -1, -1}, + {8, 3, 1, 8, 1, 6, 8, 6, 4, 6, 1, 10, -1, -1, -1, -1}, + {1, 4, 9, 1, 2, 4, 2, 6, 4, -1, -1, -1, -1, -1, -1, -1}, + {3, 0, 8, 1, 2, 9, 2, 4, 9, 2, 6, 4, -1, -1, -1, -1}, + {0, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {8, 3, 2, 8, 2, 4, 4, 2, 6, -1, -1, -1, -1, -1, -1, -1}, + {10, 4, 9, 10, 6, 4, 11, 2, 3, -1, -1, -1, -1, -1, -1, -1}, + {0, 8, 2, 2, 8, 11, 4, 9, 10, 4, 10, 6, -1, -1, -1, -1}, + {3, 11, 2, 0, 1, 6, 0, 6, 4, 6, 1, 10, -1, -1, -1, -1}, + {6, 4, 1, 6, 1, 10, 4, 8, 1, 2, 1, 11, 8, 11, 1, -1}, + {9, 6, 4, 9, 3, 6, 9, 1, 3, 11, 6, 3, -1, -1, -1, -1}, + {8, 11, 1, 8, 1, 0, 11, 6, 1, 9, 1, 4, 6, 4, 1, -1}, + {3, 11, 6, 3, 6, 0, 0, 6, 4, -1, -1, -1, -1, -1, -1, -1}, + {6, 4, 8, 11, 6, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {7, 10, 6, 7, 8, 10, 8, 9, 10, -1, -1, -1, -1, -1, -1, -1}, + {0, 7, 3, 0, 10, 7, 0, 9, 10, 6, 7, 10, -1, -1, -1, -1}, + {10, 6, 7, 1, 10, 7, 1, 7, 8, 1, 8, 0, -1, -1, -1, -1}, + {10, 6, 7, 10, 7, 1, 1, 7, 3, -1, -1, -1, -1, -1, -1, -1}, + {1, 2, 6, 1, 6, 8, 1, 8, 9, 8, 6, 7, -1, -1, -1, -1}, + {2, 6, 9, 2, 9, 1, 6, 7, 9, 0, 9, 3, 7, 3, 9, -1}, + {7, 8, 0, 7, 0, 6, 6, 0, 2, -1, -1, -1, -1, -1, -1, -1}, + {7, 3, 2, 6, 7, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {2, 3, 11, 10, 6, 8, 10, 8, 9, 8, 6, 7, -1, -1, -1, -1}, + {2, 0, 7, 2, 7, 11, 0, 9, 7, 6, 7, 10, 9, 10, 7, -1}, + {1, 8, 0, 1, 7, 8, 1, 10, 7, 6, 7, 10, 2, 3, 11, -1}, + {11, 2, 1, 11, 1, 7, 10, 6, 1, 6, 7, 1, -1, -1, -1, -1}, + {8, 9, 6, 8, 6, 7, 9, 1, 6, 11, 6, 3, 1, 3, 6, -1}, + {0, 9, 1, 11, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {7, 8, 0, 7, 0, 6, 3, 11, 0, 11, 6, 0, -1, -1, -1, -1}, + {7, 11, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {3, 0, 8, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {0, 1, 9, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {8, 1, 9, 8, 3, 1, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1}, + {10, 1, 2, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {1, 2, 10, 3, 0, 8, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1}, + {2, 9, 0, 2, 10, 9, 6, 11, 7, -1, -1, -1, -1, -1, -1, -1}, + {6, 11, 7, 2, 10, 3, 10, 8, 3, 10, 9, 8, -1, -1, -1, -1}, + {7, 2, 3, 6, 2, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {7, 0, 8, 7, 6, 0, 6, 2, 0, -1, -1, -1, -1, -1, -1, -1}, + {2, 7, 6, 2, 3, 7, 0, 1, 9, -1, -1, -1, -1, -1, -1, -1}, + {1, 6, 2, 1, 8, 6, 1, 9, 8, 8, 7, 6, -1, -1, -1, -1}, + {10, 7, 6, 10, 1, 7, 1, 3, 7, -1, -1, -1, -1, -1, -1, -1}, + {10, 7, 6, 1, 7, 10, 1, 8, 7, 1, 0, 8, -1, -1, -1, -1}, + {0, 3, 7, 0, 7, 10, 0, 10, 9, 6, 10, 7, -1, -1, -1, -1}, + {7, 6, 10, 7, 10, 8, 8, 10, 9, -1, -1, -1, -1, -1, -1, -1}, + {6, 8, 4, 11, 8, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {3, 6, 11, 3, 0, 6, 0, 4, 6, -1, -1, -1, -1, -1, -1, -1}, + {8, 6, 11, 8, 4, 6, 9, 0, 1, -1, -1, -1, -1, -1, -1, -1}, + {9, 4, 6, 9, 6, 3, 9, 3, 1, 11, 3, 6, -1, -1, -1, -1}, + {6, 8, 4, 6, 11, 8, 2, 10, 1, -1, -1, -1, -1, -1, -1, -1}, + {1, 2, 10, 3, 0, 11, 0, 6, 11, 0, 4, 6, -1, -1, -1, -1}, + {4, 11, 8, 4, 6, 11, 0, 2, 9, 2, 10, 9, -1, -1, -1, -1}, + {10, 9, 3, 10, 3, 2, 9, 4, 3, 11, 3, 6, 4, 6, 3, -1}, + {8, 2, 3, 8, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1}, + {0, 4, 2, 4, 6, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {1, 9, 0, 2, 3, 4, 2, 4, 6, 4, 3, 8, -1, -1, -1, -1}, + {1, 9, 4, 1, 4, 2, 2, 4, 6, -1, -1, -1, -1, -1, -1, -1}, + {8, 1, 3, 8, 6, 1, 8, 4, 6, 6, 10, 1, -1, -1, -1, -1}, + {10, 1, 0, 10, 0, 6, 6, 0, 4, -1, -1, -1, -1, -1, -1, -1}, + {4, 6, 3, 4, 3, 8, 6, 10, 3, 0, 3, 9, 10, 9, 3, -1}, + {10, 9, 4, 6, 10, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {4, 9, 5, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {0, 8, 3, 4, 9, 5, 11, 7, 6, -1, -1, -1, -1, -1, -1, -1}, + {5, 0, 1, 5, 4, 0, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1}, + {11, 7, 6, 8, 3, 4, 3, 5, 4, 3, 1, 5, -1, -1, -1, -1}, + {9, 5, 4, 10, 1, 2, 7, 6, 11, -1, -1, -1, -1, -1, -1, -1}, + {6, 11, 7, 1, 2, 10, 0, 8, 3, 4, 9, 5, -1, -1, -1, -1}, + {7, 6, 11, 5, 4, 10, 4, 2, 10, 4, 0, 2, -1, -1, -1, -1}, + {3, 4, 8, 3, 5, 4, 3, 2, 5, 10, 5, 2, 11, 7, 6, -1}, + {7, 2, 3, 7, 6, 2, 5, 4, 9, -1, -1, -1, -1, -1, -1, -1}, + {9, 5, 4, 0, 8, 6, 0, 6, 2, 6, 8, 7, -1, -1, -1, -1}, + {3, 6, 2, 3, 7, 6, 1, 5, 0, 5, 4, 0, -1, -1, -1, -1}, + {6, 2, 8, 6, 8, 7, 2, 1, 8, 4, 8, 5, 1, 5, 8, -1}, + {9, 5, 4, 10, 1, 6, 1, 7, 6, 1, 3, 7, -1, -1, -1, -1}, + {1, 6, 10, 1, 7, 6, 1, 0, 7, 8, 7, 0, 9, 5, 4, -1}, + {4, 0, 10, 4, 10, 5, 0, 3, 10, 6, 10, 7, 3, 7, 10, -1}, + {7, 6, 10, 7, 10, 8, 5, 4, 10, 4, 8, 10, -1, -1, -1, -1}, + {6, 9, 5, 6, 11, 9, 11, 8, 9, -1, -1, -1, -1, -1, -1, -1}, + {3, 6, 11, 0, 6, 3, 0, 5, 6, 0, 9, 5, -1, -1, -1, -1}, + {0, 11, 8, 0, 5, 11, 0, 1, 5, 5, 6, 11, -1, -1, -1, -1}, + {6, 11, 3, 6, 3, 5, 5, 3, 1, -1, -1, -1, -1, -1, -1, -1}, + {1, 2, 10, 9, 5, 11, 9, 11, 8, 11, 5, 6, -1, -1, -1, -1}, + {0, 11, 3, 0, 6, 11, 0, 9, 6, 5, 6, 9, 1, 2, 10, -1}, + {11, 8, 5, 11, 5, 6, 8, 0, 5, 10, 5, 2, 0, 2, 5, -1}, + {6, 11, 3, 6, 3, 5, 2, 10, 3, 10, 5, 3, -1, -1, -1, -1}, + {5, 8, 9, 5, 2, 8, 5, 6, 2, 3, 8, 2, -1, -1, -1, -1}, + {9, 5, 6, 9, 6, 0, 0, 6, 2, -1, -1, -1, -1, -1, -1, -1}, + {1, 5, 8, 1, 8, 0, 5, 6, 8, 3, 8, 2, 6, 2, 8, -1}, + {1, 5, 6, 2, 1, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {1, 3, 6, 1, 6, 10, 3, 8, 6, 5, 6, 9, 8, 9, 6, -1}, + {10, 1, 0, 10, 0, 6, 9, 5, 0, 5, 6, 0, -1, -1, -1, -1}, + {0, 3, 8, 5, 6, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {10, 5, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {11, 5, 10, 7, 5, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {11, 5, 10, 11, 7, 5, 8, 3, 0, -1, -1, -1, -1, -1, -1, -1}, + {5, 11, 7, 5, 10, 11, 1, 9, 0, -1, -1, -1, -1, -1, -1, -1}, + {10, 7, 5, 10, 11, 7, 9, 8, 1, 8, 3, 1, -1, -1, -1, -1}, + {11, 1, 2, 11, 7, 1, 7, 5, 1, -1, -1, -1, -1, -1, -1, -1}, + {0, 8, 3, 1, 2, 7, 1, 7, 5, 7, 2, 11, -1, -1, -1, -1}, + {9, 7, 5, 9, 2, 7, 9, 0, 2, 2, 11, 7, -1, -1, -1, -1}, + {7, 5, 2, 7, 2, 11, 5, 9, 2, 3, 2, 8, 9, 8, 2, -1}, + {2, 5, 10, 2, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1}, + {8, 2, 0, 8, 5, 2, 8, 7, 5, 10, 2, 5, -1, -1, -1, -1}, + {9, 0, 1, 5, 10, 3, 5, 3, 7, 3, 10, 2, -1, -1, -1, -1}, + {9, 8, 2, 9, 2, 1, 8, 7, 2, 10, 2, 5, 7, 5, 2, -1}, + {1, 3, 5, 3, 7, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {0, 8, 7, 0, 7, 1, 1, 7, 5, -1, -1, -1, -1, -1, -1, -1}, + {9, 0, 3, 9, 3, 5, 5, 3, 7, -1, -1, -1, -1, -1, -1, -1}, + {9, 8, 7, 5, 9, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {5, 8, 4, 5, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1}, + {5, 0, 4, 5, 11, 0, 5, 10, 11, 11, 3, 0, -1, -1, -1, -1}, + {0, 1, 9, 8, 4, 10, 8, 10, 11, 10, 4, 5, -1, -1, -1, -1}, + {10, 11, 4, 10, 4, 5, 11, 3, 4, 9, 4, 1, 3, 1, 4, -1}, + {2, 5, 1, 2, 8, 5, 2, 11, 8, 4, 5, 8, -1, -1, -1, -1}, + {0, 4, 11, 0, 11, 3, 4, 5, 11, 2, 11, 1, 5, 1, 11, -1}, + {0, 2, 5, 0, 5, 9, 2, 11, 5, 4, 5, 8, 11, 8, 5, -1}, + {9, 4, 5, 2, 11, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {2, 5, 10, 3, 5, 2, 3, 4, 5, 3, 8, 4, -1, -1, -1, -1}, + {5, 10, 2, 5, 2, 4, 4, 2, 0, -1, -1, -1, -1, -1, -1, -1}, + {3, 10, 2, 3, 5, 10, 3, 8, 5, 4, 5, 8, 0, 1, 9, -1}, + {5, 10, 2, 5, 2, 4, 1, 9, 2, 9, 4, 2, -1, -1, -1, -1}, + {8, 4, 5, 8, 5, 3, 3, 5, 1, -1, -1, -1, -1, -1, -1, -1}, + {0, 4, 5, 1, 0, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {8, 4, 5, 8, 5, 3, 9, 0, 5, 0, 3, 5, -1, -1, -1, -1}, + {9, 4, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {4, 11, 7, 4, 9, 11, 9, 10, 11, -1, -1, -1, -1, -1, -1, -1}, + {0, 8, 3, 4, 9, 7, 9, 11, 7, 9, 10, 11, -1, -1, -1, -1}, + {1, 10, 11, 1, 11, 4, 1, 4, 0, 7, 4, 11, -1, -1, -1, -1}, + {3, 1, 4, 3, 4, 8, 1, 10, 4, 7, 4, 11, 10, 11, 4, -1}, + {4, 11, 7, 9, 11, 4, 9, 2, 11, 9, 1, 2, -1, -1, -1, -1}, + {9, 7, 4, 9, 11, 7, 9, 1, 11, 2, 11, 1, 0, 8, 3, -1}, + {11, 7, 4, 11, 4, 2, 2, 4, 0, -1, -1, -1, -1, -1, -1, -1}, + {11, 7, 4, 11, 4, 2, 8, 3, 4, 3, 2, 4, -1, -1, -1, -1}, + {2, 9, 10, 2, 7, 9, 2, 3, 7, 7, 4, 9, -1, -1, -1, -1}, + {9, 10, 7, 9, 7, 4, 10, 2, 7, 8, 7, 0, 2, 0, 7, -1}, + {3, 7, 10, 3, 10, 2, 7, 4, 10, 1, 10, 0, 4, 0, 10, -1}, + {1, 10, 2, 8, 7, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {4, 9, 1, 4, 1, 7, 7, 1, 3, -1, -1, -1, -1, -1, -1, -1}, + {4, 9, 1, 4, 1, 7, 0, 8, 1, 8, 7, 1, -1, -1, -1, -1}, + {4, 0, 3, 7, 4, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {4, 8, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {9, 10, 8, 10, 11, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {3, 0, 9, 3, 9, 11, 11, 9, 10, -1, -1, -1, -1, -1, -1, -1}, + {0, 1, 10, 0, 10, 8, 8, 10, 11, -1, -1, -1, -1, -1, -1, -1}, + {3, 1, 10, 11, 3, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {1, 2, 11, 1, 11, 9, 9, 11, 8, -1, -1, -1, -1, -1, -1, -1}, + {3, 0, 9, 3, 9, 11, 1, 2, 9, 2, 11, 9, -1, -1, -1, -1}, + {0, 2, 11, 8, 0, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {3, 2, 11, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {2, 3, 8, 2, 8, 10, 10, 8, 9, -1, -1, -1, -1, -1, -1, -1}, + {9, 10, 2, 0, 9, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {2, 3, 8, 2, 8, 10, 0, 1, 8, 1, 10, 8, -1, -1, -1, -1}, + {1, 10, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {1, 3, 8, 9, 1, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {0, 9, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {0, 3, 8, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}}; class MetaballsScene : public Scene { diff --git a/apps/scenes/animation/WaterScene.cpp b/apps/scenes/animation/WaterScene.cpp index edb15ca..790cc92 100644 --- a/apps/scenes/animation/WaterScene.cpp +++ b/apps/scenes/animation/WaterScene.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include "WaterScene.h" @@ -33,9 +30,7 @@ WaterScene::WaterScene(const std::string& name) { } -WaterScene::~WaterScene(void) -{ -} +WaterScene::~WaterScene(void) {} vec3f WaterScene::F(float x, float z, float stepX, float stepZ) { @@ -79,10 +74,12 @@ void WaterScene::processCurve(bool update) float tstep = step * 2.f; int primitiveIndex(m_initialIndex - 1); float tx = 0.f; - for (float x = -static_cast(M_PI); x < static_cast(M_PI) - step / 2.f; x += step) + for (float x = -static_cast(M_PI); + x < static_cast(M_PI) - step / 2.f; x += step) { float ty = 0.f; - for (float z = -static_cast(M_PI); z < static_cast(M_PI) - step / 2.f; z += step) + for (float z = -static_cast(M_PI); + z < static_cast(M_PI) - step / 2.f; z += step) { // Face int index(0); @@ -98,8 +95,12 @@ void WaterScene::processCurve(bool update) // Normal const vec3f P1p = F(x + X + step, z + Z, X / 2.f, Z / 2.f); const vec3f P3p = F(x + X, z + Z + step, X / 2.f, Z / 2.f); - vec3f v1 = make_vec3f(P1p.x - vertices[index].x, P1p.y - vertices[index].y, P1p.z - vertices[index].z); - vec3f v3 = make_vec3f(P3p.x - vertices[index].x, P3p.y - vertices[index].y, P3p.z - vertices[index].z); + vec3f v1 = make_vec3f(P1p.x - vertices[index].x, + P1p.y - vertices[index].y, + P1p.z - vertices[index].z); + vec3f v3 = make_vec3f(P3p.x - vertices[index].x, + P3p.y - vertices[index].y, + P3p.z - vertices[index].z); m_gpuKernel->normalizeVector(v1); m_gpuKernel->normalizeVector(v3); verticesNormals[index] = m_gpuKernel->crossProduct(v1, v3); @@ -119,20 +120,25 @@ void WaterScene::processCurve(bool update) } m_gpuKernel->setPrimitive( primitiveIndex, m_objectSize.x * vertices[0].x, - m_groundHeight + 2.f * m_objectSize.y * m_scale.y + m_objectSize.y * vertices[0].y, + m_groundHeight + 2.f * m_objectSize.y * m_scale.y + + m_objectSize.y * vertices[0].y, m_objectSize.z * vertices[0].z, m_objectSize.x * vertices[2].x, - m_groundHeight + 2.f * m_objectSize.y * m_scale.y + m_objectSize.y * vertices[2].y, + m_groundHeight + 2.f * m_objectSize.y * m_scale.y + + m_objectSize.y * vertices[2].y, m_objectSize.z * vertices[2].z, m_objectSize.x * vertices[3].x, - m_groundHeight + 2.f * m_objectSize.y * m_scale.y + m_objectSize.y * vertices[3].y, + m_groundHeight + 2.f * m_objectSize.y * m_scale.y + + m_objectSize.y * vertices[3].y, m_objectSize.z * vertices[3].z, 0.f, 0.f, 0.f, m_material); - m_gpuKernel->setPrimitiveNormals(primitiveIndex, verticesNormals[0], verticesNormals[2], + m_gpuKernel->setPrimitiveNormals(primitiveIndex, verticesNormals[0], + verticesNormals[2], verticesNormals[3]); { const vec2f tc0 = make_vec2f(tx, ty); const vec2f tc1 = make_vec2f(tx + tstep, ty); const vec2f tc2 = make_vec2f(tx + tstep, ty + tstep); - m_gpuKernel->setPrimitiveTextureCoordinates(primitiveIndex, tc0, tc1, tc2); + m_gpuKernel->setPrimitiveTextureCoordinates(primitiveIndex, tc0, + tc1, tc2); } if (update) @@ -144,20 +150,25 @@ void WaterScene::processCurve(bool update) } m_gpuKernel->setPrimitive( primitiveIndex, m_objectSize.x * vertices[3].x, - m_groundHeight + 2.f * m_objectSize.y * m_scale.y + m_objectSize.y * vertices[3].y, + m_groundHeight + 2.f * m_objectSize.y * m_scale.y + + m_objectSize.y * vertices[3].y, m_objectSize.z * vertices[3].z, m_objectSize.x * vertices[1].x, - m_groundHeight + 2.f * m_objectSize.y * m_scale.y + m_objectSize.y * vertices[1].y, + m_groundHeight + 2.f * m_objectSize.y * m_scale.y + + m_objectSize.y * vertices[1].y, m_objectSize.z * vertices[1].z, m_objectSize.x * vertices[0].x, - m_groundHeight + 2.f * m_objectSize.y * m_scale.y + m_objectSize.y * vertices[0].y, + m_groundHeight + 2.f * m_objectSize.y * m_scale.y + + m_objectSize.y * vertices[0].y, m_objectSize.z * vertices[0].z, 0.f, 0.f, 0.f, m_material); - m_gpuKernel->setPrimitiveNormals(primitiveIndex, verticesNormals[3], verticesNormals[1], + m_gpuKernel->setPrimitiveNormals(primitiveIndex, verticesNormals[3], + verticesNormals[1], verticesNormals[0]); { const vec2f tc0 = make_vec2f(tx + tstep, ty + tstep); const vec2f tc1 = make_vec2f(tx, ty + tstep); const vec2f tc2 = make_vec2f(tx, ty); - m_gpuKernel->setPrimitiveTextureCoordinates(primitiveIndex, tc0, tc1, tc2); + m_gpuKernel->setPrimitiveTextureCoordinates(primitiveIndex, tc0, + tc1, tc2); } ty += tstep; } @@ -187,8 +198,12 @@ void WaterScene::processParametricCurve(bool update) // Normal const vec3f P1p = P(t, X / 2.f, Z / 2.f); const vec3f P3p = P(t, X / 2.f, Z / 2.f); - vec3f v1 = make_vec3f(P1p.x - vertices[index].x, P1p.y - vertices[index].y, P1p.z - vertices[index].z); - vec3f v3 = make_vec3f(P3p.x - vertices[index].x, P3p.y - vertices[index].y, P3p.z - vertices[index].z); + vec3f v1 = make_vec3f(P1p.x - vertices[index].x, + P1p.y - vertices[index].y, + P1p.z - vertices[index].z); + vec3f v3 = make_vec3f(P3p.x - vertices[index].x, + P3p.y - vertices[index].y, + P3p.z - vertices[index].z); m_gpuKernel->normalizeVector(v1); m_gpuKernel->normalizeVector(v3); verticesNormals[index] = m_gpuKernel->crossProduct(v1, v3); @@ -207,13 +222,17 @@ void WaterScene::processParametricCurve(bool update) } m_gpuKernel->setPrimitive( primitiveIndex, m_objectSize.x * vertices[0].x, - m_groundHeight + 2.f * m_objectSize.y * m_scale.y + m_objectSize.y * vertices[0].y, + m_groundHeight + 2.f * m_objectSize.y * m_scale.y + + m_objectSize.y * vertices[0].y, m_objectSize.z * vertices[0].z, m_objectSize.x * vertices[2].x, - m_groundHeight + 2.f * m_objectSize.y * m_scale.y + m_objectSize.y * vertices[2].y, + m_groundHeight + 2.f * m_objectSize.y * m_scale.y + + m_objectSize.y * vertices[2].y, m_objectSize.z * vertices[2].z, m_objectSize.x * vertices[3].x, - m_groundHeight + 2.f * m_objectSize.y * m_scale.y + m_objectSize.y * vertices[3].y, + m_groundHeight + 2.f * m_objectSize.y * m_scale.y + + m_objectSize.y * vertices[3].y, m_objectSize.z * vertices[3].z, 0.f, 0.f, 0.f, m_material); - m_gpuKernel->setPrimitiveNormals(primitiveIndex, verticesNormals[0], verticesNormals[2], + m_gpuKernel->setPrimitiveNormals(primitiveIndex, verticesNormals[0], + verticesNormals[2], verticesNormals[3]); if (update) @@ -225,13 +244,17 @@ void WaterScene::processParametricCurve(bool update) } m_gpuKernel->setPrimitive( primitiveIndex, m_objectSize.x * vertices[3].x, - m_groundHeight + 2.f * m_objectSize.y * m_scale.y + m_objectSize.y * vertices[3].y, + m_groundHeight + 2.f * m_objectSize.y * m_scale.y + + m_objectSize.y * vertices[3].y, m_objectSize.z * vertices[3].z, m_objectSize.x * vertices[1].x, - m_groundHeight + 2.f * m_objectSize.y * m_scale.y + m_objectSize.y * vertices[1].y, + m_groundHeight + 2.f * m_objectSize.y * m_scale.y + + m_objectSize.y * vertices[1].y, m_objectSize.z * vertices[1].z, m_objectSize.x * vertices[0].x, - m_groundHeight + 2.f * m_objectSize.y * m_scale.y + m_objectSize.y * vertices[0].y, + m_groundHeight + 2.f * m_objectSize.y * m_scale.y + + m_objectSize.y * vertices[0].y, m_objectSize.z * vertices[0].z, 0.f, 0.f, 0.f, m_material); - m_gpuKernel->setPrimitiveNormals(primitiveIndex, verticesNormals[3], verticesNormals[1], + m_gpuKernel->setPrimitiveNormals(primitiveIndex, verticesNormals[3], + verticesNormals[1], verticesNormals[0]); } } @@ -265,7 +288,8 @@ void WaterScene::doAddLights() if (m_gpuKernel->getNbActiveLamps() == 0) { m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, 8000.f, 8000.f, -8000.f, 500.f, 0.f, 0.f, DEFAULT_LIGHT_MATERIAL); + m_gpuKernel->setPrimitive(m_nbPrimitives, 8000.f, 8000.f, -8000.f, + 500.f, 0.f, 0.f, DEFAULT_LIGHT_MATERIAL); m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); } } diff --git a/apps/scenes/animation/WaterScene.h b/apps/scenes/animation/WaterScene.h index fc744e9..d2fc098 100644 --- a/apps/scenes/animation/WaterScene.h +++ b/apps/scenes/animation/WaterScene.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once diff --git a/apps/scenes/experiments/CornellBoxScene.cpp b/apps/scenes/experiments/CornellBoxScene.cpp index 3754455..d811e9e 100644 --- a/apps/scenes/experiments/CornellBoxScene.cpp +++ b/apps/scenes/experiments/CornellBoxScene.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include "CornellBoxScene.h" @@ -31,23 +28,25 @@ CornellBoxScene::CornellBoxScene(const std::string& name) { } -CornellBoxScene::~CornellBoxScene(void) -{ -} +CornellBoxScene::~CornellBoxScene(void) {} void CornellBoxScene::doInitialize() { m_groundHeight = -5000.f; // Spheres m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, 2200.f, 0.f, 0.f, 2000.f, 0.f, 0.f, rand() % 50); + m_gpuKernel->setPrimitive(m_nbPrimitives, 2200.f, 0.f, 0.f, 2000.f, 0.f, + 0.f, rand() % 50); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, -2200.f, 0.f, 0.f, 2000.f, 0.f, 0.f, rand() % 50); + m_gpuKernel->setPrimitive(m_nbPrimitives, -2200.f, 0.f, 0.f, 2000.f, 0.f, + 0.f, rand() % 50); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, 0.f, 2200.f, 0.f, 2000.f, 0.f, 0.f, rand() % 50); + m_gpuKernel->setPrimitive(m_nbPrimitives, 0.f, 2200.f, 0.f, 2000.f, 0.f, + 0.f, rand() % 50); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, 0.f, -2200.f, 0.f, 2000.f, 0.f, 0.f, rand() % 50); + m_gpuKernel->setPrimitive(m_nbPrimitives, 0.f, -2200.f, 0.f, 2000.f, 0.f, + 0.f, rand() % 50); m_gpuKernel->getSceneInfo().nbRayIterations = 20; } @@ -67,8 +66,10 @@ void CornellBoxScene::doAddLights() { // lights m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, rand() % 20000 - 10000.f, rand() % 5000 - m_groundHeight, - rand() % 20000 - 10000.f, 10.f, 0.f, 0.f, 120 + i); + m_gpuKernel->setPrimitive(m_nbPrimitives, rand() % 20000 - 10000.f, + rand() % 5000 - m_groundHeight, + rand() % 20000 - 10000.f, 10.f, 0.f, 0.f, + 120 + i); m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); } } diff --git a/apps/scenes/experiments/CornellBoxScene.h b/apps/scenes/experiments/CornellBoxScene.h index c170515..cf78a7c 100644 --- a/apps/scenes/experiments/CornellBoxScene.h +++ b/apps/scenes/experiments/CornellBoxScene.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once diff --git a/apps/scenes/experiments/CubesScene.cpp b/apps/scenes/experiments/CubesScene.cpp index 1a96406..5607362 100644 --- a/apps/scenes/experiments/CubesScene.cpp +++ b/apps/scenes/experiments/CubesScene.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include "CubesScene.h" @@ -31,9 +28,7 @@ CubesScene::CubesScene(const std::string& name) { } -CubesScene::~CubesScene(void) -{ -} +CubesScene::~CubesScene(void) {} void CubesScene::doInitialize() { @@ -55,9 +50,7 @@ void CubesScene::doInitialize() m_gpuKernel->getSceneInfo().nbRayIterations = 20; } -void CubesScene::doAnimate() -{ -} +void CubesScene::doAnimate() {} void CubesScene::doAddLights() { @@ -65,7 +58,8 @@ void CubesScene::doAddLights() if (m_gpuKernel->getNbActiveLamps() == 0) { m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, 8000.f, 8000.f, -8000.f, 500.f, 0.f, 0.f, DEFAULT_LIGHT_MATERIAL); + m_gpuKernel->setPrimitive(m_nbPrimitives, 8000.f, 8000.f, -8000.f, + 500.f, 0.f, 0.f, DEFAULT_LIGHT_MATERIAL); m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); } } diff --git a/apps/scenes/experiments/CubesScene.h b/apps/scenes/experiments/CubesScene.h index a53d5f0..6aa7d54 100644 --- a/apps/scenes/experiments/CubesScene.h +++ b/apps/scenes/experiments/CubesScene.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once diff --git a/apps/scenes/experiments/CylinderScene.cpp b/apps/scenes/experiments/CylinderScene.cpp index 848027e..16f7670 100644 --- a/apps/scenes/experiments/CylinderScene.cpp +++ b/apps/scenes/experiments/CylinderScene.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau - * - * This file is part of Sol-R +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include "CylinderScene.h" @@ -31,9 +28,7 @@ CylinderScene::CylinderScene(const std::string& name) { } -CylinderScene::~CylinderScene(void) -{ -} +CylinderScene::~CylinderScene(void) {} /* ________________________________________________________________________________ @@ -75,26 +70,35 @@ void CylinderScene::doInitialize() m_gpuKernel->setPrimitive(m_nbPrimitives, 2500, 0, 0, 1000, 0.f, 0.f, 55); m_vt0 = make_vec2f(); m_vt1 = make_vec2f(10.f, 10.f); - m_gpuKernel->setPrimitiveTextureCoordinates(m_nbPrimitives, m_vt0, m_vt1, m_vt2); + m_gpuKernel->setPrimitiveTextureCoordinates(m_nbPrimitives, m_vt0, m_vt1, + m_vt2); m_mappedSphere = m_nbPrimitives; m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, -2500, 0, 0, 1000.f, 0.f, 0.f, 45); - m_gpuKernel->setPrimitiveTextureCoordinates(m_nbPrimitives, m_vt0, m_vt1, m_vt2); + m_gpuKernel->setPrimitive(m_nbPrimitives, -2500, 0, 0, 1000.f, 0.f, 0.f, + 45); + m_gpuKernel->setPrimitiveTextureCoordinates(m_nbPrimitives, m_vt0, m_vt1, + m_vt2); // Cylinders m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder); - m_gpuKernel->setPrimitive(m_nbPrimitives, -1000, 1000, 0, 1000, -1000, 0, size, size, 0.f, rand() % 100); + m_gpuKernel->setPrimitive(m_nbPrimitives, -1000, 1000, 0, 1000, -1000, 0, + size, size, 0.f, rand() % 100); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, -1000, -1000, 0, size, 0.f, 0.f, rand() % 40); + m_gpuKernel->setPrimitive(m_nbPrimitives, -1000, -1000, 0, size, 0.f, 0.f, + rand() % 40); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, 1000, 1000, 0, size, 0.f, 0.f, LIGHT_MATERIAL_001 /*rand()%40*/); + m_gpuKernel->setPrimitive(m_nbPrimitives, 1000, 1000, 0, size, 0.f, 0.f, + LIGHT_MATERIAL_001 /*rand()%40*/); m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder); - m_gpuKernel->setPrimitive(m_nbPrimitives, -1000, -1000, 0, 1000, 1000, 0, size, size, 0.f, rand() % 100); + m_gpuKernel->setPrimitive(m_nbPrimitives, -1000, -1000, 0, 1000, 1000, 0, + size, size, 0.f, rand() % 100); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, -1000, 1000, 0, size, 0.f, 0.f, rand() % 40); + m_gpuKernel->setPrimitive(m_nbPrimitives, -1000, 1000, 0, size, 0.f, 0.f, + rand() % 40); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, 1000, -1000, 0, size, 0.f, 0.f, LIGHT_MATERIAL_002 /*rand()%40*/); + m_gpuKernel->setPrimitive(m_nbPrimitives, 1000, -1000, 0, size, 0.f, 0.f, + LIGHT_MATERIAL_002 /*rand()%40*/); #endif // 1 m_gpuKernel->getSceneInfo().nbRayIterations = 20; @@ -106,8 +110,10 @@ void CylinderScene::doAnimate() m_gpuKernel->rotatePrimitives(m_rotationCenter, m_rotationAngles); m_vt0.x = -PI / 2.f; m_vt0.y -= 0.05f; - m_gpuKernel->setPrimitiveTextureCoordinates(m_mappedSphere, m_vt0, m_vt1, m_vt2); - m_gpuKernel->setPrimitiveTextureCoordinates(m_mappedSphere + 1, m_vt0, m_vt1, m_vt2); + m_gpuKernel->setPrimitiveTextureCoordinates(m_mappedSphere, m_vt0, m_vt1, + m_vt2); + m_gpuKernel->setPrimitiveTextureCoordinates(m_mappedSphere + 1, m_vt0, + m_vt1, m_vt2); m_gpuKernel->compactBoxes(false); } @@ -115,6 +121,7 @@ void CylinderScene::doAddLights() { // lights m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, 0.f, 10000.f, -10000.f, 2000.f, 0.f, 0, DEFAULT_LIGHT_MATERIAL); + m_gpuKernel->setPrimitive(m_nbPrimitives, 0.f, 10000.f, -10000.f, 2000.f, + 0.f, 0, DEFAULT_LIGHT_MATERIAL); m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); } diff --git a/apps/scenes/experiments/CylinderScene.h b/apps/scenes/experiments/CylinderScene.h index b28a8e0..4f6cf2a 100644 --- a/apps/scenes/experiments/CylinderScene.h +++ b/apps/scenes/experiments/CylinderScene.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once @@ -38,5 +35,4 @@ class CylinderScene : public Scene vec2f m_vt0; vec2f m_vt1; vec2f m_vt2; - }; diff --git a/apps/scenes/experiments/DoggyStyleScene.cpp b/apps/scenes/experiments/DoggyStyleScene.cpp index b4a94a0..dde2846 100644 --- a/apps/scenes/experiments/DoggyStyleScene.cpp +++ b/apps/scenes/experiments/DoggyStyleScene.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include "DoggyStyleScene.h" @@ -33,9 +30,7 @@ DoggyStyleScene::DoggyStyleScene(const std::string& name) { } -DoggyStyleScene::~DoggyStyleScene(void) -{ -} +DoggyStyleScene::~DoggyStyleScene(void) {} void DoggyStyleScene::doInitialize() { @@ -47,19 +42,20 @@ void DoggyStyleScene::doInitialize() m_gpuKernel->rotatePrimitives(center, angles); } -void DoggyStyleScene::doAnimate() -{ -} +void DoggyStyleScene::doAnimate() {} void DoggyStyleScene::doAddLights() { // Laser for (int i = 0; i < 3; ++i) { - const vec4f p1 = make_vec4f(rand() % 10000 - 5000.f, 5000.f, rand() % 10000 - 5000.f); - const vec4f p2 = make_vec4f(-(rand() % 10000 - 5000.f), -5000.f, -(rand() % 10000 - 5000.f)); + const vec4f p1 = make_vec4f(rand() % 10000 - 5000.f, 5000.f, + rand() % 10000 - 5000.f); + const vec4f p2 = make_vec4f(-(rand() % 10000 - 5000.f), -5000.f, + -(rand() % 10000 - 5000.f)); m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder); - m_gpuKernel->setPrimitive(m_nbPrimitives, p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, 100.f, 100.f, 100.f, + m_gpuKernel->setPrimitive(m_nbPrimitives, p1.x, p1.y, p1.z, p2.x, p2.y, + p2.z, 100.f, 100.f, 100.f, DEFAULT_LIGHT_MATERIAL - i); } } diff --git a/apps/scenes/experiments/DoggyStyleScene.h b/apps/scenes/experiments/DoggyStyleScene.h index e6a4fa5..f9d9b03 100644 --- a/apps/scenes/experiments/DoggyStyleScene.h +++ b/apps/scenes/experiments/DoggyStyleScene.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once diff --git a/apps/scenes/experiments/GalleryScene.cpp b/apps/scenes/experiments/GalleryScene.cpp index c5eee4a..df7a050 100644 --- a/apps/scenes/experiments/GalleryScene.cpp +++ b/apps/scenes/experiments/GalleryScene.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include "GalleryScene.h" @@ -35,9 +32,7 @@ GalleryScene::GalleryScene(const std::string& name) m_groundHeight = -2500.f; } -GalleryScene::~GalleryScene(void) -{ -} +GalleryScene::~GalleryScene(void) {} void GalleryScene::doInitialize() { @@ -82,37 +77,53 @@ void GalleryScene::doInitialize() p3.y = y + step.y - frame.y; // sin(y+step.y); p3.z = sin(x + frame.x); - const vec3f normal0 = make_vec3f(position.x - p0.x, position.y - p0.y, position.z - p0.z); - const vec3f normal1 = make_vec3f(position.x - p1.x, position.y - p1.y, position.z - p1.z); - const vec3f normal2 = make_vec3f(position.x - p2.x, position.y - p2.y, position.z - p2.z); - const vec3f normal3 = make_vec3f(position.x - p3.x, position.y - p3.y, position.z - p3.z); + const vec3f normal0 = + make_vec3f(position.x - p0.x, position.y - p0.y, + position.z - p0.z); + const vec3f normal1 = + make_vec3f(position.x - p1.x, position.y - p1.y, + position.z - p1.z); + const vec3f normal2 = + make_vec3f(position.x - p2.x, position.y - p2.y, + position.z - p2.z); + const vec3f normal3 = + make_vec3f(position.x - p3.x, position.y - p3.y, + position.z - p3.z); m_nbPrimitives = m_gpuKernel->addPrimitive(ptTriangle); - m_gpuKernel->setPrimitive(m_nbPrimitives, position.x + p0.x * size.x, position.y + p0.y * size.y, - position.z + p0.z * size.z, position.x + p1.x * size.x, - position.y + p1.y * size.y, position.z + p1.z * size.z, - position.x + p2.x * size.x, position.y + p2.y * size.y, - position.z + p2.z * size.z, 0.f, 0.f, 0.f, m); - m_gpuKernel->setPrimitiveNormals(m_nbPrimitives, normal0, normal1, normal2); + m_gpuKernel->setPrimitive( + m_nbPrimitives, position.x + p0.x * size.x, + position.y + p0.y * size.y, position.z + p0.z * size.z, + position.x + p1.x * size.x, position.y + p1.y * size.y, + position.z + p1.z * size.z, position.x + p2.x * size.x, + position.y + p2.y * size.y, position.z + p2.z * size.z, 0.f, + 0.f, 0.f, m); + m_gpuKernel->setPrimitiveNormals(m_nbPrimitives, normal0, normal1, + normal2); { const vec2f tc0 = make_vec2f(1.f, 1.f); const vec2f tc1 = make_vec2f(0.f, 1.f); const vec2f tc2 = make_vec2f(0.f, 0.f); - m_gpuKernel->setPrimitiveTextureCoordinates(m_nbPrimitives, tc0, tc1, tc2); + m_gpuKernel->setPrimitiveTextureCoordinates(m_nbPrimitives, tc0, + tc1, tc2); } m_nbPrimitives = m_gpuKernel->addPrimitive(ptTriangle); - m_gpuKernel->setPrimitive(m_nbPrimitives, position.x + p2.x * size.x, position.y + p2.y * size.y, - position.z + p2.z * size.z, position.x + p3.x * size.x, - position.y + p3.y * size.y, position.z + p3.z * size.z, - position.x + p0.x * size.x, position.y + p0.y * size.y, - position.z + p0.z * size.z, 0.f, 0.f, 0.f, m); - m_gpuKernel->setPrimitiveNormals(m_nbPrimitives, normal2, normal3, normal0); + m_gpuKernel->setPrimitive( + m_nbPrimitives, position.x + p2.x * size.x, + position.y + p2.y * size.y, position.z + p2.z * size.z, + position.x + p3.x * size.x, position.y + p3.y * size.y, + position.z + p3.z * size.z, position.x + p0.x * size.x, + position.y + p0.y * size.y, position.z + p0.z * size.z, 0.f, + 0.f, 0.f, m); + m_gpuKernel->setPrimitiveNormals(m_nbPrimitives, normal2, normal3, + normal0); { const vec2f tc0 = make_vec2f(0.f, 0.f); const vec2f tc1 = make_vec2f(1.f, 0.f); const vec2f tc2 = make_vec2f(1.f, 1.f); - m_gpuKernel->setPrimitiveTextureCoordinates(m_nbPrimitives, tc0, tc1, tc2); + m_gpuKernel->setPrimitiveTextureCoordinates(m_nbPrimitives, tc0, + tc1, tc2); } ++i; } @@ -120,8 +131,10 @@ void GalleryScene::doInitialize() for (int i(0); i < 40; ++i) { m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, rand() % 10000 - 5000.f, rand() % 10000 - 5000.f, - rand() % 10000 - 5000.f, 200.f + rand() % 200, 0.f, 0.f, 41 + rand() % 2); + m_gpuKernel->setPrimitive(m_nbPrimitives, rand() % 10000 - 5000.f, + rand() % 10000 - 5000.f, + rand() % 10000 - 5000.f, 200.f + rand() % 200, + 0.f, 0.f, 41 + rand() % 2); } } @@ -136,6 +149,7 @@ void GalleryScene::doAddLights() { // Lights m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, 0.f, 5000.f, 0.f, 0, 0, 0, DEFAULT_LIGHT_MATERIAL); + m_gpuKernel->setPrimitive(m_nbPrimitives, 0.f, 5000.f, 0.f, 0, 0, 0, + DEFAULT_LIGHT_MATERIAL); m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); } diff --git a/apps/scenes/experiments/GalleryScene.h b/apps/scenes/experiments/GalleryScene.h index 48d0f33..3077109 100644 --- a/apps/scenes/experiments/GalleryScene.h +++ b/apps/scenes/experiments/GalleryScene.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once diff --git a/apps/scenes/experiments/GraphScene.cpp b/apps/scenes/experiments/GraphScene.cpp index 4a66d31..1f24272 100644 --- a/apps/scenes/experiments/GraphScene.cpp +++ b/apps/scenes/experiments/GraphScene.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include "GraphScene.h" @@ -30,8 +27,6 @@ #endif #include -using namespace solr; - GraphScene::GraphScene(const std::string& name) : Scene(name) { @@ -55,14 +50,16 @@ void GraphScene::buildGraph(const bool update) for (int i = 0; i < m_nbGraphElements; ++i) { m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder); - m_gpuKernel->setPrimitive(m_nbPrimitives, -1000.f, -4000.f, 0.f, -1000.f, 1000.f, 0.f, 20.f, 0.f, 0.f, + m_gpuKernel->setPrimitive(m_nbPrimitives, -1000.f, -4000.f, 0.f, + -1000.f, 1000.f, 0.f, 20.f, 0.f, 0.f, material); if (i == 0) m_startGraph = m_nbPrimitives; m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, -1000.f, 1000.f, 0.f, 20.f, 0.f, 0.f, material); + m_gpuKernel->setPrimitive(m_nbPrimitives, -1000.f, 1000.f, 0.f, + 20.f, 0.f, 0.f, material); ++material; } @@ -72,50 +69,73 @@ void GraphScene::buildGraph(const bool update) material = m_graphMaterial; for (int i(0); i < m_nbGraphElements; ++i) { - m_graphValues[i] = (cos(m_gpuKernel->getSceneInfo().timestamp * 0.00402f + i * 0.2f) * - sin(m_gpuKernel->getSceneInfo().timestamp * 0.00208f + i * 0.5f)) * - 2000.f; + m_graphValues[i] = + (cos(m_gpuKernel->getSceneInfo().timestamp * 0.00402f + i * 0.2f) * + sin(m_gpuKernel->getSceneInfo().timestamp * 0.00208f + i * 0.5f)) * + 2000.f; maxY = (m_graphValues[i] > maxY ? m_graphValues[i] : maxY); switch (m_currentModel % 3) { case 0: { - float z = 4.f * m_graphSize.x * (i / (m_nbGraphElements / 2)) - 2.f * m_graphSize.x; + float z = 4.f * m_graphSize.x * (i / (m_nbGraphElements / 2)) - + 2.f * m_graphSize.x; int j = (i * 2) % (m_nbGraphElements / 2); - m_gpuKernel->setPrimitive(m_startGraph + (i * 2), m_graphSpace + j * 2.f * m_graphSpace - x / 2.f, y, z, - m_graphSpace + j * 2.f * m_graphSpace - x / 2.f, m_graphValues[i], z, - m_graphSize.x, 0.f, 0.f, material); - - m_gpuKernel->setPrimitive(m_startGraph + (i * 2) + 1, m_graphSpace + j * 2.f * m_graphSpace - x / 2.f, - m_graphValues[i], z, m_graphSize.x, 0.f, 0.f, material); + m_gpuKernel->setPrimitive( + m_startGraph + (i * 2), + m_graphSpace + j * 2.f * m_graphSpace - x / 2.f, y, z, + m_graphSpace + j * 2.f * m_graphSpace - x / 2.f, + m_graphValues[i], z, m_graphSize.x, 0.f, 0.f, material); + + m_gpuKernel->setPrimitive(m_startGraph + (i * 2) + 1, + m_graphSpace + j * 2.f * m_graphSpace - + x / 2.f, + m_graphValues[i], z, m_graphSize.x, 0.f, + 0.f, material); break; } case 1: { if (i > 0) - m_gpuKernel->setPrimitive(m_startGraph + (i * 2), m_graphSpace / 2.f + (i - 1) * m_graphSpace - x / 2.f, - m_graphValues[i - 1], 0.f, m_graphSpace / 2.f + i * m_graphSpace - x / 2.f, - m_graphValues[i], 0.f, m_graphSize.x / 2.f, 0.f, 0.f, material); + m_gpuKernel->setPrimitive( + m_startGraph + (i * 2), + m_graphSpace / 2.f + (i - 1) * m_graphSpace - x / 2.f, + m_graphValues[i - 1], 0.f, + m_graphSpace / 2.f + i * m_graphSpace - x / 2.f, + m_graphValues[i], 0.f, m_graphSize.x / 2.f, 0.f, 0.f, + material); else - m_gpuKernel->setPrimitive(m_startGraph + (i * 2), 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, + m_gpuKernel->setPrimitive(m_startGraph + (i * 2), 0.f, 0.f, 0.f, + 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, material); - m_gpuKernel->setPrimitive(m_startGraph + (i * 2) + 1, m_graphSpace / 2.f + i * m_graphSpace - x / 2.f, - m_graphValues[i], 0.f, m_graphSize.x / 2.f, 0.f, 0.f, material); + m_gpuKernel->setPrimitive(m_startGraph + (i * 2) + 1, + m_graphSpace / 2.f + i * m_graphSpace - + x / 2.f, + m_graphValues[i], 0.f, + m_graphSize.x / 2.f, 0.f, 0.f, material); break; } case 2: { if (i > 0) - m_gpuKernel->setPrimitive(m_startGraph + (i * 2), m_graphSpace / 2.f + (i - 1) * m_graphSpace - x / 2.f, - m_graphValues[i - 1], 0.f, m_graphSpace / 2.f + i * m_graphSpace - x / 2.f, - m_graphValues[i], 0.f, m_graphSize.x / 4.f, 0.f, 0.f, material); + m_gpuKernel->setPrimitive( + m_startGraph + (i * 2), + m_graphSpace / 2.f + (i - 1) * m_graphSpace - x / 2.f, + m_graphValues[i - 1], 0.f, + m_graphSpace / 2.f + i * m_graphSpace - x / 2.f, + m_graphValues[i], 0.f, m_graphSize.x / 4.f, 0.f, 0.f, + material); else - m_gpuKernel->setPrimitive(m_startGraph + (i * 2), 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, + m_gpuKernel->setPrimitive(m_startGraph + (i * 2), 0.f, 0.f, 0.f, + 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, material); - m_gpuKernel->setPrimitive(m_startGraph + (i * 2) + 1, m_graphSpace / 2.f + i * m_graphSpace - x / 2.f, - m_graphValues[i], 0.f, m_graphSize.x, 0.f, 0.f, material); + m_gpuKernel->setPrimitive(m_startGraph + (i * 2) + 1, + m_graphSpace / 2.f + i * m_graphSpace - + x / 2.f, + m_graphValues[i], 0.f, m_graphSize.x, 0.f, + 0.f, material); break; } } @@ -190,18 +210,28 @@ void GraphScene::buildChart(const std::string& filename) for (int z = 0; z < m_valueSize.x; ++z) { glBegin(GL_TRIANGLES); - glTranslatef(-m_graphScale.x * m_graphCenter.x, m_graphScale.y * m_graphCenter.y, + glTranslatef(-m_graphScale.x * m_graphCenter.x, + m_graphScale.y * m_graphCenter.y, -m_graphScale.z * m_graphCenter.z); m_gpuKernel->setCurrentMaterial(RANDOM_MATERIALS_OFFSET + 4 + m); for (int x = 0; x < m_valueSize.y; ++x) { - glVertex3f(m_graphScale.x * x, m_graphScale.y * m_values[x][z], -m_graphScale.z * z); - glVertex3f(m_graphScale.x * (x + 1), m_graphScale.y * m_values[x + 1][z], -m_graphScale.z * z); - glVertex3f(m_graphScale.x * (x + 1), m_graphScale.y * m_values[x + 1][z + 1], -m_graphScale.z * (z + 1)); - - glVertex3f(m_graphScale.x * (x + 1), m_graphScale.y * m_values[x + 1][z + 1], -m_graphScale.z * (z + 1)); - glVertex3f(m_graphScale.x * x, m_graphScale.y * m_values[x][z + 1], -m_graphScale.z * (z + 1)); - glVertex3f(m_graphScale.x * x, m_graphScale.y * m_values[x][z], -m_graphScale.z * z); + glVertex3f(m_graphScale.x * x, m_graphScale.y * m_values[x][z], + -m_graphScale.z * z); + glVertex3f(m_graphScale.x * (x + 1), + m_graphScale.y * m_values[x + 1][z], + -m_graphScale.z * z); + glVertex3f(m_graphScale.x * (x + 1), + m_graphScale.y * m_values[x + 1][z + 1], + -m_graphScale.z * (z + 1)); + + glVertex3f(m_graphScale.x * (x + 1), + m_graphScale.y * m_values[x + 1][z + 1], + -m_graphScale.z * (z + 1)); + glVertex3f(m_graphScale.x * x, m_graphScale.y * m_values[x][z + 1], + -m_graphScale.z * (z + 1)); + glVertex3f(m_graphScale.x * x, m_graphScale.y * m_values[x][z], + -m_graphScale.z * z); } glEnd(); ++m; @@ -210,10 +240,12 @@ void GraphScene::buildChart(const std::string& filename) for (int x = 0; x < m_valueSize.y; ++x) { int p = m_gpuKernel->addPrimitive(ptXYPlane); - m_gpuKernel->setPrimitive(p, -m_graphScale.x * m_graphCenter.x + m_graphScale.x * x, - 500.f + m_graphScale.y * m_graphCenter.y + m_graphScale.y * m_values[x][z], - m_graphScale.z * m_graphCenter.z - m_graphScale.z * z, 200.f, 100.f, 0.f, - RANDOM_MATERIALS_OFFSET + 3); + m_gpuKernel->setPrimitive( + p, -m_graphScale.x * m_graphCenter.x + m_graphScale.x * x, + 500.f + m_graphScale.y * m_graphCenter.y + + m_graphScale.y * m_values[x][z], + m_graphScale.z * m_graphCenter.z - m_graphScale.z * z, 200.f, + 100.f, 0.f, RANDOM_MATERIALS_OFFSET + 3); } } @@ -327,13 +359,12 @@ void GraphScene::doInitialize() buildGraph(false); } -void GraphScene::doAnimate() -{ -} +void GraphScene::doAnimate() {} void GraphScene::doAddLights() { // Lights m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, 0.f, 5000.f, 0.f, 50.f, 0, 0, DEFAULT_LIGHT_MATERIAL); + m_gpuKernel->setPrimitive(m_nbPrimitives, 0.f, 5000.f, 0.f, 50.f, 0, 0, + DEFAULT_LIGHT_MATERIAL); } diff --git a/apps/scenes/experiments/GraphScene.h b/apps/scenes/experiments/GraphScene.h index 2659546..4aab8c9 100644 --- a/apps/scenes/experiments/GraphScene.h +++ b/apps/scenes/experiments/GraphScene.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once diff --git a/apps/scenes/experiments/PerpetualMotionScene.cpp b/apps/scenes/experiments/PerpetualMotionScene.cpp index e368018..c38b63b 100644 --- a/apps/scenes/experiments/PerpetualMotionScene.cpp +++ b/apps/scenes/experiments/PerpetualMotionScene.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include "PerpetualMotionScene.h" @@ -31,9 +28,7 @@ PerpetualMotionScene::PerpetualMotionScene(const std::string& name) { } -PerpetualMotionScene::~PerpetualMotionScene(void) -{ -} +PerpetualMotionScene::~PerpetualMotionScene(void) {} void PerpetualMotionScene::doInitialize() { @@ -47,56 +42,71 @@ void PerpetualMotionScene::doInitialize() // Portique float radius = 200.f; m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder, true); - m_gpuKernel->setPrimitive(m_nbPrimitives, -4000, m_groundHeight, -4000, -2500, 4000, 0, radius, 0.f, 0.f, - material1); + m_gpuKernel->setPrimitive(m_nbPrimitives, -4000, m_groundHeight, -4000, + -2500, 4000, 0, radius, 0.f, 0.f, material1); m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder, true); - m_gpuKernel->setPrimitive(m_nbPrimitives, -4000, m_groundHeight, 4000, -2500, 4000, 0, radius, 0.f, 0.f, material1); + m_gpuKernel->setPrimitive(m_nbPrimitives, -4000, m_groundHeight, 4000, + -2500, 4000, 0, radius, 0.f, 0.f, material1); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere, true); - m_gpuKernel->setPrimitive(m_nbPrimitives, -2500, 4000, 0, radius, 0, 0, material1); + m_gpuKernel->setPrimitive(m_nbPrimitives, -2500, 4000, 0, radius, 0, 0, + material1); m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder, true); - m_gpuKernel->setPrimitive(m_nbPrimitives, -2500, 4000, 0, 2500, 4000, 0, radius, 0.f, 0.f, material1); + m_gpuKernel->setPrimitive(m_nbPrimitives, -2500, 4000, 0, 2500, 4000, 0, + radius, 0.f, 0.f, material1); m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder, true); - m_gpuKernel->setPrimitive(m_nbPrimitives, 4000, m_groundHeight, -4000, 2500, 4000, 0, radius, 0.f, 0.f, material1); + m_gpuKernel->setPrimitive(m_nbPrimitives, 4000, m_groundHeight, -4000, 2500, + 4000, 0, radius, 0.f, 0.f, material1); m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder, true); - m_gpuKernel->setPrimitive(m_nbPrimitives, 4000, m_groundHeight, 4000, 2500, 4000, 0, radius, 0.f, 0.f, material1); + m_gpuKernel->setPrimitive(m_nbPrimitives, 4000, m_groundHeight, 4000, 2500, + 4000, 0, radius, 0.f, 0.f, material1); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere, true); - m_gpuKernel->setPrimitive(m_nbPrimitives, 2500, 4000, 0, radius, 0, 0, material1); + m_gpuKernel->setPrimitive(m_nbPrimitives, 2500, 4000, 0, radius, 0, 0, + material1); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere, true); - m_gpuKernel->setPrimitive(m_nbPrimitives, -2500, 4000, 0, radius, 0, 0, material1); + m_gpuKernel->setPrimitive(m_nbPrimitives, -2500, 4000, 0, radius, 0, 0, + material1); // Balls m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder, true); - m_gpuKernel->setPrimitive(m_nbPrimitives, -2000, -1000.f, 0, -2000, 4000, -200, 10, 0.f, 0.f, material2); + m_gpuKernel->setPrimitive(m_nbPrimitives, -2000, -1000.f, 0, -2000, 4000, + -200, 10, 0.f, 0.f, material2); m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder, true); - m_gpuKernel->setPrimitive(m_nbPrimitives, -2000, -1000.f, 0, -2000, 4000, 200, 10, 0.f, 0.f, material2); + m_gpuKernel->setPrimitive(m_nbPrimitives, -2000, -1000.f, 0, -2000, 4000, + 200, 10, 0.f, 0.f, material2); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere, true); - m_gpuKernel->setPrimitive(m_nbPrimitives, -2000, -1000.f, 0, 1000, 0, 0, material5); + m_gpuKernel->setPrimitive(m_nbPrimitives, -2000, -1000.f, 0, 1000, 0, 0, + material5); m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder, true); - m_gpuKernel->setPrimitive(m_nbPrimitives, 0, -1000.f, 0, 0, 4000, -200, 10, 0.f, 0.f, material2); + m_gpuKernel->setPrimitive(m_nbPrimitives, 0, -1000.f, 0, 0, 4000, -200, 10, + 0.f, 0.f, material2); m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder, true); - m_gpuKernel->setPrimitive(m_nbPrimitives, 0, -1000.f, 0, 0, 4000, 200, 10, 0.f, 0.f, material2); + m_gpuKernel->setPrimitive(m_nbPrimitives, 0, -1000.f, 0, 0, 4000, 200, 10, + 0.f, 0.f, material2); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere, true); - m_gpuKernel->setPrimitive(m_nbPrimitives, 0, -1000.f, 0, 1000, 0, 0, material3); + m_gpuKernel->setPrimitive(m_nbPrimitives, 0, -1000.f, 0, 1000, 0, 0, + material3); m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder, true); - m_gpuKernel->setPrimitive(m_nbPrimitives, 2000, -1000.f, 0, 2000, 4000, -200, 10, 0.f, 0.f, material2); + m_gpuKernel->setPrimitive(m_nbPrimitives, 2000, -1000.f, 0, 2000, 4000, + -200, 10, 0.f, 0.f, material2); m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder, true); - m_gpuKernel->setPrimitive(m_nbPrimitives, 2000, -1000.f, 0, 2000, 4000, 200, 10, 0.f, 0.f, material2); + m_gpuKernel->setPrimitive(m_nbPrimitives, 2000, -1000.f, 0, 2000, 4000, 200, + 10, 0.f, 0.f, material2); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere, true); - m_gpuKernel->setPrimitive(m_nbPrimitives, 2000, -1000.f, 0, 1000, 0, 0, material4); + m_gpuKernel->setPrimitive(m_nbPrimitives, 2000, -1000.f, 0, 1000, 0, 0, + material4); m_gpuKernel->getSceneInfo().nbRayIterations = 20; } -void PerpetualMotionScene::doAnimate() -{ -} +void PerpetualMotionScene::doAnimate() {} void PerpetualMotionScene::doAddLights() { // lights float size = 1000.f; m_nbPrimitives = m_gpuKernel->addPrimitive(ptXZPlane); - m_gpuKernel->setPrimitive(m_nbPrimitives, 5000.f, 5000.f, -5000.f, size, 0.f, size * 4.f, DEFAULT_LIGHT_MATERIAL); + m_gpuKernel->setPrimitive(m_nbPrimitives, 5000.f, 5000.f, -5000.f, size, + 0.f, size * 4.f, DEFAULT_LIGHT_MATERIAL); } diff --git a/apps/scenes/experiments/PerpetualMotionScene.h b/apps/scenes/experiments/PerpetualMotionScene.h index b2ad914..2b4e49e 100644 --- a/apps/scenes/experiments/PerpetualMotionScene.h +++ b/apps/scenes/experiments/PerpetualMotionScene.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once diff --git a/apps/scenes/experiments/TransparentScene.cpp b/apps/scenes/experiments/TransparentScene.cpp index bef937a..2b29914 100644 --- a/apps/scenes/experiments/TransparentScene.cpp +++ b/apps/scenes/experiments/TransparentScene.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include "TransparentScene.h" @@ -31,18 +28,19 @@ TransparentScene::TransparentScene(const std::string& name) { } -TransparentScene::~TransparentScene(void) -{ -} +TransparentScene::~TransparentScene(void) {} void TransparentScene::doInitialize() { // Caustic material int caustic = 0; - m_gpuKernel->setMaterial(caustic, 1.f, 1.f, 0.f, 0.f, 0.f, 1.33f, false, false, 0, 0.8f, - m_gpuKernel->getSceneInfo().viewDistance, TEXTURE_NONE, TEXTURE_NONE, TEXTURE_NONE, - TEXTURE_NONE, TEXTURE_NONE, TEXTURE_NONE, TEXTURE_NONE, 0.f, 100.f, 0.f, 0.f, 10.f, - 10000.f, false); + m_gpuKernel->setMaterial(caustic, 1.f, 1.f, 0.f, 0.f, 0.f, 1.33f, false, + false, 0, 0.8f, + m_gpuKernel->getSceneInfo().viewDistance, + TEXTURE_NONE, TEXTURE_NONE, TEXTURE_NONE, + TEXTURE_NONE, TEXTURE_NONE, TEXTURE_NONE, + TEXTURE_NONE, 0.f, 100.f, 0.f, 0.f, 10.f, 10000.f, + false); vec3f center; center.x = 3000.f; @@ -80,7 +78,8 @@ void TransparentScene::doAddLights() if (m_gpuKernel->getNbActiveLamps() == 0) { m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, 8000.f, 8000.f, -8000.f, 500.f, 0.f, 0.f, DEFAULT_LIGHT_MATERIAL); + m_gpuKernel->setPrimitive(m_nbPrimitives, 8000.f, 8000.f, -8000.f, + 500.f, 0.f, 0.f, DEFAULT_LIGHT_MATERIAL); m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); } } diff --git a/apps/scenes/experiments/TransparentScene.h b/apps/scenes/experiments/TransparentScene.h index ba512a9..3703d91 100644 --- a/apps/scenes/experiments/TransparentScene.h +++ b/apps/scenes/experiments/TransparentScene.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once diff --git a/apps/scenes/experiments/XmasScene.cpp b/apps/scenes/experiments/XmasScene.cpp index eeadc55..7011f98 100644 --- a/apps/scenes/experiments/XmasScene.cpp +++ b/apps/scenes/experiments/XmasScene.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau - * - * This file is part of Sol-R +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include "XmasScene.h" @@ -32,9 +29,7 @@ XmasScene::XmasScene(const std::string& name) { } -XmasScene::~XmasScene(void) -{ -} +XmasScene::~XmasScene(void) {} /* ________________________________________________________________________________ @@ -42,7 +37,8 @@ ________________________________________________________________________________ Create tree ________________________________________________________________________________ */ -void XmasScene::createTree(int iteration, int boxId, int maxIterations, vec3f center, int material, float interval, +void XmasScene::createTree(int iteration, int boxId, int maxIterations, + vec3f center, int material, float interval, float radius) { if (iteration > 0) @@ -56,37 +52,46 @@ void XmasScene::createTree(int iteration, int boxId, int maxIterations, vec3f ce int box = (iteration < maxIterations) ? boxId : i; m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder); - m_gpuKernel->setPrimitive(m_nbPrimitives, a.x, a.y, a.z, b.x, b.y, b.z, radius / 2.f, 0.f, 0.f, material); + m_gpuKernel->setPrimitive(m_nbPrimitives, a.x, a.y, a.z, b.x, b.y, + b.z, radius / 2.f, 0.f, 0.f, material); - const vec4f angles = make_vec4f(((i == 0) ? 0.5f : 2.f) * (rand() % 100 / 100.f - 0.5f), + const vec4f angles = make_vec4f( + ((i == 0) ? 0.5f : 2.f) * (rand() % 100 / 100.f - 0.5f), ((i == 0) ? 0.5f : 2.f) * (rand() % 100 / 100.f - 0.5f), ((i == 0) ? 0.5f : 2.f) * (rand() % 100 / 100.f - 0.5f)); - const vec3f cosAngles = make_vec3f(cosf(angles.x), cosf(angles.y), cosf(angles.z)); - const vec3f sinAngles = make_vec3f(sinf(angles.x), sinf(angles.y), sinf(angles.z)); - solr::CPUPrimitive* p = m_gpuKernel->getPrimitive(m_nbPrimitives); + const vec3f cosAngles = + make_vec3f(cosf(angles.x), cosf(angles.y), cosf(angles.z)); + const vec3f sinAngles = + make_vec3f(sinf(angles.x), sinf(angles.y), sinf(angles.z)); + CPUPrimitive* p = m_gpuKernel->getPrimitive(m_nbPrimitives); m_gpuKernel->rotatePrimitive(*p, a, cosAngles, sinAngles); b.y += interval; m_gpuKernel->getPrimitiveOtherCenter(m_nbPrimitives, b); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, b.x, b.y, b.z, radius / 2.f, 0.f, 0.f, material); + m_gpuKernel->setPrimitive(m_nbPrimitives, b.x, b.y, b.z, + radius / 2.f, 0.f, 0.f, material); if (iteration == 1 && rand() % 3 == 0) { // Boule de noel m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder); - m_gpuKernel->setPrimitive(m_nbPrimitives, a.x, a.y, a.z, a.x, a.y - 300.f, a.z, 5, 0.f, 0.f, 1016); + m_gpuKernel->setPrimitive(m_nbPrimitives, a.x, a.y, a.z, a.x, + a.y - 300.f, a.z, 5, 0.f, 0.f, 1016); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, a.x, a.y - 400.f, a.z, 200, 0.f, 0.f, 1010 + rand() % 6); + m_gpuKernel->setPrimitive(m_nbPrimitives, a.x, a.y - 400.f, a.z, + 200, 0.f, 0.f, 1010 + rand() % 6); } if (iteration == 1 && rand() % 3 == 0) { // Leaves m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, b.x, b.y, b.z, 50.f + rand() % 500, 0.f, 0.f, 1002); + m_gpuKernel->setPrimitive(m_nbPrimitives, b.x, b.y, b.z, + 50.f + rand() % 500, 0.f, 0.f, 1002); } - createTree(iteration - 1, box, maxIterations, b, material, interval * (0.8f + rand() % iteration / 10.f), + createTree(iteration - 1, box, maxIterations, b, material, + interval * (0.8f + rand() % iteration / 10.f), radius * (0.4f + rand() % iteration / 10.f)); } } @@ -95,45 +100,54 @@ void XmasScene::createTree(int iteration, int boxId, int maxIterations, vec3f ce void XmasScene::doInitialize() { m_nbPrimitives = m_gpuKernel->addPrimitive(ptYZPlane); - m_gpuKernel->setPrimitive(m_nbPrimitives, -4200.f, 0.f, 0.f, 0.f, 2000.f, 200.f, 1000); + m_gpuKernel->setPrimitive(m_nbPrimitives, -4200.f, 0.f, 0.f, 0.f, 2000.f, + 200.f, 1000); m_nbPrimitives = m_gpuKernel->addPrimitive(ptXYPlane); - m_gpuKernel->setPrimitive(m_nbPrimitives, -4100.f, 0.f, 200.f, 100.f, 2000.f, 0.f, 1000); + m_gpuKernel->setPrimitive(m_nbPrimitives, -4100.f, 0.f, 200.f, 100.f, + 2000.f, 0.f, 1000); m_nbPrimitives = m_gpuKernel->addPrimitive(ptXYPlane); - m_gpuKernel->setPrimitive(m_nbPrimitives, -4100.f, 0.f, -200.f, 100.f, 2000.f, 0.f, 1000); + m_gpuKernel->setPrimitive(m_nbPrimitives, -4100.f, 0.f, -200.f, 100.f, + 2000.f, 0.f, 1000); m_nbPrimitives = m_gpuKernel->addPrimitive(ptXZPlane); - m_gpuKernel->setPrimitive(m_nbPrimitives, -4100.f, 2000.f, 0.f, 100.f, 0.f, 200.f, 1000); + m_gpuKernel->setPrimitive(m_nbPrimitives, -4100.f, 2000.f, 0.f, 100.f, 0.f, + 200.f, 1000); m_nbPrimitives = m_gpuKernel->addPrimitive(ptYZPlane); - m_gpuKernel->setPrimitive(m_nbPrimitives, 4200.f, 0.f, 0.f, 0.f, 2000.f, 200.f, 1000); + m_gpuKernel->setPrimitive(m_nbPrimitives, 4200.f, 0.f, 0.f, 0.f, 2000.f, + 200.f, 1000); m_nbPrimitives = m_gpuKernel->addPrimitive(ptXYPlane); - m_gpuKernel->setPrimitive(m_nbPrimitives, 4100.f, 0.f, 200.f, 100.f, 2000.f, 0.f, 1000); + m_gpuKernel->setPrimitive(m_nbPrimitives, 4100.f, 0.f, 200.f, 100.f, 2000.f, + 0.f, 1000); m_nbPrimitives = m_gpuKernel->addPrimitive(ptXYPlane); - m_gpuKernel->setPrimitive(m_nbPrimitives, 4100.f, 0.f, -200.f, 100.f, 2000.f, 0.f, 1000); + m_gpuKernel->setPrimitive(m_nbPrimitives, 4100.f, 0.f, -200.f, 100.f, + 2000.f, 0.f, 1000); m_nbPrimitives = m_gpuKernel->addPrimitive(ptXZPlane); - m_gpuKernel->setPrimitive(m_nbPrimitives, 4100.f, 2000.f, 0.f, 100.f, 0.f, 200.f, 1000); + m_gpuKernel->setPrimitive(m_nbPrimitives, 4100.f, 2000.f, 0.f, 100.f, 0.f, + 200.f, 1000); int material = 1001; // Tree m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder); - m_gpuKernel->setPrimitive(m_nbPrimitives, 0.f, m_groundHeight, 0.f, 0.f, -1000.f, 0.f, 250.f, 0.f, 0.f, material); + m_gpuKernel->setPrimitive(m_nbPrimitives, 0.f, m_groundHeight, 0.f, 0.f, + -1000.f, 0.f, 250.f, 0.f, 0.f, material); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, 0.f, -1000.f, 0.f, 250.f, 0.f, 0.f, material); + m_gpuKernel->setPrimitive(m_nbPrimitives, 0.f, -1000.f, 0.f, 250.f, 0.f, + 0.f, material); int nbIterations = 2 + rand() % 3; vec3f center = make_vec3f(0.f, -1000.f, 0.f); createTree(nbIterations, 10, nbIterations, center, material, 1000.f, //+rand()%800, 200.f //+rand()%300 - ); + ); } -void XmasScene::doAnimate() -{ -} +void XmasScene::doAnimate() {} void XmasScene::doAddLights() { // lights m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, -4000.f, 0.f, 0.f, 0.f, 2000.f, 200.f, DEFAULT_LIGHT_MATERIAL); + m_gpuKernel->setPrimitive(m_nbPrimitives, -4000.f, 0.f, 0.f, 0.f, 2000.f, + 200.f, DEFAULT_LIGHT_MATERIAL); } diff --git a/apps/scenes/experiments/XmasScene.h b/apps/scenes/experiments/XmasScene.h index 0b7e054..09ee7e0 100644 --- a/apps/scenes/experiments/XmasScene.h +++ b/apps/scenes/experiments/XmasScene.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once @@ -34,6 +31,6 @@ class XmasScene : public Scene virtual void doAddLights(); private: - void createTree(int iteration, int boxId, int maxIterations, vec3f center, int material, float interval, - float radius); + void createTree(int iteration, int boxId, int maxIterations, vec3f center, + int material, float interval, float radius); }; diff --git a/apps/scenes/experiments/Year2013.cpp b/apps/scenes/experiments/Year2013.cpp index 6b29c97..7e980df 100644 --- a/apps/scenes/experiments/Year2013.cpp +++ b/apps/scenes/experiments/Year2013.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include "Year2013.h" @@ -31,9 +28,7 @@ Year2013::Year2013(const std::string& name) { } -Year2013::~Year2013(void) -{ -} +Year2013::~Year2013(void) {} void Year2013::doInitialize() { @@ -70,16 +65,17 @@ void Year2013::doInitialize() */ // CERN - int g2013[10][23] = {{0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1}, - {1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1}, - {1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1}, - {1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1}, - {1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1}, - {1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1}, - {0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1}, - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 0, 2, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 2, 0, 0}, - {0, 0, 3, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 3, 0, 0}}; + int g2013[10][23] = { + {0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1}, + {1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1}, + {1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1}, + {1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1}, + {1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1}, + {1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1}, + {0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 2, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 2, 0, 0}, + {0, 0, 3, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 3, 0, 0}}; float size = 250.f; float X = -(15.f * size); @@ -95,22 +91,26 @@ void Year2013::doInitialize() case 1: { m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, X + x * S, Y - y * S, 0.f, size * 1.2f, 0.f, 0.f, + m_gpuKernel->setPrimitive(m_nbPrimitives, X + x * S, Y - y * S, + 0.f, size * 1.2f, 0.f, 0.f, 1030 + (x / 6) * 5); break; } case 2: { m_nbPrimitives = m_gpuKernel->addPrimitive(ptEllipsoid); - m_gpuKernel->setPrimitive(m_nbPrimitives, X + x * S, Y - y * S, 0.f, size * 4.f, size, size * 4.f, + m_gpuKernel->setPrimitive(m_nbPrimitives, X + x * S, Y - y * S, + 0.f, size * 4.f, size, size * 4.f, 1040); break; } case 3: { m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder); - m_gpuKernel->setPrimitive(m_nbPrimitives, X + x * S, Y - (y + 3) * S, 0.f, X + x * S, Y - (y - 1) * S, - 0.f, size * 4.f, 0.f, 0.f, 1040); + m_gpuKernel->setPrimitive(m_nbPrimitives, X + x * S, + Y - (y + 3) * S, 0.f, X + x * S, + Y - (y - 1) * S, 0.f, size * 4.f, 0.f, + 0.f, 1040); break; } } @@ -134,14 +134,13 @@ void Year2013::doInitialize() m_gpuKernel->getSceneInfo().nbRayIterations = 20; } -void Year2013::doAnimate() -{ -} +void Year2013::doAnimate() {} void Year2013::doAddLights() { // lights float size = 50.f; m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, 5000.f, 5000.f, -5000.f, size, size * 2.f, 0.f, DEFAULT_LIGHT_MATERIAL); + m_gpuKernel->setPrimitive(m_nbPrimitives, 5000.f, 5000.f, -5000.f, size, + size * 2.f, 0.f, DEFAULT_LIGHT_MATERIAL); } diff --git a/apps/scenes/experiments/Year2013.h b/apps/scenes/experiments/Year2013.h index 42d4b64..86dda3f 100644 --- a/apps/scenes/experiments/Year2013.h +++ b/apps/scenes/experiments/Year2013.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once diff --git a/apps/scenes/games/SpindizzyScene.cpp b/apps/scenes/games/SpindizzyScene.cpp index 2990d38..0e20bc0 100644 --- a/apps/scenes/games/SpindizzyScene.cpp +++ b/apps/scenes/games/SpindizzyScene.cpp @@ -1,37 +1,30 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include "SpindizzyScene.h" #include -using namespace solr; - SpindizzyScene::SpindizzyScene(const std::string& name) : Scene(name) { } -SpindizzyScene::~SpindizzyScene(void) -{ -} +SpindizzyScene::~SpindizzyScene(void) {} void SpindizzyScene::doInitialize() { @@ -107,11 +100,14 @@ void SpindizzyScene::doAnimate() void SpindizzyScene::doAddLights() { // lights - m_gpuKernel->setMaterial(129, 1.f, 1.f, 1.f, 0.f, 0.f, 0.f, false, false, 0, 0.f, - m_gpuKernel->getSceneInfo().viewDistance, TEXTURE_NONE, TEXTURE_NONE, TEXTURE_NONE, - TEXTURE_NONE, TEXTURE_NONE, TEXTURE_NONE, TEXTURE_NONE, 1.f, 100.f, 0.f, 1.0f, 50.f, + m_gpuKernel->setMaterial(129, 1.f, 1.f, 1.f, 0.f, 0.f, 0.f, false, false, 0, + 0.f, m_gpuKernel->getSceneInfo().viewDistance, + TEXTURE_NONE, TEXTURE_NONE, TEXTURE_NONE, + TEXTURE_NONE, TEXTURE_NONE, TEXTURE_NONE, + TEXTURE_NONE, 1.f, 100.f, 0.f, 1.0f, 50.f, m_gpuKernel->getSceneInfo().viewDistance, false); m_nbPrimitives = m_gpuKernel->addPrimitive(ptXZPlane); - m_gpuKernel->setPrimitive(m_nbPrimitives, -10000.f, 10000.f - m_groundHeight, -10000.f, 500.f, 0.f, 500.f * 4.f, - DEFAULT_LIGHT_MATERIAL); + m_gpuKernel->setPrimitive(m_nbPrimitives, -10000.f, + 10000.f - m_groundHeight, -10000.f, 500.f, 0.f, + 500.f * 4.f, DEFAULT_LIGHT_MATERIAL); } diff --git a/apps/scenes/games/SpindizzyScene.h b/apps/scenes/games/SpindizzyScene.h index 36aa555..c5ff946 100644 --- a/apps/scenes/games/SpindizzyScene.h +++ b/apps/scenes/games/SpindizzyScene.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once diff --git a/apps/scenes/maths/FractalScene.cpp b/apps/scenes/maths/FractalScene.cpp index c731218..376f6bd 100644 --- a/apps/scenes/maths/FractalScene.cpp +++ b/apps/scenes/maths/FractalScene.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau - * - * This file is part of Sol-R +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include "FractalScene.h" @@ -34,9 +31,7 @@ FractalScene::FractalScene(const std::string& name) { } -FractalScene::~FractalScene(void) -{ -} +FractalScene::~FractalScene(void) {} /* ________________________________________________________________________________ @@ -44,59 +39,40 @@ ________________________________________________________________________________ Create simple fractal scene ________________________________________________________________________________ */ -void FractalScene::createFractals(int iteration, int modelId, int mode, int maxIterations, vec4f center, int material, +void FractalScene::createFractals(int iteration, int modelId, int mode, + int maxIterations, vec4f center, int material, float interval, float radius) { - vec4f positions[NB_MODELS][NB_ELEMENTS] = - { - {make_vec4f(-1.f, -1.f, -1.f, 0.f), - make_vec4f(1.f, -1.f, -1.f, 0.f), - make_vec4f(0.f, -1.f, 1.f, 0.f), - make_vec4f(0.f, 1.f, 0.f, 0.f), - make_vec4f(0.f, 0.f, -1.f, 0.f), - make_vec4f(0.f, -1.f, 0.f, 0.f), - make_vec4f(0.f, 0.f, 0.f, 0.f), - make_vec4f(0.f, 0.f, 0.f, 0.f)}, - {make_vec4f(-1.f, -1.f, 1.f, 0.f), - make_vec4f(1.f, -1.f, 1.f, 0.f), - make_vec4f(-1.f, 1.f, 1.f, 0.f), - make_vec4f(1.f, 1.f, 1.f, 0.f), - make_vec4f(0.f, 0.f, 0.f, 0.f), - make_vec4f(0.f, 0.f, 0.f, 0.f), - make_vec4f(0.f, 0.f, 0.f, 0.f), - make_vec4f(0.f, 0.f, 0.f, 0.f)}, + vec4f positions[NB_MODELS][NB_ELEMENTS] = { + {make_vec4f(-1.f, -1.f, -1.f, 0.f), make_vec4f(1.f, -1.f, -1.f, 0.f), + make_vec4f(0.f, -1.f, 1.f, 0.f), make_vec4f(0.f, 1.f, 0.f, 0.f), + make_vec4f(0.f, 0.f, -1.f, 0.f), make_vec4f(0.f, -1.f, 0.f, 0.f), + make_vec4f(0.f, 0.f, 0.f, 0.f), make_vec4f(0.f, 0.f, 0.f, 0.f)}, + {make_vec4f(-1.f, -1.f, 1.f, 0.f), make_vec4f(1.f, -1.f, 1.f, 0.f), + make_vec4f(-1.f, 1.f, 1.f, 0.f), make_vec4f(1.f, 1.f, 1.f, 0.f), + make_vec4f(0.f, 0.f, 0.f, 0.f), make_vec4f(0.f, 0.f, 0.f, 0.f), + make_vec4f(0.f, 0.f, 0.f, 0.f), make_vec4f(0.f, 0.f, 0.f, 0.f)}, {// Cube - make_vec4f(-1.f, -1.f, -1.f, 0.f), - make_vec4f(1.f, -1.f, -1.f, 0.f), - make_vec4f(-1.f, 1.f, -1.f, 0.f), - make_vec4f(1.f, 1.f, -1.f, 0.f), - make_vec4f(-1.f, -1.f, 1.f, 0.f), - make_vec4f(1.f, -1.f, 1.f, 0.f), - make_vec4f(-1.f, 1.f, 1.f, 0.f), - make_vec4f(1.f, 1.f, 1.f, 0.f)}, - {make_vec4f(1.f, 0.f, 0.f, 0.f), - make_vec4f(0.f, 0.f, 1.f, 0.f), - make_vec4f(0.f, 2.f, 0.f, 0.f), - make_vec4f(-1.f, 0.f, 0.f, 0.f), - make_vec4f(0.f, 0.f, -1.f, 0.f), - make_vec4f(0.f, -1.f, 0.f, 0.f), - make_vec4f(0.f, 0.f, 0.f, 0.f), - make_vec4f(0.f, 0.f, 0.f, 0.f)}, - {make_vec4f(1.f, 1.f, 0.f, 0.f), - make_vec4f(-1.f, 1.f, 0.f, 0.f), - make_vec4f(1.f, -1.f, 0.f, 0.f), - make_vec4f(-1.f, -1.f, 0.f, 0.f), - make_vec4f(0.f, 0.f, -1.f, 0.f), - make_vec4f(0.f, 0.f, 1.f, 0.f), - make_vec4f(0.f, 0.f, 0.f, 0.f), - make_vec4f(0.f, 0.f, 0.f, 0.f)} - }; + make_vec4f(-1.f, -1.f, -1.f, 0.f), make_vec4f(1.f, -1.f, -1.f, 0.f), + make_vec4f(-1.f, 1.f, -1.f, 0.f), make_vec4f(1.f, 1.f, -1.f, 0.f), + make_vec4f(-1.f, -1.f, 1.f, 0.f), make_vec4f(1.f, -1.f, 1.f, 0.f), + make_vec4f(-1.f, 1.f, 1.f, 0.f), make_vec4f(1.f, 1.f, 1.f, 0.f)}, + {make_vec4f(1.f, 0.f, 0.f, 0.f), make_vec4f(0.f, 0.f, 1.f, 0.f), + make_vec4f(0.f, 2.f, 0.f, 0.f), make_vec4f(-1.f, 0.f, 0.f, 0.f), + make_vec4f(0.f, 0.f, -1.f, 0.f), make_vec4f(0.f, -1.f, 0.f, 0.f), + make_vec4f(0.f, 0.f, 0.f, 0.f), make_vec4f(0.f, 0.f, 0.f, 0.f)}, + {make_vec4f(1.f, 1.f, 0.f, 0.f), make_vec4f(-1.f, 1.f, 0.f, 0.f), + make_vec4f(1.f, -1.f, 0.f, 0.f), make_vec4f(-1.f, -1.f, 0.f, 0.f), + make_vec4f(0.f, 0.f, -1.f, 0.f), make_vec4f(0.f, 0.f, 1.f, 0.f), + make_vec4f(0.f, 0.f, 0.f, 0.f), make_vec4f(0.f, 0.f, 0.f, 0.f)}}; if (iteration > 0) { for (int i(0); i < NB_ELEMENTS; i++) { - if (positions[modelId][i].x != 0.f || positions[modelId][i].y != 0.f || positions[modelId][i].z != 0.f) + if (positions[modelId][i].x != 0.f || + positions[modelId][i].y != 0.f || + positions[modelId][i].z != 0.f) { vec4f c = make_vec4f(0.f, 0.f, 0.f, 0.f); c.x = center.x + positions[modelId][i].x * center.w * interval; @@ -113,17 +89,22 @@ void FractalScene::createFractals(int iteration, int modelId, int mode, int maxI case 0: { m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, c.x, c.y, c.z, (iteration == 1) ? c.w / 2.f : c.w, - (iteration == 2) ? c.w / 2.f : c.w, (iteration == 3) ? c.w / 2.f : c.w, - 1000 + iteration); - m_gpuKernel->setPrimitiveTextureCoordinates(m_nbPrimitives, vt0, vt1, vt2); - m_gpuKernel->setPrimitiveBellongsToModel(m_nbPrimitives, true); + m_gpuKernel->setPrimitive( + m_nbPrimitives, c.x, c.y, c.z, + (iteration == 1) ? c.w / 2.f : c.w, + (iteration == 2) ? c.w / 2.f : c.w, + (iteration == 3) ? c.w / 2.f : c.w, 1000 + iteration); + m_gpuKernel->setPrimitiveTextureCoordinates(m_nbPrimitives, + vt0, vt1, vt2); + m_gpuKernel->setPrimitiveBellongsToModel(m_nbPrimitives, + true); } break; case 1: { - m_gpuKernel->addCube(c.x, c.y, c.z, (iteration == 1) ? c.w / 2.f : c.w, - 1000 + ((maxIterations - iteration) * 10 /*+i*/) % 50); + m_gpuKernel->addCube( + c.x, c.y, c.z, (iteration == 1) ? c.w / 2.f : c.w, + 1000 + ((maxIterations - iteration) * 10 /*+i*/) % 50); } break; default: @@ -131,23 +112,31 @@ void FractalScene::createFractals(int iteration, int modelId, int mode, int maxI if (iteration % 2 == 1) { m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, c.x, c.y, c.z, (iteration == 1) ? c.w / 2.f : c.w, - (iteration == 2) ? c.w / 2.f : c.w, - (iteration == 3) ? c.w / 2.f : c.w, - 1000 + ((maxIterations - iteration) * 10 /*+i*/) % 50); - m_gpuKernel->setPrimitiveTextureCoordinates(m_nbPrimitives, vt0, vt1, vt2); - m_gpuKernel->setPrimitiveBellongsToModel(m_nbPrimitives, true); + m_gpuKernel->setPrimitive( + m_nbPrimitives, c.x, c.y, c.z, + (iteration == 1) ? c.w / 2.f : c.w, + (iteration == 2) ? c.w / 2.f : c.w, + (iteration == 3) ? c.w / 2.f : c.w, + 1000 + + ((maxIterations - iteration) * 10 /*+i*/) % 50); + m_gpuKernel->setPrimitiveTextureCoordinates( + m_nbPrimitives, vt0, vt1, vt2); + m_gpuKernel->setPrimitiveBellongsToModel(m_nbPrimitives, + true); } else { - m_gpuKernel->addCube(c.x, c.y, c.z, (iteration == 1) ? c.w / 2.f : c.w, - 1000 + ((maxIterations - iteration) * 10 /*+i*/) % 50); + m_gpuKernel->addCube( + c.x, c.y, c.z, (iteration == 1) ? c.w / 2.f : c.w, + 1000 + + ((maxIterations - iteration) * 10 /*+i*/) % 50); } } break; } - createFractals(iteration - 1, modelId, mode, maxIterations, c, material, interval, radius); + createFractals(iteration - 1, modelId, mode, maxIterations, c, + material, interval, radius); } } } @@ -158,8 +147,9 @@ void FractalScene::doInitialize() m_groundHeight = -5000.f; int nbIterations = 2 + rand() % 3; vec4f center = make_vec4f(0.f, 0.f, 0.f, 2000.f); - createFractals(nbIterations, rand() % NB_MODELS, rand() % 1, nbIterations, center, 1000 + rand() % 30, - 1.0f + rand() % 500 / 1000.f, 0.5f + rand() % 200 / 1000.f); + createFractals(nbIterations, rand() % NB_MODELS, rand() % 1, nbIterations, + center, 1000 + rand() % 30, 1.0f + rand() % 500 / 1000.f, + 0.5f + rand() % 200 / 1000.f); } void FractalScene::doAnimate() @@ -176,10 +166,7 @@ void FractalScene::doAddLights() { // lights m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, -15000.f, 15000.f, -15000.f, 10.f, 0.f, 0.f, DEFAULT_LIGHT_MATERIAL); + m_gpuKernel->setPrimitive(m_nbPrimitives, -15000.f, 15000.f, -15000.f, 10.f, + 0.f, 0.f, DEFAULT_LIGHT_MATERIAL); m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); - // m_nbPrimitives = m_gpuKernel->addPrimitive( ptSphere ); m_gpuKernel->setPrimitive( m_nbPrimitives, 15000.f, - // 15000.f, 15000.f, 10.f, 0.f, 0.f, 121); - // m_nbPrimitives = m_gpuKernel->addPrimitive( ptSphere ); m_gpuKernel->setPrimitive( m_nbPrimitives, 0.f, 15000.f, - // -15000.f, 10.f, 0.f, 0.f, 122); } diff --git a/apps/scenes/maths/FractalScene.h b/apps/scenes/maths/FractalScene.h index ef449bd..f0cc28d 100644 --- a/apps/scenes/maths/FractalScene.h +++ b/apps/scenes/maths/FractalScene.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once @@ -34,6 +31,7 @@ class FractalScene : public Scene virtual void doAddLights(); private: - void createFractals(int iteration, int modelId, int mode, int maxIterations, vec4f center, int material, - float interval, float radius); + void createFractals(int iteration, int modelId, int mode, int maxIterations, + vec4f center, int material, float interval, + float radius); }; diff --git a/apps/scenes/maths/FractalsScene.cpp b/apps/scenes/maths/FractalsScene.cpp index 11f4087..436c2bc 100644 --- a/apps/scenes/maths/FractalsScene.cpp +++ b/apps/scenes/maths/FractalsScene.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau - * - * This file is part of Sol-R +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include "FractalsScene.h" @@ -33,9 +30,7 @@ FractalsScene::FractalsScene(const std::string& name) { } -FractalsScene::~FractalsScene(void) -{ -} +FractalsScene::~FractalsScene(void) {} /* ________________________________________________________________________________ @@ -43,7 +38,8 @@ ________________________________________________________________________________ Create simple fractal scene ________________________________________________________________________________ */ -void FractalsScene::createFractals(float maxIterations, const vec4f& center, int material) +void FractalsScene::createFractals(float maxIterations, const vec4f& center, + int material) { SceneInfo& sceneInfo = m_gpuKernel->getSceneInfo(); float W = (float)sceneInfo.size.x; @@ -83,24 +79,29 @@ void FractalsScene::createFractals(float maxIterations, const vec4f& center, int if (n > 5) { m_nbPrimitives = m_gpuKernel->addPrimitive(ptTriangle); - m_gpuKernel->setPrimitive(m_nbPrimitives, (x - 250.f) * center.w, (y - 250.f) * center.w, 0.f, - (x + step - 250.f) * center.w, (y - 250.f) * center.w, 0.f, - (x + step - 250.f) * center.w, (y + step - 250.f) * center.w, 0.f, - 10.f * center.w, 0.f, 0.f, material + (n % 40)); + m_gpuKernel->setPrimitive( + m_nbPrimitives, (x - 250.f) * center.w, + (y - 250.f) * center.w, 0.f, (x + step - 250.f) * center.w, + (y - 250.f) * center.w, 0.f, (x + step - 250.f) * center.w, + (y + step - 250.f) * center.w, 0.f, 10.f * center.w, 0.f, + 0.f, material + (n % 40)); m_gpuKernel->setPrimitiveBellongsToModel(m_nbPrimitives, true); m_nbPrimitives = m_gpuKernel->addPrimitive(ptTriangle); - m_gpuKernel->setPrimitive(m_nbPrimitives, (x + step - 250.f) * center.w, (y + step - 250.f) * center.w, - 0.f, (x - 250.f) * center.w, (y + step - 250.f) * center.w, 0.f, - (x - 250.f) * center.w, (y - 250.f) * center.w, 0.f, 10.f * center.w, 0.f, - 0.f, material + (n % 40)); + m_gpuKernel->setPrimitive( + m_nbPrimitives, (x + step - 250.f) * center.w, + (y + step - 250.f) * center.w, 0.f, (x - 250.f) * center.w, + (y + step - 250.f) * center.w, 0.f, (x - 250.f) * center.w, + (y - 250.f) * center.w, 0.f, 10.f * center.w, 0.f, 0.f, + material + (n % 40)); m_gpuKernel->setPrimitiveBellongsToModel(m_nbPrimitives, true); } } } } -vec4f FractalsScene::MandelBox(vec3f V, const vec3f& Scale, float R, float S, float C) +vec4f FractalsScene::MandelBox(vec3f V, const vec3f& Scale, float R, float S, + float C) { V.x /= Scale.x; V.y /= Scale.y; @@ -154,7 +155,8 @@ vec4f FractalsScene::MandelBox(vec3f V, const vec3f& Scale, float R, float S, fl { int div = maxiter / 5; m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, V.x, V.y, V.z, Scale.x, Scale.y, Scale.z, 1000 + div); + m_gpuKernel->setPrimitive(m_nbPrimitives, V.x, V.y, V.z, Scale.x, + Scale.y, Scale.z, 1000 + div); m_gpuKernel->setPrimitiveBellongsToModel(m_nbPrimitives, true); } return color; @@ -201,31 +203,40 @@ float FractalsScene::DE(vec3f pos, const int iterations, const vec2f params) if (!add) { m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, pos.x, pos.y, pos.z, 0.01f * log(r) * r / dr, 0.f, 0.f, 40); + m_gpuKernel->setPrimitive(m_nbPrimitives, pos.x, pos.y, pos.z, + 0.01f * log(r) * r / dr, 0.f, 0.f, 40); m_gpuKernel->setPrimitiveBellongsToModel(m_nbPrimitives, true); } return 0.f; } /** - * Decides if a point at a specific location is filled or not. This works by iteration first checking if - * the pixel is unfilled in successively larger squares or cannot be in the center of any larger square. - * @param x is the x coordinate of the point being checked with zero being the first pixel - * @param y is the y coordinate of the point being checked with zero being the first pixel + * Decides if a point at a specific location is filled or not. This works by + * iteration first checking if the pixel is unfilled in successively larger + * squares or cannot be in the center of any larger square. + * @param x is the x coordinate of the point being checked with zero being the + * first pixel + * @param y is the y coordinate of the point being checked with zero being the + * first pixel * @return 1 if it is to be filled or 0 if it is open */ bool FractalsScene::isSierpinskiCarpetPixelFilled(int i, vec3i v) { - while (v.x > 0 || v.y > 0 || v.z > 0) // when either of these reaches zero the pixel is determined to be on the edge + while (v.x > 0 || v.y > 0 || + v.z > 0) // when either of these reaches zero the pixel is determined + // to be on the edge { if (v.x % i == 1 && v.y % i == 1 && - v.z % i == 1) // checks if the pixel is in the center for the current square level + v.z % i == 1) // checks if the pixel is in the center for the + // current square level return false; - v.x /= i; // x and y are decremented to check the next larger square level + v.x /= + i; // x and y are decremented to check the next larger square level v.y /= i; v.z /= i; } - return true; // if all possible square levels are checked and the pixel is not determined + return true; // if all possible square levels are checked and the pixel is + // not determined // to be open it must be filled } @@ -244,8 +255,11 @@ void FractalsScene::doInitialize() { vec3i v = make_vec3i(x, y, z); if (!isSierpinskiCarpetPixelFilled(nbIterations, v)) - m_nbPrimitives = m_gpuKernel->addCube((x - size / 2.f) * radius, (y - size / 2.f) * radius, - (z - size / 2.f) * radius, step * radius, 39); + m_nbPrimitives = + m_gpuKernel->addCube((x - size / 2.f) * radius, + (y - size / 2.f) * radius, + (z - size / 2.f) * radius, + step * radius, 39); } } @@ -260,5 +274,6 @@ void FractalsScene::doAddLights() { // lights m_nbPrimitives = m_gpuKernel->addPrimitive(ptXZPlane); - m_gpuKernel->setPrimitive(m_nbPrimitives, 0.f, 5000.f, 0.f, 500.f, 0.f, 500.f, DEFAULT_LIGHT_MATERIAL); + m_gpuKernel->setPrimitive(m_nbPrimitives, 0.f, 5000.f, 0.f, 500.f, 0.f, + 500.f, DEFAULT_LIGHT_MATERIAL); } diff --git a/apps/scenes/maths/FractalsScene.h b/apps/scenes/maths/FractalsScene.h index 74ce6f1..2ac47b1 100644 --- a/apps/scenes/maths/FractalsScene.h +++ b/apps/scenes/maths/FractalsScene.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once diff --git a/apps/scenes/maths/TrefoilKnotScene.cpp b/apps/scenes/maths/TrefoilKnotScene.cpp index dbb8f53..eb3b5d8 100644 --- a/apps/scenes/maths/TrefoilKnotScene.cpp +++ b/apps/scenes/maths/TrefoilKnotScene.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include "TrefoilKnotScene.h" @@ -33,9 +30,7 @@ TrefoilKnotScene::TrefoilKnotScene(const std::string& name) { } -TrefoilKnotScene::~TrefoilKnotScene(void) -{ -} +TrefoilKnotScene::~TrefoilKnotScene(void) {} void TrefoilKnotScene::trefoilKnot(float R, float t, vec4f& p) { @@ -68,7 +63,8 @@ void TrefoilKnotScene::spring(float R, float t, vec4f& p) void TrefoilKnotScene::heart(float R, float u, float v, vec4f& p) { p.x = R * 4.f * pow(sin(u), 3.f); - p.y = R * 0.25f * (13 * cos(u) - 5 * cos(2.f * u) - 2.f * cos(3.f * u) - cos(4.f * u)); + p.y = R * 0.25f * + (13 * cos(u) - 5 * cos(2.f * u) - 2.f * cos(3.f * u) - cos(4.f * u)); p.z = 0.f; } @@ -79,7 +75,8 @@ void TrefoilKnotScene::thing(float R, float t, vec4f a, vec4f& p) p.z = R * (-sin(a.z * t)); } -void TrefoilKnotScene::moebius(float R, float u, float v, float s, float du, float dv, vec4f& p) +void TrefoilKnotScene::moebius(float R, float u, float v, float s, float du, + float dv, vec4f& p) { p.x = 4.f * R * (cos(u) + v * cos(u / 2) * cos(u)); p.y = 4.f * R * (sin(u) + v * cos(u / 2) * sin(u)); @@ -96,7 +93,8 @@ void TrefoilKnotScene::doInitialize() const float R = 500.f; const float r = 50.f + rand() % 800; const int geometry = rand() % 10; - const vec4f a = make_vec4f(1.f + rand() % 4, 1.f + rand() % 4, 1.f + rand() % 4, 1.f + rand() % 4); + const vec4f a = make_vec4f(1.f + rand() % 4, 1.f + rand() % 4, + 1.f + rand() % 4, 1.f + rand() % 4); const float s = 1.f; vec4f U, V; @@ -216,17 +214,21 @@ void TrefoilKnotScene::doInitialize() break; } m_nbPrimitives = m_gpuKernel->addPrimitive(ptCylinder); - m_gpuKernel->setPrimitive(m_nbPrimitives, p0.x, p0.y, p0.z, p1.x, p1.y, p1.z, r, 0.f, 0.f, material + M); + m_gpuKernel->setPrimitive(m_nbPrimitives, p0.x, p0.y, p0.z, p1.x, + p1.y, p1.z, r, 0.f, 0.f, material + M); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, p1.x, p1.y, p1.z, r, 0.f, 0.f, material + M); + m_gpuKernel->setPrimitive(m_nbPrimitives, p1.x, p1.y, p1.z, r, 0.f, + 0.f, material + M); ++element; } } m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, -4000.f, -1000.f, 1000.f, 1500.f, 0.f, 0.f, 114); + m_gpuKernel->setPrimitive(m_nbPrimitives, -4000.f, -1000.f, 1000.f, 1500.f, + 0.f, 0.f, 114); m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, 4000.f, -1000.f, 1000.f, 1500.f, 0.f, 0.f, 113); + m_gpuKernel->setPrimitive(m_nbPrimitives, 4000.f, -1000.f, 1000.f, 1500.f, + 0.f, 0.f, 113); m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); m_gpuKernel->getSceneInfo().nbRayIterations = 20; } @@ -241,5 +243,6 @@ void TrefoilKnotScene::doAnimate() void TrefoilKnotScene::doAddLights() { m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, 0.f, 5000.f, 0.f, 50.f, 0.f, 0.f, DEFAULT_LIGHT_MATERIAL); + m_gpuKernel->setPrimitive(m_nbPrimitives, 0.f, 5000.f, 0.f, 50.f, 0.f, 0.f, + DEFAULT_LIGHT_MATERIAL); } diff --git a/apps/scenes/maths/TrefoilKnotScene.h b/apps/scenes/maths/TrefoilKnotScene.h index 4274758..cc70604 100644 --- a/apps/scenes/maths/TrefoilKnotScene.h +++ b/apps/scenes/maths/TrefoilKnotScene.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once @@ -40,5 +37,6 @@ class TrefoilKnotScene : public Scene void spring(float R, float t, vec4f& p); void heart(float R, float u, float v, vec4f& p); void thing(float R, float t, vec4f a, vec4f& p); - void moebius(float R, float u, float v, float s, float du, float dv, vec4f& p); + void moebius(float R, float u, float v, float s, float du, float dv, + vec4f& p); }; diff --git a/apps/scenes/meshes/ObjScene.cpp b/apps/scenes/meshes/ObjScene.cpp index c7b936a..747a94c 100644 --- a/apps/scenes/meshes/ObjScene.cpp +++ b/apps/scenes/meshes/ObjScene.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include "ObjScene.h" @@ -35,9 +32,7 @@ ObjScene::ObjScene(const std::string& name, const std::string& filename) m_groundHeight = -2500.f; } -ObjScene::~ObjScene(void) -{ -} +ObjScene::~ObjScene(void) {} void ObjScene::doInitialize() { @@ -49,7 +44,7 @@ void ObjScene::doInitialize() // Scene Bounding Box SceneInfo& sceneInfo = m_gpuKernel->getSceneInfo(); - solr::CPUBoundingBox AABB; + CPUBoundingBox AABB; AABB.parameters[0].x = sceneInfo.viewDistance; AABB.parameters[0].y = sceneInfo.viewDistance; AABB.parameters[0].z = sceneInfo.viewDistance; @@ -60,40 +55,44 @@ void ObjScene::doInitialize() if (m_filename.length() != 0) { LOG_INFO(1, "Loading " << m_filename); - solr::OBJReader objectReader; - solr::CPUBoundingBox aabb; - solr::CPUBoundingBox inAABB; - memset(&inAABB, 0, sizeof(solr::CPUBoundingBox)); - vec4f size = objectReader.loadModelFromFile(m_filename, *m_gpuKernel, objectPosition, true, m_objectScale, true, - RANDOM_MATERIALS_OFFSET, false, true, aabb, false, inAABB); + OBJReader objectReader; + CPUBoundingBox aabb; + CPUBoundingBox inAABB; + memset(&inAABB, 0, sizeof(CPUBoundingBox)); + vec4f size = + objectReader.loadModelFromFile(m_filename, *m_gpuKernel, + objectPosition, true, m_objectScale, + true, RANDOM_MATERIALS_OFFSET, false, + true, aabb, false, inAABB); m_groundHeight = -size.y / 2.f - sceneInfo.geometryEpsilon; } else { Strings extensions; extensions.push_back(".obj"); - const Strings fileNames = getFilesFromFolder(std::string(DEFAULT_MEDIA_FOLDER) + "/obj", extensions); + const Strings fileNames = + getFilesFromFolder(std::string(DEFAULT_MEDIA_FOLDER) + "/obj", + extensions); if (!fileNames.empty()) { m_filename = fileNames[m_currentModel % fileNames.size()]; - solr::OBJReader objectReader; - solr::CPUBoundingBox aabb; - solr::CPUBoundingBox inAABB; - memset(&inAABB, 0, sizeof(solr::CPUBoundingBox)); - vec4f size = objectReader.loadModelFromFile(m_filename, *m_gpuKernel, objectPosition, true, m_objectScale, - true, 1000, false, true, aabb, false, inAABB); + OBJReader objectReader; + CPUBoundingBox aabb; + CPUBoundingBox inAABB; + memset(&inAABB, 0, sizeof(CPUBoundingBox)); + vec4f size = + objectReader.loadModelFromFile(m_filename, *m_gpuKernel, + objectPosition, true, + m_objectScale, true, 1000, false, + true, aabb, false, inAABB); m_groundHeight = -size.y / 2.f - sceneInfo.geometryEpsilon * 10.f; } } } -void ObjScene::doPostInitialize() -{ -} +void ObjScene::doPostInitialize() {} -void ObjScene::doAnimate() -{ -} +void ObjScene::doAnimate() {} void ObjScene::doAddLights() { @@ -101,6 +100,7 @@ void ObjScene::doAddLights() if (m_gpuKernel->getNbActiveLamps() == 0) { m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, 8000.f, 8000.f, -8000.f, 10.f, 0.f, 0.f, DEFAULT_LIGHT_MATERIAL); + m_gpuKernel->setPrimitive(m_nbPrimitives, 8000.f, 8000.f, -8000.f, 10.f, + 0.f, 0.f, DEFAULT_LIGHT_MATERIAL); } } diff --git a/apps/scenes/meshes/ObjScene.h b/apps/scenes/meshes/ObjScene.h index d56c371..c041951 100644 --- a/apps/scenes/meshes/ObjScene.h +++ b/apps/scenes/meshes/ObjScene.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once diff --git a/apps/scenes/meshes/TrianglesScene.cpp b/apps/scenes/meshes/TrianglesScene.cpp index 5ea4341..7c48983 100644 --- a/apps/scenes/meshes/TrianglesScene.cpp +++ b/apps/scenes/meshes/TrianglesScene.cpp @@ -1,30 +1,27 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include "TrianglesScene.h" #include -#include #include #include #include +#include TrianglesScene::TrianglesScene(const std::string& name) : Scene(name) @@ -34,22 +31,23 @@ TrianglesScene::TrianglesScene(const std::string& name) m_groundHeight = -2500.f; } -TrianglesScene::~TrianglesScene(void) -{ -} +TrianglesScene::~TrianglesScene(void) {} void TrianglesScene::doInitialize() { Strings extensions; extensions.push_back(".irt"); - const Strings fileNames = getFilesFromFolder(std::string(DEFAULT_MEDIA_FOLDER) + "/irt", extensions); + const Strings fileNames = + getFilesFromFolder(std::string(DEFAULT_MEDIA_FOLDER) + "/irt", + extensions); if (fileNames.size() != 0) { const vec4f center = make_vec4f(); const float objectScale = 1.f; m_currentModel = m_currentModel % fileNames.size(); - solr::FileMarshaller fm; - fm.loadFromFile(*m_gpuKernel, fileNames[m_currentModel], center, objectScale * 5000.f); + FileMarshaller fm; + fm.loadFromFile(*m_gpuKernel, fileNames[m_currentModel], center, + objectScale * 5000.f); m_groundHeight = -2500.f; } } @@ -69,7 +67,8 @@ void TrianglesScene::doAddLights() { LOG_INFO(3, "Adding sun light"); m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, 5000.f, 5000.f, -5000.f, 10.f, 0.f, 0.f, DEFAULT_LIGHT_MATERIAL); + m_gpuKernel->setPrimitive(m_nbPrimitives, 5000.f, 5000.f, -5000.f, 10.f, + 0.f, 0.f, DEFAULT_LIGHT_MATERIAL); m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); } } diff --git a/apps/scenes/meshes/TrianglesScene.h b/apps/scenes/meshes/TrianglesScene.h index 250875a..f738125 100644 --- a/apps/scenes/meshes/TrianglesScene.h +++ b/apps/scenes/meshes/TrianglesScene.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once diff --git a/apps/scenes/science/ColumnScene.cpp b/apps/scenes/science/ColumnScene.cpp index 5abed39..7c42c27 100644 --- a/apps/scenes/science/ColumnScene.cpp +++ b/apps/scenes/science/ColumnScene.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau - * - * This file is part of Sol-R +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include "ColumnScene.h" @@ -40,9 +37,7 @@ ColumnScene::ColumnScene(const std::string& name) { } -ColumnScene::~ColumnScene(void) -{ -} +ColumnScene::~ColumnScene(void) {} /* ________________________________________________________________________________ @@ -64,7 +59,7 @@ void ColumnScene::doInitialize() // Scene Bounding Box SceneInfo& sceneInfo = m_gpuKernel->getSceneInfo(); - solr::CPUBoundingBox AABB; + CPUBoundingBox AABB; AABB.parameters[0].x = sceneInfo.viewDistance; AABB.parameters[0].y = sceneInfo.viewDistance; AABB.parameters[0].z = sceneInfo.viewDistance; @@ -75,24 +70,29 @@ void ColumnScene::doInitialize() Strings extensions; extensions.push_back(".obj"); extensions.push_back(".mtl"); - const Strings fileNames = getFilesFromFolder(std::string(DEFAULT_MEDIA_FOLDER) + "/obj", extensions); + const Strings fileNames = + getFilesFromFolder(std::string(DEFAULT_MEDIA_FOLDER) + "/obj", + extensions); const std::string star("neuron_12558.obj"); - solr::OBJReader objectReader; - solr::CPUBoundingBox inAABB; - memset(&inAABB, 0, sizeof(solr::CPUBoundingBox)); - const vec4f size = - objectReader.loadModelFromFile(path + "\\" + star, *m_gpuKernel, objectPosition, false, m_objectScale, - false, 10, false, false, AABB, false, inAABB); - - const vec4f halfSize = make_vec4f( - (AABB.parameters[1].x - AABB.parameters[0].x) / 2.f, - (AABB.parameters[1].y - AABB.parameters[0].y) / 2.f, - (AABB.parameters[1].z - AABB.parameters[0].z) / 2.f); - - const vec4f boxCenter = make_vec4f((AABB.parameters[0].x + AABB.parameters[1].x) / 2.f, - (AABB.parameters[0].y + AABB.parameters[1].y) / 2.f, - (AABB.parameters[0].z + AABB.parameters[1].z) / 2.f); + OBJReader objectReader; + CPUBoundingBox inAABB; + memset(&inAABB, 0, sizeof(CPUBoundingBox)); + const vec4f size = + objectReader.loadModelFromFile(path + "\\" + star, *m_gpuKernel, + objectPosition, false, m_objectScale, + false, 10, false, false, AABB, false, + inAABB); + + const vec4f halfSize = + make_vec4f((AABB.parameters[1].x - AABB.parameters[0].x) / 2.f, + (AABB.parameters[1].y - AABB.parameters[0].y) / 2.f, + (AABB.parameters[1].z - AABB.parameters[0].z) / 2.f); + + const vec4f boxCenter = + make_vec4f((AABB.parameters[0].x + AABB.parameters[1].x) / 2.f, + (AABB.parameters[0].y + AABB.parameters[1].y) / 2.f, + (AABB.parameters[0].z + AABB.parameters[1].z) / 2.f); inAABB.parameters[0].x = (boxCenter.x - halfSize.x * boxScale); inAABB.parameters[0].y = (boxCenter.y - halfSize.y * boxScale); @@ -102,7 +102,9 @@ void ColumnScene::doInitialize() inAABB.parameters[1].z = (boxCenter.z + halfSize.z * boxScale); m_actorPosition = boxCenter; - LOG_INFO(1, "Actor Position: " << m_actorPosition.x << "," << m_actorPosition.y << "," << m_actorPosition.z << ")"); + LOG_INFO(1, "Actor Position: " << m_actorPosition.x << "," + << m_actorPosition.y << "," + << m_actorPosition.z << ")"); for (int i(0); i < fileNames.size(); ++i) { @@ -111,9 +113,10 @@ void ColumnScene::doInitialize() LOG_INFO(1, "--- Loading " << m_name << " ---"); if (m_name.find(star) == -1) { - solr::CPUBoundingBox aabb; - objectReader.loadModelFromFile(m_name, *m_gpuKernel, objectPosition, false, m_objectScale, false, 11, false, - false, aabb, true, inAABB); + CPUBoundingBox aabb; + objectReader.loadModelFromFile(m_name, *m_gpuKernel, objectPosition, + false, m_objectScale, false, 11, + false, false, aabb, true, inAABB); m_groundHeight = -size.y / 2.f - sceneInfo.geometryEpsilon; @@ -134,7 +137,7 @@ void ColumnScene::doInitialize() } // Save to binary format - solr::FileMarshaller fm; + FileMarshaller fm; fm.saveToFile(*m_gpuKernel, "column.irt"); } @@ -153,8 +156,10 @@ void ColumnScene::doAddLights() { // lights m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, rand() % 20000 - 10000.f, rand() % 5000 - m_groundHeight, - rand() % 20000 - 10000.f, 10.f, 0.f, 0.f, 120 + i); + m_gpuKernel->setPrimitive(m_nbPrimitives, rand() % 20000 - 10000.f, + rand() % 5000 - m_groundHeight, + rand() % 20000 - 10000.f, 10.f, 0.f, 0.f, + 120 + i); m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); } } diff --git a/apps/scenes/science/ColumnScene.h b/apps/scenes/science/ColumnScene.h index 11cebc4..9f8d5ee 100644 --- a/apps/scenes/science/ColumnScene.h +++ b/apps/scenes/science/ColumnScene.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once diff --git a/apps/scenes/science/HypercubeScene.cpp b/apps/scenes/science/HypercubeScene.cpp new file mode 100644 index 0000000..fb1a649 --- /dev/null +++ b/apps/scenes/science/HypercubeScene.cpp @@ -0,0 +1,327 @@ +/* + * Copyright (c) 2011-2022, Cyrille Favreau + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* +IMPORTANT: This code is based on the Hypercube dephi code by cs_Forman +http://codes-sources.commentcamarche.net/source/33735-hypercubes +*/ + +#include "HypercubeScene.h" + +#include + +#ifdef WIN32 +#include +#else +#include +#endif + +float animationAngles[MaxDimensions]; + +HypercubeScene::HypercubeScene(const std::string& name) + : Scene(name) + , _primitiveIndex(0) + , _scale(1000.f) + , _transparency((rand() % 100 > 50) ? 0.5f : 0.f) + , _reflection((rand() % 100 > 50) ? 1.f : 0.f) + , _explosionFactor(1.f + rand() % 50 / 50.f) +{ + srand(static_cast(time(0))); + _dimension = 4 + rand() % (MaxDimensions - 5); + LOG_INFO(1, "Number of dimensions: " << _dimension); + for (size_t i = 0; i < MaxDimensions; ++i) + if (rand() % 4 != 0) + animationAngles[i] = (rand() % 1000 - 500) / 200.f; + else + animationAngles[i] = 0.f; +} + +HypercubeScene::~HypercubeScene(void) {} + +float HypercubeScene::powerOfTwo(const size_t n) +{ + return round(exp(log(2.f) * n)); +} + +void HypercubeScene::makeMatrix() +{ + const float ratio = static_cast(M_PI) / 360.f; + _matrix = identityMatrix(); + _matrix = multiplyMatrices( + _matrix, makeRotationMatrix(0, 1, _angles[2] * ratio)); // Rotate + // YZ + _matrix = multiplyMatrices( + _matrix, makeRotationMatrix(1, 2, _angles[0] * ratio)); // Rotate + // XZ + _matrix = multiplyMatrices( + _matrix, makeRotationMatrix(2, 0, _angles[1] * ratio)); // Rotate + // XY + for (size_t a = 0; a < 3 * (_dimension - 3); ++a) + { + auto i = a % 3; + auto j = (a / 3) + 3; + if (a == 0) + { + auto t = i; + i = j; + j = t; + } + _matrix = + multiplyMatrices(_matrix, + makeRotationMatrix(i, j, _angles[a + 3] * ratio)); + } +} + +Matrix HypercubeScene::makeRotationMatrix(const size_t i, const size_t j, + const float angle) +{ + Matrix matrix = identityMatrix(); + const auto c = cos(angle); + const auto s = sin(angle); + matrix.values[i][i] = c; + matrix.values[j][j] = c; + matrix.values[j][i] = s; + matrix.values[i][j] = -s; + return matrix; +} + +Matrix HypercubeScene::identityMatrix() +{ + Matrix matrix; + memset(&matrix, 0, sizeof(Matrix)); + for (size_t a = 0; a < MaxDimensions; ++a) + matrix.values[a][a] = 1.f; + return matrix; +} + +Matrix HypercubeScene::multiplyMatrices(const Matrix& matrix1, + const Matrix& matrix2) +{ + Matrix matrix; + for (size_t a = 0; a < MaxDimensions; ++a) + for (size_t b = 0; b < MaxDimensions; ++b) + { + float s = 0.f; + for (size_t c = 0; c < MaxDimensions; ++c) + s += matrix1.values[a][c] * matrix2.values[c][b]; + matrix.values[a][b] = s; + } + return matrix; +} + +Vector HypercubeScene::cross(const Vector& u, const Vector& v) +{ + Vector vector(3, 0); + vector[0] = u[1] * v[2] - u[2] * v[1]; + vector[1] = u[2] * v[0] - u[0] * v[2]; + vector[2] = u[0] * v[1] - u[1] * v[0]; + return vector; +} + +void HypercubeScene::makeSubFaces(const size_t a, const size_t b, size_t& c, + const size_t n) +{ + const float s = _scale * _explosionFactor; + for (size_t i = 0; i < n; ++i) + { + const size_t index = c + 4 * i; + _vertices[index + 0].resize(MaxDimensions, 0.f); + _vertices[index + 1].resize(MaxDimensions, 0.f); + _vertices[index + 2].resize(MaxDimensions, 0.f); + _vertices[index + 3].resize(MaxDimensions, 0.f); + float v; + size_t u = 1; + for (size_t j = 0; j < _dimension; ++j) + { + if ((j == a) || (j == b)) + continue; + if ((u & i) == u) + v = s; + else + v = -s; + _vertices[index + 0][j] = v; + _vertices[index + 1][j] = v; + _vertices[index + 2][j] = v; + _vertices[index + 3][j] = v; + u *= 2; + } + _vertices[index + 0][a] = s; + _vertices[index + 1][a] = s; + _vertices[index + 2][a] = -s; + _vertices[index + 3][a] = -s; + _vertices[index + 0][b] = s; + _vertices[index + 1][b] = -s; + _vertices[index + 2][b] = -s; + _vertices[index + 3][b] = s; + } + + c += 4 * n; +} + +void HypercubeScene::createGeometry() +{ + const size_t nbVertices = + (_dimension - 1) * _dimension * powerOfTwo(_dimension - 1); + + const float refraction = 1.f; + for (unsigned int i = 0; i < (nbVertices + 4); ++i) + m_gpuKernel->setMaterial(i, 0.5f + 0.5f * cos(i), 0.5f, + 0.5f + 0.5f * cos(i) * sin(i), 0.f, + _reflection, refraction, false, false, 0, + _transparency, 0.f, TEXTURE_NONE, TEXTURE_NONE, + TEXTURE_NONE, TEXTURE_NONE, TEXTURE_NONE, + TEXTURE_NONE, TEXTURE_NONE, 0.f, 100.f, 0.f, + 0.f, 10.f, 10000.f, false); + + _vertices.clear(); + size_t c = 0; + const size_t n = powerOfTwo(_dimension - 2); + for (size_t a = 0; a < _dimension - 1; ++a) + for (size_t b = a + 1; b < _dimension; ++b) + makeSubFaces(a, b, c, n); + makeMatrix(); +} + +Vector HypercubeScene::multiplyVector(const Matrix& m, const Vector& v) +{ + Vector vector(_dimension, 0.f); + for (size_t a = 0; a < _dimension; ++a) + { + float s = 0.f; + for (size_t b = 0; b < _dimension; ++b) + s += m.values[a][b] * v[b]; + vector[a] = s; + } + return vector; +} + +Vector HypercubeScene::subtractVector(const Vector& u, const Vector& v) +{ + Vector vector(_dimension, 0.f); + for (size_t a = 0; a < _dimension; ++a) + vector[a] = u[a] - v[a]; + return vector; +} + +void HypercubeScene::drawFace(const size_t Id) +{ + Vector t = multiplyVector(_matrix, _vertices[Id + 0]); + Vector u = multiplyVector(_matrix, _vertices[Id + 1]); + Vector v = multiplyVector(_matrix, _vertices[Id + 2]); + Vector w = multiplyVector(_matrix, _vertices[Id + 3]); + + const Vector n = cross(subtractVector(t, v), subtractVector(u, w)); + vec3f normal = make_vec3f(n[0], n[1], n[2]); + + const size_t index = 0; + if (m_currentModel % 2 == 0) + { + m_gpuKernel->setCurrentMaterial(static_cast(Id)); + glBegin(GL_TRIANGLES); + glVertex3f(t[index], t[index + 1], t[index + 2]); + glNormal3f(normal.x, normal.y, normal.z); + glVertex3f(u[index], u[index + 1], u[index + 2]); + glNormal3f(normal.x, normal.y, normal.z); + glVertex3f(v[index], v[index + 1], v[index + 2]); + glNormal3f(normal.x, normal.y, normal.z); + glEnd(); + + glBegin(GL_TRIANGLES); + glVertex3f(v[index], v[index + 1], v[index + 2]); + glNormal3f(normal.x, normal.y, normal.z); + glVertex3f(w[index], w[index + 1], w[index + 2]); + glNormal3f(normal.x, normal.y, normal.z); + glVertex3f(t[index], t[index + 1], t[index + 2]); + glNormal3f(normal.x, normal.y, normal.z); + glEnd(); + } + + if (m_currentModel % 10 != 0) + { + const float radius = _scale / 50.f; + _primitiveIndex = m_gpuKernel->addPrimitive(ptCylinder); + m_gpuKernel->setPrimitive(_primitiveIndex, t[index], t[index + 1], + t[index + 2], u[index], u[index + 1], + u[index + 2], radius, 0.f, 0.f, + METAL_MATERIAL); + _primitiveIndex = m_gpuKernel->addPrimitive(ptCylinder); + m_gpuKernel->setPrimitive(_primitiveIndex, u[index], u[index + 1], + u[index + 2], v[index], v[index + 1], + v[index + 2], radius, 0.f, 0.f, + METAL_MATERIAL); + _primitiveIndex = m_gpuKernel->addPrimitive(ptCylinder); + m_gpuKernel->setPrimitive(_primitiveIndex, v[index], v[index + 1], + v[index + 2], w[index], w[index + 1], + w[index + 2], radius, 0.f, 0.f, + METAL_MATERIAL); + _primitiveIndex = m_gpuKernel->addPrimitive(ptCylinder); + m_gpuKernel->setPrimitive(_primitiveIndex, w[index], w[index + 1], + w[index + 2], t[index], t[index + 1], + t[index + 2], radius, 0.f, 0.f, + METAL_MATERIAL); + } +} + +void HypercubeScene::drawFaces() +{ + for (size_t a = 0; a < (_vertices.size() + 1) / 4; ++a) + drawFace(4 * a); + + if (m_currentModel % 3 == 0) + for (size_t a = 0; a < _vertices.size(); ++a) + { + const size_t index = 0; + const float radius = _scale / 10.f; + Vector t = multiplyVector(_matrix, _vertices[a]); + _primitiveIndex = m_gpuKernel->addPrimitive(ptSphere); + m_gpuKernel->setPrimitive(_primitiveIndex, t[index], t[index + 1], + t[index + 2], radius, 0.f, 0.f, + METAL_MATERIAL); + } +} + +void HypercubeScene::doInitialize() +{ + _angles.resize(MaxDimensions, 0.f); + for (size_t i = 0; i < MaxDimensions; ++i) + _angles[i] = animationAngles[i]; + createGeometry(); + drawFaces(); +} + +void HypercubeScene::doAnimate() +{ + for (size_t i = 0; i < MaxDimensions; ++i) + _angles[i] += animationAngles[i]; + + _primitiveIndex = 0; + m_gpuKernel->resetFrame(); + createGeometry(); + drawFaces(); + doAddLights(); + addCornellBox(m_cornellBoxType); + m_gpuKernel->compactBoxes(true); +} + +void HypercubeScene::doAddLights() +{ + // lights + m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); + m_gpuKernel->setPrimitive(m_nbPrimitives, 0.f, 10000.f, -10000.f, 1000.f, + 0.f, 0, DEFAULT_LIGHT_MATERIAL); + m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); +} diff --git a/apps/scenes/science/HypercubeScene.h b/apps/scenes/science/HypercubeScene.h new file mode 100644 index 0000000..dae83fd --- /dev/null +++ b/apps/scenes/science/HypercubeScene.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2011-2022, Cyrille Favreau + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include + +const size_t MaxDimensions = 7; + +struct Matrix +{ + float values[MaxDimensions][MaxDimensions]; +}; + +typedef std::vector Vector; + +class HypercubeScene : public Scene +{ +public: + HypercubeScene(const std::string& name); + ~HypercubeScene(void); + +protected: + virtual void doInitialize(); + virtual void doAnimate(); + virtual void doAddLights(); + +private: + float powerOfTwo(const size_t n); + void createGeometry(); + void makeSubFaces(const size_t a, const size_t b, size_t& c, + const size_t n); + void makeMatrix(); + Matrix identityMatrix(); + Matrix multiplyMatrices(const Matrix&, const Matrix&); + Matrix makeRotationMatrix(const size_t ID, const size_t IDD, + const float angle); + + Vector cross(const Vector& u, const Vector& v); + Vector multiplyVector(const Matrix& m, const Vector& v); + Vector subtractVector(const Vector& u, const Vector& v); + + void drawFace(size_t Id); + void drawFaces(); + +private: + size_t _dimension; + std::map _vertices; + Matrix _matrix; + std::vector _angles; + int _primitiveIndex; + float _scale; + float _transparency; + float _reflection; + float _explosionFactor; +}; diff --git a/apps/scenes/science/MoleculeScene.cpp b/apps/scenes/science/MoleculeScene.cpp index 8c16414..d789684 100644 --- a/apps/scenes/science/MoleculeScene.cpp +++ b/apps/scenes/science/MoleculeScene.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include "MoleculeScene.h" @@ -41,9 +38,7 @@ MoleculeScene::MoleculeScene(const std::string& name) m_groundHeight = -5000.f; } -MoleculeScene::~MoleculeScene(void) -{ -} +MoleculeScene::~MoleculeScene(void) {} void MoleculeScene::doInitialize() { @@ -56,7 +51,9 @@ void MoleculeScene::doInitialize() Strings extensions; extensions.push_back(".pdb"); - const Strings fileNames = getFilesFromFolder(std::string(DEFAULT_MEDIA_FOLDER) + "/pdb", extensions); + const Strings fileNames = + getFilesFromFolder(std::string(DEFAULT_MEDIA_FOLDER) + "/pdb", + extensions); if (fileNames.size() != 0) { m_currentModel = m_currentModel % fileNames.size(); @@ -66,9 +63,11 @@ void MoleculeScene::doInitialize() m_name = fileNames[m_currentModel]; // PDB - solr::PDBReader pdbReader; - pdbReader.loadAtomsFromFile(m_name, *m_gpuKernel, static_cast(geometryType), - defaultAtomSize, defaultStickSize, atomMaterialType, scale, loadModels); + PDBReader pdbReader; + pdbReader.loadAtomsFromFile(m_name, *m_gpuKernel, + static_cast(geometryType), + defaultAtomSize, defaultStickSize, + atomMaterialType, scale, loadModels); } } @@ -84,6 +83,7 @@ void MoleculeScene::doAddLights() { // Lights m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, -5000.f, 5000.f, -15000.f, 1.f, 0.f, 0.f, DEFAULT_LIGHT_MATERIAL); + m_gpuKernel->setPrimitive(m_nbPrimitives, -5000.f, 5000.f, -15000.f, 1.f, + 0.f, 0.f, DEFAULT_LIGHT_MATERIAL); m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); } diff --git a/apps/scenes/science/MoleculeScene.h b/apps/scenes/science/MoleculeScene.h index afd7dfa..e74ef4f 100644 --- a/apps/scenes/science/MoleculeScene.h +++ b/apps/scenes/science/MoleculeScene.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once diff --git a/apps/scenes/science/SwcScene.cpp b/apps/scenes/science/SwcScene.cpp index 3a9dd6e..cde98f5 100644 --- a/apps/scenes/science/SwcScene.cpp +++ b/apps/scenes/science/SwcScene.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau - * - * This file is part of Sol-R +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include "SwcScene.h" @@ -29,14 +26,12 @@ SwcScene::SwcScene(const std::string &name) { } -SwcScene::~SwcScene() -{ -} +SwcScene::~SwcScene() {} /* ________________________________________________________________________________ -Create simple scene for box validation +Create simple scene for box validation ________________________________________________________________________________ */ void SwcScene::doInitialize() @@ -44,7 +39,9 @@ void SwcScene::doInitialize() // initialization Strings extensions; extensions.push_back(".swc"); - const Strings fileNames = getFilesFromFolder(std::string(DEFAULT_MEDIA_FOLDER) + "/swc", extensions); + const Strings fileNames = + getFilesFromFolder(std::string(DEFAULT_MEDIA_FOLDER) + "/swc", + extensions); if (fileNames.size() != 0) { m_currentModel = m_currentModel % fileNames.size(); @@ -54,8 +51,9 @@ void SwcScene::doInitialize() const vec4f position = make_vec4f(0.f, 0.f, 0.f); for (int i(0); i < fileNames.size(); ++i) { - solr::SWCReader swcReader; - swcReader.loadMorphologyFromFile(fileNames[i], *m_gpuKernel, position, scale, 1001); + SWCReader swcReader; + swcReader.loadMorphologyFromFile(fileNames[i], *m_gpuKernel, + position, scale, 1001); if (i == 0) m_morphologies = swcReader.getMorphologies(); @@ -66,9 +64,10 @@ void SwcScene::doInitialize() void SwcScene::doAnimate() { const int index = m_counter % m_morphologies.size(); - solr::Morphology &m = m_morphologies[index]; + Morphology &m = m_morphologies[index]; if (m_counter > 0) - m_gpuKernel->setPrimitiveMaterial(m_previousPrimitiveId, m_previousMaterial); + m_gpuKernel->setPrimitiveMaterial(m_previousPrimitiveId, + m_previousMaterial); m_previousMaterial = m_gpuKernel->getPrimitiveMaterial(m.primitiveId); m_gpuKernel->setPrimitiveMaterial(m.primitiveId, DEFAULT_LIGHT_MATERIAL); @@ -77,7 +76,7 @@ void SwcScene::doAnimate() const int light = m_gpuKernel->getLight(0); if (light != -1) { - solr::CPUPrimitive *lamp = m_gpuKernel->getPrimitive(light); + CPUPrimitive *lamp = m_gpuKernel->getPrimitive(light); lamp->p0.x = m.x; lamp->p0.y = m.y; lamp->p0.z = m.z - 50.f; @@ -92,6 +91,7 @@ void SwcScene::doAddLights() { // lights m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); - m_gpuKernel->setPrimitive(m_nbPrimitives, -10000.f, 10000.f, -10000.f, 20.f, 0.f, 0, DEFAULT_LIGHT_MATERIAL); + m_gpuKernel->setPrimitive(m_nbPrimitives, -10000.f, 10000.f, -10000.f, 20.f, + 0.f, 0, DEFAULT_LIGHT_MATERIAL); m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); } diff --git a/apps/scenes/science/SwcScene.h b/apps/scenes/science/SwcScene.h index fd31c17..9cfdc96 100644 --- a/apps/scenes/science/SwcScene.h +++ b/apps/scenes/science/SwcScene.h @@ -1,27 +1,24 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once -#include #include +#include class SwcScene : public Scene { @@ -35,7 +32,7 @@ class SwcScene : public Scene virtual void doAddLights(); private: - solr::Morphologies m_morphologies; + Morphologies m_morphologies; int m_counter; int m_previousMaterial; int m_previousPrimitiveId; diff --git a/apps/scenes/science/TesseractScene.cpp b/apps/scenes/science/TesseractScene.cpp new file mode 100644 index 0000000..be08604 --- /dev/null +++ b/apps/scenes/science/TesseractScene.cpp @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2011-2022, Cyrille Favreau + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "TesseractScene.h" + +#include + +TesseractScene::TesseractScene(const std::string& name) + : Scene(name) + , _timestamp(0.f) +{ +} + +TesseractScene::~TesseractScene() {} + +vec3f TesseractScene::computeCoordinates(const vec3f& p1, const vec3f& p2, + const vec3f& p3, const vec3f& p4) +{ + vec3f newVec; + + if (_timestamp >= 0.f && _timestamp < 0.25f) + { + newVec.x = p4.x + (p1.x - p4.x) * _timestamp * 4.f; + newVec.y = p4.y + (p1.y - p4.y) * _timestamp * 4.f; + newVec.z = p4.z + (p1.z - p4.z) * _timestamp * 4.f; + } + else if (_timestamp >= 0.25f && _timestamp < 0.5f) + { + newVec.x = p1.x + (p2.x - p1.x) * (_timestamp - 0.25f) * 4.f; + newVec.y = p1.y + (p2.y - p1.y) * (_timestamp - 0.25f) * 4.f; + newVec.z = p1.z + (p2.z - p1.z) * (_timestamp - 0.25f) * 4.f; + } + else if (_timestamp >= 0.5f && _timestamp < 0.75f) + { + newVec.x = p2.x + (p3.x - p2.x) * (_timestamp - 0.5f) * 4.f; + newVec.y = p2.y + (p3.y - p2.y) * (_timestamp - 0.5f) * 4.f; + newVec.z = p2.z + (p3.z - p2.z) * (_timestamp - 0.5f) * 4.f; + } + else if (_timestamp >= 0.75f && _timestamp < 1.f) + { + newVec.x = p3.x + (p4.x - p3.x) * (_timestamp - 0.75f) * 4.f; + newVec.y = p3.y + (p4.y - p3.y) * (_timestamp - 0.75f) * 4.f; + newVec.z = p3.z + (p4.z - p3.z) * (_timestamp - 0.75f) * 4.f; + } + + return newVec; +} + +void TesseractScene::createGeometry() +{ + vec3f tesseract[16] = { + {-0.5, -0.5, -0.5}, {0.5, -0.5, -0.5}, {0.5, 0.5, -0.5}, + {-0.5, 0.5, -0.5}, {-0.5, -0.5, 0.5}, {0.5, -0.5, 0.5}, + {0.5, 0.5, 0.5}, {-0.5, 0.5, 0.5}, {-1, -1, -1}, + {1, -1, -1}, {1, 1, -1}, {-1, 1, -1}, + {-1, -1, 1}, {1, -1, 1}, {1, 1, 1}, + {-1, 1, 1}, + }; + + vec3f vertices[16] = {computeCoordinates(tesseract[8], tesseract[9], + tesseract[1], tesseract[0]), + computeCoordinates(tesseract[0], tesseract[8], + tesseract[9], tesseract[1]), + computeCoordinates(tesseract[3], tesseract[11], + tesseract[10], tesseract[2]), + computeCoordinates(tesseract[11], tesseract[10], + tesseract[2], tesseract[3]), + computeCoordinates(tesseract[12], tesseract[13], + tesseract[5], tesseract[4]), + computeCoordinates(tesseract[4], tesseract[12], + tesseract[13], tesseract[5]), + computeCoordinates(tesseract[7], tesseract[15], + tesseract[14], tesseract[6]), + computeCoordinates(tesseract[15], tesseract[14], + tesseract[6], tesseract[7]), + computeCoordinates(tesseract[9], tesseract[1], + tesseract[0], tesseract[8]), + computeCoordinates(tesseract[1], tesseract[0], + tesseract[8], tesseract[9]), + computeCoordinates(tesseract[2], tesseract[3], + tesseract[11], tesseract[10]), + computeCoordinates(tesseract[10], tesseract[2], + tesseract[3], tesseract[11]), + computeCoordinates(tesseract[13], tesseract[5], + tesseract[4], tesseract[12]), + computeCoordinates(tesseract[5], tesseract[4], + tesseract[12], tesseract[13]), + computeCoordinates(tesseract[6], tesseract[7], + tesseract[15], tesseract[14]), + computeCoordinates(tesseract[14], tesseract[6], + tesseract[7], tesseract[15])}; + + const float s = 2000.f; + float radius = s / 10.f; + for (size_t i = 0; i < 16; ++i) + { + vec3f t = vertices[i]; + size_t primitiveIndex = m_gpuKernel->addPrimitive(ptSphere); + m_gpuKernel->setPrimitive(primitiveIndex, s * t.x, s * t.y, s * t.z, + radius, 0.f, 0.f, METAL_MATERIAL); + } + + const size_t joints[32][2] = { + {0, 1}, {1, 2}, {2, 3}, {3, 0}, {0, 4}, {1, 5}, {2, 6}, + {3, 7}, {4, 5}, {5, 6}, {6, 7}, {7, 4}, {0, 8}, {1, 9}, + {2, 10}, {3, 11}, {4, 12}, {5, 13}, {6, 14}, {7, 15}, {8, 9}, + {9, 10}, {10, 11}, {11, 8}, {8, 12}, {9, 13}, {10, 14}, {11, 15}, + {12, 13}, {13, 14}, {14, 15}, {15, 12}, + }; + + radius = s / 20.f; + for (size_t i = 0; i < 32; ++i) + { + vec3f t = vertices[joints[i][0]]; + vec3f u = vertices[joints[i][1]]; + + size_t primitiveIndex = m_gpuKernel->addPrimitive(ptCylinder); + m_gpuKernel->setPrimitive(primitiveIndex, s * t.x, s * t.y, s * t.z, + s * u.x, s * u.y, s * u.z, radius, 0.f, 0.f, + METAL_MATERIAL); + } + + size_t material = BASIC_REFLECTION_MATERIAL_002; + for (size_t i = 0; i < 32; i += 4) + { + vec3f t = vertices[joints[i][0]]; + vec3f u = vertices[joints[i + 1][0]]; + vec3f v = vertices[joints[i + 2][0]]; + vec3f w = vertices[joints[i + 3][0]]; + + m_gpuKernel->setCurrentMaterial(material); + glBegin(GL_TRIANGLES); + glVertex3f(s * t.x, s * t.y, s * t.z); + glVertex3f(s * u.x, s * u.y, s * u.z); + glVertex3f(s * v.x, s * v.y, s * v.z); + glEnd(); + + glBegin(GL_TRIANGLES); + glVertex3f(s * v.x, s * v.y, s * v.z); + glVertex3f(s * w.x, s * w.y, s * w.z); + glVertex3f(s * t.x, s * t.y, s * t.z); + glEnd(); + } +} + +void TesseractScene::doInitialize() +{ + createGeometry(); + doAddLights(); +} + +void TesseractScene::doAnimate() +{ + m_gpuKernel->resetFrame(); + createGeometry(); + doAddLights(); + addCornellBox(m_cornellBoxType); + m_gpuKernel->compactBoxes(true); + _timestamp += 0.005f; + if (_timestamp > 1.f) + _timestamp = 0.f; +} + +void TesseractScene::doAddLights() +{ + // lights + m_nbPrimitives = m_gpuKernel->addPrimitive(ptSphere); + m_gpuKernel->setPrimitive(m_nbPrimitives, 0.f, 10000.f, -10000.f, 1000.f, + 0.f, 0, DEFAULT_LIGHT_MATERIAL); + m_gpuKernel->setPrimitiveIsMovable(m_nbPrimitives, false); +} diff --git a/apps/scenes/science/TesseractScene.h b/apps/scenes/science/TesseractScene.h new file mode 100644 index 0000000..e13be64 --- /dev/null +++ b/apps/scenes/science/TesseractScene.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2011-2022, Cyrille Favreau + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include + +class TesseractScene : public Scene +{ +public: + TesseractScene(const std::string& name); + ~TesseractScene(); + +protected: + virtual void doInitialize(); + virtual void doAnimate(); + virtual void doAddLights(); + +private: + vec3f computeCoordinates(const vec3f& p1, const vec3f& p2, const vec3f& p3, + const vec3f& p4); + void createGeometry(); + float _timestamp; +}; diff --git a/apps/solrViewer.cpp b/apps/solrViewer.cpp index 290a552..915e9b4 100644 --- a/apps/solrViewer.cpp +++ b/apps/solrViewer.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ // OpenGL Graphics Includes @@ -45,26 +42,28 @@ #include #include #include -#include -#include #include #include #include #include +#include +#include #include #include #include #include #include #include +#include #include #include +#include + +#include // Ray-tracing Kernel solr::GPUKernel *gKernel = solr::SingletonKernel::kernel(); -using namespace solr; - // General Settings const int TARGET_FPS = 60; const int REFRESH_DELAY = 1000 / TARGET_FPS; // ms @@ -110,8 +109,8 @@ std::string gFilename; unsigned int gWindowWidth = 1280 / 2; unsigned int gWindowHeight = 800 / 2; #else -unsigned int gWindowWidth = 800; -unsigned int gWindowHeight = static_cast(gWindowWidth * 9.f / 16.f); +unsigned int gWindowWidth = 960; +unsigned int gWindowHeight = 540; #endif // USE_OCULUS unsigned int gWindowDepth = 4; @@ -125,28 +124,29 @@ struct MenuItem char key; }; const int NB_MENU_ITEMS = 22; -MenuItem menuItems[NB_MENU_ITEMS] = {{"a: Black background and no image noise", 'a'}, - {"b: Randomly set background color and image noise", 'b'}, - {"f: Auto-focus", 'f'}, - {"h: Help", 'h'}, - {"i: Show/hide Bounding boxes", 'i'}, - {"m: Animate scene", 'm'}, - {"n: Load next 3D model (in folder medias/obj)", 'n'}, - {"o: Switch to VR mode", 'o'}, - {"p: Post processing (Depth of field, ambient occlusion, bloom, etc)", 'p'}, - {"r: Reset current scene", 'r'}, - {"t: Next scene", 't'}, - {"s: Change graphics level", 's'}, - {"v: Random materials", 'i'}, - {"x: Next environment (CornellBox, SkyBox, etc.)", 'x'}, - {"*: View modes (Standard, Anaglyth 3D, Oculus Rift", '*'}, - {"1: Camera mouse control", '1'}, - {"2: Light mouse control", '2'}, - {"3: 3D model mouse control", '3'}, - {"4: Depth of field mouse control", '3'}, - {"5: Field of view mouse control", '3'}, - {"9: Shadow strength", '9'}, - {"Esc: Exit application", '\033'}}; +MenuItem menuItems[NB_MENU_ITEMS] = { + {"A: Black background and no image noise", 'A'}, + {"b: Randomly set background color and image noise", 'b'}, + {"f: Auto-focus", 'f'}, + {"h: Help", 'h'}, + {"i: Show/hide Bounding boxes", 'i'}, + {"m: Animate scene", 'm'}, + {"n: Load next 3D model (in folder medias/obj)", 'n'}, + {"o: Switch to VR mode", 'o'}, + {"p: Post processing (Depth of field, ambient occlusion, bloom, etc)", 'p'}, + {"r: Reset current scene", 'r'}, + {"t: Next scene", 't'}, + {"s: Change graphics level", 's'}, + {"v: Random materials", 'i'}, + {"x: Next environment (CornellBox, SkyBox, etc.)", 'x'}, + {"*: View modes (Standard, Anaglyth 3D, Oculus Rift", '*'}, + {"1: Camera mouse control", '1'}, + {"2: Light mouse control", '2'}, + {"3: 3D model mouse control", '3'}, + {"4: Depth of field mouse control", '3'}, + {"5: Field of view mouse control", '3'}, + {"9: Shadow strength", '9'}, + {"Esc: Exit application", '\033'}}; // controlType enum ControlType @@ -168,7 +168,7 @@ int gMaterials[2]; int gWallTexture = 3; // Scene description and behavior -int gCornellBoxType = 1; +int gCornellBoxType = 0; int gNbBoxes = 0; int m_nbPrimitives = 0; int gLampId = 0; @@ -191,7 +191,6 @@ float gSpecValue = 1.f; float gSpecPower = 100.f; float gSpecCoef = 1.f; float gInnerIllumination = 0.f; -bool gNoise(false); // OpenGL int gTimebase(0); @@ -209,7 +208,8 @@ void reshape(int x, int y); void createScene(); #ifdef WIN32 -void RenderString(float x, float y, float z, void *font, const std::string &string, const vec4f &rgb); +void RenderString(float x, float y, float z, void *font, + const std::string &string, const vec4f &rgb); #endif // Helpers @@ -271,7 +271,7 @@ void initgl(int argc, char **argv) glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glutInitWindowPosition(glutGet(GLUT_SCREEN_WIDTH) / 2 - gWindowWidth / 2, glutGet(GLUT_SCREEN_HEIGHT) / 2 - gWindowHeight / 2); - std::string caption("SoL-R tech demo v00.02.00"); + std::string caption("Quantum of SoL-R tech demo v00.02.00"); #ifdef USE_CUDA caption += " (Powered by CUDA)"; glutInitWindowSize(gWindowWidth, gWindowHeight); @@ -290,11 +290,13 @@ void initgl(int argc, char **argv) } #ifdef WIN32 -void RenderString(float x, float y, float z, void *font, const std::string &string, const vec4f &rgb) +void RenderString(float x, float y, float z, void *font, + const std::string &string, const vec4f &rgb) { // glColor3f(rgb.x, rgb.y, rgb.z); glRasterPos3f(x, y, z); - glutBitmapString(font, reinterpret_cast(string.c_str())); + glutBitmapString(font, + reinterpret_cast(string.c_str())); } #endif @@ -357,15 +359,20 @@ void display() tmpMenuItems += "\n"; } vec4f textColor = {1.f, 1.f, 1.f}; - sprintf(tmp, - "%sSelected primitive: %d\nFPS: %d on %s (%dx%d)\nScene " - "%d: %s\nMouse control: %s\nPrimitives/Boxes: " - "%d/%d\nhttp://cudaopencl.blogspot.com [%d]", - tmpMenuItems.c_str(), gSelectedPrimitive, gFPS, gKernel->getGPUDescription().c_str(), - gScene->getSceneInfo().size.x, gScene->getSceneInfo().size.y, gSceneId, - gScene->getName().c_str(), gHint.c_str(), gKernel->getNbActivePrimitives(), - gKernel->getNbActiveBoxes(), si.pathTracingIteration); - RenderString(-0.9f, 0.9f, 0.f, GLUT_BITMAP_HELVETICA_10, tmp, textColor); + sprintf( + tmp, + "%sSelected primitive: %d\nFPS: %d on %s (%dx%d)\nScene " + "%d: %s\nMouse control: %s\nPrimitives/Boxes: " + "%d/%d\nhttp://cudaopencl.blogspot.com [%d]", + tmpMenuItems.c_str(), gSelectedPrimitive, gFPS, + gKernel->getGPUDescription().c_str(), + gScene->getSceneInfo().size.x, + gScene->getSceneInfo().size.y, gSceneId, + gScene->getName().c_str(), gHint.c_str(), + gKernel->getNbActivePrimitives(), + gKernel->getNbActiveBoxes(), si.pathTracingIteration); + RenderString(-0.9f, 0.9f, 0.f, GLUT_BITMAP_HELVETICA_10, tmp, + textColor); } #endif // WIN32 } @@ -387,18 +394,22 @@ void display() text << gRenderingTime << " ms\n"; text << gKernel->getGPUDescription(); text << "\n" - << gKernel->getNbActivePrimitives() << " triangles, " << si.size.x << "x" << si.size.y << ", " + << gKernel->getNbActivePrimitives() << " triangles, " + << si.size.x << "x" << si.size.y << ", " << si.maxPathTracingIterations << " samples/pixel"; - RenderString(-0.95f, -0.8f, 0.f, GLUT_BITMAP_HELVETICA_10, text.str().c_str(), make_vec4f(1.f,1.f,1.f)); + RenderString(-0.95f, -0.8f, 0.f, GLUT_BITMAP_HELVETICA_10, + text.str().c_str(), make_vec4f(1.f, 1.f, 1.f)); gScene->renderText(); #endif if (!gSavedToDisk) { int margin = 32; - size_t size = (si.size.x - margin) * (si.size.y - margin) * gColorDepth; + size_t size = + (si.size.x - margin) * (si.size.y - margin) * gColorDepth; GLubyte *buffer = new GLubyte[size]; - glReadPixels(0, 0, si.size.x - margin, si.size.y - margin, GL_RGB, GL_UNSIGNED_BYTE, buffer); + glReadPixels(0, 0, si.size.x - margin, si.size.y - margin, + GL_RGB, GL_UNSIGNED_BYTE, buffer); GLubyte *dst = new GLubyte[size]; int X = (si.size.x - margin) * gColorDepth; @@ -412,8 +423,10 @@ void display() // Save to disc std::string filename("./SolR"); filename += ".jpg"; - jpge::compress_image_to_jpeg_file(filename.c_str(), si.size.x - margin, si.size.y - margin, gColorDepth, - dst); + jpge::compress_image_to_jpeg_file(filename.c_str(), + si.size.x - margin, + si.size.y - margin, + gColorDepth, dst); delete[] buffer; delete[] dst; gSavedToDisk = true; @@ -427,7 +440,8 @@ void display() // Copyright const char *copyright = "http://cudaopencl.blogspot.com"; float p = strlen(copyright) * 20.f / si.size.x; - RenderString(-p / 2.f, -0.9f, 0.f, GLUT_BITMAP_HELVETICA_18, copyright, make_vec4f(1.f,1.f,1.f)); + RenderString(-p / 2.f, -0.9f, 0.f, GLUT_BITMAP_HELVETICA_18, + copyright, make_vec4f(1.f, 1.f, 1.f)); gScene->renderText(); } @@ -454,7 +468,8 @@ case 10: // Kinect { for (int x(0); x < KINECT_DEPTH_WIDTH; x += gKinectStep) { - int index = KINECT_DEPTH_SIZE - (y * KINECT_DEPTH_WIDTH + x) * KINECT_DEPTH_DEPTH; + int index = KINECT_DEPTH_SIZE - + (y * KINECT_DEPTH_WIDTH + x) * KINECT_DEPTH_DEPTH; char a = depthBitmap[index]; char b = depthBitmap[index + 1]; int s = b * 256 + a; @@ -463,8 +478,10 @@ case 10: // Kinect if (s < 1 || s > 15000) s = 50000; - kernel.setPrimitive(p, 5 + p / gKinectNbSpherePerBox, -(x - 160) * gKinectSpace, - (y - 120) * gKinectSpace, s / 3.f - 5000.f, gKinectSize, 0.f, 0.f, 7, 1, 1); + kernel.setPrimitive(p, 5 + p / gKinectNbSpherePerBox, + -(x - 160) * gKinectSpace, + (y - 120) * gKinectSpace, s / 3.f - 5000.f, + gKinectSize, 0.f, 0.f, 7, 1, 1); ++b; ++p; @@ -485,7 +502,6 @@ void reshape(int x, int y) x += 32 - (x % 32); if (y % 32 != 0) y += 32 - (y % 32); - // y = x*9/16; SceneInfo &sceneInfo = gScene->getSceneInfo(); sceneInfo.size.x = x; sceneInfo.size.y = y; @@ -531,17 +547,21 @@ void keyboard(unsigned char key, int x, int y) } case 'B': { - gScene->getSceneInfo().backgroundColor.x = 1.f; - gScene->getSceneInfo().backgroundColor.y = 1.f; - gScene->getSceneInfo().backgroundColor.z = 1.f; + gScene->getSceneInfo().backgroundColor.x = 0.1f; + gScene->getSceneInfo().backgroundColor.y = 0.1f; + gScene->getSceneInfo().backgroundColor.z = 0.1f; gScene->getSceneInfo().backgroundColor.w = 0.5f; gScene->getSceneInfo().skyboxMaterialId = - (gScene->getSceneInfo().skyboxMaterialId == MATERIAL_NONE) ? SKYBOX_SPHERE_MATERIAL : MATERIAL_NONE; + (gScene->getSceneInfo().skyboxMaterialId == MATERIAL_NONE) + ? SKYBOX_SPHERE_MATERIAL + : MATERIAL_NONE; break; } case 'b': { - gScene->getSceneInfo().backgroundColor = make_vec4f(rand() % 255 / 255.f, rand() % 255 / 255.f, rand() % 255 / 255.f, 0.5f); + gScene->getSceneInfo().backgroundColor = + make_vec4f(rand() % 255 / 255.f, rand() % 255 / 255.f, + rand() % 255 / 255.f, 0.5f); break; } case 'D': @@ -560,7 +580,8 @@ void keyboard(unsigned char key, int x, int y) case 'E': { // Extended geometry - gScene->getSceneInfo().extendedGeometry = !gScene->getSceneInfo().extendedGeometry; + gScene->getSceneInfo().extendedGeometry = + !gScene->getSceneInfo().extendedGeometry; break; } case 'e': @@ -571,11 +592,16 @@ void keyboard(unsigned char key, int x, int y) { Material *m = kernel->getMaterial(SKYBOX_SPHERE_MATERIAL); gSphereMaterial = (gSphereMaterial + 1) % nbHDRI; - kernel->setMaterial(SKYBOX_SPHERE_MATERIAL, m->color.x, m->color.y, m->color.z, m->color.w, 0.f, 0.f, - (m->attributes.y == 1), (m->attributes.z == 1), m->attributes.w, 0.f, m->opacity, - gSphereMaterial, TEXTURE_NONE, TEXTURE_NONE, TEXTURE_NONE, TEXTURE_NONE, TEXTURE_NONE, - TEXTURE_NONE, m->specular.x, m->specular.y, m->specular.z, m->innerIllumination.x, - m->innerIllumination.y, m->innerIllumination.z, (m->attributes.x == 1)); + kernel->setMaterial(SKYBOX_SPHERE_MATERIAL, m->color.x, m->color.y, + m->color.z, m->color.w, 0.f, 0.f, + (m->attributes.y == 1), (m->attributes.z == 1), + m->attributes.w, 0.f, m->opacity, + gSphereMaterial, TEXTURE_NONE, TEXTURE_NONE, + TEXTURE_NONE, TEXTURE_NONE, TEXTURE_NONE, + TEXTURE_NONE, m->specular.x, m->specular.y, + m->specular.z, m->innerIllumination.x, + m->innerIllumination.y, m->innerIllumination.z, + (m->attributes.x == 1)); } break; } @@ -597,7 +623,8 @@ void keyboard(unsigned char key, int x, int y) } case 'g': { - int nbTextures = (kernel->getNbActiveTextures() - gScene->getNbHDRI()) / 5; + int nbTextures = + (kernel->getNbActiveTextures() - gScene->getNbHDRI()) / 5; if (nbTextures > 0) { gGroundMaterial = (gGroundMaterial + 1) % nbTextures; @@ -648,12 +675,17 @@ void keyboard(unsigned char key, int x, int y) m->transparency = 1.f; m->refraction = 1.1f; } - kernel->setMaterial(SKYBOX_GROUND_MATERIAL, m->color.x, m->color.y, m->color.z, m->color.w, 1.f, - m->refraction, (m->attributes.y == 1), (m->attributes.z == 1), m->attributes.w, - m->transparency, m->opacity, diffuseTextureId, normalTextureId, bumpTextureId, - specularTextureId, reflectionTextureId, transparencyTextureId, TEXTURE_NONE, - m->specular.x, m->specular.y, m->specular.z, m->innerIllumination.x, - m->innerIllumination.y, m->innerIllumination.z, (m->attributes.x == 1)); + kernel->setMaterial(SKYBOX_GROUND_MATERIAL, m->color.x, m->color.y, + m->color.z, m->color.w, 1.f, m->refraction, + (m->attributes.y == 1), (m->attributes.z == 1), + m->attributes.w, m->transparency, m->opacity, + diffuseTextureId, normalTextureId, + bumpTextureId, specularTextureId, + reflectionTextureId, transparencyTextureId, + TEXTURE_NONE, m->specular.x, m->specular.y, + m->specular.z, m->innerIllumination.x, + m->innerIllumination.y, m->innerIllumination.z, + (m->attributes.x == 1)); } break; } @@ -665,7 +697,8 @@ void keyboard(unsigned char key, int x, int y) case 'I': { gScene->getSceneInfo().advancedIllumination = - static_cast((gScene->getSceneInfo().advancedIllumination + 1) % 3); + static_cast( + (gScene->getSceneInfo().advancedIllumination + 1) % 3); break; } case 'i': @@ -678,7 +711,8 @@ void keyboard(unsigned char key, int x, int y) } case 'k': { - gScene->getSceneInfo().gradientBackground = !gScene->getSceneInfo().gradientBackground; + gScene->getSceneInfo().gradientBackground = + !gScene->getSceneInfo().gradientBackground; break; } case 'K': @@ -716,11 +750,16 @@ void keyboard(unsigned char key, int x, int y) case 'o': { gScene->getSceneInfo().cameraType = - (gScene->getSceneInfo().cameraType == ctVolumeRendering) ? ctPerspective : ctVolumeRendering; + (gScene->getSceneInfo().cameraType == ctVolumeRendering) + ? ctPerspective + : ctVolumeRendering; gScene->getSceneInfo().graphicsLevel = - (gScene->getSceneInfo().cameraType == ctVolumeRendering) ? glNoShading : glReflectionsAndRefractions; + (gScene->getSceneInfo().cameraType == ctVolumeRendering) + ? glNoShading + : glReflectionsAndRefractions; gScene->getSceneInfo().backgroundColor.w = - (gScene->getSceneInfo().cameraType == ctVolumeRendering) ? 0.01f : 0.5f; + (gScene->getSceneInfo().cameraType == ctVolumeRendering) ? 0.01f + : 0.5f; break; } case 'p': @@ -741,26 +780,27 @@ void keyboard(unsigned char key, int x, int y) if (key == 'q') { #ifdef WIN32 - std::string filename("E:/Cloud/Dropbox/Samsung Link/Photos/1K/CudaSolR_"); + std::string filename( + "E:/Cloud/Dropbox/Samsung Link/Photos/1K/CudaSolR_"); #else - std::string filename("~/Pictures/1K/CudaSolR_"); + std::string filename("/tmp/CudaSolR_1k_"); #endif filename += buffer; if (kernel) - kernel->generateScreenshot(filename, 2100, 2970, gScene->getSceneInfo().maxPathTracingIterations); + kernel->generateScreenshot(filename, 960, 960, 256); } else { #ifdef WIN32 - std::string filename("E:/Cloud/Dropbox/Samsung Link/Photos/4K/CudaSolR_"); + std::string filename( + "E:/Cloud/Dropbox/Samsung Link/Photos/4K/CudaSolR_"); #else - std::string filename("~/Pictures/4K/CudaSolR_"); + std::string filename("/tmp/CudaSolR_4k_"); #endif filename += buffer; if (kernel) - kernel->generateScreenshot(filename, 2 * 2970, 2 * 2100, - gScene->getSceneInfo().maxPathTracingIterations); + kernel->generateScreenshot(filename, 3840, 3840, 256); } break; } @@ -780,7 +820,8 @@ void keyboard(unsigned char key, int x, int y) } case 'S': { - gScene->getSceneInfo().graphicsLevel = static_cast(gScene->getSceneInfo().graphicsLevel + 1); + gScene->getSceneInfo().graphicsLevel = static_cast( + gScene->getSceneInfo().graphicsLevel + 1); if (gScene->getSceneInfo().graphicsLevel > glFull) gScene->getSceneInfo().graphicsLevel = glNoShading; break; @@ -795,7 +836,8 @@ void keyboard(unsigned char key, int x, int y) case 'T': { // Double sided triangles - gScene->getSceneInfo().doubleSidedTriangles = !gScene->getSceneInfo().doubleSidedTriangles; + gScene->getSceneInfo().doubleSidedTriangles = + !gScene->getSceneInfo().doubleSidedTriangles; break; } case 't': @@ -804,7 +846,7 @@ void keyboard(unsigned char key, int x, int y) delete gScene; gScene = 0; gAnimate = false; - gSceneId = ((gSceneId + 1) % 16); + gSceneId = ((gSceneId + 1) % 17); createScene(); break; } @@ -824,7 +866,9 @@ void keyboard(unsigned char key, int x, int y) { gScene->getSceneInfo().backgroundColor.w += 0.1f; gScene->getSceneInfo().backgroundColor.w = - (gScene->getSceneInfo().backgroundColor.w > 1.f) ? 0.f : gScene->getSceneInfo().backgroundColor.w; + (gScene->getSceneInfo().backgroundColor.w > 1.f) + ? 0.f + : gScene->getSceneInfo().backgroundColor.w; break; } case 'x': @@ -862,7 +906,8 @@ void keyboard(unsigned char key, int x, int y) } case '*': { - gScene->getSceneInfo().cameraType = static_cast((gScene->getSceneInfo().cameraType + 1) % 7); + gScene->getSceneInfo().cameraType = static_cast( + (gScene->getSceneInfo().cameraType + 1) % 7); LOG_INFO(1, "Camera type: " << gScene->getSceneInfo().cameraType); break; } @@ -927,7 +972,9 @@ void keyboard(unsigned char key, int x, int y) { gScene->getSceneInfo().shadowIntensity += 0.05f; gScene->getSceneInfo().shadowIntensity = - (gScene->getSceneInfo().shadowIntensity > 1.f) ? 0.f : gScene->getSceneInfo().shadowIntensity; + (gScene->getSceneInfo().shadowIntensity > 1.f) + ? 0.f + : gScene->getSceneInfo().shadowIntensity; break; } case '+': @@ -1138,9 +1185,12 @@ void motion(int x, int y) // Changing camera angle gViewPos.z -= 50 * (mouse_old_y - y); gViewAngles.w -= 50 * (mouse_old_x - x); - LOG_INFO(1, "ViewPos = " << gViewPos.x << "," << gViewPos.y << "," << gViewPos.z); - LOG_INFO(1, "ViewDir = " << gViewDir.x << "," << gViewDir.y << "," << gViewDir.z); - LOG_INFO(1, "Eye Separation = " << gScene->getSceneInfo().eyeSeparation); + LOG_INFO(1, "ViewPos = " << gViewPos.x << "," << gViewPos.y + << "," << gViewPos.z); + LOG_INFO(1, "ViewDir = " << gViewDir.x << "," << gViewDir.y + << "," << gViewDir.z); + LOG_INFO(1, "Eye Separation = " + << gScene->getSceneInfo().eyeSeparation); break; } case ctGroundHeight: @@ -1166,7 +1216,8 @@ void motion(int x, int y) if (gAutoFocus) { // Autofocus - int index = gKernel->getPrimitiveAt(gKernel->getSceneInfo().size.x / 2, gKernel->getSceneInfo().size.y / 2); + int index = gKernel->getPrimitiveAt(gKernel->getSceneInfo().size.x / 2, + gKernel->getSceneInfo().size.y / 2); if (index != -1) { solr::CPUPrimitive *p = gKernel->getPrimitive(index); @@ -1179,6 +1230,7 @@ void motion(int x, int y) void Cleanup(int iExitCode) { + RandomGenerator::getInstance().close(); #ifdef WIN32 gTickCount = GetTickCount() - gTickCount; LOG_INFO(1, "Benchmark: " << gTickCount << " tick counts"); @@ -1220,41 +1272,49 @@ void createKinectScene(int platform, int device) USHORT RealDepth = (s & 0xfff8) >> 3; // Masque pour retrouver si un player a �t� detect� USHORT Player = s & 7; - // Transforme les informations de profondeur sur 13-Bit en une intensit� - // cod� sur 8 Bits + // Transforme les informations de profondeur sur 13-Bit en une + // intensit� cod� sur 8 Bits // afin d'afficher une couleur en fonction de la profondeur BYTE l = 255 - (BYTE)(256 * RealDepth / 0x0fff); int p = kernel.addPrimitive(ptSphere); - kernel.setPrimitive(p, 5 + p / gKinectNbSpherePerBox, (x - 160) * 100.f, (y - 120) * 100.f, 0.f, - gKinectStep * 10.f, 0.f, 0.f, 20 + x % 20, 1, 1); + kernel.setPrimitive(p, 5 + p / gKinectNbSpherePerBox, + (x - 160) * 100.f, (y - 120) * 100.f, 0.f, + gKinectStep * 10.f, 0.f, 0.f, 20 + x % 20, + 1, 1); } } } // Sol int s0 = kernel.addPrimitive(ptXZPlane); - kernel.setPrimitive(s0, 0, 0.f, -5000.f, 0.f, 10000.f, 0.f, 10000.f, 100, 1, 1); + kernel.setPrimitive(s0, 0, 0.f, -5000.f, 0.f, 10000.f, 0.f, 10000.f, 100, 1, + 1); // Wall int m_nbPrimitives = kernel.addPrimitive(ptXYPlane); - kernel.setPrimitive(m_nbPrimitives, 0, 0.f, 0.f, 5000.f, 5000.f, 5000.f, 0.f, 110, 1, 1); + kernel.setPrimitive(m_nbPrimitives, 0, 0.f, 0.f, 5000.f, 5000.f, 5000.f, + 0.f, 110, 1, 1); m_nbPrimitives = kernel.addPrimitive(ptYZPlane); - kernel.setPrimitive(m_nbPrimitives, 1, -5000.f, 0.f, 0.f, 0.f, 5000.f, 5000.f, 107, 1, 1); + kernel.setPrimitive(m_nbPrimitives, 1, -5000.f, 0.f, 0.f, 0.f, 5000.f, + 5000.f, 107, 1, 1); m_nbPrimitives = kernel.addPrimitive(ptYZPlane); - kernel.setPrimitive(m_nbPrimitives, 2, 5000.f, 0.f, 0.f, 0.f, 5000.f, 5000.f, 108, 1, 1); + kernel.setPrimitive(m_nbPrimitives, 2, 5000.f, 0.f, 0.f, 0.f, 5000.f, + 5000.f, 108, 1, 1); m_nbPrimitives = kernel.addPrimitive(ptXZPlane); - kernel.setPrimitive(m_nbPrimitives, 3, 0.f, 5000.f, 0.f, 5000.f, 0.f, 5000.f, 110, 1, 1); + kernel.setPrimitive(m_nbPrimitives, 3, 0.f, 5000.f, 0.f, 5000.f, 0.f, + 5000.f, 110, 1, 1); // Camera m_nbPrimitives = kernel.addPrimitive(ptCamera); - kernel.setPrimitive(m_nbPrimitives, 0, -2500.f, -4000.f, -5000.f, 1500.f, 1500.f, 0.f, DEFAULT_LIGHT_MATERIAL, 1, - 1); + kernel.setPrimitive(m_nbPrimitives, 0, -2500.f, -4000.f, -5000.f, 1500.f, + 1500.f, 0.f, DEFAULT_LIGHT_MATERIAL, 1, 1); // Lights gLampIndex = kernel.addPrimitive(ptSphere); - kernel.setPrimitive(gLampIndex, 4, -5000.f, 2000.f, -20000.f, 500, 0, 50, 128, 1, 1); + kernel.setPrimitive(gLampIndex, 4, -5000.f, 2000.f, -20000.f, 500, 0, 50, + 128, 1, 1); gNbBoxes = kernel.compactBoxes(); } @@ -1262,6 +1322,7 @@ void createKinectScene(int platform, int device) void createScene() { + RandomGenerator::getInstance().pause(); gAnimate = false; gHint = "Camera"; switch (gSceneId) @@ -1276,7 +1337,7 @@ void createScene() gScene = new MoleculeScene("Molecules"); break; case 4: - gScene = new FractalScene("Fractals"); + gScene = new HypercubeScene("Hypercubes"); break; case 5: gScene = new CylinderScene("Cylinders"); @@ -1312,12 +1373,16 @@ void createScene() case 15: gScene = new SwcScene("Neuroscience"); break; + case 16: + gScene = new FractalScene("Fractals"); + break; default: #ifdef _USE_KINECT gScene = new KinectFaceTrackingScene("Kinect Face Tracking"); break; #else - gScene = new PerpetualMotionScene("Perpetual Motion"); + gScene = new TesseractScene("Tesseract"); + // gScene = new PerpetualMotionScene("Perpetual Motion"); break; #endif } @@ -1326,6 +1391,7 @@ void createScene() gScene->setCurrentModel(m_counter); gScene->initialize(gKernel, gWindowWidth, gWindowHeight); gKernel->setCamera(gViewPos, gViewDir, gViewAngles); + RandomGenerator::getInstance().resume(); } int main(int argc, char *argv[]) @@ -1346,6 +1412,9 @@ int main(int argc, char *argv[]) createScene(); LOG_INFO(1, "Sol-R is happily running... (^_^)y"); + for (const auto &menuItem : menuItems) + LOG_INFO(3, menuItem.description); + glutMainLoop(); Cleanup(EXIT_SUCCESS); diff --git a/debug_tsdviewer.sh b/debug_tsdviewer.sh new file mode 100755 index 0000000..6466d2e --- /dev/null +++ b/debug_tsdviewer.sh @@ -0,0 +1,19 @@ +#!/bin/bash +# Debug script for tsdViewer with Sol-R ANARI device + +export LD_LIBRARY_PATH=/home/cfavreau/code/favreau/VisRTX/build/Debug:/home/cfavreau/code/favreau/Sol-R/build/Debug/devices/solr:$LD_LIBRARY_PATH +export TSD_ANARI_LIBRARIES=solr +export ANARI_LIBRARY_solr=/home/cfavreau/code/favreau/Sol-R/build/Debug/devices/solr/libanari_library_solr.so + +echo "Environment variables set:" +echo " LD_LIBRARY_PATH=$LD_LIBRARY_PATH" +echo " TSD_ANARI_LIBRARIES=$TSD_ANARI_LIBRARIES" +echo " ANARI_LIBRARY_solr=$ANARI_LIBRARY_solr" +echo "" +echo "Starting GDB..." + +gdb -ex "set environment LD_LIBRARY_PATH $LD_LIBRARY_PATH" \ + -ex "set environment TSD_ANARI_LIBRARIES solr" \ + -ex "set environment ANARI_LIBRARY_solr $ANARI_LIBRARY_solr" \ + /home/cfavreau/code/favreau/VisRTX/build/Debug/tsdViewer + diff --git a/devices/CMakeLists.txt b/devices/CMakeLists.txt new file mode 100644 index 0000000..f0e5904 --- /dev/null +++ b/devices/CMakeLists.txt @@ -0,0 +1,19 @@ +# Copyright (c) 2011-2022, Cyrille Favreau +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +option(SOLR_BUILD_ANARI_DEVICE "Build Sol-R ANARI device" ON) +if (SOLR_BUILD_ANARI_DEVICE) + add_subdirectory(solr) +endif() \ No newline at end of file diff --git a/devices/README.md b/devices/README.md new file mode 100644 index 0000000..ed5acf2 --- /dev/null +++ b/devices/README.md @@ -0,0 +1,61 @@ +# Sol-R ANARI Device + +This directory contains the ANARI device implementation for Sol-R, allowing Sol-R to be used as an ANARI-compliant ray tracing library. + +## Building with ANARI Support + +To build Sol-R with ANARI device support: + +1. Install the ANARI SDK: + ```bash + git clone https://github.com/KhronosGroup/ANARI-SDK.git + cd ANARI-SDK + mkdir build && cd build + cmake .. -DCMAKE_INSTALL_PREFIX=/path/to/anari-install + make -j && make install + ``` + +2. Configure Sol-R with ANARI enabled: + ```bash + cd Sol-R + mkdir build && cd build + cmake .. -DSOLR_BUILD_ANARI_DEVICE=ON -Danari_DIR=/path/to/anari-install/lib/cmake/anari + make -j + ``` + +## Using the Sol-R ANARI Device + +The Sol-R ANARI device can be used with any ANARI-compatible application: + +```cpp +#include + +// Load the Sol-R device library +ANARILibrary lib = anariLoadLibrary("solr", nullptr, nullptr); +ANARIDevice device = anariNewDevice(lib, "default"); + +// Use standard ANARI calls +ANARICamera camera = anariNewCamera(device, "perspective"); +ANARIRenderer renderer = anariNewRenderer(device, "pathtracer"); +// ... etc +``` + +## Supported Features + +The Sol-R ANARI device currently supports: + +- **Cameras**: perspective, orthographic +- **Geometries**: triangle, sphere, cylinder, cone +- **Materials**: matte, physically-based +- **Lights**: directional, point, spot +- **Renderers**: raycast, pathtracer + +## Device Parameters + +- `solr.engine`: Rendering engine to use ("cuda", "opencl", "cpu") +- `solr.samples`: Number of samples per pixel (1-1024) +- `solr.maxDepth`: Maximum ray depth (1-32) + +## Status + +This is an initial implementation providing basic ANARI device functionality. The implementation currently provides placeholder objects and will need to be extended to fully integrate with Sol-R's existing ray tracing pipeline. \ No newline at end of file diff --git a/devices/solr/CMakeLists.txt b/devices/solr/CMakeLists.txt new file mode 100644 index 0000000..4fa90e8 --- /dev/null +++ b/devices/solr/CMakeLists.txt @@ -0,0 +1,122 @@ +# Copyright (c) 2011-2022, Cyrille Favreau +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +include(GenerateExportHeader) +include(GNUInstallDirs) + +# Set policy for file(GENERATE) behavior +cmake_policy(SET CMP0070 NEW) + +## Establish project ## + +project(anari_library_solr VERSION ${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}.${${PROJECT_NAME}_VERSION_PATCH} LANGUAGES CXX) + +## Compilation setup ## + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +set(CMAKE_CXX_VISIBILITY_PRESET hidden) +set(CMAKE_VISIBILITY_INLINES_HIDDEN TRUE) + +## Find dependencies ## + +# We already have the solr library target available + +## Build library target ## + +set(SOURCES + Object.cpp + SolRDevice.cpp + SolRLibrary.cpp + Extensions.cpp + SimpleQueries.cpp +) + +add_library(${PROJECT_NAME} SHARED ${SOURCES}) + +# Ensure C++17 is properly enabled +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) + +generate_export_header(${PROJECT_NAME} + EXPORT_MACRO_NAME "SOLR_DEVICE_INTERFACE" +) + +target_include_directories(${PROJECT_NAME} +PUBLIC + $ + $ +PRIVATE + ${PROJECT_SOURCE_DIR}/solr + ${PROJECT_SOURCE_DIR}/generated +) + +target_link_libraries(${PROJECT_NAME} +PUBLIC + anari::anari +PRIVATE + anari::helium + # solr # TODO: Re-enable after fixing Sol-R CUDA compilation issues +) + +target_compile_definitions(${PROJECT_NAME} +PRIVATE + SOLR_VERSION_MAJOR=${SolR_VERSION_MAJOR} + SOLR_VERSION_MINOR=${SolR_VERSION_MINOR} + SOLR_VERSION_PATCH=${SolR_VERSION_PATCH} + solr_EXPORTS +) + +# Force C++17 to override Sol-R's C++11 setting +target_compile_options(${PROJECT_NAME} PRIVATE -std=c++17) + +## Query code generation ## +# Temporarily disable automatic generation due to C++ compatibility issues +# file(GLOB DEVICE_JSONS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.json") +# foreach(file ${DEVICE_JSONS}) +# configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${file} ${CMAKE_CURRENT_BINARY_DIR}/${file} COPYONLY) +# endforeach() + +# anari_generate_queries( +# DEVICE_TARGET ${PROJECT_NAME} +# CPP_NAMESPACE solr +# JSON_ROOT_LOCATION ${CMAKE_CURRENT_BINARY_DIR} +# JSON_DEFINITIONS_FILE ${CMAKE_CURRENT_BINARY_DIR}/solr_device.json +# JSON_EXTENSION_FILES ${DEVICE_JSONS} +# ) + +## Install library + headers ## + +install(TARGETS ${PROJECT_NAME} + EXPORT SolR_Exports + LIBRARY DESTINATION lib + # on Windows put the dlls into bin + RUNTIME DESTINATION bin + # ... and the import lib into the devel package + ARCHIVE DESTINATION lib +) + +install( +FILES + ${PROJECT_BINARY_DIR}/${PROJECT_NAME}_export.h +DESTINATION + include/anari/ext/solr +) + +install(EXPORT SolR_Exports + DESTINATION lib/cmake/SolR + NAMESPACE SolR:: +) \ No newline at end of file diff --git a/devices/solr/Extensions.cpp b/devices/solr/Extensions.cpp new file mode 100644 index 0000000..67efffa --- /dev/null +++ b/devices/solr/Extensions.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2011-2022, Cyrille Favreau + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +namespace solr +{ + +const char **query_extensions() +{ + static const char *extensions[] = {"KHR_CAMERA_ORTHOGRAPHIC", + "KHR_CAMERA_PERSPECTIVE", + "KHR_DEVICE_SYNCHRONIZATION", + "KHR_FRAME_ACCUMULATION", + "KHR_FRAME_COMPLETION_CALLBACK", + "KHR_GEOMETRY_TRIANGLE", + "KHR_GEOMETRY_SPHERE", + "KHR_GEOMETRY_CYLINDER", + "KHR_GEOMETRY_CONE", + "KHR_INSTANCE_TRANSFORM", + "KHR_LIGHT_DIRECTIONAL", + "KHR_LIGHT_POINT", + "KHR_LIGHT_SPOT", + "KHR_MATERIAL_MATTE", + "KHR_MATERIAL_PHYSICALLY_BASED", + "KHR_RENDERER_AMBIENT_LIGHT", + "KHR_RENDERER_BACKGROUND_COLOR", + "KHR_SAMPLER_IMAGE2D", + "KHR_SAMPLER_PRIMITIVE", + nullptr}; + return extensions; +} + +} // namespace solr \ No newline at end of file diff --git a/devices/solr/Object.cpp b/devices/solr/Object.cpp new file mode 100644 index 0000000..40a2d83 --- /dev/null +++ b/devices/solr/Object.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2011-2022, Cyrille Favreau + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "Object.h" +#include "helium/BaseDevice.h" + +namespace solr +{ + +Object::Object(ANARIDataType type, ANARIDevice device) + : helium::BaseObject(type, nullptr) // Pass nullptr when building ANARI + // device standalone + , m_device(device) +{ +} + +} // namespace solr \ No newline at end of file diff --git a/devices/solr/Object.h b/devices/solr/Object.h new file mode 100644 index 0000000..3e22e97 --- /dev/null +++ b/devices/solr/Object.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2011-2022, Cyrille Favreau + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +// helium +#include "helium/BaseObject.h" + +namespace solr +{ + +struct Object : public helium::BaseObject +{ + Object(ANARIDataType type, ANARIDevice device); + virtual ~Object() = default; + + virtual void commit() {} + + ANARIDevice deviceHandle() const; + +private: + ANARIDevice m_device{nullptr}; +}; + +// Inlined definitions //////////////////////////////////////////////////////// + +inline ANARIDevice Object::deviceHandle() const +{ + return m_device; +} + +} // namespace solr \ No newline at end of file diff --git a/devices/solr/SimpleQueries.cpp b/devices/solr/SimpleQueries.cpp new file mode 100644 index 0000000..d825e13 --- /dev/null +++ b/devices/solr/SimpleQueries.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2011-2022, Cyrille Favreau + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "anari/anari.h" + +namespace solr +{ + +const char **query_object_types(ANARIDataType type) +{ + static const char *cameras[] = {"perspective", "orthographic", nullptr}; + static const char *geometries[] = {"triangle", "sphere", nullptr}; + static const char *lights[] = {"directional", "point", nullptr}; + static const char *materials[] = {"matte", nullptr}; + static const char *renderers[] = {"raycast", "pathtracer", nullptr}; + static const char *empty[] = {nullptr}; + + switch (type) + { + case ANARI_CAMERA: + return cameras; + case ANARI_GEOMETRY: + return geometries; + case ANARI_LIGHT: + return lights; + case ANARI_MATERIAL: + return materials; + case ANARI_RENDERER: + return renderers; + default: + return empty; + } +} + +const void *query_object_info(ANARIDataType type, const char *name, + ANARIDataType infoType) +{ + // Simple implementation - just return nullptr for now + return nullptr; +} + +const void *query_param_info(ANARIDataType type, const char *name, + ANARIDataType paramType, const char *infoType) +{ + // Simple implementation - just return nullptr for now + return nullptr; +} + +} // namespace solr \ No newline at end of file diff --git a/devices/solr/SolRDevice.cpp b/devices/solr/SolRDevice.cpp new file mode 100644 index 0000000..e233481 --- /dev/null +++ b/devices/solr/SolRDevice.cpp @@ -0,0 +1,451 @@ +/* + * Copyright (c) 2011-2022, Cyrille Favreau + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "SolRDevice.h" +// std +#include + +// Disable verbose debug messages to avoid initialization issues +#define SOLR_VERBOSE_DEBUG 0 + +namespace solr +{ + +const char **query_extensions(); + +/////////////////////////////////////////////////////////////////////////////// +// Generated function declarations //////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// + +const char **query_object_types(ANARIDataType type); +const void *query_object_info(ANARIDataType type, const char *name, + ANARIDataType infoType); +const void *query_param_info(ANARIDataType type, const char *name, + ANARIDataType paramType, const char *infoType); + +/////////////////////////////////////////////////////////////////////////////// +// SolRDevice definitions ///////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// + +// Data Arrays //////////////////////////////////////////////////////////////// + +void *SolRDevice::mapArray(ANARIArray a) +{ +#if SOLR_VERBOSE_DEBUG +#if SOLR_VERBOSE_DEBUG + + reportMessage(ANARI_SEVERITY_DEBUG, "SolRDevice::mapArray called"); + +#endif +#endif + // For now, return a placeholder - implement based on Sol-R's memory + // management + return nullptr; +} + +void SolRDevice::unmapArray(ANARIArray a) +{ +#if SOLR_VERBOSE_DEBUG + + reportMessage(ANARI_SEVERITY_DEBUG, "SolRDevice::unmapArray called"); + +#endif + // Implement based on Sol-R's memory management +} + +ANARIArray1D SolRDevice::newArray1D(const void *appMemory, + ANARIMemoryDeleter deleter, + const void *deleterPtr, ANARIDataType type, + uint64_t numItems1) +{ +#if SOLR_VERBOSE_DEBUG + + reportMessage(ANARI_SEVERITY_DEBUG, "SolRDevice::newArray1D called"); + +#endif + // Return a placeholder array object - implement proper array handling + return (ANARIArray1D)this; +} + +ANARIArray2D SolRDevice::newArray2D(const void *appMemory, + ANARIMemoryDeleter deleter, + const void *deleterPtr, ANARIDataType type, + uint64_t numItems1, uint64_t numItems2) +{ +#if SOLR_VERBOSE_DEBUG + + reportMessage(ANARI_SEVERITY_DEBUG, "SolRDevice::newArray2D called"); + +#endif + return (ANARIArray2D)this; +} + +ANARIArray3D SolRDevice::newArray3D(const void *appMemory, + ANARIMemoryDeleter deleter, + const void *deleterPtr, ANARIDataType type, + uint64_t numItems1, uint64_t numItems2, + uint64_t numItems3) +{ +#if SOLR_VERBOSE_DEBUG + + reportMessage(ANARI_SEVERITY_DEBUG, "SolRDevice::newArray3D called"); + +#endif + return (ANARIArray3D)this; +} + +// Renderable Objects ///////////////////////////////////////////////////////// + +ANARICamera SolRDevice::newCamera(const char *type) +{ +#if SOLR_VERBOSE_DEBUG + + reportMessage(ANARI_SEVERITY_DEBUG, + "SolRDevice::newCamera called with type: %s", + type ? type : "NULL"); + +#endif + return (ANARICamera)this; +} + +ANARIFrame SolRDevice::newFrame() +{ +#if SOLR_VERBOSE_DEBUG + + reportMessage(ANARI_SEVERITY_DEBUG, "SolRDevice::newFrame called"); + +#endif + return (ANARIFrame)this; +} + +ANARIGeometry SolRDevice::newGeometry(const char *type) +{ +#if SOLR_VERBOSE_DEBUG + + reportMessage(ANARI_SEVERITY_DEBUG, + "SolRDevice::newGeometry called with type: %s", + type ? type : "NULL"); + +#endif + return (ANARIGeometry)this; +} + +ANARIGroup SolRDevice::newGroup() +{ +#if SOLR_VERBOSE_DEBUG + + reportMessage(ANARI_SEVERITY_DEBUG, "SolRDevice::newGroup called"); + +#endif + return (ANARIGroup)this; +} + +ANARIInstance SolRDevice::newInstance(const char *type) +{ +#if SOLR_VERBOSE_DEBUG + + reportMessage(ANARI_SEVERITY_DEBUG, + "SolRDevice::newInstance called with type: %s", + type ? type : "NULL"); + +#endif + return (ANARIInstance)this; +} + +ANARILight SolRDevice::newLight(const char *type) +{ +#if SOLR_VERBOSE_DEBUG + + reportMessage(ANARI_SEVERITY_DEBUG, + "SolRDevice::newLight called with type: %s", + type ? type : "NULL"); + +#endif + return (ANARILight)this; +} + +ANARIMaterial SolRDevice::newMaterial(const char *material_type) +{ +#if SOLR_VERBOSE_DEBUG + + reportMessage(ANARI_SEVERITY_DEBUG, + "SolRDevice::newMaterial called with type: %s", + material_type ? material_type : "NULL"); + +#endif + return (ANARIMaterial)this; +} + +ANARIRenderer SolRDevice::newRenderer(const char *type) +{ +#if SOLR_VERBOSE_DEBUG + + reportMessage(ANARI_SEVERITY_DEBUG, + "SolRDevice::newRenderer called with type: %s", + type ? type : "NULL"); + +#endif + return (ANARIRenderer)this; +} + +ANARISampler SolRDevice::newSampler(const char *type) +{ +#if SOLR_VERBOSE_DEBUG + + reportMessage(ANARI_SEVERITY_DEBUG, + "SolRDevice::newSampler called with type: %s", + type ? type : "NULL"); + +#endif + return (ANARISampler)this; +} + +ANARISpatialField SolRDevice::newSpatialField(const char *type) +{ +#if SOLR_VERBOSE_DEBUG + + reportMessage(ANARI_SEVERITY_DEBUG, + "SolRDevice::newSpatialField called with type: %s", + type ? type : "NULL"); + +#endif + return (ANARISpatialField)this; +} + +ANARISurface SolRDevice::newSurface() +{ +#if SOLR_VERBOSE_DEBUG + + reportMessage(ANARI_SEVERITY_DEBUG, "SolRDevice::newSurface called"); + +#endif + return (ANARISurface)this; +} + +ANARIVolume SolRDevice::newVolume(const char *type) +{ +#if SOLR_VERBOSE_DEBUG + + reportMessage(ANARI_SEVERITY_DEBUG, + "SolRDevice::newVolume called with type: %s", + type ? type : "NULL"); + +#endif + return (ANARIVolume)this; +} + +ANARIWorld SolRDevice::newWorld() +{ +#if SOLR_VERBOSE_DEBUG + + reportMessage(ANARI_SEVERITY_DEBUG, "SolRDevice::newWorld called"); + +#endif + return (ANARIWorld)this; +} + +// Object + Parameter Introspection /////////////////////////////////////////// + +void SolRDevice::commitParameters(ANARIObject object) +{ + if (this == (SolRDevice *)object) + { + deviceCommit(); + } +} + +void SolRDevice::release(ANARIObject _obj) +{ +#if SOLR_VERBOSE_DEBUG + + reportMessage(ANARI_SEVERITY_DEBUG, "SolRDevice::release called"); + +#endif + // For now, don't actually release anything since we're using placeholders +} + +int SolRDevice::getProperty(ANARIObject object, const char *name, + ANARIDataType type, void *mem, uint64_t size, + uint32_t mask) +{ +#if SOLR_VERBOSE_DEBUG + + reportMessage(ANARI_SEVERITY_DEBUG, "SolRDevice::getProperty called"); + +#endif + if (object == (ANARIObject)this) + { + return deviceGetProperty(name, type, mem, size, mask); + } + return 0; +} + +// Frame Operations //////////////////////////////////////////////////////////// + +void SolRDevice::renderFrame(ANARIFrame frame) +{ +#if SOLR_VERBOSE_DEBUG + + reportMessage(ANARI_SEVERITY_DEBUG, "SolRDevice::renderFrame called"); + +#endif + // Implement actual rendering using Sol-R + // SolRStub disabled when building ANARI device standalone + // This would integrate with Sol-R's rendering pipeline + // For now, just increment frame counter + m_frameCounter++; +} + +int SolRDevice::frameReady(ANARIFrame frame, ANARIWaitMask m) +{ +#if SOLR_VERBOSE_DEBUG + + reportMessage(ANARI_SEVERITY_DEBUG, "SolRDevice::frameReady called"); + +#endif + // For now, always return ready + return 1; +} + +void SolRDevice::discardFrame(ANARIFrame frame) +{ +#if SOLR_VERBOSE_DEBUG + + reportMessage(ANARI_SEVERITY_DEBUG, "SolRDevice::discardFrame called"); + +#endif + // Implement frame discard logic +} + +// Other SolRDevice definitions /////////////////////////////////////////////// + +SolRDevice::SolRDevice(ANARIStatusCallback defaultCallback, const void *userPtr) + : helium::BaseDevice(defaultCallback, userPtr) +{ + // SolRStub disabled when building ANARI device standalone + // m_solrStub = std::make_unique(); + // Note: deviceCommit() is called automatically by helium framework +} + +SolRDevice::SolRDevice(ANARILibrary library) + : helium::BaseDevice(library) +{ + // SolRStub disabled when building ANARI device standalone + // m_solrStub = std::make_unique(); + // Note: deviceCommit() is called automatically by helium framework +} + +SolRDevice::~SolRDevice() +{ +#if SOLR_VERBOSE_DEBUG + + reportMessage(ANARI_SEVERITY_DEBUG, "SolRDevice destroyed"); + +#endif +} + +void SolRDevice::initDevice() +{ + if (m_initStatus != DeviceInitStatus::UNINITIALIZED) + return; + + try + { + // SolRStub disabled when building ANARI device standalone + m_initStatus = DeviceInitStatus::SUCCESS; + } + catch (const std::exception &e) + { + m_initStatus = DeviceInitStatus::FAILURE; + } +} + +void SolRDevice::deviceCommit() +{ + initDevice(); + + // Note: Initialization status checking moved to after device is fully + // initialized +} + +int SolRDevice::deviceGetProperty(const char *name, ANARIDataType type, + void *mem, uint64_t size, uint32_t mask) +{ + if (!name || !mem) + return 0; + + std::string prop = name; + if (prop == "feature" && type == ANARI_STRING_LIST) + { + *(const char ***)mem = query_extensions(); + return 1; + } + else if (prop == "solr" && type == ANARI_BOOL) + { + *(bool *)mem = true; + return 1; + } + else if (prop == "version" && type == ANARI_STRING) + { + *(const char **)mem = "0.1.0"; + return 1; + } + else if (type == ANARI_STRING_LIST) + { + // Return empty list for unknown string list properties + static const char *empty_list[] = {nullptr}; + *(const char ***)mem = empty_list; + return 1; + } + + return 0; +} + +void SolRDevice::flushCommitBuffer() +{ + // This method can be used to batch commits if needed +} + +// SolRStub *SolRDevice::getSolRStub() const +// { +// return m_solrStub.get(); +// } + +const char **SolRDevice::getObjectSubtypes(ANARIDataType objectType) +{ + return query_object_types(objectType); +} + +const void *SolRDevice::getObjectInfo(ANARIDataType objectType, + const char *objectSubtype, + const char *infoName, + ANARIDataType infoType) +{ + return query_object_info(objectType, objectSubtype, infoType); +} + +const void *SolRDevice::getParameterInfo(ANARIDataType objectType, + const char *objectSubtype, + const char *parameterName, + ANARIDataType parameterType, + const char *infoName, + ANARIDataType infoType) +{ + return query_param_info(objectType, objectSubtype, parameterType, infoName); +} + +} // namespace solr \ No newline at end of file diff --git a/devices/solr/SolRDevice.h b/devices/solr/SolRDevice.h new file mode 100644 index 0000000..6b48154 --- /dev/null +++ b/devices/solr/SolRDevice.h @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2011-2022, Cyrille Favreau + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +// helium +#include "helium/BaseDevice.h" +// solr +// #include "SolRStub.h" // Disabled when building ANARI device standalone +// std +#include +#include + +namespace solr +{ + +enum class DeviceInitStatus +{ + UNINITIALIZED, + SUCCESS, + FAILURE +}; + +struct SolRDevice : public helium::BaseDevice +{ + ///////////////////////////////////////////////////////////////////////////// + // Main interface to accepting API calls + ///////////////////////////////////////////////////////////////////////////// + + void *mapArray(ANARIArray) override; + void unmapArray(ANARIArray) override; + + ANARIArray1D newArray1D(const void *appMemory, ANARIMemoryDeleter deleter, + const void *deleterPtr, ANARIDataType, + uint64_t numItems1) override; + + ANARIArray2D newArray2D(const void *appMemory, ANARIMemoryDeleter deleter, + const void *deleterPtr, ANARIDataType, + uint64_t numItems1, uint64_t numItems2) override; + + ANARIArray3D newArray3D(const void *appMemory, ANARIMemoryDeleter deleter, + const void *deleterPtr, ANARIDataType, + uint64_t numItems1, uint64_t numItems2, + uint64_t numItems3) override; + + ANARICamera newCamera(const char *type) override; + ANARIFrame newFrame() override; + ANARIGeometry newGeometry(const char *type) override; + ANARIGroup newGroup() override; + ANARIInstance newInstance(const char *type) override; + ANARILight newLight(const char *type) override; + ANARIMaterial newMaterial(const char *material_type) override; + ANARIRenderer newRenderer(const char *type) override; + ANARISampler newSampler(const char *type) override; + ANARISpatialField newSpatialField(const char *type) override; + ANARISurface newSurface() override; + ANARIVolume newVolume(const char *type) override; + ANARIWorld newWorld() override; + + // Commit and release + void commitParameters(ANARIObject object) override; + void release(ANARIObject _obj) override; + + // Object + Parameter Introspection + int getProperty(ANARIObject object, const char *name, ANARIDataType type, + void *mem, uint64_t size, uint32_t mask) override; + + // Frame operations + void renderFrame(ANARIFrame) override; + int frameReady(ANARIFrame, ANARIWaitMask) override; + void discardFrame(ANARIFrame) override; + + ///////////////////////////////////////////////////////////////////////////// + // Helper/other functions and data members + ///////////////////////////////////////////////////////////////////////////// + + SolRDevice(ANARIStatusCallback defaultCallback, const void *userPtr); + SolRDevice(ANARILibrary library); + + ~SolRDevice() override; + + void initDevice(); + + int deviceGetProperty(const char *name, ANARIDataType type, void *mem, + uint64_t size, uint32_t mask) override; + + void deviceCommit(); + + void flushCommitBuffer(); + + // ANARI interface requirements + const char **getObjectSubtypes(ANARIDataType objectType) override; + const void *getObjectInfo(ANARIDataType objectType, + const char *objectSubtype, const char *infoName, + ANARIDataType infoType) override; + const void *getParameterInfo(ANARIDataType objectType, + const char *objectSubtype, + const char *parameterName, + ANARIDataType parameterType, + const char *infoName, + ANARIDataType infoType) override; + + // SolRStub *getSolRStub() const; // Disabled when building ANARI device + // standalone + +private: + DeviceInitStatus m_initStatus{DeviceInitStatus::UNINITIALIZED}; + // std::unique_ptr m_solrStub; // Disabled when building ANARI + // device standalone + + // Device state + std::atomic m_frameCounter{0}; +}; + +} // namespace solr \ No newline at end of file diff --git a/devices/solr/SolRLibrary.cpp b/devices/solr/SolRLibrary.cpp new file mode 100644 index 0000000..71b019c --- /dev/null +++ b/devices/solr/SolRLibrary.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2011-2022, Cyrille Favreau + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "SolRDevice.h" +#include "anari/backend/LibraryImpl.h" +#include "anari_library_solr_export.h" + +namespace solr +{ + +const char **query_extensions(); + +struct SolRLibrary : public anari::LibraryImpl +{ + SolRLibrary(void *lib, ANARIStatusCallback defaultStatusCB, + const void *statusCBPtr); + + ANARIDevice newDevice(const char *subtype) override; + const char **getDeviceExtensions(const char *deviceType) override; +}; + +// Definitions //////////////////////////////////////////////////////////////// + +SolRLibrary::SolRLibrary(void *lib, ANARIStatusCallback defaultStatusCB, + const void *statusCBPtr) + : anari::LibraryImpl(lib, defaultStatusCB, statusCBPtr) +{ +} + +ANARIDevice SolRLibrary::newDevice(const char * /*subtype*/) +{ + return (ANARIDevice) new SolRDevice(this_library()); +} + +const char **SolRLibrary::getDeviceExtensions(const char * /*deviceType*/) +{ + return query_extensions(); +} + +} // namespace solr + +// Define library entrypoint ////////////////////////////////////////////////// + +extern "C" SOLR_DEVICE_INTERFACE ANARI_DEFINE_LIBRARY_ENTRYPOINT(solr, handle, + scb, scbPtr) +{ + return (ANARILibrary) new solr::SolRLibrary(handle, scb, scbPtr); +} + +extern "C" SOLR_DEVICE_INTERFACE ANARIDevice + makeSolRDevice(ANARIStatusCallback defaultCallback, const void *userPtr) +{ + return (ANARIDevice) new solr::SolRDevice(defaultCallback, userPtr); +} \ No newline at end of file diff --git a/devices/solr/solr_device.json b/devices/solr/solr_device.json new file mode 100644 index 0000000..6c25785 --- /dev/null +++ b/devices/solr/solr_device.json @@ -0,0 +1,380 @@ +{ + "info": { + "name": "SOLR_DEVICE", + "type": "device", + "dependencies": [ + "anari_core_1_0", + "anari_core_objects_base_1_0", + "khr_camera_orthographic", + "khr_camera_perspective", + "khr_device_synchronization", + "khr_frame_accumulation", + "khr_frame_completion_callback", + "khr_geometry_triangle", + "khr_geometry_sphere", + "khr_geometry_cylinder", + "khr_geometry_cone", + "khr_instance_transform", + "khr_light_directional", + "khr_light_point", + "khr_light_spot", + "khr_material_matte", + "khr_material_physically_based", + "khr_renderer_ambient_light", + "khr_renderer_background_color", + "khr_sampler_image2d", + "khr_sampler_primitive" + ] + }, + "parameters": [ + { + "name": "solr.engine", + "types": [ + "ANARI_STRING" + ], + "tags": [], + "default": "cuda", + "description": "Specify the Sol-R rendering engine to use" + }, + { + "name": "solr.samples", + "types": [ + "ANARI_INT32" + ], + "tags": [], + "default": 1, + "minimum": 1, + "maximum": 1024, + "description": "Number of samples per pixel" + }, + { + "name": "solr.maxDepth", + "types": [ + "ANARI_INT32" + ], + "tags": [], + "default": 5, + "minimum": 1, + "maximum": 32, + "description": "Maximum ray depth" + } + ], + "objects": [ + { + "type": "ANARI_CAMERA", + "name": "perspective", + "parameters": [ + { + "name": "aspect", + "types": [ + "ANARI_FLOAT32" + ], + "tags": [], + "default": 1.0 + }, + { + "name": "fovy", + "types": [ + "ANARI_FLOAT32" + ], + "tags": [], + "default": 1.0472 + }, + { + "name": "position", + "types": [ + "ANARI_FLOAT32_VEC3" + ], + "tags": [], + "default": [ + 0.0, + 0.0, + 0.0 + ] + }, + { + "name": "direction", + "types": [ + "ANARI_FLOAT32_VEC3" + ], + "tags": [], + "default": [ + 0.0, + 0.0, + -1.0 + ] + }, + { + "name": "up", + "types": [ + "ANARI_FLOAT32_VEC3" + ], + "tags": [], + "default": [ + 0.0, + 1.0, + 0.0 + ] + } + ] + }, + { + "type": "ANARI_CAMERA", + "name": "orthographic", + "parameters": [ + { + "name": "aspect", + "types": [ + "ANARI_FLOAT32" + ], + "tags": [], + "default": 1.0 + }, + { + "name": "height", + "types": [ + "ANARI_FLOAT32" + ], + "tags": [], + "default": 1.0 + }, + { + "name": "position", + "types": [ + "ANARI_FLOAT32_VEC3" + ], + "tags": [], + "default": [ + 0.0, + 0.0, + 0.0 + ] + }, + { + "name": "direction", + "types": [ + "ANARI_FLOAT32_VEC3" + ], + "tags": [], + "default": [ + 0.0, + 0.0, + -1.0 + ] + }, + { + "name": "up", + "types": [ + "ANARI_FLOAT32_VEC3" + ], + "tags": [], + "default": [ + 0.0, + 1.0, + 0.0 + ] + } + ] + }, + { + "type": "ANARI_GEOMETRY", + "name": "triangle", + "parameters": [ + { + "name": "vertex.position", + "types": [ + "ANARI_ARRAY1D" + ], + "elementType": "ANARI_FLOAT32_VEC3", + "tags": [] + }, + { + "name": "vertex.normal", + "types": [ + "ANARI_ARRAY1D" + ], + "elementType": "ANARI_FLOAT32_VEC3", + "tags": [] + }, + { + "name": "vertex.color", + "types": [ + "ANARI_ARRAY1D" + ], + "elementType": "ANARI_FLOAT32_VEC4", + "tags": [] + }, + { + "name": "primitive.index", + "types": [ + "ANARI_ARRAY1D" + ], + "elementType": "ANARI_UINT32_VEC3", + "tags": [] + } + ] + }, + { + "type": "ANARI_GEOMETRY", + "name": "sphere", + "parameters": [ + { + "name": "vertex.position", + "types": [ + "ANARI_ARRAY1D" + ], + "elementType": "ANARI_FLOAT32_VEC3", + "tags": [] + }, + { + "name": "vertex.radius", + "types": [ + "ANARI_ARRAY1D" + ], + "elementType": "ANARI_FLOAT32", + "tags": [] + } + ] + }, + { + "type": "ANARI_LIGHT", + "name": "directional", + "parameters": [ + { + "name": "direction", + "types": [ + "ANARI_FLOAT32_VEC3" + ], + "tags": [], + "default": [ + 0.0, + 0.0, + -1.0 + ] + }, + { + "name": "color", + "types": [ + "ANARI_FLOAT32_VEC3" + ], + "tags": [], + "default": [ + 1.0, + 1.0, + 1.0 + ] + }, + { + "name": "intensity", + "types": [ + "ANARI_FLOAT32" + ], + "tags": [], + "default": 1.0 + } + ] + }, + { + "type": "ANARI_LIGHT", + "name": "point", + "parameters": [ + { + "name": "position", + "types": [ + "ANARI_FLOAT32_VEC3" + ], + "tags": [], + "default": [ + 0.0, + 0.0, + 0.0 + ] + }, + { + "name": "color", + "types": [ + "ANARI_FLOAT32_VEC3" + ], + "tags": [], + "default": [ + 1.0, + 1.0, + 1.0 + ] + }, + { + "name": "intensity", + "types": [ + "ANARI_FLOAT32" + ], + "tags": [], + "default": 1.0 + } + ] + }, + { + "type": "ANARI_MATERIAL", + "name": "matte", + "parameters": [ + { + "name": "color", + "types": [ + "ANARI_FLOAT32_VEC3" + ], + "tags": [], + "default": [ + 0.8, + 0.8, + 0.8 + ] + } + ] + }, + { + "type": "ANARI_RENDERER", + "name": "raycast", + "parameters": [ + { + "name": "background", + "types": [ + "ANARI_FLOAT32_VEC4" + ], + "tags": [], + "default": [ + 0.0, + 0.0, + 0.0, + 1.0 + ] + } + ] + }, + { + "type": "ANARI_RENDERER", + "name": "pathtracer", + "parameters": [ + { + "name": "background", + "types": [ + "ANARI_FLOAT32_VEC4" + ], + "tags": [], + "default": [ + 0.0, + 0.0, + 0.0, + 1.0 + ] + }, + { + "name": "samples", + "types": [ + "ANARI_INT32" + ], + "tags": [], + "default": 1 + } + ] + } + ] +} \ No newline at end of file diff --git a/doc/images/Sol-R_001.png b/doc/images/Sol-R_001.png index bb57eb1..4f7fd88 100644 Binary files a/doc/images/Sol-R_001.png and b/doc/images/Sol-R_001.png differ diff --git a/doc/images/Sol-R_002.png b/doc/images/Sol-R_002.png index eea8f57..cde09bf 100644 Binary files a/doc/images/Sol-R_002.png and b/doc/images/Sol-R_002.png differ diff --git a/doc/images/Sol-R_003.png b/doc/images/Sol-R_003.png deleted file mode 100644 index 7fb7989..0000000 Binary files a/doc/images/Sol-R_003.png and /dev/null differ diff --git a/doc/images/Sol-R_004.png b/doc/images/Sol-R_004.png deleted file mode 100644 index 10bb38c..0000000 Binary files a/doc/images/Sol-R_004.png and /dev/null differ diff --git a/doc/images/Sol-R_005.png b/doc/images/Sol-R_005.png deleted file mode 100644 index 949a135..0000000 Binary files a/doc/images/Sol-R_005.png and /dev/null differ diff --git a/doc/images/Sol-R_006.png b/doc/images/Sol-R_006.png deleted file mode 100644 index 7649ffe..0000000 Binary files a/doc/images/Sol-R_006.png and /dev/null differ diff --git a/doc/images/Sol-R_007.png b/doc/images/Sol-R_007.png deleted file mode 100644 index 22ad114..0000000 Binary files a/doc/images/Sol-R_007.png and /dev/null differ diff --git a/doc/images/Sol-R_008.png b/doc/images/Sol-R_008.png deleted file mode 100644 index 839b2a4..0000000 Binary files a/doc/images/Sol-R_008.png and /dev/null differ diff --git a/doc/images/Sol-R_009.png b/doc/images/Sol-R_009.png deleted file mode 100644 index 6fb0817..0000000 Binary files a/doc/images/Sol-R_009.png and /dev/null differ diff --git a/doc/images/Sol-R_010.png b/doc/images/Sol-R_010.png deleted file mode 100644 index b14ed37..0000000 Binary files a/doc/images/Sol-R_010.png and /dev/null differ diff --git a/medias/hdri/0000.jpg b/medias/hdri/0000.jpg index 5e086b7..47fc4c0 100644 Binary files a/medias/hdri/0000.jpg and b/medias/hdri/0000.jpg differ diff --git a/medias/hdri/0001.jpg b/medias/hdri/0001.jpg index 12cfbb9..ec2e9a7 100644 Binary files a/medias/hdri/0001.jpg and b/medias/hdri/0001.jpg differ diff --git a/medias/hdri/0002.jpg b/medias/hdri/0002.jpg index a1534cc..6ddcb0e 100644 Binary files a/medias/hdri/0002.jpg and b/medias/hdri/0002.jpg differ diff --git a/medias/hdri/1000.jpg b/medias/hdri/1000.jpg new file mode 100644 index 0000000..5e086b7 Binary files /dev/null and b/medias/hdri/1000.jpg differ diff --git a/medias/hdri/1001.jpg b/medias/hdri/1001.jpg new file mode 100644 index 0000000..12cfbb9 Binary files /dev/null and b/medias/hdri/1001.jpg differ diff --git a/medias/hdri/1002.jpg b/medias/hdri/1002.jpg new file mode 100644 index 0000000..a1534cc Binary files /dev/null and b/medias/hdri/1002.jpg differ diff --git a/run_tsdviewer.sh b/run_tsdviewer.sh new file mode 100755 index 0000000..3583c98 --- /dev/null +++ b/run_tsdviewer.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# Run script for tsdViewer with Sol-R ANARI device + +export LD_LIBRARY_PATH=/home/cfavreau/code/favreau/VisRTX/build/Debug:/home/cfavreau/code/favreau/Sol-R/build/Debug/devices/solr:$LD_LIBRARY_PATH +export TSD_ANARI_LIBRARIES=solr +export ANARI_LIBRARY_solr=/home/cfavreau/code/favreau/Sol-R/build/Debug/devices/solr/libanari_library_solr.so + +echo "Environment variables set:" +echo " LD_LIBRARY_PATH=$LD_LIBRARY_PATH" +echo " TSD_ANARI_LIBRARIES=$TSD_ANARI_LIBRARIES" +echo " ANARI_LIBRARY_solr=$ANARI_LIBRARY_solr" +echo "" +echo "Starting tsdViewer..." +echo "" + +/home/cfavreau/code/favreau/VisRTX/build/Debug/tsdViewer "$@" + diff --git a/solr/CMakeLists.txt b/solr/CMakeLists.txt index 797d5cc..a819100 100644 --- a/solr/CMakeLists.txt +++ b/solr/CMakeLists.txt @@ -1,52 +1,89 @@ +# Copyright (c) 2011-2022, Cyrille Favreau +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + include_directories(${PROJECT_SOURCE_DIR}/solr ${PROJECT_SOURCE_DIR}/generated) SET(SOLR_SOURCES - DLL_API.h - Logging.h - types.h - Consts.h SolRStub.cpp - SolRStub.h + engines/random/RandomGenerator.cpp engines/GPUKernel.cpp - engines/GPUKernel.h #engines/cpu/CPUKernel.cpp - #engines/cpu/CPUKernel.h io/PDBReader.cpp - io/PDBReader.h io/OBJReader.cpp - io/OBJReader.h - io/FileMarshaller.cpp io/SWCReader.cpp - io/SWCReader.h io/FileMarshaller.cpp - io/FileMarshaller.h images/ImageLoader.cpp - images/ImageLoader.h images/jpge.cpp - images/jpge.h images/jpgd.cpp - images/jpgd.h images/tgad.cpp - images/tgad.h opengl/rtgl.cpp - opengl/rtgl.h games/MapReader.cpp +) + +SET(SOLR_HEADERS + Logging.h + SolRStub.h + engines/random/RandomGenerator.h + engines/GPUKernel.h + #engines/cpu/CPUKernel.h + io/PDBReader.h + io/OBJReader.h + io/SWCReader.h + io/FileMarshaller.h + images/ImageLoader.h + images/jpge.h + images/jpgd.h + images/tgad.h + opengl/rtgl.h games/MapReader.h ) +SET(SOLR_PUBLIC_HEADERS + ../generated/solr_defines.h + engines/GPUKernel.h + api.h + solr.h + consts.h +) + +SET(SOLR_ENGINE_PUBLIC_HEADERS + engines/GPUKernel.h +) + +unset(SOLR_ENGINE_LIBRARIES) + +# TODO: Include random number device library +#if( ... _FOUND) +# SET(SOLR_ENGINE_LIBRARIES ${ ... _LIBRARY}) +#endif( ... _FOUND) + if (CUDA_FOUND) if(UNIX) set(CUDA_NVCC_USER_ARGS + -std=c++11 -D_FORCE_INLINES + --compiler-options "-fPIC" --maxrregcount=32 --use_fast_math - -gencode=arch=compute_30,code=sm_30 - -gencode=arch=compute_35,code=sm_35 - -gencode=arch=compute_50,code=sm_50 -gencode=arch=compute_52,code=sm_52 + -gencode=arch=compute_60,code=sm_60 + -gencode=arch=compute_70,code=sm_70 + -gencode=arch=compute_80,code=sm_80 ) else(UNIX) - CUDA_SELECT_NVCC_ARCH_FLAGS(ARCH_FLAGS 3.0 3.5 5.0 5.2 6.0 6.1) + CUDA_SELECT_NVCC_ARCH_FLAGS(ARCH_FLAGS 3.0 3.5 5.0 5.2 6.0 6.1 7.0 8.0 8.9) set(CUDA_NVCC_USER_ARGS -D_FORCE_INLINES --maxrregcount=32 --use_fast_math) endif(UNIX) @@ -78,7 +115,9 @@ if (CUDA_FOUND) ${KINECT_LIBRARIES} ${OCULUS_SDK_LIBRARIES} ${SIXENSESDK_LIBRARIES} - ) + ${SOLR_ENGINE_LIBRARIES} + ) + list(APPEND SOLR_ENGINE_PUBLIC_HEADERS engines/cuda/CudaKernel.h) endif() if(OPENCL_FOUND) @@ -88,6 +127,9 @@ if(OPENCL_FOUND) engines/opencl/RayTracer.cl ${SOLR_SOURCES}) + # __STRICT_ANSI__ needs to be undefined for OpenCL to access x,y,z members of cl_float2/3/.. types + target_compile_options(solr PRIVATE -U__STRICT_ANSI__) + TARGET_LINK_LIBRARIES( solr ${OPENCL_LIBRARIES} @@ -97,11 +139,15 @@ if(OPENCL_FOUND) ${KINECT_LIBRARIES} ${OCULUS_SDK_LIBRARIES} ${SIXENSESDK_LIBRARIES} - ) + ${SOLR_ENGINE_LIBRARIES} + ) + # ================================================================================ # Install kernels # ================================================================================ INSTALL( FILES engines/opencl/RayTracer.cl DESTINATION bin/kernels ) + + list(APPEND SOLR_ENGINE_PUBLIC_HEADERS engines/opencl/OpenCLKernel.h) endif() # ================================================================================ @@ -111,3 +157,6 @@ INSTALL(TARGETS solr RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) +# Install headers +INSTALL( FILES ${SOLR_PUBLIC_HEADERS} DESTINATION include/solr ) +INSTALL( FILES ${SOLR_ENGINE_PUBLIC_HEADERS} DESTINATION include/solr/engines ) diff --git a/solr/DLL_API.h b/solr/DLL_API.h deleted file mode 100644 index 3a3d25c..0000000 --- a/solr/DLL_API.h +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau - * - * This file is part of Sol-R - * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#pragma once - -#pragma warning(disable : 4251) -#pragma warning(disable : 4996) -#pragma warning(disable : 4244) // Oculus DK1 SDK - -#ifdef WIN32 -#define SOLR_API __declspec(dllexport) -#else -#define SOLR_API -#endif diff --git a/solr/Logging.h b/solr/Logging.h index 4caf5ce..9d819a0 100644 --- a/solr/Logging.h +++ b/solr/Logging.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once @@ -51,30 +48,34 @@ inline std::string getTimestamp() #ifdef WIN32 #if 0 -#define LOG_INFO(__level, __msg) \ - { \ - if (__level == 1) \ - std::cout << getTimestamp() << " INFO [" << __level << "] " << __msg << std::endl; \ +#define LOG_INFO(__level, __msg) \ + { \ + if (__level == 1) \ + std::cout << getTimestamp() << " INFO [" << __level << "] " \ + << __msg << std::endl; \ } -#define LOG_ERROR(__msg) std::cout << getTimestamp() << " ERROR [1] " << __msg << std::endl; +#define LOG_ERROR(__msg) \ + std::cout << getTimestamp() << " ERROR [1] " << __msg << std::endl; #else -#define LOG_INFO(__level, __msg) \ - { \ - if (__level == 1) \ - { \ - std::stringstream __s; \ - __s << getTimestamp() << " [" << GetCurrentThreadId() << "] [INFO] " << __msg; \ - OutputDebugString(__s.str().c_str()); \ - std::cout << "[INFO ] " << __s.str() << std::endl; \ - } \ +#define LOG_INFO(__level, __msg) \ + { \ + if (__level == 1) \ + { \ + std::stringstream __s; \ + __s << getTimestamp() << " [" << GetCurrentThreadId() \ + << "] [INFO] " << __msg; \ + OutputDebugString(__s.str().c_str()); \ + std::cout << "[INFO ] " << __s.str() << std::endl; \ + } \ } -#define LOG_ERROR(__msg) \ - { \ - std::stringstream __s; \ - __s << getTimestamp() << " [" << GetCurrentThreadId() << "] [ERROR] " << __msg; \ - OutputDebugString(__s.str().c_str()); \ - std::cerr << "[ERROR] " << __s.str() << std::endl; \ +#define LOG_ERROR(__msg) \ + { \ + std::stringstream __s; \ + __s << getTimestamp() << " [" << GetCurrentThreadId() << "] [ERROR] " \ + << __msg; \ + OutputDebugString(__s.str().c_str()); \ + std::cerr << "[ERROR] " << __s.str() << std::endl; \ } #endif // 0 #else diff --git a/solr/SolRStub.cpp b/solr/SolRStub.cpp index 2c75255..78ff265 100644 --- a/solr/SolRStub.cpp +++ b/solr/SolRStub.cpp @@ -1,32 +1,29 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma warning(disable : 4996) -#include "types.h" -#include "Logging.h" #include "SolRStub.h" +#include "Logging.h" #include "engines/GPUKernel.h" #include "io/FileMarshaller.h" #include "io/OBJReader.h" #include "io/PDBReader.h" +#include "solr.h" #include @@ -34,6 +31,8 @@ #include #endif +using namespace solr; + SceneInfo gSceneInfoStub; PostProcessingInfo gPostProcessingInfoStub; @@ -45,22 +44,27 @@ int SolR_SetSceneInfo1() return 0; } -extern "C" SOLR_API int SolR_SetSceneInfo(int width, int height, int graphicsLevel, int nbRayIterations, - double transparentColor, double viewDistance, double shadowIntensity, - double eyeSeparation, double bgColorR, double bgColorG, double bgColorB, - double bgColorA, int renderBoxes, int pathTracingIteration, - int maxPathTracingIterations, int frameBufferType, int timestamp, - int atmosphericEffect, int cameraType, int doubleSidedTriangles, - int extendedGeometry, int advancedIllumination, int skyboxSize, - int skyboxMaterialId, double geometryEpsilon, double rayEpsilon) -{ - LOG_INFO(3, "SolR_SetSceneInfo (" << width << "," << height << "," << graphicsLevel << "," << nbRayIterations << "," - << transparentColor << "," << viewDistance << "," << shadowIntensity << "," - << eyeSeparation << "," << bgColorR << "," << bgColorG << "," << bgColorB << "," - << bgColorA << "," << cameraType << "," << renderBoxes << "," - << pathTracingIteration << "," << maxPathTracingIterations << "," - << frameBufferType << "," << timestamp << "," << atmosphericEffect << "," - << cameraType << "," << geometryEpsilon << "," << rayEpsilon); +extern "C" SOLR_API int SolR_SetSceneInfo( + int width, int height, int graphicsLevel, int nbRayIterations, + double transparentColor, double viewDistance, double shadowIntensity, + double eyeSeparation, double bgColorR, double bgColorG, double bgColorB, + double bgColorA, int renderBoxes, int pathTracingIteration, + int maxPathTracingIterations, int frameBufferType, int timestamp, + int atmosphericEffect, int cameraType, int doubleSidedTriangles, + int extendedGeometry, int advancedIllumination, int skyboxSize, + int skyboxMaterialId, double geometryEpsilon, double rayEpsilon) +{ + LOG_INFO(3, "SolR_SetSceneInfo (" + << width << "," << height << "," << graphicsLevel << "," + << nbRayIterations << "," << transparentColor << "," + << viewDistance << "," << shadowIntensity << "," + << eyeSeparation << "," << bgColorR << "," << bgColorG + << "," << bgColorB << "," << bgColorA << "," << cameraType + << "," << renderBoxes << "," << pathTracingIteration << "," + << maxPathTracingIterations << "," << frameBufferType << "," + << timestamp << "," << atmosphericEffect << "," + << cameraType << "," << geometryEpsilon << "," + << rayEpsilon); gSceneInfoStub.size.x = width; gSceneInfoStub.size.y = height; @@ -77,13 +81,16 @@ extern "C" SOLR_API int SolR_SetSceneInfo(int width, int height, int graphicsLev gSceneInfoStub.renderBoxes = static_cast(renderBoxes); gSceneInfoStub.pathTracingIteration = pathTracingIteration; gSceneInfoStub.maxPathTracingIterations = maxPathTracingIterations; - gSceneInfoStub.frameBufferType = static_cast(frameBufferType); + gSceneInfoStub.frameBufferType = + static_cast(frameBufferType); gSceneInfoStub.timestamp = timestamp; - gSceneInfoStub.atmosphericEffect = static_cast(atmosphericEffect); + gSceneInfoStub.atmosphericEffect = + static_cast(atmosphericEffect); gSceneInfoStub.cameraType = static_cast(cameraType); gSceneInfoStub.doubleSidedTriangles = doubleSidedTriangles; gSceneInfoStub.extendedGeometry = extendedGeometry; - gSceneInfoStub.advancedIllumination = static_cast(advancedIllumination); + gSceneInfoStub.advancedIllumination = + static_cast(advancedIllumination); gSceneInfoStub.skyboxRadius = skyboxSize; gSceneInfoStub.skyboxMaterialId = skyboxMaterialId; @@ -92,7 +99,8 @@ extern "C" SOLR_API int SolR_SetSceneInfo(int width, int height, int graphicsLev return 0; } -int SolR_SetPostProcessingInfo(int type, double param1, double param2, int param3) +int SolR_SetPostProcessingInfo(int type, double param1, double param2, + int param3) { LOG_INFO(3, "SolR_SetPostProcessingInfo"); gPostProcessingInfoStub.type = type; @@ -139,14 +147,20 @@ int SolR_ResetKernel() } // -------------------------------------------------------------------------------- -void SolR_SetCamera(double eye_x, double eye_y, double eye_z, double dir_x, double dir_y, double dir_z, double angle_x, - double angle_y, double angle_z) +void SolR_SetCamera(double eye_x, double eye_y, double eye_z, double dir_x, + double dir_y, double dir_z, double angle_x, double angle_y, + double angle_z) { LOG_INFO(3, "SolR_SetCamera"); - const vec3f eye = make_vec3f(static_cast(eye_x), static_cast(eye_y), static_cast(eye_z)); - const vec3f dir = make_vec3f(static_cast(dir_x), static_cast(dir_y), static_cast(dir_z)); - const vec4f angles = make_vec4f(static_cast(angle_x), static_cast(angle_y), static_cast(angle_z), - 6400.f); + const vec3f eye = + make_vec3f(static_cast(eye_x), static_cast(eye_y), + static_cast(eye_z)); + const vec3f dir = + make_vec3f(static_cast(dir_x), static_cast(dir_y), + static_cast(dir_z)); + const vec4f angles = + make_vec4f(static_cast(angle_x), static_cast(angle_y), + static_cast(angle_z), 6400.f); solr::SingletonKernel::kernel()->setCamera(eye, dir, angles); } @@ -155,7 +169,8 @@ int SolR_RunKernel(double timer, BitmapBuffer *image) { LOG_INFO(3, "SolR_RunKernel"); solr::SingletonKernel::kernel()->setSceneInfo(gSceneInfoStub); - solr::SingletonKernel::kernel()->setPostProcessingInfo(gPostProcessingInfoStub); + solr::SingletonKernel::kernel()->setPostProcessingInfo( + gPostProcessingInfoStub); solr::SingletonKernel::kernel()->render_begin(static_cast(timer)); solr::SingletonKernel::kernel()->render_end(); memcpy(image, solr::SingletonKernel::kernel()->getBitmap(), @@ -167,32 +182,37 @@ int SolR_RunKernel(double timer, BitmapBuffer *image) int SolR_AddPrimitive(int type, int movable) { LOG_INFO(3, "SolR_AddPrimitive"); - int id = solr::SingletonKernel::kernel()->addPrimitive(static_cast(type)); + int id = solr::SingletonKernel::kernel()->addPrimitive( + static_cast(type)); solr::SingletonKernel::kernel()->setPrimitiveIsMovable(id, (movable == 1)); return id; } // -------------------------------------------------------------------------------- -int SolR_SetPrimitive(int index, double p0_x, double p0_y, double p0_z, double p1_x, double p1_y, double p1_z, - double p2_x, double p2_y, double p2_z, double size_x, double size_y, double size_z, - int materialId) +int SolR_SetPrimitive(int index, double p0_x, double p0_y, double p0_z, + double p1_x, double p1_y, double p1_z, double p2_x, + double p2_y, double p2_z, double size_x, double size_y, + double size_z, int materialId) { LOG_INFO(3, "SolR_SetPrimitive"); - solr::SingletonKernel::kernel()->setPrimitive(index, static_cast(p0_x), static_cast(p0_y), - static_cast(p0_z), static_cast(p1_x), - static_cast(p1_y), static_cast(p1_z), - static_cast(p2_x), static_cast(p2_y), - static_cast(p2_z), static_cast(size_x), - static_cast(size_y), static_cast(size_z), materialId); + solr::SingletonKernel::kernel()->setPrimitive( + index, static_cast(p0_x), static_cast(p0_y), + static_cast(p0_z), static_cast(p1_x), + static_cast(p1_y), static_cast(p1_z), + static_cast(p2_x), static_cast(p2_y), + static_cast(p2_z), static_cast(size_x), + static_cast(size_y), static_cast(size_z), materialId); return 0; } -int SolR_GetPrimitive(int index, double &p0_x, double &p0_y, double &p0_z, double &p1_x, double &p1_y, double &p1_z, - double &p2_x, double &p2_y, double &p2_z, double &size_x, double &size_y, double &size_z, - int &materialId) +int SolR_GetPrimitive(int index, double &p0_x, double &p0_y, double &p0_z, + double &p1_x, double &p1_y, double &p1_z, double &p2_x, + double &p2_y, double &p2_z, double &size_x, + double &size_y, double &size_z, int &materialId) { LOG_INFO(3, "SolR_GetPrimitive"); - solr::CPUPrimitive *primitive = solr::SingletonKernel::kernel()->getPrimitive(index); + solr::CPUPrimitive *primitive = + solr::SingletonKernel::kernel()->getPrimitive(index); if (primitive != NULL) { p0_x = primitive->p0.x; @@ -229,25 +249,35 @@ int SolR_GetPrimitiveCenter(int index, double &x, double &y, double &z) return 0; } -int SolR_RotatePrimitive(int index, double rx, double ry, double rz, double ax, double ay, double az) +int SolR_RotatePrimitive(int index, double rx, double ry, double rz, double ax, + double ay, double az) { LOG_INFO(3, "SolR_RotatePrimitive"); -// vec4f rotationCenter = {{static_cast(rx), static_cast(ry), static_cast(rz), 0.f}}; -// vec4f angles = {{static_cast(ax), static_cast(ay), static_cast(az), 0.f}}; -// -// solr::SingletonKernel::kernel()->rotatePrimitive( index, boxId, rotationCenter, angles ); // TODO!! + // vec4f rotationCenter = {{static_cast(rx), + // static_cast(ry), static_cast(rz), 0.f}}; vec4f angles = + // {{static_cast(ax), static_cast(ay), + // static_cast(az), 0.f}}; + // + // solr::SingletonKernel::kernel()->rotatePrimitive( index, boxId, + // rotationCenter, angles ); // TODO!! return 0; } -int SolR_RotatePrimitives(int fromBoxId, int toBoxId, double rx, double ry, double rz, double ax, double ay, double az) +int SolR_RotatePrimitives(int fromBoxId, int toBoxId, double rx, double ry, + double rz, double ax, double ay, double az) { LOG_INFO(3, "SolR_RotatePrimitives"); try { - vec3f rotationCenter = make_vec3f(static_cast(rx), static_cast(ry), static_cast(rz)); - vec4f angles = make_vec4f(static_cast(ax), static_cast(ay), static_cast(az)); - - solr::SingletonKernel::kernel()->rotatePrimitives(rotationCenter, angles); + vec3f rotationCenter = + make_vec3f(static_cast(rx), static_cast(ry), + static_cast(rz)); + vec4f angles = + make_vec4f(static_cast(ax), static_cast(ay), + static_cast(az)); + + solr::SingletonKernel::kernel()->rotatePrimitives(rotationCenter, + angles); solr::SingletonKernel::kernel()->compactBoxes(false); } catch (...) @@ -269,41 +299,53 @@ int SolR_GetPrimitiveMaterial(int index) return solr::SingletonKernel::kernel()->getPrimitiveMaterial(index); } -int SolR_SetPrimitiveNormals(int index, double n0_x, double n0_y, double n0_z, double n1_x, double n1_y, double n1_z, - double n2_x, double n2_y, double n2_z) +int SolR_SetPrimitiveNormals(int index, double n0_x, double n0_y, double n0_z, + double n1_x, double n1_y, double n1_z, double n2_x, + double n2_y, double n2_z) { LOG_INFO(3, "SolR_SetPrimitiveNormals"); - vec3f n0 = make_vec3f(static_cast(n0_x), static_cast(n0_y), static_cast(n0_z)); - vec3f n1 = make_vec3f(static_cast(n1_x), static_cast(n1_y), static_cast(n1_z)); - vec3f n2 = make_vec3f(static_cast(n2_x), static_cast(n2_y), static_cast(n2_z)); + vec3f n0 = make_vec3f(static_cast(n0_x), static_cast(n0_y), + static_cast(n0_z)); + vec3f n1 = make_vec3f(static_cast(n1_x), static_cast(n1_y), + static_cast(n1_z)); + vec3f n2 = make_vec3f(static_cast(n2_x), static_cast(n2_y), + static_cast(n2_z)); solr::SingletonKernel::kernel()->setPrimitiveNormals(index, n0, n1, n2); return 0; } -int SolR_SetPrimitiveTextureCoordinates(int index, double t0_x, double t0_y, double t1_x, double t1_y, - double t2_x, double t2_y) +int SolR_SetPrimitiveTextureCoordinates(int index, double t0_x, double t0_y, + double t1_x, double t1_y, double t2_x, + double t2_y) { LOG_INFO(3, "SolR_SetPrimitiveTextureCoordinates"); - const vec2f t0 = make_vec2f(static_cast(t0_x), static_cast(t0_y)); - const vec2f t1 = make_vec2f(static_cast(t1_x), static_cast(t1_y)); - const vec2f t2 = make_vec2f(static_cast(t2_x), static_cast(t2_y)); - solr::SingletonKernel::kernel()->setPrimitiveTextureCoordinates(index, t0, t1, t2); + const vec2f t0 = + make_vec2f(static_cast(t0_x), static_cast(t0_y)); + const vec2f t1 = + make_vec2f(static_cast(t1_x), static_cast(t1_y)); + const vec2f t2 = + make_vec2f(static_cast(t2_x), static_cast(t2_y)); + solr::SingletonKernel::kernel()->setPrimitiveTextureCoordinates(index, t0, + t1, t2); return 0; } // -------------------------------------------------------------------------------- -int SolR_UpdateSkeletons(int index, double p0_x, double p0_y, double p0_z, double size, double radius, int materialId, - double head_radius, int head_materialId, double hands_radius, int hands_materialId, +int SolR_UpdateSkeletons(int index, double p0_x, double p0_y, double p0_z, + double size, double radius, int materialId, + double head_radius, int head_materialId, + double hands_radius, int hands_materialId, double feet_radius, int feet_materialId) { LOG_INFO(3, "SolR_UpdateSkeletons"); #if USE_KINECT - vec3f position = {static_cast(p0_x), static_cast(p0_y), static_cast(p0_z)}; - return solr::SingletonKernel::kernel()->updateSkeletons(index, position, static_cast(size), - static_cast(radius), materialId, - static_cast(head_radius), head_materialId, - static_cast(hands_radius), hands_materialId, - static_cast(feet_radius), feet_materialId); + vec3f position = {static_cast(p0_x), static_cast(p0_y), + static_cast(p0_z)}; + return solr::SingletonKernel::kernel()->updateSkeletons( + index, position, static_cast(size), static_cast(radius), + materialId, static_cast(head_radius), head_materialId, + static_cast(hands_radius), hands_materialId, + static_cast(feet_radius), feet_materialId); #else return 0; #endif // USE_KINECT @@ -313,7 +355,8 @@ int SolR_UpdateSkeletons(int index, double p0_x, double p0_y, double p0_z, doubl int SolR_LoadTextureFromFile(int index, char *filename) { LOG_INFO(3, "SolR_LoadTextureFromFile"); - return solr::SingletonKernel::kernel()->loadTextureFromFile(index, filename); + return solr::SingletonKernel::kernel()->loadTextureFromFile(index, + filename); } // -------------------------------------------------------------------------------- @@ -332,7 +375,8 @@ int SolR_SetTexture(int index, HANDLE texture) int SolR_GetTextureSize(int index, int &width, int &height, int &depth) { LOG_INFO(3, "SolR_GetTextureSize"); - if (index < static_cast(solr::SingletonKernel::kernel()->getNbActiveTextures())) + if (index < static_cast( + solr::SingletonKernel::kernel()->getNbActiveTextures())) { TextureInfo texInfo; memset(&texInfo, 0, sizeof(TextureInfo)); @@ -351,7 +395,8 @@ int SolR_GetTextureSize(int index, int &width, int &height, int &depth) int SolR_GetTexture(int index, BitmapBuffer *image) { LOG_INFO(3, "SolR_GetTexture"); - if (index < static_cast(solr::SingletonKernel::kernel()->getNbActiveTextures())) + if (index < static_cast( + solr::SingletonKernel::kernel()->getNbActiveTextures())) { TextureInfo texInfo; memset(&texInfo, 0, sizeof(TextureInfo)); @@ -386,72 +431,98 @@ int SolR_AddMaterial() } // -------------------------------------------------------------------------------- -int SolR_SetMaterial(int index, double color_r, double color_g, double color_b, double noise, double reflection, - double refraction, int procedural, int wireframe, int wireframeDepth, double transparency, - double opacity, int diffuseTextureId, int normalTextureId, int bumpTextureId, - int specularTextureId, int reflectionTextureId, int transparencyTextureId, - int ambientOcclusionTextureId, double specValue, double specPower, double specCoef, - double innerIllumination, double illuminationDiffusion, double illuminationPropagation, - int fastTransparency) -{ - LOG_INFO(3, "SolR_SetMaterial (" << index << "," << static_cast(color_r) << "," - << static_cast(color_g) << "," << static_cast(color_b) << "," - << static_cast(noise) << "," << static_cast(reflection) << "," - << static_cast(refraction) << "," << procedural << "," << wireframe << "," - << static_cast(wireframeDepth) << "," << static_cast(transparency) - << "," << static_cast(opacity) << "," << static_cast(diffuseTextureId) - << "," << static_cast(normalTextureId) << "," - << static_cast(bumpTextureId) << "," << static_cast(specularTextureId) - << "," << static_cast(reflectionTextureId) << "," - << static_cast(transparencyTextureId) << "," - << static_cast(ambientOcclusionTextureId) << "," - << static_cast(specValue) << "," << static_cast(specPower) << "," - << static_cast(specCoef) << "," << static_cast(innerIllumination) - << "," << static_cast(illuminationDiffusion) << "," - << static_cast(illuminationPropagation) << "," << fastTransparency << ")"); +int SolR_SetMaterial(int index, double color_r, double color_g, double color_b, + double gloss, double reflection, double refraction, + int procedural, int wireframe, int wireframeDepth, + double transparency, double opacity, int diffuseTextureId, + int normalTextureId, int bumpTextureId, + int specularTextureId, int reflectionTextureId, + int transparencyTextureId, int ambientOcclusionTextureId, + double specValue, double specPower, double specCoef, + double innerIllumination, double illuminationDiffusion, + double illuminationPropagation, int fastTransparency) +{ + LOG_INFO(3, "SolR_SetMaterial (" + << index << "," << static_cast(color_r) << "," + << static_cast(color_g) << "," + << static_cast(color_b) << "," + << static_cast(gloss) << "," + << static_cast(reflection) << "," + << static_cast(refraction) << "," << procedural + << "," << wireframe << "," + << static_cast(wireframeDepth) << "," + << static_cast(transparency) << "," + << static_cast(opacity) << "," + << static_cast(diffuseTextureId) << "," + << static_cast(normalTextureId) << "," + << static_cast(bumpTextureId) << "," + << static_cast(specularTextureId) << "," + << static_cast(reflectionTextureId) << "," + << static_cast(transparencyTextureId) << "," + << static_cast(ambientOcclusionTextureId) << "," + << static_cast(specValue) << "," + << static_cast(specPower) << "," + << static_cast(specCoef) << "," + << static_cast(innerIllumination) << "," + << static_cast(illuminationDiffusion) << "," + << static_cast(illuminationPropagation) << "," + << fastTransparency << ")"); solr::SingletonKernel::kernel()->setMaterial( - index, static_cast(color_r), static_cast(color_g), static_cast(color_b), - static_cast(noise), static_cast(reflection), static_cast(refraction), (procedural == 1), - (wireframe == 1), static_cast(wireframeDepth), static_cast(transparency), - static_cast(opacity), static_cast(diffuseTextureId), static_cast(normalTextureId), - static_cast(bumpTextureId), static_cast(specularTextureId), static_cast(reflectionTextureId), - static_cast(transparencyTextureId), static_cast(ambientOcclusionTextureId), - static_cast(specValue), static_cast(specPower), static_cast(specCoef), - static_cast(innerIllumination), static_cast(illuminationDiffusion), + index, static_cast(color_r), static_cast(color_g), + static_cast(color_b), static_cast(gloss), + static_cast(reflection), static_cast(refraction), + (procedural == 1), (wireframe == 1), static_cast(wireframeDepth), + static_cast(transparency), static_cast(opacity), + static_cast(diffuseTextureId), static_cast(normalTextureId), + static_cast(bumpTextureId), static_cast(specularTextureId), + static_cast(reflectionTextureId), + static_cast(transparencyTextureId), + static_cast(ambientOcclusionTextureId), + static_cast(specValue), static_cast(specPower), + static_cast(specCoef), static_cast(innerIllumination), + static_cast(illuminationDiffusion), static_cast(illuminationPropagation), (fastTransparency == 1)); return 0; } // -------------------------------------------------------------------------------- -int SolR_GetMaterial(int in_index, double &out_color_r, double &out_color_g, double &out_color_b, double &out_noise, - double &out_reflection, double &out_refraction, int &out_procedural, int &out_wireframe, - int &out_wireframeDepth, double &out_transparency, double &out_opacity, int &out_diffuseTextureId, - int &out_normalTextureId, int &out_bumpTextureId, int &out_specularTextureId, - int &out_reflectionTextureId, int &out_transparencyTextureId, int &out_ambientOcclusionTextureId, - double &out_specValue, double &out_specPower, double &out_specCoef, double &out_innerIllumination, - double &out_illuminationDiffusion, double &out_illuminationPropagation, int &out_fastTransparency) +int SolR_GetMaterial( + int in_index, double &out_color_r, double &out_color_g, double &out_color_b, + double &out_gloss, double &out_reflection, double &out_refraction, + int &out_procedural, int &out_wireframe, int &out_wireframeDepth, + double &out_transparency, double &out_opacity, int &out_diffuseTextureId, + int &out_normalTextureId, int &out_bumpTextureId, + int &out_specularTextureId, int &out_reflectionTextureId, + int &out_transparencyTextureId, int &out_ambientOcclusionTextureId, + double &out_specValue, double &out_specPower, double &out_specCoef, + double &out_innerIllumination, double &out_illuminationDiffusion, + double &out_illuminationPropagation, int &out_fastTransparency) { LOG_INFO(3, "SolR_GetMaterial"); - float color_r, color_g, color_b, noise, reflection, refraction, transparency, opacity; - float specValue, specPower, specCoef, innerIllumination, illuminationDiffusion, illuminationPropagation; + float color_r, color_g, color_b, gloss, reflection, refraction, + transparency, opacity; + float specValue, specPower, specCoef, innerIllumination, + illuminationDiffusion, illuminationPropagation; bool procedural; bool wireframe; int wireframeDepth; - int diffuseTextureId, normalTextureId, bumpTextureId, specularTextureId, reflectionTextureId, transparencyTextureId, - ambientOcclusionTextureId; + int diffuseTextureId, normalTextureId, bumpTextureId, specularTextureId, + reflectionTextureId, transparencyTextureId, ambientOcclusionTextureId; bool fastTransparency; int returnValue = solr::SingletonKernel::kernel()->getMaterialAttributes( - in_index, color_r, color_g, color_b, noise, reflection, refraction, procedural, wireframe, wireframeDepth, - transparency, opacity, diffuseTextureId, normalTextureId, bumpTextureId, specularTextureId, reflectionTextureId, - transparencyTextureId, ambientOcclusionTextureId, specValue, specPower, specCoef, innerIllumination, + in_index, color_r, color_g, color_b, gloss, reflection, refraction, + procedural, wireframe, wireframeDepth, transparency, opacity, + diffuseTextureId, normalTextureId, bumpTextureId, specularTextureId, + reflectionTextureId, transparencyTextureId, ambientOcclusionTextureId, + specValue, specPower, specCoef, innerIllumination, illuminationDiffusion, illuminationPropagation, fastTransparency); out_color_r = static_cast(color_r); out_color_g = static_cast(color_g); out_color_b = static_cast(color_b); - out_noise = static_cast(noise); + out_gloss = static_cast(gloss); out_reflection = static_cast(reflection); out_refraction = static_cast(refraction); out_transparency = static_cast(transparency); @@ -477,8 +548,9 @@ int SolR_GetMaterial(int in_index, double &out_color_r, double &out_color_g, dou } // -------------------------------------------------------------------------------- -int SolR_LoadMolecule(char *filename, int geometryType, double defaultAtomSize, double defaultStickSize, - int atomMaterialType, double scale) +int SolR_LoadMolecule(char *filename, int geometryType, double defaultAtomSize, + double defaultStickSize, int atomMaterialType, + double scale) { LOG_INFO(3, "SolR_LoadMolecule"); // PDB @@ -486,13 +558,16 @@ int SolR_LoadMolecule(char *filename, int geometryType, double defaultAtomSize, const float s(static_cast(scale)); const vec4f objectScale = make_vec4f(s, s, s); prbReader.loadAtomsFromFile(filename, *solr::SingletonKernel::kernel(), - static_cast(geometryType), static_cast(defaultAtomSize), - static_cast(defaultStickSize), atomMaterialType, objectScale); + static_cast(geometryType), + static_cast(defaultAtomSize), + static_cast(defaultStickSize), + atomMaterialType, objectScale); return solr::SingletonKernel::kernel()->getNbActivePrimitives(); } // -------------------------------------------------------------------------------- -int SolR_LoadOBJModel(char *filename, int materialId, int autoScale, double scale, int autoCenter, double &height) +int SolR_LoadOBJModel(char *filename, int materialId, int autoScale, + double scale, int autoCenter, double &height) { LOG_INFO(3, "SolR_LoadOBJModel"); vec4f center = make_vec4f(0.f, 0.f, 0.f); @@ -503,8 +578,10 @@ int SolR_LoadOBJModel(char *filename, int materialId, int autoScale, double scal solr::CPUBoundingBox aabb; solr::CPUBoundingBox inAABB; vec4f minPos = - objReader.loadModelFromFile(filename, *solr::SingletonKernel::kernel(), center, (autoScale == 1), objectScale, - true, materialId, false, (autoCenter == 1), aabb, false, inAABB); + objReader.loadModelFromFile(filename, *solr::SingletonKernel::kernel(), + center, (autoScale == 1), objectScale, true, + materialId, false, (autoCenter == 1), aabb, + false, inAABB); height = -minPos.y / 2.f; return solr::SingletonKernel::kernel()->getNbActivePrimitives(); @@ -525,7 +602,8 @@ int SolR_LoadFromFile(char *filename, double scale) LOG_INFO(3, "SolR_LoadFromFile"); vec4f center = make_vec4f(0.f, 0.f, 0.f); solr::FileMarshaller fm; - fm.loadFromFile(*solr::SingletonKernel::kernel(), filename, center, static_cast(scale)); + fm.loadFromFile(*solr::SingletonKernel::kernel(), filename, center, + static_cast(scale)); return solr::SingletonKernel::kernel()->getNbActivePrimitives(); } @@ -545,7 +623,8 @@ int SolR_GetLight(int index) int SolR_GenerateScreenshot(char *filename, int width, int height, int quality) { - solr::SingletonKernel::kernel()->generateScreenshot(filename, width, height, quality); + solr::SingletonKernel::kernel()->generateScreenshot(filename, width, height, + quality); return 0; } @@ -553,33 +632,40 @@ int SolR_GenerateScreenshot(char *filename, int width, int height, int quality) int SolR_GetOpenCLPlaformCount() { solr::SingletonKernel::kernel()->queryDevice(); - return dynamic_cast(solr::SingletonKernel::kernel())->getNumPlatforms(); + return dynamic_cast(solr::SingletonKernel::kernel()) + ->getNumPlatforms(); } -int SolR_GetOpenCLPlatformDescription(int platform, char *value, int valueLength) +int SolR_GetOpenCLPlatformDescription(int platform, char *value, + int valueLength) { std::string description = - dynamic_cast(solr::SingletonKernel::kernel())->getPlatformDescription(platform); + dynamic_cast(solr::SingletonKernel::kernel()) + ->getPlatformDescription(platform); strncpy(value, description.c_str(), valueLength); return 0; } int SolR_GetOpenCLDeviceCount(int platform) { - return dynamic_cast(solr::SingletonKernel::kernel())->getNumDevices(platform); + return dynamic_cast(solr::SingletonKernel::kernel()) + ->getNumDevices(platform); } -int SolR_GetOpenCLDeviceDescription(int platform, int device, char *value, int valueLength) +int SolR_GetOpenCLDeviceDescription(int platform, int device, char *value, + int valueLength) { std::string description = - dynamic_cast(solr::SingletonKernel::kernel())->getDeviceDescription(platform, device); + dynamic_cast(solr::SingletonKernel::kernel()) + ->getDeviceDescription(platform, device); strncpy(value, description.c_str(), valueLength); return 0; } int SolR_PopulateOpenCLInformation() { - dynamic_cast(solr::SingletonKernel::kernel())->queryDevice(); + dynamic_cast(solr::SingletonKernel::kernel()) + ->queryDevice(); return 0; } @@ -595,7 +681,8 @@ int SolR_GetOpenCLPlaformCount() return 0; } -int SolR_GetOpenCLPlatformDescription(int platform, char *value, int valueLength) +int SolR_GetOpenCLPlatformDescription(int platform, char *value, + int valueLength) { std::string description = "This library was not compiled for OpenCL"; strncpy(value, description.c_str(), valueLength); @@ -607,7 +694,8 @@ int SolR_GetOpenCLDeviceCount(int platform) return 0; } -int SolR_GetOpenCLDeviceDescription(int platform, int device, char *value, int valueLength) +int SolR_GetOpenCLDeviceDescription(int platform, int device, char *value, + int valueLength) { std::string description = "This library was not compiled for OpenCL"; strncpy(value, description.c_str(), valueLength); diff --git a/solr/SolRStub.h b/solr/SolRStub.h index df8c4cf..58b44a0 100644 --- a/solr/SolRStub.h +++ b/solr/SolRStub.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ // -------------------------------------------------------------------- @@ -30,95 +27,119 @@ typedef char *HANDLE; #endif -#include "DLL_API.h" +#include "api.h" #include "engines/GPUKernel.h" // ---------- OpenCL ---------- extern "C" SOLR_API int SolR_PopulateOpenCLInformation(); extern "C" SOLR_API int SolR_GetOpenCLPlaformCount(); -extern "C" SOLR_API int SolR_GetOpenCLPlatformDescription(int platform, char *value, int valueLength); +extern "C" SOLR_API int SolR_GetOpenCLPlatformDescription(int platform, + char *value, + int valueLength); extern "C" SOLR_API int SolR_GetOpenCLDeviceCount(int platform); -extern "C" SOLR_API int SolR_GetOpenCLDeviceDescription(int platform, int device, char *value, int valueLength); +extern "C" SOLR_API int SolR_GetOpenCLDeviceDescription(int platform, + int device, char *value, + int valueLength); extern "C" SOLR_API int SolR_RecompileKernels(char *filename); // ---------- Scene ---------- -extern "C" SOLR_API int SolR_SetSceneInfo(int width, int height, int graphicsLevel, int nbRayIterations, - double transparentColor, double viewDistance, double shadowIntensity, - double eyeSeparation, double bgColorR, double bgColorG, double bgColorB, - double bgColorA, int renderBoxes, int pathTracingIteration, - int maxPathTracingIterations, int frameBufferType, int timestamp, - int atmosphericEffect, int cameraType, int doubleSidedTriangles, - int extendedGeometry, int advancedIllumination, int skyboxSize, - int skyboxMaterialId, double geometryEpsilon, double rayEpsilon); - -extern "C" SOLR_API int SolR_SetPostProcessingInfo(int type, double param1, double param2, int param3); +extern "C" SOLR_API int SolR_SetSceneInfo( + int width, int height, int graphicsLevel, int nbRayIterations, + double transparentColor, double viewDistance, double shadowIntensity, + double eyeSeparation, double bgColorR, double bgColorG, double bgColorB, + double bgColorA, int renderBoxes, int pathTracingIteration, + int maxPathTracingIterations, int frameBufferType, int timestamp, + int atmosphericEffect, int cameraType, int doubleSidedTriangles, + int extendedGeometry, int advancedIllumination, int skyboxSize, + int skyboxMaterialId, double geometryEpsilon, double rayEpsilon); + +extern "C" SOLR_API int SolR_SetPostProcessingInfo(int type, double param1, + double param2, int param3); extern "C" SOLR_API int SolR_SetDraftMode(int draft); -extern "C" SOLR_API int SolR_InitializeKernel(bool activeLogging, int platform, int device); +extern "C" SOLR_API int SolR_InitializeKernel(bool activeLogging, int platform, + int device); extern "C" SOLR_API int SolR_FinalizeKernel(); extern "C" SOLR_API int SolR_ResetKernel(); -extern "C" SOLR_API int SolR_GenerateScreenshot(char *filename, int width, int height, int quality); +extern "C" SOLR_API int SolR_GenerateScreenshot(char *filename, int width, + int height, int quality); // ---------- Camera ---------- -extern "C" SOLR_API void SolR_SetCamera(double eye_x, double eye_y, double eye_z, double dir_x, double dir_y, - double dir_z, double angle_x, double angle_y, double angle_z); +extern "C" SOLR_API void SolR_SetCamera(double eye_x, double eye_y, + double eye_z, double dir_x, + double dir_y, double dir_z, + double angle_x, double angle_y, + double angle_z); // ---------- Rendering ---------- -extern "C" SOLR_API int SolR_RunKernel(double timer, BitmapBuffer *image); +extern "C" SOLR_API int SolR_RunKernel(double timer, solr::BitmapBuffer *image); // ---------- Primitives ---------- extern "C" SOLR_API int SolR_AddPrimitive(int type, int movable); -extern "C" SOLR_API int SolR_SetPrimitive(int index, double p0_x, double p0_y, double p0_z, double p1_x, double p1_y, - double p1_z, double p2_x, double p2_y, double p2_z, double size_x, - double size_y, double size_z, int materialId); +extern "C" SOLR_API int SolR_SetPrimitive(int index, double p0_x, double p0_y, + double p0_z, double p1_x, double p1_y, + double p1_z, double p2_x, double p2_y, + double p2_z, double size_x, + double size_y, double size_z, + int materialId); -extern "C" SOLR_API int SolR_GetPrimitive(int index, double &p0_x, double &p0_y, double &p0_z, double &p1_x, - double &p1_y, double &p1_z, double &p2_x, double &p2_y, double &p2_z, - double &size_x, double &size_y, double &size_z, int &materialId); +extern "C" SOLR_API int SolR_GetPrimitive( + int index, double &p0_x, double &p0_y, double &p0_z, double &p1_x, + double &p1_y, double &p1_z, double &p2_x, double &p2_y, double &p2_z, + double &size_x, double &size_y, double &size_z, int &materialId); extern "C" SOLR_API int SolR_GetPrimitiveAt(int x, int y); -extern "C" SOLR_API int SolR_GetPrimitiveCenter(int index, double &x, double &y, double &z); +extern "C" SOLR_API int SolR_GetPrimitiveCenter(int index, double &x, double &y, + double &z); -extern "C" SOLR_API int SolR_RotatePrimitive(int index, double rx, double ry, double rz, double ax, double ay, +extern "C" SOLR_API int SolR_RotatePrimitive(int index, double rx, double ry, + double rz, double ax, double ay, double az); -extern "C" SOLR_API int SolR_RotatePrimitives(int fromBoxId, int toBoxId, double rx, double ry, double rz, double ax, - double ay, double az); +extern "C" SOLR_API int SolR_RotatePrimitives(int fromBoxId, int toBoxId, + double rx, double ry, double rz, + double ax, double ay, double az); extern "C" SOLR_API int SolR_SetPrimitiveMaterial(int index, int materialId); extern "C" SOLR_API int SolR_GetPrimitiveMaterial(int index); -extern "C" SOLR_API int SolR_SetPrimitiveNormals(int index, double n0_x, double n0_y, double n0_z, double n1_x, - double n1_y, double n1_z, double n2_x, double n2_y, double n2_z); +extern "C" SOLR_API int SolR_SetPrimitiveNormals(int index, double n0_x, + double n0_y, double n0_z, + double n1_x, double n1_y, + double n1_z, double n2_x, + double n2_y, double n2_z); -extern "C" SOLR_API int SolR_SetPrimitiveTextureCoordinates(int index, double t0_x, double t0_y, - double t1_x, double t1_y, double t2_x, - double t2_y); +extern "C" SOLR_API int SolR_SetPrimitiveTextureCoordinates( + int index, double t0_x, double t0_y, double t1_x, double t1_y, double t2_x, + double t2_y); // ---------- Materials ---------- extern "C" SOLR_API int SolR_AddMaterial(); -extern "C" SOLR_API int SolR_SetMaterial(int index, double color_r, double color_g, double color_b, double noise, - double reflection, double refraction, int procedural, int wireframe, - int wireframeDepth, double transparency, double opacity, int diffuseTextureId, - int normalTextureId, int bumpTextureId, int specularTextureId, - int reflectionTextureId, int transparencyTextureId, - int ambientOcclusionTextureId, double specValue, double specPower, - double specCoef, double innerIllumination, double illuminationDiffusion, - double illuminationPropagation, int fastTransparency); - -extern "C" SOLR_API int SolR_GetMaterial(int index, double &color_r, double &color_g, double &color_b, double &noise, - double &reflection, double &refraction, int &procedural, int &wireframe, - int &wireframeDepth, double &transparency, double &opacity, - int &diffuseTextureId, int &bumpTextureId, int &normalTextureId, - int &specularTextureId, int &reflectionTextureId, int &transparencyTextureId, - int &ambientOcclusionTextureId, double &specValue, double &specPower, - double &specCoef, double &innerIllumination, double &illuminationDiffusion, - double &illuminationPropagation, int &fastTransparency); +extern "C" SOLR_API int SolR_SetMaterial( + int index, double color_r, double color_g, double color_b, double gloss, + double reflection, double refraction, int procedural, int wireframe, + int wireframeDepth, double transparency, double opacity, + int diffuseTextureId, int normalTextureId, int bumpTextureId, + int specularTextureId, int reflectionTextureId, int transparencyTextureId, + int ambientOcclusionTextureId, double specValue, double specPower, + double specCoef, double innerIllumination, double illuminationDiffusion, + double illuminationPropagation, int fastTransparency); + +extern "C" SOLR_API int SolR_GetMaterial( + int index, double &color_r, double &color_g, double &color_b, double &gloss, + double &reflection, double &refraction, int &procedural, int &wireframe, + int &wireframeDepth, double &transparency, double &opacity, + int &diffuseTextureId, int &bumpTextureId, int &normalTextureId, + int &specularTextureId, int &reflectionTextureId, + int &transparencyTextureId, int &ambientOcclusionTextureId, + double &specValue, double &specPower, double &specCoef, + double &innerIllumination, double &illuminationDiffusion, + double &illuminationPropagation, int &fastTransparency); // Boxes extern "C" SOLR_API int SolR_CompactBoxes(bool update); @@ -129,17 +150,21 @@ extern "C" SOLR_API int SolR_GetLight(int index); // ---------- Textures ---------- extern "C" SOLR_API int SolR_LoadTextureFromFile(int index, char *filename); extern "C" SOLR_API int SolR_SetTexture(int index, HANDLE texture); -extern "C" SOLR_API int SolR_GetTextureSize(int index, int &width, int &height, int &depth); -extern "C" SOLR_API int SolR_GetTexture(int index, BitmapBuffer *image); +extern "C" SOLR_API int SolR_GetTextureSize(int index, int &width, int &height, + int &depth); +extern "C" SOLR_API int SolR_GetTexture(int index, solr::BitmapBuffer *image); extern "C" SOLR_API int SolR_GetNbTextures(int &nbTextures); // ---------- Molecules ---------- -extern "C" SOLR_API int SolR_LoadMolecule(char *filename, int geometryType, double defaultAtomSize, - double defaultStickSize, int atomMaterialType, double scale); +extern "C" SOLR_API int SolR_LoadMolecule(char *filename, int geometryType, + double defaultAtomSize, + double defaultStickSize, + int atomMaterialType, double scale); // ---------- OBJ models ---------- -extern "C" SOLR_API int SolR_LoadOBJModel(char *filename, int materialId, int autoScale, double scale, int autoCenter, - double &height); +extern "C" SOLR_API int SolR_LoadOBJModel(char *filename, int materialId, + int autoScale, double scale, + int autoCenter, double &height); // ---------- File marshaller ---------- extern "C" SOLR_API int SolR_SaveToFile(char *filename); @@ -147,8 +172,9 @@ extern "C" SOLR_API int SolR_LoadFromFile(char *filename, double scale); #ifdef USE_KINECT // ---------- Kinect ---------- -extern "C" SOLR_API int SolR_UpdateSkeletons(int index, double center_x, double center_y, double center_z, double size, - double radius, int materialId, double head_radius, int head_materialId, - double hands_radius, int hands_materialId, double feet_radius, - int feet_materialId); +extern "C" SOLR_API int SolR_UpdateSkeletons( + int index, double center_x, double center_y, double center_z, double size, + double radius, int materialId, double head_radius, int head_materialId, + double hands_radius, int hands_materialId, double feet_radius, + int feet_materialId); #endif // USE_KINECT diff --git a/solr/api.h b/solr/api.h new file mode 100644 index 0000000..db1d6f0 --- /dev/null +++ b/solr/api.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2011-2022, Cyrille Favreau + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#pragma warning(disable : 4251) +#pragma warning(disable : 4996) +#pragma warning(disable : 4244) // Oculus DK1 SDK + +#ifdef WIN32 +#define SOLR_API __declspec(dllexport) +#else +#define SOLR_API +#endif diff --git a/solr/Consts.h b/solr/consts.h similarity index 74% rename from solr/Consts.h rename to solr/consts.h index 3a538b0..9c74b3a 100644 --- a/solr/Consts.h +++ b/solr/consts.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once @@ -32,12 +29,13 @@ const unsigned int BOUNDING_BOXES_TREE_DEPTH = 64; const unsigned int NB_MAX_BOXES = 2500000; const unsigned int NB_MAX_PRIMITIVES = 2500000; const unsigned int NB_MAX_LAMPS = 512; -const unsigned int NB_MAX_MATERIALS = 65506 + 30; // Last 30 materials are reserved +const unsigned int NB_MAX_MATERIALS = + 65506 + 30; // Last 30 materials are reserved const unsigned int NB_MAX_TEXTURES = 512; const unsigned int NB_MAX_FRAMES = 512; const unsigned int NB_MAX_LIGHTINFORMATIONS = 512; -const unsigned int MAX_BITMAP_WIDTH = 1920; -const unsigned int MAX_BITMAP_HEIGHT = 1080; +const unsigned int MAX_BITMAP_WIDTH = 3840; +const unsigned int MAX_BITMAP_HEIGHT = 3840; const unsigned int MAX_BITMAP_SIZE = MAX_BITMAP_WIDTH * MAX_BITMAP_HEIGHT; // Constants @@ -49,7 +47,7 @@ const int gColorDepth = 3; // Globals #define PI 3.14159265358979323846f -#define STANDARD_LUNINANCE_STRENGTH 0.1f +#define MATERIAL_DEFAULT_EMMISION_STRENGTH 0.6f #define SKYBOX_LUNINANCE_STRENGTH 0.2f #define EXTENDED_GEOMETRY // Includes spheres, cylinders, etc #define NATURAL_DEPTHOFFIELD @@ -119,15 +117,20 @@ const unsigned int SKYBOX_SPHERE_MATERIAL = NB_MAX_MATERIALS - 41; const unsigned int KINECT_COLOR_MATERIAL = NB_MAX_MATERIALS - 42; const unsigned int KINECT_DEPTH_MATERIAL = NB_MAX_MATERIALS - 43; +// Metal +const unsigned int METAL_MATERIAL = NB_MAX_MATERIALS - 44; + const unsigned int KINECT_COLOR_TEXTURE = 0; const unsigned int KINECT_DEPTH_TEXTURE = 1; const unsigned int KINECT_COLOR_WIDTH = 640; const unsigned int KINECT_COLOR_HEIGHT = 480; const unsigned int KINECT_COLOR_DEPTH = 4; -const unsigned int KINECT_COLOR_SIZE = KINECT_COLOR_WIDTH * KINECT_COLOR_HEIGHT * KINECT_COLOR_DEPTH; +const unsigned int KINECT_COLOR_SIZE = + KINECT_COLOR_WIDTH * KINECT_COLOR_HEIGHT * KINECT_COLOR_DEPTH; const unsigned int KINECT_DEPTH_WIDTH = 320; const unsigned int KINECT_DEPTH_HEIGHT = 240; const unsigned int KINECT_DEPTH_DEPTH = 2; -const unsigned int KINECT_DEPTH_SIZE = KINECT_DEPTH_WIDTH * KINECT_DEPTH_HEIGHT * KINECT_DEPTH_DEPTH; +const unsigned int KINECT_DEPTH_SIZE = + KINECT_DEPTH_WIDTH * KINECT_DEPTH_HEIGHT * KINECT_DEPTH_DEPTH; diff --git a/solr/engines/GPUKernel.cpp b/solr/engines/GPUKernel.cpp index b3c3bfa..1be71ef 100644 --- a/solr/engines/GPUKernel.cpp +++ b/solr/engines/GPUKernel.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau - * - * This file is part of Sol-R +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #ifdef WIN32 @@ -23,24 +20,25 @@ #else #include #include +#include #include #include #include -#include #endif -#include - -// JPeg -#include -#include - // Raytracing -#include "Consts.h" #include "GPUKernel.h" #include "Logging.h" +#include "consts.h" #include "io/FileMarshaller.h" #include "opengl/rtgl.h" +#include "random/RandomGenerator.h" + +#include + +// JPeg +#include +#include #ifdef USE_CUDA #include @@ -48,7 +46,9 @@ #ifdef USE_OPENCL #include #else +#ifdef USE_CPU #include "cpu/CPUKernel.h" +#endif // USE_CPU #endif // USE_OPENCL #endif // USE_CUDA @@ -66,7 +66,14 @@ extern "C" FILE *__cdecl __iob_func(void) #endif #endif // USE_OCULUS +#ifdef USE_RANDOM_DEVICE +#include +#endif + +using namespace solr; + const unsigned int AABB_MAGIC_NUMBER = 6400; +const float DEFAULT_RANDOM_MULTIPLIER = 0.002f; vec3f min2(const vec3f a, const vec3f b) { @@ -108,9 +115,7 @@ namespace solr { GPUKernel *SingletonKernel::m_kernel = 0; -SingletonKernel::SingletonKernel() -{ -} +SingletonKernel::SingletonKernel() {} GPUKernel *SingletonKernel::kernel() { @@ -121,7 +126,9 @@ GPUKernel *SingletonKernel::kernel() #ifdef USE_OPENCL m_kernel = new OpenCLKernel(); #else +#ifdef USE_OPENCL m_kernel = new CPUKernel(); +#endif // USE_CPU #endif // USE_OPENCL #endif // USE_CUDA return m_kernel; @@ -135,7 +142,8 @@ float GPUKernel::dotProduct(const vec3f &a, const vec3f &b) // ________________________________________________________________________________ float GPUKernel::vectorLength(const vec3f &vector) { - return sqrt(vector.x * vector.x + vector.y * vector.y + vector.z * vector.z); + return sqrt(vector.x * vector.x + vector.y * vector.y + + vector.z * vector.z); } // ________________________________________________________________________________ @@ -183,7 +191,6 @@ GPUKernel::GPUKernel() , m_hPrimitives(0) , m_hLamps(0) , m_hMaterials(0) - , m_hRandoms(0) , m_hPrimitivesXYIds(0) , m_nbActiveMaterials(-1) , m_nbActiveTextures(0) @@ -226,24 +233,30 @@ GPUKernel::GPUKernel() #endif // USE_OCULUS { LOG_INFO(1, ""); - LOG_INFO(1, " _|_|_| _| _|_|_| "); - LOG_INFO(1, " _| _|_| _| _| _|"); - LOG_INFO(1, " _|_| _| _| _| _|_|_|_|_| _|_|_| "); - LOG_INFO(1, " _| _| _| _| _| _|"); - LOG_INFO(1, " _|_|_| _|_| _| _| _|"); + LOG_INFO(1, + " _|_|_| _| _|_|_| "); + LOG_INFO(1, + " _| _|_| _| _| _|"); + LOG_INFO(1, + " _|_| _| _| _| _|_|_|_|_| _|_|_| "); + LOG_INFO(1, + " _| _| _| _| _| _|"); + LOG_INFO(1, + " _|_|_| _|_| _| _| _|"); LOG_INFO(1, ""); LOG_INFO(1, " Speed Of Light Ray-tracer"); LOG_INFO(1, " Created by cyrille.favreau@gmail.com"); LOG_INFO(1, ""); - for (int i(0); i < NB_MAX_FRAMES; ++i) + for (size_t i = 0; i < NB_MAX_FRAMES; ++i) { m_nbActiveBoxes[i] = 0; m_nbActivePrimitives[i] = 0; m_nbActiveLamps[i] = 0; } - LOG_INFO(3, "----------++++++++++ GPU Kernel created ++++++++++----------"); + LOG_INFO(3, + "----------++++++++++ GPU Kernel created ++++++++++----------"); LOG_INFO(3, "CPU: SceneInfo : " << sizeof(SceneInfo)); LOG_INFO(3, "CPU: Ray : " << sizeof(Ray)); LOG_INFO(3, "CPU: PrimitiveType : " << sizeof(PrimitiveType)); @@ -269,7 +282,8 @@ GPUKernel::GPUKernel() LOG_INFO(1, " | "); LOG_INFO(1, "Kinect initialization / \\"); - HRESULT hr = NuiInitialize(NUI_INITIALIZE_FLAG_USES_DEPTH_AND_PLAYER_INDEX | NUI_INITIALIZE_FLAG_USES_SKELETON | + HRESULT hr = NuiInitialize(NUI_INITIALIZE_FLAG_USES_DEPTH_AND_PLAYER_INDEX | + NUI_INITIALIZE_FLAG_USES_SKELETON | NUI_INITIALIZE_FLAG_USES_COLOR); m_kinectEnabled = (hr == S_OK); @@ -280,11 +294,13 @@ GPUKernel::GPUKernel() m_hNextSkeletonEvent = CreateEvent(NULL, TRUE, FALSE, NULL); m_skeletons = CreateEvent(NULL, TRUE, FALSE, NULL); - NuiSkeletonTrackingEnable(m_skeletons, NUI_SKELETON_TRACKING_FLAG_ENABLE_SEATED_SUPPORT); + NuiSkeletonTrackingEnable( + m_skeletons, NUI_SKELETON_TRACKING_FLAG_ENABLE_SEATED_SUPPORT); - NuiImageStreamOpen(NUI_IMAGE_TYPE_COLOR, NUI_IMAGE_RESOLUTION_640x480, 0, 2, m_hNextVideoFrameEvent, - &m_pVideoStreamHandle); - NuiImageStreamOpen(NUI_IMAGE_TYPE_DEPTH_AND_PLAYER_INDEX, NUI_IMAGE_RESOLUTION_320x240, 0, 2, + NuiImageStreamOpen(NUI_IMAGE_TYPE_COLOR, NUI_IMAGE_RESOLUTION_640x480, + 0, 2, m_hNextVideoFrameEvent, &m_pVideoStreamHandle); + NuiImageStreamOpen(NUI_IMAGE_TYPE_DEPTH_AND_PLAYER_INDEX, + NUI_IMAGE_RESOLUTION_320x240, 0, 2, m_hNextDepthFrameEvent, &m_pDepthStreamHandle); NuiCameraElevationSetAngle(0); @@ -295,6 +311,8 @@ GPUKernel::GPUKernel() } LOG_INFO(3, "----------------------------"); #endif // USE_KINECT + + RandomGenerator::getInstance().initialize(DEFAULT_RANDOM_MULTIPLIER); } GPUKernel::~GPUKernel() @@ -313,7 +331,8 @@ GPUKernel::~GPUKernel() #endif // USE_KINECT cleanup(); - LOG_INFO(3, "----------++++++++++ GPU Kernel Destroyed ++++++++++----------"); + LOG_INFO(3, + "----------++++++++++ GPU Kernel Destroyed ++++++++++----------"); } void GPUKernel::initBuffers() @@ -340,25 +359,7 @@ void GPUKernel::initBuffers() // Textures memset(m_hTextures, 0, NB_MAX_TEXTURES * sizeof(TextureInfo)); - // Randoms - size_t size = MAX_BITMAP_WIDTH * MAX_BITMAP_HEIGHT; - if (m_hRandoms) - delete m_hRandoms; - m_hRandoms = new RandomBuffer[size]; - - // Primitive IDs - if (m_hPrimitivesXYIds) - delete m_hPrimitivesXYIds; - m_hPrimitivesXYIds = new PrimitiveXYIdBuffer[size]; - memset(m_hPrimitivesXYIds, 0, size * sizeof(PrimitiveXYIdBuffer)); - - // Bitmap - if (m_bitmap) - delete m_bitmap; - size *= gColorDepth; - m_bitmap = new BitmapBuffer[size]; - memset(m_bitmap, 0, size * sizeof(BitmapBuffer)); - LOG_INFO(3, m_bitmap << " - Bitmap Size=" << size); + reshape(); #ifdef USE_OCULUS LOG_INFO(1, "Initializing Oculus DK1"); @@ -371,18 +372,17 @@ void GPUKernel::initBuffers() void GPUKernel::cleanup() { + RandomGenerator::getInstance().pause(); #ifdef USE_OCULUS // finializeOVR(); #endif // USE_OCULUS LOG_INFO(3, "Cleaning up resources"); - for (int i(0); i < NB_MAX_FRAMES; ++i) + for (size_t i = 0; i < NB_MAX_FRAMES; ++i) { for (int j(0); j < BOUNDING_BOXES_TREE_DEPTH; ++j) - { m_boundingBoxes[i][j].clear(); - } m_nbActiveBoxes[i] = 0; m_primitives[i].clear(); @@ -399,17 +399,17 @@ void GPUKernel::cleanup() m_maxPos[i].z = m_sceneInfo.viewDistance; } - for (int i(0); i < NB_MAX_TEXTURES; ++i) + for (size_t i = 0; i < NB_MAX_TEXTURES; ++i) { #ifdef USE_KINECT if (i > 1 && m_hTextures[i].buffer) - delete[] m_hTextures[i].buffer; + delete m_hTextures[i].buffer; #else if (m_hTextures[i].buffer != 0) { LOG_INFO(3, "[cleanup] Buffer " << i << " needs to be released"); - delete[] m_hTextures[i].buffer; - m_hTextures[i].buffer = 0; + delete m_hTextures[i].buffer; + m_hTextures[i].buffer = nullptr; } #endif // USE_KINECT } @@ -419,32 +419,29 @@ void GPUKernel::cleanup() m_normals.clear(); m_textCoords.clear(); - if (m_hRandoms) - delete m_hRandoms; - m_hRandoms = 0; if (m_bitmap) delete[] m_bitmap; - m_bitmap = 0; + m_bitmap = nullptr; #ifndef USE_MANAGED_MEMORY if (m_hBoundingBoxes) - delete m_hBoundingBoxes; - m_hBoundingBoxes = 0; + delete[] m_hBoundingBoxes; + m_hBoundingBoxes = nullptr; if (m_hPrimitives) - delete m_hPrimitives; + delete[] m_hPrimitives; m_hPrimitives = nullptr; #endif if (m_hLamps) - delete m_hLamps; - m_hLamps = 0; + delete[] m_hLamps; + m_hLamps = nullptr; if (m_hMaterials) - delete m_hMaterials; - m_hMaterials = 0; + delete[] m_hMaterials; + m_hMaterials = nullptr; if (m_hPrimitivesXYIds) - delete m_hPrimitivesXYIds; - m_hPrimitivesXYIds = 0; + delete[] m_hPrimitivesXYIds; + m_hPrimitivesXYIds = nullptr; if (m_lightInformation) - delete m_lightInformation; - m_lightInformation = 0; + delete[] m_lightInformation; + m_lightInformation = nullptr; m_nbActiveMaterials = -1; m_nbActiveTextures = 0; @@ -472,7 +469,25 @@ void GPUKernel::cleanup() void GPUKernel::reshape() { - // m_randomsTransfered=false; + RandomGenerator::getInstance().pause(); + const size_t size = m_sceneInfo.size.x * m_sceneInfo.size.y; + LOG_INFO(1, "Reshaping frame buffers to " << m_sceneInfo.size.x << "x" + << m_sceneInfo.size.y); + + // Primitive IDs + if (m_hPrimitivesXYIds) + delete[] m_hPrimitivesXYIds; + m_hPrimitivesXYIds = new PrimitiveXYIdBuffer[size]; + memset(m_hPrimitivesXYIds, 0, size * sizeof(PrimitiveXYIdBuffer)); + + // Bitmap + if (m_bitmap) + delete[] m_bitmap; + m_bitmap = new BitmapBuffer[size * gColorDepth]; + + // Randoms + RandomGenerator::getInstance().reshape(size); + RandomGenerator::getInstance().resume(); } /* @@ -481,11 +496,13 @@ ________________________________________________________________________________ Sets camera ________________________________________________________________________________ */ -void GPUKernel::setCamera(const vec3f &eye, const vec3f &dir, const vec4f &angles) +void GPUKernel::setCamera(const vec3f &eye, const vec3f &dir, + const vec4f &angles) { - LOG_INFO(3, "GPUKernel::setCamera(" << eye.x << "," << eye.y << "," << eye.z << " -> " << dir.x << "," << dir.y - << "," << dir.z << " : " << angles.x << "," << angles.y << "," << angles.z - << ")"); + LOG_INFO(3, "GPUKernel::setCamera(" + << eye.x << "," << eye.y << "," << eye.z << " -> " << dir.x + << "," << dir.y << "," << dir.z << " : " << angles.x << "," + << angles.y << "," << angles.z << ")"); m_viewPos = eye; m_viewDir = dir; m_angles = angles; @@ -525,19 +542,25 @@ CPUPrimitive *GPUKernel::getPrimitive(const unsigned int index) return returnValue; } -void GPUKernel::setPrimitive(const int &index, float x0, float y0, float z0, float w, float h, float d, int materialId) +void GPUKernel::setPrimitive(const int &index, float x0, float y0, float z0, + float w, float h, float d, int materialId) { - setPrimitive(index, x0, y0, z0, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, w, h, d, materialId); + setPrimitive(index, x0, y0, z0, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, w, h, d, + materialId); } -void GPUKernel::setPrimitive(const int &index, float x0, float y0, float z0, float x1, float y1, float z1, float w, - float h, float d, int materialId) +void GPUKernel::setPrimitive(const int &index, float x0, float y0, float z0, + float x1, float y1, float z1, float w, float h, + float d, int materialId) { - setPrimitive(index, x0, y0, z0, x1, y1, z1, 0.f, 0.f, 0.f, w, h, d, materialId); + setPrimitive(index, x0, y0, z0, x1, y1, z1, 0.f, 0.f, 0.f, w, h, d, + materialId); } -void GPUKernel::setPrimitive(const int &index, float x0, float y0, float z0, float x1, float y1, float z1, float x2, - float y2, float z2, float w, float h, float d, int materialId) +void GPUKernel::setPrimitive(const int &index, float x0, float y0, float z0, + float x1, float y1, float z1, float x2, float y2, + float z2, float w, float h, float d, + int materialId) { float scale = 1.f; m_primitivesTransfered = false; @@ -588,7 +611,8 @@ void GPUKernel::setPrimitive(const int &index, float x0, float y0, float z0, flo axis.x = x1 * scale - x0 * scale; axis.y = y1 * scale - y0 * scale; axis.z = z1 * scale - z0 * scale; - float len = sqrt(axis.x * axis.x + axis.y * axis.y + axis.z * axis.z); + float len = + sqrt(axis.x * axis.x + axis.y * axis.y + axis.z * axis.z); if (len != 0.f) { axis.x /= len; @@ -600,9 +624,12 @@ void GPUKernel::setPrimitive(const int &index, float x0, float y0, float z0, flo (m_primitives[m_frame])[index].n1.z = axis.z; // Center - (m_primitives[m_frame])[index].p2.x = (x0 * scale + x1 * scale) / 2.f; - (m_primitives[m_frame])[index].p2.y = (y0 * scale + y1 * scale) / 2.f; - (m_primitives[m_frame])[index].p2.z = (z0 * scale + z1 * scale) / 2.f; + (m_primitives[m_frame])[index].p2.x = + (x0 * scale + x1 * scale) / 2.f; + (m_primitives[m_frame])[index].p2.y = + (y0 * scale + y1 * scale) / 2.f; + (m_primitives[m_frame])[index].p2.z = + (z0 * scale + z1 * scale) / 2.f; // Length (m_primitives[m_frame])[index].size.x = w * scale; @@ -624,8 +651,10 @@ void GPUKernel::setPrimitive(const int &index, float x0, float y0, float z0, flo (m_primitives[m_frame])[index].n0.x = 0.f; (m_primitives[m_frame])[index].n0.y = 0.f; (m_primitives[m_frame])[index].n0.z = 1.f; - (m_primitives[m_frame])[index].n1 = (m_primitives[m_frame])[index].n0; - (m_primitives[m_frame])[index].n2 = (m_primitives[m_frame])[index].n0; + (m_primitives[m_frame])[index].n1 = + (m_primitives[m_frame])[index].n0; + (m_primitives[m_frame])[index].n2 = + (m_primitives[m_frame])[index].n0; break; } case ptYZPlane: @@ -633,8 +662,10 @@ void GPUKernel::setPrimitive(const int &index, float x0, float y0, float z0, flo (m_primitives[m_frame])[index].n0.x = 1.f; (m_primitives[m_frame])[index].n0.y = 0.f; (m_primitives[m_frame])[index].n0.z = 0.f; - (m_primitives[m_frame])[index].n1 = (m_primitives[m_frame])[index].n0; - (m_primitives[m_frame])[index].n2 = (m_primitives[m_frame])[index].n0; + (m_primitives[m_frame])[index].n1 = + (m_primitives[m_frame])[index].n0; + (m_primitives[m_frame])[index].n2 = + (m_primitives[m_frame])[index].n0; break; } case ptXZPlane: @@ -643,27 +674,37 @@ void GPUKernel::setPrimitive(const int &index, float x0, float y0, float z0, flo (m_primitives[m_frame])[index].n0.x = 0.f; (m_primitives[m_frame])[index].n0.y = 1.f; (m_primitives[m_frame])[index].n0.z = 0.f; - (m_primitives[m_frame])[index].n1 = (m_primitives[m_frame])[index].n0; - (m_primitives[m_frame])[index].n2 = (m_primitives[m_frame])[index].n0; + (m_primitives[m_frame])[index].n1 = + (m_primitives[m_frame])[index].n0; + (m_primitives[m_frame])[index].n2 = + (m_primitives[m_frame])[index].n0; break; } case ptTriangle: { vec3f v0, v1; - v0.x = (m_primitives[m_frame])[index].p1.x - (m_primitives[m_frame])[index].p0.x; - v0.y = (m_primitives[m_frame])[index].p1.y - (m_primitives[m_frame])[index].p0.y; - v0.z = (m_primitives[m_frame])[index].p1.z - (m_primitives[m_frame])[index].p0.z; + v0.x = (m_primitives[m_frame])[index].p1.x - + (m_primitives[m_frame])[index].p0.x; + v0.y = (m_primitives[m_frame])[index].p1.y - + (m_primitives[m_frame])[index].p0.y; + v0.z = (m_primitives[m_frame])[index].p1.z - + (m_primitives[m_frame])[index].p0.z; normalizeVector(v0); - v1.x = (m_primitives[m_frame])[index].p2.x - (m_primitives[m_frame])[index].p0.x; - v1.y = (m_primitives[m_frame])[index].p2.y - (m_primitives[m_frame])[index].p0.y; - v1.z = (m_primitives[m_frame])[index].p2.z - (m_primitives[m_frame])[index].p0.z; + v1.x = (m_primitives[m_frame])[index].p2.x - + (m_primitives[m_frame])[index].p0.x; + v1.y = (m_primitives[m_frame])[index].p2.y - + (m_primitives[m_frame])[index].p0.y; + v1.z = (m_primitives[m_frame])[index].p2.z - + (m_primitives[m_frame])[index].p0.z; normalizeVector(v1); (m_primitives[m_frame])[index].n0 = crossProduct(v0, v1); normalizeVector((m_primitives[m_frame])[index].n0); - (m_primitives[m_frame])[index].n1 = (m_primitives[m_frame])[index].n0; - (m_primitives[m_frame])[index].n2 = (m_primitives[m_frame])[index].n0; + (m_primitives[m_frame])[index].n1 = + (m_primitives[m_frame])[index].n0; + (m_primitives[m_frame])[index].n2 = + (m_primitives[m_frame])[index].n0; break; } } @@ -679,7 +720,8 @@ void GPUKernel::setPrimitive(const int &index, float x0, float y0, float z0, flo } else { - LOG_ERROR("GPUKernel::setPrimitive: Out of bounds (" << index << "/" << NB_MAX_PRIMITIVES << ")"); + LOG_ERROR("GPUKernel::setPrimitive: Out of bounds (" + << index << "/" << NB_MAX_PRIMITIVES << ")"); } } @@ -692,7 +734,8 @@ void GPUKernel::setPrimitiveIsMovable(const int &index, bool movable) } } -void GPUKernel::setPrimitiveBellongsToModel(const int &index, bool bellongsToModel) +void GPUKernel::setPrimitiveBellongsToModel(const int &index, + bool bellongsToModel) { if (index >= 0 && index < m_primitives[m_frame].size()) { @@ -701,7 +744,10 @@ void GPUKernel::setPrimitiveBellongsToModel(const int &index, bool bellongsToMod } } -void GPUKernel::setPrimitiveTextureCoordinates(const unsigned int index, const vec2f& vt0, const vec2f& vt1, const vec2f& vt2) +void GPUKernel::setPrimitiveTextureCoordinates(const unsigned int index, + const vec2f &vt0, + const vec2f &vt1, + const vec2f &vt2) { if (index < m_primitives[m_frame].size()) { @@ -712,7 +758,8 @@ void GPUKernel::setPrimitiveTextureCoordinates(const unsigned int index, const v } } -void GPUKernel::setPrimitiveNormals(int unsigned index, vec3f n0, vec3f n1, vec3f n2) +void GPUKernel::setPrimitiveNormals(int unsigned index, vec3f n0, vec3f n1, + vec3f n2) { if (index < m_primitives[m_frame].size()) { @@ -731,7 +778,8 @@ unsigned int GPUKernel::getPrimitiveAt(int x, int y) LOG_INFO(3, "GPUKernel::getPrimitiveAt(" << x << "," << y << ")"); unsigned int returnValue = -1; unsigned int index = y * m_sceneInfo.size.x + x; - if (index < static_cast(m_sceneInfo.size.x * m_sceneInfo.size.y)) + if (index < + static_cast(m_sceneInfo.size.x * m_sceneInfo.size.y)) { returnValue = m_hPrimitivesXYIds[index].x; } @@ -758,7 +806,8 @@ bool GPUKernel::updateBoundingBox(CPUBoundingBox &box) for (const auto &p : box.primitives) { CPUPrimitive &primitive = (m_primitives[m_frame])[p]; - result = (m_hMaterials[primitive.materialId].innerIllumination.x != 0.f); + result = + (m_hMaterials[primitive.materialId].innerIllumination.x != 0.f); switch (primitive.type) { case ptTriangle: @@ -838,7 +887,8 @@ bool GPUKernel::updateBoundingBox(CPUBoundingBox &box) return result; } -bool GPUKernel::updateOutterBoundingBox(CPUBoundingBox &outterBox, const int depth) +bool GPUKernel::updateOutterBoundingBox(CPUBoundingBox &outterBox, + const int depth) { LOG_INFO(3, "GPUKernel::updateOutterBoundingBox()"); @@ -852,11 +902,16 @@ bool GPUKernel::updateOutterBoundingBox(CPUBoundingBox &outterBox, const int dep outterBox.parameters[1].y = -m_sceneInfo.viewDistance; outterBox.parameters[1].z = -m_sceneInfo.viewDistance; - LOG_INFO(3, "OutterBox: (" << outterBox.center.x << "," << outterBox.center.y << "," << outterBox.center.z << "),(" - << outterBox.indexForNextBox << "," << outterBox.primitives.size() << "),(" - << outterBox.parameters[0].x << "," << outterBox.parameters[0].y << "," - << outterBox.parameters[0].z << "),(" << outterBox.parameters[1].x << "," - << outterBox.parameters[1].y << "," << outterBox.parameters[1].z << ")"); + LOG_INFO(3, "OutterBox: (" + << outterBox.center.x << "," << outterBox.center.y << "," + << outterBox.center.z << "),(" << outterBox.indexForNextBox + << "," << outterBox.primitives.size() << "),(" + << outterBox.parameters[0].x << "," + << outterBox.parameters[0].y << "," + << outterBox.parameters[0].z << "),(" + << outterBox.parameters[1].x << "," + << outterBox.parameters[1].y << "," + << outterBox.parameters[1].z << ")"); // Process box size for (const auto &p : outterBox.primitives) @@ -882,9 +937,12 @@ bool GPUKernel::updateOutterBoundingBox(CPUBoundingBox &outterBox, const int dep LOG_ERROR("Ca chie grave dans les boites!"); } } - outterBox.center.x = (outterBox.parameters[0].x + outterBox.parameters[1].x) / 2.f; - outterBox.center.y = (outterBox.parameters[0].y + outterBox.parameters[1].y) / 2.f; - outterBox.center.z = (outterBox.parameters[0].z + outterBox.parameters[1].z) / 2.f; + outterBox.center.x = + (outterBox.parameters[0].x + outterBox.parameters[1].x) / 2.f; + outterBox.center.y = + (outterBox.parameters[0].y + outterBox.parameters[1].y) / 2.f; + outterBox.center.z = + (outterBox.parameters[0].z + outterBox.parameters[1].z) / 2.f; return result; } @@ -892,7 +950,7 @@ bool GPUKernel::updateOutterBoundingBox(CPUBoundingBox &outterBox, const int dep void GPUKernel::resetBoxes(bool resetPrimitives) { if (resetPrimitives) - for (int i(0); i < m_boundingBoxes[m_frame][0].size(); ++i) + for (size_t i = 0; i < m_boundingBoxes[m_frame][0].size(); ++i) resetBox(m_boundingBoxes[m_frame][0][i], resetPrimitives); else m_boundingBoxes[m_frame][0].clear(); @@ -935,9 +993,12 @@ int GPUKernel::processBoxes(const int boxSize, bool simulate) auto &primitive = prim.second; const auto ¢er = primitive.p0; - unsigned int X = static_cast((center.x - m_minPos[m_frame].x) / boxSteps.x); - unsigned int Y = static_cast((center.y - m_minPos[m_frame].y) / boxSteps.y); - unsigned int Z = static_cast((center.z - m_minPos[m_frame].z) / boxSteps.z); + unsigned int X = + static_cast((center.x - m_minPos[m_frame].x) / boxSteps.x); + unsigned int Y = + static_cast((center.y - m_minPos[m_frame].y) / boxSteps.y); + unsigned int Z = + static_cast((center.z - m_minPos[m_frame].z) / boxSteps.z); unsigned int B = 1 + 1000 * (X * boxSize * boxSize + Y * boxSize + Z); if (simulate) @@ -966,17 +1027,23 @@ int GPUKernel::processBoxes(const int boxSize, bool simulate) if (m_hMaterials[primitive.materialId].innerIllumination.x != 0.f) { // Lights are added to first box of higher level - m_boundingBoxes[m_frame][m_treeDepth][0].primitives.push_back(p); - LOG_INFO(3, "[" << m_treeDepth << "] Lamp " << p << " added (" << primitive.p0.x << "," - << primitive.p0.y << "," << primitive.p0.z << " " << m_nbActiveLamps[m_frame] << "/" - << NB_MAX_LAMPS << "), Material ID=" << primitive.materialId); + m_boundingBoxes[m_frame][m_treeDepth][0].primitives.push_back( + p); + LOG_INFO(3, "[" << m_treeDepth << "] Lamp " << p << " added (" + << primitive.p0.x << "," << primitive.p0.y + << "," << primitive.p0.z << " " + << m_nbActiveLamps[m_frame] << "/" + << NB_MAX_LAMPS + << "), Material ID=" << primitive.materialId); } else { // LOG_INFO(3, "Adding primitive to box " << B); m_boundingBoxes[m_frame][0][B].primitives.push_back(p); - if (m_boundingBoxes[m_frame][0][B].primitives.size() > maxPrimitivesPerBox) - maxPrimitivesPerBox = m_boundingBoxes[m_frame][0][B].primitives.size(); + if (m_boundingBoxes[m_frame][0][B].primitives.size() > + maxPrimitivesPerBox) + maxPrimitivesPerBox = + m_boundingBoxes[m_frame][0][B].primitives.size(); } } ++p; @@ -987,13 +1054,16 @@ int GPUKernel::processBoxes(const int boxSize, bool simulate) for (auto &box : m_boundingBoxes[m_frame][0]) updateBoundingBox(box.second); - LOG_INFO(3, "Maximum number of primitives per box=" << maxPrimitivesPerBox << " for level 0"); + LOG_INFO(3, "Maximum number of primitives per box=" << maxPrimitivesPerBox + << " for level 0"); return static_cast(maxPrimitivesPerBox); } -int GPUKernel::processOutterBoxes(const int boxSize, const int boundingBoxesDepth) +int GPUKernel::processOutterBoxes(const int boxSize, + const int boundingBoxesDepth) { - LOG_INFO(3, "processOutterBoxes(" << boxSize << "," << boundingBoxesDepth << ")"); + LOG_INFO(3, "processOutterBoxes(" << boxSize << "," << boundingBoxesDepth + << ")"); vec4f boxSteps; boxSteps.x = (m_maxPos[m_frame].x - m_minPos[m_frame].x) / boxSize; boxSteps.y = (m_maxPos[m_frame].y - m_minPos[m_frame].y) / boxSize; @@ -1013,34 +1083,48 @@ int GPUKernel::processOutterBoxes(const int boxSize, const int boundingBoxesDept int Z = static_cast((center.z - m_minPos[m_frame].z) / boxSteps.z); int B = (X * boxSize * boxSize + Y * boxSize + Z); - B++; // Index 0 is used to store lights, so we start storing primitives - // from index 1 + B++; // Index 0 is used to store lights, so we start storing + // primitives from index 1 // Box B - m_boundingBoxes[m_frame][boundingBoxesDepth][B].parameters[0].x = m_sceneInfo.viewDistance; - m_boundingBoxes[m_frame][boundingBoxesDepth][B].parameters[0].y = m_sceneInfo.viewDistance; - m_boundingBoxes[m_frame][boundingBoxesDepth][B].parameters[0].z = m_sceneInfo.viewDistance; - m_boundingBoxes[m_frame][boundingBoxesDepth][B].parameters[1].x = -m_sceneInfo.viewDistance; - m_boundingBoxes[m_frame][boundingBoxesDepth][B].parameters[1].y = -m_sceneInfo.viewDistance; - m_boundingBoxes[m_frame][boundingBoxesDepth][B].parameters[1].z = -m_sceneInfo.viewDistance; - m_boundingBoxes[m_frame][boundingBoxesDepth][B].primitives.push_back(box.first); - if (m_boundingBoxes[m_frame][boundingBoxesDepth][B].primitives.size() > maxPrimitivesPerBox) - maxPrimitivesPerBox = m_boundingBoxes[m_frame][boundingBoxesDepth][B].primitives.size(); - } - LOG_INFO(3, "Depth " << boundingBoxesDepth << ": " << m_boundingBoxes[m_frame][boundingBoxesDepth].size() + m_boundingBoxes[m_frame][boundingBoxesDepth][B].parameters[0].x = + m_sceneInfo.viewDistance; + m_boundingBoxes[m_frame][boundingBoxesDepth][B].parameters[0].y = + m_sceneInfo.viewDistance; + m_boundingBoxes[m_frame][boundingBoxesDepth][B].parameters[0].z = + m_sceneInfo.viewDistance; + m_boundingBoxes[m_frame][boundingBoxesDepth][B].parameters[1].x = + -m_sceneInfo.viewDistance; + m_boundingBoxes[m_frame][boundingBoxesDepth][B].parameters[1].y = + -m_sceneInfo.viewDistance; + m_boundingBoxes[m_frame][boundingBoxesDepth][B].parameters[1].z = + -m_sceneInfo.viewDistance; + m_boundingBoxes[m_frame][boundingBoxesDepth][B].primitives.push_back( + box.first); + if (m_boundingBoxes[m_frame][boundingBoxesDepth][B].primitives.size() > + maxPrimitivesPerBox) + maxPrimitivesPerBox = + m_boundingBoxes[m_frame][boundingBoxesDepth][B] + .primitives.size(); + } + LOG_INFO(3, "Depth " << boundingBoxesDepth << ": " + << m_boundingBoxes[m_frame][boundingBoxesDepth].size() << " created"); // Now update box sizes for (auto &box : m_boundingBoxes[m_frame][boundingBoxesDepth]) updateOutterBoundingBox(box.second, boundingBoxesDepth - 1); - LOG_INFO(3, "Maximum number of sub-boxes per box=" << maxPrimitivesPerBox << " for level " << boundingBoxesDepth); + LOG_INFO(3, "Maximum number of sub-boxes per box=" << maxPrimitivesPerBox + << " for level " + << boundingBoxesDepth); return static_cast(maxPrimitivesPerBox); } int GPUKernel::compactBoxes(bool reconstructBoxes) { - LOG_INFO(3, "GPUKernel::compactBoxes (" << (reconstructBoxes ? "true" : "false") << ")"); + LOG_INFO(3, "GPUKernel::compactBoxes (" + << (reconstructBoxes ? "true" : "false") << ")"); // First box of highest level is dedicated to light sources m_primitivesTransfered = false; @@ -1073,8 +1157,8 @@ int GPUKernel::compactBoxes(bool reconstructBoxes) processOutterBoxes(nbBoxes, m_treeDepth); nbBoxes /= gridDivider; } while (nbBoxes > gridGranularity); - LOG_INFO(1, "Primitives.........: " << m_primitives[m_frame].size()); - LOG_INFO(1, "Scene depth........: " << m_treeDepth); + LOG_INFO(2, "Primitives.........: " << m_primitives[m_frame].size()); + LOG_INFO(2, "Scene depth........: " << m_treeDepth); } LOG_INFO(3, "Streaming data to GPU"); @@ -1082,10 +1166,12 @@ int GPUKernel::compactBoxes(bool reconstructBoxes) return static_cast(m_nbActiveBoxes[m_frame]); } -void GPUKernel::recursiveDataStreamToGPU(const int depth, std::vector &elements) +void GPUKernel::recursiveDataStreamToGPU(const int depth, + std::vector &elements) { LOG_INFO(3, "RecursiveDataStreamToGPU(" << depth << ")"); - LOG_INFO(3, "Depth " << depth << " contains " << elements.size() << " boxes"); + LOG_INFO(3, + "Depth " << depth << " contains " << elements.size() << " boxes"); size_t c = 0; for (const auto &element : elements) @@ -1093,23 +1179,31 @@ void GPUKernel::recursiveDataStreamToGPU(const int depth, std::vector &ele // Create Box CPUBoundingBox &box = m_boundingBoxes[m_frame][depth][element]; - if (box.primitives.size() != 0 && m_nbActiveBoxes[m_frame] < NB_MAX_BOXES) + if (box.primitives.size() != 0 && + m_nbActiveBoxes[m_frame] < NB_MAX_BOXES) { int boxIndex = m_nbActiveBoxes[m_frame]; m_hBoundingBoxes[boxIndex].parameters[0] = box.parameters[0]; m_hBoundingBoxes[boxIndex].parameters[1] = box.parameters[1]; - m_hBoundingBoxes[boxIndex].nbPrimitives = (depth == 0) ? static_cast(box.primitives.size()) : 0; - m_hBoundingBoxes[boxIndex].startIndex = (depth == 0) ? m_nbActivePrimitives[m_frame] : depth; - LOG_INFO(3, "==> Box " << boxIndex << " Depth [" << depth << "] ++"); + m_hBoundingBoxes[boxIndex].nbPrimitives = + (depth == 0) ? static_cast(box.primitives.size()) : 0; + m_hBoundingBoxes[boxIndex].startIndex = + (depth == 0) ? m_nbActivePrimitives[m_frame] : depth; + LOG_INFO(3, + "==> Box " << boxIndex << " Depth [" << depth << "] ++"); ++m_nbActiveBoxes[m_frame]; ++c; if (depth == 0) { - LOG_INFO(3, "=== Box " << boxIndex << " Depth [" << depth << "] ... adding " << box.primitives.size() + LOG_INFO(3, "=== Box " << boxIndex << " Depth [" << depth + << "] ... adding " + << box.primitives.size() << " primitives"); m_maxPrimitivesPerBox = - (box.primitives.size() > m_maxPrimitivesPerBox) ? box.primitives.size() : m_maxPrimitivesPerBox; + (box.primitives.size() > m_maxPrimitivesPerBox) + ? box.primitives.size() + : m_maxPrimitivesPerBox; // Add primitive for Nodes std::vector::const_iterator itp = box.primitives.begin(); while (itp != box.primitives.end()) @@ -1118,19 +1212,32 @@ void GPUKernel::recursiveDataStreamToGPU(const int depth, std::vector &ele if ((*itp) < NB_MAX_PRIMITIVES) { CPUPrimitive &primitive = (m_primitives[m_frame])[*itp]; - m_hPrimitives[m_nbActivePrimitives[m_frame]].index = (*itp); - m_hPrimitives[m_nbActivePrimitives[m_frame]].type = primitive.type; - m_hPrimitives[m_nbActivePrimitives[m_frame]].p0 = primitive.p0; - m_hPrimitives[m_nbActivePrimitives[m_frame]].p1 = primitive.p1; - m_hPrimitives[m_nbActivePrimitives[m_frame]].p2 = primitive.p2; - m_hPrimitives[m_nbActivePrimitives[m_frame]].n0 = primitive.n0; - m_hPrimitives[m_nbActivePrimitives[m_frame]].n1 = primitive.n1; - m_hPrimitives[m_nbActivePrimitives[m_frame]].n2 = primitive.n2; - m_hPrimitives[m_nbActivePrimitives[m_frame]].size = primitive.size; - m_hPrimitives[m_nbActivePrimitives[m_frame]].materialId = primitive.materialId; - m_hPrimitives[m_nbActivePrimitives[m_frame]].vt0 = primitive.vt0; - m_hPrimitives[m_nbActivePrimitives[m_frame]].vt1 = primitive.vt1; - m_hPrimitives[m_nbActivePrimitives[m_frame]].vt2 = primitive.vt2; + m_hPrimitives[m_nbActivePrimitives[m_frame]].index = + (*itp); + m_hPrimitives[m_nbActivePrimitives[m_frame]].type = + primitive.type; + m_hPrimitives[m_nbActivePrimitives[m_frame]].p0 = + primitive.p0; + m_hPrimitives[m_nbActivePrimitives[m_frame]].p1 = + primitive.p1; + m_hPrimitives[m_nbActivePrimitives[m_frame]].p2 = + primitive.p2; + m_hPrimitives[m_nbActivePrimitives[m_frame]].n0 = + primitive.n0; + m_hPrimitives[m_nbActivePrimitives[m_frame]].n1 = + primitive.n1; + m_hPrimitives[m_nbActivePrimitives[m_frame]].n2 = + primitive.n2; + m_hPrimitives[m_nbActivePrimitives[m_frame]].size = + primitive.size; + m_hPrimitives[m_nbActivePrimitives[m_frame]] + .materialId = primitive.materialId; + m_hPrimitives[m_nbActivePrimitives[m_frame]].vt0 = + primitive.vt0; + m_hPrimitives[m_nbActivePrimitives[m_frame]].vt1 = + primitive.vt1; + m_hPrimitives[m_nbActivePrimitives[m_frame]].vt2 = + primitive.vt2; ++m_nbActivePrimitives[m_frame]; } ++itp; @@ -1140,16 +1247,23 @@ void GPUKernel::recursiveDataStreamToGPU(const int depth, std::vector &ele // Resursively continue to build the tree recursiveDataStreamToGPU(depth - 1, box.primitives); - m_hBoundingBoxes[boxIndex].indexForNextBox.x = (depth == 0) ? 1 : m_nbActiveBoxes[m_frame] - boxIndex; - LOG_INFO(3, "<== Box " << boxIndex << " Depth [" << depth << "] --> " - << m_hBoundingBoxes[boxIndex].indexForNextBox.x << " = box " - << boxIndex + m_hBoundingBoxes[boxIndex].indexForNextBox.x); + m_hBoundingBoxes[boxIndex].indexForNextBox.x = + (depth == 0) ? 1 : m_nbActiveBoxes[m_frame] - boxIndex; + LOG_INFO(3, + "<== Box " + << boxIndex << " Depth [" << depth << "] --> " + << m_hBoundingBoxes[boxIndex].indexForNextBox.x + << " = box " + << boxIndex + + m_hBoundingBoxes[boxIndex].indexForNextBox.x); } } } void GPUKernel::streamDataToGPU() { + RandomGenerator::getInstance().pause(); + LOG_INFO(3, "GPUKernel::streamDataToGPU"); // -------------------------------------------------------------------------------- // Transform data for ray-tracer @@ -1163,7 +1277,8 @@ void GPUKernel::streamDataToGPU() // Build boxes tree recursively int maxDepth(m_treeDepth); - LOG_INFO(3, "Processing " << m_boundingBoxes[m_frame][maxDepth].size() << " master boxes"); + LOG_INFO(3, "Processing " << m_boundingBoxes[m_frame][maxDepth].size() + << " master boxes"); BoxContainer::iterator itob = m_boundingBoxes[m_frame][maxDepth].begin(); while (itob != m_boundingBoxes[m_frame][maxDepth].end()) { @@ -1180,13 +1295,20 @@ void GPUKernel::streamDataToGPU() { LOG_INFO(3, "Box 0 of higher level (" << 0 << ") contains ligths"); m_lightInformationSize = 0; - m_hBoundingBoxes[boxIndex].parameters[0].x = -m_sceneInfo.viewDistance; - m_hBoundingBoxes[boxIndex].parameters[0].y = -m_sceneInfo.viewDistance; - m_hBoundingBoxes[boxIndex].parameters[0].z = -m_sceneInfo.viewDistance; - m_hBoundingBoxes[boxIndex].parameters[1].x = m_sceneInfo.viewDistance; - m_hBoundingBoxes[boxIndex].parameters[1].y = m_sceneInfo.viewDistance; - m_hBoundingBoxes[boxIndex].parameters[1].z = m_sceneInfo.viewDistance; - m_hBoundingBoxes[boxIndex].nbPrimitives = static_cast(box.primitives.size()); + m_hBoundingBoxes[boxIndex].parameters[0].x = + -m_sceneInfo.viewDistance; + m_hBoundingBoxes[boxIndex].parameters[0].y = + -m_sceneInfo.viewDistance; + m_hBoundingBoxes[boxIndex].parameters[0].z = + -m_sceneInfo.viewDistance; + m_hBoundingBoxes[boxIndex].parameters[1].x = + m_sceneInfo.viewDistance; + m_hBoundingBoxes[boxIndex].parameters[1].y = + m_sceneInfo.viewDistance; + m_hBoundingBoxes[boxIndex].parameters[1].z = + m_sceneInfo.viewDistance; + m_hBoundingBoxes[boxIndex].nbPrimitives = + static_cast(box.primitives.size()); m_hBoundingBoxes[boxIndex].startIndex = 0; std::vector::const_iterator itp = box.primitives.begin(); while (itp != box.primitives.end()) @@ -1194,24 +1316,31 @@ void GPUKernel::streamDataToGPU() // Add the primitive CPUPrimitive &primitive = (m_primitives[m_frame])[*itp]; m_hPrimitives[m_nbActivePrimitives[m_frame]].index = (*itp); - m_hPrimitives[m_nbActivePrimitives[m_frame]].type = primitive.type; + m_hPrimitives[m_nbActivePrimitives[m_frame]].type = + primitive.type; m_hPrimitives[m_nbActivePrimitives[m_frame]].p0 = primitive.p0; m_hPrimitives[m_nbActivePrimitives[m_frame]].p1 = primitive.p1; m_hPrimitives[m_nbActivePrimitives[m_frame]].p2 = primitive.p2; m_hPrimitives[m_nbActivePrimitives[m_frame]].n0 = primitive.n0; m_hPrimitives[m_nbActivePrimitives[m_frame]].n1 = primitive.n1; m_hPrimitives[m_nbActivePrimitives[m_frame]].n2 = primitive.n2; - m_hPrimitives[m_nbActivePrimitives[m_frame]].size = primitive.size; - m_hPrimitives[m_nbActivePrimitives[m_frame]].materialId = primitive.materialId; - m_hPrimitives[m_nbActivePrimitives[m_frame]].vt0 = primitive.vt0; - m_hPrimitives[m_nbActivePrimitives[m_frame]].vt1 = primitive.vt1; - m_hPrimitives[m_nbActivePrimitives[m_frame]].vt2 = primitive.vt2; + m_hPrimitives[m_nbActivePrimitives[m_frame]].size = + primitive.size; + m_hPrimitives[m_nbActivePrimitives[m_frame]].materialId = + primitive.materialId; + m_hPrimitives[m_nbActivePrimitives[m_frame]].vt0 = + primitive.vt0; + m_hPrimitives[m_nbActivePrimitives[m_frame]].vt1 = + primitive.vt1; + m_hPrimitives[m_nbActivePrimitives[m_frame]].vt2 = + primitive.vt2; ++m_nbActivePrimitives[m_frame]; // Add light information related to primitive Material &material = m_hMaterials[primitive.materialId]; LightInformation lightInformation; - LOG_INFO(3, "LightInformation " << (*itp) << ", MaterialId=" << primitive.materialId); + LOG_INFO(3, "LightInformation " << (*itp) << ", MaterialId=" + << primitive.materialId); lightInformation.primitiveId = (*itp); lightInformation.materialId = primitive.materialId; @@ -1226,15 +1355,27 @@ void GPUKernel::streamDataToGPU() m_lightInformation[m_lightInformationSize] = lightInformation; - LOG_INFO(3, "Adding Light Information: " << m_lightInformation[m_lightInformationSize].primitiveId - << "," << m_lightInformation[m_lightInformationSize].materialId - << ":" << m_lightInformation[m_lightInformationSize].location.x - << "," << m_lightInformation[m_lightInformationSize].location.y - << "," << m_lightInformation[m_lightInformationSize].location.z - << " " << m_lightInformation[m_lightInformationSize].color.x - << "," << m_lightInformation[m_lightInformationSize].color.y - << "," << m_lightInformation[m_lightInformationSize].color.z - << " " << m_lightInformation[m_lightInformationSize].color.w); + LOG_INFO( + 3, + "Adding Light Information: " + << m_lightInformation[m_lightInformationSize] + .primitiveId + << "," + << m_lightInformation[m_lightInformationSize].materialId + << ":" + << m_lightInformation[m_lightInformationSize].location.x + << "," + << m_lightInformation[m_lightInformationSize].location.y + << "," + << m_lightInformation[m_lightInformationSize].location.z + << " " + << m_lightInformation[m_lightInformationSize].color.x + << "," + << m_lightInformation[m_lightInformationSize].color.y + << "," + << m_lightInformation[m_lightInformationSize].color.z + << " " + << m_lightInformation[m_lightInformationSize].color.w); m_hLamps[m_nbActiveLamps[m_frame]] = *itp; ++m_nbActiveLamps[m_frame]; @@ -1249,11 +1390,14 @@ void GPUKernel::streamDataToGPU() if (maxDepth > 0) recursiveDataStreamToGPU(maxDepth - 1, box.primitives); - m_hBoundingBoxes[boxIndex].indexForNextBox.x = m_nbActiveBoxes[m_frame] - boxIndex; - LOG_INFO(3, "Master Primitive (" << box.parameters[0].x << "," << box.parameters[0].y << "," - << box.parameters[0].z << "),(" << box.parameters[1].x << "," - << box.parameters[1].y << "," << box.parameters[1].z << ")," - << m_hBoundingBoxes[boxIndex].indexForNextBox.x); + m_hBoundingBoxes[boxIndex].indexForNextBox.x = + m_nbActiveBoxes[m_frame] - boxIndex; + LOG_INFO(3, "Master Primitive (" + << box.parameters[0].x << "," << box.parameters[0].y + << "," << box.parameters[0].z << "),(" + << box.parameters[1].x << "," << box.parameters[1].y + << "," << box.parameters[1].z << ")," + << m_hBoundingBoxes[boxIndex].indexForNextBox.x); ++itob; } @@ -1263,21 +1407,27 @@ void GPUKernel::streamDataToGPU() // buildLightInformationFromTexture(4); // Done - LOG_INFO(3, "Compacted " << m_nbActiveBoxes[m_frame] << " boxes, " << m_nbActivePrimitives[m_frame] - << " primitives and " << m_nbActiveLamps[m_frame] << " lamps"); + LOG_INFO(3, "Compacted " << m_nbActiveBoxes[m_frame] << " boxes, " + << m_nbActivePrimitives[m_frame] + << " primitives and " << m_nbActiveLamps[m_frame] + << " lamps"); if (m_nbActivePrimitives[m_frame] != m_primitives[m_frame].size()) { - LOG_ERROR("Lost primitives on the way for frame " << m_frame << "... " << m_nbActivePrimitives[m_frame] - << "!=" << m_primitives[m_frame].size()); + LOG_ERROR("Lost primitives on the way for frame " + << m_frame << "... " << m_nbActivePrimitives[m_frame] + << "!=" << m_primitives[m_frame].size()); } - for (int i(0); i < m_nbActiveBoxes[m_frame]; ++i) + for (size_t i = 0; i < m_nbActiveBoxes[m_frame]; ++i) { - if (i + m_hBoundingBoxes[i].indexForNextBox.x > m_nbActiveBoxes[m_frame]) + if (i + m_hBoundingBoxes[i].indexForNextBox.x > + m_nbActiveBoxes[m_frame]) { - LOG_ERROR("Box " << i << " --> " << i + m_hBoundingBoxes[i].indexForNextBox.x); + LOG_ERROR("Box " << i << " --> " + << i + m_hBoundingBoxes[i].indexForNextBox.x); } } + RandomGenerator::getInstance().resume(); } void GPUKernel::resetFrame() @@ -1288,7 +1438,7 @@ void GPUKernel::resetFrame() m_currentMaterial = 0; - for (int i(0); i < BOUNDING_BOXES_TREE_DEPTH; ++i) + for (size_t i = 0; i < BOUNDING_BOXES_TREE_DEPTH; ++i) m_boundingBoxes[m_frame][i].clear(); m_boundingBoxes[m_frame][0].clear(); @@ -1326,16 +1476,16 @@ void GPUKernel::resetAll() m_nbActiveMaterials = -1; m_materialsTransfered = false; - for (int i(0); i < NB_MAX_TEXTURES; ++i) + for (size_t i = 0; i < NB_MAX_TEXTURES; ++i) { #ifdef USE_KINECT if (i > 1 && m_hTextures[i].buffer != 0) - delete[] m_hTextures[i].buffer; + delete m_hTextures[i].buffer; #else if (m_hTextures[i].buffer) { LOG_INFO(3, "[resetAll] Buffer " << i << " needs to be released"); - delete[] m_hTextures[i].buffer; + delete m_hTextures[i].buffer; m_hTextures[i].buffer = 0; } #endif // USE_KINECT @@ -1350,32 +1500,37 @@ void GPUKernel::resetAll() void GPUKernel::displayBoxesInfo() { - for (unsigned int i(0); i <= m_boundingBoxes[m_frame][0].size(); ++i) + for (unsigned int i = 0; i <= m_boundingBoxes[m_frame][0].size(); ++i) { CPUBoundingBox &box = m_boundingBoxes[m_frame][0][i]; LOG_INFO(3, "Box " << i); LOG_INFO(3, "- # of primitives: " << box.primitives.size()); - LOG_INFO(3, "- Corners 1 : " << box.parameters[0].x << "," << box.parameters[0].y << "," + LOG_INFO(3, "- Corners 1 : " << box.parameters[0].x << "," + << box.parameters[0].y << "," << box.parameters[0].z); - LOG_INFO(3, "- Corners 2 : " << box.parameters[1].x << "," << box.parameters[1].y << "," + LOG_INFO(3, "- Corners 2 : " << box.parameters[1].x << "," + << box.parameters[1].y << "," << box.parameters[1].z); unsigned int p(0); std::vector::const_iterator it = box.primitives.begin(); while (it != box.primitives.end()) { CPUPrimitive &primitive((m_primitives[m_frame])[*it]); - LOG_INFO(3, "- - " << p << ":" - << "type = " << primitive.type << ", " - << "center = (" << primitive.p0.x << "," << primitive.p0.y << "," << primitive.p0.z - << "), " - << "p1 = (" << primitive.p1.x << "," << primitive.p1.y << "," << primitive.p1.z << ")"); + LOG_INFO(3, "- - " + << p << ":" + << "type = " << primitive.type << ", " + << "center = (" << primitive.p0.x << "," + << primitive.p0.y << "," << primitive.p0.z << "), " + << "p1 = (" << primitive.p1.x << "," + << primitive.p1.y << "," << primitive.p1.z << ")"); ++p; ++it; } } } -void GPUKernel::rotatePrimitives(const vec3f &rotationCenter, const vec4f &angles) +void GPUKernel::rotatePrimitives(const vec3f &rotationCenter, + const vec4f &angles) { LOG_INFO(3, "GPUKernel::rotatePrimitives"); @@ -1391,15 +1546,16 @@ void GPUKernel::rotatePrimitives(const vec3f &rotationCenter, const vec4f &angle sinAngles.z = sin(angles.z); #pragma omp parallel - for (BoxContainer::iterator itb = m_boundingBoxes[m_frame][0].begin(); itb != m_boundingBoxes[m_frame][0].end(); - ++itb) + for (BoxContainer::iterator itb = m_boundingBoxes[m_frame][0].begin(); + itb != m_boundingBoxes[m_frame][0].end(); ++itb) { #pragma omp single nowait { CPUBoundingBox &box = (*itb).second; resetBox(box, false); - for (std::vector::iterator it = box.primitives.begin(); it != box.primitives.end(); ++it) + for (std::vector::iterator it = box.primitives.begin(); + it != box.primitives.end(); ++it) { //#pragma single nowait CPUPrimitive &primitive((m_primitives[m_frame])[*it]); @@ -1435,7 +1591,8 @@ void GPUKernel::rotatePrimitives(const vec3f &rotationCenter, const vec4f &angle primitive.speed0.y = 0.f; } #else - rotatePrimitive(primitive, rotationCenter, cosAngles, sinAngles); + rotatePrimitive(primitive, rotationCenter, cosAngles, + sinAngles); #endif // 0 } updateBoundingBox(box); @@ -1447,8 +1604,8 @@ void GPUKernel::rotatePrimitives(const vec3f &rotationCenter, const vec4f &angle for (int b(1); b < BOUNDING_BOXES_TREE_DEPTH; ++b) { #pragma omp parallel - for (BoxContainer::iterator itb = m_boundingBoxes[m_frame][b].begin(); itb != m_boundingBoxes[m_frame][b].end(); - ++itb) + for (BoxContainer::iterator itb = m_boundingBoxes[m_frame][b].begin(); + itb != m_boundingBoxes[m_frame][b].end(); ++itb) { #pragma omp single nowait { @@ -1461,17 +1618,19 @@ void GPUKernel::rotatePrimitives(const vec3f &rotationCenter, const vec4f &angle void GPUKernel::translatePrimitives(const vec3f &translation) { - LOG_INFO(3, "GPUKernel::translatePrimitives (" << m_boundingBoxes[m_frame][0].size() << ")"); + LOG_INFO(3, "GPUKernel::translatePrimitives (" + << m_boundingBoxes[m_frame][0].size() << ")"); m_primitivesTransfered = false; - for (BoxContainer::iterator itb = m_boundingBoxes[m_frame][0].begin(); itb != m_boundingBoxes[m_frame][0].end(); - ++itb) + for (BoxContainer::iterator itb = m_boundingBoxes[m_frame][0].begin(); + itb != m_boundingBoxes[m_frame][0].end(); ++itb) { #pragma omp single nowait { CPUBoundingBox &box = (*itb).second; resetBox(box, false); - for (std::vector::iterator it = box.primitives.begin(); it != box.primitives.end(); ++it) + for (std::vector::iterator it = box.primitives.begin(); + it != box.primitives.end(); ++it) { //#pragma single nowait CPUPrimitive &primitive((m_primitives[m_frame])[*it]); @@ -1498,8 +1657,8 @@ void GPUKernel::translatePrimitives(const vec3f &translation) for (int b(1); b < BOUNDING_BOXES_TREE_DEPTH; ++b) { #pragma omp parallel - for (BoxContainer::iterator itb = m_boundingBoxes[m_frame][b].begin(); itb != m_boundingBoxes[m_frame][b].end(); - ++itb) + for (BoxContainer::iterator itb = m_boundingBoxes[m_frame][b].begin(); + itb != m_boundingBoxes[m_frame][b].end(); ++itb) { #pragma omp single nowait { @@ -1515,19 +1674,23 @@ void GPUKernel::morphPrimitives() LOG_INFO(3, "Morphing frames " << m_nbFrames); for (unsigned int frame(1); frame < (m_nbFrames - 1); ++frame) { - LOG_INFO(3, "Morphing frame " << frame << ", " << m_primitives[0].size() << " primitives"); + LOG_INFO(3, "Morphing frame " << frame << ", " << m_primitives[0].size() + << " primitives"); setFrame(frame); resetFrame(); PrimitiveContainer::iterator it2 = m_primitives[m_nbFrames - 1].begin(); for (PrimitiveContainer::iterator it1 = m_primitives[0].begin(); - it1 != m_primitives[0].end() && it2 != m_primitives[m_nbFrames - 1].end(); ++it1) + it1 != m_primitives[0].end() && + it2 != m_primitives[m_nbFrames - 1].end(); + ++it1) { CPUPrimitive &primitive1((*it1).second); CPUPrimitive &primitive2((*it2).second); vec3f p0, p1, p2; vec3f n0, n1, n2; vec3f size; - float r = static_cast(m_frame) / static_cast(m_nbFrames); + float r = + static_cast(m_frame) / static_cast(m_nbFrames); p0.x = primitive1.p0.x + r * (primitive2.p0.x - primitive1.p0.x); p0.y = primitive1.p0.y + r * (primitive2.p0.y - primitive1.p0.y); p0.z = primitive1.p0.z + r * (primitive2.p0.z - primitive1.p0.z); @@ -1552,16 +1715,20 @@ void GPUKernel::morphPrimitives() n2.y = primitive1.n2.y + r * (primitive2.n2.y - primitive1.n2.y); n2.z = primitive1.n2.z + r * (primitive2.n2.z - primitive1.n2.z); - size.x = primitive1.size.x + r * (primitive2.size.x - primitive1.size.x); - size.y = primitive1.size.y + r * (primitive2.size.y - primitive1.size.y); - size.z = primitive1.size.z + r * (primitive2.size.z - primitive1.size.z); + size.x = + primitive1.size.x + r * (primitive2.size.x - primitive1.size.x); + size.y = + primitive1.size.y + r * (primitive2.size.y - primitive1.size.y); + size.z = + primitive1.size.z + r * (primitive2.size.z - primitive1.size.z); int i = addPrimitive(PrimitiveType(primitive1.type)); - setPrimitive(i, p0.x, p0.y, p0.z, p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, size.x, size.y, size.z, - primitive1.materialId); + setPrimitive(i, p0.x, p0.y, p0.z, p1.x, p1.y, p1.z, p2.x, p2.y, + p2.z, size.x, size.y, size.z, primitive1.materialId); setPrimitiveNormals(i, n0, n1, n2); - setPrimitiveTextureCoordinates(i, primitive1.vt0, primitive1.vt1, primitive1.vt2); + setPrimitiveTextureCoordinates(i, primitive1.vt0, primitive1.vt1, + primitive1.vt2); setPrimitiveIsMovable(i, primitive1.movable); @@ -1599,7 +1766,8 @@ void GPUKernel::scalePrimitives(float scale, unsigned int from, unsigned int to) } } -void GPUKernel::rotateVector(vec3f &v, const vec3f &rotationCenter, const vec3f &cosAngles, const vec3f &sinAngles) +void GPUKernel::rotateVector(vec3f &v, const vec3f &rotationCenter, + const vec3f &cosAngles, const vec3f &sinAngles) { // Rotate Center vec3f vector; @@ -1629,15 +1797,17 @@ void GPUKernel::rotateVector(vec3f &v, const vec3f &rotationCenter, const vec3f v.z = result.z + rotationCenter.z; } -void GPUKernel::rotateBox(CPUBoundingBox &box, vec3f rotationCenter, vec3f cosAngles, vec3f sinAngles) +void GPUKernel::rotateBox(CPUBoundingBox &box, vec3f rotationCenter, + vec3f cosAngles, vec3f sinAngles) { LOG_INFO(3, "GPUKernel::rotatePrimitive"); rotateVector(box.parameters[0], rotationCenter, cosAngles, sinAngles); rotateVector(box.parameters[1], rotationCenter, cosAngles, sinAngles); } -void GPUKernel::rotatePrimitive(CPUPrimitive &primitive, const vec3f &rotationCenter, const vec3f &cosAngles, - const vec3f &sinAngles) +void GPUKernel::rotatePrimitive(CPUPrimitive &primitive, + const vec3f &rotationCenter, + const vec3f &cosAngles, const vec3f &sinAngles) { LOG_INFO(3, "GPUKernel::rotatePrimitive"); rotateVector(primitive.p0, rotationCenter, cosAngles, sinAngles); @@ -1657,7 +1827,8 @@ void GPUKernel::rotatePrimitive(CPUPrimitive &primitive, const vec3f &rotationCe axis.x = primitive.p1.x - primitive.p0.x; axis.y = primitive.p1.y - primitive.p0.y; axis.z = primitive.p1.z - primitive.p0.z; - float len = sqrtf(axis.x * axis.x + axis.y * axis.y + axis.z * axis.z); + float len = + sqrtf(axis.x * axis.x + axis.y * axis.y + axis.z * axis.z); if (len != 0) { axis.x /= len; @@ -1708,7 +1879,8 @@ int GPUKernel::addCube(float x, float y, float z, float radius, int materialId) return addRectangle(x, y, z, radius, radius, radius, materialId); } -int GPUKernel::addRectangle(float x, float y, float z, float w, float h, float d, int materialId) +int GPUKernel::addRectangle(float x, float y, float z, float w, float h, + float d, int materialId) { LOG_INFO(3, "GPUKernel::addRectangle(" << m_frame << ")"); int returnValue; @@ -1740,7 +1912,8 @@ int GPUKernel::addRectangle(float x, float y, float z, float w, float h, float d void GPUKernel::setPrimitiveMaterial(unsigned int index, int materialId) { - LOG_INFO(3, "GPUKernel::setPrimitiveMaterial(" << index << "," << materialId << ")"); + LOG_INFO(3, "GPUKernel::setPrimitiveMaterial(" << index << "," << materialId + << ")"); if (index <= m_primitives[m_frame].size()) { (m_primitives[m_frame])[index].materialId = materialId; @@ -1777,34 +1950,46 @@ void GPUKernel::setMaterial(unsigned int index, const Material &material) } } -void GPUKernel::setMaterial(unsigned int index, float r, float g, float b, float noise, float reflection, - float refraction, bool procedural, bool wireframe, int wireframeWidth, float transparency, - float opacity, int diffuseTextureId, int normalTextureId, int bumpTextureId, - int specularTextureId, int reflectionTextureId, int transparentTextureId, - int ambientOcclusionTextureId, float specValue, float specPower, float specCoef, - float innerIllumination, float illuminationDiffusion, float illuminationPropagation, - bool fastTransparency) +void GPUKernel::setMaterial( + unsigned int index, float r, float g, float b, float gloss, + float reflection, float refraction, bool procedural, bool wireframe, + int wireframeWidth, float transparency, float opacity, int diffuseTextureId, + int normalTextureId, int bumpTextureId, int specularTextureId, + int reflectionTextureId, int transparentTextureId, + int ambientOcclusionTextureId, float specValue, float specPower, + float specCoef, float innerIllumination, float illuminationDiffusion, + float illuminationPropagation, bool fastTransparency) { LOG_INFO(3, "GPUKernel::setMaterial (" - << index << "," << static_cast(r) << "," << static_cast(g) << "," - << static_cast(b) << "," << static_cast(noise) << "," - << static_cast(reflection) << "," << static_cast(refraction) << "," << procedural - << "," << wireframe << "," << static_cast(wireframeWidth) << "," - << static_cast(transparency) << "," << static_cast(opacity) << "," - << static_cast(diffuseTextureId) << "," << static_cast(normalTextureId) << "," - << static_cast(bumpTextureId) << "," << static_cast(specularTextureId) << "," - << static_cast(reflectionTextureId) << "," << static_cast(transparentTextureId) << "," - << static_cast(specValue) << "," << static_cast(specPower) << "," - << static_cast(specCoef) << "," << static_cast(innerIllumination) << "," - << static_cast(illuminationDiffusion) << "," << static_cast(illuminationPropagation) - << "," << fastTransparency << ")"); + << index << "," << static_cast(r) << "," + << static_cast(g) << "," << static_cast(b) + << "," << static_cast(gloss) << "," + << static_cast(reflection) << "," + << static_cast(refraction) << "," << procedural + << "," << wireframe << "," + << static_cast(wireframeWidth) << "," + << static_cast(transparency) << "," + << static_cast(opacity) << "," + << static_cast(diffuseTextureId) << "," + << static_cast(normalTextureId) << "," + << static_cast(bumpTextureId) << "," + << static_cast(specularTextureId) << "," + << static_cast(reflectionTextureId) << "," + << static_cast(transparentTextureId) << "," + << static_cast(specValue) << "," + << static_cast(specPower) << "," + << static_cast(specCoef) << "," + << static_cast(innerIllumination) << "," + << static_cast(illuminationDiffusion) << "," + << static_cast(illuminationPropagation) << "," + << fastTransparency << ")"); if (index < NB_MAX_MATERIALS) { m_hMaterials[index].color.x = r; m_hMaterials[index].color.y = g; m_hMaterials[index].color.z = b; - m_hMaterials[index].color.w = 0.f; // noise; + m_hMaterials[index].color.w = gloss / 100.f; m_hMaterials[index].specular.x = specValue; m_hMaterials[index].specular.y = specPower; m_hMaterials[index].specular.z = 0.f; // Not used @@ -1812,14 +1997,15 @@ void GPUKernel::setMaterial(unsigned int index, float r, float g, float b, float m_hMaterials[index].innerIllumination.x = innerIllumination; m_hMaterials[index].innerIllumination.y = illuminationDiffusion; m_hMaterials[index].innerIllumination.z = illuminationPropagation; - m_hMaterials[index].innerIllumination.w = noise; + m_hMaterials[index].innerIllumination.w = 0.f; // noise; m_hMaterials[index].reflection = reflection; m_hMaterials[index].refraction = refraction; m_hMaterials[index].transparency = transparency; m_hMaterials[index].opacity = opacity; m_hMaterials[index].attributes.x = fastTransparency ? 1 : 0; m_hMaterials[index].attributes.y = procedural ? 1 : 0; - m_hMaterials[index].attributes.z = wireframe ? ((wireframeWidth == 0) ? 1 : 2) : 0; + m_hMaterials[index].attributes.z = + wireframe ? ((wireframeWidth == 0) ? 1 : 2) : 0; m_hMaterials[index].attributes.w = wireframeWidth; m_hMaterials[index].textureMapping.x = 1; m_hMaterials[index].textureMapping.y = 1; @@ -1843,45 +2029,64 @@ void GPUKernel::setMaterial(unsigned int index, float r, float g, float b, float switch (diffuseTextureId) { case KINECT_COLOR_TEXTURE: - m_hMaterials[index].textureMapping.x = KINECT_COLOR_WIDTH; // Width - m_hMaterials[index].textureMapping.y = KINECT_COLOR_HEIGHT; // Height - m_hMaterials[index].textureMapping.w = KINECT_COLOR_DEPTH; // Depth + m_hMaterials[index].textureMapping.x = KINECT_COLOR_WIDTH; // Width + m_hMaterials[index].textureMapping.y = + KINECT_COLOR_HEIGHT; // Height + m_hMaterials[index].textureMapping.w = KINECT_COLOR_DEPTH; // Depth break; case KINECT_DEPTH_TEXTURE: - m_hMaterials[index].textureMapping.x = KINECT_DEPTH_WIDTH; // Width - m_hMaterials[index].textureMapping.y = KINECT_DEPTH_HEIGHT; // Height - m_hMaterials[index].textureMapping.w = KINECT_DEPTH_DEPTH; // Depth + m_hMaterials[index].textureMapping.x = KINECT_DEPTH_WIDTH; // Width + m_hMaterials[index].textureMapping.y = + KINECT_DEPTH_HEIGHT; // Height + m_hMaterials[index].textureMapping.w = KINECT_DEPTH_DEPTH; // Depth break; } #endif // USE_KINECT if (diffuseTextureId >= 0 && diffuseTextureId < m_nbActiveTextures) { - m_hMaterials[index].textureMapping.x = m_hTextures[diffuseTextureId].size.x; // Width - m_hMaterials[index].textureMapping.y = m_hTextures[diffuseTextureId].size.y; // Height - m_hMaterials[index].textureMapping.w = m_hTextures[diffuseTextureId].size.z; // Depth - m_hMaterials[index].textureMapping.z = TEXTURE_NONE; // Deprecated + m_hMaterials[index].textureMapping.x = + m_hTextures[diffuseTextureId].size.x; // Width + m_hMaterials[index].textureMapping.y = + m_hTextures[diffuseTextureId].size.y; // Height + m_hMaterials[index].textureMapping.w = + m_hTextures[diffuseTextureId].size.z; // Depth + m_hMaterials[index].textureMapping.z = TEXTURE_NONE; // Deprecated m_hMaterials[index].textureIds.x = diffuseTextureId; m_hMaterials[index].textureIds.y = normalTextureId; m_hMaterials[index].textureIds.z = bumpTextureId; m_hMaterials[index].textureIds.w = specularTextureId; - m_hMaterials[index].textureOffset.x = m_hTextures[diffuseTextureId].offset; // Offset + m_hMaterials[index].textureOffset.x = + m_hTextures[diffuseTextureId].offset; // Offset m_hMaterials[index].textureOffset.y = - (normalTextureId == TEXTURE_NONE) ? 0 : m_hTextures[normalTextureId].offset; + (normalTextureId == TEXTURE_NONE) + ? 0 + : m_hTextures[normalTextureId].offset; m_hMaterials[index].textureOffset.z = - (bumpTextureId == TEXTURE_NONE) ? 0 : m_hTextures[bumpTextureId].offset; + (bumpTextureId == TEXTURE_NONE) + ? 0 + : m_hTextures[bumpTextureId].offset; m_hMaterials[index].textureOffset.w = - (specularTextureId == TEXTURE_NONE) ? 0 : m_hTextures[specularTextureId].offset; + (specularTextureId == TEXTURE_NONE) + ? 0 + : m_hTextures[specularTextureId].offset; // Advanced textures m_hMaterials[index].advancedTextureIds.x = reflectionTextureId; m_hMaterials[index].advancedTextureIds.y = transparentTextureId; - m_hMaterials[index].advancedTextureIds.z = ambientOcclusionTextureId; + m_hMaterials[index].advancedTextureIds.z = + ambientOcclusionTextureId; m_hMaterials[index].advancedTextureOffset.x = - (reflectionTextureId == TEXTURE_NONE) ? 0 : m_hTextures[reflectionTextureId].offset; + (reflectionTextureId == TEXTURE_NONE) + ? 0 + : m_hTextures[reflectionTextureId].offset; m_hMaterials[index].advancedTextureOffset.y = - (transparentTextureId == TEXTURE_NONE) ? 0 : m_hTextures[transparentTextureId].offset; + (transparentTextureId == TEXTURE_NONE) + ? 0 + : m_hTextures[transparentTextureId].offset; m_hMaterials[index].advancedTextureOffset.z = - (ambientOcclusionTextureId == TEXTURE_NONE) ? 0 : m_hTextures[ambientOcclusionTextureId].offset; + (ambientOcclusionTextureId == TEXTURE_NONE) + ? 0 + : m_hTextures[ambientOcclusionTextureId].offset; } else { @@ -1904,18 +2109,22 @@ void GPUKernel::setMaterial(unsigned int index, float r, float g, float b, float } else { - LOG_ERROR("GPUKernel::setMaterial: Out of bounds(" << index << "/" << NB_MAX_MATERIALS << ")"); + LOG_ERROR("GPUKernel::setMaterial: Out of bounds(" + << index << "/" << NB_MAX_MATERIALS << ")"); } } void GPUKernel::setMaterialColor(unsigned int index, float r, float g, float b) { LOG_INFO(3, "GPUKernel::setMaterialColor( " << index << "," - << "color=(" << r << "," << g << "," << b << ")"); + << "color=(" << r << "," << g + << "," << b << ")"); if (index < NB_MAX_MATERIALS) { - if (m_hMaterials[index].color.x != r || m_hMaterials[index].color.y != g || m_hMaterials[index].color.z != b) + if (m_hMaterials[index].color.x != r || + m_hMaterials[index].color.y != g || + m_hMaterials[index].color.z != b) { m_hMaterials[index].color.x = r; m_hMaterials[index].color.y = g; @@ -1925,14 +2134,16 @@ void GPUKernel::setMaterialColor(unsigned int index, float r, float g, float b) } else { - LOG_ERROR("GPUKernel::setMaterial: Out of bounds(" << index << "/" << NB_MAX_MATERIALS << ")"); + LOG_ERROR("GPUKernel::setMaterial: Out of bounds(" + << index << "/" << NB_MAX_MATERIALS << ")"); } } void GPUKernel::setMaterialTextureId(unsigned int textureId) { - LOG_INFO(3, "GPUKernel::setMaterialTextureId( " << m_currentMaterial << "," - << "Texture Id=" << textureId << ")"); + LOG_INFO(3, "GPUKernel::setMaterialTextureId( " + << m_currentMaterial << "," + << "Texture Id=" << textureId << ")"); if (textureId != m_hMaterials[m_currentMaterial].textureIds.x) { @@ -1940,10 +2151,14 @@ void GPUKernel::setMaterialTextureId(unsigned int textureId) m_hMaterials[m_currentMaterial].refraction = 0.f; m_hMaterials[m_currentMaterial].transparency = 0.f; m_hMaterials[m_currentMaterial].opacity = 0.f; - m_hMaterials[m_currentMaterial].textureMapping.x = m_hTextures[textureId].size.x; - m_hMaterials[m_currentMaterial].textureMapping.y = m_hTextures[textureId].size.y; - m_hMaterials[m_currentMaterial].textureMapping.z = TEXTURE_NONE; // Deprecated - m_hMaterials[m_currentMaterial].textureMapping.w = m_hTextures[textureId].size.z; + m_hMaterials[m_currentMaterial].textureMapping.x = + m_hTextures[textureId].size.x; + m_hMaterials[m_currentMaterial].textureMapping.y = + m_hTextures[textureId].size.y; + m_hMaterials[m_currentMaterial].textureMapping.z = + TEXTURE_NONE; // Deprecated + m_hMaterials[m_currentMaterial].textureMapping.w = + m_hTextures[textureId].size.z; m_hMaterials[m_currentMaterial].textureIds.x = textureId; m_hMaterials[m_currentMaterial].textureIds.y = TEXTURE_NONE; m_hMaterials[m_currentMaterial].textureIds.z = TEXTURE_NONE; @@ -1952,14 +2167,15 @@ void GPUKernel::setMaterialTextureId(unsigned int textureId) } } -int GPUKernel::getMaterialAttributes(int index, float &r, float &g, float &b, float &noise, float &reflection, - float &refraction, bool &procedural, bool &wireframe, int &wireframeDepth, - float &transparency, float &opacity, int &diffuseTextureId, int &normalTextureId, - int &bumpTextureId, int &specularTextureId, int &reflectionTextureId, - int &transparencyTextureId, int &ambientOcclusionTextureId, float &specValue, - float &specPower, float &specCoef, float &innerIllumination, - float &illuminationDiffusion, float &illuminationPropagation, - bool &fastTransparency) +int GPUKernel::getMaterialAttributes( + int index, float &r, float &g, float &b, float &gloss, float &reflection, + float &refraction, bool &procedural, bool &wireframe, int &wireframeDepth, + float &transparency, float &opacity, int &diffuseTextureId, + int &normalTextureId, int &bumpTextureId, int &specularTextureId, + int &reflectionTextureId, int &transparencyTextureId, + int &ambientOcclusionTextureId, float &specValue, float &specPower, + float &specCoef, float &innerIllumination, float &illuminationDiffusion, + float &illuminationPropagation, bool &fastTransparency) { int returnValue = -1; @@ -1968,6 +2184,7 @@ int GPUKernel::getMaterialAttributes(int index, float &r, float &g, float &b, fl r = m_hMaterials[index].color.x; g = m_hMaterials[index].color.y; b = m_hMaterials[index].color.z; + gloss = m_hMaterials[index].color.w; reflection = m_hMaterials[index].reflection; refraction = m_hMaterials[index].refraction; @@ -1988,7 +2205,6 @@ int GPUKernel::getMaterialAttributes(int index, float &r, float &g, float &b, fl innerIllumination = m_hMaterials[index].innerIllumination.x; illuminationDiffusion = m_hMaterials[index].innerIllumination.y; illuminationPropagation = m_hMaterials[index].innerIllumination.z; - noise = m_hMaterials[index].innerIllumination.w; fastTransparency = (m_hMaterials[index].attributes.x == 1); procedural = (m_hMaterials[index].attributes.y == 1); wireframe = (m_hMaterials[index].attributes.z == 1); @@ -1997,7 +2213,8 @@ int GPUKernel::getMaterialAttributes(int index, float &r, float &g, float &b, fl } else { - LOG_ERROR("GPUKernel::setMaterial: Out of bounds(" << index << "/" << NB_MAX_MATERIALS << ")"); + LOG_ERROR("GPUKernel::setMaterial: Out of bounds(" + << index << "/" << NB_MAX_MATERIALS << ")"); } return returnValue; } @@ -2016,11 +2233,12 @@ Material *GPUKernel::getMaterial(const int index) // ---------- Textures ---------- void GPUKernel::setTexture(const int index, const TextureInfo &textureInfo) { - LOG_INFO(1, "GPUKernel::setTexture(" << index << "/" << m_nbActiveTextures << ")"); + LOG_INFO(1, "GPUKernel::setTexture(" << index << "/" << m_nbActiveTextures + << ")"); if (index >= m_nbActiveTextures) ++m_nbActiveTextures; if (m_hTextures[index].buffer != 0) - delete[] m_hTextures[index].buffer; + delete m_hTextures[index].buffer; int size = textureInfo.size.x * textureInfo.size.y * textureInfo.size.z; m_hTextures[index].buffer = new BitmapBuffer[size]; m_hTextures[index].offset = 0; @@ -2041,11 +2259,13 @@ void GPUKernel::getTexture(const int index, TextureInfo &textureInfo) } } -void GPUKernel::setSceneInfo(int width, int height, float transparentColor, int graphicsLevel, float viewDistance, - float shadowIntensity, int nbRayIterations, vec4f backgroundColor, int cameraType, - float eyeSeparation, bool renderBoxes, int pathTracingIteration, - int maxPathTracingIterations, FrameBufferType frameBufferType, int timestamp, - int atmosphericEffect, int skyboxSize, int skyboxMaterialId) +void GPUKernel::setSceneInfo( + int width, int height, float transparentColor, int graphicsLevel, + float viewDistance, float shadowIntensity, int nbRayIterations, + vec4f backgroundColor, int cameraType, float eyeSeparation, + bool renderBoxes, int pathTracingIteration, int maxPathTracingIterations, + FrameBufferType frameBufferType, int timestamp, int atmosphericEffect, + int skyboxSize, int skyboxMaterialId) { LOG_INFO(3, "GPUKernel::setSceneInfo"); memset(&m_sceneInfo, 0, sizeof(SceneInfo)); @@ -2063,7 +2283,8 @@ void GPUKernel::setSceneInfo(int width, int height, float transparentColor, int m_sceneInfo.maxPathTracingIterations = maxPathTracingIterations; m_sceneInfo.frameBufferType = frameBufferType; m_sceneInfo.timestamp = timestamp; - m_sceneInfo.atmosphericEffect = static_cast(atmosphericEffect); + m_sceneInfo.atmosphericEffect = + static_cast(atmosphericEffect); m_sceneInfo.skyboxRadius = skyboxSize; m_sceneInfo.skyboxMaterialId = skyboxMaterialId; } @@ -2078,7 +2299,8 @@ SceneInfo &GPUKernel::getSceneInfo() return m_sceneInfo; } -void GPUKernel::setPostProcessingInfo(PostProcessingType type, float param1, float param2, int param3) +void GPUKernel::setPostProcessingInfo(PostProcessingType type, float param1, + float param2, int param3) { LOG_INFO(3, "GPUKernel::setPostProcessingInfo"); m_postProcessingInfo.type = type; @@ -2087,7 +2309,8 @@ void GPUKernel::setPostProcessingInfo(PostProcessingType type, float param1, flo m_postProcessingInfo.param3 = param3; } -void GPUKernel::setPostProcessingInfo(const PostProcessingInfo &postProcessingInfo) +void GPUKernel::setPostProcessingInfo( + const PostProcessingInfo &postProcessingInfo) { m_postProcessingInfo = postProcessingInfo; } @@ -2107,9 +2330,12 @@ void GPUKernel::saveToFile(const std::string &filename) } // ---------- Kinect ---------- -bool GPUKernel::loadTextureFromFile(const int index, const std::string &filename) +bool GPUKernel::loadTextureFromFile(const int index, + const std::string &filename) { - LOG_INFO(3, "Loading texture from file " << filename << " into slot " << index << "/" << m_nbActiveTextures); + LOG_INFO(3, "Loading texture from file " << filename << " into slot " + << index << "/" + << m_nbActiveTextures); bool result(false); if (filename.length() != 0) @@ -2133,7 +2359,8 @@ bool GPUKernel::loadTextureFromFile(const int index, const std::string &filename if (result) { m_textureFilenames[index] = filename; - m_hTextures[index].type = tex_diffuse; // Default texture type is 'diffused' + m_hTextures[index].type = + tex_diffuse; // Default texture type is 'diffused' if (filename.find("b.") != std::string::npos) m_hTextures[index].type = tex_bump; if (filename.find("n.") != std::string::npos) @@ -2147,9 +2374,12 @@ bool GPUKernel::loadTextureFromFile(const int index, const std::string &filename if (filename.find("t.") != std::string::npos) m_hTextures[index].type = tex_transparent; - LOG_INFO(3, "Texture " << index << "(" << filename << ") loaded. Type=" << m_hTextures[index].type - << " size=" << m_hTextures[index].size.x << "x" << m_hTextures[index].size.y << "x" - << m_hTextures[index].size.z); + LOG_INFO(3, "Texture " + << index << "(" << filename + << ") loaded. Type=" << m_hTextures[index].type + << " size=" << m_hTextures[index].size.x << "x" + << m_hTextures[index].size.y << "x" + << m_hTextures[index].size.z); ++m_nbActiveTextures; } else @@ -2179,11 +2409,14 @@ void GPUKernel::reorganizeLights() { // Lights bool found(false); - int i(0); + size_t i = 0; while (!found && i < m_nbActiveLamps[m_frame]) { - LOG_INFO(1, "[Box " << (*it).first << "] Lamp " << i << "/" << m_nbActiveLamps[m_frame] << " = " - << m_hLamps[i] << ", Primitive index=" << primitive.index); + LOG_INFO(1, "[Box " << (*it).first << "] Lamp " << i + << "/" << m_nbActiveLamps[m_frame] + << " = " << m_hLamps[i] + << ", Primitive index=" + << primitive.index); if (m_hLamps[i] == primitive.index) { LOG_INFO(1, "Lamp " << i << " FOUND"); @@ -2206,17 +2439,38 @@ void GPUKernel::reorganizeLights() lightInformation.color.z = material.color.z; lightInformation.color.w = 0.f; // not used - LOG_INFO(3, "Lamp " << m_lightInformation[m_lightInformationSize].primitiveId << "," - << m_lightInformation[m_lightInformationSize].materialId << ":" - << m_lightInformation[m_lightInformationSize].location.x << "," - << m_lightInformation[m_lightInformationSize].location.y << "," - << m_lightInformation[m_lightInformationSize].location.z << " " - << m_lightInformation[m_lightInformationSize].color.x << "," - << m_lightInformation[m_lightInformationSize].color.y << "," - << m_lightInformation[m_lightInformationSize].color.z << " " - << m_lightInformation[m_lightInformationSize].color.w); - - m_lightInformation[m_nbActiveLamps[m_frame] + m_lightInformationSize] = lightInformation; + LOG_INFO( + 3, "Lamp " + << m_lightInformation[m_lightInformationSize] + .primitiveId + << "," + << m_lightInformation[m_lightInformationSize] + .materialId + << ":" + << m_lightInformation[m_lightInformationSize] + .location.x + << "," + << m_lightInformation[m_lightInformationSize] + .location.y + << "," + << m_lightInformation[m_lightInformationSize] + .location.z + << " " + << m_lightInformation[m_lightInformationSize] + .color.x + << "," + << m_lightInformation[m_lightInformationSize] + .color.y + << "," + << m_lightInformation[m_lightInformationSize] + .color.z + << " " + << m_lightInformation[m_lightInformationSize] + .color.w); + + m_lightInformation[m_nbActiveLamps[m_frame] + + m_lightInformationSize] = + lightInformation; m_lightInformationSize++; } } @@ -2230,8 +2484,9 @@ void GPUKernel::reorganizeLights() TextureInfo &GPUKernel::getTextureInformation(const int index) { - LOG_INFO(3, "Getting texture " << index << ": " << m_hTextures[index].size.x << "x" << m_hTextures[index].size.y - << "x" << m_hTextures[index].size.z); + LOG_INFO(3, "Getting texture " << index << ": " << m_hTextures[index].size.x + << "x" << m_hTextures[index].size.y << "x" + << m_hTextures[index].size.z); return m_hTextures[index]; } @@ -2243,7 +2498,7 @@ void GPUKernel::realignTexturesAndMaterials() processTextureOffsets(); // Materials - for (int i(0); i < m_nbActiveMaterials; ++i) + for (size_t i = 0; i < m_nbActiveMaterials; ++i) { int diffuseTextureId = m_hMaterials[i].textureIds.x; int normalTextureId = m_hMaterials[i].textureIds.y; @@ -2283,28 +2538,43 @@ void GPUKernel::realignTexturesAndMaterials() default: if (diffuseTextureId < m_nbActiveTextures) { - m_hMaterials[i].textureMapping.x = m_hTextures[diffuseTextureId].size.x; - m_hMaterials[i].textureMapping.y = m_hTextures[diffuseTextureId].size.y; + m_hMaterials[i].textureMapping.x = + m_hTextures[diffuseTextureId].size.x; + m_hMaterials[i].textureMapping.y = + m_hTextures[diffuseTextureId].size.y; m_hMaterials[i].textureMapping.z = TEXTURE_NONE; // Deprecated - m_hMaterials[i].textureMapping.w = m_hTextures[diffuseTextureId].size.z; + m_hMaterials[i].textureMapping.w = + m_hTextures[diffuseTextureId].size.z; m_hMaterials[i].textureIds.x = diffuseTextureId; m_hMaterials[i].textureIds.y = normalTextureId; m_hMaterials[i].textureIds.z = bumpTextureId; m_hMaterials[i].textureIds.w = specularTextureId; m_hMaterials[i].textureOffset.x = - (diffuseTextureId == TEXTURE_NONE) ? 0 : m_hTextures[diffuseTextureId].offset; + (diffuseTextureId == TEXTURE_NONE) + ? 0 + : m_hTextures[diffuseTextureId].offset; m_hMaterials[i].textureOffset.y = - (normalTextureId == TEXTURE_NONE) ? 0 : m_hTextures[normalTextureId].offset; + (normalTextureId == TEXTURE_NONE) + ? 0 + : m_hTextures[normalTextureId].offset; m_hMaterials[i].textureOffset.z = - (bumpTextureId == TEXTURE_NONE) ? 0 : m_hTextures[bumpTextureId].offset; + (bumpTextureId == TEXTURE_NONE) + ? 0 + : m_hTextures[bumpTextureId].offset; m_hMaterials[i].textureOffset.w = - (specularTextureId == TEXTURE_NONE) ? 0 : m_hTextures[specularTextureId].offset; + (specularTextureId == TEXTURE_NONE) + ? 0 + : m_hTextures[specularTextureId].offset; m_hMaterials[i].advancedTextureIds.x = reflectionTextureId; m_hMaterials[i].advancedTextureIds.y = transparencyTextureId; m_hMaterials[i].advancedTextureOffset.x = - (reflectionTextureId == TEXTURE_NONE) ? 0 : m_hTextures[reflectionTextureId].offset; + (reflectionTextureId == TEXTURE_NONE) + ? 0 + : m_hTextures[reflectionTextureId].offset; m_hMaterials[i].advancedTextureOffset.y = - (transparencyTextureId == TEXTURE_NONE) ? 0 : m_hTextures[transparencyTextureId].offset; + (transparencyTextureId == TEXTURE_NONE) + ? 0 + : m_hTextures[transparencyTextureId].offset; m_hMaterials[i].mappingOffset.x = 1.f; m_hMaterials[i].mappingOffset.y = 0.f; } @@ -2337,12 +2607,15 @@ void GPUKernel::realignTexturesAndMaterials() if (diffuseTextureId != TEXTURE_NONE) { - LOG_INFO(3, "Material " << i << ": " << m_hMaterials[i].textureMapping.x << "x" - << m_hMaterials[i].textureMapping.y << "x" << m_hMaterials[i].textureMapping.w - << ", Wireframe: " << m_hMaterials[i].attributes.z << ", diffuseTextureId [" - << diffuseTextureId << "] offset=" << m_hMaterials[i].textureOffset.x - << ", bumpTextureId [" << bumpTextureId - << "] offset=" << m_hMaterials[i].textureOffset.y); + LOG_INFO(3, "Material " + << i << ": " << m_hMaterials[i].textureMapping.x + << "x" << m_hMaterials[i].textureMapping.y << "x" + << m_hMaterials[i].textureMapping.w + << ", Wireframe: " << m_hMaterials[i].attributes.z + << ", diffuseTextureId [" << diffuseTextureId + << "] offset=" << m_hMaterials[i].textureOffset.x + << ", bumpTextureId [" << bumpTextureId + << "] offset=" << m_hMaterials[i].textureOffset.y); } } } @@ -2352,7 +2625,8 @@ void GPUKernel::buildLightInformationFromTexture(unsigned int index) LOG_INFO(3, "buildLightInformationFromTexture"); m_lightInformationSize = 0; reorganizeLights(); - LOG_INFO(3, "Light Information Size = " << m_nbActiveLamps[m_frame] << "/" << m_lightInformationSize); + LOG_INFO(3, "Light Information Size = " << m_nbActiveLamps[m_frame] << "/" + << m_lightInformationSize); } #ifdef USE_KINECT @@ -2372,9 +2646,12 @@ void GPUKernel::initializeKinectTextures() m_nbActiveTextures = 2; } -int GPUKernel::updateSkeletons(unsigned int primitiveIndex, vec3f skeletonPosition, float size, float radius, - int materialId, float head_radius, int head_materialId, float hands_radius, - int hands_materialId, float feet_radius, int feet_materialId) +int GPUKernel::updateSkeletons(unsigned int primitiveIndex, + vec3f skeletonPosition, float size, float radius, + int materialId, float head_radius, + int head_materialId, float hands_radius, + int hands_materialId, float feet_radius, + int feet_materialId) { m_skeletonIndex = -1; HRESULT hr = NuiSkeletonGetNextFrame(0, &m_skeletonFrame); @@ -2384,7 +2661,8 @@ int GPUKernel::updateSkeletons(unsigned int primitiveIndex, vec3f skeletonPositi int i = 0; while (i < NUI_SKELETON_COUNT && !found) { - if (m_skeletonFrame.SkeletonData[i].eTrackingState == NUI_SKELETON_TRACKED) + if (m_skeletonFrame.SkeletonData[i].eTrackingState == + NUI_SKELETON_TRACKED) { m_skeletonIndex = i; found = true; //(m_skeletonIndex==0); @@ -2431,9 +2709,14 @@ bool GPUKernel::getSkeletonPosition(int index, vec3f &position) bool returnValue(false); if (m_skeletonIndex != -1) { - position.x = m_skeletonFrame.SkeletonData[m_skeletonIndex].SkeletonPositions[index].x; - position.y = 0.f; // m_skeletonFrame.SkeletonData[m_skeletonIndex].SkeletonPositions[index].y; - position.z = m_skeletonFrame.SkeletonData[m_skeletonIndex].SkeletonPositions[index].z; + position.x = m_skeletonFrame.SkeletonData[m_skeletonIndex] + .SkeletonPositions[index] + .x; + position.y = + 0.f; // m_skeletonFrame.SkeletonData[m_skeletonIndex].SkeletonPositions[index].y; + position.z = m_skeletonFrame.SkeletonData[m_skeletonIndex] + .SkeletonPositions[index] + .z; returnValue = true; } return returnValue; @@ -2441,14 +2724,17 @@ bool GPUKernel::getSkeletonPosition(int index, vec3f &position) #endif // USE_KINECT -void GPUKernel::saveBitmapToFile(const std::string &filename, BitmapBuffer *bitmap, const int width, const int height, - const int depth) +void GPUKernel::saveBitmapToFile(const std::string &filename, + BitmapBuffer *bitmap, const int width, + const int height, const int depth) { FILE *f; - unsigned char bmpfileheader[14] = {'B', 'M', 0, 0, 0, 0, 0, 0, 0, 0, 54, 0, 0, 0}; - unsigned char bmpinfoheader[40] = {40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 32, 0}; - + unsigned char bmpfileheader[14] = {'B', 'M', 0, 0, 0, 0, 0, + 0, 0, 0, 54, 0, 0, 0}; + unsigned char bmpinfoheader[40] = {40, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, 32, 0}; + int w = width; int h = height; int filesize = 54 + depth * w * h; @@ -2488,7 +2774,8 @@ int GPUKernel::getLight(int index) } else { - LOG_ERROR("getLight(" << index << "/" << m_nbActiveLamps[m_frame] << ") is out of bounds"); + LOG_ERROR("getLight(" << index << "/" << m_nbActiveLamps[m_frame] + << ") is out of bounds"); } return -1; } @@ -2499,7 +2786,7 @@ int GPUKernel::setGLMode(const int &glMode) int p = -1; if (glMode == -1) { - for (int i(0); i < m_vertices.size(); ++i) + for (size_t i = 0; i < m_vertices.size(); ++i) { m_vertices[i].x += m_translation.x; m_vertices[i].y += m_translation.y; @@ -2510,10 +2797,11 @@ int GPUKernel::setGLMode(const int &glMode) { case GL_POINTS: { - for (int i(0); i < m_vertices.size(); ++i) + for (size_t i = 0; i < m_vertices.size(); ++i) { p = addPrimitive(ptSphere); - setPrimitive(p, m_vertices[i].x, m_vertices[i].y, m_vertices[i].z, m_pointSize, 0.f, 0.f, + setPrimitive(p, m_vertices[i].x, m_vertices[i].y, + m_vertices[i].z, m_pointSize, 0.f, 0.f, m_currentMaterial); } LOG_INFO(3, "[OpenGL] Added " << m_vertices.size() << " Points"); @@ -2522,14 +2810,16 @@ int GPUKernel::setGLMode(const int &glMode) case GL_LINES: { int nbLines = static_cast(m_vertices.size() / 2); - for (int i(0); i < nbLines; ++i) + for (size_t i = 0; i < nbLines; ++i) { int index = i * 2; if (index + 1 <= m_vertices.size()) { p = addPrimitive(ptCylinder); - setPrimitive(p, m_vertices[i].x, m_vertices[i].y, m_vertices[i].z, m_vertices[i + 1].x, - m_vertices[i + 1].y, m_vertices[i + 1].z, m_pointSize, 0.f, 0.f, m_currentMaterial); + setPrimitive(p, m_vertices[i].x, m_vertices[i].y, + m_vertices[i].z, m_vertices[i + 1].x, + m_vertices[i + 1].y, m_vertices[i + 1].z, + m_pointSize, 0.f, 0.f, m_currentMaterial); } } LOG_INFO(3, "[OpenGL] Added " << nbLines << " Lines"); @@ -2539,66 +2829,89 @@ int GPUKernel::setGLMode(const int &glMode) { // Vertices int nbTriangles = static_cast(m_vertices.size() / 3); - for (int i(0); i < nbTriangles; ++i) + for (size_t i = 0; i < nbTriangles; ++i) { int index = i * 3; if (index + 2 <= m_vertices.size()) { p = addPrimitive(ptTriangle); - setPrimitive(p, m_vertices[index].x, m_vertices[index].y, m_vertices[index].z, - m_vertices[index + 1].x, m_vertices[index + 1].y, m_vertices[index + 1].z, - m_vertices[index + 2].x, m_vertices[index + 2].y, m_vertices[index + 2].z, 0.f, 0.f, - 0.f, m_currentMaterial); + setPrimitive(p, m_vertices[index].x, m_vertices[index].y, + m_vertices[index].z, m_vertices[index + 1].x, + m_vertices[index + 1].y, + m_vertices[index + 1].z, + m_vertices[index + 2].x, + m_vertices[index + 2].y, + m_vertices[index + 2].z, 0.f, 0.f, 0.f, + m_currentMaterial); } if (index + 2 <= m_textCoords.size()) - setPrimitiveTextureCoordinates(p, m_textCoords[index], m_textCoords[index + 1], + setPrimitiveTextureCoordinates(p, m_textCoords[index], + m_textCoords[index + 1], m_textCoords[index + 2]); if (index + 2 <= m_normals.size()) { - setPrimitiveNormals(p, m_normals[index], m_normals[index + 1], m_normals[index + 2]); + setPrimitiveNormals(p, m_normals[index], + m_normals[index + 1], + m_normals[index + 2]); } } - LOG_INFO(3, "[OpenGL] Added " << nbTriangles << " triangles with material ID " << m_currentMaterial); + LOG_INFO(3, "[OpenGL] Added " << nbTriangles + << " triangles with material ID " + << m_currentMaterial); } break; case GL_QUADS: { // Vertices int nbQuads = static_cast(m_vertices.size() / 4); - for (int i(0); i < nbQuads; ++i) + for (size_t i = 0; i < nbQuads; ++i) { int p1, p2; int index = i * 4; if (index + 2 <= m_vertices.size()) { p1 = addPrimitive(ptTriangle); - setPrimitive(p1, m_vertices[index].x, m_vertices[index].y, m_vertices[index].z, - m_vertices[index + 1].x, m_vertices[index + 1].y, m_vertices[index + 1].z, - m_vertices[index + 2].x, m_vertices[index + 2].y, m_vertices[index + 2].z, 0.f, 0.f, - 0.f, m_currentMaterial); + setPrimitive(p1, m_vertices[index].x, m_vertices[index].y, + m_vertices[index].z, m_vertices[index + 1].x, + m_vertices[index + 1].y, + m_vertices[index + 1].z, + m_vertices[index + 2].x, + m_vertices[index + 2].y, + m_vertices[index + 2].z, 0.f, 0.f, 0.f, + m_currentMaterial); p2 = addPrimitive(ptTriangle); - setPrimitive(p2, m_vertices[index + 1].x, m_vertices[index + 1].y, m_vertices[index + 1].z, - m_vertices[index + 3].x, m_vertices[index + 3].y, m_vertices[index + 3].z, - m_vertices[index + 0].x, m_vertices[index + 0].y, m_vertices[index + 0].z, 0.f, 0.f, - 0.f, m_currentMaterial); + setPrimitive( + p2, m_vertices[index + 1].x, m_vertices[index + 1].y, + m_vertices[index + 1].z, m_vertices[index + 3].x, + m_vertices[index + 3].y, m_vertices[index + 3].z, + m_vertices[index + 0].x, m_vertices[index + 0].y, + m_vertices[index + 0].z, 0.f, 0.f, 0.f, + m_currentMaterial); } if (index + 3 <= m_textCoords.size()) { - setPrimitiveTextureCoordinates(p1, m_textCoords[index], m_textCoords[index + 1], + setPrimitiveTextureCoordinates(p1, m_textCoords[index], + m_textCoords[index + 1], m_textCoords[index + 2]); - setPrimitiveTextureCoordinates(p2, m_textCoords[index + 2], m_textCoords[index + 3], + setPrimitiveTextureCoordinates(p2, m_textCoords[index + 2], + m_textCoords[index + 3], m_textCoords[index]); } if (index + 3 <= m_normals.size()) { - setPrimitiveNormals(p1, m_normals[index], m_normals[index + 1], m_normals[index + 2]); - setPrimitiveNormals(p2, m_normals[index + 2], m_normals[index + 3], m_normals[index]); + setPrimitiveNormals(p1, m_normals[index], + m_normals[index + 1], + m_normals[index + 2]); + setPrimitiveNormals(p2, m_normals[index + 2], + m_normals[index + 3], m_normals[index]); } } - LOG_INFO(3, "[OpenGL] " << nbQuads << " quads created with material ID " << m_currentMaterial); + LOG_INFO(3, "[OpenGL] " << nbQuads + << " quads created with material ID " + << m_currentMaterial); } break; default: @@ -2621,7 +2934,7 @@ int GPUKernel::setGLMode(const int &glMode) void GPUKernel::addVertex(float x, float y, float z) { - m_vertices.push_back(make_vec3f(x,y,z)); + m_vertices.push_back(make_vec3f(x, y, z)); } void GPUKernel::addNormal(float x, float y, float z) @@ -2692,12 +3005,13 @@ void GPUKernel::processTextureOffsets() { // Reprocess offset int totalSize = 0; - for (int i(0); i < NB_MAX_TEXTURES; ++i) + for (size_t i = 0; i < NB_MAX_TEXTURES; ++i) { if (m_hTextures[i].buffer != 0) { m_hTextures[i].offset = totalSize; - totalSize += m_hTextures[i].size.x * m_hTextures[i].size.y * m_hTextures[i].size.z; + totalSize += m_hTextures[i].size.x * m_hTextures[i].size.y * + m_hTextures[i].size.z; } else m_hTextures[i].offset = 0; @@ -2712,19 +3026,23 @@ void GPUKernel::setPointSize(const float pointSize) void GPUKernel::render_begin(const float timer) { LOG_INFO(3, "GPUKernel::render_begin"); - LOG_INFO(3, "Scene size: " << m_sceneInfo.size.x << "x" << m_sceneInfo.size.y); + LOG_INFO(3, + "Scene size: " << m_sceneInfo.size.x << "x" << m_sceneInfo.size.y); - // Random - const size_t size = m_sceneInfo.size.x * m_sceneInfo.size.y; + // Randoms + // const size_t size = m_sceneInfo.size.x * m_sceneInfo.size.y; m_sceneInfo.timestamp = rand() % 10000; - if (!m_randomsTransfered || m_sceneInfo.pathTracingIteration % 50 == 1) - { - m_randomsTransfered = false; - srand(static_cast(time(0))); -#pragma omp parallel for - for (int i = 0; i < size; ++i) - m_hRandoms[i] = 0.000005f * (rand() % 2000 - 1000); - } + // if (m_sceneInfo.pathTracingIteration % 20 == 19) + // m_sceneInfo.timestamp = rand() % m_sceneInfo.size.x; + // if (m_sceneInfo.pathTracingIteration % 20 == 19) + // { + // m_randomsTransfered = false; + // LOG_INFO(1, "Quantum"); + // auto floats = + // RandomGenerator::getInstance().getFloats(size, + // DEFAULT_RANDOM_MULTIPLIER); + // memcpy(&m_hRandoms[0], floats.data(), floats.size() * sizeof(float)); + // } #ifdef USE_OCULUS if (m_oculus && m_sensorFusion && m_sensorFusion->IsAttachedToSensor()) @@ -2789,64 +3107,67 @@ void GPUKernel::switchOculusVR() } } -void GPUKernel::generateScreenshot(const std::string &filename, const unsigned int width, const unsigned int height, +void GPUKernel::generateScreenshot(const std::string &filename, + const unsigned int width, + const unsigned int height, const unsigned int quality) { - LOG_INFO(1, "Generating screenshot " << filename << " (Quality=" << quality << ", Size=" << width << "x" << height + LOG_INFO(1, "Generating screenshot " << filename << " (Quality=" << quality + << ", Size=" << width << "x" << height << ")"); - SceneInfo sceneInfo = m_sceneInfo; SceneInfo bakSceneInfo = m_sceneInfo; - sceneInfo.size.x = std::min(width, MAX_BITMAP_WIDTH); - sceneInfo.size.y = std::min(height, MAX_BITMAP_HEIGHT); - sceneInfo.maxPathTracingIterations = quality; + m_sceneInfo.size.x = width; + m_sceneInfo.size.y = height; + m_sceneInfo.maxPathTracingIterations = quality; + reshape(); + for (unsigned int i = 0; i < quality; ++i) { #ifdef WIN32 long t = GetTickCount(); #endif - sceneInfo.pathTracingIteration = i; - m_sceneInfo = sceneInfo; - render_begin(0); + m_sceneInfo.pathTracingIteration = i; + render_begin(rand() % 10000); render_end(); - LOG_INFO(1, "Frame " << i << " rendered!"); + LOG_INFO(1, "Frame " << i << "/" << quality << " rendered!"); #ifdef WIN32 int avg = GetTickCount() - t; - int left = static_cast(static_cast(quality - i) * static_cast(avg) / 1000.f); - LOG_INFO(1, "Frame " << i << " generated in " << avg << "ms (" << left << " seconds left...)"); + int left = static_cast(static_cast(quality - i) * + static_cast(avg) / 1000.f); + LOG_INFO(1, "Frame " << i << " generated in " << avg << "ms (" << left + << " seconds left...)"); #endif - LOG_INFO(1, "Saving bitmap to disk"); - size_t size = sceneInfo.size.x * sceneInfo.size.y * gColorDepth; - switch (sceneInfo.frameBufferType) - { - case ftRGB: + } + + LOG_INFO(1, "Saving bitmap to disk: " << filename); + const size_t size = m_sceneInfo.size.x * m_sceneInfo.size.y * gColorDepth; + BitmapBuffer *dst = new BitmapBuffer[size]; + switch (m_sceneInfo.frameBufferType) + { + case ftRGB: + { + for (size_t i = 0; i < size; i += gColorDepth) { - BitmapBuffer *dst = new BitmapBuffer[size]; - for (int i(0); i < size; i += gColorDepth) - { - dst[i] = m_bitmap[size - i]; - dst[i + 1] = m_bitmap[size - i + 1]; - dst[i + 2] = m_bitmap[size - i + 2]; - } - jpge::compress_image_to_jpeg_file(filename.c_str(), sceneInfo.size.x, sceneInfo.size.y, gColorDepth, dst); - delete[] dst; - break; + dst[i] = m_bitmap[size - i]; + dst[i + 1] = m_bitmap[size - i + 1]; + dst[i + 2] = m_bitmap[size - i + 2]; } - default: + break; + } + default: + { + for (size_t i = 0; i < size; i += gColorDepth) { - BitmapBuffer *dst = new BitmapBuffer[size]; - for (int i(0); i < size; i += gColorDepth) - { - dst[i] = m_bitmap[size - i + 2]; - dst[i + 1] = m_bitmap[size - i + 1]; - dst[i + 2] = m_bitmap[size - i]; - } - jpge::compress_image_to_jpeg_file(filename.c_str(), sceneInfo.size.x, sceneInfo.size.y, gColorDepth, dst); - delete[] dst; - break; + dst[i] = m_bitmap[size - i + 2]; + dst[i + 1] = m_bitmap[size - i + 1]; + dst[i + 2] = m_bitmap[size - i]; } break; - } } + } + jpge::compress_image_to_jpeg_file(filename.c_str(), m_sceneInfo.size.x, + m_sceneInfo.size.y, gColorDepth, dst); + delete dst; m_sceneInfo = bakSceneInfo; LOG_INFO(1, "Screenshot successfully generated!"); } @@ -2878,7 +3199,8 @@ void GPUKernel::initializeOVR() } else { - m_sensor = *m_manager->EnumerateDevices().CreateDevice(); + m_sensor = + *m_manager->EnumerateDevices().CreateDevice(); } if (m_sensorFusion == 0) @@ -2908,4 +3230,4 @@ void GPUKernel::finializeOVR() OVR::System::Destroy(); } #endif // USE_OCULUS -} +} // namespace solr diff --git a/solr/engines/GPUKernel.h b/solr/engines/GPUKernel.h index 8e464b3..a975a1c 100644 --- a/solr/engines/GPUKernel.h +++ b/solr/engines/GPUKernel.h @@ -1,28 +1,24 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once -#include "types.h" - -#include "DLL_API.h" +#include "api.h" +#include "solr.h" #ifdef WIN32 #ifdef USE_KINECT @@ -43,39 +39,6 @@ namespace solr { -struct CPUPrimitive -{ - bool belongsToModel; - bool movable; - vec3f p0; - vec3f p1; - vec3f p2; - vec3f n0; - vec3f n1; - vec3f n2; - vec3f size; - int type; - int materialId; - vec2f vt0; // Texture coordinates - vec2f vt1; - vec2f vt2; - vec3f speed0; - vec3f speed1; - vec3f speed2; -}; - -struct CPUBoundingBox -{ - vec3f parameters[2]; - vec3f center; - std::vector primitives; - long indexForNextBox; -}; - -typedef std::map BoxContainer; -typedef std::map PrimitiveContainer; -typedef std::map LampContainer; - class SOLR_API GPUKernel { public: @@ -100,17 +63,21 @@ class SOLR_API GPUKernel virtual void render_begin(const float timer); virtual void render_end() = 0; BitmapBuffer *getBitmap() { return m_bitmap; } - void generateScreenshot(const std::string &filename, const unsigned int width, const unsigned int height, + void generateScreenshot(const std::string &filename, + const unsigned int width, const unsigned int height, const unsigned int quality); public: // ---------- Primitives ---------- int addPrimitive(PrimitiveType type, bool belongsToModel = false); - void setPrimitive(const int &index, float x0, float y0, float z0, float w, float h, float d, int materialId); - void setPrimitive(const int &index, float x0, float y0, float z0, float x1, float y1, float z1, float w, float h, - float d, int materialId); - void setPrimitive(const int &index, float x0, float y0, float z0, float x1, float y1, float z1, float x2, float y2, - float z2, float w, float h, float d, int materialId); + void setPrimitive(const int &index, float x0, float y0, float z0, float w, + float h, float d, int materialId); + void setPrimitive(const int &index, float x0, float y0, float z0, float x1, + float y1, float z1, float w, float h, float d, + int materialId); + void setPrimitive(const int &index, float x0, float y0, float z0, float x1, + float y1, float z1, float x2, float y2, float z2, float w, + float h, float d, int materialId); unsigned int getPrimitiveAt(int x, int y); void setPrimitiveIsMovable(const int &index, bool movable); void setPrimitiveBellongsToModel(const int &index, bool bellongsToModel); @@ -120,9 +87,10 @@ class SOLR_API GPUKernel // Rotation void rotatePrimitives(const vec3f &rotationCenter, const vec4f &angles); - void rotatePrimitive(CPUPrimitive &primitive, const vec3f &rotationCenter, const vec3f &cosAngles, - const vec3f &sinAngles); - void rotateBox(CPUBoundingBox &box, vec3f rotationCenter, vec3f cosAngles, vec3f sinAngles); + void rotatePrimitive(CPUPrimitive &primitive, const vec3f &rotationCenter, + const vec3f &cosAngles, const vec3f &sinAngles); + void rotateBox(CPUBoundingBox &box, vec3f rotationCenter, vec3f cosAngles, + vec3f sinAngles); vec4f getRotation() { return m_rotation; } // Translation void translatePrimitives(const vec3f &); @@ -138,7 +106,9 @@ class SOLR_API GPUKernel void setPrimitiveCenter(unsigned int index, const vec3f ¢er); // Texture coordinates - void setPrimitiveTextureCoordinates(const unsigned int index, const vec2f& vt0, const vec2f& vt1, const vec2f& vt2); + void setPrimitiveTextureCoordinates(const unsigned int index, + const vec2f &vt0, const vec2f &vt1, + const vec2f &vt2); // Normals void setPrimitiveNormals(unsigned int index, vec3f n0, vec3f n1, vec3f n2); @@ -161,29 +131,37 @@ class SOLR_API GPUKernel // ---------- Complex objects ---------- int addCube(float x, float y, float z, float radius, int materialId); - int addRectangle(float x, float y, float z, float w, float h, float d, int materialId); + int addRectangle(float x, float y, float z, float w, float h, float d, + int materialId); public: // ---------- Materials ---------- int addMaterial(); void setMaterial(unsigned int index, const Material &material); - void setMaterial(unsigned int index, float r, float g, float b, float noise, float reflection, float refraction, - bool procedural, bool wireframe, int wireframeWidth, float transparency, float opacity, - int diffuseTextureId, int normalTextureId, int bumpTextureId, int specularTextureId, - int reflectionTextureId, int transparentTextureId, int ambientOcclusionTextureId, float specValue, - float specPower, float specCoef, float innerIllumination, float illuminationDiffusion, - float illuminationPropagation, bool fastTransparency); + void setMaterial(unsigned int index, float r, float g, float b, float gloss, + float reflection, float refraction, bool procedural, + bool wireframe, int wireframeWidth, float transparency, + float opacity, int diffuseTextureId, int normalTextureId, + int bumpTextureId, int specularTextureId, + int reflectionTextureId, int transparentTextureId, + int ambientOcclusionTextureId, float specValue, + float specPower, float specCoef, float innerIllumination, + float illuminationDiffusion, float illuminationPropagation, + bool fastTransparency); void setMaterialColor(unsigned int index, float r, float g, float b); void setMaterialTextureId(unsigned int textureId); - int getMaterialAttributes(int index, float &r, float &g, float &b, float &noise, float &reflection, - float &refraction, bool &procedural, bool &wireframe, int &wireframeDepth, - float &transparency, float &opacity, int &diffuseTextureId, int &normalTextureId, - int &bumpTextureId, int &specularTextureId, int &reflectionTextureId, - int &transparencyTextureId, int &ambientOcclusionTextureId, float &specValue, - float &specPower, float &specCoef, float &innerIllumination, float &illuminationDiffusion, - float &illuminationPropagation, bool &fastTransparency); + int getMaterialAttributes( + int index, float &r, float &g, float &b, float &gloss, + float &reflection, float &refraction, bool &procedural, bool &wireframe, + int &wireframeDepth, float &transparency, float &opacity, + int &diffuseTextureId, int &normalTextureId, int &bumpTextureId, + int &specularTextureId, int &reflectionTextureId, + int &transparencyTextureId, int &ambientOcclusionTextureId, + float &specValue, float &specPower, float &specCoef, + float &innerIllumination, float &illuminationDiffusion, + float &illuminationPropagation, bool &fastTransparency); Material *getMaterial(const int index); int getCurrentMaterial(); @@ -197,7 +175,10 @@ class SOLR_API GPUKernel // ---------- Textures ---------- void setTexture(const int index, const TextureInfo &textureInfo); void getTexture(const int index, TextureInfo &textureInfo); - void setTexturesTransfered(const bool transfered) { m_texturesTransfered = transfered; } + void setTexturesTransfered(const bool transfered) + { + m_texturesTransfered = transfered; + } void realignTexturesAndMaterials(); bool loadTextureFromFile(const int index, const std::string &filename); @@ -205,10 +186,14 @@ class SOLR_API GPUKernel void processTextureOffsets(); public: - void setSceneInfo(int width, int height, float transparentColor, int shadowsEnabled, float viewDistance, - float shadowIntensity, int nbRayIterations, vec4f backgroundColor, int supportFor3DVision, - float eyeSeparation, bool renderBoxes, int pathTracingIteration, int maxPathTracingIterations, - FrameBufferType frameBufferType, int timestamp, int atmosphericEffect, int skyboxSize, + void setSceneInfo(int width, int height, float transparentColor, + int shadowsEnabled, float viewDistance, + float shadowIntensity, int nbRayIterations, + vec4f backgroundColor, int supportFor3DVision, + float eyeSeparation, bool renderBoxes, + int pathTracingIteration, int maxPathTracingIterations, + FrameBufferType frameBufferType, int timestamp, + int atmosphericEffect, int skyboxSize, int skyboxMaterialId); // Scene @@ -216,7 +201,8 @@ class SOLR_API GPUKernel SceneInfo &getSceneInfo(); // Post processing - void setPostProcessingInfo(PostProcessingType type, float param1, float param2, int param3); + void setPostProcessingInfo(PostProcessingType type, float param1, + float param2, int param3); void setPostProcessingInfo(const PostProcessingInfo &postProcessingInfo); PostProcessingInfo &getPostProcessingInfo() { return m_postProcessingInfo; } @@ -228,8 +214,8 @@ class SOLR_API GPUKernel float dotProduct(const vec3f &a, const vec3f &b); // Bitmap export - void saveBitmapToFile(const std::string &filename, BitmapBuffer *bitmap, const int width, const int height, - const int depth); + void saveBitmapToFile(const std::string &filename, BitmapBuffer *bitmap, + const int width, const int height, const int depth); // Oculus public: @@ -254,13 +240,21 @@ class SOLR_API GPUKernel // ---------- Kinect ---------- void initializeKinectTextures(); - int updateSkeletons(unsigned int primitiveIndex, vec3f skeletonPosition, float size, float radius, int materialId, - float head_radius, int head_materialId, float hands_radius, int hands_materialId, + int updateSkeletons(unsigned int primitiveIndex, vec3f skeletonPosition, + float size, float radius, int materialId, + float head_radius, int head_materialId, + float hands_radius, int hands_materialId, float feet_radius, int feet_materialId); bool getSkeletonPosition(int index, vec3f &position); - BitmapBuffer *getDepthBitmap() { return m_hDepth; } - BitmapBuffer *getVideoBitmap() { return m_hVideo; } + BitmapBuffer *getDepthBitmap() + { + return m_hDepth; + } + BitmapBuffer *getVideoBitmap() + { + return m_hVideo; + } #endif // USE_KINECT public: @@ -272,12 +266,21 @@ class SOLR_API GPUKernel std::string getTextureFilename(const int index); TextureInfo &getTextureInformation(const int index); - void resetAddingIndex() { m_addingIndex = 0; } - void doneWithAdding(const bool &doneWithAdding) { m_doneWithAdding = doneWithAdding; } + void resetAddingIndex() + { + m_addingIndex = 0; + } + void doneWithAdding(const bool &doneWithAdding) + { + m_doneWithAdding = doneWithAdding; + } void resetFrame(); void resetAll(); - void setDistortion(const float distortion) { m_distortion = distortion; } + void setDistortion(const float distortion) + { + m_distortion = distortion; + } void setPointSize(const float pointSize); public: @@ -298,7 +301,8 @@ class SOLR_API GPUKernel void previousFrame(); public: - void rotateVector(vec3f &v, const vec3f &rotationCenter, const vec3f &cosAngles, const vec3f &sinAngles); + void rotateVector(vec3f &v, const vec3f &rotationCenter, + const vec3f &cosAngles, const vec3f &sinAngles); public: int compactBoxes(bool reconstructBoxes); @@ -306,12 +310,24 @@ class SOLR_API GPUKernel void displayBoxesInfo(); void resetBoxes(bool resetPrimitives); - void setPrimitivesTransfered(const bool value) { m_primitivesTransfered = value; } + void setPrimitivesTransfered(const bool value) + { + m_primitivesTransfered = value; + } public: - vec3f &getViewPos() { return m_viewPos; } - vec3f &getViewDir() { return m_viewDir; } - vec4f &getViewAngles() { return m_angles; } + vec3f &getViewPos() + { + return m_viewPos; + } + vec3f &getViewDir() + { + return m_viewDir; + } + vec4f &getViewAngles() + { + return m_angles; + } protected: // Bounding boxes management @@ -325,18 +341,17 @@ class SOLR_API GPUKernel protected: // GPU - BoundingBox *m_hBoundingBoxes; - Primitive *m_hPrimitives; - int *m_hLamps; - Material *m_hMaterials; + BoundingBox *m_hBoundingBoxes{nullptr}; + Primitive *m_hPrimitives{nullptr}; + int *m_hLamps{nullptr}; + Material *m_hMaterials{nullptr}; // Textures TextureInfo m_hTextures[NB_MAX_TEXTURES]; std::map m_textureFilenames; // Scene - RandomBuffer *m_hRandoms; - PrimitiveXYIdBuffer *m_hPrimitivesXYIds; + PrimitiveXYIdBuffer *m_hPrimitivesXYIds{nullptr}; // Acceleration structures int m_nbActiveBoxes[NB_MAX_FRAMES]; @@ -348,7 +363,7 @@ class SOLR_API GPUKernel size_t m_maxPrimitivesPerBox; bool m_doneWithAdding; int m_addingIndex; - + // Camersa position vec3f m_viewPos; vec3f m_viewDir; @@ -401,7 +416,7 @@ class SOLR_API GPUKernel BoxContainer m_boundingBoxes[NB_MAX_FRAMES][BOUNDING_BOXES_TREE_DEPTH]; PrimitiveContainer m_primitives[NB_MAX_FRAMES]; LampContainer m_lamps[NB_MAX_FRAMES]; - LightInformation *m_lightInformation; + LightInformation *m_lightInformation{nullptr}; protected: int m_optimalNbOfBoxes; @@ -453,4 +468,4 @@ class SOLR_API SingletonKernel public: static GPUKernel *kernel(); }; -} +} // namespace solr diff --git a/solr/engines/cpu/CPUKernel.cpp b/solr/engines/cpu/CPUKernel.cpp index 581aafc..9987c90 100644 --- a/solr/engines/cpu/CPUKernel.cpp +++ b/solr/engines/cpu/CPUKernel.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ // System @@ -39,8 +36,8 @@ #include "../opencl/types.h" #endif -#include #include +#include #include "CPUKernel.h" @@ -129,7 +126,8 @@ n1 : index of refraction of original medium n2 : index of refraction of new medium ________________________________________________________________________________ */ -void CPUKernel::vectorRefraction(Vertex &refracted, const Vertex incident, const float n1, const Vertex normal, +void CPUKernel::vectorRefraction(Vertex &refracted, const Vertex incident, + const float n1, const Vertex normal, const float n2) { refracted = incident; @@ -138,9 +136,12 @@ void CPUKernel::vectorRefraction(Vertex &refracted, const Vertex incident, const float r = n1 / n2; float cosI = dot(incident, normal); float cosT2 = 1.f - r * r * (1.f - cosI * cosI); - refracted.x = r * incident.x + (r * cosI - sqrt(fabs(cosT2))) * normal.x; - refracted.y = r * incident.y + (r * cosI - sqrt(fabs(cosT2))) * normal.y; - refracted.z = r * incident.z + (r * cosI - sqrt(fabs(cosT2))) * normal.z; + refracted.x = + r * incident.x + (r * cosI - sqrt(fabs(cosT2))) * normal.x; + refracted.y = + r * incident.y + (r * cosI - sqrt(fabs(cosT2))) * normal.y; + refracted.z = + r * incident.z + (r * cosI - sqrt(fabs(cosT2))) * normal.z; } } @@ -151,7 +152,8 @@ __c : Center of rotations __a : m_angles ________________________________________________________________________________ */ -void CPUKernel::vectorRotation(Vertex &v, const Vertex &rotationCenter, const Vertex &m_angles) +void CPUKernel::vectorRotation(Vertex &v, const Vertex &rotationCenter, + const Vertex &m_angles) { Vertex cosAngles, sinAngles; @@ -207,14 +209,15 @@ void CPUKernel::computeRayAttributes(Ray &ray) ray.signs.z = (ray.inv_direction.z < 0); } -void CPUKernel::juliaSet(const Primitive &primitive, const float x, const float y, FLOAT4 &color) +void CPUKernel::juliaSet(const Primitive &primitive, const float x, + const float y, FLOAT4 &color) { Material &material = m_hMaterials[primitive.materialId]; float W = (float)material.textureMapping.x; float H = (float)material.textureMapping.y; - // pick some values for the constant c, this determines the shape of the Julia - // Set + // pick some values for the constant c, this determines the shape of the + // Julia Set float cRe = -0.7f + 0.4f * sinf(m_sceneInfo.misc.y / 1500.f); float cIm = 0.27015f + 0.4f * cosf(m_sceneInfo.misc.y / 2000.f); @@ -238,17 +241,16 @@ void CPUKernel::juliaSet(const Primitive &primitive, const float x, const float if ((newRe * newRe + newIm * newIm) > 4.f) break; } - // use color model conversion to get rainbow palette, make brightness black if - // maxIterations reached - // color.x += newRe/4.f; - // color.z += newIm/4.f; + // use color model conversion to get rainbow palette, make brightness black + // if maxIterations reached color.x += newRe/4.f; color.z += newIm/4.f; color.x = 1.f - color.x * (n / maxIterations); color.y = 1.f - color.y * (n / maxIterations); color.z = 1.f - color.z * (n / maxIterations); color.w = 1.f - (n / maxIterations); } -void CPUKernel::mandelbrotSet(const Primitive &primitive, const float x, const float y, FLOAT4 &color) +void CPUKernel::mandelbrotSet(const Primitive &primitive, const float x, + const float y, FLOAT4 &color) { Material &material = m_hMaterials[primitive.materialId]; float W = (float)material.textureMapping.x; @@ -260,7 +262,8 @@ void CPUKernel::mandelbrotSet(const Primitive &primitive, const float x, const f float MaxIm = MinIm + (MaxRe - MinRe) * H / W; float Re_factor = (MaxRe - MinRe) / (W - 1.f); float Im_factor = (MaxIm - MinIm) / (H - 1.f); - float maxIterations = (float)(NB_MAX_ITERATIONS + m_sceneInfo.pathTracingIteration); + float maxIterations = + (float)(NB_MAX_ITERATIONS + m_sceneInfo.pathTracingIteration); float c_im = MaxIm - y * Im_factor; float c_re = MinRe + x * Re_factor; @@ -292,7 +295,8 @@ ________________________________________________________________________________ Sphere texture Mapping ________________________________________________________________________________ */ -FLOAT4 CPUKernel::sphereUVMapping(const Primitive &primitive, const Vertex &intersection) +FLOAT4 CPUKernel::sphereUVMapping(const Primitive &primitive, + const Vertex &intersection) { Material &material = m_hMaterials[primitive.materialId]; FLOAT4 result = material.color; @@ -309,7 +313,9 @@ FLOAT4 CPUKernel::sphereUVMapping(const Primitive &primitive, const Vertex &inte #else float len, U, V; float z = intersection.z; - len = sqrt(intersection.x * intersection.x + intersection.y * intersection.y + intersection.z * intersection.z); + len = + sqrt(intersection.x * intersection.x + intersection.y * intersection.y + + intersection.z * intersection.z); if (len > 0.0f) { if (intersection.x == 0.0f && intersection.y == 0.0f) @@ -333,11 +339,13 @@ FLOAT4 CPUKernel::sphereUVMapping(const Primitive &primitive, const Vertex &inte u = u % material.textureMapping.x; if (material.textureMapping.y != 0) v = v % material.textureMapping.y; - if (u >= 0 && u < material.textureMapping.x && v >= 0 && v < material.textureMapping.y) + if (u >= 0 && u < material.textureMapping.x && v >= 0 && + v < material.textureMapping.y) { int textureId = material.textureMapping.z; int A = (v * material.textureMapping.x + u) * material.textureMapping.w; - int B = m_hTextures[textureId].size.x * m_hTextures[textureId].size.y * m_hTextures[textureId].size.z; + int B = m_hTextures[textureId].size.x * m_hTextures[textureId].size.y * + m_hTextures[textureId].size.z; int index = A % B; BitmapBuffer r = m_hTextures[textureId].buffer[index]; BitmapBuffer g = m_hTextures[textureId].buffer[index + 1]; @@ -355,17 +363,22 @@ ________________________________________________________________________________ Triangle texture Mapping ________________________________________________________________________________ */ -FLOAT4 CPUKernel::triangleUVMapping(const Primitive &primitive, const Vertex &intersection, const Vertex &areas) +FLOAT4 CPUKernel::triangleUVMapping(const Primitive &primitive, + const Vertex &intersection, + const Vertex &areas) { Material &material = m_hMaterials[primitive.materialId]; FLOAT4 result = material.color; Vertex T; - T.x = (primitive.vt0.x * areas.x + primitive.vt1.x * areas.y + primitive.vt2.x * areas.z) / + T.x = (primitive.vt0.x * areas.x + primitive.vt1.x * areas.y + + primitive.vt2.x * areas.z) / (areas.x + areas.y + areas.z); - T.y = (primitive.vt0.y * areas.x + primitive.vt1.y * areas.y + primitive.vt2.y * areas.z) / + T.y = (primitive.vt0.y * areas.x + primitive.vt1.y * areas.y + + primitive.vt2.y * areas.z) / (areas.x + areas.y + areas.z); - T.z = (primitive.vt0.z * areas.x + primitive.vt1.z * areas.y + primitive.vt2.z * areas.z) / + T.z = (primitive.vt0.z * areas.x + primitive.vt1.z * areas.y + + primitive.vt2.z * areas.z) / (areas.x + areas.y + areas.z); int u = int(T.x * material.textureMapping.x); @@ -374,21 +387,27 @@ FLOAT4 CPUKernel::triangleUVMapping(const Primitive &primitive, const Vertex &in u = u % material.textureMapping.x; v = v % material.textureMapping.y; - if (u >= 0 && u < material.textureMapping.x && v >= 0 && v < material.textureMapping.y) + if (u >= 0 && u < material.textureMapping.x && v >= 0 && + v < material.textureMapping.y) { switch (material.textureMapping.z) { case TEXTURE_MANDELBROT: - mandelbrotSet(primitive, static_cast(u), static_cast(v), result); + mandelbrotSet(primitive, static_cast(u), + static_cast(v), result); break; case TEXTURE_JULIA: - juliaSet(primitive, static_cast(u), static_cast(v), result); + juliaSet(primitive, static_cast(u), static_cast(v), + result); break; default: { int textureId = material.textureMapping.z; - int A = (v * material.textureMapping.x + u) * material.textureMapping.w; - int B = m_hTextures[textureId].size.x * m_hTextures[textureId].size.y * m_hTextures[textureId].size.z; + int A = + (v * material.textureMapping.x + u) * material.textureMapping.w; + int B = m_hTextures[textureId].size.x * + m_hTextures[textureId].size.y * + m_hTextures[textureId].size.z; int index = A % B; BitmapBuffer r = m_hTextures[textureId].buffer[index]; BitmapBuffer g = m_hTextures[textureId].buffer[index + 1]; @@ -408,7 +427,8 @@ ________________________________________________________________________________ Cube texture mapping ________________________________________________________________________________ */ -FLOAT4 CPUKernel::cubeMapping(const Primitive &primitive, const Vertex &intersection) +FLOAT4 CPUKernel::cubeMapping(const Primitive &primitive, + const Vertex &intersection) { Material &material = m_hMaterials[primitive.materialId]; FLOAT4 result = material.color; @@ -416,20 +436,30 @@ FLOAT4 CPUKernel::cubeMapping(const Primitive &primitive, const Vertex &intersec #ifdef USE_KINECT if (primitive.type == ptCamera) { - int x = static_cast((intersection.x - primitive.p0.x + primitive.size.x) * material.textureMapping.x); - int y = static_cast(KINECT_COLOR_HEIGHT - - (intersection.y - primitive.p0.y + primitive.size.y) * material.textureMapping.y); + int x = static_cast( + (intersection.x - primitive.p0.x + primitive.size.x) * + material.textureMapping.x); + int y = static_cast( + KINECT_COLOR_HEIGHT - + (intersection.y - primitive.p0.y + primitive.size.y) * + material.textureMapping.y); x = (x + KINECT_COLOR_WIDTH) % KINECT_COLOR_WIDTH; y = (y + KINECT_COLOR_HEIGHT) % KINECT_COLOR_HEIGHT; - if (x >= 0 && x < KINECT_COLOR_WIDTH && y >= 0 && y < KINECT_COLOR_HEIGHT) + if (x >= 0 && x < KINECT_COLOR_WIDTH && y >= 0 && + y < KINECT_COLOR_HEIGHT) { int index = (y * KINECT_COLOR_WIDTH + x) * KINECT_COLOR_DEPTH; - index = index % (material.textureMapping.x * material.textureMapping.y * material.textureMapping.w); - BitmapBuffer r = m_hTextures[material.textureMapping.z].buffer[index + 2]; - BitmapBuffer g = m_hTextures[material.textureMapping.z].buffer[index + 1]; - BitmapBuffer b = m_hTextures[material.textureMapping.z].buffer[index]; + index = + index % (material.textureMapping.x * material.textureMapping.y * + material.textureMapping.w); + BitmapBuffer r = + m_hTextures[material.textureMapping.z].buffer[index + 2]; + BitmapBuffer g = + m_hTextures[material.textureMapping.z].buffer[index + 1]; + BitmapBuffer b = + m_hTextures[material.textureMapping.z].buffer[index]; result.x = r / 256.f; result.y = g / 256.f; result.z = b / 256.f; @@ -438,32 +468,44 @@ FLOAT4 CPUKernel::cubeMapping(const Primitive &primitive, const Vertex &intersec else #endif // USE_KINECT { - int u = ((primitive.type == ptCheckboard) || (primitive.type == ptXZPlane) || (primitive.type == ptXYPlane)) - ? static_cast(intersection.x - primitive.p0.x + primitive.size.x) - : static_cast(intersection.z - primitive.p0.z + primitive.size.z); - - int v = ((primitive.type == ptCheckboard) || (primitive.type == ptXZPlane)) - ? static_cast(intersection.z + primitive.p0.z + primitive.size.z) - : static_cast(intersection.y - primitive.p0.y + primitive.size.y); + int u = ((primitive.type == ptCheckboard) || + (primitive.type == ptXZPlane) || (primitive.type == ptXYPlane)) + ? static_cast(intersection.x - primitive.p0.x + + primitive.size.x) + : static_cast(intersection.z - primitive.p0.z + + primitive.size.z); + + int v = + ((primitive.type == ptCheckboard) || (primitive.type == ptXZPlane)) + ? static_cast(intersection.z + primitive.p0.z + + primitive.size.z) + : static_cast(intersection.y - primitive.p0.y + + primitive.size.y); u = u % material.textureMapping.x; v = v % material.textureMapping.y; - if (u >= 0 && u < material.textureMapping.x && v >= 0 && v < material.textureMapping.x) + if (u >= 0 && u < material.textureMapping.x && v >= 0 && + v < material.textureMapping.x) { switch (material.textureMapping.z) { case TEXTURE_MANDELBROT: - mandelbrotSet(primitive, static_cast(u), static_cast(v), result); + mandelbrotSet(primitive, static_cast(u), + static_cast(v), result); break; case TEXTURE_JULIA: - juliaSet(primitive, static_cast(u), static_cast(v), result); + juliaSet(primitive, static_cast(u), + static_cast(v), result); break; default: { int textureId = material.textureMapping.z; - int A = (v * material.textureMapping.x + u) * material.textureMapping.w; - int B = m_hTextures[textureId].size.x * m_hTextures[textureId].size.y * m_hTextures[textureId].size.z; + int A = (v * material.textureMapping.x + u) * + material.textureMapping.w; + int B = m_hTextures[textureId].size.x * + m_hTextures[textureId].size.y * + m_hTextures[textureId].size.z; int index = A % B; BitmapBuffer r = m_hTextures[textureId].buffer[index]; BitmapBuffer g = m_hTextures[textureId].buffer[index + 1]; @@ -479,7 +521,8 @@ FLOAT4 CPUKernel::cubeMapping(const Primitive &primitive, const Vertex &intersec return result; } -bool CPUKernel::wireFrameMapping(float x, float y, int width, const Primitive &primitive) +bool CPUKernel::wireFrameMapping(float x, float y, int width, + const Primitive &primitive) { int X = static_cast(fabs(x)); int Y = static_cast(fabs(y)); @@ -494,14 +537,18 @@ ________________________________________________________________________________ Box intersection ________________________________________________________________________________ */ -bool CPUKernel::boxIntersection(const BoundingBox &box, const Ray &ray, const float &t0, const float &t1) +bool CPUKernel::boxIntersection(const BoundingBox &box, const Ray &ray, + const float &t0, const float &t1) { float tmin, tmax, tymin, tymax, tzmin, tzmax; tmin = (box.parameters[ray.signs.x].x - ray.origin.x) * ray.inv_direction.x; - tmax = (box.parameters[1 - ray.signs.x].x - ray.origin.x) * ray.inv_direction.x; - tymin = (box.parameters[ray.signs.y].y - ray.origin.y) * ray.inv_direction.y; - tymax = (box.parameters[1 - ray.signs.y].y - ray.origin.y) * ray.inv_direction.y; + tmax = (box.parameters[1 - ray.signs.x].x - ray.origin.x) * + ray.inv_direction.x; + tymin = + (box.parameters[ray.signs.y].y - ray.origin.y) * ray.inv_direction.y; + tymax = (box.parameters[1 - ray.signs.y].y - ray.origin.y) * + ray.inv_direction.y; if ((tmin > tymax) || (tymin > tmax)) return false; @@ -510,8 +557,10 @@ bool CPUKernel::boxIntersection(const BoundingBox &box, const Ray &ray, const fl tmin = tymin; if (tymax < tmax) tmax = tymax; - tzmin = (box.parameters[ray.signs.z].z - ray.origin.z) * ray.inv_direction.z; - tzmax = (box.parameters[1 - ray.signs.z].z - ray.origin.z) * ray.inv_direction.z; + tzmin = + (box.parameters[ray.signs.z].z - ray.origin.z) * ray.inv_direction.z; + tzmax = (box.parameters[1 - ray.signs.z].z - ray.origin.z) * + ray.inv_direction.z; if ((tmin > tzmax) || (tzmin > tmax)) return false; @@ -529,8 +578,10 @@ ________________________________________________________________________________ Ellipsoid intersection ________________________________________________________________________________ */ -bool CPUKernel::ellipsoidIntersection(const Primitive &ellipsoid, const Ray &ray, Vertex &intersection, Vertex &normal, - float &shadowIntensity, bool &back) +bool CPUKernel::ellipsoidIntersection(const Primitive &ellipsoid, + const Ray &ray, Vertex &intersection, + Vertex &normal, float &shadowIntensity, + bool &back) { // Shadow intensity shadowIntensity = 1.f; @@ -563,11 +614,11 @@ bool CPUKernel::ellipsoidIntersection(const Primitive &ellipsoid, const Ray &ray float t2 = (-b - d) / (2.f * a); if (t1 <= EPSILON && t2 <= EPSILON) - return false; // both intersections are behind the ray m_viewPos + return false; // both intersections are behind the ray m_viewPos back = (t1 <= EPSILON || t2 <= EPSILON); // If only one intersection (t>0) - // then we are inside the sphere and - // the intersection is at the back of - // the sphere + // then we are inside the sphere + // and the intersection is at the + // back of the sphere float t = 0.f; if (t1 <= EPSILON) @@ -603,7 +654,8 @@ ________________________________________________________________________________ Sphere intersection ________________________________________________________________________________ */ -bool CPUKernel::sphereIntersection(const Primitive &sphere, const Ray &ray, Vertex &intersection, Vertex &normal, +bool CPUKernel::sphereIntersection(const Primitive &sphere, const Ray &ray, + Vertex &intersection, Vertex &normal, float &shadowIntensity, bool &back) { // solve the equation sphere-ray to find the intersections @@ -625,11 +677,11 @@ bool CPUKernel::sphereIntersection(const Primitive &sphere, const Ray &ray, Vert float t2 = (-b + r) / a; if (t1 <= EPSILON && t2 <= EPSILON) - return false; // both intersections are behind the ray m_viewPos + return false; // both intersections are behind the ray m_viewPos back = (t1 <= EPSILON || t2 <= EPSILON); // If only one intersection (t>0) - // then we are inside the sphere and - // the intersection is at the back of - // the sphere + // then we are inside the sphere + // and the intersection is at the + // back of the sphere float t = 0.f; if (t1 <= EPSILON) @@ -659,9 +711,15 @@ bool CPUKernel::sphereIntersection(const Primitive &sphere, const Ray &ray, Vert { // Procedural texture Vertex newCenter; - newCenter.x = sphere.p0.x + 0.008f * sphere.size.x * cos(m_sceneInfo.misc.y + intersection.x); - newCenter.y = sphere.p0.y + 0.008f * sphere.size.y * sin(m_sceneInfo.misc.y + intersection.y); - newCenter.z = sphere.p0.z + 0.008f * sphere.size.z * sin(cos(m_sceneInfo.misc.y + intersection.z)); + newCenter.x = + sphere.p0.x + + 0.008f * sphere.size.x * cos(m_sceneInfo.misc.y + intersection.x); + newCenter.y = + sphere.p0.y + + 0.008f * sphere.size.y * sin(m_sceneInfo.misc.y + intersection.y); + newCenter.z = + sphere.p0.z + 0.008f * sphere.size.z * + sin(cos(m_sceneInfo.misc.y + intersection.z)); normal.x = intersection.x - newCenter.x; normal.y = intersection.y - newCenter.y; normal.z = intersection.z - newCenter.z; @@ -672,19 +730,20 @@ bool CPUKernel::sphereIntersection(const Primitive &sphere, const Ray &ray, Vert normal = normalize(normal); shadowIntensity = 1.f; -// Shadow management -/* -r = dot(dir,normal); -shadowIntensity = (m_hMaterials[sphere.materialId].transparency != 0.f) ? -(1.f-fabs(r)) : 1.f; -*/ + // Shadow management + /* + r = dot(dir,normal); + shadowIntensity = (m_hMaterials[sphere.materialId].transparency != 0.f) ? + (1.f-fabs(r)) : 1.f; + */ #if EXTENDED_FEATURES // Power textures if (m_hMaterials[sphere.materialId].textureInfo.y != TEXTURE_NONE && m_hMaterials[sphere.materialId].transparency != 0) { - Vertex color = sphereUVMapping(sphere, m_hMaterials, textures, intersection, timer); + Vertex color = sphereUVMapping(sphere, m_hMaterials, textures, + intersection, timer); return ((color.x + color.y + color.z) >= m_sceneInfo.transparentColor); } #endif // 0 @@ -698,7 +757,8 @@ ________________________________________________________________________________ Cylinder intersection ________________________________________________________________________________ */ -bool CPUKernel::cylinderIntersection(const Primitive &cylinder, const Ray &ray, Vertex &intersection, Vertex &normal, +bool CPUKernel::cylinderIntersection(const Primitive &cylinder, const Ray &ray, + Vertex &intersection, Vertex &normal, float &shadowIntensity, bool &back) { back = false; @@ -728,7 +788,8 @@ bool CPUKernel::cylinderIntersection(const Primitive &cylinder, const Ray &ray, Vertex O = crossProduct(O_C, cylinder.n1); float t = -dot(O, n) / ln; O = normalize(crossProduct(n, cylinder.n1)); - float s = fabs(sqrtf(cylinder.size.x * cylinder.size.x - d * d) / dot(dir, O)); + float s = + fabs(sqrtf(cylinder.size.x * cylinder.size.x - d * d) / dot(dir, O)); float in = t - s; float out = t + s; @@ -788,11 +849,17 @@ bool CPUKernel::cylinderIntersection(const Primitive &cylinder, const Ray &ray, // Procedural texture Vertex newCenter; newCenter.x = - cylinder.p0.x + 0.01f * cylinder.size.x * cos(m_sceneInfo.misc.y / 100.f + intersection.x); + cylinder.p0.x + + 0.01f * cylinder.size.x * + cos(m_sceneInfo.misc.y / 100.f + intersection.x); newCenter.y = - cylinder.p0.y + 0.01f * cylinder.size.y * sin(m_sceneInfo.misc.y / 100.f + intersection.y); + cylinder.p0.y + + 0.01f * cylinder.size.y * + sin(m_sceneInfo.misc.y / 100.f + intersection.y); newCenter.z = - cylinder.p0.z + 0.01f * cylinder.size.z * sin(cos(m_sceneInfo.misc.y / 100.f + intersection.z)); + cylinder.p0.z + + 0.01f * cylinder.size.z * + sin(cos(m_sceneInfo.misc.y / 100.f + intersection.z)); HB1.x = intersection.x - newCenter.x; HB1.y = intersection.y - newCenter.y; HB1.z = intersection.z - newCenter.z; @@ -809,8 +876,8 @@ bool CPUKernel::cylinderIntersection(const Primitive &cylinder, const Ray &ray, // Shadow management dir = normalize(dir); float r = dot(dir,normal); - shadowIntensity = (m_hMaterials[cylinder.materialId].transparency != 0.f) - ? (1.f-fabs(r)) : 1.f; + shadowIntensity = (m_hMaterials[cylinder.materialId].transparency != + 0.f) ? (1.f-fabs(r)) : 1.f; */ return true; } @@ -824,7 +891,8 @@ ________________________________________________________________________________ Checkboard intersection ________________________________________________________________________________ */ -bool CPUKernel::planeIntersection(const Primitive &primitive, const Ray &ray, Vertex &intersection, Vertex &normal, +bool CPUKernel::planeIntersection(const Primitive &primitive, const Ray &ray, + Vertex &intersection, Vertex &normal, float &shadowIntensity, bool reverse) { bool collision = false; @@ -838,82 +906,112 @@ bool CPUKernel::planeIntersection(const Primitive &primitive, const Ray &ray, Ve { intersection.y = primitive.p0.y; float y = ray.origin.y - primitive.p0.y; - if (reverted * ray.origin.y < 0.f && reverted * ray.origin.y > reverted * primitive.p0.y) + if (reverted * ray.origin.y < 0.f && + reverted * ray.origin.y > reverted * primitive.p0.y) { - intersection.x = ray.origin.x + y * ray.direction.x / -ray.direction.y; - intersection.z = ray.origin.z + y * ray.direction.z / -ray.direction.y; - collision = fabs(intersection.x - primitive.p0.x) < primitive.size.x && - fabs(intersection.z - primitive.p0.z) < primitive.size.z; + intersection.x = + ray.origin.x + y * ray.direction.x / -ray.direction.y; + intersection.z = + ray.origin.z + y * ray.direction.z / -ray.direction.y; + collision = + fabs(intersection.x - primitive.p0.x) < primitive.size.x && + fabs(intersection.z - primitive.p0.z) < primitive.size.z; } break; } case ptXZPlane: { float y = ray.origin.y - primitive.p0.y; - if (reverted * ray.origin.y < 0.f && reverted * ray.origin.y > reverted * primitive.p0.y) + if (reverted * ray.origin.y < 0.f && + reverted * ray.origin.y > reverted * primitive.p0.y) { - intersection.x = ray.origin.x + y * ray.direction.x / -ray.direction.y; + intersection.x = + ray.origin.x + y * ray.direction.x / -ray.direction.y; intersection.y = primitive.p0.y; - intersection.z = ray.origin.z + y * ray.direction.z / -ray.direction.y; - collision = fabs(intersection.x - primitive.p0.x) < primitive.size.x && - fabs(intersection.z - primitive.p0.z) < primitive.size.z; - if (m_hMaterials[primitive.materialId].attributes.z == 2) // Wireframe - collision &= wireFrameMapping(intersection.x, intersection.z, - m_hMaterials[primitive.materialId].attributes.w, primitive); + intersection.z = + ray.origin.z + y * ray.direction.z / -ray.direction.y; + collision = + fabs(intersection.x - primitive.p0.x) < primitive.size.x && + fabs(intersection.z - primitive.p0.z) < primitive.size.z; + if (m_hMaterials[primitive.materialId].attributes.z == + 2) // Wireframe + collision &= wireFrameMapping( + intersection.x, intersection.z, + m_hMaterials[primitive.materialId].attributes.w, primitive); } - if (!collision && reverted * ray.origin.y > 0.f && reverted * ray.origin.y < reverted * primitive.p0.y) + if (!collision && reverted * ray.origin.y > 0.f && + reverted * ray.origin.y < reverted * primitive.p0.y) { normal.x = -normal.x; normal.y = -normal.y; normal.z = -normal.z; - intersection.x = ray.origin.x + y * ray.direction.x / -ray.direction.y; + intersection.x = + ray.origin.x + y * ray.direction.x / -ray.direction.y; intersection.y = primitive.p0.y; - intersection.z = ray.origin.z + y * ray.direction.z / -ray.direction.y; - collision = fabs(intersection.x - primitive.p0.x) < primitive.size.x && - fabs(intersection.z - primitive.p0.z) < primitive.size.z; - if (m_hMaterials[primitive.materialId].attributes.z == 2) // Wireframe - collision &= wireFrameMapping(intersection.x, intersection.z, - m_hMaterials[primitive.materialId].attributes.w, primitive); + intersection.z = + ray.origin.z + y * ray.direction.z / -ray.direction.y; + collision = + fabs(intersection.x - primitive.p0.x) < primitive.size.x && + fabs(intersection.z - primitive.p0.z) < primitive.size.z; + if (m_hMaterials[primitive.materialId].attributes.z == + 2) // Wireframe + collision &= wireFrameMapping( + intersection.x, intersection.z, + m_hMaterials[primitive.materialId].attributes.w, primitive); } break; } case ptYZPlane: { float x = ray.origin.x - primitive.p0.x; - if (reverted * ray.origin.x < 0.f && reverted * ray.origin.x > reverted * primitive.p0.x) + if (reverted * ray.origin.x < 0.f && + reverted * ray.origin.x > reverted * primitive.p0.x) { intersection.x = primitive.p0.x; - intersection.y = ray.origin.y + x * ray.direction.y / -ray.direction.x; - intersection.z = ray.origin.z + x * ray.direction.z / -ray.direction.x; - collision = fabs(intersection.y - primitive.p0.y) < primitive.size.y && - fabs(intersection.z - primitive.p0.z) < primitive.size.z; + intersection.y = + ray.origin.y + x * ray.direction.y / -ray.direction.x; + intersection.z = + ray.origin.z + x * ray.direction.z / -ray.direction.x; + collision = + fabs(intersection.y - primitive.p0.y) < primitive.size.y && + fabs(intersection.z - primitive.p0.z) < primitive.size.z; if (m_hMaterials[primitive.materialId].innerIllumination.x != 0.f) { // Chessboard like Lights - collision &= int(fabs(intersection.z)) % 4000 < 2000 && int(fabs(intersection.y)) % 4000 < 2000; + collision &= int(fabs(intersection.z)) % 4000 < 2000 && + int(fabs(intersection.y)) % 4000 < 2000; } - if (m_hMaterials[primitive.materialId].attributes.z == 2) // Wireframe - collision &= wireFrameMapping(intersection.y, intersection.z, - m_hMaterials[primitive.materialId].attributes.w, primitive); + if (m_hMaterials[primitive.materialId].attributes.z == + 2) // Wireframe + collision &= wireFrameMapping( + intersection.y, intersection.z, + m_hMaterials[primitive.materialId].attributes.w, primitive); } - if (!collision && reverted * ray.origin.x > 0.f && reverted * ray.origin.x < reverted * primitive.p0.x) + if (!collision && reverted * ray.origin.x > 0.f && + reverted * ray.origin.x < reverted * primitive.p0.x) { normal.x = -normal.x; normal.y = -normal.y; normal.z = -normal.z; intersection.x = primitive.p0.x; - intersection.y = ray.origin.y + x * ray.direction.y / -ray.direction.x; - intersection.z = ray.origin.z + x * ray.direction.z / -ray.direction.x; - collision = fabs(intersection.y - primitive.p0.y) < primitive.size.y && - fabs(intersection.z - primitive.p0.z) < primitive.size.z; + intersection.y = + ray.origin.y + x * ray.direction.y / -ray.direction.x; + intersection.z = + ray.origin.z + x * ray.direction.z / -ray.direction.x; + collision = + fabs(intersection.y - primitive.p0.y) < primitive.size.y && + fabs(intersection.z - primitive.p0.z) < primitive.size.z; if (m_hMaterials[primitive.materialId].innerIllumination.x != 0.f) { // Chessboard like Lights - collision &= int(fabs(intersection.z)) % 4000 < 2000 && int(fabs(intersection.y)) % 4000 < 2000; + collision &= int(fabs(intersection.z)) % 4000 < 2000 && + int(fabs(intersection.y)) % 4000 < 2000; } - if (m_hMaterials[primitive.materialId].attributes.z == 2) // Wireframe - collision &= wireFrameMapping(intersection.y, intersection.z, - m_hMaterials[primitive.materialId].attributes.w, primitive); + if (m_hMaterials[primitive.materialId].attributes.z == + 2) // Wireframe + collision &= wireFrameMapping( + intersection.y, intersection.z, + m_hMaterials[primitive.materialId].attributes.w, primitive); } break; } @@ -921,30 +1019,42 @@ bool CPUKernel::planeIntersection(const Primitive &primitive, const Ray &ray, Ve case ptCamera: { float z = ray.origin.z - primitive.p0.z; - if (reverted * ray.origin.z < 0.f && reverted * ray.origin.z > reverted * primitive.p0.z) + if (reverted * ray.origin.z < 0.f && + reverted * ray.origin.z > reverted * primitive.p0.z) { intersection.z = primitive.p0.z; - intersection.x = ray.origin.x + z * ray.direction.x / -ray.direction.z; - intersection.y = ray.origin.y + z * ray.direction.y / -ray.direction.z; - collision = fabs(intersection.x - primitive.p0.x) < primitive.size.x && - fabs(intersection.y - primitive.p0.y) < primitive.size.y; - if (m_hMaterials[primitive.materialId].attributes.z == 2) // Wireframe - collision &= wireFrameMapping(intersection.x, intersection.y, - m_hMaterials[primitive.materialId].attributes.w, primitive); + intersection.x = + ray.origin.x + z * ray.direction.x / -ray.direction.z; + intersection.y = + ray.origin.y + z * ray.direction.y / -ray.direction.z; + collision = + fabs(intersection.x - primitive.p0.x) < primitive.size.x && + fabs(intersection.y - primitive.p0.y) < primitive.size.y; + if (m_hMaterials[primitive.materialId].attributes.z == + 2) // Wireframe + collision &= wireFrameMapping( + intersection.x, intersection.y, + m_hMaterials[primitive.materialId].attributes.w, primitive); } - if (!collision && reverted * ray.origin.z > 0.f && reverted * ray.origin.z < reverted * primitive.p0.z) + if (!collision && reverted * ray.origin.z > 0.f && + reverted * ray.origin.z < reverted * primitive.p0.z) { normal.x = -normal.x; normal.y = -normal.y; normal.z = -normal.z; intersection.z = primitive.p0.z; - intersection.x = ray.origin.x + z * ray.direction.x / -ray.direction.z; - intersection.y = ray.origin.y + z * ray.direction.y / -ray.direction.z; - collision = fabs(intersection.x - primitive.p0.x) < primitive.size.x && - fabs(intersection.y - primitive.p0.y) < primitive.size.y; - if (m_hMaterials[primitive.materialId].attributes.z == 2) // Wireframe - collision &= wireFrameMapping(intersection.x, intersection.y, - m_hMaterials[primitive.materialId].attributes.w, primitive); + intersection.x = + ray.origin.x + z * ray.direction.x / -ray.direction.z; + intersection.y = + ray.origin.y + z * ray.direction.y / -ray.direction.z; + collision = + fabs(intersection.x - primitive.p0.x) < primitive.size.x && + fabs(intersection.y - primitive.p0.y) < primitive.size.y; + if (m_hMaterials[primitive.materialId].attributes.z == + 2) // Wireframe + collision &= wireFrameMapping( + intersection.x, intersection.y, + m_hMaterials[primitive.materialId].attributes.w, primitive); } break; } @@ -953,10 +1063,12 @@ bool CPUKernel::planeIntersection(const Primitive &primitive, const Ray &ray, Ve if (collision) { // Shadow intensity - shadowIntensity = 1.f; // m_sceneInfo.shadowIntensity*(1.f-m_hMaterials[primitive.materialId].transparency); + shadowIntensity = + 1.f; // m_sceneInfo.shadowIntensity*(1.f-m_hMaterials[primitive.materialId].transparency); FLOAT4 color = m_hMaterials[primitive.materialId].color; - if (primitive.type == ptCamera || m_hMaterials[primitive.materialId].textureMapping.z != TEXTURE_NONE) + if (primitive.type == ptCamera || + m_hMaterials[primitive.materialId].textureMapping.z != TEXTURE_NONE) { color = cubeMapping(primitive, intersection); shadowIntensity = color.w; @@ -976,21 +1088,26 @@ ________________________________________________________________________________ Triangle intersection ________________________________________________________________________________ */ -bool CPUKernel::triangleIntersection(const Primitive &triangle, const Ray &ray, Vertex &intersection, Vertex &normal, - Vertex &areas, float &shadowIntensity, bool &back) +bool CPUKernel::triangleIntersection(const Primitive &triangle, const Ray &ray, + Vertex &intersection, Vertex &normal, + Vertex &areas, float &shadowIntensity, + bool &back) { back = false; // Reject rays using the barycentric coordinates of // the intersection point with respect to T. - Vertex E01 = {triangle.p1.x - triangle.p0.x, triangle.p1.y - triangle.p0.y, triangle.p1.z - triangle.p0.z}; - Vertex E03 = {triangle.p2.x - triangle.p0.x, triangle.p2.y - triangle.p0.y, triangle.p2.z - triangle.p0.z}; + Vertex E01 = {triangle.p1.x - triangle.p0.x, triangle.p1.y - triangle.p0.y, + triangle.p1.z - triangle.p0.z}; + Vertex E03 = {triangle.p2.x - triangle.p0.x, triangle.p2.y - triangle.p0.y, + triangle.p2.z - triangle.p0.z}; Vertex P = crossProduct(ray.direction, E03); float det = dot(E01, P); if (fabs(det) < EPSILON) return false; - Vertex T = {ray.origin.x - triangle.p0.x, ray.origin.y - triangle.p0.y, ray.origin.z - triangle.p0.z}; + Vertex T = {ray.origin.x - triangle.p0.x, ray.origin.y - triangle.p0.y, + ray.origin.z - triangle.p0.z}; float a = dot(T, P) / det; if (a < 0.f || a > 1.f) return false; @@ -1004,13 +1121,18 @@ bool CPUKernel::triangleIntersection(const Primitive &triangle, const Ray &ray, // the intersection point with respect to T′. if ((a + b) > 1.f) { - Vertex E23 = {triangle.p0.x - triangle.p1.x, triangle.p0.y - triangle.p1.y, triangle.p0.z - triangle.p1.z}; - Vertex E21 = {triangle.p1.x - triangle.p1.x, triangle.p1.y - triangle.p1.y, triangle.p1.z - triangle.p1.z}; + Vertex E23 = {triangle.p0.x - triangle.p1.x, + triangle.p0.y - triangle.p1.y, + triangle.p0.z - triangle.p1.z}; + Vertex E21 = {triangle.p1.x - triangle.p1.x, + triangle.p1.y - triangle.p1.y, + triangle.p1.z - triangle.p1.z}; Vertex P_ = crossProduct(ray.direction, E21); float det_ = dot(E23, P_); if (fabs(det_) < EPSILON) return false; - Vertex T_ = {ray.origin.x - triangle.p2.x, ray.origin.y - triangle.p2.y, ray.origin.z - triangle.p2.z}; + Vertex T_ = {ray.origin.x - triangle.p2.x, ray.origin.y - triangle.p2.y, + ray.origin.z - triangle.p2.z}; float a_ = dot(T_, P_) / det_; if (a_ < 0.f) return false; @@ -1033,20 +1155,26 @@ bool CPUKernel::triangleIntersection(const Primitive &triangle, const Ray &ray, // Normal normal = triangle.n0; - Vertex v0 = {triangle.p0.x - intersection.x, triangle.p0.y - intersection.y, triangle.p0.z - intersection.z}; - Vertex v1 = {triangle.p1.x - intersection.x, triangle.p1.y - intersection.y, triangle.p1.z - intersection.z}; - Vertex v2 = {triangle.p2.x - intersection.x, triangle.p2.y - intersection.y, triangle.p2.z - intersection.z}; + Vertex v0 = {triangle.p0.x - intersection.x, triangle.p0.y - intersection.y, + triangle.p0.z - intersection.z}; + Vertex v1 = {triangle.p1.x - intersection.x, triangle.p1.y - intersection.y, + triangle.p1.z - intersection.z}; + Vertex v2 = {triangle.p2.x - intersection.x, triangle.p2.y - intersection.y, + triangle.p2.z - intersection.z}; areas.x = 0.5f * vectorLength(crossProduct(v1, v2)); areas.y = 0.5f * vectorLength(crossProduct(v0, v2)); areas.z = 0.5f * vectorLength(crossProduct(v0, v1)); - normal.x = - (triangle.n0.x * areas.x + triangle.n1.x * areas.y + triangle.n2.x * areas.z) / (areas.x + areas.y + areas.z); - normal.y = - (triangle.n0.y * areas.x + triangle.n1.y * areas.y + triangle.n2.y * areas.z) / (areas.x + areas.y + areas.z); - normal.z = - (triangle.n0.z * areas.x + triangle.n1.z * areas.y + triangle.n2.z * areas.z) / (areas.x + areas.y + areas.z); + normal.x = (triangle.n0.x * areas.x + triangle.n1.x * areas.y + + triangle.n2.x * areas.z) / + (areas.x + areas.y + areas.z); + normal.y = (triangle.n0.y * areas.x + triangle.n1.y * areas.y + + triangle.n2.y * areas.z) / + (areas.x + areas.y + areas.z); + normal.z = (triangle.n0.z * areas.x + triangle.n1.z * areas.y + + triangle.n2.z * areas.z) / + (areas.x + areas.y + areas.z); normal = normalize(normal); Vertex dir = normalize(ray.direction); @@ -1070,9 +1198,10 @@ ________________________________________________________________________________ Intersections with primitives ________________________________________________________________________________ */ -bool CPUKernel::intersectionWithPrimitives(const Ray &ray, const int &iteration, int &closestPrimitive, - Vertex &closestIntersection, Vertex &closestNormal, Vertex &closestAreas, - FLOAT4 &colorBox, bool &back, const int currentMaterialId) +bool CPUKernel::intersectionWithPrimitives( + const Ray &ray, const int &iteration, int &closestPrimitive, + Vertex &closestIntersection, Vertex &closestNormal, Vertex &closestAreas, + FLOAT4 &colorBox, bool &back, const int currentMaterialId) { bool intersections = false; float minDistance = m_sceneInfo.viewDistance / (iteration + 1); @@ -1098,23 +1227,33 @@ bool CPUKernel::intersectionWithPrimitives(const Ray &ray, const int &iteration, // Intersection with Box if (m_sceneInfo.renderBoxes != 0) { - colorBox.x += m_hMaterials[box.startIndex % NB_MAX_MATERIALS].color.x / 50.f; - colorBox.y += m_hMaterials[box.startIndex % NB_MAX_MATERIALS].color.y / 50.f; - colorBox.z += m_hMaterials[box.startIndex % NB_MAX_MATERIALS].color.z / 50.f; + colorBox.x += + m_hMaterials[box.startIndex % NB_MAX_MATERIALS].color.x / + 50.f; + colorBox.y += + m_hMaterials[box.startIndex % NB_MAX_MATERIALS].color.y / + 50.f; + colorBox.z += + m_hMaterials[box.startIndex % NB_MAX_MATERIALS].color.z / + 50.f; } else { // Intersection with primitive within boxes - for (int cptPrimitives = 0; cptPrimitives < box.nbPrimitives; ++cptPrimitives) + for (int cptPrimitives = 0; cptPrimitives < box.nbPrimitives; + ++cptPrimitives) { - Primitive &primitive = m_hPrimitives[box.startIndex + cptPrimitives]; + Primitive &primitive = + m_hPrimitives[box.startIndex + cptPrimitives]; Material &material = m_hMaterials[primitive.materialId]; if (material.attributes.x == 0 || - (material.attributes.x == 1 && currentMaterialId != primitive.materialId)) // !!!! TEST SHALL BE - // REMOVED TO - // INCREASE - // TRANSPARENCY - // QUALITY !!! + (material.attributes.x == 1 && + currentMaterialId != + primitive.materialId)) // !!!! TEST SHALL BE + // REMOVED TO + // INCREASE + // TRANSPARENCY + // QUALITY !!! { Vertex areas = {0.f, 0.f, 0.f}; i = false; @@ -1123,29 +1262,39 @@ bool CPUKernel::intersectionWithPrimitives(const Ray &ray, const int &iteration, case ptEnvironment: case ptSphere: { - i = sphereIntersection(primitive, r, intersection, normal, shadowIntensity, back); + i = sphereIntersection(primitive, r, intersection, + normal, shadowIntensity, + back); break; } case ptCylinder: { - i = cylinderIntersection(primitive, r, intersection, normal, shadowIntensity, back); + i = cylinderIntersection(primitive, r, intersection, + normal, shadowIntensity, + back); break; } case ptEllipsoid: { - i = ellipsoidIntersection(primitive, r, intersection, normal, shadowIntensity, back); + i = ellipsoidIntersection(primitive, r, + intersection, normal, + shadowIntensity, back); break; } case ptTriangle: { back = false; - i = triangleIntersection(primitive, r, intersection, normal, areas, shadowIntensity, back); + i = triangleIntersection(primitive, r, intersection, + normal, areas, + shadowIntensity, back); break; } default: { back = false; - i = planeIntersection(primitive, r, intersection, normal, shadowIntensity, false); + i = planeIntersection(primitive, r, intersection, + normal, shadowIntensity, + false); break; } } @@ -1211,7 +1360,8 @@ void CPUKernel::makeColor(FLOAT4 &color, int index) } case otJPEG: { - mdc_index = (m_sceneInfo.size.x * m_sceneInfo.size.y - index) * gColorDepth; + mdc_index = + (m_sceneInfo.size.x * m_sceneInfo.size.y - index) * gColorDepth; // JPEG m_bitmap[mdc_index + 2] = (char)(color.z * 255.f); // Blue m_bitmap[mdc_index + 1] = (char)(color.y * 255.f); // Green @@ -1246,7 +1396,8 @@ light source center. ________________________________________________________________________________ */ -float CPUKernel::processShadows(const Vertex &lampCenter, const Vertex &m_viewPos, const int &objectId, +float CPUKernel::processShadows(const Vertex &lampCenter, + const Vertex &m_viewPos, const int &objectId, const int &iteration, FLOAT4 &color) { float result = 0.f; @@ -1262,43 +1413,55 @@ float CPUKernel::processShadows(const Vertex &lampCenter, const Vertex &m_viewPo r.direction.z = lampCenter.z - m_viewPos.z; computeRayAttributes(r); - while (result < m_sceneInfo.shadowIntensity && cptBoxes < m_nbActiveBoxes[m_frame]) + while (result < m_sceneInfo.shadowIntensity && + cptBoxes < m_nbActiveBoxes[m_frame]) { BoundingBox &box = m_hBoundingBoxes[cptBoxes]; if (boxIntersection(box, r, 0.f, m_sceneInfo.viewDistance)) { int cptPrimitives = 0; - while (result < m_sceneInfo.shadowIntensity && cptPrimitives < box.nbPrimitives) + while (result < m_sceneInfo.shadowIntensity && + cptPrimitives < box.nbPrimitives) { Vertex intersection = {0.f, 0.f, 0.f}; Vertex normal = {0.f, 0.f, 0.f}; Vertex areas = {0.f, 0.f, 0.f}; float shadowIntensity = 0.f; - Primitive &primitive = m_hPrimitives[box.startIndex + cptPrimitives]; - if (primitive.index != objectId && m_hMaterials[primitive.materialId].attributes.x == 0) + Primitive &primitive = + m_hPrimitives[box.startIndex + cptPrimitives]; + if (primitive.index != objectId && + m_hMaterials[primitive.materialId].attributes.x == 0) { bool hit = false; bool back; switch (primitive.type) { case ptSphere: - hit = sphereIntersection(primitive, r, intersection, normal, shadowIntensity, back); + hit = sphereIntersection(primitive, r, intersection, + normal, shadowIntensity, back); break; case ptEllipsoid: - hit = ellipsoidIntersection(primitive, r, intersection, normal, shadowIntensity, back); + hit = ellipsoidIntersection(primitive, r, intersection, + normal, shadowIntensity, + back); break; case ptCylinder: - hit = cylinderIntersection(primitive, r, intersection, normal, shadowIntensity, back); + hit = + cylinderIntersection(primitive, r, intersection, + normal, shadowIntensity, back); break; case ptTriangle: - hit = triangleIntersection(primitive, r, intersection, normal, areas, shadowIntensity, back); + hit = triangleIntersection(primitive, r, intersection, + normal, areas, + shadowIntensity, back); break; case ptCamera: hit = false; break; default: - hit = planeIntersection(primitive, r, intersection, normal, shadowIntensity, false); + hit = planeIntersection(primitive, r, intersection, + normal, shadowIntensity, false); break; } @@ -1317,19 +1480,38 @@ float CPUKernel::processShadows(const Vertex &lampCenter, const Vertex &m_viewPo float l = vectorLength(O_I); if (l > EPSILON && l < vectorLength(O_L)) { - float ratio = shadowIntensity * m_sceneInfo.shadowIntensity; - if (m_hMaterials[primitive.materialId].transparency != 0.f) + float ratio = + shadowIntensity * m_sceneInfo.shadowIntensity; + if (m_hMaterials[primitive.materialId] + .transparency != 0.f) { O_L = normalize(O_L); float a = fabs(dot(O_L, normal)); - float r = (m_hMaterials[primitive.materialId].transparency == 0.f) - ? 1.f - : (1.f - 0.8f * m_hMaterials[primitive.materialId].transparency); + float r = + (m_hMaterials[primitive.materialId] + .transparency == 0.f) + ? 1.f + : (1.f - + 0.8f * m_hMaterials[primitive + .materialId] + .transparency); ratio *= r * a; // Shadow color - color.x += ratio * (0.3f - 0.3f * m_hMaterials[primitive.materialId].color.x); - color.y += ratio * (0.3f - 0.3f * m_hMaterials[primitive.materialId].color.y); - color.z += ratio * (0.3f - 0.3f * m_hMaterials[primitive.materialId].color.z); + color.x += + ratio * + (0.3f - + 0.3f * m_hMaterials[primitive.materialId] + .color.x); + color.y += + ratio * + (0.3f - + 0.3f * m_hMaterials[primitive.materialId] + .color.y); + color.z += + ratio * + (0.3f - + 0.3f * m_hMaterials[primitive.materialId] + .color.z); } result += ratio; } @@ -1341,7 +1523,9 @@ float CPUKernel::processShadows(const Vertex &lampCenter, const Vertex &m_viewPo } cptBoxes++; } - result = (result > m_sceneInfo.shadowIntensity) ? m_sceneInfo.shadowIntensity : result; + result = (result > m_sceneInfo.shadowIntensity) + ? m_sceneInfo.shadowIntensity + : result; result = (result < 0.f) ? 0.f : result; return result; } @@ -1352,10 +1536,13 @@ ________________________________________________________________________________ Intersection Shader ________________________________________________________________________________ */ -FLOAT4 CPUKernel::intersectionShader(const Primitive &primitive, const Vertex &intersection, const Vertex &areas) +FLOAT4 CPUKernel::intersectionShader(const Primitive &primitive, + const Vertex &intersection, + const Vertex &areas) { FLOAT4 colorAtIntersection = m_hMaterials[primitive.materialId].color; - colorAtIntersection.w = 0.f; // w attribute is used to dtermine light intensity of the material + colorAtIntersection.w = + 0.f; // w attribute is used to dtermine light intensity of the material switch (primitive.type) { @@ -1385,8 +1572,12 @@ FLOAT4 CPUKernel::intersectionShader(const Primitive &primitive, const Vertex &i } else { - int x = static_cast(m_sceneInfo.viewDistance + ((intersection.x - primitive.p0.x) / primitive.size.x)); - int z = static_cast(m_sceneInfo.viewDistance + ((intersection.z - primitive.p0.z) / primitive.size.x)); + int x = static_cast( + m_sceneInfo.viewDistance + + ((intersection.x - primitive.p0.x) / primitive.size.x)); + int z = static_cast( + m_sceneInfo.viewDistance + + ((intersection.z - primitive.p0.z) / primitive.size.x)); if (x % 2 == 0) { if (z % 2 == 0) @@ -1423,7 +1614,8 @@ FLOAT4 CPUKernel::intersectionShader(const Primitive &primitive, const Vertex &i { if (m_hMaterials[primitive.materialId].textureMapping.z != TEXTURE_NONE) { - colorAtIntersection = triangleUVMapping(primitive, intersection, areas); + colorAtIntersection = + triangleUVMapping(primitive, intersection, areas); } break; } @@ -1437,11 +1629,12 @@ ________________________________________________________________________________ Primitive shader ________________________________________________________________________________ */ -FLOAT4 CPUKernel::primitiveShader(const Vertex &m_viewPos, const Vertex &normal, const int &objectId, - const Vertex &intersection, const Vertex &areas, const int &iteration, - FLOAT4 &refractionFromColor, float &shadowIntensity, FLOAT4 &totalBlinn, - LightInformation *pathTracingInformation, const int pathTracingInformationSize, - const bool isLightRay) +FLOAT4 CPUKernel::primitiveShader( + const Vertex &m_viewPos, const Vertex &normal, const int &objectId, + const Vertex &intersection, const Vertex &areas, const int &iteration, + FLOAT4 &refractionFromColor, float &shadowIntensity, FLOAT4 &totalBlinn, + LightInformation *pathTracingInformation, + const int pathTracingInformationSize, const bool isLightRay) { Primitive primitive = m_hPrimitives[objectId]; FLOAT4 color = m_hMaterials[primitive.materialId].color; @@ -1471,40 +1664,54 @@ FLOAT4 CPUKernel::primitiveShader(const Vertex &m_viewPos, const Vertex &normal, bool processStdLigths(pathTracingInformationSize == 0); // if( !processStdLigths ) LOG_INFO(1,"pathTracingInformationSize=" << - // pathTracingInformationSize << " (" << pathTracingInformation[0].color.x + // pathTracingInformationSize << " (" << + // pathTracingInformation[0].color.x // << "," << pathTracingInformation[0].color.y << "," << // pathTracingInformation[0].color.z); - int nbLamps = processStdLigths ? m_lightInformationSize : pathTracingInformationSize; + int nbLamps = processStdLigths ? m_lightInformationSize + : pathTracingInformationSize; for (int cpt = 0; cpt < nbLamps; ++cpt) { int cptLamp = cpt; - LightInformation &li = (processStdLigths ? m_lightInformation[cptLamp] : pathTracingInformation[cptLamp]); + LightInformation &li = + (processStdLigths ? m_lightInformation[cptLamp] + : pathTracingInformation[cptLamp]); if (li.attribute.x != primitive.index) { Vertex center = li.location; // randomize lamp center - if (li.attribute.x >= 0 && li.attribute.x < m_nbActivePrimitives[m_frame]) + if (li.attribute.x >= 0 && + li.attribute.x < m_nbActivePrimitives[m_frame]) { Primitive &lamp = m_hPrimitives[li.attribute.x]; int t = 3 * m_sceneInfo.misc.y; t = t % (m_sceneInfo.size.x * m_sceneInfo.size.y - 3); - center.x += m_hMaterials[lamp.materialId].innerIllumination.y * m_hRandoms[t] * - m_sceneInfo.pathTracingIteration / float(m_sceneInfo.maxPathTracingIterations); - center.y += m_hMaterials[lamp.materialId].innerIllumination.y * m_hRandoms[t + 1] * - m_sceneInfo.pathTracingIteration / float(m_sceneInfo.maxPathTracingIterations); - center.z += m_hMaterials[lamp.materialId].innerIllumination.y * m_hRandoms[t + 2] * - m_sceneInfo.pathTracingIteration / float(m_sceneInfo.maxPathTracingIterations); + center.x += + m_hMaterials[lamp.materialId].innerIllumination.y * + m_hRandoms[t] * m_sceneInfo.pathTracingIteration / + float(m_sceneInfo.maxPathTracingIterations); + center.y += + m_hMaterials[lamp.materialId].innerIllumination.y * + m_hRandoms[t + 1] * m_sceneInfo.pathTracingIteration / + float(m_sceneInfo.maxPathTracingIterations); + center.z += + m_hMaterials[lamp.materialId].innerIllumination.y * + m_hRandoms[t + 2] * m_sceneInfo.pathTracingIteration / + float(m_sceneInfo.maxPathTracingIterations); } FLOAT4 shadowColor = {0.f, 0.f, 0.f, 0.f}; if (m_sceneInfo.graphicsLevel > 3 && iteration < 4 && - m_hMaterials[primitive.materialId].innerIllumination.x == 0.f) + m_hMaterials[primitive.materialId].innerIllumination.x == + 0.f) { - shadowIntensity = processShadows(center, intersection, li.attribute.x, iteration, shadowColor); + shadowIntensity = + processShadows(center, intersection, li.attribute.x, + iteration, shadowColor); } if (m_sceneInfo.graphicsLevel > 0) @@ -1518,20 +1725,30 @@ FLOAT4 CPUKernel::primitiveShader(const Vertex &m_viewPos, const Vertex &normal, // -------------------------------------------------------------------------------- // Lambert // -------------------------------------------------------------------------------- - float lambert = (m_postProcessingInfo.type == ppe_ambientOcclusion) ? 0.6f : dot(normal, lightRay); - // Transparent m_hMaterials are lighted on both sides but the amount - // of light received by the "dark side" - // depends on the transparency rate. - lambert *= (lambert < 0.f) ? -m_hMaterials[primitive.materialId].transparency : lambert; + float lambert = + (m_postProcessingInfo.type == ppe_ambientOcclusion) + ? 0.6f + : dot(normal, lightRay); + // Transparent m_hMaterials are lighted on both sides but + // the amount of light received by the "dark side" depends + // on the transparency rate. + lambert *= + (lambert < 0.f) + ? -m_hMaterials[primitive.materialId].transparency + : lambert; lambert *= li.color.w; lambert *= (1.f - shadowIntensity); // Lighted object, not in the shades - lampsColor.x += lambert * li.color.x * li.color.w - shadowColor.x; - lampsColor.y += lambert * li.color.y * li.color.w - shadowColor.y; - lampsColor.z += lambert * li.color.z * li.color.w - shadowColor.z; - - if (m_sceneInfo.graphicsLevel > 1 && shadowIntensity < m_sceneInfo.shadowIntensity) + lampsColor.x += + lambert * li.color.x * li.color.w - shadowColor.x; + lampsColor.y += + lambert * li.color.y * li.color.w - shadowColor.y; + lampsColor.z += + lambert * li.color.z * li.color.w - shadowColor.z; + + if (m_sceneInfo.graphicsLevel > 1 && + shadowIntensity < m_sceneInfo.shadowIntensity) { // -------------------------------------------------------------------------------- // Blinn - Phong @@ -1558,8 +1775,11 @@ FLOAT4 CPUKernel::primitiveShader(const Vertex &m_viewPos, const Vertex &normal, float blinnTerm = dot(blinnDir, normal); blinnTerm = (blinnTerm < 0.f) ? 0.f : blinnTerm; - blinnTerm = m_hMaterials[primitive.materialId].specular.x * - pow(blinnTerm, m_hMaterials[primitive.materialId].specular.y); + blinnTerm = + m_hMaterials[primitive.materialId].specular.x * + pow(blinnTerm, + m_hMaterials[primitive.materialId] + .specular.y); totalBlinn.x += li.color.x * li.color.w * blinnTerm; totalBlinn.y += li.color.y * li.color.w * blinnTerm; @@ -1570,7 +1790,8 @@ FLOAT4 CPUKernel::primitiveShader(const Vertex &m_viewPos, const Vertex &normal, } // Final color - FLOAT4 intersectionColor = intersectionShader(primitive, intersection, areas); + FLOAT4 intersectionColor = + intersectionShader(primitive, intersection, areas); // Light impact on material color.x += intersectionColor.x * lampsColor.x; @@ -1580,7 +1801,8 @@ FLOAT4 CPUKernel::primitiveShader(const Vertex &m_viewPos, const Vertex &normal, // Saturate color saturateVector(color); - refractionFromColor = intersectionColor; // Refraction depending on color; + refractionFromColor = + intersectionColor; // Refraction depending on color; saturateVector(totalBlinn); } } @@ -1611,8 +1833,10 @@ the ray). It can be considered as a light source if its inner light rate is > 0. ________________________________________________________________________________ */ -FLOAT4 CPUKernel::launchRay(const Ray &ray, Vertex &intersection, float &depthOfField, INT4 &primitiveXYId, - LightInformation *pathTracingInformation, int &pathTracingInformationSize, bool isLightRay) +FLOAT4 CPUKernel::launchRay(const Ray &ray, Vertex &intersection, + float &depthOfField, INT4 &primitiveXYId, + LightInformation *pathTracingInformation, + int &pathTracingInformationSize, bool isLightRay) { FLOAT4 intersectionColor = {0.f, 0.f, 0.f, 0.f}; @@ -1654,8 +1878,12 @@ FLOAT4 CPUKernel::launchRay(const Ray &ray, Vertex &intersection, float &depthOf FLOAT4 rBlinn = {0.f, 0.f, 0.f, 0.f}; int currentMaxIteration = - (m_sceneInfo.graphicsLevel < 3) ? 1 : m_sceneInfo.nbRayIterations + m_sceneInfo.pathTracingIteration; - currentMaxIteration = (currentMaxIteration > NB_MAX_ITERATIONS) ? NB_MAX_ITERATIONS : currentMaxIteration; + (m_sceneInfo.graphicsLevel < 3) + ? 1 + : m_sceneInfo.nbRayIterations + m_sceneInfo.pathTracingIteration; + currentMaxIteration = (currentMaxIteration > NB_MAX_ITERATIONS) + ? NB_MAX_ITERATIONS + : currentMaxIteration; #ifdef PHOTON_ENERGY while (iteration < currentMaxIteration && carryon && photonDistance > 0.f) @@ -1668,8 +1896,11 @@ FLOAT4 CPUKernel::launchRay(const Ray &ray, Vertex &intersection, float &depthOf // Primitives if (carryon) { - carryon = intersectionWithPrimitives(rayOrigin, iteration, closestPrimitive, closestIntersection, normal, - areas, colorBox, back, currentMaterialId); + carryon = + intersectionWithPrimitives(rayOrigin, iteration, + closestPrimitive, + closestIntersection, normal, areas, + colorBox, back, currentMaterialId); } if (carryon) @@ -1695,19 +1926,27 @@ FLOAT4 CPUKernel::launchRay(const Ray &ray, Vertex &intersection, float &depthOf d.y = closestIntersection.y - rayOrigin.origin.y; d.z = closestIntersection.z - rayOrigin.origin.z; photonDistance -= vectorLength(d) * (2.f - previousTransparency); - previousTransparency = back ? 1.f : m_hMaterials[m_hPrimitives[closestPrimitive].materialId].transparency; + previousTransparency = + back ? 1.f + : m_hMaterials[m_hPrimitives[closestPrimitive].materialId] + .transparency; #endif // PHOTON_ENERGY // Get object color - colors[iteration] = primitiveShader(rayOrigin.origin, normal, closestPrimitive, closestIntersection, areas, - iteration, refractionFromColor, shadowIntensity, rBlinn, - pathTracingInformation, pathTracingInformationSize, isLightRay); + colors[iteration] = + primitiveShader(rayOrigin.origin, normal, closestPrimitive, + closestIntersection, areas, iteration, + refractionFromColor, shadowIntensity, rBlinn, + pathTracingInformation, + pathTracingInformationSize, isLightRay); if (isLightRay) { // Accumulate Path tracing information - pathTracingInformation[iteration].location = closestIntersection; - pathTracingInformation[iteration].attribute.x = closestPrimitive; + pathTracingInformation[iteration].location = + closestIntersection; + pathTracingInformation[iteration].attribute.x = + closestPrimitive; pathTracingInformation[iteration].color = colors[iteration]; pathTracingInformation[iteration].color.w = 1.f; // LOG_INFO(1,"CI[" << iteration << "]=" << @@ -1721,11 +1960,13 @@ FLOAT4 CPUKernel::launchRay(const Ray &ray, Vertex &intersection, float &depthOf // Refraction // ---------- - if (m_hMaterials[m_hPrimitives[closestPrimitive].materialId].transparency != 0.f) + if (m_hMaterials[m_hPrimitives[closestPrimitive].materialId] + .transparency != 0.f) { // Replace the normal using the intersection color // r,g,b become x,y,z... What the fuck!! - if (m_hMaterials[m_hPrimitives[closestPrimitive].materialId].textureMapping.z != TEXTURE_NONE) + if (m_hMaterials[m_hPrimitives[closestPrimitive].materialId] + .textureMapping.z != TEXTURE_NONE) { normal.x *= (colors[iteration].x - 0.5f); normal.y *= (colors[iteration].y - 0.5f); @@ -1733,7 +1974,11 @@ FLOAT4 CPUKernel::launchRay(const Ray &ray, Vertex &intersection, float &depthOf } // Back of the object? If so, reset refraction to 1.f (air) - float refraction = back ? 1.f : m_hMaterials[m_hPrimitives[closestPrimitive].materialId].refraction; + float refraction = + back ? 1.f + : m_hMaterials[m_hPrimitives[closestPrimitive] + .materialId] + .refraction; // Actual refraction Vertex O_E; @@ -1741,18 +1986,26 @@ FLOAT4 CPUKernel::launchRay(const Ray &ray, Vertex &intersection, float &depthOf O_E.y = rayOrigin.origin.y - closestIntersection.y; O_E.z = rayOrigin.origin.z - closestIntersection.z; O_E = normalize(O_E); - vectorRefraction(rayOrigin.direction, O_E, refraction, normal, initialRefraction); + vectorRefraction(rayOrigin.direction, O_E, refraction, normal, + initialRefraction); - reflectedTarget.x = closestIntersection.x - rayOrigin.direction.x; - reflectedTarget.y = closestIntersection.y - rayOrigin.direction.y; - reflectedTarget.z = closestIntersection.z - rayOrigin.direction.z; + reflectedTarget.x = + closestIntersection.x - rayOrigin.direction.x; + reflectedTarget.y = + closestIntersection.y - rayOrigin.direction.y; + reflectedTarget.z = + closestIntersection.z - rayOrigin.direction.z; - colorContributions[iteration] = m_hMaterials[m_hPrimitives[closestPrimitive].materialId].transparency; + colorContributions[iteration] = + m_hMaterials[m_hPrimitives[closestPrimitive].materialId] + .transparency; // Prepare next ray initialRefraction = refraction; - if (reflectedRays == -1 && m_hMaterials[m_hPrimitives[closestPrimitive].materialId].reflection != 0.f) + if (reflectedRays == -1 && + m_hMaterials[m_hPrimitives[closestPrimitive].materialId] + .reflection != 0.f) { vectorReflection(reflectedRay.direction, O_E, normal); Vertex rt; @@ -1760,12 +2013,17 @@ FLOAT4 CPUKernel::launchRay(const Ray &ray, Vertex &intersection, float &depthOf rt.y = closestIntersection.y - reflectedRay.direction.y; rt.z = closestIntersection.z - reflectedRay.direction.z; - reflectedRay.origin.x = closestIntersection.x + rt.x * 0.00001f; - reflectedRay.origin.y = closestIntersection.y + rt.y * 0.00001f; - reflectedRay.origin.z = closestIntersection.z + rt.z * 0.00001f; + reflectedRay.origin.x = + closestIntersection.x + rt.x * 0.00001f; + reflectedRay.origin.y = + closestIntersection.y + rt.y * 0.00001f; + reflectedRay.origin.z = + closestIntersection.z + rt.z * 0.00001f; reflectedRay.direction = rt; - reflectedRatio = m_hMaterials[m_hPrimitives[closestPrimitive].materialId].reflection; + reflectedRatio = + m_hMaterials[m_hPrimitives[closestPrimitive].materialId] + .reflection; reflectedRays = iteration; } } @@ -1774,7 +2032,8 @@ FLOAT4 CPUKernel::launchRay(const Ray &ray, Vertex &intersection, float &depthOf // ---------- // Reflection // ---------- - if (m_hMaterials[m_hPrimitives[closestPrimitive].materialId].reflection != 0.f) + if (m_hMaterials[m_hPrimitives[closestPrimitive].materialId] + .reflection != 0.f) { Vertex O_E; O_E.x = rayOrigin.origin.x - closestIntersection.x; @@ -1782,10 +2041,15 @@ FLOAT4 CPUKernel::launchRay(const Ray &ray, Vertex &intersection, float &depthOf O_E.z = rayOrigin.origin.z - closestIntersection.z; vectorReflection(rayOrigin.direction, O_E, normal); - reflectedTarget.x = closestIntersection.x - rayOrigin.direction.x; - reflectedTarget.y = closestIntersection.y - rayOrigin.direction.y; - reflectedTarget.z = closestIntersection.z - rayOrigin.direction.z; - colorContributions[iteration] = m_hMaterials[m_hPrimitives[closestPrimitive].materialId].reflection; + reflectedTarget.x = + closestIntersection.x - rayOrigin.direction.x; + reflectedTarget.y = + closestIntersection.y - rayOrigin.direction.y; + reflectedTarget.z = + closestIntersection.z - rayOrigin.direction.z; + colorContributions[iteration] = + m_hMaterials[m_hPrimitives[closestPrimitive].materialId] + .reflection; } else { @@ -1799,19 +2063,30 @@ FLOAT4 CPUKernel::launchRay(const Ray &ray, Vertex &intersection, float &depthOf recursiveBlinn.y += rBlinn.y; recursiveBlinn.z += rBlinn.z; - rayOrigin.origin.x = closestIntersection.x + reflectedTarget.x * 0.00001f; - rayOrigin.origin.y = closestIntersection.y + reflectedTarget.y * 0.00001f; - rayOrigin.origin.z = closestIntersection.z + reflectedTarget.z * 0.00001f; + rayOrigin.origin.x = + closestIntersection.x + reflectedTarget.x * 0.00001f; + rayOrigin.origin.y = + closestIntersection.y + reflectedTarget.y * 0.00001f; + rayOrigin.origin.z = + closestIntersection.z + reflectedTarget.z * 0.00001f; rayOrigin.direction = reflectedTarget; // Noise management if (m_sceneInfo.pathTracingIteration != 0 && - m_hMaterials[m_hPrimitives[closestPrimitive].materialId].color.w != 0.f) + m_hMaterials[m_hPrimitives[closestPrimitive].materialId] + .color.w != 0.f) { // Randomize view - float ratio = m_hMaterials[m_hPrimitives[closestPrimitive].materialId].color.w; - ratio *= (m_hMaterials[m_hPrimitives[closestPrimitive].materialId].transparency == 0.f) ? 1000.f : 1.f; - int rindex = 3 * m_sceneInfo.misc.y + m_sceneInfo.pathTracingIteration; + float ratio = + m_hMaterials[m_hPrimitives[closestPrimitive].materialId] + .color.w; + ratio *= + (m_hMaterials[m_hPrimitives[closestPrimitive].materialId] + .transparency == 0.f) + ? 1000.f + : 1.f; + int rindex = + 3 * m_sceneInfo.misc.y + m_sceneInfo.pathTracingIteration; rindex = rindex % (m_sceneInfo.size.x * m_sceneInfo.size.y); rayOrigin.direction.x += m_hRandoms[rindex] * ratio; rayOrigin.direction.y += m_hRandoms[rindex + 1] * ratio; @@ -1846,17 +2121,23 @@ FLOAT4 CPUKernel::launchRay(const Ray &ray, Vertex &intersection, float &depthOf pathTracingInformationSize = iteration; } - if (m_sceneInfo.graphicsLevel >= 3 && reflectedRays != -1) // TODO: Draft mode should only test - // "m_sceneInfo.pathTracingIteration==iteration" + if (m_sceneInfo.graphicsLevel >= 3 && + reflectedRays != -1) // TODO: Draft mode should only test + // "m_sceneInfo.pathTracingIteration==iteration" { Vertex areas = {0.f, 0.f, 0.f}; // TODO: Dodgy implementation - if (intersectionWithPrimitives(reflectedRay, reflectedRays, closestPrimitive, closestIntersection, normal, - areas, colorBox, back, currentMaterialId)) + if (intersectionWithPrimitives(reflectedRay, reflectedRays, + closestPrimitive, closestIntersection, + normal, areas, colorBox, back, + currentMaterialId)) { - FLOAT4 color = primitiveShader(reflectedRay.origin, normal, closestPrimitive, closestIntersection, areas, - reflectedRays, refractionFromColor, shadowIntensity, rBlinn, - pathTracingInformation, pathTracingInformationSize, isLightRay); + FLOAT4 color = + primitiveShader(reflectedRay.origin, normal, closestPrimitive, + closestIntersection, areas, reflectedRays, + refractionFromColor, shadowIntensity, rBlinn, + pathTracingInformation, + pathTracingInformationSize, isLightRay); colors[reflectedRays].x += color.x * reflectedRatio; colors[reflectedRays].y += color.y * reflectedRatio; @@ -1868,9 +2149,12 @@ FLOAT4 CPUKernel::launchRay(const Ray &ray, Vertex &intersection, float &depthOf { for (int i = iteration - 2; i >= 0; --i) { - colors[i].x = colors[i].x * (1.f - colorContributions[i]) + colors[i + 1].x * colorContributions[i]; - colors[i].y = colors[i].y * (1.f - colorContributions[i]) + colors[i + 1].y * colorContributions[i]; - colors[i].z = colors[i].z * (1.f - colorContributions[i]) + colors[i + 1].z * colorContributions[i]; + colors[i].x = colors[i].x * (1.f - colorContributions[i]) + + colors[i + 1].x * colorContributions[i]; + colors[i].y = colors[i].y * (1.f - colorContributions[i]) + + colors[i + 1].y * colorContributions[i]; + colors[i].z = colors[i].z * (1.f - colorContributions[i]) + + colors[i + 1].z * colorContributions[i]; } intersectionColor = colors[0]; intersectionColor.x += recursiveBlinn.x; @@ -1891,15 +2175,25 @@ FLOAT4 CPUKernel::launchRay(const Ray &ray, Vertex &intersection, float &depthOf // -------------------------------------------------- // Photon energy // -------------------------------------------------- - intersectionColor.x *= (photonDistance > 0.f) ? (photonDistance / m_sceneInfo.viewDistance) : 0.f; - intersectionColor.y *= (photonDistance > 0.f) ? (photonDistance / m_sceneInfo.viewDistance) : 0.f; - intersectionColor.z *= (photonDistance > 0.f) ? (photonDistance / m_sceneInfo.viewDistance) : 0.f; + intersectionColor.x *= + (photonDistance > 0.f) + ? (photonDistance / m_sceneInfo.viewDistance) + : 0.f; + intersectionColor.y *= + (photonDistance > 0.f) + ? (photonDistance / m_sceneInfo.viewDistance) + : 0.f; + intersectionColor.z *= + (photonDistance > 0.f) + ? (photonDistance / m_sceneInfo.viewDistance) + : 0.f; #endif // PHOTON_ENERGY // -------------------------------------------------- // Fog // -------------------------------------------------- - // intersectionColor += m_hRandoms[((int)len + m_sceneInfo.misc.y)%100]; + // intersectionColor += m_hRandoms[((int)len + + // m_sceneInfo.misc.y)%100]; // -------------------------------------------------- // Background color @@ -1910,9 +2204,12 @@ FLOAT4 CPUKernel::launchRay(const Ray &ray, Vertex &intersection, float &depthOf float D2 = m_sceneInfo.viewDistance * 0.05f; float a = len - D1; float b = 1.f - (a / D2); - intersectionColor.x = intersectionColor.x * b + m_sceneInfo.backgroundColor.x * (1.f - b); - intersectionColor.y = intersectionColor.y * b + m_sceneInfo.backgroundColor.y * (1.f - b); - intersectionColor.z = intersectionColor.z * b + m_sceneInfo.backgroundColor.z * (1.f - b); + intersectionColor.x = intersectionColor.x * b + + m_sceneInfo.backgroundColor.x * (1.f - b); + intersectionColor.y = intersectionColor.y * b + + m_sceneInfo.backgroundColor.y * (1.f - b); + intersectionColor.z = intersectionColor.z * b + + m_sceneInfo.backgroundColor.z * (1.f - b); } } depthOfField = (len - depthOfField) / m_sceneInfo.viewDistance; @@ -1958,7 +2255,8 @@ void CPUKernel::k_standardRenderer() Vertex rotationCenter = {0.f, 0.f, 0.f}; bool antialiasingActivated = (m_sceneInfo.misc.w == 2); - bool pathTracing(m_sceneInfo.pathTracingIteration >= NB_MAX_ITERATIONS && + bool pathTracing(m_sceneInfo.pathTracingIteration >= + NB_MAX_ITERATIONS && m_sceneInfo.pathTracingIteration % 2 == 0); if (m_sceneInfo.pathTracingIteration == 0) @@ -1976,22 +2274,29 @@ void CPUKernel::k_standardRenderer() lightRay.origin = m_lightInformation[0].location; lightRay.direction = lightRay.origin; - int rindex = 3 * (index + m_sceneInfo.pathTracingIteration + m_sceneInfo.misc.y); - rindex = rindex % (m_sceneInfo.size.x * m_sceneInfo.size.y - 3); - lightRay.direction.x += 1000.f * m_hRandoms[rindex] * m_postProcessingInfo.param1; - lightRay.direction.y += 1000.f * m_hRandoms[rindex + 1] * m_postProcessingInfo.param1; - lightRay.direction.z += 1000.f * m_hRandoms[rindex + 2] * m_postProcessingInfo.param1; + int rindex = 3 * (index + m_sceneInfo.pathTracingIteration + + m_sceneInfo.misc.y); + rindex = + rindex % (m_sceneInfo.size.x * m_sceneInfo.size.y - 3); + lightRay.direction.x += 1000.f * m_hRandoms[rindex] * + m_postProcessingInfo.param1; + lightRay.direction.y += 1000.f * m_hRandoms[rindex + 1] * + m_postProcessingInfo.param1; + lightRay.direction.z += 1000.f * m_hRandoms[rindex + 2] * + m_postProcessingInfo.param1; // Launch light ray - launchRay(lightRay, intersection, dof, m_hPrimitivesXYIds[index], pathTracingInformation, + launchRay(lightRay, intersection, dof, + m_hPrimitivesXYIds[index], pathTracingInformation, pathTracingInformationSize, true); } /* // Path Tracing int rindex = 3*(index+m_sceneInfo.misc.y) + 5000; - rindex = rindex%(m_sceneInfo.size.x*m_sceneInfo.size.y-3); - ray.origin.x += m_hRandoms[rindex + rindex = + rindex%(m_sceneInfo.size.x*m_sceneInfo.size.y-3); ray.origin.x + += m_hRandoms[rindex ]*m_postProcessingBuffer[index].w*m_postProcessingInfo.param1; ray.origin.y += m_hRandoms[rindex+1]*m_postProcessingBuffer[index].w*m_postProcessingInfo.param1; @@ -1999,7 +2304,8 @@ void CPUKernel::k_standardRenderer() m_hRandoms[rindex+2]*m_postProcessingBuffer[index].w*m_postProcessingInfo.param1; rindex = 3*(index+m_sceneInfo.misc.y); - rindex = rindex%(m_sceneInfo.size.x*m_sceneInfo.size.y-3); + rindex = + rindex%(m_sceneInfo.size.x*m_sceneInfo.size.y-3); ray.direction.x += m_hRandoms[rindex ]*m_postProcessingBuffer[index].w*m_postProcessingInfo.param1; ray.direction.y += @@ -2013,29 +2319,41 @@ void CPUKernel::k_standardRenderer() { if (m_sceneInfo.misc.w == 1) // Isometric 3D { - ray.direction.x = ray.origin.z * 0.001f * (float)(x - (m_sceneInfo.size.x / 2)); - ray.direction.y = -ray.origin.z * 0.001f * (float)(y - (m_sceneInfo.size.y / 2)); + ray.direction.x = ray.origin.z * 0.001f * + (float)(x - (m_sceneInfo.size.x / 2)); + ray.direction.y = -ray.origin.z * 0.001f * + (float)(y - (m_sceneInfo.size.y / 2)); ray.origin.x = ray.direction.x; ray.origin.y = ray.direction.y; } else { - float ratio = (float)m_sceneInfo.size.x / (float)m_sceneInfo.size.y; + float ratio = + (float)m_sceneInfo.size.x / (float)m_sceneInfo.size.y; FLOAT2 step; step.x = ratio * 6400.f / (float)m_sceneInfo.size.x; step.y = 6400.f / (float)m_sceneInfo.size.y; - ray.direction.x = ray.direction.x - step.x * (float)(x - (m_sceneInfo.size.x / 2)); - ray.direction.y = ray.direction.y + step.y * (float)(y - (m_sceneInfo.size.y / 2)); + ray.direction.x = + ray.direction.x - + step.x * (float)(x - (m_sceneInfo.size.x / 2)); + ray.direction.y = + ray.direction.y + + step.y * (float)(y - (m_sceneInfo.size.y / 2)); } vectorRotation(ray.origin, rotationCenter, m_angles); vectorRotation(ray.direction, rotationCenter, m_angles); } // Antialisazing - FLOAT2 AArotatedGrid[4] = {{3.f, 5.f}, {5.f, -3.f}, {-3.f, -5.f}, {-5.f, 3.f}}; - - if (m_sceneInfo.pathTracingIteration > m_hPrimitivesXYIds[index].y && - m_sceneInfo.pathTracingIteration > 0 && m_sceneInfo.pathTracingIteration <= NB_MAX_ITERATIONS) + FLOAT2 AArotatedGrid[4] = {{3.f, 5.f}, + {5.f, -3.f}, + {-3.f, -5.f}, + {-5.f, 3.f}}; + + if (m_sceneInfo.pathTracingIteration > + m_hPrimitivesXYIds[index].y && + m_sceneInfo.pathTracingIteration > 0 && + m_sceneInfo.pathTracingIteration <= NB_MAX_ITERATIONS) break; FLOAT4 color = {0.f, 0.f, 0.f, 0.f}; @@ -2046,7 +2364,9 @@ void CPUKernel::k_standardRenderer() { r.direction.x = ray.origin.x + AArotatedGrid[I].x; r.direction.y = ray.origin.y + AArotatedGrid[I].y; - FLOAT4 c = launchRay(r, intersection, dof, m_hPrimitivesXYIds[index], pathTracingInformation, + FLOAT4 c = launchRay(r, intersection, dof, + m_hPrimitivesXYIds[index], + pathTracingInformation, pathTracingInformationSize); color.x += c.x; color.y += c.y; @@ -2055,8 +2375,9 @@ void CPUKernel::k_standardRenderer() } // Launch Eye Ray - FLOAT4 c = launchRay(ray, intersection, dof, m_hPrimitivesXYIds[index], pathTracingInformation, - pathTracingInformationSize); + FLOAT4 c = + launchRay(ray, intersection, dof, m_hPrimitivesXYIds[index], + pathTracingInformation, pathTracingInformationSize); color.x += c.x; color.y += c.y; @@ -2156,7 +2477,8 @@ void CPUKernel::k_fishEyeRenderer() // Normal Y axis FLOAT2 step; step.y = 6400.f / (float)m_sceneInfo.size.y; - ray.origin.y = ray.origin.y + step.y * (float)(y - (m_sceneInfo.size.y / 2)); + ray.origin.y = + ray.origin.y + step.y * (float)(y - (m_sceneInfo.size.y / 2)); // 360° X axis step.x = 2.f * PI / static_cast(m_sceneInfo.size.x); @@ -2171,14 +2493,17 @@ void CPUKernel::k_fishEyeRenderer() // vectorRotation( ray.origin, rotationCenter, m_angles ); // vectorRotation( ray.direction, rotationCenter, m_angles ); - if (m_sceneInfo.pathTracingIteration > m_hPrimitivesXYIds[index].y && - m_sceneInfo.pathTracingIteration > 0 && m_sceneInfo.pathTracingIteration <= NB_MAX_ITERATIONS) + if (m_sceneInfo.pathTracingIteration > + m_hPrimitivesXYIds[index].y && + m_sceneInfo.pathTracingIteration > 0 && + m_sceneInfo.pathTracingIteration <= NB_MAX_ITERATIONS) break; LightInformation pathTracingInformation[NB_MAX_ITERATIONS]; int pathTracingInformationSize = 0; - color = launchRay(ray, intersection, dof, m_hPrimitivesXYIds[index], pathTracingInformation, - pathTracingInformationSize); + color = + launchRay(ray, intersection, dof, m_hPrimitivesXYIds[index], + pathTracingInformation, pathTracingInformationSize); if (m_sceneInfo.pathTracingIteration == 0) { @@ -2240,8 +2565,10 @@ void CPUKernel::k_anaglyphRenderer() eyeRay.origin.y = m_viewPos.y; eyeRay.origin.z = m_viewPos.z; - eyeRay.direction.x = m_viewDir.x - step.x * (float)(x - (m_sceneInfo.size.x / 2)); - eyeRay.direction.y = m_viewDir.y + step.y * (float)(y - (m_sceneInfo.size.y / 2)); + eyeRay.direction.x = + m_viewDir.x - step.x * (float)(x - (m_sceneInfo.size.x / 2)); + eyeRay.direction.y = + m_viewDir.y + step.y * (float)(y - (m_sceneInfo.size.y / 2)); eyeRay.direction.z = m_viewDir.z; vectorRotation(eyeRay.origin, rotationCenter, m_angles); @@ -2249,24 +2576,29 @@ void CPUKernel::k_anaglyphRenderer() LightInformation pathTracingInformation[NB_MAX_ITERATIONS]; int pathTracingInformationSize = 0; - FLOAT4 colorLeft = launchRay(eyeRay, intersection, dof, m_hPrimitivesXYIds[index], pathTracingInformation, - pathTracingInformationSize); + FLOAT4 colorLeft = + launchRay(eyeRay, intersection, dof, m_hPrimitivesXYIds[index], + pathTracingInformation, pathTracingInformationSize); // Right eye eyeRay.origin.x = m_viewPos.x - m_sceneInfo.width3DVision; eyeRay.origin.y = m_viewPos.y; eyeRay.origin.z = m_viewPos.z; - eyeRay.direction.x = m_viewDir.x - step.x * (float)(x - (m_sceneInfo.size.x / 2)); - eyeRay.direction.y = m_viewDir.y + step.y * (float)(y - (m_sceneInfo.size.y / 2)); + eyeRay.direction.x = + m_viewDir.x - step.x * (float)(x - (m_sceneInfo.size.x / 2)); + eyeRay.direction.y = + m_viewDir.y + step.y * (float)(y - (m_sceneInfo.size.y / 2)); eyeRay.direction.z = m_viewDir.z; vectorRotation(eyeRay.origin, rotationCenter, m_angles); vectorRotation(eyeRay.direction, rotationCenter, m_angles); - FLOAT4 colorRight = launchRay(eyeRay, intersection, dof, m_hPrimitivesXYIds[index], pathTracingInformation, - pathTracingInformationSize); + FLOAT4 colorRight = + launchRay(eyeRay, intersection, dof, m_hPrimitivesXYIds[index], + pathTracingInformation, pathTracingInformationSize); - float r1 = colorLeft.x * 0.299f + colorLeft.y * 0.587f + colorLeft.z * 0.114f; + float r1 = colorLeft.x * 0.299f + colorLeft.y * 0.587f + + colorLeft.z * 0.114f; float b1 = 0.f; float g1 = 0.f; @@ -2335,8 +2667,13 @@ void CPUKernel::k_3DVisionRenderer() eyeRay.origin.y = m_viewPos.y; eyeRay.origin.z = m_viewPos.z; - eyeRay.direction.x = m_viewDir.x - step.x * (float)(x - (m_sceneInfo.size.x / 2) + halfWidth / 2); - eyeRay.direction.y = m_viewDir.y + step.y * (float)(y - (m_sceneInfo.size.y / 2)); + eyeRay.direction.x = + m_viewDir.x - + step.x * + (float)(x - (m_sceneInfo.size.x / 2) + halfWidth / 2); + eyeRay.direction.y = + m_viewDir.y + + step.y * (float)(y - (m_sceneInfo.size.y / 2)); eyeRay.direction.z = m_viewDir.z; } else @@ -2346,8 +2683,13 @@ void CPUKernel::k_3DVisionRenderer() eyeRay.origin.y = m_viewPos.y; eyeRay.origin.z = m_viewPos.z; - eyeRay.direction.x = m_viewDir.x - step.x * (float)(x - (m_sceneInfo.size.x / 2) - halfWidth / 2); - eyeRay.direction.y = m_viewDir.y + step.y * (float)(y - (m_sceneInfo.size.y / 2)); + eyeRay.direction.x = + m_viewDir.x - + step.x * + (float)(x - (m_sceneInfo.size.x / 2) - halfWidth / 2); + eyeRay.direction.y = + m_viewDir.y + + step.y * (float)(y - (m_sceneInfo.size.y / 2)); eyeRay.direction.z = m_viewDir.z; } @@ -2356,8 +2698,9 @@ void CPUKernel::k_3DVisionRenderer() LightInformation pathTracingInformation[NB_MAX_ITERATIONS]; int pathTracingInformationSize = 0; - FLOAT4 color = launchRay(eyeRay, intersection, dof, m_hPrimitivesXYIds[index], pathTracingInformation, - pathTracingInformationSize); + FLOAT4 color = + launchRay(eyeRay, intersection, dof, m_hPrimitivesXYIds[index], + pathTracingInformation, pathTracingInformationSize); if (m_sceneInfo.pathTracingIteration == 0) m_postProcessingBuffer[index].w = dof; @@ -2396,9 +2739,12 @@ void CPUKernel::k_default() if (m_sceneInfo.pathTracingIteration > NB_MAX_ITERATIONS) { - localColor.x /= (float)(m_sceneInfo.pathTracingIteration - NB_MAX_ITERATIONS + 1); - localColor.y /= (float)(m_sceneInfo.pathTracingIteration - NB_MAX_ITERATIONS + 1); - localColor.z /= (float)(m_sceneInfo.pathTracingIteration - NB_MAX_ITERATIONS + 1); + localColor.x /= (float)(m_sceneInfo.pathTracingIteration - + NB_MAX_ITERATIONS + 1); + localColor.y /= (float)(m_sceneInfo.pathTracingIteration - + NB_MAX_ITERATIONS + 1); + localColor.z /= (float)(m_sceneInfo.pathTracingIteration - + NB_MAX_ITERATIONS + 1); } makeColor(localColor, index); @@ -2421,7 +2767,8 @@ void CPUKernel::k_depthOfField() for (int y(0); y < m_sceneInfo.size.y; ++y) { int index = y * m_sceneInfo.size.x + x; - float depth = m_postProcessingInfo.param2 * m_postProcessingBuffer[index].w; + float depth = + m_postProcessingInfo.param2 * m_postProcessingBuffer[index].w; int wh = m_sceneInfo.size.x * m_sceneInfo.size.y; FLOAT4 localColor = {0.f, 0.f, 0.f}; @@ -2431,7 +2778,8 @@ void CPUKernel::k_depthOfField() int iy = (i + m_sceneInfo.size.x) % wh; int xx = x + static_cast(depth * m_hRandoms[ix] * 0.5f); int yy = y + static_cast(depth * m_hRandoms[iy] * 0.5f); - if (xx >= 0 && xx < m_sceneInfo.size.x && yy >= 0 && yy < m_sceneInfo.size.y) + if (xx >= 0 && xx < m_sceneInfo.size.x && yy >= 0 && + yy < m_sceneInfo.size.y) { int localIndex = yy * m_sceneInfo.size.x + xx; if (localIndex >= 0 && localIndex < wh) @@ -2454,9 +2802,12 @@ void CPUKernel::k_depthOfField() if (m_sceneInfo.pathTracingIteration > NB_MAX_ITERATIONS) { - localColor.x /= (float)(m_sceneInfo.pathTracingIteration - NB_MAX_ITERATIONS + 1); - localColor.y /= (float)(m_sceneInfo.pathTracingIteration - NB_MAX_ITERATIONS + 1); - localColor.z /= (float)(m_sceneInfo.pathTracingIteration - NB_MAX_ITERATIONS + 1); + localColor.x /= (float)(m_sceneInfo.pathTracingIteration - + NB_MAX_ITERATIONS + 1); + localColor.y /= (float)(m_sceneInfo.pathTracingIteration - + NB_MAX_ITERATIONS + 1); + localColor.z /= (float)(m_sceneInfo.pathTracingIteration - + NB_MAX_ITERATIONS + 1); } localColor.w = 1.f; @@ -2492,7 +2843,8 @@ void CPUKernel::k_ambiantOcclusion() { int xx = x + X; int yy = y + Y; - if (xx >= 0 && xx < m_sceneInfo.size.x && yy >= 0 && yy < m_sceneInfo.size.y) + if (xx >= 0 && xx < m_sceneInfo.size.x && yy >= 0 && + yy < m_sceneInfo.size.y) { int localIndex = yy * m_sceneInfo.size.x + xx; if (m_postProcessingBuffer[localIndex].w >= depth) @@ -2513,9 +2865,12 @@ void CPUKernel::k_ambiantOcclusion() if (m_sceneInfo.pathTracingIteration > NB_MAX_ITERATIONS) { - localColor.x /= (float)(m_sceneInfo.pathTracingIteration - NB_MAX_ITERATIONS + 1); - localColor.y /= (float)(m_sceneInfo.pathTracingIteration - NB_MAX_ITERATIONS + 1); - localColor.z /= (float)(m_sceneInfo.pathTracingIteration - NB_MAX_ITERATIONS + 1); + localColor.x /= (float)(m_sceneInfo.pathTracingIteration - + NB_MAX_ITERATIONS + 1); + localColor.y /= (float)(m_sceneInfo.pathTracingIteration - + NB_MAX_ITERATIONS + 1); + localColor.z /= (float)(m_sceneInfo.pathTracingIteration - + NB_MAX_ITERATIONS + 1); } saturateVector(localColor); @@ -2543,29 +2898,41 @@ void CPUKernel::k_radiosity() int index = y * m_sceneInfo.size.x + x; int wh = m_sceneInfo.size.x * m_sceneInfo.size.y; - int div = (m_sceneInfo.pathTracingIteration > NB_MAX_ITERATIONS) - ? (m_sceneInfo.pathTracingIteration - NB_MAX_ITERATIONS + 1) - : 1; + int div = + (m_sceneInfo.pathTracingIteration > NB_MAX_ITERATIONS) + ? (m_sceneInfo.pathTracingIteration - NB_MAX_ITERATIONS + 1) + : 1; FLOAT4 localColor = {0.f, 0.f, 0.f}; for (int i = 0; i < m_postProcessingInfo.param3; ++i) { int ix = (i + m_sceneInfo.pathTracingIteration) % wh; int iy = (i + m_sceneInfo.size.x) % wh; - int xx = x + static_cast(m_hRandoms[ix] * m_postProcessingInfo.param2 / 10.f); - int yy = y + static_cast(m_hRandoms[iy] * m_postProcessingInfo.param2 / 10.f); + int xx = + x + static_cast(m_hRandoms[ix] * + m_postProcessingInfo.param2 / 10.f); + int yy = + y + static_cast(m_hRandoms[iy] * + m_postProcessingInfo.param2 / 10.f); localColor.x += m_postProcessingBuffer[index].x; localColor.y += m_postProcessingBuffer[index].y; localColor.z += m_postProcessingBuffer[index].z; - if (xx >= 0 && xx < m_sceneInfo.size.x && yy >= 0 && yy < m_sceneInfo.size.y) + if (xx >= 0 && xx < m_sceneInfo.size.x && yy >= 0 && + yy < m_sceneInfo.size.y) { int localIndex = yy * m_sceneInfo.size.x + xx; localColor.x += - (localIndex >= 0 && localIndex < wh) ? div * m_hPrimitivesXYIds[localIndex].z / 255 : 0.f; + (localIndex >= 0 && localIndex < wh) + ? div * m_hPrimitivesXYIds[localIndex].z / 255 + : 0.f; localColor.y += - (localIndex >= 0 && localIndex < wh) ? div * m_hPrimitivesXYIds[localIndex].z / 255 : 0.f; + (localIndex >= 0 && localIndex < wh) + ? div * m_hPrimitivesXYIds[localIndex].z / 255 + : 0.f; localColor.z += - (localIndex >= 0 && localIndex < wh) ? div * m_hPrimitivesXYIds[localIndex].z / 255 : 0.f; + (localIndex >= 0 && localIndex < wh) + ? div * m_hPrimitivesXYIds[localIndex].z / 255 + : 0.f; } } localColor.x /= m_postProcessingInfo.param3; @@ -2589,9 +2956,7 @@ ________________________________________________________________________________ Post Processing Effect: Radiosity ________________________________________________________________________________ */ -void CPUKernel::k_oneColor() -{ -} +void CPUKernel::k_oneColor() {} /* ________________________________________________________________________________ @@ -2603,7 +2968,8 @@ void CPUKernel::render_begin(const float timer) GPUKernel::render_begin(timer); if (m_postProcessingBuffer == 0) { - m_postProcessingBuffer = new FLOAT4[m_sceneInfo.size.x * m_sceneInfo.size.y]; + m_postProcessingBuffer = + new FLOAT4[m_sceneInfo.size.x * m_sceneInfo.size.y]; } switch (m_sceneInfo.renderingType) @@ -2651,7 +3017,8 @@ void CPUKernel::render_end() ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); ::glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); - ::glTexImage2D(GL_TEXTURE_2D, 0, 3, m_sceneInfo.size.x, m_sceneInfo.size.y, 0, GL_RGB, GL_UNSIGNED_BYTE, + ::glTexImage2D(GL_TEXTURE_2D, 0, 3, m_sceneInfo.size.x, + m_sceneInfo.size.y, 0, GL_RGB, GL_UNSIGNED_BYTE, m_bitmap); ::glBegin(GL_QUADS); ::glTexCoord2f(1.f, 1.f); @@ -2666,4 +3033,4 @@ void CPUKernel::render_end() ::glDisable(GL_TEXTURE_2D); } } -} +} // namespace solr diff --git a/solr/engines/cpu/CPUKernel.h b/solr/engines/cpu/CPUKernel.h index ad594e3..c47613b 100644 --- a/solr/engines/cpu/CPUKernel.h +++ b/solr/engines/cpu/CPUKernel.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once @@ -43,53 +40,77 @@ class SOLR_API CPUKernel : public GPUKernel float dot(const Vertex &v1, const Vertex &v2); Vertex normalize(const Vertex &v); void vectorReflection(Vertex &r, const Vertex &i, const Vertex &n); - void vectorRefraction(Vertex &refracted, const Vertex incident, const float n1, const Vertex normal, - const float n2); - void vectorRotation(Vertex &v, const Vertex &rotationCenter, const Vertex &angles); + void vectorRefraction(Vertex &refracted, const Vertex incident, + const float n1, const Vertex normal, const float n2); + void vectorRotation(Vertex &v, const Vertex &rotationCenter, + const Vertex &angles); protected: void computeRayAttributes(Ray &ray); // Texture mapping - void juliaSet(const Primitive &primitive, const float x, const float y, FLOAT4 &color); - void mandelbrotSet(const Primitive &primitive, const float x, const float y, FLOAT4 &color); - FLOAT4 sphereUVMapping(const Primitive &primitive, const Vertex &intersection); - FLOAT4 triangleUVMapping(const Primitive &primitive, const Vertex &intersection, const Vertex &areas); + void juliaSet(const Primitive &primitive, const float x, const float y, + FLOAT4 &color); + void mandelbrotSet(const Primitive &primitive, const float x, const float y, + FLOAT4 &color); + FLOAT4 sphereUVMapping(const Primitive &primitive, + const Vertex &intersection); + FLOAT4 triangleUVMapping(const Primitive &primitive, + const Vertex &intersection, const Vertex &areas); FLOAT4 cubeMapping(const Primitive &primitive, const Vertex &intersection); - bool wireFrameMapping(float x, float y, int width, const Primitive &primitive); + bool wireFrameMapping(float x, float y, int width, + const Primitive &primitive); protected: // Intersections - bool boxIntersection(const BoundingBox &box, const Ray &ray, const float &t0, const float &t1); - bool ellipsoidIntersection(const Primitive &ellipsoid, const Ray &ray, Vertex &intersection, Vertex &normal, + bool boxIntersection(const BoundingBox &box, const Ray &ray, + const float &t0, const float &t1); + bool ellipsoidIntersection(const Primitive &ellipsoid, const Ray &ray, + Vertex &intersection, Vertex &normal, float &shadowIntensity, bool &back); - bool sphereIntersection(const Primitive &sphere, const Ray &ray, Vertex &intersection, Vertex &normal, + bool sphereIntersection(const Primitive &sphere, const Ray &ray, + Vertex &intersection, Vertex &normal, float &shadowIntensity, bool &back); - bool cylinderIntersection(const Primitive &cylinder, const Ray &ray, Vertex &intersection, Vertex &normal, + bool cylinderIntersection(const Primitive &cylinder, const Ray &ray, + Vertex &intersection, Vertex &normal, float &shadowIntensity, bool &back); - bool planeIntersection(const Primitive &primitive, const Ray &ray, Vertex &intersection, Vertex &normal, + bool planeIntersection(const Primitive &primitive, const Ray &ray, + Vertex &intersection, Vertex &normal, float &shadowIntensity, bool reverse); - bool triangleIntersection(const Primitive &triangle, const Ray &ray, Vertex &intersection, Vertex &normal, - Vertex &areas, float &shadowIntensity, bool &back); - bool intersectionWithPrimitives(const Ray &ray, const int &iteration, int &closestPrimitive, - Vertex &closestIntersection, Vertex &closestNormal, Vertex &closestAreas, - FLOAT4 &colorBox, bool &back, const int currentMaterialId); + bool triangleIntersection(const Primitive &triangle, const Ray &ray, + Vertex &intersection, Vertex &normal, + Vertex &areas, float &shadowIntensity, + bool &back); + bool intersectionWithPrimitives(const Ray &ray, const int &iteration, + int &closestPrimitive, + Vertex &closestIntersection, + Vertex &closestNormal, Vertex &closestAreas, + FLOAT4 &colorBox, bool &back, + const int currentMaterialId); protected: // Color management void makeColor(FLOAT4 &color, int index); - float processShadows(const Vertex &lampCenter, const Vertex &origin, const int &objectId, const int &iteration, + float processShadows(const Vertex &lampCenter, const Vertex &origin, + const int &objectId, const int &iteration, FLOAT4 &color); - FLOAT4 intersectionShader(const Primitive &primitive, const Vertex &intersection, const Vertex &areas); - FLOAT4 primitiveShader(const Vertex &origin, const Vertex &normal, const int &objectId, const Vertex &intersection, - const Vertex &areas, const int &iteration, FLOAT4 &refractionFromColor, - float &shadowIntensity, FLOAT4 &totalBlinn, LightInformation *pathTracingInformation, - const int pathTracingInformationSize, const bool isLightRay); + FLOAT4 intersectionShader(const Primitive &primitive, + const Vertex &intersection, const Vertex &areas); + FLOAT4 primitiveShader(const Vertex &origin, const Vertex &normal, + const int &objectId, const Vertex &intersection, + const Vertex &areas, const int &iteration, + FLOAT4 &refractionFromColor, float &shadowIntensity, + FLOAT4 &totalBlinn, + LightInformation *pathTracingInformation, + const int pathTracingInformationSize, + const bool isLightRay); protected: // Rays - FLOAT4 launchRay(const Ray &ray, Vertex &intersection, float &depthOfField, INT4 &primitiveXYId, - LightInformation *pathTracingInformation, int &pathTracingInformationSize, + FLOAT4 launchRay(const Ray &ray, Vertex &intersection, float &depthOfField, + INT4 &primitiveXYId, + LightInformation *pathTracingInformation, + int &pathTracingInformationSize, const bool lightRay = false); protected: @@ -107,4 +128,4 @@ class SOLR_API CPUKernel : public GPUKernel private: FLOAT4 *m_postProcessingBuffer; }; -} +} // namespace solr diff --git a/solr/engines/cuda/CudaKernel.cpp b/solr/engines/cuda/CudaKernel.cpp index 644748d..ced7a52 100644 --- a/solr/engines/cuda/CudaKernel.cpp +++ b/solr/engines/cuda/CudaKernel.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau - * - * This file is part of Sol-R +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #define _ALLOW_KEYWORD_MACROS @@ -26,19 +23,21 @@ #include #endif -#include -#include #include "CudaKernel.h" #include "CudaRayTracer.h" +#include + +#include +#include #ifdef WIN32 #include #else -#include #include #include #include #include +#include #include #include #include @@ -94,9 +93,12 @@ CudaKernel::CudaKernel() #ifdef LOGGING // Initialize Log - LOG_INITIALIZE_ETW(&GPU_CudaRAYTRACERMODULE, &GPU_CudaRAYTRACERMODULE_EVENT_DEBUG, - &GPU_CudaRAYTRACERMODULE_EVENT_VERBOSE, &GPU_CudaRAYTRACERMODULE_EVENT_INFO, - &GPU_CudaRAYTRACERMODULE_EVENT_WARNING, &GPU_CudaRAYTRACERMODULE_EVENT_ERROR); + LOG_INITIALIZE_ETW(&GPU_CudaRAYTRACERMODULE, + &GPU_CudaRAYTRACERMODULE_EVENT_DEBUG, + &GPU_CudaRAYTRACERMODULE_EVENT_VERBOSE, + &GPU_CudaRAYTRACERMODULE_EVENT_INFO, + &GPU_CudaRAYTRACERMODULE_EVENT_WARNING, + &GPU_CudaRAYTRACERMODULE_EVENT_ERROR); #endif } @@ -135,12 +137,13 @@ ________________________________________________________________________________ void CudaKernel::initializeDevice() { LOG_INFO(3, "CudaKernel::initializeDevice"); - initialize_scene(m_occupancyParameters, m_sceneInfo, NB_MAX_PRIMITIVES, NB_MAX_LAMPS, NB_MAX_MATERIALS + initialize_scene(m_occupancyParameters, m_sceneInfo, NB_MAX_PRIMITIVES, + NB_MAX_LAMPS, NB_MAX_MATERIALS #ifdef USE_MANAGED_MEMORY , m_hBoundingBoxes, m_hPrimitives #endif - ); + ); reshape_scene(m_occupancyParameters, m_sceneInfo); } @@ -162,7 +165,7 @@ void CudaKernel::releaseDevice() , m_hBoundingBoxes, m_hPrimitives #endif - ); + ); } /* @@ -186,32 +189,37 @@ void CudaKernel::render_begin(const float timer) int nbLamps = m_nbActiveLamps[m_frame]; int nbMaterials = m_nbActiveMaterials + 1; - LOG_INFO(3, "Data sizes [" << m_frame << "]: " << nbBoxes << ", " << nbPrimitives << ", " << nbMaterials << ", " - << nbLamps); - LOG_INFO(3, "Pos = " << m_viewPos.x << "," << m_viewPos.y << "," << m_viewPos.z); - LOG_INFO(3, "Dir = " << m_viewDir.x << "," << m_viewDir.y << "," << m_viewDir.z); - LOG_INFO(3, "Ang = " << m_angles.x << "," << m_angles.y << "," << m_angles.z); - LOG_INFO(3, "Min = " << m_minPos[m_frame].x << "," << m_minPos[m_frame].y << "," << m_minPos[m_frame].z); - LOG_INFO(3, "Max = " << m_maxPos[m_frame].x << "," << m_maxPos[m_frame].y << "," << m_maxPos[m_frame].z); + LOG_INFO(3, "Data sizes [" << m_frame << "]: " << nbBoxes << ", " + << nbPrimitives << ", " << nbMaterials + << ", " << nbLamps); + LOG_INFO(3, "Pos = " << m_viewPos.x << "," << m_viewPos.y << "," + << m_viewPos.z); + LOG_INFO(3, "Dir = " << m_viewDir.x << "," << m_viewDir.y << "," + << m_viewDir.z); + LOG_INFO(3, "Ang = " << m_angles.x << "," << m_angles.y << "," + << m_angles.z); + LOG_INFO(3, "Min = " << m_minPos[m_frame].x << "," + << m_minPos[m_frame].y << "," + << m_minPos[m_frame].z); + LOG_INFO(3, "Max = " << m_maxPos[m_frame].x << "," + << m_maxPos[m_frame].y << "," + << m_maxPos[m_frame].z); if (!m_primitivesTransfered) { - LOG_INFO(3, "Transfering " << nbBoxes << " boxes, " << nbPrimitives << " primitives and " << nbLamps + LOG_INFO(3, "Transfering " << nbBoxes << " boxes, " << nbPrimitives + << " primitives and " << nbLamps << " lamps"); - h2d_scene(m_occupancyParameters, m_hBoundingBoxes, nbBoxes, m_hPrimitives, nbPrimitives, m_hLamps, nbLamps); + h2d_scene(m_occupancyParameters, m_hBoundingBoxes, nbBoxes, + m_hPrimitives, nbPrimitives, m_hLamps, nbLamps); - LOG_INFO(3, "Transfering " << m_lightInformationSize << " light elements"); - h2d_lightInformation(m_occupancyParameters, m_lightInformation, m_lightInformationSize); + LOG_INFO(3, "Transfering " << m_lightInformationSize + << " light elements"); + h2d_lightInformation(m_occupancyParameters, m_lightInformation, + m_lightInformationSize); m_primitivesTransfered = true; } - if (!m_randomsTransfered) - { - h2d_randoms(m_occupancyParameters, m_hRandoms); - LOG_INFO(3, "Transfering random numbers"); - m_randomsTransfered = true; - } - if (!m_materialsTransfered) { realignTexturesAndMaterials(); @@ -223,8 +231,9 @@ void CudaKernel::render_begin(const float timer) if (!m_texturesTransfered) { - LOG_INFO(3, "Transfering " << m_nbActiveTextures << " textures, and " << m_lightInformationSize - << " light information"); + LOG_INFO(3, "Transfering " + << m_nbActiveTextures << " textures, and " + << m_lightInformationSize << " light information"); h2d_textures(m_occupancyParameters, NB_MAX_TEXTURES, m_hTextures); m_texturesTransfered = true; } @@ -236,7 +245,8 @@ void CudaKernel::render_begin(const float timer) m_hVideo = 0; const NUI_IMAGE_FRAME *pImageFrame = 0; WaitForSingleObject(m_hNextVideoFrameEvent, INFINITE); - HRESULT status = NuiImageStreamGetNextFrame(m_pVideoStreamHandle, 0, &pImageFrame); + HRESULT status = NuiImageStreamGetNextFrame(m_pVideoStreamHandle, 0, + &pImageFrame); if ((status == S_OK) && pImageFrame) { INuiFrameTexture *pTexture = pImageFrame->pFrameTexture; @@ -252,7 +262,8 @@ void CudaKernel::render_begin(const float timer) m_hDepth = 0; const NUI_IMAGE_FRAME *pDepthFrame = 0; WaitForSingleObject(m_hNextDepthFrameEvent, INFINITE); - status = NuiImageStreamGetNextFrame(m_pDepthStreamHandle, 0, &pDepthFrame); + status = NuiImageStreamGetNextFrame(m_pDepthStreamHandle, 0, + &pDepthFrame); if ((status == S_OK) && pDepthFrame) { INuiFrameTexture *pTexture = pDepthFrame->pFrameTexture; @@ -287,35 +298,45 @@ void CudaKernel::render_begin(const float timer) SceneInfo sceneInfo = m_sceneInfo; if (m_sceneInfo.draftMode && m_sceneInfo.pathTracingIteration == 0) sceneInfo.graphicsLevel = glNoShading; - if (m_sceneInfo.draftMode && m_sceneInfo.pathTracingIteration == m_sceneInfo.maxPathTracingIterations) + if (m_sceneInfo.draftMode && m_sceneInfo.pathTracingIteration == + m_sceneInfo.maxPathTracingIterations) sceneInfo.cameraType = ctAntialiazed; - cudaRender(m_occupancyParameters, m_blockSize, sceneInfo, objects, m_postProcessingInfo, m_viewPos, m_viewDir, - m_angles + // LOG_INFO(1, "Transfering random numbers"); + h2d_randoms(m_occupancyParameters, + RandomGenerator::getInstance().getBuffer(), sceneInfo.size); + + cudaRender(m_occupancyParameters, m_blockSize, sceneInfo, objects, + m_postProcessingInfo, m_viewPos, m_viewDir, m_angles #ifdef USE_MANAGED_MEMORY , m_hBoundingBoxes, m_hPrimitives #endif - ); + ); } - m_refresh = (m_sceneInfo.pathTracingIteration < m_sceneInfo.maxPathTracingIterations); + m_refresh = (m_sceneInfo.pathTracingIteration < + m_sceneInfo.maxPathTracingIterations); } void CudaKernel::render_end() { // GPU -> CPU Data transfers - d2h_bitmap(m_occupancyParameters, m_sceneInfo, m_bitmap, m_hPrimitivesXYIds); + d2h_bitmap(m_occupancyParameters, m_sceneInfo, m_bitmap, + m_hPrimitivesXYIds); #ifdef WIN32 - if (m_sceneInfo.pathTracingIteration == m_sceneInfo.maxPathTracingIterations - 1) - LOG_INFO(1, "Rendering completed in " << GetTickCount() - m_counter << " ms"); + if (m_sceneInfo.pathTracingIteration == + m_sceneInfo.maxPathTracingIterations - 1) + LOG_INFO(1, "Rendering completed in " << GetTickCount() - m_counter + << " ms"); #endif // WIN32 if (m_sceneInfo.frameBufferType == ftRGB) { ::glEnable(GL_TEXTURE_2D); ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - ::glTexImage2D(GL_TEXTURE_2D, 0, gColorDepth, m_sceneInfo.size.x, m_sceneInfo.size.y, 0, GL_RGB, - GL_UNSIGNED_BYTE, m_bitmap); + ::glTexImage2D(GL_TEXTURE_2D, 0, gColorDepth, m_sceneInfo.size.x, + m_sceneInfo.size.y, 0, GL_RGB, GL_UNSIGNED_BYTE, + m_bitmap); if (m_sceneInfo.cameraType == ctVR) { @@ -335,10 +356,14 @@ void CudaKernel::render_end() for (float y(0); y < 1; y += step) { vec2f s = {scale, scale}; - const vec2f p0 = {s.x * x - halfStep, s.y * y - halfStep}; - const vec2f p1 = {s.x * (x + step) - halfStep, s.y * y - halfStep}; - const vec2f p2 = {s.x * (x + step) - halfStep, s.y * (y + step) - halfStep}; - const vec2f p3 = {s.x * x - halfStep, s.y * (y + step) - halfStep}; + const vec2f p0 = {s.x * x - halfStep, + s.y * y - halfStep}; + const vec2f p1 = {s.x * (x + step) - halfStep, + s.y * y - halfStep}; + const vec2f p2 = {s.x * (x + step) - halfStep, + s.y * (y + step) - halfStep}; + const vec2f p3 = {s.x * x - halfStep, + s.y * (y + step) - halfStep}; float d0 = sqrt(pow(p0.x, 2) + pow(p0.y, 2)); float d1 = sqrt(pow(p1.x, 2) + pow(p1.y, 2)); @@ -352,16 +377,20 @@ void CudaKernel::render_end() ::glBegin(GL_QUADS); ::glTexCoord2f(1.f - (b + (x / 2.f)), y); - ::glVertex3f(center.x + 0.5f * p0.x * d0, center.y + p0.y * d0, 0.f); + ::glVertex3f(center.x + 0.5f * p0.x * d0, + center.y + p0.y * d0, 0.f); ::glTexCoord2f(1.f - (b + (x + step) / 2.f), y); - ::glVertex3f(center.x + 0.5f * p1.x * d1, center.y + p1.y * d1, 0.f); + ::glVertex3f(center.x + 0.5f * p1.x * d1, + center.y + p1.y * d1, 0.f); ::glTexCoord2f(1.f - (b + (x + step) / 2.f), y + step); - ::glVertex3f(center.x + 0.5f * p2.x * d2, center.y + p2.y * d2, 0.f); + ::glVertex3f(center.x + 0.5f * p2.x * d2, + center.y + p2.y * d2, 0.f); ::glTexCoord2f(1.f - (b + (x / 2.f)), y + step); - ::glVertex3f(center.x + 0.5f * p3.x * d3, center.y + p3.y * d3, 0.f); + ::glVertex3f(center.x + 0.5f * p3.x * d3, + center.y + p3.y * d3, 0.f); ::glEnd(); } } @@ -390,13 +419,16 @@ void CudaKernel::render_end() void CudaKernel::queryDevice() { - LOG_INFO(3, "CUDA Device Query (Runtime API) version (CUDART static linking)"); + LOG_INFO(3, + "CUDA Device Query (Runtime API) version (CUDART static linking)"); int deviceCount = 0; cudaError_t error_id = cudaGetDeviceCount(&deviceCount); if (error_id != cudaSuccess) - LOG_INFO(3, "cudaGetDeviceCount returned " << (int)error_id << " -> " << cudaGetErrorString(error_id)); + LOG_INFO(3, "cudaGetDeviceCount returned " + << (int)error_id << " -> " + << cudaGetErrorString(error_id)); // This function call returns 0 if there are no CUDA capable devices. if (deviceCount == 0) @@ -419,61 +451,90 @@ void CudaKernel::queryDevice() cudaDriverGetVersion(&driverVersion); cudaRuntimeGetVersion(&runtimeVersion); LOG_INFO(1, " - CUDA Driver Version / Runtime Version..........: " - << driverVersion / 1000 << "." << (driverVersion % 100) / 10 << " / " << runtimeVersion / 1000 - << "." << (runtimeVersion % 100) / 10); - LOG_INFO(1, " - CUDA Capability Major/Minor version number.....: " << deviceProp.major << "." - << deviceProp.minor); + << driverVersion / 1000 << "." + << (driverVersion % 100) / 10 << " / " + << runtimeVersion / 1000 << "." + << (runtimeVersion % 100) / 10); + LOG_INFO(1, " - CUDA Capability Major/Minor version number.....: " + << deviceProp.major << "." << deviceProp.minor); LOG_INFO(1, " - Total amount of global memory..................: " - << (float)deviceProp.totalGlobalMem / 1048576.0f << "MBytes (" - << (unsigned long long)deviceProp.totalGlobalMem << " bytes)"); + << (float)deviceProp.totalGlobalMem / 1048576.0f + << "MBytes (" + << (unsigned long long)deviceProp.totalGlobalMem + << " bytes)"); LOG_INFO(3, " - Max Texture Dimension Size (x,y,z).............: 1D=(" - << deviceProp.maxTexture1D << "), 2D=(" << deviceProp.maxTexture2D[0] << "," - << deviceProp.maxTexture2D[1] << "), 3D=(" << deviceProp.maxTexture3D[0] << "," - << deviceProp.maxTexture3D[1] << "," << deviceProp.maxTexture3D[2] << ")"); + << deviceProp.maxTexture1D << "), 2D=(" + << deviceProp.maxTexture2D[0] << "," + << deviceProp.maxTexture2D[1] << "), 3D=(" + << deviceProp.maxTexture3D[0] << "," + << deviceProp.maxTexture3D[1] << "," + << deviceProp.maxTexture3D[2] << ")"); LOG_INFO(3, " - Max Layered Texture Size (dim) x layers........: 1D=(" - << deviceProp.maxTexture1DLayered[0] << ") x " << deviceProp.maxTexture1DLayered[1] << ", 2D=(" - << deviceProp.maxTexture2DLayered[0] << "," << deviceProp.maxTexture2DLayered[1] << ") x " + << deviceProp.maxTexture1DLayered[0] << ") x " + << deviceProp.maxTexture1DLayered[1] << ", 2D=(" + << deviceProp.maxTexture2DLayered[0] << "," + << deviceProp.maxTexture2DLayered[1] << ") x " << deviceProp.maxTexture2DLayered[2]); - LOG_INFO(3, " - Total amount of constant memory................: " << deviceProp.totalConstMem << "bytes"); - LOG_INFO(3, " - Total amount of shared memory per block........: " << deviceProp.sharedMemPerBlock << "bytes"); - LOG_INFO(3, " - Total number of registers available per block..: " << deviceProp.regsPerBlock); - LOG_INFO(3, " - Warp size......................................: " << deviceProp.warpSize); - LOG_INFO(3, " - Maximum number of threads per multiprocessor...: " << deviceProp.maxThreadsPerMultiProcessor); - LOG_INFO(3, " - Maximum number of threads per block............: " << deviceProp.maxThreadsPerBlock); - LOG_INFO(3, " - Maximum sizes of each dimension of a block.....: " << deviceProp.maxThreadsDim[0] << " x " - << deviceProp.maxThreadsDim[1] << " x " - << deviceProp.maxThreadsDim[2]); - LOG_INFO(3, " - Maximum sizes of each dimension of a grid......: " << deviceProp.maxGridSize[0] << " x " - << deviceProp.maxGridSize[1] << " x " - << deviceProp.maxGridSize[2]); - LOG_INFO(3, " - Maximum memory pitch...........................: " << deviceProp.memPitch << "bytes"); - LOG_INFO(3, " - Texture alignment..............................: " << deviceProp.textureAlignment << "bytes"); - LOG_INFO(3, " - Concurrent copy and execution..................: " << (deviceProp.deviceOverlap ? "Yes" : "No") - << " with " << deviceProp.asyncEngineCount - << "copy engine(s)"); - LOG_INFO(3, " - Run time limit on kernels......................: " - << (deviceProp.kernelExecTimeoutEnabled ? "Yes" : "No")); - LOG_INFO(3, " - Integrated GPU sharing Host Memory.............: " << (deviceProp.integrated ? "Yes" : "No")); - LOG_INFO(3, " - Support host page-locked memory mapping........: " << (deviceProp.canMapHostMemory ? "Yes" - : "No")); - LOG_INFO(3, " - Concurrent GPUKernel execution.................: " << (deviceProp.concurrentKernels ? "Yes" - : "No")); - LOG_INFO(3, " - Alignment requirement for Surfaces.............: " << (deviceProp.surfaceAlignment ? "Yes" - : "No")); - LOG_INFO(3, " - Device has ECC support enabled.................: " << (deviceProp.ECCEnabled ? "Yes" : "No")); - LOG_INFO(3, " - Device is using TCC driver mode................: " << (deviceProp.tccDriver ? "Yes" : "No")); - LOG_INFO(3, " - Device supports Unified Addressing (UVA).......: " << (deviceProp.unifiedAddressing ? "Yes" - : "No")); - LOG_INFO(3, " - Device PCI Bus ID / PCI location ID............: " << deviceProp.pciBusID << "/" - << deviceProp.pciDeviceID); + LOG_INFO(3, " - Total amount of constant memory................: " + << deviceProp.totalConstMem << "bytes"); + LOG_INFO(3, " - Total amount of shared memory per block........: " + << deviceProp.sharedMemPerBlock << "bytes"); + LOG_INFO(3, " - Total number of registers available per block..: " + << deviceProp.regsPerBlock); + LOG_INFO(3, " - Warp size......................................: " + << deviceProp.warpSize); + LOG_INFO(3, " - Maximum number of threads per multiprocessor...: " + << deviceProp.maxThreadsPerMultiProcessor); + LOG_INFO(3, " - Maximum number of threads per block............: " + << deviceProp.maxThreadsPerBlock); + LOG_INFO(3, " - Maximum sizes of each dimension of a block.....: " + << deviceProp.maxThreadsDim[0] << " x " + << deviceProp.maxThreadsDim[1] << " x " + << deviceProp.maxThreadsDim[2]); + LOG_INFO(3, " - Maximum sizes of each dimension of a grid......: " + << deviceProp.maxGridSize[0] << " x " + << deviceProp.maxGridSize[1] << " x " + << deviceProp.maxGridSize[2]); + LOG_INFO(3, " - Maximum memory pitch...........................: " + << deviceProp.memPitch << "bytes"); + LOG_INFO(3, " - Texture alignment..............................: " + << deviceProp.textureAlignment << "bytes"); + LOG_INFO(3, " - Concurrent copy and execution..................: " + << (deviceProp.deviceOverlap ? "Yes" : "No") << " with " + << deviceProp.asyncEngineCount << "copy engine(s)"); + LOG_INFO(3, + " - Run time limit on kernels......................: " + << (deviceProp.kernelExecTimeoutEnabled ? "Yes" : "No")); + LOG_INFO(3, " - Integrated GPU sharing Host Memory.............: " + << (deviceProp.integrated ? "Yes" : "No")); + LOG_INFO(3, " - Support host page-locked memory mapping........: " + << (deviceProp.canMapHostMemory ? "Yes" : "No")); + LOG_INFO(3, " - Concurrent GPUKernel execution.................: " + << (deviceProp.concurrentKernels ? "Yes" : "No")); + LOG_INFO(3, " - Alignment requirement for Surfaces.............: " + << (deviceProp.surfaceAlignment ? "Yes" : "No")); + LOG_INFO(3, " - Device has ECC support enabled.................: " + << (deviceProp.ECCEnabled ? "Yes" : "No")); + LOG_INFO(3, " - Device is using TCC driver mode................: " + << (deviceProp.tccDriver ? "Yes" : "No")); + LOG_INFO(3, " - Device supports Unified Addressing (UVA).......: " + << (deviceProp.unifiedAddressing ? "Yes" : "No")); + LOG_INFO(3, " - Device PCI Bus ID / PCI location ID............: " + << deviceProp.pciBusID << "/" + << deviceProp.pciDeviceID); const char *sComputeMode[] = { - "Default (multiple host threads can use ::cudaSetDevice() with device simultaneously)", - "Exclusive (only one host thread in one process is able to use ::cudaSetDevice() with this device)", - "Prohibited (no host thread can use ::cudaSetDevice() with this device)", - "Exclusive Process (many threads in one process is able to use ::cudaSetDevice() with this device) Unknown", + "Default (multiple host threads can use ::cudaSetDevice() with " + "device simultaneously)", + "Exclusive (only one host thread in one process is able to use " + "::cudaSetDevice() with this device)", + "Prohibited (no host thread can use ::cudaSetDevice() with this " + "device)", + "Exclusive Process (many threads in one process is able to use " + "::cudaSetDevice() with this device) Unknown", NULL}; - LOG_INFO(3, " - Compute Mode...................................: " << sComputeMode[deviceProp.computeMode]); + LOG_INFO(3, " - Compute Mode...................................: " + << sComputeMode[deviceProp.computeMode]); LOG_INFO(3, ""); LOG_INFO(3, "Data type sizes (in bytes)"); LOG_INFO(3, " - float : " << sizeof(float)); @@ -494,46 +555,27 @@ void CudaKernel::queryDevice() LOG_INFO(3, " - PostProcessingInfo: " << sizeof(PostProcessingInfo)); } - // exe and CUDA driver name - std::string sProfileString = "deviceQuery, CUDA Driver = CUDART"; - char cTemp[10]; - // driver version - sProfileString += ", CUDA Driver Version = "; -#ifdef WIN32 - sprintf_s(cTemp, 10, "%d.%d", driverVersion / 1000, (driverVersion % 100) / 10); -#else - sprintf(cTemp, "%d.%d", driverVersion / 1000, (driverVersion % 100) / 10); -#endif - sProfileString += cTemp; + LOG_INFO(1, "CUDA Driver Version : " << driverVersion / 1000 << "." + << (driverVersion % 100) / 10); // Runtime version - sProfileString += ", CUDA Runtime Version = "; -#ifdef WIN32 - sprintf_s(cTemp, 10, "%d.%d", runtimeVersion / 1000, (runtimeVersion % 100) / 10); -#else - sprintf(cTemp, "%d.%d", runtimeVersion / 1000, (runtimeVersion % 100) / 10); -#endif - sProfileString += cTemp; + LOG_INFO(1, "CUDA Runtime Version : " << runtimeVersion / 1000 << "." + << (runtimeVersion % 100) / 10); // Device count - sProfileString += ", NumDevs = "; -#ifdef WIN32 - sprintf_s(cTemp, 10, "%d", deviceCount); -#else - sprintf(cTemp, "%d", deviceCount); -#endif - sProfileString += cTemp; + LOG_INFO(1, "Number of CUDA devices: " << deviceCount); // First 2 device names, if any for (dev = 0; dev < ((deviceCount > 2) ? 2 : deviceCount); ++dev) { cudaDeviceProp deviceProp; cudaGetDeviceProperties(&deviceProp, dev); - sProfileString += ", Device = "; - sProfileString += deviceProp.name; + LOG_INFO(1, " - Device : " << deviceProp.name); } - LOG_INFO(3, " - Profile........................................: " << sProfileString); + LOG_INFO(1, + "-----------------------------------------------------------------" + "---------------"); } void CudaKernel::reshape() @@ -546,4 +588,4 @@ std::string CudaKernel::getGPUDescription() { return m_gpuDescription; } -} +} // namespace solr diff --git a/solr/engines/cuda/CudaKernel.h b/solr/engines/cuda/CudaKernel.h index 76850a9..22b3ec4 100644 --- a/solr/engines/cuda/CudaKernel.h +++ b/solr/engines/cuda/CudaKernel.h @@ -1,27 +1,23 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once -#include -#include +#include "../GPUKernel.h" namespace solr { @@ -39,6 +35,7 @@ class SOLR_API CudaKernel : public GPUKernel virtual void setDeviceId(const int) {} virtual void setKernelFilename(const std::string&) {} virtual void recompileKernels() {} + public: // ---------- Devices ---------- void initializeDevice(); @@ -65,10 +62,14 @@ class SOLR_API CudaKernel : public GPUKernel m_blockSize.y = y; m_blockSize.z = z; } - void setSharedMemSize(int sharedMemSize) { m_sharedMemSize = sharedMemSize; } + void setSharedMemSize(int sharedMemSize) + { + m_sharedMemSize = sharedMemSize; + } + private: // Runtime kernel execution parameters vec4i m_blockSize; int m_sharedMemSize; }; -} +} // namespace solr diff --git a/solr/engines/cuda/CudaRayTracer.cu b/solr/engines/cuda/CudaRayTracer.cu index 7049eda..6db3a5c 100644 --- a/solr/engines/cuda/CudaRayTracer.cu +++ b/solr/engines/cuda/CudaRayTracer.cu @@ -1,29 +1,26 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ // Project -#include -#include -#include "TextureMapping.cuh" #include "GeometryIntersections.cuh" +#include "TextureMapping.cuh" #include "VectorUtils.cuh" +#include +#include // Device resources #ifndef USE_MANAGED_MEMORY @@ -47,32 +44,33 @@ cudaStream_t d_streams[MAX_GPU_COUNT][MAX_STREAM_COUNT]; __x = 0; \ } -__device__ __INLINE__ float4 launchVolumeRendering(const int& index, BoundingBox* boundingBoxes, - const int& nbActiveBoxes, Primitive* primitives, - const int& nbActivePrimitives, LightInformation* lightInformation, - const int& lightInformationSize, const int& nbActiveLamps, - Material* materials, BitmapBuffer* textures, RandomBuffer* randoms, - const Ray& ray, const SceneInfo& sceneInfo, - const PostProcessingInfo& postProcessingInfo, float& depthOfField, - PrimitiveXYIdBuffer& primitiveXYId) +__device__ __INLINE__ float4 launchVolumeRendering( + const int& index, BoundingBox* boundingBoxes, const int& nbActiveBoxes, + Primitive* primitives, const int& nbActivePrimitives, + LightInformation* lightInformation, const int& lightInformationSize, + const int& nbActiveLamps, Material* materials, BitmapBuffer* textures, + RandomBuffer* randoms, const Ray& ray, const SceneInfo& sceneInfo, + const PostProcessingInfo& postProcessingInfo, float& depthOfField, + PrimitiveXYIdBuffer& primitiveXYId) { primitiveXYId.x = -1; primitiveXYId.y = 1; primitiveXYId.z = 0; - float4 intersectionColor = - intersectionsWithPrimitives(index, sceneInfo, boundingBoxes, nbActiveBoxes, primitives, nbActivePrimitives, - materials, textures, lightInformation, lightInformationSize, nbActiveLamps, randoms, - postProcessingInfo, ray); + float4 intersectionColor = intersectionsWithPrimitives( + index, sceneInfo, boundingBoxes, nbActiveBoxes, primitives, + nbActivePrimitives, materials, textures, lightInformation, + lightInformationSize, nbActiveLamps, randoms, postProcessingInfo, ray); return intersectionColor; } -__device__ __INLINE__ float4 launchRayTracing(const int& index, BoundingBox* boundingBoxes, const int& nbActiveBoxes, - Primitive* primitives, const int& nbActivePrimitives, - LightInformation* lightInformation, const int& lightInformationSize, - const int& nbActiveLamps, Material* materials, BitmapBuffer* textures, - RandomBuffer* randoms, const Ray& ray, const SceneInfo& sceneInfo, - const PostProcessingInfo& postProcessingInfo, float& depthOfField, - PrimitiveXYIdBuffer& primitiveXYId) +__device__ __INLINE__ float4 launchRayTracing( + const int& index, BoundingBox* boundingBoxes, const int& nbActiveBoxes, + Primitive* primitives, const int& nbActivePrimitives, + LightInformation* lightInformation, const int& lightInformationSize, + const int& nbActiveLamps, Material* materials, BitmapBuffer* textures, + RandomBuffer* randoms, const Ray& ray, const SceneInfo& sceneInfo, + const PostProcessingInfo& postProcessingInfo, float& depthOfField, + PrimitiveXYIdBuffer& primitiveXYId) { float4 intersectionColor = {0.f, 0.f, 0.f, 0.f}; vec3f closestIntersection = {0.f, 0.f, 0.f}; @@ -115,32 +113,43 @@ __device__ __INLINE__ float4 launchRayTracing(const int& index, BoundingBox* bou Ray pathTracingRay; float pathTracingRatio = 0.f; float4 pathTracingColor = {0.f, 0.f, 0.f, 0.f}; - bool useGlobalIllumination = false; + bool processGI = false; float4 rBlinn = {0.f, 0.f, 0.f, 0.f}; int currentMaxIteration = - (sceneInfo.graphicsLevel < glReflectionsAndRefractions) ? 1 : sceneInfo.nbRayIterations + sceneInfo.pathTracingIteration; - currentMaxIteration = (currentMaxIteration > NB_MAX_ITERATIONS) ? NB_MAX_ITERATIONS : currentMaxIteration; - - while (iteration < currentMaxIteration && rayLength < sceneInfo.viewDistance && carryon) + (sceneInfo.graphicsLevel < glReflectionsAndRefractions) + ? 1 + : sceneInfo.nbRayIterations + sceneInfo.pathTracingIteration; + currentMaxIteration = (currentMaxIteration > NB_MAX_ITERATIONS) + ? NB_MAX_ITERATIONS + : currentMaxIteration; + + while (iteration < currentMaxIteration && + rayLength < sceneInfo.viewDistance && carryon) { vec3f areas = {0.f, 0.f, 0.f}; - // If no intersection with lamps detected. Now compute intersection with Primitives + // If no intersection with lamps detected. Now compute intersection with + // Primitives if (carryon) - carryon = intersectionWithPrimitives(sceneInfo, postProcessingInfo, boundingBoxes, nbActiveBoxes, - primitives, nbActivePrimitives, materials, textures, rayOrigin, - iteration, closestPrimitive, closestIntersection, normal, areas, - closestColor, colorBox, currentMaterialId); + carryon = intersectionWithPrimitives( + sceneInfo, postProcessingInfo, boundingBoxes, nbActiveBoxes, + primitives, nbActivePrimitives, materials, textures, rayOrigin, + iteration, closestPrimitive, closestIntersection, normal, areas, + closestColor, colorBox, currentMaterialId); if (carryon) { currentMaterialId = primitives[closestPrimitive].materialId; vec4f attributes; - attributes.x = materials[primitives[closestPrimitive].materialId].reflection; - attributes.y = materials[primitives[closestPrimitive].materialId].transparency; - attributes.z = materials[primitives[closestPrimitive].materialId].refraction; - attributes.w = materials[primitives[closestPrimitive].materialId].opacity; + attributes.x = + materials[primitives[closestPrimitive].materialId].reflection; + attributes.y = + materials[primitives[closestPrimitive].materialId].transparency; + attributes.z = + materials[primitives[closestPrimitive].materialId].refraction; + attributes.w = + materials[primitives[closestPrimitive].materialId].opacity; if (iteration == 0) { @@ -154,23 +163,28 @@ __device__ __INLINE__ float4 launchRayTracing(const int& index, BoundingBox* bou latestIntersection = closestIntersection; depthOfField = length(firstIntersection - ray.origin); - if (materials[primitives[closestPrimitive].materialId].innerIllumination.x == 0.f && - (sceneInfo.advancedIllumination == aiBasic || - sceneInfo.advancedIllumination == aiFull)) + if (materials[primitives[closestPrimitive].materialId] + .innerIllumination.x == 0.f && + sceneInfo.advancedIllumination != aiNone) { // Global illumination - int t = (index + sceneInfo.pathTracingIteration * 100 + sceneInfo.timestamp) % (MAX_BITMAP_SIZE - 3); - pathTracingRay.origin = closestIntersection + normal * sceneInfo.rayEpsilon; - pathTracingRay.direction.x = normal.x + 100.f * randoms[t]; - pathTracingRay.direction.y = normal.y + 100.f * randoms[t + 1]; - pathTracingRay.direction.z = normal.z + 100.f * randoms[t + 2]; - - float cos_theta = dot(normalize(pathTracingRay.direction), normal); + const int t = (index + sceneInfo.timestamp) % + (sceneInfo.size.x * sceneInfo.size.y - 3); + pathTracingRay.origin = + closestIntersection + normal * sceneInfo.rayEpsilon; + pathTracingRay.direction.x = randoms[t]; + pathTracingRay.direction.y = randoms[t + 1]; + pathTracingRay.direction.z = randoms[t + 2]; + pathTracingRay.direction = + normalize(pathTracingRay.direction); + + const float cos_theta = + dot(pathTracingRay.direction, normal); if (cos_theta < 0.f) pathTracingRay.direction = -pathTracingRay.direction; pathTracingRay.direction += closestIntersection; - pathTracingRatio = (1.f - attributes.y) * fabs(cos_theta); - useGlobalIllumination = true; + pathTracingRatio = (1.f - attributes.y) * abs(cos_theta); + processGI = true; } // Primitive ID for current pixel @@ -179,17 +193,23 @@ __device__ __INLINE__ float4 launchRayTracing(const int& index, BoundingBox* bou // Get object color rBlinn.w = attributes.y; - colors[iteration] = primitiveShader(index, sceneInfo, postProcessingInfo, boundingBoxes, nbActiveBoxes, - primitives, nbActivePrimitives, lightInformation, lightInformationSize, - nbActiveLamps, materials, textures, randoms, rayOrigin.origin, normal, - closestPrimitive, closestIntersection, areas, closestColor, iteration, - refractionFromColor, shadowIntensity, rBlinn, attributes); + colors[iteration] = + primitiveShader(index, sceneInfo, postProcessingInfo, + boundingBoxes, nbActiveBoxes, primitives, + nbActivePrimitives, lightInformation, + lightInformationSize, nbActiveLamps, materials, + textures, randoms, rayOrigin.origin, normal, + closestPrimitive, closestIntersection, areas, + closestColor, iteration, refractionFromColor, + shadowIntensity, rBlinn, attributes); // Primitive illumination - Material& material = materials[primitives[closestPrimitive].materialId]; + Material& material = + materials[primitives[closestPrimitive].materialId]; primitiveXYId.z += material.innerIllumination.x * 256; - float segmentLength = length(closestIntersection - latestIntersection); + float segmentLength = + length(closestIntersection - latestIntersection); latestIntersection = closestIntersection; // Refraction @@ -204,9 +224,12 @@ __device__ __INLINE__ float4 launchRayTracing(const int& index, BoundingBox* bou { // Opacity refraction = 1.f; - float length = segmentLength * (attributes.w * (1.f - transparency)); + float length = + segmentLength * (attributes.w * (1.f - transparency)); rayLength += length; - rayLength = (rayLength > sceneInfo.viewDistance) ? sceneInfo.viewDistance : rayLength; + rayLength = (rayLength > sceneInfo.viewDistance) + ? sceneInfo.viewDistance + : rayLength; a = (rayLength / sceneInfo.viewDistance); colors[iteration].x -= a; colors[iteration].y -= a; @@ -215,7 +238,8 @@ __device__ __INLINE__ float4 launchRayTracing(const int& index, BoundingBox* bou // Actual refraction vec3f O_E = normalize(closestIntersection - rayOrigin.origin); - vectorRefraction(reflectedTarget, O_E, refraction, normal, initialRefraction); + vectorRefraction(reflectedTarget, O_E, refraction, normal, + initialRefraction); colorContributions[iteration] = transparency - a; @@ -225,42 +249,51 @@ __device__ __INLINE__ float4 launchRayTracing(const int& index, BoundingBox* bou if (reflectedRays == -1 && attributes.x != 0.f) { vectorReflection(reflectedRay.direction, O_E, normal); - reflectedRay.origin = closestIntersection + reflectedRay.direction * sceneInfo.rayEpsilon; - reflectedRay.direction = closestIntersection + reflectedRay.direction; + reflectedRay.origin = + closestIntersection + + reflectedRay.direction * sceneInfo.rayEpsilon; + reflectedRay.direction = + closestIntersection + reflectedRay.direction; reflectedRatio = attributes.x; reflectedRays = iteration; } } + else if (attributes.x != 0.f) // Reflection + { + vec3f O_E = normalize(closestIntersection - rayOrigin.origin); + vectorReflection(reflectedTarget, O_E, normal); + colorContributions[iteration] = attributes.x; + } else - if (attributes.x != 0.f) // Reflection - { - vec3f O_E = normalize(closestIntersection - rayOrigin.origin); - vectorReflection(reflectedTarget, O_E, normal); - colorContributions[iteration] = attributes.x; - } - else - { - carryon = false; - colorContributions[iteration] = 1.f; - } + { + carryon = false; + colorContributions[iteration] = 1.f; + } // Contribute to final color rBlinn /= (iteration + 1); - recursiveBlinn.x = (rBlinn.x > recursiveBlinn.x) ? rBlinn.x : recursiveBlinn.x; - recursiveBlinn.y = (rBlinn.y > recursiveBlinn.y) ? rBlinn.y : recursiveBlinn.y; - recursiveBlinn.z = (rBlinn.z > recursiveBlinn.z) ? rBlinn.z : recursiveBlinn.z; - - rayOrigin.origin = closestIntersection + reflectedTarget * sceneInfo.rayEpsilon; + recursiveBlinn.x = + (rBlinn.x > recursiveBlinn.x) ? rBlinn.x : recursiveBlinn.x; + recursiveBlinn.y = + (rBlinn.y > recursiveBlinn.y) ? rBlinn.y : recursiveBlinn.y; + recursiveBlinn.z = + (rBlinn.z > recursiveBlinn.z) ? rBlinn.z : recursiveBlinn.z; + + rayOrigin.origin = + closestIntersection + reflectedTarget * sceneInfo.rayEpsilon; rayOrigin.direction = closestIntersection + reflectedTarget; - // Noise management + // Gloss management if (sceneInfo.pathTracingIteration != 0 && - materials[primitives[closestPrimitive].materialId].color.w != 0.f) + materials[primitives[closestPrimitive].materialId].color.w != + 0.f) { // Randomize view - float ratio = materials[primitives[closestPrimitive].materialId].color.w; + float ratio = + materials[primitives[closestPrimitive].materialId].color.w; ratio *= (attributes.y == 0.f) ? 1000.f : 1.f; - int rindex = (index + sceneInfo.timestamp) % (MAX_BITMAP_SIZE - 3); + int rindex = + (index + sceneInfo.timestamp) % (MAX_BITMAP_SIZE - 3); rayOrigin.direction.x += randoms[rindex] * ratio; rayOrigin.direction.y += randoms[rindex + 1] * ratio; rayOrigin.direction.z += randoms[rindex + 2] * ratio; @@ -270,24 +303,25 @@ __device__ __INLINE__ float4 launchRayTracing(const int& index, BoundingBox* bou { if (sceneInfo.skyboxMaterialId != MATERIAL_NONE) { - colors[iteration] = skyboxMapping(sceneInfo, materials, textures, rayOrigin); - float rad = colors[iteration].x + colors[iteration].y + colors[iteration].z; + colors[iteration] = + skyboxMapping(sceneInfo, materials, textures, rayOrigin); + float rad = colors[iteration].x + colors[iteration].y + + colors[iteration].z; primitiveXYId.z += (rad > 2.5f) ? rad * 256.f : 0.f; } + else if (sceneInfo.gradientBackground) + { + // Background + vec3f normal = {0.f, 1.f, 0.f}; + vec3f dir = normalize(rayOrigin.direction - rayOrigin.origin); + float angle = 0.5f - dot(normal, dir); + angle = (angle > 1.f) ? 1.f : angle; + colors[iteration] = (1.f - angle) * sceneInfo.backgroundColor; + } else - if (sceneInfo.gradientBackground) - { - // Background - vec3f normal = {0.f, 1.f, 0.f}; - vec3f dir = normalize(rayOrigin.direction - rayOrigin.origin); - float angle = 0.5f - dot(normal, dir); - angle = (angle > 1.f) ? 1.f : angle; - colors[iteration] = (1.f - angle) * sceneInfo.backgroundColor; - } - else - { - colors[iteration] = sceneInfo.backgroundColor; - } + { + colors[iteration] = sceneInfo.backgroundColor; + } colorContributions[iteration] = 1.f; } iteration++; @@ -295,97 +329,97 @@ __device__ __INLINE__ float4 launchRayTracing(const int& index, BoundingBox* bou vec3f areas = {0.f, 0.f, 0.f}; if (sceneInfo.graphicsLevel >= glReflectionsAndRefractions && - reflectedRays != -1) // TODO: Draft mode should only test "sceneInfo.pathTracingIteration==iteration" + reflectedRays != -1) // TODO: Draft mode should only test + // "sceneInfo.pathTracingIteration==iteration" // TODO: Dodgy implementation - if (intersectionWithPrimitives(sceneInfo, postProcessingInfo, boundingBoxes, nbActiveBoxes, primitives, - nbActivePrimitives, materials, textures, reflectedRay, reflectedRays, - closestPrimitive, closestIntersection, normal, areas, closestColor, colorBox, + if (intersectionWithPrimitives(sceneInfo, postProcessingInfo, + boundingBoxes, nbActiveBoxes, primitives, + nbActivePrimitives, materials, textures, + reflectedRay, reflectedRays, + closestPrimitive, closestIntersection, + normal, areas, closestColor, colorBox, currentMaterialId)) { vec4f attributes; - attributes.x = materials[primitives[closestPrimitive].materialId].reflection; - float4 color = primitiveShader(index, sceneInfo, postProcessingInfo, boundingBoxes, nbActiveBoxes, - primitives, nbActivePrimitives, lightInformation, lightInformationSize, - nbActiveLamps, materials, textures, randoms, reflectedRay.origin, normal, - closestPrimitive, closestIntersection, areas, closestColor, reflectedRays, - refractionFromColor, shadowIntensity, rBlinn, attributes); + attributes.x = + materials[primitives[closestPrimitive].materialId].reflection; + float4 color = primitiveShader( + index, sceneInfo, postProcessingInfo, boundingBoxes, + nbActiveBoxes, primitives, nbActivePrimitives, lightInformation, + lightInformationSize, nbActiveLamps, materials, textures, + randoms, reflectedRay.origin, normal, closestPrimitive, + closestIntersection, areas, closestColor, reflectedRays, + refractionFromColor, shadowIntensity, rBlinn, attributes); colors[reflectedRays] += color * reflectedRatio; primitiveXYId.w = shadowIntensity * 255; } - bool test(true); - if ((sceneInfo.advancedIllumination == aiBasic || sceneInfo.advancedIllumination == aiFull) && - sceneInfo.pathTracingIteration >= NB_MAX_ITERATIONS) + if (processGI && sceneInfo.pathTracingIteration >= NB_MAX_ITERATIONS) { - if (useGlobalIllumination && sceneInfo.advancedIllumination == aiFull) + float alphaIntensity = 1.f; + if (sceneInfo.advancedIllumination == aiFull) { // Global illumination - if (intersectionWithPrimitives(sceneInfo, postProcessingInfo, boundingBoxes, nbActiveBoxes, primitives, - nbActivePrimitives, materials, textures, pathTracingRay, - 30, // Only consider close geometry (max distance / 30) - closestPrimitive, closestIntersection, normal, areas, closestColor, colorBox, - MATERIAL_NONE)) + if (intersectionWithPrimitives( + sceneInfo, postProcessingInfo, boundingBoxes, nbActiveBoxes, + primitives, nbActivePrimitives, materials, textures, + pathTracingRay, + 10, // Only consider nearby geometry (max distance / 10) + closestPrimitive, closestIntersection, normal, areas, + closestColor, colorBox, MATERIAL_NONE)) { + // Ambient occlusion and material emission if (primitives[closestPrimitive].materialId != MATERIAL_NONE) { - Material& material = materials[primitives[closestPrimitive].materialId]; - if (material.innerIllumination.x == 0.f) - { - colors[0] = material.color * material.innerIllumination.x * pathTracingRatio; - test = false; - } - else - colors[0] = material.color * pathTracingRatio; - } - if (test) - { - pathTracingRatio *= STANDARD_LUNINANCE_STRENGTH; + Material& material = + materials[primitives[closestPrimitive].materialId]; + const float distanceToPrimitive = + length(closestIntersection - pathTracingRay.origin); + const float normalizedDistanceToPrimitive = + 1.f - + min(1.f, distanceToPrimitive / sceneInfo.viewDistance); vec4f attributes; - - Material& material = materials[primitives[closestPrimitive].materialId]; - if (material.innerIllumination.x == 0.f) - { - float len = length(closestIntersection - pathTracingRay.origin); - colors[0] -= sceneInfo.shadowIntensity; - } - else - pathTracingColor = - primitiveShader(index, sceneInfo, postProcessingInfo, boundingBoxes, nbActiveBoxes, - primitives, nbActivePrimitives, lightInformation, lightInformationSize, - nbActiveLamps, materials, textures, randoms, pathTracingRay.origin, normal, - closestPrimitive, closestIntersection, areas, closestColor, iteration, - refractionFromColor, shadowIntensity, rBlinn, attributes); + pathTracingColor = primitiveShader( + index, sceneInfo, postProcessingInfo, boundingBoxes, + nbActiveBoxes, primitives, nbActivePrimitives, + lightInformation, lightInformationSize, nbActiveLamps, + materials, textures, randoms, pathTracingRay.origin, + normal, closestPrimitive, closestIntersection, areas, + closestColor, iteration, refractionFromColor, + shadowIntensity, rBlinn, attributes); + alphaIntensity -= sceneInfo.shadowIntensity * + normalizedDistanceToPrimitive; + pathTracingRatio *= (MATERIAL_DEFAULT_EMMISION_STRENGTH + + material.innerIllumination.x) * + normalizedDistanceToPrimitive; } } - else - // Background - if (sceneInfo.skyboxMaterialId != MATERIAL_NONE) - { - pathTracingColor = skyboxMapping(sceneInfo, materials, textures, pathTracingRay); - pathTracingRatio *= SKYBOX_LUNINANCE_STRENGTH; - } - } - else - // Background - if (sceneInfo.skyboxMaterialId != MATERIAL_NONE) + else if (sceneInfo.skyboxMaterialId != MATERIAL_NONE) { - pathTracingColor = skyboxMapping(sceneInfo, materials, textures, pathTracingRay); + // Background + pathTracingColor = skyboxMapping(sceneInfo, materials, textures, + pathTracingRay); pathTracingRatio *= SKYBOX_LUNINANCE_STRENGTH; } - if (test) - colors[0] += pathTracingColor * pathTracingRatio; - } + } + else if (sceneInfo.skyboxMaterialId != MATERIAL_NONE) + { + // Background + pathTracingColor = + skyboxMapping(sceneInfo, materials, textures, pathTracingRay); + pathTracingRatio *= SKYBOX_LUNINANCE_STRENGTH; + } - if (test) - { - for (int i = iteration - 2; i >= 0; --i) - colors[i] = colors[i] * (1.f - colorContributions[i]) + colors[i + 1] * colorContributions[i]; - intersectionColor = colors[0]; - intersectionColor += recursiveBlinn; + colors[0] = + colors[0] * alphaIntensity + pathTracingColor * pathTracingRatio; } - else - intersectionColor = colors[0]; + + for (int i = iteration - 2; i >= 0; --i) + colors[i] = colors[i] * (1.f - colorContributions[i]) + + colors[i + 1] * colorContributions[i]; + intersectionColor = colors[0]; + intersectionColor += recursiveBlinn; // Background color float D1 = sceneInfo.viewDistance * 0.95f; @@ -394,7 +428,8 @@ __device__ __INLINE__ float4 launchRayTracing(const int& index, BoundingBox* bou float D2 = sceneInfo.viewDistance * 0.05f; float a = depthOfField - D1; float b = 1.f - (a / D2); - intersectionColor = intersectionColor * b + sceneInfo.backgroundColor * (1.f - b); + intersectionColor = + intersectionColor * b + sceneInfo.backgroundColor * (1.f - b); } // Primitive information @@ -408,53 +443,62 @@ __device__ __INLINE__ float4 launchRayTracing(const int& index, BoundingBox* bou } /*! -* ------------------------------------------------------------------------------------------------------------------------ -* \brief This kernel processes a "standard" image, meaning that the screen is a single image for -* which every pixel is a ray of light entering the same camera. -* ------------------------------------------------------------------------------------------------------------------------ -* \param[in] occupancyParameters Contains the number of GPUs and streams involded in the GPU processing -* \param[in] device_split Y coordinate from where the current GPU should start working -* \param[in] stream_split Y coordinate from where the current stream should start working -* \param[in] BoundingBoxes Pointer to the array of bounding boxes -* \param[in] nbActiveBoxes Number of bounding boxes -* \param[in] primitives Pointer to the array of primitives -* \param[in] nbActivePrimitives Number of primitives -* \param[in] lightInformation Pointer to the array of light positions and intensities (Used for global illumination) -* \param[in] lightInformationSize Number of lights -* \param[in] nbActiveLamps Number of lamps -* \param[in] materials Pointer to the array of materials -* \param[in] textures Pointer to the array of textures -* \param[in] randoms Pointer to the array of random floats (GPUs are not good at generating numbers, done by the CPU) -* \param[in] origin Camera position -* \param[in] direction Camera LookAt -* \param[in] angles Angles applied to the camera. The rotation center is {0,0,0} -* \param[in] sceneInfo Information about the scene and environment -* \param[in] postProcessingInfo Information about PostProcessing effect -* \param[out] postProcessingBuffer Pointer to the output array of color information -* \param[out] primitiveXYIds Pointer to the array containing the Id of the primitivive for each pixel -* ------------------------------------------------------------------------------------------------------------------------ -*/ -__global__ void k_standardRenderer(const int2 occupancyParameters, int device_split, int stream_split, - BoundingBox* BoundingBoxes, int nbActiveBoxes, Primitive* primitives, - int nbActivePrimitives, LightInformation* lightInformation, int lightInformationSize, - int nbActiveLamps, Material* materials, BitmapBuffer* textures, - RandomBuffer* randoms, vec3f origin, vec3f direction, vec4f angles, - SceneInfo sceneInfo, PostProcessingInfo postProcessingInfo, - PostProcessingBuffer* postProcessingBuffer, PrimitiveXYIdBuffer* primitiveXYIds) + * ------------------------------------------------------------------------------------------------------------------------ + * \brief This kernel processes a "standard" image, meaning that the screen + * is a single image for which every pixel is a ray of light entering the same + * camera. + * ------------------------------------------------------------------------------------------------------------------------ + * \param[in] occupancyParameters Contains the number of GPUs and streams + * involded in the GPU processing \param[in] device_split Y coordinate from + * where the current GPU should start working \param[in] stream_split Y + * coordinate from where the current stream should start working \param[in] + * BoundingBoxes Pointer to the array of bounding boxes \param[in] nbActiveBoxes + * Number of bounding boxes \param[in] primitives Pointer to the array of + * primitives \param[in] nbActivePrimitives Number of primitives \param[in] + * lightInformation Pointer to the array of light positions and intensities + * (Used for global illumination) \param[in] lightInformationSize Number of + * lights \param[in] nbActiveLamps Number of lamps \param[in] materials + * Pointer to the array of materials \param[in] textures Pointer to the array + * of textures \param[in] randoms Pointer to the array of random floats (GPUs + * are not good at generating numbers, done by the CPU) \param[in] origin + * Camera position \param[in] direction Camera LookAt \param[in] angles Angles + * applied to the camera. The rotation center is {0,0,0} \param[in] sceneInfo + * Information about the scene and environment \param[in] postProcessingInfo + * Information about PostProcessing effect \param[out] postProcessingBuffer + * Pointer to the output array of color information \param[out] primitiveXYIds + * Pointer to the array containing the Id of the primitivive for each pixel + * ------------------------------------------------------------------------------------------------------------------------ + */ +__global__ void k_standardRenderer( + const int2 occupancyParameters, int device_split, int stream_split, + BoundingBox* BoundingBoxes, int nbActiveBoxes, Primitive* primitives, + int nbActivePrimitives, LightInformation* lightInformation, + int lightInformationSize, int nbActiveLamps, Material* materials, + BitmapBuffer* textures, RandomBuffer* randoms, vec3f origin, + vec3f direction, vec4f angles, SceneInfo sceneInfo, + PostProcessingInfo postProcessingInfo, + PostProcessingBuffer* postProcessingBuffer, + PrimitiveXYIdBuffer* primitiveXYIds) { int x = blockDim.x * blockIdx.x + threadIdx.x; int y = blockDim.y * blockIdx.y + threadIdx.y; int index = (stream_split + y) * sceneInfo.size.x + x; // Antialisazing - float2 AArotatedGrid[4] = {{3.f, 5.f}, {5.f, -3.f}, {-3.f, -5.f}, {-5.f, 3.f}}; + float2 AArotatedGrid[4] = {{3.f, 5.f}, + {5.f, -3.f}, + {-3.f, -5.f}, + {-5.f, 3.f}}; // Beware out of bounds error! \[^_^]/ // And only process pixels that need extra rendering if (index >= sceneInfo.size.x * sceneInfo.size.y / occupancyParameters.x || - (sceneInfo.pathTracingIteration > primitiveXYIds[index].y && // Still need to process iterations - primitiveXYIds[index].w == 0 && // Shadows? if so, compute soft shadows by randomizing light positions - sceneInfo.pathTracingIteration > 0 && sceneInfo.pathTracingIteration <= NB_MAX_ITERATIONS)) + (sceneInfo.pathTracingIteration > + primitiveXYIds[index].y && // Still need to process iterations + primitiveXYIds[index].w == 0 && // Shadows? if so, compute soft shadows + // by randomizing light positions + sceneInfo.pathTracingIteration > 0 && + sceneInfo.pathTracingIteration <= NB_MAX_ITERATIONS)) return; Ray ray; @@ -468,13 +512,16 @@ __global__ void k_standardRenderer(const int2 occupancyParameters, int device_sp bool antialiasingActivated = (sceneInfo.cameraType == ctAntialiazed); #ifdef NATURAL_DEPTHOFFIELD - if (postProcessingInfo.type != ppe_depthOfField && sceneInfo.pathTracingIteration >= NB_MAX_ITERATIONS) + if (postProcessingInfo.type != ppe_depthOfField && + sceneInfo.pathTracingIteration >= NB_MAX_ITERATIONS) { // Randomize view for natural depth of field float a = (postProcessingInfo.param1 / 20000.f); int rindex = index + sceneInfo.timestamp % (MAX_BITMAP_SIZE - 2); - ray.origin.x += randoms[rindex] * postProcessingBuffer[index].colorInfo.w * a; - ray.origin.y += randoms[rindex + 1] * postProcessingBuffer[index].colorInfo.w * a; + ray.origin.x += + randoms[rindex] * postProcessingBuffer[index].colorInfo.w * a; + ray.origin.y += + randoms[rindex + 1] * postProcessingBuffer[index].colorInfo.w * a; } #endif // NATURAL_DEPTHOFFIELD @@ -482,7 +529,9 @@ __global__ void k_standardRenderer(const int2 occupancyParameters, int device_sp if (sceneInfo.cameraType == ctOrthographic) { ray.direction.x = ray.origin.z * 0.001f * (x - (sceneInfo.size.x / 2)); - ray.direction.y = -ray.origin.z * 0.001f * (device_split + stream_split + y - (sceneInfo.size.y / 2)); + ray.direction.y = + -ray.origin.z * 0.001f * + (device_split + stream_split + y - (sceneInfo.size.y / 2)); ray.origin.x = ray.direction.x; ray.origin.y = ray.direction.y; } @@ -492,8 +541,11 @@ __global__ void k_standardRenderer(const int2 occupancyParameters, int device_sp float2 step; step.x = ratio * angles.w / (float)sceneInfo.size.x; step.y = angles.w / (float)sceneInfo.size.y; - ray.direction.x = ray.direction.x - step.x * (x - (sceneInfo.size.x / 2)); - ray.direction.y = ray.direction.y + step.y * (device_split + stream_split + y - (sceneInfo.size.y / 2)); + ray.direction.x = + ray.direction.x - step.x * (x - (sceneInfo.size.x / 2)); + ray.direction.y = + ray.direction.y + + step.y * (device_split + stream_split + y - (sceneInfo.size.y / 2)); } vectorRotation(ray.origin, rotationCenter, angles); @@ -507,9 +559,12 @@ __global__ void k_standardRenderer(const int2 occupancyParameters, int device_sp r.origin.x += AArotatedGrid[I].x; r.origin.y += AArotatedGrid[I].y; float4 c; - c = launchRayTracing(index, BoundingBoxes, nbActiveBoxes, primitives, nbActivePrimitives, lightInformation, - lightInformationSize, nbActiveLamps, materials, textures, randoms, r, sceneInfo, - postProcessingInfo, dof, primitiveXYIds[index]); + c = launchRayTracing(index, BoundingBoxes, nbActiveBoxes, + primitives, nbActivePrimitives, + lightInformation, lightInformationSize, + nbActiveLamps, materials, textures, randoms, r, + sceneInfo, postProcessingInfo, dof, + primitiveXYIds[index]); color += c; } else if (sceneInfo.pathTracingIteration >= NB_MAX_ITERATIONS) @@ -520,8 +575,10 @@ __global__ void k_standardRenderer(const int2 occupancyParameters, int device_sp // r.origin.x += AArotatedGrid[sceneInfo.pathTracingIteration%4].x; // r.origin.y += AArotatedGrid[sceneInfo.pathTracingIteration%4].y; } - color += launchRayTracing(index, BoundingBoxes, nbActiveBoxes, primitives, nbActivePrimitives, lightInformation, - lightInformationSize, nbActiveLamps, materials, textures, randoms, r, sceneInfo, + color += launchRayTracing(index, BoundingBoxes, nbActiveBoxes, primitives, + nbActivePrimitives, lightInformation, + lightInformationSize, nbActiveLamps, materials, + textures, randoms, r, sceneInfo, postProcessingInfo, dof, primitiveXYIds[index]); if (sceneInfo.advancedIllumination == aiRandomIllumination) @@ -550,66 +607,84 @@ __global__ void k_standardRenderer(const int2 occupancyParameters, int device_sp else { postProcessingBuffer[index].sceneInfo.x = - (primitiveXYIds[index].z > 0) ? max(postProcessingBuffer[index].sceneInfo.x, color.x) : color.x; + (primitiveXYIds[index].z > 0) + ? max(postProcessingBuffer[index].sceneInfo.x, color.x) + : color.x; postProcessingBuffer[index].sceneInfo.y = - (primitiveXYIds[index].z > 0) ? max(postProcessingBuffer[index].sceneInfo.y, color.y) : color.y; + (primitiveXYIds[index].z > 0) + ? max(postProcessingBuffer[index].sceneInfo.y, color.y) + : color.y; postProcessingBuffer[index].sceneInfo.z = - (primitiveXYIds[index].z > 0) ? max(postProcessingBuffer[index].sceneInfo.z, color.z) : color.z; - - postProcessingBuffer[index].colorInfo.x += postProcessingBuffer[index].sceneInfo.x; - postProcessingBuffer[index].colorInfo.y += postProcessingBuffer[index].sceneInfo.y; - postProcessingBuffer[index].colorInfo.z += postProcessingBuffer[index].sceneInfo.z; + (primitiveXYIds[index].z > 0) + ? max(postProcessingBuffer[index].sceneInfo.z, color.z) + : color.z; + + postProcessingBuffer[index].colorInfo.x += + postProcessingBuffer[index].sceneInfo.x; + postProcessingBuffer[index].colorInfo.y += + postProcessingBuffer[index].sceneInfo.y; + postProcessingBuffer[index].colorInfo.z += + postProcessingBuffer[index].sceneInfo.z; } } /*! -* ------------------------------------------------------------------------------------------------------------------------ -* \brief This kernel processes a "standard" image, meaning that the screen is a single image for -* which every pixel is a ray of light entering the same camera. -* ------------------------------------------------------------------------------------------------------------------------ -* \param[in] occupancyParameters Contains the number of GPUs and streams involded in the GPU processing -* \param[in] device_split Y coordinate from where the current GPU should start working -* \param[in] stream_split Y coordinate from where the current stream should start working -* \param[in] BoundingBoxes Pointer to the array of bounding boxes -* \param[in] nbActiveBoxes Number of bounding boxes -* \param[in] primitives Pointer to the array of primitives -* \param[in] nbActivePrimitives Number of primitives -* \param[in] lightInformation Pointer to the array of light positions and intensities (Used for global illumination) -* \param[in] lightInformationSize Number of lights -* \param[in] nbActiveLamps Number of lamps -* \param[in] materials Pointer to the array of materials -* \param[in] textures Pointer to the array of textures -* \param[in] randoms Pointer to the array of random floats (GPUs are not good at generating numbers, done by the CPU) -* \param[in] origin Camera position -* \param[in] direction Camera LookAt -* \param[in] angles Angles applied to the camera. The rotation center is {0,0,0} -* \param[in] sceneInfo Information about the scene and environment -* \param[in] postProcessingInfo Information about PostProcessing effect -* \param[out] postProcessingBuffer Pointer to the output array of color information -* \param[out] primitiveXYIds Pointer to the array containing the Id of the primitivive for each pixel -* ------------------------------------------------------------------------------------------------------------------------ -*/ -__global__ void k_volumeRenderer(const int2 occupancyParameters, int device_split, int stream_split, - BoundingBox* BoundingBoxes, int nbActiveBoxes, Primitive* primitives, - int nbActivePrimitives, LightInformation* lightInformation, int lightInformationSize, - int nbActiveLamps, Material* materials, BitmapBuffer* textures, RandomBuffer* randoms, - vec3f origin, vec3f direction, vec4f angles, SceneInfo sceneInfo, - PostProcessingInfo postProcessingInfo, PostProcessingBuffer* postProcessingBuffer, - PrimitiveXYIdBuffer* primitiveXYIds) + * ------------------------------------------------------------------------------------------------------------------------ + * \brief This kernel processes a "standard" image, meaning that the screen + * is a single image for which every pixel is a ray of light entering the same + * camera. + * ------------------------------------------------------------------------------------------------------------------------ + * \param[in] occupancyParameters Contains the number of GPUs and streams + * involded in the GPU processing \param[in] device_split Y coordinate from + * where the current GPU should start working \param[in] stream_split Y + * coordinate from where the current stream should start working \param[in] + * BoundingBoxes Pointer to the array of bounding boxes \param[in] nbActiveBoxes + * Number of bounding boxes \param[in] primitives Pointer to the array of + * primitives \param[in] nbActivePrimitives Number of primitives \param[in] + * lightInformation Pointer to the array of light positions and intensities + * (Used for global illumination) \param[in] lightInformationSize Number of + * lights \param[in] nbActiveLamps Number of lamps \param[in] materials + * Pointer to the array of materials \param[in] textures Pointer to the array + * of textures \param[in] randoms Pointer to the array of random floats (GPUs + * are not good at generating numbers, done by the CPU) \param[in] origin + * Camera position \param[in] direction Camera LookAt \param[in] angles Angles + * applied to the camera. The rotation center is {0,0,0} \param[in] sceneInfo + * Information about the scene and environment \param[in] postProcessingInfo + * Information about PostProcessing effect \param[out] postProcessingBuffer + * Pointer to the output array of color information \param[out] primitiveXYIds + * Pointer to the array containing the Id of the primitivive for each pixel + * ------------------------------------------------------------------------------------------------------------------------ + */ +__global__ void k_volumeRenderer( + const int2 occupancyParameters, int device_split, int stream_split, + BoundingBox* BoundingBoxes, int nbActiveBoxes, Primitive* primitives, + int nbActivePrimitives, LightInformation* lightInformation, + int lightInformationSize, int nbActiveLamps, Material* materials, + BitmapBuffer* textures, RandomBuffer* randoms, vec3f origin, + vec3f direction, vec4f angles, SceneInfo sceneInfo, + PostProcessingInfo postProcessingInfo, + PostProcessingBuffer* postProcessingBuffer, + PrimitiveXYIdBuffer* primitiveXYIds) { int x = blockDim.x * blockIdx.x + threadIdx.x; int y = blockDim.y * blockIdx.y + threadIdx.y; int index = (stream_split + y) * sceneInfo.size.x + x; // Antialisazing - float2 AArotatedGrid[4] = {{3.f, 5.f}, {5.f, -3.f}, {-3.f, -5.f}, {-5.f, 3.f}}; + float2 AArotatedGrid[4] = {{3.f, 5.f}, + {5.f, -3.f}, + {-3.f, -5.f}, + {-5.f, 3.f}}; // Beware out of bounds error! \[^_^]/ // And only process pixels that need extra rendering if (index >= sceneInfo.size.x * sceneInfo.size.y / occupancyParameters.x || - (sceneInfo.pathTracingIteration > primitiveXYIds[index].y && // Still need to process iterations - primitiveXYIds[index].w == 0 && // Shadows? if so, compute soft shadows by randomizing light positions - sceneInfo.pathTracingIteration > 0 && sceneInfo.pathTracingIteration <= NB_MAX_ITERATIONS)) + (sceneInfo.pathTracingIteration > + primitiveXYIds[index].y && // Still need to process iterations + primitiveXYIds[index].w == 0 && // Shadows? if so, compute soft shadows + // by randomizing light positions + sceneInfo.pathTracingIteration > 0 && + sceneInfo.pathTracingIteration <= NB_MAX_ITERATIONS)) return; Ray ray; @@ -622,20 +697,25 @@ __global__ void k_volumeRenderer(const int2 occupancyParameters, int device_spli bool antialiasingActivated = (sceneInfo.cameraType == ctAntialiazed); - if (postProcessingInfo.type != ppe_depthOfField && sceneInfo.pathTracingIteration >= NB_MAX_ITERATIONS) + if (postProcessingInfo.type != ppe_depthOfField && + sceneInfo.pathTracingIteration >= NB_MAX_ITERATIONS) { // Randomize view for natural depth of field float a = (postProcessingInfo.param1 / 20000.f); int rindex = index + sceneInfo.timestamp % (MAX_BITMAP_SIZE - 2); - ray.origin.x += randoms[rindex] * postProcessingBuffer[index].colorInfo.w * a; - ray.origin.y += randoms[rindex + 1] * postProcessingBuffer[index].colorInfo.w * a; + ray.origin.x += + randoms[rindex] * postProcessingBuffer[index].colorInfo.w * a; + ray.origin.y += + randoms[rindex + 1] * postProcessingBuffer[index].colorInfo.w * a; } float dof = 0.f; if (sceneInfo.cameraType == ctOrthographic) { ray.direction.x = ray.origin.z * 0.001f * (x - (sceneInfo.size.x / 2)); - ray.direction.y = -ray.origin.z * 0.001f * (device_split + stream_split + y - (sceneInfo.size.y / 2)); + ray.direction.y = + -ray.origin.z * 0.001f * + (device_split + stream_split + y - (sceneInfo.size.y / 2)); ray.origin.x = ray.direction.x; ray.origin.y = ray.direction.y; } @@ -645,8 +725,11 @@ __global__ void k_volumeRenderer(const int2 occupancyParameters, int device_spli float2 step; step.x = ratio * angles.w / (float)sceneInfo.size.x; step.y = angles.w / (float)sceneInfo.size.y; - ray.direction.x = ray.direction.x - step.x * (x - (sceneInfo.size.x / 2)); - ray.direction.y = ray.direction.y + step.y * (device_split + stream_split + y - (sceneInfo.size.y / 2)); + ray.direction.x = + ray.direction.x - step.x * (x - (sceneInfo.size.x / 2)); + ray.direction.y = + ray.direction.y + + step.y * (device_split + stream_split + y - (sceneInfo.size.y / 2)); } vectorRotation(ray.origin, rotationCenter, angles); @@ -660,19 +743,27 @@ __global__ void k_volumeRenderer(const int2 occupancyParameters, int device_spli r.direction.x = ray.direction.x + AArotatedGrid[I].x; r.direction.y = ray.direction.y + AArotatedGrid[I].y; float4 c; - c = launchVolumeRendering(index, BoundingBoxes, nbActiveBoxes, primitives, nbActivePrimitives, - lightInformation, lightInformationSize, nbActiveLamps, materials, textures, - randoms, r, sceneInfo, postProcessingInfo, dof, primitiveXYIds[index]); + c = launchVolumeRendering(index, BoundingBoxes, nbActiveBoxes, + primitives, nbActivePrimitives, + lightInformation, lightInformationSize, + nbActiveLamps, materials, textures, + randoms, r, sceneInfo, postProcessingInfo, + dof, primitiveXYIds[index]); color += c; } else { - r.direction.x = ray.direction.x + AArotatedGrid[sceneInfo.pathTracingIteration % 4].x; - r.direction.y = ray.direction.y + AArotatedGrid[sceneInfo.pathTracingIteration % 4].y; + r.direction.x = ray.direction.x + + AArotatedGrid[sceneInfo.pathTracingIteration % 4].x; + r.direction.y = ray.direction.y + + AArotatedGrid[sceneInfo.pathTracingIteration % 4].y; } - color += launchVolumeRendering(index, BoundingBoxes, nbActiveBoxes, primitives, nbActivePrimitives, - lightInformation, lightInformationSize, nbActiveLamps, materials, textures, randoms, - r, sceneInfo, postProcessingInfo, dof, primitiveXYIds[index]); + color += + launchVolumeRendering(index, BoundingBoxes, nbActiveBoxes, primitives, + nbActivePrimitives, lightInformation, + lightInformationSize, nbActiveLamps, materials, + textures, randoms, r, sceneInfo, + postProcessingInfo, dof, primitiveXYIds[index]); if (sceneInfo.advancedIllumination == aiRandomIllumination) { @@ -700,51 +791,61 @@ __global__ void k_volumeRenderer(const int2 occupancyParameters, int device_spli else { postProcessingBuffer[index].sceneInfo.x = - (primitiveXYIds[index].z > 0) ? max(postProcessingBuffer[index].sceneInfo.x, color.x) : color.x; + (primitiveXYIds[index].z > 0) + ? max(postProcessingBuffer[index].sceneInfo.x, color.x) + : color.x; postProcessingBuffer[index].sceneInfo.y = - (primitiveXYIds[index].z > 0) ? max(postProcessingBuffer[index].sceneInfo.y, color.y) : color.y; + (primitiveXYIds[index].z > 0) + ? max(postProcessingBuffer[index].sceneInfo.y, color.y) + : color.y; postProcessingBuffer[index].sceneInfo.z = - (primitiveXYIds[index].z > 0) ? max(postProcessingBuffer[index].sceneInfo.z, color.z) : color.z; - - postProcessingBuffer[index].colorInfo.x += postProcessingBuffer[index].sceneInfo.x; - postProcessingBuffer[index].colorInfo.y += postProcessingBuffer[index].sceneInfo.y; - postProcessingBuffer[index].colorInfo.z += postProcessingBuffer[index].sceneInfo.z; + (primitiveXYIds[index].z > 0) + ? max(postProcessingBuffer[index].sceneInfo.z, color.z) + : color.z; + + postProcessingBuffer[index].colorInfo.x += + postProcessingBuffer[index].sceneInfo.x; + postProcessingBuffer[index].colorInfo.y += + postProcessingBuffer[index].sceneInfo.y; + postProcessingBuffer[index].colorInfo.z += + postProcessingBuffer[index].sceneInfo.z; } } /*! -* ------------------------------------------------------------------------------------------------------------------------ -* \brief This kernel processes a fisheye image -* ------------------------------------------------------------------------------------------------------------------------ -* \param[in] occupancyParameters Contains the number of GPUs and streams involded in the GPU processing -* \param[in] device_split Y coordinate from where the current GPU should start working -* \param[in] stream_split Y coordinate from where the current stream should start working -* \param[in] BoundingBoxes Pointer to the array of bounding boxes -* \param[in] nbActiveBoxes Number of bounding boxes -* \param[in] primitives Pointer to the array of primitives -* \param[in] nbActivePrimitives Number of primitives -* \param[in] lightInformation Pointer to the array of light positions and intensities (Used for global illumination) -* \param[in] lightInformationSize Number of lights -* \param[in] nbActiveLamps Number of lamps -* \param[in] materials Pointer to the array of materials -* \param[in] textures Pointer to the array of textures -* \param[in] randoms Pointer to the array of random floats (GPUs are not good at generating numbers, done by the CPU) -* \param[in] origin Camera position -* \param[in] direction Camera LookAt -* \param[in] angles Angles applied to the camera. The rotation center is {0,0,0} -* \param[in] sceneInfo Information about the scene and environment -* \param[in] postProcessingInfo Information about PostProcessing effect -* \param[out] postProcessingBuffer Pointer to the output array of color information -* \param[out] primitiveXYIds Pointer to the array containing the Id of the primitivive for each pixel -* ------------------------------------------------------------------------------------------------------------------------ -*/ -__global__ void k_fishEyeRenderer(const int2 occupancyParameters, int split_y, BoundingBox* BoundingBoxes, - int nbActiveBoxes, Primitive* primitives, int nbActivePrimitives, - LightInformation* lightInformation, int lightInformationSize, int nbActiveLamps, - Material* materials, BitmapBuffer* textures, RandomBuffer* randoms, vec3f origin, - vec3f direction, vec4f angles, SceneInfo sceneInfo, - PostProcessingInfo postProcessingInfo, PostProcessingBuffer* postProcessingBuffer, - PrimitiveXYIdBuffer* primitiveXYIds) + * ------------------------------------------------------------------------------------------------------------------------ + * \brief This kernel processes a fisheye image + * ------------------------------------------------------------------------------------------------------------------------ + * \param[in] occupancyParameters Contains the number of GPUs and streams + * involded in the GPU processing \param[in] device_split Y coordinate from + * where the current GPU should start working \param[in] stream_split Y + * coordinate from where the current stream should start working \param[in] + * BoundingBoxes Pointer to the array of bounding boxes \param[in] nbActiveBoxes + * Number of bounding boxes \param[in] primitives Pointer to the array of + * primitives \param[in] nbActivePrimitives Number of primitives \param[in] + * lightInformation Pointer to the array of light positions and intensities + * (Used for global illumination) \param[in] lightInformationSize Number of + * lights \param[in] nbActiveLamps Number of lamps \param[in] materials + * Pointer to the array of materials \param[in] textures Pointer to the array + * of textures \param[in] randoms Pointer to the array of random floats (GPUs + * are not good at generating numbers, done by the CPU) \param[in] origin + * Camera position \param[in] direction Camera LookAt \param[in] angles Angles + * applied to the camera. The rotation center is {0,0,0} \param[in] sceneInfo + * Information about the scene and environment \param[in] postProcessingInfo + * Information about PostProcessing effect \param[out] postProcessingBuffer + * Pointer to the output array of color information \param[out] primitiveXYIds + * Pointer to the array containing the Id of the primitivive for each pixel + * ------------------------------------------------------------------------------------------------------------------------ + */ +__global__ void k_fishEyeRenderer( + const int2 occupancyParameters, int split_y, BoundingBox* BoundingBoxes, + int nbActiveBoxes, Primitive* primitives, int nbActivePrimitives, + LightInformation* lightInformation, int lightInformationSize, + int nbActiveLamps, Material* materials, BitmapBuffer* textures, + RandomBuffer* randoms, vec3f origin, vec3f direction, vec4f angles, + SceneInfo sceneInfo, PostProcessingInfo postProcessingInfo, + PostProcessingBuffer* postProcessingBuffer, + PrimitiveXYIdBuffer* primitiveXYIds) { int x = blockDim.x * blockIdx.x + threadIdx.x; int y = blockDim.y * blockIdx.y + threadIdx.y; @@ -753,9 +854,12 @@ __global__ void k_fishEyeRenderer(const int2 occupancyParameters, int split_y, B // Beware out of bounds error! \[^_^]/ // And only process pixels that need extra rendering if (index >= sceneInfo.size.x * sceneInfo.size.y / occupancyParameters.x || - (sceneInfo.pathTracingIteration > primitiveXYIds[index].y && // Still need to process iterations - primitiveXYIds[index].w == 0 && // Shadows? if so, compute soft shadows by randomizing light positions - sceneInfo.pathTracingIteration > 0 && sceneInfo.pathTracingIteration <= NB_MAX_ITERATIONS)) + (sceneInfo.pathTracingIteration > + primitiveXYIds[index].y && // Still need to process iterations + primitiveXYIds[index].w == 0 && // Shadows? if so, compute soft shadows + // by randomizing light positions + sceneInfo.pathTracingIteration > 0 && + sceneInfo.pathTracingIteration <= NB_MAX_ITERATIONS)) return; Ray ray; @@ -766,12 +870,17 @@ __global__ void k_fishEyeRenderer(const int2 occupancyParameters, int split_y, B if (sceneInfo.pathTracingIteration >= NB_MAX_ITERATIONS) { int rindex = (index + sceneInfo.timestamp) % (MAX_BITMAP_SIZE - 3); - float a = float(sceneInfo.pathTracingIteration) / float(sceneInfo.maxPathTracingIterations); - ray.direction.x += randoms[rindex] * postProcessingBuffer[index].colorInfo.w * postProcessingInfo.param2 * a; - ray.direction.y += - randoms[rindex + 1] * postProcessingBuffer[index].colorInfo.w * postProcessingInfo.param2 * a; - ray.direction.z += - randoms[rindex + 2] * postProcessingBuffer[index].colorInfo.w * postProcessingInfo.param2 * a; + float a = float(sceneInfo.pathTracingIteration) / + float(sceneInfo.maxPathTracingIterations); + ray.direction.x += randoms[rindex] * + postProcessingBuffer[index].colorInfo.w * + postProcessingInfo.param2 * a; + ray.direction.y += randoms[rindex + 1] * + postProcessingBuffer[index].colorInfo.w * + postProcessingInfo.param2 * a; + ray.direction.z += randoms[rindex + 2] * + postProcessingBuffer[index].colorInfo.w * + postProcessingInfo.param2 * a; } float dof = 0.f; @@ -779,7 +888,8 @@ __global__ void k_fishEyeRenderer(const int2 occupancyParameters, int split_y, B // Normal Y axis float2 step; step.y = angles.w / (float)sceneInfo.size.y; - ray.direction.y = ray.direction.y + step.y * (float)(split_y + y - (sceneInfo.size.y / 2)); + ray.direction.y = ray.direction.y + + step.y * (float)(split_y + y - (sceneInfo.size.y / 2)); // 360° X axis step.x = 2.f * PI / sceneInfo.size.x; @@ -791,8 +901,10 @@ __global__ void k_fishEyeRenderer(const int2 occupancyParameters, int split_y, B vectorRotation(ray.direction, ray.origin, fishEyeAngles); float4 color = {0.f, 0.f, 0.f, 0.f}; - color += launchRayTracing(index, BoundingBoxes, nbActiveBoxes, primitives, nbActivePrimitives, lightInformation, - lightInformationSize, nbActiveLamps, materials, textures, randoms, ray, sceneInfo, + color += launchRayTracing(index, BoundingBoxes, nbActiveBoxes, primitives, + nbActivePrimitives, lightInformation, + lightInformationSize, nbActiveLamps, materials, + textures, randoms, ray, sceneInfo, postProcessingInfo, dof, primitiveXYIds[index]); if (sceneInfo.pathTracingIteration == 0) @@ -813,36 +925,39 @@ __global__ void k_fishEyeRenderer(const int2 occupancyParameters, int split_y, B } /*! -* ------------------------------------------------------------------------------------------------------------------------ -* \brief This kernel processes an anaglyph image. The sceneInfo.eyeSeparation parameter specifies the distance -* between both eyes. -* ------------------------------------------------------------------------------------------------------------------------ -* \param[in] occupancyParameters Contains the number of GPUs and streams involded in the GPU processing -* \param[in] BoundingBoxes Pointer to the array of bounding boxes -* \param[in] nbActiveBoxes Number of bounding boxes -* \param[in] primitives Pointer to the array of primitives -* \param[in] nbActivePrimitives Number of primitives -* \param[in] lightInformation Pointer to the array of light positions and intensities (Used for global illumination) -* \param[in] lightInformationSize Number of lights -* \param[in] nbActiveLamps Number of lamps -* \param[in] materials Pointer to the array of materials -* \param[in] textures Pointer to the array of textures -* \param[in] randoms Pointer to the array of random floats (GPUs are not good at generating numbers, done by the CPU) -* \param[in] origin Camera position -* \param[in] direction Camera LookAt -* \param[in] angles Angles applied to the camera. The rotation center is {0,0,0} -* \param[in] sceneInfo Information about the scene and environment -* \param[in] postProcessingInfo Information about PostProcessing effect -* \param[out] postProcessingBuffer Pointer to the output array of color information -* \param[out] primitiveXYIds Pointer to the array containing the Id of the primitivive for each pixel -* ------------------------------------------------------------------------------------------------------------------------ -*/ -__global__ void k_anaglyphRenderer(const int2 occupancyParameters, BoundingBox* boundingBoxes, int nbActiveBoxes, - Primitive* primitives, int nbActivePrimitives, LightInformation* lightInformation, - int lightInformationSize, int nbActiveLamps, Material* materials, - BitmapBuffer* textures, RandomBuffer* randoms, vec3f origin, vec3f direction, - vec4f angles, SceneInfo sceneInfo, PostProcessingInfo postProcessingInfo, - PostProcessingBuffer* postProcessingBuffer, PrimitiveXYIdBuffer* primitiveXYIds) + * ------------------------------------------------------------------------------------------------------------------------ + * \brief This kernel processes an anaglyph image. The + * sceneInfo.eyeSeparation parameter specifies the distance between both eyes. + * ------------------------------------------------------------------------------------------------------------------------ + * \param[in] occupancyParameters Contains the number of GPUs and streams + * involded in the GPU processing \param[in] BoundingBoxes Pointer to the array + * of bounding boxes \param[in] nbActiveBoxes Number of bounding boxes + * \param[in] primitives Pointer to the array of primitives + * \param[in] nbActivePrimitives Number of primitives + * \param[in] lightInformation Pointer to the array of light positions and + * intensities (Used for global illumination) \param[in] lightInformationSize + * Number of lights \param[in] nbActiveLamps Number of lamps \param[in] + * materials Pointer to the array of materials \param[in] textures Pointer to + * the array of textures \param[in] randoms Pointer to the array of random + * floats (GPUs are not good at generating numbers, done by the CPU) \param[in] + * origin Camera position \param[in] direction Camera LookAt \param[in] angles + * Angles applied to the camera. The rotation center is {0,0,0} \param[in] + * sceneInfo Information about the scene and environment \param[in] + * postProcessingInfo Information about PostProcessing effect \param[out] + * postProcessingBuffer Pointer to the output array of color information + * \param[out] primitiveXYIds Pointer to the array containing the Id of the + * primitivive for each pixel + * ------------------------------------------------------------------------------------------------------------------------ + */ +__global__ void k_anaglyphRenderer( + const int2 occupancyParameters, BoundingBox* boundingBoxes, + int nbActiveBoxes, Primitive* primitives, int nbActivePrimitives, + LightInformation* lightInformation, int lightInformationSize, + int nbActiveLamps, Material* materials, BitmapBuffer* textures, + RandomBuffer* randoms, vec3f origin, vec3f direction, vec4f angles, + SceneInfo sceneInfo, PostProcessingInfo postProcessingInfo, + PostProcessingBuffer* postProcessingBuffer, + PrimitiveXYIdBuffer* primitiveXYIds) { int x = blockDim.x * blockIdx.x + threadIdx.x; int y = blockDim.y * blockIdx.y + threadIdx.y; @@ -851,9 +966,12 @@ __global__ void k_anaglyphRenderer(const int2 occupancyParameters, BoundingBox* // Beware out of bounds error! \[^_^]/ // And only process pixels that need extra rendering if (index >= sceneInfo.size.x * sceneInfo.size.y / occupancyParameters.x || - (sceneInfo.pathTracingIteration > primitiveXYIds[index].y && // Still need to process iterations - primitiveXYIds[index].w == 0 && // Shadows? if so, compute soft shadows by randomizing light positions - sceneInfo.pathTracingIteration > 0 && sceneInfo.pathTracingIteration <= NB_MAX_ITERATIONS)) + (sceneInfo.pathTracingIteration > + primitiveXYIds[index].y && // Still need to process iterations + primitiveXYIds[index].w == 0 && // Shadows? if so, compute soft shadows + // by randomizing light positions + sceneInfo.pathTracingIteration > 0 && + sceneInfo.pathTracingIteration <= NB_MAX_ITERATIONS)) return; vec3f rotationCenter = {0.f, 0.f, 0.f}; @@ -873,34 +991,45 @@ __global__ void k_anaglyphRenderer(const int2 occupancyParameters, BoundingBox* eyeRay.origin.y = origin.y; eyeRay.origin.z = origin.z; - eyeRay.direction.x = direction.x - step.x * (float)(x - (sceneInfo.size.x / 2)); - eyeRay.direction.y = direction.y + step.y * (float)(y - (sceneInfo.size.y / 2)); + eyeRay.direction.x = + direction.x - step.x * (float)(x - (sceneInfo.size.x / 2)); + eyeRay.direction.y = + direction.y + step.y * (float)(y - (sceneInfo.size.y / 2)); eyeRay.direction.z = direction.z; vectorRotation(eyeRay.origin, rotationCenter, angles); vectorRotation(eyeRay.direction, rotationCenter, angles); - float4 colorLeft = launchRayTracing(index, boundingBoxes, nbActiveBoxes, primitives, nbActivePrimitives, - lightInformation, lightInformationSize, nbActiveLamps, materials, textures, - randoms, eyeRay, sceneInfo, postProcessingInfo, dof, primitiveXYIds[index]); + float4 colorLeft = + launchRayTracing(index, boundingBoxes, nbActiveBoxes, primitives, + nbActivePrimitives, lightInformation, + lightInformationSize, nbActiveLamps, materials, + textures, randoms, eyeRay, sceneInfo, + postProcessingInfo, dof, primitiveXYIds[index]); // Right eye eyeRay.origin.x = origin.x + sceneInfo.eyeSeparation; eyeRay.origin.y = origin.y; eyeRay.origin.z = origin.z; - eyeRay.direction.x = direction.x - step.x * (float)(x - (sceneInfo.size.x / 2)); - eyeRay.direction.y = direction.y + step.y * (float)(y - (sceneInfo.size.y / 2)); + eyeRay.direction.x = + direction.x - step.x * (float)(x - (sceneInfo.size.x / 2)); + eyeRay.direction.y = + direction.y + step.y * (float)(y - (sceneInfo.size.y / 2)); eyeRay.direction.z = direction.z; vectorRotation(eyeRay.origin, rotationCenter, angles); vectorRotation(eyeRay.direction, rotationCenter, angles); - float4 colorRight = launchRayTracing(index, boundingBoxes, nbActiveBoxes, primitives, nbActivePrimitives, - lightInformation, lightInformationSize, nbActiveLamps, materials, textures, - randoms, eyeRay, sceneInfo, postProcessingInfo, dof, primitiveXYIds[index]); + float4 colorRight = + launchRayTracing(index, boundingBoxes, nbActiveBoxes, primitives, + nbActivePrimitives, lightInformation, + lightInformationSize, nbActiveLamps, materials, + textures, randoms, eyeRay, sceneInfo, + postProcessingInfo, dof, primitiveXYIds[index]); - float r1 = colorLeft.x * 0.299f + colorLeft.y * 0.587f + colorLeft.z * 0.114f; + float r1 = + colorLeft.x * 0.299f + colorLeft.y * 0.587f + colorLeft.z * 0.114f; float b1 = 0.f; float g1 = 0.f; @@ -926,36 +1055,39 @@ __global__ void k_anaglyphRenderer(const int2 occupancyParameters, BoundingBox* } /*! -* ------------------------------------------------------------------------------------------------------------------------ -* \brief This kernel processes two images in a side-by-side format. The sceneInfo.eyeSeparation parameter specifies -* the distance between both eyes. -* ------------------------------------------------------------------------------------------------------------------------ -* \param[in] occupancyParameters Contains the number of GPUs and streams involded in the GPU processing -* \param[in] BoundingBoxes Pointer to the array of bounding boxes -* \param[in] nbActiveBoxes Number of bounding boxes -* \param[in] primitives Pointer to the array of primitives -* \param[in] nbActivePrimitives Number of primitives -* \param[in] lightInformation Pointer to the array of light positions and intensities (Used for global illumination) -* \param[in] lightInformationSize Number of lights -* \param[in] nbActiveLamps Number of lamps -* \param[in] materials Pointer to the array of materials -* \param[in] textures Pointer to the array of textures -* \param[in] randoms Pointer to the array of random floats (GPUs are not good at generating numbers, done by the CPU) -* \param[in] origin Camera position -* \param[in] direction Camera LookAt -* \param[in] angles Angles applied to the camera. The rotation center is {0,0,0} -* \param[in] sceneInfo Information about the scene and environment -* \param[in] postProcessingInfo Information about PostProcessing effect -* \param[out] postProcessingBuffer Pointer to the output array of color information -* \param[out] primitiveXYIds Pointer to the array containing the Id of the primitivive for each pixel -* ------------------------------------------------------------------------------------------------------------------------ -*/ -__global__ void k_3DVisionRenderer(const int2 occupancyParameters, BoundingBox* boundingBoxes, int nbActiveBoxes, - Primitive* primitives, int nbActivePrimitives, LightInformation* lightInformation, - int lightInformationSize, int nbActiveLamps, Material* materials, - BitmapBuffer* textures, RandomBuffer* randoms, vec3f origin, vec3f direction, - vec4f angles, SceneInfo sceneInfo, PostProcessingInfo postProcessingInfo, - PostProcessingBuffer* postProcessingBuffer, PrimitiveXYIdBuffer* primitiveXYIds) + * ------------------------------------------------------------------------------------------------------------------------ + * \brief This kernel processes two images in a side-by-side format. The + * sceneInfo.eyeSeparation parameter specifies the distance between both eyes. + * ------------------------------------------------------------------------------------------------------------------------ + * \param[in] occupancyParameters Contains the number of GPUs and streams + * involded in the GPU processing \param[in] BoundingBoxes Pointer to the array + * of bounding boxes \param[in] nbActiveBoxes Number of bounding boxes + * \param[in] primitives Pointer to the array of primitives + * \param[in] nbActivePrimitives Number of primitives + * \param[in] lightInformation Pointer to the array of light positions and + * intensities (Used for global illumination) \param[in] lightInformationSize + * Number of lights \param[in] nbActiveLamps Number of lamps \param[in] + * materials Pointer to the array of materials \param[in] textures Pointer to + * the array of textures \param[in] randoms Pointer to the array of random + * floats (GPUs are not good at generating numbers, done by the CPU) \param[in] + * origin Camera position \param[in] direction Camera LookAt \param[in] angles + * Angles applied to the camera. The rotation center is {0,0,0} \param[in] + * sceneInfo Information about the scene and environment \param[in] + * postProcessingInfo Information about PostProcessing effect \param[out] + * postProcessingBuffer Pointer to the output array of color information + * \param[out] primitiveXYIds Pointer to the array containing the Id of the + * primitivive for each pixel + * ------------------------------------------------------------------------------------------------------------------------ + */ +__global__ void k_3DVisionRenderer( + const int2 occupancyParameters, BoundingBox* boundingBoxes, + int nbActiveBoxes, Primitive* primitives, int nbActivePrimitives, + LightInformation* lightInformation, int lightInformationSize, + int nbActiveLamps, Material* materials, BitmapBuffer* textures, + RandomBuffer* randoms, vec3f origin, vec3f direction, vec4f angles, + SceneInfo sceneInfo, PostProcessingInfo postProcessingInfo, + PostProcessingBuffer* postProcessingBuffer, + PrimitiveXYIdBuffer* primitiveXYIds) { int x = blockDim.x * blockIdx.x + threadIdx.x; int y = blockDim.y * blockIdx.y + threadIdx.y; @@ -964,12 +1096,18 @@ __global__ void k_3DVisionRenderer(const int2 occupancyParameters, BoundingBox* // Beware out of bounds error! \[^_^]/ // And only process pixels that need extra rendering if (index >= sceneInfo.size.x * sceneInfo.size.y / occupancyParameters.x || - (sceneInfo.pathTracingIteration > primitiveXYIds[index].y && // Still need to process iterations - primitiveXYIds[index].w == 0 && // Shadows? if so, compute soft shadows by randomizing light positions - sceneInfo.pathTracingIteration > 0 && sceneInfo.pathTracingIteration <= NB_MAX_ITERATIONS)) + (sceneInfo.pathTracingIteration > + primitiveXYIds[index].y && // Still need to process iterations + primitiveXYIds[index].w == 0 && // Shadows? if so, compute soft shadows + // by randomizing light positions + sceneInfo.pathTracingIteration > 0 && + sceneInfo.pathTracingIteration <= NB_MAX_ITERATIONS)) return; - float focus = fabs(postProcessingBuffer[sceneInfo.size.x / 2 * sceneInfo.size.y / 2].colorInfo.w - origin.z); + float focus = + fabs(postProcessingBuffer[sceneInfo.size.x / 2 * sceneInfo.size.y / 2] + .colorInfo.w - + origin.z); float eyeSeparation = sceneInfo.eyeSeparation * (direction.z / focus); vec3f rotationCenter = {0.f, 0.f, 0.f}; @@ -993,8 +1131,11 @@ __global__ void k_3DVisionRenderer(const int2 occupancyParameters, BoundingBox* eyeRay.origin.z = origin.z; eyeRay.direction.x = - direction.x - step.x * (float)(x - (sceneInfo.size.x / 2) + halfWidth / 2) + sceneInfo.eyeSeparation; - eyeRay.direction.y = direction.y + step.y * (float)(y - (sceneInfo.size.y / 2)); + direction.x - + step.x * (float)(x - (sceneInfo.size.x / 2) + halfWidth / 2) + + sceneInfo.eyeSeparation; + eyeRay.direction.y = + direction.y + step.y * (float)(y - (sceneInfo.size.y / 2)); eyeRay.direction.z = direction.z; } else @@ -1005,17 +1146,23 @@ __global__ void k_3DVisionRenderer(const int2 occupancyParameters, BoundingBox* eyeRay.origin.z = origin.z; eyeRay.direction.x = - direction.x - step.x * (float)(x - (sceneInfo.size.x / 2) - halfWidth / 2) - sceneInfo.eyeSeparation; - eyeRay.direction.y = direction.y + step.y * (float)(y - (sceneInfo.size.y / 2)); + direction.x - + step.x * (float)(x - (sceneInfo.size.x / 2) - halfWidth / 2) - + sceneInfo.eyeSeparation; + eyeRay.direction.y = + direction.y + step.y * (float)(y - (sceneInfo.size.y / 2)); eyeRay.direction.z = direction.z; } vectorRotation(eyeRay.origin, rotationCenter, angles); vectorRotation(eyeRay.direction, rotationCenter, angles); - float4 color = launchRayTracing(index, boundingBoxes, nbActiveBoxes, primitives, nbActivePrimitives, - lightInformation, lightInformationSize, nbActiveLamps, materials, textures, randoms, - eyeRay, sceneInfo, postProcessingInfo, dof, primitiveXYIds[index]); + float4 color = + launchRayTracing(index, boundingBoxes, nbActiveBoxes, primitives, + nbActivePrimitives, lightInformation, + lightInformationSize, nbActiveLamps, materials, + textures, randoms, eyeRay, sceneInfo, + postProcessingInfo, dof, primitiveXYIds[index]); if (sceneInfo.advancedIllumination == aiRandomIllumination) { @@ -1043,19 +1190,22 @@ __global__ void k_3DVisionRenderer(const int2 occupancyParameters, BoundingBox* } /*! -* ------------------------------------------------------------------------------------------------------------------------ -* \brief This post-processing kernel simply converts the contents of the postProcessingBuffer into a bitmap -* ------------------------------------------------------------------------------------------------------------------------ -* \param[in] occupancyParameters Contains the number of GPUs and streams involded in the GPU processing -* \param[in] sceneInfo Information about the scene and environment -* \param[in] postProcessingInfo Information about PostProcessing effect -* \param[in] postProcessingBuffer Pointer to the output array of color information -* \param[out] Bitmap Pointer to a bitmap. The bitmap is encoded according to the value of the sceneInfo.frameBufferType -* parameter -* ------------------------------------------------------------------------------------------------------------------------ -*/ -__global__ void k_default(const int2 occupancyParameters, SceneInfo sceneInfo, PostProcessingInfo PostProcessingInfo, - PostProcessingBuffer* postProcessingBuffer, BitmapBuffer* bitmap) + * ------------------------------------------------------------------------------------------------- + * \brief This post-processing kernel simply converts the contents of the + * postProcessingBuffer into a bitmap + * ------------------------------------------------------------------------------------------------- + * \param[in] occupancyParameters Contains the number of GPUs and streams + * involded in the GPU processing \param[in] sceneInfo Information about the + * scene and environment \param[in] postProcessingInfo Information about + * PostProcessing effect \param[in] postProcessingBuffer Pointer to the output + * array of color information \param[out] Bitmap Pointer to a bitmap. The bitmap + * is encoded according to the value of the sceneInfo.frameBufferType parameter + * ------------------------------------------------------------------------------------------------- + */ +__global__ void k_default(const int2 occupancyParameters, SceneInfo sceneInfo, + PostProcessingInfo PostProcessingInfo, + PostProcessingBuffer* postProcessingBuffer, + BitmapBuffer* bitmap) { int x = blockDim.x * blockIdx.x + threadIdx.x; int y = blockDim.y * blockIdx.y + threadIdx.y; @@ -1067,7 +1217,8 @@ __global__ void k_default(const int2 occupancyParameters, SceneInfo sceneInfo, P float4 localColor = postProcessingBuffer[index].colorInfo; if (sceneInfo.pathTracingIteration > NB_MAX_ITERATIONS) - localColor /= (float)(sceneInfo.pathTracingIteration - NB_MAX_ITERATIONS + 1); + localColor /= + (float)(sceneInfo.pathTracingIteration - NB_MAX_ITERATIONS + 1); makeColor(sceneInfo, localColor, bitmap, index); } @@ -1078,8 +1229,10 @@ ________________________________________________________________________________ Post Processing Effect: Depth of field ________________________________________________________________________________ */ -__global__ void k_depthOfField(const int2 occupancyParameters, SceneInfo sceneInfo, - PostProcessingInfo postProcessingInfo, PostProcessingBuffer* postProcessingBuffer, +__global__ void k_depthOfField(const int2 occupancyParameters, + SceneInfo sceneInfo, + PostProcessingInfo postProcessingInfo, + PostProcessingBuffer* postProcessingBuffer, RandomBuffer* randoms, BitmapBuffer* bitmap) { int x = blockDim.x * blockIdx.x + threadIdx.x; @@ -1091,7 +1244,9 @@ __global__ void k_depthOfField(const int2 occupancyParameters, SceneInfo sceneIn return; float4 localColor = {0.f, 0.f, 0.f}; - float depth = fabs(postProcessingBuffer[index].colorInfo.w - postProcessingInfo.param1) / sceneInfo.viewDistance; + float depth = fabs(postProcessingBuffer[index].colorInfo.w - + postProcessingInfo.param1) / + sceneInfo.viewDistance; int wh = sceneInfo.size.x * sceneInfo.size.y; for (int i = 0; i < postProcessingInfo.param3; ++i) @@ -1100,7 +1255,8 @@ __global__ void k_depthOfField(const int2 occupancyParameters, SceneInfo sceneIn int iy = (i + 1000) % wh; int xx = x + depth * randoms[ix] * postProcessingInfo.param2; int yy = y + depth * randoms[iy] * postProcessingInfo.param2; - if (xx >= 0 && xx < sceneInfo.size.x && yy >= 0 && yy < sceneInfo.size.y) + if (xx >= 0 && xx < sceneInfo.size.x && yy >= 0 && + yy < sceneInfo.size.y) { int localIndex = yy * sceneInfo.size.x + xx; if (localIndex >= 0 && localIndex < wh) @@ -1112,7 +1268,8 @@ __global__ void k_depthOfField(const int2 occupancyParameters, SceneInfo sceneIn localColor /= postProcessingInfo.param3; if (sceneInfo.pathTracingIteration > NB_MAX_ITERATIONS) - localColor /= (float)(sceneInfo.pathTracingIteration - NB_MAX_ITERATIONS + 1); + localColor /= + (float)(sceneInfo.pathTracingIteration - NB_MAX_ITERATIONS + 1); localColor.w = 1.f; @@ -1125,8 +1282,10 @@ ________________________________________________________________________________ Post Processing Effect: Ambiant Occlusion ________________________________________________________________________________ */ -__global__ void k_ambiantOcclusion(const int2 occupancyParameters, SceneInfo sceneInfo, - PostProcessingInfo postProcessingInfo, PostProcessingBuffer* postProcessingBuffer, +__global__ void k_ambiantOcclusion(const int2 occupancyParameters, + SceneInfo sceneInfo, + PostProcessingInfo postProcessingInfo, + PostProcessingBuffer* postProcessingBuffer, RandomBuffer* randoms, BitmapBuffer* bitmap) { int x = blockDim.x * blockIdx.x + threadIdx.x; @@ -1153,7 +1312,8 @@ __global__ void k_ambiantOcclusion(const int2 occupancyParameters, SceneInfo sce c += 1.f; int xx = x + (X * postProcessingInfo.param2 * randoms[ix] / 10.f); int yy = y + (Y * postProcessingInfo.param2 * randoms[iy] / 10.f); - if (xx >= 0 && xx < sceneInfo.size.x && yy >= 0 && yy < sceneInfo.size.y) + if (xx >= 0 && xx < sceneInfo.size.x && yy >= 0 && + yy < sceneInfo.size.y) { int localIndex = yy * sceneInfo.size.x + xx; if (postProcessingBuffer[localIndex].colorInfo.w >= depth) @@ -1172,7 +1332,8 @@ __global__ void k_ambiantOcclusion(const int2 occupancyParameters, SceneInfo sce localColor.z *= occ; } if (sceneInfo.pathTracingIteration > NB_MAX_ITERATIONS) - localColor /= (float)(sceneInfo.pathTracingIteration - NB_MAX_ITERATIONS + 1); + localColor /= + (float)(sceneInfo.pathTracingIteration - NB_MAX_ITERATIONS + 1); saturateVector(localColor); localColor.w = 1.f; @@ -1186,8 +1347,10 @@ ________________________________________________________________________________ Post Processing Effect: Radiosity ________________________________________________________________________________ */ -__global__ void k_radiosity(const int2 occupancyParameters, SceneInfo sceneInfo, PostProcessingInfo postProcessingInfo, - PrimitiveXYIdBuffer* primitiveXYIds, PostProcessingBuffer* postProcessingBuffer, +__global__ void k_radiosity(const int2 occupancyParameters, SceneInfo sceneInfo, + PostProcessingInfo postProcessingInfo, + PrimitiveXYIdBuffer* primitiveXYIds, + PostProcessingBuffer* postProcessingBuffer, RandomBuffer* randoms, BitmapBuffer* bitmap) { int x = blockDim.x * blockIdx.x + threadIdx.x; @@ -1212,11 +1375,13 @@ __global__ void k_radiosity(const int2 occupancyParameters, SceneInfo sceneInfo, int xx = x + randoms[ix] * postProcessingInfo.param2; int yy = y + randoms[iy] * postProcessingInfo.param2; localColor += postProcessingBuffer[index].colorInfo; - if (xx >= 0 && xx < sceneInfo.size.x && yy >= 0 && yy < sceneInfo.size.y) + if (xx >= 0 && xx < sceneInfo.size.x && yy >= 0 && + yy < sceneInfo.size.y) { int localIndex = yy * sceneInfo.size.x + xx; float4 lightColor = postProcessingBuffer[localIndex].colorInfo; - localColor += lightColor * float(primitiveXYIds[localIndex].z) / 256.f; + localColor += + lightColor * float(primitiveXYIds[localIndex].z) / 256.f; } } localColor /= postProcessingInfo.param3; @@ -1233,8 +1398,10 @@ ________________________________________________________________________________ Post Processing Effect: Filters ________________________________________________________________________________ */ -__global__ void k_filter(const int2 occupancyParameters, SceneInfo sceneInfo, PostProcessingInfo postProcessingInfo, - PostProcessingBuffer* postProcessingBuffer, BitmapBuffer* bitmap) +__global__ void k_filter(const int2 occupancyParameters, SceneInfo sceneInfo, + PostProcessingInfo postProcessingInfo, + PostProcessingBuffer* postProcessingBuffer, + BitmapBuffer* bitmap) { int x = blockDim.x * blockIdx.x + threadIdx.x; int y = blockDim.y * blockIdx.y + threadIdx.y; @@ -1246,84 +1413,101 @@ __global__ void k_filter(const int2 occupancyParameters, SceneInfo sceneInfo, Po // Filters const uint NB_FILTERS = 6; - const int2 filterSize[NB_FILTERS] = {{3, 3}, {5, 5}, {3, 3}, {3, 3}, {5, 5}, {5, 5}}; - - const float2 filterFactors[NB_FILTERS] = {{1.f, 128.f}, {1.f, 0.f}, {1.f, 0.f}, - {1.f, 0.f}, {0.2f, 0.f}, {0.125f, 0.f}}; // Factor and Bias - - const float filterInfo[NB_FILTERS][5][5] = {{// Emboss - {-1.0f, -1.0f, 0.0f, 0.0f, 0.0f}, - {-1.0f, 0.0f, 1.0f, 0.0f, 0.0f}, - {0.0f, 1.0f, 1.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}}, - {// Find edges - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, - {-1.0f, -1.0f, 2.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}}, - {// Sharpen - {-1.0f, -1.0f, -1.0f, 0.0f, 0.0f}, - {-1.0f, 9.0f, -1.0f, 0.0f, 0.0f}, - {-1.0f, -1.0f, -1.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}}, - {// Blur - {0.0f, 0.2f, 0.0f, 0.0f, 0.0f}, - {0.2f, 0.2f, 0.2f, 0.0f, 0.0f}, - {0.0f, 0.2f, 0.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}}, - {// Motion Blur - {1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, - {0.0f, 1.0f, 0.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 1.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 1.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 0.0f, 1.0f}}, - {// Subtle Sharpen - {-1.0f, -1.0f, -1.0f, -1.0f, -1.0f}, - {-1.0f, 2.0f, 2.0f, 2.0f, -1.0f}, - {-1.0f, 2.0f, 8.0f, 2.0f, -1.0f}, - {-1.0f, 2.0f, 2.0f, 2.0f, -1.0f}, - {-1.0f, -1.0f, -1.0f, -1.0f, -1.0f}}}; + const int2 filterSize[NB_FILTERS] = {{3, 3}, {5, 5}, {3, 3}, + {3, 3}, {5, 5}, {5, 5}}; + + const float2 filterFactors[NB_FILTERS] = { + {1.f, 128.f}, {1.f, 0.f}, {1.f, 0.f}, + {1.f, 0.f}, {0.2f, 0.f}, {0.125f, 0.f}}; // Factor and Bias + + const float filterInfo[NB_FILTERS][5][5] = { + {// Emboss + {-1.0f, -1.0f, 0.0f, 0.0f, 0.0f}, + {-1.0f, 0.0f, 1.0f, 0.0f, 0.0f}, + {0.0f, 1.0f, 1.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}}, + {// Find edges + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, + {-1.0f, -1.0f, 2.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}}, + {// Sharpen + {-1.0f, -1.0f, -1.0f, 0.0f, 0.0f}, + {-1.0f, 9.0f, -1.0f, 0.0f, 0.0f}, + {-1.0f, -1.0f, -1.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}}, + {// Blur + {0.0f, 0.2f, 0.0f, 0.0f, 0.0f}, + {0.2f, 0.2f, 0.2f, 0.0f, 0.0f}, + {0.0f, 0.2f, 0.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}}, + {// Motion Blur + {1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, 1.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 1.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 1.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 0.0f, 1.0f}}, + {// Subtle Sharpen + {-1.0f, -1.0f, -1.0f, -1.0f, -1.0f}, + {-1.0f, 2.0f, 2.0f, 2.0f, -1.0f}, + {-1.0f, 2.0f, 8.0f, 2.0f, -1.0f}, + {-1.0f, 2.0f, 2.0f, 2.0f, -1.0f}, + {-1.0f, -1.0f, -1.0f, -1.0f, -1.0f}}}; float4 localColor = {0.f, 0.f, 0.f, 0.f}; float4 color = {0.f, 0.f, 0.f, 0.f}; if (postProcessingInfo.param3 < NB_FILTERS) { // multiply every value of the filter with corresponding image pixel - for (int filterX = 0; filterX < filterSize[postProcessingInfo.param3].x; filterX++) - for (int filterY = 0; filterY < filterSize[postProcessingInfo.param3].y; filterY++) + for (int filterX = 0; filterX < filterSize[postProcessingInfo.param3].x; + filterX++) + for (int filterY = 0; + filterY < filterSize[postProcessingInfo.param3].y; filterY++) { - int imageX = - (x - filterSize[postProcessingInfo.param3].x / 2 + filterX + sceneInfo.size.x) % sceneInfo.size.x; - int imageY = - (y - filterSize[postProcessingInfo.param3].y / 2 + filterY + sceneInfo.size.y) % sceneInfo.size.y; + int imageX = (x - filterSize[postProcessingInfo.param3].x / 2 + + filterX + sceneInfo.size.x) % + sceneInfo.size.x; + int imageY = (y - filterSize[postProcessingInfo.param3].y / 2 + + filterY + sceneInfo.size.y) % + sceneInfo.size.y; int localIndex = imageY * sceneInfo.size.x + imageX; float4 c = postProcessingBuffer[localIndex].colorInfo; if (sceneInfo.pathTracingIteration > NB_MAX_ITERATIONS) { - c /= (float)(sceneInfo.pathTracingIteration - NB_MAX_ITERATIONS + 1); + c /= (float)(sceneInfo.pathTracingIteration - + NB_MAX_ITERATIONS + 1); } - localColor.x += c.x * filterInfo[postProcessingInfo.param3][filterX][filterY]; - localColor.y += c.y * filterInfo[postProcessingInfo.param3][filterX][filterY]; - localColor.z += c.z * filterInfo[postProcessingInfo.param3][filterX][filterY]; + localColor.x += + c.x * + filterInfo[postProcessingInfo.param3][filterX][filterY]; + localColor.y += + c.y * + filterInfo[postProcessingInfo.param3][filterX][filterY]; + localColor.z += + c.z * + filterInfo[postProcessingInfo.param3][filterX][filterY]; } // truncate values smaller than zero and larger than 255 - color.x += min(max(filterFactors[postProcessingInfo.param3].x * localColor.x + - filterFactors[postProcessingInfo.param3].y / 255.f, - 0.f), - 1.f); - color.y += min(max(filterFactors[postProcessingInfo.param3].x * localColor.y + - filterFactors[postProcessingInfo.param3].y / 255.f, - 0.f), - 1.f); - color.z += min(max(filterFactors[postProcessingInfo.param3].x * localColor.z + - filterFactors[postProcessingInfo.param3].y / 255.f, - 0.f), - 1.f); + color.x += + min(max(filterFactors[postProcessingInfo.param3].x * localColor.x + + filterFactors[postProcessingInfo.param3].y / 255.f, + 0.f), + 1.f); + color.y += + min(max(filterFactors[postProcessingInfo.param3].x * localColor.y + + filterFactors[postProcessingInfo.param3].y / 255.f, + 0.f), + 1.f); + color.z += + min(max(filterFactors[postProcessingInfo.param3].x * localColor.z + + filterFactors[postProcessingInfo.param3].y / 255.f, + 0.f), + 1.f); } saturateVector(color); @@ -1338,8 +1522,10 @@ ________________________________________________________________________________ Post Processing Effect: Filters ________________________________________________________________________________ */ -__global__ void k_cartoon(const int2 occupancyParameters, SceneInfo sceneInfo, PostProcessingInfo postProcessingInfo, - PostProcessingBuffer* postProcessingBuffer, BitmapBuffer* bitmap) +__global__ void k_cartoon(const int2 occupancyParameters, SceneInfo sceneInfo, + PostProcessingInfo postProcessingInfo, + PostProcessingBuffer* postProcessingBuffer, + BitmapBuffer* bitmap) { int x = blockDim.x * blockIdx.x + threadIdx.x; int y = blockDim.y * blockIdx.y + threadIdx.y; @@ -1349,7 +1535,9 @@ __global__ void k_cartoon(const int2 occupancyParameters, SceneInfo sceneInfo, P if (index >= sceneInfo.size.x * sceneInfo.size.y / occupancyParameters.x) return; - float depth = sceneInfo.viewDistance / fabs(postProcessingBuffer[index].colorInfo.w - postProcessingInfo.param1); + float depth = + sceneInfo.viewDistance / fabs(postProcessingBuffer[index].colorInfo.w - + postProcessingInfo.param1); float4 color = {depth, depth, depth, 0.f}; saturateVector(color); color.w = 1.f; @@ -1371,31 +1559,36 @@ extern "C" void reshape_scene(int2 occupancyParameters, SceneInfo sceneInfo) FREECUDARESOURCE(d_primitivesXYIds[device]); // Randoms - size_t size = MAX_BITMAP_WIDTH * MAX_BITMAP_HEIGHT * sizeof(RandomBuffer); + size_t size = + MAX_BITMAP_WIDTH * MAX_BITMAP_HEIGHT * sizeof(RandomBuffer); LOG_INFO(3, "d_randoms: " << size << " bytes"); checkCudaErrors(cudaMalloc((void**)&d_randoms[device], size)); totalMemoryAllocation += size; // Post-processing - size = MAX_BITMAP_WIDTH * MAX_BITMAP_HEIGHT * sizeof(PostProcessingBuffer) / occupancyParameters.x; + size = MAX_BITMAP_WIDTH * MAX_BITMAP_HEIGHT * + sizeof(PostProcessingBuffer) / occupancyParameters.x; LOG_INFO(3, "d_postProcessingBuffer: " << size << " bytes"); - checkCudaErrors(cudaMalloc((void**)&d_postProcessingBuffer[device], size)); + checkCudaErrors( + cudaMalloc((void**)&d_postProcessingBuffer[device], size)); totalMemoryAllocation += size; // Bitmap - size = MAX_BITMAP_WIDTH * MAX_BITMAP_HEIGHT * gColorDepth * sizeof(BitmapBuffer) / occupancyParameters.x; + size = MAX_BITMAP_WIDTH * MAX_BITMAP_HEIGHT * gColorDepth * + sizeof(BitmapBuffer) / occupancyParameters.x; LOG_INFO(3, "d_bitmap: " << size << " bytes"); checkCudaErrors(cudaMalloc((void**)&d_bitmap[device], size)); totalMemoryAllocation += size; // Primitive IDs - size = MAX_BITMAP_WIDTH * MAX_BITMAP_HEIGHT * sizeof(PrimitiveXYIdBuffer) / occupancyParameters.x; + size = MAX_BITMAP_WIDTH * MAX_BITMAP_HEIGHT * + sizeof(PrimitiveXYIdBuffer) / occupancyParameters.x; LOG_INFO(3, "d_primitivesXYIds: " << size << " bytes"); checkCudaErrors(cudaMalloc((void**)&d_primitivesXYIds[device], size)); totalMemoryAllocation += size; - LOG_INFO(1, " - Total variable GPU memory allocated on device " << device << ": " << totalMemoryAllocation - << " bytes"); + LOG_INFO(1, " - Total variable GPU memory allocated on device " + << device << ": " << totalMemoryAllocation << " bytes"); } } @@ -1405,13 +1598,14 @@ ________________________________________________________________________________ GPU initialization ________________________________________________________________________________ */ -extern "C" void initialize_scene(int2 occupancyParameters, SceneInfo sceneInfo, int nbPrimitives, int nbLamps, - int nbMaterials +extern "C" void initialize_scene(int2 occupancyParameters, SceneInfo sceneInfo, + int nbPrimitives, int nbLamps, int nbMaterials #ifdef USE_MANAGED_MEMORY , - BoundingBox*& boundingBoxes, Primitive*& primitives + BoundingBox*& boundingBoxes, + Primitive*& primitives #endif - ) +) { // Multi GPU initialization int nbGPUs; @@ -1421,8 +1615,9 @@ extern "C" void initialize_scene(int2 occupancyParameters, SceneInfo sceneInfo, if (occupancyParameters.x > nbGPUs) { - LOG_INFO(1, "You asked for " << occupancyParameters.x << " CUDA-capable devices, but only " << nbGPUs - << " are available"); + LOG_INFO(1, "You asked for " << occupancyParameters.x + << " CUDA-capable devices, but only " + << nbGPUs << " are available"); occupancyParameters.x = nbGPUs; } else @@ -1434,13 +1629,15 @@ extern "C" void initialize_scene(int2 occupancyParameters, SceneInfo sceneInfo, checkCudaErrors(cudaSetDevice(device)); for (int stream(0); stream < occupancyParameters.y; ++stream) checkCudaErrors(cudaStreamCreate(&d_streams[device][stream])); - LOG_INFO(3, "Created " << occupancyParameters.y << " streams on device " << device); + LOG_INFO(3, "Created " << occupancyParameters.y << " streams on device " + << device); // Bounding boxes int size(NB_MAX_BOXES * sizeof(BoundingBox)); LOG_INFO(3, "d_boundingBoxes: " << size << " bytes"); #ifdef USE_MANAGED_MEMORY - checkCudaErrors(cudaMallocManaged(&boundingBoxes, size, cudaMemAttachHost)); + checkCudaErrors( + cudaMallocManaged(&boundingBoxes, size, cudaMemAttachHost)); #else checkCudaErrors(cudaMalloc((void**)&d_boundingBoxes[device], size)); #endif @@ -1450,7 +1647,8 @@ extern "C" void initialize_scene(int2 occupancyParameters, SceneInfo sceneInfo, size = NB_MAX_PRIMITIVES * sizeof(Primitive); LOG_INFO(3, "d_primitives: " << size << " bytes"); #ifdef USE_MANAGED_MEMORY - checkCudaErrors(cudaMallocManaged(&primitives, size, cudaMemAttachHost)); + checkCudaErrors( + cudaMallocManaged(&primitives, size, cudaMemAttachHost)); #else checkCudaErrors(cudaMalloc((void**)&d_primitives[device], size)); #endif @@ -1475,8 +1673,8 @@ extern "C" void initialize_scene(int2 occupancyParameters, SceneInfo sceneInfo, totalMemoryAllocation += size; d_textures[device] = 0; - LOG_INFO(3, "Total constant GPU memory allocated on device " << device << ": " << totalMemoryAllocation - << " bytes"); + LOG_INFO(3, "Total constant GPU memory allocated on device " + << device << ": " << totalMemoryAllocation << " bytes"); } LOG_INFO(3, "GPU: SceneInfo : " << sizeof(SceneInfo)); @@ -1501,7 +1699,7 @@ extern "C" void finalize_scene(int2 occupancyParameters , BoundingBox* boundingBoxes, Primitive* primitives #endif - ) +) { LOG_INFO(3, "Releasing device resources"); for (int device(0); device < occupancyParameters.x; ++device) @@ -1537,45 +1735,56 @@ ________________________________________________________________________________ CPU -> GPU data transfers ________________________________________________________________________________ */ -extern "C" void h2d_scene(int2 occupancyParameters, BoundingBox* boundingBoxes, int nbActiveBoxes, - Primitive* primitives, int nbPrimitives, Lamp* lamps, int nbLamps) +extern "C" void h2d_scene(int2 occupancyParameters, BoundingBox* boundingBoxes, + int nbActiveBoxes, Primitive* primitives, + int nbPrimitives, Lamp* lamps, int nbLamps) { for (int device(0); device < occupancyParameters.x; ++device) { checkCudaErrors(cudaSetDevice(device)); #ifndef USE_MANAGED_MEMORY - checkCudaErrors(cudaMemcpyAsync(d_boundingBoxes[device], boundingBoxes, nbActiveBoxes * sizeof(BoundingBox), - cudaMemcpyHostToDevice, d_streams[device][0])); - checkCudaErrors(cudaMemcpyAsync(d_primitives[device], primitives, nbPrimitives * sizeof(Primitive), - cudaMemcpyHostToDevice, d_streams[device][0])); -#endif - checkCudaErrors(cudaMemcpyAsync(d_lamps[device], lamps, nbLamps * sizeof(Lamp), cudaMemcpyHostToDevice, + checkCudaErrors(cudaMemcpyAsync(d_boundingBoxes[device], boundingBoxes, + nbActiveBoxes * sizeof(BoundingBox), + cudaMemcpyHostToDevice, + d_streams[device][0])); + checkCudaErrors(cudaMemcpyAsync(d_primitives[device], primitives, + nbPrimitives * sizeof(Primitive), + cudaMemcpyHostToDevice, d_streams[device][0])); +#endif + checkCudaErrors( + cudaMemcpyAsync(d_lamps[device], lamps, nbLamps * sizeof(Lamp), + cudaMemcpyHostToDevice, d_streams[device][0])); } } -extern "C" void h2d_materials(int2 occupancyParameters, Material* materials, int nbActiveMaterials) +extern "C" void h2d_materials(int2 occupancyParameters, Material* materials, + int nbActiveMaterials) { for (int device(0); device < occupancyParameters.x; ++device) { checkCudaErrors(cudaSetDevice(device)); - checkCudaErrors(cudaMemcpyAsync(d_materials[device], materials, nbActiveMaterials * sizeof(Material), - cudaMemcpyHostToDevice, d_streams[device][0])); + checkCudaErrors(cudaMemcpyAsync(d_materials[device], materials, + nbActiveMaterials * sizeof(Material), + cudaMemcpyHostToDevice, + d_streams[device][0])); } } -extern "C" void h2d_randoms(int2 occupancyParameters, float* randoms) +extern "C" void h2d_randoms(int2 occupancyParameters, float* randoms, int2 size) { for (int device(0); device < occupancyParameters.x; ++device) { checkCudaErrors(cudaSetDevice(device)); checkCudaErrors(cudaMemcpyAsync(d_randoms[device], randoms, - MAX_BITMAP_WIDTH * MAX_BITMAP_HEIGHT * sizeof(float), cudaMemcpyHostToDevice, + size.x * size.y * sizeof(float), + cudaMemcpyHostToDevice, d_streams[device][0])); } } -extern "C" void h2d_textures(int2 occupancyParameters, int activeTextures, TextureInfo* textureInfos) +extern "C" void h2d_textures(int2 occupancyParameters, int activeTextures, + TextureInfo* textureInfos) { for (int device(0); device < occupancyParameters.x; ++device) { @@ -1585,55 +1794,72 @@ extern "C" void h2d_textures(int2 occupancyParameters, int activeTextures, Textu if (textureInfos[i].buffer) { LOG_INFO(3, "Texture [" << i << "] memory allocated=" - << textureInfos[i].size.x * textureInfos[i].size.y * textureInfos[i].size.z + << textureInfos[i].size.x * + textureInfos[i].size.y * + textureInfos[i].size.z << " bytes"); - totalSize += textureInfos[i].size.x * textureInfos[i].size.y * textureInfos[i].size.z; + totalSize += textureInfos[i].size.x * textureInfos[i].size.y * + textureInfos[i].size.z; } FREECUDARESOURCE(d_textures[device]); if (totalSize > 0) { totalSize *= sizeof(BitmapBuffer); - LOG_INFO(3, "Total GPU texture memory to allocate: " << totalSize << " bytes"); + LOG_INFO(3, "Total GPU texture memory to allocate: " << totalSize + << " bytes"); checkCudaErrors(cudaMalloc((void**)&d_textures[device], totalSize)); for (int i(0); i < activeTextures; ++i) if (textureInfos[i].buffer != 0) { - LOG_INFO(3, "Texture [" << i << "] transfered=" << textureInfos[i].size.x << "," - << textureInfos[i].size.y << "," << textureInfos[i].size.z - << ", offset=" << textureInfos[i].offset); - int textureSize = textureInfos[i].size.x * textureInfos[i].size.y * textureInfos[i].size.z; - checkCudaErrors(cudaMemcpyAsync(d_textures[device] + textureInfos[i].offset, textureInfos[i].buffer, - textureSize * sizeof(BitmapBuffer), cudaMemcpyHostToDevice, - d_streams[device][0])); + LOG_INFO(3, "Texture [" + << i + << "] transfered=" << textureInfos[i].size.x + << "," << textureInfos[i].size.y << "," + << textureInfos[i].size.z + << ", offset=" << textureInfos[i].offset); + int textureSize = textureInfos[i].size.x * + textureInfos[i].size.y * + textureInfos[i].size.z; + checkCudaErrors(cudaMemcpyAsync( + d_textures[device] + textureInfos[i].offset, + textureInfos[i].buffer, + textureSize * sizeof(BitmapBuffer), + cudaMemcpyHostToDevice, d_streams[device][0])); } } } } -extern "C" void h2d_lightInformation(int2 occupancyParameters, LightInformation* lightInformation, +extern "C" void h2d_lightInformation(int2 occupancyParameters, + LightInformation* lightInformation, int lightInformationSize) { for (int device(0); device < occupancyParameters.x; ++device) { checkCudaErrors(cudaSetDevice(device)); - checkCudaErrors(cudaMemcpyAsync(d_lightInformation[device], lightInformation, - lightInformationSize * sizeof(LightInformation), cudaMemcpyHostToDevice, - d_streams[device][0])); + checkCudaErrors( + cudaMemcpyAsync(d_lightInformation[device], lightInformation, + lightInformationSize * sizeof(LightInformation), + cudaMemcpyHostToDevice, d_streams[device][0])); } } #ifdef USE_KINECT -extern "C" void h2d_kinect(int2 occupancyParameters, BitmapBuffer* kinectVideo, BitmapBuffer* kinectDepth) +extern "C" void h2d_kinect(int2 occupancyParameters, BitmapBuffer* kinectVideo, + BitmapBuffer* kinectDepth) { for (int device(0); device < occupancyParameters.x; ++device) { - checkCudaErrors(cudaMemcpyAsync(d_textures[device], kinectVideo, KINECT_COLOR_SIZE * sizeof(BitmapBuffer), - cudaMemcpyHostToDevice, d_streams[device][0])); - checkCudaErrors(cudaMemcpyAsync(d_textures[device] + KINECT_COLOR_SIZE, kinectDepth, - KINECT_DEPTH_SIZE * sizeof(BitmapBuffer), cudaMemcpyHostToDevice, - d_streams[device][0])); + checkCudaErrors( + cudaMemcpyAsync(d_textures[device], kinectVideo, + KINECT_COLOR_SIZE * sizeof(BitmapBuffer), + cudaMemcpyHostToDevice, d_streams[device][0])); + checkCudaErrors( + cudaMemcpyAsync(d_textures[device] + KINECT_COLOR_SIZE, kinectDepth, + KINECT_DEPTH_SIZE * sizeof(BitmapBuffer), + cudaMemcpyHostToDevice, d_streams[device][0])); } } #endif // USE_KINECT @@ -1644,11 +1870,14 @@ ________________________________________________________________________________ GPU -> CPU data transfers ________________________________________________________________________________ */ -extern "C" void d2h_bitmap(int2 occupancyParameters, SceneInfo sceneInfo, BitmapBuffer* bitmap, +extern "C" void d2h_bitmap(int2 occupancyParameters, SceneInfo sceneInfo, + BitmapBuffer* bitmap, PrimitiveXYIdBuffer* primitivesXYIds) { - int offsetBitmap = sceneInfo.size.x * sceneInfo.size.y * gColorDepth * sizeof(BitmapBuffer) / occupancyParameters.x; - int offsetXYIds = sceneInfo.size.x * sceneInfo.size.y * sizeof(PrimitiveXYIdBuffer) / occupancyParameters.x; + int offsetBitmap = sceneInfo.size.x * sceneInfo.size.y * gColorDepth * + sizeof(BitmapBuffer) / occupancyParameters.x; + int offsetXYIds = sceneInfo.size.x * sceneInfo.size.y * + sizeof(PrimitiveXYIdBuffer) / occupancyParameters.x; for (int device(0); device < occupancyParameters.x; ++device) { checkCudaErrors(cudaSetDevice(device)); @@ -1656,17 +1885,22 @@ extern "C" void d2h_bitmap(int2 occupancyParameters, SceneInfo sceneInfo, Bitmap // Synchronize stream for (int stream(0); stream < occupancyParameters.y; ++stream) { - LOG_INFO(3, "Synchronizing stream " << stream << "/" << occupancyParameters.y << " on device " << device - << "/" << occupancyParameters.x); + LOG_INFO(3, "Synchronizing stream " + << stream << "/" << occupancyParameters.y + << " on device " << device << "/" + << occupancyParameters.x); checkCudaErrors(cudaStreamSynchronize(d_streams[device][stream])); } // Copy results back to host - LOG_INFO(3, "Copy results back to host: " << device * offsetBitmap << "/" << offsetBitmap << ", " - << device * offsetXYIds << "/" << offsetXYIds); - checkCudaErrors( - cudaMemcpyAsync(bitmap + device * offsetBitmap, d_bitmap[device], offsetBitmap, cudaMemcpyDeviceToHost)); - checkCudaErrors(cudaMemcpyAsync(primitivesXYIds + device * offsetXYIds, d_primitivesXYIds[device], offsetXYIds, + LOG_INFO(3, "Copy results back to host: " + << device * offsetBitmap << "/" << offsetBitmap << ", " + << device * offsetXYIds << "/" << offsetXYIds); + checkCudaErrors(cudaMemcpyAsync(bitmap + device * offsetBitmap, + d_bitmap[device], offsetBitmap, + cudaMemcpyDeviceToHost)); + checkCudaErrors(cudaMemcpyAsync(primitivesXYIds + device * offsetXYIds, + d_primitivesXYIds[device], offsetXYIds, cudaMemcpyDeviceToHost)); } } @@ -1677,13 +1911,15 @@ ________________________________________________________________________________ Kernel launcher ________________________________________________________________________________ */ -extern "C" void cudaRender(int2 occupancyParameters, int4 blockSize, SceneInfo sceneInfo, int4 objects, - PostProcessingInfo postProcessingInfo, vec3f origin, vec3f direction, vec4f angles +extern "C" void cudaRender(int2 occupancyParameters, int4 blockSize, + SceneInfo sceneInfo, int4 objects, + PostProcessingInfo postProcessingInfo, vec3f origin, + vec3f direction, vec4f angles #ifdef USE_MANAGED_MEMORY , BoundingBox* boundingBoxes, Primitive* primitives #endif - ) +) { LOG_INFO(3, "CPU PostProcessingBuffer: " << sizeof(PostProcessingBuffer)); LOG_INFO(3, "CPU PrimitiveXYIdBuffer : " << sizeof(PrimitiveXYIdBuffer)); @@ -1693,7 +1929,8 @@ extern "C" void cudaRender(int2 occupancyParameters, int4 blockSize, SceneInfo s int2 size; size.x = static_cast(sceneInfo.size.x); - size.y = static_cast(sceneInfo.size.y) / (occupancyParameters.x * occupancyParameters.y); + size.y = static_cast(sceneInfo.size.y) / + (occupancyParameters.x * occupancyParameters.y); dim3 grid; grid.x = (size.x + blockSize.x - 1) / blockSize.x; @@ -1716,7 +1953,8 @@ extern "C" void cudaRender(int2 occupancyParameters, int4 blockSize, SceneInfo s { case ctAnaglyph: { - k_anaglyphRenderer<<>>( + k_anaglyphRenderer<<>>( occupancyParameters, #ifndef USE_MANAGED_MEMORY d_boundingBoxes[device], @@ -1729,14 +1967,16 @@ extern "C" void cudaRender(int2 occupancyParameters, int4 blockSize, SceneInfo s #else primitives, #endif - objects.y, d_lightInformation[device], objects.w, objects.z, d_materials[device], - d_textures[device], d_randoms[device], origin, direction, angles, sceneInfo, postProcessingInfo, + objects.y, d_lightInformation[device], objects.w, objects.z, + d_materials[device], d_textures[device], d_randoms[device], + origin, direction, angles, sceneInfo, postProcessingInfo, d_postProcessingBuffer[device], d_primitivesXYIds[device]); break; } case ctVR: { - k_3DVisionRenderer<<>>( + k_3DVisionRenderer<<>>( occupancyParameters, #ifndef USE_MANAGED_MEMORY d_boundingBoxes[device], @@ -1749,14 +1989,16 @@ extern "C" void cudaRender(int2 occupancyParameters, int4 blockSize, SceneInfo s #else primitives, #endif - objects.y, d_lightInformation[device], objects.w, objects.z, d_materials[device], - d_textures[device], d_randoms[device], origin, direction, angles, sceneInfo, postProcessingInfo, + objects.y, d_lightInformation[device], objects.w, objects.z, + d_materials[device], d_textures[device], d_randoms[device], + origin, direction, angles, sceneInfo, postProcessingInfo, d_postProcessingBuffer[device], d_primitivesXYIds[device]); break; } case ctPanoramic: { - k_fishEyeRenderer<<>>( + k_fishEyeRenderer<<>>( occupancyParameters, device * stream * size.y, #ifndef USE_MANAGED_MEMORY d_boundingBoxes[device], @@ -1769,15 +2011,18 @@ extern "C" void cudaRender(int2 occupancyParameters, int4 blockSize, SceneInfo s #else primitives, #endif - objects.y, d_lightInformation[device], objects.w, objects.z, d_materials[device], - d_textures[device], d_randoms[device], origin, direction, angles, sceneInfo, postProcessingInfo, + objects.y, d_lightInformation[device], objects.w, objects.z, + d_materials[device], d_textures[device], d_randoms[device], + origin, direction, angles, sceneInfo, postProcessingInfo, d_postProcessingBuffer[device], d_primitivesXYIds[device]); break; } case ctVolumeRendering: { - k_volumeRenderer<<>>( - occupancyParameters, device * (size.y / occupancyParameters.x), stream * size.y, + k_volumeRenderer<<>>( + occupancyParameters, + device * (size.y / occupancyParameters.x), stream * size.y, #ifndef USE_MANAGED_MEMORY d_boundingBoxes[device], #else @@ -1789,15 +2034,18 @@ extern "C" void cudaRender(int2 occupancyParameters, int4 blockSize, SceneInfo s #else primitives, #endif - objects.y, d_lightInformation[device], objects.w, objects.z, d_materials[device], - d_textures[device], d_randoms[device], origin, direction, angles, sceneInfo, postProcessingInfo, + objects.y, d_lightInformation[device], objects.w, objects.z, + d_materials[device], d_textures[device], d_randoms[device], + origin, direction, angles, sceneInfo, postProcessingInfo, d_postProcessingBuffer[device], d_primitivesXYIds[device]); break; } default: { - k_standardRenderer<<>>( - occupancyParameters, device * (size.y / occupancyParameters.x), stream * size.y, + k_standardRenderer<<>>( + occupancyParameters, + device * (size.y / occupancyParameters.x), stream * size.y, #ifndef USE_MANAGED_MEMORY d_boundingBoxes[device], #else @@ -1809,8 +2057,9 @@ extern "C" void cudaRender(int2 occupancyParameters, int4 blockSize, SceneInfo s #else primitives, #endif - objects.y, d_lightInformation[device], objects.w, objects.z, d_materials[device], - d_textures[device], d_randoms[device], origin, direction, angles, sceneInfo, postProcessingInfo, + objects.y, d_lightInformation[device], objects.w, objects.z, + d_materials[device], d_textures[device], d_randoms[device], + origin, direction, angles, sceneInfo, postProcessingInfo, d_postProcessingBuffer[device], d_primitivesXYIds[device]); break; } @@ -1818,17 +2067,24 @@ extern "C" void cudaRender(int2 occupancyParameters, int4 blockSize, SceneInfo s cudaError_t status = cudaGetLastError(); if (status != cudaSuccess) { - LOG_ERROR("********************************************************************************"); - LOG_ERROR("Error code : [" << status << "] " << cudaGetErrorString(status)); + LOG_ERROR( + "**********************************************************" + "**********************"); + LOG_ERROR("Error code : [" << status << "] " + << cudaGetErrorString(status)); LOG_ERROR("Device : " << device); LOG_ERROR("Stream : " << stream); LOG_ERROR("Image size : " << size.x << ", " << size.y); - LOG_ERROR("Grid size : " << grid.x << ", " << grid.y << ", " << grid.z); - LOG_ERROR("Block size : " << blocks.x << ", " << blocks.y << ", " << blocks.z); + LOG_ERROR("Grid size : " << grid.x << ", " << grid.y << ", " + << grid.z); + LOG_ERROR("Block size : " << blocks.x << ", " << blocks.y + << ", " << blocks.z); LOG_ERROR("Boxes : " << objects.x); LOG_ERROR("Primitives : " << objects.y); LOG_ERROR("Lamps : " << objects.z); - LOG_ERROR("********************************************************************************"); + LOG_ERROR( + "**********************************************************" + "**********************"); } } // checkCudaErrors(cudaThreadSynchronize()); @@ -1857,51 +2113,61 @@ extern "C" void cudaRender(int2 occupancyParameters, int4 blockSize, SceneInfo s switch (postProcessingInfo.type) { case ppe_depthOfField: - k_depthOfField<<>>(occupancyParameters, sceneInfo, - postProcessingInfo, - d_postProcessingBuffer[device], d_randoms[device], - d_bitmap[device]); + k_depthOfField<<>>( + occupancyParameters, sceneInfo, postProcessingInfo, + d_postProcessingBuffer[device], d_randoms[device], + d_bitmap[device]); break; case ppe_ambientOcclusion: - k_ambiantOcclusion<<>>(occupancyParameters, sceneInfo, - postProcessingInfo, - d_postProcessingBuffer[device], - d_randoms[device], d_bitmap[device]); + k_ambiantOcclusion<<>>( + occupancyParameters, sceneInfo, postProcessingInfo, + d_postProcessingBuffer[device], d_randoms[device], + d_bitmap[device]); break; case ppe_radiosity: - k_radiosity<<>>(occupancyParameters, sceneInfo, postProcessingInfo, - d_primitivesXYIds[device], - d_postProcessingBuffer[device], d_randoms[device], - d_bitmap[device]); + k_radiosity<<>>( + occupancyParameters, sceneInfo, postProcessingInfo, + d_primitivesXYIds[device], d_postProcessingBuffer[device], + d_randoms[device], d_bitmap[device]); break; case ppe_filter: - k_filter<<>>(occupancyParameters, sceneInfo, postProcessingInfo, - d_postProcessingBuffer[device], d_bitmap[device]); + k_filter<<>>( + occupancyParameters, sceneInfo, postProcessingInfo, + d_postProcessingBuffer[device], d_bitmap[device]); break; case ppe_cartoon: - k_cartoon<<>>(occupancyParameters, sceneInfo, postProcessingInfo, - d_postProcessingBuffer[device], d_bitmap[device]); + k_cartoon<<>>( + occupancyParameters, sceneInfo, postProcessingInfo, + d_postProcessingBuffer[device], d_bitmap[device]); break; default: - k_default<<>>(occupancyParameters, sceneInfo, postProcessingInfo, - d_postProcessingBuffer[device], d_bitmap[device]); + k_default<<>>( + occupancyParameters, sceneInfo, postProcessingInfo, + d_postProcessingBuffer[device], d_bitmap[device]); break; } cudaError_t status = cudaGetLastError(); if (status != cudaSuccess) { - LOG_ERROR("********************************************************************************"); - LOG_ERROR("Error code : [" << status << "] " << cudaGetErrorString(status)); + LOG_ERROR( + "**************************************************************" + "******************"); + LOG_ERROR("Error code : [" << status << "] " + << cudaGetErrorString(status)); LOG_ERROR("Device : " << device); LOG_ERROR("Stream : " << 0); LOG_ERROR("Image size : " << size.x << ", " << size.y); - LOG_ERROR("Grid size : " << grid.x << ", " << grid.y << ", " << grid.z); - LOG_ERROR("Block size : " << blocks.x << ", " << blocks.y << ", " << blocks.z); + LOG_ERROR("Grid size : " << grid.x << ", " << grid.y << ", " + << grid.z); + LOG_ERROR("Block size : " << blocks.x << ", " << blocks.y << ", " + << blocks.z); LOG_ERROR("Boxes : " << objects.x); LOG_ERROR("Primitives : " << objects.y); LOG_ERROR("Lamps : " << objects.z); - LOG_ERROR("********************************************************************************"); + LOG_ERROR( + "**************************************************************" + "******************"); } } LOG_INFO(3, "Post-processing kernel done!"); diff --git a/solr/engines/cuda/CudaRayTracer.h b/solr/engines/cuda/CudaRayTracer.h index 0f86f57..9f2d257 100644 --- a/solr/engines/cuda/CudaRayTracer.h +++ b/solr/engines/cuda/CudaRayTracer.h @@ -1,67 +1,76 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once -#include +#include + +using namespace solr; -extern "C" void initialize_scene(vec2i occupancyParameters, SceneInfo sceneInfo, int nbPrimitives, int nbLamps, - int nbMaterials +extern "C" void initialize_scene(vec2i occupancyParameters, SceneInfo sceneInfo, + int nbPrimitives, int nbLamps, int nbMaterials #ifdef USE_MANAGED_MEMORY , - BoundingBox *&boundingBoxes, Primitive *&primitives + BoundingBox *&boundingBoxes, + Primitive *&primitives #endif - ); +); extern "C" void finalize_scene(vec2i occupancyParameters #ifdef USE_MANAGED_MEMORY , BoundingBox *boundingBoxes, Primitive *primitives #endif - ); +); extern "C" void reshape_scene(vec2i occupancyParameters, SceneInfo sceneInfo); -extern "C" void h2d_scene(vec2i occupancyParameters, BoundingBox *boundingBoxes, int nbActiveBoxes, - Primitive *primitives, int nbPrimitives, Lamp *lamps, int nbLamps); +extern "C" void h2d_scene(vec2i occupancyParameters, BoundingBox *boundingBoxes, + int nbActiveBoxes, Primitive *primitives, + int nbPrimitives, Lamp *lamps, int nbLamps); -extern "C" void h2d_materials(vec2i occupancyParameters, Material *materials, int nbActiveMaterials); +extern "C" void h2d_materials(vec2i occupancyParameters, Material *materials, + int nbActiveMaterials); -extern "C" void h2d_randoms(vec2i occupancyParameters, float *randoms); +extern "C" void h2d_randoms(vec2i occupancyParameters, float *randoms, + vec2i size); -extern "C" void h2d_textures(vec2i occupancyParameters, int activeTextures, TextureInfo *textureInfos); +extern "C" void h2d_textures(vec2i occupancyParameters, int activeTextures, + TextureInfo *textureInfos); -extern "C" void h2d_lightInformation(vec2i occupancyParameters, LightInformation *lightInformation, +extern "C" void h2d_lightInformation(vec2i occupancyParameters, + LightInformation *lightInformation, int lightInformationSize); -extern "C" void d2h_bitmap(vec2i occupancyParameters, SceneInfo sceneInfo, BitmapBuffer *bitmap, +extern "C" void d2h_bitmap(vec2i occupancyParameters, SceneInfo sceneInfo, + BitmapBuffer *bitmap, PrimitiveXYIdBuffer *primitivesXYIds); -extern "C" void cudaRender(vec2i occupancyParameters, vec4i blockSize, SceneInfo sceneInfo, vec4i objects, - PostProcessingInfo PostProcessingInfo, vec3f origin, vec3f direction, vec4f angles +extern "C" void cudaRender(vec2i occupancyParameters, vec4i blockSize, + SceneInfo sceneInfo, vec4i objects, + PostProcessingInfo PostProcessingInfo, vec3f origin, + vec3f direction, vec4f angles #ifdef USE_MANAGED_MEMORY , BoundingBox *boundingBoxes, Primitive *primitives #endif - ); +); #ifdef USE_KINECT -extern "C" void h2d_kinect(vec2i occupancyParameters, BitmapBuffer *video, BitmapBuffer *depth); +extern "C" void h2d_kinect(vec2i occupancyParameters, BitmapBuffer *video, + BitmapBuffer *depth); #endif // USE_KINECT diff --git a/solr/engines/cuda/GeometryIntersections.cuh b/solr/engines/cuda/GeometryIntersections.cuh index 1d3d5a1..32df303 100644 --- a/solr/engines/cuda/GeometryIntersections.cuh +++ b/solr/engines/cuda/GeometryIntersections.cuh @@ -1,31 +1,28 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once //#define VOLUME_RENDERING_NORMALS // Project -#include "../../types.h" -#include "VectorUtils.cuh" +#include "../../solr.h" #include "GeometryShaders.cuh" #include "TextureMapping.cuh" +#include "VectorUtils.cuh" /* ________________________________________________________________________________ @@ -49,14 +46,19 @@ ________________________________________________________________________________ Box intersection ________________________________________________________________________________ */ -__device__ __INLINE__ bool boxIntersection(const BoundingBox &box, const Ray &ray, const float &t0, const float &t1) +__device__ __INLINE__ bool boxIntersection(const BoundingBox &box, + const Ray &ray, const float &t0, + const float &t1) { float tmin, tmax, tymin, tymax, tzmin, tzmax; tmin = (box.parameters[ray.signs.x].x - ray.origin.x) * ray.inv_direction.x; - tmax = (box.parameters[1 - ray.signs.x].x - ray.origin.x) * ray.inv_direction.x; - tymin = (box.parameters[ray.signs.y].y - ray.origin.y) * ray.inv_direction.y; - tymax = (box.parameters[1 - ray.signs.y].y - ray.origin.y) * ray.inv_direction.y; + tmax = (box.parameters[1 - ray.signs.x].x - ray.origin.x) * + ray.inv_direction.x; + tymin = + (box.parameters[ray.signs.y].y - ray.origin.y) * ray.inv_direction.y; + tymax = (box.parameters[1 - ray.signs.y].y - ray.origin.y) * + ray.inv_direction.y; if ((tmin > tymax) || (tymin > tmax)) return false; @@ -65,8 +67,10 @@ __device__ __INLINE__ bool boxIntersection(const BoundingBox &box, const Ray &ra tmin = tymin; if (tymax < tmax) tmax = tymax; - tzmin = (box.parameters[ray.signs.z].z - ray.origin.z) * ray.inv_direction.z; - tzmax = (box.parameters[1 - ray.signs.z].z - ray.origin.z) * ray.inv_direction.z; + tzmin = + (box.parameters[ray.signs.z].z - ray.origin.z) * ray.inv_direction.z; + tzmax = (box.parameters[1 - ray.signs.z].z - ray.origin.z) * + ray.inv_direction.z; if ((tmin > tzmax) || (tzmin > tmax)) return false; @@ -84,7 +88,9 @@ ________________________________________________________________________________ Skybox mapping ________________________________________________________________________________ */ -__device__ __INLINE__ vec4f skyboxMapping(const SceneInfo &sceneInfo, Material *materials, BitmapBuffer *textures, +__device__ __INLINE__ vec4f skyboxMapping(const SceneInfo &sceneInfo, + Material *materials, + BitmapBuffer *textures, const Ray &ray) { Material &material = materials[sceneInfo.skyboxMaterialId]; @@ -94,7 +100,8 @@ __device__ __INLINE__ vec4f skyboxMapping(const SceneInfo &sceneInfo, Material * float a = 2.f * dot(dir, dir); float b = 2.f * dot(ray.origin, dir); - float c = dot(ray.origin, ray.origin) - (sceneInfo.skyboxRadius * sceneInfo.skyboxRadius); + float c = dot(ray.origin, ray.origin) - + (sceneInfo.skyboxRadius * sceneInfo.skyboxRadius); float d = b * b - 2.f * a * c; if (d <= 0.f || a == 0.f) @@ -130,10 +137,12 @@ __device__ __INLINE__ vec4f skyboxMapping(const SceneInfo &sceneInfo, Material * if (material.textureMapping.y != 0) v %= material.textureMapping.y; - if (u >= 0 && u < material.textureMapping.x && v >= 0 && v < material.textureMapping.y) + if (u >= 0 && u < material.textureMapping.x && v >= 0 && + v < material.textureMapping.y) { int A = (v * material.textureMapping.x + u) * material.textureMapping.w; - int B = material.textureMapping.x * material.textureMapping.y * material.textureMapping.w; + int B = material.textureMapping.x * material.textureMapping.y * + material.textureMapping.w; int index = A % B; // Diffuse @@ -156,9 +165,9 @@ ________________________________________________________________________________ Ellipsoid intersection ________________________________________________________________________________ */ -__device__ __INLINE__ bool ellipsoidIntersection(const SceneInfo &sceneInfo, const Primitive &ellipsoid, - Material *materials, const Ray &ray, vec3f &intersection, - vec3f &normal, float &shadowIntensity) +__device__ __INLINE__ bool ellipsoidIntersection( + const SceneInfo &sceneInfo, const Primitive &ellipsoid, Material *materials, + const Ray &ray, vec3f &intersection, vec3f &normal, float &shadowIntensity) { // Shadow intensity shadowIntensity = 1.f; @@ -217,9 +226,9 @@ ________________________________________________________________________________ Sphere intersection ________________________________________________________________________________ */ -__device__ __INLINE__ bool sphereIntersection(const SceneInfo &sceneInfo, const Primitive &sphere, Material *materials, - const Ray &ray, vec3f &intersection, vec3f &normal, - float &shadowIntensity) +__device__ __INLINE__ bool sphereIntersection( + const SceneInfo &sceneInfo, const Primitive &sphere, Material *materials, + const Ray &ray, vec3f &intersection, vec3f &normal, float &shadowIntensity) { bool back = false; // solve the equation sphere-ray to find the intersections @@ -267,9 +276,15 @@ __device__ __INLINE__ bool sphereIntersection(const SceneInfo &sceneInfo, const { // Procedural texture vec3f newCenter; - newCenter.x = sphere.p0.x + 0.008f * sphere.size.x * cos(sceneInfo.timestamp + intersection.x); - newCenter.y = sphere.p0.y + 0.008f * sphere.size.y * sin(sceneInfo.timestamp + intersection.y); - newCenter.z = sphere.p0.z + 0.008f * sphere.size.z * sin(cos(sceneInfo.timestamp + intersection.z)); + newCenter.x = + sphere.p0.x + + 0.008f * sphere.size.x * cos(sceneInfo.timestamp + intersection.x); + newCenter.y = + sphere.p0.y + + 0.008f * sphere.size.y * sin(sceneInfo.timestamp + intersection.y); + newCenter.z = + sphere.p0.z + 0.008f * sphere.size.z * + sin(cos(sceneInfo.timestamp + intersection.z)); normal = intersection - newCenter; } normal = normalize(normal); @@ -278,7 +293,9 @@ __device__ __INLINE__ bool sphereIntersection(const SceneInfo &sceneInfo, const // Shadow management r = dot(dir, normal); - shadowIntensity = (materials[sphere.materialId].transparency != 0.f) ? (1.f - fabs(r)) : 1.f; + shadowIntensity = (materials[sphere.materialId].transparency != 0.f) + ? (1.f - fabs(r)) + : 1.f; return true; } @@ -290,9 +307,9 @@ Cylinder intersection ref: http://courses.cms.caltech.edu/cs11/material/advcpp/lab7/index.html ________________________________________________________________________________ */ -__device__ __INLINE__ bool cylinderIntersection(const SceneInfo &sceneInfo, const Primitive &cylinder, - Material *materials, const Ray &ray, vec3f &intersection, vec3f &normal, - float &shadowIntensity) +__device__ __INLINE__ bool cylinderIntersection( + const SceneInfo &sceneInfo, const Primitive &cylinder, Material *materials, + const Ray &ray, vec3f &intersection, vec3f &normal, float &shadowIntensity) { vec3f O_C = ray.origin - cylinder.p0; vec3f dir = ray.direction; @@ -315,7 +332,8 @@ __device__ __INLINE__ bool cylinderIntersection(const SceneInfo &sceneInfo, cons return false; O = normalize(crossProduct(n, cylinder.n1)); - float s = fabs(sqrtf(cylinder.size.x * cylinder.size.x - d * d) / dot(dir, O)); + float s = + fabs(sqrtf(cylinder.size.x * cylinder.size.x - d * d) / dot(dir, O)); float t1 = t - s; float t2 = t + s; @@ -327,7 +345,8 @@ __device__ __INLINE__ bool cylinderIntersection(const SceneInfo &sceneInfo, cons float scale1 = dot(HB1, cylinder.n1); float scale2 = dot(HB2, cylinder.n1); // Cylinder length - if (scale1 < sceneInfo.geometryEpsilon || scale2 > sceneInfo.geometryEpsilon) + if (scale1 < sceneInfo.geometryEpsilon || + scale2 > sceneInfo.geometryEpsilon) { intersection = ray.origin + t2 * dir; HB1 = intersection - cylinder.p0; @@ -335,7 +354,8 @@ __device__ __INLINE__ bool cylinderIntersection(const SceneInfo &sceneInfo, cons scale1 = dot(HB1, cylinder.n1); scale2 = dot(HB2, cylinder.n1); // Cylinder length - if (scale1 < sceneInfo.geometryEpsilon || scale2 > sceneInfo.geometryEpsilon) + if (scale1 < sceneInfo.geometryEpsilon || + scale2 > sceneInfo.geometryEpsilon) return false; } @@ -355,8 +375,11 @@ Cone intersection ref: http://courses.cms.caltech.edu/cs11/material/advcpp/lab7/index.html ________________________________________________________________________________ */ -__device__ __INLINE__ bool coneIntersection(const SceneInfo &sceneInfo, const Primitive &cone, Material *materials, - const Ray &ray, vec3f &intersection, vec3f &normal, float &shadowIntensity) +__device__ __INLINE__ bool coneIntersection(const SceneInfo &sceneInfo, + const Primitive &cone, + Material *materials, const Ray &ray, + vec3f &intersection, vec3f &normal, + float &shadowIntensity) { vec3f O_C = ray.origin - cone.p0; vec3f dir = ray.direction; @@ -392,7 +415,8 @@ __device__ __INLINE__ bool coneIntersection(const SceneInfo &sceneInfo, const Pr float scale1 = dot(HB1, cone.n1); float scale2 = dot(HB2, cone.n1); // Cylinder length - if (scale1 < sceneInfo.geometryEpsilon || scale2 > sceneInfo.geometryEpsilon) + if (scale1 < sceneInfo.geometryEpsilon || + scale2 > sceneInfo.geometryEpsilon) { intersection = ray.origin + t2 * dir; HB1 = intersection - cone.p0; @@ -400,7 +424,8 @@ __device__ __INLINE__ bool coneIntersection(const SceneInfo &sceneInfo, const Pr scale1 = dot(HB1, cone.n1); scale2 = dot(HB2, cone.n1); // Cylinder length - if (scale1 < sceneInfo.geometryEpsilon || scale2 > sceneInfo.geometryEpsilon) + if (scale1 < sceneInfo.geometryEpsilon || + scale2 > sceneInfo.geometryEpsilon) return false; } @@ -421,9 +446,10 @@ ________________________________________________________________________________ Checkboard intersection ________________________________________________________________________________ */ -__device__ __INLINE__ bool planeIntersection(const SceneInfo &sceneInfo, const Primitive &primitive, - Material *materials, BitmapBuffer *textures, const Ray &ray, - vec3f &intersection, vec3f &normal, float &shadowIntensity, bool reverse) +__device__ __INLINE__ bool planeIntersection( + const SceneInfo &sceneInfo, const Primitive &primitive, Material *materials, + BitmapBuffer *textures, const Ray &ray, vec3f &intersection, vec3f &normal, + float &shadowIntensity, bool reverse) { bool collision = false; @@ -436,78 +462,104 @@ __device__ __INLINE__ bool planeIntersection(const SceneInfo &sceneInfo, const P { intersection.y = primitive.p0.y; float y = ray.origin.y - primitive.p0.y; - if (reverted * ray.direction.y < 0.f && reverted * ray.origin.y > reverted * primitive.p0.y) + if (reverted * ray.direction.y < 0.f && + reverted * ray.origin.y > reverted * primitive.p0.y) { - intersection.x = ray.origin.x + y * ray.direction.x / -ray.direction.y; - intersection.z = ray.origin.z + y * ray.direction.z / -ray.direction.y; - collision = fabs(intersection.x - primitive.p0.x) < primitive.size.x && - fabs(intersection.z - primitive.p0.z) < primitive.size.z; + intersection.x = + ray.origin.x + y * ray.direction.x / -ray.direction.y; + intersection.z = + ray.origin.z + y * ray.direction.z / -ray.direction.y; + collision = + fabs(intersection.x - primitive.p0.x) < primitive.size.x && + fabs(intersection.z - primitive.p0.z) < primitive.size.z; } break; } case ptXZPlane: { float y = ray.origin.y - primitive.p0.y; - if (reverted * ray.direction.y < 0.f && reverted * ray.origin.y > reverted * primitive.p0.y) + if (reverted * ray.direction.y < 0.f && + reverted * ray.origin.y > reverted * primitive.p0.y) { - intersection.x = ray.origin.x + y * ray.direction.x / -ray.direction.y; + intersection.x = + ray.origin.x + y * ray.direction.x / -ray.direction.y; intersection.y = primitive.p0.y; - intersection.z = ray.origin.z + y * ray.direction.z / -ray.direction.y; - collision = fabs(intersection.x - primitive.p0.x) < primitive.size.x && - fabs(intersection.z - primitive.p0.z) < primitive.size.z; + intersection.z = + ray.origin.z + y * ray.direction.z / -ray.direction.y; + collision = + fabs(intersection.x - primitive.p0.x) < primitive.size.x && + fabs(intersection.z - primitive.p0.z) < primitive.size.z; if (materials[primitive.materialId].attributes.z == 2) // Wireframe - collision &= wireFrameMapping(intersection.x, intersection.z, - materials[primitive.materialId].attributes.w, primitive); + collision &= wireFrameMapping( + intersection.x, intersection.z, + materials[primitive.materialId].attributes.w, primitive); } - if (!collision && reverted * ray.direction.y > 0.f && reverted * ray.origin.y < reverted * primitive.p0.y) + if (!collision && reverted * ray.direction.y > 0.f && + reverted * ray.origin.y < reverted * primitive.p0.y) { normal = -normal; - intersection.x = ray.origin.x + y * ray.direction.x / -ray.direction.y; + intersection.x = + ray.origin.x + y * ray.direction.x / -ray.direction.y; intersection.y = primitive.p0.y; - intersection.z = ray.origin.z + y * ray.direction.z / -ray.direction.y; - collision = fabs(intersection.x - primitive.p0.x) < primitive.size.x && - fabs(intersection.z - primitive.p0.z) < primitive.size.z; + intersection.z = + ray.origin.z + y * ray.direction.z / -ray.direction.y; + collision = + fabs(intersection.x - primitive.p0.x) < primitive.size.x && + fabs(intersection.z - primitive.p0.z) < primitive.size.z; if (materials[primitive.materialId].attributes.z == 2) // Wireframe - collision &= wireFrameMapping(intersection.x, intersection.z, - materials[primitive.materialId].attributes.w, primitive); + collision &= wireFrameMapping( + intersection.x, intersection.z, + materials[primitive.materialId].attributes.w, primitive); } break; } case ptYZPlane: { float x = ray.origin.x - primitive.p0.x; - if (reverted * ray.direction.x < 0.f && reverted * ray.origin.x > reverted * primitive.p0.x) + if (reverted * ray.direction.x < 0.f && + reverted * ray.origin.x > reverted * primitive.p0.x) { intersection.x = primitive.p0.x; - intersection.y = ray.origin.y + x * ray.direction.y / -ray.direction.x; - intersection.z = ray.origin.z + x * ray.direction.z / -ray.direction.x; - collision = fabs(intersection.y - primitive.p0.y) < primitive.size.y && - fabs(intersection.z - primitive.p0.z) < primitive.size.z; + intersection.y = + ray.origin.y + x * ray.direction.y / -ray.direction.x; + intersection.z = + ray.origin.z + x * ray.direction.z / -ray.direction.x; + collision = + fabs(intersection.y - primitive.p0.y) < primitive.size.y && + fabs(intersection.z - primitive.p0.z) < primitive.size.z; if (materials[primitive.materialId].innerIllumination.x != 0.f) { // Chessboard like Lights - collision &= int(fabs(intersection.z)) % 4000 < 2000 && int(fabs(intersection.y)) % 4000 < 2000; + collision &= int(fabs(intersection.z)) % 4000 < 2000 && + int(fabs(intersection.y)) % 4000 < 2000; } if (materials[primitive.materialId].attributes.z == 2) // Wireframe - collision &= wireFrameMapping(intersection.y, intersection.z, - materials[primitive.materialId].attributes.w, primitive); + collision &= wireFrameMapping( + intersection.y, intersection.z, + materials[primitive.materialId].attributes.w, primitive); } - if (!collision && reverted * ray.direction.x > 0.f && reverted * ray.origin.x < reverted * primitive.p0.x) + if (!collision && reverted * ray.direction.x > 0.f && + reverted * ray.origin.x < reverted * primitive.p0.x) { normal = -normal; intersection.x = primitive.p0.x; - intersection.y = ray.origin.y + x * ray.direction.y / -ray.direction.x; - intersection.z = ray.origin.z + x * ray.direction.z / -ray.direction.x; - collision = fabs(intersection.y - primitive.p0.y) < primitive.size.y && - fabs(intersection.z - primitive.p0.z) < primitive.size.z; + intersection.y = + ray.origin.y + x * ray.direction.y / -ray.direction.x; + intersection.z = + ray.origin.z + x * ray.direction.z / -ray.direction.x; + collision = + fabs(intersection.y - primitive.p0.y) < primitive.size.y && + fabs(intersection.z - primitive.p0.z) < primitive.size.z; if (materials[primitive.materialId].innerIllumination.x != 0.f) { // Chessboard like Lights - collision &= int(fabs(intersection.z)) % 4000 < 2000 && int(fabs(intersection.y)) % 4000 < 2000; + collision &= int(fabs(intersection.z)) % 4000 < 2000 && + int(fabs(intersection.y)) % 4000 < 2000; } if (materials[primitive.materialId].attributes.z == 2) // Wireframe - collision &= wireFrameMapping(intersection.y, intersection.z, - materials[primitive.materialId].attributes.w, primitive); + collision &= wireFrameMapping( + intersection.y, intersection.z, + materials[primitive.materialId].attributes.w, primitive); } break; } @@ -515,28 +567,38 @@ __device__ __INLINE__ bool planeIntersection(const SceneInfo &sceneInfo, const P case ptCamera: { float z = ray.origin.z - primitive.p0.z; - if (reverted * ray.direction.z < 0.f && reverted * ray.origin.z > reverted * primitive.p0.z) + if (reverted * ray.direction.z < 0.f && + reverted * ray.origin.z > reverted * primitive.p0.z) { intersection.z = primitive.p0.z; - intersection.x = ray.origin.x + z * ray.direction.x / -ray.direction.z; - intersection.y = ray.origin.y + z * ray.direction.y / -ray.direction.z; - collision = fabs(intersection.x - primitive.p0.x) < primitive.size.x && - fabs(intersection.y - primitive.p0.y) < primitive.size.y; + intersection.x = + ray.origin.x + z * ray.direction.x / -ray.direction.z; + intersection.y = + ray.origin.y + z * ray.direction.y / -ray.direction.z; + collision = + fabs(intersection.x - primitive.p0.x) < primitive.size.x && + fabs(intersection.y - primitive.p0.y) < primitive.size.y; if (materials[primitive.materialId].attributes.z == 2) // Wireframe - collision &= wireFrameMapping(intersection.x, intersection.y, - materials[primitive.materialId].attributes.w, primitive); + collision &= wireFrameMapping( + intersection.x, intersection.y, + materials[primitive.materialId].attributes.w, primitive); } - if (!collision && reverted * ray.direction.z > 0.f && reverted * ray.origin.z < reverted * primitive.p0.z) + if (!collision && reverted * ray.direction.z > 0.f && + reverted * ray.origin.z < reverted * primitive.p0.z) { normal = -normal; intersection.z = primitive.p0.z; - intersection.x = ray.origin.x + z * ray.direction.x / -ray.direction.z; - intersection.y = ray.origin.y + z * ray.direction.y / -ray.direction.z; - collision = fabs(intersection.x - primitive.p0.x) < primitive.size.x && - fabs(intersection.y - primitive.p0.y) < primitive.size.y; + intersection.x = + ray.origin.x + z * ray.direction.x / -ray.direction.z; + intersection.y = + ray.origin.y + z * ray.direction.y / -ray.direction.z; + collision = + fabs(intersection.x - primitive.p0.x) < primitive.size.x && + fabs(intersection.y - primitive.p0.y) < primitive.size.y; if (materials[primitive.materialId].attributes.z == 2) // Wireframe - collision &= wireFrameMapping(intersection.x, intersection.y, - materials[primitive.materialId].attributes.w, primitive); + collision &= wireFrameMapping( + intersection.x, intersection.y, + materials[primitive.materialId].attributes.w, primitive); } break; } @@ -545,15 +607,18 @@ __device__ __INLINE__ bool planeIntersection(const SceneInfo &sceneInfo, const P if (collision) { // Shadow intensity - shadowIntensity = 1.f; // sceneInfo.shadowIntensity*(1.f-materials[primitive.materialId].transparency); + shadowIntensity = + 1.f; // sceneInfo.shadowIntensity*(1.f-materials[primitive.materialId].transparency); vec4f color = materials[primitive.materialId].color; - if (primitive.type == ptCamera || materials[primitive.materialId].textureIds.x != TEXTURE_NONE) + if (primitive.type == ptCamera || + materials[primitive.materialId].textureIds.x != TEXTURE_NONE) { vec4f specular = {0.f, 0.f, 0.f}; // TODO? vec4f attributes; vec4f advancedAttributes; - color = cubeMapping(sceneInfo, primitive, materials, textures, intersection, normal, specular, attributes, + color = cubeMapping(sceneInfo, primitive, materials, textures, + intersection, normal, specular, attributes, advancedAttributes); shadowIntensity = color.w; } @@ -567,14 +632,15 @@ __device__ __INLINE__ bool planeIntersection(const SceneInfo &sceneInfo, const P } /* -________________________________________________________________________________ +______80__________________________________________________________________________ Triangle intersection ________________________________________________________________________________ */ -__device__ __INLINE__ bool triangleIntersection(const SceneInfo &sceneInfo, const Primitive &triangle, const Ray &ray, - vec3f &intersection, vec3f &normal, vec3f &areas, - float &shadowIntensity, const bool &processingShadows) +__device__ __INLINE__ bool triangleIntersection( + const SceneInfo &sceneInfo, const Primitive &triangle, const Ray &ray, + vec3f &intersection, vec3f &normal, vec3f &areas, float &shadowIntensity, + const bool &processingShadows) { // Reject rays using the barycentric coordinates of // the intersection point with respect to T. @@ -632,7 +698,8 @@ __device__ __INLINE__ bool triangleIntersection(const SceneInfo &sceneInfo, cons areas.x = 0.5f * length(crossProduct(v1, v2)); areas.y = 0.5f * length(crossProduct(v0, v2)); areas.z = 0.5f * length(crossProduct(v0, v1)); - normal = normalize((triangle.n0 * areas.x + triangle.n1 * areas.y + triangle.n2 * areas.z) / + normal = normalize((triangle.n0 * areas.x + triangle.n1 * areas.y + + triangle.n2 * areas.z) / (areas.x + areas.y + areas.z)); if (sceneInfo.doubleSidedTriangles) @@ -665,13 +732,17 @@ Intersections with primitives ________________________________________________________________________________ */ __device__ __INLINE__ bool intersectionWithPrimitives( - const SceneInfo &sceneInfo, const PostProcessingInfo &postProcessingInfo, BoundingBox *boundingBoxes, - const int &nbActiveBoxes, Primitive *primitives, const int &nbActivePrimitives, Material *materials, - BitmapBuffer *textures, const Ray &ray, const int &iteration, int &closestPrimitive, vec3f &closestIntersection, - vec3f &closestNormal, vec3f &closestAreas, vec4f &closestColor, vec4f &colorBox, const int currentmaterialId) + const SceneInfo &sceneInfo, const PostProcessingInfo &postProcessingInfo, + BoundingBox *boundingBoxes, const int &nbActiveBoxes, Primitive *primitives, + const int &nbActivePrimitives, Material *materials, BitmapBuffer *textures, + const Ray &ray, const int &iteration, int &closestPrimitive, + vec3f &closestIntersection, vec3f &closestNormal, vec3f &closestAreas, + vec4f &closestColor, vec4f &colorBox, const int currentmaterialId) { bool intersections = false; - float minDistance = (iteration < 2) ? sceneInfo.viewDistance : sceneInfo.viewDistance / (iteration + 1); + float minDistance = (iteration < 2) + ? sceneInfo.viewDistance + : sceneInfo.viewDistance / (iteration + 1); Ray r; r.origin = ray.origin; @@ -690,23 +761,29 @@ __device__ __INLINE__ bool intersectionWithPrimitives( if (boxIntersection(box, r, 0.f, minDistance)) { // Intersection with Box - if (sceneInfo.renderBoxes != 0) // Box 0 is for light emitting objects + if (sceneInfo.renderBoxes != 0) // Box 0 is for light emitting + // objects { - colorBox += materials[box.startIndex % NB_MAX_MATERIALS].color / 200.f; + colorBox += + materials[box.startIndex % NB_MAX_MATERIALS].color / 50.f; } else { // Intersection with primitive within boxes - for (int cptPrimitives = 0; cptPrimitives < box.nbPrimitives; ++cptPrimitives) + for (int cptPrimitives = 0; cptPrimitives < box.nbPrimitives; + ++cptPrimitives) { - Primitive &primitive = primitives[box.startIndex + cptPrimitives]; + Primitive &primitive = + primitives[box.startIndex + cptPrimitives]; Material &material = materials[primitive.materialId]; if (material.attributes.x == 0 || - (material.attributes.x == 1 && currentmaterialId != primitive.materialId)) // !!!! TEST SHALL BE - // REMOVED TO - // INCREASE - // TRANSPARENCY - // QUALITY !!! + (material.attributes.x == 1 && + currentmaterialId != + primitive.materialId)) // !!!! TEST SHALL BE + // REMOVED TO + // INCREASE + // TRANSPARENCY + // QUALITY !!! { vec3f areas = {0.f, 0.f, 0.f}; if (sceneInfo.extendedGeometry) @@ -716,39 +793,54 @@ __device__ __INLINE__ bool intersectionWithPrimitives( { case ptEnvironment: case ptSphere: - i = sphereIntersection(sceneInfo, primitive, materials, r, intersection, normal, + i = sphereIntersection(sceneInfo, primitive, + materials, r, + intersection, normal, shadowIntensity); break; case ptCylinder: - i = cylinderIntersection(sceneInfo, primitive, materials, r, intersection, normal, + i = cylinderIntersection(sceneInfo, primitive, + materials, r, + intersection, normal, shadowIntensity); break; case ptCone: - i = coneIntersection(sceneInfo, primitive, materials, r, intersection, normal, - shadowIntensity); + i = coneIntersection(sceneInfo, primitive, + materials, r, intersection, + normal, shadowIntensity); break; case ptEllipsoid: - i = ellipsoidIntersection(sceneInfo, primitive, materials, r, intersection, normal, + i = ellipsoidIntersection(sceneInfo, primitive, + materials, r, + intersection, normal, shadowIntensity); break; case ptTriangle: - i = triangleIntersection(sceneInfo, primitive, r, intersection, normal, areas, - shadowIntensity, false); + i = triangleIntersection(sceneInfo, primitive, + r, intersection, + normal, areas, + shadowIntensity, + false); break; default: - i = planeIntersection(sceneInfo, primitive, materials, textures, r, intersection, - normal, shadowIntensity, false); + i = planeIntersection(sceneInfo, primitive, + materials, textures, r, + intersection, normal, + shadowIntensity, false); } } else { - i = triangleIntersection(sceneInfo, primitive, r, intersection, normal, areas, - shadowIntensity, false); + i = triangleIntersection(sceneInfo, primitive, r, + intersection, normal, + areas, shadowIntensity, + false); } float distance = length(intersection - r.origin); - if (i && distance > sceneInfo.geometryEpsilon && distance < minDistance) + if (i && distance > sceneInfo.geometryEpsilon && + distance < minDistance) { // Only keep intersection with the closest object minDistance = distance; @@ -795,11 +887,12 @@ light source center. ________________________________________________________________________________ */ -__device__ __INLINE__ float processShadows(const SceneInfo &sceneInfo, BoundingBox *boudingBoxes, - const int &nbActiveBoxes, Primitive *primitives, Material *materials, - BitmapBuffer *textures, const int &nbPrimitives, const vec3f &lampCenter, - const vec3f &origin, const int &lightId, const int &iteration, vec4f &color, - const int &objectId) +__device__ __INLINE__ float processShadows( + const SceneInfo &sceneInfo, BoundingBox *boudingBoxes, + const int &nbActiveBoxes, Primitive *primitives, Material *materials, + BitmapBuffer *textures, const int &nbPrimitives, const vec3f &lampCenter, + const vec3f &origin, const int &lightId, const int &iteration, vec4f &color, + const int &objectId) { float result = 0.f; int cptBoxes = 0; @@ -810,7 +903,9 @@ __device__ __INLINE__ float processShadows(const SceneInfo &sceneInfo, BoundingB r.direction = lampCenter - origin; r.origin = origin + normalize(r.direction) * sceneInfo.rayEpsilon; computeRayAttributes(r); - const float minDistance = (iteration < 2) ? sceneInfo.viewDistance : sceneInfo.viewDistance / (iteration + 1); + const float minDistance = (iteration < 2) + ? sceneInfo.viewDistance + : sceneInfo.viewDistance / (iteration + 1); while (result < (sceneInfo.shadowIntensity) && cptBoxes < nbActiveBoxes) { @@ -818,14 +913,16 @@ __device__ __INLINE__ float processShadows(const SceneInfo &sceneInfo, BoundingB if (boxIntersection(box, r, 0.f, minDistance)) { int cptPrimitives = 0; - while (result < sceneInfo.shadowIntensity && cptPrimitives < box.nbPrimitives) + while (result < sceneInfo.shadowIntensity && + cptPrimitives < box.nbPrimitives) { vec3f intersection = {0.f, 0.f, 0.f}; vec3f normal = {0.f, 0.f, 0.f}; vec3f areas = {0.f, 0.f, 0.f}; float shadowIntensity = 0.f; - Primitive &primitive = primitives[box.startIndex + cptPrimitives]; + Primitive &primitive = + primitives[box.startIndex + cptPrimitives]; if (primitive.index != lightId && primitive.index != objectId && materials[primitive.materialId].attributes.x == 0) { @@ -835,37 +932,48 @@ __device__ __INLINE__ float processShadows(const SceneInfo &sceneInfo, BoundingB switch (primitive.type) { case ptSphere: - hit = sphereIntersection(sceneInfo, primitive, materials, r, intersection, normal, - shadowIntensity); + hit = sphereIntersection(sceneInfo, primitive, + materials, r, intersection, + normal, shadowIntensity); break; case ptEllipsoid: - hit = ellipsoidIntersection(sceneInfo, primitive, materials, r, intersection, normal, + hit = ellipsoidIntersection(sceneInfo, primitive, + materials, r, + intersection, normal, shadowIntensity); break; case ptCylinder: - hit = cylinderIntersection(sceneInfo, primitive, materials, r, intersection, normal, - shadowIntensity); + hit = + cylinderIntersection(sceneInfo, primitive, + materials, r, intersection, + normal, shadowIntensity); break; case ptCone: - hit = coneIntersection(sceneInfo, primitive, materials, r, intersection, normal, - shadowIntensity); + hit = coneIntersection(sceneInfo, primitive, + materials, r, intersection, + normal, shadowIntensity); break; case ptTriangle: - hit = triangleIntersection(sceneInfo, primitive, r, intersection, normal, areas, - shadowIntensity, true); + hit = triangleIntersection(sceneInfo, primitive, r, + intersection, normal, + areas, shadowIntensity, + true); break; case ptCamera: hit = false; break; default: - hit = planeIntersection(sceneInfo, primitive, materials, textures, r, intersection, normal, + hit = planeIntersection(sceneInfo, primitive, + materials, textures, r, + intersection, normal, shadowIntensity, false); break; } } else { - hit = triangleIntersection(sceneInfo, primitive, r, intersection, normal, areas, + hit = triangleIntersection(sceneInfo, primitive, r, + intersection, normal, areas, shadowIntensity, true); } @@ -876,19 +984,36 @@ __device__ __INLINE__ float processShadows(const SceneInfo &sceneInfo, BoundingB float l = length(O_I); if (l > sceneInfo.geometryEpsilon && l < length(O_L)) { - float ratio = shadowIntensity * sceneInfo.shadowIntensity; - if (materials[primitive.materialId].transparency != 0.f) + float ratio = + shadowIntensity * sceneInfo.shadowIntensity; + if (materials[primitive.materialId].transparency != + 0.f) { // Shadow color O_L = normalize(O_L); float a = fabs(dot(O_L, normal)); - float r = (materials[primitive.materialId].transparency == 0.f) - ? 1.f - : (1.f - materials[primitive.materialId].transparency); + float r = + (materials[primitive.materialId] + .transparency == 0.f) + ? 1.f + : (1.f - materials[primitive.materialId] + .transparency); ratio *= r * a; - color.x += ratio * (0.3f - 0.3f * materials[primitive.materialId].color.x); - color.y += ratio * (0.3f - 0.3f * materials[primitive.materialId].color.y); - color.z += ratio * (0.3f - 0.3f * materials[primitive.materialId].color.z); + color.x += + ratio * + (0.3f - + 0.3f * materials[primitive.materialId] + .color.x); + color.y += + ratio * + (0.3f - + 0.3f * materials[primitive.materialId] + .color.y); + color.z += + ratio * + (0.3f - + 0.3f * materials[primitive.materialId] + .color.z); } result += ratio; } @@ -914,12 +1039,16 @@ Primitive shader ________________________________________________________________________________ */ __device__ __INLINE__ vec4f primitiveShader( - const int &index, const SceneInfo &sceneInfo, const PostProcessingInfo &postProcessingInfo, - BoundingBox *boundingBoxes, const int &nbActiveBoxes, Primitive *primitives, const int &nbActivePrimitives, - LightInformation *lightInformation, const int &lightInformationSize, const int &nbActiveLamps, Material *materials, - BitmapBuffer *textures, RandomBuffer *randoms, const vec3f &origin, vec3f &normal, const int &objectId, - vec3f &intersection, const vec3f &areas, vec4f &closestColor, const int &iteration, vec4f &refractionFromColor, - float &shadowIntensity, vec4f &totalBlinn, vec4f &attributes) + const int &index, const SceneInfo &sceneInfo, + const PostProcessingInfo &postProcessingInfo, BoundingBox *boundingBoxes, + const int &nbActiveBoxes, Primitive *primitives, + const int &nbActivePrimitives, LightInformation *lightInformation, + const int &lightInformationSize, const int &nbActiveLamps, + Material *materials, BitmapBuffer *textures, RandomBuffer *randoms, + const vec3f &origin, vec3f &normal, const int &objectId, + vec3f &intersection, const vec3f &areas, vec4f &closestColor, + const int &iteration, vec4f &refractionFromColor, float &shadowIntensity, + vec4f &totalBlinn, vec4f &attributes) { Primitive &primitive = primitives[objectId]; Material &material = materials[primitive.materialId]; @@ -939,8 +1068,10 @@ __device__ __INLINE__ vec4f primitiveShader( specular.z = material.specular.z; // Intersection color - vec4f intersectionColor = intersectionShader(sceneInfo, primitive, materials, textures, intersection, areas, - bumpNormal, specular, attributes, advancedAttributes); + vec4f intersectionColor = + intersectionShader(sceneInfo, primitive, materials, textures, + intersection, areas, bumpNormal, specular, + attributes, advancedAttributes); normal += bumpNormal; normal = normalize(normal); @@ -955,9 +1086,10 @@ __device__ __INLINE__ vec4f primitiveShader( closestColor *= material.innerIllumination.x; for (int cpt = 0; cpt < lightInformationSize; ++cpt) { - int cptLamp = (sceneInfo.pathTracingIteration >= NB_MAX_ITERATIONS) - ? (sceneInfo.pathTracingIteration % lightInformationSize) - : 0; + int cptLamp = + (sceneInfo.pathTracingIteration >= NB_MAX_ITERATIONS) + ? (sceneInfo.pathTracingIteration % lightInformationSize) + : 0; if (lightInformation[cptLamp].primitiveId != primitive.index) { vec3f center; @@ -968,7 +1100,8 @@ __device__ __INLINE__ vec4f primitiveShader( Material &m = materials[lightInformation[cptLamp].materialId]; if (sceneInfo.pathTracingIteration >= NB_MAX_ITERATIONS) { - float a = m.innerIllumination.y * 10.f * sceneInfo.pathTracingIteration / + float a = m.innerIllumination.y * 10.f * + sceneInfo.pathTracingIteration / sceneInfo.maxPathTracingIterations; center.x += randoms[t] * a; center.y += randoms[t + 1] * a; @@ -984,51 +1117,68 @@ __device__ __INLINE__ vec4f primitiveShader( // Lambert // -------------------------------------------------------------------------------- lightRay = normalize(lightRay); - float lambert = material.innerIllumination.x + dot(normal, lightRay); + float lambert = + material.innerIllumination.x + dot(normal, lightRay); if (lambert > 0.f && sceneInfo.graphicsLevel > 3 && - iteration < 4 && // No need to process shadows after 4 generations - // of rays... cannot be seen anyway. + iteration < 4 && // No need to process shadows after 4 + // generations of rays... cannot be + // seen anyway. material.innerIllumination.x == 0.f) { - shadowIntensity = - processShadows(sceneInfo, boundingBoxes, nbActiveBoxes, primitives, materials, textures, - nbActivePrimitives, center, intersection, - lightInformation[cptLamp].primitiveId, iteration, shadowColor, objectId); + shadowIntensity = processShadows( + sceneInfo, boundingBoxes, nbActiveBoxes, primitives, + materials, textures, nbActivePrimitives, center, + intersection, lightInformation[cptLamp].primitiveId, + iteration, shadowColor, objectId); } if (sceneInfo.graphicsLevel > glNoShading) { - float photonEnergy = sqrt(lightRayLength / m.innerIllumination.z); - photonEnergy = (photonEnergy > 1.f) ? 1.f : photonEnergy; - photonEnergy = (photonEnergy < 0.f) ? 0.f : photonEnergy; - - // Transparent materials are lighted on both sides but the amount - // of light received by the "dark side" + float photonEnergy = + sqrt(lightRayLength / m.innerIllumination.z); + photonEnergy = + (photonEnergy > 1.f) ? 1.f : photonEnergy; + photonEnergy = + (photonEnergy < 0.f) ? 0.f : photonEnergy; + + // Transparent materials are lighted on both sides but + // the amount of light received by the "dark side" // depends on the transparency rate. - lambert *= (lambert < 0.f) ? -materials[primitive.materialId].transparency : 1.f; + lambert *= + (lambert < 0.f) + ? -materials[primitive.materialId].transparency + : 1.f; - if (lightInformation[cptLamp].materialId != MATERIAL_NONE) + if (lightInformation[cptLamp].materialId != + MATERIAL_NONE) { - Material &m = materials[lightInformation[cptLamp].materialId]; - lambert *= m.innerIllumination.x; // Lamp illumination + Material &m = + materials[lightInformation[cptLamp].materialId]; + lambert *= + m.innerIllumination.x; // Lamp illumination } else lambert *= lightInformation[cptLamp].color.w; if (material.innerIllumination.w != 0.f) - // Randomize lamp intensity depending on material noise, for - // more realistic rendering - lambert *= (1.f + randoms[t] * material.innerIllumination.w * 100.f); + // Randomize lamp intensity depending on material + // noise, for more realistic rendering + lambert *= (1.f + randoms[t] * + material.innerIllumination.w * + 100.f); lambert *= (1.f - shadowIntensity); lambert += sceneInfo.backgroundColor.w; lambert *= (1.f - photonEnergy); // Lighted object, not in the shades - lampsColor += lambert * lightInformation[cptLamp].color - shadowColor; + lampsColor += + lambert * lightInformation[cptLamp].color - + shadowColor; - if (sceneInfo.graphicsLevel > 1 && shadowIntensity < sceneInfo.shadowIntensity) + if (sceneInfo.graphicsLevel > 1 && + shadowIntensity < sceneInfo.shadowIntensity) { // -------------------------------------------------------------------------------- // Blinn - Phong @@ -1043,10 +1193,13 @@ __device__ __INLINE__ vec4f primitiveShader( float blinnTerm = dot(blinnDir, normal); blinnTerm = (blinnTerm < 0.f) ? 0.f : blinnTerm; - blinnTerm = specular.x * pow(blinnTerm, specular.y); + blinnTerm = + specular.x * pow(blinnTerm, specular.y); blinnTerm *= (1.f - photonEnergy); totalBlinn += - lightInformation[cptLamp].color * lightInformation[cptLamp].color.w * blinnTerm; + lightInformation[cptLamp].color * + lightInformation[cptLamp].color.w * + blinnTerm; // Get transparency from specular map totalBlinn.w = specular.z; @@ -1068,7 +1221,8 @@ __device__ __INLINE__ vec4f primitiveShader( // Saturate color saturateVector(closestColor); - refractionFromColor = intersectionColor; // Refraction depending on color; + refractionFromColor = + intersectionColor; // Refraction depending on color; saturateVector(totalBlinn); } } @@ -1086,10 +1240,12 @@ Intersections with primitives ________________________________________________________________________________ */ __device__ __INLINE__ vec4f intersectionsWithPrimitives( - const int &index, const SceneInfo &sceneInfo, BoundingBox *boundingBoxes, const int &nbActiveBoxes, - Primitive *primitives, const int &nbActivePrimitives, Material *materials, BitmapBuffer *textures, - LightInformation *lightInformation, const int &lightInformationSize, const int &nbActiveLamps, - RandomBuffer *randoms, const PostProcessingInfo &postProcessingInfo, const Ray &ray) + const int &index, const SceneInfo &sceneInfo, BoundingBox *boundingBoxes, + const int &nbActiveBoxes, Primitive *primitives, + const int &nbActivePrimitives, Material *materials, BitmapBuffer *textures, + LightInformation *lightInformation, const int &lightInformationSize, + const int &nbActiveLamps, RandomBuffer *randoms, + const PostProcessingInfo &postProcessingInfo, const Ray &ray) { Ray r; r.origin = ray.origin; @@ -1123,10 +1279,12 @@ __device__ __INLINE__ vec4f intersectionsWithPrimitives( if (boxIntersection(box, r, 0.f, sceneInfo.viewDistance)) { // Intersection with primitive within boxes - for (int cptPrimitives = 0; cptPrimitives < box.nbPrimitives; ++cptPrimitives) + for (int cptPrimitives = 0; cptPrimitives < box.nbPrimitives; + ++cptPrimitives) { i = false; - Primitive &primitive = primitives[box.startIndex + cptPrimitives]; + Primitive &primitive = + primitives[box.startIndex + cptPrimitives]; Material &material = materials[primitive.materialId]; vec3f areas = {0.f, 0.f, 0.f}; if (sceneInfo.extendedGeometry) @@ -1135,34 +1293,42 @@ __device__ __INLINE__ vec4f intersectionsWithPrimitives( { case ptEnvironment: case ptSphere: - i = sphereIntersection(sceneInfo, primitive, materials, r, intersection, normal, + i = sphereIntersection(sceneInfo, primitive, materials, + r, intersection, normal, shadowIntensity); break; case ptCylinder: - i = cylinderIntersection(sceneInfo, primitive, materials, r, intersection, normal, - shadowIntensity); + i = cylinderIntersection(sceneInfo, primitive, + materials, r, intersection, + normal, shadowIntensity); break; case ptCone: - i = coneIntersection(sceneInfo, primitive, materials, r, intersection, normal, shadowIntensity); + i = coneIntersection(sceneInfo, primitive, materials, r, + intersection, normal, + shadowIntensity); break; case ptEllipsoid: - i = ellipsoidIntersection(sceneInfo, primitive, materials, r, intersection, normal, - shadowIntensity); + i = ellipsoidIntersection(sceneInfo, primitive, + materials, r, intersection, + normal, shadowIntensity); break; case ptTriangle: - i = triangleIntersection(sceneInfo, primitive, r, intersection, normal, areas, shadowIntensity, - false); + i = triangleIntersection(sceneInfo, primitive, r, + intersection, normal, areas, + shadowIntensity, false); break; default: - i = planeIntersection(sceneInfo, primitive, materials, textures, r, intersection, normal, + i = planeIntersection(sceneInfo, primitive, materials, + textures, r, intersection, normal, shadowIntensity, false); break; } } else { - i = triangleIntersection(sceneInfo, primitive, r, intersection, normal, areas, shadowIntensity, - false); + i = triangleIntersection(sceneInfo, primitive, r, + intersection, normal, areas, + shadowIntensity, false); } if (i) { @@ -1183,18 +1349,23 @@ __device__ __INLINE__ vec4f intersectionsWithPrimitives( vec4f refractionFromColor; vec4f closestColor = material.color; shadowIntensity = 0.f; - color = - primitiveShader(index, sceneInfo, postProcessingInfo, boundingBoxes, nbActiveBoxes, - primitives, nbActivePrimitives, lightInformation, lightInformationSize, - nbActiveLamps, materials, textures, randoms, r.origin, normal, - box.startIndex + cptPrimitives, intersection, areas, closestColor, 0, - refractionFromColor, shadowIntensity, rBlinn, attributes); + color = primitiveShader( + index, sceneInfo, postProcessingInfo, + boundingBoxes, nbActiveBoxes, primitives, + nbActivePrimitives, lightInformation, + lightInformationSize, nbActiveLamps, materials, + textures, randoms, r.origin, normal, + box.startIndex + cptPrimitives, intersection, + areas, closestColor, 0, refractionFromColor, + shadowIntensity, rBlinn, attributes); } for (int i(0); i < MAXDEPTH; ++i) { if (dist < colors[i].w) { - float a = dot(normalize(ray.direction - ray.origin), normal); + float a = + dot(normalize(ray.direction - ray.origin), + normal); for (int j(MAXDEPTH - 1); j >= i; --j) { colors[j + 1] = colors[j]; diff --git a/solr/engines/cuda/GeometryShaders.cuh b/solr/engines/cuda/GeometryShaders.cuh index 9ce255f..750d7a9 100644 --- a/solr/engines/cuda/GeometryShaders.cuh +++ b/solr/engines/cuda/GeometryShaders.cuh @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau - * - * This file is part of Sol-R +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once @@ -33,12 +30,17 @@ ________________________________________________________________________________ Intersection Shader ________________________________________________________________________________ */ -__device__ vec4f intersectionShader(const SceneInfo &sceneInfo, const Primitive &primitive, Material *materials, - BitmapBuffer *textures, vec3f &intersection, const vec3f &areas, vec3f &normal, - vec4f &specular, vec4f &attributes, vec4f &advancedAttributes) +__device__ vec4f intersectionShader(const SceneInfo &sceneInfo, + const Primitive &primitive, + Material *materials, BitmapBuffer *textures, + vec3f &intersection, const vec3f &areas, + vec3f &normal, vec4f &specular, + vec4f &attributes, + vec4f &advancedAttributes) { vec4f colorAtIntersection = materials[primitive.materialId].color; - colorAtIntersection.w = 0.f; // w attribute is used to dtermine light intensity of the material + colorAtIntersection.w = + 0.f; // w attribute is used to dtermine light intensity of the material if (sceneInfo.extendedGeometry) { @@ -52,8 +54,10 @@ __device__ vec4f intersectionShader(const SceneInfo &sceneInfo, const Primitive { if (materials[primitive.materialId].textureIds.x != TEXTURE_NONE) { - colorAtIntersection = sphereUVMapping(primitive, materials, textures, intersection, normal, specular, - attributes, advancedAttributes); + colorAtIntersection = + sphereUVMapping(primitive, materials, textures, + intersection, normal, specular, attributes, + advancedAttributes); } break; } @@ -61,13 +65,17 @@ __device__ vec4f intersectionShader(const SceneInfo &sceneInfo, const Primitive { if (materials[primitive.materialId].textureIds.x != TEXTURE_NONE) { - colorAtIntersection = cubeMapping(sceneInfo, primitive, materials, textures, intersection, normal, - specular, attributes, advancedAttributes); + colorAtIntersection = + cubeMapping(sceneInfo, primitive, materials, textures, + intersection, normal, specular, attributes, + advancedAttributes); } else { - int x = sceneInfo.viewDistance + ((intersection.x - primitive.p0.x) / primitive.size.x); - int z = sceneInfo.viewDistance + ((intersection.z - primitive.p0.z) / primitive.size.x); + int x = sceneInfo.viewDistance + + ((intersection.x - primitive.p0.x) / primitive.size.x); + int z = sceneInfo.viewDistance + + ((intersection.z - primitive.p0.z) / primitive.size.x); if (x % 2 == 0) { if (z % 2 == 0) @@ -96,8 +104,10 @@ __device__ vec4f intersectionShader(const SceneInfo &sceneInfo, const Primitive { if (materials[primitive.materialId].textureIds.x != TEXTURE_NONE) { - colorAtIntersection = cubeMapping(sceneInfo, primitive, materials, textures, intersection, normal, - specular, attributes, advancedAttributes); + colorAtIntersection = + cubeMapping(sceneInfo, primitive, materials, textures, + intersection, normal, specular, attributes, + advancedAttributes); } break; } @@ -105,8 +115,10 @@ __device__ vec4f intersectionShader(const SceneInfo &sceneInfo, const Primitive { if (materials[primitive.materialId].textureIds.x != TEXTURE_NONE) { - colorAtIntersection = triangleUVMapping(sceneInfo, primitive, materials, textures, intersection, areas, - normal, specular, attributes, advancedAttributes); + colorAtIntersection = + triangleUVMapping(sceneInfo, primitive, materials, textures, + intersection, areas, normal, specular, + attributes, advancedAttributes); } break; } @@ -116,8 +128,10 @@ __device__ vec4f intersectionShader(const SceneInfo &sceneInfo, const Primitive { if (materials[primitive.materialId].textureIds.x != TEXTURE_NONE) { - colorAtIntersection = triangleUVMapping(sceneInfo, primitive, materials, textures, intersection, areas, - normal, specular, attributes, advancedAttributes); + colorAtIntersection = + triangleUVMapping(sceneInfo, primitive, materials, textures, + intersection, areas, normal, specular, + attributes, advancedAttributes); } } return colorAtIntersection; @@ -129,7 +143,8 @@ ________________________________________________________________________________ Convert vec4f into OpenGL RGB color ________________________________________________________________________________ */ -__device__ __INLINE__ void makeColor(const SceneInfo &sceneInfo, vec4f &color, BitmapBuffer *bitmap, int index) +__device__ __INLINE__ void makeColor(const SceneInfo &sceneInfo, vec4f &color, + BitmapBuffer *bitmap, int index) { int mdc_index = index * gColorDepth; color.x = (color.x > 1.f) ? 1.f : color.x; @@ -153,13 +168,13 @@ __device__ __INLINE__ void makeColor(const SceneInfo &sceneInfo, vec4f &color, B bitmap[i + 2] = (BitmapBuffer)(color.x * 255.f); // Red break; } - default: - { - // OpenGL - bitmap[mdc_index] = (BitmapBuffer)(color.x * 255.f); // Red - bitmap[mdc_index + 1] = (BitmapBuffer)(color.y * 255.f); // Green - bitmap[mdc_index + 2] = (BitmapBuffer)(color.z * 255.f); // Blue - break; - } - } + default: + { + // OpenGL + bitmap[mdc_index] = (BitmapBuffer)(color.x * 255.f); // Red + bitmap[mdc_index + 1] = (BitmapBuffer)(color.y * 255.f); // Green + bitmap[mdc_index + 2] = (BitmapBuffer)(color.z * 255.f); // Blue + break; + } + } } diff --git a/solr/engines/cuda/TextureMapping.cuh b/solr/engines/cuda/TextureMapping.cuh index e896f61..7a52c24 100644 --- a/solr/engines/cuda/TextureMapping.cuh +++ b/solr/engines/cuda/TextureMapping.cuh @@ -1,33 +1,31 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau - * - * This file is part of Sol-R +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once // Project -#include "../../types.h" +#include "../../solr.h" #include "VectorUtils.cuh" // ---------- // Normal mapping // -------------------- -__device__ __INLINE__ void normalMap(const int &index, const Material &material, BitmapBuffer *textures, vec3f &normal, +__device__ __INLINE__ void normalMap(const int &index, const Material &material, + BitmapBuffer *textures, vec3f &normal, const float strength) { int i = material.textureOffset.y + index; @@ -42,8 +40,9 @@ __device__ __INLINE__ void normalMap(const int &index, const Material &material, // ---------- // Bump mapping // -------------------- -__device__ __INLINE__ void bumpMap(const int &index, const Material &material, BitmapBuffer *textures, - vec3f &intersection, float &value) +__device__ __INLINE__ void bumpMap(const int &index, const Material &material, + BitmapBuffer *textures, vec3f &intersection, + float &value) { int i = material.textureOffset.z + index; BitmapBuffer r, g, b; @@ -59,8 +58,9 @@ __device__ __INLINE__ void bumpMap(const int &index, const Material &material, B // ---------- // Normal mapping // -------------------- -__device__ __INLINE__ void specularMap(const int &index, const Material &material, BitmapBuffer *textures, - vec4f &specular) +__device__ __INLINE__ void specularMap(const int &index, + const Material &material, + BitmapBuffer *textures, vec4f &specular) { int i = material.textureOffset.w + index; BitmapBuffer r, g, b; @@ -75,7 +75,9 @@ __device__ __INLINE__ void specularMap(const int &index, const Material &materia // ---------- // Reflection mapping // -------------------- -__device__ __INLINE__ void reflectionMap(const int &index, const Material &material, BitmapBuffer *textures, +__device__ __INLINE__ void reflectionMap(const int &index, + const Material &material, + BitmapBuffer *textures, vec4f &attributes) { int i = material.advancedTextureOffset.x + index; @@ -89,7 +91,9 @@ __device__ __INLINE__ void reflectionMap(const int &index, const Material &mater // ---------- // Transparency mapping // -------------------- -__device__ __INLINE__ void transparencyMap(const int &index, const Material &material, BitmapBuffer *textures, +__device__ __INLINE__ void transparencyMap(const int &index, + const Material &material, + BitmapBuffer *textures, vec4f &attributes) { int i = material.advancedTextureOffset.y + index; @@ -104,7 +108,9 @@ __device__ __INLINE__ void transparencyMap(const int &index, const Material &mat // ---------- // Ambient occlusion // -------------------- -__device__ __INLINE__ void ambientOcclusionMap(const int &index, const Material &material, BitmapBuffer *textures, +__device__ __INLINE__ void ambientOcclusionMap(const int &index, + const Material &material, + BitmapBuffer *textures, vec4f &advancedAttributes) { int i = material.advancedTextureOffset.z + index; @@ -115,15 +121,17 @@ __device__ __INLINE__ void ambientOcclusionMap(const int &index, const Material advancedAttributes.x = (r + g + b) / 768.f; } -__device__ __INLINE__ void juliaSet(const Primitive &primitive, Material *materials, const SceneInfo &sceneInfo, - const float x, const float y, float4 &color) +__device__ __INLINE__ void juliaSet(const Primitive &primitive, + Material *materials, + const SceneInfo &sceneInfo, const float x, + const float y, float4 &color) { Material &material = materials[primitive.materialId]; float W = (float)material.textureMapping.x; float H = (float)material.textureMapping.y; - // pick some values for the constant c, this determines the shape of the Julia - // Set + // pick some values for the constant c, this determines the shape of the + // Julia Set float cRe = -0.7f + 0.4f * sinf(sceneInfo.timestamp / 1500.f); float cIm = 0.27015f + 0.4f * cosf(sceneInfo.timestamp / 2000.f); @@ -147,18 +155,19 @@ __device__ __INLINE__ void juliaSet(const Primitive &primitive, Material *materi if ((newRe * newRe + newIm * newIm) > 4.f) break; } - // use color model conversion to get rainbow palette, make brightness black if - // maxIterations reached - // color.x += newRe/4.f; - // color.z += newIm/4.f; + // use color model conversion to get rainbow palette, make brightness black + // if maxIterations reached color.x += newRe/4.f; color.z += newIm/4.f; color.x = 1.f - color.x * (n / maxIterations); color.y = 1.f - color.y * (n / maxIterations); color.z = 1.f - color.z * (n / maxIterations); color.w = 1.f - (n / maxIterations); } -__device__ __INLINE__ void mandelbrotSet(const Primitive &primitive, Material *materials, const SceneInfo &sceneInfo, - const float x, const float y, float4 &color) +__device__ __INLINE__ void mandelbrotSet(const Primitive &primitive, + Material *materials, + const SceneInfo &sceneInfo, + const float x, const float y, + float4 &color) { Material &material = materials[primitive.materialId]; float W = (float)material.textureMapping.x; @@ -202,16 +211,18 @@ ________________________________________________________________________________ Triangle texture Mapping ________________________________________________________________________________ */ -__device__ __INLINE__ float4 triangleUVMapping(const SceneInfo &sceneInfo, const Primitive &primitive, - Material *materials, BitmapBuffer *textures, vec3f &intersection, - const vec3f &areas, vec3f &normal, vec4f &specular, vec4f &attributes, - vec4f &advancedAttributes) +__device__ __INLINE__ float4 triangleUVMapping( + const SceneInfo &sceneInfo, const Primitive &primitive, Material *materials, + BitmapBuffer *textures, vec3f &intersection, const vec3f &areas, + vec3f &normal, vec4f &specular, vec4f &attributes, + vec4f &advancedAttributes) { Material &material = materials[primitive.materialId]; float4 result = material.color; - vec2f T = - (primitive.vt0 * areas.x + primitive.vt1 * areas.y + primitive.vt2 * areas.z) / (areas.x + areas.y + areas.z); + vec2f T = (primitive.vt0 * areas.x + primitive.vt1 * areas.y + + primitive.vt2 * areas.z) / + (areas.x + areas.y + areas.z); float2 mappingOffset = {0.f, 0.f}; if (material.attributes.y == 1) { @@ -223,7 +234,8 @@ __device__ __INLINE__ float4 triangleUVMapping(const SceneInfo &sceneInfo, const u = u % material.textureMapping.x; v = v % material.textureMapping.y; - if (u >= 0 && u < material.textureMapping.x && v >= 0 && v < material.textureMapping.y) + if (u >= 0 && u < material.textureMapping.x && v >= 0 && + v < material.textureMapping.y) { switch (material.textureIds.x) { @@ -235,8 +247,10 @@ __device__ __INLINE__ float4 triangleUVMapping(const SceneInfo &sceneInfo, const break; default: { - int A = (v * material.textureMapping.x + u) * material.textureMapping.w; - int B = material.textureMapping.x * material.textureMapping.y * material.textureMapping.w; + int A = + (v * material.textureMapping.x + u) * material.textureMapping.w; + int B = material.textureMapping.x * material.textureMapping.y * + material.textureMapping.w; int index = A % B; // Diffuse @@ -275,7 +289,8 @@ __device__ __INLINE__ float4 triangleUVMapping(const SceneInfo &sceneInfo, const transparencyMap(index, material, textures, attributes); // Ambient occulusion mapping if (material.advancedTextureIds.z != TEXTURE_NONE) - ambientOcclusionMap(index, material, textures, advancedAttributes); + ambientOcclusionMap(index, material, textures, + advancedAttributes); } } } @@ -288,8 +303,11 @@ ________________________________________________________________________________ Sphere texture Mapping ________________________________________________________________________________ */ -__device__ __INLINE__ float4 sphereUVMapping(const Primitive &primitive, Material *materials, BitmapBuffer *textures, - vec3f &intersection, vec3f &normal, vec4f &specular, vec4f &attributes, +__device__ __INLINE__ float4 sphereUVMapping(const Primitive &primitive, + Material *materials, + BitmapBuffer *textures, + vec3f &intersection, vec3f &normal, + vec4f &specular, vec4f &attributes, vec4f &advancedAttributes) { Material &material = materials[primitive.materialId]; @@ -306,10 +324,12 @@ __device__ __INLINE__ float4 sphereUVMapping(const Primitive &primitive, Materia u = u % material.textureMapping.x; if (material.textureMapping.y != 0) v = v % material.textureMapping.y; - if (u >= 0 && u < material.textureMapping.x && v >= 0 && v < material.textureMapping.y) + if (u >= 0 && u < material.textureMapping.x && v >= 0 && + v < material.textureMapping.y) { int A = (v * material.textureMapping.x + u) * material.textureMapping.w; - int B = material.textureMapping.x * material.textureMapping.y * material.textureMapping.w; + int B = material.textureMapping.x * material.textureMapping.y * + material.textureMapping.w; int index = A % B; // Diffuse @@ -351,9 +371,10 @@ ________________________________________________________________________________ Cube texture mapping ________________________________________________________________________________ */ -__device__ __INLINE__ float4 cubeMapping(const SceneInfo &sceneInfo, const Primitive &primitive, Material *materials, - BitmapBuffer *textures, vec3f &intersection, vec3f &normal, vec4f &specular, - vec4f &attributes, vec4f &advancedAttributes) +__device__ __INLINE__ float4 cubeMapping( + const SceneInfo &sceneInfo, const Primitive &primitive, Material *materials, + BitmapBuffer *textures, vec3f &intersection, vec3f &normal, vec4f &specular, + vec4f &attributes, vec4f &advancedAttributes) { Material &material = materials[primitive.materialId]; float4 result = material.color; @@ -361,16 +382,22 @@ __device__ __INLINE__ float4 cubeMapping(const SceneInfo &sceneInfo, const Primi #ifdef USE_KINECT if (primitive.type == ptCamera) { - int x = (intersection.x - primitive.p0.x + primitive.size.x) * material.textureMapping.x; - int y = KINECT_COLOR_HEIGHT - (intersection.y - primitive.p0.y + primitive.size.y) * material.textureMapping.y; + int x = (intersection.x - primitive.p0.x + primitive.size.x) * + material.textureMapping.x; + int y = KINECT_COLOR_HEIGHT - + (intersection.y - primitive.p0.y + primitive.size.y) * + material.textureMapping.y; x = (x + KINECT_COLOR_WIDTH) % KINECT_COLOR_WIDTH; y = (y + KINECT_COLOR_HEIGHT) % KINECT_COLOR_HEIGHT; - if (x >= 0 && x < KINECT_COLOR_WIDTH && y >= 0 && y < KINECT_COLOR_HEIGHT) + if (x >= 0 && x < KINECT_COLOR_WIDTH && y >= 0 && + y < KINECT_COLOR_HEIGHT) { int index = (y * KINECT_COLOR_WIDTH + x) * KINECT_COLOR_DEPTH; - index = index % (material.textureMapping.x * material.textureMapping.y * material.textureMapping.w); + index = + index % (material.textureMapping.x * material.textureMapping.y * + material.textureMapping.w); BitmapBuffer r = textures[index + 2]; BitmapBuffer g = textures[index + 1]; BitmapBuffer b = textures[index + 0]; @@ -382,20 +409,23 @@ __device__ __INLINE__ float4 cubeMapping(const SceneInfo &sceneInfo, const Primi else #endif // USE_KINECT { - int u = ((primitive.type == ptCheckboard) || (primitive.type == ptXZPlane) || (primitive.type == ptXYPlane)) + int u = ((primitive.type == ptCheckboard) || + (primitive.type == ptXZPlane) || (primitive.type == ptXYPlane)) ? (intersection.x - primitive.p0.x + primitive.size.x) : (intersection.z - primitive.p0.z + primitive.size.z); - int v = ((primitive.type == ptCheckboard) || (primitive.type == ptXZPlane)) - ? (intersection.z + primitive.p0.z + primitive.size.z) - : (intersection.y - primitive.p0.y + primitive.size.y); + int v = + ((primitive.type == ptCheckboard) || (primitive.type == ptXZPlane)) + ? (intersection.z + primitive.p0.z + primitive.size.z) + : (intersection.y - primitive.p0.y + primitive.size.y); if (material.textureMapping.x != 0) u = u % material.textureMapping.x; if (material.textureMapping.y != 0) v = v % material.textureMapping.y; - if (u >= 0 && u < material.textureMapping.x && v >= 0 && v < material.textureMapping.x) + if (u >= 0 && u < material.textureMapping.x && v >= 0 && + v < material.textureMapping.x) { switch (material.textureIds.x) { @@ -407,8 +437,10 @@ __device__ __INLINE__ float4 cubeMapping(const SceneInfo &sceneInfo, const Primi break; default: { - int A = (v * material.textureMapping.x + u) * material.textureMapping.w; - int B = material.textureMapping.x * material.textureMapping.y * material.textureMapping.w; + int A = (v * material.textureMapping.x + u) * + material.textureMapping.w; + int B = material.textureMapping.x * material.textureMapping.y * + material.textureMapping.w; int index = A % B; int i = material.textureOffset.x + index; BitmapBuffer r, g, b; @@ -437,7 +469,8 @@ __device__ __INLINE__ float4 cubeMapping(const SceneInfo &sceneInfo, const Primi transparencyMap(index, material, textures, attributes); // Ambient occulusion mapping if (material.advancedTextureIds.z != TEXTURE_NONE) - ambientOcclusionMap(index, material, textures, advancedAttributes); + ambientOcclusionMap(index, material, textures, + advancedAttributes); } break; } @@ -446,7 +479,8 @@ __device__ __INLINE__ float4 cubeMapping(const SceneInfo &sceneInfo, const Primi return result; } -__device__ __INLINE__ bool wireFrameMapping(float x, float y, int width, const Primitive &primitive) +__device__ __INLINE__ bool wireFrameMapping(float x, float y, int width, + const Primitive &primitive) { int X = abs(x); int Y = abs(y); diff --git a/solr/engines/cuda/VectorUtils.cuh b/solr/engines/cuda/VectorUtils.cuh index 55bbaa9..89ef7a3 100644 --- a/solr/engines/cuda/VectorUtils.cuh +++ b/solr/engines/cuda/VectorUtils.cuh @@ -1,31 +1,30 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau - * - * This file is part of Sol-R +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once // Project -#include "../../types.h" +#include "../../solr.h" // Cuda -#include "helper_math.h" #include "helper_cuda.h" +#include "helper_math.h" + +using namespace solr; // _____________________________________________________________________________________________________________________ __device__ __INLINE__ void saturateVector(float4 &v) @@ -53,24 +52,27 @@ __device__ __INLINE__ vec3f crossProduct(const vec3f &b, const vec3f &c) /* ________________________________________________________________________________________________________________________ -incident : le vecteur normal inverse a la direction d'incidence de la source lumineuse -normal : la normale a l'interface orientee dans le materiau ou se propage le rayon incident -reflected : le vecteur normal reflechi +incident : le vecteur normal inverse a la direction d'incidence de la source +lumineuse normal : la normale a l'interface orientee dans le materiau ou se +propage le rayon incident reflected : le vecteur normal reflechi ________________________________________________________________________________________________________________________ */ -__device__ __INLINE__ void vectorReflection(vec3f &r, const vec3f &i, const vec3f &n) +__device__ __INLINE__ void vectorReflection(vec3f &r, const vec3f &i, + const vec3f &n) { r = i - 2.f * dot(i, n) * n; } /* ________________________________________________________________________________________________________________________ -incident: le vecteur norm? inverse ? la direction d?incidence de la source lumineuse -n1 : index of refraction of original medium -n2 : index of refraction of new medium +incident: le vecteur norm? inverse ? la direction d?incidence de la source +lumineuse n1 : index of refraction of original medium n2 : index of +refraction of new medium ________________________________________________________________________________________________________________________ */ -__device__ __INLINE__ void vectorRefraction(vec3f &refracted, const vec3f incident, const float n1, const vec3f normal, +__device__ __INLINE__ void vectorRefraction(vec3f &refracted, + const vec3f incident, + const float n1, const vec3f normal, const float n2) { refracted = incident; @@ -101,7 +103,8 @@ __c : Center of rotations __a : Angles ________________________________________________________________________________________________________________________ */ -__device__ __INLINE__ void vectorRotation(vec3f &v, const vec3f &rotationCenter, const vec4f &angles) +__device__ __INLINE__ void vectorRotation(vec3f &v, const vec3f &rotationCenter, + const vec4f &angles) { vec4f cosAngles, sinAngles; diff --git a/solr/engines/cuda/helper_cuda.h b/solr/engines/cuda/helper_cuda.h index 410e131..fc9db96 100644 --- a/solr/engines/cuda/helper_cuda.h +++ b/solr/engines/cuda/helper_cuda.h @@ -65,673 +65,687 @@ inline void EXIT_DELAY(int return_code) // CUDA Runtime error messages #ifdef __DRIVER_TYPES_H__ -static const char *_cudaGetErrorEnum(cudaError_t error) { - switch (error) { - case cudaSuccess: - return "cudaSuccess"; +static const char *_cudaGetErrorEnum(cudaError_t error) +{ + switch (error) + { + case cudaSuccess: + return "cudaSuccess"; - case cudaErrorMissingConfiguration: - return "cudaErrorMissingConfiguration"; + case cudaErrorMissingConfiguration: + return "cudaErrorMissingConfiguration"; - case cudaErrorMemoryAllocation: - return "cudaErrorMemoryAllocation"; + case cudaErrorMemoryAllocation: + return "cudaErrorMemoryAllocation"; - case cudaErrorInitializationError: - return "cudaErrorInitializationError"; + case cudaErrorInitializationError: + return "cudaErrorInitializationError"; - case cudaErrorLaunchFailure: - return "cudaErrorLaunchFailure"; + case cudaErrorLaunchFailure: + return "cudaErrorLaunchFailure"; - case cudaErrorPriorLaunchFailure: - return "cudaErrorPriorLaunchFailure"; + case cudaErrorPriorLaunchFailure: + return "cudaErrorPriorLaunchFailure"; - case cudaErrorLaunchTimeout: - return "cudaErrorLaunchTimeout"; + case cudaErrorLaunchTimeout: + return "cudaErrorLaunchTimeout"; - case cudaErrorLaunchOutOfResources: - return "cudaErrorLaunchOutOfResources"; + case cudaErrorLaunchOutOfResources: + return "cudaErrorLaunchOutOfResources"; - case cudaErrorInvalidDeviceFunction: - return "cudaErrorInvalidDeviceFunction"; + case cudaErrorInvalidDeviceFunction: + return "cudaErrorInvalidDeviceFunction"; - case cudaErrorInvalidConfiguration: - return "cudaErrorInvalidConfiguration"; + case cudaErrorInvalidConfiguration: + return "cudaErrorInvalidConfiguration"; - case cudaErrorInvalidDevice: - return "cudaErrorInvalidDevice"; + case cudaErrorInvalidDevice: + return "cudaErrorInvalidDevice"; - case cudaErrorInvalidValue: - return "cudaErrorInvalidValue"; + case cudaErrorInvalidValue: + return "cudaErrorInvalidValue"; - case cudaErrorInvalidPitchValue: - return "cudaErrorInvalidPitchValue"; + case cudaErrorInvalidPitchValue: + return "cudaErrorInvalidPitchValue"; - case cudaErrorInvalidSymbol: - return "cudaErrorInvalidSymbol"; + case cudaErrorInvalidSymbol: + return "cudaErrorInvalidSymbol"; - case cudaErrorMapBufferObjectFailed: - return "cudaErrorMapBufferObjectFailed"; + case cudaErrorMapBufferObjectFailed: + return "cudaErrorMapBufferObjectFailed"; - case cudaErrorUnmapBufferObjectFailed: - return "cudaErrorUnmapBufferObjectFailed"; + case cudaErrorUnmapBufferObjectFailed: + return "cudaErrorUnmapBufferObjectFailed"; - case cudaErrorInvalidHostPointer: - return "cudaErrorInvalidHostPointer"; + case cudaErrorInvalidHostPointer: + return "cudaErrorInvalidHostPointer"; - case cudaErrorInvalidDevicePointer: - return "cudaErrorInvalidDevicePointer"; + case cudaErrorInvalidDevicePointer: + return "cudaErrorInvalidDevicePointer"; - case cudaErrorInvalidTexture: - return "cudaErrorInvalidTexture"; + case cudaErrorInvalidTexture: + return "cudaErrorInvalidTexture"; - case cudaErrorInvalidTextureBinding: - return "cudaErrorInvalidTextureBinding"; + case cudaErrorInvalidTextureBinding: + return "cudaErrorInvalidTextureBinding"; - case cudaErrorInvalidChannelDescriptor: - return "cudaErrorInvalidChannelDescriptor"; + case cudaErrorInvalidChannelDescriptor: + return "cudaErrorInvalidChannelDescriptor"; - case cudaErrorInvalidMemcpyDirection: - return "cudaErrorInvalidMemcpyDirection"; + case cudaErrorInvalidMemcpyDirection: + return "cudaErrorInvalidMemcpyDirection"; - case cudaErrorAddressOfConstant: - return "cudaErrorAddressOfConstant"; + case cudaErrorAddressOfConstant: + return "cudaErrorAddressOfConstant"; - case cudaErrorTextureFetchFailed: - return "cudaErrorTextureFetchFailed"; + case cudaErrorTextureFetchFailed: + return "cudaErrorTextureFetchFailed"; - case cudaErrorTextureNotBound: - return "cudaErrorTextureNotBound"; + case cudaErrorTextureNotBound: + return "cudaErrorTextureNotBound"; - case cudaErrorSynchronizationError: - return "cudaErrorSynchronizationError"; + case cudaErrorSynchronizationError: + return "cudaErrorSynchronizationError"; - case cudaErrorInvalidFilterSetting: - return "cudaErrorInvalidFilterSetting"; + case cudaErrorInvalidFilterSetting: + return "cudaErrorInvalidFilterSetting"; - case cudaErrorInvalidNormSetting: - return "cudaErrorInvalidNormSetting"; + case cudaErrorInvalidNormSetting: + return "cudaErrorInvalidNormSetting"; - case cudaErrorMixedDeviceExecution: - return "cudaErrorMixedDeviceExecution"; + case cudaErrorMixedDeviceExecution: + return "cudaErrorMixedDeviceExecution"; - case cudaErrorCudartUnloading: - return "cudaErrorCudartUnloading"; + case cudaErrorCudartUnloading: + return "cudaErrorCudartUnloading"; - case cudaErrorUnknown: - return "cudaErrorUnknown"; + case cudaErrorUnknown: + return "cudaErrorUnknown"; - case cudaErrorNotYetImplemented: - return "cudaErrorNotYetImplemented"; + case cudaErrorNotYetImplemented: + return "cudaErrorNotYetImplemented"; - case cudaErrorMemoryValueTooLarge: - return "cudaErrorMemoryValueTooLarge"; + case cudaErrorMemoryValueTooLarge: + return "cudaErrorMemoryValueTooLarge"; - case cudaErrorInvalidResourceHandle: - return "cudaErrorInvalidResourceHandle"; + case cudaErrorInvalidResourceHandle: + return "cudaErrorInvalidResourceHandle"; - case cudaErrorNotReady: - return "cudaErrorNotReady"; + case cudaErrorNotReady: + return "cudaErrorNotReady"; - case cudaErrorInsufficientDriver: - return "cudaErrorInsufficientDriver"; + case cudaErrorInsufficientDriver: + return "cudaErrorInsufficientDriver"; - case cudaErrorSetOnActiveProcess: - return "cudaErrorSetOnActiveProcess"; + case cudaErrorSetOnActiveProcess: + return "cudaErrorSetOnActiveProcess"; - case cudaErrorInvalidSurface: - return "cudaErrorInvalidSurface"; + case cudaErrorInvalidSurface: + return "cudaErrorInvalidSurface"; - case cudaErrorNoDevice: - return "cudaErrorNoDevice"; + case cudaErrorNoDevice: + return "cudaErrorNoDevice"; - case cudaErrorECCUncorrectable: - return "cudaErrorECCUncorrectable"; + case cudaErrorECCUncorrectable: + return "cudaErrorECCUncorrectable"; - case cudaErrorSharedObjectSymbolNotFound: - return "cudaErrorSharedObjectSymbolNotFound"; + case cudaErrorSharedObjectSymbolNotFound: + return "cudaErrorSharedObjectSymbolNotFound"; - case cudaErrorSharedObjectInitFailed: - return "cudaErrorSharedObjectInitFailed"; + case cudaErrorSharedObjectInitFailed: + return "cudaErrorSharedObjectInitFailed"; - case cudaErrorUnsupportedLimit: - return "cudaErrorUnsupportedLimit"; + case cudaErrorUnsupportedLimit: + return "cudaErrorUnsupportedLimit"; - case cudaErrorDuplicateVariableName: - return "cudaErrorDuplicateVariableName"; + case cudaErrorDuplicateVariableName: + return "cudaErrorDuplicateVariableName"; - case cudaErrorDuplicateTextureName: - return "cudaErrorDuplicateTextureName"; + case cudaErrorDuplicateTextureName: + return "cudaErrorDuplicateTextureName"; - case cudaErrorDuplicateSurfaceName: - return "cudaErrorDuplicateSurfaceName"; + case cudaErrorDuplicateSurfaceName: + return "cudaErrorDuplicateSurfaceName"; - case cudaErrorDevicesUnavailable: - return "cudaErrorDevicesUnavailable"; + case cudaErrorDevicesUnavailable: + return "cudaErrorDevicesUnavailable"; - case cudaErrorInvalidKernelImage: - return "cudaErrorInvalidKernelImage"; + case cudaErrorInvalidKernelImage: + return "cudaErrorInvalidKernelImage"; - case cudaErrorNoKernelImageForDevice: - return "cudaErrorNoKernelImageForDevice"; + case cudaErrorNoKernelImageForDevice: + return "cudaErrorNoKernelImageForDevice"; - case cudaErrorIncompatibleDriverContext: - return "cudaErrorIncompatibleDriverContext"; + case cudaErrorIncompatibleDriverContext: + return "cudaErrorIncompatibleDriverContext"; - case cudaErrorPeerAccessAlreadyEnabled: - return "cudaErrorPeerAccessAlreadyEnabled"; + case cudaErrorPeerAccessAlreadyEnabled: + return "cudaErrorPeerAccessAlreadyEnabled"; - case cudaErrorPeerAccessNotEnabled: - return "cudaErrorPeerAccessNotEnabled"; + case cudaErrorPeerAccessNotEnabled: + return "cudaErrorPeerAccessNotEnabled"; - case cudaErrorDeviceAlreadyInUse: - return "cudaErrorDeviceAlreadyInUse"; + case cudaErrorDeviceAlreadyInUse: + return "cudaErrorDeviceAlreadyInUse"; - case cudaErrorProfilerDisabled: - return "cudaErrorProfilerDisabled"; + case cudaErrorProfilerDisabled: + return "cudaErrorProfilerDisabled"; - case cudaErrorProfilerNotInitialized: - return "cudaErrorProfilerNotInitialized"; + case cudaErrorProfilerNotInitialized: + return "cudaErrorProfilerNotInitialized"; - case cudaErrorProfilerAlreadyStarted: - return "cudaErrorProfilerAlreadyStarted"; + case cudaErrorProfilerAlreadyStarted: + return "cudaErrorProfilerAlreadyStarted"; - case cudaErrorProfilerAlreadyStopped: - return "cudaErrorProfilerAlreadyStopped"; + case cudaErrorProfilerAlreadyStopped: + return "cudaErrorProfilerAlreadyStopped"; #if __CUDA_API_VERSION >= 0x4000 - case cudaErrorAssert: - return "cudaErrorAssert"; + case cudaErrorAssert: + return "cudaErrorAssert"; - case cudaErrorTooManyPeers: - return "cudaErrorTooManyPeers"; + case cudaErrorTooManyPeers: + return "cudaErrorTooManyPeers"; - case cudaErrorHostMemoryAlreadyRegistered: - return "cudaErrorHostMemoryAlreadyRegistered"; + case cudaErrorHostMemoryAlreadyRegistered: + return "cudaErrorHostMemoryAlreadyRegistered"; - case cudaErrorHostMemoryNotRegistered: - return "cudaErrorHostMemoryNotRegistered"; + case cudaErrorHostMemoryNotRegistered: + return "cudaErrorHostMemoryNotRegistered"; #endif - case cudaErrorStartupFailure: - return "cudaErrorStartupFailure"; + case cudaErrorStartupFailure: + return "cudaErrorStartupFailure"; - case cudaErrorApiFailureBase: - return "cudaErrorApiFailureBase"; - } + case cudaErrorApiFailureBase: + return "cudaErrorApiFailureBase"; + } - return ""; + return ""; } #endif #ifdef __cuda_cuda_h__ // CUDA Driver API errors -static const char *_cudaGetErrorEnum(CUresult error) { - switch (error) { - case CUDA_SUCCESS: - return "CUDA_SUCCESS"; +static const char *_cudaGetErrorEnum(CUresult error) +{ + switch (error) + { + case CUDA_SUCCESS: + return "CUDA_SUCCESS"; - case CUDA_ERROR_INVALID_VALUE: - return "CUDA_ERROR_INVALID_VALUE"; + case CUDA_ERROR_INVALID_VALUE: + return "CUDA_ERROR_INVALID_VALUE"; - case CUDA_ERROR_OUT_OF_MEMORY: - return "CUDA_ERROR_OUT_OF_MEMORY"; + case CUDA_ERROR_OUT_OF_MEMORY: + return "CUDA_ERROR_OUT_OF_MEMORY"; - case CUDA_ERROR_NOT_INITIALIZED: - return "CUDA_ERROR_NOT_INITIALIZED"; + case CUDA_ERROR_NOT_INITIALIZED: + return "CUDA_ERROR_NOT_INITIALIZED"; - case CUDA_ERROR_DEINITIALIZED: - return "CUDA_ERROR_DEINITIALIZED"; + case CUDA_ERROR_DEINITIALIZED: + return "CUDA_ERROR_DEINITIALIZED"; - case CUDA_ERROR_PROFILER_DISABLED: - return "CUDA_ERROR_PROFILER_DISABLED"; + case CUDA_ERROR_PROFILER_DISABLED: + return "CUDA_ERROR_PROFILER_DISABLED"; - case CUDA_ERROR_PROFILER_NOT_INITIALIZED: - return "CUDA_ERROR_PROFILER_NOT_INITIALIZED"; + case CUDA_ERROR_PROFILER_NOT_INITIALIZED: + return "CUDA_ERROR_PROFILER_NOT_INITIALIZED"; - case CUDA_ERROR_PROFILER_ALREADY_STARTED: - return "CUDA_ERROR_PROFILER_ALREADY_STARTED"; + case CUDA_ERROR_PROFILER_ALREADY_STARTED: + return "CUDA_ERROR_PROFILER_ALREADY_STARTED"; - case CUDA_ERROR_PROFILER_ALREADY_STOPPED: - return "CUDA_ERROR_PROFILER_ALREADY_STOPPED"; + case CUDA_ERROR_PROFILER_ALREADY_STOPPED: + return "CUDA_ERROR_PROFILER_ALREADY_STOPPED"; - case CUDA_ERROR_NO_DEVICE: - return "CUDA_ERROR_NO_DEVICE"; + case CUDA_ERROR_NO_DEVICE: + return "CUDA_ERROR_NO_DEVICE"; - case CUDA_ERROR_INVALID_DEVICE: - return "CUDA_ERROR_INVALID_DEVICE"; + case CUDA_ERROR_INVALID_DEVICE: + return "CUDA_ERROR_INVALID_DEVICE"; - case CUDA_ERROR_INVALID_IMAGE: - return "CUDA_ERROR_INVALID_IMAGE"; + case CUDA_ERROR_INVALID_IMAGE: + return "CUDA_ERROR_INVALID_IMAGE"; - case CUDA_ERROR_INVALID_CONTEXT: - return "CUDA_ERROR_INVALID_CONTEXT"; + case CUDA_ERROR_INVALID_CONTEXT: + return "CUDA_ERROR_INVALID_CONTEXT"; - case CUDA_ERROR_CONTEXT_ALREADY_CURRENT: - return "CUDA_ERROR_CONTEXT_ALREADY_CURRENT"; + case CUDA_ERROR_CONTEXT_ALREADY_CURRENT: + return "CUDA_ERROR_CONTEXT_ALREADY_CURRENT"; - case CUDA_ERROR_MAP_FAILED: - return "CUDA_ERROR_MAP_FAILED"; + case CUDA_ERROR_MAP_FAILED: + return "CUDA_ERROR_MAP_FAILED"; - case CUDA_ERROR_UNMAP_FAILED: - return "CUDA_ERROR_UNMAP_FAILED"; + case CUDA_ERROR_UNMAP_FAILED: + return "CUDA_ERROR_UNMAP_FAILED"; - case CUDA_ERROR_ARRAY_IS_MAPPED: - return "CUDA_ERROR_ARRAY_IS_MAPPED"; + case CUDA_ERROR_ARRAY_IS_MAPPED: + return "CUDA_ERROR_ARRAY_IS_MAPPED"; - case CUDA_ERROR_ALREADY_MAPPED: - return "CUDA_ERROR_ALREADY_MAPPED"; + case CUDA_ERROR_ALREADY_MAPPED: + return "CUDA_ERROR_ALREADY_MAPPED"; - case CUDA_ERROR_NO_BINARY_FOR_GPU: - return "CUDA_ERROR_NO_BINARY_FOR_GPU"; + case CUDA_ERROR_NO_BINARY_FOR_GPU: + return "CUDA_ERROR_NO_BINARY_FOR_GPU"; - case CUDA_ERROR_ALREADY_ACQUIRED: - return "CUDA_ERROR_ALREADY_ACQUIRED"; + case CUDA_ERROR_ALREADY_ACQUIRED: + return "CUDA_ERROR_ALREADY_ACQUIRED"; - case CUDA_ERROR_NOT_MAPPED: - return "CUDA_ERROR_NOT_MAPPED"; + case CUDA_ERROR_NOT_MAPPED: + return "CUDA_ERROR_NOT_MAPPED"; - case CUDA_ERROR_NOT_MAPPED_AS_ARRAY: - return "CUDA_ERROR_NOT_MAPPED_AS_ARRAY"; + case CUDA_ERROR_NOT_MAPPED_AS_ARRAY: + return "CUDA_ERROR_NOT_MAPPED_AS_ARRAY"; - case CUDA_ERROR_NOT_MAPPED_AS_POINTER: - return "CUDA_ERROR_NOT_MAPPED_AS_POINTER"; + case CUDA_ERROR_NOT_MAPPED_AS_POINTER: + return "CUDA_ERROR_NOT_MAPPED_AS_POINTER"; - case CUDA_ERROR_ECC_UNCORRECTABLE: - return "CUDA_ERROR_ECC_UNCORRECTABLE"; + case CUDA_ERROR_ECC_UNCORRECTABLE: + return "CUDA_ERROR_ECC_UNCORRECTABLE"; - case CUDA_ERROR_UNSUPPORTED_LIMIT: - return "CUDA_ERROR_UNSUPPORTED_LIMIT"; + case CUDA_ERROR_UNSUPPORTED_LIMIT: + return "CUDA_ERROR_UNSUPPORTED_LIMIT"; - case CUDA_ERROR_CONTEXT_ALREADY_IN_USE: - return "CUDA_ERROR_CONTEXT_ALREADY_IN_USE"; + case CUDA_ERROR_CONTEXT_ALREADY_IN_USE: + return "CUDA_ERROR_CONTEXT_ALREADY_IN_USE"; - case CUDA_ERROR_INVALID_SOURCE: - return "CUDA_ERROR_INVALID_SOURCE"; + case CUDA_ERROR_INVALID_SOURCE: + return "CUDA_ERROR_INVALID_SOURCE"; - case CUDA_ERROR_FILE_NOT_FOUND: - return "CUDA_ERROR_FILE_NOT_FOUND"; + case CUDA_ERROR_FILE_NOT_FOUND: + return "CUDA_ERROR_FILE_NOT_FOUND"; - case CUDA_ERROR_SHARED_OBJECT_SYMBOL_NOT_FOUND: - return "CUDA_ERROR_SHARED_OBJECT_SYMBOL_NOT_FOUND"; + case CUDA_ERROR_SHARED_OBJECT_SYMBOL_NOT_FOUND: + return "CUDA_ERROR_SHARED_OBJECT_SYMBOL_NOT_FOUND"; - case CUDA_ERROR_SHARED_OBJECT_INIT_FAILED: - return "CUDA_ERROR_SHARED_OBJECT_INIT_FAILED"; + case CUDA_ERROR_SHARED_OBJECT_INIT_FAILED: + return "CUDA_ERROR_SHARED_OBJECT_INIT_FAILED"; - case CUDA_ERROR_OPERATING_SYSTEM: - return "CUDA_ERROR_OPERATING_SYSTEM"; + case CUDA_ERROR_OPERATING_SYSTEM: + return "CUDA_ERROR_OPERATING_SYSTEM"; - case CUDA_ERROR_INVALID_HANDLE: - return "CUDA_ERROR_INVALID_HANDLE"; + case CUDA_ERROR_INVALID_HANDLE: + return "CUDA_ERROR_INVALID_HANDLE"; - case CUDA_ERROR_NOT_FOUND: - return "CUDA_ERROR_NOT_FOUND"; + case CUDA_ERROR_NOT_FOUND: + return "CUDA_ERROR_NOT_FOUND"; - case CUDA_ERROR_NOT_READY: - return "CUDA_ERROR_NOT_READY"; + case CUDA_ERROR_NOT_READY: + return "CUDA_ERROR_NOT_READY"; - case CUDA_ERROR_LAUNCH_FAILED: - return "CUDA_ERROR_LAUNCH_FAILED"; + case CUDA_ERROR_LAUNCH_FAILED: + return "CUDA_ERROR_LAUNCH_FAILED"; - case CUDA_ERROR_LAUNCH_OUT_OF_RESOURCES: - return "CUDA_ERROR_LAUNCH_OUT_OF_RESOURCES"; + case CUDA_ERROR_LAUNCH_OUT_OF_RESOURCES: + return "CUDA_ERROR_LAUNCH_OUT_OF_RESOURCES"; - case CUDA_ERROR_LAUNCH_TIMEOUT: - return "CUDA_ERROR_LAUNCH_TIMEOUT"; + case CUDA_ERROR_LAUNCH_TIMEOUT: + return "CUDA_ERROR_LAUNCH_TIMEOUT"; - case CUDA_ERROR_LAUNCH_INCOMPATIBLE_TEXTURING: - return "CUDA_ERROR_LAUNCH_INCOMPATIBLE_TEXTURING"; + case CUDA_ERROR_LAUNCH_INCOMPATIBLE_TEXTURING: + return "CUDA_ERROR_LAUNCH_INCOMPATIBLE_TEXTURING"; - case CUDA_ERROR_PEER_ACCESS_ALREADY_ENABLED: - return "CUDA_ERROR_PEER_ACCESS_ALREADY_ENABLED"; + case CUDA_ERROR_PEER_ACCESS_ALREADY_ENABLED: + return "CUDA_ERROR_PEER_ACCESS_ALREADY_ENABLED"; - case CUDA_ERROR_PEER_ACCESS_NOT_ENABLED: - return "CUDA_ERROR_PEER_ACCESS_NOT_ENABLED"; + case CUDA_ERROR_PEER_ACCESS_NOT_ENABLED: + return "CUDA_ERROR_PEER_ACCESS_NOT_ENABLED"; - case CUDA_ERROR_PRIMARY_CONTEXT_ACTIVE: - return "CUDA_ERROR_PRIMARY_CONTEXT_ACTIVE"; + case CUDA_ERROR_PRIMARY_CONTEXT_ACTIVE: + return "CUDA_ERROR_PRIMARY_CONTEXT_ACTIVE"; - case CUDA_ERROR_CONTEXT_IS_DESTROYED: - return "CUDA_ERROR_CONTEXT_IS_DESTROYED"; + case CUDA_ERROR_CONTEXT_IS_DESTROYED: + return "CUDA_ERROR_CONTEXT_IS_DESTROYED"; - case CUDA_ERROR_ASSERT: - return "CUDA_ERROR_ASSERT"; + case CUDA_ERROR_ASSERT: + return "CUDA_ERROR_ASSERT"; - case CUDA_ERROR_TOO_MANY_PEERS: - return "CUDA_ERROR_TOO_MANY_PEERS"; + case CUDA_ERROR_TOO_MANY_PEERS: + return "CUDA_ERROR_TOO_MANY_PEERS"; - case CUDA_ERROR_HOST_MEMORY_ALREADY_REGISTERED: - return "CUDA_ERROR_HOST_MEMORY_ALREADY_REGISTERED"; + case CUDA_ERROR_HOST_MEMORY_ALREADY_REGISTERED: + return "CUDA_ERROR_HOST_MEMORY_ALREADY_REGISTERED"; - case CUDA_ERROR_HOST_MEMORY_NOT_REGISTERED: - return "CUDA_ERROR_HOST_MEMORY_NOT_REGISTERED"; + case CUDA_ERROR_HOST_MEMORY_NOT_REGISTERED: + return "CUDA_ERROR_HOST_MEMORY_NOT_REGISTERED"; - case CUDA_ERROR_UNKNOWN: - return "CUDA_ERROR_UNKNOWN"; - } + case CUDA_ERROR_UNKNOWN: + return "CUDA_ERROR_UNKNOWN"; + } - return ""; + return ""; } #endif #ifdef CUBLAS_API_H_ // cuBLAS API errors -static const char *_cudaGetErrorEnum(cublasStatus_t error) { - switch (error) { - case CUBLAS_STATUS_SUCCESS: - return "CUBLAS_STATUS_SUCCESS"; +static const char *_cudaGetErrorEnum(cublasStatus_t error) +{ + switch (error) + { + case CUBLAS_STATUS_SUCCESS: + return "CUBLAS_STATUS_SUCCESS"; - case CUBLAS_STATUS_NOT_INITIALIZED: - return "CUBLAS_STATUS_NOT_INITIALIZED"; + case CUBLAS_STATUS_NOT_INITIALIZED: + return "CUBLAS_STATUS_NOT_INITIALIZED"; - case CUBLAS_STATUS_ALLOC_FAILED: - return "CUBLAS_STATUS_ALLOC_FAILED"; + case CUBLAS_STATUS_ALLOC_FAILED: + return "CUBLAS_STATUS_ALLOC_FAILED"; - case CUBLAS_STATUS_INVALID_VALUE: - return "CUBLAS_STATUS_INVALID_VALUE"; + case CUBLAS_STATUS_INVALID_VALUE: + return "CUBLAS_STATUS_INVALID_VALUE"; - case CUBLAS_STATUS_ARCH_MISMATCH: - return "CUBLAS_STATUS_ARCH_MISMATCH"; + case CUBLAS_STATUS_ARCH_MISMATCH: + return "CUBLAS_STATUS_ARCH_MISMATCH"; - case CUBLAS_STATUS_MAPPING_ERROR: - return "CUBLAS_STATUS_MAPPING_ERROR"; + case CUBLAS_STATUS_MAPPING_ERROR: + return "CUBLAS_STATUS_MAPPING_ERROR"; - case CUBLAS_STATUS_EXECUTION_FAILED: - return "CUBLAS_STATUS_EXECUTION_FAILED"; + case CUBLAS_STATUS_EXECUTION_FAILED: + return "CUBLAS_STATUS_EXECUTION_FAILED"; - case CUBLAS_STATUS_INTERNAL_ERROR: - return "CUBLAS_STATUS_INTERNAL_ERROR"; - } + case CUBLAS_STATUS_INTERNAL_ERROR: + return "CUBLAS_STATUS_INTERNAL_ERROR"; + } - return ""; + return ""; } #endif #ifdef _CUFFT_H_ // cuFFT API errors -static const char *_cudaGetErrorEnum(cufftResult error) { - switch (error) { - case CUFFT_SUCCESS: - return "CUFFT_SUCCESS"; +static const char *_cudaGetErrorEnum(cufftResult error) +{ + switch (error) + { + case CUFFT_SUCCESS: + return "CUFFT_SUCCESS"; - case CUFFT_INVALID_PLAN: - return "CUFFT_INVALID_PLAN"; + case CUFFT_INVALID_PLAN: + return "CUFFT_INVALID_PLAN"; - case CUFFT_ALLOC_FAILED: - return "CUFFT_ALLOC_FAILED"; + case CUFFT_ALLOC_FAILED: + return "CUFFT_ALLOC_FAILED"; - case CUFFT_INVALID_TYPE: - return "CUFFT_INVALID_TYPE"; + case CUFFT_INVALID_TYPE: + return "CUFFT_INVALID_TYPE"; - case CUFFT_INVALID_VALUE: - return "CUFFT_INVALID_VALUE"; + case CUFFT_INVALID_VALUE: + return "CUFFT_INVALID_VALUE"; - case CUFFT_INTERNAL_ERROR: - return "CUFFT_INTERNAL_ERROR"; + case CUFFT_INTERNAL_ERROR: + return "CUFFT_INTERNAL_ERROR"; - case CUFFT_EXEC_FAILED: - return "CUFFT_EXEC_FAILED"; + case CUFFT_EXEC_FAILED: + return "CUFFT_EXEC_FAILED"; - case CUFFT_SETUP_FAILED: - return "CUFFT_SETUP_FAILED"; + case CUFFT_SETUP_FAILED: + return "CUFFT_SETUP_FAILED"; - case CUFFT_INVALID_SIZE: - return "CUFFT_INVALID_SIZE"; + case CUFFT_INVALID_SIZE: + return "CUFFT_INVALID_SIZE"; - case CUFFT_UNALIGNED_DATA: - return "CUFFT_UNALIGNED_DATA"; - } + case CUFFT_UNALIGNED_DATA: + return "CUFFT_UNALIGNED_DATA"; + } - return ""; + return ""; } #endif #ifdef CUSPARSEAPI // cuSPARSE API errors -static const char *_cudaGetErrorEnum(cusparseStatus_t error) { - switch (error) { - case CUSPARSE_STATUS_SUCCESS: - return "CUSPARSE_STATUS_SUCCESS"; +static const char *_cudaGetErrorEnum(cusparseStatus_t error) +{ + switch (error) + { + case CUSPARSE_STATUS_SUCCESS: + return "CUSPARSE_STATUS_SUCCESS"; - case CUSPARSE_STATUS_NOT_INITIALIZED: - return "CUSPARSE_STATUS_NOT_INITIALIZED"; + case CUSPARSE_STATUS_NOT_INITIALIZED: + return "CUSPARSE_STATUS_NOT_INITIALIZED"; - case CUSPARSE_STATUS_ALLOC_FAILED: - return "CUSPARSE_STATUS_ALLOC_FAILED"; + case CUSPARSE_STATUS_ALLOC_FAILED: + return "CUSPARSE_STATUS_ALLOC_FAILED"; - case CUSPARSE_STATUS_INVALID_VALUE: - return "CUSPARSE_STATUS_INVALID_VALUE"; + case CUSPARSE_STATUS_INVALID_VALUE: + return "CUSPARSE_STATUS_INVALID_VALUE"; - case CUSPARSE_STATUS_ARCH_MISMATCH: - return "CUSPARSE_STATUS_ARCH_MISMATCH"; + case CUSPARSE_STATUS_ARCH_MISMATCH: + return "CUSPARSE_STATUS_ARCH_MISMATCH"; - case CUSPARSE_STATUS_MAPPING_ERROR: - return "CUSPARSE_STATUS_MAPPING_ERROR"; + case CUSPARSE_STATUS_MAPPING_ERROR: + return "CUSPARSE_STATUS_MAPPING_ERROR"; - case CUSPARSE_STATUS_EXECUTION_FAILED: - return "CUSPARSE_STATUS_EXECUTION_FAILED"; + case CUSPARSE_STATUS_EXECUTION_FAILED: + return "CUSPARSE_STATUS_EXECUTION_FAILED"; - case CUSPARSE_STATUS_INTERNAL_ERROR: - return "CUSPARSE_STATUS_INTERNAL_ERROR"; + case CUSPARSE_STATUS_INTERNAL_ERROR: + return "CUSPARSE_STATUS_INTERNAL_ERROR"; - case CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED: - return "CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED"; - } + case CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED: + return "CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED"; + } - return ""; + return ""; } #endif #ifdef CURAND_H_ // cuRAND API errors -static const char *_cudaGetErrorEnum(curandStatus_t error) { - switch (error) { - case CURAND_STATUS_SUCCESS: - return "CURAND_STATUS_SUCCESS"; +static const char *_cudaGetErrorEnum(curandStatus_t error) +{ + switch (error) + { + case CURAND_STATUS_SUCCESS: + return "CURAND_STATUS_SUCCESS"; - case CURAND_STATUS_VERSION_MISMATCH: - return "CURAND_STATUS_VERSION_MISMATCH"; + case CURAND_STATUS_VERSION_MISMATCH: + return "CURAND_STATUS_VERSION_MISMATCH"; - case CURAND_STATUS_NOT_INITIALIZED: - return "CURAND_STATUS_NOT_INITIALIZED"; + case CURAND_STATUS_NOT_INITIALIZED: + return "CURAND_STATUS_NOT_INITIALIZED"; - case CURAND_STATUS_ALLOCATION_FAILED: - return "CURAND_STATUS_ALLOCATION_FAILED"; + case CURAND_STATUS_ALLOCATION_FAILED: + return "CURAND_STATUS_ALLOCATION_FAILED"; - case CURAND_STATUS_TYPE_ERROR: - return "CURAND_STATUS_TYPE_ERROR"; + case CURAND_STATUS_TYPE_ERROR: + return "CURAND_STATUS_TYPE_ERROR"; - case CURAND_STATUS_OUT_OF_RANGE: - return "CURAND_STATUS_OUT_OF_RANGE"; + case CURAND_STATUS_OUT_OF_RANGE: + return "CURAND_STATUS_OUT_OF_RANGE"; - case CURAND_STATUS_LENGTH_NOT_MULTIPLE: - return "CURAND_STATUS_LENGTH_NOT_MULTIPLE"; + case CURAND_STATUS_LENGTH_NOT_MULTIPLE: + return "CURAND_STATUS_LENGTH_NOT_MULTIPLE"; - case CURAND_STATUS_DOUBLE_PRECISION_REQUIRED: - return "CURAND_STATUS_DOUBLE_PRECISION_REQUIRED"; + case CURAND_STATUS_DOUBLE_PRECISION_REQUIRED: + return "CURAND_STATUS_DOUBLE_PRECISION_REQUIRED"; - case CURAND_STATUS_LAUNCH_FAILURE: - return "CURAND_STATUS_LAUNCH_FAILURE"; + case CURAND_STATUS_LAUNCH_FAILURE: + return "CURAND_STATUS_LAUNCH_FAILURE"; - case CURAND_STATUS_PREEXISTING_FAILURE: - return "CURAND_STATUS_PREEXISTING_FAILURE"; + case CURAND_STATUS_PREEXISTING_FAILURE: + return "CURAND_STATUS_PREEXISTING_FAILURE"; - case CURAND_STATUS_INITIALIZATION_FAILED: - return "CURAND_STATUS_INITIALIZATION_FAILED"; + case CURAND_STATUS_INITIALIZATION_FAILED: + return "CURAND_STATUS_INITIALIZATION_FAILED"; - case CURAND_STATUS_ARCH_MISMATCH: - return "CURAND_STATUS_ARCH_MISMATCH"; + case CURAND_STATUS_ARCH_MISMATCH: + return "CURAND_STATUS_ARCH_MISMATCH"; - case CURAND_STATUS_INTERNAL_ERROR: - return "CURAND_STATUS_INTERNAL_ERROR"; - } + case CURAND_STATUS_INTERNAL_ERROR: + return "CURAND_STATUS_INTERNAL_ERROR"; + } - return ""; + return ""; } #endif #ifdef NV_NPPIDEFS_H // NPP API errors -static const char *_cudaGetErrorEnum(NppStatus error) { - switch (error) { - case NPP_NOT_SUPPORTED_MODE_ERROR: - return "NPP_NOT_SUPPORTED_MODE_ERROR"; +static const char *_cudaGetErrorEnum(NppStatus error) +{ + switch (error) + { + case NPP_NOT_SUPPORTED_MODE_ERROR: + return "NPP_NOT_SUPPORTED_MODE_ERROR"; - case NPP_ROUND_MODE_NOT_SUPPORTED_ERROR: - return "NPP_ROUND_MODE_NOT_SUPPORTED_ERROR"; + case NPP_ROUND_MODE_NOT_SUPPORTED_ERROR: + return "NPP_ROUND_MODE_NOT_SUPPORTED_ERROR"; - case NPP_RESIZE_NO_OPERATION_ERROR: - return "NPP_RESIZE_NO_OPERATION_ERROR"; + case NPP_RESIZE_NO_OPERATION_ERROR: + return "NPP_RESIZE_NO_OPERATION_ERROR"; - case NPP_NOT_SUFFICIENT_COMPUTE_CAPABILITY: - return "NPP_NOT_SUFFICIENT_COMPUTE_CAPABILITY"; + case NPP_NOT_SUFFICIENT_COMPUTE_CAPABILITY: + return "NPP_NOT_SUFFICIENT_COMPUTE_CAPABILITY"; #if ((NPP_VERSION_MAJOR << 12) + (NPP_VERSION_MINOR << 4)) <= 0x5000 - case NPP_BAD_ARG_ERROR: - return "NPP_BAD_ARGUMENT_ERROR"; + case NPP_BAD_ARG_ERROR: + return "NPP_BAD_ARGUMENT_ERROR"; - case NPP_COEFF_ERROR: - return "NPP_COEFFICIENT_ERROR"; + case NPP_COEFF_ERROR: + return "NPP_COEFFICIENT_ERROR"; - case NPP_RECT_ERROR: - return "NPP_RECTANGLE_ERROR"; + case NPP_RECT_ERROR: + return "NPP_RECTANGLE_ERROR"; - case NPP_QUAD_ERROR: - return "NPP_QUADRANGLE_ERROR"; + case NPP_QUAD_ERROR: + return "NPP_QUADRANGLE_ERROR"; - case NPP_MEM_ALLOC_ERR: - return "NPP_MEMORY_ALLOCATION_ERROR"; + case NPP_MEM_ALLOC_ERR: + return "NPP_MEMORY_ALLOCATION_ERROR"; - case NPP_HISTO_NUMBER_OF_LEVELS_ERROR: - return "NPP_HISTOGRAM_NUMBER_OF_LEVELS_ERROR"; + case NPP_HISTO_NUMBER_OF_LEVELS_ERROR: + return "NPP_HISTOGRAM_NUMBER_OF_LEVELS_ERROR"; - case NPP_INVALID_INPUT: - return "NPP_INVALID_INPUT"; + case NPP_INVALID_INPUT: + return "NPP_INVALID_INPUT"; - case NPP_POINTER_ERROR: - return "NPP_POINTER_ERROR"; + case NPP_POINTER_ERROR: + return "NPP_POINTER_ERROR"; - case NPP_WARNING: - return "NPP_WARNING"; + case NPP_WARNING: + return "NPP_WARNING"; - case NPP_ODD_ROI_WARNING: - return "NPP_ODD_ROI_WARNING"; + case NPP_ODD_ROI_WARNING: + return "NPP_ODD_ROI_WARNING"; #else - // These are for CUDA 5.5 or higher - case NPP_BAD_ARGUMENT_ERROR: - return "NPP_BAD_ARGUMENT_ERROR"; + // These are for CUDA 5.5 or higher + case NPP_BAD_ARGUMENT_ERROR: + return "NPP_BAD_ARGUMENT_ERROR"; - case NPP_COEFFICIENT_ERROR: - return "NPP_COEFFICIENT_ERROR"; + case NPP_COEFFICIENT_ERROR: + return "NPP_COEFFICIENT_ERROR"; - case NPP_RECTANGLE_ERROR: - return "NPP_RECTANGLE_ERROR"; + case NPP_RECTANGLE_ERROR: + return "NPP_RECTANGLE_ERROR"; - case NPP_QUADRANGLE_ERROR: - return "NPP_QUADRANGLE_ERROR"; + case NPP_QUADRANGLE_ERROR: + return "NPP_QUADRANGLE_ERROR"; - case NPP_MEMORY_ALLOCATION_ERR: - return "NPP_MEMORY_ALLOCATION_ERROR"; + case NPP_MEMORY_ALLOCATION_ERR: + return "NPP_MEMORY_ALLOCATION_ERROR"; - case NPP_HISTOGRAM_NUMBER_OF_LEVELS_ERROR: - return "NPP_HISTOGRAM_NUMBER_OF_LEVELS_ERROR"; + case NPP_HISTOGRAM_NUMBER_OF_LEVELS_ERROR: + return "NPP_HISTOGRAM_NUMBER_OF_LEVELS_ERROR"; - case NPP_INVALID_HOST_POINTER_ERROR: - return "NPP_INVALID_HOST_POINTER_ERROR"; + case NPP_INVALID_HOST_POINTER_ERROR: + return "NPP_INVALID_HOST_POINTER_ERROR"; - case NPP_INVALID_DEVICE_POINTER_ERROR: - return "NPP_INVALID_DEVICE_POINTER_ERROR"; + case NPP_INVALID_DEVICE_POINTER_ERROR: + return "NPP_INVALID_DEVICE_POINTER_ERROR"; #endif - case NPP_LUT_NUMBER_OF_LEVELS_ERROR: - return "NPP_LUT_NUMBER_OF_LEVELS_ERROR"; + case NPP_LUT_NUMBER_OF_LEVELS_ERROR: + return "NPP_LUT_NUMBER_OF_LEVELS_ERROR"; - case NPP_TEXTURE_BIND_ERROR: - return "NPP_TEXTURE_BIND_ERROR"; + case NPP_TEXTURE_BIND_ERROR: + return "NPP_TEXTURE_BIND_ERROR"; - case NPP_WRONG_INTERSECTION_ROI_ERROR: - return "NPP_WRONG_INTERSECTION_ROI_ERROR"; + case NPP_WRONG_INTERSECTION_ROI_ERROR: + return "NPP_WRONG_INTERSECTION_ROI_ERROR"; - case NPP_NOT_EVEN_STEP_ERROR: - return "NPP_NOT_EVEN_STEP_ERROR"; + case NPP_NOT_EVEN_STEP_ERROR: + return "NPP_NOT_EVEN_STEP_ERROR"; - case NPP_INTERPOLATION_ERROR: - return "NPP_INTERPOLATION_ERROR"; + case NPP_INTERPOLATION_ERROR: + return "NPP_INTERPOLATION_ERROR"; - case NPP_RESIZE_FACTOR_ERROR: - return "NPP_RESIZE_FACTOR_ERROR"; + case NPP_RESIZE_FACTOR_ERROR: + return "NPP_RESIZE_FACTOR_ERROR"; - case NPP_HAAR_CLASSIFIER_PIXEL_MATCH_ERROR: - return "NPP_HAAR_CLASSIFIER_PIXEL_MATCH_ERROR"; + case NPP_HAAR_CLASSIFIER_PIXEL_MATCH_ERROR: + return "NPP_HAAR_CLASSIFIER_PIXEL_MATCH_ERROR"; #if ((NPP_VERSION_MAJOR << 12) + (NPP_VERSION_MINOR << 4)) <= 0x5000 - case NPP_MEMFREE_ERR: - return "NPP_MEMFREE_ERR"; + case NPP_MEMFREE_ERR: + return "NPP_MEMFREE_ERR"; - case NPP_MEMSET_ERR: - return "NPP_MEMSET_ERR"; + case NPP_MEMSET_ERR: + return "NPP_MEMSET_ERR"; - case NPP_MEMCPY_ERR: - return "NPP_MEMCPY_ERROR"; + case NPP_MEMCPY_ERR: + return "NPP_MEMCPY_ERROR"; - case NPP_MIRROR_FLIP_ERR: - return "NPP_MIRROR_FLIP_ERR"; + case NPP_MIRROR_FLIP_ERR: + return "NPP_MIRROR_FLIP_ERR"; #else - case NPP_MEMFREE_ERROR: - return "NPP_MEMFREE_ERROR"; + case NPP_MEMFREE_ERROR: + return "NPP_MEMFREE_ERROR"; - case NPP_MEMSET_ERROR: - return "NPP_MEMSET_ERROR"; + case NPP_MEMSET_ERROR: + return "NPP_MEMSET_ERROR"; - case NPP_MEMCPY_ERROR: - return "NPP_MEMCPY_ERROR"; + case NPP_MEMCPY_ERROR: + return "NPP_MEMCPY_ERROR"; - case NPP_MIRROR_FLIP_ERROR: - return "NPP_MIRROR_FLIP_ERROR"; + case NPP_MIRROR_FLIP_ERROR: + return "NPP_MIRROR_FLIP_ERROR"; #endif - case NPP_ALIGNMENT_ERROR: - return "NPP_ALIGNMENT_ERROR"; + case NPP_ALIGNMENT_ERROR: + return "NPP_ALIGNMENT_ERROR"; - case NPP_STEP_ERROR: - return "NPP_STEP_ERROR"; + case NPP_STEP_ERROR: + return "NPP_STEP_ERROR"; - case NPP_SIZE_ERROR: - return "NPP_SIZE_ERROR"; + case NPP_SIZE_ERROR: + return "NPP_SIZE_ERROR"; - case NPP_NULL_POINTER_ERROR: - return "NPP_NULL_POINTER_ERROR"; + case NPP_NULL_POINTER_ERROR: + return "NPP_NULL_POINTER_ERROR"; - case NPP_CUDA_KERNEL_EXECUTION_ERROR: - return "NPP_CUDA_KERNEL_EXECUTION_ERROR"; + case NPP_CUDA_KERNEL_EXECUTION_ERROR: + return "NPP_CUDA_KERNEL_EXECUTION_ERROR"; - case NPP_NOT_IMPLEMENTED_ERROR: - return "NPP_NOT_IMPLEMENTED_ERROR"; + case NPP_NOT_IMPLEMENTED_ERROR: + return "NPP_NOT_IMPLEMENTED_ERROR"; - case NPP_ERROR: - return "NPP_ERROR"; + case NPP_ERROR: + return "NPP_ERROR"; - case NPP_SUCCESS: - return "NPP_SUCCESS"; + case NPP_SUCCESS: + return "NPP_SUCCESS"; - case NPP_WRONG_INTERSECTION_QUAD_WARNING: - return "NPP_WRONG_INTERSECTION_QUAD_WARNING"; + case NPP_WRONG_INTERSECTION_QUAD_WARNING: + return "NPP_WRONG_INTERSECTION_QUAD_WARNING"; - case NPP_MISALIGNED_DST_ROI_WARNING: - return "NPP_MISALIGNED_DST_ROI_WARNING"; + case NPP_MISALIGNED_DST_ROI_WARNING: + return "NPP_MISALIGNED_DST_ROI_WARNING"; - case NPP_AFFINE_QUAD_INCORRECT_WARNING: - return "NPP_AFFINE_QUAD_INCORRECT_WARNING"; + case NPP_AFFINE_QUAD_INCORRECT_WARNING: + return "NPP_AFFINE_QUAD_INCORRECT_WARNING"; - case NPP_DOUBLE_SIZE_WARNING: - return "NPP_DOUBLE_SIZE_WARNING"; + case NPP_DOUBLE_SIZE_WARNING: + return "NPP_DOUBLE_SIZE_WARNING"; - case NPP_WRONG_INTERSECTION_ROI_WARNING: - return "NPP_WRONG_INTERSECTION_ROI_WARNING"; - } + case NPP_WRONG_INTERSECTION_ROI_WARNING: + return "NPP_WRONG_INTERSECTION_ROI_WARNING"; + } - return ""; + return ""; } #endif @@ -747,14 +761,17 @@ static const char *_cudaGetErrorEnum(NppStatus error) { template void check(T result, char const *const func, const char *const file, - int const line) { - if (result) { - fprintf(stderr, "CUDA error at %s:%d code=%d(%s) \"%s\" \n", file, line, - static_cast(result), _cudaGetErrorEnum(result), func); - DEVICE_RESET - // Make sure we call CUDA Device Reset before exiting - exit(EXIT_FAILURE); - } + int const line) +{ + if (result) + { + fprintf(stderr, "CUDA error at %s:%d code=%d(%s) \"%s\" \n", file, line, + static_cast(result), _cudaGetErrorEnum(result), + func); + DEVICE_RESET + // Make sure we call CUDA Device Reset before exiting + exit(EXIT_FAILURE); + } } #ifdef __DRIVER_TYPES_H__ @@ -766,15 +783,18 @@ void check(T result, char const *const func, const char *const file, #define getLastCudaError(msg) __getLastCudaError(msg, __FILE__, __LINE__) inline void __getLastCudaError(const char *errorMessage, const char *file, - const int line) { - cudaError_t err = cudaGetLastError(); - - if (cudaSuccess != err) { - fprintf(stderr, "%s(%i) : getLastCudaError() CUDA error : %s : (%d) %s.\n", - file, line, errorMessage, (int)err, cudaGetErrorString(err)); - DEVICE_RESET - exit(EXIT_FAILURE); - } + const int line) +{ + cudaError_t err = cudaGetLastError(); + + if (cudaSuccess != err) + { + fprintf(stderr, + "%s(%i) : getLastCudaError() CUDA error : %s : (%d) %s.\n", + file, line, errorMessage, (int)err, cudaGetErrorString(err)); + DEVICE_RESET + exit(EXIT_FAILURE); + } } #endif @@ -783,218 +803,257 @@ inline void __getLastCudaError(const char *errorMessage, const char *file, #endif // Beginning of GPU Architecture definitions -inline int _ConvertSMVer2Cores(int major, int minor) { - // Defines for GPU Architecture types (using the SM version to determine the # - // of cores per SM - typedef struct { - int SM; // 0xMm (hexidecimal notation), M = SM Major version, and m = SM - // minor version - int Cores; - } sSMtoCores; - - sSMtoCores nGpuArchCoresPerSM[] = { - {0x10, 8}, // Tesla Generation (SM 1.0) G80 class - {0x11, 8}, // Tesla Generation (SM 1.1) G8x class - {0x12, 8}, // Tesla Generation (SM 1.2) G9x class - {0x13, 8}, // Tesla Generation (SM 1.3) GT200 class - {0x20, 32}, // Fermi Generation (SM 2.0) GF100 class - {0x21, 48}, // Fermi Generation (SM 2.1) GF10x class - {0x30, 192}, // Kepler Generation (SM 3.0) GK10x class - {0x35, 192}, // Kepler Generation (SM 3.5) GK11x class - {-1, -1}}; - - int index = 0; - - while (nGpuArchCoresPerSM[index].SM != -1) { - if (nGpuArchCoresPerSM[index].SM == ((major << 4) + minor)) { - return nGpuArchCoresPerSM[index].Cores; - } +inline int _ConvertSMVer2Cores(int major, int minor) +{ + // Defines for GPU Architecture types (using the SM version to determine the + // # of cores per SM + typedef struct + { + int SM; // 0xMm (hexidecimal notation), M = SM Major version, and m = SM + // minor version + int Cores; + } sSMtoCores; + + sSMtoCores nGpuArchCoresPerSM[] = { + {0x10, 8}, // Tesla Generation (SM 1.0) G80 class + {0x11, 8}, // Tesla Generation (SM 1.1) G8x class + {0x12, 8}, // Tesla Generation (SM 1.2) G9x class + {0x13, 8}, // Tesla Generation (SM 1.3) GT200 class + {0x20, 32}, // Fermi Generation (SM 2.0) GF100 class + {0x21, 48}, // Fermi Generation (SM 2.1) GF10x class + {0x30, 192}, // Kepler Generation (SM 3.0) GK10x class + {0x35, 192}, // Kepler Generation (SM 3.5) GK11x class + {-1, -1}}; + + int index = 0; + + while (nGpuArchCoresPerSM[index].SM != -1) + { + if (nGpuArchCoresPerSM[index].SM == ((major << 4) + minor)) + { + return nGpuArchCoresPerSM[index].Cores; + } - index++; - } + index++; + } - // If we don't find the values, we default use the previous one to run - // properly - printf( - "MapSMtoCores for SM %d.%d is undefined. Default to use %d Cores/SM\n", - major, minor, nGpuArchCoresPerSM[7].Cores); - return nGpuArchCoresPerSM[7].Cores; + // If we don't find the values, we default use the previous one to run + // properly + printf( + "MapSMtoCores for SM %d.%d is undefined. Default to use %d Cores/SM\n", + major, minor, nGpuArchCoresPerSM[7].Cores); + return nGpuArchCoresPerSM[7].Cores; } // end of GPU Architecture definitions #ifdef __CUDA_RUNTIME_H__ // General GPU Device CUDA Initialization -inline int gpuDeviceInit(int devID) { - int device_count; - checkCudaErrors(cudaGetDeviceCount(&device_count)); - - if (device_count == 0) { - fprintf(stderr, - "gpuDeviceInit() CUDA error: no devices supporting CUDA.\n"); - exit(EXIT_FAILURE); - } - - if (devID < 0) { - devID = 0; - } - - if (devID > device_count - 1) { - fprintf(stderr, "\n"); - fprintf(stderr, ">> %d CUDA capable GPU device(s) detected. <<\n", - device_count); - fprintf(stderr, - ">> gpuDeviceInit (-device=%d) is not a valid GPU device. <<\n", - devID); - fprintf(stderr, "\n"); - return -devID; - } - - cudaDeviceProp deviceProp; - checkCudaErrors(cudaGetDeviceProperties(&deviceProp, devID)); - - if (deviceProp.computeMode == cudaComputeModeProhibited) { - fprintf(stderr, "Error: device is running in , no " - "threads can use ::cudaSetDevice().\n"); - return -1; - } - - if (deviceProp.major < 1) { - fprintf(stderr, "gpuDeviceInit(): GPU device does not support CUDA.\n"); - exit(EXIT_FAILURE); - } - - checkCudaErrors(cudaSetDevice(devID)); - printf("gpuDeviceInit() CUDA Device [%d]: \"%s\n", devID, deviceProp.name); - - return devID; +inline int gpuDeviceInit(int devID) +{ + int device_count; + checkCudaErrors(cudaGetDeviceCount(&device_count)); + + if (device_count == 0) + { + fprintf(stderr, + "gpuDeviceInit() CUDA error: no devices supporting CUDA.\n"); + exit(EXIT_FAILURE); + } + + if (devID < 0) + { + devID = 0; + } + + if (devID > device_count - 1) + { + fprintf(stderr, "\n"); + fprintf(stderr, ">> %d CUDA capable GPU device(s) detected. <<\n", + device_count); + fprintf(stderr, + ">> gpuDeviceInit (-device=%d) is not a valid GPU device. <<\n", + devID); + fprintf(stderr, "\n"); + return -devID; + } + + cudaDeviceProp deviceProp; + checkCudaErrors(cudaGetDeviceProperties(&deviceProp, devID)); + + if (deviceProp.computeMode == cudaComputeModeProhibited) + { + fprintf(stderr, + "Error: device is running in , no " + "threads can use ::cudaSetDevice().\n"); + return -1; + } + + if (deviceProp.major < 1) + { + fprintf(stderr, "gpuDeviceInit(): GPU device does not support CUDA.\n"); + exit(EXIT_FAILURE); + } + + checkCudaErrors(cudaSetDevice(devID)); + printf("gpuDeviceInit() CUDA Device [%d]: \"%s\n", devID, deviceProp.name); + + return devID; } // This function returns the best GPU (with maximum GFLOPS) -inline int gpuGetMaxGflopsDeviceId() { - int current_device = 0, sm_per_multiproc = 0; - int max_compute_perf = 0, max_perf_device = 0; - int device_count = 0, best_SM_arch = 0; - cudaDeviceProp deviceProp; - cudaGetDeviceCount(&device_count); - - checkCudaErrors(cudaGetDeviceCount(&device_count)); - - if (device_count == 0) { - fprintf( - stderr, - "gpuGetMaxGflopsDeviceId() CUDA error: no devices supporting CUDA.\n"); - exit(EXIT_FAILURE); - } - - // Find the best major SM Architecture GPU device - while (current_device < device_count) { - cudaGetDeviceProperties(&deviceProp, current_device); - - // If this GPU is not running on Compute Mode prohibited, then we can add it - // to the list - if (deviceProp.computeMode != cudaComputeModeProhibited) { - if (deviceProp.major > 0 && deviceProp.major < 9999) { - best_SM_arch = MAX(best_SM_arch, deviceProp.major); - } +inline int gpuGetMaxGflopsDeviceId() +{ + int current_device = 0, sm_per_multiproc = 0; + int max_compute_perf = 0, max_perf_device = 0; + int device_count = 0, best_SM_arch = 0; + cudaDeviceProp deviceProp; + cudaGetDeviceCount(&device_count); + + checkCudaErrors(cudaGetDeviceCount(&device_count)); + + if (device_count == 0) + { + fprintf(stderr, + "gpuGetMaxGflopsDeviceId() CUDA error: no devices supporting " + "CUDA.\n"); + exit(EXIT_FAILURE); } - current_device++; - } - - // Find the best CUDA capable GPU device - current_device = 0; - - while (current_device < device_count) { - cudaGetDeviceProperties(&deviceProp, current_device); - - // If this GPU is not running on Compute Mode prohibited, then we can add it - // to the list - if (deviceProp.computeMode != cudaComputeModeProhibited) { - if (deviceProp.major == 9999 && deviceProp.minor == 9999) { - sm_per_multiproc = 1; - } else { - sm_per_multiproc = - _ConvertSMVer2Cores(deviceProp.major, deviceProp.minor); - } - - int compute_perf = deviceProp.multiProcessorCount * sm_per_multiproc * - deviceProp.clockRate; - - if (compute_perf > max_compute_perf) { - // If we find GPU with SM major > 2, search only these - if (best_SM_arch > 2) { - // If our device==dest_SM_arch, choose this, or else pass - if (deviceProp.major == best_SM_arch) { - max_compute_perf = compute_perf; - max_perf_device = current_device; - } - } else { - max_compute_perf = compute_perf; - max_perf_device = current_device; + // Find the best major SM Architecture GPU device + while (current_device < device_count) + { + cudaGetDeviceProperties(&deviceProp, current_device); + + // If this GPU is not running on Compute Mode prohibited, then we can + // add it to the list + if (deviceProp.computeMode != cudaComputeModeProhibited) + { + if (deviceProp.major > 0 && deviceProp.major < 9999) + { + best_SM_arch = MAX(best_SM_arch, deviceProp.major); + } } - } + + current_device++; } - ++current_device; - } + // Find the best CUDA capable GPU device + current_device = 0; + + while (current_device < device_count) + { + cudaGetDeviceProperties(&deviceProp, current_device); + + // If this GPU is not running on Compute Mode prohibited, then we can + // add it to the list + if (deviceProp.computeMode != cudaComputeModeProhibited) + { + if (deviceProp.major == 9999 && deviceProp.minor == 9999) + { + sm_per_multiproc = 1; + } + else + { + sm_per_multiproc = + _ConvertSMVer2Cores(deviceProp.major, deviceProp.minor); + } + + int compute_perf = deviceProp.multiProcessorCount * + sm_per_multiproc * deviceProp.clockRate; + + if (compute_perf > max_compute_perf) + { + // If we find GPU with SM major > 2, search only these + if (best_SM_arch > 2) + { + // If our device==dest_SM_arch, choose this, or else pass + if (deviceProp.major == best_SM_arch) + { + max_compute_perf = compute_perf; + max_perf_device = current_device; + } + } + else + { + max_compute_perf = compute_perf; + max_perf_device = current_device; + } + } + } + + ++current_device; + } - return max_perf_device; + return max_perf_device; } // Initialization code to find the best CUDA Device -inline int findCudaDevice(int argc, const char **argv) { - cudaDeviceProp deviceProp; - int devID = 0; - - // If the command-line has a device number specified, use it - if (checkCmdLineFlag(argc, argv, "device")) { - devID = getCmdLineArgumentInt(argc, argv, "device="); - - if (devID < 0) { - printf("Invalid command line parameter\n "); - exit(EXIT_FAILURE); - } else { - devID = gpuDeviceInit(devID); - - if (devID < 0) { - printf("exiting...\n"); - exit(EXIT_FAILURE); - } +inline int findCudaDevice(int argc, const char **argv) +{ + cudaDeviceProp deviceProp; + int devID = 0; + + // If the command-line has a device number specified, use it + if (checkCmdLineFlag(argc, argv, "device")) + { + devID = getCmdLineArgumentInt(argc, argv, "device="); + + if (devID < 0) + { + printf("Invalid command line parameter\n "); + exit(EXIT_FAILURE); + } + else + { + devID = gpuDeviceInit(devID); + + if (devID < 0) + { + printf("exiting...\n"); + exit(EXIT_FAILURE); + } + } + } + else + { + // Otherwise pick the device with highest Gflops/s + devID = gpuGetMaxGflopsDeviceId(); + checkCudaErrors(cudaSetDevice(devID)); + checkCudaErrors(cudaGetDeviceProperties(&deviceProp, devID)); + printf("GPU Device %d: \"%s\" with compute capability %d.%d\n\n", devID, + deviceProp.name, deviceProp.major, deviceProp.minor); } - } else { - // Otherwise pick the device with highest Gflops/s - devID = gpuGetMaxGflopsDeviceId(); - checkCudaErrors(cudaSetDevice(devID)); - checkCudaErrors(cudaGetDeviceProperties(&deviceProp, devID)); - printf("GPU Device %d: \"%s\" with compute capability %d.%d\n\n", devID, - deviceProp.name, deviceProp.major, deviceProp.minor); - } - return devID; + return devID; } // General check for CUDA GPU SM Capabilities -inline bool checkCudaCapabilities(int major_version, int minor_version) { - cudaDeviceProp deviceProp; - deviceProp.major = 0; - deviceProp.minor = 0; - int dev; - - checkCudaErrors(cudaGetDevice(&dev)); - checkCudaErrors(cudaGetDeviceProperties(&deviceProp, dev)); - - if ((deviceProp.major > major_version) || - (deviceProp.major == major_version && - deviceProp.minor >= minor_version)) { - printf("> Device %d: <%16s >, Compute SM %d.%d detected\n", dev, - deviceProp.name, deviceProp.major, deviceProp.minor); - return true; - } else { - printf("No GPU device was found that can support CUDA compute capability " - "%d.%d.\n", - major_version, minor_version); - return false; - } +inline bool checkCudaCapabilities(int major_version, int minor_version) +{ + cudaDeviceProp deviceProp; + deviceProp.major = 0; + deviceProp.minor = 0; + int dev; + + checkCudaErrors(cudaGetDevice(&dev)); + checkCudaErrors(cudaGetDeviceProperties(&deviceProp, dev)); + + if ((deviceProp.major > major_version) || + (deviceProp.major == major_version && + deviceProp.minor >= minor_version)) + { + printf("> Device %d: <%16s >, Compute SM %d.%d detected\n", dev, + deviceProp.name, deviceProp.major, deviceProp.minor); + return true; + } + else + { + printf( + "No GPU device was found that can support CUDA compute capability " + "%d.%d.\n", + major_version, minor_version); + return false; + } } #endif diff --git a/solr/engines/cuda/helper_math.h b/solr/engines/cuda/helper_math.h index c9c07c3..1afd83a 100644 --- a/solr/engines/cuda/helper_math.h +++ b/solr/engines/cuda/helper_math.h @@ -225,7 +225,6 @@ inline __host__ __device__ int4 make_int4(float4 a) return make_int4(int(a.x), int(a.y), int(a.z), int(a.w)); } - inline __host__ __device__ uint4 make_uint4(uint s) { return make_uint4(s, s, s, s); @@ -345,7 +344,6 @@ inline __host__ __device__ void operator+=(uint2 &a, uint b) a.y += b; } - inline __host__ __device__ float3 operator+(float3 a, float3 b) { return make_float3(a.x + b.x, a.y + b.y, a.z + b.z); @@ -424,7 +422,7 @@ inline __host__ __device__ float3 operator+(float b, float3 a) inline __host__ __device__ float4 operator+(float4 a, float4 b) { - return make_float4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); + return make_float4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); } inline __host__ __device__ void operator+=(float4 &a, float4 b) { @@ -451,7 +449,7 @@ inline __host__ __device__ void operator+=(float4 &a, float b) inline __host__ __device__ int4 operator+(int4 a, int4 b) { - return make_int4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); + return make_int4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); } inline __host__ __device__ void operator+=(int4 &a, int4 b) { @@ -462,11 +460,11 @@ inline __host__ __device__ void operator+=(int4 &a, int4 b) } inline __host__ __device__ int4 operator+(int4 a, int b) { - return make_int4(a.x + b, a.y + b, a.z + b, a.w + b); + return make_int4(a.x + b, a.y + b, a.z + b, a.w + b); } inline __host__ __device__ int4 operator+(int b, int4 a) { - return make_int4(a.x + b, a.y + b, a.z + b, a.w + b); + return make_int4(a.x + b, a.y + b, a.z + b, a.w + b); } inline __host__ __device__ void operator+=(int4 &a, int b) { @@ -478,7 +476,7 @@ inline __host__ __device__ void operator+=(int4 &a, int b) inline __host__ __device__ uint4 operator+(uint4 a, uint4 b) { - return make_uint4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); + return make_uint4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); } inline __host__ __device__ void operator+=(uint4 &a, uint4 b) { @@ -489,11 +487,11 @@ inline __host__ __device__ void operator+=(uint4 &a, uint4 b) } inline __host__ __device__ uint4 operator+(uint4 a, uint b) { - return make_uint4(a.x + b, a.y + b, a.z + b, a.w + b); + return make_uint4(a.x + b, a.y + b, a.z + b, a.w + b); } inline __host__ __device__ uint4 operator+(uint b, uint4 a) { - return make_uint4(a.x + b, a.y + b, a.z + b, a.w + b); + return make_uint4(a.x + b, a.y + b, a.z + b, a.w + b); } inline __host__ __device__ void operator+=(uint4 &a, uint b) { @@ -653,7 +651,7 @@ inline __host__ __device__ void operator-=(uint3 &a, uint b) inline __host__ __device__ float4 operator-(float4 a, float4 b) { - return make_float4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); + return make_float4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); } inline __host__ __device__ void operator-=(float4 &a, float4 b) { @@ -664,7 +662,7 @@ inline __host__ __device__ void operator-=(float4 &a, float4 b) } inline __host__ __device__ float4 operator-(float4 a, float b) { - return make_float4(a.x - b, a.y - b, a.z - b, a.w - b); + return make_float4(a.x - b, a.y - b, a.z - b, a.w - b); } inline __host__ __device__ void operator-=(float4 &a, float b) { @@ -676,7 +674,7 @@ inline __host__ __device__ void operator-=(float4 &a, float b) inline __host__ __device__ int4 operator-(int4 a, int4 b) { - return make_int4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); + return make_int4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); } inline __host__ __device__ void operator-=(int4 &a, int4 b) { @@ -687,7 +685,7 @@ inline __host__ __device__ void operator-=(int4 &a, int4 b) } inline __host__ __device__ int4 operator-(int4 a, int b) { - return make_int4(a.x - b, a.y - b, a.z - b, a.w - b); + return make_int4(a.x - b, a.y - b, a.z - b, a.w - b); } inline __host__ __device__ int4 operator-(int b, int4 a) { @@ -703,7 +701,7 @@ inline __host__ __device__ void operator-=(int4 &a, int b) inline __host__ __device__ uint4 operator-(uint4 a, uint4 b) { - return make_uint4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); + return make_uint4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); } inline __host__ __device__ void operator-=(uint4 &a, uint4 b) { @@ -714,7 +712,7 @@ inline __host__ __device__ void operator-=(uint4 &a, uint4 b) } inline __host__ __device__ uint4 operator-(uint4 a, uint b) { - return make_uint4(a.x - b, a.y - b, a.z - b, a.w - b); + return make_uint4(a.x - b, a.y - b, a.z - b, a.w - b); } inline __host__ __device__ uint4 operator-(uint b, uint4 a) { @@ -878,7 +876,7 @@ inline __host__ __device__ void operator*=(uint3 &a, uint b) inline __host__ __device__ float4 operator*(float4 a, float4 b) { - return make_float4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); + return make_float4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); } inline __host__ __device__ void operator*=(float4 &a, float4 b) { @@ -889,7 +887,7 @@ inline __host__ __device__ void operator*=(float4 &a, float4 b) } inline __host__ __device__ float4 operator*(float4 a, float b) { - return make_float4(a.x * b, a.y * b, a.z * b, a.w * b); + return make_float4(a.x * b, a.y * b, a.z * b, a.w * b); } inline __host__ __device__ float4 operator*(float b, float4 a) { @@ -905,7 +903,7 @@ inline __host__ __device__ void operator*=(float4 &a, float b) inline __host__ __device__ int4 operator*(int4 a, int4 b) { - return make_int4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); + return make_int4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); } inline __host__ __device__ void operator*=(int4 &a, int4 b) { @@ -916,7 +914,7 @@ inline __host__ __device__ void operator*=(int4 &a, int4 b) } inline __host__ __device__ int4 operator*(int4 a, int b) { - return make_int4(a.x * b, a.y * b, a.z * b, a.w * b); + return make_int4(a.x * b, a.y * b, a.z * b, a.w * b); } inline __host__ __device__ int4 operator*(int b, int4 a) { @@ -932,7 +930,7 @@ inline __host__ __device__ void operator*=(int4 &a, int b) inline __host__ __device__ uint4 operator*(uint4 a, uint4 b) { - return make_uint4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); + return make_uint4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); } inline __host__ __device__ void operator*=(uint4 &a, uint4 b) { @@ -943,7 +941,7 @@ inline __host__ __device__ void operator*=(uint4 &a, uint4 b) } inline __host__ __device__ uint4 operator*(uint4 a, uint b) { - return make_uint4(a.x * b, a.y * b, a.z * b, a.w * b); + return make_uint4(a.x * b, a.y * b, a.z * b, a.w * b); } inline __host__ __device__ uint4 operator*(uint b, uint4 a) { @@ -1011,7 +1009,7 @@ inline __host__ __device__ float3 operator/(float b, float3 a) inline __host__ __device__ float4 operator/(float4 a, float4 b) { - return make_float4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w); + return make_float4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w); } inline __host__ __device__ void operator/=(float4 &a, float4 b) { @@ -1022,7 +1020,7 @@ inline __host__ __device__ void operator/=(float4 &a, float4 b) } inline __host__ __device__ float4 operator/(float4 a, float b) { - return make_float4(a.x / b, a.y / b, a.z / b, a.w / b); + return make_float4(a.x / b, a.y / b, a.z / b, a.w / b); } inline __host__ __device__ void operator/=(float4 &a, float b) { @@ -1040,43 +1038,46 @@ inline __host__ __device__ float4 operator/(float b, float4 a) // min //////////////////////////////////////////////////////////////////////////////// -inline __host__ __device__ float2 fminf(float2 a, float2 b) +inline __host__ __device__ float2 fminf(float2 a, float2 b) { - return make_float2(fminf(a.x,b.x), fminf(a.y,b.y)); + return make_float2(fminf(a.x, b.x), fminf(a.y, b.y)); } inline __host__ __device__ float3 fminf(float3 a, float3 b) { - return make_float3(fminf(a.x,b.x), fminf(a.y,b.y), fminf(a.z,b.z)); + return make_float3(fminf(a.x, b.x), fminf(a.y, b.y), fminf(a.z, b.z)); } -inline __host__ __device__ float4 fminf(float4 a, float4 b) +inline __host__ __device__ float4 fminf(float4 a, float4 b) { - return make_float4(fminf(a.x,b.x), fminf(a.y,b.y), fminf(a.z,b.z), fminf(a.w,b.w)); + return make_float4(fminf(a.x, b.x), fminf(a.y, b.y), fminf(a.z, b.z), + fminf(a.w, b.w)); } inline __host__ __device__ int2 min(int2 a, int2 b) { - return make_int2(min(a.x,b.x), min(a.y,b.y)); + return make_int2(min(a.x, b.x), min(a.y, b.y)); } inline __host__ __device__ int3 min(int3 a, int3 b) { - return make_int3(min(a.x,b.x), min(a.y,b.y), min(a.z,b.z)); + return make_int3(min(a.x, b.x), min(a.y, b.y), min(a.z, b.z)); } inline __host__ __device__ int4 min(int4 a, int4 b) { - return make_int4(min(a.x,b.x), min(a.y,b.y), min(a.z,b.z), min(a.w,b.w)); + return make_int4(min(a.x, b.x), min(a.y, b.y), min(a.z, b.z), + min(a.w, b.w)); } inline __host__ __device__ uint2 min(uint2 a, uint2 b) { - return make_uint2(min(a.x,b.x), min(a.y,b.y)); + return make_uint2(min(a.x, b.x), min(a.y, b.y)); } inline __host__ __device__ uint3 min(uint3 a, uint3 b) { - return make_uint3(min(a.x,b.x), min(a.y,b.y), min(a.z,b.z)); + return make_uint3(min(a.x, b.x), min(a.y, b.y), min(a.z, b.z)); } inline __host__ __device__ uint4 min(uint4 a, uint4 b) { - return make_uint4(min(a.x,b.x), min(a.y,b.y), min(a.z,b.z), min(a.w,b.w)); + return make_uint4(min(a.x, b.x), min(a.y, b.y), min(a.z, b.z), + min(a.w, b.w)); } //////////////////////////////////////////////////////////////////////////////// @@ -1085,41 +1086,44 @@ inline __host__ __device__ uint4 min(uint4 a, uint4 b) inline __host__ __device__ float2 fmaxf(float2 a, float2 b) { - return make_float2(fmaxf(a.x,b.x), fmaxf(a.y,b.y)); + return make_float2(fmaxf(a.x, b.x), fmaxf(a.y, b.y)); } inline __host__ __device__ float3 fmaxf(float3 a, float3 b) { - return make_float3(fmaxf(a.x,b.x), fmaxf(a.y,b.y), fmaxf(a.z,b.z)); + return make_float3(fmaxf(a.x, b.x), fmaxf(a.y, b.y), fmaxf(a.z, b.z)); } inline __host__ __device__ float4 fmaxf(float4 a, float4 b) { - return make_float4(fmaxf(a.x,b.x), fmaxf(a.y,b.y), fmaxf(a.z,b.z), fmaxf(a.w,b.w)); + return make_float4(fmaxf(a.x, b.x), fmaxf(a.y, b.y), fmaxf(a.z, b.z), + fmaxf(a.w, b.w)); } inline __host__ __device__ int2 max(int2 a, int2 b) { - return make_int2(max(a.x,b.x), max(a.y,b.y)); + return make_int2(max(a.x, b.x), max(a.y, b.y)); } inline __host__ __device__ int3 max(int3 a, int3 b) { - return make_int3(max(a.x,b.x), max(a.y,b.y), max(a.z,b.z)); + return make_int3(max(a.x, b.x), max(a.y, b.y), max(a.z, b.z)); } inline __host__ __device__ int4 max(int4 a, int4 b) { - return make_int4(max(a.x,b.x), max(a.y,b.y), max(a.z,b.z), max(a.w,b.w)); + return make_int4(max(a.x, b.x), max(a.y, b.y), max(a.z, b.z), + max(a.w, b.w)); } inline __host__ __device__ uint2 max(uint2 a, uint2 b) { - return make_uint2(max(a.x,b.x), max(a.y,b.y)); + return make_uint2(max(a.x, b.x), max(a.y, b.y)); } inline __host__ __device__ uint3 max(uint3 a, uint3 b) { - return make_uint3(max(a.x,b.x), max(a.y,b.y), max(a.z,b.z)); + return make_uint3(max(a.x, b.x), max(a.y, b.y), max(a.z, b.z)); } inline __host__ __device__ uint4 max(uint4 a, uint4 b) { - return make_uint4(max(a.x,b.x), max(a.y,b.y), max(a.z,b.z), max(a.w,b.w)); + return make_uint4(max(a.x, b.x), max(a.y, b.y), max(a.z, b.z), + max(a.w, b.w)); } //////////////////////////////////////////////////////////////////////////////// @@ -1129,19 +1133,19 @@ inline __host__ __device__ uint4 max(uint4 a, uint4 b) inline __device__ __host__ float lerp(float a, float b, float t) { - return a + t*(b-a); + return a + t * (b - a); } inline __device__ __host__ float2 lerp(float2 a, float2 b, float t) { - return a + t*(b-a); + return a + t * (b - a); } inline __device__ __host__ float3 lerp(float3 a, float3 b, float t) { - return a + t*(b-a); + return a + t * (b - a); } inline __device__ __host__ float4 lerp(float4 a, float4 b, float t) { - return a + t*(b-a); + return a + t * (b - a); } //////////////////////////////////////////////////////////////////////////////// @@ -1176,15 +1180,18 @@ inline __device__ __host__ float3 clamp(float3 v, float a, float b) } inline __device__ __host__ float3 clamp(float3 v, float3 a, float3 b) { - return make_float3(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z)); + return make_float3(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), + clamp(v.z, a.z, b.z)); } inline __device__ __host__ float4 clamp(float4 v, float a, float b) { - return make_float4(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b), clamp(v.w, a, b)); + return make_float4(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b), + clamp(v.w, a, b)); } inline __device__ __host__ float4 clamp(float4 v, float4 a, float4 b) { - return make_float4(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z), clamp(v.w, a.w, b.w)); + return make_float4(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), + clamp(v.z, a.z, b.z), clamp(v.w, a.w, b.w)); } inline __device__ __host__ int2 clamp(int2 v, int a, int b) @@ -1201,15 +1208,18 @@ inline __device__ __host__ int3 clamp(int3 v, int a, int b) } inline __device__ __host__ int3 clamp(int3 v, int3 a, int3 b) { - return make_int3(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z)); + return make_int3(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), + clamp(v.z, a.z, b.z)); } inline __device__ __host__ int4 clamp(int4 v, int a, int b) { - return make_int4(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b), clamp(v.w, a, b)); + return make_int4(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b), + clamp(v.w, a, b)); } inline __device__ __host__ int4 clamp(int4 v, int4 a, int4 b) { - return make_int4(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z), clamp(v.w, a.w, b.w)); + return make_int4(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), + clamp(v.z, a.z, b.z), clamp(v.w, a.w, b.w)); } inline __device__ __host__ uint2 clamp(uint2 v, uint a, uint b) @@ -1226,15 +1236,18 @@ inline __device__ __host__ uint3 clamp(uint3 v, uint a, uint b) } inline __device__ __host__ uint3 clamp(uint3 v, uint3 a, uint3 b) { - return make_uint3(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z)); + return make_uint3(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), + clamp(v.z, a.z, b.z)); } inline __device__ __host__ uint4 clamp(uint4 v, uint a, uint b) { - return make_uint4(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b), clamp(v.w, a, b)); + return make_uint4(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b), + clamp(v.w, a, b)); } inline __device__ __host__ uint4 clamp(uint4 v, uint4 a, uint4 b) { - return make_uint4(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z), clamp(v.w, a.w, b.w)); + return make_uint4(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), + clamp(v.z, a.z, b.z), clamp(v.w, a.w, b.w)); } //////////////////////////////////////////////////////////////////////////////// @@ -1369,7 +1382,8 @@ inline __host__ __device__ float3 fmodf(float3 a, float3 b) } inline __host__ __device__ float4 fmodf(float4 a, float4 b) { - return make_float4(fmodf(a.x, b.x), fmodf(a.y, b.y), fmodf(a.z, b.z), fmodf(a.w, b.w)); + return make_float4(fmodf(a.x, b.x), fmodf(a.y, b.y), fmodf(a.z, b.z), + fmodf(a.w, b.w)); } //////////////////////////////////////////////////////////////////////////////// @@ -1410,7 +1424,7 @@ inline __host__ __device__ int4 abs(int4 v) inline __host__ __device__ float3 reflect(float3 i, float3 n) { - return i - 2.0f * n * dot(n,i); + return i - 2.0f * n * dot(n, i); } //////////////////////////////////////////////////////////////////////////////// @@ -1419,7 +1433,8 @@ inline __host__ __device__ float3 reflect(float3 i, float3 n) inline __host__ __device__ float3 cross(float3 a, float3 b) { - return make_float3(a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x); + return make_float3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, + a.x * b.y - a.y * b.x); } //////////////////////////////////////////////////////////////////////////////// @@ -1432,22 +1447,22 @@ inline __host__ __device__ float3 cross(float3 a, float3 b) inline __device__ __host__ float smoothstep(float a, float b, float x) { float y = clamp((x - a) / (b - a), 0.0f, 1.0f); - return (y*y*(3.0f - (2.0f*y))); + return (y * y * (3.0f - (2.0f * y))); } inline __device__ __host__ float2 smoothstep(float2 a, float2 b, float2 x) { float2 y = clamp((x - a) / (b - a), 0.0f, 1.0f); - return (y*y*(make_float2(3.0f) - (make_float2(2.0f)*y))); + return (y * y * (make_float2(3.0f) - (make_float2(2.0f) * y))); } inline __device__ __host__ float3 smoothstep(float3 a, float3 b, float3 x) { float3 y = clamp((x - a) / (b - a), 0.0f, 1.0f); - return (y*y*(make_float3(3.0f) - (make_float3(2.0f)*y))); + return (y * y * (make_float3(3.0f) - (make_float3(2.0f) * y))); } inline __device__ __host__ float4 smoothstep(float4 a, float4 b, float4 x) { float4 y = clamp((x - a) / (b - a), 0.0f, 1.0f); - return (y*y*(make_float4(3.0f) - (make_float4(2.0f)*y))); + return (y * y * (make_float4(3.0f) - (make_float4(2.0f) * y))); } #endif diff --git a/solr/engines/cuda/helper_string.h b/solr/engines/cuda/helper_string.h index 961642a..61882cf 100644 --- a/solr/engines/cuda/helper_string.h +++ b/solr/engines/cuda/helper_string.h @@ -13,9 +13,9 @@ #ifndef STRING_HELPER_H #define STRING_HELPER_H +#include #include #include -#include #include #if defined(WIN32) || defined(_WIN32) || defined(WIN64) @@ -23,7 +23,7 @@ #define _CRT_SECURE_NO_DEPRECATE #endif #ifndef STRCASECMP -#define STRCASECMP _stricmp +#define STRCASECMP _stricmp #endif #ifndef STRNCASECMP #define STRNCASECMP _strnicmp @@ -33,7 +33,7 @@ #endif #ifndef FOPEN -#define FOPEN(fHandle,filename,mode) fopen_s(&fHandle, filename, mode) +#define FOPEN(fHandle, filename, mode) fopen_s(&fHandle, filename, mode) #endif #ifndef FOPEN_FAIL #define FOPEN_FAIL(result) (result != 0) @@ -49,7 +49,7 @@ #include #ifndef STRCASECMP -#define STRCASECMP strcasecmp +#define STRCASECMP strcasecmp #endif #ifndef STRNCASECMP #define STRNCASECMP strncasecmp @@ -59,7 +59,7 @@ #endif #ifndef FOPEN -#define FOPEN(fHandle,filename,mode) (fHandle = fopen(filename, mode)) +#define FOPEN(fHandle, filename, mode) (fHandle = fopen(filename, mode)) #endif #ifndef FOPEN_FAIL #define FOPEN_FAIL(result) (result == NULL) @@ -86,7 +86,7 @@ inline int stringRemoveDelimiter(char delimiter, const char *string) string_start++; } - if (string_start >= (int)strlen(string)-1) + if (string_start >= (int)strlen(string) - 1) { return 0; } @@ -104,7 +104,8 @@ inline int getFileExtension(char *filename, char **extension) break; } - if (string_length > 0) string_length += 2; + if (string_length > 0) + string_length += 2; if (string_length == 0) *extension = NULL; @@ -114,24 +115,26 @@ inline int getFileExtension(char *filename, char **extension) return string_length; } - -inline bool checkCmdLineFlag(const int argc, const char **argv, const char *string_ref) +inline bool checkCmdLineFlag(const int argc, const char **argv, + const char *string_ref) { bool bFound = false; if (argc >= 1) { - for (int i=1; i < argc; i++) + for (int i = 1; i < argc; i++) { int string_start = stringRemoveDelimiter('-', argv[i]); const char *string_argv = &argv[i][string_start]; const char *equal_pos = strchr(string_argv, '='); - int argv_length = (int)(equal_pos == 0 ? strlen(string_argv) : equal_pos - string_argv); + int argv_length = (int)(equal_pos == 0 ? strlen(string_argv) + : equal_pos - string_argv); int length = (int)strlen(string_ref); - if (length == argv_length && !STRNCASECMP(string_argv, string_ref, length)) + if (length == argv_length && + !STRNCASECMP(string_argv, string_ref, length)) { bFound = true; continue; @@ -144,13 +147,14 @@ inline bool checkCmdLineFlag(const int argc, const char **argv, const char *stri // This function wraps the CUDA Driver API into a template function template -inline bool getCmdLineArgumentValue(const int argc, const char **argv, const char *string_ref, T *value) +inline bool getCmdLineArgumentValue(const int argc, const char **argv, + const char *string_ref, T *value) { bool bFound = false; if (argc >= 1) { - for (int i=1; i < argc; i++) + for (int i = 1; i < argc; i++) { int string_start = stringRemoveDelimiter('-', argv[i]); const char *string_argv = &argv[i][string_start]; @@ -158,14 +162,14 @@ inline bool getCmdLineArgumentValue(const int argc, const char **argv, const cha if (!STRNCASECMP(string_argv, string_ref, length)) { - if (length+1 <= (int)strlen(string_argv)) + if (length + 1 <= (int)strlen(string_argv)) { int auto_inc = (string_argv[length] == '=') ? 1 : 0; *value = (T)atoi(&string_argv[length + auto_inc]); } bFound = true; - i=argc; + i = argc; } } } @@ -173,14 +177,15 @@ inline bool getCmdLineArgumentValue(const int argc, const char **argv, const cha return bFound; } -inline int getCmdLineArgumentInt(const int argc, const char **argv, const char *string_ref) +inline int getCmdLineArgumentInt(const int argc, const char **argv, + const char *string_ref) { bool bFound = false; int value = -1; if (argc >= 1) { - for (int i=1; i < argc; i++) + for (int i = 1; i < argc; i++) { int string_start = stringRemoveDelimiter('-', argv[i]); const char *string_argv = &argv[i][string_start]; @@ -188,7 +193,7 @@ inline int getCmdLineArgumentInt(const int argc, const char **argv, const char * if (!STRNCASECMP(string_argv, string_ref, length)) { - if (length+1 <= (int)strlen(string_argv)) + if (length + 1 <= (int)strlen(string_argv)) { int auto_inc = (string_argv[length] == '=') ? 1 : 0; value = atoi(&string_argv[length + auto_inc]); @@ -214,14 +219,15 @@ inline int getCmdLineArgumentInt(const int argc, const char **argv, const char * } } -inline float getCmdLineArgumentFloat(const int argc, const char **argv, const char *string_ref) +inline float getCmdLineArgumentFloat(const int argc, const char **argv, + const char *string_ref) { bool bFound = false; float value = -1; if (argc >= 1) { - for (int i=1; i < argc; i++) + for (int i = 1; i < argc; i++) { int string_start = stringRemoveDelimiter('-', argv[i]); const char *string_argv = &argv[i][string_start]; @@ -229,7 +235,7 @@ inline float getCmdLineArgumentFloat(const int argc, const char **argv, const ch if (!STRNCASECMP(string_argv, string_ref, length)) { - if (length+1 <= (int)strlen(string_argv)) + if (length + 1 <= (int)strlen(string_argv)) { int auto_inc = (string_argv[length] == '=') ? 1 : 0; value = (float)atof(&string_argv[length + auto_inc]); @@ -256,13 +262,14 @@ inline float getCmdLineArgumentFloat(const int argc, const char **argv, const ch } inline bool getCmdLineArgumentString(const int argc, const char **argv, - const char *string_ref, char **string_retval) + const char *string_ref, + char **string_retval) { bool bFound = false; if (argc >= 1) { - for (int i=1; i < argc; i++) + for (int i = 1; i < argc; i++) { int string_start = stringRemoveDelimiter('-', argv[i]); char *string_argv = (char *)&argv[i][string_start]; @@ -270,7 +277,7 @@ inline bool getCmdLineArgumentString(const int argc, const char **argv, if (!STRNCASECMP(string_argv, string_ref, length)) { - *string_retval = &string_argv[length+1]; + *string_retval = &string_argv[length + 1]; bFound = true; continue; } @@ -295,103 +302,212 @@ inline bool getCmdLineArgumentString(const int argc, const char **argv, ////////////////////////////////////////////////////////////////////////////// inline char *sdkFindFilePath(const char *filename, const char *executable_path) { - // defines a variable that is replaced with the name of the executable - - // Typical relative search paths to locate needed companion files (e.g. sample input data, or JIT source files) - // The origin for the relative search may be the .exe file, a .bat file launching an .exe, a browser .exe launching the .exe or .bat, etc - const char *searchPath[] = - { - "./", // same dir - "./common/", // "/common/" subdir - "./common/data/", // "/common/data/" subdir - "./data/", // "/data/" subdir - "./src/", // "/src/" subdir - "./src//data/", // "/src//data/" subdir - "./inc/", // "/inc/" subdir - "./0_Simple/", // "/0_Simple/" subdir - "./1_Utilities/", // "/1_Utilities/" subdir - "./2_Graphics/", // "/2_Graphics/" subdir - "./3_Imaging/", // "/3_Imaging/" subdir - "./4_Financial/", // "/4_Financial/" subdir - "./5_Simulations/", // "/5_Simulations/" subdir - "./6_Advanced/", // "/6_Advanced/" subdir - "./7_CUDALibraries/", // "/7_CUDALibraries/" subdir - "./samples/", // "/samples/" subdir - - "../", // up 1 in tree - "../common/", // up 1 in tree, "/common/" subdir - "../common/data/", // up 1 in tree, "/common/data/" subdir - "../data/", // up 1 in tree, "/data/" subdir - "../src/", // up 1 in tree, "/src/" subdir - "../inc/", // up 1 in tree, "/inc/" subdir - - "../0_Simple//data/", // up 1 in tree, "/0_Simple//" subdir - "../1_Utilities//data/", // up 1 in tree, "/1_Utilities//" subdir - "../2_Graphics//data/", // up 1 in tree, "/2_Graphics//" subdir - "../3_Imaging//data/", // up 1 in tree, "/3_Imaging//" subdir - "../4_Financial//data/", // up 1 in tree, "/4_Financial//" subdir - "../5_Simulations//data/", // up 1 in tree, "/5_Simulations//" subdir - "../6_Advanced//data/", // up 1 in tree, "/6_Advanced//" subdir - "../7_CUDALibraries//data/", // up 1 in tree, "/7_CUDALibraries//" subdir - "../samples//data/", // up 1 in tree, "/samples//" subdir - "../../", // up 2 in tree - "../../common/", // up 2 in tree, "/common/" subdir - "../../common/data/", // up 2 in tree, "/common/data/" subdir - "../../data/", // up 2 in tree, "/data/" subdir - "../../src/", // up 2 in tree, "/src/" subdir - "../../inc/", // up 2 in tree, "/inc/" subdir - "../../sandbox//data/", // up 2 in tree, "/sandbox//" subdir - "../../0_Simple//data/", // up 2 in tree, "/0_Simple//" subdir - "../../1_Utilities//data/", // up 2 in tree, "/1_Utilities//" subdir - "../../2_Graphics//data/", // up 2 in tree, "/2_Graphics//" subdir - "../../3_Imaging//data/", // up 2 in tree, "/3_Imaging//" subdir - "../../4_Financial//data/", // up 2 in tree, "/4_Financial//" subdir - "../../5_Simulations//data/", // up 2 in tree, "/5_Simulations//" subdir - "../../6_Advanced//data/", // up 2 in tree, "/6_Advanced//" subdir - "../../7_CUDALibraries//data/", // up 2 in tree, "/7_CUDALibraries//" subdir - "../../samples//data/", // up 2 in tree, "/samples//" subdir - "../../../", // up 3 in tree - "../../../src//", // up 3 in tree, "/src//" subdir - "../../../src//data/", // up 3 in tree, "/src//data/" subdir - "../../../src//src/", // up 3 in tree, "/src//src/" subdir - "../../../src//inc/", // up 3 in tree, "/src//inc/" subdir - "../../../sandbox//", // up 3 in tree, "/sandbox//" subdir - "../../../sandbox//data/", // up 3 in tree, "/sandbox//data/" subdir - "../../../sandbox//src/", // up 3 in tree, "/sandbox//src/" subdir - "../../../sandbox//inc/", // up 3 in tree, "/sandbox//inc/" subdir - "../../../0_Simple//data/", // up 3 in tree, "/0_Simple//" subdir - "../../../1_Utilities//data/", // up 3 in tree, "/1_Utilities//" subdir - "../../../2_Graphics//data/", // up 3 in tree, "/2_Graphics//" subdir - "../../../3_Imaging//data/", // up 3 in tree, "/3_Imaging//" subdir - "../../../4_Financial//data/", // up 3 in tree, "/4_Financial//" subdir - "../../../5_Simulations//data/",// up 3 in tree, "/5_Simulations//" subdir - "../../../6_Advanced//data/", // up 3 in tree, "/6_Advanced//" subdir - "../../../7_CUDALibraries//data/", // up 3 in tree, "/7_CUDALibraries//" subdir - "../../../samples//data/", // up 3 in tree, "/samples//" subdir - "../../../common/", // up 3 in tree, "../../../common/" subdir - "../../../common/data/", // up 3 in tree, "../../../common/data/" subdir - "../../../data/", // up 3 in tree, "../../../data/" subdir - "../../../../", // up 4 in tree - "../../../../src//", // up 4 in tree, "/src//" subdir - "../../../../src//data/", // up 4 in tree, "/src//data/" subdir - "../../../../src//src/", // up 4 in tree, "/src//src/" subdir - "../../../../src//inc/", // up 4 in tree, "/src//inc/" subdir - "../../../../sandbox//", // up 4 in tree, "/sandbox//" subdir - "../../../../sandbox//data/", // up 4 in tree, "/sandbox//data/" subdir - "../../../../sandbox//src/", // up 4 in tree, "/sandbox//src/" subdir - "../../../../sandbox//inc/", // up 4 in tree, "/sandbox//inc/" subdir - "../../../../0_Simple//data/", // up 4 in tree, "/0_Simple//" subdir - "../../../../1_Utilities//data/", // up 4 in tree, "/1_Utilities//" subdir - "../../../../2_Graphics//data/", // up 4 in tree, "/2_Graphics//" subdir - "../../../../3_Imaging//data/", // up 4 in tree, "/3_Imaging//" subdir - "../../../../4_Financial//data/", // up 4 in tree, "/4_Financial//" subdir - "../../../../5_Simulations//data/",// up 4 in tree, "/5_Simulations//" subdir - "../../../../6_Advanced//data/", // up 4 in tree, "/6_Advanced//" subdir - "../../../../7_CUDALibraries//data/", // up 4 in tree, "/7_CUDALibraries//" subdir - "../../../../samples//data/", // up 4 in tree, "/samples//" subdir - "../../../../common/", // up 4 in tree, "../../../common/" subdir - "../../../../common/data/", // up 4 in tree, "../../../common/data/" subdir - "../../../../data/", // up 4 in tree, "../../../data/" subdir + // defines a variable that is replaced with the name of + // the executable + + // Typical relative search paths to locate needed companion files (e.g. + // sample input data, or JIT source files) The origin for the relative + // search may be the .exe file, a .bat file launching an .exe, a browser + // .exe launching the .exe or .bat, etc + const char *searchPath[] = { + "./", // same dir + "./common/", // "/common/" subdir + "./common/data/", // "/common/data/" subdir + "./data/", // "/data/" subdir + "./src/", // "/src/" subdir + "./src//data/", // "/src//data/" + // subdir + "./inc/", // "/inc/" subdir + "./0_Simple/", // "/0_Simple/" subdir + "./1_Utilities/", // "/1_Utilities/" subdir + "./2_Graphics/", // "/2_Graphics/" subdir + "./3_Imaging/", // "/3_Imaging/" subdir + "./4_Financial/", // "/4_Financial/" subdir + "./5_Simulations/", // "/5_Simulations/" subdir + "./6_Advanced/", // "/6_Advanced/" subdir + "./7_CUDALibraries/", // "/7_CUDALibraries/" subdir + "./samples/", // "/samples/" subdir + + "../", // up 1 in tree + "../common/", // up 1 in tree, "/common/" subdir + "../common/data/", // up 1 in tree, "/common/data/" subdir + "../data/", // up 1 in tree, "/data/" subdir + "../src/", // up 1 in tree, "/src/" subdir + "../inc/", // up 1 in tree, "/inc/" subdir + + "../0_Simple//data/", // up 1 in tree, + // "/0_Simple//" + // subdir + "../1_Utilities//data/", // up 1 in tree, + // "/1_Utilities//" + // subdir + "../2_Graphics//data/", // up 1 in tree, + // "/2_Graphics//" + // subdir + "../3_Imaging//data/", // up 1 in tree, + // "/3_Imaging//" + // subdir + "../4_Financial//data/", // up 1 in tree, + // "/4_Financial//" + // subdir + "../5_Simulations//data/", // up 1 in tree, + // "/5_Simulations//" + // subdir + "../6_Advanced//data/", // up 1 in tree, + // "/6_Advanced//" + // subdir + "../7_CUDALibraries//data/", // up 1 in tree, + // "/7_CUDALibraries//" + // subdir + "../samples//data/", // up 1 in tree, + // "/samples//" + // subdir + "../../", // up 2 in tree + "../../common/", // up 2 in tree, "/common/" subdir + "../../common/data/", // up 2 in tree, "/common/data/" subdir + "../../data/", // up 2 in tree, "/data/" subdir + "../../src/", // up 2 in tree, "/src/" subdir + "../../inc/", // up 2 in tree, "/inc/" subdir + "../../sandbox//data/", // up 2 in tree, + // "/sandbox//" + // subdir + "../../0_Simple//data/", // up 2 in tree, + // "/0_Simple//" + // subdir + "../../1_Utilities//data/", // up 2 in tree, + // "/1_Utilities//" + // subdir + "../../2_Graphics//data/", // up 2 in tree, + // "/2_Graphics//" + // subdir + "../../3_Imaging//data/", // up 2 in tree, + // "/3_Imaging//" + // subdir + "../../4_Financial//data/", // up 2 in tree, + // "/4_Financial//" + // subdir + "../../5_Simulations//data/", // up 2 in tree, + // "/5_Simulations//" + // subdir + "../../6_Advanced//data/", // up 2 in tree, + // "/6_Advanced//" + // subdir + "../../7_CUDALibraries//data/", // up 2 in tree, + // "/7_CUDALibraries//" + // subdir + "../../samples//data/", // up 2 in tree, + // "/samples//" + // subdir + "../../../", // up 3 in tree + "../../../src//", // up 3 in tree, + // "/src//" subdir + "../../../src//data/", // up 3 in tree, + // "/src//data/" + // subdir + "../../../src//src/", // up 3 in tree, + // "/src//src/" + // subdir + "../../../src//inc/", // up 3 in tree, + // "/src//inc/" + // subdir + "../../../sandbox//", // up 3 in tree, + // "/sandbox//" + // subdir + "../../../sandbox//data/", // up 3 in tree, + // "/sandbox//data/" + // subdir + "../../../sandbox//src/", // up 3 in tree, + // "/sandbox//src/" + // subdir + "../../../sandbox//inc/", // up 3 in tree, + // "/sandbox//inc/" + // subdir + "../../../0_Simple//data/", // up 3 in tree, + // "/0_Simple//" + // subdir + "../../../1_Utilities//data/", // up 3 in tree, + // "/1_Utilities//" + // subdir + "../../../2_Graphics//data/", // up 3 in tree, + // "/2_Graphics//" + // subdir + "../../../3_Imaging//data/", // up 3 in tree, + // "/3_Imaging//" + // subdir + "../../../4_Financial//data/", // up 3 in tree, + // "/4_Financial//" + // subdir + "../../../5_Simulations//data/", // up 3 in tree, + // "/5_Simulations//" + // subdir + "../../../6_Advanced//data/", // up 3 in tree, + // "/6_Advanced//" + // subdir + "../../../7_CUDALibraries//data/", // up 3 in tree, + // "/7_CUDALibraries//" + // subdir + "../../../samples//data/", // up 3 in tree, + // "/samples//" + // subdir + "../../../common/", // up 3 in tree, "../../../common/" subdir + "../../../common/data/", // up 3 in tree, "../../../common/data/" subdir + "../../../data/", // up 3 in tree, "../../../data/" subdir + "../../../../", // up 4 in tree + "../../../../src//", // up 4 in tree, + // "/src//" + // subdir + "../../../../src//data/", // up 4 in tree, + // "/src//data/" + // subdir + "../../../../src//src/", // up 4 in tree, + // "/src//src/" + // subdir + "../../../../src//inc/", // up 4 in tree, + // "/src//inc/" + // subdir + "../../../../sandbox//", // up 4 in tree, + // "/sandbox//" + // subdir + "../../../../sandbox//data/", // up 4 in tree, + // "/sandbox//data/" + // subdir + "../../../../sandbox//src/", // up 4 in tree, + // "/sandbox//src/" + // subdir + "../../../../sandbox//inc/", // up 4 in tree, + // "/sandbox//inc/" + // subdir + "../../../../0_Simple//data/", // up 4 in tree, + // "/0_Simple//" + // subdir + "../../../../1_Utilities//data/", // up 4 in tree, + // "/1_Utilities//" + // subdir + "../../../../2_Graphics//data/", // up 4 in tree, + // "/2_Graphics//" + // subdir + "../../../../3_Imaging//data/", // up 4 in tree, + // "/3_Imaging//" + // subdir + "../../../../4_Financial//data/", // up 4 in tree, + // "/4_Financial//" + // subdir + "../../../../5_Simulations//data/", // up 4 in tree, + // "/5_Simulations//" + // subdir + "../../../../6_Advanced//data/", // up 4 in tree, + // "/6_Advanced//" + // subdir + "../../../../7_CUDALibraries//data/", // up 4 in tree, + // "/7_CUDALibraries//" + // subdir + "../../../../samples//data/", // up 4 in tree, + // "/samples//" + // subdir + "../../../../common/", // up 4 in tree, "../../../common/" subdir + "../../../../common/data/", // up 4 in tree, "../../../common/data/" + // subdir + "../../../../data/", // up 4 in tree, "../../../data/" subdir }; // Extract the executable name @@ -415,12 +531,12 @@ inline char *sdkFindFilePath(const char *filename, const char *executable_path) #else // Linux & OSX path delimiter size_t delimiter_pos = executable_name.find_last_of('/'); - executable_name.erase(0,delimiter_pos+1); + executable_name.erase(0, delimiter_pos + 1); #endif } // Loop over all search paths and return the first hit - for (unsigned int i = 0; i < sizeof(searchPath)/sizeof(char *); ++i) + for (unsigned int i = 0; i < sizeof(searchPath) / sizeof(char *); ++i) { std::string path(searchPath[i]); size_t executable_name_pos = path.find(""); @@ -431,7 +547,8 @@ inline char *sdkFindFilePath(const char *filename, const char *executable_path) { if (executable_path != 0) { - path.replace(executable_name_pos, strlen(""), executable_name); + path.replace(executable_name_pos, strlen(""), + executable_name); } else { @@ -453,8 +570,9 @@ inline char *sdkFindFilePath(const char *filename, const char *executable_path) { fclose(fp); // File found - // returning an allocated array here for backwards compatibility reasons - char *file_path = (char *) malloc(path.length() + 1); + // returning an allocated array here for backwards compatibility + // reasons + char *file_path = (char *)malloc(path.length() + 1); STRCPY(file_path, path.length() + 1, path.c_str()); return file_path; } diff --git a/solr/engines/opencl/OpenCLKernel.cpp b/solr/engines/opencl/OpenCLKernel.cpp index c2d2fd3..f0f0cac 100644 --- a/solr/engines/opencl/OpenCLKernel.cpp +++ b/solr/engines/opencl/OpenCLKernel.cpp @@ -1,33 +1,30 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau - * - * This file is part of Sol-R +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ -#include -#include - #ifdef __APPLE__ #include #else #include #endif +#include #include +#include +#include #ifdef WIN32 #include @@ -39,7 +36,6 @@ #define __CL_ENABLE_EXCEPTIONS - namespace solr { void getKernelCode(std::string &str) @@ -166,7 +162,8 @@ void buildNotify(cl_program, void *user_data) { LOG_ERROR("OpenCL Error (via buildNotify): " << user_data); } -void contextNotify(const char *errinfo, const void *private_info, size_t cb, void *user_data) +void contextNotify(const char *errinfo, const void *private_info, size_t cb, + void *user_data) { LOG_ERROR("OpenCL Error (via contextNotify): " << errinfo); } @@ -178,14 +175,15 @@ void contextNotify(const char *errinfo, const void *private_info, size_t cb, voi int __status = CL_SUCCESS; /*LOG_INFO(1,"[] " #stmt " []"); \*/ -#define CHECKSTATUS(stmt) \ - { \ - __status = stmt; \ - if (__status != CL_SUCCESS) \ - { \ - LOG_ERROR("Status=" << __status << " (" << getErrorDesc(__status) << ") for " #stmt); \ - exit(1); \ - } \ +#define CHECKSTATUS(stmt) \ + { \ + __status = stmt; \ + if (__status != CL_SUCCESS) \ + { \ + LOG_ERROR("Status=" << __status << " (" << getErrorDesc(__status) \ + << ") for " #stmt); \ + exit(1); \ + } \ } /* @@ -225,14 +223,18 @@ OpenCLKernel::OpenCLKernel() #ifdef LOGGING // Initialize Log - LOG_INITIALIZE_ETW(&GPU_OPENCLRAYTRACERMODULE, &GPU_OPENCLRAYTRACERMODULE_EVENT_DEBUG, - &GPU_OPENCLRAYTRACERMODULE_EVENT_VERBOSE, &GPU_OPENCLRAYTRACERMODULE_EVENT_INFO, - &GPU_OPENCLRAYTRACERMODULE_EVENT_WARNING, &GPU_OPENCLRAYTRACERMODULE_EVENT_ERROR); + LOG_INITIALIZE_ETW(&GPU_OPENCLRAYTRACERMODULE, + &GPU_OPENCLRAYTRACERMODULE_EVENT_DEBUG, + &GPU_OPENCLRAYTRACERMODULE_EVENT_VERBOSE, + &GPU_OPENCLRAYTRACERMODULE_EVENT_INFO, + &GPU_OPENCLRAYTRACERMODULE_EVENT_WARNING, + &GPU_OPENCLRAYTRACERMODULE_EVENT_ERROR); #endif // NDEBUG #if USE_KINECT // Initialize Kinect - int status = NuiInitialize(NUI_INITIALIZE_FLAG_USES_DEPTH_AND_PLAYER_INDEX | NUI_INITIALIZE_FLAG_USES_SKELETON | + int status = NuiInitialize(NUI_INITIALIZE_FLAG_USES_DEPTH_AND_PLAYER_INDEX | + NUI_INITIALIZE_FLAG_USES_SKELETON | NUI_INITIALIZE_FLAG_USES_COLOR); m_hNextDepthFrameEvent = CreateEvent(NULL, TRUE, FALSE, NULL); @@ -242,9 +244,11 @@ OpenCLKernel::OpenCLKernel() m_skeletons = CreateEvent(NULL, TRUE, FALSE, NULL); status = NuiSkeletonTrackingEnable(m_skeletons, 0); - status = NuiImageStreamOpen(NUI_IMAGE_TYPE_COLOR, NUI_IMAGE_RESOLUTION_640x480, 0, 2, m_hNextVideoFrameEvent, - &m_pVideoStreamHandle); - status = NuiImageStreamOpen(NUI_IMAGE_TYPE_DEPTH_AND_PLAYER_INDEX, NUI_IMAGE_RESOLUTION_320x240, 0, 2, + status = + NuiImageStreamOpen(NUI_IMAGE_TYPE_COLOR, NUI_IMAGE_RESOLUTION_640x480, + 0, 2, m_hNextVideoFrameEvent, &m_pVideoStreamHandle); + status = NuiImageStreamOpen(NUI_IMAGE_TYPE_DEPTH_AND_PLAYER_INDEX, + NUI_IMAGE_RESOLUTION_320x240, 0, 2, m_hNextDepthFrameEvent, &m_pDepthStreamHandle); status = NuiCameraElevationSetAngle(0); @@ -290,12 +294,14 @@ void OpenCLKernel::recompileKernels() LOG_INFO(3, "Create Program from source"); const char *kernel_code = kernelCode.c_str(); const size_t len = kernelCode.length(); - m_hProgram = - clCreateProgramWithSource(m_hContext, 1, (const char **)&kernel_code, (const size_t *)&len, &status); + m_hProgram = clCreateProgramWithSource(m_hContext, 1, + (const char **)&kernel_code, + (const size_t *)&len, &status); CHECKSTATUS(status); std::string compilationOptions = - "-cl-no-signed-zeros -cl-fast-relaxed-math -cl-unsafe-math-optimizations " + "-cl-no-signed-zeros -cl-fast-relaxed-math " + "-cl-unsafe-math-optimizations " "-cl-mad-enable"; #ifdef WIN32 compilationOptions += " -DMSVC"; @@ -308,11 +314,16 @@ void OpenCLKernel::recompileKernels() #endif LOG_INFO(1, "Building Program with " << compilationOptions); CHECKSTATUS( - clBuildProgram(m_hProgram, 1, &m_devices[m_platform][m_device], compilationOptions.c_str(), &buildNotify, NULL)); + clBuildProgram(m_hProgram, 1, &m_devices[m_platform][m_device], + compilationOptions.c_str(), &buildNotify, NULL)); size_t logSize; - CHECKSTATUS(clGetProgramBuildInfo(m_hProgram, m_hDeviceId, CL_PROGRAM_BUILD_LOG, 0, NULL, &logSize)); - char* log = new char[logSize]; - CHECKSTATUS(clGetProgramBuildInfo(m_hProgram, m_hDeviceId, CL_PROGRAM_BUILD_LOG, logSize, log, NULL)); + CHECKSTATUS(clGetProgramBuildInfo(m_hProgram, m_hDeviceId, + CL_PROGRAM_BUILD_LOG, 0, NULL, + &logSize)); + char *log = new char[logSize]; + CHECKSTATUS(clGetProgramBuildInfo(m_hProgram, m_hDeviceId, + CL_PROGRAM_BUILD_LOG, logSize, log, + NULL)); if (logSize > 1) LOG_INFO(1, log); delete[] log; @@ -322,8 +333,9 @@ void OpenCLKernel::recompileKernels() CHECKSTATUS(status); size_t szLocalWorkSize[] = {1, 1}; size_t szGlobalWorkSize[] = {1, 1}; - CHECKSTATUS( - clEnqueueNDRangeKernel(m_hQueue, m_kAlignment, 2, NULL, szGlobalWorkSize, szLocalWorkSize, 0, 0, 0)); + CHECKSTATUS(clEnqueueNDRangeKernel(m_hQueue, m_kAlignment, 2, NULL, + szGlobalWorkSize, szLocalWorkSize, 0, + 0, 0)); LOG_INFO(3, "--== C++ Data structures ==--"); LOG_INFO(3, "Ray : " << sizeof(Ray)); LOG_INFO(3, "SceneInfo : " << sizeof(SceneInfo)); @@ -337,19 +349,24 @@ void OpenCLKernel::recompileKernels() #endif // Rendering kernels - m_kStandardRenderer = clCreateKernel(m_hProgram, "k_standardRenderer", &status); + m_kStandardRenderer = + clCreateKernel(m_hProgram, "k_standardRenderer", &status); CHECKSTATUS(status); - m_kAnaglyphRenderer = clCreateKernel(m_hProgram, "k_anaglyphRenderer", &status); + m_kAnaglyphRenderer = + clCreateKernel(m_hProgram, "k_anaglyphRenderer", &status); CHECKSTATUS(status); - m_k3DVisionRenderer = clCreateKernel(m_hProgram, "k_3DVisionRenderer", &status); + m_k3DVisionRenderer = + clCreateKernel(m_hProgram, "k_3DVisionRenderer", &status); CHECKSTATUS(status); - m_kFishEyeRenderer = clCreateKernel(m_hProgram, "k_fishEyeRenderer", &status); + m_kFishEyeRenderer = + clCreateKernel(m_hProgram, "k_fishEyeRenderer", &status); CHECKSTATUS(status); - m_kVolumeRenderer = clCreateKernel(m_hProgram, "k_volumeRenderer", &status); + m_kVolumeRenderer = + clCreateKernel(m_hProgram, "k_volumeRenderer", &status); CHECKSTATUS(status); LOG_INFO(1, "Rendering kernels created"); @@ -361,7 +378,8 @@ void OpenCLKernel::recompileKernels() m_kDepthOfField = clCreateKernel(m_hProgram, "k_depthOfField", &status); CHECKSTATUS(status); - m_kAmbientOcclusion = clCreateKernel(m_hProgram, "k_ambientOcclusion", &status); + m_kAmbientOcclusion = + clCreateKernel(m_hProgram, "k_ambientOcclusion", &status); CHECKSTATUS(status); m_kRadiosity = clCreateKernel(m_hProgram, "k_radiosity", &status); @@ -385,12 +403,16 @@ void OpenCLKernel::initializeDevice() queryDevice(); // initialize OpenCL device - LOG_INFO(1, "Initializing OpenCL context on platform: " << m_platform << ", device: " << m_hDeviceId); - m_hContext = clCreateContext(NULL, m_numberOfDevices[m_platform], m_devices[m_platform], &contextNotify, NULL, &status); + LOG_INFO(1, "Initializing OpenCL context on platform: " + << m_platform << ", device: " << m_hDeviceId); + m_hContext = + clCreateContext(NULL, m_numberOfDevices[m_platform], + m_devices[m_platform], &contextNotify, NULL, &status); CHECKSTATUS(status); m_hDeviceId = m_devices[m_platform][m_device]; if (m_hContext) - LOG_INFO(1, "OpenCL context successfully initialized on platform: " << m_platform << ", device: " << m_device); + LOG_INFO(1, "OpenCL context successfully initialized on platform: " + << m_platform << ", device: " << m_device); m_hQueue = clCreateCommandQueue(m_hContext, m_hDeviceId, 0, &status); CHECKSTATUS(status); if (m_hQueue) @@ -400,17 +422,28 @@ void OpenCLKernel::initializeDevice() LOG_INFO(3, "Setup device memory"); vec1i errorCode = 0; reshape(); - m_dBoundingBoxes = clCreateBuffer(m_hContext, CL_MEM_READ_ONLY, sizeof(BoundingBox) * NB_MAX_BOXES, 0, &errorCode); - m_dLamps = clCreateBuffer(m_hContext, CL_MEM_READ_ONLY, sizeof(Lamp) * NB_MAX_LAMPS, 0, &errorCode); - m_dLightInformation = clCreateBuffer(m_hContext, CL_MEM_READ_ONLY, - sizeof(LightInformation) * NB_MAX_LIGHTINFORMATIONS, 0, &errorCode); - m_dMaterials = clCreateBuffer(m_hContext, CL_MEM_READ_ONLY, sizeof(Material) * NB_MAX_MATERIALS, 0, &errorCode); + m_dBoundingBoxes = + clCreateBuffer(m_hContext, CL_MEM_READ_ONLY, + sizeof(BoundingBox) * NB_MAX_BOXES, 0, &errorCode); + m_dLamps = clCreateBuffer(m_hContext, CL_MEM_READ_ONLY, + sizeof(Lamp) * NB_MAX_LAMPS, 0, &errorCode); + m_dLightInformation = + clCreateBuffer(m_hContext, CL_MEM_READ_ONLY, + sizeof(LightInformation) * NB_MAX_LIGHTINFORMATIONS, 0, + &errorCode); + m_dMaterials = + clCreateBuffer(m_hContext, CL_MEM_READ_ONLY, + sizeof(Material) * NB_MAX_MATERIALS, 0, &errorCode); #if USE_KINECT m_dVideo = clCreateBuffer(m_hContext, CL_MEM_READ_ONLY, - KINECT_COLOR_WIDTH * KINECT_COLOR_HEIGHT * KINECT_COLOR_DEPTH, 0, &errorCode); + KINECT_COLOR_WIDTH * KINECT_COLOR_HEIGHT * + KINECT_COLOR_DEPTH, + 0, &errorCode); m_dDepth = clCreateBuffer(m_hContext, CL_MEM_READ_ONLY, - KINECT_DEPTH_WIDTH * KINECT_DEPTH_HEIGHT * KINECT_DEPTH_DEPTH, 0, &errorCode); + KINECT_DEPTH_WIDTH * KINECT_DEPTH_HEIGHT * + KINECT_DEPTH_DEPTH, + 0, &errorCode); #endif // USE_KINECT } @@ -541,41 +574,51 @@ void OpenCLKernel::render_begin(const float timer) int nbPrimitives = m_nbActivePrimitives[m_frame]; int nbLamps = m_nbActiveLamps[m_frame]; int nbMaterials = m_nbActiveMaterials + 1; - LOG_INFO(3, "Data sizes [" << m_frame << "]: " << nbBoxes << ", " << nbPrimitives << ", " - << m_lightInformationSize << ", " << nbLamps); + LOG_INFO(3, "Data sizes [" + << m_frame << "]: " << nbBoxes << ", " << nbPrimitives + << ", " << m_lightInformationSize << ", " << nbLamps); if (!m_primitivesTransfered) { - CHECKSTATUS(clEnqueueWriteBuffer(m_hQueue, m_dBoundingBoxes, CL_TRUE, 0, nbBoxes * sizeof(BoundingBox), + CHECKSTATUS(clEnqueueWriteBuffer(m_hQueue, m_dBoundingBoxes, + CL_TRUE, 0, + nbBoxes * sizeof(BoundingBox), m_hBoundingBoxes, 0, NULL, NULL)); int errorCode; if (_dPrimitives) CHECKSTATUS(clReleaseMemObject(_dPrimitives)); _dPrimitives = - clCreateBuffer(m_hContext, CL_MEM_READ_ONLY, sizeof(Primitive) * nbPrimitives, 0, &errorCode); - CHECKSTATUS(clEnqueueWriteBuffer(m_hQueue, _dPrimitives, CL_TRUE, 0, nbPrimitives * sizeof(Primitive), + clCreateBuffer(m_hContext, CL_MEM_READ_ONLY, + sizeof(Primitive) * nbPrimitives, 0, &errorCode); + CHECKSTATUS(clEnqueueWriteBuffer(m_hQueue, _dPrimitives, CL_TRUE, 0, + nbPrimitives * sizeof(Primitive), m_hPrimitives, 0, NULL, NULL)); + CHECKSTATUS(clEnqueueWriteBuffer(m_hQueue, m_dLamps, CL_TRUE, 0, + nbLamps * sizeof(Lamp), m_hLamps, + 0, NULL, NULL)); CHECKSTATUS( - clEnqueueWriteBuffer(m_hQueue, m_dLamps, CL_TRUE, 0, nbLamps * sizeof(Lamp), m_hLamps, 0, NULL, NULL)); - CHECKSTATUS(clEnqueueWriteBuffer(m_hQueue, m_dLightInformation, CL_TRUE, 0, - m_lightInformationSize * sizeof(LightInformation), m_lightInformation, 0, - NULL, NULL)); + clEnqueueWriteBuffer(m_hQueue, m_dLightInformation, CL_TRUE, 0, + m_lightInformationSize * + sizeof(LightInformation), + m_lightInformation, 0, NULL, NULL)); m_primitivesTransfered = true; } if (!m_randomsTransfered) { - CHECKSTATUS(clEnqueueWriteBuffer(m_hQueue, m_dRandoms, CL_TRUE, 0, - m_sceneInfo.size.x * m_sceneInfo.size.y * sizeof(RandomBuffer), m_hRandoms, - 0, NULL, NULL)); + CHECKSTATUS(clEnqueueWriteBuffer( + m_hQueue, m_dRandoms, CL_TRUE, 0, + m_sceneInfo.size.x * m_sceneInfo.size.y * sizeof(RandomBuffer), + RandomGenerator::getInstance().getBuffer(), 0, NULL, NULL)); m_randomsTransfered = true; } if (!m_materialsTransfered) { realignTexturesAndMaterials(); - CHECKSTATUS(clEnqueueWriteBuffer(m_hQueue, m_dMaterials, CL_TRUE, 0, nbMaterials * sizeof(Material), + CHECKSTATUS(clEnqueueWriteBuffer(m_hQueue, m_dMaterials, CL_TRUE, 0, + nbMaterials * sizeof(Material), m_hMaterials, 0, NULL, NULL)); m_materialsTransfered = true; } @@ -586,7 +629,8 @@ void OpenCLKernel::render_begin(const float timer) // Video const NUI_IMAGE_FRAME *pImageFrame = 0; WaitForSingleObject(m_hNextVideoFrameEvent, INFINITE); - HRESULT status = NuiImageStreamGetNextFrame(m_pVideoStreamHandle, 0, &pImageFrame); + HRESULT status = NuiImageStreamGetNextFrame(m_pVideoStreamHandle, 0, + &pImageFrame); if ((status == S_OK) && pImageFrame) { INuiFrameTexture *pTexture = pImageFrame->pFrameTexture; @@ -601,7 +645,8 @@ void OpenCLKernel::render_begin(const float timer) // Depth const NUI_IMAGE_FRAME *pDepthFrame = 0; WaitForSingleObject(m_hNextDepthFrameEvent, INFINITE); - status = NuiImageStreamGetNextFrame(m_pDepthStreamHandle, 0, &pDepthFrame); + status = NuiImageStreamGetNextFrame(m_pDepthStreamHandle, 0, + &pDepthFrame); if ((status == S_OK) && pDepthFrame) { INuiFrameTexture *pTexture = pDepthFrame->pFrameTexture; @@ -629,7 +674,8 @@ void OpenCLKernel::render_begin(const float timer) int totalSize(0); for (int i(0); i < m_nbActiveTextures; ++i) { - totalSize += m_hTextures[i].size.x * m_hTextures[i].size.y * m_hTextures[i].size.z; + totalSize += m_hTextures[i].size.x * m_hTextures[i].size.y * + m_hTextures[i].size.z; } LOG_INFO(3, "Total texture size: " << totalSize << " bytes"); @@ -648,23 +694,33 @@ void OpenCLKernel::render_begin(const float timer) { if (m_hTextures[i].buffer != 0) { - int textureSize = m_hTextures[i].size.x * m_hTextures[i].size.y * m_hTextures[i].size.z; - memcpy(tmpTextures + m_hTextures[i].offset, m_hTextures[i].buffer, textureSize); + int textureSize = m_hTextures[i].size.x * + m_hTextures[i].size.y * + m_hTextures[i].size.z; + memcpy(tmpTextures + m_hTextures[i].offset, + m_hTextures[i].buffer, textureSize); } } LOG_INFO(3, "Creating texture buffer"); - m_dTextures = clCreateBuffer(m_hContext, CL_MEM_READ_ONLY, totalSize * sizeof(BitmapBuffer), 0, NULL); - CHECKSTATUS(clEnqueueWriteBuffer(m_hQueue, m_dTextures, CL_TRUE, 0, totalSize * sizeof(BitmapBuffer), - tmpTextures, 0, NULL, NULL)); - LOG_INFO(3, "Total GPU texture memory allocated: " << totalSize << " bytes"); + m_dTextures = + clCreateBuffer(m_hContext, CL_MEM_READ_ONLY, + totalSize * sizeof(BitmapBuffer), 0, NULL); + CHECKSTATUS( + clEnqueueWriteBuffer(m_hQueue, m_dTextures, CL_TRUE, 0, + totalSize * sizeof(BitmapBuffer), + tmpTextures, 0, NULL, NULL)); + LOG_INFO(3, "Total GPU texture memory allocated: " << totalSize + << " bytes"); delete[] tmpTextures; } m_texturesTransfered = true; } // Kernel execution - LOG_INFO(3, "CPU PostProcessingBuffer: " << sizeof(PostProcessingBuffer)); - LOG_INFO(3, "CPU PrimitiveXYIdBuffer : " << sizeof(PrimitiveXYIdBuffer)); + LOG_INFO(3, + "CPU PostProcessingBuffer: " << sizeof(PostProcessingBuffer)); + LOG_INFO(3, + "CPU PrimitiveXYIdBuffer : " << sizeof(PrimitiveXYIdBuffer)); LOG_INFO(3, "CPU BoundingBox : " << sizeof(BoundingBox)); LOG_INFO(3, "CPU Primitive : " << sizeof(Primitive)); LOG_INFO(3, "CPU Material : " << sizeof(Material)); @@ -674,7 +730,8 @@ void OpenCLKernel::render_begin(const float timer) sceneInfo.graphicsLevel = glNoShading; size_t szLocalWorkSize[] = {1, 1}; - size_t szGlobalWorkSize[] = {m_sceneInfo.size.x / szLocalWorkSize[0], m_sceneInfo.size.y / szLocalWorkSize[1]}; + size_t szGlobalWorkSize[] = {m_sceneInfo.size.x / szLocalWorkSize[0], + m_sceneInfo.size.y / szLocalWorkSize[1]}; int zero(0); LOG_INFO(3, "Running default rendering kernel"); switch (sceneInfo.cameraType) @@ -682,136 +739,241 @@ void OpenCLKernel::render_begin(const float timer) case ctAnaglyph: { // Run the post processing kernel!! - CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 0, sizeof(vec2i), (void *)&m_occupancyParameters)); - CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 1, sizeof(vec1i), (void *)&zero)); - CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 2, sizeof(vec1i), (void *)&zero)); - CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 3, sizeof(cl_mem), (void *)&m_dBoundingBoxes)); - CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 4, sizeof(vec1i), (void *)&nbBoxes)); - CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 5, sizeof(cl_mem), (void *)&_dPrimitives)); - CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 6, sizeof(vec1i), (void *)&nbPrimitives)); - CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 7, sizeof(cl_mem), (void *)&m_dLightInformation)); - CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 8, sizeof(vec1i), (void *)&m_lightInformationSize)); - CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 9, sizeof(vec1i), (void *)&nbLamps)); - CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 10, sizeof(cl_mem), (void *)&m_dMaterials)); - CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 11, sizeof(cl_mem), (void *)&m_dTextures)); - CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 12, sizeof(cl_mem), (void *)&m_dRandoms)); - CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 13, sizeof(vec4f), (void *)&m_viewPos)); - CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 14, sizeof(vec4f), (void *)&m_viewDir)); - CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 15, sizeof(vec4f), (void *)&m_angles)); - CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 16, sizeof(SceneInfo), (void *)&sceneInfo)); - CHECKSTATUS( - clSetKernelArg(m_kAnaglyphRenderer, 17, sizeof(PostProcessingInfo), (void *)&m_postProcessingInfo)); - CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 18, sizeof(cl_mem), (void *)&m_dPostProcessingBuffer)); - CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 19, sizeof(cl_mem), (void *)&m_dPrimitivesXYIds)); - CHECKSTATUS(clEnqueueNDRangeKernel(m_hQueue, m_kAnaglyphRenderer, 2, NULL, szGlobalWorkSize, + CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 0, sizeof(vec2i), + (void *)&m_occupancyParameters)); + CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 1, sizeof(vec1i), + (void *)&zero)); + CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 2, sizeof(vec1i), + (void *)&zero)); + CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 3, sizeof(cl_mem), + (void *)&m_dBoundingBoxes)); + CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 4, sizeof(vec1i), + (void *)&nbBoxes)); + CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 5, sizeof(cl_mem), + (void *)&_dPrimitives)); + CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 6, sizeof(vec1i), + (void *)&nbPrimitives)); + CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 7, sizeof(cl_mem), + (void *)&m_dLightInformation)); + CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 8, sizeof(vec1i), + (void *)&m_lightInformationSize)); + CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 9, sizeof(vec1i), + (void *)&nbLamps)); + CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 10, sizeof(cl_mem), + (void *)&m_dMaterials)); + CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 11, sizeof(cl_mem), + (void *)&m_dTextures)); + CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 12, sizeof(cl_mem), + (void *)&m_dRandoms)); + CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 13, sizeof(vec4f), + (void *)&m_viewPos)); + CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 14, sizeof(vec4f), + (void *)&m_viewDir)); + CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 15, sizeof(vec4f), + (void *)&m_angles)); + CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 16, + sizeof(SceneInfo), (void *)&sceneInfo)); + CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 17, + sizeof(PostProcessingInfo), + (void *)&m_postProcessingInfo)); + CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 18, sizeof(cl_mem), + (void *)&m_dPostProcessingBuffer)); + CHECKSTATUS(clSetKernelArg(m_kAnaglyphRenderer, 19, sizeof(cl_mem), + (void *)&m_dPrimitivesXYIds)); + CHECKSTATUS(clEnqueueNDRangeKernel(m_hQueue, m_kAnaglyphRenderer, 2, + NULL, szGlobalWorkSize, szLocalWorkSize, 0, 0, 0)); break; } case ctVR: { - CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 0, sizeof(vec2i), (void *)&m_occupancyParameters)); - CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 1, sizeof(vec1i), (void *)&zero)); - CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 2, sizeof(vec1i), (void *)&zero)); - CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 3, sizeof(cl_mem), (void *)&m_dBoundingBoxes)); - CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 4, sizeof(vec1i), (void *)&nbBoxes)); - CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 5, sizeof(cl_mem), (void *)&_dPrimitives)); - CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 6, sizeof(vec1i), (void *)&nbPrimitives)); - CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 7, sizeof(cl_mem), (void *)&m_dLightInformation)); - CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 8, sizeof(vec1i), (void *)&m_lightInformationSize)); - CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 9, sizeof(vec1i), (void *)&nbLamps)); - CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 10, sizeof(cl_mem), (void *)&m_dMaterials)); - CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 11, sizeof(cl_mem), (void *)&m_dTextures)); - CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 12, sizeof(cl_mem), (void *)&m_dRandoms)); - CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 13, sizeof(vec4f), (void *)&m_viewPos)); - CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 14, sizeof(vec4f), (void *)&m_viewDir)); - CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 15, sizeof(vec4f), (void *)&m_angles)); - CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 16, sizeof(SceneInfo), (void *)&sceneInfo)); - CHECKSTATUS( - clSetKernelArg(m_k3DVisionRenderer, 17, sizeof(PostProcessingInfo), (void *)&m_postProcessingInfo)); - CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 18, sizeof(cl_mem), (void *)&m_dPostProcessingBuffer)); - CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 19, sizeof(cl_mem), (void *)&m_dPrimitivesXYIds)); - CHECKSTATUS(clEnqueueNDRangeKernel(m_hQueue, m_k3DVisionRenderer, 2, NULL, szGlobalWorkSize, + CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 0, sizeof(vec2i), + (void *)&m_occupancyParameters)); + CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 1, sizeof(vec1i), + (void *)&zero)); + CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 2, sizeof(vec1i), + (void *)&zero)); + CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 3, sizeof(cl_mem), + (void *)&m_dBoundingBoxes)); + CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 4, sizeof(vec1i), + (void *)&nbBoxes)); + CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 5, sizeof(cl_mem), + (void *)&_dPrimitives)); + CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 6, sizeof(vec1i), + (void *)&nbPrimitives)); + CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 7, sizeof(cl_mem), + (void *)&m_dLightInformation)); + CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 8, sizeof(vec1i), + (void *)&m_lightInformationSize)); + CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 9, sizeof(vec1i), + (void *)&nbLamps)); + CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 10, sizeof(cl_mem), + (void *)&m_dMaterials)); + CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 11, sizeof(cl_mem), + (void *)&m_dTextures)); + CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 12, sizeof(cl_mem), + (void *)&m_dRandoms)); + CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 13, sizeof(vec4f), + (void *)&m_viewPos)); + CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 14, sizeof(vec4f), + (void *)&m_viewDir)); + CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 15, sizeof(vec4f), + (void *)&m_angles)); + CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 16, + sizeof(SceneInfo), (void *)&sceneInfo)); + CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 17, + sizeof(PostProcessingInfo), + (void *)&m_postProcessingInfo)); + CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 18, sizeof(cl_mem), + (void *)&m_dPostProcessingBuffer)); + CHECKSTATUS(clSetKernelArg(m_k3DVisionRenderer, 19, sizeof(cl_mem), + (void *)&m_dPrimitivesXYIds)); + CHECKSTATUS(clEnqueueNDRangeKernel(m_hQueue, m_k3DVisionRenderer, 2, + NULL, szGlobalWorkSize, szLocalWorkSize, 0, 0, 0)); break; } case ctPanoramic: { - CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 0, sizeof(vec2i), (void *)&m_occupancyParameters)); - CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 1, sizeof(vec1i), (void *)&zero)); - CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 2, sizeof(vec1i), (void *)&zero)); - CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 3, sizeof(cl_mem), (void *)&m_dBoundingBoxes)); - CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 4, sizeof(vec1i), (void *)&nbBoxes)); - CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 5, sizeof(cl_mem), (void *)&_dPrimitives)); - CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 6, sizeof(vec1i), (void *)&nbPrimitives)); - CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 7, sizeof(cl_mem), (void *)&m_dLightInformation)); - CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 8, sizeof(vec1i), (void *)&m_lightInformationSize)); - CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 9, sizeof(vec1i), (void *)&nbLamps)); - CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 10, sizeof(cl_mem), (void *)&m_dMaterials)); - CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 11, sizeof(cl_mem), (void *)&m_dTextures)); - CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 12, sizeof(cl_mem), (void *)&m_dRandoms)); - CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 13, sizeof(vec4f), (void *)&m_viewPos)); - CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 14, sizeof(vec4f), (void *)&m_viewDir)); - CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 15, sizeof(vec4f), (void *)&m_angles)); - CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 16, sizeof(SceneInfo), (void *)&sceneInfo)); - CHECKSTATUS( - clSetKernelArg(m_kFishEyeRenderer, 17, sizeof(PostProcessingInfo), (void *)&m_postProcessingInfo)); - CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 18, sizeof(cl_mem), (void *)&m_dPostProcessingBuffer)); - CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 19, sizeof(cl_mem), (void *)&m_dPrimitivesXYIds)); - CHECKSTATUS(clEnqueueNDRangeKernel(m_hQueue, m_kFishEyeRenderer, 2, NULL, szGlobalWorkSize, szLocalWorkSize, - 0, 0, 0)); + CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 0, sizeof(vec2i), + (void *)&m_occupancyParameters)); + CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 1, sizeof(vec1i), + (void *)&zero)); + CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 2, sizeof(vec1i), + (void *)&zero)); + CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 3, sizeof(cl_mem), + (void *)&m_dBoundingBoxes)); + CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 4, sizeof(vec1i), + (void *)&nbBoxes)); + CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 5, sizeof(cl_mem), + (void *)&_dPrimitives)); + CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 6, sizeof(vec1i), + (void *)&nbPrimitives)); + CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 7, sizeof(cl_mem), + (void *)&m_dLightInformation)); + CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 8, sizeof(vec1i), + (void *)&m_lightInformationSize)); + CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 9, sizeof(vec1i), + (void *)&nbLamps)); + CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 10, sizeof(cl_mem), + (void *)&m_dMaterials)); + CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 11, sizeof(cl_mem), + (void *)&m_dTextures)); + CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 12, sizeof(cl_mem), + (void *)&m_dRandoms)); + CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 13, sizeof(vec4f), + (void *)&m_viewPos)); + CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 14, sizeof(vec4f), + (void *)&m_viewDir)); + CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 15, sizeof(vec4f), + (void *)&m_angles)); + CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 16, + sizeof(SceneInfo), (void *)&sceneInfo)); + CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 17, + sizeof(PostProcessingInfo), + (void *)&m_postProcessingInfo)); + CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 18, sizeof(cl_mem), + (void *)&m_dPostProcessingBuffer)); + CHECKSTATUS(clSetKernelArg(m_kFishEyeRenderer, 19, sizeof(cl_mem), + (void *)&m_dPrimitivesXYIds)); + CHECKSTATUS(clEnqueueNDRangeKernel(m_hQueue, m_kFishEyeRenderer, 2, + NULL, szGlobalWorkSize, + szLocalWorkSize, 0, 0, 0)); break; } case ctVolumeRendering: { - CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 0, sizeof(vec2i), (void *)&m_occupancyParameters)); - CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 1, sizeof(vec1i), (void *)&zero)); - CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 2, sizeof(vec1i), (void *)&zero)); - CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 3, sizeof(cl_mem), (void *)&m_dBoundingBoxes)); - CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 4, sizeof(vec1i), (void *)&nbBoxes)); - CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 5, sizeof(cl_mem), (void *)&_dPrimitives)); - CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 6, sizeof(vec1i), (void *)&nbPrimitives)); - CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 7, sizeof(cl_mem), (void *)&m_dLightInformation)); - CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 8, sizeof(vec1i), (void *)&m_lightInformationSize)); - CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 9, sizeof(vec1i), (void *)&nbLamps)); - CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 10, sizeof(cl_mem), (void *)&m_dMaterials)); - CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 11, sizeof(cl_mem), (void *)&m_dTextures)); - CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 12, sizeof(cl_mem), (void *)&m_dRandoms)); - CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 13, sizeof(vec4f), (void *)&m_viewPos)); - CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 14, sizeof(vec4f), (void *)&m_viewDir)); - CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 15, sizeof(vec4f), (void *)&m_angles)); - CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 16, sizeof(SceneInfo), (void *)&sceneInfo)); - CHECKSTATUS( - clSetKernelArg(m_kVolumeRenderer, 17, sizeof(PostProcessingInfo), (void *)&m_postProcessingInfo)); - CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 18, sizeof(cl_mem), (void *)&m_dPostProcessingBuffer)); - CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 19, sizeof(cl_mem), (void *)&m_dPrimitivesXYIds)); - CHECKSTATUS(clEnqueueNDRangeKernel(m_hQueue, m_kVolumeRenderer, 2, NULL, szGlobalWorkSize, szLocalWorkSize, - 0, 0, 0)); + CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 0, sizeof(vec2i), + (void *)&m_occupancyParameters)); + CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 1, sizeof(vec1i), + (void *)&zero)); + CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 2, sizeof(vec1i), + (void *)&zero)); + CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 3, sizeof(cl_mem), + (void *)&m_dBoundingBoxes)); + CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 4, sizeof(vec1i), + (void *)&nbBoxes)); + CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 5, sizeof(cl_mem), + (void *)&_dPrimitives)); + CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 6, sizeof(vec1i), + (void *)&nbPrimitives)); + CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 7, sizeof(cl_mem), + (void *)&m_dLightInformation)); + CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 8, sizeof(vec1i), + (void *)&m_lightInformationSize)); + CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 9, sizeof(vec1i), + (void *)&nbLamps)); + CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 10, sizeof(cl_mem), + (void *)&m_dMaterials)); + CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 11, sizeof(cl_mem), + (void *)&m_dTextures)); + CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 12, sizeof(cl_mem), + (void *)&m_dRandoms)); + CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 13, sizeof(vec4f), + (void *)&m_viewPos)); + CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 14, sizeof(vec4f), + (void *)&m_viewDir)); + CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 15, sizeof(vec4f), + (void *)&m_angles)); + CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 16, sizeof(SceneInfo), + (void *)&sceneInfo)); + CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 17, + sizeof(PostProcessingInfo), + (void *)&m_postProcessingInfo)); + CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 18, sizeof(cl_mem), + (void *)&m_dPostProcessingBuffer)); + CHECKSTATUS(clSetKernelArg(m_kVolumeRenderer, 19, sizeof(cl_mem), + (void *)&m_dPrimitivesXYIds)); + CHECKSTATUS(clEnqueueNDRangeKernel(m_hQueue, m_kVolumeRenderer, 2, + NULL, szGlobalWorkSize, + szLocalWorkSize, 0, 0, 0)); break; } default: { - CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 0, sizeof(vec2i), (void *)&m_occupancyParameters)); - CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 1, sizeof(vec1i), (void *)&zero)); - CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 2, sizeof(vec1i), (void *)&zero)); - CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 3, sizeof(cl_mem), (void *)&m_dBoundingBoxes)); - CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 4, sizeof(vec1i), (void *)&nbBoxes)); - CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 5, sizeof(cl_mem), (void *)&_dPrimitives)); - CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 6, sizeof(vec1i), (void *)&nbPrimitives)); - CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 7, sizeof(cl_mem), (void *)&m_dLightInformation)); - CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 8, sizeof(vec1i), (void *)&m_lightInformationSize)); - CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 9, sizeof(vec1i), (void *)&nbLamps)); - CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 10, sizeof(cl_mem), (void *)&m_dMaterials)); - CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 11, sizeof(cl_mem), (void *)&m_dTextures)); - CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 12, sizeof(cl_mem), (void *)&m_dRandoms)); - CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 13, sizeof(vec4f), (void *)&m_viewPos)); - CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 14, sizeof(vec4f), (void *)&m_viewDir)); - CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 15, sizeof(vec4f), (void *)&m_angles)); - CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 16, sizeof(SceneInfo), (void *)&sceneInfo)); - CHECKSTATUS( - clSetKernelArg(m_kStandardRenderer, 17, sizeof(PostProcessingInfo), (void *)&m_postProcessingInfo)); - CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 18, sizeof(cl_mem), (void *)&m_dPostProcessingBuffer)); - CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 19, sizeof(cl_mem), (void *)&m_dPrimitivesXYIds)); - CHECKSTATUS(clEnqueueNDRangeKernel(m_hQueue, m_kStandardRenderer, 2, NULL, szGlobalWorkSize, + CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 0, sizeof(vec2i), + (void *)&m_occupancyParameters)); + CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 1, sizeof(vec1i), + (void *)&zero)); + CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 2, sizeof(vec1i), + (void *)&zero)); + CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 3, sizeof(cl_mem), + (void *)&m_dBoundingBoxes)); + CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 4, sizeof(vec1i), + (void *)&nbBoxes)); + CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 5, sizeof(cl_mem), + (void *)&_dPrimitives)); + CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 6, sizeof(vec1i), + (void *)&nbPrimitives)); + CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 7, sizeof(cl_mem), + (void *)&m_dLightInformation)); + CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 8, sizeof(vec1i), + (void *)&m_lightInformationSize)); + CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 9, sizeof(vec1i), + (void *)&nbLamps)); + CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 10, sizeof(cl_mem), + (void *)&m_dMaterials)); + CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 11, sizeof(cl_mem), + (void *)&m_dTextures)); + CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 12, sizeof(cl_mem), + (void *)&m_dRandoms)); + CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 13, sizeof(vec4f), + (void *)&m_viewPos)); + CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 14, sizeof(vec4f), + (void *)&m_viewDir)); + CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 15, sizeof(vec4f), + (void *)&m_angles)); + CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 16, + sizeof(SceneInfo), (void *)&sceneInfo)); + CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 17, + sizeof(PostProcessingInfo), + (void *)&m_postProcessingInfo)); + CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 18, sizeof(cl_mem), + (void *)&m_dPostProcessingBuffer)); + CHECKSTATUS(clSetKernelArg(m_kStandardRenderer, 19, sizeof(cl_mem), + (void *)&m_dPrimitivesXYIds)); + CHECKSTATUS(clEnqueueNDRangeKernel(m_hQueue, m_kStandardRenderer, 2, + NULL, szGlobalWorkSize, szLocalWorkSize, 0, 0, 0)); break; } @@ -825,58 +987,94 @@ void OpenCLKernel::render_begin(const float timer) switch (m_postProcessingInfo.type) { case ppe_depthOfField: - CHECKSTATUS(clSetKernelArg(m_kDepthOfField, 0, sizeof(vec2i), (void *)&m_occupancyParameters)); - CHECKSTATUS(clSetKernelArg(m_kDepthOfField, 1, sizeof(SceneInfo), (void *)&sceneInfo)); - CHECKSTATUS(clSetKernelArg(m_kDepthOfField, 2, sizeof(PostProcessingInfo), (void *)&m_postProcessingInfo)); - CHECKSTATUS(clSetKernelArg(m_kDepthOfField, 3, sizeof(cl_mem), (void *)&m_dPostProcessingBuffer)); - CHECKSTATUS(clSetKernelArg(m_kDepthOfField, 4, sizeof(cl_mem), (void *)&m_dRandoms)); - CHECKSTATUS(clSetKernelArg(m_kDepthOfField, 5, sizeof(cl_mem), (void *)&m_dBitmap)); - CHECKSTATUS( - clEnqueueNDRangeKernel(m_hQueue, m_kDepthOfField, 2, NULL, szGlobalWorkSize, szLocalWorkSize, 0, 0, 0)); + CHECKSTATUS(clSetKernelArg(m_kDepthOfField, 0, sizeof(vec2i), + (void *)&m_occupancyParameters)); + CHECKSTATUS(clSetKernelArg(m_kDepthOfField, 1, sizeof(SceneInfo), + (void *)&sceneInfo)); + CHECKSTATUS(clSetKernelArg(m_kDepthOfField, 2, + sizeof(PostProcessingInfo), + (void *)&m_postProcessingInfo)); + CHECKSTATUS(clSetKernelArg(m_kDepthOfField, 3, sizeof(cl_mem), + (void *)&m_dPostProcessingBuffer)); + CHECKSTATUS(clSetKernelArg(m_kDepthOfField, 4, sizeof(cl_mem), + (void *)&m_dRandoms)); + CHECKSTATUS(clSetKernelArg(m_kDepthOfField, 5, sizeof(cl_mem), + (void *)&m_dBitmap)); + CHECKSTATUS(clEnqueueNDRangeKernel(m_hQueue, m_kDepthOfField, 2, + NULL, szGlobalWorkSize, + szLocalWorkSize, 0, 0, 0)); break; case ppe_ambientOcclusion: - CHECKSTATUS(clSetKernelArg(m_kAmbientOcclusion, 0, sizeof(vec2i), (void *)&m_occupancyParameters)); - CHECKSTATUS(clSetKernelArg(m_kAmbientOcclusion, 1, sizeof(SceneInfo), (void *)&sceneInfo)); - CHECKSTATUS( - clSetKernelArg(m_kAmbientOcclusion, 2, sizeof(PostProcessingInfo), (void *)&m_postProcessingInfo)); - CHECKSTATUS(clSetKernelArg(m_kAmbientOcclusion, 3, sizeof(cl_mem), (void *)&m_dPostProcessingBuffer)); - CHECKSTATUS(clSetKernelArg(m_kAmbientOcclusion, 4, sizeof(cl_mem), (void *)&m_dRandoms)); - CHECKSTATUS(clSetKernelArg(m_kAmbientOcclusion, 5, sizeof(cl_mem), (void *)&m_dBitmap)); - CHECKSTATUS(clEnqueueNDRangeKernel(m_hQueue, m_kAmbientOcclusion, 2, NULL, szGlobalWorkSize, + CHECKSTATUS(clSetKernelArg(m_kAmbientOcclusion, 0, sizeof(vec2i), + (void *)&m_occupancyParameters)); + CHECKSTATUS(clSetKernelArg(m_kAmbientOcclusion, 1, + sizeof(SceneInfo), (void *)&sceneInfo)); + CHECKSTATUS(clSetKernelArg(m_kAmbientOcclusion, 2, + sizeof(PostProcessingInfo), + (void *)&m_postProcessingInfo)); + CHECKSTATUS(clSetKernelArg(m_kAmbientOcclusion, 3, sizeof(cl_mem), + (void *)&m_dPostProcessingBuffer)); + CHECKSTATUS(clSetKernelArg(m_kAmbientOcclusion, 4, sizeof(cl_mem), + (void *)&m_dRandoms)); + CHECKSTATUS(clSetKernelArg(m_kAmbientOcclusion, 5, sizeof(cl_mem), + (void *)&m_dBitmap)); + CHECKSTATUS(clEnqueueNDRangeKernel(m_hQueue, m_kAmbientOcclusion, 2, + NULL, szGlobalWorkSize, szLocalWorkSize, 0, 0, 0)); break; case ppe_radiosity: - CHECKSTATUS(clSetKernelArg(m_kRadiosity, 0, sizeof(vec2i), (void *)&m_occupancyParameters)); - CHECKSTATUS(clSetKernelArg(m_kRadiosity, 1, sizeof(SceneInfo), (void *)&sceneInfo)); - CHECKSTATUS(clSetKernelArg(m_kRadiosity, 2, sizeof(PostProcessingInfo), (void *)&m_postProcessingInfo)); - CHECKSTATUS(clSetKernelArg(m_kRadiosity, 3, sizeof(cl_mem), (void *)&m_dPrimitivesXYIds)); - CHECKSTATUS(clSetKernelArg(m_kRadiosity, 4, sizeof(cl_mem), (void *)&m_dPostProcessingBuffer)); - CHECKSTATUS(clSetKernelArg(m_kRadiosity, 5, sizeof(cl_mem), (void *)&m_dRandoms)); - CHECKSTATUS(clSetKernelArg(m_kRadiosity, 6, sizeof(cl_mem), (void *)&m_dBitmap)); - CHECKSTATUS( - clEnqueueNDRangeKernel(m_hQueue, m_kRadiosity, 2, NULL, szGlobalWorkSize, szLocalWorkSize, 0, 0, 0)); + CHECKSTATUS(clSetKernelArg(m_kRadiosity, 0, sizeof(vec2i), + (void *)&m_occupancyParameters)); + CHECKSTATUS(clSetKernelArg(m_kRadiosity, 1, sizeof(SceneInfo), + (void *)&sceneInfo)); + CHECKSTATUS(clSetKernelArg(m_kRadiosity, 2, + sizeof(PostProcessingInfo), + (void *)&m_postProcessingInfo)); + CHECKSTATUS(clSetKernelArg(m_kRadiosity, 3, sizeof(cl_mem), + (void *)&m_dPrimitivesXYIds)); + CHECKSTATUS(clSetKernelArg(m_kRadiosity, 4, sizeof(cl_mem), + (void *)&m_dPostProcessingBuffer)); + CHECKSTATUS(clSetKernelArg(m_kRadiosity, 5, sizeof(cl_mem), + (void *)&m_dRandoms)); + CHECKSTATUS(clSetKernelArg(m_kRadiosity, 6, sizeof(cl_mem), + (void *)&m_dBitmap)); + CHECKSTATUS(clEnqueueNDRangeKernel(m_hQueue, m_kRadiosity, 2, NULL, + szGlobalWorkSize, + szLocalWorkSize, 0, 0, 0)); break; case ppe_filter: - CHECKSTATUS(clSetKernelArg(m_kFilter, 0, sizeof(vec2i), (void *)&m_occupancyParameters)); - CHECKSTATUS(clSetKernelArg(m_kFilter, 1, sizeof(SceneInfo), (void *)&sceneInfo)); - CHECKSTATUS(clSetKernelArg(m_kFilter, 2, sizeof(PostProcessingInfo), (void *)&m_postProcessingInfo)); - CHECKSTATUS(clSetKernelArg(m_kFilter, 3, sizeof(cl_mem), (void *)&m_dPostProcessingBuffer)); - CHECKSTATUS(clSetKernelArg(m_kFilter, 4, sizeof(cl_mem), (void *)&m_dBitmap)); - CHECKSTATUS( - clEnqueueNDRangeKernel(m_hQueue, m_kFilter, 2, NULL, szGlobalWorkSize, szLocalWorkSize, 0, 0, 0)); + CHECKSTATUS(clSetKernelArg(m_kFilter, 0, sizeof(vec2i), + (void *)&m_occupancyParameters)); + CHECKSTATUS(clSetKernelArg(m_kFilter, 1, sizeof(SceneInfo), + (void *)&sceneInfo)); + CHECKSTATUS(clSetKernelArg(m_kFilter, 2, sizeof(PostProcessingInfo), + (void *)&m_postProcessingInfo)); + CHECKSTATUS(clSetKernelArg(m_kFilter, 3, sizeof(cl_mem), + (void *)&m_dPostProcessingBuffer)); + CHECKSTATUS(clSetKernelArg(m_kFilter, 4, sizeof(cl_mem), + (void *)&m_dBitmap)); + CHECKSTATUS(clEnqueueNDRangeKernel(m_hQueue, m_kFilter, 2, NULL, + szGlobalWorkSize, + szLocalWorkSize, 0, 0, 0)); break; default: - CHECKSTATUS(clSetKernelArg(m_kDefault, 0, sizeof(vec2i), (void *)&m_occupancyParameters)); - CHECKSTATUS(clSetKernelArg(m_kDefault, 1, sizeof(SceneInfo), (void *)&sceneInfo)); - CHECKSTATUS(clSetKernelArg(m_kDefault, 2, sizeof(cl_mem), (void *)&m_dPostProcessingBuffer)); - CHECKSTATUS(clSetKernelArg(m_kDefault, 3, sizeof(cl_mem), (void *)&m_dBitmap)); - CHECKSTATUS( - clEnqueueNDRangeKernel(m_hQueue, m_kDefault, 2, NULL, szGlobalWorkSize, szLocalWorkSize, 0, 0, 0)); + CHECKSTATUS(clSetKernelArg(m_kDefault, 0, sizeof(vec2i), + (void *)&m_occupancyParameters)); + CHECKSTATUS(clSetKernelArg(m_kDefault, 1, sizeof(SceneInfo), + (void *)&sceneInfo)); + CHECKSTATUS(clSetKernelArg(m_kDefault, 2, sizeof(cl_mem), + (void *)&m_dPostProcessingBuffer)); + CHECKSTATUS(clSetKernelArg(m_kDefault, 3, sizeof(cl_mem), + (void *)&m_dBitmap)); + CHECKSTATUS(clEnqueueNDRangeKernel(m_hQueue, m_kDefault, 2, NULL, + szGlobalWorkSize, + szLocalWorkSize, 0, 0, 0)); break; } LOG_INFO(3, "Post-Processing Kernel done"); } - m_refresh = (m_sceneInfo.pathTracingIteration < m_sceneInfo.maxPathTracingIterations); + m_refresh = (m_sceneInfo.pathTracingIteration < + m_sceneInfo.maxPathTracingIterations); } void OpenCLKernel::render_end() @@ -884,18 +1082,25 @@ void OpenCLKernel::render_end() // ------------------------------------------------------------ // Read back the results // ------------------------------------------------------------ - size_t size = m_sceneInfo.size.x * m_sceneInfo.size.y * sizeof(BitmapBuffer) * gColorDepth; - LOG_INFO(3, m_hQueue << ", " << m_dBitmap << ", " << m_bitmap << " - Bitmap Size=" << size); - CHECKSTATUS(clEnqueueReadBuffer(m_hQueue, m_dBitmap, CL_TRUE, 0, size, m_bitmap, 0, NULL, NULL)); - size = m_sceneInfo.size.x * m_sceneInfo.size.y * sizeof(PrimitiveXYIdBuffer); + size_t size = m_sceneInfo.size.x * m_sceneInfo.size.y * + sizeof(BitmapBuffer) * gColorDepth; + LOG_INFO(3, m_hQueue << ", " << m_dBitmap << ", " << m_bitmap + << " - Bitmap Size=" << size); + CHECKSTATUS(clEnqueueReadBuffer(m_hQueue, m_dBitmap, CL_TRUE, 0, size, + m_bitmap, 0, NULL, NULL)); + size = + m_sceneInfo.size.x * m_sceneInfo.size.y * sizeof(PrimitiveXYIdBuffer); LOG_INFO(3, "PrimitivesID Size=" << size); - CHECKSTATUS(clEnqueueReadBuffer(m_hQueue, m_dPrimitivesXYIds, CL_TRUE, 0, size, m_hPrimitivesXYIds, 0, NULL, NULL)); + CHECKSTATUS(clEnqueueReadBuffer(m_hQueue, m_dPrimitivesXYIds, CL_TRUE, 0, + size, m_hPrimitivesXYIds, 0, NULL, NULL)); LOG_INFO(3, "Flushing queues"); CHECKSTATUS(clFlush(m_hQueue)); CHECKSTATUS(clFinish(m_hQueue)); #ifdef WIN32 - if (m_sceneInfo.pathTracingIteration == m_sceneInfo.maxPathTracingIterations - 1) - LOG_INFO(1, "Rendering completed in " << GetTickCount() - m_counter << " ms"); + if (m_sceneInfo.pathTracingIteration == + m_sceneInfo.maxPathTracingIterations - 1) + LOG_INFO(1, "Rendering completed in " << GetTickCount() - m_counter + << " ms"); #endif if (m_sceneInfo.frameBufferType == 0) @@ -905,15 +1110,16 @@ void OpenCLKernel::render_end() //::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); //::glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); - ::glTexImage2D(GL_TEXTURE_2D, 0, gColorDepth, m_sceneInfo.size.x, m_sceneInfo.size.y, 0, GL_RGB, - GL_UNSIGNED_BYTE, m_bitmap); + ::glTexImage2D(GL_TEXTURE_2D, 0, gColorDepth, m_sceneInfo.size.x, + m_sceneInfo.size.y, 0, GL_RGB, GL_UNSIGNED_BYTE, + m_bitmap); if (m_sceneInfo.cameraType == ctVR) { float step = 0.1f; float halfStep = 1.f; float scale = 2.f; - + for (int a(0); a < 2; ++a) { cl_float2 center = {{0.f, 0.f}}; @@ -928,10 +1134,14 @@ void OpenCLKernel::render_end() s.x = scale; s.y = scale; - cl_float2 p0 = {{s.x * x - halfStep, s.y * y - halfStep}}; - cl_float2 p1 = {{s.x * (x + step) - halfStep, s.y * y - halfStep}}; - cl_float2 p2 = {{s.x * (x + step) - halfStep, s.y * (y + step) - halfStep}}; - cl_float2 p3 = {{s.x * x - halfStep, s.y * (y + step) - halfStep}}; + cl_float2 p0 = { + {s.x * x - halfStep, s.y * y - halfStep}}; + cl_float2 p1 = { + {s.x * (x + step) - halfStep, s.y * y - halfStep}}; + cl_float2 p2 = {{s.x * (x + step) - halfStep, + s.y * (y + step) - halfStep}}; + cl_float2 p3 = { + {s.x * x - halfStep, s.y * (y + step) - halfStep}}; float d0 = sqrt(pow(p0.x, 2) + pow(p0.y, 2)); float d1 = sqrt(pow(p1.x, 2) + pow(p1.y, 2)); @@ -945,16 +1155,20 @@ void OpenCLKernel::render_end() ::glBegin(GL_QUADS); ::glTexCoord2f(1.f - (b + (x / 2.f)), y); - ::glVertex3f(center.x + 0.5f * p0.x * d0, center.y + p0.y * d0, 0.f); + ::glVertex3f(center.x + 0.5f * p0.x * d0, + center.y + p0.y * d0, 0.f); ::glTexCoord2f(1.f - (b + (x + step) / 2.f), y); - ::glVertex3f(center.x + 0.5f * p1.x * d1, center.y + p1.y * d1, 0.f); + ::glVertex3f(center.x + 0.5f * p1.x * d1, + center.y + p1.y * d1, 0.f); ::glTexCoord2f(1.f - (b + (x + step) / 2.f), y + step); - ::glVertex3f(center.x + 0.5f * p2.x * d2, center.y + p2.y * d2, 0.f); + ::glVertex3f(center.x + 0.5f * p2.x * d2, + center.y + p2.y * d2, 0.f); ::glTexCoord2f(1.f - (b + (x / 2.f)), y + step); - ::glVertex3f(center.x + 0.5f * p3.x * d3, center.y + p3.y * d3, 0.f); + ::glVertex3f(center.x + 0.5f * p3.x * d3, + center.y + p3.y * d3, 0.f); ::glEnd(); } } @@ -1017,13 +1231,21 @@ void OpenCLKernel::reshape() CHECKSTATUS(clReleaseMemObject(m_dBitmap)); int errorCode; - m_dBitmap = clCreateBuffer(m_hContext, CL_MEM_READ_WRITE, MAX_BITMAP_SIZE * sizeof(BitmapBuffer) * gColorDepth, 0, - &errorCode); - m_dRandoms = clCreateBuffer(m_hContext, CL_MEM_READ_ONLY, MAX_BITMAP_SIZE * sizeof(RandomBuffer), 0, &errorCode); + m_dBitmap = + clCreateBuffer(m_hContext, CL_MEM_READ_WRITE, + MAX_BITMAP_SIZE * sizeof(BitmapBuffer) * gColorDepth, 0, + &errorCode); + m_dRandoms = + clCreateBuffer(m_hContext, CL_MEM_READ_ONLY, + MAX_BITMAP_SIZE * sizeof(RandomBuffer), 0, &errorCode); m_dPostProcessingBuffer = - clCreateBuffer(m_hContext, CL_MEM_READ_WRITE, MAX_BITMAP_SIZE * sizeof(PostProcessingBuffer), 0, &errorCode); + clCreateBuffer(m_hContext, CL_MEM_READ_WRITE, + MAX_BITMAP_SIZE * sizeof(PostProcessingBuffer), 0, + &errorCode); m_dPrimitivesXYIds = - clCreateBuffer(m_hContext, CL_MEM_READ_WRITE, MAX_BITMAP_SIZE * sizeof(PrimitiveXYIdBuffer), 0, &errorCode); + clCreateBuffer(m_hContext, CL_MEM_READ_WRITE, + MAX_BITMAP_SIZE * sizeof(PrimitiveXYIdBuffer), 0, + &errorCode); } int OpenCLKernel::getNumPlatforms() @@ -1041,7 +1263,8 @@ std::string OpenCLKernel::getPlatformDescription(const int platform) return m_platformsDescription[platform]; } -std::string OpenCLKernel::getDeviceDescription(const int platform, const int device) +std::string OpenCLKernel::getDeviceDescription(const int platform, + const int device) { return m_devicesDescription[platform][device]; } @@ -1056,7 +1279,8 @@ void OpenCLKernel::queryDevice() size_t len; std::stringstream s; - CHECKSTATUS(clGetPlatformIDs(MAX_PLATFORMS, m_platforms, &m_numberOfPlatforms)); + CHECKSTATUS( + clGetPlatformIDs(MAX_PLATFORMS, m_platforms, &m_numberOfPlatforms)); LOG_INFO(1, "Number of platforms detected: " << m_numberOfPlatforms); for (cl_uint platform(0); platform < m_numberOfPlatforms; ++platform) @@ -1065,62 +1289,78 @@ void OpenCLKernel::queryDevice() std::string platformDescription; LOG_INFO(1, "Platform " << platform); - CHECKSTATUS(clGetPlatformInfo(m_platforms[platform], CL_PLATFORM_NAME, MAX_SOURCE_SIZE, buffer, &len)); + CHECKSTATUS(clGetPlatformInfo(m_platforms[platform], CL_PLATFORM_NAME, + MAX_SOURCE_SIZE, buffer, &len)); buffer[len] = 0; LOG_INFO(1, " Name..............: " << buffer); platformDescription = buffer; - CHECKSTATUS(clGetPlatformInfo(m_platforms[platform], CL_PLATFORM_VERSION, MAX_SOURCE_SIZE, buffer, &len)); + CHECKSTATUS(clGetPlatformInfo(m_platforms[platform], + CL_PLATFORM_VERSION, MAX_SOURCE_SIZE, + buffer, &len)); buffer[len] = 0; LOG_INFO(1, " Version...........: " << buffer); platformDescription += " ("; platformDescription += buffer; - CHECKSTATUS(clGetPlatformInfo(m_platforms[platform], CL_PLATFORM_VENDOR, MAX_SOURCE_SIZE, buffer, &len)); + CHECKSTATUS(clGetPlatformInfo(m_platforms[platform], CL_PLATFORM_VENDOR, + MAX_SOURCE_SIZE, buffer, &len)); buffer[len] = 0; LOG_INFO(1, " Vendor............: " << buffer); platformDescription += ", "; platformDescription += buffer; platformDescription += ")"; - CHECKSTATUS(clGetPlatformInfo(m_platforms[platform], CL_PLATFORM_PROFILE, MAX_SOURCE_SIZE, buffer, &len)); + CHECKSTATUS(clGetPlatformInfo(m_platforms[platform], + CL_PLATFORM_PROFILE, MAX_SOURCE_SIZE, + buffer, &len)); buffer[len] = 0; LOG_INFO(1, " Profile...........: " << buffer); - CHECKSTATUS(clGetPlatformInfo(m_platforms[platform], CL_PLATFORM_EXTENSIONS, MAX_SOURCE_SIZE, buffer, &len)); + CHECKSTATUS(clGetPlatformInfo(m_platforms[platform], + CL_PLATFORM_EXTENSIONS, MAX_SOURCE_SIZE, + buffer, &len)); buffer[len] = 0; LOG_INFO(3, " Extensions........: " << buffer); m_platformsDescription[platform] = platformDescription; - if (clGetDeviceIDs(m_platforms[platform], CL_DEVICE_TYPE_ALL, MAX_DEVICES, m_devices[platform], + if (clGetDeviceIDs(m_platforms[platform], CL_DEVICE_TYPE_ALL, + MAX_DEVICES, m_devices[platform], &m_numberOfDevices[platform]) == CL_SUCCESS) { // m_devices - for (cl_uint device = 0; device < m_numberOfDevices[platform]; ++device) + for (cl_uint device = 0; device < m_numberOfDevices[platform]; + ++device) { LOG_INFO(1, " --------------------------------------"); - LOG_INFO(1, " Device " << device << " id=" << m_devices[platform][device]); + LOG_INFO(1, " Device " << device << " id=" + << m_devices[platform][device]); LOG_INFO(1, " --------------------------------------"); std::string deviceDescription; - CHECKSTATUS(clGetDeviceInfo(m_devices[platform][device], CL_DEVICE_NAME, sizeof(buffer), buffer, NULL)); + CHECKSTATUS(clGetDeviceInfo(m_devices[platform][device], + CL_DEVICE_NAME, sizeof(buffer), + buffer, NULL)); LOG_INFO(1, " Name............: " << buffer); deviceDescription = buffer; - CHECKSTATUS( - clGetDeviceInfo(m_devices[platform][device], CL_DEVICE_VENDOR, sizeof(buffer), buffer, NULL)); + CHECKSTATUS(clGetDeviceInfo(m_devices[platform][device], + CL_DEVICE_VENDOR, sizeof(buffer), + buffer, NULL)); LOG_INFO(1, " Vendor..........: " << buffer); deviceDescription += " ("; deviceDescription += buffer; - CHECKSTATUS( - clGetDeviceInfo(m_devices[platform][device], CL_DEVICE_VERSION, sizeof(buffer), buffer, NULL)); + CHECKSTATUS(clGetDeviceInfo(m_devices[platform][device], + CL_DEVICE_VERSION, sizeof(buffer), + buffer, NULL)); LOG_INFO(1, " Version.........: " << buffer); deviceDescription += ", "; deviceDescription += buffer; - CHECKSTATUS( - clGetDeviceInfo(m_devices[platform][device], CL_DRIVER_VERSION, sizeof(buffer), buffer, NULL)); + CHECKSTATUS(clGetDeviceInfo(m_devices[platform][device], + CL_DRIVER_VERSION, sizeof(buffer), + buffer, NULL)); LOG_INFO(1, " Driver version..: " << buffer); deviceDescription += ", "; deviceDescription += buffer; @@ -1130,22 +1370,29 @@ void OpenCLKernel::queryDevice() cl_uint value; cl_uint values[10]; - CHECKSTATUS(clGetDeviceInfo(m_devices[platform][device], CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(value), - &value, NULL)); + CHECKSTATUS(clGetDeviceInfo(m_devices[platform][device], + CL_DEVICE_MAX_COMPUTE_UNITS, + sizeof(value), &value, NULL)); LOG_INFO(3, " Compute units...: " << value); - CHECKSTATUS(clGetDeviceInfo(m_devices[platform][device], CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, + CHECKSTATUS(clGetDeviceInfo(m_devices[platform][device], + CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, sizeof(value), &value, NULL)); LOG_INFO(3, " Work item dims..: " << value); - CHECKSTATUS(clGetDeviceInfo(m_devices[platform][device], CL_DEVICE_MAX_WORK_ITEM_SIZES, sizeof(values), - &values, NULL)); - LOG_INFO(3, " Work item size..: " << values[0] << ", " << values[1] << ", " << values[2]); - CHECKSTATUS(clGetDeviceInfo(m_devices[platform][device], CL_DEVICE_MAX_CLOCK_FREQUENCY, sizeof(value), - &value, NULL)); + CHECKSTATUS(clGetDeviceInfo(m_devices[platform][device], + CL_DEVICE_MAX_WORK_ITEM_SIZES, + sizeof(values), &values, NULL)); + LOG_INFO(3, " Work item size..: " << values[0] << ", " + << values[1] << ", " + << values[2]); + CHECKSTATUS(clGetDeviceInfo(m_devices[platform][device], + CL_DEVICE_MAX_CLOCK_FREQUENCY, + sizeof(value), &value, NULL)); LOG_INFO(1, " Clock frequency.: " << value << " Hz"); cl_device_type infoType; - CHECKSTATUS( - clGetDeviceInfo(m_devices[platform][device], CL_DEVICE_TYPE, sizeof(infoType), &infoType, NULL)); + CHECKSTATUS(clGetDeviceInfo(m_devices[platform][device], + CL_DEVICE_TYPE, sizeof(infoType), + &infoType, NULL)); if (infoType & CL_DEVICE_TYPE_DEFAULT) { infoType &= ~CL_DEVICE_TYPE_DEFAULT; @@ -1195,4 +1442,4 @@ void OpenCLKernel::queryDevice() LOG_INFO(3, "- PostProcessingInfo: " << sizeof(PostProcessingInfo)); LOG_INFO(3, "_______________________________________|"); } -} +} // namespace solr diff --git a/solr/engines/opencl/OpenCLKernel.h b/solr/engines/opencl/OpenCLKernel.h index 77dd5ad..47e4d34 100644 --- a/solr/engines/opencl/OpenCLKernel.h +++ b/solr/engines/opencl/OpenCLKernel.h @@ -1,27 +1,23 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once -#include "types.h" -#include +#include "../GPUKernel.h" #ifdef WIN32 #include @@ -56,7 +52,10 @@ class SOLR_API OpenCLKernel : public GPUKernel virtual void setPlatformId(const int platform) { m_platform = platform; } virtual void setDeviceId(const int device) { m_device = device; } - virtual void setKernelFilename(const std::string &kernelFilename) { m_kernelFilename = kernelFilename; } + virtual void setKernelFilename(const std::string &kernelFilename) + { + m_kernelFilename = kernelFilename; + } public: // ---------- Devices ---------- @@ -80,7 +79,8 @@ class SOLR_API OpenCLKernel : public GPUKernel static int getNumPlatforms(); static std::string getPlatformDescription(const int platform); static int getNumDevices(const int platform); - static std::string getDeviceDescription(const int platform, const int device); + static std::string getDeviceDescription(const int platform, + const int device); private: // Platforms @@ -140,4 +140,4 @@ class SOLR_API OpenCLKernel : public GPUKernel cl_mem m_dDepth; #endif // KINECT }; -} +} // namespace solr diff --git a/solr/engines/opencl/RayTracer.cl b/solr/engines/opencl/RayTracer.cl index 04492cd..f48fbba 100644 --- a/solr/engines/opencl/RayTracer.cl +++ b/solr/engines/opencl/RayTracer.cl @@ -1,26 +1,24 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau - * - * This file is part of Sol-R +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ // IMPORTANT #ifdef MSVC -#define ALIGNMENT __attribute__((packed)) // This is apparently required on Windows... +#define ALIGNMENT \ + __attribute__((packed)) // This is apparently required on Windows... #else #define ALIGNMENT #endif @@ -67,7 +65,7 @@ typedef struct #define MAX_BITMAP_HEIGHT 1080 #define MAX_BITMAP_SIZE 2073600 // 1920x1080 -#define STANDARD_LUNINANCE_STRENGTH 0.6f +#define MATERIAL_DEFAULT_EMMISION_STRENGTH 0.6f #define SKYBOX_LUNINANCE_STRENGTH 0.4f enum FrameBufferType @@ -113,39 +111,45 @@ enum AtmosphericEffect // Scene information typedef struct ALIGNMENT { - int2 size; // Image size - enum CameraType cameraType; // Camera type( Perspective, Orthographic, Antialiazed, Volume Rendering ) - enum GraphicsLevel graphicsLevel; // Graphics level( No Shading=0, Lambert=1, Specular=2, Reflections and - // Refractions=3, Shadows=4 ) - int nbRayIterations; // Maximum number of ray iterations for current frame - float transparentColor; // Value above which r+g+b color is considered as transparent - float viewDistance; // Maximum viewing distance - float shadowIntensity; // Shadow intensity( off=0, pitch black=1) - float eyeSeparation; // 3D: Distance between both eyes - int renderBoxes; // Activate bounding box rendering( off=0, on=1 ); - int pathTracingIteration; // Current iteration for current frame - int maxPathTracingIterations; // Maximum number of iterations for current frame + int2 size; // Image size + enum CameraType cameraType; // Camera type( Perspective, Orthographic, + // Antialiazed, Volume Rendering ) + enum GraphicsLevel graphicsLevel; // Graphics level( No Shading=0, + // Lambert=1, Specular=2, Reflections and + // Refractions=3, Shadows=4 ) + int nbRayIterations; // Maximum number of ray iterations for current frame + float transparentColor; // Value above which r+g+b color is considered as + // transparent + float viewDistance; // Maximum viewing distance + float shadowIntensity; // Shadow intensity( off=0, pitch black=1) + float eyeSeparation; // 3D: Distance between both eyes + int renderBoxes; // Activate bounding box rendering( off=0, on=1 ); + int pathTracingIteration; // Current iteration for current frame + int maxPathTracingIterations; // Maximum number of iterations for current + // frame enum FrameBufferType frameBufferType; // Frame buffer type( RGB or BGR ) int timestamp; // Timestamp for the scene enum AtmosphericEffect atmosphericEffect; // Fog, etc int doubleSidedTriangles; // Use double-sided triangles int extendedGeometry; // Use extended geometry - enum AdvancedIllumination advancedIllumination; // Advanced features (Global illumination, random lightning, - // etc) - int draftMode; // Draft mode when camera in motion - int skyboxRadius; // Skybox sphere radius - int skyboxMaterialId; // Skybox material Id - int gradientBackground; // Gradient background - float geometryEpsilon; // Geometry epsilon - float rayEpsilon; // Ray epsilon - float4 backgroundColor; // Background color + enum AdvancedIllumination advancedIllumination; // Advanced features (Global + // illumination, random + // lightning, etc) + int draftMode; // Draft mode when camera in motion + int skyboxRadius; // Skybox sphere radius + int skyboxMaterialId; // Skybox material Id + int gradientBackground; // Gradient background + float geometryEpsilon; // Geometry epsilon + float rayEpsilon; // Ray epsilon + float4 backgroundColor; // Background color } SceneInfo; typedef struct ALIGNMENT { float4 origin; // Origin of the ray float4 direction; // Direction of the ray - float4 inv_direction; // Inverted direction( Used for optimal Ray-Box intersection ) + float4 inv_direction; // Inverted direction( Used for optimal Ray-Box + // intersection ) int4 signs; // Signs ( Used for optimal Ray-Box intersection ) } Ray; @@ -185,12 +189,14 @@ typedef struct ALIGNMENT // y: Power // z: // w: - float reflection; // Reflection rate( No reflection=0 -> Full reflection=1 ) - float refraction; // Refraction index( ex: glass=1.33 ) + float reflection; // Reflection rate( No reflection=0 -> Full reflection=1 ) + float refraction; // Refraction index( ex: glass=1.33 ) float transparency; // Transparency rate( Opaque=0 -> Full transparency=1 ) float opacity; // Opacity strength - int4 attributes; // x: Fast transparency( off=0, on=1 ). Fast transparency produces no shadows - // and drops intersections if rays intersects primitive with the same material ID + int4 attributes; // x: Fast transparency( off=0, on=1 ). Fast transparency + // produces no shadows + // and drops intersections if rays intersects primitive with the same + // material ID // y: Procedural textures( off=0, on=1 ) // z: Wireframe( off=0, on=1 ). Wire frame produces no shading // w: Wireframe Width @@ -214,7 +220,8 @@ typedef struct ALIGNMENT // y: Transparency map // z: Ambient Occulsion map // w: not used - float2 mappingOffset; // Texture mapping offsets based on sceneInfo.timestamp + float2 mappingOffset; // Texture mapping offsets based on + // sceneInfo.timestamp } Material; typedef struct ALIGNMENT @@ -222,7 +229,8 @@ typedef struct ALIGNMENT float4 parameters[2]; // Bottom-Left and Top-Right corners int nbPrimitives; // Number of primitives in the box int startIndex; // Index of the first primitive in the box - int2 indexForNextBox; // If no intersection, how many of the following boxes can be skipped? + int2 indexForNextBox; // If no intersection, how many of the following boxes + // can be skipped? } BoundingBox; typedef struct ALIGNMENT @@ -263,7 +271,8 @@ enum TextureType typedef struct ALIGNMENT { unsigned char* buffer; // Pointer to the texture - int offset; // Offset of the texture in the global texture buffer (the one that will be transfered to the GPU) + int offset; // Offset of the texture in the global texture buffer (the one + // that will be transfered to the GPU) int3 size; // Size of the texture enum TextureType type; } TextureInfo; @@ -319,7 +328,8 @@ n1 : index of refraction of original medium n2 : index of refraction of new medium ________________________________________________________________________________ */ -static void vectorRefraction(float4* refracted, const float4 incident, const float n1, const float4 normal, +static void vectorRefraction(float4* refracted, const float4 incident, + const float n1, const float4 normal, const float n2) { (*refracted) = incident; @@ -340,7 +350,8 @@ __c : Center of rotations __a : Angles ________________________________________________________________________________ */ -static void vectorRotation(float4* vector, const float4 center, const float4 angles) +static void vectorRotation(float4* vector, const float4 center, + const float4 angles) { float4 __r = (*vector); /* X axis */ @@ -362,9 +373,12 @@ ________________________________________________________________________________ */ static void computeRayAttributes(Ray* ray) { - (*ray).inv_direction.x = ((*ray).direction.x != 0.f) ? 1.f / (*ray).direction.x : 0.f; - (*ray).inv_direction.y = ((*ray).direction.y != 0.f) ? 1.f / (*ray).direction.y : 0.f; - (*ray).inv_direction.z = ((*ray).direction.z != 0.f) ? 1.f / (*ray).direction.z : 0.f; + (*ray).inv_direction.x = + ((*ray).direction.x != 0.f) ? 1.f / (*ray).direction.x : 0.f; + (*ray).inv_direction.y = + ((*ray).direction.y != 0.f) ? 1.f / (*ray).direction.y : 0.f; + (*ray).inv_direction.z = + ((*ray).direction.z != 0.f) ? 1.f / (*ray).direction.z : 0.f; (*ray).signs.x = ((*ray).inv_direction.x < 0); (*ray).signs.y = ((*ray).inv_direction.y < 0); (*ray).signs.z = ((*ray).inv_direction.z < 0); @@ -376,7 +390,8 @@ ________________________________________________________________________________ Convert float4 into OpenGL RGB color ________________________________________________________________________________ */ -static void makeColor(const SceneInfo* sceneInfo, const float4* color, CONST BitmapBuffer* bitmap, int index) +static void makeColor(const SceneInfo* sceneInfo, const float4* color, + CONST BitmapBuffer* bitmap, int index) { (*color).x = ((*color).x > 1.f) ? 1.f : (*color).x; (*color).y = ((*color).y > 1.f) ? 1.f : (*color).y; @@ -388,26 +403,26 @@ static void makeColor(const SceneInfo* sceneInfo, const float4* color, CONST Bit int mdc_index = index * gColorDepth; switch ((*sceneInfo).frameBufferType) { - case fbBGR: - { - // Delphi - int y = index / (*sceneInfo).size.y; - int x = index % (*sceneInfo).size.x; - int i = (y + 1) * (*sceneInfo).size.y - x - 1; - i *= gColorDepth; - bitmap[i] = (BitmapBuffer)((*color).z * 255.f); // Blue - bitmap[i + 1] = (BitmapBuffer)((*color).y * 255.f); // Green - bitmap[i + 2] = (BitmapBuffer)((*color).x * 255.f); // Red - break; - } - default: - { - // OpenGL - bitmap[mdc_index] = (BitmapBuffer)((*color).x * 255.f); // Red - bitmap[mdc_index + 1] = (BitmapBuffer)((*color).y * 255.f); // Green - bitmap[mdc_index + 2] = (BitmapBuffer)((*color).z * 255.f); // Blue - break; - } + case fbBGR: + { + // Delphi + int y = index / (*sceneInfo).size.y; + int x = index % (*sceneInfo).size.x; + int i = (y + 1) * (*sceneInfo).size.y - x - 1; + i *= gColorDepth; + bitmap[i] = (BitmapBuffer)((*color).z * 255.f); // Blue + bitmap[i + 1] = (BitmapBuffer)((*color).y * 255.f); // Green + bitmap[i + 2] = (BitmapBuffer)((*color).x * 255.f); // Red + break; + } + default: + { + // OpenGL + bitmap[mdc_index] = (BitmapBuffer)((*color).x * 255.f); // Red + bitmap[mdc_index + 1] = (BitmapBuffer)((*color).y * 255.f); // Green + bitmap[mdc_index + 2] = (BitmapBuffer)((*color).z * 255.f); // Blue + break; + } } } @@ -417,18 +432,21 @@ ________________________________________________________________________________ Mandelbrot Set ________________________________________________________________________________ */ -static void juliaSet(CONST Primitive* primitive, CONST Material* materials, const SceneInfo* sceneInfo, const float x, - const float y, float4* color) +static void juliaSet(CONST Primitive* primitive, CONST Material* materials, + const SceneInfo* sceneInfo, const float x, const float y, + float4* color) { CONST Material* material = &materials[(*primitive).materialId]; float W = (float)(*material).textureMapping.x; float H = (float)(*material).textureMapping.y; - // pick some values for the constant c, this determines the shape of the Julia Set + // pick some values for the constant c, this determines the shape of the + // Julia Set float cRe = -0.7f + 0.4f * sin((*sceneInfo).timestamp / 1500.f); float cIm = 0.27015f + 0.4f * cos((*sceneInfo).timestamp / 2000.f); - // calculate the initial real and imaginary part of z, based on the pixel location and zoom and position values + // calculate the initial real and imaginary part of z, based on the pixel + // location and zoom and position values float newRe = 1.5f * (x - W / 2.f) / (0.5f * W); float newIm = (y - H / 2.f) / (0.5f * H); // i will represent the number of iterations @@ -447,9 +465,8 @@ static void juliaSet(CONST Primitive* primitive, CONST Material* materials, cons if ((newRe * newRe + newIm * newIm) > 4.f) break; } - // use color model conversion to get rainbow palette, make brightness black if maxIterations reached - // color.x += newRe/4.f; - // color.z += newIm/4.f; + // use color model conversion to get rainbow palette, make brightness black + // if maxIterations reached color.x += newRe/4.f; color.z += newIm/4.f; (*color).x = 1.f - (*color).x * (n / maxIterations); (*color).y = 1.f - (*color).y * (n / maxIterations); (*color).z = 1.f - (*color).z * (n / maxIterations); @@ -462,8 +479,9 @@ ________________________________________________________________________________ Mandelbrot Set ________________________________________________________________________________ */ -static void mandelbrotSet(CONST Primitive* primitive, CONST Material* materials, const SceneInfo* sceneInfo, - const float x, const float y, float4* color) +static void mandelbrotSet(CONST Primitive* primitive, CONST Material* materials, + const SceneInfo* sceneInfo, const float x, + const float y, float4* color) { CONST Material* material = &materials[(*primitive).materialId]; float W = (float)(*material).textureMapping.x; @@ -502,7 +520,8 @@ static void mandelbrotSet(CONST Primitive* primitive, CONST Material* materials, // ---------- // Normal mapping // -------------------- -static void normalMap(const int index, CONST Material* material, CONST BitmapBuffer* textures, float4* normal, +static void normalMap(const int index, CONST Material* material, + CONST BitmapBuffer* textures, float4* normal, const float strength) { int i = (*material).textureOffset.y + index; @@ -516,7 +535,8 @@ static void normalMap(const int index, CONST Material* material, CONST BitmapBuf // ---------- // Bump mapping // -------------------- -static void bumpMap(const int index, CONST Material* material, CONST BitmapBuffer* textures, float4* intersection, +static void bumpMap(const int index, CONST Material* material, + CONST BitmapBuffer* textures, float4* intersection, float* value) { int i = (*material).textureOffset.z + index; @@ -530,7 +550,8 @@ static void bumpMap(const int index, CONST Material* material, CONST BitmapBuffe // ---------- // Specular mapping // -------------------- -static void specularMap(const int index, CONST Material* material, CONST BitmapBuffer* textures, float4* specular) +static void specularMap(const int index, CONST Material* material, + CONST BitmapBuffer* textures, float4* specular) { int i = (*material).textureOffset.w + index; BitmapBuffer r, g, b; @@ -543,7 +564,8 @@ static void specularMap(const int index, CONST Material* material, CONST BitmapB // ---------- // Reflection mapping // -------------------- -static void reflectionMap(const int index, CONST Material* material, CONST BitmapBuffer* textures, float4* attributes) +static void reflectionMap(const int index, CONST Material* material, + CONST BitmapBuffer* textures, float4* attributes) { int i = (*material).advancedTextureOffset.x + index; BitmapBuffer r, g, b; @@ -556,7 +578,8 @@ static void reflectionMap(const int index, CONST Material* material, CONST Bitma // ---------- // Transparency mapping // -------------------- -static void transparencyMap(const int index, CONST Material* material, CONST BitmapBuffer* textures, float4* attributes) +static void transparencyMap(const int index, CONST Material* material, + CONST BitmapBuffer* textures, float4* attributes) { int i = (*material).advancedTextureOffset.y + index; BitmapBuffer r, g, b; @@ -570,7 +593,8 @@ static void transparencyMap(const int index, CONST Material* material, CONST Bit // ---------- // Ambient occlusion // -------------------- -static void ambientOcclusionMap(const int index, CONST Material* material, CONST BitmapBuffer* textures, +static void ambientOcclusionMap(const int index, CONST Material* material, + CONST BitmapBuffer* textures, float4* advancedAttributes) { int i = (*material).advancedTextureOffset.z + index; @@ -587,8 +611,11 @@ ________________________________________________________________________________ Sphere texture Mapping ________________________________________________________________________________ */ -static float4 sphereUVMapping(CONST Primitive* primitive, CONST Material* materials, CONST BitmapBuffer* textures, - float4* intersection, float4* normal, float4* specular, float4* attributes, +static float4 sphereUVMapping(CONST Primitive* primitive, + CONST Material* materials, + CONST BitmapBuffer* textures, + float4* intersection, float4* normal, + float4* specular, float4* attributes, float4* advancedAttributes) { CONST Material* material = &materials[(*primitive).materialId]; @@ -604,12 +631,14 @@ static float4 sphereUVMapping(CONST Primitive* primitive, CONST Material* materi u %= (*material).textureMapping.x; if ((*material).textureMapping.y != 0) v %= (*material).textureMapping.y; - const bool condition = - u >= 0 && u < (*material).textureMapping.x && v >= 0 && v < (*material).textureMapping.y; + const bool condition = u >= 0 && u < (*material).textureMapping.x && + v >= 0 && v < (*material).textureMapping.y; if (condition) { - int A = (v * (*material).textureMapping.x + u) * (*material).textureMapping.w; - int B = (*material).textureMapping.x * (*material).textureMapping.y * (*material).textureMapping.w; + int A = (v * (*material).textureMapping.x + u) * + (*material).textureMapping.w; + int B = (*material).textureMapping.x * (*material).textureMapping.y * + (*material).textureMapping.w; int index = A % B; // Diffuse @@ -651,9 +680,11 @@ ________________________________________________________________________________ Cube texture mapping ________________________________________________________________________________ */ -static float4 cubeMapping(const SceneInfo* sceneInfo, CONST Primitive* primitive, CONST Material* materials, - CONST BitmapBuffer* textures, float4* intersection, float4* normal, float4* specular, - float4* attributes, float4* advancedAttributes) +static float4 cubeMapping(const SceneInfo* sceneInfo, + CONST Primitive* primitive, CONST Material* materials, + CONST BitmapBuffer* textures, float4* intersection, + float4* normal, float4* specular, float4* attributes, + float4* advancedAttributes) { CONST Material* material = &materials[(*primitive).materialId]; float4 result = (*material).color; @@ -661,18 +692,23 @@ static float4 cubeMapping(const SceneInfo* sceneInfo, CONST Primitive* primitive #ifdef USE_KINECT if (primitive.type.x == ptCamera) { - int x = ((*intersection).x - (*primitive).p0.x + (*primitive).size.x) * material.textureMapping.x; + int x = ((*intersection).x - (*primitive).p0.x + (*primitive).size.x) * + material.textureMapping.x; int y = KINECT_COLOR_HEIGHT - - ((*intersection).y - (*primitive).p0.y + (*primitive).size.y) * material.textureMapping.y; + ((*intersection).y - (*primitive).p0.y + (*primitive).size.y) * + material.textureMapping.y; x = (x + KINECT_COLOR_WIDTH) % KINECT_COLOR_WIDTH; y = (y + KINECT_COLOR_HEIGHT) % KINECT_COLOR_HEIGHT; - const bool condition = x >= 0 && x < KINECT_COLOR_WIDTH && y >= 0 && y < KINECT_COLOR_HEIGHT; + const bool condition = x >= 0 && x < KINECT_COLOR_WIDTH && y >= 0 && + y < KINECT_COLOR_HEIGHT; if (condition) { int index = (y * KINECT_COLOR_WIDTH + x) * KINECT_COLOR_DEPTH; - index = index % (material.textureMapping.x * material.textureMapping.y * material.textureMapping.w); + index = + index % (material.textureMapping.x * material.textureMapping.y * + material.textureMapping.w); BitmapBuffer r = textures[index + 2]; BitmapBuffer g = textures[index + 1]; BitmapBuffer b = textures[index + 0]; @@ -684,21 +720,26 @@ static float4 cubeMapping(const SceneInfo* sceneInfo, CONST Primitive* primitive else #endif // USE_KINECT { - int u = (((*primitive).type == ptCheckboard) || ((*primitive).type == ptXZPlane) || - ((*primitive).type == ptXYPlane)) - ? ((*intersection).x - (*primitive).p0.x + (*primitive).size.x) - : ((*intersection).z - (*primitive).p0.z + (*primitive).size.z); - - int v = (((*primitive).type == ptCheckboard) || ((*primitive).type == ptXZPlane)) - ? ((*intersection).z + (*primitive).p0.z + (*primitive).size.z) - : ((*intersection).y - (*primitive).p0.y + (*primitive).size.y); + int u = + (((*primitive).type == ptCheckboard) || + ((*primitive).type == ptXZPlane) || + ((*primitive).type == ptXYPlane)) + ? ((*intersection).x - (*primitive).p0.x + (*primitive).size.x) + : ((*intersection).z - (*primitive).p0.z + (*primitive).size.z); + + int v = + (((*primitive).type == ptCheckboard) || + ((*primitive).type == ptXZPlane)) + ? ((*intersection).z + (*primitive).p0.z + (*primitive).size.z) + : ((*intersection).y - (*primitive).p0.y + (*primitive).size.y); if ((*material).textureMapping.x != 0) u = u % (*material).textureMapping.x; if ((*material).textureMapping.y != 0) v = v % (*material).textureMapping.y; - if (u >= 0 && u < (*material).textureMapping.x && v >= 0 && v < (*material).textureMapping.x) + if (u >= 0 && u < (*material).textureMapping.x && v >= 0 && + v < (*material).textureMapping.x) { switch ((*material).textureIds.x) { @@ -710,8 +751,11 @@ static float4 cubeMapping(const SceneInfo* sceneInfo, CONST Primitive* primitive break; default: { - int A = (v * (*material).textureMapping.x + u) * (*material).textureMapping.w; - int B = (*material).textureMapping.x * (*material).textureMapping.y * (*material).textureMapping.w; + int A = (v * (*material).textureMapping.x + u) * + (*material).textureMapping.w; + int B = (*material).textureMapping.x * + (*material).textureMapping.y * + (*material).textureMapping.w; int index = A % B; int i = (*material).textureOffset.x + index; BitmapBuffer r, g, b; @@ -740,7 +784,8 @@ static float4 cubeMapping(const SceneInfo* sceneInfo, CONST Primitive* primitive transparencyMap(index, material, textures, attributes); // Ambient occlusion mapping if ((*material).advancedTextureIds.z != TEXTURE_NONE) - ambientOcclusionMap(index, material, textures, advancedAttributes); + ambientOcclusionMap(index, material, textures, + advancedAttributes); } break; } @@ -755,14 +800,19 @@ ________________________________________________________________________________ Triangle texture Mapping ________________________________________________________________________________ */ -static float4 triangleUVMapping(const SceneInfo* sceneInfo, CONST Primitive* primitive, CONST Material* materials, - CONST BitmapBuffer* textures, float4* intersection, const float4 areas, float4* normal, - float4* specular, float4* attributes, float4* advancedAttributes) +static float4 triangleUVMapping(const SceneInfo* sceneInfo, + CONST Primitive* primitive, + CONST Material* materials, + CONST BitmapBuffer* textures, + float4* intersection, const float4 areas, + float4* normal, float4* specular, + float4* attributes, float4* advancedAttributes) { CONST Material* material = &materials[(*primitive).materialId]; float4 result = (*material).color; - float2 T = ((*primitive).vt0 * areas.x + (*primitive).vt1 * areas.y + (*primitive).vt2 * areas.z) / + float2 T = ((*primitive).vt0 * areas.x + (*primitive).vt1 * areas.y + + (*primitive).vt2 * areas.z) / (areas.x + areas.y + areas.z); float2 mappingOffset = {0.f, 0.f}; if ((*material).attributes.y == 1) @@ -775,7 +825,8 @@ static float4 triangleUVMapping(const SceneInfo* sceneInfo, CONST Primitive* pri u = u % (*material).textureMapping.x; v = v % (*material).textureMapping.y; - const bool condition = u >= 0 && u < (*material).textureMapping.x && v >= 0 && v < (*material).textureMapping.y; + const bool condition = u >= 0 && u < (*material).textureMapping.x && + v >= 0 && v < (*material).textureMapping.y; if (condition) { switch ((*material).textureIds.x) @@ -788,8 +839,10 @@ static float4 triangleUVMapping(const SceneInfo* sceneInfo, CONST Primitive* pri break; default: { - int A = (v * (*material).textureMapping.x + u) * (*material).textureMapping.w; - int B = (*material).textureMapping.x * (*material).textureMapping.y * (*material).textureMapping.w; + int A = (v * (*material).textureMapping.x + u) * + (*material).textureMapping.w; + int B = (*material).textureMapping.x * + (*material).textureMapping.y * (*material).textureMapping.w; int index = A % B; // Diffuse @@ -831,7 +884,8 @@ static float4 triangleUVMapping(const SceneInfo* sceneInfo, CONST Primitive* pri transparencyMap(index, material, textures, attributes); // Ambient occulusion mapping if ((*material).advancedTextureIds.z != TEXTURE_NONE) - ambientOcclusionMap(index, material, textures, advancedAttributes); + ambientOcclusionMap(index, material, textures, + advancedAttributes); } } } @@ -844,14 +898,19 @@ ________________________________________________________________________________ Box intersection ________________________________________________________________________________ */ -static bool boxIntersection(CONST BoundingBox* box, const Ray* ray, const float t0, const float t1) +static bool boxIntersection(CONST BoundingBox* box, const Ray* ray, + const float t0, const float t1) { float tmin, tmax, tymin, tymax, tzmin, tzmax; - tmin = ((*box).parameters[(*ray).signs.x].x - (*ray).origin.x) * (*ray).inv_direction.x; - tmax = ((*box).parameters[1 - (*ray).signs.x].x - (*ray).origin.x) * (*ray).inv_direction.x; - tymin = ((*box).parameters[(*ray).signs.y].y - (*ray).origin.y) * (*ray).inv_direction.y; - tymax = ((*box).parameters[1 - (*ray).signs.y].y - (*ray).origin.y) * (*ray).inv_direction.y; + tmin = ((*box).parameters[(*ray).signs.x].x - (*ray).origin.x) * + (*ray).inv_direction.x; + tmax = ((*box).parameters[1 - (*ray).signs.x].x - (*ray).origin.x) * + (*ray).inv_direction.x; + tymin = ((*box).parameters[(*ray).signs.y].y - (*ray).origin.y) * + (*ray).inv_direction.y; + tymax = ((*box).parameters[1 - (*ray).signs.y].y - (*ray).origin.y) * + (*ray).inv_direction.y; if ((tmin > tymax) || (tymin > tmax)) return false; @@ -860,8 +919,10 @@ static bool boxIntersection(CONST BoundingBox* box, const Ray* ray, const float tmin = tymin; if (tymax < tmax) tmax = tymax; - tzmin = ((*box).parameters[(*ray).signs.z].z - (*ray).origin.z) * (*ray).inv_direction.z; - tzmax = ((*box).parameters[1 - (*ray).signs.z].z - (*ray).origin.z) * (*ray).inv_direction.z; + tzmin = ((*box).parameters[(*ray).signs.z].z - (*ray).origin.z) * + (*ray).inv_direction.z; + tzmax = ((*box).parameters[1 - (*ray).signs.z].z - (*ray).origin.z) * + (*ray).inv_direction.z; if ((tmin > tzmax) || (tzmin > tmax)) return false; @@ -879,8 +940,11 @@ ________________________________________________________________________________ Ellipsoid intersection ________________________________________________________________________________ */ -static bool ellipsoidIntersection(const SceneInfo* sceneInfo, CONST Primitive* ellipsoid, CONST Material* materials, - const Ray* ray, float4* intersection, float4* normal, float* shadowIntensity) +static bool ellipsoidIntersection(const SceneInfo* sceneInfo, + CONST Primitive* ellipsoid, + CONST Material* materials, const Ray* ray, + float4* intersection, float4* normal, + float* shadowIntensity) { // Shadow intensity (*shadowIntensity) = 1.f; @@ -892,12 +956,14 @@ static bool ellipsoidIntersection(const SceneInfo* sceneInfo, CONST Primitive* e float a = ((dir.x * dir.x) / ((*ellipsoid).size.x * (*ellipsoid).size.x)) + ((dir.y * dir.y) / ((*ellipsoid).size.y * (*ellipsoid).size.y)) + ((dir.z * dir.z) / ((*ellipsoid).size.z * (*ellipsoid).size.z)); - float b = ((2.f * O_C.x * dir.x) / ((*ellipsoid).size.x * (*ellipsoid).size.x)) + - ((2.f * O_C.y * dir.y) / ((*ellipsoid).size.y * (*ellipsoid).size.y)) + - ((2.f * O_C.z * dir.z) / ((*ellipsoid).size.z * (*ellipsoid).size.z)); + float b = + ((2.f * O_C.x * dir.x) / ((*ellipsoid).size.x * (*ellipsoid).size.x)) + + ((2.f * O_C.y * dir.y) / ((*ellipsoid).size.y * (*ellipsoid).size.y)) + + ((2.f * O_C.z * dir.z) / ((*ellipsoid).size.z * (*ellipsoid).size.z)); float c = ((O_C.x * O_C.x) / ((*ellipsoid).size.x * (*ellipsoid).size.x)) + ((O_C.y * O_C.y) / ((*ellipsoid).size.y * (*ellipsoid).size.y)) + - ((O_C.z * O_C.z) / ((*ellipsoid).size.z * (*ellipsoid).size.z)) - 1.f; + ((O_C.z * O_C.z) / ((*ellipsoid).size.z * (*ellipsoid).size.z)) - + 1.f; float d = ((b * b) - (4.f * a * c)); const float condition = d < 0.f || a == 0.f || b == 0.f || c == 0.f; @@ -908,7 +974,8 @@ static bool ellipsoidIntersection(const SceneInfo* sceneInfo, CONST Primitive* e float t1 = (-b + d) / (2.f * a); float t2 = (-b - d) / (2.f * a); - if (t1 <= (*sceneInfo).geometryEpsilon && t2 <= (*sceneInfo).geometryEpsilon) + if (t1 <= (*sceneInfo).geometryEpsilon && + t2 <= (*sceneInfo).geometryEpsilon) return false; // both intersections are behind the ray origin float t = 0.f; @@ -924,9 +991,12 @@ static bool ellipsoidIntersection(const SceneInfo* sceneInfo, CONST Primitive* e (*intersection) = (*ray).origin + t * dir; (*normal) = (*intersection) - (*ellipsoid).p0; - (*normal).x = 2.f * (*normal).x / ((*ellipsoid).size.x * (*ellipsoid).size.x); - (*normal).y = 2.f * (*normal).y / ((*ellipsoid).size.y * (*ellipsoid).size.y); - (*normal).z = 2.f * (*normal).z / ((*ellipsoid).size.z * (*ellipsoid).size.z); + (*normal).x = + 2.f * (*normal).x / ((*ellipsoid).size.x * (*ellipsoid).size.x); + (*normal).y = + 2.f * (*normal).y / ((*ellipsoid).size.y * (*ellipsoid).size.y); + (*normal).z = + 2.f * (*normal).z / ((*ellipsoid).size.z * (*ellipsoid).size.z); (*normal) = normalize(*normal); return true; @@ -938,8 +1008,9 @@ ________________________________________________________________________________ Skybox mapping ________________________________________________________________________________ */ -static float4 skyboxMapping(const SceneInfo* sceneInfo, CONST Material* materials, CONST BitmapBuffer* textures, - const Ray* ray) +static float4 skyboxMapping(const SceneInfo* sceneInfo, + CONST Material* materials, + CONST BitmapBuffer* textures, const Ray* ray) { CONST Material* material = &materials[(*sceneInfo).skyboxMaterialId]; float4 result = (*material).color; @@ -949,7 +1020,8 @@ static float4 skyboxMapping(const SceneInfo* sceneInfo, CONST Material* material float a = 2.f * dot(dir, dir); float b = 2.f * dot((*ray).origin, dir); - float c = dot((*ray).origin, (*ray).origin) - ((*sceneInfo).skyboxRadius * (*sceneInfo).skyboxRadius); + float c = dot((*ray).origin, (*ray).origin) - + ((*sceneInfo).skyboxRadius * (*sceneInfo).skyboxRadius); float d = b * b - 2.f * a * c; if (d <= 0.f || a == 0.f) @@ -958,7 +1030,8 @@ static float4 skyboxMapping(const SceneInfo* sceneInfo, CONST Material* material float t1 = (-b - r) / a; float t2 = (-b + r) / a; - if (t1 <= (*sceneInfo).geometryEpsilon && t2 <= (*sceneInfo).geometryEpsilon) + if (t1 <= (*sceneInfo).geometryEpsilon && + t2 <= (*sceneInfo).geometryEpsilon) return result; // both intersections are behind the ray origin float t = 0.f; @@ -985,11 +1058,14 @@ static float4 skyboxMapping(const SceneInfo* sceneInfo, CONST Material* material u %= (*material).textureMapping.x; if ((*material).textureMapping.y != 0) v %= (*material).textureMapping.y; - const bool condition = u >= 0 && u < (*material).textureMapping.x && v >= 0 && v < (*material).textureMapping.y; + const bool condition = u >= 0 && u < (*material).textureMapping.x && + v >= 0 && v < (*material).textureMapping.y; if (condition) { - int A = (v * (*material).textureMapping.x + u) * (*material).textureMapping.w; - int B = (*material).textureMapping.x * (*material).textureMapping.y * (*material).textureMapping.w; + int A = (v * (*material).textureMapping.x + u) * + (*material).textureMapping.w; + int B = (*material).textureMapping.x * (*material).textureMapping.y * + (*material).textureMapping.w; int index = A % B; // Diffuse @@ -1011,8 +1087,11 @@ ________________________________________________________________________________ Sphere intersection ________________________________________________________________________________ */ -static bool sphereIntersection(const SceneInfo* sceneInfo, CONST Primitive* sphere, CONST Material* materials, - const Ray* ray, float4* intersection, float4* normal, float* shadowIntensity) +static bool sphereIntersection(const SceneInfo* sceneInfo, + CONST Primitive* sphere, + CONST Material* materials, const Ray* ray, + float4* intersection, float4* normal, + float* shadowIntensity) { bool back = false; // solve the equation sphere-ray to find the intersections @@ -1030,7 +1109,8 @@ static bool sphereIntersection(const SceneInfo* sceneInfo, CONST Primitive* sphe float t1 = (-b - r) / a; float t2 = (-b + r) / a; - if (t1 <= (*sceneInfo).geometryEpsilon && t2 <= (*sceneInfo).geometryEpsilon) + if (t1 <= (*sceneInfo).geometryEpsilon && + t2 <= (*sceneInfo).geometryEpsilon) return false; // both intersections are behind the ray origin float t = 0.f; @@ -1057,9 +1137,15 @@ static bool sphereIntersection(const SceneInfo* sceneInfo, CONST Primitive* sphe { // Procedural texture float4 newCenter; - newCenter.x = (*sphere).p0.x + 0.008f * (*sphere).size.x * cos((*sceneInfo).timestamp + (*intersection).x); - newCenter.y = (*sphere).p0.y + 0.008f * (*sphere).size.y * sin((*sceneInfo).timestamp + (*intersection).y); - newCenter.z = (*sphere).p0.z + 0.008f * (*sphere).size.z * sin(cos((*sceneInfo).timestamp + (*intersection).z)); + newCenter.x = (*sphere).p0.x + + 0.008f * (*sphere).size.x * + cos((*sceneInfo).timestamp + (*intersection).x); + newCenter.y = (*sphere).p0.y + + 0.008f * (*sphere).size.y * + sin((*sceneInfo).timestamp + (*intersection).y); + newCenter.z = (*sphere).p0.z + + 0.008f * (*sphere).size.z * + sin(cos((*sceneInfo).timestamp + (*intersection).z)); (*normal) = (*intersection) - newCenter; } (*normal) = normalize(*normal); @@ -1068,7 +1154,9 @@ static bool sphereIntersection(const SceneInfo* sceneInfo, CONST Primitive* sphe // Shadow management r = dot(dir, (*normal)); - (*shadowIntensity) = (materials[(*sphere).materialId].transparency != 0.f) ? (1.f - fabs(r)) : 1.f; + (*shadowIntensity) = (materials[(*sphere).materialId].transparency != 0.f) + ? (1.f - fabs(r)) + : 1.f; return true; } @@ -1084,8 +1172,11 @@ ________________________________________________________________________________ Cylinder (*intersection) ________________________________________________________________________________ */ -static bool cylinderIntersection(const SceneInfo* sceneInfo, CONST Primitive* cylinder, CONST Material* materials, - const Ray* ray, float4* intersection, float4* normal, float* shadowIntensity) +static bool cylinderIntersection(const SceneInfo* sceneInfo, + CONST Primitive* cylinder, + CONST Material* materials, const Ray* ray, + float4* intersection, float4* normal, + float* shadowIntensity) { float4 O_C = (*ray).origin - (*cylinder).p0; float4 dir = (*ray).direction; @@ -1108,7 +1199,8 @@ static bool cylinderIntersection(const SceneInfo* sceneInfo, CONST Primitive* cy return false; O = normalize(cross(n, (*cylinder).n1)); - float s = fabs(sqrt((*cylinder).size.x * (*cylinder).size.x - d * d) / dot(dir, O)); + float s = fabs(sqrt((*cylinder).size.x * (*cylinder).size.x - d * d) / + dot(dir, O)); float t1 = t - s; float t2 = t + s; @@ -1120,7 +1212,8 @@ static bool cylinderIntersection(const SceneInfo* sceneInfo, CONST Primitive* cy float scale1 = dot(HB1, (*cylinder).n1); float scale2 = dot(HB2, (*cylinder).n1); // Cylinder length - if (scale1 < (*sceneInfo).geometryEpsilon || scale2 > (*sceneInfo).geometryEpsilon) + if (scale1 < (*sceneInfo).geometryEpsilon || + scale2 > (*sceneInfo).geometryEpsilon) { (*intersection) = (*ray).origin + t2 * dir; HB1 = (*intersection) - (*cylinder).p0; @@ -1128,7 +1221,8 @@ static bool cylinderIntersection(const SceneInfo* sceneInfo, CONST Primitive* cy scale1 = dot(HB1, (*cylinder).n1); scale2 = dot(HB2, (*cylinder).n1); // Cylinder length - if (scale1 < (*sceneInfo).geometryEpsilon || scale2 > (*sceneInfo).geometryEpsilon) + if (scale1 < (*sceneInfo).geometryEpsilon || + scale2 > (*sceneInfo).geometryEpsilon) return false; (*normal) = normalize(*normal); } @@ -1148,137 +1242,177 @@ ________________________________________________________________________________ Checkboard (*intersection) ________________________________________________________________________________ */ -static bool planeIntersection(const SceneInfo* sceneInfo, CONST Primitive* primitive, CONST Material* materials, - CONST BitmapBuffer* textures, const Ray* ray, float4* intersection, float4* normal, - float* shadowIntensity, bool reverse) +static bool planeIntersection(const SceneInfo* sceneInfo, + CONST Primitive* primitive, + CONST Material* materials, + CONST BitmapBuffer* textures, const Ray* ray, + float4* intersection, float4* normal, + float* shadowIntensity, bool reverse) { bool collision = false; float reverted = reverse ? -1.f : 1.f; switch ((*primitive).type) { - case ptMagicCarpet: - case ptCheckboard: + case ptMagicCarpet: + case ptCheckboard: + { + (*intersection).y = (*primitive).p0.y; + float y = (*ray).origin.y - (*primitive).p0.y; + if (reverted * (*ray).direction.y < 0.f && + reverted * (*ray).origin.y > reverted * (*primitive).p0.y) { + (*normal).x = 0.f; + (*normal).y = 1.f; + (*normal).z = 0.f; + (*intersection).x = + (*ray).origin.x + y * (*ray).direction.x / -(*ray).direction.y; + (*intersection).z = + (*ray).origin.z + y * (*ray).direction.z / -(*ray).direction.y; + collision = fabs((*intersection).x - (*primitive).p0.x) < + (*primitive).size.x && + fabs((*intersection).z - (*primitive).p0.z) < + (*primitive).size.z; + } + break; + } + case ptXZPlane: + { + float y = (*ray).origin.y - (*primitive).p0.y; + if (reverted * (*ray).direction.y < 0.f && + reverted * (*ray).origin.y > reverted * (*primitive).p0.y) + { + (*normal).x = 0.f; + (*normal).y = 1.f; + (*normal).z = 0.f; + (*intersection).x = + (*ray).origin.x + y * (*ray).direction.x / -(*ray).direction.y; (*intersection).y = (*primitive).p0.y; - float y = (*ray).origin.y - (*primitive).p0.y; - if (reverted * (*ray).direction.y < 0.f && reverted * (*ray).origin.y > reverted * (*primitive).p0.y) - { - (*normal).x = 0.f; - (*normal).y = 1.f; - (*normal).z = 0.f; - (*intersection).x = (*ray).origin.x + y * (*ray).direction.x / -(*ray).direction.y; - (*intersection).z = (*ray).origin.z + y * (*ray).direction.z / -(*ray).direction.y; - collision = fabs((*intersection).x - (*primitive).p0.x) < (*primitive).size.x && - fabs((*intersection).z - (*primitive).p0.z) < (*primitive).size.z; - } - break; + (*intersection).z = + (*ray).origin.z + y * (*ray).direction.z / -(*ray).direction.y; + collision = fabs((*intersection).x - (*primitive).p0.x) < + (*primitive).size.x && + fabs((*intersection).z - (*primitive).p0.z) < + (*primitive).size.z; } - case ptXZPlane: + const bool condition = + !collision && reverted * (*ray).direction.y > 0.f && + reverted * (*ray).origin.y < reverted * (*primitive).p0.y; + if (condition) { - float y = (*ray).origin.y - (*primitive).p0.y; - if (reverted * (*ray).direction.y < 0.f && reverted * (*ray).origin.y > reverted * (*primitive).p0.y) - { - (*normal).x = 0.f; - (*normal).y = 1.f; - (*normal).z = 0.f; - (*intersection).x = (*ray).origin.x + y * (*ray).direction.x / -(*ray).direction.y; - (*intersection).y = (*primitive).p0.y; - (*intersection).z = (*ray).origin.z + y * (*ray).direction.z / -(*ray).direction.y; - collision = fabs((*intersection).x - (*primitive).p0.x) < (*primitive).size.x && - fabs((*intersection).z - (*primitive).p0.z) < (*primitive).size.z; - } - const bool condition = - !collision && reverted * (*ray).direction.y > 0.f && - reverted * (*ray).origin.y < reverted * (*primitive).p0.y; - if (condition) - { - (*normal).x = 0.f; - (*normal).y = -1.f; - (*normal).z = 0.f; - (*intersection).x = (*ray).origin.x + y * (*ray).direction.x / -(*ray).direction.y; - (*intersection).y = (*primitive).p0.y; - (*intersection).z = (*ray).origin.z + y * (*ray).direction.z / -(*ray).direction.y; - collision = fabs((*intersection).x - (*primitive).p0.x) < (*primitive).size.x && - fabs((*intersection).z - (*primitive).p0.z) < (*primitive).size.z; - } - break; + (*normal).x = 0.f; + (*normal).y = -1.f; + (*normal).z = 0.f; + (*intersection).x = + (*ray).origin.x + y * (*ray).direction.x / -(*ray).direction.y; + (*intersection).y = (*primitive).p0.y; + (*intersection).z = + (*ray).origin.z + y * (*ray).direction.z / -(*ray).direction.y; + collision = fabs((*intersection).x - (*primitive).p0.x) < + (*primitive).size.x && + fabs((*intersection).z - (*primitive).p0.z) < + (*primitive).size.z; } - case ptYZPlane: + break; + } + case ptYZPlane: + { + float x = (*ray).origin.x - (*primitive).p0.x; + if (reverted * (*ray).direction.x < 0.f && + reverted * (*ray).origin.x > reverted * (*primitive).p0.x) { - float x = (*ray).origin.x - (*primitive).p0.x; - if (reverted * (*ray).direction.x < 0.f && reverted * (*ray).origin.x > reverted * (*primitive).p0.x) - { - (*normal).x = 1.f; - (*normal).y = 0.f; - (*normal).z = 0.f; - (*intersection).x = (*primitive).p0.x; - (*intersection).y = (*ray).origin.y + x * (*ray).direction.y / -(*ray).direction.x; - (*intersection).z = (*ray).origin.z + x * (*ray).direction.z / -(*ray).direction.x; - collision = fabs((*intersection).y - (*primitive).p0.y) < (*primitive).size.y && - fabs((*intersection).z - (*primitive).p0.z) < (*primitive).size.z; - } - const bool condition = - !collision && reverted * (*ray).direction.x > 0.f && - reverted * (*ray).origin.x < reverted * (*primitive).p0.x; - if (condition) - { - (*normal).x = -1.f; - (*normal).y = 0.f; - (*normal).z = 0.f; - (*intersection).x = (*primitive).p0.x; - (*intersection).y = (*ray).origin.y + x * (*ray).direction.y / -(*ray).direction.x; - (*intersection).z = (*ray).origin.z + x * (*ray).direction.z / -(*ray).direction.x; - collision = fabs((*intersection).y - (*primitive).p0.y) < (*primitive).size.y && - fabs((*intersection).z - (*primitive).p0.z) < (*primitive).size.z; - } - break; + (*normal).x = 1.f; + (*normal).y = 0.f; + (*normal).z = 0.f; + (*intersection).x = (*primitive).p0.x; + (*intersection).y = + (*ray).origin.y + x * (*ray).direction.y / -(*ray).direction.x; + (*intersection).z = + (*ray).origin.z + x * (*ray).direction.z / -(*ray).direction.x; + collision = fabs((*intersection).y - (*primitive).p0.y) < + (*primitive).size.y && + fabs((*intersection).z - (*primitive).p0.z) < + (*primitive).size.z; } - case ptXYPlane: + const bool condition = + !collision && reverted * (*ray).direction.x > 0.f && + reverted * (*ray).origin.x < reverted * (*primitive).p0.x; + if (condition) { - float z = (*ray).origin.z - (*primitive).p0.z; - if (reverted * (*ray).direction.z < 0.f && reverted * (*ray).origin.z > reverted * (*primitive).p0.z) - { - (*normal).x = 0.f; - (*normal).y = 0.f; - (*normal).z = 1.f; - (*intersection).z = (*primitive).p0.z; - (*intersection).x = (*ray).origin.x + z * (*ray).direction.x / -(*ray).direction.z; - (*intersection).y = (*ray).origin.y + z * (*ray).direction.y / -(*ray).direction.z; - collision = fabs((*intersection).x - (*primitive).p0.x) < (*primitive).size.x && - fabs((*intersection).y - (*primitive).p0.y) < (*primitive).size.y; - } - const bool condition = - !collision && reverted * (*ray).direction.z > 0.f && - reverted * (*ray).origin.z < reverted * (*primitive).p0.z; - if (condition) - { - (*normal).x = 0.f; - (*normal).y = 0.f; - (*normal).z = -1.f; - (*intersection).z = (*primitive).p0.z; - (*intersection).x = (*ray).origin.x + z * (*ray).direction.x / -(*ray).direction.z; - (*intersection).y = (*ray).origin.y + z * (*ray).direction.y / -(*ray).direction.z; - collision = fabs((*intersection).x - (*primitive).p0.x) < (*primitive).size.x && - fabs((*intersection).y - (*primitive).p0.y) < (*primitive).size.y; - } - break; + (*normal).x = -1.f; + (*normal).y = 0.f; + (*normal).z = 0.f; + (*intersection).x = (*primitive).p0.x; + (*intersection).y = + (*ray).origin.y + x * (*ray).direction.y / -(*ray).direction.x; + (*intersection).z = + (*ray).origin.z + x * (*ray).direction.z / -(*ray).direction.x; + collision = fabs((*intersection).y - (*primitive).p0.y) < + (*primitive).size.y && + fabs((*intersection).z - (*primitive).p0.z) < + (*primitive).size.z; } - case ptCamera: + break; + } + case ptXYPlane: + { + float z = (*ray).origin.z - (*primitive).p0.z; + if (reverted * (*ray).direction.z < 0.f && + reverted * (*ray).origin.z > reverted * (*primitive).p0.z) { - if (reverted * (*ray).direction.z < 0.f && reverted * (*ray).origin.z > reverted * (*primitive).p0.z) - { - (*normal).x = 0.f; - (*normal).y = 0.f; - (*normal).z = 1.f; - (*intersection).z = (*primitive).p0.z; - float z = (*ray).origin.z - (*primitive).p0.z; - (*intersection).x = (*ray).origin.x + z * (*ray).direction.x / -(*ray).direction.z; - (*intersection).y = (*ray).origin.y + z * (*ray).direction.y / -(*ray).direction.z; - collision = fabs((*intersection).x - (*primitive).p0.x) < (*primitive).size.x && - fabs((*intersection).y - (*primitive).p0.y) < (*primitive).size.y; - } - break; + (*normal).x = 0.f; + (*normal).y = 0.f; + (*normal).z = 1.f; + (*intersection).z = (*primitive).p0.z; + (*intersection).x = + (*ray).origin.x + z * (*ray).direction.x / -(*ray).direction.z; + (*intersection).y = + (*ray).origin.y + z * (*ray).direction.y / -(*ray).direction.z; + collision = fabs((*intersection).x - (*primitive).p0.x) < + (*primitive).size.x && + fabs((*intersection).y - (*primitive).p0.y) < + (*primitive).size.y; + } + const bool condition = + !collision && reverted * (*ray).direction.z > 0.f && + reverted * (*ray).origin.z < reverted * (*primitive).p0.z; + if (condition) + { + (*normal).x = 0.f; + (*normal).y = 0.f; + (*normal).z = -1.f; + (*intersection).z = (*primitive).p0.z; + (*intersection).x = + (*ray).origin.x + z * (*ray).direction.x / -(*ray).direction.z; + (*intersection).y = + (*ray).origin.y + z * (*ray).direction.y / -(*ray).direction.z; + collision = fabs((*intersection).x - (*primitive).p0.x) < + (*primitive).size.x && + fabs((*intersection).y - (*primitive).p0.y) < + (*primitive).size.y; } + break; + } + case ptCamera: + { + if (reverted * (*ray).direction.z < 0.f && + reverted * (*ray).origin.z > reverted * (*primitive).p0.z) + { + (*normal).x = 0.f; + (*normal).y = 0.f; + (*normal).z = 1.f; + (*intersection).z = (*primitive).p0.z; + float z = (*ray).origin.z - (*primitive).p0.z; + (*intersection).x = + (*ray).origin.x + z * (*ray).direction.x / -(*ray).direction.z; + (*intersection).y = + (*ray).origin.y + z * (*ray).direction.y / -(*ray).direction.z; + collision = fabs((*intersection).x - (*primitive).p0.x) < + (*primitive).size.x && + fabs((*intersection).y - (*primitive).p0.y) < + (*primitive).size.y; + } + break; + } } if (collision) @@ -1287,18 +1421,21 @@ static bool planeIntersection(const SceneInfo* sceneInfo, CONST Primitive* primi (*shadowIntensity) = 1.f; float4 color = materials[(*primitive).materialId].color; - if ((*primitive).type == ptCamera || materials[(*primitive).materialId].textureIds.x != TEXTURE_NONE) + if ((*primitive).type == ptCamera || + materials[(*primitive).materialId].textureIds.x != TEXTURE_NONE) { // TODO? float4 specular = {0.f, 0.f, 0.f, 0.f}; float4 attributes; float4 advancedAttributes; - color = cubeMapping(sceneInfo, primitive, materials, textures, intersection, normal, &specular, &attributes, + color = cubeMapping(sceneInfo, primitive, materials, textures, + intersection, normal, &specular, &attributes, &advancedAttributes); (*shadowIntensity) = color.w; } - if ((color.x + color.y + color.z) / 3.f >= (*sceneInfo).transparentColor) + if ((color.x + color.y + color.z) / 3.f >= + (*sceneInfo).transparentColor) collision = false; } return collision; @@ -1310,8 +1447,10 @@ ________________________________________________________________________________ Triangle intersection ________________________________________________________________________________ */ -static bool triangleIntersection(const SceneInfo* sceneInfo, CONST Primitive* triangle, const Ray* ray, - float4* intersection, float4* normal, float4* areas, float* shadowIntensity, +static bool triangleIntersection(const SceneInfo* sceneInfo, + CONST Primitive* triangle, const Ray* ray, + float4* intersection, float4* normal, + float4* areas, float* shadowIntensity, const bool processingShadows) { // Reject rays using the barycentric coordinates of @@ -1373,7 +1512,8 @@ static bool triangleIntersection(const SceneInfo* sceneInfo, CONST Primitive* tr (*areas).z = 0.5f * length(cross(v0, v1)); (*areas) = normalize(*areas); - (*normal) = ((*triangle).n0 * (*areas).x + (*triangle).n1 * (*areas).y + (*triangle).n2 * (*areas).z) / + (*normal) = ((*triangle).n0 * (*areas).x + (*triangle).n1 * (*areas).y + + (*triangle).n2 * (*areas).z) / ((*areas).x + (*areas).y + (*areas).z); if ((*sceneInfo).doubleSidedTriangles) @@ -1410,12 +1550,17 @@ ________________________________________________________________________________ (*intersection) Shader ________________________________________________________________________________ */ -static float4 intersectionShader(const SceneInfo* sceneInfo, CONST Primitive* primitive, CONST Material* materials, - CONST BitmapBuffer* textures, float4* intersection, const float4 areas, float4* normal, - float4* specular, float4* attributes, float4* advancedAttributes) +static float4 intersectionShader(const SceneInfo* sceneInfo, + CONST Primitive* primitive, + CONST Material* materials, + CONST BitmapBuffer* textures, + float4* intersection, const float4 areas, + float4* normal, float4* specular, + float4* attributes, float4* advancedAttributes) { float4 colorAtIntersection = materials[(*primitive).materialId].color; - colorAtIntersection.w = 0.f; // w attribute is used to dtermine light intensity of the material + colorAtIntersection.w = + 0.f; // w attribute is used to dtermine light intensity of the material if ((*sceneInfo).extendedGeometry) { @@ -1424,8 +1569,10 @@ static float4 intersectionShader(const SceneInfo* sceneInfo, CONST Primitive* pr case ptCylinder: { if (materials[(*primitive).materialId].textureIds.x != TEXTURE_NONE) - colorAtIntersection = sphereUVMapping(primitive, materials, textures, intersection, normal, specular, - attributes, advancedAttributes); + colorAtIntersection = + sphereUVMapping(primitive, materials, textures, + intersection, normal, specular, attributes, + advancedAttributes); break; } case ptEnvironment: @@ -1433,19 +1580,27 @@ static float4 intersectionShader(const SceneInfo* sceneInfo, CONST Primitive* pr case ptEllipsoid: { if (materials[(*primitive).materialId].textureIds.x != TEXTURE_NONE) - colorAtIntersection = sphereUVMapping(primitive, materials, textures, intersection, normal, specular, - attributes, advancedAttributes); + colorAtIntersection = + sphereUVMapping(primitive, materials, textures, + intersection, normal, specular, attributes, + advancedAttributes); break; } case ptCheckboard: { if (materials[(*primitive).materialId].textureIds.x != TEXTURE_NONE) - colorAtIntersection = cubeMapping(sceneInfo, primitive, materials, textures, intersection, normal, - specular, attributes, advancedAttributes); + colorAtIntersection = + cubeMapping(sceneInfo, primitive, materials, textures, + intersection, normal, specular, attributes, + advancedAttributes); else { - int x = (*sceneInfo).viewDistance + (((*intersection).x - (*primitive).p0.x) / (*primitive).size.x); - int z = (*sceneInfo).viewDistance + (((*intersection).z - (*primitive).p0.z) / (*primitive).size.x); + int x = (*sceneInfo).viewDistance + + (((*intersection).x - (*primitive).p0.x) / + (*primitive).size.x); + int z = (*sceneInfo).viewDistance + + (((*intersection).z - (*primitive).p0.z) / + (*primitive).size.x); if (x % 2 == 0) { if (z % 2 == 0) @@ -1473,23 +1628,28 @@ static float4 intersectionShader(const SceneInfo* sceneInfo, CONST Primitive* pr case ptCamera: { if (materials[(*primitive).materialId].textureIds.x != TEXTURE_NONE) - colorAtIntersection = cubeMapping(sceneInfo, primitive, materials, textures, intersection, normal, - specular, attributes, advancedAttributes); + colorAtIntersection = + cubeMapping(sceneInfo, primitive, materials, textures, + intersection, normal, specular, attributes, + advancedAttributes); break; } case ptTriangle: { if (materials[(*primitive).materialId].textureIds.x != TEXTURE_NONE) - colorAtIntersection = triangleUVMapping(sceneInfo, primitive, materials, textures, intersection, areas, - normal, specular, attributes, advancedAttributes); + colorAtIntersection = + triangleUVMapping(sceneInfo, primitive, materials, textures, + intersection, areas, normal, specular, + attributes, advancedAttributes); break; } } } - else - if (materials[(*primitive).materialId].textureIds.x != TEXTURE_NONE) - colorAtIntersection = triangleUVMapping(sceneInfo, primitive, materials, textures, intersection, areas, - normal, specular, attributes, advancedAttributes); + else if (materials[(*primitive).materialId].textureIds.x != TEXTURE_NONE) + colorAtIntersection = + triangleUVMapping(sceneInfo, primitive, materials, textures, + intersection, areas, normal, specular, attributes, + advancedAttributes); return colorAtIntersection; } @@ -1500,16 +1660,18 @@ Shadows computation We do not consider the object from which the ray is launched... This object cannot shadow itself ! -We now have to find the (*intersection) between the considered object and the ray -which origin is the considered 3D float4 and which direction is defined by the -light source center. +We now have to find the (*intersection) between the considered object and the +ray which origin is the considered 3D float4 and which direction is defined by +the light source center. @return 1.f when pixel is in the shades ________________________________________________________________________________ */ -static float processShadows(const SceneInfo* sceneInfo, CONST BoundingBox* boudingBoxes, const int nbActiveBoxes, - CONST Primitive* primitives, CONST Material* materials, CONST BitmapBuffer* textures, - const int nbPrimitives, const float4 lampCenter, const float4 origin, const int objectId, - const int iteration, float4* color) +static float processShadows( + const SceneInfo* sceneInfo, CONST BoundingBox* boudingBoxes, + const int nbActiveBoxes, CONST Primitive* primitives, + CONST Material* materials, CONST BitmapBuffer* textures, + const int nbPrimitives, const float4 lampCenter, const float4 origin, + const int objectId, const int iteration, float4* color) { float result = 0.f; int cptBoxes = 0; @@ -1520,7 +1682,9 @@ static float processShadows(const SceneInfo* sceneInfo, CONST BoundingBox* boudi r.direction = lampCenter - origin; r.origin = origin + normalize(r.direction) * (*sceneInfo).rayEpsilon; computeRayAttributes(&r); - float minDistance = (iteration < 2) ? (*sceneInfo).viewDistance : (*sceneInfo).viewDistance / (iteration + 1); + float minDistance = (iteration < 2) + ? (*sceneInfo).viewDistance + : (*sceneInfo).viewDistance / (iteration + 1); while (result < (*sceneInfo).shadowIntensity && cptBoxes < nbActiveBoxes) { @@ -1528,15 +1692,18 @@ static float processShadows(const SceneInfo* sceneInfo, CONST BoundingBox* boudi if (boxIntersection(box, &r, 0.05f, minDistance)) { int cptPrimitives = 0; - while (result < (*sceneInfo).shadowIntensity && cptPrimitives < (*box).nbPrimitives) + while (result < (*sceneInfo).shadowIntensity && + cptPrimitives < (*box).nbPrimitives) { float4 intersection = {0.f, 0.f, 0.f, 0.f}; float4 normal = {0.f, 0.f, 0.f, 0.f}; float4 areas = {0.f, 0.f, 0.f, 0.f}; float shadowIntensity = 0.f; - CONST Primitive* primitive = &primitives[(*box).startIndex + cptPrimitives]; - if ((*primitive).index != objectId && materials[(*primitive).materialId].attributes.x == 0) + CONST Primitive* primitive = + &primitives[(*box).startIndex + cptPrimitives]; + if ((*primitive).index != objectId && + materials[(*primitive).materialId].attributes.x == 0) { bool hit = false; if ((*sceneInfo).extendedGeometry) @@ -1544,34 +1711,46 @@ static float processShadows(const SceneInfo* sceneInfo, CONST BoundingBox* boudi switch ((*primitive).type) { case ptSphere: - hit = sphereIntersection(sceneInfo, primitive, materials, &r, &intersection, &normal, - &shadowIntensity); + hit = + sphereIntersection(sceneInfo, primitive, + materials, &r, &intersection, + &normal, &shadowIntensity); break; case ptCylinder: - hit = cylinderIntersection(sceneInfo, primitive, materials, &r, &intersection, &normal, + hit = cylinderIntersection(sceneInfo, primitive, + materials, &r, + &intersection, &normal, &shadowIntensity); break; case ptCamera: hit = false; break; case ptEllipsoid: - hit = ellipsoidIntersection(sceneInfo, primitive, materials, &r, &intersection, &normal, + hit = ellipsoidIntersection(sceneInfo, primitive, + materials, &r, + &intersection, &normal, &shadowIntensity); break; case ptTriangle: - hit = triangleIntersection(sceneInfo, primitive, &r, &intersection, &normal, &areas, - &shadowIntensity, true); + hit = triangleIntersection(sceneInfo, primitive, &r, + &intersection, &normal, + &areas, &shadowIntensity, + true); break; default: - hit = planeIntersection(sceneInfo, primitive, materials, textures, &r, &intersection, - &normal, &shadowIntensity, false); + hit = planeIntersection(sceneInfo, primitive, + materials, textures, &r, + &intersection, &normal, + &shadowIntensity, false); break; } } else { - hit = triangleIntersection(sceneInfo, primitive, &r, &intersection, &normal, &areas, - &shadowIntensity, true); + hit = + triangleIntersection(sceneInfo, primitive, &r, + &intersection, &normal, &areas, + &shadowIntensity, true); } if (hit) { @@ -1580,19 +1759,38 @@ static float processShadows(const SceneInfo* sceneInfo, CONST BoundingBox* boudi float l = length(O_I); if (l > (*sceneInfo).geometryEpsilon && l < length(O_L)) { - float ratio = shadowIntensity * (*sceneInfo).shadowIntensity; - if (materials[(*primitive).materialId].transparency != 0.f) + float ratio = + shadowIntensity * (*sceneInfo).shadowIntensity; + if (materials[(*primitive).materialId] + .transparency != 0.f) { // Shadow color O_L = normalize(O_L); float a = fabs(dot(O_L, normal)); - float r = (materials[(*primitive).materialId].transparency == 0.f) - ? 1.f - : (1.f - 0.8f * materials[(*primitive).materialId].transparency); + float r = + (materials[(*primitive).materialId] + .transparency == 0.f) + ? 1.f + : (1.f - + 0.8f * materials[(*primitive) + .materialId] + .transparency); ratio *= r * a; - (*color).x += ratio * (0.3f - 0.3f * materials[(*primitive).materialId].color.x); - (*color).y += ratio * (0.3f - 0.3f * materials[(*primitive).materialId].color.y); - (*color).z += ratio * (0.3f - 0.3f * materials[(*primitive).materialId].color.z); + (*color).x += + ratio * + (0.3f - + 0.3f * materials[(*primitive).materialId] + .color.x); + (*color).y += + ratio * + (0.3f - + 0.3f * materials[(*primitive).materialId] + .color.y); + (*color).z += + ratio * + (0.3f - + 0.3f * materials[(*primitive).materialId] + .color.z); } result += ratio; } @@ -1617,14 +1815,18 @@ ________________________________________________________________________________ Primitive shader ________________________________________________________________________________ */ -static float4 primitiveShader(const int index, const SceneInfo* sceneInfo, const PostProcessingInfo* postProcessingInfo, - CONST BoundingBox* boundingBoxes, const int nbActiveBoxes, CONST Primitive* primitives, - const int nbActivePrimitives, CONST LightInformation* lightInformation, - const int lightInformationSize, const int nbActiveLamps, CONST Material* materials, - CONST BitmapBuffer* textures, CONST RandomBuffer* randoms, const float4 origin, - float4* normal, const int objectId, float4* intersection, const float4 areas, - float4* closestColor, const int iteration, float4* refractionFromColor, - float* shadowIntensity, float4* totalBlinn, float4* attributes) +static float4 primitiveShader( + const int index, const SceneInfo* sceneInfo, + const PostProcessingInfo* postProcessingInfo, + CONST BoundingBox* boundingBoxes, const int nbActiveBoxes, + CONST Primitive* primitives, const int nbActivePrimitives, + CONST LightInformation* lightInformation, const int lightInformationSize, + const int nbActiveLamps, CONST Material* materials, + CONST BitmapBuffer* textures, CONST RandomBuffer* randoms, + const float4 origin, float4* normal, const int objectId, + float4* intersection, const float4 areas, float4* closestColor, + const int iteration, float4* refractionFromColor, float* shadowIntensity, + float4* totalBlinn, float4* attributes) { CONST Primitive* primitive = &(primitives[objectId]); CONST Material* material = &materials[(*primitive).materialId]; @@ -1644,14 +1846,16 @@ static float4 primitiveShader(const int index, const SceneInfo* sceneInfo, const specular.z = (*material).specular.z; // Intersection color - float4 intersectionColor = intersectionShader(sceneInfo, primitive, materials, textures, intersection, areas, - &bumpNormal, &specular, attributes, &advancedAttributes); + float4 intersectionColor = + intersectionShader(sceneInfo, primitive, materials, textures, + intersection, areas, &bumpNormal, &specular, + attributes, &advancedAttributes); (*normal) += bumpNormal; (*normal) = normalize((*normal)); - const bool condition = - (*sceneInfo).graphicsLevel == glNoShading || (*material).innerIllumination.x != 0.f || - (*material).attributes.z != 0; + const bool condition = (*sceneInfo).graphicsLevel == glNoShading || + (*material).innerIllumination.x != 0.f || + (*material).attributes.z != 0; if (condition) { // Wireframe returns constant color @@ -1664,24 +1868,30 @@ static float4 primitiveShader(const int index, const SceneInfo* sceneInfo, const int C = 1; // (lightInformationSize>1) ? 2 : 1; for (int c = 0; c < C; ++c) { - int cptLamp = ((*sceneInfo).pathTracingIteration >= NB_MAX_ITERATIONS) - ? ((*sceneInfo).pathTracingIteration % lightInformationSize + C - 1) - : 0; + int cptLamp = + ((*sceneInfo).pathTracingIteration >= NB_MAX_ITERATIONS) + ? ((*sceneInfo).pathTracingIteration % + lightInformationSize + + C - 1) + : 0; if (lightInformation[cptLamp].primitiveId != (*primitive).index) { // randomize lamp center float4 center = lightInformation[cptLamp].location; - int t = (index + (*sceneInfo).timestamp) % (MAX_BITMAP_SIZE - 3); - CONST Material* m = &materials[lightInformation[cptLamp].materialId]; + int t = + (index + (*sceneInfo).timestamp) % (MAX_BITMAP_SIZE - 3); + CONST Material* m = + &materials[lightInformation[cptLamp].materialId]; const bool condition = (*sceneInfo).pathTracingIteration >= NB_MAX_ITERATIONS && lightInformation[cptLamp].primitiveId >= 0 && lightInformation[cptLamp].primitiveId < nbActivePrimitives; if (condition) { - float a = (*m).innerIllumination.y * 10.f * (*sceneInfo).pathTracingIteration / + float a = (*m).innerIllumination.y * 10.f * + (*sceneInfo).pathTracingIteration / (float)((*sceneInfo).maxPathTracingIterations); center.x += randoms[t] * a; center.y += randoms[t + 1] * a; @@ -1701,43 +1911,66 @@ static float4 primitiveShader(const int index, const SceneInfo* sceneInfo, const float lambert = dot((*normal), lightRay); const bool condition = - lambert > 0.f && (*sceneInfo).graphicsLevel > glReflectionsAndRefractions && - iteration < 4 && // No need to process shadows after 4 generations of rays... cannot be seen anyway. + lambert > 0.f && + (*sceneInfo).graphicsLevel > + glReflectionsAndRefractions && + iteration < 4 && // No need to process shadows after 4 + // generations of rays... cannot be + // seen anyway. (*material).innerIllumination.x == 0.f; if (condition) - (*shadowIntensity) = - processShadows(sceneInfo, boundingBoxes, nbActiveBoxes, primitives, materials, textures, - nbActivePrimitives, center, (*intersection), - lightInformation[cptLamp].primitiveId, iteration, &shadowColor); + (*shadowIntensity) = processShadows( + sceneInfo, boundingBoxes, nbActiveBoxes, primitives, + materials, textures, nbActivePrimitives, center, + (*intersection), + lightInformation[cptLamp].primitiveId, iteration, + &shadowColor); if ((*sceneInfo).graphicsLevel > glNoShading) { - float photonEnergy = sqrt(lightRayLength / (*m).innerIllumination.z); - photonEnergy = (photonEnergy > 1.f) ? 1.f : photonEnergy; - photonEnergy = (photonEnergy < 0.f) ? 0.f : photonEnergy; - - // Transparent materials are lighted on both sides but the amount of light received by the dark - // side depends on the transparency rate. - lambert *= (lambert < 0.f) ? -materials[(*primitive).materialId].transparency : 1.f; - - if (lightInformation[cptLamp].materialId != MATERIAL_NONE) + float photonEnergy = + sqrt(lightRayLength / (*m).innerIllumination.z); + photonEnergy = + (photonEnergy > 1.f) ? 1.f : photonEnergy; + photonEnergy = + (photonEnergy < 0.f) ? 0.f : photonEnergy; + + // Transparent materials are lighted on both sides but + // the amount of light received by the dark side depends + // on the transparency rate. + lambert *= (lambert < 0.f) + ? -materials[(*primitive).materialId] + .transparency + : 1.f; + + if (lightInformation[cptLamp].materialId != + MATERIAL_NONE) { - CONST Material* m = &materials[lightInformation[cptLamp].materialId]; - lambert *= (*m).innerIllumination.x; // Lamp illumination + CONST Material* m = + &materials[lightInformation[cptLamp] + .materialId]; + lambert *= + (*m).innerIllumination.x; // Lamp illumination } else lambert *= lightInformation[cptLamp].color.w; if ((*material).innerIllumination.w != 0.f) - // Randomize lamp intensity depending on material noise, for more realistic rendering - lambert *= (1.f + randoms[t] * (*material).innerIllumination.w * 100.f); + // Randomize lamp intensity depending on material + // noise, for more realistic rendering + lambert *= + (1.f + randoms[t] * + (*material).innerIllumination.w * + 100.f); lambert *= (1.f - (*shadowIntensity)); lambert += (*sceneInfo).backgroundColor.w; lambert *= (1.f - photonEnergy); // Lighted object, not in the shades - lampsColor += lambert * lightInformation[cptLamp].color - shadowColor; + lampsColor += + lambert * lightInformation[cptLamp].color - + shadowColor; const bool condition = (*sceneInfo).graphicsLevel > glPhong && @@ -1748,7 +1981,8 @@ static float4 primitiveShader(const int index, const SceneInfo* sceneInfo, const // -------------------------------------------------------------------------------- // Blinn - Phong // -------------------------------------------------------------------------------- - float4 viewRay = normalize((*intersection) - origin); + float4 viewRay = + normalize((*intersection) - origin); float4 blinnDir = lightRay - viewRay; const float temp = sqrt(dot(blinnDir, blinnDir)); if (temp != 0.f) @@ -1758,14 +1992,21 @@ static float4 primitiveShader(const int index, const SceneInfo* sceneInfo, const float blinnTerm = dot(blinnDir, (*normal)); blinnTerm = (blinnTerm < 0.f) ? 0.f : blinnTerm; - blinnTerm = specular.x * pow(blinnTerm, specular.y); + blinnTerm = + specular.x * pow(blinnTerm, specular.y); blinnTerm *= (1.f - photonEnergy); (*totalBlinn).x += - lightInformation[cptLamp].color.x * lightInformation[cptLamp].color.w * blinnTerm; + lightInformation[cptLamp].color.x * + lightInformation[cptLamp].color.w * + blinnTerm; (*totalBlinn).y += - lightInformation[cptLamp].color.y * lightInformation[cptLamp].color.w * blinnTerm; + lightInformation[cptLamp].color.y * + lightInformation[cptLamp].color.w * + blinnTerm; (*totalBlinn).z += - lightInformation[cptLamp].color.z * lightInformation[cptLamp].color.w * blinnTerm; + lightInformation[cptLamp].color.z * + lightInformation[cptLamp].color.w * + blinnTerm; // Get transparency from specular map (*totalBlinn).w = specular.z; @@ -1778,7 +2019,8 @@ static float4 primitiveShader(const int index, const SceneInfo* sceneInfo, const // Light impact on material (*closestColor) += intersectionColor * lampsColor; - (*refractionFromColor) = intersectionColor; // Refraction depending on color; + (*refractionFromColor) = + intersectionColor; // Refraction depending on color; saturateVector(totalBlinn); } } @@ -1799,15 +2041,18 @@ ________________________________________________________________________________ Intersections with primitives ________________________________________________________________________________ */ -inline bool intersectionWithPrimitives(const SceneInfo* sceneInfo, CONST BoundingBox* boundingBoxes, - const int nbActiveBoxes, CONST Primitive* primitives, - const int nbActivePrimitives, CONST Material* materials, - CONST BitmapBuffer* textures, const Ray* ray, const int iteration, - int* closestPrimitive, float4* closestIntersection, float4* closestNormal, - float4* closestAreas, float4* colorBox, const int currentMaterialId) +inline bool intersectionWithPrimitives( + const SceneInfo* sceneInfo, CONST BoundingBox* boundingBoxes, + const int nbActiveBoxes, CONST Primitive* primitives, + const int nbActivePrimitives, CONST Material* materials, + CONST BitmapBuffer* textures, const Ray* ray, const int iteration, + int* closestPrimitive, float4* closestIntersection, float4* closestNormal, + float4* closestAreas, float4* colorBox, const int currentMaterialId) { bool intersections = false; - float minDistance = (iteration < 2) ? (*sceneInfo).viewDistance : (*sceneInfo).viewDistance / (iteration + 1); + float minDistance = (iteration < 2) + ? (*sceneInfo).viewDistance + : (*sceneInfo).viewDistance / (iteration + 1); Ray r; r.origin = (*ray).origin; @@ -1815,7 +2060,7 @@ inline bool intersectionWithPrimitives(const SceneInfo* sceneInfo, CONST Boundin computeRayAttributes(&r); float4 intersection; // = {0.f, 0.f, 0.f, 0.f}; - float4 normal; // = {0.f, 0.f, 0.f, 0.f}; + float4 normal; // = {0.f, 0.f, 0.f, 0.f}; bool i = false; float shadowIntensity = 0.f; @@ -1829,15 +2074,19 @@ inline bool intersectionWithPrimitives(const SceneInfo* sceneInfo, CONST Boundin if ((*sceneInfo).renderBoxes == 0) { // Intersection with primitive within boxes - for (int cptPrimitives = 0; cptPrimitives < (*box).nbPrimitives; ++cptPrimitives) + for (int cptPrimitives = 0; cptPrimitives < (*box).nbPrimitives; + ++cptPrimitives) { - CONST Primitive* primitive = &primitives[(*box).startIndex + cptPrimitives]; - CONST Material* material = &materials[(*primitive).materialId]; + CONST Primitive* primitive = + &primitives[(*box).startIndex + cptPrimitives]; + CONST Material* material = + &materials[(*primitive).materialId]; const bool condition = (*material).attributes.x == 0 || ((*material).attributes.x == 1 && currentMaterialId != (*primitive).materialId); - if (condition) // !!!! TEST SHALL BE REMOVED TO INCREASE TRANSPARENCY QUALITY !!! + if (condition) // !!!! TEST SHALL BE REMOVED TO INCREASE + // TRANSPARENCY QUALITY !!! { float4 areas = {0.f, 0.f, 0.f, 0.f}; i = false; @@ -1847,41 +2096,55 @@ inline bool intersectionWithPrimitives(const SceneInfo* sceneInfo, CONST Boundin { case ptEnvironment: case ptSphere: - i = sphereIntersection(sceneInfo, primitive, materials, &r, &intersection, &normal, + i = sphereIntersection(sceneInfo, primitive, + materials, &r, + &intersection, &normal, &shadowIntensity); break; case ptCylinder: - i = cylinderIntersection(sceneInfo, primitive, materials, &r, &intersection, &normal, + i = cylinderIntersection(sceneInfo, primitive, + materials, &r, + &intersection, &normal, &shadowIntensity); break; case ptEllipsoid: - i = ellipsoidIntersection(sceneInfo, primitive, materials, &r, &intersection, &normal, + i = ellipsoidIntersection(sceneInfo, primitive, + materials, &r, + &intersection, + &normal, &shadowIntensity); break; case ptTriangle: - i = triangleIntersection(sceneInfo, primitive, &r, &intersection, &normal, &areas, - &shadowIntensity, false); + i = triangleIntersection(sceneInfo, primitive, + &r, &intersection, + &normal, &areas, + &shadowIntensity, + false); break; default: - i = planeIntersection(sceneInfo, primitive, materials, textures, &r, &intersection, - &normal, &shadowIntensity, false); + i = planeIntersection(sceneInfo, primitive, + materials, textures, &r, + &intersection, &normal, + &shadowIntensity, false); break; } } else - i = triangleIntersection(sceneInfo, primitive, &r, &intersection, &normal, &areas, - &shadowIntensity, false); + i = triangleIntersection(sceneInfo, primitive, &r, + &intersection, &normal, + &areas, &shadowIntensity, + false); const float distance = length(intersection - r.origin); const bool condition = - i && - distance > (*sceneInfo).geometryEpsilon && + i && distance > (*sceneInfo).geometryEpsilon && distance < minDistance; if (condition) { // Only keep intersection with the closest object minDistance = distance; - (*closestPrimitive) = (*box).startIndex + cptPrimitives; + (*closestPrimitive) = + (*box).startIndex + cptPrimitives; (*closestIntersection) = intersection; (*closestNormal) = normal; (*closestAreas) = areas; @@ -1891,7 +2154,9 @@ inline bool intersectionWithPrimitives(const SceneInfo* sceneInfo, CONST Boundin } } else - (*colorBox) += materials[(*box).startIndex % NB_MAX_MATERIALS].color / 50.f; + (*colorBox) += + materials[(*box).startIndex % NB_MAX_MATERIALS].color / + 50.f; ++cptBoxes; } else @@ -1906,13 +2171,14 @@ ________________________________________________________________________________ Intersections with primitives ________________________________________________________________________________ */ -inline float4 intersectionsWithPrimitives(const int index, const SceneInfo* sceneInfo, CONST BoundingBox* boundingBoxes, - const int nbActiveBoxes, CONST Primitive* primitives, - const int nbActivePrimitives, CONST Material* materials, - CONST BitmapBuffer* textures, CONST LightInformation* lightInformation, - const int lightInformationSize, const int nbActiveLamps, - CONST RandomBuffer* randoms, const PostProcessingInfo* postProcessingInfo, - const Ray* ray) +inline float4 intersectionsWithPrimitives( + const int index, const SceneInfo* sceneInfo, + CONST BoundingBox* boundingBoxes, const int nbActiveBoxes, + CONST Primitive* primitives, const int nbActivePrimitives, + CONST Material* materials, CONST BitmapBuffer* textures, + CONST LightInformation* lightInformation, const int lightInformationSize, + const int nbActiveLamps, CONST RandomBuffer* randoms, + const PostProcessingInfo* postProcessingInfo, const Ray* ray) { Ray r; r.origin = (*ray).origin; @@ -1942,10 +2208,12 @@ inline float4 intersectionsWithPrimitives(const int index, const SceneInfo* scen if (boxIntersection(box, &r, 0.f, (*sceneInfo).viewDistance)) { // Intersection with primitive within boxes - for (int cptPrimitives = 0; cptPrimitives < (*box).nbPrimitives; ++cptPrimitives) + for (int cptPrimitives = 0; cptPrimitives < (*box).nbPrimitives; + ++cptPrimitives) { i = false; - CONST Primitive* primitive = &primitives[(*box).startIndex + cptPrimitives]; + CONST Primitive* primitive = + &primitives[(*box).startIndex + cptPrimitives]; CONST Material* material = &materials[(*primitive).materialId]; float4 areas = {0.f, 0.f, 0.f, 0.f}; if ((*sceneInfo).extendedGeometry) @@ -1954,31 +2222,37 @@ inline float4 intersectionsWithPrimitives(const int index, const SceneInfo* scen { case ptEnvironment: case ptSphere: - i = sphereIntersection(sceneInfo, primitive, materials, &r, &intersection, &normal, + i = sphereIntersection(sceneInfo, primitive, materials, + &r, &intersection, &normal, &shadowIntensity); break; case ptCylinder: - i = cylinderIntersection(sceneInfo, primitive, materials, &r, &intersection, &normal, - &shadowIntensity); + i = cylinderIntersection(sceneInfo, primitive, + materials, &r, &intersection, + &normal, &shadowIntensity); break; case ptEllipsoid: - i = ellipsoidIntersection(sceneInfo, primitive, materials, &r, &intersection, &normal, - &shadowIntensity); + i = ellipsoidIntersection(sceneInfo, primitive, + materials, &r, &intersection, + &normal, &shadowIntensity); break; case ptTriangle: - i = triangleIntersection(sceneInfo, primitive, &r, &intersection, &normal, &areas, + i = triangleIntersection(sceneInfo, primitive, &r, + &intersection, &normal, &areas, &shadowIntensity, false); break; default: - i = planeIntersection(sceneInfo, primitive, materials, textures, &r, &intersection, &normal, - &shadowIntensity, false); + i = planeIntersection(sceneInfo, primitive, materials, + textures, &r, &intersection, + &normal, &shadowIntensity, false); break; } } else { - i = triangleIntersection(sceneInfo, primitive, &r, &intersection, &normal, &areas, &shadowIntensity, - false); + i = triangleIntersection(sceneInfo, primitive, &r, + &intersection, &normal, &areas, + &shadowIntensity, false); } if (i) { @@ -1998,12 +2272,16 @@ inline float4 intersectionsWithPrimitives(const int index, const SceneInfo* scen float4 refractionFromColor; float4 closestColor = (*material).color; shadowIntensity = 0.f; - color = - primitiveShader(index, sceneInfo, postProcessingInfo, boundingBoxes, nbActiveBoxes, - primitives, nbActivePrimitives, lightInformation, lightInformationSize, - nbActiveLamps, materials, textures, randoms, r.origin, &normal, - (*box).startIndex + cptPrimitives, &intersection, areas, &closestColor, - 0, &refractionFromColor, &shadowIntensity, &rBlinn, &attributes); + color = primitiveShader( + index, sceneInfo, postProcessingInfo, + boundingBoxes, nbActiveBoxes, primitives, + nbActivePrimitives, lightInformation, + lightInformationSize, nbActiveLamps, materials, + textures, randoms, r.origin, &normal, + (*box).startIndex + cptPrimitives, + &intersection, areas, &closestColor, 0, + &refractionFromColor, &shadowIntensity, &rBlinn, + &attributes); } for (int i = 0; i < MAXDEPTH; ++i) { @@ -2013,7 +2291,8 @@ inline float4 intersectionsWithPrimitives(const int index, const SceneInfo* scen { colors[j + 1] = colors[j]; // normals[j+1]=normals[j]; - // float a=dot(normalize(r.direction-r.origin),normal); + // float + // a=dot(normalize(r.direction-r.origin),normal); colors[j] = color; // *(fabs(a)); colors[j].w = dist; // normals[j] = (a>=0.f); @@ -2038,7 +2317,8 @@ inline float4 intersectionsWithPrimitives(const int index, const SceneInfo* scen int C = 0; float T = colors[C].w; float a = 5 / s; - for (float t = 0; C < MAXDEPTH && t < (*sceneInfo).viewDistance; t += (*sceneInfo).viewDistance / s) + for (float t = 0; C < MAXDEPTH && t < (*sceneInfo).viewDistance; + t += (*sceneInfo).viewDistance / s) { if (t < T) { @@ -2070,21 +2350,22 @@ inline float4 intersectionsWithPrimitives(const int index, const SceneInfo* scen return color; } -inline float4 launchVolumeRendering(const int index, CONST BoundingBox* boundingBoxes, const int nbActiveBoxes, - CONST Primitive* primitives, const int nbActivePrimitives, - CONST LightInformation* lightInformation, const int lightInformationSize, - const int nbActiveLamps, CONST Material* materials, CONST BitmapBuffer* textures, - CONST RandomBuffer* randoms, const Ray* ray, const SceneInfo* sceneInfo, - const PostProcessingInfo* postProcessingInfo, float* depthOfField, - CONST PrimitiveXYIdBuffer* primitiveXYId) +inline float4 launchVolumeRendering( + const int index, CONST BoundingBox* boundingBoxes, const int nbActiveBoxes, + CONST Primitive* primitives, const int nbActivePrimitives, + CONST LightInformation* lightInformation, const int lightInformationSize, + const int nbActiveLamps, CONST Material* materials, + CONST BitmapBuffer* textures, CONST RandomBuffer* randoms, const Ray* ray, + const SceneInfo* sceneInfo, const PostProcessingInfo* postProcessingInfo, + float* depthOfField, CONST PrimitiveXYIdBuffer* primitiveXYId) { (*primitiveXYId).x = -1; (*primitiveXYId).y = 1; (*primitiveXYId).z = 0; - float4 intersectionColor = - intersectionsWithPrimitives(index, sceneInfo, boundingBoxes, nbActiveBoxes, primitives, nbActivePrimitives, - materials, textures, lightInformation, lightInformationSize, nbActiveLamps, randoms, - postProcessingInfo, ray); + float4 intersectionColor = intersectionsWithPrimitives( + index, sceneInfo, boundingBoxes, nbActiveBoxes, primitives, + nbActivePrimitives, materials, textures, lightInformation, + lightInformationSize, nbActiveLamps, randoms, postProcessingInfo, ray); return intersectionColor; } @@ -2101,13 +2382,14 @@ the ray). It can be considered as a light source if its inner light rate is > 0. ________________________________________________________________________________ */ -inline float4 launchRayTracing(const int index, CONST BoundingBox* boundingBoxes, const int nbActiveBoxes, - CONST Primitive* primitives, const int nbActivePrimitives, - CONST LightInformation* lightInformation, const int lightInformationSize, - const int nbActiveLamps, CONST Material* materials, CONST BitmapBuffer* textures, - CONST RandomBuffer* randoms, const Ray* ray, const SceneInfo* sceneInfo, - const PostProcessingInfo* postProcessingInfo, float* depthOfField, - CONST PrimitiveXYIdBuffer* primitiveXYId) +inline float4 launchRayTracing( + const int index, CONST BoundingBox* boundingBoxes, const int nbActiveBoxes, + CONST Primitive* primitives, const int nbActivePrimitives, + CONST LightInformation* lightInformation, const int lightInformationSize, + const int nbActiveLamps, CONST Material* materials, + CONST BitmapBuffer* textures, CONST RandomBuffer* randoms, const Ray* ray, + const SceneInfo* sceneInfo, const PostProcessingInfo* postProcessingInfo, + float* depthOfField, CONST PrimitiveXYIdBuffer* primitiveXYId) { float4 intersectionColor = {0.f, 0.f, 0.f, 0.f}; float4 closestIntersection = {0.f, 0.f, 0.f, 0.f}; @@ -2154,29 +2436,46 @@ inline float4 launchRayTracing(const int index, CONST BoundingBox* boundingBoxes Ray pathTracingRay; float pathTracingRatio = 0.f; float4 pathTracingColor = {0.f, 0.f, 0.f, 0.f}; + bool processGI = false; float4 rBlinn = {0.f, 0.f, 0.f, 0.f}; - int currentMaxIteration = ((*sceneInfo).graphicsLevel < glReflectionsAndRefractions) - ? 1 - : (*sceneInfo).nbRayIterations + (*sceneInfo).pathTracingIteration; - currentMaxIteration = (currentMaxIteration > NB_MAX_ITERATIONS) ? NB_MAX_ITERATIONS : currentMaxIteration; - - while (iteration < currentMaxIteration && rayLength < (*sceneInfo).viewDistance && carryon) + int currentMaxIteration = + ((*sceneInfo).graphicsLevel < glReflectionsAndRefractions) + ? 1 + : (*sceneInfo).nbRayIterations + (*sceneInfo).pathTracingIteration; + currentMaxIteration = (currentMaxIteration > NB_MAX_ITERATIONS) + ? NB_MAX_ITERATIONS + : currentMaxIteration; + + while (iteration < currentMaxIteration && + rayLength < (*sceneInfo).viewDistance && carryon) { float4 areas = {0.f, 0.f, 0.f, 0.f}; - // If no intersection with lamps detected. Now compute intersection with Primitives + // If no intersection with lamps detected. Now compute intersection with + // Primitives if (carryon) { - carryon = - intersectionWithPrimitives(sceneInfo, boundingBoxes, nbActiveBoxes, primitives, nbActivePrimitives, - materials, textures, &rayOrigin, iteration, &closestPrimitive, - &closestIntersection, &normal, &areas, &colorBox, currentMaterialId); + carryon = intersectionWithPrimitives( + sceneInfo, boundingBoxes, nbActiveBoxes, primitives, + nbActivePrimitives, materials, textures, &rayOrigin, iteration, + &closestPrimitive, &closestIntersection, &normal, &areas, + &colorBox, currentMaterialId); } if (carryon) { currentMaterialId = primitives[closestPrimitive].materialId; + float4 attributes; + attributes.x = + materials[primitives[closestPrimitive].materialId].reflection; + attributes.y = + materials[primitives[closestPrimitive].materialId].transparency; + attributes.z = + materials[primitives[closestPrimitive].materialId].refraction; + attributes.w = + materials[primitives[closestPrimitive].materialId].opacity; + if (iteration == 0) { colors[iteration].x = 0.f; @@ -2188,45 +2487,53 @@ inline float4 launchRayTracing(const int index, CONST BoundingBox* boundingBoxes firstIntersection = closestIntersection; latestIntersection = closestIntersection; - if ((*sceneInfo).advancedIllumination == aiBasic || (*sceneInfo).advancedIllumination == aiFull) + if ((*sceneInfo).advancedIllumination != aiNone) { // Global illumination - int t = (index + (*sceneInfo).timestamp) % (MAX_BITMAP_SIZE - 3); - pathTracingRay.origin = closestIntersection + normal * (*sceneInfo).rayEpsilon; - pathTracingRay.direction.x = 50.f * randoms[t]; - pathTracingRay.direction.y = 50.f * randoms[t + 1]; - pathTracingRay.direction.z = 50.f * randoms[t + 2]; - - float cos_theta = dot(normalize(pathTracingRay.direction), normal); + const int t = + (index + (*sceneInfo).timestamp) % + ((*sceneInfo).size.x * (*sceneInfo).size.y - 3); + pathTracingRay.origin = + closestIntersection + normal * (*sceneInfo).rayEpsilon; + pathTracingRay.direction.x = randoms[t]; + pathTracingRay.direction.y = randoms[t + 1]; + pathTracingRay.direction.z = randoms[t + 2]; + pathTracingRay.direction = + normalize(pathTracingRay.direction); + + const float cos_theta = + dot(normalize(pathTracingRay.direction), normal); if (cos_theta < 0.f) pathTracingRay.direction = -pathTracingRay.direction; pathTracingRay.direction += closestIntersection; - pathTracingRatio = fabs(cos_theta); + pathTracingRatio = (1.f - attributes.y) * fabs(cos_theta); + processGI = true; } // Primitive ID for current pixel (*primitiveXYId).x = primitives[closestPrimitive].index; } - float4 attributes; - attributes.x = materials[primitives[closestPrimitive].materialId].reflection; - attributes.y = materials[primitives[closestPrimitive].materialId].transparency; - attributes.z = materials[primitives[closestPrimitive].materialId].refraction; - attributes.w = materials[primitives[closestPrimitive].materialId].opacity; - // Get object color rBlinn.w = attributes.y; - colors[iteration] = primitiveShader(index, sceneInfo, postProcessingInfo, boundingBoxes, nbActiveBoxes, - primitives, nbActivePrimitives, lightInformation, lightInformationSize, - nbActiveLamps, materials, textures, randoms, rayOrigin.origin, &normal, - closestPrimitive, &closestIntersection, areas, &closestColor, iteration, - &refractionFromColor, &shadowIntensity, &rBlinn, &attributes); + colors[iteration] = + primitiveShader(index, sceneInfo, postProcessingInfo, + boundingBoxes, nbActiveBoxes, primitives, + nbActivePrimitives, lightInformation, + lightInformationSize, nbActiveLamps, materials, + textures, randoms, rayOrigin.origin, &normal, + closestPrimitive, &closestIntersection, areas, + &closestColor, iteration, &refractionFromColor, + &shadowIntensity, &rBlinn, &attributes); // Primitive illumination - float colorLight = colors[iteration].x + colors[iteration].y + colors[iteration].z; - (*primitiveXYId).z += (colorLight > (*sceneInfo).transparentColor) ? 16 : 0; + float colorLight = + colors[iteration].x + colors[iteration].y + colors[iteration].z; + (*primitiveXYId).z += + (colorLight > (*sceneInfo).transparentColor) ? 16 : 0; - float segmentLength = length(closestIntersection - latestIntersection); + float segmentLength = + length(closestIntersection - latestIntersection); latestIntersection = closestIntersection; // ---------- // Refraction @@ -2242,9 +2549,12 @@ inline float4 launchRayTracing(const int index, CONST BoundingBox* boundingBoxes { // Opacity refraction = 1.f; - float length = segmentLength * (attributes.w * (1.f - transparency)); + float length = + segmentLength * (attributes.w * (1.f - transparency)); rayLength += length; - rayLength = (rayLength > (*sceneInfo).viewDistance) ? (*sceneInfo).viewDistance : rayLength; + rayLength = (rayLength > (*sceneInfo).viewDistance) + ? (*sceneInfo).viewDistance + : rayLength; a = (rayLength / (*sceneInfo).viewDistance); colors[iteration].x -= a; colors[iteration].y -= a; @@ -2253,7 +2563,8 @@ inline float4 launchRayTracing(const int index, CONST BoundingBox* boundingBoxes // Actual refraction float4 O_E = normalize(closestIntersection - rayOrigin.origin); - vectorRefraction(&reflectedTarget, O_E, refraction, normal, initialRefraction); + vectorRefraction(&reflectedTarget, O_E, refraction, normal, + initialRefraction); colorContributions[iteration] = transparency - a; @@ -2263,8 +2574,11 @@ inline float4 launchRayTracing(const int index, CONST BoundingBox* boundingBoxes if (reflectedRays == -1 && attributes.x != 0.f) // Reflection { vectorReflection(reflectedRay.direction, O_E, normal); - reflectedRay.origin = closestIntersection + reflectedRay.direction * (*sceneInfo).rayEpsilon; - reflectedRay.direction = closestIntersection + reflectedRay.direction; + reflectedRay.origin = + closestIntersection + + reflectedRay.direction * (*sceneInfo).rayEpsilon; + reflectedRay.direction = + closestIntersection + reflectedRay.direction; reflectedRatio = attributes.x; reflectedRays = iteration; } @@ -2274,7 +2588,8 @@ inline float4 launchRayTracing(const int index, CONST BoundingBox* boundingBoxes rayLength += segmentLength; if (attributes.x != 0.f) // Reflection { - float4 O_E = normalize(closestIntersection - rayOrigin.origin); + float4 O_E = + normalize(closestIntersection - rayOrigin.origin); vectorReflection(reflectedTarget, O_E, normal); colorContributions[iteration] = attributes.x; } @@ -2288,21 +2603,28 @@ inline float4 launchRayTracing(const int index, CONST BoundingBox* boundingBoxes // Contribute to final color rBlinn /= (iteration + 1); - recursiveBlinn.x = (rBlinn.x > recursiveBlinn.x) ? rBlinn.x : recursiveBlinn.x; - recursiveBlinn.y = (rBlinn.y > recursiveBlinn.y) ? rBlinn.y : recursiveBlinn.y; - recursiveBlinn.z = (rBlinn.z > recursiveBlinn.z) ? rBlinn.z : recursiveBlinn.z; - - rayOrigin.origin = closestIntersection + reflectedTarget * (*sceneInfo).rayEpsilon; + recursiveBlinn.x = + (rBlinn.x > recursiveBlinn.x) ? rBlinn.x : recursiveBlinn.x; + recursiveBlinn.y = + (rBlinn.y > recursiveBlinn.y) ? rBlinn.y : recursiveBlinn.y; + recursiveBlinn.z = + (rBlinn.z > recursiveBlinn.z) ? rBlinn.z : recursiveBlinn.z; + + rayOrigin.origin = + closestIntersection + reflectedTarget * (*sceneInfo).rayEpsilon; rayOrigin.direction = closestIntersection + reflectedTarget; // Noise management if ((*sceneInfo).pathTracingIteration != 0 && - materials[primitives[closestPrimitive].materialId].color.w != 0.f) + materials[primitives[closestPrimitive].materialId].color.w != + 0.f) { // Randomize view - float ratio = materials[primitives[closestPrimitive].materialId].color.w; + float ratio = + materials[primitives[closestPrimitive].materialId].color.w; ratio *= (attributes.y == 0.f) ? 1000.f : 1.f; - int rindex = (index + (*sceneInfo).timestamp) % (MAX_BITMAP_SIZE - 3); + int rindex = + (index + (*sceneInfo).timestamp) % (MAX_BITMAP_SIZE - 3); rayOrigin.direction.x += randoms[rindex] * ratio; rayOrigin.direction.y += randoms[rindex + 1] * ratio; rayOrigin.direction.z += randoms[rindex + 2] * ratio; @@ -2312,16 +2634,19 @@ inline float4 launchRayTracing(const int index, CONST BoundingBox* boundingBoxes { // Background if ((*sceneInfo).skyboxMaterialId != MATERIAL_NONE) - colors[iteration] = skyboxMapping(sceneInfo, materials, textures, &rayOrigin); + colors[iteration] = + skyboxMapping(sceneInfo, materials, textures, &rayOrigin); else { if ((*sceneInfo).extendedGeometry == 2) { float4 normal = {0.f, 1.f, 0.f, 0.f}; - float4 dir = normalize(rayOrigin.direction - rayOrigin.origin); + float4 dir = + normalize(rayOrigin.direction - rayOrigin.origin); float angle = 0.5f - dot(normal, dir); angle = (angle > 1.f) ? 1.f : angle; - colors[iteration] = (1.f - angle) * (*sceneInfo).backgroundColor; + colors[iteration] = + (1.f - angle) * (*sceneInfo).backgroundColor; } else colors[iteration] = (*sceneInfo).backgroundColor; @@ -2333,80 +2658,102 @@ inline float4 launchRayTracing(const int index, CONST BoundingBox* boundingBoxes float4 areas = {0.f, 0.f, 0.f, 0.f}; if ((*sceneInfo).graphicsLevel >= glReflectionsAndRefractions && - reflectedRays != -1) // TODO: Draft mode should only test (*sceneInfo).pathTracingIteration==iteration + reflectedRays != -1) // TODO: Draft mode should only test + // (*sceneInfo).pathTracingIteration==iteration { // TODO: Dodgy implementation of reflections for transparent material - if (intersectionWithPrimitives(sceneInfo, boundingBoxes, nbActiveBoxes, primitives, nbActivePrimitives, - materials, textures, &reflectedRay, reflectedRays, &closestPrimitive, - &closestIntersection, &normal, &areas, &colorBox, currentMaterialId)) + if (intersectionWithPrimitives(sceneInfo, boundingBoxes, nbActiveBoxes, + primitives, nbActivePrimitives, + materials, textures, &reflectedRay, + reflectedRays, &closestPrimitive, + &closestIntersection, &normal, &areas, + &colorBox, currentMaterialId)) { float4 attributes; - attributes.x = materials[primitives[closestPrimitive].materialId].reflection; - float4 color = primitiveShader(index, sceneInfo, postProcessingInfo, boundingBoxes, nbActiveBoxes, - primitives, nbActivePrimitives, lightInformation, lightInformationSize, - nbActiveLamps, materials, textures, randoms, reflectedRay.origin, &normal, - closestPrimitive, &closestIntersection, areas, &closestColor, iteration, - &refractionFromColor, &shadowIntensity, &rBlinn, &attributes); + attributes.x = + materials[primitives[closestPrimitive].materialId].reflection; + float4 color = + primitiveShader(index, sceneInfo, postProcessingInfo, + boundingBoxes, nbActiveBoxes, primitives, + nbActivePrimitives, lightInformation, + lightInformationSize, nbActiveLamps, materials, + textures, randoms, reflectedRay.origin, &normal, + closestPrimitive, &closestIntersection, areas, + &closestColor, iteration, &refractionFromColor, + &shadowIntensity, &rBlinn, &attributes); colors[reflectedRays] += color * reflectedRatio; (*primitiveXYId).w = shadowIntensity * 255; } } - bool test = true; const bool condition = - ((*sceneInfo).advancedIllumination == aiBasic || (*sceneInfo).advancedIllumination == aiFull) && - (*sceneInfo).pathTracingIteration >= NB_MAX_ITERATIONS; + processGI && (*sceneInfo).pathTracingIteration >= NB_MAX_ITERATIONS; if (condition) { + float alphaIntensity = 1.f; if ((*sceneInfo).advancedIllumination == aiFull) { // Global illumination - if (intersectionWithPrimitives(sceneInfo, boundingBoxes, nbActiveBoxes, primitives, nbActivePrimitives, - materials, textures, &pathTracingRay, NB_MAX_ITERATIONS, &closestPrimitive, - &closestIntersection, &normal, &areas, &colorBox, MATERIAL_NONE)) + if (intersectionWithPrimitives( + sceneInfo, boundingBoxes, nbActiveBoxes, primitives, + nbActivePrimitives, materials, textures, &pathTracingRay, + 10, &closestPrimitive, &closestIntersection, &normal, + &areas, &colorBox, MATERIAL_NONE)) { - // if( (*sceneInfo).advancedIllumination==aiGlobalIllumination ) + // Ambient occlusion and material emission + if (primitives[closestPrimitive].materialId != MATERIAL_NONE) { - // Ambient occlusion - pathTracingColor.x = -1.f; - pathTracingColor.y = -1.f; - pathTracingColor.z = -1.f; - pathTracingRatio = 1.f; + CONST Material* material = + &materials[primitives[closestPrimitive].materialId]; + const float distanceToPrimitive = + length(closestIntersection - pathTracingRay.origin); + const float normalizedDistanceToPrimitive = + 1.f - min(1.f, distanceToPrimitive / + (*sceneInfo).viewDistance); + float4 attributes; + pathTracingColor = primitiveShader( + index, sceneInfo, postProcessingInfo, boundingBoxes, + nbActiveBoxes, primitives, nbActivePrimitives, + lightInformation, lightInformationSize, nbActiveLamps, + materials, textures, randoms, pathTracingRay.origin, + &normal, closestPrimitive, &closestIntersection, areas, + &closestColor, iteration, &refractionFromColor, + &shadowIntensity, &rBlinn, &attributes); + alphaIntensity -= (*sceneInfo).shadowIntensity * + normalizedDistanceToPrimitive; + pathTracingRatio *= (MATERIAL_DEFAULT_EMMISION_STRENGTH + + (*material).innerIllumination.x) * + normalizedDistanceToPrimitive; } } - else + else if ((*sceneInfo).skyboxMaterialId != MATERIAL_NONE) { // Background - if ((*sceneInfo).skyboxMaterialId != MATERIAL_NONE) - { - pathTracingColor = skyboxMapping(sceneInfo, materials, textures, &pathTracingRay); - pathTracingRatio *= SKYBOX_LUNINANCE_STRENGTH; - } + pathTracingColor = skyboxMapping(sceneInfo, materials, textures, + &pathTracingRay); + pathTracingRatio *= SKYBOX_LUNINANCE_STRENGTH; } } else { - // Background if ((*sceneInfo).skyboxMaterialId != MATERIAL_NONE) { - pathTracingColor = skyboxMapping(sceneInfo, materials, textures, &pathTracingRay); - pathTracingRatio *= 0.5f; + // Background + pathTracingColor = skyboxMapping(sceneInfo, materials, textures, + &pathTracingRay); + pathTracingRatio *= SKYBOX_LUNINANCE_STRENGTH; } } - if (test) - colors[0] += pathTracingColor * pathTracingRatio; + colors[0] = + colors[0] * alphaIntensity + pathTracingColor * pathTracingRatio; } - if (test) - { - for (int i = iteration - 2; i >= 0; --i) - colors[i] = colors[i] * (1.f - colorContributions[i]) + colors[i + 1] * colorContributions[i]; - intersectionColor = colors[0]; - intersectionColor += recursiveBlinn; - } - else - intersectionColor = colors[0]; + for (int i = iteration - 2; i >= 0; --i) + colors[i] = colors[i] * (1.f - colorContributions[i]) + + colors[i + 1] * colorContributions[i]; + intersectionColor = colors[0]; + intersectionColor += recursiveBlinn; float len = length(firstIntersection - (*ray).origin); (*depthOfField) = len; @@ -2426,7 +2773,8 @@ inline float4 launchRayTracing(const int index, CONST BoundingBox* boundingBoxes float D2 = (*sceneInfo).viewDistance * 0.05f; float a = len - D1; float b = 1.f - (a / D2); - intersectionColor = intersectionColor * b + (*sceneInfo).backgroundColor * (1.f - b); + intersectionColor = + intersectionColor * b + (*sceneInfo).backgroundColor * (1.f - b); } // Primitive information @@ -2445,15 +2793,16 @@ ________________________________________________________________________________ Standard renderer ________________________________________________________________________________ */ -__kernel void k_standardRenderer(const int2 occupancyParameters, int device_split, int stream_split, - CONST BoundingBox* boundingBoxes, int nbActiveBoxes, CONST Primitive* primitives, - int nbActivePrimitives, CONST LightInformation* lightInformation, - int lightInformationSize, int nbActiveLamps, CONST Material* materials, - CONST BitmapBuffer* textures, CONST RandomBuffer* randoms, float4 origin, - float4 direction, float4 angles, const SceneInfo sceneInfo, - const PostProcessingInfo postProcessingInfo, - CONST PostProcessingBuffer* postProcessingBuffer, - CONST PrimitiveXYIdBuffer* primitiveXYIds) +__kernel void k_standardRenderer( + const int2 occupancyParameters, int device_split, int stream_split, + CONST BoundingBox* boundingBoxes, int nbActiveBoxes, + CONST Primitive* primitives, int nbActivePrimitives, + CONST LightInformation* lightInformation, int lightInformationSize, + int nbActiveLamps, CONST Material* materials, CONST BitmapBuffer* textures, + CONST RandomBuffer* randoms, float4 origin, float4 direction, float4 angles, + const SceneInfo sceneInfo, const PostProcessingInfo postProcessingInfo, + CONST PostProcessingBuffer* postProcessingBuffer, + CONST PrimitiveXYIdBuffer* primitiveXYIds) { int x = get_global_id(0); int y = get_global_id(1); @@ -2462,15 +2811,21 @@ __kernel void k_standardRenderer(const int2 occupancyParameters, int device_spli return; // Antialisazing - float2 AArotatedGrid[4] = {{3.f, 5.f}, {5.f, -3.f}, {-3.f, -5.f}, {-5.f, 3.f}}; + float2 AArotatedGrid[4] = {{3.f, 5.f}, + {5.f, -3.f}, + {-3.f, -5.f}, + {-5.f, 3.f}}; // Beware out of bounds error! // And only process pixels that need extra rendering const bool condition = index >= sceneInfo.size.x * sceneInfo.size.y / occupancyParameters.x || - (sceneInfo.pathTracingIteration > primitiveXYIds[index].y && // Still need to process iterations - primitiveXYIds[index].w == 0 && // Shadows? if so, compute soft shadows by randomizing light positions - sceneInfo.pathTracingIteration > 0 && sceneInfo.pathTracingIteration <= NB_MAX_ITERATIONS); + (sceneInfo.pathTracingIteration > + primitiveXYIds[index].y && // Still need to process iterations + primitiveXYIds[index].w == 0 && // Shadows? if so, compute soft shadows + // by randomizing light positions + sceneInfo.pathTracingIteration > 0 && + sceneInfo.pathTracingIteration <= NB_MAX_ITERATIONS); if (condition) return; @@ -2484,21 +2839,27 @@ __kernel void k_standardRenderer(const int2 occupancyParameters, int device_spli bool antialiasingActivated = (sceneInfo.cameraType == ctAntialiazed); - if (postProcessingInfo.type != ppe_depthOfField && sceneInfo.pathTracingIteration >= NB_MAX_ITERATIONS) + if (postProcessingInfo.type != ppe_depthOfField && + sceneInfo.pathTracingIteration >= NB_MAX_ITERATIONS) { // Randomize view for natural depth of field float a = postProcessingInfo.param1 / 20000.f; int rindex = (index + sceneInfo.timestamp) % (MAX_BITMAP_SIZE - 2); - ray.origin.x += randoms[rindex] * postProcessingBuffer[index].colorInfo.w * a; - ray.origin.y += randoms[rindex + 1] * postProcessingBuffer[index].colorInfo.w * a; + ray.origin.x += + randoms[rindex] * postProcessingBuffer[index].colorInfo.w * a; + ray.origin.y += + randoms[rindex + 1] * postProcessingBuffer[index].colorInfo.w * a; } float dof = 0.f; if (sceneInfo.cameraType == ctOrthographic) { - ray.direction.x = ray.origin.z * 0.001f * (float)(x - (sceneInfo.size.x / 2)); - ray.direction.y = -ray.origin.z * 0.001f * (float)(device_split + stream_split + y - (sceneInfo.size.y / 2)); + ray.direction.x = + ray.origin.z * 0.001f * (float)(x - (sceneInfo.size.x / 2)); + ray.direction.y = + -ray.origin.z * 0.001f * + (float)(device_split + stream_split + y - (sceneInfo.size.y / 2)); ray.origin.x = ray.direction.x; ray.origin.y = ray.direction.y; } @@ -2508,8 +2869,11 @@ __kernel void k_standardRenderer(const int2 occupancyParameters, int device_spli float2 step; step.x = ratio * angles.w / (float)sceneInfo.size.x; step.y = angles.w / (float)sceneInfo.size.y; - ray.direction.x = ray.direction.x - step.x * (float)(x - (sceneInfo.size.x / 2)); - ray.direction.y = ray.direction.y + step.y * (float)(device_split + stream_split + y - (sceneInfo.size.y / 2)); + ray.direction.x = + ray.direction.x - step.x * (float)(x - (sceneInfo.size.x / 2)); + ray.direction.y = + ray.direction.y + step.y * (float)(device_split + stream_split + y - + (sceneInfo.size.y / 2)); } vectorRotation(&ray.origin, rotationCenter, angles); @@ -2523,20 +2887,29 @@ __kernel void k_standardRenderer(const int2 occupancyParameters, int device_spli { r.direction.x = ray.direction.x + AArotatedGrid[I].x; r.direction.y = ray.direction.y + AArotatedGrid[I].y; - float4 c = launchRayTracing(index, boundingBoxes, nbActiveBoxes, primitives, nbActivePrimitives, - lightInformation, lightInformationSize, nbActiveLamps, materials, textures, - randoms, &r, &sceneInfo, &postProcessingInfo, &dof, &primitiveXYIds[index]); + float4 c = + launchRayTracing(index, boundingBoxes, nbActiveBoxes, + primitives, nbActivePrimitives, + lightInformation, lightInformationSize, + nbActiveLamps, materials, textures, randoms, + &r, &sceneInfo, &postProcessingInfo, &dof, + &primitiveXYIds[index]); color += c; } } else { - r.direction.x = ray.direction.x + AArotatedGrid[sceneInfo.pathTracingIteration % 4].x; - r.direction.y = ray.direction.y + AArotatedGrid[sceneInfo.pathTracingIteration % 4].y; + r.direction.x = ray.direction.x + + AArotatedGrid[sceneInfo.pathTracingIteration % 4].x; + r.direction.y = ray.direction.y + + AArotatedGrid[sceneInfo.pathTracingIteration % 4].y; } - color += launchRayTracing(index, boundingBoxes, nbActiveBoxes, primitives, nbActivePrimitives, lightInformation, - lightInformationSize, nbActiveLamps, materials, textures, randoms, &r, &sceneInfo, - &postProcessingInfo, &dof, &primitiveXYIds[index]); + color += + launchRayTracing(index, boundingBoxes, nbActiveBoxes, primitives, + nbActivePrimitives, lightInformation, + lightInformationSize, nbActiveLamps, materials, + textures, randoms, &r, &sceneInfo, &postProcessingInfo, + &dof, &primitiveXYIds[index]); if (sceneInfo.advancedIllumination == aiRandomIllumination) { @@ -2571,30 +2944,37 @@ ________________________________________________________________________________ Standard renderer ________________________________________________________________________________ */ -__kernel void k_volumeRenderer(const int2 occupancyParameters, int device_split, int stream_split, - CONST BoundingBox* boundingBoxes, int nbActiveBoxes, CONST Primitive* primitives, - int nbActivePrimitives, CONST LightInformation* lightInformation, - int lightInformationSize, int nbActiveLamps, CONST Material* materials, - CONST BitmapBuffer* textures, CONST RandomBuffer* randoms, float4 origin, - float4 direction, float4 angles, const SceneInfo sceneInfo, - const PostProcessingInfo postProcessingInfo, - CONST PostProcessingBuffer* postProcessingBuffer, - CONST PrimitiveXYIdBuffer* primitiveXYIds) +__kernel void k_volumeRenderer( + const int2 occupancyParameters, int device_split, int stream_split, + CONST BoundingBox* boundingBoxes, int nbActiveBoxes, + CONST Primitive* primitives, int nbActivePrimitives, + CONST LightInformation* lightInformation, int lightInformationSize, + int nbActiveLamps, CONST Material* materials, CONST BitmapBuffer* textures, + CONST RandomBuffer* randoms, float4 origin, float4 direction, float4 angles, + const SceneInfo sceneInfo, const PostProcessingInfo postProcessingInfo, + CONST PostProcessingBuffer* postProcessingBuffer, + CONST PrimitiveXYIdBuffer* primitiveXYIds) { int x = get_global_id(0); int y = get_global_id(1); int index = (stream_split + y) * sceneInfo.size.x + x; // Antialisazing - float2 AArotatedGrid[4] = {{3.f, 5.f}, {5.f, -3.f}, {-3.f, -5.f}, {-5.f, 3.f}}; + float2 AArotatedGrid[4] = {{3.f, 5.f}, + {5.f, -3.f}, + {-3.f, -5.f}, + {-5.f, 3.f}}; // Beware out of bounds error! // And only process pixels that need extra rendering const bool condition = index >= sceneInfo.size.x * sceneInfo.size.y / occupancyParameters.x || - (sceneInfo.pathTracingIteration > primitiveXYIds[index].y && // Still need to process iterations - primitiveXYIds[index].w == 0 && // Shadows? if so, compute soft shadows by randomizing light positions - sceneInfo.pathTracingIteration > 0 && sceneInfo.pathTracingIteration <= NB_MAX_ITERATIONS); + (sceneInfo.pathTracingIteration > + primitiveXYIds[index].y && // Still need to process iterations + primitiveXYIds[index].w == 0 && // Shadows? if so, compute soft shadows + // by randomizing light positions + sceneInfo.pathTracingIteration > 0 && + sceneInfo.pathTracingIteration <= NB_MAX_ITERATIONS); if (condition) return; @@ -2609,21 +2989,27 @@ __kernel void k_volumeRenderer(const int2 occupancyParameters, int device_split, bool antialiasingActivated = (sceneInfo.cameraType == ctAntialiazed); - if (postProcessingInfo.type != ppe_depthOfField && sceneInfo.pathTracingIteration >= NB_MAX_ITERATIONS) + if (postProcessingInfo.type != ppe_depthOfField && + sceneInfo.pathTracingIteration >= NB_MAX_ITERATIONS) { // Randomize view for natural depth of field float a = postProcessingInfo.param1 / 20000.f; int rindex = (index + sceneInfo.timestamp) % (MAX_BITMAP_SIZE - 2); - ray.origin.x += randoms[rindex] * postProcessingBuffer[index].colorInfo.w * a; - ray.origin.y += randoms[rindex + 1] * postProcessingBuffer[index].colorInfo.w * a; + ray.origin.x += + randoms[rindex] * postProcessingBuffer[index].colorInfo.w * a; + ray.origin.y += + randoms[rindex + 1] * postProcessingBuffer[index].colorInfo.w * a; } float dof = 0.f; if (sceneInfo.cameraType == ctOrthographic) { - ray.direction.x = ray.origin.z * 0.001f * (float)(x - (sceneInfo.size.x / 2)); - ray.direction.y = -ray.origin.z * 0.001f * (float)(device_split + stream_split + y - (sceneInfo.size.y / 2)); + ray.direction.x = + ray.origin.z * 0.001f * (float)(x - (sceneInfo.size.x / 2)); + ray.direction.y = + -ray.origin.z * 0.001f * + (float)(device_split + stream_split + y - (sceneInfo.size.y / 2)); ray.origin.x = ray.direction.x; ray.origin.y = ray.direction.y; } @@ -2633,8 +3019,11 @@ __kernel void k_volumeRenderer(const int2 occupancyParameters, int device_split, float2 step; step.x = ratio * angles.w / (float)sceneInfo.size.x; step.y = angles.w / (float)sceneInfo.size.y; - ray.direction.x = ray.direction.x - step.x * (float)(x - (sceneInfo.size.x / 2)); - ray.direction.y = ray.direction.y + step.y * (float)(device_split + stream_split + y - (sceneInfo.size.y / 2)); + ray.direction.x = + ray.direction.x - step.x * (float)(x - (sceneInfo.size.x / 2)); + ray.direction.y = + ray.direction.y + step.y * (float)(device_split + stream_split + y - + (sceneInfo.size.y / 2)); } vectorRotation(&ray.origin, rotationCenter, angles); @@ -2648,21 +3037,27 @@ __kernel void k_volumeRenderer(const int2 occupancyParameters, int device_split, { r.direction.x = ray.direction.x + AArotatedGrid[I].x; r.direction.y = ray.direction.y + AArotatedGrid[I].y; - float4 c = - launchVolumeRendering(index, boundingBoxes, nbActiveBoxes, primitives, nbActivePrimitives, - lightInformation, lightInformationSize, nbActiveLamps, materials, textures, - randoms, &r, &sceneInfo, &postProcessingInfo, &dof, &primitiveXYIds[index]); + float4 c = launchVolumeRendering( + index, boundingBoxes, nbActiveBoxes, primitives, + nbActivePrimitives, lightInformation, lightInformationSize, + nbActiveLamps, materials, textures, randoms, &r, &sceneInfo, + &postProcessingInfo, &dof, &primitiveXYIds[index]); color += c; } } else { - r.direction.x = ray.direction.x + AArotatedGrid[sceneInfo.pathTracingIteration % 4].x; - r.direction.y = ray.direction.y + AArotatedGrid[sceneInfo.pathTracingIteration % 4].y; + r.direction.x = ray.direction.x + + AArotatedGrid[sceneInfo.pathTracingIteration % 4].x; + r.direction.y = ray.direction.y + + AArotatedGrid[sceneInfo.pathTracingIteration % 4].y; } - color += launchVolumeRendering(index, boundingBoxes, nbActiveBoxes, primitives, nbActivePrimitives, - lightInformation, lightInformationSize, nbActiveLamps, materials, textures, randoms, - &r, &sceneInfo, &postProcessingInfo, &dof, &primitiveXYIds[index]); + color += launchVolumeRendering(index, boundingBoxes, nbActiveBoxes, + primitives, nbActivePrimitives, + lightInformation, lightInformationSize, + nbActiveLamps, materials, textures, randoms, + &r, &sceneInfo, &postProcessingInfo, &dof, + &primitiveXYIds[index]); if (sceneInfo.advancedIllumination == aiRandomIllumination) { @@ -2697,15 +3092,16 @@ ________________________________________________________________________________ Anaglyph Renderer ________________________________________________________________________________ */ -__kernel void k_anaglyphRenderer(const int2 occupancyParameters, int device_split, int stream_split, - CONST BoundingBox* boundingBoxes, int nbActiveBoxes, CONST Primitive* primitives, - int nbActivePrimitives, CONST LightInformation* lightInformation, - int lightInformationSize, int nbActiveLamps, CONST Material* materials, - CONST BitmapBuffer* textures, CONST RandomBuffer* randoms, float4 origin, - float4 direction, float4 angles, const SceneInfo sceneInfo, - const PostProcessingInfo postProcessingInfo, - CONST PostProcessingBuffer* postProcessingBuffer, - CONST PrimitiveXYIdBuffer* primitiveXYIds) +__kernel void k_anaglyphRenderer( + const int2 occupancyParameters, int device_split, int stream_split, + CONST BoundingBox* boundingBoxes, int nbActiveBoxes, + CONST Primitive* primitives, int nbActivePrimitives, + CONST LightInformation* lightInformation, int lightInformationSize, + int nbActiveLamps, CONST Material* materials, CONST BitmapBuffer* textures, + CONST RandomBuffer* randoms, float4 origin, float4 direction, float4 angles, + const SceneInfo sceneInfo, const PostProcessingInfo postProcessingInfo, + CONST PostProcessingBuffer* postProcessingBuffer, + CONST PrimitiveXYIdBuffer* primitiveXYIds) { int x = get_global_id(0); int y = get_global_id(1); @@ -2715,7 +3111,8 @@ __kernel void k_anaglyphRenderer(const int2 occupancyParameters, int device_spli if (index >= sceneInfo.size.x * sceneInfo.size.y / occupancyParameters.x) return; - float focus = primitiveXYIds[sceneInfo.size.x * sceneInfo.size.y / 2].x - origin.z; + float focus = + primitiveXYIds[sceneInfo.size.x * sceneInfo.size.y / 2].x - origin.z; float eyeSeparation = sceneInfo.eyeSeparation * (focus / direction.z); float4 rotationCenter = {0.f, 0.f, 0.f, 0.f}; @@ -2743,16 +3140,20 @@ __kernel void k_anaglyphRenderer(const int2 occupancyParameters, int device_spli eyeRay.origin.y = origin.y; eyeRay.origin.z = origin.z; - eyeRay.direction.x = direction.x - step.x * (float)(x - (sceneInfo.size.x / 2)); - eyeRay.direction.y = direction.y + step.y * (float)(y - (sceneInfo.size.y / 2)); + eyeRay.direction.x = + direction.x - step.x * (float)(x - (sceneInfo.size.x / 2)); + eyeRay.direction.y = + direction.y + step.y * (float)(y - (sceneInfo.size.y / 2)); eyeRay.direction.z = direction.z; // vectorRotation( eyeRay.origin, rotationCenter, angles ); vectorRotation(&eyeRay.direction, rotationCenter, angles); float4 colorLeft = - launchRayTracing(index, boundingBoxes, nbActiveBoxes, primitives, nbActivePrimitives, lightInformation, - lightInformationSize, nbActiveLamps, materials, textures, randoms, &eyeRay, &sceneInfo, + launchRayTracing(index, boundingBoxes, nbActiveBoxes, primitives, + nbActivePrimitives, lightInformation, + lightInformationSize, nbActiveLamps, materials, + textures, randoms, &eyeRay, &sceneInfo, &postProcessingInfo, &dof, &primitiveXYIds[index]); // Right eye @@ -2760,18 +3161,23 @@ __kernel void k_anaglyphRenderer(const int2 occupancyParameters, int device_spli eyeRay.origin.y = origin.y; eyeRay.origin.z = origin.z; - eyeRay.direction.x = direction.x - step.x * (float)(x - (sceneInfo.size.x / 2)); - eyeRay.direction.y = direction.y + step.y * (float)(y - (sceneInfo.size.y / 2)); + eyeRay.direction.x = + direction.x - step.x * (float)(x - (sceneInfo.size.x / 2)); + eyeRay.direction.y = + direction.y + step.y * (float)(y - (sceneInfo.size.y / 2)); eyeRay.direction.z = direction.z; vectorRotation(&eyeRay.direction, rotationCenter, angles); float4 colorRight = - launchRayTracing(index, boundingBoxes, nbActiveBoxes, primitives, nbActivePrimitives, lightInformation, - lightInformationSize, nbActiveLamps, materials, textures, randoms, &eyeRay, &sceneInfo, + launchRayTracing(index, boundingBoxes, nbActiveBoxes, primitives, + nbActivePrimitives, lightInformation, + lightInformationSize, nbActiveLamps, materials, + textures, randoms, &eyeRay, &sceneInfo, &postProcessingInfo, &dof, &primitiveXYIds[index]); - float r1 = colorLeft.x * 0.299f + colorLeft.y * 0.587f + colorLeft.z * 0.114f; + float r1 = + colorLeft.x * 0.299f + colorLeft.y * 0.587f + colorLeft.z * 0.114f; float b1 = 0.f; float g1 = 0.f; @@ -2801,15 +3207,16 @@ ________________________________________________________________________________ 3D Vision Renderer ________________________________________________________________________________ */ -__kernel void k_3DVisionRenderer(const int2 occupancyParameters, int device_split, int stream_split, - CONST BoundingBox* boundingBoxes, int nbActiveBoxes, CONST Primitive* primitives, - int nbActivePrimitives, CONST LightInformation* lightInformation, - int lightInformationSize, int nbActiveLamps, CONST Material* materials, - CONST BitmapBuffer* textures, CONST RandomBuffer* randoms, float4 origin, - float4 direction, float4 angles, const SceneInfo sceneInfo, - const PostProcessingInfo postProcessingInfo, - CONST PostProcessingBuffer* postProcessingBuffer, - CONST PrimitiveXYIdBuffer* primitiveXYIds) +__kernel void k_3DVisionRenderer( + const int2 occupancyParameters, int device_split, int stream_split, + CONST BoundingBox* boundingBoxes, int nbActiveBoxes, + CONST Primitive* primitives, int nbActivePrimitives, + CONST LightInformation* lightInformation, int lightInformationSize, + int nbActiveLamps, CONST Material* materials, CONST BitmapBuffer* textures, + CONST RandomBuffer* randoms, float4 origin, float4 direction, float4 angles, + const SceneInfo sceneInfo, const PostProcessingInfo postProcessingInfo, + CONST PostProcessingBuffer* postProcessingBuffer, + CONST PrimitiveXYIdBuffer* primitiveXYIds) { int x = get_global_id(0); int y = get_global_id(1); @@ -2819,7 +3226,8 @@ __kernel void k_3DVisionRenderer(const int2 occupancyParameters, int device_spli if (index >= sceneInfo.size.x * sceneInfo.size.y / occupancyParameters.x) return; - float focus = primitiveXYIds[sceneInfo.size.x * sceneInfo.size.y / 2].x - origin.z; + float focus = + primitiveXYIds[sceneInfo.size.x * sceneInfo.size.y / 2].x - origin.z; float eyeSeparation = sceneInfo.eyeSeparation * (direction.z / focus); float4 rotationCenter = {0.f, 0.f, 0.f, 0.f}; @@ -2851,8 +3259,11 @@ __kernel void k_3DVisionRenderer(const int2 occupancyParameters, int device_spli eyeRay.origin.z = origin.z; eyeRay.direction.x = - direction.x - step.x * (float)(x - (sceneInfo.size.x / 2) + halfWidth / 2) + sceneInfo.eyeSeparation; - eyeRay.direction.y = direction.y + step.y * (float)(y - (sceneInfo.size.y / 2)); + direction.x - + step.x * (float)(x - (sceneInfo.size.x / 2) + halfWidth / 2) + + sceneInfo.eyeSeparation; + eyeRay.direction.y = + direction.y + step.y * (float)(y - (sceneInfo.size.y / 2)); eyeRay.direction.z = direction.z; } else @@ -2863,20 +3274,27 @@ __kernel void k_3DVisionRenderer(const int2 occupancyParameters, int device_spli eyeRay.origin.z = origin.z; eyeRay.direction.x = - direction.x - step.x * (float)(x - (sceneInfo.size.x / 2) - halfWidth / 2) - sceneInfo.eyeSeparation; - eyeRay.direction.y = direction.y + step.y * (float)(y - (sceneInfo.size.y / 2)); + direction.x - + step.x * (float)(x - (sceneInfo.size.x / 2) - halfWidth / 2) - + sceneInfo.eyeSeparation; + eyeRay.direction.y = + direction.y + step.y * (float)(y - (sceneInfo.size.y / 2)); eyeRay.direction.z = direction.z; } - if (sqrt(eyeRay.direction.x * eyeRay.direction.x + eyeRay.direction.y * eyeRay.direction.y) > (halfWidth * 6)) + if (sqrt(eyeRay.direction.x * eyeRay.direction.x + + eyeRay.direction.y * eyeRay.direction.y) > (halfWidth * 6)) return; vectorRotation(&eyeRay.origin, rotationCenter, angles); vectorRotation(&eyeRay.direction, rotationCenter, angles); - float4 color = launchRayTracing(index, boundingBoxes, nbActiveBoxes, primitives, nbActivePrimitives, - lightInformation, lightInformationSize, nbActiveLamps, materials, textures, randoms, - &eyeRay, &sceneInfo, &postProcessingInfo, &dof, &primitiveXYIds[index]); + float4 color = + launchRayTracing(index, boundingBoxes, nbActiveBoxes, primitives, + nbActivePrimitives, lightInformation, + lightInformationSize, nbActiveLamps, materials, + textures, randoms, &eyeRay, &sceneInfo, + &postProcessingInfo, &dof, &primitiveXYIds[index]); // Randomize light intensity int rindex = (index + sceneInfo.timestamp) % MAX_BITMAP_SIZE; @@ -2905,15 +3323,16 @@ ________________________________________________________________________________ 3D Vision Renderer ________________________________________________________________________________ */ -__kernel void k_fishEyeRenderer(const int2 occupancyParameters, int device_split, int stream_split, - CONST BoundingBox* boundingBoxes, int nbActiveBoxes, CONST Primitive* primitives, - int nbActivePrimitives, CONST LightInformation* lightInformation, - int lightInformationSize, int nbActiveLamps, CONST Material* materials, - CONST BitmapBuffer* textures, CONST RandomBuffer* randoms, float4 origin, - float4 direction, float4 angles, const SceneInfo sceneInfo, - const PostProcessingInfo postProcessingInfo, - CONST PostProcessingBuffer* postProcessingBuffer, - CONST PrimitiveXYIdBuffer* primitiveXYIds) +__kernel void k_fishEyeRenderer( + const int2 occupancyParameters, int device_split, int stream_split, + CONST BoundingBox* boundingBoxes, int nbActiveBoxes, + CONST Primitive* primitives, int nbActivePrimitives, + CONST LightInformation* lightInformation, int lightInformationSize, + int nbActiveLamps, CONST Material* materials, CONST BitmapBuffer* textures, + CONST RandomBuffer* randoms, float4 origin, float4 direction, float4 angles, + const SceneInfo sceneInfo, const PostProcessingInfo postProcessingInfo, + CONST PostProcessingBuffer* postProcessingBuffer, + CONST PrimitiveXYIdBuffer* primitiveXYIds) { } @@ -2923,8 +3342,10 @@ ________________________________________________________________________________ Post Processing Effect: Default ________________________________________________________________________________ */ -__kernel void k_default(const int2 occupancyParameters, const SceneInfo sceneInfo, - CONST PostProcessingBuffer* postProcessingBuffer, CONST BitmapBuffer* bitmap) +__kernel void k_default(const int2 occupancyParameters, + const SceneInfo sceneInfo, + CONST PostProcessingBuffer* postProcessingBuffer, + CONST BitmapBuffer* bitmap) { int x = get_global_id(0); int y = get_global_id(1); @@ -2936,7 +3357,8 @@ __kernel void k_default(const int2 occupancyParameters, const SceneInfo sceneInf float4 localColor = postProcessingBuffer[index].colorInfo; if (sceneInfo.pathTracingIteration > NB_MAX_ITERATIONS) - localColor /= (float)(sceneInfo.pathTracingIteration - NB_MAX_ITERATIONS + 1); + localColor /= + (float)(sceneInfo.pathTracingIteration - NB_MAX_ITERATIONS + 1); makeColor(&sceneInfo, &localColor, bitmap, index); } @@ -2946,8 +3368,11 @@ ________________________________________________________________________________ Post Processing Effect: Depth of field ________________________________________________________________________________ */ -__kernel void k_depthOfField(const int2 occupancyParameters, const SceneInfo sceneInfo, const PostProcessingInfo postProcessingInfo, - CONST PostProcessingBuffer* postProcessingBuffer, CONST RandomBuffer* randoms, +__kernel void k_depthOfField(const int2 occupancyParameters, + const SceneInfo sceneInfo, + const PostProcessingInfo postProcessingInfo, + CONST PostProcessingBuffer* postProcessingBuffer, + CONST RandomBuffer* randoms, CONST BitmapBuffer* bitmap) { int x = get_global_id(0); @@ -2959,7 +3384,9 @@ __kernel void k_depthOfField(const int2 occupancyParameters, const SceneInfo sce return; float4 localColor = {0.f, 0.f, 0.f, 0.f}; - float depth = fabs(postProcessingBuffer[index].colorInfo.w - postProcessingInfo.param1) / sceneInfo.viewDistance; + float depth = fabs(postProcessingBuffer[index].colorInfo.w - + postProcessingInfo.param1) / + sceneInfo.viewDistance; int wh = sceneInfo.size.x * sceneInfo.size.y; for (int i = 0; i < postProcessingInfo.param3; ++i) @@ -2968,7 +3395,8 @@ __kernel void k_depthOfField(const int2 occupancyParameters, const SceneInfo sce int iy = (i + 100) % wh; int xx = x + depth * randoms[ix] * postProcessingInfo.param2; int yy = y + depth * randoms[iy] * postProcessingInfo.param2; - if (xx >= 0 && xx < sceneInfo.size.x && yy >= 0 && yy < sceneInfo.size.y) + if (xx >= 0 && xx < sceneInfo.size.x && yy >= 0 && + yy < sceneInfo.size.y) { int localIndex = yy * sceneInfo.size.x + xx; if (localIndex >= 0 && localIndex < wh) @@ -2980,7 +3408,8 @@ __kernel void k_depthOfField(const int2 occupancyParameters, const SceneInfo sce localColor /= postProcessingInfo.param3; if (sceneInfo.pathTracingIteration > NB_MAX_ITERATIONS) - localColor /= (float)(sceneInfo.pathTracingIteration - NB_MAX_ITERATIONS + 1); + localColor /= + (float)(sceneInfo.pathTracingIteration - NB_MAX_ITERATIONS + 1); localColor.w = 1.f; makeColor(&sceneInfo, &localColor, bitmap, index); } @@ -2991,10 +3420,11 @@ ________________________________________________________________________________ Post Processing Effect: Ambiant Occlusion ________________________________________________________________________________ */ -__kernel void k_ambientOcclusion(const int2 occupancyParameters, SceneInfo sceneInfo, - PostProcessingInfo postProcessingInfo, - CONST PostProcessingBuffer* postProcessingBuffer, CONST RandomBuffer* randoms, - CONST BitmapBuffer* bitmap) +__kernel void k_ambientOcclusion( + const int2 occupancyParameters, SceneInfo sceneInfo, + PostProcessingInfo postProcessingInfo, + CONST PostProcessingBuffer* postProcessingBuffer, + CONST RandomBuffer* randoms, CONST BitmapBuffer* bitmap) { int x = get_global_id(0); int y = get_global_id(1); @@ -3020,11 +3450,14 @@ __kernel void k_ambientOcclusion(const int2 occupancyParameters, SceneInfo scene c += 1.f; int xx = x + (X * postProcessingInfo.param2 * randoms[ix] / 10.f); int yy = y + (Y * postProcessingInfo.param2 * randoms[iy] / 10.f); - if (xx >= 0 && xx < sceneInfo.size.x && yy >= 0 && yy < sceneInfo.size.y) + if (xx >= 0 && xx < sceneInfo.size.x && yy >= 0 && + yy < sceneInfo.size.y) { int localIndex = yy * sceneInfo.size.x + xx; if (postProcessingBuffer[localIndex].colorInfo.w < depth) - occ += 1.f - (postProcessingBuffer[localIndex].colorInfo.w - depth) / sceneInfo.viewDistance; + occ += 1.f - (postProcessingBuffer[localIndex].colorInfo.w - + depth) / + sceneInfo.viewDistance; } else occ += 1.f; @@ -3035,7 +3468,8 @@ __kernel void k_ambientOcclusion(const int2 occupancyParameters, SceneInfo scene occ = (occ > 1.f) ? 1.f : occ; occ = (occ < 0.f) ? 0.f : occ; if (sceneInfo.pathTracingIteration > NB_MAX_ITERATIONS) - localColor /= (float)(sceneInfo.pathTracingIteration - NB_MAX_ITERATIONS + 1); + localColor /= + (float)(sceneInfo.pathTracingIteration - NB_MAX_ITERATIONS + 1); localColor.x -= occ; localColor.y -= occ; @@ -3053,9 +3487,12 @@ ________________________________________________________________________________ Post Processing Effect: radiosity ________________________________________________________________________________ */ -__kernel void k_radiosity(const int2 occupancyParameters, SceneInfo sceneInfo, PostProcessingInfo postProcessingInfo, - CONST PrimitiveXYIdBuffer* primitiveXYIds, CONST PostProcessingBuffer* postProcessingBuffer, - CONST RandomBuffer* randoms, CONST BitmapBuffer* bitmap) +__kernel void k_radiosity(const int2 occupancyParameters, SceneInfo sceneInfo, + PostProcessingInfo postProcessingInfo, + CONST PrimitiveXYIdBuffer* primitiveXYIds, + CONST PostProcessingBuffer* postProcessingBuffer, + CONST RandomBuffer* randoms, + CONST BitmapBuffer* bitmap) { int x = get_global_id(0); int y = get_global_id(1); @@ -3080,8 +3517,10 @@ ________________________________________________________________________________ Post Processing Effect: Default ________________________________________________________________________________ */ -__kernel void k_filter(const int2 occupancyParameters, SceneInfo sceneInfo, PostProcessingInfo postProcessingInfo, - CONST PostProcessingBuffer* postProcessingBuffer, CONST BitmapBuffer* bitmap) +__kernel void k_filter(const int2 occupancyParameters, SceneInfo sceneInfo, + PostProcessingInfo postProcessingInfo, + CONST PostProcessingBuffer* postProcessingBuffer, + CONST BitmapBuffer* bitmap) { int x = get_global_id(0); int y = get_global_id(1); @@ -3090,82 +3529,86 @@ __kernel void k_filter(const int2 occupancyParameters, SceneInfo sceneInfo, Post if (index >= sceneInfo.size.x * sceneInfo.size.y / occupancyParameters.x) return; - // Filters - #define NB_FILTERS 6 - const int2 filterSize[NB_FILTERS]; // = {{3, 3}, {5, 5}, {3, 3}, {3, 3}, {5, 5}, {5, 5}}; +// Filters +#define NB_FILTERS 6 + const int2 filterSize[NB_FILTERS]; // = {{3, 3}, {5, 5}, {3, 3}, {3, 3}, {5, + // 5}, {5, 5}}; const float2 filterFactors[NB_FILTERS]; // = {{1.f, 128.f}, {1.f, 0.f}, {1.f, 0.f}, // {1.f, 0.f}, {0.2f, 0.f}, {0.125f, 0.f}}; // Factor and Bias - const float filterInfo[NB_FILTERS][5][5] = - { + const float filterInfo[NB_FILTERS][5][5] = { {// Emboss - {-1.0f, -1.0f, 0.0f, 0.0f, 0.0f}, - {-1.0f, 0.0f, 1.0f, 0.0f, 0.0f}, - {0.0f, 1.0f, 1.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f} - }, + {-1.0f, -1.0f, 0.0f, 0.0f, 0.0f}, + {-1.0f, 0.0f, 1.0f, 0.0f, 0.0f}, + {0.0f, 1.0f, 1.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}}, {// Find edges - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, - {-1.0f, -1.0f, 2.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f} - }, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, + {-1.0f, -1.0f, 2.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}}, {// Sharpen - {-1.0f, -1.0f, -1.0f, 0.0f, 0.0f}, - {-1.0f, 9.0f, -1.0f, 0.0f, 0.0f}, - {-1.0f, -1.0f, -1.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f} - }, + {-1.0f, -1.0f, -1.0f, 0.0f, 0.0f}, + {-1.0f, 9.0f, -1.0f, 0.0f, 0.0f}, + {-1.0f, -1.0f, -1.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}}, {// Blur - {0.0f, 0.2f, 0.0f, 0.0f, 0.0f}, - {0.2f, 0.2f, 0.2f, 0.0f, 0.0f}, - {0.0f, 0.2f, 0.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 0.0f, 0.0f} - }, + {0.0f, 0.2f, 0.0f, 0.0f, 0.0f}, + {0.2f, 0.2f, 0.2f, 0.0f, 0.0f}, + {0.0f, 0.2f, 0.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f}}, {// Motion Blur - {1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, - {0.0f, 1.0f, 0.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 1.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 1.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 0.0f, 1.0f} - }, + {1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, 1.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 1.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 1.0f, 0.0f}, + {0.0f, 0.0f, 0.0f, 0.0f, 1.0f}}, {// Subtle Sharpen - {-1.0f, -1.0f, -1.0f, -1.0f, -1.0f}, - {-1.0f, 2.0f, 2.0f, 2.0f, -1.0f}, - {-1.0f, 2.0f, 8.0f, 2.0f, -1.0f}, - {-1.0f, 2.0f, 2.0f, 2.0f, -1.0f}, - {-1.0f, -1.0f, -1.0f, -1.0f, -1.0f} - } - }; + {-1.0f, -1.0f, -1.0f, -1.0f, -1.0f}, + {-1.0f, 2.0f, 2.0f, 2.0f, -1.0f}, + {-1.0f, 2.0f, 8.0f, 2.0f, -1.0f}, + {-1.0f, 2.0f, 2.0f, 2.0f, -1.0f}, + {-1.0f, -1.0f, -1.0f, -1.0f, -1.0f}}}; float4 localColor = {0.f, 0.f, 0.f, 0.f}; float4 color = {0.f, 0.f, 0.f, 0.f}; if (postProcessingInfo.param3 < NB_FILTERS) { // multiply every value of the filter with corresponding image pixel - for (int filterX = 0; filterX < filterSize[postProcessingInfo.param3].x; filterX++) + for (int filterX = 0; filterX < filterSize[postProcessingInfo.param3].x; + filterX++) { - for (int filterY = 0; filterY < filterSize[postProcessingInfo.param3].y; filterY++) + for (int filterY = 0; + filterY < filterSize[postProcessingInfo.param3].y; filterY++) { - int imageX = - (x - filterSize[postProcessingInfo.param3].x / 2 + filterX + sceneInfo.size.x) % sceneInfo.size.x; - int imageY = - (y - filterSize[postProcessingInfo.param3].y / 2 + filterY + sceneInfo.size.y) % sceneInfo.size.y; + int imageX = (x - filterSize[postProcessingInfo.param3].x / 2 + + filterX + sceneInfo.size.x) % + sceneInfo.size.x; + int imageY = (y - filterSize[postProcessingInfo.param3].y / 2 + + filterY + sceneInfo.size.y) % + sceneInfo.size.y; int localIndex = imageY * sceneInfo.size.x + imageX; float4 c = postProcessingBuffer[localIndex].colorInfo; if (sceneInfo.pathTracingIteration > NB_MAX_ITERATIONS) - c /= (float)(sceneInfo.pathTracingIteration - NB_MAX_ITERATIONS + 1); - - localColor.x += c.x * filterInfo[postProcessingInfo.param3][filterX][filterY]; - localColor.y += c.y * filterInfo[postProcessingInfo.param3][filterX][filterY]; - localColor.z += c.z * filterInfo[postProcessingInfo.param3][filterX][filterY]; + c /= (float)(sceneInfo.pathTracingIteration - + NB_MAX_ITERATIONS + 1); + + localColor.x += + c.x * + filterInfo[postProcessingInfo.param3][filterX][filterY]; + localColor.y += + c.y * + filterInfo[postProcessingInfo.param3][filterX][filterY]; + localColor.z += + c.z * + filterInfo[postProcessingInfo.param3][filterX][filterY]; } } // truncate values smaller than zero and larger than 255 diff --git a/solr/engines/random/RandomGenerator.cpp b/solr/engines/random/RandomGenerator.cpp new file mode 100644 index 0000000..830ec19 --- /dev/null +++ b/solr/engines/random/RandomGenerator.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2011-2022, Cyrille Favreau + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "RandomGenerator.h" + +#include "Logging.h" + +namespace solr +{ + +RandomGenerator* RandomGenerator::_instance = nullptr; +std::mutex RandomGenerator::_mutex; + +RandomGenerator::~RandomGenerator() +{ + close(); +} + +void RandomGenerator::close() +{ + if (_thread) + { + delete _thread; + _thread = nullptr; + } +} + +void RandomGenerator::initialize(const float multiplier) +{ + _multiplier = multiplier; + _count = 0; + _thread = new std::thread(&RandomGenerator::_getFloats, this); + if (_thread) + { + LOG_INFO(1, "Thread for random numbers is up and running!"); + _thread->detach(); + } +} + +void RandomGenerator::reshape(const size_t nbFloats) +{ + LOG_INFO(1, "Reshaping random generator to " << nbFloats << " floats"); + _randomMutex.lock(); + _buffer.resize(nbFloats); + _randomMutex.unlock(); +} + +void RandomGenerator::_getFloats() +{ + while (true) + { + if (_paused) + continue; + _randomMutex.lock(); + LOG_INFO(3, "Fetching " << _buffer.size() << " from CPU"); + for (size_t i = 0; i < _buffer.size() && !_paused; ++i) + _buffer[i] = _multiplier * (rand() % 200 - 100) / 100.f; + _randomMutex.unlock(); + } +} + +void RandomGenerator::pause() +{ + _paused = true; + // Wait for thread to complete current loop + _randomMutex.lock(); + _randomMutex.unlock(); +} + +void RandomGenerator::resume() +{ + _paused = false; + _randomMutex.unlock(); +} + +} // namespace solr \ No newline at end of file diff --git a/solr/engines/random/RandomGenerator.h b/solr/engines/random/RandomGenerator.h new file mode 100644 index 0000000..b54b085 --- /dev/null +++ b/solr/engines/random/RandomGenerator.h @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2011-2022, Cyrille Favreau + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include + +#include + +#include +#include +#include + +namespace solr +{ +class RandomGenerator +{ +public: + /** + * @brief Get the Instance object + * + * @return RandomGenerator Reference to the object + */ + static RandomGenerator& getInstance() + { + std::lock_guard lock(_mutex); + if (!_instance) + _instance = new RandomGenerator(); + return *_instance; + } + + /** + * @brief Initialized the random frame buffer, a buffer with the size of the + * image, filled with random numbers and used by the engine for launching + * random rays. Random numbers are constantly processed in a dedicated + * thread. The random frame buffer is transferred to the GPU before + * rendering. + * + * @param multiplier Multiplier applied to every random number + */ + void initialize(const float multiplier); + + /** + * @brief Pauses the thread + * + */ + void pause(); + /** + * @brief Resumes the thread + * + */ + void resume(); + + /** + * @brief Stops the thread and releases potential randomization devices + * + */ + void close(); + + /** + * @brief Set the Buffer object + * + * @param buffer Pointer to the buffer filled by the randomizer + * @param nbFloats Number of floats in the buffer + */ + void reshape(const size_t nbFloats); + + RandomBuffer* getBuffer() { return _buffer.data(); } + + static std::mutex _mutex; + static RandomGenerator* _instance; + +private: + void _getFloats(); + + ~RandomGenerator(); + + std::thread* _thread{nullptr}; + std::vector _buffer; + float _multiplier; + size_t _count{0}; + bool _paused{false}; + + std::mutex _randomMutex; +}; +} // namespace solr \ No newline at end of file diff --git a/solr/games/MapReader.cpp b/solr/games/MapReader.cpp index 3fee1da..e8595ab 100644 --- a/solr/games/MapReader.cpp +++ b/solr/games/MapReader.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include @@ -28,20 +25,16 @@ #include #include -#include "../Consts.h" #include "../Logging.h" +#include "../consts.h" #include "MapReader.h" namespace solr { -MapReader::MapReader(void) -{ -} +MapReader::MapReader(void) {} -MapReader::~MapReader(void) -{ -} +MapReader::~MapReader(void) {} vec3i readInt3(const std::string &value) { @@ -114,7 +107,8 @@ vec4f MapReader::loadFromFile(const std::string &filename, GPUKernel &kernel) { ++index_jewel; MapJewel malJewel; - s >> item >> item >> malJewel.location.x >> malJewel.location.z >> + s >> item >> item >> malJewel.location.x >> + malJewel.location.z >> malJewel.location.y; // Caution y <-> z jewels[index_jewel] = malJewel; } @@ -123,23 +117,26 @@ vec4f MapReader::loadFromFile(const std::string &filename, GPUKernel &kernel) // ++index_zone; MapZone mapZone; - s >> item >> item >> mapZone.location.x >> mapZone.location.z >> + s >> item >> item >> mapZone.location.x >> + mapZone.location.z >> mapZone.location.y >> // Caution y <-> z - item >> mapZone.dimension.x >> mapZone.dimension.y >> mapZone.dimension.z >> item >> - mapZone.colorScene; + item >> mapZone.dimension.x >> mapZone.dimension.y >> + mapZone.dimension.z >> item >> mapZone.colorScene; zones[index_zone] = mapZone; } else if (line.find(" + // ++index_block; MapBlock block; memset(&block, 0, sizeof(MapBlock)); - s >> item >> item >> block.location.x >> block.location.z >> block.location.y >> // Caution y <-> z - item >> block.dimension.x >> block.dimension.z >> block.dimension.y; + s >> item >> item >> block.location.x >> block.location.z >> + block.location.y >> // Caution y <-> z + item >> block.dimension.x >> block.dimension.z >> + block.dimension.y; if (line.find("TYPE") != -1) { @@ -147,8 +144,9 @@ vec4f MapReader::loadFromFile(const std::string &filename, GPUKernel &kernel) } else { - s >> item >> block.north >> item >> block.south >> item >> block.east >> item >> block.west >> - item >> block.split >> item >> block.hollow; + s >> item >> block.north >> item >> block.south >> + item >> block.east >> item >> block.west >> item >> + block.split >> item >> block.hollow; } block.zone = index_zone; blocks[index_block] = block; @@ -170,8 +168,10 @@ vec4f MapReader::loadFromFile(const std::string &filename, GPUKernel &kernel) position.y = jewel.location.y * blockSize.y; position.z = jewel.location.z * blockSize.z; int nbPrimitives = kernel.addPrimitive(ptSphere); - kernel.setPrimitive(nbPrimitives, position.x + blockSize.x / 2.f, position.y + blockSize.x / 2.f, - position.z + blockSize.x / 2.f, blockSize.x / 4.f, 0.f, 0.f, jewelMaterial); + kernel.setPrimitive(nbPrimitives, position.x + blockSize.x / 2.f, + position.y + blockSize.x / 2.f, + position.z + blockSize.x / 2.f, blockSize.x / 4.f, + 0.f, 0.f, jewelMaterial); ++itj; } @@ -230,43 +230,63 @@ vec4f MapReader::loadFromFile(const std::string &filename, GPUKernel &kernel) #if 1 // Front nbPrimitives = kernel.addPrimitive(ptTriangle); - kernel.setPrimitive(nbPrimitives, position.x, position.y, position.z, dimension.x, position.y, position.z, - dimension.x, dimension.y, position.z, 0.f, 0.f, 0.f, blockMaterial); + kernel.setPrimitive(nbPrimitives, position.x, position.y, position.z, + dimension.x, position.y, position.z, dimension.x, + dimension.y, position.z, 0.f, 0.f, 0.f, + blockMaterial); nbPrimitives = kernel.addPrimitive(ptTriangle); - kernel.setPrimitive(nbPrimitives, dimension.x, dimension.y, position.z, position.x, dimension.y, position.z, - position.x, position.y, position.z, 0.f, 0.f, 0.f, blockMaterial); + kernel.setPrimitive(nbPrimitives, dimension.x, dimension.y, position.z, + position.x, dimension.y, position.z, position.x, + position.y, position.z, 0.f, 0.f, 0.f, + blockMaterial); // Back nbPrimitives = kernel.addPrimitive(ptTriangle); - kernel.setPrimitive(nbPrimitives, position.x, position.y, dimension.z, dimension.x, position.y, dimension.z, - dimension.x, dimension.y, dimension.z, 0.f, 0.f, 0.f, blockMaterial); + kernel.setPrimitive(nbPrimitives, position.x, position.y, dimension.z, + dimension.x, position.y, dimension.z, dimension.x, + dimension.y, dimension.z, 0.f, 0.f, 0.f, + blockMaterial); nbPrimitives = kernel.addPrimitive(ptTriangle); - kernel.setPrimitive(nbPrimitives, dimension.x, dimension.y, dimension.z, position.x, dimension.y, dimension.z, - position.x, position.y, dimension.z, 0.f, 0.f, 0.f, blockMaterial); + kernel.setPrimitive(nbPrimitives, dimension.x, dimension.y, dimension.z, + position.x, dimension.y, dimension.z, position.x, + position.y, dimension.z, 0.f, 0.f, 0.f, + blockMaterial); // Left nbPrimitives = kernel.addPrimitive(ptTriangle); - kernel.setPrimitive(nbPrimitives, position.x, position.y, position.z, position.x, position.y, dimension.z, - position.x, dimension.y, dimension.z, 0.f, 0.f, 0.f, blockMaterial); + kernel.setPrimitive(nbPrimitives, position.x, position.y, position.z, + position.x, position.y, dimension.z, position.x, + dimension.y, dimension.z, 0.f, 0.f, 0.f, + blockMaterial); nbPrimitives = kernel.addPrimitive(ptTriangle); - kernel.setPrimitive(nbPrimitives, position.x, dimension.y, dimension.z, position.x, dimension.y, position.z, - position.x, position.y, position.z, 0.f, 0.f, 0.f, blockMaterial); + kernel.setPrimitive(nbPrimitives, position.x, dimension.y, dimension.z, + position.x, dimension.y, position.z, position.x, + position.y, position.z, 0.f, 0.f, 0.f, + blockMaterial); // Right nbPrimitives = kernel.addPrimitive(ptTriangle); - kernel.setPrimitive(nbPrimitives, dimension.x, position.y, position.z, dimension.x, position.y, dimension.z, - dimension.x, dimension.y, dimension.z, 0.f, 0.f, 0.f, blockMaterial); + kernel.setPrimitive(nbPrimitives, dimension.x, position.y, position.z, + dimension.x, position.y, dimension.z, dimension.x, + dimension.y, dimension.z, 0.f, 0.f, 0.f, + blockMaterial); nbPrimitives = kernel.addPrimitive(ptTriangle); - kernel.setPrimitive(nbPrimitives, dimension.x, dimension.y, dimension.z, dimension.x, dimension.y, position.z, - dimension.x, position.y, position.z, 0.f, 0.f, 0.f, blockMaterial); + kernel.setPrimitive(nbPrimitives, dimension.x, dimension.y, dimension.z, + dimension.x, dimension.y, position.z, dimension.x, + position.y, position.z, 0.f, 0.f, 0.f, + blockMaterial); // Top nbPrimitives = kernel.addPrimitive(ptTriangle); - kernel.setPrimitive(nbPrimitives, position.x, dimension.y, position.z, dimension.x, dimension.y, position.z, - dimension.x, dimension.y, dimension.z, 0.f, 0.f, 0.f, blockMaterial); + kernel.setPrimitive(nbPrimitives, position.x, dimension.y, position.z, + dimension.x, dimension.y, position.z, dimension.x, + dimension.y, dimension.z, 0.f, 0.f, 0.f, + blockMaterial); nbPrimitives = kernel.addPrimitive(ptTriangle); - kernel.setPrimitive(nbPrimitives, dimension.x, dimension.y, dimension.z, position.x, dimension.y, dimension.z, - position.x, dimension.y, position.z, 0.f, 0.f, 0.f, blockMaterial); + kernel.setPrimitive(nbPrimitives, dimension.x, dimension.y, dimension.z, + position.x, dimension.y, dimension.z, position.x, + dimension.y, position.z, 0.f, 0.f, 0.f, + blockMaterial); #else // Blocks @@ -275,11 +295,15 @@ vec4f MapReader::loadFromFile(const std::string &filename, GPUKernel &kernel) case 19: { int nbPrimitives = kernel.addPrimitive(ptTriangle); - kernel.setPrimitive(nbPrimitives, position.x, position.y, position.z, dimension.x, position.y, position.z, - dimension.x, position.y, dimension.z, 0.f, 0.f, 0.f, zoneMaterial, 1, 1); + kernel.setPrimitive(nbPrimitives, position.x, position.y, + position.z, dimension.x, position.y, position.z, + dimension.x, position.y, dimension.z, 0.f, 0.f, + 0.f, zoneMaterial, 1, 1); nbPrimitives = kernel.addPrimitive(ptTriangle); - kernel.setPrimitive(nbPrimitives, dimension.x, position.y, dimension.z, position.x, position.y, dimension.z, - position.x, position.y, position.z, 0.f, 0.f, 0.f, zoneMaterial, 1, 1); + kernel.setPrimitive(nbPrimitives, dimension.x, position.y, + dimension.z, position.x, position.y, + dimension.z, position.x, position.y, position.z, + 0.f, 0.f, 0.f, zoneMaterial, 1, 1); break; } default: @@ -297,4 +321,4 @@ vec4f MapReader::loadFromFile(const std::string &filename, GPUKernel &kernel) objectSize.z = (maxPos.z - minPos.z); return objectSize; } -} +} // namespace solr diff --git a/solr/games/MapReader.h b/solr/games/MapReader.h index 0c3458c..ac675c5 100644 --- a/solr/games/MapReader.h +++ b/solr/games/MapReader.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once @@ -76,4 +73,4 @@ class SOLR_API MapReader vec4f loadFromFile(const std::string &filename, GPUKernel &cudaKernel); }; -} +} // namespace solr diff --git a/solr/images/ImageLoader.cpp b/solr/images/ImageLoader.cpp index 6fa3b0b..66fce4a 100644 --- a/solr/images/ImageLoader.cpp +++ b/solr/images/ImageLoader.cpp @@ -1,27 +1,24 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include -#include "../Consts.h" #include "../Logging.h" +#include "../consts.h" #include "ImageLoader.h" @@ -59,15 +56,12 @@ typedef struct tagBITMAPINFOHEADER } BITMAPINFOHEADER, *PBITMAPINFOHEADER; #endif // WIN32 -ImageLoader::ImageLoader(void) -{ -} +ImageLoader::ImageLoader(void) {} -ImageLoader::~ImageLoader(void) -{ -} +ImageLoader::~ImageLoader(void) {} -bool ImageLoader::loadBMP24(const int index, const std::string &filename, TextureInfo *textureInformations) +bool ImageLoader::loadBMP24(const int index, const std::string &filename, + TextureInfo *textureInformations) { FILE *filePtr(0); // our file pointer BITMAPFILEHEADER bitmapFileHeader; // our bitmap file header @@ -88,7 +82,8 @@ bool ImageLoader::loadBMP24(const int index, const std::string &filename, Textur } // read the bitmap file header - size_t status = fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr); + size_t status = + fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr); // verify that this is a bmp file by check bitmap id if (bitmapFileHeader.bfType != 0x4D42) @@ -104,7 +99,9 @@ bool ImageLoader::loadBMP24(const int index, const std::string &filename, Textur // move file point to the begging of bitmap data fseek(filePtr, bitmapFileHeader.bfOffBits, SEEK_SET); - unsigned int bitmapSize = bitmapInfoHeader.biWidth * bitmapInfoHeader.biHeight * bitmapInfoHeader.biBitCount / 8; + unsigned int bitmapSize = bitmapInfoHeader.biWidth * + bitmapInfoHeader.biHeight * + bitmapInfoHeader.biBitCount / 8; // Add Texture to CPU Memory if (textureInformations[index].buffer != 0) @@ -123,7 +120,8 @@ bool ImageLoader::loadBMP24(const int index, const std::string &filename, Textur { free(textureInformations[index].buffer); fclose(filePtr); - LOG_ERROR("Failed to load " << filename << ", invalid memory allocation"); + LOG_ERROR("Failed to load " << filename + << ", invalid memory allocation"); return false; } @@ -134,7 +132,8 @@ bool ImageLoader::loadBMP24(const int index, const std::string &filename, Textur if (textureInformations[index].buffer == NULL) { fclose(filePtr); - LOG_ERROR("Failed to load " << filename << ", bitmap image could not be read"); + LOG_ERROR("Failed to load " << filename + << ", bitmap image could not be read"); return false; } @@ -142,36 +141,47 @@ bool ImageLoader::loadBMP24(const int index, const std::string &filename, Textur for (imageIdx = 0; imageIdx < bitmapSize; imageIdx += 3) { tempRGB = textureInformations[index].buffer[imageIdx]; - textureInformations[index].buffer[imageIdx] = textureInformations[index].buffer[imageIdx + 2]; + textureInformations[index].buffer[imageIdx] = + textureInformations[index].buffer[imageIdx + 2]; textureInformations[index].buffer[imageIdx + 2] = tempRGB; } // close file and return bitmap image data fclose(filePtr); - LOG_INFO(3, "[" << index << "] Successfully loaded " << filename << std::endl - << "biSize : " << bitmapInfoHeader.biSize << std::endl - << "biWidth : " << bitmapInfoHeader.biWidth << std::endl - << "biHeight : " << bitmapInfoHeader.biHeight << std::endl - << "biPlanes : " << bitmapInfoHeader.biPlanes << std::endl - << "biBitCount : " << bitmapInfoHeader.biBitCount << std::endl - << "biCompression : " << bitmapInfoHeader.biCompression << std::endl - << "biSizeImage : " << bitmapSize << "/" << bitmapInfoHeader.biSizeImage << std::endl - << "biXPelsPerMeter: " << bitmapInfoHeader.biXPelsPerMeter << std::endl - << "biXPelsPerMeter: " << bitmapInfoHeader.biYPelsPerMeter); - - LOG_INFO(3, "Slot " << index << ": Successfully loaded texture " << filename << " (" - << textureInformations[index].size.x << "," << textureInformations[index].size.y << "," + LOG_INFO(3, + "[" << index << "] Successfully loaded " << filename << std::endl + << "biSize : " << bitmapInfoHeader.biSize << std::endl + << "biWidth : " << bitmapInfoHeader.biWidth << std::endl + << "biHeight : " << bitmapInfoHeader.biHeight + << std::endl + << "biPlanes : " << bitmapInfoHeader.biPlanes + << std::endl + << "biBitCount : " << bitmapInfoHeader.biBitCount + << std::endl + << "biCompression : " << bitmapInfoHeader.biCompression + << std::endl + << "biSizeImage : " << bitmapSize << "/" + << bitmapInfoHeader.biSizeImage << std::endl + << "biXPelsPerMeter: " << bitmapInfoHeader.biXPelsPerMeter + << std::endl + << "biXPelsPerMeter: " << bitmapInfoHeader.biYPelsPerMeter); + + LOG_INFO(3, "Slot " << index << ": Successfully loaded texture " << filename + << " (" << textureInformations[index].size.x << "," + << textureInformations[index].size.y << "," << textureInformations[index].size.z << ")"); return true; } -bool ImageLoader::loadJPEG(const int index, const std::string &filename, TextureInfo *textureInformations) +bool ImageLoader::loadJPEG(const int index, const std::string &filename, + TextureInfo *textureInformations) { int width, height, actual_comps, req_comps(3); BitmapBuffer *buffer = - jpgd::decompress_jpeg_image_from_file(filename.c_str(), &width, &height, &actual_comps, req_comps); + jpgd::decompress_jpeg_image_from_file(filename.c_str(), &width, &height, + &actual_comps, req_comps); if (buffer != 0) { @@ -200,8 +210,10 @@ bool ImageLoader::loadJPEG(const int index, const std::string &filename, Texture textureInformations[index].size.z = actual_comps; textureInformations[index].offset = 0; - LOG_INFO(3, "Slot " << index << ": Successfully loaded texture " << filename << " (" - << textureInformations[index].size.x << "," << textureInformations[index].size.y << "," + LOG_INFO(3, "Slot " << index << ": Successfully loaded texture " + << filename << " (" + << textureInformations[index].size.x << "," + << textureInformations[index].size.y << "," << textureInformations[index].size.z << ")"); return true; @@ -209,7 +221,8 @@ bool ImageLoader::loadJPEG(const int index, const std::string &filename, Texture return false; } -bool ImageLoader::loadTGA(const int index, const std::string &filename, TextureInfo *textureInformations) +bool ImageLoader::loadTGA(const int index, const std::string &filename, + TextureInfo *textureInformations) { #if 0 TGAFILE tgaFile; @@ -311,10 +324,11 @@ bool ImageLoader::loadTGA(const int index, const std::string &filename, TextureI textureInformations[index].size.z = texture.bpp / 8; #endif - LOG_INFO(3, "Slot " << index << ": Successfully loaded texture " << filename << " (" - << textureInformations[index].size.x << "," << textureInformations[index].size.y << "," + LOG_INFO(3, "Slot " << index << ": Successfully loaded texture " << filename + << " (" << textureInformations[index].size.x << "," + << textureInformations[index].size.y << "," << textureInformations[index].size.z << ")"); return true; } -} +} // namespace solr diff --git a/solr/images/ImageLoader.h b/solr/images/ImageLoader.h index a062048..032dec3 100644 --- a/solr/images/ImageLoader.h +++ b/solr/images/ImageLoader.h @@ -1,28 +1,25 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once -#include +#include #include -#include +#include namespace solr { @@ -42,13 +39,16 @@ class ImageLoader public: // BITMAP - bool loadBMP24(const int index, const std::string &filename, TextureInfo *textureInformations); + bool loadBMP24(const int index, const std::string &filename, + TextureInfo *textureInformations); // JPEG // https://code.google.com/p/jpeg-compressor - bool loadJPEG(const int index, const std::string &filename, TextureInfo *textureInformations); + bool loadJPEG(const int index, const std::string &filename, + TextureInfo *textureInformations); // TGA - bool loadTGA(const int index, const std::string &filename, TextureInfo *textureInformations); + bool loadTGA(const int index, const std::string &filename, + TextureInfo *textureInformations); }; -} +} // namespace solr diff --git a/solr/images/jpgd.cpp b/solr/images/jpgd.cpp index fc9aabc..9e01fe7 100644 --- a/solr/images/jpgd.cpp +++ b/solr/images/jpgd.cpp @@ -1,13 +1,15 @@ // jpgd.cpp - C++ class for JPEG decompression. // Public domain, Rich Geldreich // Alex Evans: Linear memory allocator (taken from jpge.h). -// v1.04, May. 19, 2012: Code tweaks to fix VS2008 static code analysis warnings (all looked harmless) +// v1.04, May. 19, 2012: Code tweaks to fix VS2008 static code analysis warnings +// (all looked harmless) // -// Supports progressive and baseline sequential JPEG image files, and the most common chroma subsampling factors: Y, -// H1V1, H2V1, H1V2, and H2V2. +// Supports progressive and baseline sequential JPEG image files, and the most +// common chroma subsampling factors: Y, H1V1, H2V1, H1V2, and H2V2. // -// Chroma upsampling quality: H2V2 is upsampled in the frequency domain, H2V1 and H1V2 are upsampled using point -// sampling. Chroma upsampling reference: "Fast Scheme for Image Size Change in the Compressed Domain" +// Chroma upsampling quality: H2V2 is upsampled in the frequency domain, H2V1 +// and H1V2 are upsampled using point sampling. Chroma upsampling reference: +// "Fast Scheme for Image Size Change in the Compressed Domain" // http://vision.ai.uiuc.edu/~dugad/research/dct/index.html #include "jpgd.h" @@ -17,12 +19,13 @@ #define JPGD_ASSERT(x) assert(x) #ifdef _MSC_VER -#pragma warning( \ - disable : 4611) // warning C4611: interaction between '_setjmp' and C++ object destruction is non-portable +#pragma warning(disable : 4611) // warning C4611: interaction between '_setjmp' + // and C++ object destruction is non-portable #endif -// Set to 1 to enable freq. domain chroma upsampling on images using H2V2 subsampling (0=faster nearest neighbor -// sampling). This is slower, but results in higher quality on images with highly saturated colors. +// Set to 1 to enable freq. domain chroma upsampling on images using H2V2 +// subsampling (0=faster nearest neighbor sampling). This is slower, but results +// in higher quality on images with highly saturated colors. #define JPGD_SUPPORT_FREQ_DOMAIN_UPSAMPLING 1 #define JPGD_TRUE (1) @@ -43,9 +46,11 @@ static inline void jpgd_free(void *p) } // DCT coefficients are stored in this sequence. -static int g_ZAG[64] = {0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5, 12, 19, 26, 33, 40, 48, - 41, 34, 27, 20, 13, 6, 7, 14, 21, 28, 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, - 30, 37, 44, 51, 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63}; +static int g_ZAG[64] = {0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, + 11, 4, 5, 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, + 13, 6, 7, 14, 21, 28, 35, 42, 49, 56, 57, 50, 43, + 36, 29, 22, 15, 23, 30, 37, 44, 51, 58, 59, 52, 45, + 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63}; enum JPEG_MARKER { @@ -118,7 +123,8 @@ enum JPEG_SUBSAMPLING #define FIX_3_072711026 ((int32)25172) /* FIX(3.072711026) */ #define DESCALE(x, n) (((x) + (SCALEDONE << ((n)-1))) >> (n)) -#define DESCALE_ZEROSHIFT(x, n) (((x) + (128 << (n)) + (SCALEDONE << ((n)-1))) >> (n)) +#define DESCALE_ZEROSHIFT(x, n) \ + (((x) + (128 << (n)) + (SCALEDONE << ((n)-1))) >> (n)) #define MULTIPLY(var, cnst) ((var) * (cnst)) @@ -130,7 +136,8 @@ struct Row { static void idct(int *pTemp, const jpgd_block_t *pSrc) { -// ACCESS_COL() will be optimized at compile time to either an array access, or 0. +// ACCESS_COL() will be optimized at compile time to either an array access, or +// 0. #define ACCESS_COL(x) (((x) < NONZERO_COLS) ? (int)pSrc[x] : 0) const int z2 = ACCESS_COL(2), z3 = ACCESS_COL(6); @@ -142,11 +149,14 @@ struct Row const int tmp0 = (ACCESS_COL(0) + ACCESS_COL(4)) << CONST_BITS; const int tmp1 = (ACCESS_COL(0) - ACCESS_COL(4)) << CONST_BITS; - const int tmp10 = tmp0 + tmp3, tmp13 = tmp0 - tmp3, tmp11 = tmp1 + tmp2, tmp12 = tmp1 - tmp2; + const int tmp10 = tmp0 + tmp3, tmp13 = tmp0 - tmp3, tmp11 = tmp1 + tmp2, + tmp12 = tmp1 - tmp2; - const int atmp0 = ACCESS_COL(7), atmp1 = ACCESS_COL(5), atmp2 = ACCESS_COL(3), atmp3 = ACCESS_COL(1); + const int atmp0 = ACCESS_COL(7), atmp1 = ACCESS_COL(5), + atmp2 = ACCESS_COL(3), atmp3 = ACCESS_COL(1); - const int bz1 = atmp0 + atmp3, bz2 = atmp1 + atmp2, bz3 = atmp0 + atmp2, bz4 = atmp1 + atmp3; + const int bz1 = atmp0 + atmp3, bz2 = atmp1 + atmp2, bz3 = atmp0 + atmp2, + bz4 = atmp1 + atmp3; const int bz5 = MULTIPLY(bz3 + bz4, FIX_1_175875602); const int az1 = MULTIPLY(bz1, -FIX_0_899976223); @@ -206,7 +216,8 @@ struct Col { static void idct(uint8 *pDst_ptr, const int *pTemp) { -// ACCESS_ROW() will be optimized at compile time to either an array access, or 0. +// ACCESS_ROW() will be optimized at compile time to either an array access, or +// 0. #define ACCESS_ROW(x) (((x) < NONZERO_ROWS) ? pTemp[x * 8] : 0) const int z2 = ACCESS_ROW(2); @@ -219,11 +230,14 @@ struct Col const int tmp0 = (ACCESS_ROW(0) + ACCESS_ROW(4)) << CONST_BITS; const int tmp1 = (ACCESS_ROW(0) - ACCESS_ROW(4)) << CONST_BITS; - const int tmp10 = tmp0 + tmp3, tmp13 = tmp0 - tmp3, tmp11 = tmp1 + tmp2, tmp12 = tmp1 - tmp2; + const int tmp10 = tmp0 + tmp3, tmp13 = tmp0 - tmp3, tmp11 = tmp1 + tmp2, + tmp12 = tmp1 - tmp2; - const int atmp0 = ACCESS_ROW(7), atmp1 = ACCESS_ROW(5), atmp2 = ACCESS_ROW(3), atmp3 = ACCESS_ROW(1); + const int atmp0 = ACCESS_ROW(7), atmp1 = ACCESS_ROW(5), + atmp2 = ACCESS_ROW(3), atmp3 = ACCESS_ROW(1); - const int bz1 = atmp0 + atmp3, bz2 = atmp1 + atmp2, bz3 = atmp0 + atmp2, bz4 = atmp1 + atmp3; + const int bz1 = atmp0 + atmp3, bz2 = atmp1 + atmp2, bz3 = atmp0 + atmp2, + bz4 = atmp1 + atmp3; const int bz5 = MULTIPLY(bz3 + bz4, FIX_1_175875602); const int az1 = MULTIPLY(bz1, -FIX_0_899976223); @@ -281,25 +295,34 @@ struct Col<1> }; static const uint8 s_idct_row_table[] = { - 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 0, 0, 0, 0, 0, 2, 1, 1, 0, 0, 0, 0, 0, 2, 2, 1, 0, 0, - 0, 0, 0, 3, 2, 1, 0, 0, 0, 0, 0, 4, 2, 1, 0, 0, 0, 0, 0, 4, 3, 1, 0, 0, 0, 0, 0, 4, 3, 2, 0, 0, 0, 0, 0, 4, 3, - 2, 1, 0, 0, 0, 0, 4, 3, 2, 1, 1, 0, 0, 0, 4, 3, 2, 2, 1, 0, 0, 0, 4, 3, 3, 2, 1, 0, 0, 0, 4, 4, 3, 2, 1, 0, 0, - 0, 5, 4, 3, 2, 1, 0, 0, 0, 6, 4, 3, 2, 1, 0, 0, 0, 6, 5, 3, 2, 1, 0, 0, 0, 6, 5, 4, 2, 1, 0, 0, 0, 6, 5, 4, 3, - 1, 0, 0, 0, 6, 5, 4, 3, 2, 0, 0, 0, 6, 5, 4, 3, 2, 1, 0, 0, 6, 5, 4, 3, 2, 1, 1, 0, 6, 5, 4, 3, 2, 2, 1, 0, 6, - 5, 4, 3, 3, 2, 1, 0, 6, 5, 4, 4, 3, 2, 1, 0, 6, 5, 5, 4, 3, 2, 1, 0, 6, 6, 5, 4, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, - 1, 0, 8, 6, 5, 4, 3, 2, 1, 0, 8, 7, 5, 4, 3, 2, 1, 0, 8, 7, 6, 4, 3, 2, 1, 0, 8, 7, 6, 5, 3, 2, 1, 0, 8, 7, 6, - 5, 4, 2, 1, 0, 8, 7, 6, 5, 4, 3, 1, 0, 8, 7, 6, 5, 4, 3, 2, 0, 8, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 2, - 8, 7, 6, 5, 4, 3, 3, 2, 8, 7, 6, 5, 4, 4, 3, 2, 8, 7, 6, 5, 5, 4, 3, 2, 8, 7, 6, 6, 5, 4, 3, 2, 8, 7, 7, 6, 5, - 4, 3, 2, 8, 8, 7, 6, 5, 4, 3, 2, 8, 8, 8, 6, 5, 4, 3, 2, 8, 8, 8, 7, 5, 4, 3, 2, 8, 8, 8, 7, 6, 4, 3, 2, 8, 8, - 8, 7, 6, 5, 3, 2, 8, 8, 8, 7, 6, 5, 4, 2, 8, 8, 8, 7, 6, 5, 4, 3, 8, 8, 8, 7, 6, 5, 4, 4, 8, 8, 8, 7, 6, 5, 5, - 4, 8, 8, 8, 7, 6, 6, 5, 4, 8, 8, 8, 7, 7, 6, 5, 4, 8, 8, 8, 8, 7, 6, 5, 4, 8, 8, 8, 8, 8, 6, 5, 4, 8, 8, 8, 8, - 8, 7, 5, 4, 8, 8, 8, 8, 8, 7, 6, 4, 8, 8, 8, 8, 8, 7, 6, 5, 8, 8, 8, 8, 8, 7, 6, 6, 8, 8, 8, 8, 8, 7, 7, 6, 8, - 8, 8, 8, 8, 8, 7, 6, 8, 8, 8, 8, 8, 8, 8, 6, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, + 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 0, 0, 0, 0, 0, 2, + 1, 1, 0, 0, 0, 0, 0, 2, 2, 1, 0, 0, 0, 0, 0, 3, 2, 1, 0, 0, 0, 0, 0, 4, 2, + 1, 0, 0, 0, 0, 0, 4, 3, 1, 0, 0, 0, 0, 0, 4, 3, 2, 0, 0, 0, 0, 0, 4, 3, 2, + 1, 0, 0, 0, 0, 4, 3, 2, 1, 1, 0, 0, 0, 4, 3, 2, 2, 1, 0, 0, 0, 4, 3, 3, 2, + 1, 0, 0, 0, 4, 4, 3, 2, 1, 0, 0, 0, 5, 4, 3, 2, 1, 0, 0, 0, 6, 4, 3, 2, 1, + 0, 0, 0, 6, 5, 3, 2, 1, 0, 0, 0, 6, 5, 4, 2, 1, 0, 0, 0, 6, 5, 4, 3, 1, 0, + 0, 0, 6, 5, 4, 3, 2, 0, 0, 0, 6, 5, 4, 3, 2, 1, 0, 0, 6, 5, 4, 3, 2, 1, 1, + 0, 6, 5, 4, 3, 2, 2, 1, 0, 6, 5, 4, 3, 3, 2, 1, 0, 6, 5, 4, 4, 3, 2, 1, 0, + 6, 5, 5, 4, 3, 2, 1, 0, 6, 6, 5, 4, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1, 0, 8, + 6, 5, 4, 3, 2, 1, 0, 8, 7, 5, 4, 3, 2, 1, 0, 8, 7, 6, 4, 3, 2, 1, 0, 8, 7, + 6, 5, 3, 2, 1, 0, 8, 7, 6, 5, 4, 2, 1, 0, 8, 7, 6, 5, 4, 3, 1, 0, 8, 7, 6, + 5, 4, 3, 2, 0, 8, 7, 6, 5, 4, 3, 2, 1, 8, 7, 6, 5, 4, 3, 2, 2, 8, 7, 6, 5, + 4, 3, 3, 2, 8, 7, 6, 5, 4, 4, 3, 2, 8, 7, 6, 5, 5, 4, 3, 2, 8, 7, 6, 6, 5, + 4, 3, 2, 8, 7, 7, 6, 5, 4, 3, 2, 8, 8, 7, 6, 5, 4, 3, 2, 8, 8, 8, 6, 5, 4, + 3, 2, 8, 8, 8, 7, 5, 4, 3, 2, 8, 8, 8, 7, 6, 4, 3, 2, 8, 8, 8, 7, 6, 5, 3, + 2, 8, 8, 8, 7, 6, 5, 4, 2, 8, 8, 8, 7, 6, 5, 4, 3, 8, 8, 8, 7, 6, 5, 4, 4, + 8, 8, 8, 7, 6, 5, 5, 4, 8, 8, 8, 7, 6, 6, 5, 4, 8, 8, 8, 7, 7, 6, 5, 4, 8, + 8, 8, 8, 7, 6, 5, 4, 8, 8, 8, 8, 8, 6, 5, 4, 8, 8, 8, 8, 8, 7, 5, 4, 8, 8, + 8, 8, 8, 7, 6, 4, 8, 8, 8, 8, 8, 7, 6, 5, 8, 8, 8, 8, 8, 7, 6, 6, 8, 8, 8, + 8, 8, 7, 7, 6, 8, 8, 8, 8, 8, 8, 7, 6, 8, 8, 8, 8, 8, 8, 8, 6, 8, 8, 8, 8, + 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, }; -static const uint8 s_idct_col_table[] = {1, 1, 2, 3, 3, 3, 3, 3, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8}; +static const uint8 s_idct_col_table[] = {1, 1, 2, 3, 3, 3, 3, 3, 3, 4, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 6, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8}; void idct(const jpgd_block_t *pSrc_ptr, uint8 *pDst_ptr, int block_max_zag) { @@ -453,7 +476,8 @@ inline uint jpeg_decoder::get_char() return c; } -// Same as previous method, except can indicate if the character is a pad character or not. +// Same as previous method, except can indicate if the character is a pad +// character or not. inline uint jpeg_decoder::get_char(bool *pPadding_flag) { if (!m_in_buf_left) @@ -486,8 +510,8 @@ inline void jpeg_decoder::stuff_char(uint8 q) m_in_buf_left++; } -// Retrieves one character from the input stream, but does not read past markers. Will continue to return 0xFF when a -// marker is encountered. +// Retrieves one character from the input stream, but does not read past +// markers. Will continue to return 0xFF when a marker is encountered. inline uint8 jpeg_decoder::get_octet() { bool padding_flag; @@ -518,7 +542,8 @@ inline uint8 jpeg_decoder::get_octet() return static_cast(c); } -// Retrieves a variable number of bits from the input stream. Does not recognize markers. +// Retrieves a variable number of bits from the input stream. Does not recognize +// markers. inline uint jpeg_decoder::get_bits(int num_bits) { if (!num_bits) @@ -546,8 +571,9 @@ inline uint jpeg_decoder::get_bits(int num_bits) return i; } -// Retrieves a variable number of bits from the input stream. Markers will not be read into the input bit buffer. -// Instead, an infinite number of all 1's will be returned when a marker is encountered. +// Retrieves a variable number of bits from the input stream. Markers will not +// be read into the input bit buffer. Instead, an infinite number of all 1's +// will be returned when a marker is encountered. inline uint jpeg_decoder::get_bits_no_markers(int num_bits) { if (!num_bits) @@ -559,7 +585,8 @@ inline uint jpeg_decoder::get_bits_no_markers(int num_bits) { m_bit_buf <<= (num_bits += m_bits_left); - if ((m_in_buf_left < 2) || (m_pIn_buf_ofs[0] == 0xFF) || (m_pIn_buf_ofs[1] == 0xFF)) + if ((m_in_buf_left < 2) || (m_pIn_buf_ofs[0] == 0xFF) || + (m_pIn_buf_ofs[1] == 0xFF)) { uint c1 = get_octet(); uint c2 = get_octet(); @@ -630,7 +657,9 @@ inline int jpeg_decoder::huff_decode(huff_tables *pH, int &extra_bits) } else { - JPGD_ASSERT(((symbol >> 8) & 31) == pH->code_size[symbol & 255] + ((symbol & 0x8000) ? (symbol & 15) : 0)); + JPGD_ASSERT(((symbol >> 8) & 31) == + pH->code_size[symbol & 255] + + ((symbol & 0x8000) ? (symbol & 15) : 0)); if (symbol & 0x8000) { @@ -643,7 +672,8 @@ inline int jpeg_decoder::huff_decode(huff_tables *pH, int &extra_bits) int num_extra_bits = symbol & 0xF; int bits = code_size + num_extra_bits; if (bits <= (m_bits_left + 16)) - extra_bits = get_bits_no_markers(bits) & ((1 << num_extra_bits) - 1); + extra_bits = + get_bits_no_markers(bits) & ((1 << num_extra_bits) - 1); else { get_bits_no_markers(code_size); @@ -658,8 +688,10 @@ inline int jpeg_decoder::huff_decode(huff_tables *pH, int &extra_bits) } // Tables and macro used to fully decode the DPCM differences. -static const int s_extend_test[16] = {0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, - 0x0080, 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000}; +static const int s_extend_test[16] = {0, 0x0001, 0x0002, 0x0004, + 0x0008, 0x0010, 0x0020, 0x0040, + 0x0080, 0x0100, 0x0200, 0x0400, + 0x0800, 0x1000, 0x2000, 0x4000}; static const int s_extend_offset[16] = {0, ((-1) << 1) + 1, ((-1) << 2) + 1, @@ -676,9 +708,10 @@ static const int s_extend_offset[16] = {0, ((-1) << 13) + 1, ((-1) << 14) + 1, ((-1) << 15) + 1}; -// The logical AND's in this macro are to shut up static code analysis (aren't really necessary - couldn't find another -// way to do this) -#define JPGD_HUFF_EXTEND(x, s) (((x) < s_extend_test[s & 15]) ? ((x) + s_extend_offset[s & 15]) : (x)) +// The logical AND's in this macro are to shut up static code analysis (aren't +// really necessary - couldn't find another way to do this) +#define JPGD_HUFF_EXTEND(x, s) \ + (((x) < s_extend_test[s & 15]) ? ((x) + s_extend_offset[s & 15]) : (x)) // Clamps a value between 0-255. inline uint8 jpeg_decoder::clamp(int i) @@ -760,25 +793,35 @@ struct Matrix44 return ret; } - static inline void add_and_store(jpgd_block_t *pDst, const Matrix44 &a, const Matrix44 &b) + static inline void add_and_store(jpgd_block_t *pDst, const Matrix44 &a, + const Matrix44 &b) { for (int r = 0; r < 4; r++) { - pDst[0 * 8 + r] = static_cast(a.at(r, 0) + b.at(r, 0)); - pDst[1 * 8 + r] = static_cast(a.at(r, 1) + b.at(r, 1)); - pDst[2 * 8 + r] = static_cast(a.at(r, 2) + b.at(r, 2)); - pDst[3 * 8 + r] = static_cast(a.at(r, 3) + b.at(r, 3)); + pDst[0 * 8 + r] = + static_cast(a.at(r, 0) + b.at(r, 0)); + pDst[1 * 8 + r] = + static_cast(a.at(r, 1) + b.at(r, 1)); + pDst[2 * 8 + r] = + static_cast(a.at(r, 2) + b.at(r, 2)); + pDst[3 * 8 + r] = + static_cast(a.at(r, 3) + b.at(r, 3)); } } - static inline void sub_and_store(jpgd_block_t *pDst, const Matrix44 &a, const Matrix44 &b) + static inline void sub_and_store(jpgd_block_t *pDst, const Matrix44 &a, + const Matrix44 &b) { for (int r = 0; r < 4; r++) { - pDst[0 * 8 + r] = static_cast(a.at(r, 0) - b.at(r, 0)); - pDst[1 * 8 + r] = static_cast(a.at(r, 1) - b.at(r, 1)); - pDst[2 * 8 + r] = static_cast(a.at(r, 2) - b.at(r, 2)); - pDst[3 * 8 + r] = static_cast(a.at(r, 3) - b.at(r, 3)); + pDst[0 * 8 + r] = + static_cast(a.at(r, 0) - b.at(r, 0)); + pDst[1 * 8 + r] = + static_cast(a.at(r, 1) - b.at(r, 1)); + pDst[2 * 8 + r] = + static_cast(a.at(r, 2) - b.at(r, 2)); + pDst[3 * 8 + r] = + static_cast(a.at(r, 3) - b.at(r, 3)); } } }; @@ -790,8 +833,10 @@ typedef int Temp_Type; #define D(i) (((i) + (SCALE >> 1)) >> FRACT_BITS) #define F(i) ((int)((i)*SCALE + .5f)) -// Any decent C++ compiler will optimize this at compile time to a 0, or an array access. -#define AT(c, r) ((((c) >= NUM_COLS) || ((r) >= NUM_ROWS)) ? 0 : pSrc[(c) + (r)*8]) +// Any decent C++ compiler will optimize this at compile time to a 0, or an +// array access. +#define AT(c, r) \ + ((((c) >= NUM_COLS) || ((r) >= NUM_ROWS)) ? 0 : pSrc[(c) + (r)*8]) // NUM_ROWS/NUM_COLS = # of non-zero rows/cols in input matrix template @@ -809,21 +854,29 @@ struct P_Q const Temp_Type X006 = AT(0, 6); const Temp_Type X007 = AT(0, 7); const Temp_Type X010 = - D(F(0.415735f) * AT(1, 0) + F(0.791065f) * AT(3, 0) + F(-0.352443f) * AT(5, 0) + F(0.277785f) * AT(7, 0)); + D(F(0.415735f) * AT(1, 0) + F(0.791065f) * AT(3, 0) + + F(-0.352443f) * AT(5, 0) + F(0.277785f) * AT(7, 0)); const Temp_Type X011 = - D(F(0.415735f) * AT(1, 1) + F(0.791065f) * AT(3, 1) + F(-0.352443f) * AT(5, 1) + F(0.277785f) * AT(7, 1)); + D(F(0.415735f) * AT(1, 1) + F(0.791065f) * AT(3, 1) + + F(-0.352443f) * AT(5, 1) + F(0.277785f) * AT(7, 1)); const Temp_Type X012 = - D(F(0.415735f) * AT(1, 2) + F(0.791065f) * AT(3, 2) + F(-0.352443f) * AT(5, 2) + F(0.277785f) * AT(7, 2)); + D(F(0.415735f) * AT(1, 2) + F(0.791065f) * AT(3, 2) + + F(-0.352443f) * AT(5, 2) + F(0.277785f) * AT(7, 2)); const Temp_Type X013 = - D(F(0.415735f) * AT(1, 3) + F(0.791065f) * AT(3, 3) + F(-0.352443f) * AT(5, 3) + F(0.277785f) * AT(7, 3)); + D(F(0.415735f) * AT(1, 3) + F(0.791065f) * AT(3, 3) + + F(-0.352443f) * AT(5, 3) + F(0.277785f) * AT(7, 3)); const Temp_Type X014 = - D(F(0.415735f) * AT(1, 4) + F(0.791065f) * AT(3, 4) + F(-0.352443f) * AT(5, 4) + F(0.277785f) * AT(7, 4)); + D(F(0.415735f) * AT(1, 4) + F(0.791065f) * AT(3, 4) + + F(-0.352443f) * AT(5, 4) + F(0.277785f) * AT(7, 4)); const Temp_Type X015 = - D(F(0.415735f) * AT(1, 5) + F(0.791065f) * AT(3, 5) + F(-0.352443f) * AT(5, 5) + F(0.277785f) * AT(7, 5)); + D(F(0.415735f) * AT(1, 5) + F(0.791065f) * AT(3, 5) + + F(-0.352443f) * AT(5, 5) + F(0.277785f) * AT(7, 5)); const Temp_Type X016 = - D(F(0.415735f) * AT(1, 6) + F(0.791065f) * AT(3, 6) + F(-0.352443f) * AT(5, 6) + F(0.277785f) * AT(7, 6)); + D(F(0.415735f) * AT(1, 6) + F(0.791065f) * AT(3, 6) + + F(-0.352443f) * AT(5, 6) + F(0.277785f) * AT(7, 6)); const Temp_Type X017 = - D(F(0.415735f) * AT(1, 7) + F(0.791065f) * AT(3, 7) + F(-0.352443f) * AT(5, 7) + F(0.277785f) * AT(7, 7)); + D(F(0.415735f) * AT(1, 7) + F(0.791065f) * AT(3, 7) + + F(-0.352443f) * AT(5, 7) + F(0.277785f) * AT(7, 7)); const Temp_Type X020 = AT(4, 0); const Temp_Type X021 = AT(4, 1); const Temp_Type X022 = AT(4, 2); @@ -833,57 +886,81 @@ struct P_Q const Temp_Type X026 = AT(4, 6); const Temp_Type X027 = AT(4, 7); const Temp_Type X030 = - D(F(0.022887f) * AT(1, 0) + F(-0.097545f) * AT(3, 0) + F(0.490393f) * AT(5, 0) + F(0.865723f) * AT(7, 0)); + D(F(0.022887f) * AT(1, 0) + F(-0.097545f) * AT(3, 0) + + F(0.490393f) * AT(5, 0) + F(0.865723f) * AT(7, 0)); const Temp_Type X031 = - D(F(0.022887f) * AT(1, 1) + F(-0.097545f) * AT(3, 1) + F(0.490393f) * AT(5, 1) + F(0.865723f) * AT(7, 1)); + D(F(0.022887f) * AT(1, 1) + F(-0.097545f) * AT(3, 1) + + F(0.490393f) * AT(5, 1) + F(0.865723f) * AT(7, 1)); const Temp_Type X032 = - D(F(0.022887f) * AT(1, 2) + F(-0.097545f) * AT(3, 2) + F(0.490393f) * AT(5, 2) + F(0.865723f) * AT(7, 2)); + D(F(0.022887f) * AT(1, 2) + F(-0.097545f) * AT(3, 2) + + F(0.490393f) * AT(5, 2) + F(0.865723f) * AT(7, 2)); const Temp_Type X033 = - D(F(0.022887f) * AT(1, 3) + F(-0.097545f) * AT(3, 3) + F(0.490393f) * AT(5, 3) + F(0.865723f) * AT(7, 3)); + D(F(0.022887f) * AT(1, 3) + F(-0.097545f) * AT(3, 3) + + F(0.490393f) * AT(5, 3) + F(0.865723f) * AT(7, 3)); const Temp_Type X034 = - D(F(0.022887f) * AT(1, 4) + F(-0.097545f) * AT(3, 4) + F(0.490393f) * AT(5, 4) + F(0.865723f) * AT(7, 4)); + D(F(0.022887f) * AT(1, 4) + F(-0.097545f) * AT(3, 4) + + F(0.490393f) * AT(5, 4) + F(0.865723f) * AT(7, 4)); const Temp_Type X035 = - D(F(0.022887f) * AT(1, 5) + F(-0.097545f) * AT(3, 5) + F(0.490393f) * AT(5, 5) + F(0.865723f) * AT(7, 5)); + D(F(0.022887f) * AT(1, 5) + F(-0.097545f) * AT(3, 5) + + F(0.490393f) * AT(5, 5) + F(0.865723f) * AT(7, 5)); const Temp_Type X036 = - D(F(0.022887f) * AT(1, 6) + F(-0.097545f) * AT(3, 6) + F(0.490393f) * AT(5, 6) + F(0.865723f) * AT(7, 6)); + D(F(0.022887f) * AT(1, 6) + F(-0.097545f) * AT(3, 6) + + F(0.490393f) * AT(5, 6) + F(0.865723f) * AT(7, 6)); const Temp_Type X037 = - D(F(0.022887f) * AT(1, 7) + F(-0.097545f) * AT(3, 7) + F(0.490393f) * AT(5, 7) + F(0.865723f) * AT(7, 7)); + D(F(0.022887f) * AT(1, 7) + F(-0.097545f) * AT(3, 7) + + F(0.490393f) * AT(5, 7) + F(0.865723f) * AT(7, 7)); // 4x4 = 4x8 times 8x4, matrix 1 is constant P.at(0, 0) = X000; - P.at(0, 1) = D(X001 * F(0.415735f) + X003 * F(0.791065f) + X005 * F(-0.352443f) + X007 * F(0.277785f)); + P.at(0, 1) = D(X001 * F(0.415735f) + X003 * F(0.791065f) + + X005 * F(-0.352443f) + X007 * F(0.277785f)); P.at(0, 2) = X004; - P.at(0, 3) = D(X001 * F(0.022887f) + X003 * F(-0.097545f) + X005 * F(0.490393f) + X007 * F(0.865723f)); + P.at(0, 3) = D(X001 * F(0.022887f) + X003 * F(-0.097545f) + + X005 * F(0.490393f) + X007 * F(0.865723f)); P.at(1, 0) = X010; - P.at(1, 1) = D(X011 * F(0.415735f) + X013 * F(0.791065f) + X015 * F(-0.352443f) + X017 * F(0.277785f)); + P.at(1, 1) = D(X011 * F(0.415735f) + X013 * F(0.791065f) + + X015 * F(-0.352443f) + X017 * F(0.277785f)); P.at(1, 2) = X014; - P.at(1, 3) = D(X011 * F(0.022887f) + X013 * F(-0.097545f) + X015 * F(0.490393f) + X017 * F(0.865723f)); + P.at(1, 3) = D(X011 * F(0.022887f) + X013 * F(-0.097545f) + + X015 * F(0.490393f) + X017 * F(0.865723f)); P.at(2, 0) = X020; - P.at(2, 1) = D(X021 * F(0.415735f) + X023 * F(0.791065f) + X025 * F(-0.352443f) + X027 * F(0.277785f)); + P.at(2, 1) = D(X021 * F(0.415735f) + X023 * F(0.791065f) + + X025 * F(-0.352443f) + X027 * F(0.277785f)); P.at(2, 2) = X024; - P.at(2, 3) = D(X021 * F(0.022887f) + X023 * F(-0.097545f) + X025 * F(0.490393f) + X027 * F(0.865723f)); + P.at(2, 3) = D(X021 * F(0.022887f) + X023 * F(-0.097545f) + + X025 * F(0.490393f) + X027 * F(0.865723f)); P.at(3, 0) = X030; - P.at(3, 1) = D(X031 * F(0.415735f) + X033 * F(0.791065f) + X035 * F(-0.352443f) + X037 * F(0.277785f)); + P.at(3, 1) = D(X031 * F(0.415735f) + X033 * F(0.791065f) + + X035 * F(-0.352443f) + X037 * F(0.277785f)); P.at(3, 2) = X034; - P.at(3, 3) = D(X031 * F(0.022887f) + X033 * F(-0.097545f) + X035 * F(0.490393f) + X037 * F(0.865723f)); + P.at(3, 3) = D(X031 * F(0.022887f) + X033 * F(-0.097545f) + + X035 * F(0.490393f) + X037 * F(0.865723f)); // 40 muls 24 adds // 4x4 = 4x8 times 8x4, matrix 1 is constant - Q.at(0, 0) = D(X001 * F(0.906127f) + X003 * F(-0.318190f) + X005 * F(0.212608f) + X007 * F(-0.180240f)); + Q.at(0, 0) = D(X001 * F(0.906127f) + X003 * F(-0.318190f) + + X005 * F(0.212608f) + X007 * F(-0.180240f)); Q.at(0, 1) = X002; - Q.at(0, 2) = D(X001 * F(-0.074658f) + X003 * F(0.513280f) + X005 * F(0.768178f) + X007 * F(-0.375330f)); + Q.at(0, 2) = D(X001 * F(-0.074658f) + X003 * F(0.513280f) + + X005 * F(0.768178f) + X007 * F(-0.375330f)); Q.at(0, 3) = X006; - Q.at(1, 0) = D(X011 * F(0.906127f) + X013 * F(-0.318190f) + X015 * F(0.212608f) + X017 * F(-0.180240f)); + Q.at(1, 0) = D(X011 * F(0.906127f) + X013 * F(-0.318190f) + + X015 * F(0.212608f) + X017 * F(-0.180240f)); Q.at(1, 1) = X012; - Q.at(1, 2) = D(X011 * F(-0.074658f) + X013 * F(0.513280f) + X015 * F(0.768178f) + X017 * F(-0.375330f)); + Q.at(1, 2) = D(X011 * F(-0.074658f) + X013 * F(0.513280f) + + X015 * F(0.768178f) + X017 * F(-0.375330f)); Q.at(1, 3) = X016; - Q.at(2, 0) = D(X021 * F(0.906127f) + X023 * F(-0.318190f) + X025 * F(0.212608f) + X027 * F(-0.180240f)); + Q.at(2, 0) = D(X021 * F(0.906127f) + X023 * F(-0.318190f) + + X025 * F(0.212608f) + X027 * F(-0.180240f)); Q.at(2, 1) = X022; - Q.at(2, 2) = D(X021 * F(-0.074658f) + X023 * F(0.513280f) + X025 * F(0.768178f) + X027 * F(-0.375330f)); + Q.at(2, 2) = D(X021 * F(-0.074658f) + X023 * F(0.513280f) + + X025 * F(0.768178f) + X027 * F(-0.375330f)); Q.at(2, 3) = X026; - Q.at(3, 0) = D(X031 * F(0.906127f) + X033 * F(-0.318190f) + X035 * F(0.212608f) + X037 * F(-0.180240f)); + Q.at(3, 0) = D(X031 * F(0.906127f) + X033 * F(-0.318190f) + + X035 * F(0.212608f) + X037 * F(-0.180240f)); Q.at(3, 1) = X032; - Q.at(3, 2) = D(X031 * F(-0.074658f) + X033 * F(0.513280f) + X035 * F(0.768178f) + X037 * F(-0.375330f)); + Q.at(3, 2) = D(X031 * F(-0.074658f) + X033 * F(0.513280f) + + X035 * F(0.768178f) + X037 * F(-0.375330f)); Q.at(3, 3) = X036; // 40 muls 24 adds } @@ -896,21 +973,29 @@ struct R_S { // 4x8 = 4x8 times 8x8, matrix 0 is constant const Temp_Type X100 = - D(F(0.906127f) * AT(1, 0) + F(-0.318190f) * AT(3, 0) + F(0.212608f) * AT(5, 0) + F(-0.180240f) * AT(7, 0)); + D(F(0.906127f) * AT(1, 0) + F(-0.318190f) * AT(3, 0) + + F(0.212608f) * AT(5, 0) + F(-0.180240f) * AT(7, 0)); const Temp_Type X101 = - D(F(0.906127f) * AT(1, 1) + F(-0.318190f) * AT(3, 1) + F(0.212608f) * AT(5, 1) + F(-0.180240f) * AT(7, 1)); + D(F(0.906127f) * AT(1, 1) + F(-0.318190f) * AT(3, 1) + + F(0.212608f) * AT(5, 1) + F(-0.180240f) * AT(7, 1)); const Temp_Type X102 = - D(F(0.906127f) * AT(1, 2) + F(-0.318190f) * AT(3, 2) + F(0.212608f) * AT(5, 2) + F(-0.180240f) * AT(7, 2)); + D(F(0.906127f) * AT(1, 2) + F(-0.318190f) * AT(3, 2) + + F(0.212608f) * AT(5, 2) + F(-0.180240f) * AT(7, 2)); const Temp_Type X103 = - D(F(0.906127f) * AT(1, 3) + F(-0.318190f) * AT(3, 3) + F(0.212608f) * AT(5, 3) + F(-0.180240f) * AT(7, 3)); + D(F(0.906127f) * AT(1, 3) + F(-0.318190f) * AT(3, 3) + + F(0.212608f) * AT(5, 3) + F(-0.180240f) * AT(7, 3)); const Temp_Type X104 = - D(F(0.906127f) * AT(1, 4) + F(-0.318190f) * AT(3, 4) + F(0.212608f) * AT(5, 4) + F(-0.180240f) * AT(7, 4)); + D(F(0.906127f) * AT(1, 4) + F(-0.318190f) * AT(3, 4) + + F(0.212608f) * AT(5, 4) + F(-0.180240f) * AT(7, 4)); const Temp_Type X105 = - D(F(0.906127f) * AT(1, 5) + F(-0.318190f) * AT(3, 5) + F(0.212608f) * AT(5, 5) + F(-0.180240f) * AT(7, 5)); + D(F(0.906127f) * AT(1, 5) + F(-0.318190f) * AT(3, 5) + + F(0.212608f) * AT(5, 5) + F(-0.180240f) * AT(7, 5)); const Temp_Type X106 = - D(F(0.906127f) * AT(1, 6) + F(-0.318190f) * AT(3, 6) + F(0.212608f) * AT(5, 6) + F(-0.180240f) * AT(7, 6)); + D(F(0.906127f) * AT(1, 6) + F(-0.318190f) * AT(3, 6) + + F(0.212608f) * AT(5, 6) + F(-0.180240f) * AT(7, 6)); const Temp_Type X107 = - D(F(0.906127f) * AT(1, 7) + F(-0.318190f) * AT(3, 7) + F(0.212608f) * AT(5, 7) + F(-0.180240f) * AT(7, 7)); + D(F(0.906127f) * AT(1, 7) + F(-0.318190f) * AT(3, 7) + + F(0.212608f) * AT(5, 7) + F(-0.180240f) * AT(7, 7)); const Temp_Type X110 = AT(2, 0); const Temp_Type X111 = AT(2, 1); const Temp_Type X112 = AT(2, 2); @@ -920,21 +1005,29 @@ struct R_S const Temp_Type X116 = AT(2, 6); const Temp_Type X117 = AT(2, 7); const Temp_Type X120 = - D(F(-0.074658f) * AT(1, 0) + F(0.513280f) * AT(3, 0) + F(0.768178f) * AT(5, 0) + F(-0.375330f) * AT(7, 0)); + D(F(-0.074658f) * AT(1, 0) + F(0.513280f) * AT(3, 0) + + F(0.768178f) * AT(5, 0) + F(-0.375330f) * AT(7, 0)); const Temp_Type X121 = - D(F(-0.074658f) * AT(1, 1) + F(0.513280f) * AT(3, 1) + F(0.768178f) * AT(5, 1) + F(-0.375330f) * AT(7, 1)); + D(F(-0.074658f) * AT(1, 1) + F(0.513280f) * AT(3, 1) + + F(0.768178f) * AT(5, 1) + F(-0.375330f) * AT(7, 1)); const Temp_Type X122 = - D(F(-0.074658f) * AT(1, 2) + F(0.513280f) * AT(3, 2) + F(0.768178f) * AT(5, 2) + F(-0.375330f) * AT(7, 2)); + D(F(-0.074658f) * AT(1, 2) + F(0.513280f) * AT(3, 2) + + F(0.768178f) * AT(5, 2) + F(-0.375330f) * AT(7, 2)); const Temp_Type X123 = - D(F(-0.074658f) * AT(1, 3) + F(0.513280f) * AT(3, 3) + F(0.768178f) * AT(5, 3) + F(-0.375330f) * AT(7, 3)); + D(F(-0.074658f) * AT(1, 3) + F(0.513280f) * AT(3, 3) + + F(0.768178f) * AT(5, 3) + F(-0.375330f) * AT(7, 3)); const Temp_Type X124 = - D(F(-0.074658f) * AT(1, 4) + F(0.513280f) * AT(3, 4) + F(0.768178f) * AT(5, 4) + F(-0.375330f) * AT(7, 4)); + D(F(-0.074658f) * AT(1, 4) + F(0.513280f) * AT(3, 4) + + F(0.768178f) * AT(5, 4) + F(-0.375330f) * AT(7, 4)); const Temp_Type X125 = - D(F(-0.074658f) * AT(1, 5) + F(0.513280f) * AT(3, 5) + F(0.768178f) * AT(5, 5) + F(-0.375330f) * AT(7, 5)); + D(F(-0.074658f) * AT(1, 5) + F(0.513280f) * AT(3, 5) + + F(0.768178f) * AT(5, 5) + F(-0.375330f) * AT(7, 5)); const Temp_Type X126 = - D(F(-0.074658f) * AT(1, 6) + F(0.513280f) * AT(3, 6) + F(0.768178f) * AT(5, 6) + F(-0.375330f) * AT(7, 6)); + D(F(-0.074658f) * AT(1, 6) + F(0.513280f) * AT(3, 6) + + F(0.768178f) * AT(5, 6) + F(-0.375330f) * AT(7, 6)); const Temp_Type X127 = - D(F(-0.074658f) * AT(1, 7) + F(0.513280f) * AT(3, 7) + F(0.768178f) * AT(5, 7) + F(-0.375330f) * AT(7, 7)); + D(F(-0.074658f) * AT(1, 7) + F(0.513280f) * AT(3, 7) + + F(0.768178f) * AT(5, 7) + F(-0.375330f) * AT(7, 7)); const Temp_Type X130 = AT(6, 0); const Temp_Type X131 = AT(6, 1); const Temp_Type X132 = AT(6, 2); @@ -947,38 +1040,54 @@ struct R_S // 4x4 = 4x8 times 8x4, matrix 1 is constant R.at(0, 0) = X100; - R.at(0, 1) = D(X101 * F(0.415735f) + X103 * F(0.791065f) + X105 * F(-0.352443f) + X107 * F(0.277785f)); + R.at(0, 1) = D(X101 * F(0.415735f) + X103 * F(0.791065f) + + X105 * F(-0.352443f) + X107 * F(0.277785f)); R.at(0, 2) = X104; - R.at(0, 3) = D(X101 * F(0.022887f) + X103 * F(-0.097545f) + X105 * F(0.490393f) + X107 * F(0.865723f)); + R.at(0, 3) = D(X101 * F(0.022887f) + X103 * F(-0.097545f) + + X105 * F(0.490393f) + X107 * F(0.865723f)); R.at(1, 0) = X110; - R.at(1, 1) = D(X111 * F(0.415735f) + X113 * F(0.791065f) + X115 * F(-0.352443f) + X117 * F(0.277785f)); + R.at(1, 1) = D(X111 * F(0.415735f) + X113 * F(0.791065f) + + X115 * F(-0.352443f) + X117 * F(0.277785f)); R.at(1, 2) = X114; - R.at(1, 3) = D(X111 * F(0.022887f) + X113 * F(-0.097545f) + X115 * F(0.490393f) + X117 * F(0.865723f)); + R.at(1, 3) = D(X111 * F(0.022887f) + X113 * F(-0.097545f) + + X115 * F(0.490393f) + X117 * F(0.865723f)); R.at(2, 0) = X120; - R.at(2, 1) = D(X121 * F(0.415735f) + X123 * F(0.791065f) + X125 * F(-0.352443f) + X127 * F(0.277785f)); + R.at(2, 1) = D(X121 * F(0.415735f) + X123 * F(0.791065f) + + X125 * F(-0.352443f) + X127 * F(0.277785f)); R.at(2, 2) = X124; - R.at(2, 3) = D(X121 * F(0.022887f) + X123 * F(-0.097545f) + X125 * F(0.490393f) + X127 * F(0.865723f)); + R.at(2, 3) = D(X121 * F(0.022887f) + X123 * F(-0.097545f) + + X125 * F(0.490393f) + X127 * F(0.865723f)); R.at(3, 0) = X130; - R.at(3, 1) = D(X131 * F(0.415735f) + X133 * F(0.791065f) + X135 * F(-0.352443f) + X137 * F(0.277785f)); + R.at(3, 1) = D(X131 * F(0.415735f) + X133 * F(0.791065f) + + X135 * F(-0.352443f) + X137 * F(0.277785f)); R.at(3, 2) = X134; - R.at(3, 3) = D(X131 * F(0.022887f) + X133 * F(-0.097545f) + X135 * F(0.490393f) + X137 * F(0.865723f)); + R.at(3, 3) = D(X131 * F(0.022887f) + X133 * F(-0.097545f) + + X135 * F(0.490393f) + X137 * F(0.865723f)); // 40 muls 24 adds // 4x4 = 4x8 times 8x4, matrix 1 is constant - S.at(0, 0) = D(X101 * F(0.906127f) + X103 * F(-0.318190f) + X105 * F(0.212608f) + X107 * F(-0.180240f)); + S.at(0, 0) = D(X101 * F(0.906127f) + X103 * F(-0.318190f) + + X105 * F(0.212608f) + X107 * F(-0.180240f)); S.at(0, 1) = X102; - S.at(0, 2) = D(X101 * F(-0.074658f) + X103 * F(0.513280f) + X105 * F(0.768178f) + X107 * F(-0.375330f)); + S.at(0, 2) = D(X101 * F(-0.074658f) + X103 * F(0.513280f) + + X105 * F(0.768178f) + X107 * F(-0.375330f)); S.at(0, 3) = X106; - S.at(1, 0) = D(X111 * F(0.906127f) + X113 * F(-0.318190f) + X115 * F(0.212608f) + X117 * F(-0.180240f)); + S.at(1, 0) = D(X111 * F(0.906127f) + X113 * F(-0.318190f) + + X115 * F(0.212608f) + X117 * F(-0.180240f)); S.at(1, 1) = X112; - S.at(1, 2) = D(X111 * F(-0.074658f) + X113 * F(0.513280f) + X115 * F(0.768178f) + X117 * F(-0.375330f)); + S.at(1, 2) = D(X111 * F(-0.074658f) + X113 * F(0.513280f) + + X115 * F(0.768178f) + X117 * F(-0.375330f)); S.at(1, 3) = X116; - S.at(2, 0) = D(X121 * F(0.906127f) + X123 * F(-0.318190f) + X125 * F(0.212608f) + X127 * F(-0.180240f)); + S.at(2, 0) = D(X121 * F(0.906127f) + X123 * F(-0.318190f) + + X125 * F(0.212608f) + X127 * F(-0.180240f)); S.at(2, 1) = X122; - S.at(2, 2) = D(X121 * F(-0.074658f) + X123 * F(0.513280f) + X125 * F(0.768178f) + X127 * F(-0.375330f)); + S.at(2, 2) = D(X121 * F(-0.074658f) + X123 * F(0.513280f) + + X125 * F(0.768178f) + X127 * F(-0.375330f)); S.at(2, 3) = X126; - S.at(3, 0) = D(X131 * F(0.906127f) + X133 * F(-0.318190f) + X135 * F(0.212608f) + X137 * F(-0.180240f)); + S.at(3, 0) = D(X131 * F(0.906127f) + X133 * F(-0.318190f) + + X135 * F(0.212608f) + X137 * F(-0.180240f)); S.at(3, 1) = X132; - S.at(3, 2) = D(X131 * F(-0.074658f) + X133 * F(0.513280f) + X135 * F(0.768178f) + X137 * F(-0.375330f)); + S.at(3, 2) = D(X131 * F(-0.074658f) + X133 * F(0.513280f) + + X135 * F(0.768178f) + X137 * F(-0.375330f)); S.at(3, 3) = X136; // 40 muls 24 adds } @@ -1065,7 +1174,9 @@ void jpeg_decoder::prep_in_buffer() do { - int bytes_read = m_pStream->read(m_in_buf + m_in_buf_left, JPGD_IN_BUF_SIZE - m_in_buf_left, &m_eof_flag); + int bytes_read = + m_pStream->read(m_in_buf + m_in_buf_left, + JPGD_IN_BUF_SIZE - m_in_buf_left, &m_eof_flag); if (bytes_read == -1) stop_decoding(JPGD_STREAM_READ); @@ -1074,8 +1185,9 @@ void jpeg_decoder::prep_in_buffer() m_total_bytes_read += m_in_buf_left; - // Pad the end of the block with M_EOI (prevents the decompressor from going off the rails if the stream is - // invalid). (This dates way back to when this decompressor was written in C/asm, and the all-asm Huffman decoder + // Pad the end of the block with M_EOI (prevents the decompressor from going + // off the rails if the stream is invalid). (This dates way back to when + // this decompressor was written in C/asm, and the all-asm Huffman decoder // did some fancy things to increase perf.) word_clear(m_pIn_buf_ofs + m_in_buf_left, 0xD9FF, 64); } @@ -1124,7 +1236,8 @@ void jpeg_decoder::read_dht_marker() if ((index & 0x10) > 0x10) stop_decoding(JPGD_BAD_DHT_INDEX); - index = (index & 0x0F) + ((index & 0x10) >> 4) * (JPGD_MAX_HUFF_TABLES >> 1); + index = (index & 0x0F) + + ((index & 0x10) >> 4) * (JPGD_MAX_HUFF_TABLES >> 1); if (index >= JPGD_MAX_HUFF_TABLES) stop_decoding(JPGD_BAD_DHT_INDEX); @@ -1198,7 +1311,8 @@ void jpeg_decoder::read_sof_marker() num_left = get_bits(16); - if (get_bits(8) != 8) /* precision: sorry, only 8-bit precision is supported right now */ + if (get_bits(8) != 8) /* precision: sorry, only 8-bit precision is supported + right now */ stop_decoding(JPGD_BAD_PRECISION); m_image_y_size = get_bits(16); @@ -1270,7 +1384,8 @@ void jpeg_decoder::read_sos_marker() num_left -= 3; - if ((num_left != (uint)(n * 2 + 3)) || (n < 1) || (n > JPGD_MAX_COMPS_IN_SCAN)) + if ((num_left != (uint)(n * 2 + 3)) || (n < 1) || + (n > JPGD_MAX_COMPS_IN_SCAN)) stop_decoding(JPGD_BAD_SOS_LENGTH); for (i = 0; i < n; i++) @@ -1391,7 +1506,7 @@ int jpeg_decoder::process_markers() read_dri_marker(); break; } - // case M_APP0: /* no need to read the JFIF marker */ + // case M_APP0: /* no need to read the JFIF marker */ case M_JPG: case M_RST0: /* no parameters */ @@ -1448,13 +1563,14 @@ void jpeg_decoder::locate_soi_marker() { if (thischar == M_SOI) break; - else if (thischar == M_EOI) // get_bits will keep returning M_EOI if we read past the end + else if (thischar == M_EOI) // get_bits will keep returning M_EOI if + // we read past the end stop_decoding(JPGD_NOT_JPEG); } } - // Check the next character after marker: if it's not 0xFF, it can't be the start of the next marker, so the file is - // bad. + // Check the next character after marker: if it's not 0xFF, it can't be the + // start of the next marker, so the file is bad. thischar = (m_bit_buf >> 24) & 0xFF; if (thischar != 0xFF) @@ -1662,10 +1778,14 @@ void jpeg_decoder::transform_mcu(int mcu_row) } } -static const uint8 s_max_rc[64] = {17, 18, 34, 50, 50, 51, 52, 52, 52, 68, 84, 84, 84, 84, 85, 86, - 86, 86, 86, 86, 102, 118, 118, 118, 118, 118, 118, 119, 120, 120, 120, 120, - 120, 120, 120, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136}; +static const uint8 s_max_rc[64] = {17, 18, 34, 50, 50, 51, 52, 52, + 52, 68, 84, 84, 84, 84, 85, 86, + 86, 86, 86, 86, 102, 118, 118, 118, + 118, 118, 118, 119, 120, 120, 120, 120, + 120, 120, 120, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136, + 136, 136, 136, 136, 136, 136, 136, 136}; void jpeg_decoder::transform_mcu_expand(int mcu_row) { @@ -1674,7 +1794,8 @@ void jpeg_decoder::transform_mcu_expand(int mcu_row) // Y IDCT int mcu_block; - for (mcu_block = 0; mcu_block < m_expanded_blocks_per_component; mcu_block++) + for (mcu_block = 0; mcu_block < m_expanded_blocks_per_component; + mcu_block++) { idct(pSrc_ptr, pDst_ptr, m_mcu_block_max_zag[mcu_block]); pSrc_ptr += 64; @@ -1693,7 +1814,8 @@ void jpeg_decoder::transform_mcu_expand(int mcu_row) int max_zag = m_mcu_block_max_zag[mcu_block++] - 1; if (max_zag <= 0) - max_zag = 0; // should never happen, only here to shut up static analysis + max_zag = + 0; // should never happen, only here to shut up static analysis switch (s_max_rc[max_zag]) { case 1 * 16 + 1: @@ -1811,10 +1933,14 @@ void jpeg_decoder::load_next_row() p = m_pMCU_coefficients + 64 * mcu_block; - jpgd_block_t *pAC = coeff_buf_getp(m_ac_coeffs[component_id], block_x_mcu[component_id] + block_x_mcu_ofs, - m_block_y_mcu[component_id] + block_y_mcu_ofs); - jpgd_block_t *pDC = coeff_buf_getp(m_dc_coeffs[component_id], block_x_mcu[component_id] + block_x_mcu_ofs, - m_block_y_mcu[component_id] + block_y_mcu_ofs); + jpgd_block_t *pAC = + coeff_buf_getp(m_ac_coeffs[component_id], + block_x_mcu[component_id] + block_x_mcu_ofs, + m_block_y_mcu[component_id] + block_y_mcu_ofs); + jpgd_block_t *pDC = + coeff_buf_getp(m_dc_coeffs[component_id], + block_x_mcu[component_id] + block_x_mcu_ofs, + m_block_y_mcu[component_id] + block_y_mcu_ofs); p[0] = pDC[0]; memcpy(&p[1], &pAC[1], 63 * sizeof(jpgd_block_t)); @@ -1842,7 +1968,8 @@ void jpeg_decoder::load_next_row() { block_y_mcu_ofs = 0; - block_x_mcu[component_id] += m_comp_h_samp[component_id]; + block_x_mcu[component_id] += + m_comp_h_samp[component_id]; } } } @@ -1858,7 +1985,8 @@ void jpeg_decoder::load_next_row() m_block_y_mcu[m_comp_list[0]]++; else { - for (component_num = 0; component_num < m_comps_in_scan; component_num++) + for (component_num = 0; component_num < m_comps_in_scan; + component_num++) { component_id = m_comp_list[component_num]; @@ -1874,8 +2002,8 @@ void jpeg_decoder::process_restart() int c = 0; // Align to a byte boundry - // FIXME: Is this really necessary? get_bits_no_markers() never reads in markers! - // get_bits_no_markers(m_bits_left & 7); + // FIXME: Is this really necessary? get_bits_no_markers() never reads in + // markers! get_bits_no_markers(m_bits_left & 7); // Let's scan a little bit to find the marker, but not _too_ far. // 1536 is a "fudge factor" that determines how much to scan. @@ -1930,7 +2058,8 @@ void jpeg_decoder::decode_next_row() process_restart(); jpgd_block_t *p = m_pMCU_coefficients; - for (int mcu_block = 0; mcu_block < m_blocks_per_mcu; mcu_block++, p += 64) + for (int mcu_block = 0; mcu_block < m_blocks_per_mcu; + mcu_block++, p += 64) { int component_id = m_mcu_org[mcu_block]; jpgd_quant_t *q = m_quant[m_comp_quant[component_id]]; @@ -1978,7 +2107,8 @@ void jpeg_decoder::decode_next_row() JPGD_ASSERT(k < 64); - p[g_ZAG[k]] = static_cast(dequantize_ac(s, q[k])); // s * q[k]; + p[g_ZAG[k]] = static_cast( + dequantize_ac(s, q[k])); // s * q[k]; } else { @@ -2234,7 +2364,8 @@ void jpeg_decoder::expanded_convert() { int row = m_max_mcu_y_size - m_mcu_lines_left; - uint8 *Py = m_pSample_buf + (row / 8) * 64 * m_comp_h_samp[0] + (row & 7) * 8; + uint8 *Py = + m_pSample_buf + (row / 8) * 64 * m_comp_h_samp[0] + (row & 7) * 8; uint8 *d = m_pScan_line_0; @@ -2264,7 +2395,8 @@ void jpeg_decoder::expanded_convert() } } -// Find end of image (EOI) marker, so we can return to the user the exact size of the input stream. +// Find end of image (EOI) marker, so we can return to the user the exact size +// of the input stream. void jpeg_decoder::find_eoi() { if (!m_progressive_flag) @@ -2453,7 +2585,8 @@ void jpeg_decoder::make_huff_table(int index, huff_tables *pH) if (total_codesize <= 8) { has_extrabits = true; - extra_bits = ((1 << num_extra_bits) - 1) & (code >> (8 - total_codesize)); + extra_bits = ((1 << num_extra_bits) - 1) & + (code >> (8 - total_codesize)); JPGD_ASSERT(extra_bits <= 0x7FFF); bits_to_fetch += num_extra_bits; } @@ -2462,7 +2595,8 @@ void jpeg_decoder::make_huff_table(int index, huff_tables *pH) if (!has_extrabits) pH->look_up2[code] = i | (bits_to_fetch << 8); else - pH->look_up2[code] = i | 0x8000 | (extra_bits << 16) | (bits_to_fetch << 8); + pH->look_up2[code] = + i | 0x8000 | (extra_bits << 16) | (bits_to_fetch << 8); code++; } @@ -2525,10 +2659,12 @@ void jpeg_decoder::check_huff_tables() { for (int i = 0; i < m_comps_in_scan; i++) { - if ((m_spectral_start == 0) && (m_huff_num[m_comp_dc_tab[m_comp_list[i]]] == NULL)) + if ((m_spectral_start == 0) && + (m_huff_num[m_comp_dc_tab[m_comp_list[i]]] == NULL)) stop_decoding(JPGD_UNDEFINED_HUFF_TABLE); - if ((m_spectral_end > 0) && (m_huff_num[m_comp_ac_tab[m_comp_list[i]]] == NULL)) + if ((m_spectral_end > 0) && + (m_huff_num[m_comp_ac_tab[m_comp_list[i]]] == NULL)) stop_decoding(JPGD_UNDEFINED_HUFF_TABLE); } @@ -2561,9 +2697,17 @@ void jpeg_decoder::calc_mcu_block_order() for (component_id = 0; component_id < m_comps_in_frame; component_id++) { m_comp_h_blocks[component_id] = - ((((m_image_x_size * m_comp_h_samp[component_id]) + (max_h_samp - 1)) / max_h_samp) + 7) / 8; + ((((m_image_x_size * m_comp_h_samp[component_id]) + + (max_h_samp - 1)) / + max_h_samp) + + 7) / + 8; m_comp_v_blocks[component_id] = - ((((m_image_y_size * m_comp_v_samp[component_id]) + (max_v_samp - 1)) / max_v_samp) + 7) / 8; + ((((m_image_y_size * m_comp_v_samp[component_id]) + + (max_v_samp - 1)) / + max_v_samp) + + 7) / + 8; } if (m_comps_in_scan == 1) @@ -2573,8 +2717,10 @@ void jpeg_decoder::calc_mcu_block_order() } else { - m_mcus_per_row = (((m_image_x_size + 7) / 8) + (max_h_samp - 1)) / max_h_samp; - m_mcus_per_col = (((m_image_y_size + 7) / 8) + (max_v_samp - 1)) / max_v_samp; + m_mcus_per_row = + (((m_image_x_size + 7) / 8) + (max_h_samp - 1)) / max_h_samp; + m_mcus_per_col = + (((m_image_y_size + 7) / 8) + (max_v_samp - 1)) / max_v_samp; } if (m_comps_in_scan == 1) @@ -2587,13 +2733,15 @@ void jpeg_decoder::calc_mcu_block_order() { m_blocks_per_mcu = 0; - for (component_num = 0; component_num < m_comps_in_scan; component_num++) + for (component_num = 0; component_num < m_comps_in_scan; + component_num++) { int num_blocks; component_id = m_comp_list[component_num]; - num_blocks = m_comp_h_samp[component_id] * m_comp_v_samp[component_id]; + num_blocks = + m_comp_h_samp[component_id] * m_comp_v_samp[component_id]; while (num_blocks--) m_mcu_org[m_blocks_per_mcu++] = component_id; @@ -2685,8 +2833,10 @@ void jpeg_decoder::init_frame() else stop_decoding(JPGD_UNSUPPORTED_COLORSPACE); - m_max_mcus_per_row = (m_image_x_size + (m_max_mcu_x_size - 1)) / m_max_mcu_x_size; - m_max_mcus_per_col = (m_image_y_size + (m_max_mcu_y_size - 1)) / m_max_mcu_y_size; + m_max_mcus_per_row = + (m_image_x_size + (m_max_mcu_x_size - 1)) / m_max_mcu_x_size; + m_max_mcus_per_col = + (m_image_y_size + (m_max_mcu_y_size - 1)) / m_max_mcu_y_size; // These values are for the *destination* pixels: after conversion. if (m_scan_type == JPGD_GRAYSCALE) @@ -2694,7 +2844,8 @@ void jpeg_decoder::init_frame() else m_dest_bytes_per_pixel = 4; - m_dest_bytes_per_scan_line = ((m_image_x_size + 15) & 0xFFF0) * m_dest_bytes_per_pixel; + m_dest_bytes_per_scan_line = + ((m_image_x_size + 15) & 0xFFF0) * m_dest_bytes_per_pixel; m_real_dest_bytes_per_scan_line = (m_image_x_size * m_dest_bytes_per_pixel); @@ -2710,15 +2861,18 @@ void jpeg_decoder::init_frame() stop_decoding(JPGD_ASSERTION_ERROR); // Allocate the coefficient buffer, enough for one MCU - m_pMCU_coefficients = (jpgd_block_t *)alloc(m_max_blocks_per_mcu * 64 * sizeof(jpgd_block_t)); + m_pMCU_coefficients = + (jpgd_block_t *)alloc(m_max_blocks_per_mcu * 64 * sizeof(jpgd_block_t)); for (i = 0; i < m_max_blocks_per_mcu; i++) m_mcu_block_max_zag[i] = 64; m_expanded_blocks_per_component = m_comp_h_samp[0] * m_comp_v_samp[0]; - m_expanded_blocks_per_mcu = m_expanded_blocks_per_component * m_comps_in_frame; + m_expanded_blocks_per_mcu = + m_expanded_blocks_per_component * m_comps_in_frame; m_expanded_blocks_per_row = m_max_mcus_per_row * m_expanded_blocks_per_mcu; - // Freq. domain chroma upsampling is only supported for H2V2 subsampling factor (the most common one I've seen). + // Freq. domain chroma upsampling is only supported for H2V2 subsampling + // factor (the most common one I've seen). m_freq_domain_chroma_upsample = false; #if JPGD_SUPPORT_FREQ_DOMAIN_UPSAMPLING m_freq_domain_chroma_upsample = (m_expanded_blocks_per_mcu == 4 * 3); @@ -2740,7 +2894,9 @@ void jpeg_decoder::init_frame() // into a "virtual" file which was located in EMS, XMS, or a disk file. A cache // was used to make this process more efficient. Now, we can store the entire // thing in RAM. -jpeg_decoder::coeff_buf *jpeg_decoder::coeff_buf_open(int block_num_x, int block_num_y, int block_len_x, +jpeg_decoder::coeff_buf *jpeg_decoder::coeff_buf_open(int block_num_x, + int block_num_y, + int block_len_x, int block_len_y) { coeff_buf *cb = (coeff_buf *)alloc(sizeof(coeff_buf)); @@ -2750,24 +2906,30 @@ jpeg_decoder::coeff_buf *jpeg_decoder::coeff_buf_open(int block_num_x, int block cb->block_len_x = block_len_x; cb->block_len_y = block_len_y; cb->block_size = (block_len_x * block_len_y) * sizeof(jpgd_block_t); - cb->pData = (uint8 *)alloc(cb->block_size * block_num_x * block_num_y, true); + cb->pData = + (uint8 *)alloc(cb->block_size * block_num_x * block_num_y, true); return cb; } -inline jpgd_block_t *jpeg_decoder::coeff_buf_getp(coeff_buf *cb, int block_x, int block_y) +inline jpgd_block_t *jpeg_decoder::coeff_buf_getp(coeff_buf *cb, int block_x, + int block_y) { JPGD_ASSERT((block_x < cb->block_num_x) && (block_y < cb->block_num_y)); - return (jpgd_block_t *)(cb->pData + block_x * cb->block_size + block_y * (cb->block_size * cb->block_num_x)); + return (jpgd_block_t *)(cb->pData + block_x * cb->block_size + + block_y * (cb->block_size * cb->block_num_x)); } // The following methods decode the various types of m_blocks encountered // in progressively encoded images. -void jpeg_decoder::decode_block_dc_first(jpeg_decoder *pD, int component_id, int block_x, int block_y) +void jpeg_decoder::decode_block_dc_first(jpeg_decoder *pD, int component_id, + int block_x, int block_y) { int s, r; - jpgd_block_t *p = pD->coeff_buf_getp(pD->m_dc_coeffs[component_id], block_x, block_y); + jpgd_block_t *p = + pD->coeff_buf_getp(pD->m_dc_coeffs[component_id], block_x, block_y); - if ((s = pD->huff_decode(pD->m_pHuff_tabs[pD->m_comp_dc_tab[component_id]])) != 0) + if ((s = pD->huff_decode( + pD->m_pHuff_tabs[pD->m_comp_dc_tab[component_id]])) != 0) { r = pD->get_bits_no_markers(s); s = JPGD_HUFF_EXTEND(r, s); @@ -2778,17 +2940,20 @@ void jpeg_decoder::decode_block_dc_first(jpeg_decoder *pD, int component_id, int p[0] = static_cast(s << pD->m_successive_low); } -void jpeg_decoder::decode_block_dc_refine(jpeg_decoder *pD, int component_id, int block_x, int block_y) +void jpeg_decoder::decode_block_dc_refine(jpeg_decoder *pD, int component_id, + int block_x, int block_y) { if (pD->get_bits_no_markers(1)) { - jpgd_block_t *p = pD->coeff_buf_getp(pD->m_dc_coeffs[component_id], block_x, block_y); + jpgd_block_t *p = + pD->coeff_buf_getp(pD->m_dc_coeffs[component_id], block_x, block_y); p[0] |= (1 << pD->m_successive_low); } } -void jpeg_decoder::decode_block_ac_first(jpeg_decoder *pD, int component_id, int block_x, int block_y) +void jpeg_decoder::decode_block_ac_first(jpeg_decoder *pD, int component_id, + int block_x, int block_y) { int k, s, r; @@ -2798,7 +2963,8 @@ void jpeg_decoder::decode_block_ac_first(jpeg_decoder *pD, int component_id, int return; } - jpgd_block_t *p = pD->coeff_buf_getp(pD->m_ac_coeffs[component_id], block_x, block_y); + jpgd_block_t *p = + pD->coeff_buf_getp(pD->m_ac_coeffs[component_id], block_x, block_y); for (k = pD->m_spectral_start; k <= pD->m_spectral_end; k++) { @@ -2839,12 +3005,14 @@ void jpeg_decoder::decode_block_ac_first(jpeg_decoder *pD, int component_id, int } } -void jpeg_decoder::decode_block_ac_refine(jpeg_decoder *pD, int component_id, int block_x, int block_y) +void jpeg_decoder::decode_block_ac_refine(jpeg_decoder *pD, int component_id, + int block_x, int block_y) { int s, k, r; int p1 = 1 << pD->m_successive_low; int m1 = (-1) << pD->m_successive_low; - jpgd_block_t *p = pD->coeff_buf_getp(pD->m_ac_coeffs[component_id], block_x, block_y); + jpgd_block_t *p = + pD->coeff_buf_getp(pD->m_ac_coeffs[component_id], block_x, block_y); JPGD_ASSERT(pD->m_spectral_end <= 63); @@ -2854,7 +3022,8 @@ void jpeg_decoder::decode_block_ac_refine(jpeg_decoder *pD, int component_id, in { for (; k <= pD->m_spectral_end; k++) { - s = pD->huff_decode(pD->m_pHuff_tabs[pD->m_comp_ac_tab[component_id]]); + s = pD->huff_decode( + pD->m_pHuff_tabs[pD->m_comp_ac_tab[component_id]]); r = s >> 4; s &= 15; @@ -2893,9 +3062,11 @@ void jpeg_decoder::decode_block_ac_refine(jpeg_decoder *pD, int component_id, in if ((*this_coef & p1) == 0) { if (*this_coef >= 0) - *this_coef = static_cast(*this_coef + p1); + *this_coef = + static_cast(*this_coef + p1); else - *this_coef = static_cast(*this_coef + m1); + *this_coef = + static_cast(*this_coef + m1); } } } @@ -2920,7 +3091,9 @@ void jpeg_decoder::decode_block_ac_refine(jpeg_decoder *pD, int component_id, in { for (; k <= pD->m_spectral_end; k++) { - jpgd_block_t *this_coef = p + g_ZAG[k & 63]; // logical AND to shut up static code analysis + jpgd_block_t *this_coef = + p + + g_ZAG[k & 63]; // logical AND to shut up static code analysis if (*this_coef != 0) { @@ -2929,9 +3102,11 @@ void jpeg_decoder::decode_block_ac_refine(jpeg_decoder *pD, int component_id, in if ((*this_coef & p1) == 0) { if (*this_coef >= 0) - *this_coef = static_cast(*this_coef + p1); + *this_coef = + static_cast(*this_coef + p1); else - *this_coef = static_cast(*this_coef + m1); + *this_coef = + static_cast(*this_coef + m1); } } } @@ -2966,8 +3141,10 @@ void jpeg_decoder::decode_scan(pDecode_block_func decode_block_func) { component_id = m_mcu_org[mcu_block]; - decode_block_func(this, component_id, block_x_mcu[component_id] + block_x_mcu_ofs, - m_block_y_mcu[component_id] + block_y_mcu_ofs); + decode_block_func(this, component_id, + block_x_mcu[component_id] + block_x_mcu_ofs, + m_block_y_mcu[component_id] + + block_y_mcu_ofs); if (m_comps_in_scan == 1) block_x_mcu[component_id]++; @@ -2980,7 +3157,8 @@ void jpeg_decoder::decode_scan(pDecode_block_func decode_block_func) if (++block_y_mcu_ofs == m_comp_v_samp[component_id]) { block_y_mcu_ofs = 0; - block_x_mcu[component_id] += m_comp_h_samp[component_id]; + block_x_mcu[component_id] += + m_comp_h_samp[component_id]; } } } @@ -2993,7 +3171,8 @@ void jpeg_decoder::decode_scan(pDecode_block_func decode_block_func) m_block_y_mcu[m_comp_list[0]]++; else { - for (component_num = 0; component_num < m_comps_in_scan; component_num++) + for (component_num = 0; component_num < m_comps_in_scan; + component_num++) { component_id = m_comp_list[component_num]; m_block_y_mcu[component_id] += m_comp_v_samp[component_id]; @@ -3014,9 +3193,11 @@ void jpeg_decoder::init_progressive() for (i = 0; i < m_comps_in_frame; i++) { m_dc_coeffs[i] = - coeff_buf_open(m_max_mcus_per_row * m_comp_h_samp[i], m_max_mcus_per_col * m_comp_v_samp[i], 1, 1); + coeff_buf_open(m_max_mcus_per_row * m_comp_h_samp[i], + m_max_mcus_per_col * m_comp_v_samp[i], 1, 1); m_ac_coeffs[i] = - coeff_buf_open(m_max_mcus_per_row * m_comp_h_samp[i], m_max_mcus_per_col * m_comp_v_samp[i], 8, 8); + coeff_buf_open(m_max_mcus_per_row * m_comp_h_samp[i], + m_max_mcus_per_col * m_comp_v_samp[i], 8, 8); } for (;;) @@ -3038,7 +3219,8 @@ void jpeg_decoder::init_progressive() if (m_spectral_end) stop_decoding(JPGD_BAD_SOS_SPECTRAL); } - else if (m_comps_in_scan != 1) /* AC scans can only contain one component */ + else if (m_comps_in_scan != 1) /* AC scans can only contain one + component */ stop_decoding(JPGD_BAD_SOS_SPECTRAL); if ((refinement_scan) && (m_successive_low != m_successive_high - 1)) @@ -3166,7 +3348,8 @@ bool jpeg_decoder_file_stream::open(const char *Pfilename) return m_pFile != NULL; } -int jpeg_decoder_file_stream::read(uint8 *pBuf, int max_bytes_to_read, bool *pEOF_flag) +int jpeg_decoder_file_stream::read(uint8 *pBuf, int max_bytes_to_read, + bool *pEOF_flag) { if (!m_pFile) return -1; @@ -3180,7 +3363,8 @@ int jpeg_decoder_file_stream::read(uint8 *pBuf, int max_bytes_to_read, bool *pEO if (m_error_flag) return -1; - int bytes_read = static_cast(fread(pBuf, 1, max_bytes_to_read, m_pFile)); + int bytes_read = + static_cast(fread(pBuf, 1, max_bytes_to_read, m_pFile)); if (bytes_read < max_bytes_to_read) { if (ferror(m_pFile)) @@ -3205,7 +3389,8 @@ bool jpeg_decoder_mem_stream::open(const uint8 *pSrc_data, uint size) return true; } -int jpeg_decoder_mem_stream::read(uint8 *pBuf, int max_bytes_to_read, bool *pEOF_flag) +int jpeg_decoder_mem_stream::read(uint8 *pBuf, int max_bytes_to_read, + bool *pEOF_flag) { *pEOF_flag = false; @@ -3225,8 +3410,10 @@ int jpeg_decoder_mem_stream::read(uint8 *pBuf, int max_bytes_to_read, bool *pEOF return max_bytes_to_read; } -unsigned char *decompress_jpeg_image_from_stream(jpeg_decoder_stream *pStream, int *width, int *height, - int *actual_comps, int req_comps) +unsigned char *decompress_jpeg_image_from_stream(jpeg_decoder_stream *pStream, + int *width, int *height, + int *actual_comps, + int req_comps) { if (!actual_comps) return NULL; @@ -3242,7 +3429,8 @@ unsigned char *decompress_jpeg_image_from_stream(jpeg_decoder_stream *pStream, i if (decoder.get_error_code() != JPGD_SUCCESS) return NULL; - const int image_width = decoder.get_width(), image_height = decoder.get_height(); + const int image_width = decoder.get_width(), + image_height = decoder.get_height(); *width = image_width; *height = image_height; *actual_comps = decoder.get_num_components(); @@ -3260,7 +3448,8 @@ unsigned char *decompress_jpeg_image_from_stream(jpeg_decoder_stream *pStream, i { const uint8 *pScan_line; uint scan_line_len; - if (decoder.decode((const void **)&pScan_line, &scan_line_len) != JPGD_SUCCESS) + if (decoder.decode((const void **)&pScan_line, &scan_line_len) != + JPGD_SUCCESS) { jpgd_free(pImage_data); return NULL; @@ -3307,7 +3496,8 @@ unsigned char *decompress_jpeg_image_from_stream(jpeg_decoder_stream *pStream, i int r = pScan_line[x * 4 + 0]; int g = pScan_line[x * 4 + 1]; int b = pScan_line[x * 4 + 2]; - *pDst++ = static_cast((r * YR + g * YG + b * YB + 32768) >> 16); + *pDst++ = static_cast( + (r * YR + g * YG + b * YB + 32768) >> 16); } } else @@ -3326,20 +3516,25 @@ unsigned char *decompress_jpeg_image_from_stream(jpeg_decoder_stream *pStream, i return pImage_data; } -unsigned char *decompress_jpeg_image_from_memory(const unsigned char *pSrc_data, int src_data_size, int *width, - int *height, int *actual_comps, int req_comps) +unsigned char *decompress_jpeg_image_from_memory(const unsigned char *pSrc_data, + int src_data_size, int *width, + int *height, int *actual_comps, + int req_comps) { jpgd::jpeg_decoder_mem_stream mem_stream(pSrc_data, src_data_size); - return decompress_jpeg_image_from_stream(&mem_stream, width, height, actual_comps, req_comps); + return decompress_jpeg_image_from_stream(&mem_stream, width, height, + actual_comps, req_comps); } -unsigned char *decompress_jpeg_image_from_file(const char *pSrc_filename, int *width, int *height, int *actual_comps, - int req_comps) +unsigned char *decompress_jpeg_image_from_file(const char *pSrc_filename, + int *width, int *height, + int *actual_comps, int req_comps) { jpgd::jpeg_decoder_file_stream file_stream; if (!file_stream.open(pSrc_filename)) return NULL; - return decompress_jpeg_image_from_stream(&file_stream, width, height, actual_comps, req_comps); + return decompress_jpeg_image_from_stream(&file_stream, width, height, + actual_comps, req_comps); } } // namespace jpgd diff --git a/solr/images/jpgd.h b/solr/images/jpgd.h index 292fd31..02ec190 100644 --- a/solr/images/jpgd.h +++ b/solr/images/jpgd.h @@ -3,9 +3,9 @@ #ifndef JPEG_DECODER_H #define JPEG_DECODER_H -#include -#include #include +#include +#include #ifdef _MSC_VER #define JPGD_NORETURN __declspec(noreturn) @@ -25,14 +25,20 @@ typedef signed int int32; // Loads a JPEG image from a memory buffer or a file. // req_comps can be 1 (grayscale), 3 (RGB), or 4 (RGBA). -// On return, width/height will be set to the image's dimensions, and actual_comps will be set to the either 1 -// (grayscale) or 3 (RGB). Notes: For more control over where and how the source data is read, see the -// decompress_jpeg_image_from_stream() function below, or call the jpeg_decoder class directly. Requesting a 8 or 32bpp -// image is currently a little faster than 24bpp because the jpeg_decoder class itself currently always unpacks to +// On return, width/height will be set to the image's dimensions, and +// actual_comps will be set to the either 1 (grayscale) or 3 (RGB). Notes: For +// more control over where and how the source data is read, see the +// decompress_jpeg_image_from_stream() function below, or call the jpeg_decoder +// class directly. Requesting a 8 or 32bpp image is currently a little faster +// than 24bpp because the jpeg_decoder class itself currently always unpacks to // either 8 or 32bpp. -unsigned char *decompress_jpeg_image_from_memory(const unsigned char *pSrc_data, int src_data_size, int *width, - int *height, int *actual_comps, int req_comps); -unsigned char *decompress_jpeg_image_from_file(const char *pSrc_filename, int *width, int *height, int *actual_comps, +unsigned char *decompress_jpeg_image_from_memory(const unsigned char *pSrc_data, + int src_data_size, int *width, + int *height, int *actual_comps, + int req_comps); +unsigned char *decompress_jpeg_image_from_file(const char *pSrc_filename, + int *width, int *height, + int *actual_comps, int req_comps); // Success/failure error codes. @@ -77,10 +83,12 @@ enum jpgd_status }; // Input stream interface. -// Derive from this class to read input data from sources other than files or memory. Set m_eof_flag to true when no -// more data is available. The decoder is rather greedy: it will keep on calling this method until its internal input -// buffer is full, or until the EOF flag is set. It the input stream contains data after the JPEG stream's EOI (end of -// image) marker it will probably be pulled into the internal buffer. Call the get_total_bytes_read() method to +// Derive from this class to read input data from sources other than files or +// memory. Set m_eof_flag to true when no more data is available. The decoder is +// rather greedy: it will keep on calling this method until its internal input +// buffer is full, or until the EOF flag is set. It the input stream contains +// data after the JPEG stream's EOI (end of image) marker it will probably be +// pulled into the internal buffer. Call the get_total_bytes_read() method to // determine the actual size of the JPEG stream after successful decoding. class jpeg_decoder_stream { @@ -92,9 +100,11 @@ class jpeg_decoder_stream // Parameters: // pBuf - input buffer // max_bytes_to_read - maximum bytes that can be written to pBuf - // pEOF_flag - set this to true if at end of stream (no more bytes remaining) - // Returns -1 on error, otherwise return the number of bytes actually written to the buffer (which may be 0). - // Notes: This method will be called in a loop until you set *pEOF_flag to true or the internal buffer is full. + // pEOF_flag - set this to true if at end of stream (no more bytes + // remaining) Returns -1 on error, otherwise return the number of bytes + // actually written to the buffer (which may be 0). Notes: This method will + // be called in a loop until you set *pEOF_flag to true or the internal + // buffer is full. virtual int read(uint8 *pBuf, int max_bytes_to_read, bool *pEOF_flag) = 0; }; @@ -151,8 +161,10 @@ class jpeg_decoder_mem_stream : public jpeg_decoder_stream }; // Loads JPEG file from a jpeg_decoder_stream. -unsigned char *decompress_jpeg_image_from_stream(jpeg_decoder_stream *pStream, int *width, int *height, - int *actual_comps, int req_comps); +unsigned char *decompress_jpeg_image_from_stream(jpeg_decoder_stream *pStream, + int *width, int *height, + int *actual_comps, + int req_comps); enum { @@ -173,9 +185,11 @@ typedef int16 jpgd_block_t; class jpeg_decoder { public: - // Call get_error_code() after constructing to determine if the stream is valid or not. You may call the - // get_width(), get_height(), etc. methods after the constructor is called. You may then either destruct the object, - // or begin decoding the image by calling begin_decoding(), then decode() on each scanline. + // Call get_error_code() after constructing to determine if the stream is + // valid or not. You may call the get_width(), get_height(), etc. methods + // after the constructor is called. You may then either destruct the object, + // or begin decoding the image by calling begin_decoding(), then decode() on + // each scanline. jpeg_decoder(jpeg_decoder_stream *pStream); ~jpeg_decoder(); @@ -185,11 +199,13 @@ class jpeg_decoder int begin_decoding(); // Returns the next scan line. - // For grayscale images, pScan_line will point to a buffer containing 8-bit pixels (get_bytes_per_pixel() will - // return 1). Otherwise, it will always point to a buffer containing 32-bit RGBA pixels (A will always be 255, and - // get_bytes_per_pixel() will return 4). Returns JPGD_SUCCESS if a scan line has been returned. Returns JPGD_DONE if - // all scan lines have been returned. Returns JPGD_FAILED if an error occurred. Call get_error_code() for a more - // info. + // For grayscale images, pScan_line will point to a buffer containing 8-bit + // pixels (get_bytes_per_pixel() will return 1). Otherwise, it will always + // point to a buffer containing 32-bit RGBA pixels (A will always be 255, + // and get_bytes_per_pixel() will return 4). Returns JPGD_SUCCESS if a scan + // line has been returned. Returns JPGD_DONE if all scan lines have been + // returned. Returns JPGD_FAILED if an error occurred. Call get_error_code() + // for a more info. int decode(const void **pScan_line, uint *pScan_line_len); inline jpgd_status get_error_code() const { return m_error_code; } @@ -200,10 +216,13 @@ class jpeg_decoder inline int get_num_components() const { return m_comps_in_frame; } inline int get_bytes_per_pixel() const { return m_dest_bytes_per_pixel; } - inline int get_bytes_per_scan_line() const { return m_image_x_size * get_bytes_per_pixel(); } + inline int get_bytes_per_scan_line() const + { + return m_image_x_size * get_bytes_per_pixel(); + } - // Returns the total number of bytes actually consumed by the decoder (which should equal the actual size of the - // JPEG file). + // Returns the total number of bytes actually consumed by the decoder (which + // should equal the actual size of the JPEG file). inline int get_total_bytes_read() const { return m_total_bytes_read; } private: @@ -244,21 +263,30 @@ class jpeg_decoder jpeg_decoder_stream *m_pStream; int m_progressive_flag; uint8 m_huff_ac[JPGD_MAX_HUFF_TABLES]; - uint8 *m_huff_num[JPGD_MAX_HUFF_TABLES]; // pointer to number of Huffman codes per bit size - uint8 *m_huff_val[JPGD_MAX_HUFF_TABLES]; // pointer to Huffman codes per bit size - jpgd_quant_t *m_quant[JPGD_MAX_QUANT_TABLES]; // pointer to quantization tables - int m_scan_type; // Gray, Yh1v1, Yh1v2, Yh2v1, Yh2v2 (CMYK111, CMYK4114 no longer supported) + uint8 *m_huff_num[JPGD_MAX_HUFF_TABLES]; // pointer to number of Huffman + // codes per bit size + uint8 *m_huff_val[JPGD_MAX_HUFF_TABLES]; // pointer to Huffman codes per bit + // size + jpgd_quant_t *m_quant[JPGD_MAX_QUANT_TABLES]; // pointer to quantization + // tables + int m_scan_type; // Gray, Yh1v1, Yh1v2, Yh2v1, Yh2v2 (CMYK111, CMYK4114 no + // longer supported) int m_comps_in_frame; // # of components in frame - int m_comp_h_samp[JPGD_MAX_COMPONENTS]; // component's horizontal sampling factor - int m_comp_v_samp[JPGD_MAX_COMPONENTS]; // component's vertical sampling factor - int m_comp_quant[JPGD_MAX_COMPONENTS]; // component's quantization table selector + int m_comp_h_samp[JPGD_MAX_COMPONENTS]; // component's horizontal sampling + // factor + int m_comp_v_samp[JPGD_MAX_COMPONENTS]; // component's vertical sampling + // factor + int m_comp_quant[JPGD_MAX_COMPONENTS]; // component's quantization table + // selector int m_comp_ident[JPGD_MAX_COMPONENTS]; // component's ID int m_comp_h_blocks[JPGD_MAX_COMPONENTS]; int m_comp_v_blocks[JPGD_MAX_COMPONENTS]; int m_comps_in_scan; // # of components in scan int m_comp_list[JPGD_MAX_COMPS_IN_SCAN]; // components in this scan - int m_comp_dc_tab[JPGD_MAX_COMPONENTS]; // component's DC Huffman coding table selector - int m_comp_ac_tab[JPGD_MAX_COMPONENTS]; // component's AC Huffman coding table selector + int m_comp_dc_tab[JPGD_MAX_COMPONENTS]; // component's DC Huffman coding + // table selector + int m_comp_ac_tab[JPGD_MAX_COMPONENTS]; // component's AC Huffman coding + // table selector int m_spectral_start; // spectral selection start int m_spectral_end; // spectral selection end int m_successive_low; // successive approximation low @@ -333,8 +361,10 @@ class jpeg_decoder void fix_in_buffer(); void transform_mcu(int mcu_row); void transform_mcu_expand(int mcu_row); - coeff_buf *coeff_buf_open(int block_num_x, int block_num_y, int block_len_x, int block_len_y); - inline jpgd_block_t *coeff_buf_getp(coeff_buf *cb, int block_x, int block_y); + coeff_buf *coeff_buf_open(int block_num_x, int block_num_y, int block_len_x, + int block_len_y); + inline jpgd_block_t *coeff_buf_getp(coeff_buf *cb, int block_x, + int block_y); void load_next_row(); void decode_next_row(); void make_huff_table(int index, huff_tables *pH); @@ -365,10 +395,14 @@ class jpeg_decoder inline int huff_decode(huff_tables *pH); inline int huff_decode(huff_tables *pH, int &extrabits); static inline uint8 clamp(int i); - static void decode_block_dc_first(jpeg_decoder *pD, int component_id, int block_x, int block_y); - static void decode_block_dc_refine(jpeg_decoder *pD, int component_id, int block_x, int block_y); - static void decode_block_ac_first(jpeg_decoder *pD, int component_id, int block_x, int block_y); - static void decode_block_ac_refine(jpeg_decoder *pD, int component_id, int block_x, int block_y); + static void decode_block_dc_first(jpeg_decoder *pD, int component_id, + int block_x, int block_y); + static void decode_block_dc_refine(jpeg_decoder *pD, int component_id, + int block_x, int block_y); + static void decode_block_ac_first(jpeg_decoder *pD, int component_id, + int block_x, int block_y); + static void decode_block_ac_refine(jpeg_decoder *pD, int component_id, + int block_x, int block_y); }; } // namespace jpgd diff --git a/solr/images/jpge.cpp b/solr/images/jpge.cpp index 9a9aa77..64d7341 100644 --- a/solr/images/jpge.cpp +++ b/solr/images/jpge.cpp @@ -1,15 +1,20 @@ // jpge.cpp - C++ class for JPEG compression. // Public domain, Rich Geldreich // v1.01, Dec. 18, 2010 - Initial release -// v1.02, Apr. 6, 2011 - Removed 2x2 ordered dither in H2V1 chroma subsampling method load_block_16_8_8(). (The rounding -// factor was 2, when it should have been 1. Either way, it wasn't helping.) v1.03, Apr. 16, 2011 - Added support for -// optimized Huffman code tables, optimized dynamic memory allocation down to only 1 alloc. -// Also from Alex Evans: Added RGBA support, linear memory allocator (no longer needed in v1.03). -// v1.04, May. 19, 2012: Forgot to set m_pFile ptr to NULL in cfile_stream::close(). Thanks to Owen Kaluza for reporting -// this bug. -// Code tweaks to fix VS2008 static code analysis warnings (all looked harmless). -// Code review revealed method load_block_16_8_8() (used for the non-default H2V1 sampling mode to -// downsample chroma) somehow didn't get the rounding factor fix from v1.02. +// v1.02, Apr. 6, 2011 - Removed 2x2 ordered dither in H2V1 chroma subsampling +// method load_block_16_8_8(). (The rounding factor was 2, when it should have +// been 1. Either way, it wasn't helping.) v1.03, Apr. 16, 2011 - Added support +// for optimized Huffman code tables, optimized dynamic memory allocation down +// to only 1 alloc. +// Also from Alex Evans: Added RGBA support, linear +// memory allocator (no longer needed in v1.03). +// v1.04, May. 19, 2012: Forgot to set m_pFile ptr to NULL in +// cfile_stream::close(). Thanks to Owen Kaluza for reporting this bug. +// Code tweaks to fix VS2008 static code analysis warnings +// (all looked harmless). Code review revealed method +// load_block_16_8_8() (used for the non-default H2V1 +// sampling mode to downsample chroma) somehow didn't get +// the rounding factor fix from v1.02. #include "jpge.h" @@ -52,43 +57,65 @@ enum MAX_HUFF_CODESIZE = 32 }; -static uint8 s_zag[64] = {0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5, 12, 19, 26, 33, 40, 48, - 41, 34, 27, 20, 13, 6, 7, 14, 21, 28, 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, - 30, 37, 44, 51, 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63}; -static int16 s_std_lum_quant[64] = {16, 11, 12, 14, 12, 10, 16, 14, 13, 14, 18, 17, 16, 19, 24, 40, - 26, 24, 22, 22, 24, 49, 35, 37, 29, 40, 58, 51, 61, 60, 57, 51, - 56, 55, 64, 72, 92, 78, 64, 68, 87, 69, 55, 56, 80, 109, 81, 87, - 95, 98, 103, 104, 103, 62, 77, 113, 121, 112, 100, 120, 92, 101, 103, 99}; -static int16 s_std_croma_quant[64] = {17, 18, 18, 24, 21, 24, 47, 26, 26, 47, 99, 66, 56, 66, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}; -static uint8 s_dc_lum_bits[17] = {0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0}; -static uint8 s_dc_lum_val[DC_LUM_CODES] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; -static uint8 s_ac_lum_bits[17] = {0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d}; +static uint8 s_zag[64] = {0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, + 11, 4, 5, 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, + 13, 6, 7, 14, 21, 28, 35, 42, 49, 56, 57, 50, 43, + 36, 29, 22, 15, 23, 30, 37, 44, 51, 58, 59, 52, 45, + 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63}; +static int16 s_std_lum_quant[64] = { + 16, 11, 12, 14, 12, 10, 16, 14, 13, 14, 18, 17, 16, 19, 24, 40, + 26, 24, 22, 22, 24, 49, 35, 37, 29, 40, 58, 51, 61, 60, 57, 51, + 56, 55, 64, 72, 92, 78, 64, 68, 87, 69, 55, 56, 80, 109, 81, 87, + 95, 98, 103, 104, 103, 62, 77, 113, 121, 112, 100, 120, 92, 101, 103, 99}; +static int16 s_std_croma_quant[64] = {17, 18, 18, 24, 21, 24, 47, 26, 26, 47, + 99, 66, 56, 66, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99}; +static uint8 s_dc_lum_bits[17] = {0, 0, 1, 5, 1, 1, 1, 1, 1, + 1, 0, 0, 0, 0, 0, 0, 0}; +static uint8 s_dc_lum_val[DC_LUM_CODES] = {0, 1, 2, 3, 4, 5, + 6, 7, 8, 9, 10, 11}; +static uint8 s_ac_lum_bits[17] = {0, 0, 2, 1, 3, 3, 2, 4, 3, + 5, 5, 4, 4, 0, 0, 1, 0x7d}; static uint8 s_ac_lum_val[AC_LUM_CODES] = { - 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, 0x22, 0x71, - 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08, 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0, 0x24, 0x33, 0x62, 0x72, - 0x82, 0x09, 0x0a, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, - 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x83, - 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, - 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, - 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2, - 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa}; -static uint8 s_dc_chroma_bits[17] = {0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}; -static uint8 s_dc_chroma_val[DC_CHROMA_CODES] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; -static uint8 s_ac_chroma_bits[17] = {0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77}; + 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06, + 0x13, 0x51, 0x61, 0x07, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08, + 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0, 0x24, 0x33, 0x62, 0x72, + 0x82, 0x09, 0x0a, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45, + 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, + 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x73, 0x74, 0x75, + 0x76, 0x77, 0x78, 0x79, 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, + 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, + 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, + 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, + 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2, + 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf1, 0xf2, 0xf3, 0xf4, + 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa}; +static uint8 s_dc_chroma_bits[17] = {0, 0, 3, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 0, 0, 0, 0, 0}; +static uint8 s_dc_chroma_val[DC_CHROMA_CODES] = {0, 1, 2, 3, 4, 5, + 6, 7, 8, 9, 10, 11}; +static uint8 s_ac_chroma_bits[17] = {0, 0, 2, 1, 2, 4, 4, 3, 4, + 7, 5, 4, 4, 0, 1, 2, 0x77}; static uint8 s_ac_chroma_val[AC_CHROMA_CODES] = { - 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, 0x13, 0x22, - 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0, 0x15, 0x62, 0x72, 0xd1, - 0x0a, 0x16, 0x24, 0x34, 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, - 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, - 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, - 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, - 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, - 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, - 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa}; + 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41, + 0x51, 0x07, 0x61, 0x71, 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, + 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0, 0x15, 0x62, 0x72, 0xd1, + 0x0a, 0x16, 0x24, 0x34, 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26, + 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, + 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, + 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x73, 0x74, + 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, + 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, + 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, + 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, + 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, + 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf2, 0xf3, 0xf4, + 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa}; // Low-level helper functions. template @@ -97,8 +124,8 @@ inline void clear_obj(T &obj) memset(&obj, 0, sizeof(obj)); } -const int YR = 19595, YG = 38470, YB = 7471, CB_R = -11059, CB_G = -21709, CB_B = 32768, CR_R = 32768, CR_G = -27439, - CR_B = -5329; +const int YR = 19595, YG = 38470, YB = 7471, CB_R = -11059, CB_G = -21709, + CB_B = 32768, CR_R = 32768, CR_G = -27439, CR_B = -5329; static inline uint8 clamp(int i) { if (static_cast(i) > 255U) @@ -125,7 +152,8 @@ static void RGB_to_YCC(uint8 *pDst, const uint8 *pSrc, int num_pixels) static void RGB_to_Y(uint8 *pDst, const uint8 *pSrc, int num_pixels) { for (; num_pixels; pDst++, pSrc += 3, num_pixels--) - pDst[0] = static_cast((pSrc[0] * YR + pSrc[1] * YG + pSrc[2] * YB + 32768) >> 16); + pDst[0] = static_cast( + (pSrc[0] * YR + pSrc[1] * YG + pSrc[2] * YB + 32768) >> 16); } static void RGBA_to_YCC(uint8 *pDst, const uint8 *pSrc, int num_pixels) @@ -142,7 +170,8 @@ static void RGBA_to_YCC(uint8 *pDst, const uint8 *pSrc, int num_pixels) static void RGBA_to_Y(uint8 *pDst, const uint8 *pSrc, int num_pixels) { for (; num_pixels; pDst++, pSrc += 4, num_pixels--) - pDst[0] = static_cast((pSrc[0] * YR + pSrc[1] * YG + pSrc[2] * YB + 32768) >> 16); + pDst[0] = static_cast( + (pSrc[0] * YR + pSrc[1] * YG + pSrc[2] * YB + 32768) >> 16); } static void Y_to_YCC(uint8 *pDst, const uint8 *pSrc, int num_pixels) @@ -163,31 +192,31 @@ enum }; #define DCT_DESCALE(x, n) (((x) + (((int32)1) << ((n)-1))) >> (n)) #define DCT_MUL(var, c) (static_cast(var) * static_cast(c)) -#define DCT1D(s0, s1, s2, s3, s4, s5, s6, s7) \ - int32 t0 = s0 + s7, t7 = s0 - s7, t1 = s1 + s6, t6 = s1 - s6, t2 = s2 + s5, t5 = s2 - s5, t3 = s3 + s4, \ - t4 = s3 - s4; \ - int32 t10 = t0 + t3, t13 = t0 - t3, t11 = t1 + t2, t12 = t1 - t2; \ - int32 u1 = DCT_MUL(t12 + t13, 4433); \ - s2 = u1 + DCT_MUL(t13, 6270); \ - s6 = u1 + DCT_MUL(t12, -15137); \ - u1 = t4 + t7; \ - int32 u2 = t5 + t6, u3 = t4 + t6, u4 = t5 + t7; \ - int32 z5 = DCT_MUL(u3 + u4, 9633); \ - t4 = DCT_MUL(t4, 2446); \ - t5 = DCT_MUL(t5, 16819); \ - t6 = DCT_MUL(t6, 25172); \ - t7 = DCT_MUL(t7, 12299); \ - u1 = DCT_MUL(u1, -7373); \ - u2 = DCT_MUL(u2, -20995); \ - u3 = DCT_MUL(u3, -16069); \ - u4 = DCT_MUL(u4, -3196); \ - u3 += z5; \ - u4 += z5; \ - s0 = t10 + t11; \ - s1 = t7 + u1 + u4; \ - s3 = t6 + u2 + u3; \ - s4 = t10 - t11; \ - s5 = t5 + u2 + u4; \ +#define DCT1D(s0, s1, s2, s3, s4, s5, s6, s7) \ + int32 t0 = s0 + s7, t7 = s0 - s7, t1 = s1 + s6, t6 = s1 - s6, \ + t2 = s2 + s5, t5 = s2 - s5, t3 = s3 + s4, t4 = s3 - s4; \ + int32 t10 = t0 + t3, t13 = t0 - t3, t11 = t1 + t2, t12 = t1 - t2; \ + int32 u1 = DCT_MUL(t12 + t13, 4433); \ + s2 = u1 + DCT_MUL(t13, 6270); \ + s6 = u1 + DCT_MUL(t12, -15137); \ + u1 = t4 + t7; \ + int32 u2 = t5 + t6, u3 = t4 + t6, u4 = t5 + t7; \ + int32 z5 = DCT_MUL(u3 + u4, 9633); \ + t4 = DCT_MUL(t4, 2446); \ + t5 = DCT_MUL(t5, 16819); \ + t6 = DCT_MUL(t6, 25172); \ + t7 = DCT_MUL(t7, 12299); \ + u1 = DCT_MUL(u1, -7373); \ + u2 = DCT_MUL(u2, -20995); \ + u3 = DCT_MUL(u3, -16069); \ + u4 = DCT_MUL(u4, -3196); \ + u3 += z5; \ + u4 += z5; \ + s0 = t10 + t11; \ + s1 = t7 + u1 + u4; \ + s3 = t6 + u2 + u3; \ + s4 = t10 - t11; \ + s5 = t5 + u2 + u4; \ s7 = t4 + u1 + u3; static void DCT2D(int32 *p) @@ -195,7 +224,8 @@ static void DCT2D(int32 *p) int32 c, *q = p; for (c = 7; c >= 0; c--, q += 8) { - int32 s0 = q[0], s1 = q[1], s2 = q[2], s3 = q[3], s4 = q[4], s5 = q[5], s6 = q[6], s7 = q[7]; + int32 s0 = q[0], s1 = q[1], s2 = q[2], s3 = q[3], s4 = q[4], s5 = q[5], + s6 = q[6], s7 = q[7]; DCT1D(s0, s1, s2, s3, s4, s5, s6, s7); q[0] = s0 << ROW_BITS; q[1] = DCT_DESCALE(s1, CONST_BITS - ROW_BITS); @@ -208,8 +238,8 @@ static void DCT2D(int32 *p) } for (q = p, c = 7; c >= 0; c--, q++) { - int32 s0 = q[0 * 8], s1 = q[1 * 8], s2 = q[2 * 8], s3 = q[3 * 8], s4 = q[4 * 8], s5 = q[5 * 8], s6 = q[6 * 8], - s7 = q[7 * 8]; + int32 s0 = q[0 * 8], s1 = q[1 * 8], s2 = q[2 * 8], s3 = q[3 * 8], + s4 = q[4 * 8], s5 = q[5 * 8], s6 = q[6 * 8], s7 = q[7 * 8]; DCT1D(s0, s1, s2, s3, s4, s5, s6, s7); q[0 * 8] = DCT_DESCALE(s0, ROW_BITS + 3); q[1 * 8] = DCT_DESCALE(s1, CONST_BITS + ROW_BITS + 3); @@ -227,8 +257,10 @@ struct sym_freq uint m_key, m_sym_index; }; -// Radix sorts sym_freq[] array by 32-bit key m_key. Returns ptr to sorted values. -static inline sym_freq *radix_sort_syms(uint num_syms, sym_freq *pSyms0, sym_freq *pSyms1) +// Radix sorts sym_freq[] array by 32-bit key m_key. Returns ptr to sorted +// values. +static inline sym_freq *radix_sort_syms(uint num_syms, sym_freq *pSyms0, + sym_freq *pSyms1) { const uint cMaxPasses = 4; uint32 hist[256 * cMaxPasses]; @@ -245,7 +277,8 @@ static inline sym_freq *radix_sort_syms(uint num_syms, sym_freq *pSyms0, sym_fre uint total_passes = cMaxPasses; while ((total_passes > 1) && (num_syms == hist[(total_passes - 1) * 256])) total_passes--; - for (uint pass_shift = 0, pass = 0; pass < total_passes; pass++, pass_shift += 8) + for (uint pass_shift = 0, pass = 0; pass < total_passes; + pass++, pass_shift += 8) { const uint32 *pHist = &hist[pass << 8]; uint offsets[256], cur_ofs = 0; @@ -255,7 +288,8 @@ static inline sym_freq *radix_sort_syms(uint num_syms, sym_freq *pSyms0, sym_fre cur_ofs += pHist[i]; } for (uint i = 0; i < num_syms; i++) - pNew_syms[offsets[(pCur_syms[i].m_key >> pass_shift) & 0xFF]++] = pCur_syms[i]; + pNew_syms[offsets[(pCur_syms[i].m_key >> pass_shift) & 0xFF]++] = + pCur_syms[i]; sym_freq *t = pCur_syms; pCur_syms = pNew_syms; pNew_syms = t; @@ -263,8 +297,8 @@ static inline sym_freq *radix_sort_syms(uint num_syms, sym_freq *pSyms0, sym_fre return pCur_syms; } -// calculate_minimum_redundancy() originally written by: Alistair Moffat, alistair@cs.mu.oz.au, Jyrki Katajainen, -// jyrki@diku.dk, November 1996. +// calculate_minimum_redundancy() originally written by: Alistair Moffat, +// alistair@cs.mu.oz.au, Jyrki Katajainen, jyrki@diku.dk, November 1996. static void calculate_minimum_redundancy(sym_freq *A, int n) { int root, leaf, next, avbl, used, dpth; @@ -321,7 +355,8 @@ static void calculate_minimum_redundancy(sym_freq *A, int n) } // Limits canonical Huffman code table's max code size to max_code_size. -static void huffman_enforce_max_code_size(int *pNum_codes, int code_list_len, int max_code_size) +static void huffman_enforce_max_code_size(int *pNum_codes, int code_list_len, + int max_code_size) { if (code_list_len <= 1) return; @@ -354,7 +389,8 @@ void jpeg_encoder::optimize_huffman_table(int table_num, int table_len) { sym_freq syms0[MAX_HUFF_SYMBOLS], syms1[MAX_HUFF_SYMBOLS]; syms0[0].m_key = 1; - syms0[0].m_sym_index = 0; // dummy symbol, assures that no valid code contains all 1's + syms0[0].m_sym_index = + 0; // dummy symbol, assures that no valid code contains all 1's int num_used_syms = 1; const uint32 *pSym_count = &m_huff_count[table_num][0]; for (int i = 0; i < table_len; i++) @@ -372,9 +408,11 @@ void jpeg_encoder::optimize_huffman_table(int table_num, int table_len) for (int i = 0; i < num_used_syms; i++) num_codes[pSyms[i].m_key]++; - const uint JPGE_CODE_SIZE_LIMIT = 16; // the maximum possible size of a JPEG Huffman code (valid range is [9,16] - 9 - // vs. 8 because of the dummy symbol) - huffman_enforce_max_code_size(num_codes, num_used_syms, JPGE_CODE_SIZE_LIMIT); + const uint JPGE_CODE_SIZE_LIMIT = + 16; // the maximum possible size of a JPEG Huffman code (valid range is + // [9,16] - 9 vs. 8 because of the dummy symbol) + huffman_enforce_max_code_size(num_codes, num_used_syms, + JPGE_CODE_SIZE_LIMIT); // Compute m_huff_bits array, which contains the # of symbols per code size. clear_obj(m_huff_bits[table_num]); @@ -391,15 +429,18 @@ void jpeg_encoder::optimize_huffman_table(int table_num, int table_len) } } - // Compute the m_huff_val array, which contains the symbol indices sorted by code size (smallest to largest). + // Compute the m_huff_val array, which contains the symbol indices sorted by + // code size (smallest to largest). for (int i = num_used_syms - 1; i >= 1; i--) - m_huff_val[table_num][num_used_syms - 1 - i] = static_cast(pSyms[i].m_sym_index - 1); + m_huff_val[table_num][num_used_syms - 1 - i] = + static_cast(pSyms[i].m_sym_index - 1); } // JPEG marker generation. void jpeg_encoder::emit_byte(uint8 i) { - m_all_stream_writes_succeeded = m_all_stream_writes_succeeded && m_pStream->put_obj(i); + m_all_stream_writes_succeeded = + m_all_stream_writes_succeeded && m_pStream->put_obj(i); } void jpeg_encoder::emit_word(uint i) @@ -457,9 +498,10 @@ void jpeg_encoder::emit_sof() emit_byte(m_num_components); for (int i = 0; i < m_num_components; i++) { - emit_byte(static_cast(i + 1)); /* component ID */ - emit_byte((m_comp_h_samp[i] << 4) + m_comp_v_samp[i]); /* h and v sampling */ - emit_byte(i > 0); /* quant. table num */ + emit_byte(static_cast(i + 1)); /* component ID */ + emit_byte((m_comp_h_samp[i] << 4) + m_comp_v_samp[i]); /* h and v + sampling */ + emit_byte(i > 0); /* quant. table num */ } } @@ -524,8 +566,10 @@ void jpeg_encoder::emit_markers() emit_sos(); } -// Compute the actual canonical Huffman codes/code sizes given the JPEG huff bits and val arrays. -void jpeg_encoder::compute_huffman_table(uint *codes, uint8 *code_sizes, uint8 *bits, uint8 *val) +// Compute the actual canonical Huffman codes/code sizes given the JPEG huff +// bits and val arrays. +void jpeg_encoder::compute_huffman_table(uint *codes, uint8 *code_sizes, + uint8 *bits, uint8 *val) { int i, l, last_p, si; uint8 huff_size[257]; @@ -589,13 +633,17 @@ void jpeg_encoder::first_pass_init() bool jpeg_encoder::second_pass_init() { - compute_huffman_table(&m_huff_codes[0 + 0][0], &m_huff_code_sizes[0 + 0][0], m_huff_bits[0 + 0], m_huff_val[0 + 0]); - compute_huffman_table(&m_huff_codes[2 + 0][0], &m_huff_code_sizes[2 + 0][0], m_huff_bits[2 + 0], m_huff_val[2 + 0]); + compute_huffman_table(&m_huff_codes[0 + 0][0], &m_huff_code_sizes[0 + 0][0], + m_huff_bits[0 + 0], m_huff_val[0 + 0]); + compute_huffman_table(&m_huff_codes[2 + 0][0], &m_huff_code_sizes[2 + 0][0], + m_huff_bits[2 + 0], m_huff_val[2 + 0]); if (m_num_components > 1) { - compute_huffman_table(&m_huff_codes[0 + 1][0], &m_huff_code_sizes[0 + 1][0], m_huff_bits[0 + 1], + compute_huffman_table(&m_huff_codes[0 + 1][0], + &m_huff_code_sizes[0 + 1][0], m_huff_bits[0 + 1], m_huff_val[0 + 1]); - compute_huffman_table(&m_huff_codes[2 + 1][0], &m_huff_code_sizes[2 + 1][0], m_huff_bits[2 + 1], + compute_huffman_table(&m_huff_codes[2 + 1][0], + &m_huff_code_sizes[2 + 1][0], m_huff_bits[2 + 1], m_huff_val[2 + 1]); } first_pass_init(); @@ -665,14 +713,16 @@ bool jpeg_encoder::jpg_open(int p_x_res, int p_y_res, int src_channels) m_image_bpl_mcu = m_image_x_mcu * m_num_components; m_mcus_per_row = m_image_x_mcu / m_mcu_x; - if ((m_mcu_lines[0] = static_cast(jpge_malloc(m_image_bpl_mcu * m_mcu_y))) == NULL) + if ((m_mcu_lines[0] = static_cast( + jpge_malloc(m_image_bpl_mcu * m_mcu_y))) == NULL) return false; for (int i = 1; i < m_mcu_y; i++) m_mcu_lines[i] = m_mcu_lines[i - 1] + m_image_bpl_mcu; compute_quant_table(m_quantization_tables[0], s_std_lum_quant); compute_quant_table(m_quantization_tables[1], - m_params.m_no_chroma_discrim_flag ? s_std_lum_quant : s_std_croma_quant); + m_params.m_no_chroma_discrim_flag ? s_std_lum_quant + : s_std_croma_quant); m_out_buf_left = JPGE_OUT_BUF_SIZE; m_pOut_buf = m_out_buf; @@ -747,14 +797,38 @@ void jpeg_encoder::load_block_16_8(int x, int c) { pSrc1 = m_mcu_lines[i + 0] + x; pSrc2 = m_mcu_lines[i + 1] + x; - pDst[0] = ((pSrc1[0 * 3] + pSrc1[1 * 3] + pSrc2[0 * 3] + pSrc2[1 * 3] + a) >> 2) - 128; - pDst[1] = ((pSrc1[2 * 3] + pSrc1[3 * 3] + pSrc2[2 * 3] + pSrc2[3 * 3] + b) >> 2) - 128; - pDst[2] = ((pSrc1[4 * 3] + pSrc1[5 * 3] + pSrc2[4 * 3] + pSrc2[5 * 3] + a) >> 2) - 128; - pDst[3] = ((pSrc1[6 * 3] + pSrc1[7 * 3] + pSrc2[6 * 3] + pSrc2[7 * 3] + b) >> 2) - 128; - pDst[4] = ((pSrc1[8 * 3] + pSrc1[9 * 3] + pSrc2[8 * 3] + pSrc2[9 * 3] + a) >> 2) - 128; - pDst[5] = ((pSrc1[10 * 3] + pSrc1[11 * 3] + pSrc2[10 * 3] + pSrc2[11 * 3] + b) >> 2) - 128; - pDst[6] = ((pSrc1[12 * 3] + pSrc1[13 * 3] + pSrc2[12 * 3] + pSrc2[13 * 3] + a) >> 2) - 128; - pDst[7] = ((pSrc1[14 * 3] + pSrc1[15 * 3] + pSrc2[14 * 3] + pSrc2[15 * 3] + b) >> 2) - 128; + pDst[0] = + ((pSrc1[0 * 3] + pSrc1[1 * 3] + pSrc2[0 * 3] + pSrc2[1 * 3] + a) >> + 2) - + 128; + pDst[1] = + ((pSrc1[2 * 3] + pSrc1[3 * 3] + pSrc2[2 * 3] + pSrc2[3 * 3] + b) >> + 2) - + 128; + pDst[2] = + ((pSrc1[4 * 3] + pSrc1[5 * 3] + pSrc2[4 * 3] + pSrc2[5 * 3] + a) >> + 2) - + 128; + pDst[3] = + ((pSrc1[6 * 3] + pSrc1[7 * 3] + pSrc2[6 * 3] + pSrc2[7 * 3] + b) >> + 2) - + 128; + pDst[4] = + ((pSrc1[8 * 3] + pSrc1[9 * 3] + pSrc2[8 * 3] + pSrc2[9 * 3] + a) >> + 2) - + 128; + pDst[5] = ((pSrc1[10 * 3] + pSrc1[11 * 3] + pSrc2[10 * 3] + + pSrc2[11 * 3] + b) >> + 2) - + 128; + pDst[6] = ((pSrc1[12 * 3] + pSrc1[13 * 3] + pSrc2[12 * 3] + + pSrc2[13 * 3] + a) >> + 2) - + 128; + pDst[7] = ((pSrc1[14 * 3] + pSrc1[15 * 3] + pSrc2[14 * 3] + + pSrc2[15 * 3] + b) >> + 2) - + 128; int temp = a; a = b; b = temp; @@ -809,7 +883,8 @@ void jpeg_encoder::flush_output_buffer() { if (m_out_buf_left != JPGE_OUT_BUF_SIZE) m_all_stream_writes_succeeded = - m_all_stream_writes_succeeded && m_pStream->put_buf(m_out_buf, JPGE_OUT_BUF_SIZE - m_out_buf_left); + m_all_stream_writes_succeeded && + m_pStream->put_buf(m_out_buf, JPGE_OUT_BUF_SIZE - m_out_buf_left); m_pOut_buf = m_out_buf; m_out_buf_left = JPGE_OUT_BUF_SIZE; } @@ -840,8 +915,10 @@ void jpeg_encoder::code_coefficients_pass_one(int component_num) return; // just to shut up static analysis int i, run_len, nbits, temp1; int16 *src = m_coefficient_array; - uint32 *dc_count = component_num ? m_huff_count[0 + 1] : m_huff_count[0 + 0], - *ac_count = component_num ? m_huff_count[2 + 1] : m_huff_count[2 + 0]; + uint32 *dc_count = + component_num ? m_huff_count[0 + 1] : m_huff_count[0 + 0], + *ac_count = + component_num ? m_huff_count[2 + 1] : m_huff_count[2 + 0]; temp1 = src[0] - m_last_dc_val[component_num]; m_last_dc_val[component_num] = src[0]; @@ -1045,7 +1122,8 @@ bool jpeg_encoder::process_end_of_image() if (m_mcu_y_ofs < 16) // check here just to shut up static analysis { for (int i = m_mcu_y_ofs; i < m_mcu_y; i++) - memcpy(m_mcu_lines[i], m_mcu_lines[m_mcu_y_ofs - 1], m_image_bpl_mcu); + memcpy(m_mcu_lines[i], m_mcu_lines[m_mcu_y_ofs - 1], + m_image_bpl_mcu); } process_mcu_row(); @@ -1061,7 +1139,8 @@ void jpeg_encoder::load_mcu(const void *pSrc) { const uint8 *Psrc = reinterpret_cast(pSrc); - uint8 *pDst = m_mcu_lines[m_mcu_y_ofs]; // OK to write up to m_image_bpl_xlt bytes to pDst + uint8 *pDst = m_mcu_lines[m_mcu_y_ofs]; // OK to write up to m_image_bpl_xlt + // bytes to pDst if (m_num_components == 1) { @@ -1084,10 +1163,12 @@ void jpeg_encoder::load_mcu(const void *pSrc) // Possibly duplicate pixels at end of scanline if not a multiple of 8 or 16 if (m_num_components == 1) - memset(m_mcu_lines[m_mcu_y_ofs] + m_image_bpl_xlt, pDst[m_image_bpl_xlt - 1], m_image_x_mcu - m_image_x); + memset(m_mcu_lines[m_mcu_y_ofs] + m_image_bpl_xlt, + pDst[m_image_bpl_xlt - 1], m_image_x_mcu - m_image_x); else { - const uint8 y = pDst[m_image_bpl_xlt - 3 + 0], cb = pDst[m_image_bpl_xlt - 3 + 1], + const uint8 y = pDst[m_image_bpl_xlt - 3 + 0], + cb = pDst[m_image_bpl_xlt - 3 + 1], cr = pDst[m_image_bpl_xlt - 3 + 2]; uint8 *q = m_mcu_lines[m_mcu_y_ofs] + m_image_bpl_xlt; for (int i = m_image_x; i < m_image_x_mcu; i++) @@ -1122,11 +1203,13 @@ jpeg_encoder::~jpeg_encoder() deinit(); } -bool jpeg_encoder::init(output_stream *pStream, int width, int height, int src_channels, const params &comp_params) +bool jpeg_encoder::init(output_stream *pStream, int width, int height, + int src_channels, const params &comp_params) { deinit(); if (((!pStream) || (width < 1) || (height < 1)) || - ((src_channels != 1) && (src_channels != 3) && (src_channels != 4)) || (!comp_params.check())) + ((src_channels != 1) && (src_channels != 3) && (src_channels != 4)) || + (!comp_params.check())) return false; m_pStream = pStream; m_params = comp_params; @@ -1209,8 +1292,9 @@ class cfile_stream : public output_stream }; // Writes JPEG image to file. -bool compress_image_to_jpeg_file(const char *pFilename, int width, int height, int num_channels, - const uint8 *pImage_data, const params &comp_params) +bool compress_image_to_jpeg_file(const char *pFilename, int width, int height, + int num_channels, const uint8 *pImage_data, + const params &comp_params) { cfile_stream dst_stream; if (!dst_stream.open(pFilename)) @@ -1220,7 +1304,8 @@ bool compress_image_to_jpeg_file(const char *pFilename, int width, int height, i if (!dst_image.init(&dst_stream, width, height, num_channels, comp_params)) return false; - for (uint pass_index = 0; pass_index < dst_image.get_total_passes(); pass_index++) + for (uint pass_index = 0; pass_index < dst_image.get_total_passes(); + pass_index++) { for (int i = 0; i < height; i++) { @@ -1268,8 +1353,11 @@ class memory_stream : public output_stream uint get_size() const { return m_buf_ofs; } }; -bool compress_image_to_jpeg_file_in_memory(void *pDstBuf, int &buf_size, int width, int height, int num_channels, - const uint8 *pImage_data, const params &comp_params) +bool compress_image_to_jpeg_file_in_memory(void *pDstBuf, int &buf_size, + int width, int height, + int num_channels, + const uint8 *pImage_data, + const params &comp_params) { if ((!pDstBuf) || (!buf_size)) return false; @@ -1282,7 +1370,8 @@ bool compress_image_to_jpeg_file_in_memory(void *pDstBuf, int &buf_size, int wid if (!dst_image.init(&dst_stream, width, height, num_channels, comp_params)) return false; - for (uint pass_index = 0; pass_index < dst_image.get_total_passes(); pass_index++) + for (uint pass_index = 0; pass_index < dst_image.get_total_passes(); + pass_index++) { for (int i = 0; i < height; i++) { diff --git a/solr/images/jpge.h b/solr/images/jpge.h index 791736a..9964634 100644 --- a/solr/images/jpge.h +++ b/solr/images/jpge.h @@ -4,7 +4,7 @@ #ifndef JPEG_ENCODER_H #define JPEG_ENCODER_H -#include "../DLL_API.h" +#include "../api.h" namespace jpge { @@ -15,7 +15,8 @@ typedef unsigned short uint16; typedef unsigned int uint32; typedef unsigned int uint; -// JPEG chroma subsampling factors. Y_ONLY (grayscale images) and H2V2 (color images) are the most common. +// JPEG chroma subsampling factors. Y_ONLY (grayscale images) and H2V2 (color +// images) are the most common. enum subsampling_t { Y_ONLY = 0, @@ -62,19 +63,24 @@ struct params }; // Writes JPEG image to a file. -// num_channels must be 1 (Y) or 3 (RGB), image pitch must be width*num_channels. -bool SOLR_API compress_image_to_jpeg_file(const char *pFilename, int width, int height, int num_channels, - const uint8 *pImage_data, const params &comp_params = params()); +// num_channels must be 1 (Y) or 3 (RGB), image pitch must be +// width*num_channels. +bool SOLR_API compress_image_to_jpeg_file(const char *pFilename, int width, + int height, int num_channels, + const uint8 *pImage_data, + const params &comp_params = params()); // Writes JPEG image to memory buffer. -// On entry, buf_size is the size of the output buffer pointed at by pBuf, which should be at least ~1024 bytes. -// If return value is true, buf_size will be set to the size of the compressed data. -bool SOLR_API compress_image_to_jpeg_file_in_memory(void *pBuf, int &buf_size, int width, int height, int num_channels, - const uint8 *pImage_data, const params &comp_params = params()); - -// Output stream abstract class - used by the jpeg_encoder class to write to the output stream. -// put_buf() is generally called with len==JPGE_OUT_BUF_SIZE bytes, but for headers it'll be called with smaller -// amounts. +// On entry, buf_size is the size of the output buffer pointed at by pBuf, which +// should be at least ~1024 bytes. If return value is true, buf_size will be set +// to the size of the compressed data. +bool SOLR_API compress_image_to_jpeg_file_in_memory( + void *pBuf, int &buf_size, int width, int height, int num_channels, + const uint8 *pImage_data, const params &comp_params = params()); + +// Output stream abstract class - used by the jpeg_encoder class to write to the +// output stream. put_buf() is generally called with len==JPGE_OUT_BUF_SIZE +// bytes, but for headers it'll be called with smaller amounts. class output_stream { public: @@ -87,7 +93,8 @@ class output_stream } }; -// Lower level jpeg_encoder class - useful if more control is needed than the above helper functions. +// Lower level jpeg_encoder class - useful if more control is needed than the +// above helper functions. class jpeg_encoder { public: @@ -98,13 +105,15 @@ class jpeg_encoder // pStream: The stream object to use for writing compressed data. // params - Compression parameters structure, defined above. // width, height - Image dimensions. - // channels - May be 1, or 3. 1 indicates grayscale, 3 indicates RGB source data. - // Returns false on out of memory or if a stream write fails. - bool init(output_stream *pStream, int width, int height, int src_channels, const params &comp_params = params()); + // channels - May be 1, or 3. 1 indicates grayscale, 3 indicates RGB source + // data. Returns false on out of memory or if a stream write fails. + bool init(output_stream *pStream, int width, int height, int src_channels, + const params &comp_params = params()); const params &get_params() const { return m_params; } - // Deinitializes the compressor, freeing any allocated memory. May be called at any time. + // Deinitializes the compressor, freeing any allocated memory. May be called + // at any time. void deinit(); uint get_total_passes() const { return m_params.m_two_pass_flag ? 2 : 1; } @@ -112,8 +121,8 @@ class jpeg_encoder // Call this method with each source scanline. // width * src_channels bytes per scanline is expected (RGB or Y format). - // You must call with NULL after all scanlines are processed to finish compression. - // Returns false on out of memory or if a stream write fails. + // You must call with NULL after all scanlines are processed to finish + // compression. Returns false on out of memory or if a stream write fails. bool process_scanline(const void *pScanline); private: @@ -165,7 +174,8 @@ class jpeg_encoder void emit_dhts(); void emit_sos(); void emit_markers(); - void compute_huffman_table(uint *codes, uint8 *code_sizes, uint8 *bits, uint8 *val); + void compute_huffman_table(uint *codes, uint8 *code_sizes, uint8 *bits, + uint8 *val); void compute_quant_table(int32 *dst, int16 *src); void adjust_quant_table(int32 *dst, int32 *src); void first_pass_init(); diff --git a/solr/images/tgad.cpp b/solr/images/tgad.cpp index 9c3662c..aa2dc1b 100644 --- a/solr/images/tgad.cpp +++ b/solr/images/tgad.cpp @@ -1,24 +1,26 @@ #define _CRT_SECURE_NO_WARNINGS -#include -#include #include +#include +#include #include "../Logging.h" #include "tgad.h" /******************************************************************************** -/name : LoadTGA(Texture * texture, char * filename) * -/function: Open and test the file to make sure it is a valid TGA file * -/parems: texture, pointer to a Texture structure * -/ filename, string pointing to file to open * +/name : LoadTGA(Texture * texture, char * filename) * /function: Open and +test the file to make sure it is a valid TGA file * /parems: texture, +pointer to a Texture structure * +/ filename, string pointing to file to open * /********************************************************************************/ -unsigned char uTGAcompare[12] = {0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // Uncompressed TGA Header -unsigned char cTGAcompare[12] = {0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // Compressed TGA Header -TGAHeader tgaheader; // TGA header -TGA tga; // TGA image data +unsigned char uTGAcompare[12] = {0, 0, 2, 0, 0, 0, + 0, 0, 0, 0, 0, 0}; // Uncompressed TGA Header +unsigned char cTGAcompare[12] = {0, 0, 10, 0, 0, 0, + 0, 0, 0, 0, 0, 0}; // Compressed TGA Header +TGAHeader tgaheader; // TGA header +TGA tga; // TGA image data bool LoadTGA(Texture *texture, char *filename) // Load a TGA file { @@ -27,28 +29,36 @@ bool LoadTGA(Texture *texture, char *filename) // Load a TGA file if (fTGA == NULL) // If it didn't open.... { - LOG_ERROR("Could not open texture file" << filename); // Display an error message - return false; // Exit function + LOG_ERROR("Could not open texture file" + << filename); // Display an error message + return false; // Exit function } TGAHeader tgaheader; - if (fread(&tgaheader, sizeof(TGAHeader), 1, fTGA) == 0) // Attempt to read 12 byte header from file + if (fread(&tgaheader, sizeof(TGAHeader), 1, fTGA) == + 0) // Attempt to read 12 byte header from file { - LOG_ERROR("Could not read file header"); // If it fails, display an error message - if (fTGA != NULL) // Check to seeiffile is still open + LOG_ERROR("Could not read file header"); // If it fails, display an + // error message + if (fTGA != NULL) // Check to seeiffile is still open { fclose(fTGA); // If it is, close it } return false; // Exit function } - if (memcmp(uTGAcompare, &tgaheader, sizeof(tgaheader)) == 0) // See if header matches the predefined header of - { // an Uncompressed TGA image - LoadUncompressedTGA(texture, filename, fTGA); // If so, jump to Uncompressed TGA loading code + if (memcmp(uTGAcompare, &tgaheader, sizeof(tgaheader)) == + 0) // See if header matches the predefined header of + { // an Uncompressed TGA image + LoadUncompressedTGA(texture, filename, + fTGA); // If so, jump to Uncompressed TGA loading + // code } - else if (memcmp(cTGAcompare, &tgaheader, sizeof(tgaheader)) == 0) // See if header matches the predefined header of - { // an RLE compressed TGA image - LoadCompressedTGA(texture, filename, fTGA); // If so, jump to Compressed TGA loading code + else if (memcmp(cTGAcompare, &tgaheader, sizeof(tgaheader)) == + 0) // See if header matches the predefined header of + { // an RLE compressed TGA image + LoadCompressedTGA(texture, filename, + fTGA); // If so, jump to Compressed TGA loading code } else // If header matches neither type { @@ -60,7 +70,8 @@ bool LoadTGA(Texture *texture, char *filename) // Load a TGA file } bool LoadUncompressedTGA(Texture *texture, char *filename, - FILE *fTGA) // Load an uncompressed TGA (note, much of this code is based on NeHe's + FILE *fTGA) // Load an uncompressed TGA (note, much of + // this code is based on NeHe's { // TGA Loading code nehe.gamedev.net) if (fread(tga.header, sizeof(tga.header), 1, fTGA) == 0) // Read TGA header @@ -73,15 +84,20 @@ bool LoadUncompressedTGA(Texture *texture, char *filename, return false; // Return failular } - texture->width = tga.header[1] * 256 + tga.header[0]; // Determine The TGA Width (highbyte*256+lowbyte) - texture->height = tga.header[3] * 256 + tga.header[2]; // Determine The TGA Height (highbyte*256+lowbyte) - texture->bpp = tga.header[4]; // Determine the bits per pixel - tga.Width = texture->width; // Copy width into local structure - tga.Height = texture->height; // Copy height into local structure - tga.Bpp = texture->bpp; // Copy BPP into local structure + texture->width = + tga.header[1] * 256 + + tga.header[0]; // Determine The TGA Width (highbyte*256+lowbyte) + texture->height = + tga.header[3] * 256 + + tga.header[2]; // Determine The TGA Height (highbyte*256+lowbyte) + texture->bpp = tga.header[4]; // Determine the bits per pixel + tga.Width = texture->width; // Copy width into local structure + tga.Height = texture->height; // Copy height into local structure + tga.Bpp = texture->bpp; // Copy BPP into local structure if ((texture->width <= 0) || (texture->height <= 0) || - ((texture->bpp != 24) && (texture->bpp != 32))) // Make sure all information is valid + ((texture->bpp != 24) && (texture->bpp != 32))) // Make sure all + // information is valid { LOG_ERROR("Invalid texture information"); // Display Error if (fTGA != NULL) // Check if file is still open @@ -92,16 +108,20 @@ bool LoadUncompressedTGA(Texture *texture, char *filename, } /* - if(texture->bpp == 24) // If the BPP of the image is 24... - texture->type = GL_RGB; // Set Image type to GL_RGB - else // Else if its 32 BPP - texture->type = GL_RGBA; // Set image type to GL_RGBA + if(texture->bpp == 24) // + If the BPP of the image is 24... texture->type = GL_RGB; + // Set Image type to GL_RGB else + // Else if its 32 BPP + texture->type = GL_RGBA; // Set image type to + GL_RGBA */ tga.bytesPerPixel = (tga.Bpp / 8); // Compute the number of BYTES per pixel tga.imageSize = - (tga.bytesPerPixel * tga.Width * tga.Height); // Compute the total amout ofmemory needed to store data - texture->imageData = (unsigned char *)malloc(tga.imageSize); // Allocate that much memory + (tga.bytesPerPixel * tga.Width * + tga.Height); // Compute the total amout ofmemory needed to store data + texture->imageData = + (unsigned char *)malloc(tga.imageSize); // Allocate that much memory if (texture->imageData == NULL) // If no space was allocated { @@ -110,7 +130,8 @@ bool LoadUncompressedTGA(Texture *texture, char *filename, return false; // Return failed } - if (fread(texture->imageData, 1, tga.imageSize, fTGA) != tga.imageSize) // Attempt to read image data + if (fread(texture->imageData, 1, tga.imageSize, fTGA) != + tga.imageSize) // Attempt to read image data { LOG_ERROR("Could not read image data"); // Display Error if (texture->imageData != NULL) // If imagedata has data in it @@ -122,19 +143,22 @@ bool LoadUncompressedTGA(Texture *texture, char *filename, } // Byte Swapping Optimized By Steve Thomas - for (unsigned int cswap = 0; cswap < (int)tga.imageSize; cswap += tga.bytesPerPixel) + for (unsigned int cswap = 0; cswap < (int)tga.imageSize; + cswap += tga.bytesPerPixel) { - texture->imageData[cswap] ^= texture->imageData[cswap + 2] ^= texture->imageData[cswap] ^= - texture->imageData[cswap + 2]; + texture->imageData[cswap] ^= texture->imageData[cswap + 2] ^= + texture->imageData[cswap] ^= texture->imageData[cswap + 2]; } fclose(fTGA); // Close file return true; // Return success } -bool LoadCompressedTGA(Texture *texture, char *filename, FILE *fTGA) // Load COMPRESSED TGAs +bool LoadCompressedTGA(Texture *texture, char *filename, + FILE *fTGA) // Load COMPRESSED TGAs { - if (fread(tga.header, sizeof(tga.header), 1, fTGA) == 0) // Attempt to read header + if (fread(tga.header, sizeof(tga.header), 1, fTGA) == 0) // Attempt to read + // header { LOG_ERROR("Could not read info header"); // Display Error if (fTGA != NULL) // If file is open @@ -144,15 +168,20 @@ bool LoadCompressedTGA(Texture *texture, char *filename, FILE *fTGA) // Load COM return false; // Return failed } - texture->width = tga.header[1] * 256 + tga.header[0]; // Determine The TGA Width (highbyte*256+lowbyte) - texture->height = tga.header[3] * 256 + tga.header[2]; // Determine The TGA Height (highbyte*256+lowbyte) - texture->bpp = tga.header[4]; // Determine Bits Per Pixel - tga.Width = texture->width; // Copy width to local structure - tga.Height = texture->height; // Copy width to local structure - tga.Bpp = texture->bpp; // Copy width to local structure + texture->width = + tga.header[1] * 256 + + tga.header[0]; // Determine The TGA Width (highbyte*256+lowbyte) + texture->height = + tga.header[3] * 256 + + tga.header[2]; // Determine The TGA Height (highbyte*256+lowbyte) + texture->bpp = tga.header[4]; // Determine Bits Per Pixel + tga.Width = texture->width; // Copy width to local structure + tga.Height = texture->height; // Copy width to local structure + tga.Bpp = texture->bpp; // Copy width to local structure if ((texture->width <= 0) || (texture->height <= 0) || - ((texture->bpp != 24) && (texture->bpp != 32))) // Make sure all texture info is ok + ((texture->bpp != 24) && (texture->bpp != 32))) // Make sure all texture + // info is ok { LOG_ERROR("Invalid texture information"); // If it isnt...Display error if (fTGA != NULL) // Check if file is open @@ -163,15 +192,20 @@ bool LoadCompressedTGA(Texture *texture, char *filename, FILE *fTGA) // Load COM } /* - if(texture->bpp == 24) // If the BPP of the image is 24... - texture->type = GL_RGB; // Set Image type to GL_RGB - else // Else if its 32 BPP - texture->type = GL_RGBA; // Set image type to GL_RGBA + if(texture->bpp == 24) // + If the BPP of the image is 24... texture->type = GL_RGB; + // Set Image type to GL_RGB else + // Else if its 32 BPP + texture->type = GL_RGBA; // Set image type to + GL_RGBA */ - tga.bytesPerPixel = (tga.Bpp / 8); // Compute BYTES per pixel - tga.imageSize = (tga.bytesPerPixel * tga.Width * tga.Height); // Compute amout of memory needed to store image - texture->imageData = (unsigned char *)malloc(tga.imageSize); // Allocate that much memory + tga.bytesPerPixel = (tga.Bpp / 8); // Compute BYTES per pixel + tga.imageSize = + (tga.bytesPerPixel * tga.Width * tga.Height); // Compute amout of memory + // needed to store image + texture->imageData = + (unsigned char *)malloc(tga.imageSize); // Allocate that much memory if (texture->imageData == NULL) // If it wasnt allocated correctly.. { @@ -180,16 +214,19 @@ bool LoadCompressedTGA(Texture *texture, char *filename, FILE *fTGA) // Load COM return false; // Return failed } - unsigned int pixelcount = tga.Height * tga.Width; // Nuber of pixels in the image - unsigned int currentpixel = 0; // Current pixel being read - unsigned int currentbyte = 0; // Current byte - unsigned char *colorbuffer = (unsigned char *)malloc(tga.bytesPerPixel); // Storage for 1 pixel + unsigned int pixelcount = + tga.Height * tga.Width; // Nuber of pixels in the image + unsigned int currentpixel = 0; // Current pixel being read + unsigned int currentbyte = 0; // Current byte + unsigned char *colorbuffer = + (unsigned char *)malloc(tga.bytesPerPixel); // Storage for 1 pixel do { unsigned char chunkheader = 0; // Storage for "chunk" header - if (fread(&chunkheader, sizeof(unsigned char), 1, fTGA) == 0) // Read in the 1 byte header + if (fread(&chunkheader, sizeof(unsigned char), 1, fTGA) == + 0) // Read in the 1 byte header { LOG_ERROR("Could not read RLE header"); // Display Error if (fTGA != NULL) // If file is open @@ -203,26 +240,32 @@ bool LoadCompressedTGA(Texture *texture, char *filename, FILE *fTGA) // Load COM return false; // Return failed } - if (chunkheader < 128) // If the ehader is < 128, it means the that is the number of RAW color packets minus 1 + if (chunkheader < 128) // If the ehader is < 128, it means the that is + // the number of RAW color packets minus 1 { // that follow the header chunkheader++; // add 1 to get number of following color values - for (short counter = 0; counter < chunkheader; counter++) // Read RAW color values + for (short counter = 0; counter < chunkheader; + counter++) // Read RAW color values { - if (fread(colorbuffer, 1, tga.bytesPerPixel, fTGA) != tga.bytesPerPixel) // Try to read 1 pixel + if (fread(colorbuffer, 1, tga.bytesPerPixel, fTGA) != + tga.bytesPerPixel) // Try to read 1 pixel { - LOG_ERROR("Could not read image data"); // IF we cant, display an error + LOG_ERROR("Could not read image data"); // IF we cant, + // display an error if (fTGA != NULL) // See if file is open { fclose(fTGA); // If so, close file } - if (colorbuffer != NULL) // See if colorbuffer has data in it + if (colorbuffer != NULL) // See if colorbuffer has data in + // it { free(colorbuffer); // If so, delete it } - if (texture->imageData != NULL) // See if there is stored Image data + if (texture->imageData != NULL) // See if there is stored + // Image data { free(texture->imageData); // If so, delete it too } @@ -230,21 +273,29 @@ bool LoadCompressedTGA(Texture *texture, char *filename, FILE *fTGA) // Load COM return false; // Return failed } // write to memory - texture->imageData[currentbyte] = colorbuffer[2]; // Flip R and B vcolor values around in the process + texture->imageData[currentbyte] = + colorbuffer[2]; // Flip R and B vcolor values around in the + // process texture->imageData[currentbyte + 1] = colorbuffer[1]; texture->imageData[currentbyte + 2] = colorbuffer[0]; if (tga.bytesPerPixel == 4) // if its a 32 bpp image { - texture->imageData[currentbyte + 3] = colorbuffer[3]; // copy the 4th byte + texture->imageData[currentbyte + 3] = + colorbuffer[3]; // copy the 4th byte } - currentbyte += tga.bytesPerPixel; // Increase thecurrent byte by the number of bytes per pixel - currentpixel++; // Increase current pixel by 1 + currentbyte += + tga.bytesPerPixel; // Increase thecurrent byte by the number + // of bytes per pixel + currentpixel++; // Increase current pixel by 1 - if (currentpixel > pixelcount) // Make sure we havent read too many pixels + if (currentpixel > pixelcount) // Make sure we havent read too + // many pixels { - LOG_ERROR("Too many pixels read"); // if there is too many... Display an error! + LOG_ERROR("Too many pixels read"); // if there is too + // many... Display an + // error! if (fTGA != NULL) // If there is a file open { @@ -265,13 +316,16 @@ bool LoadCompressedTGA(Texture *texture, char *filename, FILE *fTGA) // Load COM } } } - else // chunkheader > 128 RLE data, next color reapeated chunkheader - 127 times + else // chunkheader > 128 RLE data, next color reapeated chunkheader - + // 127 times { chunkheader -= 127; // Subteact 127 to get rid of the ID bit if (fread(colorbuffer, 1, tga.bytesPerPixel, fTGA) != - tga.bytesPerPixel) // Attempt to read following color values + tga.bytesPerPixel) // Attempt to read following color + // values { - LOG_ERROR("Could not read from file"); // If attempt fails.. Display error (again) + LOG_ERROR("Could not read from file"); // If attempt fails.. + // Display error (again) if (fTGA != NULL) // If thereis a file open { @@ -292,23 +346,32 @@ bool LoadCompressedTGA(Texture *texture, char *filename, FILE *fTGA) // Load COM } for (short counter = 0; counter < chunkheader; - counter++) // copy the color into the image data as many times as dictated + counter++) // copy the color into the image data as many times + // as dictated { // by the header - texture->imageData[currentbyte] = colorbuffer[2]; // switch R and B bytes areound while copying + texture->imageData[currentbyte] = + colorbuffer[2]; // switch R and B bytes areound while + // copying texture->imageData[currentbyte + 1] = colorbuffer[1]; texture->imageData[currentbyte + 2] = colorbuffer[0]; if (tga.bytesPerPixel == 4) // If TGA images is 32 bpp { - texture->imageData[currentbyte + 3] = colorbuffer[3]; // Copy 4th byte + texture->imageData[currentbyte + 3] = + colorbuffer[3]; // Copy 4th byte } - currentbyte += tga.bytesPerPixel; // Increase current byte by the number of bytes per pixel - currentpixel++; // Increase pixel count by 1 + currentbyte += + tga.bytesPerPixel; // Increase current byte by the number of + // bytes per pixel + currentpixel++; // Increase pixel count by 1 - if (currentpixel > pixelcount) // Make sure we havent written too many pixels + if (currentpixel > pixelcount) // Make sure we havent written + // too many pixels { - LOG_ERROR("Too many pixels read"); // if there is too many... Display an error! + LOG_ERROR("Too many pixels read"); // if there is too + // many... Display an + // error! if (fTGA != NULL) // If there is a file open { diff --git a/solr/images/tgad.h b/solr/images/tgad.h index 5dd208f..d7dfa9e 100644 --- a/solr/images/tgad.h +++ b/solr/images/tgad.h @@ -25,17 +25,20 @@ typedef struct typedef struct { unsigned char header[6]; // First 6 Useful Bytes From The Header - unsigned int bytesPerPixel; // Holds Number Of Bytes Per Pixel Used In The TGA File - unsigned int imageSize; // Used To Store The Image Size When Setting Aside Ram - unsigned int temp; // Temporary Variable + unsigned int bytesPerPixel; // Holds Number Of Bytes Per Pixel Used In The + // TGA File + unsigned int imageSize; // Used To Store The Image Size When Setting Aside + // Ram + unsigned int temp; // Temporary Variable unsigned int type; unsigned int Height; // Height of Image unsigned int Width; // Width ofImage unsigned int Bpp; // Bits Per Pixel } TGA; -bool LoadTGA(Texture *texture, char *filename); // Load a TGA file -bool LoadUncompressedTGA(Texture *, char *, FILE *); // Load an Uncompressed file -bool LoadCompressedTGA(Texture *, char *, FILE *); // Load a Compressed file +bool LoadTGA(Texture *texture, char *filename); // Load a TGA file +bool LoadUncompressedTGA(Texture *, char *, + FILE *); // Load an Uncompressed file +bool LoadCompressedTGA(Texture *, char *, FILE *); // Load a Compressed file #endif diff --git a/solr/io/FileMarshaller.cpp b/solr/io/FileMarshaller.cpp index 81ba75f..c77913c 100644 --- a/solr/io/FileMarshaller.cpp +++ b/solr/io/FileMarshaller.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #ifdef WIN32 @@ -31,8 +28,8 @@ #include #include -#include "../Consts.h" #include "../Logging.h" +#include "../consts.h" #include "FileMarshaller.h" @@ -47,20 +44,23 @@ const size_t FORMAT_VERSION = 1; #else const size_t FORMAT_VERSION = 2; #endif -} +} // namespace namespace solr { -vec4f FileMarshaller::loadFromFile(GPUKernel &kernel, const std::string &filename, const vec4f ¢er, - const float scale) +vec4f FileMarshaller::loadFromFile(GPUKernel &kernel, + const std::string &filename, + const vec4f ¢er, const float scale) { LOG_INFO(1, "IRT Filename.......: " << filename); vec4f returnValue = make_vec4f(0.f, 0.f, 0.f, 0.f); - vec4f min = make_vec4f(kernel.getSceneInfo().viewDistance, kernel.getSceneInfo().viewDistance, - kernel.getSceneInfo().viewDistance); - vec4f max = make_vec4f(-kernel.getSceneInfo().viewDistance, -kernel.getSceneInfo().viewDistance, - -kernel.getSceneInfo().viewDistance); + vec4f min = make_vec4f(kernel.getSceneInfo().viewDistance, + kernel.getSceneInfo().viewDistance, + kernel.getSceneInfo().viewDistance); + vec4f max = make_vec4f(-kernel.getSceneInfo().viewDistance, + -kernel.getSceneInfo().viewDistance, + -kernel.getSceneInfo().viewDistance); std::ifstream myfile; myfile.open(filename.c_str(), std::ifstream::binary); @@ -93,23 +93,35 @@ vec4f FileMarshaller::loadFromFile(GPUKernel &kernel, const std::string &filenam CPUPrimitive primitive; myfile.read((char *)&primitive, sizeof(CPUPrimitive)); - int n = kernel.addPrimitive(static_cast(primitive.type)); - kernel.setPrimitive(n, center.x + primitive.p0.x, center.y + primitive.p0.y, center.z + primitive.p0.z, - center.x + primitive.p1.x, center.y + primitive.p1.y, center.z + primitive.p1.z, - center.x + primitive.p2.x, center.y + primitive.p2.y, center.z + primitive.p2.z, - primitive.size.x, primitive.size.y, primitive.size.z, primitive.materialId); + int n = + kernel.addPrimitive(static_cast(primitive.type)); + kernel.setPrimitive( + n, center.x + primitive.p0.x, center.y + primitive.p0.y, + center.z + primitive.p0.z, center.x + primitive.p1.x, + center.y + primitive.p1.y, center.z + primitive.p1.z, + center.x + primitive.p2.x, center.y + primitive.p2.y, + center.z + primitive.p2.z, primitive.size.x, primitive.size.y, + primitive.size.z, primitive.materialId); kernel.setPrimitiveBellongsToModel(n, true); kernel.setPrimitiveIsMovable(n, false); - kernel.setPrimitiveNormals(n, primitive.n0, primitive.n1, primitive.n2); - kernel.setPrimitiveTextureCoordinates(n, primitive.vt0, primitive.vt1, primitive.vt2); + kernel.setPrimitiveNormals(n, primitive.n0, primitive.n1, + primitive.n2); + kernel.setPrimitiveTextureCoordinates(n, primitive.vt0, + primitive.vt1, primitive.vt2); vec4f pmin, pmax; - pmin.x = std::min(std::min(primitive.p0.x, primitive.p1.x), primitive.p2.x); - pmin.y = std::min(std::min(primitive.p0.y, primitive.p1.y), primitive.p2.y); - pmin.z = std::min(std::min(primitive.p0.z, primitive.p1.z), primitive.p2.z); - pmax.x = std::max(std::max(primitive.p0.x, primitive.p1.x), primitive.p2.x); - pmax.y = std::max(std::max(primitive.p0.y, primitive.p1.y), primitive.p2.y); - pmax.z = std::max(std::max(primitive.p0.z, primitive.p1.z), primitive.p2.z); + pmin.x = std::min(std::min(primitive.p0.x, primitive.p1.x), + primitive.p2.x); + pmin.y = std::min(std::min(primitive.p0.y, primitive.p1.y), + primitive.p2.y); + pmin.z = std::min(std::min(primitive.p0.z, primitive.p1.z), + primitive.p2.z); + pmax.x = std::max(std::max(primitive.p0.x, primitive.p1.x), + primitive.p2.x); + pmax.y = std::max(std::max(primitive.p0.y, primitive.p1.y), + primitive.p2.y); + pmax.z = std::max(std::max(primitive.p0.z, primitive.p1.z), + primitive.p2.z); min.x = (pmin.x < min.x) ? pmin.x : min.x; min.y = (pmin.y < min.y) ? pmin.y : min.y; @@ -135,14 +147,17 @@ vec4f FileMarshaller::loadFromFile(GPUKernel &kernel, const std::string &filenam TextureInfo texInfo; myfile.read((char *)&texInfo, sizeof(TextureInfo)); - LOG_INFO(3, "Texture with id " << id << " and size: " << texInfo.size.x << "x" << texInfo.size.y << "x" - << texInfo.size.z << " loaded into slot " << nbActiveTextures + i); + LOG_INFO(3, "Texture with id " + << id << " and size: " << texInfo.size.x << "x" + << texInfo.size.y << "x" << texInfo.size.z + << " loaded into slot " << nbActiveTextures + i); size_t imageSize = texInfo.size.x * texInfo.size.y * texInfo.size.z; texInfo.buffer = new BitmapBuffer[imageSize]; myfile.read((char *)texInfo.buffer, imageSize); - kernel.setTexture(static_cast(nbActiveTextures + i), texInfo); + kernel.setTexture(static_cast(nbActiveTextures + i), + texInfo); delete[] texInfo.buffer; } @@ -175,11 +190,15 @@ vec4f FileMarshaller::loadFromFile(GPUKernel &kernel, const std::string &filenam material.advancedTextureIds.z += nbActiveTextures; if (material.advancedTextureIds.w != TEXTURE_NONE) material.advancedTextureIds.w += nbActiveTextures; - LOG_INFO(3, "Loading material " << id << " (" << material.textureIds.x << "," << material.textureIds.y - << "," << material.textureIds.z << "," << material.textureIds.w - << material.advancedTextureIds.x << "," << material.advancedTextureIds.y - << "," << material.advancedTextureIds.z << "," - << material.advancedTextureIds.w << ")"); + LOG_INFO(3, "Loading material " + << id << " (" << material.textureIds.x << "," + << material.textureIds.y << "," + << material.textureIds.z << "," + << material.textureIds.w + << material.advancedTextureIds.x << "," + << material.advancedTextureIds.y << "," + << material.advancedTextureIds.z << "," + << material.advancedTextureIds.w << ")"); kernel.setMaterial(static_cast(id), material); } } @@ -192,10 +211,14 @@ vec4f FileMarshaller::loadFromFile(GPUKernel &kernel, const std::string &filenam returnValue.z = fabs(max.z - min.z); // Resize to fit required size - float ratio = scale / returnValue.y; // std::max(returnValue.x,std::max(returnValue.y,returnValue.z)); + float ratio = + scale / + returnValue + .y; // std::max(returnValue.x,std::max(returnValue.y,returnValue.z)); kernel.scalePrimitives(ratio, 0, NB_MAX_BOXES); - LOG_INFO(3, "Object size: " << returnValue.x << ", " << returnValue.y << ", " << returnValue.z); + LOG_INFO(3, "Object size: " << returnValue.x << ", " << returnValue.y + << ", " << returnValue.z); return returnValue; } @@ -235,7 +258,8 @@ void FileMarshaller::saveToFile(GPUKernel &kernel, const std::string &filename) { CPUPrimitive *primitive = kernel.getPrimitive(i); myfile.write((char *)primitive, sizeof(CPUPrimitive)); - materials[primitive->materialId] = kernel.getMaterial(primitive->materialId); + materials[primitive->materialId] = + kernel.getMaterial(primitive->materialId); } // Determine textures in use @@ -243,25 +267,33 @@ void FileMarshaller::saveToFile(GPUKernel &kernel, const std::string &filename) for (auto material : materials) { if (material.second->textureIds.x != TEXTURE_NONE) - textures[material.second->textureIds.x] = kernel.getTextureInformation(material.second->textureIds.x); + textures[material.second->textureIds.x] = + kernel.getTextureInformation(material.second->textureIds.x); if (material.second->textureIds.y != TEXTURE_NONE) - textures[material.second->textureIds.y] = kernel.getTextureInformation(material.second->textureIds.y); + textures[material.second->textureIds.y] = + kernel.getTextureInformation(material.second->textureIds.y); if (material.second->textureIds.z != TEXTURE_NONE) - textures[material.second->textureIds.z] = kernel.getTextureInformation(material.second->textureIds.z); + textures[material.second->textureIds.z] = + kernel.getTextureInformation(material.second->textureIds.z); if (material.second->textureIds.w != TEXTURE_NONE) - textures[material.second->textureIds.w] = kernel.getTextureInformation(material.second->textureIds.w); + textures[material.second->textureIds.w] = + kernel.getTextureInformation(material.second->textureIds.w); if (material.second->advancedTextureIds.x != TEXTURE_NONE) textures[material.second->advancedTextureIds.x] = - kernel.getTextureInformation(material.second->advancedTextureIds.x); + kernel.getTextureInformation( + material.second->advancedTextureIds.x); if (material.second->advancedTextureIds.y != TEXTURE_NONE) textures[material.second->advancedTextureIds.y] = - kernel.getTextureInformation(material.second->advancedTextureIds.y); + kernel.getTextureInformation( + material.second->advancedTextureIds.y); if (material.second->advancedTextureIds.z != TEXTURE_NONE) textures[material.second->advancedTextureIds.z] = - kernel.getTextureInformation(material.second->advancedTextureIds.z); + kernel.getTextureInformation( + material.second->advancedTextureIds.z); if (material.second->advancedTextureIds.w != TEXTURE_NONE) textures[material.second->advancedTextureIds.w] = - kernel.getTextureInformation(material.second->advancedTextureIds.w); + kernel.getTextureInformation( + material.second->advancedTextureIds.w); } // Write Textures @@ -280,11 +312,13 @@ void FileMarshaller::saveToFile(GPUKernel &kernel, const std::string &filename) texInfo.offset = 0; size_t id = texture.first; idMapping[id] = static_cast(index); - LOG_INFO(1, "Texture " << id << ": " << texInfo.size.x << "x" << texInfo.size.y << "x" << texInfo.size.z + LOG_INFO(1, "Texture " << id << ": " << texInfo.size.x << "x" + << texInfo.size.y << "x" << texInfo.size.z << " saved with id " << index); myfile.write((char *)(&index), sizeof(size_t)); myfile.write((char *)(&texInfo), sizeof(TextureInfo)); - myfile.write((char *)(savedBuffer), texInfo.size.x * texInfo.size.y * texInfo.size.z); + myfile.write((char *)(savedBuffer), + texInfo.size.x * texInfo.size.y * texInfo.size.z); ++index; } @@ -295,25 +329,37 @@ void FileMarshaller::saveToFile(GPUKernel &kernel, const std::string &filename) for (const auto &material : materials) { - material.second->textureIds.x = idMapping[material.second->textureIds.x]; - material.second->textureIds.y = idMapping[material.second->textureIds.y]; - material.second->textureIds.z = idMapping[material.second->textureIds.z]; - material.second->textureIds.w = idMapping[material.second->textureIds.w]; - material.second->advancedTextureIds.x = idMapping[material.second->advancedTextureIds.x]; - material.second->advancedTextureIds.y = idMapping[material.second->advancedTextureIds.y]; - material.second->advancedTextureIds.z = idMapping[material.second->advancedTextureIds.z]; - material.second->advancedTextureIds.w = idMapping[material.second->advancedTextureIds.w]; + material.second->textureIds.x = + idMapping[material.second->textureIds.x]; + material.second->textureIds.y = + idMapping[material.second->textureIds.y]; + material.second->textureIds.z = + idMapping[material.second->textureIds.z]; + material.second->textureIds.w = + idMapping[material.second->textureIds.w]; + material.second->advancedTextureIds.x = + idMapping[material.second->advancedTextureIds.x]; + material.second->advancedTextureIds.y = + idMapping[material.second->advancedTextureIds.y]; + material.second->advancedTextureIds.z = + idMapping[material.second->advancedTextureIds.z]; + material.second->advancedTextureIds.w = + idMapping[material.second->advancedTextureIds.w]; myfile.write((char *)&(material.first), sizeof(size_t)); myfile.write((char *)(material.second), sizeof(Material)); LOG_INFO(1, "Saving material " - << material.first << " (" << material.second->textureIds.x << "," - << material.second->textureIds.y << "," << material.second->textureIds.z << "," - << material.second->textureIds.w << "," << material.second->advancedTextureIds.x << "," - << material.second->advancedTextureIds.y << "," << material.second->advancedTextureIds.z - << "," << material.second->advancedTextureIds.w << ")"); + << material.first << " (" + << material.second->textureIds.x << "," + << material.second->textureIds.y << "," + << material.second->textureIds.z << "," + << material.second->textureIds.w << "," + << material.second->advancedTextureIds.x << "," + << material.second->advancedTextureIds.y << "," + << material.second->advancedTextureIds.z << "," + << material.second->advancedTextureIds.w << ")"); } myfile.close(); } } -} +} // namespace solr diff --git a/solr/io/FileMarshaller.h b/solr/io/FileMarshaller.h index cb5306d..ed769e6 100644 --- a/solr/io/FileMarshaller.h +++ b/solr/io/FileMarshaller.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once @@ -29,8 +26,10 @@ class SOLR_API FileMarshaller public: FileMarshaller() {} ~FileMarshaller() {} + public: - vec4f loadFromFile(GPUKernel &kernel, const std::string &filename, const vec4f ¢er, const float scale); + vec4f loadFromFile(GPUKernel &kernel, const std::string &filename, + const vec4f ¢er, const float scale); void saveToFile(GPUKernel &kernel, const std::string &filename); }; -} +} // namespace solr diff --git a/solr/io/OBJReader.cpp b/solr/io/OBJReader.cpp index 0a93164..cb16f6f 100644 --- a/solr/io/OBJReader.cpp +++ b/solr/io/OBJReader.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include @@ -28,22 +25,19 @@ #include #include -#include "../Consts.h" #include "../Logging.h" +#include "../consts.h" #include "OBJReader.h" namespace solr { -const int NB_MAX_FACES = static_cast(NB_MAX_PRIMITIVES * 0.9f); // Max number of faces +const int NB_MAX_FACES = + static_cast(NB_MAX_PRIMITIVES * 0.9f); // Max number of faces -OBJReader::OBJReader() -{ -} +OBJReader::OBJReader() {} -OBJReader::~OBJReader() -{ -} +OBJReader::~OBJReader() {} vec4f readVertex(const std::string &value) { @@ -157,9 +151,9 @@ vec4i readFace(const std::string &face) return returnValue; } -unsigned int OBJReader::loadMaterialsFromFile(const std::string &filename, - std::map &materials, GPUKernel &kernel, - int materialId) +unsigned int OBJReader::loadMaterialsFromFile( + const std::string &filename, std::map &materials, + GPUKernel &kernel, int materialId) { LOG_INFO(1, " - Material library: " << filename); const float innerDiffusion = 1000.f; @@ -186,26 +180,39 @@ unsigned int OBJReader::loadMaterialsFromFile(const std::string &filename, MaterialMTL &m = materials[id]; // Grey material is reflective!!! :-) - // if(m.Kd.x>0.4f && m.Kd.x>0.6f && fabs(m.Kd.x-m.Kd.y)<0.01f && - // fabs(m.Kd.y-m.Kd.z)<0.01f) m.reflection=0.5f; + // if(m.Kd.x>0.4f && m.Kd.x>0.6f && + // fabs(m.Kd.x-m.Kd.y)<0.01f && fabs(m.Kd.y-m.Kd.z)<0.01f) + // m.reflection=0.5f; // Add material to kernel - kernel.setMaterial(m.index, m.Kd.x, m.Kd.y, m.Kd.z, m.noise, m.reflection, m.refraction, false, - false, 0, m.transparency, m.opacity, m.diffuseTextureId, m.normalTextureId, - m.bumpTextureId, m.specularTextureId, m.reflectionTextureId, - m.transparencyTextureId, m.ambientOcclusionTextureId, m.Ks.x, 100.f * m.Ks.y, - m.Ks.z, m.illumination, innerDiffusion, innerDiffusion * diffusionRatio, false); - LOG_INFO(3, "[" << m.index << "] Added material [" << id << "] " - << "( " << m.Kd.x << ", " << m.Kd.y << ", " << m.Kd.z << ") " - << "( " << m.Ks.x << ", " << m.Ks.y << ", " << m.Ks.z << ") " + kernel.setMaterial(m.index, m.Kd.x, m.Kd.y, m.Kd.z, m.gloss, + m.reflection, m.refraction, false, false, + 0, m.transparency, m.opacity, + m.diffuseTextureId, m.normalTextureId, + m.bumpTextureId, m.specularTextureId, + m.reflectionTextureId, + m.transparencyTextureId, + m.ambientOcclusionTextureId, m.Ks.x, + 100.f * m.Ks.y, m.Ks.z, m.illumination, + innerDiffusion, + innerDiffusion * diffusionRatio, false); + LOG_INFO(3, "[" << m.index << "] Added material [" << id + << "] " + << "( " << m.Kd.x << ", " << m.Kd.y << ", " + << m.Kd.z << ") " + << "( " << m.Ks.x << ", " << m.Ks.y << ", " + << m.Ks.z << ") " << "( " << m.illumination << ") " - << ", Textures [" << m.diffuseTextureId << "," << m.bumpTextureId - << "]=" << kernel.getTextureFilename(m.diffuseTextureId)); + << ", Textures [" << m.diffuseTextureId + << "," << m.bumpTextureId << "]=" + << kernel.getTextureFilename( + m.diffuseTextureId)); } id = line.substr(7); MaterialMTL material; memset(&material, 0, sizeof(MaterialMTL)); - material.index = static_cast(materials.size() + materialId); + material.index = + static_cast(materials.size() + materialId); // material.reflection = 0.2f; material.diffuseTextureId = MATERIAL_NONE; material.normalTextureId = MATERIAL_NONE; @@ -216,7 +223,7 @@ unsigned int OBJReader::loadMaterialsFromFile(const std::string &filename, material.ambientOcclusionTextureId = MATERIAL_NONE; materials[id].isSketchupLightMaterial = false; material.opacity = 0.f; - material.noise = 0.f; + material.gloss = 0.f; materials[id] = material; materials[id].Ks.x = 1.f; materials[id].Ks.y = 500.f; @@ -229,7 +236,10 @@ unsigned int OBJReader::loadMaterialsFromFile(const std::string &filename, materials[id].Kd = readVertex(line); if (materials[id].isSketchupLightMaterial) { - materials[id].illumination = (materials[id].Kd.x + materials[id].Kd.y + materials[id].Kd.z) / 3.f; + materials[id].illumination = + (materials[id].Kd.x + materials[id].Kd.y + + materials[id].Kd.z) / + 3.f; } } @@ -268,30 +278,42 @@ unsigned int OBJReader::loadMaterialsFromFile(const std::string &filename, if (diffuseMap) { materials[id].diffuseTextureId = idx; - LOG_INFO(3, "[Slot " << idx << "] Diffuse texture " << folder - << " successfully loaded and assigned to material " << id << "(" - << materials[id].index << ")"); + LOG_INFO(3, "[Slot " << idx << "] Diffuse texture " + << folder + << " successfully loaded and " + "assigned to material " + << id << "(" << materials[id].index + << ")"); } if (bumpMap) { materials[id].bumpTextureId = idx; - LOG_INFO(3, "[Slot " << idx << "] Bump texture " << folder - << " successfully loaded and assigned to material " << id << "(" - << materials[id].index << ")"); + LOG_INFO(3, "[Slot " << idx << "] Bump texture " + << folder + << " successfully loaded and " + "assigned to material " + << id << "(" << materials[id].index + << ")"); } if (normalMap) { materials[id].normalTextureId = idx; - LOG_INFO(3, "[Slot " << idx << "] Mormal texture " << folder - << " successfully loaded and assigned to material " << id << "(" - << materials[id].index << ")"); + LOG_INFO(3, "[Slot " << idx << "] Mormal texture " + << folder + << " successfully loaded and " + "assigned to material " + << id << "(" << materials[id].index + << ")"); } if (specularlMap) { materials[id].specularTextureId = idx; - LOG_INFO(3, "[Slot " << idx << "] Specular texture " << folder - << " successfully loaded and assigned to material " << id << "(" - << materials[id].index << ")"); + LOG_INFO(3, "[Slot " << idx << "] Specular texture " + << folder + << " successfully loaded and " + "assigned to material " + << id << "(" << materials[id].index + << ")"); } } else @@ -306,7 +328,7 @@ unsigned int OBJReader::loadMaterialsFromFile(const std::string &filename, materials[id].reflection = 1.f; materials[id].transparency = 0.5f + (d / 50.f); materials[id].refraction = 1.1f; - materials[id].noise = 0.f; + materials[id].gloss = 0.f; } if (line.find("SoL_R_Light") != -1) @@ -347,17 +369,25 @@ unsigned int OBJReader::loadMaterialsFromFile(const std::string &filename, // fabs(m.Kd.y-m.Kd.z)<0.01f) m.reflection=0.5f; // Add material to kernel - kernel.setMaterial(m.index, m.Kd.x, m.Kd.y, m.Kd.z, m.noise, m.reflection, m.refraction, false, false, 0, - m.transparency, m.opacity, m.diffuseTextureId, m.normalTextureId, m.bumpTextureId, - m.specularTextureId, m.reflectionTextureId, m.transparencyTextureId, - m.ambientOcclusionTextureId, m.Ks.x, 100.f * m.Ks.y, m.Ks.z, m.illumination, - innerDiffusion, innerDiffusion * diffusionRatio, false); + kernel.setMaterial(m.index, m.Kd.x, m.Kd.y, m.Kd.z, m.gloss, + m.reflection, m.refraction, false, false, 0, + m.transparency, m.opacity, m.diffuseTextureId, + m.normalTextureId, m.bumpTextureId, + m.specularTextureId, m.reflectionTextureId, + m.transparencyTextureId, + m.ambientOcclusionTextureId, m.Ks.x, + 100.f * m.Ks.y, m.Ks.z, m.illumination, + innerDiffusion, innerDiffusion * diffusionRatio, + false); LOG_INFO(3, "[" << m.index << "] Added material [" << id << "] " - << "( " << m.Kd.x << ", " << m.Kd.y << ", " << m.Kd.z << ") " - << "( " << m.Ks.x << ", " << m.Ks.y << ", " << m.Ks.z << ") " + << "( " << m.Kd.x << ", " << m.Kd.y << ", " + << m.Kd.z << ") " + << "( " << m.Ks.x << ", " << m.Ks.y << ", " + << m.Ks.z << ") " << "( " << m.illumination << ") " - << ", Textures [" << m.diffuseTextureId << "," << m.bumpTextureId - << "]=" << kernel.getTextureFilename(m.diffuseTextureId)); + << ", Textures [" << m.diffuseTextureId << "," + << m.bumpTextureId << "]=" + << kernel.getTextureFilename(m.diffuseTextureId)); } file.close(); @@ -365,8 +395,11 @@ unsigned int OBJReader::loadMaterialsFromFile(const std::string &filename, return 0; } -void OBJReader::addLightComponent(GPUKernel &kernel, std::vector &solrVertices, const vec4f ¢er, - const vec4f &objectCenter, const vec4f &objectScale, const int material, +void OBJReader::addLightComponent(GPUKernel &kernel, + std::vector &solrVertices, + const vec4f ¢er, + const vec4f &objectCenter, + const vec4f &objectScale, const int material, CPUBoundingBox &aabb) { size_t len = solrVertices.size(); @@ -381,35 +414,48 @@ void OBJReader::addLightComponent(GPUKernel &kernel, std::vector &solrVer aabb.parameters[1].z = -1000000.f; for (size_t i(0); i < len; ++i) { - aabb.parameters[0].x = std::min(solrVertices[i].x, aabb.parameters[0].x); - aabb.parameters[1].x = std::max(solrVertices[i].x, aabb.parameters[1].x); - aabb.parameters[0].y = std::min(solrVertices[i].y, aabb.parameters[0].y); - aabb.parameters[1].y = std::max(solrVertices[i].y, aabb.parameters[1].y); - aabb.parameters[0].z = std::min(solrVertices[i].z, aabb.parameters[0].z); - aabb.parameters[1].z = std::max(solrVertices[i].z, aabb.parameters[1].z); + aabb.parameters[0].x = + std::min(solrVertices[i].x, aabb.parameters[0].x); + aabb.parameters[1].x = + std::max(solrVertices[i].x, aabb.parameters[1].x); + aabb.parameters[0].y = + std::min(solrVertices[i].y, aabb.parameters[0].y); + aabb.parameters[1].y = + std::max(solrVertices[i].y, aabb.parameters[1].y); + aabb.parameters[0].z = + std::min(solrVertices[i].z, aabb.parameters[0].z); + aabb.parameters[1].z = + std::max(solrVertices[i].z, aabb.parameters[1].z); } lightCenter.x = (aabb.parameters[1].x + aabb.parameters[0].x) / 2.f; lightCenter.y = (aabb.parameters[1].y + aabb.parameters[0].y) / 2.f; lightCenter.z = (aabb.parameters[1].z + aabb.parameters[0].z) / 2.f; - const vec4f L = make_vec4f(aabb.parameters[1].x - aabb.parameters[0].x, aabb.parameters[1].y - aabb.parameters[0].y, - aabb.parameters[1].z - aabb.parameters[0].z); + const vec4f L = make_vec4f(aabb.parameters[1].x - aabb.parameters[0].x, + aabb.parameters[1].y - aabb.parameters[0].y, + aabb.parameters[1].z - aabb.parameters[0].z); const float radius = sqrt(L.x * L.x + L.y * L.y + L.z * L.z) / 2.f; const int nbPrimitives = kernel.addPrimitive(ptSphere); - LOG_INFO(3, "Adding SoL-R light [" << material << "] to primitive " << nbPrimitives << " (" << lightCenter.x - << "," << lightCenter.y << "," << lightCenter.z << ") r=" << radius); - kernel.setPrimitive(nbPrimitives, center.x + objectScale.x * (-objectCenter.x + lightCenter.x), - center.y + objectScale.y * (-objectCenter.y + lightCenter.y), - center.z + objectScale.z * (-objectCenter.z + lightCenter.z), radius, 0.f, 0.f, material); + LOG_INFO(3, "Adding SoL-R light [" + << material << "] to primitive " << nbPrimitives << " (" + << lightCenter.x << "," << lightCenter.y << "," + << lightCenter.z << ") r=" << radius); + kernel.setPrimitive( + nbPrimitives, + center.x + objectScale.x * (-objectCenter.x + lightCenter.x), + center.y + objectScale.y * (-objectCenter.y + lightCenter.y), + center.z + objectScale.z * (-objectCenter.z + lightCenter.z), + radius, 0.f, 0.f, material); kernel.setPrimitiveBellongsToModel(nbPrimitives, true); } solrVertices.clear(); } -vec4f OBJReader::loadModelFromFile(const std::string &filename, GPUKernel &kernel, const vec4f &objectPosition, - const bool autoScale, const vec4f &scale, bool loadMaterials, int materialId, - bool allSpheres, bool autoCenter, CPUBoundingBox &aabb, const bool &checkInAABB, - const CPUBoundingBox &inAABB) +vec4f OBJReader::loadModelFromFile( + const std::string &filename, GPUKernel &kernel, const vec4f &objectPosition, + const bool autoScale, const vec4f &scale, bool loadMaterials, + int materialId, bool allSpheres, bool autoCenter, CPUBoundingBox &aabb, + const bool &checkInAABB, const CPUBoundingBox &inAABB) { LOG_INFO(1, "OBJ Filename.......: " << filename); std::map vertices; @@ -454,9 +500,11 @@ vec4f OBJReader::loadModelFromFile(const std::string &filename, GPUKernel &kerne { // Load materials std::string materialFileName = line.substr(7); - std::string folder = noExtFilename.substr(0, noExtFilename.rfind('/')); + std::string folder = + noExtFilename.substr(0, noExtFilename.rfind('/')); materialFileName = folder + '/' + materialFileName; - loadMaterialsFromFile(materialFileName, materials, kernel, materialId); + loadMaterialsFromFile(materialFileName, materials, kernel, + materialId); } if (line[0] == 'v') { @@ -474,13 +522,16 @@ vec4f OBJReader::loadModelFromFile(const std::string &filename, GPUKernel &kerne switch (item) { case 1: - vertex.x = static_cast(atof(value.c_str())); + vertex.x = + static_cast(atof(value.c_str())); break; case 2: - vertex.y = static_cast(atof(value.c_str())); + vertex.y = + static_cast(atof(value.c_str())); break; case 3: - vertex.z = static_cast(atof(value.c_str())); + vertex.z = + static_cast(atof(value.c_str())); break; } ++item; @@ -538,7 +589,8 @@ vec4f OBJReader::loadModelFromFile(const std::string &filename, GPUKernel &kerne texCoords.y = Yb; } - textureCoordinates[index_textureCoordinates] = texCoords; + textureCoordinates[index_textureCoordinates] = + texCoords; ++index_textureCoordinates; } else @@ -551,14 +603,32 @@ vec4f OBJReader::loadModelFromFile(const std::string &filename, GPUKernel &kerne ++index_vertices; // min - aabb.parameters[0].x = (vertex.x < aabb.parameters[0].x) ? vertex.x : aabb.parameters[0].x; - aabb.parameters[0].y = (vertex.y < aabb.parameters[0].y) ? vertex.y : aabb.parameters[0].y; - aabb.parameters[0].z = (vertex.z < aabb.parameters[0].z) ? vertex.z : aabb.parameters[0].z; + aabb.parameters[0].x = + (vertex.x < aabb.parameters[0].x) + ? vertex.x + : aabb.parameters[0].x; + aabb.parameters[0].y = + (vertex.y < aabb.parameters[0].y) + ? vertex.y + : aabb.parameters[0].y; + aabb.parameters[0].z = + (vertex.z < aabb.parameters[0].z) + ? vertex.z + : aabb.parameters[0].z; // max - aabb.parameters[1].x = (vertex.x > aabb.parameters[1].x) ? vertex.x : aabb.parameters[1].x; - aabb.parameters[1].y = (vertex.y > aabb.parameters[1].y) ? vertex.y : aabb.parameters[1].y; - aabb.parameters[1].z = (vertex.z > aabb.parameters[1].z) ? vertex.z : aabb.parameters[1].z; + aabb.parameters[1].x = + (vertex.x > aabb.parameters[1].x) + ? vertex.x + : aabb.parameters[1].x; + aabb.parameters[1].y = + (vertex.y > aabb.parameters[1].y) + ? vertex.y + : aabb.parameters[1].y; + aabb.parameters[1].z = + (vertex.z > aabb.parameters[1].z) + ? vertex.z + : aabb.parameters[1].z; } } } @@ -589,9 +659,10 @@ vec4f OBJReader::loadModelFromFile(const std::string &filename, GPUKernel &kerne vec4f objectScale = scale; if (autoScale) { - float os = std::max(aabb.parameters[1].x - aabb.parameters[0].x, - std::max(aabb.parameters[1].y - aabb.parameters[0].y, - aabb.parameters[1].z - aabb.parameters[0].z)); + float os = + std::max(aabb.parameters[1].x - aabb.parameters[0].x, + std::max(aabb.parameters[1].y - aabb.parameters[0].y, + aabb.parameters[1].z - aabb.parameters[0].z)); objectScale.x = scale.x / os; objectScale.y = scale.y / os; objectScale.z = scale.z / os; @@ -599,9 +670,12 @@ vec4f OBJReader::loadModelFromFile(const std::string &filename, GPUKernel &kerne if (autoCenter) { // Center align object - objectCenter.x = (aabb.parameters[0].x + aabb.parameters[1].x) / 2.f; - objectCenter.y = (aabb.parameters[0].y + aabb.parameters[1].y) / 2.f; - objectCenter.z = (aabb.parameters[0].z + aabb.parameters[1].z) / 2.f; + objectCenter.x = + (aabb.parameters[0].x + aabb.parameters[1].x) / 2.f; + objectCenter.y = + (aabb.parameters[0].y + aabb.parameters[1].y) / 2.f; + objectCenter.z = + (aabb.parameters[0].z + aabb.parameters[1].z) / 2.f; } } @@ -631,8 +705,10 @@ vec4f OBJReader::loadModelFromFile(const std::string &filename, GPUKernel &kerne { if (line != component) { - addLightComponent(kernel, solrVertices, objectPosition, objectCenter, objectScale, - sketchupMaterial, aabb); + addLightComponent(kernel, solrVertices, + objectPosition, objectCenter, + objectScale, sketchupMaterial, + aabb); } component = line; } @@ -666,7 +742,8 @@ vec4f OBJReader::loadModelFromFile(const std::string &filename, GPUKernel &kerne { if (line[i] != ' ') value += line[i]; - if (i == (line.length() - 1) || (line[i] == ' ' && previousChar != ' ')) + if (i == (line.length() - 1) || + (line[i] == ' ' && previousChar != ' ')) if (value.length() != 0) { vec4i v = readFace(value); @@ -683,62 +760,106 @@ vec4f OBJReader::loadModelFromFile(const std::string &filename, GPUKernel &kerne { vec4f sphereCenter; sphereCenter.x = - (vertices[face[f].x].x + vertices[face[f + 1].x].x + vertices[face[f + 2].x].x) / 3.f; + (vertices[face[f].x].x + vertices[face[f + 1].x].x + + vertices[face[f + 2].x].x) / + 3.f; sphereCenter.y = - (vertices[face[f].x].y + vertices[face[f + 1].x].y + vertices[face[f + 2].x].y) / 3.f; + (vertices[face[f].x].y + vertices[face[f + 1].x].y + + vertices[face[f + 2].x].y) / + 3.f; sphereCenter.z = - (vertices[face[f].x].z + vertices[face[f + 1].x].z + vertices[face[f + 2].x].z) / 3.f; + (vertices[face[f].x].z + vertices[face[f + 1].x].z + + vertices[face[f + 2].x].z) / + 3.f; vec4f sphereRadius[3]; for (int i = 0; i < 3; ++i) { - sphereRadius[i].x = (sphereCenter.x - vertices[face[f + i].x].x); - sphereRadius[i].y = (sphereCenter.y - vertices[face[f + i].x].y); - sphereRadius[i].z = (sphereCenter.z - vertices[face[f + i].x].z); + sphereRadius[i].x = + (sphereCenter.x - vertices[face[f + i].x].x); + sphereRadius[i].y = + (sphereCenter.y - vertices[face[f + i].x].y); + sphereRadius[i].z = + (sphereCenter.z - vertices[face[f + i].x].z); } vec4f s; - s.x = std::max(sphereRadius[0].x, std::max(sphereRadius[1].x, sphereRadius[2].x)); - s.y = std::max(sphereRadius[0].y, std::max(sphereRadius[1].y, sphereRadius[2].y)); - s.z = std::max(sphereRadius[0].z, std::max(sphereRadius[1].z, sphereRadius[2].z)); + s.x = std::max(sphereRadius[0].x, + std::max(sphereRadius[1].x, + sphereRadius[2].x)); + s.y = std::max(sphereRadius[0].y, + std::max(sphereRadius[1].y, + sphereRadius[2].y)); + s.z = std::max(sphereRadius[0].z, + std::max(sphereRadius[1].z, + sphereRadius[2].z)); if (isSketchupLightMaterial) solrVertices.push_back(sphereCenter); else { nbPrimitives = kernel.addPrimitive(ptEllipsoid); - kernel.setPrimitive(nbPrimitives, - objectPosition.x + objectScale.x * (-objectCenter.x + sphereCenter.x), - objectPosition.y + objectScale.y * (-objectCenter.y + sphereCenter.y), - objectPosition.z + objectScale.z * (-objectCenter.z + sphereCenter.z), - objectScale.x * s.x, objectScale.y * s.y, objectScale.z * s.z, - material); - kernel.setPrimitiveBellongsToModel(nbPrimitives, true); + kernel.setPrimitive( + nbPrimitives, + objectPosition.x + + objectScale.x * + (-objectCenter.x + sphereCenter.x), + objectPosition.y + + objectScale.y * + (-objectCenter.y + sphereCenter.y), + objectPosition.z + + objectScale.z * + (-objectCenter.z + sphereCenter.z), + objectScale.x * s.x, objectScale.y * s.y, + objectScale.z * s.z, material); + kernel.setPrimitiveBellongsToModel(nbPrimitives, + true); } } else { nbPrimitives = kernel.addPrimitive(ptTriangle); kernel.setPrimitive( - nbPrimitives, objectPosition.x + objectScale.x * (-objectCenter.x + vertices[face[f].x].x), - objectPosition.y + objectScale.y * (-objectCenter.y + vertices[face[f].x].y), - objectPosition.z + objectScale.z * (-objectCenter.z + vertices[face[f].x].z), - objectPosition.x + objectScale.x * (-objectCenter.x + vertices[face[f + 1].x].x), - objectPosition.y + objectScale.y * (-objectCenter.y + vertices[face[f + 1].x].y), - objectPosition.z + objectScale.z * (-objectCenter.z + vertices[face[f + 1].x].z), - objectPosition.x + objectScale.x * (-objectCenter.x + vertices[face[f + 2].x].x), - objectPosition.y + objectScale.y * (-objectCenter.y + vertices[face[f + 2].x].y), - objectPosition.z + objectScale.z * (-objectCenter.z + vertices[face[f + 2].x].z), 0.f, 0.f, - 0.f, material); + nbPrimitives, + objectPosition.x + + objectScale.x * + (-objectCenter.x + vertices[face[f].x].x), + objectPosition.y + + objectScale.y * + (-objectCenter.y + vertices[face[f].x].y), + objectPosition.z + + objectScale.z * + (-objectCenter.z + vertices[face[f].x].z), + objectPosition.x + + objectScale.x * (-objectCenter.x + + vertices[face[f + 1].x].x), + objectPosition.y + + objectScale.y * (-objectCenter.y + + vertices[face[f + 1].x].y), + objectPosition.z + + objectScale.z * (-objectCenter.z + + vertices[face[f + 1].x].z), + objectPosition.x + + objectScale.x * (-objectCenter.x + + vertices[face[f + 2].x].x), + objectPosition.y + + objectScale.y * (-objectCenter.y + + vertices[face[f + 2].x].y), + objectPosition.z + + objectScale.z * (-objectCenter.z + + vertices[face[f + 2].x].z), + 0.f, 0.f, 0.f, material); kernel.setPrimitiveBellongsToModel(nbPrimitives, true); } // Texture coordinates - kernel.setPrimitiveTextureCoordinates(nbPrimitives, textureCoordinates[face[f].y], - textureCoordinates[face[f + 1].y], - textureCoordinates[face[f + 2].y]); + kernel.setPrimitiveTextureCoordinates( + nbPrimitives, textureCoordinates[face[f].y], + textureCoordinates[face[f + 1].y], + textureCoordinates[face[f + 2].y]); // Normals - kernel.setPrimitiveNormals(nbPrimitives, normals[face[f].z], normals[face[f + 1].z], + kernel.setPrimitiveNormals(nbPrimitives, normals[face[f].z], + normals[face[f + 1].z], normals[face[f + 2].z]); if (face.size() == 4) @@ -747,51 +868,90 @@ vec4f OBJReader::loadModelFromFile(const std::string &filename, GPUKernel &kerne if (allSpheres) { vec4f sphereCenter; - sphereCenter.x = - (vertices[face[f + 3].x].x + vertices[face[f + 2].x].x + vertices[face[f].x].x) / 3.f; - sphereCenter.y = - (vertices[face[f + 3].x].y + vertices[face[f + 2].x].y + vertices[face[f].x].y) / 3.f; - sphereCenter.z = - (vertices[face[f + 3].x].z + vertices[face[f + 2].x].z + vertices[face[f].x].z) / 3.f; + sphereCenter.x = (vertices[face[f + 3].x].x + + vertices[face[f + 2].x].x + + vertices[face[f].x].x) / + 3.f; + sphereCenter.y = (vertices[face[f + 3].x].y + + vertices[face[f + 2].x].y + + vertices[face[f].x].y) / + 3.f; + sphereCenter.z = (vertices[face[f + 3].x].z + + vertices[face[f + 2].x].z + + vertices[face[f].x].z) / + 3.f; vec4f sphereRadius; - sphereRadius.x = sphereCenter.x - vertices[face[f].x].x; - sphereRadius.y = sphereCenter.y - vertices[face[f].x].y; - sphereRadius.z = sphereCenter.z - vertices[face[f].x].z; + sphereRadius.x = + sphereCenter.x - vertices[face[f].x].x; + sphereRadius.y = + sphereCenter.y - vertices[face[f].x].y; + sphereRadius.z = + sphereCenter.z - vertices[face[f].x].z; float radius = 100.f; // objectScale*sqrt(sphereRadius.x*sphereRadius.x+sphereRadius.y*sphereRadius.y+sphereRadius.z*sphereRadius.z); nbPrimitives = kernel.addPrimitive(ptSphere); - kernel.setPrimitive(nbPrimitives, - objectPosition.x + objectScale.x * (-objectCenter.x + sphereCenter.x), - objectPosition.y + objectScale.y * (-objectCenter.y + sphereCenter.y), - objectPosition.z + objectScale.z * (-objectCenter.z + sphereCenter.z), - radius, 0.f, 0.f, material); - kernel.setPrimitiveBellongsToModel(nbPrimitives, true); + kernel.setPrimitive( + nbPrimitives, + objectPosition.x + + objectScale.x * + (-objectCenter.x + sphereCenter.x), + objectPosition.y + + objectScale.y * + (-objectCenter.y + sphereCenter.y), + objectPosition.z + + objectScale.z * + (-objectCenter.z + sphereCenter.z), + radius, 0.f, 0.f, material); + kernel.setPrimitiveBellongsToModel(nbPrimitives, + true); } else { nbPrimitives = kernel.addPrimitive(ptTriangle); kernel.setPrimitive( nbPrimitives, - objectPosition.x + objectScale.x * (-objectCenter.x + vertices[face[f + 3].x].x), - objectPosition.y + objectScale.y * (-objectCenter.y + vertices[face[f + 3].x].y), - objectPosition.z + objectScale.z * (-objectCenter.z + vertices[face[f + 3].x].z), - objectPosition.x + objectScale.x * (-objectCenter.x + vertices[face[f + 2].x].x), - objectPosition.y + objectScale.y * (-objectCenter.y + vertices[face[f + 2].x].y), - objectPosition.z + objectScale.z * (-objectCenter.z + vertices[face[f + 2].x].z), - objectPosition.x + objectScale.x * (-objectCenter.x + vertices[face[f].x].x), - objectPosition.y + objectScale.y * (-objectCenter.y + vertices[face[f].x].y), - objectPosition.z + objectScale.z * (-objectCenter.z + vertices[face[f].x].z), 0.f, 0.f, - 0.f, material); - kernel.setPrimitiveBellongsToModel(nbPrimitives, true); + objectPosition.x + + objectScale.x * (-objectCenter.x + + vertices[face[f + 3].x].x), + objectPosition.y + + objectScale.y * (-objectCenter.y + + vertices[face[f + 3].x].y), + objectPosition.z + + objectScale.z * (-objectCenter.z + + vertices[face[f + 3].x].z), + objectPosition.x + + objectScale.x * (-objectCenter.x + + vertices[face[f + 2].x].x), + objectPosition.y + + objectScale.y * (-objectCenter.y + + vertices[face[f + 2].x].y), + objectPosition.z + + objectScale.z * (-objectCenter.z + + vertices[face[f + 2].x].z), + objectPosition.x + + objectScale.x * (-objectCenter.x + + vertices[face[f].x].x), + objectPosition.y + + objectScale.y * (-objectCenter.y + + vertices[face[f].x].y), + objectPosition.z + + objectScale.z * (-objectCenter.z + + vertices[face[f].x].z), + 0.f, 0.f, 0.f, material); + kernel.setPrimitiveBellongsToModel(nbPrimitives, + true); } // Texture coordinates - kernel.setPrimitiveTextureCoordinates(nbPrimitives, textureCoordinates[face[f + 3].y], - textureCoordinates[face[f + 2].y], - textureCoordinates[face[f].y]); - kernel.setPrimitiveNormals(nbPrimitives, normals[face[f + 3].z], normals[face[f + 2].z], + kernel.setPrimitiveTextureCoordinates( + nbPrimitives, textureCoordinates[face[f + 3].y], + textureCoordinates[face[f + 2].y], + textureCoordinates[face[f].y]); + kernel.setPrimitiveNormals(nbPrimitives, + normals[face[f + 3].z], + normals[face[f + 2].z], normals[face[f].z]); } } @@ -801,28 +961,43 @@ vec4f OBJReader::loadModelFromFile(const std::string &filename, GPUKernel &kerne // Remaining SoL-R lights if (solrVertices.size() != 0) - addLightComponent(kernel, solrVertices, objectPosition, objectCenter, objectScale, sketchupMaterial, aabb); + addLightComponent(kernel, solrVertices, objectPosition, + objectCenter, objectScale, sketchupMaterial, + aabb); } - objectSize.x = objectScale.x * (aabb.parameters[1].x - aabb.parameters[0].x); - objectSize.y = objectScale.y * (aabb.parameters[1].y - aabb.parameters[0].y); - objectSize.z = objectScale.z * (aabb.parameters[1].z - aabb.parameters[0].z); + objectSize.x = + objectScale.x * (aabb.parameters[1].x - aabb.parameters[0].x); + objectSize.y = + objectScale.y * (aabb.parameters[1].y - aabb.parameters[0].y); + objectSize.z = + objectScale.z * (aabb.parameters[1].z - aabb.parameters[0].z); LOG_INFO(1, " - Vertices........: " << kernel.getNbActivePrimitives()); LOG_INFO(1, " - Faces...........: " << kernel.getNbActivePrimitives() / 3); - LOG_INFO(3, " - Min.............: " << aabb.parameters[0].x << "," << aabb.parameters[0].y << "," + LOG_INFO(3, " - Min.............: " << aabb.parameters[0].x << "," + << aabb.parameters[0].y << "," << aabb.parameters[0].z); - LOG_INFO(3, " - Max.............: " << aabb.parameters[1].x << "," << aabb.parameters[1].y << "," + LOG_INFO(3, " - Max.............: " << aabb.parameters[1].x << "," + << aabb.parameters[1].y << "," << aabb.parameters[1].z); - LOG_INFO(3, " - Center..........: " << objectCenter.x << "," << objectCenter.y << "," << objectCenter.z); - LOG_INFO(3, " - Scale...........: " << objectScale.x << "," << objectScale.y << "," << objectScale.z); - LOG_INFO(1, " - Object size.....: " << objectSize.x << "," << objectSize.y << "," << objectSize.z); - LOG_INFO(3, " - AABB............: (" << aabb.parameters[0].x << "," << aabb.parameters[0].y << "," - << aabb.parameters[0].z << "),(" << aabb.parameters[1].x << "," - << aabb.parameters[1].y << "," << aabb.parameters[1].z << ")"); - LOG_INFO(3, " - inAABB..........: (" << inAABB.parameters[0].x << "," << inAABB.parameters[0].y << "," - << inAABB.parameters[0].z << "),(" << inAABB.parameters[1].x << "," - << inAABB.parameters[1].y << "," << inAABB.parameters[1].z << ")"); + LOG_INFO(3, " - Center..........: " << objectCenter.x << "," + << objectCenter.y << "," + << objectCenter.z); + LOG_INFO(3, " - Scale...........: " << objectScale.x << "," << objectScale.y + << "," << objectScale.z); + LOG_INFO(1, " - Object size.....: " << objectSize.x << "," << objectSize.y + << "," << objectSize.z); + LOG_INFO(3, " - AABB............: (" + << aabb.parameters[0].x << "," << aabb.parameters[0].y + << "," << aabb.parameters[0].z << "),(" + << aabb.parameters[1].x << "," << aabb.parameters[1].y + << "," << aabb.parameters[1].z << ")"); + LOG_INFO(3, " - inAABB..........: (" + << inAABB.parameters[0].x << "," << inAABB.parameters[0].y + << "," << inAABB.parameters[0].z << "),(" + << inAABB.parameters[1].x << "," << inAABB.parameters[1].y + << "," << inAABB.parameters[1].z << ")"); return objectSize; } -} +} // namespace solr diff --git a/solr/io/OBJReader.h b/solr/io/OBJReader.h index 55b2494..1b9ed6c 100644 --- a/solr/io/OBJReader.h +++ b/solr/io/OBJReader.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once @@ -37,7 +34,7 @@ struct MaterialMTL float transparency; float opacity; float refraction; - float noise; + float gloss; int diffuseTextureId; int normalTextureId; int bumpTextureId; @@ -55,17 +52,22 @@ class SOLR_API OBJReader OBJReader(); ~OBJReader(); - unsigned int loadMaterialsFromFile(const std::string &filename, std::map &m_materials, - GPUKernel &GPUKernel, int materialId); + unsigned int loadMaterialsFromFile( + const std::string &filename, + std::map &m_materials, GPUKernel &GPUKernel, + int materialId); - vec4f loadModelFromFile(const std::string &filename, GPUKernel &cudaKernel, const vec4f ¢er, - const bool autoScale, const vec4f &scale, bool loadMaterials, int materialId, - bool allSpheres, bool autoCenter, CPUBoundingBox &aabb, const bool &checkInAABB, - const CPUBoundingBox &inAABB); + vec4f loadModelFromFile(const std::string &filename, GPUKernel &cudaKernel, + const vec4f ¢er, const bool autoScale, + const vec4f &scale, bool loadMaterials, + int materialId, bool allSpheres, bool autoCenter, + CPUBoundingBox &aabb, const bool &checkInAABB, + const CPUBoundingBox &inAABB); private: - void addLightComponent(GPUKernel &kernel, std::vector &solrVertices, const vec4f ¢er, - const vec4f &objectCenter, const vec4f &objectScale, const int material, + void addLightComponent(GPUKernel &kernel, std::vector &solrVertices, + const vec4f ¢er, const vec4f &objectCenter, + const vec4f &objectScale, const int material, CPUBoundingBox &aabb); }; -} +} // namespace solr diff --git a/solr/io/PDBReader.cpp b/solr/io/PDBReader.cpp index 6c8a53f..9be0879 100644 --- a/solr/io/PDBReader.cpp +++ b/solr/io/PDBReader.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau - * - * This file is part of Sol-R +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include @@ -27,8 +24,8 @@ #include #include -#include "../Consts.h" #include "../Logging.h" +#include "../consts.h" #include "PDBReader.h" //#define CONNECTIONS @@ -55,129 +52,224 @@ struct Element // https://github.com/openbabel/openbabel/blob/master/data/element.txt const int NB_ELEMENTS = 119; -Element elements[NB_ELEMENTS] = - { // Symb ARENeg RCov RBO RVdW MaxBnd - // Mass ElNeg. Ionization ElAffinity Red - // Green Blue Name - {"Xx", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.07, 0.5, 0.7, "Dummy"}, - {"H", 2.2, 0.31, 0.31, 1.1, 1, 1.00794, 2.2, 13.5984, 0.75420375, 0.75, 0.75, 0.75, "Hydrogen"}, - {"He", 0, 0.28, 0.28, 1.4, 0, 4.002602, 0, 24.5874, 0, 0.85, 1, 1, "Helium"}, - {"Li", 0.97, 1.28, 1.28, 1.81, 1, 6.941, 0.98, 5.3917, 0.618049, 0.8, 0.5, 1, "Lithium"}, - {"Be", 1.47, 0.96, 0.96, 1.53, 2, 9.012182, 1.57, 9.3227, 0, 0.76, 1, 0, "Beryllium"}, - {"B", 2.01, 0.84, 0.84, 1.92, 4, 10.811, 2.04, 8.298, 0.279723, 1, 0.71, 0.71, "Boron"}, - {"C", 2.5, 0.76, 0.76, 1.7, 4, 12.0107, 2.55, 11.2603, 1.262118, 0.4, 0.4, 0.4, "Carbon"}, - {"N", 3.07, 0.71, 0.71, 1.55, 4, 14.0067, 3.04, 14.5341, -0.07, 0.05, 0.05, 1, "Nitrogen"}, - {"O", 3.5, 0.66, 0.66, 1.52, 2, 15.9994, 3.44, 13.6181, 1.461112, 1, 0.05, 0.05, "Oxygen"}, - {"F", 4.1, 0.57, 0.57, 1.47, 1, 18.9984032, 3.98, 17.4228, 3.4011887, 0.5, 0.7, 1, "Fluorine"}, - {"Ne", 0, 0.58, 0.58, 1.54, 0, 20.1797, 0, 21.5645, 0, 0.7, 0.89, 0.96, "Neon"}, - {"Na", 1.01, 1.66, 1.66, 2.27, 1, 22.98977, 0.93, 5.1391, 0.547926, 0.67, 0.36, 0.95, "Sodium"}, - {"Mg", 1.23, 1.41, 1.41, 1.73, 2, 24.305, 1.31, 7.6462, 0, 0.54, 1, 0, "Magnesium"}, - {"Al", 1.47, 1.21, 1.21, 1.84, 6, 26.981538, 1.61, 5.9858, 0.43283, 0.75, 0.65, 0.65, "Aluminium"}, - {"Si", 1.74, 1.11, 1.11, 2.1, 6, 28.0855, 1.9, 8.1517, 1.389521, 0.5, 0.6, 0.6, "Silicon"}, - {"P", 2.06, 1.07, 1.07, 1.8, 6, 30.973761, 2.19, 10.4867, 0.7465, 1, 0.5, 0, "Phosphorus"}, - {"S", 2.44, 1.05, 1.05, 1.8, 6, 32.065, 2.58, 10.36, 2.0771029, 0.7, 0.7, 0, "Sulfur"}, - {"Cl", 2.83, 1.02, 1.02, 1.75, 1, 35.453, 3.16, 12.9676, 3.612724, 0.12, 0.94, 0.12, "Chlorine"}, - {"Ar", 0, 1.06, 1.06, 1.88, 0, 39.948, 0, 15.7596, 0, 0.5, 0.82, 0.89, "Argon"}, - {"K", 0.91, 2.03, 2.03, 2.75, 1, 39.0983, 0.82, 4.3407, 0.501459, 0.56, 0.25, 0.83, "Potassium"}, - {"Ca", 1.04, 1.76, 1.76, 2.31, 2, 40.078, 1, 6.1132, 0.02455, 0.24, 1, 0, "Calcium"}, - {"Sc", 1.2, 1.7, 1.7, 2.3, 6, 44.95591, 1.36, 6.5615, 0.188, 0.9, 0.9, 0.9, "Scandium"}, - {"Ti", 1.32, 1.6, 1.6, 2.15, 6, 47.867, 1.54, 6.8281, 0.084, 0.75, 0.76, 0.78, "Titanium"}, - {"V", 1.45, 1.53, 1.53, 2.05, 6, 50.9415, 1.63, 6.7462, 0.525, 0.65, 0.65, 0.67, "Vanadium"}, - {"Cr", 1.56, 1.39, 1.39, 2.05, 6, 51.9961, 1.66, 6.7665, 0.67584, 0.54, 0.6, 0.78, "Chromium"}, - {"Mn", 1.6, 1.39, 1.39, 2.05, 8, 54.938049, 1.55, 7.434, 0, 0.61, 0.48, 0.78, "Manganese"}, - {"Fe", 1.64, 1.32, 1.32, 2.05, 6, 55.845, 1.83, 7.9024, 0.151, 0.88, 0.4, 0.2, "Iron"}, - {"Co", 1.7, 1.26, 1.26, 2, 6, 58.9332, 1.88, 7.881, 0.6633, 0.94, 0.56, 0.63, "Cobalt"}, - {"Ni", 1.75, 1.24, 1.24, 2, 6, 58.6934, 1.91, 7.6398, 1.15716, 0.31, 0.82, 0.31, "Nickel"}, - {"Cu", 1.75, 1.32, 1.32, 2, 6, 63.546, 1.9, 7.7264, 1.23578, 0.78, 0.5, 0.2, "Copper"}, - {"Zn", 1.66, 1.22, 1.22, 2.1, 6, 65.38, 1.65, 9.3942, 0, 0.49, 0.5, 0.69, "Zinc"}, - {"Ga", 1.82, 1.22, 1.22, 1.87, 3, 69.723, 1.81, 5.9993, 0.41, 0.76, 0.56, 0.56, "Gallium"}, - {"Ge", 2.02, 1.2, 1.2, 2.11, 4, 72.64, 2.01, 7.8994, 1.232712, 0.4, 0.56, 0.56, "Germanium"}, - {"As", 2.2, 1.19, 1.19, 1.85, 3, 74.9216, 2.18, 9.7886, 0.814, 0.74, 0.5, 0.89, "Arsenic"}, - {"Se", 2.48, 1.2, 1.2, 1.9, 2, 78.96, 2.55, 9.7524, 2.02067, 1, 0.63, 0, "Selenium"}, - {"Br", 2.74, 1.2, 1.2, 1.83, 1, 79.904, 2.96, 11.8138, 3.363588, 0.65, 0.16, 0.16, "Bromine"}, - {"Kr", 0, 1.16, 1.16, 2.02, 0, 83.798, 3, 13.9996, 0, 0.36, 0.72, 0.82, "Krypton"}, - {"Rb", 0.89, 2.2, 2.2, 3.03, 1, 85.4678, 0.82, 4.1771, 0.485916, 0.44, 0.18, 0.69, "Rubidium"}, - {"Sr", 0.99, 1.95, 1.95, 2.49, 2, 87.62, 0.95, 5.6949, 0.05206, 0, 1, 0, "Strontium"}, - {"Y", 1.11, 1.9, 1.9, 2.4, 6, 88.90585, 1.22, 6.2173, 0.307, 0.58, 1, 1, "Yttrium"}, - {"Zr", 1.22, 1.75, 1.75, 2.3, 6, 91.224, 1.33, 6.6339, 0.426, 0.58, 0.88, 0.88, "Zirconium"}, - {"Nb", 1.23, 1.64, 1.64, 2.15, 6, 92.90638, 1.6, 6.7589, 0.893, 0.45, 0.76, 0.79, "Niobium"}, - {"Mo", 1.3, 1.54, 1.54, 2.1, 6, 95.96, 2.16, 7.0924, 0.7472, 0.33, 0.71, 0.71, "Molybdenum"}, - {"Tc", 1.36, 1.47, 1.47, 2.05, 6, 98, 1.9, 7.28, 0.55, 0.23, 0.62, 0.62, "Technetium"}, - {"Ru", 1.42, 1.46, 1.46, 2.05, 6, 101.07, 2.2, 7.3605, 1.04638, 0.14, 0.56, 0.56, "Ruthenium"}, - {"Rh", 1.45, 1.42, 1.42, 2, 6, 102.9055, 2.28, 7.4589, 1.14289, 0.04, 0.49, 0.55, "Rhodium"}, - {"Pd", 1.35, 1.39, 1.39, 2.05, 6, 106.42, 2.2, 8.3369, 0.56214, 0, 0.41, 0.52, "Palladium"}, - {"Ag", 1.42, 1.45, 1.45, 2.1, 6, 107.8682, 1.93, 7.5762, 1.30447, 0.88, 0.88, 1, "Silver"}, - {"Cd", 1.46, 1.44, 1.44, 2.2, 6, 112.411, 1.69, 8.9938, 0, 1, 0.85, 0.56, "Cadmium"}, - {"In", 1.49, 1.42, 1.42, 2.2, 3, 114.818, 1.78, 5.7864, 0.404, 0.65, 0.46, 0.45, "Indium"}, - {"Sn", 1.72, 1.39, 1.39, 1.93, 4, 118.701, 1.96, 7.3439, 1.112066, 0.4, 0.5, 0.5, "Tin"}, - {"Sb", 1.82, 1.39, 1.39, 2.17, 3, 121.76, 2.05, 8.6084, 1.047401, 0.62, 0.39, 0.71, "Antimony"}, - {"Te", 2.01, 1.38, 1.38, 2.06, 2, 127.6, 2.1, 9.0096, 1.970875, 0.83, 0.48, 0, "Tellurium"}, - {"I", 2.21, 1.39, 1.39, 1.98, 1, 126.90447, 2.66, 10.4513, 3.059038, 0.58, 0, 0.58, "Iodine"}, - {"Xe", 0, 1.4, 1.4, 2.16, 0, 131.293, 2.6, 12.1298, 0, 0.26, 0.62, 0.69, "Xenon"}, - {"Cs", 0.86, 2.44, 2.44, 3.43, 1, 132.90545, 0.79, 3.8939, 0.471626, 0.34, 0.09, 0.56, "Caesium"}, - {"Ba", 0.97, 2.15, 2.15, 2.68, 2, 137.327, 0.89, 5.2117, 0.14462, 0, 0.79, 0, "Barium"}, - {"La", 1.08, 2.07, 2.07, 2.5, 12, 138.9055, 1.1, 5.5769, 0.47, 0.44, 0.83, 1, "Lanthanum"}, - {"Ce", 0, 2.04, 2.04, 2.48, 6, 140.116, 1.12, 5.5387, 0.5, 1, 1, 0.78, "Cerium"}, - {"Pr", 0, 2.03, 2.03, 2.47, 6, 140.90765, 1.13, 5.473, 0.5, 0.85, 1, 0.78, "Praseodymium"}, - {"Nd", 0, 2.01, 2.01, 2.45, 6, 144.24, 1.14, 5.525, 0.5, 0.78, 1, 0.78, "Neodymium"}, - {"Pm", 0, 1.99, 1.99, 2.43, 6, 145, 0, 5.582, 0.5, 0.64, 1, 0.78, "Promethium"}, - {"Sm", 0, 1.98, 1.98, 2.42, 6, 150.36, 1.17, 5.6437, 0.5, 0.56, 1, 0.78, "Samarium"}, - {"Eu", 0, 1.98, 1.98, 2.4, 6, 151.964, 0, 5.6704, 0.5, 0.38, 1, 0.78, "Europium"}, - {"Gd", 0, 1.96, 1.96, 2.38, 6, 157.25, 1.2, 6.1498, 0.5, 0.27, 1, 0.78, "Gadolinium"}, - {"Tb", 0, 1.94, 1.94, 2.37, 6, 158.92534, 0, 5.8638, 0.5, 0.19, 1, 0.78, "Terbium"}, - {"Dy", 0, 1.92, 1.92, 2.35, 6, 162.5, 1.22, 5.9389, 0.5, 0.12, 1, 0.78, "Dysprosium"}, - {"Ho", 0, 1.92, 1.92, 2.33, 6, 164.93032, 1.23, 6.0215, 0.5, 0, 1, 0.61, "Holmium"}, - {"Er", 0, 1.89, 1.89, 2.32, 6, 167.259, 1.24, 6.1077, 0.5, 0, 0.9, 0.46, "Erbium"}, - {"Tm", 0, 1.9, 1.9, 2.3, 6, 168.93421, 1.25, 6.1843, 0.5, 0, 0.83, 0.32, "Thulium"}, - {"Yb", 0, 1.87, 1.87, 2.28, 6, 173.054, 0, 6.2542, 0.5, 0, 0.75, 0.22, "Ytterbium"}, - {"Lu", 0, 1.87, 1.87, 2.27, 6, 174.9668, 1.27, 5.4259, 0.5, 0, 0.67, 0.14, "Lutetium"}, - {"Hf", 1.23, 1.75, 1.75, 2.25, 6, 178.49, 1.3, 6.8251, 0, 0.3, 0.76, 1, "Hafnium"}, - {"Ta", 1.33, 1.7, 1.7, 2.2, 6, 180.9479, 1.5, 7.5496, 0.322, 0.3, 0.65, 1, "Tantalum"}, - {"W", 1.4, 1.62, 1.62, 2.1, 6, 183.84, 2.36, 7.864, 0.815, 0.13, 0.58, 0.84, "Tungsten"}, - {"Re", 1.46, 1.51, 1.51, 2.05, 6, 186.207, 1.9, 7.8335, 0.15, 0.15, 0.49, 0.67, "Rhenium"}, - {"Os", 1.52, 1.44, 1.44, 2, 6, 190.23, 2.2, 8.4382, 1.0778, 0.15, 0.4, 0.59, "Osmium"}, - {"Ir", 1.55, 1.41, 1.41, 2, 6, 192.217, 2.2, 8.967, 1.56436, 0.09, 0.33, 0.53, "Iridium"}, - {"Pt", 1.44, 1.36, 1.36, 2.05, 6, 195.078, 2.28, 8.9588, 2.1251, 0.9, 0.85, 0.68, "Platinum"}, - {"Au", 1.42, 1.36, 1.36, 2.1, 6, 196.96655, 2.54, 9.2255, 2.30861, 0.8, 0.82, 0.12, "Gold"}, - {"Hg", 1.44, 1.32, 1.32, 2.05, 6, 200.59, 2, 10.4375, 0, 0.71, 0.71, 0.76, "Mercury"}, - {"Tl", 1.44, 1.45, 1.45, 1.96, 3, 204.3833, 1.62, 6.1082, 0.377, 0.65, 0.33, 0.3, "Thallium"}, - {"Pb", 1.55, 1.46, 1.46, 2.02, 4, 207.2, 2.33, 7.4167, 0.364, 0.34, 0.35, 0.38, "Lead"}, - {"Bi", 1.67, 1.48, 1.48, 2.07, 3, 208.9804, 2.02, 7.2855, 0.942363, 0.62, 0.31, 0.71, "Bismuth"}, - {"Po", 1.76, 1.4, 1.4, 1.97, 2, 209, 2, 8.414, 1.9, 0.67, 0.36, 0, "Polonium"}, - {"At", 1.9, 1.5, 1.5, 2.02, 1, 210, 2.2, 0, 2.8, 0.46, 0.31, 0.27, "Astatine"}, - {"Rn", 0, 1.5, 1.5, 2.2, 0, 222, 0, 10.7485, 0, 0.26, 0.51, 0.59, "Radon"}, - {"Fr", 0, 2.6, 2.6, 3.48, 1, 223, 0.7, 4.0727, 0, 0.26, 0, 0.4, "Francium"}, - {"Ra", 0, 2.21, 2.21, 2.83, 2, 226, 0.9, 5.2784, 0, 0, 0.49, 0, "Radium"}, - {"Ac", 0, 2.15, 2.15, 2, 6, 227, 1.1, 5.17, 0, 0.44, 0.67, 0.98, "Actinium"}, - {"Th", 0, 2.06, 2.06, 2.4, 6, 232.0381, 1.3, 6.3067, 0, 0, 0.73, 1, "Thorium"}, - {"Pa", 0, 2, 2, 2, 6, 231.03588, 1.5, 5.89, 0, 0, 0.63, 1, "Protactinium"}, - {"U", 0, 1.96, 1.96, 2.3, 6, 238.02891, 1.38, 6.1941, 0, 0, 0.56, 1, "Uranium"}, - {"Np", 0, 1.9, 1.9, 2, 6, 237.05, 1.36, 6.2657, 0, 0, 0.5, 1, "Neptunium"}, - {"Pu", 0, 1.87, 1.87, 2, 6, 244.06, 1.28, 6.026, 0, 0, 0.42, 1, "Plutonium"}, - {"Am", 0, 1.8, 1.8, 2, 6, 243.06, 1.3, 5.9738, 0, 0.33, 0.36, 0.95, "Americium"}, - {"Cm", 0, 1.69, 1.69, 2, 6, 247.07, 1.3, 5.9914, 0, 0.47, 0.36, 0.89, "Curium"}, - {"Bk", 0, 1.6, 1.6, 2, 6, 247.07, 1.3, 6.1979, 0, 0.54, 0.31, 0.89, "Berkelium"}, - {"Cf", 0, 1.6, 1.6, 2, 6, 251.08, 1.3, 6.2817, 0, 0.63, 0.21, 0.83, "Californium"}, - {"Es", 0, 1.6, 1.6, 2, 6, 252.08, 1.3, 6.42, 0, 0.7, 0.12, 0.83, "Einsteinium"}, - {"Fm", 0, 1.6, 1.6, 2, 6, 257.1, 1.3, 6.5, 0, 0.7, 0.12, 0.73, "Fermium"}, - {"Md", 0, 1.6, 1.6, 2, 6, 258.1, 1.3, 6.58, 0, 0.7, 0.05, 0.65, "Mendelevium"}, - {"No", 0, 1.6, 1.6, 2, 6, 259.1, 1.3, 6.65, 0, 0.74, 0.05, 0.53, "Nobelium"}, - {"Lr", 0, 1.6, 1.6, 2, 6, 262.11, 0, 4.9, 0, 0.78, 0, 0.4, "Lawrencium"}, - {"Rf", 0, 1.6, 1.6, 2, 6, 265.12, 0, 6, 0, 0.8, 0, 0.35, "Rutherfordium"}, - {"Db", 0, 1.6, 1.6, 2, 6, 268.13, 0, 0, 0, 0.82, 0, 0.31, "Dubnium"}, - {"Sg", 0, 1.6, 1.6, 2, 6, 271.13, 0, 0, 0, 0.85, 0, 0.27, "Seaborgium"}, - {"Bh", 0, 1.6, 1.6, 2, 6, 270, 0, 0, 0, 0.88, 0, 0.22, "Bohrium"}, - {"Hs", 0, 1.6, 1.6, 2, 6, 277.15, 0, 0, 0, 0.9, 0, 0.18, "Hassium"}, - {"Mt", 0, 1.6, 1.6, 2, 6, 276.15, 0, 0, 0, 0.92, 0, 0.15, "Meitnerium"}, - {"Ds", 0, 1.6, 1.6, 2, 6, 281.16, 0, 0, 0, 0.93, 0, 0.14, "Darmstadtium"}, - {"Rg", 0, 1.6, 1.6, 2, 6, 280.16, 0, 0, 0, 0.94, 0, 0.13, "Roentgenium"}, - {"Cn", 0, 1.6, 1.6, 2, 6, 285.17, 0, 0, 0, 0.95, 0, 0.12, "Copernicium"}, - {"Uut", 0, 1.6, 1.6, 2, 6, 284.18, 0, 0, 0, 0.96, 0, 0.11, "Ununtrium"}, - {"Fl", 0, 1.6, 1.6, 2, 6, 289.19, 0, 0, 0, 0.97, 0, 0.1, "Flerovium"}, - {"Uup", 0, 1.6, 1.6, 2, 6, 288.19, 0, 0, 0, 0.98, 0, 0.09, "Ununpentium"}, - {"Lv", 0, 1.6, 1.6, 2, 6, 293, 0, 0, 0, 0.99, 0, 0.08, "Livermorium"}, - {"Uuh", 0, 1.6, 1.6, 2, 6, 294, 0, 0, 0, 0.99, 0, 0.07, "Ununseptium"}, - {"Uuh", 0, 1.6, 1.6, 2, 6, 294, 0, 0, 0, 0.99, 0, 0.06, "Ununoctium"}}; +Element elements[NB_ELEMENTS] = { // Symb ARENeg RCov RBO RVdW MaxBnd + // Mass ElNeg. Ionization ElAffinity Red + // Green Blue Name + {"Xx", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.07, 0.5, 0.7, "Dummy"}, + {"H", 2.2, 0.31, 0.31, 1.1, 1, 1.00794, 2.2, 13.5984, 0.75420375, 0.75, + 0.75, 0.75, "Hydrogen"}, + {"He", 0, 0.28, 0.28, 1.4, 0, 4.002602, 0, 24.5874, 0, 0.85, 1, 1, + "Helium"}, + {"Li", 0.97, 1.28, 1.28, 1.81, 1, 6.941, 0.98, 5.3917, 0.618049, 0.8, 0.5, + 1, "Lithium"}, + {"Be", 1.47, 0.96, 0.96, 1.53, 2, 9.012182, 1.57, 9.3227, 0, 0.76, 1, 0, + "Beryllium"}, + {"B", 2.01, 0.84, 0.84, 1.92, 4, 10.811, 2.04, 8.298, 0.279723, 1, 0.71, + 0.71, "Boron"}, + {"C", 2.5, 0.76, 0.76, 1.7, 4, 12.0107, 2.55, 11.2603, 1.262118, 0.4, 0.4, + 0.4, "Carbon"}, + {"N", 3.07, 0.71, 0.71, 1.55, 4, 14.0067, 3.04, 14.5341, -0.07, 0.05, 0.05, + 1, "Nitrogen"}, + {"O", 3.5, 0.66, 0.66, 1.52, 2, 15.9994, 3.44, 13.6181, 1.461112, 1, 0.05, + 0.05, "Oxygen"}, + {"F", 4.1, 0.57, 0.57, 1.47, 1, 18.9984032, 3.98, 17.4228, 3.4011887, 0.5, + 0.7, 1, "Fluorine"}, + {"Ne", 0, 0.58, 0.58, 1.54, 0, 20.1797, 0, 21.5645, 0, 0.7, 0.89, 0.96, + "Neon"}, + {"Na", 1.01, 1.66, 1.66, 2.27, 1, 22.98977, 0.93, 5.1391, 0.547926, 0.67, + 0.36, 0.95, "Sodium"}, + {"Mg", 1.23, 1.41, 1.41, 1.73, 2, 24.305, 1.31, 7.6462, 0, 0.54, 1, 0, + "Magnesium"}, + {"Al", 1.47, 1.21, 1.21, 1.84, 6, 26.981538, 1.61, 5.9858, 0.43283, 0.75, + 0.65, 0.65, "Aluminium"}, + {"Si", 1.74, 1.11, 1.11, 2.1, 6, 28.0855, 1.9, 8.1517, 1.389521, 0.5, 0.6, + 0.6, "Silicon"}, + {"P", 2.06, 1.07, 1.07, 1.8, 6, 30.973761, 2.19, 10.4867, 0.7465, 1, 0.5, 0, + "Phosphorus"}, + {"S", 2.44, 1.05, 1.05, 1.8, 6, 32.065, 2.58, 10.36, 2.0771029, 0.7, 0.7, 0, + "Sulfur"}, + {"Cl", 2.83, 1.02, 1.02, 1.75, 1, 35.453, 3.16, 12.9676, 3.612724, 0.12, + 0.94, 0.12, "Chlorine"}, + {"Ar", 0, 1.06, 1.06, 1.88, 0, 39.948, 0, 15.7596, 0, 0.5, 0.82, 0.89, + "Argon"}, + {"K", 0.91, 2.03, 2.03, 2.75, 1, 39.0983, 0.82, 4.3407, 0.501459, 0.56, + 0.25, 0.83, "Potassium"}, + {"Ca", 1.04, 1.76, 1.76, 2.31, 2, 40.078, 1, 6.1132, 0.02455, 0.24, 1, 0, + "Calcium"}, + {"Sc", 1.2, 1.7, 1.7, 2.3, 6, 44.95591, 1.36, 6.5615, 0.188, 0.9, 0.9, 0.9, + "Scandium"}, + {"Ti", 1.32, 1.6, 1.6, 2.15, 6, 47.867, 1.54, 6.8281, 0.084, 0.75, 0.76, + 0.78, "Titanium"}, + {"V", 1.45, 1.53, 1.53, 2.05, 6, 50.9415, 1.63, 6.7462, 0.525, 0.65, 0.65, + 0.67, "Vanadium"}, + {"Cr", 1.56, 1.39, 1.39, 2.05, 6, 51.9961, 1.66, 6.7665, 0.67584, 0.54, 0.6, + 0.78, "Chromium"}, + {"Mn", 1.6, 1.39, 1.39, 2.05, 8, 54.938049, 1.55, 7.434, 0, 0.61, 0.48, + 0.78, "Manganese"}, + {"Fe", 1.64, 1.32, 1.32, 2.05, 6, 55.845, 1.83, 7.9024, 0.151, 0.88, 0.4, + 0.2, "Iron"}, + {"Co", 1.7, 1.26, 1.26, 2, 6, 58.9332, 1.88, 7.881, 0.6633, 0.94, 0.56, + 0.63, "Cobalt"}, + {"Ni", 1.75, 1.24, 1.24, 2, 6, 58.6934, 1.91, 7.6398, 1.15716, 0.31, 0.82, + 0.31, "Nickel"}, + {"Cu", 1.75, 1.32, 1.32, 2, 6, 63.546, 1.9, 7.7264, 1.23578, 0.78, 0.5, 0.2, + "Copper"}, + {"Zn", 1.66, 1.22, 1.22, 2.1, 6, 65.38, 1.65, 9.3942, 0, 0.49, 0.5, 0.69, + "Zinc"}, + {"Ga", 1.82, 1.22, 1.22, 1.87, 3, 69.723, 1.81, 5.9993, 0.41, 0.76, 0.56, + 0.56, "Gallium"}, + {"Ge", 2.02, 1.2, 1.2, 2.11, 4, 72.64, 2.01, 7.8994, 1.232712, 0.4, 0.56, + 0.56, "Germanium"}, + {"As", 2.2, 1.19, 1.19, 1.85, 3, 74.9216, 2.18, 9.7886, 0.814, 0.74, 0.5, + 0.89, "Arsenic"}, + {"Se", 2.48, 1.2, 1.2, 1.9, 2, 78.96, 2.55, 9.7524, 2.02067, 1, 0.63, 0, + "Selenium"}, + {"Br", 2.74, 1.2, 1.2, 1.83, 1, 79.904, 2.96, 11.8138, 3.363588, 0.65, 0.16, + 0.16, "Bromine"}, + {"Kr", 0, 1.16, 1.16, 2.02, 0, 83.798, 3, 13.9996, 0, 0.36, 0.72, 0.82, + "Krypton"}, + {"Rb", 0.89, 2.2, 2.2, 3.03, 1, 85.4678, 0.82, 4.1771, 0.485916, 0.44, 0.18, + 0.69, "Rubidium"}, + {"Sr", 0.99, 1.95, 1.95, 2.49, 2, 87.62, 0.95, 5.6949, 0.05206, 0, 1, 0, + "Strontium"}, + {"Y", 1.11, 1.9, 1.9, 2.4, 6, 88.90585, 1.22, 6.2173, 0.307, 0.58, 1, 1, + "Yttrium"}, + {"Zr", 1.22, 1.75, 1.75, 2.3, 6, 91.224, 1.33, 6.6339, 0.426, 0.58, 0.88, + 0.88, "Zirconium"}, + {"Nb", 1.23, 1.64, 1.64, 2.15, 6, 92.90638, 1.6, 6.7589, 0.893, 0.45, 0.76, + 0.79, "Niobium"}, + {"Mo", 1.3, 1.54, 1.54, 2.1, 6, 95.96, 2.16, 7.0924, 0.7472, 0.33, 0.71, + 0.71, "Molybdenum"}, + {"Tc", 1.36, 1.47, 1.47, 2.05, 6, 98, 1.9, 7.28, 0.55, 0.23, 0.62, 0.62, + "Technetium"}, + {"Ru", 1.42, 1.46, 1.46, 2.05, 6, 101.07, 2.2, 7.3605, 1.04638, 0.14, 0.56, + 0.56, "Ruthenium"}, + {"Rh", 1.45, 1.42, 1.42, 2, 6, 102.9055, 2.28, 7.4589, 1.14289, 0.04, 0.49, + 0.55, "Rhodium"}, + {"Pd", 1.35, 1.39, 1.39, 2.05, 6, 106.42, 2.2, 8.3369, 0.56214, 0, 0.41, + 0.52, "Palladium"}, + {"Ag", 1.42, 1.45, 1.45, 2.1, 6, 107.8682, 1.93, 7.5762, 1.30447, 0.88, + 0.88, 1, "Silver"}, + {"Cd", 1.46, 1.44, 1.44, 2.2, 6, 112.411, 1.69, 8.9938, 0, 1, 0.85, 0.56, + "Cadmium"}, + {"In", 1.49, 1.42, 1.42, 2.2, 3, 114.818, 1.78, 5.7864, 0.404, 0.65, 0.46, + 0.45, "Indium"}, + {"Sn", 1.72, 1.39, 1.39, 1.93, 4, 118.701, 1.96, 7.3439, 1.112066, 0.4, 0.5, + 0.5, "Tin"}, + {"Sb", 1.82, 1.39, 1.39, 2.17, 3, 121.76, 2.05, 8.6084, 1.047401, 0.62, + 0.39, 0.71, "Antimony"}, + {"Te", 2.01, 1.38, 1.38, 2.06, 2, 127.6, 2.1, 9.0096, 1.970875, 0.83, 0.48, + 0, "Tellurium"}, + {"I", 2.21, 1.39, 1.39, 1.98, 1, 126.90447, 2.66, 10.4513, 3.059038, 0.58, + 0, 0.58, "Iodine"}, + {"Xe", 0, 1.4, 1.4, 2.16, 0, 131.293, 2.6, 12.1298, 0, 0.26, 0.62, 0.69, + "Xenon"}, + {"Cs", 0.86, 2.44, 2.44, 3.43, 1, 132.90545, 0.79, 3.8939, 0.471626, 0.34, + 0.09, 0.56, "Caesium"}, + {"Ba", 0.97, 2.15, 2.15, 2.68, 2, 137.327, 0.89, 5.2117, 0.14462, 0, 0.79, + 0, "Barium"}, + {"La", 1.08, 2.07, 2.07, 2.5, 12, 138.9055, 1.1, 5.5769, 0.47, 0.44, 0.83, + 1, "Lanthanum"}, + {"Ce", 0, 2.04, 2.04, 2.48, 6, 140.116, 1.12, 5.5387, 0.5, 1, 1, 0.78, + "Cerium"}, + {"Pr", 0, 2.03, 2.03, 2.47, 6, 140.90765, 1.13, 5.473, 0.5, 0.85, 1, 0.78, + "Praseodymium"}, + {"Nd", 0, 2.01, 2.01, 2.45, 6, 144.24, 1.14, 5.525, 0.5, 0.78, 1, 0.78, + "Neodymium"}, + {"Pm", 0, 1.99, 1.99, 2.43, 6, 145, 0, 5.582, 0.5, 0.64, 1, 0.78, + "Promethium"}, + {"Sm", 0, 1.98, 1.98, 2.42, 6, 150.36, 1.17, 5.6437, 0.5, 0.56, 1, 0.78, + "Samarium"}, + {"Eu", 0, 1.98, 1.98, 2.4, 6, 151.964, 0, 5.6704, 0.5, 0.38, 1, 0.78, + "Europium"}, + {"Gd", 0, 1.96, 1.96, 2.38, 6, 157.25, 1.2, 6.1498, 0.5, 0.27, 1, 0.78, + "Gadolinium"}, + {"Tb", 0, 1.94, 1.94, 2.37, 6, 158.92534, 0, 5.8638, 0.5, 0.19, 1, 0.78, + "Terbium"}, + {"Dy", 0, 1.92, 1.92, 2.35, 6, 162.5, 1.22, 5.9389, 0.5, 0.12, 1, 0.78, + "Dysprosium"}, + {"Ho", 0, 1.92, 1.92, 2.33, 6, 164.93032, 1.23, 6.0215, 0.5, 0, 1, 0.61, + "Holmium"}, + {"Er", 0, 1.89, 1.89, 2.32, 6, 167.259, 1.24, 6.1077, 0.5, 0, 0.9, 0.46, + "Erbium"}, + {"Tm", 0, 1.9, 1.9, 2.3, 6, 168.93421, 1.25, 6.1843, 0.5, 0, 0.83, 0.32, + "Thulium"}, + {"Yb", 0, 1.87, 1.87, 2.28, 6, 173.054, 0, 6.2542, 0.5, 0, 0.75, 0.22, + "Ytterbium"}, + {"Lu", 0, 1.87, 1.87, 2.27, 6, 174.9668, 1.27, 5.4259, 0.5, 0, 0.67, 0.14, + "Lutetium"}, + {"Hf", 1.23, 1.75, 1.75, 2.25, 6, 178.49, 1.3, 6.8251, 0, 0.3, 0.76, 1, + "Hafnium"}, + {"Ta", 1.33, 1.7, 1.7, 2.2, 6, 180.9479, 1.5, 7.5496, 0.322, 0.3, 0.65, 1, + "Tantalum"}, + {"W", 1.4, 1.62, 1.62, 2.1, 6, 183.84, 2.36, 7.864, 0.815, 0.13, 0.58, 0.84, + "Tungsten"}, + {"Re", 1.46, 1.51, 1.51, 2.05, 6, 186.207, 1.9, 7.8335, 0.15, 0.15, 0.49, + 0.67, "Rhenium"}, + {"Os", 1.52, 1.44, 1.44, 2, 6, 190.23, 2.2, 8.4382, 1.0778, 0.15, 0.4, 0.59, + "Osmium"}, + {"Ir", 1.55, 1.41, 1.41, 2, 6, 192.217, 2.2, 8.967, 1.56436, 0.09, 0.33, + 0.53, "Iridium"}, + {"Pt", 1.44, 1.36, 1.36, 2.05, 6, 195.078, 2.28, 8.9588, 2.1251, 0.9, 0.85, + 0.68, "Platinum"}, + {"Au", 1.42, 1.36, 1.36, 2.1, 6, 196.96655, 2.54, 9.2255, 2.30861, 0.8, + 0.82, 0.12, "Gold"}, + {"Hg", 1.44, 1.32, 1.32, 2.05, 6, 200.59, 2, 10.4375, 0, 0.71, 0.71, 0.76, + "Mercury"}, + {"Tl", 1.44, 1.45, 1.45, 1.96, 3, 204.3833, 1.62, 6.1082, 0.377, 0.65, 0.33, + 0.3, "Thallium"}, + {"Pb", 1.55, 1.46, 1.46, 2.02, 4, 207.2, 2.33, 7.4167, 0.364, 0.34, 0.35, + 0.38, "Lead"}, + {"Bi", 1.67, 1.48, 1.48, 2.07, 3, 208.9804, 2.02, 7.2855, 0.942363, 0.62, + 0.31, 0.71, "Bismuth"}, + {"Po", 1.76, 1.4, 1.4, 1.97, 2, 209, 2, 8.414, 1.9, 0.67, 0.36, 0, + "Polonium"}, + {"At", 1.9, 1.5, 1.5, 2.02, 1, 210, 2.2, 0, 2.8, 0.46, 0.31, 0.27, + "Astatine"}, + {"Rn", 0, 1.5, 1.5, 2.2, 0, 222, 0, 10.7485, 0, 0.26, 0.51, 0.59, "Radon"}, + {"Fr", 0, 2.6, 2.6, 3.48, 1, 223, 0.7, 4.0727, 0, 0.26, 0, 0.4, "Francium"}, + {"Ra", 0, 2.21, 2.21, 2.83, 2, 226, 0.9, 5.2784, 0, 0, 0.49, 0, "Radium"}, + {"Ac", 0, 2.15, 2.15, 2, 6, 227, 1.1, 5.17, 0, 0.44, 0.67, 0.98, + "Actinium"}, + {"Th", 0, 2.06, 2.06, 2.4, 6, 232.0381, 1.3, 6.3067, 0, 0, 0.73, 1, + "Thorium"}, + {"Pa", 0, 2, 2, 2, 6, 231.03588, 1.5, 5.89, 0, 0, 0.63, 1, "Protactinium"}, + {"U", 0, 1.96, 1.96, 2.3, 6, 238.02891, 1.38, 6.1941, 0, 0, 0.56, 1, + "Uranium"}, + {"Np", 0, 1.9, 1.9, 2, 6, 237.05, 1.36, 6.2657, 0, 0, 0.5, 1, "Neptunium"}, + {"Pu", 0, 1.87, 1.87, 2, 6, 244.06, 1.28, 6.026, 0, 0, 0.42, 1, + "Plutonium"}, + {"Am", 0, 1.8, 1.8, 2, 6, 243.06, 1.3, 5.9738, 0, 0.33, 0.36, 0.95, + "Americium"}, + {"Cm", 0, 1.69, 1.69, 2, 6, 247.07, 1.3, 5.9914, 0, 0.47, 0.36, 0.89, + "Curium"}, + {"Bk", 0, 1.6, 1.6, 2, 6, 247.07, 1.3, 6.1979, 0, 0.54, 0.31, 0.89, + "Berkelium"}, + {"Cf", 0, 1.6, 1.6, 2, 6, 251.08, 1.3, 6.2817, 0, 0.63, 0.21, 0.83, + "Californium"}, + {"Es", 0, 1.6, 1.6, 2, 6, 252.08, 1.3, 6.42, 0, 0.7, 0.12, 0.83, + "Einsteinium"}, + {"Fm", 0, 1.6, 1.6, 2, 6, 257.1, 1.3, 6.5, 0, 0.7, 0.12, 0.73, "Fermium"}, + {"Md", 0, 1.6, 1.6, 2, 6, 258.1, 1.3, 6.58, 0, 0.7, 0.05, 0.65, + "Mendelevium"}, + {"No", 0, 1.6, 1.6, 2, 6, 259.1, 1.3, 6.65, 0, 0.74, 0.05, 0.53, + "Nobelium"}, + {"Lr", 0, 1.6, 1.6, 2, 6, 262.11, 0, 4.9, 0, 0.78, 0, 0.4, "Lawrencium"}, + {"Rf", 0, 1.6, 1.6, 2, 6, 265.12, 0, 6, 0, 0.8, 0, 0.35, "Rutherfordium"}, + {"Db", 0, 1.6, 1.6, 2, 6, 268.13, 0, 0, 0, 0.82, 0, 0.31, "Dubnium"}, + {"Sg", 0, 1.6, 1.6, 2, 6, 271.13, 0, 0, 0, 0.85, 0, 0.27, "Seaborgium"}, + {"Bh", 0, 1.6, 1.6, 2, 6, 270, 0, 0, 0, 0.88, 0, 0.22, "Bohrium"}, + {"Hs", 0, 1.6, 1.6, 2, 6, 277.15, 0, 0, 0, 0.9, 0, 0.18, "Hassium"}, + {"Mt", 0, 1.6, 1.6, 2, 6, 276.15, 0, 0, 0, 0.92, 0, 0.15, "Meitnerium"}, + {"Ds", 0, 1.6, 1.6, 2, 6, 281.16, 0, 0, 0, 0.93, 0, 0.14, "Darmstadtium"}, + {"Rg", 0, 1.6, 1.6, 2, 6, 280.16, 0, 0, 0, 0.94, 0, 0.13, "Roentgenium"}, + {"Cn", 0, 1.6, 1.6, 2, 6, 285.17, 0, 0, 0, 0.95, 0, 0.12, "Copernicium"}, + {"Uut", 0, 1.6, 1.6, 2, 6, 284.18, 0, 0, 0, 0.96, 0, 0.11, "Ununtrium"}, + {"Fl", 0, 1.6, 1.6, 2, 6, 289.19, 0, 0, 0, 0.97, 0, 0.1, "Flerovium"}, + {"Uup", 0, 1.6, 1.6, 2, 6, 288.19, 0, 0, 0, 0.98, 0, 0.09, "Ununpentium"}, + {"Lv", 0, 1.6, 1.6, 2, 6, 293, 0, 0, 0, 0.99, 0, 0.08, "Livermorium"}, + {"Uuh", 0, 1.6, 1.6, 2, 6, 294, 0, 0, 0, 0.99, 0, 0.07, "Ununseptium"}, + {"Uuh", 0, 1.6, 1.6, 2, 6, 294, 0, 0, 0, 0.99, 0, 0.06, "Ununoctium"}}; struct ColorMap { @@ -185,33 +277,60 @@ struct ColorMap short R, G, B; }; ColorMap colormap[NB_ELEMENTS] = { - {"H", 0xFF, 0xFF, 0xFF}, {"He", 0xD9, 0xFF, 0xFF}, {"Li", 0xCC, 0x80, 0xFF}, {"Be", 0xC2, 0xFF, 0x00}, - {"B", 0xFF, 0xB5, 0xB5}, {"C", 0x90, 0x90, 0x90}, {"N", 0x30, 0x50, 0xF8}, {"O", 0xFF, 0x0D, 0x0D}, - {"F", 0x9E, 0x05, 0x1}, {"Ne", 0xB3, 0xE3, 0xF5}, {"Na", 0xAB, 0x5C, 0xF2}, {"Mg", 0x8A, 0xFF, 0x00}, - {"Al", 0xBF, 0xA6, 0xA6}, {"Si", 0xF0, 0xC8, 0xA0}, {"P", 0xFF, 0x80, 0x00}, {"S", 0xFF, 0xFF, 0x30}, - {"Cl", 0x1F, 0xF0, 0x1F}, {"Ar", 0x80, 0xD1, 0xE3}, {"K", 0x8F, 0x40, 0xD4}, {"Ca", 0x3D, 0xFF, 0x00}, - {"Sc", 0xE6, 0xE6, 0xE6}, {"Ti", 0xBF, 0xC2, 0xC7}, {"V", 0xA6, 0xA6, 0xAB}, {"Cr", 0x8A, 0x99, 0xC7}, - {"Mn", 0x9C, 0x7A, 0xC7}, {"Fe", 0xE0, 0x66, 0x33}, {"Co", 0xF0, 0x90, 0xA0}, {"Ni", 0x50, 0xD0, 0x50}, - {"Cu", 0xC8, 0x80, 0x33}, {"Zn", 0x7D, 0x80, 0xB0}, {"Ga", 0xC2, 0x8F, 0x8F}, {"Ge", 0x66, 0x8F, 0x8F}, - {"As", 0xBD, 0x80, 0xE3}, {"Se", 0xFF, 0xA1, 0x00}, {"Br", 0xA6, 0x29, 0x29}, {"Kr", 0x5C, 0xB8, 0xD1}, - {"Rb", 0x70, 0x2E, 0xB0}, {"Sr", 0x00, 0xFF, 0x00}, {"Y", 0x94, 0xFF, 0xFF}, {"Zr", 0x94, 0xE0, 0xE0}, - {"Nb", 0x73, 0xC2, 0xC9}, {"Mo", 0x54, 0xB5, 0xB5}, {"Tc", 0x3B, 0x9E, 0x9E}, {"Ru", 0x24, 0x8F, 0x8F}, - {"Rh", 0x0A, 0x7D, 0x8C}, {"Pd", 0x69, 0x85, 0x00}, {"Ag", 0xC0, 0xC0, 0xC0}, {"Cd", 0xFF, 0xD9, 0x8F}, - {"In", 0xA6, 0x75, 0x73}, {"Sn", 0x66, 0x80, 0x80}, {"Sb", 0x9E, 0x63, 0xB5}, {"Te", 0xD4, 0x7A, 0x00}, - {"I", 0x94, 0x00, 0x94}, {"Xe", 0x42, 0x9E, 0xB0}, {"Cs", 0x57, 0x17, 0x8F}, {"Ba", 0x00, 0xC9, 0x00}, - {"La", 0x70, 0xD4, 0xFF}, {"Ce", 0xFF, 0xFF, 0xC7}, {"Pr", 0xD9, 0xFF, 0xC7}, {"Nd", 0xC7, 0xFF, 0xC7}, - {"Pm", 0xA3, 0xFF, 0xC7}, {"Sm", 0x8F, 0xFF, 0xC7}, {"Eu", 0x61, 0xFF, 0xC7}, {"Gd", 0x45, 0xFF, 0xC7}, - {"Tb", 0x30, 0xFF, 0xC7}, {"Dy", 0x1F, 0xFF, 0xC7}, {"Ho", 0x00, 0xFF, 0x9C}, {"Er", 0x00, 0xE6, 0x75}, - {"Tm", 0x00, 0xD4, 0x52}, {"Yb", 0x00, 0xBF, 0x38}, {"Lu", 0x00, 0xAB, 0x24}, {"Hf", 0x4D, 0xC2, 0xFF}, - {"Ta", 0x4D, 0xA6, 0xFF}, {"W", 0x21, 0x94, 0xD6}, {"Re", 0x26, 0x7D, 0xAB}, {"Os", 0x26, 0x66, 0x96}, - {"Ir", 0x17, 0x54, 0x87}, {"Pt", 0xD0, 0xD0, 0xE0}, {"Au", 0xFF, 0xD1, 0x23}, {"Hg", 0xB8, 0xB8, 0xD0}, - {"Tl", 0xA6, 0x54, 0x4D}, {"Pb", 0x57, 0x59, 0x61}, {"Bi", 0x9E, 0x4F, 0xB5}, {"Po", 0xAB, 0x5C, 0x00}, - {"At", 0x75, 0x4F, 0x45}, {"Rn", 0x42, 0x82, 0x96}, {"Fr", 0x42, 0x00, 0x66}, {"Ra", 0x00, 0x7D, 0x00}, - {"Ac", 0x70, 0xAB, 0xFA}, {"Th", 0x00, 0xBA, 0xFF}, {"Pa", 0x00, 0xA1, 0xFF}, {"U", 0x00, 0x8F, 0xFF}, - {"Np", 0x00, 0x80, 0xFF}, {"Pu", 0x00, 0x6B, 0xFF}, {"Am", 0x54, 0x5C, 0xF2}, {"Cm", 0x78, 0x5C, 0xE3}, - {"Bk", 0x8A, 0x4F, 0xE3}, {"Cf", 0xA1, 0x36, 0xD4}, {"Es", 0xB3, 0x1F, 0xD4}, {"Fm", 0xB3, 0x1F, 0xBA}, - {"Md", 0xB3, 0x0D, 0xA6}, {"No", 0xBD, 0x0D, 0x87}, {"Lr", 0xC7, 0x00, 0x66}, {"Rf", 0xCC, 0x00, 0x59}, - {"Db", 0xD1, 0x00, 0x4F}, {"Sg", 0xD9, 0x00, 0x45}, {"Bh", 0xE0, 0x00, 0x38}, {"Hs", 0xE6, 0x00, 0x2E}, + {"H", 0xFF, 0xFF, 0xFF}, {"He", 0xD9, 0xFF, 0xFF}, + {"Li", 0xCC, 0x80, 0xFF}, {"Be", 0xC2, 0xFF, 0x00}, + {"B", 0xFF, 0xB5, 0xB5}, {"C", 0x90, 0x90, 0x90}, + {"N", 0x30, 0x50, 0xF8}, {"O", 0xFF, 0x0D, 0x0D}, + {"F", 0x9E, 0x05, 0x1}, {"Ne", 0xB3, 0xE3, 0xF5}, + {"Na", 0xAB, 0x5C, 0xF2}, {"Mg", 0x8A, 0xFF, 0x00}, + {"Al", 0xBF, 0xA6, 0xA6}, {"Si", 0xF0, 0xC8, 0xA0}, + {"P", 0xFF, 0x80, 0x00}, {"S", 0xFF, 0xFF, 0x30}, + {"Cl", 0x1F, 0xF0, 0x1F}, {"Ar", 0x80, 0xD1, 0xE3}, + {"K", 0x8F, 0x40, 0xD4}, {"Ca", 0x3D, 0xFF, 0x00}, + {"Sc", 0xE6, 0xE6, 0xE6}, {"Ti", 0xBF, 0xC2, 0xC7}, + {"V", 0xA6, 0xA6, 0xAB}, {"Cr", 0x8A, 0x99, 0xC7}, + {"Mn", 0x9C, 0x7A, 0xC7}, {"Fe", 0xE0, 0x66, 0x33}, + {"Co", 0xF0, 0x90, 0xA0}, {"Ni", 0x50, 0xD0, 0x50}, + {"Cu", 0xC8, 0x80, 0x33}, {"Zn", 0x7D, 0x80, 0xB0}, + {"Ga", 0xC2, 0x8F, 0x8F}, {"Ge", 0x66, 0x8F, 0x8F}, + {"As", 0xBD, 0x80, 0xE3}, {"Se", 0xFF, 0xA1, 0x00}, + {"Br", 0xA6, 0x29, 0x29}, {"Kr", 0x5C, 0xB8, 0xD1}, + {"Rb", 0x70, 0x2E, 0xB0}, {"Sr", 0x00, 0xFF, 0x00}, + {"Y", 0x94, 0xFF, 0xFF}, {"Zr", 0x94, 0xE0, 0xE0}, + {"Nb", 0x73, 0xC2, 0xC9}, {"Mo", 0x54, 0xB5, 0xB5}, + {"Tc", 0x3B, 0x9E, 0x9E}, {"Ru", 0x24, 0x8F, 0x8F}, + {"Rh", 0x0A, 0x7D, 0x8C}, {"Pd", 0x69, 0x85, 0x00}, + {"Ag", 0xC0, 0xC0, 0xC0}, {"Cd", 0xFF, 0xD9, 0x8F}, + {"In", 0xA6, 0x75, 0x73}, {"Sn", 0x66, 0x80, 0x80}, + {"Sb", 0x9E, 0x63, 0xB5}, {"Te", 0xD4, 0x7A, 0x00}, + {"I", 0x94, 0x00, 0x94}, {"Xe", 0x42, 0x9E, 0xB0}, + {"Cs", 0x57, 0x17, 0x8F}, {"Ba", 0x00, 0xC9, 0x00}, + {"La", 0x70, 0xD4, 0xFF}, {"Ce", 0xFF, 0xFF, 0xC7}, + {"Pr", 0xD9, 0xFF, 0xC7}, {"Nd", 0xC7, 0xFF, 0xC7}, + {"Pm", 0xA3, 0xFF, 0xC7}, {"Sm", 0x8F, 0xFF, 0xC7}, + {"Eu", 0x61, 0xFF, 0xC7}, {"Gd", 0x45, 0xFF, 0xC7}, + {"Tb", 0x30, 0xFF, 0xC7}, {"Dy", 0x1F, 0xFF, 0xC7}, + {"Ho", 0x00, 0xFF, 0x9C}, {"Er", 0x00, 0xE6, 0x75}, + {"Tm", 0x00, 0xD4, 0x52}, {"Yb", 0x00, 0xBF, 0x38}, + {"Lu", 0x00, 0xAB, 0x24}, {"Hf", 0x4D, 0xC2, 0xFF}, + {"Ta", 0x4D, 0xA6, 0xFF}, {"W", 0x21, 0x94, 0xD6}, + {"Re", 0x26, 0x7D, 0xAB}, {"Os", 0x26, 0x66, 0x96}, + {"Ir", 0x17, 0x54, 0x87}, {"Pt", 0xD0, 0xD0, 0xE0}, + {"Au", 0xFF, 0xD1, 0x23}, {"Hg", 0xB8, 0xB8, 0xD0}, + {"Tl", 0xA6, 0x54, 0x4D}, {"Pb", 0x57, 0x59, 0x61}, + {"Bi", 0x9E, 0x4F, 0xB5}, {"Po", 0xAB, 0x5C, 0x00}, + {"At", 0x75, 0x4F, 0x45}, {"Rn", 0x42, 0x82, 0x96}, + {"Fr", 0x42, 0x00, 0x66}, {"Ra", 0x00, 0x7D, 0x00}, + {"Ac", 0x70, 0xAB, 0xFA}, {"Th", 0x00, 0xBA, 0xFF}, + {"Pa", 0x00, 0xA1, 0xFF}, {"U", 0x00, 0x8F, 0xFF}, + {"Np", 0x00, 0x80, 0xFF}, {"Pu", 0x00, 0x6B, 0xFF}, + {"Am", 0x54, 0x5C, 0xF2}, {"Cm", 0x78, 0x5C, 0xE3}, + {"Bk", 0x8A, 0x4F, 0xE3}, {"Cf", 0xA1, 0x36, 0xD4}, + {"Es", 0xB3, 0x1F, 0xD4}, {"Fm", 0xB3, 0x1F, 0xBA}, + {"Md", 0xB3, 0x0D, 0xA6}, {"No", 0xBD, 0x0D, 0x87}, + {"Lr", 0xC7, 0x00, 0x66}, {"Rf", 0xCC, 0x00, 0x59}, + {"Db", 0xD1, 0x00, 0x4F}, {"Sg", 0xD9, 0x00, 0x45}, + {"Bh", 0xE0, 0x00, 0x38}, {"Hs", 0xE6, 0x00, 0x2E}, {"Mt", 0xEB, 0x00, 0x26}}; /* @@ -228,12 +347,7 @@ struct Atom int processed; int id; int index; -#ifdef USE_CUDA - vec4f position; -#endif -#ifdef USE_OPENCL vec4f position; -#endif int materialId; int chainId; int residue; @@ -379,23 +493,31 @@ PDBReader::PDBReader(void) { } -PDBReader::~PDBReader(void) -{ -} +PDBReader::~PDBReader(void) {} -vec4f PDBReader::loadAtomsFromFile(const std::string &filename, GPUKernel &cudaKernel, GeometryType geometryType, - const float defaultAtomSize, const float defaultStickSize, const int materialType, - const vec4f scale, const bool useModels) +vec4f PDBReader::loadAtomsFromFile(const std::string &filename, + GPUKernel &cudaKernel, + GeometryType geometryType, + const float defaultAtomSize, + const float defaultStickSize, + const int materialType, const vec4f scale, + const bool useModels) { LOG_INFO(1, "OBJ Filename.......: " << filename); for (int i = 0; i < NB_ELEMENTS; ++i) { - std::transform(colormap[i].symbol.begin(), colormap[i].symbol.end(), colormap[i].symbol.begin(), ::toupper); - cudaKernel.setMaterial(i, static_cast(colormap[i].R) / 255.f, static_cast(colormap[i].G) / 255.f, - static_cast(colormap[i].B) / 255.f, 0.f, 0.f, 0.f, false, false, 0, 0.f, 0.f, - TEXTURE_NONE, TEXTURE_NONE, TEXTURE_NONE, TEXTURE_NONE, TEXTURE_NONE, TEXTURE_NONE, - TEXTURE_NONE, 1.f, 100.f, 0.f, 0.f, cudaKernel.getSceneInfo().viewDistance, 0.f, false); + std::transform(colormap[i].symbol.begin(), colormap[i].symbol.end(), + colormap[i].symbol.begin(), ::toupper); + cudaKernel.setMaterial(i, static_cast(colormap[i].R) / 255.f, + static_cast(colormap[i].G) / 255.f, + static_cast(colormap[i].B) / 255.f, 0.f, + 0.f, 0.f, false, false, 0, 0.f, 0.f, + TEXTURE_NONE, TEXTURE_NONE, TEXTURE_NONE, + TEXTURE_NONE, TEXTURE_NONE, TEXTURE_NONE, + TEXTURE_NONE, 1.f, 100.f, 0.f, 0.f, + cudaKernel.getSceneInfo().viewDistance, 0.f, + false); } cudaKernel.resetBoxes(true); @@ -406,7 +528,9 @@ vec4f PDBReader::loadAtomsFromFile(const std::string &filename, GPUKernel &cudaK std::vector connections; vec4f minPos = make_vec4f(100000.f, 100000.f, 100000.f); vec4f maxPos = make_vec4f(-100000.f, -100000.f, -100000.f, 0.f); - LOG_INFO(1, "--------------------------------------------------------------------------------"); + LOG_INFO(1, + "-----------------------------------------------------------------" + "---------------"); LOG_INFO(1, "Loading PDB File: " << filename); int index(0); std::ifstream file(filename.c_str()); @@ -457,13 +581,16 @@ vec4f PDBReader::loadAtomsFromFile(const std::string &filename, GPUKernel &cudaK atom.residue = static_cast(atoi(value.c_str())); break; case 37: - atom.position.x = static_cast(atof(value.c_str())); + atom.position.x = + static_cast(atof(value.c_str())); break; case 45: - atom.position.y = static_cast(atof(value.c_str())); + atom.position.y = + static_cast(atof(value.c_str())); break; case 53: - atom.position.z = -static_cast(atof(value.c_str())); + atom.position.z = + -static_cast(atof(value.c_str())); break; default: if (line.at(i) != ' ') @@ -476,7 +603,8 @@ vec4f PDBReader::loadAtomsFromFile(const std::string &filename, GPUKernel &cudaK LOG_INFO(3, "Atom: " << atomName) // Backbone atom.isBackbone = - (geometryType == gtBackbone || geometryType == gtIsoSurface || atomCode.length() == 1); + (geometryType == gtBackbone || + geometryType == gtIsoSurface || atomCode.length() == 1); // Material atom.materialId = 0; @@ -490,7 +618,9 @@ vec4f PDBReader::loadAtomsFromFile(const std::string &filename, GPUKernel &cudaK switch (materialType) { case 1: - atom.materialId = (atom.chainId % 2 == 0) ? static_cast(i) : 1000; + atom.materialId = (atom.chainId % 2 == 0) + ? static_cast(i) + : 1000; break; case 2: atom.materialId = atom.residue % 10; @@ -499,13 +629,16 @@ vec4f PDBReader::loadAtomsFromFile(const std::string &filename, GPUKernel &cudaK atom.materialId = static_cast(i); break; } - atom.position.w = (geometryType == gtFixedSizeAtoms) ? defaultAtomSize : 0.5f * defaultAtomSize; + atom.position.w = (geometryType == gtFixedSizeAtoms) + ? defaultAtomSize + : 0.5f * defaultAtomSize; } ++i; } if (!found) { - LOG_ERROR("Could not find atomic color for '" << atomCode << "'"); + LOG_ERROR("Could not find atomic color for '" << atomCode + << "'"); } // Radius @@ -527,25 +660,34 @@ vec4f PDBReader::loadAtomsFromFile(const std::string &filename, GPUKernel &cudaK ++i; } if (!found) - LOG_ERROR("Could not find atomic radius for '" << atomCode << "'"); + LOG_ERROR("Could not find atomic radius for '" + << atomCode << "'"); } if (geometryType != gtBackbone || atom.isBackbone) { // Compute molecule size // min - minPos.x = (atom.position.x < minPos.x) ? atom.position.x : minPos.x; - minPos.y = (atom.position.y < minPos.y) ? atom.position.y : minPos.y; - minPos.z = (atom.position.z < minPos.z) ? atom.position.z : minPos.z; + minPos.x = (atom.position.x < minPos.x) ? atom.position.x + : minPos.x; + minPos.y = (atom.position.y < minPos.y) ? atom.position.y + : minPos.y; + minPos.z = (atom.position.z < minPos.z) ? atom.position.z + : minPos.z; // max - maxPos.x = (atom.position.x > maxPos.x) ? atom.position.x : maxPos.x; - maxPos.y = (atom.position.y > maxPos.y) ? atom.position.y : maxPos.y; - maxPos.z = (atom.position.z > maxPos.z) ? atom.position.z : maxPos.z; + maxPos.x = (atom.position.x > maxPos.x) ? atom.position.x + : maxPos.x; + maxPos.y = (atom.position.y > maxPos.y) ? atom.position.y + : maxPos.y; + maxPos.z = (atom.position.z > maxPos.z) ? atom.position.z + : maxPos.z; // add Atom to the list atom.processed = 0; - if (geometryType == gtSticks || (geometryType == gtAtomsAndSticks && atom.residue % 2 == 0)) + if (geometryType == gtSticks || + (geometryType == gtAtomsAndSticks && + atom.residue % 2 == 0)) atoms[atom.id] = atom; else atoms[index] = atom; @@ -560,14 +702,7 @@ vec4f PDBReader::loadAtomsFromFile(const std::string &filename, GPUKernel &cudaK objectSize.y = (maxPos.y - minPos.y); objectSize.z = (maxPos.z - minPos.z); -#ifdef USE_CUDA vec4f center; -#endif - -#ifdef USE_OPENCL - vec4f center; -#endif - center.x = (minPos.x + maxPos.x) / 2.f; center.y = (minPos.y + maxPos.y) / 2.f; center.z = (minPos.z + maxPos.z) / 2.f; @@ -613,7 +748,8 @@ vec4f PDBReader::loadAtomsFromFile(const std::string &filename, GPUKernel &cudaK break; } - if (geometryType == gtSticks || geometryType == gtAtomsAndSticks || geometryType == gtBackbone) + if (geometryType == gtSticks || geometryType == gtAtomsAndSticks || + geometryType == gtBackbone) { std::map::iterator it2 = atoms.begin(); while (it2 != atoms.end()) @@ -626,33 +762,47 @@ vec4f PDBReader::loadAtomsFromFile(const std::string &filename, GPUKernel &cudaK a.x = atom.position.x - atom2.position.x; a.y = atom.position.y - atom2.position.y; a.z = atom.position.z - atom2.position.z; - float distance = sqrtf(a.x * a.x + a.y * a.y + a.z * a.z); - float stickDistance = (geometryType == gtBackbone && atom2.isBackbone) - ? DEFAULT_STICK_DISTANCE * 2.f - : DEFAULT_STICK_DISTANCE; + float distance = + sqrtf(a.x * a.x + a.y * a.y + a.z * a.z); + float stickDistance = + (geometryType == gtBackbone && atom2.isBackbone) + ? DEFAULT_STICK_DISTANCE * 2.f + : DEFAULT_STICK_DISTANCE; if (distance < stickDistance) { vec4f halfCenter; - halfCenter.x = (atom.position.x + atom2.position.x) / 2.f; - halfCenter.y = (atom.position.y + atom2.position.y) / 2.f; - halfCenter.z = (atom.position.z + atom2.position.z) / 2.f; + halfCenter.x = + (atom.position.x + atom2.position.x) / 2.f; + halfCenter.y = + (atom.position.y + atom2.position.y) / 2.f; + halfCenter.z = + (atom.position.z + atom2.position.z) / 2.f; // Sticks nb = cudaKernel.addPrimitive(ptCylinder, true); cudaKernel.setPrimitive( - nb, objectScale.x * distanceRatio * atomDistance * (atom.position.x - center.x), - objectScale.y * distanceRatio * atomDistance * (atom.position.y - center.y), - objectScale.z * distanceRatio * atomDistance * (atom.position.z - center.z), - objectScale.x * distanceRatio * atomDistance * (halfCenter.x - center.x), - objectScale.y * distanceRatio * atomDistance * (halfCenter.y - center.y), - objectScale.z * distanceRatio * atomDistance * (halfCenter.z - center.z), + nb, + objectScale.x * distanceRatio * atomDistance * + (atom.position.x - center.x), + objectScale.y * distanceRatio * atomDistance * + (atom.position.y - center.y), + objectScale.z * distanceRatio * atomDistance * + (atom.position.z - center.z), + objectScale.x * distanceRatio * atomDistance * + (halfCenter.x - center.x), + objectScale.y * distanceRatio * atomDistance * + (halfCenter.y - center.y), + objectScale.z * distanceRatio * atomDistance * + (halfCenter.z - center.z), objectScale.x * stickRadius, 0.f, 0.f, - (geometryType == gtSticks) ? atom.materialId : 1010); + (geometryType == gtSticks) ? atom.materialId + : 1010); const vec2f vt0 = make_vec2f(0.f, 0.f); const vec2f vt1 = make_vec2f(1.f, 1.f); const vec2f vt2 = make_vec2f(0.f, 0.f); - cudaKernel.setPrimitiveTextureCoordinates(nb, vt0, vt1, vt2); + cudaKernel.setPrimitiveTextureCoordinates(nb, vt0, + vt1, vt2); } } it2++; @@ -676,22 +826,33 @@ vec4f PDBReader::loadAtomsFromFile(const std::string &filename, GPUKernel &cudaK const vec2f vt0 = make_vec2f(0.f, 0.f); const vec2f vt1 = make_vec2f(1.f, 1.f); const vec2f vt2 = make_vec2f(0.f, 0.f); - if (geometryType == gtIsoSurface && atom.isBackbone && atom.chainId % 2 == 0) + if (geometryType == gtIsoSurface && atom.isBackbone && + atom.chainId % 2 == 0) { nb = cudaKernel.addPrimitive(ptSphere, true); - cudaKernel.setPrimitive(nb, - objectScale.x * distanceRatio * atomDistance * (atom.position.x - center.x), - objectScale.y * distanceRatio * atomDistance * (atom.position.y - center.y), - objectScale.z * distanceRatio * atomDistance * (atom.position.z - center.z), - objectScale.x * radius * 2.f, 0.f, 0.f, 10); - cudaKernel.setPrimitiveTextureCoordinates(nb, vt0, vt1, vt2); + cudaKernel.setPrimitive( + nb, + objectScale.x * distanceRatio * atomDistance * + (atom.position.x - center.x), + objectScale.y * distanceRatio * atomDistance * + (atom.position.y - center.y), + objectScale.z * distanceRatio * atomDistance * + (atom.position.z - center.z), + objectScale.x * radius * 2.f, 0.f, 0.f, 10); + cudaKernel.setPrimitiveTextureCoordinates(nb, vt0, vt1, + vt2); } nb = cudaKernel.addPrimitive(ptSphere, true); - cudaKernel.setPrimitive(nb, objectScale.x * distanceRatio * atomDistance * (atom.position.x - center.x), - objectScale.y * distanceRatio * atomDistance * (atom.position.y - center.y), - objectScale.z * distanceRatio * atomDistance * (atom.position.z - center.z), - objectScale.x * radius, 0.f, 0.f, m); + cudaKernel.setPrimitive( + nb, + objectScale.x * distanceRatio * atomDistance * + (atom.position.x - center.x), + objectScale.y * distanceRatio * atomDistance * + (atom.position.y - center.y), + objectScale.z * distanceRatio * atomDistance * + (atom.position.z - center.z), + objectScale.x * radius, 0.f, 0.f, m); cudaKernel.setPrimitiveTextureCoordinates(nb, vt0, vt1, vt2); } } @@ -702,7 +863,8 @@ vec4f PDBReader::loadAtomsFromFile(const std::string &filename, GPUKernel &cudaK objectSize.z *= objectScale.z * distanceRatio * atomDistance; LOG_INFO(1, " - Geometry type...: " << geometryType); LOG_INFO(1, " - Number of atoms.: " << atoms.size()); - LOG_INFO(1, " - Object size.....: " << objectSize.x << "," << objectSize.y << "," << objectSize.z); + LOG_INFO(1, " - Object size.....: " << objectSize.x << "," << objectSize.y + << "," << objectSize.z); return objectSize; } -} +} // namespace solr diff --git a/solr/io/PDBReader.h b/solr/io/PDBReader.h index 909df50..0a2570b 100644 --- a/solr/io/PDBReader.h +++ b/solr/io/PDBReader.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once @@ -41,14 +38,18 @@ class SOLR_API PDBReader virtual ~PDBReader(void); public: - vec4f loadAtomsFromFile(const std::string &filename, GPUKernel &cudaKernel, GeometryType geometryType, - const float defaultAtomSize, const float defaultStickSize, const int materialType, - const vec4f scale, const bool useModels = false); + vec4f loadAtomsFromFile(const std::string &filename, GPUKernel &cudaKernel, + GeometryType geometryType, + const float defaultAtomSize, + const float defaultStickSize, + const int materialType, const vec4f scale, + const bool useModels = false); int getNbBoxes() { return m_nbBoxes; } int getNbPrimitives() { return m_nbPrimitives; } + private: int m_nbPrimitives; int m_nbBoxes; }; -} +} // namespace solr diff --git a/solr/io/SWCReader.cpp b/solr/io/SWCReader.cpp index ec59f66..05765c5 100644 --- a/solr/io/SWCReader.cpp +++ b/solr/io/SWCReader.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2017, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include @@ -28,23 +25,22 @@ #include #include -#include "../Consts.h" #include "../Logging.h" +#include "../consts.h" #include "SWCReader.h" namespace solr { -SWCReader::SWCReader() -{ -} +SWCReader::SWCReader() {} -SWCReader::~SWCReader() -{ -} +SWCReader::~SWCReader() {} -CPUBoundingBox SWCReader::loadMorphologyFromFile(const std::string &filename, GPUKernel &kernel, const vec4f &position, - const vec4f &scale, const int materialId) +CPUBoundingBox SWCReader::loadMorphologyFromFile(const std::string &filename, + GPUKernel &kernel, + const vec4f &position, + const vec4f &scale, + const int materialId) { CPUBoundingBox AABB; LOG_INFO(1, "SWC Filename.......: " << filename); @@ -65,19 +61,29 @@ CPUBoundingBox SWCReader::loadMorphologyFromFile(const std::string &filename, GP Morphology morphology; int id = atoi(A.c_str()); morphology.branch = atoi(B.c_str()); - morphology.x = static_cast(scale.x * (position.x + atof(C.c_str()))); - morphology.y = static_cast(scale.y * (position.y + atof(D.c_str()))); - morphology.z = static_cast(scale.z * (position.z + atof(E.c_str()))); - morphology.radius = static_cast(scale.w * atof(F.c_str())); + morphology.x = static_cast( + scale.x * (position.x + atof(C.c_str()))); + morphology.y = static_cast( + scale.y * (position.y + atof(D.c_str()))); + morphology.z = static_cast( + scale.z * (position.z + atof(E.c_str()))); + morphology.radius = + static_cast(scale.w * atof(F.c_str())); morphology.parent = atoi(G.c_str()); m_morphologies[id] = morphology; - AABB.parameters[0].x = std::min(AABB.parameters[0].x, morphology.x); - AABB.parameters[0].y = std::min(AABB.parameters[0].y, morphology.y); - AABB.parameters[0].z = std::min(AABB.parameters[0].z, morphology.z); - AABB.parameters[1].x = std::max(AABB.parameters[1].x, morphology.x); - AABB.parameters[1].y = std::max(AABB.parameters[1].y, morphology.y); - AABB.parameters[1].z = std::max(AABB.parameters[1].z, morphology.z); + AABB.parameters[0].x = + std::min(AABB.parameters[0].x, morphology.x); + AABB.parameters[0].y = + std::min(AABB.parameters[0].y, morphology.y); + AABB.parameters[0].z = + std::min(AABB.parameters[0].z, morphology.z); + AABB.parameters[1].x = + std::max(AABB.parameters[1].x, morphology.x); + AABB.parameters[1].y = + std::max(AABB.parameters[1].y, morphology.y); + AABB.parameters[1].z = + std::max(AABB.parameters[1].z, morphology.z); } } file.close(); @@ -95,7 +101,8 @@ CPUBoundingBox SWCReader::loadMorphologyFromFile(const std::string &filename, GP const vec2f vt2 = make_vec2f(0.f, 0.f); a.primitiveId = kernel.addPrimitive(ptSphere, true); - kernel.setPrimitive(a.primitiveId, a.x, a.y, a.z, a.radius * 1.5f, 0.f, 0.f, materialId); + kernel.setPrimitive(a.primitiveId, a.x, a.y, a.z, a.radius * 1.5f, + 0.f, 0.f, materialId); kernel.setPrimitiveTextureCoordinates(a.primitiveId, vt0, vt1, vt2); } else @@ -110,8 +117,10 @@ CPUBoundingBox SWCReader::loadMorphologyFromFile(const std::string &filename, GP const float ra = a.radius; const float rb = b.radius; b.primitiveId = kernel.addPrimitive(ptCylinder, true); - kernel.setPrimitive(b.primitiveId, a.x, a.y, a.z, b.x, b.y, b.z, ra, 0.f, 0.f, materialId); - kernel.setPrimitiveTextureCoordinates(b.primitiveId, vt0, vt1, vt2); + kernel.setPrimitive(b.primitiveId, a.x, a.y, a.z, b.x, b.y, b.z, + ra, 0.f, 0.f, materialId); + kernel.setPrimitiveTextureCoordinates(b.primitiveId, vt0, vt1, + vt2); const int p = kernel.addPrimitive(ptSphere, true); kernel.setPrimitive(p, b.x, b.y, b.z, rb, 0.f, 0.f, materialId); kernel.setPrimitiveTextureCoordinates(p, vt0, vt1, vt2); @@ -121,9 +130,11 @@ CPUBoundingBox SWCReader::loadMorphologyFromFile(const std::string &filename, GP } LOG_INFO(1, " - Points..........: " << m_morphologies.size()); - LOG_INFO(1, " - Bounding box....: (" << AABB.parameters[0].x << "," << AABB.parameters[0].y << "," - << AABB.parameters[0].z << "),(" << AABB.parameters[1].x << "," - << AABB.parameters[1].y << "," << AABB.parameters[1].z << ")"); + LOG_INFO(1, " - Bounding box....: (" + << AABB.parameters[0].x << "," << AABB.parameters[0].y + << "," << AABB.parameters[0].z << "),(" + << AABB.parameters[1].x << "," << AABB.parameters[1].y + << "," << AABB.parameters[1].z << ")"); return AABB; } -} +} // namespace solr diff --git a/solr/io/SWCReader.h b/solr/io/SWCReader.h index bbdc933..dd911c8 100644 --- a/solr/io/SWCReader.h +++ b/solr/io/SWCReader.h @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once @@ -44,11 +41,15 @@ class SOLR_API SWCReader SWCReader(); ~SWCReader(); - CPUBoundingBox loadMorphologyFromFile(const std::string &filename, GPUKernel &cudaKernel, const vec4f &position, - const vec4f &scale, const int materialId); + CPUBoundingBox loadMorphologyFromFile(const std::string &filename, + GPUKernel &cudaKernel, + const vec4f &position, + const vec4f &scale, + const int materialId); Morphologies getMorphologies() { return m_morphologies; } + private: Morphologies m_morphologies; }; -} +} // namespace solr diff --git a/solr/opengl/rtgl.cpp b/solr/opengl/rtgl.cpp index 3912f37..2571815 100644 --- a/solr/opengl/rtgl.cpp +++ b/solr/opengl/rtgl.cpp @@ -1,21 +1,18 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau - * - * This file is part of Sol-R +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #define _ALLOW_KEYWORD_MACROS @@ -26,9 +23,9 @@ #include #endif -#include "rtgl.h" -#include "types.h" #include "../Logging.h" +#include "rtgl.h" +#include "solr.h" #include #include @@ -66,7 +63,8 @@ void setOpenCLDevice(const int device) void Initialize(const int width, const int height, const char *openCLKernel = 0) { #ifdef USE_OPENCL - LOG_INFO(1, "Intializing Raytracing engine: " << gOpenCLPlatform << "," << gOpenCLDevice); + LOG_INFO(1, "Intializing Raytracing engine: " << gOpenCLPlatform << "," + << gOpenCLDevice); #else LOG_INFO(1, "Intializing Raytracing engine"); #endif // USE_OPENCL @@ -137,18 +135,19 @@ void createRandomMaterials(bool update, bool lightsOnly) float refraction = 0.f; float transparency = 0.f; int textureId = TEXTURE_NONE; - vec4f innerIllumination = make_vec4f(0.f, 40000.f, gSceneInfo.viewDistance); + vec4f innerIllumination = + make_vec4f(0.f, 40000.f, gSceneInfo.viewDistance); bool procedural = false; bool wireframe = false; int wireframeDepth = 0; - float r, g, b, noise; + float r, g, b, gloss; float opacity = gSceneInfo.viewDistance; bool fastTransparency = false; r = 0.5f + (rand() % 255) / 512.f; g = 0.5f + (rand() % 255) / 512.f; b = 0.5f + (rand() % 255) / 512.f; - noise = 0.f; + gloss = 0.f; // if( i>0 && i<100 ) { @@ -169,11 +168,13 @@ void createRandomMaterials(bool update, bool lightsOnly) } int material = update ? i : SingletonKernel::kernel()->addMaterial(); - SingletonKernel::kernel()->setMaterial(material, r, g, b, noise, reflection, refraction, procedural, wireframe, - wireframeDepth, transparency, opacity, textureId, TEXTURE_NONE, - TEXTURE_NONE, TEXTURE_NONE, TEXTURE_NONE, TEXTURE_NONE, TEXTURE_NONE, - specular.x, specular.y, specular.w, innerIllumination.x, - innerIllumination.y, innerIllumination.z, fastTransparency); + SingletonKernel::kernel()->setMaterial( + material, r, g, b, gloss, reflection, refraction, procedural, + wireframe, wireframeDepth, transparency, opacity, textureId, + TEXTURE_NONE, TEXTURE_NONE, TEXTURE_NONE, TEXTURE_NONE, + TEXTURE_NONE, TEXTURE_NONE, specular.x, specular.y, specular.w, + innerIllumination.x, innerIllumination.y, innerIllumination.z, + fastTransparency); } } @@ -196,8 +197,9 @@ void glEnable(GLenum cap) if (!gLighting) { int p = SingletonKernel::kernel()->addPrimitive(ptSphere); - SingletonKernel::kernel()->setPrimitive(p, 20.f * gScale, 20.f * gScale, -20.f * gScale, 0.1f * gScale, - 0.1f * gScale, 0.1f * gScale, DEFAULT_LIGHT_MATERIAL); + SingletonKernel::kernel()->setPrimitive( + p, 20.f * gScale, 20.f * gScale, -20.f * gScale, 0.1f * gScale, + 0.1f * gScale, 0.1f * gScale, DEFAULT_LIGHT_MATERIAL); gLighting = true; LOG_INFO(3, "[OpenGL] Light Added"); } @@ -226,7 +228,8 @@ void glVertex3f(GLfloat x, GLfloat y, GLfloat z) void glVertex3fv(const GLfloat *v) { //::glVertex3f(x,y,z); - SingletonKernel::kernel()->addVertex(v[0] * gScale, v[1] * gScale, v[2] * gScale); + SingletonKernel::kernel()->addVertex(v[0] * gScale, v[1] * gScale, + v[2] * gScale); } void glNormal3f(GLfloat x, GLfloat y, GLfloat z) @@ -272,10 +275,11 @@ void glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) { int m = SingletonKernel::kernel()->getCurrentMaterial(); ++m; - SingletonKernel::kernel()->setMaterial(m, red, green, blue, 0.f, 0.f, 1.2f, false, 0.f, 0, alpha, - gSceneInfo.viewDistance, MATERIAL_NONE, MATERIAL_NONE, MATERIAL_NONE, - MATERIAL_NONE, TEXTURE_NONE, TEXTURE_NONE, TEXTURE_NONE, 1.f, 200.f, - 1000.f, 0.f, 0.f, 0.f, false); + SingletonKernel::kernel()->setMaterial( + m, red, green, blue, 0.f, 0.f, 1.2f, false, 0.f, 0, alpha, + gSceneInfo.viewDistance, MATERIAL_NONE, MATERIAL_NONE, + MATERIAL_NONE, MATERIAL_NONE, TEXTURE_NONE, TEXTURE_NONE, + TEXTURE_NONE, 1.f, 200.f, 1000.f, 0.f, 0.f, 0.f, false); SingletonKernel::kernel()->setCurrentMaterial(m); } } @@ -312,10 +316,12 @@ void glTexEnvf(GLenum target, GLenum pname, GLfloat param) ::glTexEnvf(target, pname, param); } -void glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, - GLenum format, GLenum type, const GLvoid *pixels) +void glTexImage2D(GLenum target, GLint level, GLint internalformat, + GLsizei width, GLsizei height, GLint border, GLenum format, + GLenum type, const GLvoid *pixels) { - ::glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels); + ::glTexImage2D(target, level, internalformat, width, height, border, format, + type, pixels); } /* @@ -470,7 +476,9 @@ void gluSphere(void *, GLfloat radius, GLint, GLint) int p = SingletonKernel::kernel()->addPrimitive(ptSphere); vec3f translation = SingletonKernel::kernel()->getTranslation(); int m = SingletonKernel::kernel()->getCurrentMaterial(); - SingletonKernel::kernel()->setPrimitive(p, translation.x * gScale, translation.y * gScale, translation.z * gScale, + SingletonKernel::kernel()->setPrimitive(p, translation.x * gScale, + translation.y * gScale, + translation.z * gScale, radius * gScale, 0.f, 0.f, m); } @@ -479,8 +487,11 @@ void glutWireSphere(GLdouble radius, GLint, GLint) int p = SingletonKernel::kernel()->addPrimitive(ptSphere); vec3f translation = SingletonKernel::kernel()->getTranslation(); int m = SingletonKernel::kernel()->getCurrentMaterial(); - SingletonKernel::kernel()->setPrimitive(p, translation.x * gScale, translation.y * gScale, translation.z * gScale, - static_cast(radius) * gScale, 0.f, 0.f, m); + SingletonKernel::kernel()->setPrimitive(p, translation.x * gScale, + translation.y * gScale, + translation.z * gScale, + static_cast(radius) * gScale, + 0.f, 0.f, m); } GLUquadricObj *gluNewQuadric(void) @@ -523,7 +534,8 @@ void glBindTexture(GLenum target, GLuint texture) } } -int gluBuild2DMipmaps(GLenum target, GLint components, GLint width, GLint height, GLenum format, GLenum type, +int gluBuild2DMipmaps(GLenum target, GLint components, GLint width, + GLint height, GLenum format, GLenum type, const void *data) { TextureInfo textureInfo; @@ -558,36 +570,23 @@ void glFlush() ::glFlush(); } -void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, - GLenum format, GLenum type, const GLvoid *data); +void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, + GLsizei width, GLsizei height, GLenum format, GLenum type, + const GLvoid *data); -void glPushAttrib(GLbitfield mask) -{ -} +void glPushAttrib(GLbitfield mask) {} -void glPopAttrib() -{ -} +void glPopAttrib() {} -void glTexParameteri(GLenum target, GLenum pname, GLint param) -{ -} +void glTexParameteri(GLenum target, GLenum pname, GLint param) {} -void glBlendFunc(GLenum sfactor, GLenum dfactor) -{ -} +void glBlendFunc(GLenum sfactor, GLenum dfactor) {} -void glMatrixMode(GLenum mode) -{ -} +void glMatrixMode(GLenum mode) {} -void glPushMatrix() -{ -} +void glPushMatrix() {} -void glPopMatrix() -{ -} +void glPopMatrix() {} GLenum glGetError() { @@ -599,7 +598,8 @@ void glVertex2i(GLint x, GLint y) glVertex3f(static_cast(x), static_cast(y), 0.f); } -void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearVal, GLdouble farVal) +void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, + GLdouble nearVal, GLdouble farVal) { SingletonKernel::kernel()->getSceneInfo().cameraType = ctOrthographic; } @@ -616,8 +616,9 @@ void render() { // if no light is defined, I add one int p = SingletonKernel::kernel()->addPrimitive(ptSphere); - SingletonKernel::kernel()->setPrimitive(p, 20.f * gScale, 20.f * gScale, 20.f * gScale, 0.1f * gScale, - 0.1f * gScale, 0.1f * gScale, DEFAULT_LIGHT_MATERIAL); + SingletonKernel::kernel()->setPrimitive( + p, 20.f * gScale, 20.f * gScale, 20.f * gScale, 0.1f * gScale, + 0.1f * gScale, 0.1f * gScale, DEFAULT_LIGHT_MATERIAL); // p = ::SingletonKernel::kernel()->addPrimitive(ptSphere); // ::SingletonKernel::kernel()->setPrimitive(p,0.f,0.f,0.f,0.1f*gScale,0.1f*gScale,0.1f*gScale,0); @@ -637,16 +638,20 @@ void render() void glTranslatef(GLfloat x, GLfloat y, GLfloat z) { - SingletonKernel::kernel()->translate(x * gScale, y * gScale, -z * gScale); // Z is inverted!! + SingletonKernel::kernel()->translate(x * gScale, y * gScale, + -z * gScale); // Z is inverted!! } void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) { - SingletonKernel::kernel()->rotate(angle * x * PI / 180.f, angle * y * PI / 180.f, angle * z * PI / 180.f); + SingletonKernel::kernel()->rotate(angle * x * PI / 180.f, + angle * y * PI / 180.f, + angle * z * PI / 180.f); } -void gluLookAt(GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ, GLdouble centerX, GLdouble centerY, GLdouble centerZ, - GLdouble upX, GLdouble upY, GLdouble upZ) +void gluLookAt(GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ, GLdouble centerX, + GLdouble centerY, GLdouble centerZ, GLdouble upX, GLdouble upY, + GLdouble upZ) { gEye.x = static_cast(eyeX * gScale); gEye.y = static_cast(eyeY * gScale); @@ -656,10 +661,12 @@ void gluLookAt(GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ, GLdouble centerX, GL gDir.z = static_cast(centerZ * gScale); } -void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, - GLenum format, GLenum type, const GLvoid *data) +void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, + GLsizei width, GLsizei height, GLenum format, GLenum type, + const GLvoid *data) { - ::glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, data); + ::glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, + type, data); } void *gluNewNurbsRenderer() @@ -682,11 +689,14 @@ void glutIdleFunc(void (*func)(void)) ::glutIdleFunc(func); } -void gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar) +void gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, + GLdouble zFar) { - gEye.z = -20.f * static_cast(aspect) / tanf(static_cast(fovy)) * gScale; + gEye.z = -20.f * static_cast(aspect) / + tanf(static_cast(fovy)) * gScale; gDir.z = static_cast(gEye.z + zNear * gScale + 5000.f); - gSceneInfo.viewDistance = static_cast(gDir.z + zFar * gScale + 5000.f); + gSceneInfo.viewDistance = + static_cast(gDir.z + zFar * gScale + 5000.f); } void glutSetCursor(int cursor) @@ -699,8 +709,9 @@ void glPointSize(GLfloat size) SingletonKernel::kernel()->setPointSize(size); } -void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *data) +void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, + GLenum format, GLenum type, GLvoid *data) { ::glReadPixels(x, y, width, height, format, type, data); } -} +} // namespace solr diff --git a/solr/opengl/rtgl.h b/solr/opengl/rtgl.h index f97c563..da1ac9f 100644 --- a/solr/opengl/rtgl.h +++ b/solr/opengl/rtgl.h @@ -1,26 +1,23 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau - * - * This file is part of Sol-R +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #pragma once -#include "../DLL_API.h" +#include "../api.h" typedef unsigned int GLenum; typedef unsigned char GLboolean; @@ -582,19 +579,22 @@ void SOLR_API glVertex3fv(const GLfloat *v); void SOLR_API glNormal3f(GLfloat x, GLfloat y, GLfloat z); void SOLR_API glNormal3fv(const GLfloat *v); void SOLR_API glColor3f(GLfloat red, GLfloat green, GLfloat blue); -void SOLR_API glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +void SOLR_API glColor4f(GLfloat red, GLfloat green, GLfloat blue, + GLfloat alpha); void SOLR_API glRasterPos2f(GLfloat x, GLfloat y); void SOLR_API glRasterPos3f(GLfloat x, GLfloat y, GLfloat z); void SOLR_API glTexParameterf(GLenum target, GLenum pname, GLfloat param); void SOLR_API glTexCoord2f(GLfloat s, GLfloat t); void SOLR_API glTexCoord3f(GLfloat x, GLfloat y, GLfloat z); void SOLR_API glTexEnvf(GLenum target, GLenum pname, GLfloat param); -void SOLR_API glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, - GLint border, GLenum format, GLenum type, const GLvoid *pixels); +void SOLR_API glTexImage2D(GLenum target, GLint level, GLint internalformat, + GLsizei width, GLsizei height, GLint border, + GLenum format, GLenum type, const GLvoid *pixels); void SOLR_API gluSphere(void *, GLfloat, GLint, GLint); void SOLR_API glutWireSphere(GLdouble radius, GLint slices, GLint stacks); SOLR_API GLUquadricObj *gluNewQuadric(); -void SOLR_API glClearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); +void SOLR_API glClearColor(GLfloat red, GLfloat green, GLfloat blue, + GLfloat alpha); void SOLR_API glViewport(GLint a, GLint b, GLint width, GLint height); @@ -604,9 +604,11 @@ void SOLR_API glMaterialfv(GLenum face, GLenum pname, const GLfloat *params); // Textures void SOLR_API glGenTextures(GLsizei n, GLuint *textures); void SOLR_API glBindTexture(GLenum target, GLuint texture); -int SOLR_API gluBuild2DMipmaps(GLenum target, GLint components, GLint width, GLint height, GLenum format, GLenum type, +int SOLR_API gluBuild2DMipmaps(GLenum target, GLint components, GLint width, + GLint height, GLenum format, GLenum type, const void *data); -void SOLR_API glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, +void SOLR_API glTexSubImage2D(GLenum target, GLint level, GLint xoffset, + GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *data); void SOLR_API glPushAttrib(GLbitfield mask); void SOLR_API glPopAttrib(); @@ -616,12 +618,14 @@ void SOLR_API glMatrixMode(GLenum mode); void SOLR_API glPushMatrix(); void SOLR_API glPopMatrix(); SOLR_API GLenum glGetError(); -void SOLR_API glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearVal, GLdouble farVal); +void SOLR_API glOrtho(GLdouble left, GLdouble right, GLdouble bottom, + GLdouble top, GLdouble nearVal, GLdouble farVal); void SOLR_API glTranslatef(GLfloat x, GLfloat y, GLfloat z); void SOLR_API glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z); void SOLR_API glPointSize(GLfloat size); -void SOLR_API glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *data); +void SOLR_API glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, + GLenum format, GLenum type, GLvoid *data); // Raytracer specific void SOLR_API setOpenCLPlatform(const int platform); @@ -630,9 +634,11 @@ void SOLR_API glCompactBoxes(); void SOLR_API createRandomMaterials(bool update, bool lightsOnly); void SOLR_API setAngles(GLfloat, GLfloat, GLfloat); void SOLR_API render(); -void SOLR_API gluLookAt(GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ, GLdouble centerX, GLdouble centerY, - GLdouble centerZ, GLdouble upX, GLdouble upY, GLdouble upZ); -void SOLR_API gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar); +void SOLR_API gluLookAt(GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ, + GLdouble centerX, GLdouble centerY, GLdouble centerZ, + GLdouble upX, GLdouble upY, GLdouble upZ); +void SOLR_API gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, + GLdouble zFar); // Glut void SOLR_API glutSpecialFunc(void (*func)(int key, int x, int y)); @@ -826,7 +832,8 @@ void SOLR_API wglSwapIntervalEXT(); * * Steve Baker suggested to make it binary compatible with GLUT: */ -#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__WATCOMC__) +#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || \ + defined(__WATCOMC__) #define GLUT_STROKE_ROMAN ((void *)0x0000) #define GLUT_STROKE_MONO_ROMAN ((void *)0x0001) #define GLUT_BITMAP_9_BY_15 ((void *)0x0002) @@ -910,7 +917,8 @@ void SOLR_API glutMotionFunc(void (*callback)(int, int)); /* * Global callback functions, see freeglut_callbacks.c */ -void SOLR_API glutTimerFunc(unsigned int time, void (*callback)(int), int value); +void SOLR_API glutTimerFunc(unsigned int time, void (*callback)(int), + int value); /* * Menu stuff, see freeglut_menu.c diff --git a/solr/resource.h b/solr/resource.h index 89c7f73..dfe29a8 100644 --- a/solr/resource.h +++ b/solr/resource.h @@ -3,12 +3,12 @@ // Used by RayTracingEngine.rc // Next default values for new objects -// +// #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 101 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1001 -#define _APS_NEXT_SYMED_VALUE 101 +#define _APS_NEXT_RESOURCE_VALUE 101 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/solr/types.h b/solr/solr.h similarity index 58% rename from solr/types.h rename to solr/solr.h index 29c7502..cff6473 100644 --- a/solr/types.h +++ b/solr/solr.h @@ -1,35 +1,34 @@ -/* Copyright (c) 2011-2014, Cyrille Favreau - * All rights reserved. Do not distribute without permission. - * Responsible Author: Cyrille Favreau +/* + * Copyright (c) 2011-2022, Cyrille Favreau * - * This file is part of Sol-R + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. * - * This library is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License version 3.0 as published - * by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - * details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ -#ifndef TYPES_H -#define TYPES_H +#ifndef SOLR_H +#define SOLR_H -#include -#include "Consts.h" -#include +#include "consts.h" +#include "solr_defines.h" #include +#include +namespace solr +{ #ifdef USE_OPENCL #define CL_USE_DEPRECATED_OPENCL_1_2_APIS #ifdef __APPLE__ -#include +#include #else // __APPLE__ #include #endif // __APPLE__ @@ -44,12 +43,33 @@ typedef cl_int3 vec3i; typedef cl_int4 vec4i; typedef cl_int4 PrimitiveXYIdBuffer; -inline vec2i make_vec2i(const int x = 0, const int y = 0) { return{ { x, y } }; } -inline vec3i make_vec3i(const int x = 0, const int y = 0, const int z = 0) { return{ { x, y, z } }; } -inline vec4i make_vec4i(const int x = 0, const int y = 0, const int z = 0, const int w = 0) { return{ { x, y, z, w } }; } -inline vec2f make_vec2f(const float x = 0.f, const float y = 0.f) { return{ { x, y } }; } -inline vec3f make_vec3f(const float x = 0.f, const float y = 0.f, const float z = 0.f) { return{ { x, y, z } }; } -inline vec4f make_vec4f(const float x = 0.f, const float y = 0.f, const float z = 0.f, const float w = 0.f) { return{ {x, y, z, w } }; } +inline vec2i make_vec2i(const int x = 0, const int y = 0) +{ + return {{x, y}}; +} +inline vec3i make_vec3i(const int x = 0, const int y = 0, const int z = 0) +{ + return {{x, y, z}}; +} +inline vec4i make_vec4i(const int x = 0, const int y = 0, const int z = 0, + const int w = 0) +{ + return {{x, y, z, w}}; +} +inline vec2f make_vec2f(const float x = 0.f, const float y = 0.f) +{ + return {{x, y}}; +} +inline vec3f make_vec3f(const float x = 0.f, const float y = 0.f, + const float z = 0.f) +{ + return {{x, y, z}}; +} +inline vec4f make_vec4f(const float x = 0.f, const float y = 0.f, + const float z = 0.f, const float w = 0.f) +{ + return {{x, y, z, w}}; +} #define __ALIGN16__ #else @@ -65,12 +85,33 @@ typedef int3 vec3i; typedef int4 vec4i; typedef int4 PrimitiveXYIdBuffer; -inline vec2i make_vec2i(const int x = 0, const int y = 0) { return{ x, y }; } -inline vec3i make_vec3i(const int x = 0, const int y = 0, const int z = 0) { return{ x, y, z }; } -inline vec4i make_vec4i(const int x = 0, const int y = 0, const int z = 0, const int w = 0) { return{ x, y, z, w }; } -inline vec2f make_vec2f(const float x = 0.f, const float y = 0.f) { return{ x, y}; } -inline vec3f make_vec3f(const float x = 0.f, const float y = 0.f, const float z = 0.f) { return{ x, y, z }; } -inline vec4f make_vec4f(const float x = 0.f, const float y = 0.f, const float z = 0.f, const float w = 0.f) { return{ x, y, z, w }; } +inline vec2i make_vec2i(const int x = 0, const int y = 0) +{ + return {x, y}; +} +inline vec3i make_vec3i(const int x = 0, const int y = 0, const int z = 0) +{ + return {x, y, z}; +} +inline vec4i make_vec4i(const int x = 0, const int y = 0, const int z = 0, + const int w = 0) +{ + return {x, y, z, w}; +} +inline vec2f make_vec2f(const float x = 0.f, const float y = 0.f) +{ + return {x, y}; +} +inline vec3f make_vec3f(const float x = 0.f, const float y = 0.f, + const float z = 0.f) +{ + return {x, y, z}; +} +inline vec4f make_vec4f(const float x = 0.f, const float y = 0.f, + const float z = 0.f, const float w = 0.f) +{ + return {x, y, z, w}; +} #define __ALIGN16__ __align__(16) #endif @@ -83,13 +124,13 @@ typedef std::vector vec2is; typedef std::vector vec3is; typedef std::vector vec4is; +#define _CRT_SECURE_NO_WARNINGS +#define __INLINE__ inline + typedef unsigned char BitmapBuffer; typedef float RandomBuffer; typedef int Lamp; -#define _CRT_SECURE_NO_WARNINGS -#define __INLINE__ inline - struct PostProcessingBuffer { vec4f colorInfo; @@ -139,32 +180,37 @@ enum AtmosphericEffect // Scene information struct __ALIGN16__ SceneInfo { - vec2i size; // Image size - CameraType cameraType; // Camera type( Perspective, Orthographic, Anaglyph, VR, Panoramic, Antialiazed, Volume - // rendering ) - GraphicsLevel graphicsLevel; // Graphics level( No Shading=0, Lambert=1, Specular=2, textured=3, Reflections and + vec2i size; // Image size + CameraType cameraType; // Camera type( Perspective, Orthographic, Anaglyph, + // VR, Panoramic, Antialiazed, Volume rendering ) + GraphicsLevel graphicsLevel; // Graphics level( No Shading=0, Lambert=1, + // Specular=2, textured=3, Reflections and // Refractions=4, Shadows=5) - vec1i nbRayIterations; // Maximum number of ray iterations for current frame - vec1f transparentColor; // Value above which r+g+b color is considered as transparent - vec1f viewDistance; // Maximum viewing distance - vec1f shadowIntensity; // Shadow intensity( off=0, pitch black=1) - vec1f eyeSeparation; // Distance between both eyes (3D stereo) - vec1i renderBoxes; // Activate bounding box rendering - vec1i pathTracingIteration; // Current iteration for current frame - vec1i maxPathTracingIterations; // Maximum number of iterations for current frame - FrameBufferType frameBufferType; // Frame buffer type( RGB or BGR ) - vec1i timestamp; // Timestamp + vec1i nbRayIterations; // Maximum number of ray iterations for current frame + vec1f transparentColor; // Value above which r+g+b color is considered as + // transparent + vec1f viewDistance; // Maximum viewing distance + vec1f shadowIntensity; // Shadow intensity( off=0, pitch black=1) + vec1f eyeSeparation; // Distance between both eyes (3D stereo) + vec1i renderBoxes; // Activate bounding box rendering + vec1i pathTracingIteration; // Current iteration for current frame + vec1i maxPathTracingIterations; // Maximum number of iterations for current + // frame + FrameBufferType frameBufferType; // Frame buffer type( RGB or BGR ) + vec1i timestamp; // Timestamp AtmosphericEffect atmosphericEffect; // Atmospheric effects vec1i doubleSidedTriangles; // Use double-sided triangles vec1i extendedGeometry; // Use extended geometry - AdvancedIllumination advancedIllumination; // Advanced features (Global illumination, random lightning, etc) - vec1i draftMode; // Draft mode when camera in motion - vec1i skyboxRadius; // Skybox sphere radius - vec1i skyboxMaterialId; // Skybox material Id - vec1i gradientBackground; // Gradient background - vec1f geometryEpsilon; // Geometry epsilon - vec1f rayEpsilon; // Ray epsilon - vec4f backgroundColor; // Background color + AdvancedIllumination advancedIllumination; // Advanced features (Global + // illumination, random + // lightning, etc) + vec1i draftMode; // Draft mode when camera in motion + vec1i skyboxRadius; // Skybox sphere radius + vec1i skyboxMaterialId; // Skybox material Id + vec1i gradientBackground; // Gradient background + vec1f geometryEpsilon; // Geometry epsilon + vec1f rayEpsilon; // Ray epsilon + vec4f backgroundColor; // Background color }; // Ray structure @@ -218,15 +264,15 @@ struct __ALIGN16__ Material // y: Power // z: // w: - vec1f reflection; // Reflection rate( No reflection=0 -> Full reflection=1 ) - vec1f refraction; // Refraction index( ex: glass=1.33 ) - vec1f transparency; // Transparency rate( Opaque=0 -> Full transparency=1 ) - vec1f opacity; // Opacity strength - vec4i attributes; // x: Fast transparency( off=0, on=1 ). Fast transparency - // produces no shadows and drops intersections if rays intersects primitive with the same material ID - // y: Procedural textures( off=0, on=1 ) - // z: Wireframe( off=0, on=1 ). Wire frame produces no shading - // w: Wireframe Width + vec1f reflection; // Reflection rate( No reflection=0 -> Full reflection=1 ) + vec1f refraction; // Refraction index( ex: glass=1.33 ) + vec1f transparency; // Transparency rate( Opaque=0 -> Full transparency=1 ) + vec1f opacity; // Opacity strength + vec4i attributes; // x: Fast transparency( off=0, on=1 ). Fast transparency + // produces no shadows and drops intersections if rays intersects primitive + // with the same material ID y: Procedural textures( off=0, on=1 ) z: + // Wireframe( off=0, on=1 ). Wire frame produces no shading w: Wireframe + // Width vec4i textureMapping; // x: U padding // y: V padding // z: Texture ID (Deprecated) @@ -247,7 +293,7 @@ struct __ALIGN16__ Material // y: Transparency map // z: Ambiant Occulusion // w: not used - vec2f mappingOffset; // Texture mapping offsets based on sceneInfo.timestamp + vec2f mappingOffset; // Texture mapping offsets based on sceneInfo.timestamp }; // Bounding Box Structure @@ -256,7 +302,8 @@ struct __ALIGN16__ BoundingBox vec3f parameters[2]; // Bottom-Left and Top-Right corners vec1i nbPrimitives; // Number of primitives in the box vec1i startIndex; // Index of the first primitive in the box - vec2i indexForNextBox; // If no intersection, how many of the following boxes can be skipped? + vec2i indexForNextBox; // If no intersection, how many of the following + // boxes can be skipped? }; typedef std::map BoundingBoxes; @@ -301,10 +348,10 @@ enum TextureType struct __ALIGN16__ TextureInfo { unsigned char *buffer; // Pointer to the texture - vec1i offset; // Offset of the texture in the global texture buffer (the one - // that will be transfered to the GPU) - vec3i size; // Size of the texture - TextureType type; // Texture type (diffuse, normal, bump, etc.) + vec1i offset; // Offset of the texture in the global texture buffer (the one + // that will be transfered to the GPU) + vec3i size; // Size of the texture + TextureType type; // Texture type (diffuse, normal, bump, etc.) }; // Post processing types @@ -328,4 +375,54 @@ struct __ALIGN16__ PostProcessingInfo vec1i param3; // Parameter role depends on post processing type }; -#endif // TYPES_H +// Host data structures +struct CPUPrimitive +{ + bool belongsToModel; + bool movable; + vec3f p0; + vec3f p1; + vec3f p2; + vec3f n0; + vec3f n1; + vec3f n2; + vec3f size; + int type; + int materialId; + vec2f vt0; // Texture coordinates + vec2f vt1; + vec2f vt2; + vec3f speed0; + vec3f speed1; + vec3f speed2; +}; + +struct CPUBoundingBox +{ + vec3f parameters[2]; + vec3f center; + std::vector primitives; + long indexForNextBox; +}; + +typedef std::map BoxContainer; +typedef std::map PrimitiveContainer; +typedef std::map LampContainer; + +// Forward declarations +class GPUKernel; +#ifdef USE_CUDA +class CudaKernel; +#else +#ifdef USE_OPENCL +class OpenCLKernel; +#else +#ifdef USE_CPU +class CPUKernel; +#endif // USE_CPU +#endif // USE_OPENCL +#endif // USE_CUDA + +} // namespace solr + +#endif // SOLR_H