diff --git a/CMake/Dependencies.cmake b/CMake/Dependencies.cmake index ce9087dab7..5a7e7fb5e7 100644 --- a/CMake/Dependencies.cmake +++ b/CMake/Dependencies.cmake @@ -82,6 +82,7 @@ elseif(MYGUI_RENDERSYSTEM EQUAL 7) endif() elseif(MYGUI_RENDERSYSTEM EQUAL 8) # Find OGRE + set(OGRE_SDK "" CACHE PATH "Path to prebuilt OGRE SDK") find_package(OGRE_Old) macro_log_feature(OGRE_FOUND "ogre" "Support for the Ogre render system" "" TRUE "" "") endif() diff --git a/CMake/Packages/FindOGRE_Old.cmake b/CMake/Packages/FindOGRE_Old.cmake index 07f85f201d..2b8f20df63 100644 --- a/CMake/Packages/FindOGRE_Old.cmake +++ b/CMake/Packages/FindOGRE_Old.cmake @@ -1,146 +1,592 @@ -# Find OGRE includes and library +#------------------------------------------------------------------- +# This file is part of the CMake build system for OGRE +# (Object-oriented Graphics Rendering Engine) +# For the latest info, see http://www.ogre3d.org/ # -# This module defines -# OGRE_INCLUDE_DIR -# OGRE_LIBRARIES, the libraries to link against to use OGRE. -# OGRE_LIB_DIR, the location of the libraries -# OGRE_FOUND, If false, do not try to use OGRE +# The contents of this file are placed in the public domain. Feel +# free to make use of it in any way you like. +#------------------------------------------------------------------- + +# - Try to find OGRE +# If you have multiple versions of Ogre installed, use the CMake or +# the environment variable OGRE_HOME to point to the path where the +# desired Ogre version can be found. +# By default this script will look for a dynamic Ogre build. If you +# need to link against static Ogre libraries, set the CMake variable +# OGRE_STATIC to TRUE. +# +# Once done, this will define +# +# OGRE_FOUND - system has OGRE +# OGRE_INCLUDE_DIRS - the OGRE include directories +# OGRE_LIBRARIES - link these to use the OGRE core +# OGRE_BINARY_REL - location of the main Ogre binary (win32 non-static only, release) +# OGRE_BINARY_DBG - location of the main Ogre binaries (win32 non-static only, debug) +# +# Additionally this script searches for the following optional +# parts of the Ogre package: +# Plugin_CgProgramManager, Plugin_ParticleFX, +# RenderSystem_GL, RenderSystem_GL3Plus, +# RenderSystem_GLES, RenderSystem_GLES2, +# RenderSystem_Direct3D9, RenderSystem_Direct3D11 +# Paging, Terrain, Volume, Overlay +# +# For each of these components, the following variables are defined: +# +# OGRE_${COMPONENT}_FOUND - ${COMPONENT} is available +# OGRE_${COMPONENT}_INCLUDE_DIRS - additional include directories for ${COMPONENT} +# OGRE_${COMPONENT}_LIBRARIES - link these to use ${COMPONENT} +# OGRE_${COMPONENT}_BINARY_REL - location of the component binary (win32 non-static only, release) +# OGRE_${COMPONENT}_BINARY_DBG - location of the component binary (win32 non-static only, debug) +# +# Finally, the following variables are defined: +# +# OGRE_PLUGIN_DIR_REL - The directory where the release versions of +# the OGRE plugins are located +# OGRE_PLUGIN_DIR_DBG - The directory where the debug versions of +# the OGRE plugins are located +# OGRE_MEDIA_DIR - The directory where the OGRE sample media is +# located, if available include(FindPkgMacros) +include(PreprocessorUtils) +findpkg_begin(OGRE) + + +# Get path, convert backslashes as ${ENV_${var}} +getenv_path(OGRE_HOME) +getenv_path(OGRE_SDK) +getenv_path(OGRE_SOURCE) +getenv_path(OGRE_BUILD) +getenv_path(OGRE_DEPENDENCIES_DIR) +getenv_path(PROGRAMFILES) + +# Determine whether to search for a dynamic or static build +if (OGRE_STATIC) + set(OGRE_LIB_SUFFIX "Static") +else () + set(OGRE_LIB_SUFFIX "") +endif () + +if(APPLE AND NOT OGRE_STATIC) + set(OGRE_LIBRARY_NAMES "Ogre${OGRE_LIB_SUFFIX}") +else() + set(OGRE_LIBRARY_NAMES "OgreMain${OGRE_LIB_SUFFIX}") +endif() +get_debug_names(OGRE_LIBRARY_NAMES) + +# construct search paths from environmental hints and +# OS specific guesses +if (WIN32) + set(OGRE_PREFIX_GUESSES + ${ENV_PROGRAMFILES}/OGRE + C:/OgreSDK + ) +elseif (UNIX) + set(OGRE_PREFIX_GUESSES + /opt/ogre + /opt/OGRE + /usr/lib${LIB_SUFFIX}/ogre + /usr/lib${LIB_SUFFIX}/OGRE + /usr/local/lib${LIB_SUFFIX}/ogre + /usr/local/lib${LIB_SUFFIX}/OGRE + $ENV{HOME}/ogre + $ENV{HOME}/OGRE + ) + if (APPLE) + set(OGRE_PREFIX_GUESSES + ${CMAKE_CURRENT_SOURCE_DIR}/lib/${CMAKE_BUILD_TYPE} + ${OGRE_PREFIX_GUESSES} + ) + endif () +endif () +set(OGRE_PREFIX_PATH + ${OGRE_HOME} ${OGRE_SDK} ${ENV_OGRE_HOME} ${ENV_OGRE_SDK} + ${OGRE_PREFIX_GUESSES} +) +create_search_paths(OGRE) +# If both OGRE_BUILD and OGRE_SOURCE are set, prepare to find Ogre in a build dir +set(OGRE_PREFIX_SOURCE ${OGRE_SOURCE} ${ENV_OGRE_SOURCE}) +set(OGRE_PREFIX_BUILD ${OGRE_BUILD} ${ENV_OGRE_BUILD}) +set(OGRE_PREFIX_DEPENDENCIES_DIR ${OGRE_DEPENDENCIES_DIR} ${ENV_OGRE_DEPENDENCIES_DIR}) +if (OGRE_PREFIX_SOURCE AND OGRE_PREFIX_BUILD) + foreach(dir ${OGRE_PREFIX_SOURCE}) + set(OGRE_INC_SEARCH_PATH ${dir}/OgreMain/include ${dir}/Dependencies/include ${dir}/iOSDependencies/include ${dir}/AndroidDependencies/include ${OGRE_INC_SEARCH_PATH}) + set(OGRE_LIB_SEARCH_PATH ${dir}/lib ${dir}/Dependencies/lib ${dir}/iOSDependencies/lib ${dir}/AndroidDependencies/lib/${ANDROID_ABI} ${OGRE_LIB_SEARCH_PATH}) + set(OGRE_BIN_SEARCH_PATH ${dir}/Samples/Common/bin ${OGRE_BIN_SEARCH_PATH}) + endforeach(dir) + foreach(dir ${OGRE_PREFIX_BUILD}) + set(OGRE_INC_SEARCH_PATH ${dir}/include ${OGRE_INC_SEARCH_PATH}) + if(APPLE AND NOT OGRE_BUILD_PLATFORM_APPLE_IOS) + set(OGRE_LIB_SEARCH_PATH ${dir}/lib/macosx ${OGRE_LIB_SEARCH_PATH}) + else() + set(OGRE_LIB_SEARCH_PATH ${dir}/lib ${OGRE_LIB_SEARCH_PATH}) + endif() + + if (OGRE_BUILD_PLATFORM_APPLE_IOS) + set(OGRE_LIB_SEARCH_PATH ${dir}/lib/iphoneos ${dir}/lib/iphonesimulator ${OGRE_LIB_SEARCH_PATH}) + endif() + + set(OGRE_BIN_SEARCH_PATH ${dir}/bin ${OGRE_BIN_SEARCH_PATH}) + set(OGRE_BIN_SEARCH_PATH ${dir}/Samples/Common/bin ${OGRE_BIN_SEARCH_PATH}) + + if(APPLE AND NOT OGRE_BUILD_PLATFORM_APPLE_IOS) + set(OGRE_BIN_SEARCH_PATH ${dir}/bin/macosx ${OGRE_BIN_SEARCH_PATH}) + endif() + endforeach(dir) + + if (OGRE_PREFIX_DEPENDENCIES_DIR) + set(OGRE_INC_SEARCH_PATH ${OGRE_PREFIX_DEPENDENCIES_DIR}/include ${OGRE_INC_SEARCH_PATH}) + set(OGRE_LIB_SEARCH_PATH ${OGRE_PREFIX_DEPENDENCIES_DIR}/lib ${OGRE_LIB_SEARCH_PATH}) + set(OGRE_BIN_SEARCH_PATH ${OGRE_PREFIX_DEPENDENCIES_DIR}/bin ${OGRE_BIN_SEARCH_PATH}) + endif() +else() + set(OGRE_PREFIX_SOURCE "NOTFOUND") + set(OGRE_PREFIX_BUILD "NOTFOUND") +endif () + +# redo search if any of the environmental hints changed +set(OGRE_COMPONENTS Paging Terrain Volume Overlay + Plugin_CgProgramManager Plugin_ParticleFX + RenderSystem_Direct3D11 RenderSystem_Direct3D9 RenderSystem_GL RenderSystem_GL3Plus RenderSystem_GLES RenderSystem_GLES2) +set(OGRE_RESET_VARS + OGRE_CONFIG_INCLUDE_DIR OGRE_INCLUDE_DIR + OGRE_FRAMEWORK_INCLUDES OGRE_FRAMEWORK_PATH OGRE_LIBRARY_FWK OGRE_LIBRARY_REL OGRE_LIBRARY_DBG + OGRE_PLUGIN_DIR_DBG OGRE_PLUGIN_DIR_REL OGRE_MEDIA_DIR) +foreach (comp ${OGRE_COMPONENTS}) + set(OGRE_RESET_VARS ${OGRE_RESET_VARS} + OGRE_${comp}_INCLUDE_DIR OGRE_${comp}_LIBRARY_FWK + OGRE_${comp}_LIBRARY_DBG OGRE_${comp}_LIBRARY_REL + ) +endforeach (comp) +set(OGRE_PREFIX_WATCH ${OGRE_PREFIX_PATH} ${OGRE_PREFIX_SOURCE} ${OGRE_PREFIX_BUILD}) +clear_if_changed(OGRE_PREFIX_WATCH ${OGRE_RESET_VARS}) + +if(NOT OGRE_STATIC) + # try to locate Ogre via pkg-config + use_pkgconfig(OGRE_PKGC "OGRE${OGRE_LIB_SUFFIX}") + + # Set the framework search path for OS X + set(OGRE_FRAMEWORK_SEARCH_PATH + ${CMAKE_FRAMEWORK_PATH} + ~/Library/Frameworks + /Library/Frameworks + /System/Library/Frameworks + /Network/Library/Frameworks + ${CMAKE_CURRENT_SOURCE_DIR}/lib/macosx/Release + ${CMAKE_CURRENT_SOURCE_DIR}/lib/macosx/Debug + ${CMAKE_CURRENT_SOURCE_DIR}/lib/${CMAKE_BUILD_TYPE} + ) +else() + set(OGRE_LIBRARY_FWK "") +endif() + +# locate Ogre include files +find_path(OGRE_CONFIG_INCLUDE_DIR NAMES OgreBuildSettings.h HINTS ${OGRE_INC_SEARCH_PATH} ${OGRE_FRAMEWORK_INCLUDES} ${OGRE_PKGC_INCLUDE_DIRS} PATH_SUFFIXES "OGRE") +find_path(OGRE_INCLUDE_DIR NAMES OgreRoot.h HINTS ${OGRE_CONFIG_INCLUDE_DIR} ${OGRE_INC_SEARCH_PATH} ${OGRE_FRAMEWORK_INCLUDES} ${OGRE_PKGC_INCLUDE_DIRS} PATH_SUFFIXES "OGRE") +set(OGRE_INCOMPATIBLE FALSE) + +if (OGRE_INCLUDE_DIR) + if (NOT OGRE_CONFIG_INCLUDE_DIR) + set(OGRE_CONFIG_INCLUDE_DIR ${OGRE_INCLUDE_DIR}) + endif () + # determine Ogre version + file(READ ${OGRE_INCLUDE_DIR}/OgrePrerequisites.h OGRE_TEMP_VERSION_CONTENT) + get_preprocessor_entry(OGRE_TEMP_VERSION_CONTENT OGRE_VERSION_MAJOR OGRE_VERSION_MAJOR) + get_preprocessor_entry(OGRE_TEMP_VERSION_CONTENT OGRE_VERSION_MINOR OGRE_VERSION_MINOR) + get_preprocessor_entry(OGRE_TEMP_VERSION_CONTENT OGRE_VERSION_PATCH OGRE_VERSION_PATCH) + get_preprocessor_entry(OGRE_TEMP_VERSION_CONTENT OGRE_VERSION_NAME OGRE_VERSION_NAME) + set(OGRE_VERSION "${OGRE_VERSION_MAJOR}.${OGRE_VERSION_MINOR}.${OGRE_VERSION_PATCH}") + pkg_message(OGRE "Found Ogre ${OGRE_VERSION_NAME} (${OGRE_VERSION})") + + # determine configuration settings + set(OGRE_CONFIG_HEADERS + ${OGRE_CONFIG_INCLUDE_DIR}/OgreBuildSettings.h + ${OGRE_CONFIG_INCLUDE_DIR}/OgreConfig.h + ) + foreach(CFG_FILE ${OGRE_CONFIG_HEADERS}) + if (EXISTS ${CFG_FILE}) + set(OGRE_CONFIG_HEADER ${CFG_FILE}) + break() + endif() + endforeach() + if (OGRE_CONFIG_HEADER) + file(READ ${OGRE_CONFIG_HEADER} OGRE_TEMP_CONFIG_CONTENT) + has_preprocessor_entry(OGRE_TEMP_CONFIG_CONTENT OGRE_STATIC_LIB OGRE_CONFIG_STATIC) + get_preprocessor_entry(OGRE_TEMP_CONFIG_CONTENT OGRE_THREAD_SUPPORT OGRE_CONFIG_THREADS) + get_preprocessor_entry(OGRE_TEMP_CONFIG_CONTENT OGRE_THREAD_PROVIDER OGRE_CONFIG_THREAD_PROVIDER) + get_preprocessor_entry(OGRE_TEMP_CONFIG_CONTENT OGRE_NO_FREEIMAGE OGRE_CONFIG_FREEIMAGE) + if (OGRE_CONFIG_STATIC AND OGRE_STATIC) + elseif (OGRE_CONFIG_STATIC OR OGRE_STATIC) + pkg_message(OGRE "Build type (static, dynamic) does not match the requested one.") + set(OGRE_INCOMPATIBLE TRUE) + endif () + else () + pkg_message(OGRE "Could not determine Ogre build configuration.") + set(OGRE_INCOMPATIBLE TRUE) + endif () +else () + set(OGRE_INCOMPATIBLE FALSE) +endif () + +find_library(OGRE_LIBRARY_REL NAMES ${OGRE_LIBRARY_NAMES} HINTS ${OGRE_LIB_SEARCH_PATH} ${OGRE_PKGC_LIBRARY_DIRS} ${OGRE_FRAMEWORK_SEARCH_PATH} PATH_SUFFIXES "" "Release" "RelWithDebInfo" "MinSizeRel") +find_library(OGRE_LIBRARY_DBG NAMES ${OGRE_LIBRARY_NAMES_DBG} HINTS ${OGRE_LIB_SEARCH_PATH} ${OGRE_PKGC_LIBRARY_DIRS} ${OGRE_FRAMEWORK_SEARCH_PATH} PATH_SUFFIXES "" "Debug") + +make_library_set(OGRE_LIBRARY) + +if (OGRE_INCOMPATIBLE) + set(OGRE_LIBRARY "NOTFOUND") +endif () + +if("${OGRE_FRAMEWORK_INCLUDES}" STREQUAL NOTFOUND) + unset(OGRE_FRAMEWORK_INCLUDES CACHE) +endif() +set(OGRE_INCLUDE_DIR ${OGRE_CONFIG_INCLUDE_DIR} ${OGRE_INCLUDE_DIR} ${OGRE_FRAMEWORK_INCLUDES}) +list(REMOVE_DUPLICATES OGRE_INCLUDE_DIR) +findpkg_finish(OGRE) +add_parent_dir(OGRE_INCLUDE_DIRS OGRE_INCLUDE_DIR) +if (OGRE_SOURCE) + # If working from source rather than SDK, add samples include + set(OGRE_INCLUDE_DIRS ${OGRE_INCLUDE_DIRS} "${OGRE_SOURCE}/Samples/Common/include") +endif() + +mark_as_advanced(OGRE_CONFIG_INCLUDE_DIR OGRE_MEDIA_DIR OGRE_PLUGIN_DIR_REL OGRE_PLUGIN_DIR_DBG) -# Try to find framework first on Mac OS X -if (APPLE) - find_framework(OGRE) +if (NOT OGRE_FOUND) + return() +endif () + + +# look for required Ogre dependencies in case of static build and/or threading +if (OGRE_STATIC) + set(OGRE_DEPS_FOUND TRUE) + find_package(Cg QUIET) + find_package(DirectX QUIET) + find_package(FreeImage QUIET) + find_package(Freetype QUIET) + find_package(OpenGL QUIET) + find_package(OpenGLES QUIET) + find_package(OpenGLES2 QUIET) + find_package(ZLIB QUIET) + find_package(ZZip QUIET) + if (UNIX AND NOT APPLE AND NOT ANDROID) + find_package(X11 QUIET) + find_library(XAW_LIBRARY NAMES Xaw Xaw7 PATHS ${DEP_LIB_SEARCH_DIR} ${X11_LIB_SEARCH_PATH}) + if (NOT XAW_LIBRARY OR NOT X11_Xt_FOUND) + set(X11_FOUND FALSE) + endif () + endif () + + set(OGRE_LIBRARIES ${OGRE_LIBRARIES} ${ZZip_LIBRARIES} ${ZLIB_LIBRARIES} ${FreeImage_LIBRARIES} ${FREETYPE_LIBRARIES}) + + if (APPLE AND NOT OGRE_BUILD_PLATFORM_APPLE_IOS AND NOT ANDROID) + set(OGRE_LIBRARIES ${OGRE_LIBRARIES} ${X11_LIBRARIES} ${X11_Xt_LIBRARIES} ${XAW_LIBRARY} ${X11_Xrandr_LIB} ${Carbon_LIBRARIES} ${Cocoa_LIBRARIES}) + endif() + + if (NOT ZLIB_FOUND OR NOT ZZip_FOUND) + set(OGRE_DEPS_FOUND FALSE) + endif () + if (NOT FreeImage_FOUND AND NOT OGRE_CONFIG_FREEIMAGE) + set(OGRE_DEPS_FOUND FALSE) + endif () + if (NOT FREETYPE_FOUND) + set(OGRE_DEPS_FOUND FALSE) + endif () + if (UNIX AND NOT APPLE AND NOT ANDROID) + if (NOT X11_FOUND) + set(OGRE_DEPS_FOUND FALSE) + endif () + endif () +endif() + if (OGRE_CONFIG_THREADS) + if (OGRE_CONFIG_THREAD_PROVIDER EQUAL 1) + if (OGRE_STATIC) + set(Boost_USE_STATIC_LIBS TRUE) + if(OGRE_BUILD_PLATFORM_APPLE_IOS) + set(Boost_USE_MULTITHREADED OFF) + endif() + endif() + + set(OGRE_BOOST_COMPONENTS thread date_time) + find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET) + if(Boost_FOUND AND Boost_VERSION GREATER 104900) + if(Boost_VERSION GREATER 105300) + set(OGRE_BOOST_COMPONENTS thread date_time system atomic chrono) + else() + set(OGRE_BOOST_COMPONENTS thread date_time system chrono) + endif() + endif() + + find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET) + if (NOT Boost_THREAD_FOUND) + set(OGRE_DEPS_FOUND FALSE) + else () + set(OGRE_LIBRARIES ${OGRE_LIBRARIES} ${Boost_LIBRARIES}) + set(OGRE_INCLUDE_DIRS ${OGRE_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}) + endif () + elseif (OGRE_CONFIG_THREAD_PROVIDER EQUAL 2) + find_package(POCO QUIET) + if (NOT POCO_FOUND) + set(OGRE_DEPS_FOUND FALSE) + else () + set(OGRE_LIBRARIES ${OGRE_LIBRARIES} ${POCO_LIBRARIES}) + set(OGRE_INCLUDE_DIRS ${OGRE_INCLUDE_DIRS} ${POCO_INCLUDE_DIRS}) + endif () + elseif (OGRE_CONFIG_THREAD_PROVIDER EQUAL 3) + find_package(TBB QUIET) + if (NOT TBB_FOUND) + set(OGRE_DEPS_FOUND FALSE) + else () + set(OGRE_LIBRARIES ${OGRE_LIBRARIES} ${TBB_LIBRARIES}) + set(OGRE_INCLUDE_DIRS ${OGRE_INCLUDE_DIRS} ${TBB_INCLUDE_DIRS}) + endif () + endif () + endif () +if (OGRE_STATIC) + if (NOT OGRE_DEPS_FOUND) + pkg_message(OGRE "Could not find all required dependencies for the Ogre package.") + set(OGRE_FOUND FALSE) + endif () endif () if (NOT OGRE_FOUND) -# Then try everything else - - if (MYGUI_STANDALONE_BUILD) - CMAKE_POLICY(PUSH) - SET(OGRE_INCLUDE_DIR "C:/MYGUIHACK OGRE_HOME MYGUIBRACKETHACK/include" "C:/MYGUIHACK OGRE_SRC MYGUIBRACKETHACK/" "C:/MYGUIHACK OGRE_SRC MYGUIBRACKETHACK/OgreMain/include" "C:/MYGUIHACK OGRE_HOME MYGUIBRACKETHACK/include/OGRE" "C:/MYGUIHACK OGRE_HOME MYGUIBRACKETHACK/boost_1_42" CACHE STRING "") - SET(OGRE_LIBRARIES "debug;OgreMain_d;optimized;OgreMain" CACHE STRING "") - SET(OGRE_LIB_DIR "C:/MYGUIHACK OGRE_HOME MYGUIBRACKETHACK/lib" "C:/MYGUIHACK OGRE_SRC MYGUIBRACKETHACK/lib" "C:/MYGUIHACK OGRE_HOME MYGUIBRACKETHACK/boost_1_42/lib" CACHE STRING "") - SET(OGRE_FOUND TRUE) - CMAKE_POLICY(POP) - else() - - IF (NOT OGRE_SOURCE_DIR) - set(OGRE_SOURCE_DIR "" CACHE PATH "Path to Ogre sources (set it if you don't have OGRE_HOME or OGRE_SRC environment variables)") - ENDIF () - - if (NOT OGRE_BUILD) - set(OGRE_BUILD ${OGRE_SOURCE_DIR} CACHE PATH "Path to Ogre build directory (same as OGRE_SOURCE_DIR by default)") - endif () - - if (NOT ${OGRE_SOURCE_DIR} STREQUAL "") - set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${OGRE_SOURCE_DIR}/CMake ${OGRE_SOURCE_DIR}/CMake/Packages) - endif() + return() +endif () - if (NOT (WIN32 OR APPLE)) - set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} /usr/lib/OGRE/cmake/ /usr/local/lib/OGRE/cmake /usr/share/OGRE/cmake/modules /usr/local/share/OGRE/cmake/modules) - endif() - if (EXISTS ${OGRE_SOURCE_DIR}/CMake) - MESSAGE(STATUS "Original FindOGRE.cmake found in OGRE_SOURCE_DIR, trying to use it") - set (OGRE_HOME ${OGRE_SOURCE_DIR}) - FIND_PACKAGE(OGRE) - else() - FIND_PACKAGE(OGRE) - endif() +get_filename_component(OGRE_LIBRARY_DIR_REL "${OGRE_LIBRARY_REL}" PATH) +get_filename_component(OGRE_LIBRARY_DIR_DBG "${OGRE_LIBRARY_DBG}" PATH) +set(OGRE_LIBRARY_DIRS ${OGRE_LIBRARY_DIR_REL} ${OGRE_LIBRARY_DIR_DBG}) - if (OGRE_FOUND) - MESSAGE(STATUS "Ogre was found with it's own CMake script") - - set(BOOST_ROOT ${BOOST_ROOT} CACHE PATH "Path to Boost (required if Ogre was built with boost)") - FIND_PACKAGE(Boost) - - if (Boost_FOUND) - set (OGRE_INCLUDE_DIR ${OGRE_INCLUDE_DIR} ${Boost_INCLUDE_DIR}) - set (OGRE_LIB_DIR ${OGRE_LIB_DIR} ${Boost_LIBRARY_DIRS} ${BOOST_LIBRARYDIR}) - else() - # trying to get boost from OGRE_SOURCE_DIR - set (OGRE_INCLUDE_DIR ${OGRE_INCLUDE_DIR} ${OGRE_SOURCE_DIR}/boost) - set (OGRE_LIB_DIR ${OGRE_LIB_DIR} ${OGRE_SOURCE_DIR}/boost/lib) - endif() - - #add_definitions("-DBOOST_ALL_NO_LIB") - - return() - endif () - - # now trying to find it by our script - CMAKE_POLICY(PUSH) - - IF (OGRE_LIBRARIES AND OGRE_INCLUDE_DIR) - SET(OGRE_FIND_QUIETLY TRUE) # Already in cache, be silent - ENDIF (OGRE_LIBRARIES AND OGRE_INCLUDE_DIR) - - IF (WIN32) #Windows - MESSAGE(STATUS "Looking for OGRE") - SET(OGRESDK $ENV{OGRE_HOME}) - SET(OGRESOURCE $ENV{OGRE_SRC}) - IF (OGRE_SOURCE_DIR) - MESSAGE(STATUS "Using OGRE built from source (from specified path)") - SET(OGRE_INCLUDE_DIR ${OGRE_SOURCE_DIR}/OgreMain/include ${OGRE_SOURCE_DIR}/include) - SET(OGRE_LIB_DIR ${OGRE_SOURCE_DIR}/lib) - ELSEIF (OGRESDK) - MESSAGE(STATUS "Using OGRE SDK") - STRING(REGEX REPLACE "[\\]" "/" OGRESDK "${OGRESDK}") - SET(OGRE_INCLUDE_DIR ${OGRESDK}/include/OGRE ${OGRESDK}/include) - SET(OGRE_LIB_DIR ${OGRESDK}/lib) - IF (NOT OGRE_SOURCE_DIR) - set(OGRE_SOURCE_DIR $ENV{OGRE_HOME} CACHE PATH "Path to Ogre sources (set it if you don't have OGRE_HOME or OGRE_SRC environment variables)") - ENDIF () - ELSEIF (OGRESOURCE) - MESSAGE(STATUS "Using OGRE built from source") - SET(OGRE_INCLUDE_DIR $ENV{OGRE_SRC}/OgreMain/include ${OGRE_SOURCE_DIR}/include) - SET(OGRE_LIB_DIR $ENV{OGRE_SRC}/lib) - IF (NOT OGRE_SOURCE_DIR) - set(OGRE_SOURCE_DIR $ENV{OGRE_SRC} CACHE PATH "Path to Ogre sources (set it if you don't have OGRE_HOME or OGRE_SRC environment variables)") - ENDIF () - ENDIF () - - IF (OGRESDK OR OGRESOURCE OR OGRE_SOURCE_DIR) - SET(OGRE_LIBRARIES debug OgreMain_d optimized OgreMain) - - SET(OGRE_INCLUDE_DIR ${OGRE_INCLUDE_DIR} CACHE PATH "") - SET(OGRE_LIBRARIES ${OGRE_LIBRARIES} CACHE STRING "") - SET(OGRE_LIB_DIR ${OGRE_LIB_DIR} CACHE PATH "") - ENDIF () - ELSE (WIN32) #Unix - IF (OGRE_SOURCE_DIR) - MESSAGE(STATUS "Using OGRE built from source (from specified path)") - SET(OGRE_INCLUDE_DIR ${OGRE_SOURCE_DIR}/OgreMain/include) - SET(OGRE_LIB_DIR ${OGRE_SOURCE_DIR}/lib) - ELSE () - CMAKE_MINIMUM_REQUIRED(VERSION 2.4.7 FATAL_ERROR) - FIND_PACKAGE(PkgConfig) - PKG_SEARCH_MODULE(OGRE OGRE) - SET(OGRE_INCLUDE_DIR ${OGRE_INCLUDE_DIRS}) - SET(OGRE_LIB_DIR ${OGRE_LIBDIR}) - ENDIF () - - SET(OGRE_INCLUDE_DIR ${OGRE_INCLUDE_DIR} CACHE PATH "") - SET(OGRE_LIBRARIES ${OGRE_LIBRARIES} CACHE STRING "") - SET(OGRE_LIB_DIR ${OGRE_LIB_DIR} CACHE PATH "") - ENDIF (WIN32) - - IF (OGRE_INCLUDE_DIR AND OGRE_LIBRARIES) - SET(OGRE_FOUND TRUE) - ENDIF (OGRE_INCLUDE_DIR AND OGRE_LIBRARIES) - - IF (OGRE_FOUND) - IF (NOT OGRE_FIND_QUIETLY) - MESSAGE(STATUS " libraries : ${OGRE_LIBRARIES} from ${OGRE_LIB_DIR}") - MESSAGE(STATUS " includes : ${OGRE_INCLUDE_DIR}") - ENDIF (NOT OGRE_FIND_QUIETLY) - ELSE (OGRE_FOUND) - IF (OGRE_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "Could not find OGRE") - ENDIF (OGRE_FIND_REQUIRED) - ENDIF (OGRE_FOUND) - CMAKE_POLICY(POP) +# find binaries +if (NOT OGRE_STATIC) + if (WIN32) + find_file(OGRE_BINARY_REL NAMES "OgreMain.dll" HINTS ${OGRE_BIN_SEARCH_PATH} + PATH_SUFFIXES "" Release RelWithDebInfo MinSizeRel) + find_file(OGRE_BINARY_DBG NAMES "OgreMain_d.dll" HINTS ${OGRE_BIN_SEARCH_PATH} + PATH_SUFFIXES "" Debug ) endif() - + mark_as_advanced(OGRE_BINARY_REL OGRE_BINARY_DBG) endif() + + +######################################################### +# Find Ogre components +######################################################### + +set(OGRE_COMPONENT_SEARCH_PATH_REL + ${OGRE_LIBRARY_DIR_REL}/.. + ${OGRE_LIBRARY_DIR_REL}/../.. + ${OGRE_BIN_SEARCH_PATH} +) +set(OGRE_COMPONENT_SEARCH_PATH_DBG + ${OGRE_LIBRARY_DIR_DBG}/.. + ${OGRE_LIBRARY_DIR_DBG}/../.. + ${OGRE_BIN_SEARCH_PATH} +) + +macro(ogre_find_component COMPONENT HEADER PATH_HINTS) + set(OGRE_${COMPONENT}_FIND_QUIETLY ${OGRE_FIND_QUIETLY}) + findpkg_begin(OGRE_${COMPONENT}) + find_path(OGRE_${COMPONENT}_INCLUDE_DIR NAMES ${HEADER} HINTS ${OGRE_INCLUDE_DIRS} ${OGRE_PREFIX_SOURCE} PATH_SUFFIXES ${PATH_HINTS} ${COMPONENT} OGRE/${COMPONENT} ) + set(OGRE_${COMPONENT}_LIBRARY_NAMES "Ogre${COMPONENT}${OGRE_LIB_SUFFIX}") + get_debug_names(OGRE_${COMPONENT}_LIBRARY_NAMES) + find_library(OGRE_${COMPONENT}_LIBRARY_REL NAMES ${OGRE_${COMPONENT}_LIBRARY_NAMES} HINTS ${OGRE_LIBRARY_DIR_REL} ${OGRE_FRAMEWORK_PATH} PATH_SUFFIXES "" "Release" "RelWithDebInfo" "MinSizeRel") + find_library(OGRE_${COMPONENT}_LIBRARY_DBG NAMES ${OGRE_${COMPONENT}_LIBRARY_NAMES_DBG} HINTS ${OGRE_LIBRARY_DIR_DBG} ${OGRE_FRAMEWORK_PATH} PATH_SUFFIXES "" "Debug") + make_library_set(OGRE_${COMPONENT}_LIBRARY) + findpkg_finish(OGRE_${COMPONENT}) + if (OGRE_${COMPONENT}_FOUND) + # find binaries + if (NOT OGRE_STATIC) + if (WIN32) + find_file(OGRE_${COMPONENT}_BINARY_REL NAMES "Ogre${COMPONENT}.dll" HINTS ${OGRE_COMPONENT_SEARCH_PATH_REL} PATH_SUFFIXES "" bin bin/Release bin/RelWithDebInfo bin/MinSizeRel Release) + find_file(OGRE_${COMPONENT}_BINARY_DBG NAMES "Ogre${COMPONENT}_d.dll" HINTS ${OGRE_COMPONENT_SEARCH_PATH_DBG} PATH_SUFFIXES "" bin bin/Debug Debug) + endif() + mark_as_advanced(OGRE_${COMPONENT}_BINARY_REL OGRE_${COMPONENT}_BINARY_DBG) + endif() + endif() + unset(OGRE_${COMPONENT}_FIND_QUIETLY) +endmacro() + +# look for Paging component +ogre_find_component(Paging OgrePaging.h "") +# look for Terrain component +ogre_find_component(Terrain OgreTerrain.h "") +# look for Property component +ogre_find_component(Property OgreProperty.h "") +# look for RTShaderSystem component +ogre_find_component(RTShaderSystem OgreRTShaderSystem.h "") +# look for Volume component +ogre_find_component(Volume OgreVolumePrerequisites.h "") +# look for Overlay component +ogre_find_component(Overlay OgreOverlaySystem.h "") +#look for HlmsPbs component +ogre_find_component(HlmsPbs OgreHlmsPbs.h Hlms/Pbs/) +#look for HlmsPbsMobile component +ogre_find_component(HlmsPbsMobile OgreHlmsPbsMobile.h Hlms/PbsMobile/) +#look for HlmsPbsMobile component +ogre_find_component(HlmsUnlit OgreHlmsUnlit.h Hlms/Unlit) +#look for HlmsUnlit component +ogre_find_component(HlmsUnlitMobile OgreHlmsUnlitMobile.h Hlms/UnlitMobile) + +######################################################### +# Find Ogre plugins +######################################################### +macro(ogre_find_plugin PLUGIN HEADER) + # On Unix, the plugins might have no prefix + if (CMAKE_FIND_LIBRARY_PREFIXES) + set(TMP_CMAKE_LIB_PREFIX ${CMAKE_FIND_LIBRARY_PREFIXES}) + set(CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES} "") + endif() + + # strip RenderSystem_ or Plugin_ prefix from plugin name + string(REPLACE "RenderSystem_" "" PLUGIN_TEMP ${PLUGIN}) + string(REPLACE "Plugin_" "" PLUGIN_NAME ${PLUGIN_TEMP}) + + # header files for plugins are not usually needed, but find them anyway if they are present + set(OGRE_PLUGIN_PATH_SUFFIXES + PlugIns PlugIns/${PLUGIN_NAME} Plugins Plugins/${PLUGIN_NAME} ${PLUGIN} + RenderSystems RenderSystems/${PLUGIN_NAME} ${ARGN}) + find_path(OGRE_${PLUGIN}_INCLUDE_DIR NAMES ${HEADER} + HINTS ${OGRE_INCLUDE_DIRS} ${OGRE_PREFIX_SOURCE} + PATH_SUFFIXES ${OGRE_PLUGIN_PATH_SUFFIXES}) + # find link libraries for plugins + set(OGRE_${PLUGIN}_LIBRARY_NAMES "${PLUGIN}${OGRE_LIB_SUFFIX}") + get_debug_names(OGRE_${PLUGIN}_LIBRARY_NAMES) + set(OGRE_${PLUGIN}_LIBRARY_FWK ${OGRE_LIBRARY_FWK}) + find_library(OGRE_${PLUGIN}_LIBRARY_REL NAMES ${OGRE_${PLUGIN}_LIBRARY_NAMES} + HINTS "${OGRE_BUILD}/lib" ${OGRE_LIBRARY_DIRS} ${OGRE_FRAMEWORK_PATH} PATH_SUFFIXES "" OGRE OGRE-${OGRE_VERSION} opt Release Release/opt RelWithDebInfo RelWithDebInfo/opt MinSizeRel MinSizeRel/opt) + find_library(OGRE_${PLUGIN}_LIBRARY_DBG NAMES ${OGRE_${PLUGIN}_LIBRARY_NAMES_DBG} + HINTS "${OGRE_BUILD}/lib" ${OGRE_LIBRARY_DIRS} ${OGRE_FRAMEWORK_PATH} PATH_SUFFIXES "" OGRE OGRE-${OGRE_VERSION} opt Debug Debug/opt) + make_library_set(OGRE_${PLUGIN}_LIBRARY) + + if (OGRE_${PLUGIN}_LIBRARY OR OGRE_${PLUGIN}_INCLUDE_DIR) + set(OGRE_${PLUGIN}_FOUND TRUE) + if (OGRE_${PLUGIN}_INCLUDE_DIR) + set(OGRE_${PLUGIN}_INCLUDE_DIRS ${OGRE_${PLUGIN}_INCLUDE_DIR}) + endif() + set(OGRE_${PLUGIN}_LIBRARIES ${OGRE_${PLUGIN}_LIBRARY}) + endif () + + mark_as_advanced(OGRE_${PLUGIN}_INCLUDE_DIR OGRE_${PLUGIN}_LIBRARY_REL OGRE_${PLUGIN}_LIBRARY_DBG OGRE_${PLUGIN}_LIBRARY_FWK) + + # look for plugin dirs + if (OGRE_${PLUGIN}_FOUND) + if (NOT OGRE_PLUGIN_DIR_REL OR NOT OGRE_PLUGIN_DIR_DBG) + if (WIN32) + set(OGRE_PLUGIN_SEARCH_PATH_REL + ${OGRE_LIBRARY_DIR_REL}/.. + ${OGRE_LIBRARY_DIR_REL}/../.. + ${OGRE_BIN_SEARCH_PATH} + ) + set(OGRE_PLUGIN_SEARCH_PATH_DBG + ${OGRE_LIBRARY_DIR_DBG}/.. + ${OGRE_LIBRARY_DIR_DBG}/../.. + ${OGRE_BIN_SEARCH_PATH} + ) + find_path(OGRE_PLUGIN_DIR_REL NAMES "${PLUGIN}.dll" HINTS ${OGRE_PLUGIN_SEARCH_PATH_REL} + PATH_SUFFIXES "" bin bin/Release bin/RelWithDebInfo bin/MinSizeRel Release) + find_path(OGRE_PLUGIN_DIR_DBG NAMES "${PLUGIN}_d.dll" HINTS ${OGRE_PLUGIN_SEARCH_PATH_DBG} + PATH_SUFFIXES "" bin bin/Debug Debug) + elseif (UNIX) + get_filename_component(OGRE_PLUGIN_DIR_TMP ${OGRE_${PLUGIN}_LIBRARY_REL} PATH) + set(OGRE_PLUGIN_DIR_REL ${OGRE_PLUGIN_DIR_TMP} CACHE STRING "Ogre plugin dir (release)" FORCE) + get_filename_component(OGRE_PLUGIN_DIR_TMP ${OGRE_${PLUGIN}_LIBRARY_DBG} PATH) + set(OGRE_PLUGIN_DIR_DBG ${OGRE_PLUGIN_DIR_TMP} CACHE STRING "Ogre plugin dir (debug)" FORCE) + endif () + endif () + + # find binaries + if (NOT OGRE_STATIC) + if (WIN32) + find_file(OGRE_${PLUGIN}_REL NAMES "${PLUGIN}.dll" HINTS ${OGRE_PLUGIN_DIR_REL}) + find_file(OGRE_${PLUGIN}_DBG NAMES "${PLUGIN}_d.dll" HINTS ${OGRE_PLUGIN_DIR_DBG}) + endif() + mark_as_advanced(OGRE_${PLUGIN}_REL OGRE_${PLUGIN}_DBG) + endif() + + endif () + + if (TMP_CMAKE_LIB_PREFIX) + set(CMAKE_FIND_LIBRARY_PREFIXES ${TMP_CMAKE_LIB_PREFIX}) + endif () +endmacro(ogre_find_plugin) + +ogre_find_plugin(Plugin_CgProgramManager OgreCgProgram.h PlugIns/CgProgramManager/include) +ogre_find_plugin(Plugin_ParticleFX OgreParticleFXPrerequisites.h PlugIns/ParticleFX/include) +ogre_find_plugin(RenderSystem_GL OgreGLRenderSystem.h RenderSystems/GL/include) +ogre_find_plugin(RenderSystem_GL3Plus OgreGL3PlusRenderSystem.h RenderSystems/GL3Plus/include) +ogre_find_plugin(RenderSystem_GLES OgreGLESRenderSystem.h RenderSystems/GLES/include) +ogre_find_plugin(RenderSystem_GLES2 OgreGLES2RenderSystem.h RenderSystems/GLES2/include) +ogre_find_plugin(RenderSystem_Direct3D9 OgreD3D9RenderSystem.h RenderSystems/Direct3D9/include) +ogre_find_plugin(RenderSystem_Direct3D11 OgreD3D11RenderSystem.h RenderSystems/Direct3D11/include) + +if (OGRE_STATIC) + # check if dependencies for plugins are met + if (NOT DirectX_FOUND) + set(OGRE_RenderSystem_Direct3D9_FOUND FALSE) + endif () + if (NOT DirectX_D3D11_FOUND) + set(OGRE_RenderSystem_Direct3D11_FOUND FALSE) + endif () + if (NOT OPENGL_FOUND) + set(OGRE_RenderSystem_GL_FOUND FALSE) + endif () + if (NOT OPENGL_FOUND) + set(OGRE_RenderSystem_GL3Plus_FOUND FALSE) + endif () + if (NOT OPENGLES_FOUND) + set(OGRE_RenderSystem_GLES_FOUND FALSE) + endif () + if (NOT OPENGLES2_FOUND) + set(OGRE_RenderSystem_GLES2_FOUND FALSE) + endif () + if (NOT Cg_FOUND) + set(OGRE_Plugin_CgProgramManager_FOUND FALSE) + endif () + + set(OGRE_RenderSystem_Direct3D9_LIBRARIES ${OGRE_RenderSystem_Direct3D9_LIBRARIES} + ${DirectX_LIBRARIES} + ) + + set(OGRE_RenderSystem_Direct3D11_LIBRARIES ${OGRE_RenderSystem_Direct3D11_LIBRARIES} + ${DirectX_D3D11_LIBRARIES} + ) + set(OGRE_RenderSystem_GL_LIBRARIES ${OGRE_RenderSystem_GL_LIBRARIES} + ${OPENGL_LIBRARIES} + ) + set(OGRE_RenderSystem_GL3Plus_LIBRARIES ${OGRE_RenderSystem_GL3Plus_LIBRARIES} + ${OPENGL_LIBRARIES} + ) + set(OGRE_RenderSystem_GLES_LIBRARIES ${OGRE_RenderSystem_GLES_LIBRARIES} + ${OPENGLES_LIBRARIES} + ) + set(OGRE_RenderSystem_GLES2_LIBRARIES ${OGRE_RenderSystem_GLES2_LIBRARIES} + ${OPENGLES2_LIBRARIES} + ) + set(OGRE_Plugin_CgProgramManager_LIBRARIES ${OGRE_Plugin_CgProgramManager_LIBRARIES} + ${Cg_LIBRARIES} + ) +endif () + +# look for the media directory +set(OGRE_MEDIA_SEARCH_PATH + ${OGRE_SOURCE} + ${OGRE_LIBRARY_DIR_REL}/.. + ${OGRE_LIBRARY_DIR_DBG}/.. + ${OGRE_LIBRARY_DIR_REL}/../.. + ${OGRE_LIBRARY_DIR_DBG}/../.. + ${OGRE_PREFIX_SOURCE} +) +set(OGRE_MEDIA_SEARCH_SUFFIX + Samples/Media + Media + media + share/OGRE/media + share/OGRE/Media +) + +clear_if_changed(OGRE_PREFIX_WATCH OGRE_MEDIA_DIR) +find_path(OGRE_MEDIA_DIR NAMES packs/cubemapsJS.zip HINTS ${OGRE_MEDIA_SEARCH_PATH} + PATHS ${OGRE_PREFIX_PATH} PATH_SUFFIXES ${OGRE_MEDIA_SEARCH_SUFFIX}) + diff --git a/Common/Base/Ogre2/BaseManager.cpp b/Common/Base/Ogre2/BaseManager.cpp index d632e1edcb..34ccabd5a6 100644 --- a/Common/Base/Ogre2/BaseManager.cpp +++ b/Common/Base/Ogre2/BaseManager.cpp @@ -141,7 +141,7 @@ namespace base light->setDirection(vec); // Load resources - Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); + Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(true); mRoot->addFrameListener(this); Ogre::WindowEventUtilities::addWindowEventListener(mWindow, this); @@ -382,23 +382,33 @@ namespace base void BaseManager::registerHlms() { - Ogre::String shaderSyntax = "/GLSL"; - if (mRoot->getRenderSystem()->getName() == "Direct3D11 Rendering Subsystem") - shaderSyntax = "/HLSL"; + std::string dataFolder = getRootMedia() + "/OgreHlms/"; - Ogre::Archive *archiveCommon = Ogre::ArchiveManager::getSingletonPtr()->load( - getRootMedia() + "/OgreHlms" + "/Common" + shaderSyntax, - "FileSystem", true); - - Ogre::ArchiveVec libraryCommon; - libraryCommon.push_back(archiveCommon); - - Ogre::Archive *archiveUnlit = Ogre::ArchiveManager::getSingletonPtr()->load( - getRootMedia() + "/OgreHlms" + "/Unlit" + shaderSyntax, - "FileSystem", true); + Ogre::ArchiveManager &archiveManager = Ogre::ArchiveManager::getSingleton(); + Ogre::StringVector::const_iterator libraryFolderPathIt; + Ogre::StringVector::const_iterator libraryFolderPathEn; + { + Ogre::String unlitMainFolder; + Ogre::StringVector unlitLibraryFoldersPaths; + Ogre::HlmsUnlit::getDefaultPaths(unlitMainFolder, unlitLibraryFoldersPaths); + + Ogre::Archive *archiveUnlit = archiveManager.load(dataFolder + unlitMainFolder, + "FileSystem", true); + Ogre::ArchiveVec archiveUnlitLibraryFolders; + libraryFolderPathIt = unlitLibraryFoldersPaths.begin(); + libraryFolderPathEn = unlitLibraryFoldersPaths.end(); + while (libraryFolderPathIt != libraryFolderPathEn) + { + Ogre::Archive *archiveLibrary = + archiveManager.load(dataFolder + *libraryFolderPathIt, "FileSystem", true); + archiveUnlitLibraryFolders.push_back(archiveLibrary); + ++libraryFolderPathIt; + } - Ogre::HlmsUnlit *hlmsUnlit = OGRE_NEW Ogre::HlmsUnlit(archiveUnlit, &libraryCommon); - Ogre::Root::getSingleton().getHlmsManager()->registerHlms(hlmsUnlit); + //Create and register the unlit Hlms + Ogre::HlmsUnlit *hlmsUnlit = OGRE_NEW Ogre::HlmsUnlit(archiveUnlit, &archiveUnlitLibraryFolders); + Ogre::Root::getSingleton().getHlmsManager()->registerHlms(hlmsUnlit); + } } bool BaseManager::frameStarted(const Ogre::FrameEvent& evt) diff --git a/Media/OgreHlms/Common/GLSL/CrossPlatformSettings_piece_all.glsl b/Media/OgreHlms/Common/GLSL/CrossPlatformSettings_piece_all.glsl deleted file mode 100644 index 29c0b7a5f1..0000000000 --- a/Media/OgreHlms/Common/GLSL/CrossPlatformSettings_piece_all.glsl +++ /dev/null @@ -1,7 +0,0 @@ -@piece( SetCrossPlatformSettings ) -@property( GL430 )#version 430 core -@end @property( !GL430 ) -#version 330 core -#extension GL_ARB_shading_language_420pack: require -@end -@end diff --git a/Media/OgreHlms/Common/GLSL/Matrix_piece_all.glsl b/Media/OgreHlms/Common/GLSL/Matrix_piece_all.glsl deleted file mode 100644 index 062feded9a..0000000000 --- a/Media/OgreHlms/Common/GLSL/Matrix_piece_all.glsl +++ /dev/null @@ -1,26 +0,0 @@ -@piece( Common_Matrix_DeclUnpackMatrix4x4 ) -mat4 UNPACK_MAT4( samplerBuffer matrixBuf, uint pixelIdx ) -{ - vec4 row0 = texelFetch( matrixBuf, int((pixelIdx) << 2u) ); - vec4 row1 = texelFetch( matrixBuf, int(((pixelIdx) << 2u) + 1u) ); - vec4 row2 = texelFetch( matrixBuf, int(((pixelIdx) << 2u) + 2u) ); - vec4 row3 = texelFetch( matrixBuf, int(((pixelIdx) << 2u) + 3u) ); - return mat4( row0.x, row1.x, row2.x, row3.x, - row0.y, row1.y, row2.y, row3.y, - row0.z, row1.z, row2.z, row3.z, - row0.w, row1.w, row2.w, row3.w ); -} -@end - -@piece( Common_Matrix_DeclUnpackMatrix4x3 ) -mat4x3 UNPACK_MAT4x3( samplerBuffer matrixBuf, uint pixelIdx ) -{ - vec4 row0 = texelFetch( matrixBuf, int((pixelIdx) << 2u) ); - vec4 row1 = texelFetch( matrixBuf, int(((pixelIdx) << 2u) + 1u) ); - vec4 row2 = texelFetch( matrixBuf, int(((pixelIdx) << 2u) + 2u) ); - return mat4x3( row0.x, row1.x, row2.x, - row0.y, row1.y, row2.y, - row0.z, row1.z, row2.z, - row0.w, row1.w, row2.w ); -} -@end diff --git a/Media/OgreHlms/HLMS/Common/Any/Cubemap_piece_all.any b/Media/OgreHlms/HLMS/Common/Any/Cubemap_piece_all.any new file mode 100644 index 0000000000..afa6f78119 --- /dev/null +++ b/Media/OgreHlms/HLMS/Common/Any/Cubemap_piece_all.any @@ -0,0 +1,109 @@ + +//#include "SyntaxHighlightingMisc.h" +@property( parallax_correct_cubemaps ) + +@piece( DeclCubemapProbeStruct ) +struct CubemapProbe +{ + float4 row0_centerX; + float4 row1_centerY; + float4 row2_centerZ; + float4 halfSize; + float4 cubemapPosLS; +}; +@end + +@piece( DeclParallaxLocalCorrect ) +/** Parallax Correct a reflection dir based on an OBB (Oriented Bounding Box) from a cubemap probe. +\param reflDir + Reflection dir, in view space. +\param pos + Position of the object where the reflection is going to reflect, in local space. + Use toProbeLocalSpace to conver to LS. +\param probe + Cubemap's probe +\return + Parallax-Corrected reflection dir, IN LOCAL SPACE (local to probe's). + Unlike the inputs, this vector is LEFT HANDED. +*/ +@property( syntax == metal )inline @end float3 localCorrect( float3 reflDir, float3 posLS, + CubemapProbe probe ) +{ + float3 probeShapeHalfSize = probe.halfSize.xyz; + float3x3 viewSpaceToProbeLocal = float3x3( probe.row0_centerX.xyz, + probe.row1_centerY.xyz, + probe.row2_centerZ.xyz ); + + @property( syntax == hlsl ) + float3 reflDirLS = mul( viewSpaceToProbeLocal, reflDir ); + @end @property( syntax != hlsl ) + float3 reflDirLS = reflDir * viewSpaceToProbeLocal; + @end + + //Find the ray intersection with box plane + float3 invReflDirLS = float3( 1.0, 1.0, 1.0 ) / reflDirLS; + float3 intersectAtMinPlane = ( -probeShapeHalfSize - posLS ) * invReflDirLS; + float3 intersectAtMaxPlane = ( probeShapeHalfSize - posLS ) * invReflDirLS; + //Get the largest intersection values (we are not intersted in negative values) + float3 largestIntersect = max( intersectAtMaxPlane.xyz, intersectAtMinPlane.xyz ); + //Get the closest of all solutions + float distance = min( min( largestIntersect.x, largestIntersect.y ), largestIntersect.z ); + //Get the intersection position + float3 intersectPositionLS = posLS.xyz + reflDirLS.xyz * distance; + //Get corrected vector + float3 localCorrectedVec = intersectPositionLS.xyz - probe.cubemapPosLS.xyz; + + //Make it left-handed. + localCorrectedVec.z = -localCorrectedVec.z; + return localCorrectedVec; +} +/** Converts a position from view space to probe's local space. +\param pos + Position of the object where the reflection is going to reflect, in view space +\return + Position in local space. +*/ +@property( syntax == metal )inline @end float3 toProbeLocalSpace( float3 pos, CubemapProbe probe ) +{ + float3 probeShapeCenterVS = float3( probe.row0_centerX.w, + probe.row1_centerY.w, + probe.row2_centerZ.w ); + + float3x3 viewSpaceToProbeLocal = float3x3( probe.row0_centerX.xyz, + probe.row1_centerY.xyz, + probe.row2_centerZ.xyz ); + float3 posLS = pos - probeShapeCenterVS; + + @property( syntax == hlsl ) + posLS = mul( viewSpaceToProbeLocal, posLS ); + @end @property( syntax != hlsl ) + posLS = posLS * viewSpaceToProbeLocal; + @end + + return posLS; +} + +/// Returns true if position (in local space) is inside the probe. False otherwise +@property( syntax == metal )inline @end bool isInsideProbe( float3 posLS, CubemapProbe probe ) +{ + return !( abs( posLS.x ) > probe.halfSize.x || + abs( posLS.y ) > probe.halfSize.y || + abs( posLS.z ) > probe.halfSize.z ); +} + +/// Returns value in range (-inf; 1]. +/// 1 means being at the center of the probe. +/// 0 means being at the edge of the probe +/// <0 means position is outside the probe. +@property( syntax == metal )inline @end float getProbeFade( float3 posLS, CubemapProbe probe ) +{ + float3 vDiff = ( probe.halfSize.xyz - abs( posLS.xyz ) ) / probe.halfSize.xyz; + return min( min( vDiff.x, vDiff.y ), vDiff.z ); +} +@end + +//float3 main( float3 reflDir : TEXCOORD0, float3 pos : TEXCOORD1 ) : SV_Target0 +//{ +// return localCorrect( reflDir, pos, probe ); +//} +@end diff --git a/Media/OgreHlms/HLMS/Common/Any/ShadowCaster_piece_ps.any b/Media/OgreHlms/HLMS/Common/Any/ShadowCaster_piece_ps.any new file mode 100644 index 0000000000..630292d197 --- /dev/null +++ b/Media/OgreHlms/HLMS/Common/Any/ShadowCaster_piece_ps.any @@ -0,0 +1,40 @@ + +//#include "SyntaxHighlightingMisc.h" + +///-------------------------------------------------------------------------------------- +/// Caster +///-------------------------------------------------------------------------------------- + +@piece( DeclShadowCasterMacros ) + @property( syntax == glsl ) + @property( !hlms_render_depth_only ) + @property( GL3+ ) + #define outDepth outColour + @end + @property( !GL3+ ) + #define outDepth gl_FragColor + @end + @end + @property( hlms_render_depth_only ) + #define outDepth gl_FragDepth + @end + @end + + @property( syntax == hlsl || syntax == metal ) + #define outDepth outPs.colour0 + @end +@end + +@piece( DoShadowCastPS ) + @property( (!hlms_shadow_uses_depth_texture || exponential_shadow_maps) && !hlms_shadowcaster_point ) + outDepth = inPs.depth; + @end + @property( hlms_shadowcaster_point ) + float distanceToCamera = length( inPs.toCameraWS ); + @property( !exponential_shadow_maps ) + outDepth = (distanceToCamera - passBuf.depthRange.x) * passBuf.depthRange.y + inPs.constBias; + @end @property( exponential_shadow_maps ) + outDepth = (distanceToCamera - passBuf.depthRange.x) * passBuf.depthRange.y; + @end + @end +@end diff --git a/Media/OgreHlms/HLMS/Common/Any/ShadowCaster_piece_vs.any b/Media/OgreHlms/HLMS/Common/Any/ShadowCaster_piece_vs.any new file mode 100644 index 0000000000..988098d96e --- /dev/null +++ b/Media/OgreHlms/HLMS/Common/Any/ShadowCaster_piece_vs.any @@ -0,0 +1,51 @@ + +//#include "SyntaxHighlightingMisc.h" + +@property( hlms_shadowcaster ) + @piece( DoShadowCasterVS ) + @property( syntax == glsl ) + float shadowConstantBias = uintBitsToFloat( instance.worldMaterialIdx[drawId].y ); + @end + @property( syntax == hlsl ) + float shadowConstantBias = asfloat( worldMaterialIdx[input.drawId].y ); + @end + @property( syntax == metal ) + float shadowConstantBias = as_type( worldMaterialIdx[drawId].y ); + @end + + @property( !hlms_shadow_uses_depth_texture && !hlms_shadowcaster_point && !exponential_shadow_maps ) + //Linear depth + @property( hlms_shadowcaster_directional ) + outVs.depth = outVs_Position.z + shadowConstantBias * passBuf.depthRange.y * passBuf.depthRange.y; + @end @property( !hlms_shadowcaster_directional ) + outVs.depth = (outVs_Position.z + shadowConstantBias * passBuf.depthRange.y) * passBuf.depthRange.y; + @end + @property( syntax == glsl )outVs.depth = (outVs.depth * 0.5) + 0.5;@end + @end + + @property( hlms_shadowcaster_point ) + outVs.toCameraWS = worldPos.xyz - passBuf.cameraPosWS.xyz; + @property( !exponential_shadow_maps ) + outVs.constBias = shadowConstantBias * passBuf.depthRange.y * passBuf.depthRange.y; + @end + @end + + @property( !exponential_shadow_maps ) + //We can't make the depth buffer linear without Z out in the fragment shader; + //however we can use a cheap approximation ("pseudo linear depth") + //see http://www.yosoygames.com.ar/wp/2014/01/linear-depth-buffer-my-ass/ + @property( hlms_shadowcaster_directional ) + outVs_Position.z = outVs_Position.z + shadowConstantBias * passBuf.depthRange.y * passBuf.depthRange.y; + @end @property( !hlms_shadowcaster_directional ) + outVs_Position.z = (outVs_Position.z + shadowConstantBias * passBuf.depthRange.y) * passBuf.depthRange.y * outVs_Position.w; + @end + @end + + @property( exponential_shadow_maps && !hlms_shadowcaster_point ) + //It's the same as (float4( worldPos.xyz, 1 ) * viewMatrix).z + float linearZ = -(dot( worldPos.xyz, passBuf.viewZRow.xyz ) + passBuf.viewZRow.w); + //linearZ += (shadowConstantBias * passBuf.depthRange.y); + outVs.depth = (linearZ - passBuf.depthRange.x) * passBuf.depthRange.y; + @end + @end +@end diff --git a/Media/OgreHlms/HLMS/Common/GLSL/CrossPlatformSettings_piece_all.glsl b/Media/OgreHlms/HLMS/Common/GLSL/CrossPlatformSettings_piece_all.glsl new file mode 100644 index 0000000000..e22e1c70f9 --- /dev/null +++ b/Media/OgreHlms/HLMS/Common/GLSL/CrossPlatformSettings_piece_all.glsl @@ -0,0 +1,65 @@ +@piece( SetCrossPlatformSettings ) +@property( GL3+ >= 430 )#version 430 core +@end @property( GL3+ < 430 ) +#version 330 core +@end + +@property( GL_ARB_shading_language_420pack ) + #extension GL_ARB_shading_language_420pack: require + #define layout_constbuffer(x) layout( std140, x ) +@end +@property( GL_ARB_texture_buffer_range ) + #define bufferFetch texelFetch +@end + +#define float2 vec2 +#define float3 vec3 +#define float4 vec4 + +#define int2 ivec2 +#define int3 ivec3 +#define int4 ivec4 + +#define uint2 uvec2 +#define uint3 uvec3 +#define uint4 uvec4 + +#define float3x3 mat3 +#define float4x4 mat4 + +#define mul( x, y ) ((x) * (y)) +#define saturate(x) clamp( (x), 0.0, 1.0 ) +#define lerp mix +#define INLINE + +#define outVs_Position gl_Position +#define OGRE_SampleLevel( tex, sampler, uv, lod ) textureLod( tex, uv.xy, lod ) +@end + +@property( !GL_ARB_texture_buffer_range || !GL_ARB_shading_language_420pack ) +@piece( SetCompatibilityLayer ) + @property( !GL_ARB_texture_buffer_range ) + #define samplerBuffer sampler2D + #define isamplerBuffer isampler2D + #define usamplerBuffer usampler2D + vec4 bufferFetch( in sampler2D sampl, in int pixelIdx ) + { + ivec2 pos = ivec2( mod( pixelIdx, 2048 ), int( uint(pixelIdx) >> 11u ) ); + return texelFetch( sampl, pos, 0 ); + } + ivec4 bufferFetch(in isampler2D sampl, in int pixelIdx) + { + ivec2 pos = ivec2( mod( pixelIdx, 2048 ), int( uint(pixelIdx) >> 11u ) ); + return texelFetch( sampl, pos, 0 ); + } + uvec4 bufferFetch( in usampler2D sampl, in int pixelIdx ) + { + ivec2 pos = ivec2( mod( pixelIdx, 2048 ), int( uint(pixelIdx) >> 11u ) ); + return texelFetch( sampl, pos, 0 ); + } + @end + @property( !GL_ARB_shading_language_420pack ) + #define layout_constbuffer(x) layout( std140 ) + @end +@end +@end diff --git a/Media/OgreHlms/HLMS/Common/GLSL/Matrix_piece_all.glsl b/Media/OgreHlms/HLMS/Common/GLSL/Matrix_piece_all.glsl new file mode 100644 index 0000000000..9eda568abc --- /dev/null +++ b/Media/OgreHlms/HLMS/Common/GLSL/Matrix_piece_all.glsl @@ -0,0 +1,53 @@ +@property( GL_ARB_texture_buffer_range ) +@piece( Common_Matrix_DeclUnpackMatrix4x4 ) +mat4 UNPACK_MAT4( samplerBuffer matrixBuf, uint pixelIdx ) +{ + vec4 row0 = texelFetch( matrixBuf, int((pixelIdx) << 2u) ); + vec4 row1 = texelFetch( matrixBuf, int(((pixelIdx) << 2u) + 1u) ); + vec4 row2 = texelFetch( matrixBuf, int(((pixelIdx) << 2u) + 2u) ); + vec4 row3 = texelFetch( matrixBuf, int(((pixelIdx) << 2u) + 3u) ); + return mat4( row0, row1, row2, row3 ); +} +@end + +@piece( Common_Matrix_DeclUnpackMatrix3x4 ) +mat3x4 UNPACK_MAT3x4( samplerBuffer matrixBuf, uint pixelIdx ) +{ + vec4 row0 = texelFetch( matrixBuf, int((pixelIdx) << 2u) ); + vec4 row1 = texelFetch( matrixBuf, int(((pixelIdx) << 2u) + 1u) ); + vec4 row2 = texelFetch( matrixBuf, int(((pixelIdx) << 2u) + 2u) ); + return mat3x4( row0, row1, row2 ); +} +@end +@end + +@property( !GL_ARB_texture_buffer_range ) +@piece( Common_Matrix_DeclUnpackMatrix4x4 ) +mat4 UNPACK_MAT4( in sampler2D matrixBuf, in uint pixelIdx ) +{ + ivec2 pos0 = ivec2(int(((pixelIdx) << 2u) & 2047u), int(((pixelIdx) << 2u) >> 11u)); + ivec2 pos1 = ivec2(int((((pixelIdx) << 2u) + 1u) & 2047u), int((((pixelIdx) << 2u) + 1u) >> 11u)); + ivec2 pos2 = ivec2(int((((pixelIdx) << 2u) + 2u) & 2047u), int((((pixelIdx) << 2u) + 2u) >> 11u)); + ivec2 pos3 = ivec2(int((((pixelIdx) << 2u) + 3u) & 2047u), int((((pixelIdx) << 2u) + 3u) >> 11u)); + vec4 row0 = texelFetch( matrixBuf, pos0, 0 ); + vec4 row1 = texelFetch( matrixBuf, pos1, 0 ); + vec4 row2 = texelFetch( matrixBuf, pos2, 0 ); + vec4 row3 = texelFetch( matrixBuf, pos3, 0 ); + return mat4( row0, row1, row2, row3 ); +} +@end + +@piece( Common_Matrix_DeclUnpackMatrix3x4 ) +mat3x4 UNPACK_MAT3x4( in sampler2D matrixBuf, in uint pixelIdx ) +{ + ivec2 pos0 = ivec2(int(((pixelIdx) << 2u) & 2047u), int(((pixelIdx) << 2u) >> 11u)); + ivec2 pos1 = ivec2(int((((pixelIdx) << 2u) + 1u) & 2047u), int((((pixelIdx) << 2u) + 1u) >> 11u)); + ivec2 pos2 = ivec2(int((((pixelIdx) << 2u) + 2u) & 2047u), int((((pixelIdx) << 2u) + 2u) >> 11u)); + vec4 row0 = texelFetch( matrixBuf, pos0, 0 ); + vec4 row1 = texelFetch( matrixBuf, pos1, 0 ); + vec4 row2 = texelFetch( matrixBuf, pos2, 0 ); + return mat3x4( row0, row1, row2 ); +} +@end +@end + diff --git a/Media/OgreHlms/Common/GLSL/QuaternionCode_piece_all.glsl b/Media/OgreHlms/HLMS/Common/GLSL/QuaternionCode_piece_all.glsl similarity index 100% rename from Media/OgreHlms/Common/GLSL/QuaternionCode_piece_all.glsl rename to Media/OgreHlms/HLMS/Common/GLSL/QuaternionCode_piece_all.glsl diff --git a/Media/OgreHlms/HLMS/Common/GLSL/RenderDepthOnly_piece_ps.glsl b/Media/OgreHlms/HLMS/Common/GLSL/RenderDepthOnly_piece_ps.glsl new file mode 100644 index 0000000000..72c6269a96 --- /dev/null +++ b/Media/OgreHlms/HLMS/Common/GLSL/RenderDepthOnly_piece_ps.glsl @@ -0,0 +1,3 @@ +@property( hlms_render_depth_only && !alpha_test && !hlms_shadows_esm && !macOS) + @set( hlms_disable_stage, 1 ) +@end diff --git a/Media/OgreHlms/HLMS/Common/HLSL/CrossPlatformSettings_piece_all.hlsl b/Media/OgreHlms/HLMS/Common/HLSL/CrossPlatformSettings_piece_all.hlsl new file mode 100644 index 0000000000..2200dffe60 --- /dev/null +++ b/Media/OgreHlms/HLMS/Common/HLSL/CrossPlatformSettings_piece_all.hlsl @@ -0,0 +1,5 @@ +@piece( SetCrossPlatformSettings ) +#define INLINE +#define outVs_Position outVs.gl_Position +#define OGRE_SampleLevel( tex, sampler, uv, lod ) tex.SampleLevel( sampler, uv.xy, lod ) +@end diff --git a/Media/OgreHlms/Common/HLSL/Matrix_piece_all.hlsl b/Media/OgreHlms/HLMS/Common/HLSL/Matrix_piece_all.hlsl similarity index 72% rename from Media/OgreHlms/Common/HLSL/Matrix_piece_all.hlsl rename to Media/OgreHlms/HLMS/Common/HLSL/Matrix_piece_all.hlsl index 41eede8f99..b6aea51168 100644 --- a/Media/OgreHlms/Common/HLSL/Matrix_piece_all.hlsl +++ b/Media/OgreHlms/HLMS/Common/HLSL/Matrix_piece_all.hlsl @@ -6,17 +6,17 @@ float4x4 UNPACK_MAT4( Buffer matrixBuf, uint pixelIdx ) float4 row3 = matrixBuf.Load( int(((pixelIdx) << 2u) + 2u) ); float4 row4 = matrixBuf.Load( int(((pixelIdx) << 2u) + 3u) ); - return float4x4( row1, row2, row3, row4 ); + return transpose( float4x4( row1, row2, row3, row4 ) ); } @end -@piece( Common_Matrix_DeclUnpackMatrix3x4 ) -float3x4 UNPACK_MAT3x4( Buffer matrixBuf, uint pixelIdx ) +@piece( Common_Matrix_DeclUnpackMatrix4x3 ) +float4x3 UNPACK_MAT4x3( Buffer matrixBuf, uint pixelIdx ) { float4 row1 = matrixBuf.Load( int((pixelIdx) << 2u) ); float4 row2 = matrixBuf.Load( int(((pixelIdx) << 2u) + 1u) ); float4 row3 = matrixBuf.Load( int(((pixelIdx) << 2u) + 2u) ); - return float3x4( row1, row2, row3 ); + return transpose( float3x4( row1, row2, row3 ) ); } @end diff --git a/Media/OgreHlms/Common/HLSL/QuaternionCode_piece_all.hlsl b/Media/OgreHlms/HLMS/Common/HLSL/QuaternionCode_piece_all.hlsl similarity index 100% rename from Media/OgreHlms/Common/HLSL/QuaternionCode_piece_all.hlsl rename to Media/OgreHlms/HLMS/Common/HLSL/QuaternionCode_piece_all.hlsl diff --git a/Media/OgreHlms/HLMS/Common/HLSL/RenderDepthOnly_piece_ps.hlsl b/Media/OgreHlms/HLMS/Common/HLSL/RenderDepthOnly_piece_ps.hlsl new file mode 100644 index 0000000000..04d1ecdc0c --- /dev/null +++ b/Media/OgreHlms/HLMS/Common/HLSL/RenderDepthOnly_piece_ps.hlsl @@ -0,0 +1,26 @@ + +@property( !hlms_render_depth_only || (hlms_shadowcaster && (exponential_shadow_maps || hlms_shadowcaster_point)) ) + @piece( output_type )PS_OUTPUT@end +@end @property( !(!hlms_render_depth_only || (hlms_shadowcaster && (exponential_shadow_maps || hlms_shadowcaster_point))) ) + @piece( output_type )void@end +@end + +@property( hlms_render_depth_only && !alpha_test && !hlms_shadows_esm ) + @set( hlms_disable_stage, 1 ) +@end + +@piece( DeclOutputType ) + struct PS_OUTPUT + { + @property( !hlms_shadowcaster ) + float4 colour0 : SV_Target0; + @end @property( hlms_shadowcaster ) + @property( !hlms_render_depth_only ) + float colour0 : SV_Target0; + @end + @property( hlms_render_depth_only ) + float colour0 : SV_Depth; + @end + @end + }; +@end diff --git a/Media/OgreHlms/HLMS/Common/Metal/CrossPlatformSettings_piece_all.metal b/Media/OgreHlms/HLMS/Common/Metal/CrossPlatformSettings_piece_all.metal new file mode 100644 index 0000000000..8d0133b8a2 --- /dev/null +++ b/Media/OgreHlms/HLMS/Common/Metal/CrossPlatformSettings_piece_all.metal @@ -0,0 +1,18 @@ +@piece( SetCrossPlatformSettings ) +#include +using namespace metal; + +struct float1 +{ + float x; + float1() {} + float1( float _x ) : x( _x ) {} +}; + +#define mul( x, y ) ((x) * (y)) +#define lerp mix +#define INLINE inline + +#define outVs_Position outVs.gl_Position +#define OGRE_SampleLevel( tex, sampler, uv, lod ) tex.sample( sampler, float2( uv ), level( lod ) ) +@end diff --git a/Media/OgreHlms/HLMS/Common/Metal/Matrix_piece_all.metal b/Media/OgreHlms/HLMS/Common/Metal/Matrix_piece_all.metal new file mode 100644 index 0000000000..30463e0ac6 --- /dev/null +++ b/Media/OgreHlms/HLMS/Common/Metal/Matrix_piece_all.metal @@ -0,0 +1,27 @@ +@piece( Common_Matrix_DeclUnpackMatrix4x4 ) +inline float4x4 UNPACK_MAT4( device const float4 *matrixBuf, uint pixelIdx ) +{ + float4 row0 = matrixBuf[(pixelIdx << 2u)]; + float4 row1 = matrixBuf[(pixelIdx << 2u) + 1u]; + float4 row2 = matrixBuf[(pixelIdx << 2u) + 2u]; + float4 row3 = matrixBuf[(pixelIdx << 2u) + 3u]; + return float4x4( row0, row1, row2, row3 ); +} +@end + +@piece( Common_Matrix_DeclUnpackMatrix3x4 ) +inline float3x4 UNPACK_MAT3x4( device const float4 *matrixBuf, uint pixelIdx ) +{ + float4 row0 = matrixBuf[(pixelIdx << 2u)]; + float4 row1 = matrixBuf[(pixelIdx << 2u) + 1u]; + float4 row2 = matrixBuf[(pixelIdx << 2u) + 2u]; + return float3x4( row0, row1, row2 ); +} +@end + +@piece( Common_Matrix_Conversions ) +inline float3x3 toMat3x3( float4x4 m ) +{ + return float3x3( m[0].xyz, m[1].xyz, m[2].xyz ); +} +@end diff --git a/Media/OgreHlms/HLMS/Common/Metal/QuaternionCode_piece_all.metal b/Media/OgreHlms/HLMS/Common/Metal/QuaternionCode_piece_all.metal new file mode 100644 index 0000000000..c703afafe4 --- /dev/null +++ b/Media/OgreHlms/HLMS/Common/Metal/QuaternionCode_piece_all.metal @@ -0,0 +1,55 @@ +@piece( DeclQuat_xAxis ) +inline float3 xAxis( float4 qQuat ) +{ + float fTy = 2.0 * qQuat.y; + float fTz = 2.0 * qQuat.z; + float fTwy = fTy * qQuat.w; + float fTwz = fTz * qQuat.w; + float fTxy = fTy * qQuat.x; + float fTxz = fTz * qQuat.x; + float fTyy = fTy * qQuat.y; + float fTzz = fTz * qQuat.z; + + return float3( 1.0-(fTyy+fTzz), fTxy+fTwz, fTxz-fTwy ); +} +@end + +@piece( DeclQuat_yAxis ) +inline float3 yAxis( float4 qQuat ) +{ + float fTx = 2.0 * qQuat.x; + float fTy = 2.0 * qQuat.y; + float fTz = 2.0 * qQuat.z; + float fTwx = fTx * qQuat.w; + float fTwz = fTz * qQuat.w; + float fTxx = fTx * qQuat.x; + float fTxy = fTy * qQuat.x; + float fTyz = fTz * qQuat.y; + float fTzz = fTz * qQuat.z; + + return float3( fTxy-fTwz, 1.0-(fTxx+fTzz), fTyz+fTwx ); +} +@end + +@piece( DeclQuat_zAxis ) +inline float3 zAxis( float4 qQuat ) +{ + float fTx = 2.0 * qQuat.x; + float fTy = 2.0 * qQuat.y; + float fTz = 2.0 * qQuat.z; + float fTwx = fTx * qQuat.w; + float fTwy = fTy * qQuat.w; + float fTxx = fTx * qQuat.x; + float fTxz = fTz * qQuat.x; + float fTyy = fTy * qQuat.y; + float fTyz = fTz * qQuat.y; + + return float3( fTxz+fTwy, fTyz-fTwx, 1.0-(fTxx+fTyy) ); +} +@end + +@piece( DeclQuat_AllAxis ) +@insertpiece( DeclQuat_xAxis ) +@insertpiece( DeclQuat_yAxis ) +@insertpiece( DeclQuat_zAxis ) +@end diff --git a/Media/OgreHlms/HLMS/Common/Metal/RenderDepthOnly_piece_ps.metal b/Media/OgreHlms/HLMS/Common/Metal/RenderDepthOnly_piece_ps.metal new file mode 100644 index 0000000000..05af487571 --- /dev/null +++ b/Media/OgreHlms/HLMS/Common/Metal/RenderDepthOnly_piece_ps.metal @@ -0,0 +1,26 @@ + +@property( !hlms_render_depth_only || (hlms_shadowcaster && (exponential_shadow_maps || hlms_shadowcaster_point)) ) + @piece( output_type )PS_OUTPUT@end +@end @property( !(!hlms_render_depth_only || (hlms_shadowcaster && (exponential_shadow_maps || hlms_shadowcaster_point))) ) + @piece( output_type )void@end +@end + +@property( hlms_render_depth_only && !alpha_test && !hlms_shadows_esm ) + @set( hlms_disable_stage, 1 ) +@end + +@piece( DeclOutputType ) + struct PS_OUTPUT + { + @property( !hlms_shadowcaster ) + float4 colour0 [[ color(0) ]]; + @end @property( hlms_shadowcaster ) + @property( !hlms_render_depth_only ) + float colour0 [[ color(0) ]]; + @end + @property( hlms_render_depth_only ) + float colour0 [[ depth(any) ]]; + @end + @end + }; +@end diff --git a/Media/OgreHlms/HLMS/Unlit/Any/StructsUnlit_piece_all.any b/Media/OgreHlms/HLMS/Unlit/Any/StructsUnlit_piece_all.any new file mode 100644 index 0000000000..fb157390ad --- /dev/null +++ b/Media/OgreHlms/HLMS/Unlit/Any/StructsUnlit_piece_all.any @@ -0,0 +1,19 @@ + +@piece( PassInternalDecl ) + //Vertex shader + float4x4 viewProj[2]; + @property( hlms_global_clip_distances ) + float4 clipPlane0; + @end + @property( hlms_global_clip_distances || exponential_shadow_maps || hlms_shadowcaster_point )float4x4 invViewProj;@end + @property( hlms_shadowcaster ) + @property( exponential_shadow_maps )float4 viewZRow;@end + float4 depthRange; + @property( hlms_shadowcaster_point ) + float4 cameraPosWS; //Camera position in world space + @end + @end + //Pixel Shader + float4 invWindowSize; + @insertpiece( custom_passBuffer ) +@end diff --git a/Media/OgreHlms/Unlit/GLSL/BlendModes_piece_ps.glsl b/Media/OgreHlms/HLMS/Unlit/GLSL/BlendModes_piece_ps.glsl similarity index 57% rename from Media/OgreHlms/Unlit/GLSL/BlendModes_piece_ps.glsl rename to Media/OgreHlms/HLMS/Unlit/GLSL/BlendModes_piece_ps.glsl index 7ea6d8f4f5..f70f16bf77 100644 --- a/Media/OgreHlms/Unlit/GLSL/BlendModes_piece_ps.glsl +++ b/Media/OgreHlms/HLMS/Unlit/GLSL/BlendModes_piece_ps.glsl @@ -1,11 +1,16 @@ +//Reset t to 0 just in case (values are preserved from previous stages) +@pset( t, 0 ) + @piece( NormalNonPremul ) //Normal Non Premultiplied @counter(t) outColour.xyz = mix( outColour.xyz, topImage@value(t).xyz, topImage@value(t).a ); + outColour.w = mix( outColour.w, 1.0, topImage@value(t).w ); @end @piece( NormalPremul ) //Normal Premultiplied @counter(t) outColour.xyz = (1.0 - topImage@value(t).a) * outColour.xyz + topImage@value(t).xyz; + outColour.w = mix( outColour.w, 1.0, topImage@value(t).w ); @end @piece( Add ) @@ -94,20 +99,39 @@ @sub( diffuse_map@n_idx, diffuse_map@n, 1 ) @end @piece( diffuseIdx0 )material.indices0_3.x & 0x0000FFFFu@end -@piece( diffuseIdx1 )material.indices0_3.y >> 16u@end -@piece( diffuseIdx2 )material.indices0_3.z & 0x0000FFFFu@end -@piece( diffuseIdx3 )material.indices0_3.w >> 16u@end -@piece( diffuseIdx4 )material.indices4_7.x & 0x0000FFFFu@end -@piece( diffuseIdx5 )material.indices4_7.y >> 16u@end -@piece( diffuseIdx6 )material.indices4_7.z & 0x0000FFFFu@end -@piece( diffuseIdx7 )material.indices4_7.w >> 16u@end +@piece( diffuseIdx1 )material.indices0_3.x >> 16u@end +@piece( diffuseIdx2 )material.indices0_3.y & 0x0000FFFFu@end +@piece( diffuseIdx3 )material.indices0_3.y >> 16u@end +@piece( diffuseIdx4 )material.indices0_3.z & 0x0000FFFFu@end +@piece( diffuseIdx5 )material.indices0_3.z >> 16u@end +@piece( diffuseIdx6 )material.indices0_3.w & 0x0000FFFFu@end +@piece( diffuseIdx7 )material.indices0_3.w >> 16u@end @foreach( diffuse_map, n ) - @property( diffuse_map@n_array ) - @piece( SamplerOrigin@n )textureMapsArray[@value(diffuse_map@n_idx)]@end - @piece( SamplerUV@n )vec3( inPs.uv@value( uv_diffuse@n ).@insertpiece( uv_diffuse_swizzle@n ), @insertpiece( diffuseIdx@n ) )@end - @end @property( !diffuse_map@n_array ) - @piece( SamplerOrigin@n )textureMaps[@value(diffuse_map@n_idx)]@end - @piece( SamplerUV@n )inPs.uv@value( uv_diffuse@n ).@insertpiece( uv_diffuse_swizzle@n )@end - @end + @property( diffuse_map@n_array ) + @piece( SamplerOrigin@n )textureMapsArray[@value(diffuse_map@n_idx)]@end + @end @property( !diffuse_map@n_array ) + @piece( SamplerOrigin@n )textureMaps[@value(diffuse_map@n_idx)]@end + @end + @property( !diffuse_map@n_reflection ) + @property( diffuse_map@n_array ) + @piece( SamplerUV@n )vec3( inPs.uv@value( uv_diffuse@n ).@insertpiece( uv_diffuse_swizzle@n ), @insertpiece( diffuseIdx@n ) )@end + @end @property( !diffuse_map@n_array ) + @piece( SamplerUV@n )inPs.uv@value( uv_diffuse@n ).@insertpiece( uv_diffuse_swizzle@n )@end + @end + @end @property( diffuse_map@n_reflection ) + @property( !hlms_forwardplus_flipY ) + @property( diffuse_map@n_array ) + @piece( SamplerUV@n )vec3( gl_FragCoord.x * passBuf.invWindowSize.x, 1.0 - gl_FragCoord.y * passBuf.invWindowSize.y, @insertpiece( diffuseIdx@n ) )@end + @end @property( !diffuse_map@n_array ) + @piece( SamplerUV@n )vec2( gl_FragCoord.x * passBuf.invWindowSize.x, 1.0 - gl_FragCoord.y * passBuf.invWindowSize.y )@end + @end + @end @property( hlms_forwardplus_flipY ) + @property( diffuse_map@n_array ) + @piece( SamplerUV@n )vec3( gl_FragCoord.xy * passBuf.invWindowSize.xy, @insertpiece( diffuseIdx@n ) )@end + @end @property( !diffuse_map@n_array ) + @piece( SamplerUV@n )vec2( gl_FragCoord.xy * passBuf.invWindowSize.xy )@end + @end + @end + @end @end diff --git a/Media/OgreHlms/Unlit/GLSL/PixelShader_ps.glsl b/Media/OgreHlms/HLMS/Unlit/GLSL/PixelShader_ps.glsl similarity index 81% rename from Media/OgreHlms/Unlit/GLSL/PixelShader_ps.glsl rename to Media/OgreHlms/HLMS/Unlit/GLSL/PixelShader_ps.glsl index 0982cbe1ad..dcc83832c2 100644 --- a/Media/OgreHlms/Unlit/GLSL/PixelShader_ps.glsl +++ b/Media/OgreHlms/HLMS/Unlit/GLSL/PixelShader_ps.glsl @@ -1,8 +1,13 @@ @insertpiece( SetCrossPlatformSettings ) +@insertpiece( SetCompatibilityLayer ) layout(std140) uniform; #define FRAG_COLOR 0 +@property( hlms_vpos ) +in vec4 gl_FragCoord; +@end + @property( !hlms_shadowcaster ) layout(location = FRAG_COLOR, index = 0) out vec4 outColour; @end @property( hlms_shadowcaster ) @@ -10,16 +15,21 @@ layout(location = FRAG_COLOR, index = 0) out float outColour; @end // START UNIFORM DECLARATION +@property( has_planar_reflections ) + @insertpiece( PassDecl ) +@end @property( !hlms_shadowcaster ) @insertpiece( MaterialDecl ) @insertpiece( InstanceDecl ) @end @insertpiece( custom_ps_uniformDeclaration ) // END UNIFORM DECLARATION +@property( !hlms_shadowcaster || !hlms_shadow_uses_depth_texture || exponential_shadow_maps ) in block { @insertpiece( VStoPS_block ) } inPs; +@end @property( !hlms_shadowcaster ) @property( num_array_textures )uniform sampler2DArray textureMapsArray[@value( num_array_textures )];@end @@ -33,7 +43,7 @@ void main() { @insertpiece( custom_ps_preExecution ) @property( diffuse_map || alpha_test || diffuse ) - uint materialId = instance.materialIdx[inPs.drawId].x; + uint materialId = instance.worldMaterialIdx[inPs.drawId].x; material = materialArray.m[materialId]; @end @insertpiece( custom_ps_posMaterialLoad ) @@ -68,10 +78,20 @@ void main() } @end @property( hlms_shadowcaster ) + @property( hlms_render_depth_only && !macOS) + @set( hlms_disable_stage, 1 ) + @end + +@insertpiece( DeclShadowCasterMacros ) + +@property( hlms_shadowcaster_point ) + @insertpiece( PassDecl ) +@end + void main() { @insertpiece( custom_ps_preExecution ) - outColour = inPs.depth; + @insertpiece( DoShadowCastPS ) @insertpiece( custom_ps_posExecution ) } @end diff --git a/Media/OgreHlms/Unlit/GLSL/Structs_piece_vs_piece_ps.glsl b/Media/OgreHlms/HLMS/Unlit/GLSL/Structs_piece_vs_piece_ps.glsl similarity index 50% rename from Media/OgreHlms/Unlit/GLSL/Structs_piece_vs_piece_ps.glsl rename to Media/OgreHlms/HLMS/Unlit/GLSL/Structs_piece_vs_piece_ps.glsl index f8f227e491..bc96e1a13b 100644 --- a/Media/OgreHlms/Unlit/GLSL/Structs_piece_vs_piece_ps.glsl +++ b/Media/OgreHlms/HLMS/Unlit/GLSL/Structs_piece_vs_piece_ps.glsl @@ -1,13 +1,9 @@ -@property( hlms_shadowcaster ) @piece( PassDecl ) //Uniforms that change per pass -layout(binding = 0) uniform PassBuffer +layout_constbuffer(binding = 0) uniform PassBuffer { - //Vertex shader - vec2 depthRange; - @insertpiece( custom_passBuffer ) -} pass; -@end + @insertpiece( PassInternalDecl ) +} passBuf; @end @piece( MaterialDecl ) @@ -18,18 +14,20 @@ struct Material uvec4 indices0_3; uvec4 indices4_7; + + @insertpiece( custom_materialBuffer ) }; -layout(binding = 1) uniform MaterialBuf +layout_constbuffer(binding = 1) uniform MaterialBuf { - Material m[@insertpiece( materials_per_buffer )]; + Material m[@value( materials_per_buffer )]; } materialArray; @end @piece( InstanceDecl ) //Uniforms that change per Item/Entity -layout(binding = 2) uniform InstanceBuffer +layout_constbuffer(binding = 2) uniform InstanceBuffer { //.x = //Contains the material's start index. @@ -38,7 +36,11 @@ layout(binding = 2) uniform InstanceBuffer //shadowConstantBias. Send the bias directly to avoid an //unnecessary indirection during the shadow mapping pass. //Must be loaded with uintBitsToFloat - uvec4 materialIdx[4096]; + // + //.z = + //Contains 0 or 1 to index into passBuf.viewProj[]. Only used + //if hlms_identity_viewproj_dynamic is set. + uvec4 worldMaterialIdx[4096]; } instance; @end @@ -49,6 +51,16 @@ layout(binding = 2) uniform InstanceBuffer @foreach( out_uv_half_count, n ) vec@value( out_uv_half_count@n ) uv@n;@end @end - @property( hlms_shadowcaster ) float depth;@end + @property( hlms_shadowcaster ) + @property( (!hlms_shadow_uses_depth_texture || exponential_shadow_maps) && !hlms_shadowcaster_point ) + float depth; + @end + @property( hlms_shadowcaster_point ) + vec3 toCameraWS; + @property( !exponential_shadow_maps ) + flat float constBias; + @end + @end + @end @insertpiece( custom_VStoPS ) @end diff --git a/Media/OgreHlms/HLMS/Unlit/GLSL/VertexShader_vs.glsl b/Media/OgreHlms/HLMS/Unlit/GLSL/VertexShader_vs.glsl new file mode 100644 index 0000000000..7a26302b66 --- /dev/null +++ b/Media/OgreHlms/HLMS/Unlit/GLSL/VertexShader_vs.glsl @@ -0,0 +1,107 @@ +@insertpiece( SetCrossPlatformSettings ) +@insertpiece( SetCompatibilityLayer ) + +out gl_PerVertex +{ + vec4 gl_Position; +@property( hlms_global_clip_distances ) + float gl_ClipDistance[1]; +@end +}; + +layout(std140) uniform; + +@insertpiece( Common_Matrix_DeclUnpackMatrix4x4 ) + +in vec4 vertex; +@property( hlms_colour )in vec4 colour;@end + +@foreach( hlms_uv_count, n ) +in vec@value( hlms_uv_count@n ) uv@n;@end + +@property( GL_ARB_base_instance ) + in uint drawId; +@end + +@insertpiece( custom_vs_attributes ) + +@property( !hlms_shadowcaster || !hlms_shadow_uses_depth_texture || exponential_shadow_maps ) +out block +{ +@insertpiece( VStoPS_block ) +} outVs; +@end + +// START UNIFORM DECLARATION +@insertpiece( PassDecl ) +@insertpiece( InstanceDecl ) +/*layout(binding = 0) */uniform samplerBuffer worldMatBuf; +@property( texture_matrix )/*layout(binding = 1) */uniform samplerBuffer animationMatrixBuf;@end +@insertpiece( custom_vs_uniformDeclaration ) +@property( !GL_ARB_base_instance )uniform uint baseInstance;@end +// END UNIFORM DECLARATION + +@property( !hlms_identity_world ) + @piece( worldViewProj )worldViewProj@end +@end @property( hlms_identity_world ) + @property( !hlms_identity_viewproj_dynamic ) + @piece( worldViewProj )passBuf.viewProj[@value(hlms_identity_viewproj)]@end + @end @property( hlms_identity_viewproj_dynamic ) + @piece( worldViewProj )passBuf.viewProj[instance.worldMaterialIdx[drawId].z]@end + @end +@end + +void main() +{ +@property( !GL_ARB_base_instance ) + uint drawId = baseInstance + uint( gl_InstanceID ); +@end + + @insertpiece( custom_vs_preExecution ) + @property( !hlms_identity_world ) + mat4 worldViewProj; + worldViewProj = UNPACK_MAT4( worldMatBuf, drawId ); + @end + +@property( !hlms_dual_paraboloid_mapping ) + gl_Position = vertex * @insertpiece( worldViewProj ); +@end + +@property( hlms_dual_paraboloid_mapping ) + //Dual Paraboloid Mapping + gl_Position.w = 1.0f; + gl_Position.xyz = (vertex * @insertpiece( worldViewProj )).xyz; + float L = length( gl_Position.xyz ); + gl_Position.z += 1.0f; + gl_Position.xy /= gl_Position.z; + gl_Position.z = (L - NearPlane) / (FarPlane - NearPlane); +@end + +@property( !hlms_shadowcaster ) +@property( hlms_colour ) outVs.colour = colour;@end + +@property( texture_matrix ) mat4 textureMatrix;@end + +@foreach( out_uv_count, n ) + @property( out_uv@n_texture_matrix ) + textureMatrix = UNPACK_MAT4( animationMatrixBuf, (instance.worldMaterialIdx[drawId].x << 4u) + @value( out_uv@n_tex_unit )u ); + outVs.uv@value( out_uv@n_out_uv ).@insertpiece( out_uv@n_swizzle ) = (vec4( uv@value( out_uv@n_source_uv ).xy, 0, 1 ) * textureMatrix).xy; + @end @property( !out_uv@n_texture_matrix ) + outVs.uv@value( out_uv@n_out_uv ).@insertpiece( out_uv@n_swizzle ) = uv@value( out_uv@n_source_uv ).xy; + @end @end + + outVs.drawId = drawId; + +@end + + @property( hlms_global_clip_distances || (hlms_shadowcaster && (exponential_shadow_maps || hlms_shadowcaster_point)) ) + float3 worldPos = (gl_Position * passBuf.invViewProj).xyz; + @end + @insertpiece( DoShadowCasterVS ) + +@property( hlms_global_clip_distances ) + gl_ClipDistance[0] = dot( float4( worldPos.xyz, 1.0 ), passBuf.clipPlane0.xyzw ); +@end + + @insertpiece( custom_vs_posExecution ) +} diff --git a/Media/OgreHlms/HLMS/Unlit/HLSL/BlendModes_piece_ps.hlsl b/Media/OgreHlms/HLMS/Unlit/HLSL/BlendModes_piece_ps.hlsl new file mode 100644 index 0000000000..95c8126e1f --- /dev/null +++ b/Media/OgreHlms/HLMS/Unlit/HLSL/BlendModes_piece_ps.hlsl @@ -0,0 +1,132 @@ +//Reset t to 0 just in case (values are preserved from previous stages) +@pset( t, 0 ) + +@piece( NormalNonPremul ) + //Normal Non Premultiplied @counter(t) + outPs.colour0.xyz = lerp( outPs.colour0.xyz, topImage@value(t).xyz, topImage@value(t).a ); + outPs.colour0.w = lerp( outPs.colour0.w, 1.0, topImage@value(t).w ); +@end + +@piece( NormalPremul ) + //Normal Premultiplied @counter(t) + outPs.colour0.xyz = (1.0 - topImage@value(t).a) * outPs.colour0.xyz + topImage@value(t).xyz; + outPs.colour0.w = lerp( outPs.colour0.w, 1.0, topImage@value(t).w ); +@end + +@piece( Add ) + //Add @counter(t) + outPs.colour0.xyz = lerp( outPs.colour0.xyz, + min( outPs.colour0.xyz + topImage@value(t).xyz, float3(1.0) ), + topImage@value(t).a ); +@end + +@piece( Subtract ) + //Subtract @counter(t) + outPs.colour0.xyz = lerp( outPs.colour0.xyz, + max( outPs.colour0.xyz - topImage@value(t).xyz, float3(0.0) ), + topImage@value(t).a ); +@end + +@piece( Multiply ) + //Multiply @counter(t) + outPs.colour0.xyz = lerp( outPs.colour0.xyz, + outPs.colour0.xyz * topImage@value(t).xyz, + topImage@value(t).a ); +@end + +@piece( Multiply2x ) + //Multiply2x @counter(t) + outPs.colour0.xyz = lerp( outPs.colour0.xyz, + min( outPs.colour0.xyz * topImage@value(t).xyz * 2.0, float3(1.0) ), + topImage@value(t).a ); +@end + +@piece( Screen ) + //Screen @counter(t) + outPs.colour0.xyz = lerp( outPs.colour0.xyz, + 1.0 - (1.0 - outPs.colour0.xyz) * (1.0 - topImage@value(t).xyz), + topImage@value(t).a ); +@end + +@piece( Overlay ) + //Overlay @counter(t) + outPs.colour0.xyz = lerp( outPs.colour0.xyz, + outPs.colour0.xyz * ( outPs.colour0.xyz + 2.0 * topImage@value(t).xyz * (1.0 - outPs.colour0.xyz) ), + topImage@value(t).a ); +@end + +@piece( Lighten ) + //Lighten @counter(t) + outPs.colour0.xyz = lerp( outPs.colour0.xyz, + max( outPs.colour0.xyz, topImage@value(t).xyz ), + topImage@value(t).a ); +@end + +@piece( Darken ) + //Darken @counter(t) + outPs.colour0.xyz = lerp( outPs.colour0.xyz, + min( outPs.colour0.xyz, topImage@value(t).xyz ), + topImage@value(t).a ); +@end + +@piece( GrainExtract ) + //GrainExtract @counter(t) + outPs.colour0.xyz = lerp( outPs.colour0.xyz, + (outPs.colour0.xyz - topImage@value(t).xyz) + 0.5f, + topImage@value(t).a ); +@end + +@piece( GrainMerge ) + //GrainMerge @counter(t) + outPs.colour0.xyz = lerp( outPs.colour0.xyz, + (outPs.colour0.xyz + topImage@value(t).xyz) - 0.5f, + topImage@value(t).a ); +@end + +@piece( Difference ) + //Difference @counter(t) + outPs.colour0.xyz = lerp( outPs.colour0.xyz, + abs(outPs.colour0.xyz - topImage@value(t).xyz), + topImage@value(t).a ); +@end + +@foreach( 16, n ) +@property( uv_atlas@n ) @piece( atlasOffset@n )* atlasOffsets[@n].z + atlasOffsets[@n].xy @end @end @end + +// Get the indexes to the textureMaps[] array using template code. We had to add 1 +// to the actual value otherwise property( diffuse_map ) fails when the index is 0 +@foreach( diffuse_map, n ) + @sub( diffuse_map@n_idx, diffuse_map@n, 1 ) @end + +@piece( diffuseIdx0 )material.indices0_3.x & 0x0000FFFFu@end +@piece( diffuseIdx1 )material.indices0_3.x >> 16u@end +@piece( diffuseIdx2 )material.indices0_3.y & 0x0000FFFFu@end +@piece( diffuseIdx3 )material.indices0_3.y >> 16u@end +@piece( diffuseIdx4 )material.indices0_3.z & 0x0000FFFFu@end +@piece( diffuseIdx5 )material.indices0_3.z >> 16u@end +@piece( diffuseIdx6 )material.indices0_3.w & 0x0000FFFFu@end +@piece( diffuseIdx7 )material.indices0_3.w >> 16u@end + +@foreach( diffuse_map, n ) + @property( !diffuse_map@n_reflection ) + @property( diffuse_map@n_array ) + @piece( TextureOrigin@n )textureMapsArray@value(diffuse_map@n_idx)@end + @piece( SamplerOrigin@n )samplerState@value(diffuse_map@n_idx)@end + @piece( SamplerUV@n )float3( inPs.uv@value( uv_diffuse@n ).@insertpiece( uv_diffuse_swizzle@n ), @insertpiece( diffuseIdx@n ) )@end + @end @property( !diffuse_map@n_array ) + @piece( TextureOrigin@n )textureMaps@value(diffuse_map@n_idx)@end + @piece( SamplerOrigin@n )samplerState@value(diffuse_map@n_idx)@end + @piece( SamplerUV@n )inPs.uv@value( uv_diffuse@n ).@insertpiece( uv_diffuse_swizzle@n )@end + @end + @end @property( diffuse_map@n_reflection ) + @property( diffuse_map@n_array ) + @piece( TextureOrigin@n )textureMapsArray@value(diffuse_map@n_idx)@end + @piece( SamplerOrigin@n )samplerState@value(diffuse_map@n_idx)@end + @piece( SamplerUV@n )float3( gl_FragCoord.xy * passBuf.invWindowSize.xy, @insertpiece( diffuseIdx@n ) )@end + @end @property( !diffuse_map@n_array ) + @piece( TextureOrigin@n )textureMaps@value(diffuse_map@n_idx)@end + @piece( SamplerOrigin@n )samplerState@value(diffuse_map@n_idx)@end + @piece( SamplerUV@n )gl_FragCoord.xy * passBuf.invWindowSize.xy@end + @end + @end +@end diff --git a/Media/OgreHlms/Unlit/HLSL/PixelShader_ps.hlsl b/Media/OgreHlms/HLMS/Unlit/HLSL/PixelShader_ps.hlsl similarity index 57% rename from Media/OgreHlms/Unlit/HLSL/PixelShader_ps.hlsl rename to Media/OgreHlms/HLMS/Unlit/HLSL/PixelShader_ps.hlsl index 3068cb4b7a..6b30465642 100644 --- a/Media/OgreHlms/Unlit/HLSL/PixelShader_ps.hlsl +++ b/Media/OgreHlms/HLMS/Unlit/HLSL/PixelShader_ps.hlsl @@ -1,6 +1,9 @@ @insertpiece( SetCrossPlatformSettings ) // START UNIFORM DECLARATION +@property( has_planar_reflections ) + @insertpiece( PassDecl ) +@end @property( !hlms_shadowcaster ) @insertpiece( MaterialDecl ) @insertpiece( InstanceDecl ) @@ -27,29 +30,32 @@ SamplerState samplerState@n : register(s@counter(samplerStateBind));@end @property( diffuse )@piece( MultiplyDiffuseConst )* material.diffuse@end @end -float4 main( PS_INPUT inPs ) : SV_Target0 +@insertpiece( DeclOutputType ) + +@insertpiece( output_type ) main( PS_INPUT inPs +@property( hlms_vpos ), float4 gl_FragCoord : SV_Position@end ) { + PS_OUTPUT outPs; @insertpiece( custom_ps_preExecution ) @property( diffuse_map || alpha_test || diffuse )Material material;@end - float4 outColour; @property( diffuse_map || alpha_test || diffuse ) - uint materialId = materialIdx[inPs.drawId].x; + uint materialId = worldMaterialIdx[inPs.drawId].x; material = materialArray[materialId]; @end @insertpiece( custom_ps_posMaterialLoad ) @property( !diffuse_map && !diffuse_map0 ) -@property( hlms_colour && !diffuse_map ) outColour = inPs.colour @insertpiece( MultiplyDiffuseConst );@end -@property( !hlms_colour && !diffuse ) outColour = float4(1, 1, 1, 1);@end -@property( !hlms_colour && diffuse ) outColour = material.diffuse;@end +@property( hlms_colour && !diffuse_map ) outPs.colour0 = inPs.colour @insertpiece( MultiplyDiffuseConst );@end +@property( !hlms_colour && !diffuse ) outPs.colour0 = float4(1, 1, 1, 1);@end +@property( !hlms_colour && diffuse ) outPs.colour0 = material.diffuse;@end @end @property( diffuse_map )@property( diffuse_map0 ) //Load base image - outColour = @insertpiece( TextureOrigin0 ).Sample( @insertpiece( SamplerOrigin0 ), @insertpiece( SamplerUV0 ) ).@insertpiece(diffuse_map0_tex_swizzle);@end + outPs.colour0 = @insertpiece( TextureOrigin0 ).Sample( @insertpiece( SamplerOrigin0 ), @insertpiece( SamplerUV0 ) ).@insertpiece(diffuse_map0_tex_swizzle);@end @foreach( diffuse_map, n, 1 )@property( diffuse_map@n ) float4 topImage@n = @insertpiece( TextureOrigin@n ).Sample( @insertpiece( SamplerOrigin@n ), @insertpiece( SamplerUV@n ) ).@insertpiece(diffuse_map@n_tex_swizzle);@end @end @@ -57,25 +63,40 @@ float4 main( PS_INPUT inPs ) : SV_Target0 @foreach( diffuse_map, n, 1 )@property( diffuse_map@n ) @insertpiece( blend_mode_idx@n )@end @end - @property( hlms_colour )outColour *= inPs.colour @insertpiece( MultiplyDiffuseConst );@end - @property( !hlms_colour && diffuse )outColour *= material.diffuse;@end + @property( hlms_colour )outPs.colour0 *= inPs.colour @insertpiece( MultiplyDiffuseConst );@end + @property( !hlms_colour && diffuse )outPs.colour0 *= material.diffuse;@end @end @insertpiece( custom_ps_preLights ) @property( alpha_test ) - if( material.alpha_test_threshold.x @insertpiece( alpha_test_cmp_func ) outColour.a ) + if( material.alpha_test_threshold.x @insertpiece( alpha_test_cmp_func ) outPs.colour0.a ) discard;@end @insertpiece( custom_ps_posExecution ) - return outColour; +@property( !hlms_render_depth_only ) + return outPs; +@end } @end @property( hlms_shadowcaster ) -float main( PS_INPUT inPs ) : SV_Target0 + @property( hlms_render_depth_only ) + @set( hlms_disable_stage, 1 ) + @end +@insertpiece( DeclShadowCasterMacros ) + +@property( hlms_shadowcaster_point ) + @insertpiece( PassDecl ) +@end + +@insertpiece( DeclOutputType ) +@insertpiece( output_type ) main( PS_INPUT inPs +@property( hlms_vpos ), float4 gl_FragCoord : SV_Position@end ) { + PS_OUTPUT outPs; @insertpiece( custom_ps_preExecution ) + @insertpiece( DoShadowCastPS ) @insertpiece( custom_ps_posExecution ) - return inPs.depth; + return outPs; } @end diff --git a/Media/OgreHlms/Unlit/HLSL/Structs_piece_vs_piece_ps.hlsl b/Media/OgreHlms/HLMS/Unlit/HLSL/Structs_piece_vs_piece_ps.hlsl similarity index 57% rename from Media/OgreHlms/Unlit/HLSL/Structs_piece_vs_piece_ps.hlsl rename to Media/OgreHlms/HLMS/Unlit/HLSL/Structs_piece_vs_piece_ps.hlsl index 08275cff29..e3e12f9294 100644 --- a/Media/OgreHlms/Unlit/HLSL/Structs_piece_vs_piece_ps.hlsl +++ b/Media/OgreHlms/HLMS/Unlit/HLSL/Structs_piece_vs_piece_ps.hlsl @@ -1,17 +1,13 @@ -@property( hlms_shadowcaster ) @piece( PassDecl ) //Uniforms that change per pass cbuffer PassBuffer : register(b0) { struct PassData { - //Vertex shader - float2 depthRange; - @insertpiece( custom_passBuffer ) + @insertpiece( PassInternalDecl ) } passBuf; }; @end -@end @piece( MaterialDecl ) struct Material @@ -21,11 +17,13 @@ struct Material uint4 indices0_3; uint4 indices4_7; + + @insertpiece( custom_materialBuffer ) }; cbuffer materialArray : register(b1) { - Material materialArray[@insertpiece( materials_per_buffer )]; + Material materialArray[@value( materials_per_buffer )]; }; @end @@ -41,7 +39,15 @@ cbuffer instance : register(b2) //shadowConstantBias. Send the bias directly to avoid an //unnecessary indirection during the shadow mapping pass. //Must be loaded with uintBitsToFloat - uint4 materialIdx[4096]; + // + //.z = + //Contains 0 or 1 to index into passBuf.viewProj[]. Only used + //if hlms_identity_viewproj_dynamic is set. + @property( fast_shader_build_hack ) + uint4 worldMaterialIdx[2]; + @end @property( !fast_shader_build_hack ) + uint4 worldMaterialIdx[4096]; + @end }; @end @@ -55,6 +61,16 @@ cbuffer instance : register(b2) @foreach( out_uv_half_count, n ) float@value( out_uv_half_count@n ) uv@n : TEXCOORD@counter(texcoord);@end @end - @property( hlms_shadowcaster ) float depth : TEXCOORD@counter(texcoord);@end + @property( hlms_shadowcaster ) + @property( (!hlms_shadow_uses_depth_texture || exponential_shadow_maps) && !hlms_shadowcaster_point ) + float depth : TEXCOORD@counter(texcoord); + @end + @property( hlms_shadowcaster_point ) + float3 toCameraWS : TEXCOORD@counter(texcoord); + @property( !exponential_shadow_maps ) + nointerpolation float constBias : TEXCOORD@counter(texcoord); + @end + @end + @end @insertpiece( custom_VStoPS ) @end diff --git a/Media/OgreHlms/HLMS/Unlit/HLSL/VertexShader_vs.hlsl b/Media/OgreHlms/HLMS/Unlit/HLSL/VertexShader_vs.hlsl new file mode 100644 index 0000000000..ba15f12043 --- /dev/null +++ b/Media/OgreHlms/HLMS/Unlit/HLSL/VertexShader_vs.hlsl @@ -0,0 +1,95 @@ +@insertpiece( SetCrossPlatformSettings ) + +@insertpiece( Common_Matrix_DeclUnpackMatrix4x4 ) + +// START UNIFORM DECLARATION +@insertpiece( PassDecl ) +@insertpiece( InstanceDecl ) +Buffer worldMatBuf : register(t0); +@property( texture_matrix )Buffer animationMatrixBuf : register(t1);@end +@insertpiece( custom_vs_uniformDeclaration ) +// END UNIFORM DECLARATION + +struct VS_INPUT +{ + float4 vertex : POSITION; +@property( hlms_colour ) float4 colour : COLOR0;@end +@foreach( hlms_uv_count, n ) + float@value( hlms_uv_count@n ) uv@n : TEXCOORD@n;@end + uint drawId : DRAWID; + @insertpiece( custom_vs_attributes ) +}; + +struct PS_INPUT +{ +@insertpiece( VStoPS_block ) + float4 gl_Position : SV_Position; +@property( hlms_global_clip_distances ) + float gl_ClipDistance0 : SV_ClipDistance0; +@end +}; + +@property( !hlms_identity_world ) + @piece( worldViewProj )worldViewProj@end +@end @property( hlms_identity_world ) + @property( !hlms_identity_viewproj_dynamic ) + @piece( worldViewProj )passBuf.viewProj[@value(hlms_identity_viewproj)]@end + @end @property( hlms_identity_viewproj_dynamic ) + @piece( worldViewProj )passBuf.viewProj[worldMaterialIdx[input.drawId].z]@end + @end +@end + +PS_INPUT main( VS_INPUT input ) +{ + PS_INPUT outVs; + @insertpiece( custom_vs_preExecution ) + + @property( !hlms_identity_world ) + float4x4 worldViewProj; + worldViewProj = UNPACK_MAT4( worldMatBuf, input.drawId ); + @end + +@property( !hlms_dual_paraboloid_mapping ) + outVs.gl_Position = mul( input.vertex, @insertpiece( worldViewProj ) ); +@end + +@property( hlms_dual_paraboloid_mapping ) + //Dual Paraboloid Mapping + outVs.gl_Position.w = 1.0f; + outVs.gl_Position.xyz = mul( input.vertex, @insertpiece( worldViewProj ) ).xyz; + float L = length( outVs.gl_Position.xyz ); + outVs.gl_Position.z += 1.0f; + outVs.gl_Position.xy /= outVs.gl_Position.z; + outVs.gl_Position.z = (L - NearPlane) / (FarPlane - NearPlane); +@end + +@property( !hlms_shadowcaster ) +@property( hlms_colour ) outVs.colour = input.colour;@end + +@property( texture_matrix ) float4x4 textureMatrix;@end + +@foreach( out_uv_count, n ) + @property( out_uv@n_texture_matrix ) + textureMatrix = UNPACK_MAT4( animationMatrixBuf, (worldMaterialIdx[input.drawId].x << 4u) + @value( out_uv@n_tex_unit ) ); + outVs.uv@value( out_uv@n_out_uv ).@insertpiece( out_uv@n_swizzle ) = mul( float4( input.uv@value( out_uv@n_source_uv ).xy, 0, 1 ), textureMatrix ).xy; + @end @property( !out_uv@n_texture_matrix ) + outVs.uv@value( out_uv@n_out_uv ).@insertpiece( out_uv@n_swizzle ) = input.uv@value( out_uv@n_source_uv ).xy; + @end @end + + outVs.drawId = input.drawId; + +@end + + @property( hlms_global_clip_distances || (hlms_shadowcaster && (exponential_shadow_maps || hlms_shadowcaster_point)) ) + float3 worldPos = mul(outVs.gl_Position, passBuf.invViewProj).xyz; + @end + @insertpiece( DoShadowCasterVS ) + +@property( hlms_global_clip_distances ) + outVs.gl_ClipDistance0 = dot( float4( worldPos.xyz, 1.0 ), passBuf.clipPlane0.xyzw ); +@end + + @insertpiece( custom_vs_posExecution ) + + return outVs; +} diff --git a/Media/OgreHlms/HLMS/Unlit/Metal/BlendModes_piece_ps.metal b/Media/OgreHlms/HLMS/Unlit/Metal/BlendModes_piece_ps.metal new file mode 100644 index 0000000000..1ec58fbea5 --- /dev/null +++ b/Media/OgreHlms/HLMS/Unlit/Metal/BlendModes_piece_ps.metal @@ -0,0 +1,123 @@ +//Reset t to 0 just in case (values are preserved from previous stages) +@pset( t, 0 ) + +@piece( NormalNonPremul ) + //Normal Non Premultiplied @counter(t) + outPs.colour0.xyz = mix( outPs.colour0.xyz, topImage@value(t).xyz, topImage@value(t).a ); + outPs.colour0.w = mix( outPs.colour0.w, 1.0, topImage@value(t).w ); +@end + +@piece( NormalPremul ) + //Normal Premultiplied @counter(t) + outPs.colour0.xyz = (1.0 - topImage@value(t).a) * outPs.colour0.xyz + topImage@value(t).xyz; + outPs.colour0.w = mix( outPs.colour0.w, 1.0, topImage@value(t).w ); +@end + +@piece( Add ) + //Add @counter(t) + outPs.colour0.xyz = mix( outPs.colour0.xyz, + min( outPs.colour0.xyz + topImage@value(t).xyz, float3(1.0) ), + topImage@value(t).a ); +@end + +@piece( Subtract ) + //Subtract @counter(t) + outPs.colour0.xyz = mix( outPs.colour0.xyz, + max( outPs.colour0.xyz - topImage@value(t).xyz, float3(0.0) ), + topImage@value(t).a ); +@end + +@piece( Multiply ) + //Multiply @counter(t) + outPs.colour0.xyz = mix( outPs.colour0.xyz, + outPs.colour0.xyz * topImage@value(t).xyz, + topImage@value(t).a ); +@end + +@piece( Multiply2x ) + //Multiply2x @counter(t) + outPs.colour0.xyz = mix( outPs.colour0.xyz, + min( outPs.colour0.xyz * topImage@value(t).xyz * 2.0, float3(1.0) ), + topImage@value(t).a ); +@end + +@piece( Screen ) + //Screen @counter(t) + outPs.colour0.xyz = mix( outPs.colour0.xyz, + 1.0 - (1.0 - outPs.colour0.xyz) * (1.0 - topImage@value(t).xyz), + topImage@value(t).a ); +@end + +@piece( Overlay ) + //Overlay @counter(t) + outPs.colour0.xyz = mix( outPs.colour0.xyz, + outPs.colour0.xyz * ( outPs.colour0.xyz + 2.0 * topImage@value(t).xyz * (1.0 - outPs.colour0.xyz) ), + topImage@value(t).a ); +@end + +@piece( Lighten ) + //Lighten @counter(t) + outPs.colour0.xyz = mix( outPs.colour0.xyz, + max( outPs.colour0.xyz, topImage@value(t).xyz ), + topImage@value(t).a ); +@end + +@piece( Darken ) + //Darken @counter(t) + outPs.colour0.xyz = mix( outPs.colour0.xyz, + min( outPs.colour0.xyz, topImage@value(t).xyz ), + topImage@value(t).a ); +@end + +@piece( GrainExtract ) + //GrainExtract @counter(t) + outPs.colour0.xyz = mix( outPs.colour0.xyz, + (outPs.colour0.xyz - topImage@value(t).xyz) + 0.5f, + topImage@value(t).a ); +@end + +@piece( GrainMerge ) + //GrainMerge @counter(t) + outPs.colour0.xyz = mix( outPs.colour0.xyz, + (outPs.colour0.xyz + topImage@value(t).xyz) - 0.5f, + topImage@value(t).a ); +@end + +@piece( Difference ) + //Difference @counter(t) + outPs.colour0.xyz = mix( outPs.colour0.xyz, + abs(outPs.colour0.xyz - topImage@value(t).xyz), + topImage@value(t).a ); +@end + +@foreach( 16, n ) +@property( uv_atlas@n ) @piece( atlasOffset@n )* atlasOffsets[@n].z + atlasOffsets[@n].xy @end @end @end + +// Get the indexes to the textureMaps[] array using template code. We had to add 1 +// to the actual value otherwise property( diffuse_map ) fails when the index is 0 +@foreach( diffuse_map, n ) + @sub( diffuse_map@n_idx, diffuse_map@n, 1 ) @end + +@foreach( diffuse_map, n ) + @property( !diffuse_map@n_reflection ) + @property( diffuse_map@n_array ) + @piece( TextureOrigin@n )textureMapsArray@value(diffuse_map@n_idx)@end + @piece( SamplerOrigin@n )samplerState@value(diffuse_map@n_idx)@end + @piece( SamplerUV@n )inPs.uv@value( uv_diffuse@n ).@insertpiece( uv_diffuse_swizzle@n ), material.diffuseIdx@n @end + @end @property( !diffuse_map@n_array ) + @piece( TextureOrigin@n )textureMaps@value(diffuse_map@n_idx)@end + @piece( SamplerOrigin@n )samplerState@value(diffuse_map@n_idx)@end + @piece( SamplerUV@n )inPs.uv@value( uv_diffuse@n ).@insertpiece( uv_diffuse_swizzle@n )@end + @end + @end @property( diffuse_map@n_reflection ) + @property( diffuse_map@n_array ) + @piece( TextureOrigin@n )textureMapsArray@value(diffuse_map@n_idx)@end + @piece( SamplerOrigin@n )samplerState@value(diffuse_map@n_idx)@end + @piece( SamplerUV@n )gl_FragCoord.xy * passBuf.invWindowSize.xy, material.diffuseIdx@n@end + @end @property( !diffuse_map@n_array ) + @piece( TextureOrigin@n )textureMaps@value(diffuse_map@n_idx)@end + @piece( SamplerOrigin@n )samplerState@value(diffuse_map@n_idx)@end + @piece( SamplerUV@n )gl_FragCoord.xy * passBuf.invWindowSize.xy@end + @end + @end +@end diff --git a/Media/OgreHlms/HLMS/Unlit/Metal/PixelShader_ps.metal b/Media/OgreHlms/HLMS/Unlit/Metal/PixelShader_ps.metal new file mode 100644 index 0000000000..400d8ebc66 --- /dev/null +++ b/Media/OgreHlms/HLMS/Unlit/Metal/PixelShader_ps.metal @@ -0,0 +1,118 @@ +@insertpiece( SetCrossPlatformSettings ) + +// START UNIFORM STRUCT DECLARATION +@property( has_planar_reflections ) + @insertpiece( PassStructDecl ) +@end +@property( !hlms_shadowcaster ) +@insertpiece( MaterialStructDecl ) +@end +@insertpiece( custom_ps_uniformStructDeclaration ) +// END UNIFORM STRUCT DECLARATION +struct PS_INPUT +{ +@insertpiece( VStoPS_block ) +}; + +@property( !hlms_shadowcaster ) + +@padd( numSamplerStates, num_array_textures, num_textures ) +@pset( samplerStateBind, 2 ) + +@property( diffuse )@piece( MultiplyDiffuseConst )* material.diffuse@end @end + +@insertpiece( DeclOutputType ) + +fragment @insertpiece( output_type ) main_metal +( + PS_INPUT inPs [[stage_in]] + // START UNIFORM DECLARATION + @property( has_planar_reflections ) + @insertpiece( PassDecl ) + @end + @property( !hlms_shadowcaster ) + @insertpiece( MaterialDecl ) + @end + @insertpiece( custom_ps_uniformDeclaration ) + // END UNIFORM DECLARATION + @property( hlms_vpos ), float4 gl_FragCoord [[position]]@end + + @foreach( num_array_textures, n ) + , texture2d_array textureMapsArray@n [[texture(@value(array_texture_bind@n))]]@end + @foreach( num_textures, n ) + , texture2d textureMaps@n [[texture(@value(texture_bind@n))]]@end + @foreach( numSamplerStates, n ) + , sampler samplerState@n [[sampler(@counter(samplerStateBind))]]@end +) +{ + PS_OUTPUT outPs; + + @insertpiece( custom_ps_preExecution ) + + @property( diffuse_map || alpha_test || diffuse )Material material;@end + +@property( diffuse_map || alpha_test || diffuse ) + material = materialArray[inPs.materialId]; +@end + + @insertpiece( custom_ps_posMaterialLoad ) + +@property( !diffuse_map && !diffuse_map0 ) +@property( hlms_colour && !diffuse_map ) outPs.colour0 = inPs.colour @insertpiece( MultiplyDiffuseConst );@end +@property( !hlms_colour && !diffuse ) outPs.colour0 = float4(1, 1, 1, 1);@end +@property( !hlms_colour && diffuse ) outPs.colour0 = material.diffuse;@end +@end + +@property( diffuse_map )@property( diffuse_map0 ) + //Load base image + outPs.colour0 = @insertpiece( TextureOrigin0 ).sample( @insertpiece( SamplerOrigin0 ), @insertpiece( SamplerUV0 ) ).@insertpiece(diffuse_map0_tex_swizzle);@end + +@foreach( diffuse_map, n, 1 )@property( diffuse_map@n ) + float4 topImage@n = @insertpiece( TextureOrigin@n ).sample( @insertpiece( SamplerOrigin@n ), @insertpiece( SamplerUV@n ) ).@insertpiece(diffuse_map@n_tex_swizzle);@end @end + +@foreach( diffuse_map, n, 1 )@property( diffuse_map@n ) + @insertpiece( blend_mode_idx@n )@end @end + + @property( hlms_colour )outPs.colour0 *= inPs.colour @insertpiece( MultiplyDiffuseConst );@end + @property( !hlms_colour && diffuse )outPs.colour0 *= material.diffuse;@end +@end + + @insertpiece( custom_ps_preLights ) + +@property( alpha_test ) + if( material.alpha_test_threshold.x @insertpiece( alpha_test_cmp_func ) outPs.colour0.a ) + discard;@end + + @insertpiece( custom_ps_posExecution ) + +@property( !hlms_render_depth_only ) + return outPs; +@end +} +@end @property( hlms_shadowcaster ) + @property( hlms_render_depth_only ) + @set( hlms_disable_stage, 1 ) + @end +@insertpiece( DeclShadowCasterMacros ) +@property( hlms_shadowcaster_point ) + @insertpiece( PassStructDecl ) +@end + +@insertpiece( DeclOutputType ) +fragment @insertpiece( output_type ) main_metal +( + PS_INPUT inPs [[stage_in]] + @property( hlms_vpos ), float4 gl_FragCoord [[position]]@end + @property( hlms_shadowcaster_point ) + @insertpiece( PassDecl ) + @end +) +{ + PS_OUTPUT outPs; + @insertpiece( custom_ps_preExecution ) + @insertpiece( DoShadowCastPS ) + @insertpiece( custom_ps_posExecution ) + + return outPs; +} +@end diff --git a/Media/OgreHlms/HLMS/Unlit/Metal/Structs_piece_vs_piece_ps.metal b/Media/OgreHlms/HLMS/Unlit/Metal/Structs_piece_vs_piece_ps.metal new file mode 100644 index 0000000000..56f9e48d4c --- /dev/null +++ b/Media/OgreHlms/HLMS/Unlit/Metal/Structs_piece_vs_piece_ps.metal @@ -0,0 +1,67 @@ +@piece( PassStructDecl ) +//Uniforms that change per pass +struct PassData +{ + @insertpiece( PassInternalDecl ) +};@end + +@piece( PassDecl ) +, constant PassData &passBuf [[buffer(CONST_SLOT_START+0)]] +@end + +@piece( MaterialStructDecl ) +struct Material +{ + float4 alpha_test_threshold; + float4 diffuse; + + @foreach( 16, n ) + ushort diffuseIdx@n;@end + + @insertpiece( custom_materialBuffer ) +};@end + +@piece( MaterialDecl ) +, constant Material *materialArray [[buffer(CONST_SLOT_START+1)]] +@end + + +@piece( InstanceDecl ) +//Uniforms that change per Item/Entity +//.x = +//Contains the material's start index. +// +//.y = +//shadowConstantBias. Send the bias directly to avoid an +//unnecessary indirection during the shadow mapping pass. +//Must be loaded with uintBitsToFloat +// +//.z = +//Contains 0 or 1 to index into passBuf.viewProj[]. Only used +//if hlms_identity_viewproj_dynamic is set. +, constant uint4 *worldMaterialIdx [[buffer(CONST_SLOT_START+2)]] +@end + +//Reset texcoord to 0 for every shader stage (since values are preserved). +@pset( texcoord, 0 ) + +@piece( VStoPS_block ) + @property( !hlms_shadowcaster ) + ushort materialId [[flat]]; + @property( hlms_colour )float4 colour;@end + @foreach( out_uv_half_count, n ) + float@value( out_uv_half_count@n ) uv@n;@end + @end + @property( hlms_shadowcaster ) + @property( (!hlms_shadow_uses_depth_texture || exponential_shadow_maps) && !hlms_shadowcaster_point ) + float depth; + @end + @property( hlms_shadowcaster_point ) + float3 toCameraWS; + @property( !exponential_shadow_maps ) + float constBias [[flat]]; + @end + @end + @end + @insertpiece( custom_VStoPS ) +@end diff --git a/Media/OgreHlms/HLMS/Unlit/Metal/VertexShader_vs.metal b/Media/OgreHlms/HLMS/Unlit/Metal/VertexShader_vs.metal new file mode 100644 index 0000000000..23f5ce79db --- /dev/null +++ b/Media/OgreHlms/HLMS/Unlit/Metal/VertexShader_vs.metal @@ -0,0 +1,112 @@ +@insertpiece( SetCrossPlatformSettings ) + +// START UNIFORM STRUCT DECLARATION +@insertpiece( PassStructDecl ) +@insertpiece( custom_vs_uniformStructDeclaration ) +// END UNIFORM STRUCT DECLARATION + +struct VS_INPUT +{ + float4 position [[attribute(VES_POSITION)]]; +@property( hlms_colour ) float4 colour [[attribute(VES_DIFFUSE)]];@end +@foreach( hlms_uv_count, n ) + float@value( hlms_uv_count@n ) uv@n [[attribute(VES_TEXTURE_COORDINATES@n)]];@end +@property( !iOS ) + ushort drawId [[attribute(15)]]; +@end + @insertpiece( custom_vs_attributes ) +}; + +struct PS_INPUT +{ +@insertpiece( VStoPS_block ) + float4 gl_Position [[position]]; +@property( hlms_global_clip_distances ) + float gl_ClipDistance0 [[clip_distance]]; +@end +}; + +@property( !hlms_identity_world ) + @piece( worldViewProj )worldViewProj@end +@end @property( hlms_identity_world ) + @property( !hlms_identity_viewproj_dynamic ) + @piece( worldViewProj )passBuf.viewProj[@value(hlms_identity_viewproj)]@end + @end @property( hlms_identity_viewproj_dynamic ) + @piece( worldViewProj )passBuf.viewProj[worldMaterialIdx[drawId].z]@end + @end +@end + +vertex PS_INPUT main_metal +( + VS_INPUT input [[stage_in]] + @property( iOS ) + , ushort instanceId [[instance_id]] + , constant ushort &baseInstance [[buffer(15)]] + @end + // START UNIFORM DECLARATION + @insertpiece( PassDecl ) + @insertpiece( InstanceDecl ) + , device const float4x4 *worldMatBuf [[buffer(TEX_SLOT_START+0)]] + @property( texture_matrix ), device const float4x4 *animationMatrixBuf [[buffer(TEX_SLOT_START+1)]]@end + @insertpiece( custom_vs_uniformDeclaration ) + // END UNIFORM DECLARATION +) +{ + @property( iOS ) + ushort drawId = baseInstance + instanceId; + @end @property( !iOS ) + ushort drawId = input.drawId; + @end + + PS_INPUT outVs; + @insertpiece( custom_vs_preExecution ) + + @property( !hlms_identity_world ) + float4x4 worldViewProj; + worldViewProj = worldMatBuf[drawId]; + @end + +@property( !hlms_dual_paraboloid_mapping ) + outVs.gl_Position = input.position * @insertpiece( worldViewProj ); +@end + +@property( hlms_dual_paraboloid_mapping ) + //Dual Paraboloid Mapping + outVs.gl_Position.w = 1.0f; + outVs.gl_Position.xyz = ( input.position * @insertpiece( worldViewProj ) ).xyz; + float L = length( outVs.gl_Position.xyz ); + outVs.gl_Position.z += 1.0f; + outVs.gl_Position.xy /= outVs.gl_Position.z; + outVs.gl_Position.z = (L - NearPlane) / (FarPlane - NearPlane); +@end + +@property( !hlms_shadowcaster ) +@property( hlms_colour ) outVs.colour = input.colour;@end + +@property( texture_matrix ) float4x4 textureMatrix;@end + +@foreach( out_uv_count, n ) + @property( out_uv@n_texture_matrix ) + textureMatrix = animationMatrixBuf[(worldMaterialIdx[drawId].x << 4u) + @value( out_uv@n_tex_unit )]; + outVs.uv@value( out_uv@n_out_uv ).@insertpiece( out_uv@n_swizzle ) = (float4( input.uv@value( out_uv@n_source_uv ).xy, 0, 1 ) * textureMatrix).xy; + @end @property( !out_uv@n_texture_matrix ) + outVs.uv@value( out_uv@n_out_uv ).@insertpiece( out_uv@n_swizzle ) = input.uv@value( out_uv@n_source_uv ).xy; + @end @end + + outVs.materialId = (ushort)worldMaterialIdx[drawId].x; + +@end + + @property( hlms_global_clip_distances || (hlms_shadowcaster && (exponential_shadow_maps || hlms_shadowcaster_point)) ) + float3 worldPos = (outVs.gl_Position * passBuf.invViewProj).xyz; + @end + @insertpiece( DoShadowCasterVS ) + +@property( hlms_global_clip_distances ) + outVs.gl_ClipDistance0 = dot( float4( worldPos.xyz, 1.0 ), passBuf.clipPlane0.xyzw ); +@end + + @insertpiece( custom_vs_posExecution ) + + return outVs; +} diff --git a/Media/OgreHlms/Unlit/GLSL/VertexShader_vs.glsl b/Media/OgreHlms/Unlit/GLSL/VertexShader_vs.glsl deleted file mode 100644 index cfe37d0598..0000000000 --- a/Media/OgreHlms/Unlit/GLSL/VertexShader_vs.glsl +++ /dev/null @@ -1,78 +0,0 @@ -@insertpiece( SetCrossPlatformSettings ) - -out gl_PerVertex -{ - vec4 gl_Position; -}; - -layout(std140) uniform; - -@insertpiece( Common_Matrix_DeclUnpackMatrix4x4 ) - -in vec4 vertex; -@property( hlms_colour )in vec4 colour;@end - -@foreach( hlms_uv_count, n ) -in vec@value( hlms_uv_count@n ) uv@n;@end - -in uint drawId; - -@insertpiece( custom_vs_attributes ) - -out block -{ -@insertpiece( VStoPS_block ) -} outVs; - -// START UNIFORM DECLARATION -@insertpiece( PassDecl ) -@insertpiece( InstanceDecl ) -layout(binding = 0) uniform samplerBuffer worldMatBuf; -@property( texture_matrix )layout(binding = 1) uniform samplerBuffer animationMatrixBuf;@end -@insertpiece( custom_vs_uniformDeclaration ) -// END UNIFORM DECLARATION - -void main() -{ - @insertpiece( custom_vs_preExecution ) - //uint drawId = 1; - mat4 worldViewProj; - worldViewProj = UNPACK_MAT4( worldMatBuf, drawId ); - -@property( !hlms_dual_paraboloid_mapping ) - gl_Position = worldViewProj * vertex; -@end - -@property( hlms_dual_paraboloid_mapping ) - //Dual Paraboloid Mapping - gl_Position.w = 1.0f; - gl_Position.xyz = (worldViewProj * vertex).xyz; - float L = length( gl_Position.xyz ); - gl_Position.z += 1.0f; - gl_Position.xy /= gl_Position.z; - gl_Position.z = (L - NearPlane) / (FarPlane - NearPlane); -@end - -@property( !hlms_shadowcaster ) -@property( hlms_colour ) outVs.colour = colour;@end - -@property( texture_matrix ) mat4 textureMatrix;@end - -@foreach( out_uv_count, n ) - @property( out_uv@_texture_matrix )textureMatrix = UNPACK_MAT4( animationMatrixBuf, (instance.materialIdx[drawId].x << 4u) + @value( out_uv@n_tex_unit ) );@end - outVs.uv@value( out_uv@n_out_uv ).@insertpiece( out_uv@n_swizzle ) = uv@value( out_uv@n_source_uv ).xy @property( out_uv@_texture_matrix ) * textureMatrix@end ;@end - - outVs.drawId = drawId; - -@end @property( hlms_shadowcaster ) - float shadowConstantBias = uintBitsToFloat( instance.materialIdx[drawId].y ); - //Linear depth - outVs.depth = (gl_Position.z - pass.depthRange.x + shadowConstantBias * pass.depthRange.y) * pass.depthRange.y; - - //We can't make the depth buffer linear without Z out in the fragment shader; - //however we can use a cheap approximation ("pseudo linear depth") - //see http://www.yosoygames.com.ar/wp/2014/01/linear-depth-buffer-my-ass/ - gl_Position.z = gl_Position.z * (gl_Position.w * pass.depthRange.y); -@end - @insertpiece( custom_vs_posExecution ) -} diff --git a/Media/OgreHlms/Unlit/HLSL/BlendModes_piece_ps.hlsl b/Media/OgreHlms/Unlit/HLSL/BlendModes_piece_ps.hlsl deleted file mode 100644 index 196fe7c1e0..0000000000 --- a/Media/OgreHlms/Unlit/HLSL/BlendModes_piece_ps.hlsl +++ /dev/null @@ -1,115 +0,0 @@ -@piece( NormalNonPremul ) - //Normal Non Premultiplied @counter(t) - outColour.xyz = lerp( outColour.xyz, topImage@value(t).xyz, topImage@value(t).a ); -@end - -@piece( NormalPremul ) - //Normal Premultiplied @counter(t) - outColour.xyz = (1.0 - topImage@value(t).a) * outColour.xyz + topImage@value(t).xyz; -@end - -@piece( Add ) - //Add @counter(t) - outColour.xyz = lerp( outColour.xyz, - min( outColour.xyz + topImage@value(t).xyz, float3(1.0) ), - topImage@value(t).a ); -@end - -@piece( Subtract ) - //Subtract @counter(t) - outColour.xyz = lerp( outColour.xyz, - max( outColour.xyz - topImage@value(t).xyz, float3(0.0) ), - topImage@value(t).a ); -@end - -@piece( Multiply ) - //Multiply @counter(t) - outColour.xyz = lerp( outColour.xyz, - outColour.xyz * topImage@value(t).xyz, - topImage@value(t).a ); -@end - -@piece( Multiply2x ) - //Multiply2x @counter(t) - outColour.xyz = lerp( outColour.xyz, - min( outColour.xyz * topImage@value(t).xyz * 2.0, float3(1.0) ), - topImage@value(t).a ); -@end - -@piece( Screen ) - //Screen @counter(t) - outColour.xyz = lerp( outColour.xyz, - 1.0 - (1.0 - outColour.xyz) * (1.0 - topImage@value(t).xyz), - topImage@value(t).a ); -@end - -@piece( Overlay ) - //Overlay @counter(t) - outColour.xyz = lerp( outColour.xyz, - outColour.xyz * ( outColour.xyz + 2.0 * topImage@value(t).xyz * (1.0 - outColour.xyz) ), - topImage@value(t).a ); -@end - -@piece( Lighten ) - //Lighten @counter(t) - outColour.xyz = lerp( outColour.xyz, - max( outColour.xyz, topImage@value(t).xyz ), - topImage@value(t).a ); -@end - -@piece( Darken ) - //Darken @counter(t) - outColour.xyz = lerp( outColour.xyz, - min( outColour.xyz, topImage@value(t).xyz ), - topImage@value(t).a ); -@end - -@piece( GrainExtract ) - //GrainExtract @counter(t) - outColour.xyz = lerp( outColour.xyz, - (outColour.xyz - topImage@value(t).xyz) + 0.5f, - topImage@value(t).a ); -@end - -@piece( GrainMerge ) - //GrainMerge @counter(t) - outColour.xyz = lerp( outColour.xyz, - (outColour.xyz + topImage@value(t).xyz) - 0.5f, - topImage@value(t).a ); -@end - -@piece( Difference ) - //Difference @counter(t) - outColour.xyz = lerp( outColour.xyz, - abs(outColour.xyz - topImage@value(t).xyz), - topImage@value(t).a ); -@end - -@foreach( 16, n ) -@property( uv_atlas@n ) @piece( atlasOffset@n )* atlasOffsets[@n].z + atlasOffsets[@n].xy @end @end @end - -// Get the indexes to the textureMaps[] array using template code. We had to add 1 -// to the actual value otherwise property( diffuse_map ) fails when the index is 0 -@foreach( diffuse_map, n ) - @sub( diffuse_map@n_idx, diffuse_map@n, 1 ) @end - -@piece( diffuseIdx0 )material.indices0_3.x & 0x0000FFFFu@end -@piece( diffuseIdx1 )material.indices0_3.y >> 16u@end -@piece( diffuseIdx2 )material.indices0_3.z & 0x0000FFFFu@end -@piece( diffuseIdx3 )material.indices0_3.w >> 16u@end -@piece( diffuseIdx4 )material.indices4_7.x & 0x0000FFFFu@end -@piece( diffuseIdx5 )material.indices4_7.y >> 16u@end -@piece( diffuseIdx6 )material.indices4_7.z & 0x0000FFFFu@end -@piece( diffuseIdx7 )material.indices4_7.w >> 16u@end - -@foreach( diffuse_map, n ) - @property( diffuse_map@n_array ) - @piece( TextureOrigin@n )textureMapsArray@value(diffuse_map@n_idx)@end - @piece( SamplerOrigin@n )samplerState@value(diffuse_map@n_idx)@end - @piece( SamplerUV@n )float3( inPs.uv@value( uv_diffuse@n ).@insertpiece( uv_diffuse_swizzle@n ), @insertpiece( diffuseIdx@n ) )@end - @end @property( !diffuse_map@n_array ) - @piece( TextureOrigin@n )textureMaps@value(diffuse_map@n_idx)@end - @piece( SamplerOrigin@n )samplerState@value(diffuse_map@n_idx)@end - @piece( SamplerUV@n )inPs.uv@value( uv_diffuse@n ).@insertpiece( uv_diffuse_swizzle@n )@end - @end -@end diff --git a/Media/OgreHlms/Unlit/HLSL/VertexShader_vs.hlsl b/Media/OgreHlms/Unlit/HLSL/VertexShader_vs.hlsl deleted file mode 100644 index bad0a1551a..0000000000 --- a/Media/OgreHlms/Unlit/HLSL/VertexShader_vs.hlsl +++ /dev/null @@ -1,81 +0,0 @@ -@insertpiece( SetCrossPlatformSettings ) - -@insertpiece( Common_Matrix_DeclUnpackMatrix4x4 ) - -// START UNIFORM DECLARATION -@insertpiece( PassDecl ) -@insertpiece( InstanceDecl ) -Buffer worldMatBuf : register(t0); -@property( texture_matrix )Buffer animationMatrixBuf : register(t1);@end -@insertpiece( custom_vs_uniformDeclaration ) -// END UNIFORM DECLARATION - -struct VS_INPUT -{ - float4 vertex : POSITION; -@property( hlms_colour ) float4 colour : COLOR0;@end -@foreach( hlms_uv_count, n ) - float@value( hlms_uv_count@n ) uv@n : TEXCOORD@n;@end - uint drawId : DRAWID; - @insertpiece( custom_vs_attributes ) -}; - -struct PS_INPUT -{ -@insertpiece( VStoPS_block ) - float4 gl_Position : SV_Position; -}; - -PS_INPUT main( VS_INPUT input ) -{ - PS_INPUT outVs; - @insertpiece( custom_vs_preExecution ) - - //uint drawId = 1; - float4x4 worldViewProj; - worldViewProj = UNPACK_MAT4( worldMatBuf, input.drawId ); - -@property( !hlms_dual_paraboloid_mapping ) - outVs.gl_Position = mul( worldViewProj, input.vertex ); -@end - -@property( hlms_dual_paraboloid_mapping ) - //Dual Paraboloid Mapping - outVs.gl_Position.w = 1.0f; - outVs.gl_Position.xyz = mul( worldViewProj, input.vertex ).xyz; - float L = length( outVs.gl_Position.xyz ); - outVs.gl_Position.z += 1.0f; - outVs.gl_Position.xy /= outVs.gl_Position.z; - outVs.gl_Position.z = (L - NearPlane) / (FarPlane - NearPlane); -@end - -@property( !hlms_shadowcaster ) -@property( hlms_colour ) outVs.colour = input.colour;@end - -@property( texture_matrix ) float4x4 textureMatrix;@end - -@foreach( out_uv_count, n ) - @property( out_uv@_texture_matrix )textureMatrix = UNPACK_MAT4( animationMatrixBuf, (materialIdx[input.drawId].x << 4u) + @value( out_uv@n_tex_unit ) );@end - outVs.uv@value( out_uv@n_out_uv ).@insertpiece( out_uv@n_swizzle ) = -@property( out_uv@_texture_matrix ) - mul( textureMatrix, input.uv@value( out_uv@n_source_uv ).xy ); -@end @property( !out_uv@_texture_matrix ) - input.uv@value( out_uv@n_source_uv ).xy;@end @end - - outVs.drawId = input.drawId; - -@end @property( hlms_shadowcaster ) - float shadowConstantBias = asfloat( materialIdx[input.drawId].y ); - //Linear depth - outVs.depth = (outVs.gl_Position.z - passBuf.depthRange.x + shadowConstantBias * passBuf.depthRange.y) * passBuf.depthRange.y; - - //We can't make the depth buffer linear without Z out in the fragment shader; - //however we can use a cheap approximation ("pseudo linear depth") - //see http://www.yosoygames.com.ar/wp/2014/01/linear-depth-buffer-my-ass/ - outVs.gl_Position.z = outVs.gl_Position.z * (outVs.gl_Position.w * passBuf.depthRange.y); -@end - - @insertpiece( custom_vs_posExecution ) - - return outVs; -} diff --git a/Platforms/Ogre2/Ogre2Platform/include/MyGUI_Ogre2RenderManager.h b/Platforms/Ogre2/Ogre2Platform/include/MyGUI_Ogre2RenderManager.h index 48b7e9b39d..e954e304ac 100644 --- a/Platforms/Ogre2/Ogre2Platform/include/MyGUI_Ogre2RenderManager.h +++ b/Platforms/Ogre2/Ogre2Platform/include/MyGUI_Ogre2RenderManager.h @@ -135,9 +135,6 @@ namespace MyGUI Ogre::RenderWindow* getRenderWindow(); - bool getManualRender(); - void setManualRender(bool _value); - void render(); size_t getBatchCount() const; diff --git a/Platforms/Ogre2/Ogre2Platform/src/MyGUI_Ogre2RenderManager.cpp b/Platforms/Ogre2/Ogre2Platform/src/MyGUI_Ogre2RenderManager.cpp index 6177019db9..10ad0aa1a1 100644 --- a/Platforms/Ogre2/Ogre2Platform/src/MyGUI_Ogre2RenderManager.cpp +++ b/Platforms/Ogre2/Ogre2Platform/src/MyGUI_Ogre2RenderManager.cpp @@ -179,7 +179,7 @@ namespace MyGUI mSceneManager = _scene; if (mSceneManager != nullptr) { - mSceneManager->getRenderQueue()->setSortRenderQueue(RENDER_QUEUE_OVERLAY, false); + mSceneManager->getRenderQueue()->setSortRenderQueue(RENDER_QUEUE_OVERLAY, Ogre::RenderQueue::DisableSort); } } @@ -213,8 +213,6 @@ namespace MyGUI mCountBatch = 0; - setManualRender(true); - mSceneManager->getRenderQueue()->clear(); //get mygui to itterate through renderables and call 'doRender' @@ -386,16 +384,6 @@ namespace MyGUI return mWindow; } - bool Ogre2RenderManager::getManualRender() - { - return mManualRender; - } - - void Ogre2RenderManager::setManualRender(bool _value) - { - mManualRender = _value; - } - size_t Ogre2RenderManager::getBatchCount() const { return mCountBatch;