diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000000..009ad6d6af4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,67 @@ +Thumbs.db +*.obj +*.pdb +*.user +*.aps +*.pch +*.vspscc +*_i.c +*_p.c +*.ncb +*.suo +*.sln.docstates +*.tlb +*.tlh +*.bak +*.cache +*.ilk +*.log +[Bb]in +[Dd]ebug*/ +*.sbr +obj/ +[Rr]elease*/ +_ReSharper*/ +[Tt]est[Rr]esult* +*.vssscc +$tf*/ + +# Libraries +*.lib +*.a + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app + +# Compiled Object files +*.slo +*.lo +*.o + +# Compiled Dynamic libraries +*.so +*.dylib + +# Compiled Static libraries +*.lai +*.la + +# CMake/build directory +[Bb]uild/ +# CMake cache +CMakeCache.txt +CMakeFiles +Makefile +cmake_install.cmake +install_manifest.txt + +# NetBeans project directory +nbproject/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000000..7d0b26c9755 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,277 @@ +#/* +#----------------------------------------------------------------------------- +#Filename: CMakeLists.txt +#----------------------------------------------------------------------------- +# +#This source file is part of the +# ___ __ __ _ _ _ +# /___\__ _ _ __ ___ / / /\ \ (_) | _(_) +# // // _` | '__/ _ \ \ \/ \/ / | |/ / | +#/ \_// (_| | | | __/ \ /\ /| | <| | +#\___/ \__, |_| \___| \/ \/ |_|_|\_\_| +# |___/ +# Tutorial Framework +# http://www.ogre3d.org/tikiwiki/ +#----------------------------------------------------------------------------- +#*/ +cmake_minimum_required(VERSION 2.6) + +project(Thrive) + +# macro (add_sources) + # file (RELATIVE_PATH _relPath "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}") + # foreach (_src ${ARGN}) + # if (_relPath) + # list (APPEND SRCS "${_relPath}/${_src}") + # else() + # list (APPEND SRCS "${_src}") + # endif() + # endforeach() + # if (_relPath) + # # propagate SRCS to parent directory + # set (SRCS ${SRCS} PARENT_SCOPE) + # endif() +# endmacro() + +# function to collect all the sources from sub-directories +# into a single list +function(add_sources) + get_property(is_defined GLOBAL PROPERTY SRCS_LIST DEFINED) + if(NOT is_defined) + define_property(GLOBAL PROPERTY SRCS_LIST + BRIEF_DOCS "List of source files" + FULL_DOCS "List of source files to be compiled in one library") + endif() + # make absolute paths + set(SRCS) + foreach(s IN LISTS ARGN) + if(NOT IS_ABSOLUTE "${s}") + get_filename_component(s "${s}" ABSOLUTE) + endif() + list(APPEND SRCS "${s}") + endforeach() + # append to global list + set_property(GLOBAL APPEND PROPERTY SRCS_LIST "${SRCS}") +endfunction(add_sources) + + +if(WIN32) + set(CMAKE_MODULE_PATH "$ENV{OGRE_HOME}/CMake/;${CMAKE_MODULE_PATH}") + #set(Boost_INCLUDE_DIR "C:/boost/lib") + message("cm = ${Boost_INCLUDE_DIR}") + set(OGRE_SAMPLES_INCLUDEPATH + $ENV{OGRE_HOME}/Samples/include + ) +endif(WIN32) + +if(UNIX) + if(EXISTS "/usr/local/lib/OGRE/cmake") + + set(CMAKE_MODULE_PATH "/usr/local/lib/OGRE/cmake/;${CMAKE_MODULE_PATH}") + set(OGRE_SAMPLES_INCLUDEPATH "/usr/local/share/OGRE/samples/Common/include/") # We could just *assume* that developers uses this basepath : /usr/local + + elseif(EXISTS "/usr/lib/OGRE/cmake") + + set(CMAKE_MODULE_PATH "/usr/lib/OGRE/cmake/;${CMAKE_MODULE_PATH}") + set(OGRE_SAMPLES_INCLUDEPATH "/usr/share/OGRE/samples/Common/include/") # Otherwise, this one + + else () + message(SEND_ERROR "Failed to find module path.") + endif(EXISTS "/usr/local/lib/OGRE") +endif(UNIX) + +if (CMAKE_BUILD_TYPE STREQUAL "") + # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This screws up + # differentiation between debug and release builds. + set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build, options are: None (CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE) +endif () + +set(CMAKE_DEBUG_POSTFIX "_d") + +set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/dist") + +find_package(OGRE REQUIRED) + +#if(NOT "${OGRE_VERSION_NAME}" STREQUAL "Cthugha") +# message(SEND_ERROR "You need Ogre 1.7 Cthugha to build this.") +#endif() + +find_package(OIS REQUIRED) + +if(NOT OIS_FOUND) + message(SEND_ERROR "Failed to find OIS.") +endif() + +# Find Boost +set(Boost_Dir $ENV{BOOST_ROOT}) +if (NOT OGRE_BUILD_PLATFORM_IPHONE) + if (WIN32 OR APPLE) + set(Boost_USE_STATIC_LIBS TRUE) + else () + # Statically linking boost to a dynamic Ogre build doesn't work on Linux 64bit + set(Boost_USE_STATIC_LIBS ${OGRE_STATIC}) + endif () +# find_package(Boost) +# message("${Boost_FOUND}, ${Boost_INCLUDE_DIR}") +# set(BOOST_LIBRARYDIR "c:/boost/boost_1_51/lib") + if (MINGW) + # this is probably a bug in CMake: the boost find module tries to look for + # boost libraries with name libboost_*, but CMake already prefixes library + # search names with "lib". This is the workaround. + set(CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES} "") + endif () + # find_package(Boost) + # message("${Boost_FOUND}, ${Boost_DIR}") + + set(Boost_ADDITIONAL_VERSIONS "1.51" "1.44" "1.44.0" "1.42" "1.42.0" "1.41.0" "1.41" "1.40.0" "1.40" "1.39.0" "1.39" "1.38.0" "1.38" "1.37.0" "1.37" ) + # Components that need linking (NB does not include header-only components like bind) + # message("${Boost_COMPILER}")s + # set(Boost_COMPILER -mgw45) + set(OGRE_BOOST_COMPONENTS thread date_time system) # <-- + find_package(Boost 1.51.0 COMPONENTS ${OGRE_BOOST_COMPONENTS} REQUIRED) + + if (NOT Boost_FOUND) + # Try again with the other type of libs + set(Boost_USE_STATIC_LIBS NOT ${Boost_USE_STATIC_LIBS}) + find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} REQUIRED) + message("${Boost_FOUND}, ${Boost_DIR}") + + endif() + find_package(Boost REQUIRED) + + # Set up referencing of Boost + #find_package(Boost COMPONENTS system REQUIRED) + include_directories(${Boost_INCLUDE_DIR}) + add_definitions(-DBOOST_ALL_NO_LIB) + # set(Boost_LIBRARIES "c:/boost/lib") + # message("ogre libs ${Boost_LIBRARIES}") + set(OGRE_LIBRARIES ${OGRE_LIBRARIES} ${Boost_LIBRARIES}) +endif() + +# set(HDRS +# ) + +# set(SRCS +# ) + +# add subdirectories +add_subdirectory(src) + +# preprocess sources +set(PREP_SRCS) +get_property(SRCS GLOBAL PROPERTY SRCS_LIST) +foreach(s IN LISTS SRCS) + file(RELATIVE_PATH rs "${CMAKE_CURRENT_SOURCE_DIR}" "${s}") + string(REGEX REPLACE "r$" "" o "${CMAKE_CURRENT_BINARY_DIR}/${rs}") + add_custom_command( + OUTPUT "${o}" + COMMAND ${CMAKE_COMMAND} -E copy "${s}" "${o}" + DEPENDS "${s}" + COMMENT "Creating ${o}" + VERBATIM + ) + list(APPEND PREP_SRCS "${o}") +endforeach() + +include_directories( ${OIS_INCLUDE_DIRS} + ${OGRE_INCLUDE_DIRS} + ${OGRE_SAMPLES_INCLUDEPATH} +) + +add_executable(Thrive WIN32 ${PREP_SRCS}) #${HDRS} ${SRCS}) + +set_target_properties(Thrive PROPERTIES DEBUG_POSTFIX _d) + +target_link_libraries(Thrive ${OGRE_LIBRARIES} ${OIS_LIBRARIES}) + +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dist/bin) +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dist/media) + +# post-build copy for win32 +if(WIN32 AND NOT MINGW) + add_custom_command( TARGET Thrive PRE_BUILD + COMMAND if not exist .\\dist\\bin mkdir .\\dist\\bin ) + add_custom_command( TARGET Thrive POST_BUILD + COMMAND copy \"$(TargetPath)\" .\\dist\\bin ) +endif(WIN32 AND NOT MINGW) + +if(MINGW OR UNIX) + set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/dist/bin) +endif(MINGW OR UNIX) + +if(WIN32) + + message("configuration3 = ${CMAKE_BUILD_TYPE}") + install(TARGETS Thrive + RUNTIME DESTINATION bin + CONFIGURATIONS All) + + install(DIRECTORY ${CMAKE_SOURCE_DIR}/res/dist/Media + DESTINATION ./ + CONFIGURATIONS Release RelWithDebInfo Debug + ) + + install(FILES ${CMAKE_SOURCE_DIR}/res/dist/bin/plugins.cfg + ${CMAKE_SOURCE_DIR}/res/dist/bin/resources.cfg + DESTINATION bin + CONFIGURATIONS Release RelWithDebInfo + ) + + install(FILES ${CMAKE_SOURCE_DIR}/res/dist/bin/plugins_d.cfg + ${CMAKE_SOURCE_DIR}/res/dist/bin/resources_d.cfg + DESTINATION bin + CONFIGURATIONS Debug + ) + + # NOTE: for the 1.7.1 sdk the OIS dll is called OIS.dll instead of libOIS.dll + # so you'll have to change that to make it work with 1.7.1 + install(FILES ${OGRE_PLUGIN_DIR_REL}/OgreMain.dll + # ${OGRE_PLUGIN_DIR_REL}/RenderSystem_Direct3D9.dll + ${OGRE_PLUGIN_DIR_REL}/RenderSystem_GL.dll + ${OGRE_PLUGIN_DIR_REL}/OIS.dll + DESTINATION bin + CONFIGURATIONS Release RelWithDebInfo + ) + + install(FILES ${OGRE_PLUGIN_DIR_DBG}/OgreMain_d.dll + # ${OGRE_PLUGIN_DIR_DBG}/RenderSystem_Direct3D9_d.dll + ${OGRE_PLUGIN_DIR_DBG}/RenderSystem_GL_d.dll + ${OGRE_PLUGIN_DIR_DBG}/OIS_d.dll + DESTINATION bin + CONFIGURATIONS Debug + ) + + # as of sdk 1.7.2 we need to copy the boost dll's as well + # because they're not linked statically (it worked with 1.7.1 though) + # install(FILES ${Boost_DATE_TIME_LIBRARY_RELEASE} + # ${Boost_THREAD_LIBRARY_RELEASE} + # DESTINATION bin + # CONFIGURATIONS Release RelWithDebInfo + # ) + + # install(FILES ${Boost_DATE_TIME_LIBRARY_DEBUG} + # ${Boost_THREAD_LIBRARY_DEBUG} + # DESTINATION bin + # CONFIGURATIONS Debug + # ) +endif(WIN32) + +if(UNIX) + + install(TARGETS Thrive + RUNTIME DESTINATION bin + CONFIGURATIONS All) + + install(DIRECTORY ${CMAKE_SOURCE_DIR}/res/dist/media + DESTINATION ./ + CONFIGURATIONS Release RelWithDebInfo Debug + ) + + install(FILES ${CMAKE_SOURCE_DIR}/res/dist/bin/plugins.cfg + ${CMAKE_SOURCE_DIR}/res/dist/bin/resources.cfg + DESTINATION bin + CONFIGURATIONS Release RelWithDebInfo Debug + ) + +endif(UNIX) + diff --git a/res/dist/media/DeferredShadingMedia/COPYING b/res/dist/media/DeferredShadingMedia/COPYING new file mode 100644 index 00000000000..f26726f9775 --- /dev/null +++ b/res/dist/media/DeferredShadingMedia/COPYING @@ -0,0 +1,18 @@ +Copyright (c) W.J. van der Laan + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/res/dist/media/DeferredShadingMedia/DeferredShading/post/Ambient_ps.cg b/res/dist/media/DeferredShadingMedia/DeferredShading/post/Ambient_ps.cg new file mode 100644 index 00000000000..be47278867d --- /dev/null +++ b/res/dist/media/DeferredShadingMedia/DeferredShading/post/Ambient_ps.cg @@ -0,0 +1,68 @@ +/****************************************************************************** +Copyright (c) W.J. van der Laan + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +******************************************************************************/ +/** Deferred shading framework + // W.J. :wumpus: van der Laan 2005 // + + Post shader: Multipass, ambient (base) pass +*/ + +//GL and DX expect a different value +arbfp1 float finalDepth(float4 p) +{ + // GL needs it in [0..1] + return (p.z / p.w) * 0.5 + 0.5; +} + +float finalDepth(float4 p) +{ + // normally it's in [-1..1] + return p.z / p.w; +} + +void main( + float2 texCoord: TEXCOORD0, + float3 ray : TEXCOORD1, + + out float4 oColour : COLOR, + out float oDepth : DEPTH, + + uniform sampler Tex0: register(s0), + uniform sampler Tex1: register(s1), + uniform float4x4 proj, + uniform float4 ambientColor, + uniform float3 farCorner, + uniform float farClipDistance + ) +{ + float4 a0 = tex2D(Tex0, texCoord); // Attribute 0: Diffuse color+shininess + float4 a1 = tex2D(Tex1, texCoord); // Attribute 1: Normal+depth + + // Clip fragment if depth is too close, so the skybox can be rendered on the background + clip(a1.w-0.0001); + + // Calculate ambient colour of fragment + oColour = float4( ambientColor*float4(a0.rgb ,0)); + + // Calculate depth of fragment; + float3 viewPos = normalize(ray) * farClipDistance * a1.w; + float4 projPos = mul( proj, float4(viewPos, 1) ); + oDepth = finalDepth(projPos); +} diff --git a/res/dist/media/DeferredShadingMedia/DeferredShading/post/LightMaterial_ps.cg b/res/dist/media/DeferredShadingMedia/DeferredShading/post/LightMaterial_ps.cg new file mode 100644 index 00000000000..6752d786508 --- /dev/null +++ b/res/dist/media/DeferredShadingMedia/DeferredShading/post/LightMaterial_ps.cg @@ -0,0 +1,187 @@ +/****************************************************************************** +Copyright (c) W.J. van der Laan + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +******************************************************************************/ +/** Deferred shading framework + // W.J. :wumpus: van der Laan 2005 // + + Post shader: Light geometry material +*/ + +#define LIGHT_POINT 1 +#define LIGHT_SPOT 2 +#define LIGHT_DIRECTIONAL 3 + +////////////////////////////////////////////////////////////////////////////// +// Helper function section +////////////////////////////////////////////////////////////////////////////// + +//DirectX needs this to compensate for jitter +ps_2_x float2 fixUV(float2 texCoord, float2 texSize) +{ + return texCoord - (float2(0.5,0.5)/texSize); +} + +float2 fixUV(float2 texCoord, float2 texSize) +{ + return texCoord; +} + + +void checkShadow( + sampler2D shadowMap, + float3 viewPos, + float4x4 invView, + float4x4 shadowViewProj, + float shadowFarClip, +#if LIGHT_TYPE == LIGHT_DIRECTIONAL + float3 shadowCamPos +#else + float distanceFromLight +#endif + ) +{ + float3 worldPos = mul(invView, float4(viewPos, 1)).xyz; +#if LIGHT_TYPE == LIGHT_DIRECTIONAL + float distanceFromLight = length(shadowCamPos-worldPos); +#endif + float4 shadowProjPos = mul(shadowViewProj, float4(worldPos,1)); + shadowProjPos /= shadowProjPos.w; + float2 shadowSampleTexCoord = shadowProjPos.xy; + float shadowDepth = tex2D(shadowMap, shadowSampleTexCoord).r; + float shadowDistance = shadowDepth * shadowFarClip; + clip(shadowDistance - distanceFromLight + 0.1); +} + +////////////////////////////////////////////////////////////////////////////// +// Main shader section +////////////////////////////////////////////////////////////////////////////// + +float4 main( + +#if LIGHT_TYPE == LIGHT_DIRECTIONAL + float2 texCoord : TEXCOORD0, + float3 ray : TEXCOORD1, +#else + float4 projPos : TEXCOORD0, +#endif + + uniform sampler Tex0: register(s0), + uniform sampler Tex1: register(s1), + +#if LIGHT_TYPE != LIGHT_POINT + uniform float3 lightDir, +#endif + +#if LIGHT_TYPE == LIGHT_SPOT + uniform float4 spotParams, +#endif + +#if LIGHT_TYPE != LIGHT_DIRECTIONAL + uniform float vpWidth, + uniform float vpHeight, + uniform float3 farCorner, + uniform float flip, +#endif + +#ifdef IS_SHADOW_CASTER + uniform float4x4 invView, + uniform float4x4 shadowViewProjMat, + uniform sampler ShadowTex : register(s2), + uniform float3 shadowCamPos, + uniform float shadowFarClip, +#endif + + uniform float farClipDistance, + // Attributes of light + uniform float4 lightDiffuseColor, + uniform float4 lightSpecularColor, + uniform float4 lightFalloff, + uniform float3 lightPos + ) : COLOR +{ + + //None directional lights have some calculations to do in the beginning of the pixel shader +#if LIGHT_TYPE != LIGHT_DIRECTIONAL + projPos /= projPos.w; + // -1 is because generally +Y is down for textures but up for the screen + float2 texCoord = float2(projPos.x, projPos.y * -1 * flip) * 0.5 + 0.5; + // Texture coordinate magic, this compensates for jitter + texCoord = fixUV(texCoord, float2(vpWidth, vpHeight)); + float3 ray = float3(projPos.x, projPos.y * flip, 1) * farCorner; +#endif + + float4 a0 = tex2D(Tex0, texCoord); // Attribute 0: Diffuse color+shininess + float4 a1 = tex2D(Tex1, texCoord); // Attribute 1: Normal+depth + + // Attributes + float3 colour = a0.rgb; + float specularity = a0.a; + float distance = a1.w; // Distance from viewer (w) + float3 normal = a1.xyz; + + // Calculate position of texel in view space + float3 viewPos = normalize(ray)*distance*farClipDistance; + + // Calculate light direction and distance +#if LIGHT_TYPE == LIGHT_DIRECTIONAL + float3 objToLightDir = -lightDir.xyz; +#else + float3 objToLightVec = lightPos - viewPos; + float len_sq = dot(objToLightVec, objToLightVec); + float len = sqrt(len_sq); + float3 objToLightDir = objToLightVec/len; +#endif + +#ifdef IS_SHADOW_CASTER + #if LIGHT_TYPE == LIGHT_DIRECTIONAL + checkShadow(ShadowTex, viewPos, invView, shadowViewProjMat, shadowFarClip, shadowCamPos); + #else + checkShadow(ShadowTex, viewPos, invView, shadowViewProjMat, shadowFarClip, len); + #endif +#endif + + // Calculate diffuse colour + float3 total_light_contrib; + total_light_contrib = max(0.0,dot(objToLightDir, normal)) * lightDiffuseColor.rgb; + +#if IS_SPECULAR + // Calculate specular component + float3 viewDir = -normalize(viewPos); + float3 h = normalize(viewDir + objToLightDir); + float3 light_specular = pow(dot(normal, h),32.0) * lightSpecularColor.rgb; + + total_light_contrib += specularity * light_specular; +#endif + +#if IS_ATTENUATED + clip(lightFalloff.x - len); + // Calculate attenuation + float attenuation = dot(lightFalloff.yzw, float3(1.0, len, len_sq)); + total_light_contrib /= attenuation; +#endif + +#if LIGHT_TYPE == LIGHT_SPOT + float spotlightAngle = saturate(dot(lightDir.xyz, -objToLightDir)); + float spotFalloff = saturate((spotlightAngle - spotParams.x) / (spotParams.y - spotParams.x)); + total_light_contrib *= (1-spotFalloff); +#endif + + return float4(total_light_contrib*colour, 0.0); +} diff --git a/res/dist/media/DeferredShadingMedia/DeferredShading/post/LightMaterial_vs.cg b/res/dist/media/DeferredShadingMedia/DeferredShading/post/LightMaterial_vs.cg new file mode 100644 index 00000000000..a9b3bf4c1d8 --- /dev/null +++ b/res/dist/media/DeferredShadingMedia/DeferredShading/post/LightMaterial_vs.cg @@ -0,0 +1,53 @@ +/****************************************************************************** +Copyright (c) W.J. van der Laan + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +******************************************************************************/ +/** Deferred shading framework + // W.J. :wumpus: van der Laan 2005 // + + Post shader: Light geometry material +*/ + +void main( + float4 Pos: POSITION, + + out float4 oPos: POSITION, + out float4 oTexCoord : TEXCOORD0, + + uniform float4x4 worldViewProj + ) +{ + float4 projPos = mul(worldViewProj, Pos); + oTexCoord = projPos; + + oPos = projPos; + + // projPos is now in nonhomogeneous 2d space -- this makes sure no perspective interpolation is + // done that could mess with our concept. + //projPos = projPos/projPos.w; + //oRay = float3(projPos.x, projPos.y * flip, 1) * farCorner; + + + // -1 is because generally +Y is down for textures but up for the screen + //float2 uv = float2(projPos.x, projPos.y * -1) * 0.5 + 0.5; + + // Texture coordinate magic, this compensates for jitter + //float2 texCoord = float2(projPos[0]/2+0.5, -projPos[1]/2+0.5); + //oTexCoord = fixUV(uv, float2(vpWidth, vpHeight)); +} diff --git a/res/dist/media/DeferredShadingMedia/DeferredShading/post/ShowColour_ps.cg b/res/dist/media/DeferredShadingMedia/DeferredShading/post/ShowColour_ps.cg new file mode 100644 index 00000000000..77a4f11e71c --- /dev/null +++ b/res/dist/media/DeferredShadingMedia/DeferredShading/post/ShowColour_ps.cg @@ -0,0 +1,41 @@ +/****************************************************************************** +Copyright (c) W.J. van der Laan + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +******************************************************************************/ +/** Deferred shading framework + // W.J. :wumpus: van der Laan 2005 // + + Post shader: Debug, show colour channel +*/ + + +float4 main( + float2 texCoord: TEXCOORD0, + float2 projCoord: TEXCOORD1, + + uniform sampler Tex0: register(s0), + uniform sampler Tex1: register(s1) + ) : COLOR +{ + float4 a0 = tex2D(Tex0, texCoord); // Attribute 0: Diffuse color+shininess + float4 a1 = tex2D(Tex1, texCoord); // Attribute 1: Normal+depth + + return float4(a0.xyz, 0); +} + diff --git a/res/dist/media/DeferredShadingMedia/DeferredShading/post/ShowDS_ps.cg b/res/dist/media/DeferredShadingMedia/DeferredShading/post/ShowDS_ps.cg new file mode 100644 index 00000000000..68c268db53d --- /dev/null +++ b/res/dist/media/DeferredShadingMedia/DeferredShading/post/ShowDS_ps.cg @@ -0,0 +1,40 @@ +/****************************************************************************** +Copyright (c) W.J. van der Laan + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +******************************************************************************/ +/** Deferred shading framework + // W.J. :wumpus: van der Laan 2005 // + + Post shader: Debug, show depth and specularity channel +*/ +float4 main( + float2 texCoord: TEXCOORD0, + float2 projCoord: TEXCOORD1, + + uniform sampler Tex0: register(s0), + uniform sampler Tex1: register(s1) + ) : COLOR +{ + float4 a0 = tex2D(Tex0, texCoord); // Attribute 0: Diffuse color+shininess + float4 a1 = tex2D(Tex1, texCoord); // Attribute 1: Normal+depth + + //Get the 3rd root of the depth to show up-close differences + return float4(pow(a1.w,0.33), 0, a0.w, 0); +} + diff --git a/res/dist/media/DeferredShadingMedia/DeferredShading/post/ShowNormal_ps.cg b/res/dist/media/DeferredShadingMedia/DeferredShading/post/ShowNormal_ps.cg new file mode 100644 index 00000000000..aed75674d72 --- /dev/null +++ b/res/dist/media/DeferredShadingMedia/DeferredShading/post/ShowNormal_ps.cg @@ -0,0 +1,39 @@ +/****************************************************************************** +Copyright (c) W.J. van der Laan + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +******************************************************************************/ +/** Deferred shading framework + // W.J. :wumpus: van der Laan 2005 // + + Post shader: Debug, show normal channel +*/ +float4 main( + float2 texCoord: TEXCOORD0, + float2 projCoord: TEXCOORD1, + + uniform sampler Tex0: register(s0), + uniform sampler Tex1: register(s1) + ) : COLOR +{ + float4 a0 = tex2D(Tex0, texCoord); // Attribute 0: Diffuse color+shininess + float4 a1 = tex2D(Tex1, texCoord); // Attribute 1: Normal+depth + + return float4((a1.xyz+1)*0.5,0); +} + diff --git a/res/dist/media/DeferredShadingMedia/DeferredShading/post/vs.cg b/res/dist/media/DeferredShadingMedia/DeferredShading/post/vs.cg new file mode 100644 index 00000000000..8746e72c926 --- /dev/null +++ b/res/dist/media/DeferredShadingMedia/DeferredShading/post/vs.cg @@ -0,0 +1,54 @@ +/****************************************************************************** +Copyright (c) W.J. van der Laan + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +Software, and to permit persons to whom the Software is furnished to do so, subject +to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +******************************************************************************/ +/** Deferred shading framework + // W.J. :wumpus: van der Laan 2005 // + + Post shader: Generic fullscreen quad +*/ +void main( + float4 Pos: POSITION, + + out float4 oPos: POSITION, + out float2 oTexCoord: TEXCOORD0, + + out float3 oRay : TEXCOORD1, + + uniform float3 farCorner, + uniform float flip + ) +{ + // Clean up inaccuracies + Pos.xy = sign(Pos.xy); + + oPos = float4(Pos.xy, 0, 1); + oPos.y *= flip; + + // Image-space + oTexCoord.x = 0.5 * (1 + Pos.x); + oTexCoord.y = 0.5 * (1 - Pos.y); + + // This ray will be interpolated and will be the ray from the camera + // to the far clip plane, per pixel + oRay = farCorner * float3(Pos.xy, 1); +} + + + diff --git a/res/dist/media/DeferredShadingMedia/ShadowCaster.cg b/res/dist/media/DeferredShadingMedia/ShadowCaster.cg new file mode 100644 index 00000000000..d3336a423a8 --- /dev/null +++ b/res/dist/media/DeferredShadingMedia/ShadowCaster.cg @@ -0,0 +1,25 @@ +void ShadowCasterVP( + float4 iPosition : POSITION, + + out float4 oPosition : POSITION, + out float3 oViewPos : TEXCOORD0, + + uniform float4x4 cWorldViewProj, + uniform float4x4 cWorldView + ) +{ + oPosition = mul(cWorldViewProj, iPosition); + oViewPos = mul(cWorldView, iPosition).xyz; +} + +void ShadowCasterFP( + float3 iViewPos : TEXCOORD0, + + out float4 oColor : COLOR0, + + uniform float cFarDistance + ) +{ + float depth = length(iViewPos) / cFarDistance; + oColor.rgba = float4(depth, depth, depth, 1); +} diff --git a/res/dist/media/DeferredShadingMedia/ShadowCaster.material b/res/dist/media/DeferredShadingMedia/ShadowCaster.material new file mode 100644 index 00000000000..7ea57e9557f --- /dev/null +++ b/res/dist/media/DeferredShadingMedia/ShadowCaster.material @@ -0,0 +1,15 @@ +material DeferredShading/Shadows/Caster +{ + technique + { + pass + { + vertex_program_ref DeferredShading/Shadows/CasterVP + { + } + fragment_program_ref DeferredShading/Shadows/CasterFP + { + } + } + } +} diff --git a/res/dist/media/DeferredShadingMedia/ShadowCaster.program b/res/dist/media/DeferredShadingMedia/ShadowCaster.program new file mode 100644 index 00000000000..1e89e3ece22 --- /dev/null +++ b/res/dist/media/DeferredShadingMedia/ShadowCaster.program @@ -0,0 +1,24 @@ +// Auxiliary lights +vertex_program DeferredShading/Shadows/CasterVP cg +{ + source ShadowCaster.cg + profiles vs_1_1 arbvp1 + entry_point ShadowCasterVP + default_params + { + param_named_auto cWorldViewProj worldviewproj_matrix + param_named_auto cWorldView worldview_matrix + } +} + +fragment_program DeferredShading/Shadows/CasterFP cg +{ + source ShadowCaster.cg + profiles ps_2_0 arbfp1 + entry_point ShadowCasterFP + + default_params + { + param_named_auto cFarDistance far_clip_distance + } +} diff --git a/res/dist/media/DeferredShadingMedia/deferred.compositor b/res/dist/media/DeferredShadingMedia/deferred.compositor new file mode 100644 index 00000000000..67f8d4766c0 --- /dev/null +++ b/res/dist/media/DeferredShadingMedia/deferred.compositor @@ -0,0 +1,147 @@ +//Postfilter generating the GBuffer +compositor DeferredShading/GBuffer +{ + technique + { + // temporary textures + texture mrt_output target_width target_height PF_FLOAT16_RGBA PF_FLOAT16_RGBA chain_scope + + target mrt_output + { + input none + pass clear + { + } + + shadows off + material_scheme GBuffer + + // everything but the lights and their meshes + // could do this with something like a visibility mask too + pass render_scene + { + //These values are synchronized with the code + first_render_queue 10 + last_render_queue 79 + } + } + } +} + +//Postfilter lighting the scene using the GBuffer +compositor DeferredShading/ShowLit +{ + + technique + { + //Reference the main Gbuffer texture + texture_ref mrt_output DeferredShading/GBuffer mrt_output + + target_output + { + input none + //We will dispatch the shadow texture rendering ourselves + shadows off + + pass clear + { + + } + + // render skies and other pre-gbuffer objects + pass render_scene + { + first_render_queue 1 + last_render_queue 9 + } + + //Render the lights and their meshes + pass render_custom DeferredLight + { + input 0 mrt_output 0 + input 1 mrt_output 1 + } + + //Render the objects that skipped rendering into the gbuffer + pass render_scene + { + material_scheme NoGBuffer + first_render_queue 10 + last_render_queue 79 + } + + //Render the post-GBuffer render queue objects + pass render_scene + { + //This value is synchronized with the code + first_render_queue 80 + } + } + } +} + +// Postfilter that shows the colour channel +compositor DeferredShading/ShowColour +{ + technique + { + //Reference the main Gbuffer texture + texture_ref mrt_output DeferredShading/GBuffer mrt_output + + target_output + { + input none + + pass render_quad + { + material DeferredShading/Post/ShowColour + input 0 mrt_output 0 + input 1 mrt_output 1 + } + } + } +} + +// Postfilter that shows the normal channel +compositor DeferredShading/ShowNormals +{ + technique + { + //Reference the main Gbuffer texture + texture_ref mrt_output DeferredShading/GBuffer mrt_output + + target_output + { + input none + + pass render_quad + { + material DeferredShading/Post/ShowNormal + input 0 mrt_output 0 + input 1 mrt_output 1 + } + } + } +} + +// Postfilter that shows the depth and specular channel +compositor DeferredShading/ShowDepthSpecular +{ + technique + { + //Reference the main Gbuffer texture + texture_ref mrt_output DeferredShading/GBuffer mrt_output + + target_output + { + input none + + pass render_quad + { + material DeferredShading/Post/ShowDS + input 0 mrt_output 0 + input 1 mrt_output 1 + } + } + } +} diff --git a/res/dist/media/DeferredShadingMedia/deferred_post.material b/res/dist/media/DeferredShadingMedia/deferred_post.material new file mode 100644 index 00000000000..a4a91923d16 --- /dev/null +++ b/res/dist/media/DeferredShadingMedia/deferred_post.material @@ -0,0 +1,148 @@ +// Post processors + +//Ambient light +material DeferredShading/AmbientLight +{ + technique + { + pass + { + lighting off + + depth_write on + depth_check on + + vertex_program_ref DeferredShading/post/vs + { + + } + fragment_program_ref DeferredShading/post/Ambient_ps + { + + } + + texture_unit + { + content_type compositor DeferredShading/GBuffer mrt_output 0 + tex_address_mode clamp + filtering none + } + texture_unit + { + content_type compositor DeferredShading/GBuffer mrt_output 1 + tex_address_mode clamp + filtering none + } + } + } +} + +//These materials don't need content_type compositor, as they get their textures from the compositor that uses them +//In a full screen quad +material DeferredShading/Post/ShowNormal +{ + technique + { + pass + { + cull_hardware none + cull_software none + depth_func always_pass + fragment_program_ref DeferredShading/post/ShowNormal_ps + { + } + vertex_program_ref DeferredShading/post/vs + { + } + texture_unit + { + tex_address_mode clamp + filtering none + } + texture_unit + { + tex_coord_set 1 + tex_address_mode clamp + filtering none + } + } + } +} +material DeferredShading/Post/ShowDS +{ + technique + { + pass + { + cull_hardware none + cull_software none + depth_func always_pass + fragment_program_ref DeferredShading/post/ShowDS_ps + { + } + vertex_program_ref DeferredShading/post/vs + { + } + texture_unit + { + tex_address_mode clamp + filtering none + } + texture_unit + { + tex_coord_set 1 + tex_address_mode clamp + filtering none + } + } + } + +} +material DeferredShading/Post/ShowColour +{ + technique + { + pass + { + cull_hardware none + cull_software none + depth_func always_pass + fragment_program_ref DeferredShading/post/ShowColour_ps + { + } + vertex_program_ref DeferredShading/post/vs + { + } + texture_unit + { + tex_address_mode clamp + filtering none + } + texture_unit + { + tex_coord_set 1 + tex_address_mode clamp + filtering none + } + } + } +} + +material DeferredShading/Post/SimpleQuad +{ + technique + { + pass + { + lighting off + depth_write off + depth_check off + + texture_unit + { + texture white.bmp + filtering none + } + } + } +} diff --git a/res/dist/media/DeferredShadingMedia/deferred_post.program b/res/dist/media/DeferredShadingMedia/deferred_post.program new file mode 100644 index 00000000000..28800f7d443 --- /dev/null +++ b/res/dist/media/DeferredShadingMedia/deferred_post.program @@ -0,0 +1,85 @@ +fragment_program DeferredShading/post/Ambient_ps cg +{ + source DeferredShading/post/Ambient_ps.cg + profiles ps_2_0 arbfp1 + entry_point main + + default_params + { + param_named_auto ambientColor ambient_light_colour 0 + param_named_auto proj projection_matrix + param_named_auto farClipDistance far_clip_distance + } +} + +fragment_program DeferredShading/post/ShowNormal_ps cg +{ + source DeferredShading/post/ShowNormal_ps.cg + profiles ps_2_0 arbfp1 + entry_point main +} + +fragment_program DeferredShading/post/ShowDS_ps cg +{ + source DeferredShading/post/ShowDS_ps.cg + profiles ps_2_0 arbfp1 + entry_point main +} + +fragment_program DeferredShading/post/ShowColour_ps cg +{ + source DeferredShading/post/ShowColour_ps.cg + profiles ps_2_0 arbfp1 + entry_point main +} + +fragment_program DeferredShading/post/ShowNormal_ps cg +{ + source DeferredShading/post/ShowNormal_ps.cg + profiles ps_2_0 arbfp1 + entry_point main +} + +fragment_program DeferredShading/post/ShowDS_ps cg +{ + source DeferredShading/post/ShowDS_ps.cg + profiles ps_2_0 arbfp1 + entry_point main +} + +fragment_program DeferredShading/post/ShowColour_ps cg +{ + source DeferredShading/post/ShowColour_ps.cg + profiles ps_2_0 arbfp1 + entry_point main +} + +// Auxiliary lights +// cg +vertex_program DeferredShading/post/LightMaterial_vs cg +{ + source DeferredShading/post/LightMaterial_vs.cg + profiles vs_1_1 arbvp1 + entry_point main + default_params + { + param_named_auto worldViewProj worldviewproj_matrix + //param_named_auto invProj inverse_projection_matrix + //param_named_auto vpWidth viewport_width + //param_named_auto vpHeight viewport_height + } +} + +// Post processors +vertex_program DeferredShading/post/vs cg +{ + source DeferredShading/post/vs.cg + profiles vs_1_1 arbvp1 + entry_point main + default_params + { + //param_named_auto invProj inverse_projection_matrix + param_named_auto flip render_target_flipping + param_named farCorner float3 1 1 1 + } +} diff --git a/res/dist/media/DeferredShadingMedia/deferred_post_minilight.material b/res/dist/media/DeferredShadingMedia/deferred_post_minilight.material new file mode 100644 index 00000000000..99d22300026 --- /dev/null +++ b/res/dist/media/DeferredShadingMedia/deferred_post_minilight.material @@ -0,0 +1,71 @@ +// Auxiliary lights + +// Reference material [geometry] +material DeferredShading/LightMaterial/Geometry +{ + technique DeferredTechnique + { + pass DeferredPass + { + // Don't disable depth test, because the light doesn't have to be rendered + // if the bounding geometry is obscured. + scene_blend add + depth_write off + depth_check on + lighting off + + texture_unit GBuffer1 + { + content_type compositor DeferredShading/GBuffer mrt_output 0 + tex_address_mode clamp + filtering none + } + texture_unit GBuffer2 + { + content_type compositor DeferredShading/GBuffer mrt_output 1 + tex_address_mode clamp + filtering none + } + } + } +} + +// Reference material [geometry w/shadows] +material DeferredShading/LightMaterial/GeometryShadow : DeferredShading/LightMaterial/Geometry +{ + technique DeferredTechnique + { + pass DeferredPass + { + texture_unit ShadowMap + { + content_type shadow + } + } + } +} + +// Reference material [quad] +material DeferredShading/LightMaterial/Quad : DeferredShading/LightMaterial/Geometry +{ + technique DeferredTechnique + { + pass DeferredPass + { + depth_check off + } + } +} + + +// Reference material [quad w/shadows] +material DeferredShading/LightMaterial/QuadShadow : DeferredShading/LightMaterial/GeometryShadow +{ + technique DeferredTechnique + { + pass DeferredPass + { + depth_check off + } + } +} diff --git a/res/dist/media/DeferredShadingMedia/deferreddemo.material b/res/dist/media/DeferredShadingMedia/deferreddemo.material new file mode 100644 index 00000000000..98d9481d4e9 --- /dev/null +++ b/res/dist/media/DeferredShadingMedia/deferreddemo.material @@ -0,0 +1,73 @@ +// Materials for deferred shading test +// Sky box +material DeferredDemo/SkyBox +{ + technique + { + pass + { + depth_write off + lighting off + texture_unit + { + cubic_texture evening.jpg separateUV + tex_address_mode clamp + } + } + } +} +// Ground plane +material DeferredDemo/Ground +{ + technique + { + pass main + { + texture_unit + { + texture grass_1024.jpg + } + } + } +} +// Rock wall texture [bumpmapped] +material DeferredDemo/RockWall +{ + technique + { + pass main + { + specular 0 0 0 1 0.6 + texture_unit + { + texture rockwall.tga + } + //This directive will allow the framework to pick up on the fact + //that this texture is a normal map + texture_unit NormalMap + { + texture rockwall_NH.tga + } + } + } +} + +// Athena texture [bumpmapped, untextured] +material DeferredDemo/DeferredAthena +{ + technique + { + pass main + { + diffuse 0.7 0.7 0.7 + specular 1.0 1.0 1.0 1.0 0.5 + + texture_unit + { + //The fact that the texture has 'normal' in the name will allow the framework + //to understand that it is a normal map + texture atheneNormalMap.png + } + } + } +} diff --git a/res/dist/media/DeferredShadingMedia/ssao.cg b/res/dist/media/DeferredShadingMedia/ssao.cg new file mode 100644 index 00000000000..de610466746 --- /dev/null +++ b/res/dist/media/DeferredShadingMedia/ssao.cg @@ -0,0 +1,178 @@ +struct VIn +{ + float4 p : POSITION; + float3 n : NORMAL; + float2 uv : TEXCOORD0; +}; + +struct VOut +{ + float4 p : POSITION; + float2 uv : TEXCOORD0; + float3 ray : TEXCOORD1; +}; + +struct PIn +{ + float2 uv : TEXCOORD0; + float3 ray : TEXCOORD1; +}; + +VOut ssao_vs(VIn IN, uniform float4x4 wvp, uniform float3 farCorner) +{ + VOut OUT; + OUT.p = mul(wvp, IN.p); + // clean up inaccuracies for the UV coords + float2 uv = sign(IN.p); + // convert to image space + uv = (float2(uv.x, -uv.y) + 1.0) * 0.5; + OUT.uv = uv; + // calculate the correct ray (modify XY parameters based on screen-space quad XY) + OUT.ray = farCorner * float3(sign(IN.p.xy), 1); + return OUT; +} + +float3 computeZ(float2 xy) +{ + return float3(xy, sqrt(1.0 - dot(xy, xy))); +} + +// for ps_3_0, we want to use tex2Dlod because it's faster +ps_3_0 float4 TEX2DLOD(sampler2D map, float2 uv) +{ + return tex2Dlod(map, float4(uv.xy, 0, 0)); +} + +float4 TEX2DLOD(sampler2D map, float2 uv) +{ + return tex2D(map, uv); +} + +float4 ssao_ps( + PIn IN, + uniform float4x4 ptMat, + uniform float far, + uniform sampler2D geomMap : TEXUNIT0, + uniform sampler2D randMap : TEXUNIT1): COLOR0 +{ + #define MAX_RAND_SAMPLES 14 + + const float3 RAND_SAMPLES[MAX_RAND_SAMPLES] = + { + float3(1, 0, 0), + float3( -1, 0, 0), + float3(0, 1, 0), + float3(0, -1, 0), + float3(0, 0, 1), + float3(0, 0, -1), + normalize(float3(1, 1, 1)), + normalize(float3(-1, 1, 1)), + normalize(float3(1, -1, 1)), + normalize(float3(1, 1, -1)), + normalize(float3(-1, -1, 1)), + normalize(float3(-1, 1, -1)), + normalize(float3(1, -1, -1)), + normalize(float3(-1, -1, -1)) + }; + + // constant expressin != const int :( + #define NUM_BASE_SAMPLES 6 + + // random normal lookup from a texture and expand to [-1..1] + float3 randN = TEX2DLOD(randMap, IN.uv * 24).xyz * 2.0 - 1.0; + float4 geom = TEX2DLOD(geomMap, IN.uv); + float depth = geom.w; + + // IN.ray will be distorted slightly due to interpolation + // it should be normalized here + float3 viewPos = IN.ray * depth; + + // by computing Z manually, we lose some accuracy under extreme angles + // considering this is just for bias, this loss is acceptable + float3 viewNorm = geom.xyz;//computeZ(geom.yz); + + // accumulated occlusion factor + float occ = 0; + for (int i = 0; i < NUM_BASE_SAMPLES; ++i) + { + // reflected direction to move in for the sphere + // (based on random samples and a random texture sample) + // bias the random direction away from the normal + // this tends to minimize self occlusion + float3 randomDir = reflect(RAND_SAMPLES[i], randN) + viewNorm; + + // move new view-space position back into texture space + #define RADIUS 0.2125 + float4 nuv = mul(ptMat, float4(viewPos.xyz + randomDir * RADIUS, 1)); + nuv.xy /= nuv.w; + + // compute occlusion based on the (scaled) Z difference + float zd = saturate(far * (depth - TEX2DLOD(geomMap, nuv.xy).w)); + // this is a sample occlusion function, you can always play with + // other ones, like 1.0 / (1.0 + zd * zd) and stuff + occ += saturate(pow(1.0 - zd, 11) + zd); + } + occ /= NUM_BASE_SAMPLES; + + return float4(occ, occ, occ, 1); +} + +#define NUM_BLUR_SAMPLES 8 + +float4 ssaoBlurX_ps(float2 uv : TEXCOORD0, + uniform float4 invTexSize, + uniform sampler2D map : TEXUNIT0, uniform sampler2D geomMap : TEXUNIT1): COLOR0 +{ +// return TEX2DLOD(ssaoMap, uv); + float2 o = float2(invTexSize.x, 0); + float4 sum = TEX2DLOD(map, uv) * (NUM_BLUR_SAMPLES + 1); + float denom = NUM_BLUR_SAMPLES + 1; + float4 geom = TEX2DLOD(geomMap, uv); + for (int i = 1; i <= NUM_BLUR_SAMPLES; ++i) + { + float2 nuv = uv + o * i; + float4 nGeom = TEX2DLOD(geomMap, nuv); + float coef = (NUM_BLUR_SAMPLES + 1 - i) * (dot(geom.xyz, nGeom.xyz) > 0.9); + sum += TEX2DLOD(map, nuv) * coef; + denom += coef; + } + for (int i = 1; i <= 4; ++i) + { + float2 nuv = uv + o * -i; + float4 nGeom = TEX2DLOD(geomMap, nuv); + float coef = (NUM_BLUR_SAMPLES + 1 - i) * (dot(geom.xyz, nGeom.xyz) > 0.9); + sum += TEX2DLOD(map, nuv) * coef; + denom += coef; + } + return sum / denom; +} + +float4 ssaoBlurY_ps(float2 uv : TEXCOORD0, + uniform float4 invTexSize, + uniform sampler2D map : TEXUNIT0, uniform sampler2D geomMap : TEXUNIT1): COLOR0 +{ +// return TEX2DLOD(map, uv); + float2 o = float2(0, invTexSize.y); + float4 sum = TEX2DLOD(map, uv) * (NUM_BLUR_SAMPLES + 1); + float denom = NUM_BLUR_SAMPLES + 1; + float4 geom = TEX2DLOD(geomMap, uv); + for (int i = 1; i <= NUM_BLUR_SAMPLES; ++i) + { + float2 nuv = uv + o * i; + float4 nGeom = TEX2DLOD(geomMap, nuv); + float coef = (NUM_BLUR_SAMPLES + 1 - i) * (dot(geom.xyz, nGeom.xyz) > 0.9); + sum += TEX2DLOD(map, nuv) * coef; + denom += coef; + } + for (int i = 1; i <= 4; ++i) + { + float2 nuv = uv + o * -i; + float4 nGeom = TEX2DLOD(geomMap, nuv); + float coef = (NUM_BLUR_SAMPLES + 1 - i) * (dot(geom.xyz, nGeom.xyz) > 0.9); + sum += TEX2DLOD(map, nuv) * coef; + denom += coef; + } + return sum / denom; +} + + diff --git a/res/dist/media/DeferredShadingMedia/ssao.compositor b/res/dist/media/DeferredShadingMedia/ssao.compositor new file mode 100644 index 00000000000..bd66274491c --- /dev/null +++ b/res/dist/media/DeferredShadingMedia/ssao.compositor @@ -0,0 +1,93 @@ +compositor DeferredShading/SSAO +{ + technique + { + compositor_logic SSAOLogic + + texture_ref geom DeferredShading/GBuffer mrt_output + texture scene target_width target_height PF_R8G8B8A8 + texture ssao target_width_scaled 0.5 target_height_scaled 0.5 PF_R8G8B8 + texture ssaoBlurX target_width target_height PF_R8G8B8 + texture ssaoBlurY target_width target_height PF_R8G8B8 + + // the scene we want to modulate + target scene + { + input previous + } + + + + target ssao + { + input none + + pass clear + { + } + + pass render_quad + { + // our SSAO listener number + identifier 42 + + material ssao + // pass in the "geometry map" + input 0 geom 1 + } + } + + target ssaoBlurX + { + input none + + pass clear + { + } + + pass render_quad + { + identifier 43 + + material ssaoBlurX + input 0 ssao + input 1 geom 1 + } + } + + target ssaoBlurY + { + input none + + pass clear + { + } + + pass render_quad + { + identifier 43 + + material ssaoBlurY + input 0 ssaoBlurX + input 1 geom 1 + } + } + + + + target_output + { + input none + + pass render_quad + { + // just output something, for example, use a modulate + // material to just multiply the scene by the ssao + material modulate + input 0 scene + input 1 ssaoBlurY + //input 1 ssao + } + } + } +} diff --git a/res/dist/media/DeferredShadingMedia/ssao.material b/res/dist/media/DeferredShadingMedia/ssao.material new file mode 100644 index 00000000000..580a60ed28f --- /dev/null +++ b/res/dist/media/DeferredShadingMedia/ssao.material @@ -0,0 +1,148 @@ + +// full screen quad with camera-to-pixel ray calculations + +vertex_program ssao_vs cg +{ + source ssao.cg + profiles vs_1_1 arbvp1 + entry_point ssao_vs + default_params + { + param_named_auto wvp worldviewproj_matrix + } +} + +fragment_program ssao_ps cg +{ + source ssao.cg + entry_point ssao_ps + // will run on anything with pixel shader 2.b and up + profiles ps_2_x arbfp1 + default_params + { + } +} + +fragment_program ssaoBlurX_ps cg +{ + source ssao.cg + entry_point ssaoBlurX_ps + profiles ps_2_x arbfp1 + default_params + { + param_named_auto invTexSize inverse_texture_size 0 + } +} + +fragment_program ssaoBlurY_ps cg +{ + source ssao.cg + entry_point ssaoBlurY_ps + profiles ps_2_x arbfp1 + default_params + { + param_named_auto invTexSize inverse_texture_size 0 + } +} + +material ssao +{ + technique + { + pass + { + vertex_program_ref ssao_vs + { + } + + fragment_program_ref ssao_ps + { + } + + texture_unit geomMap + { + tex_address_mode clamp + filtering bilinear + } + + texture_unit randMap + { + texture random.png + filtering none + } + } + } +} + +material ssaoBlurX +{ + technique + { + pass + { + fragment_program_ref ssaoBlurX_ps + { + } + + texture_unit map + { + tex_address_mode clamp + filtering bilinear + } + + texture_unit geomMap + { + tex_address_mode clamp + filtering bilinear + } + } + } +} + +material ssaoBlurY +{ + technique + { + pass + { + fragment_program_ref ssaoBlurY_ps + { + } + + texture_unit map + { + tex_address_mode clamp + filtering bilinear + } + + texture_unit geomMap + { + tex_address_mode clamp + filtering bilinear + } + } + } +} + +material modulate +{ + technique + { + pass + { + lighting off + + texture_unit + { + texture white.bmp + filtering bilinear + } + + texture_unit + { + texture white.bmp + filtering bilinear + } + } + } +} diff --git a/res/dist/media/PCZAppMedia/Carpet_Diamond_Olive.jpg b/res/dist/media/PCZAppMedia/Carpet_Diamond_Olive.jpg new file mode 100644 index 00000000000..c94e0471544 Binary files /dev/null and b/res/dist/media/PCZAppMedia/Carpet_Diamond_Olive.jpg differ diff --git a/res/dist/media/PCZAppMedia/Metal_Brass_Ceiling.jpg b/res/dist/media/PCZAppMedia/Metal_Brass_Ceiling.jpg new file mode 100644 index 00000000000..c1123dbb38f Binary files /dev/null and b/res/dist/media/PCZAppMedia/Metal_Brass_Ceiling.jpg differ diff --git a/res/dist/media/PCZAppMedia/Metal_Embossed.jpg b/res/dist/media/PCZAppMedia/Metal_Embossed.jpg new file mode 100644 index 00000000000..6902ca8ab46 Binary files /dev/null and b/res/dist/media/PCZAppMedia/Metal_Embossed.jpg differ diff --git a/res/dist/media/PCZAppMedia/Metal_Rusted.jpg b/res/dist/media/PCZAppMedia/Metal_Rusted.jpg new file mode 100644 index 00000000000..a98a19a9f21 Binary files /dev/null and b/res/dist/media/PCZAppMedia/Metal_Rusted.jpg differ diff --git a/res/dist/media/PCZAppMedia/Metal_Rusted1.jpg b/res/dist/media/PCZAppMedia/Metal_Rusted1.jpg new file mode 100644 index 00000000000..a98a19a9f21 Binary files /dev/null and b/res/dist/media/PCZAppMedia/Metal_Rusted1.jpg differ diff --git a/res/dist/media/PCZAppMedia/Metal_Steel_Textured.jpg b/res/dist/media/PCZAppMedia/Metal_Steel_Textured.jpg new file mode 100644 index 00000000000..957a0ade481 Binary files /dev/null and b/res/dist/media/PCZAppMedia/Metal_Steel_Textured.jpg differ diff --git a/res/dist/media/PCZAppMedia/Metal_Steel_Textured_White.jpg b/res/dist/media/PCZAppMedia/Metal_Steel_Textured_White.jpg new file mode 100644 index 00000000000..53e8b3859fa Binary files /dev/null and b/res/dist/media/PCZAppMedia/Metal_Steel_Textured_White.jpg differ diff --git a/res/dist/media/PCZAppMedia/ROOM.material b/res/dist/media/PCZAppMedia/ROOM.material new file mode 100644 index 00000000000..c668661c164 --- /dev/null +++ b/res/dist/media/PCZAppMedia/ROOM.material @@ -0,0 +1,149 @@ +material SketchupDefault +{ + technique + { + pass + { + diffuse 0.882352941176471 0.882352941176471 0.784313725490196 + } + } +} +material Metal_Brass_Ceiling +{ + technique + { + pass + { + diffuse 1 1 1 1.0 + texture_unit + { + texture Metal_Brass_Ceiling.jpg + } + } + } +} +material Metal_Embossed +{ + technique + { + pass + { + diffuse 1 1 1 1.0 + texture_unit + { + texture Metal_Embossed.jpg + } + } + } +} +material Metal_Steel_Textured_White +{ + technique + { + pass + { + diffuse 1 1 1 1.0 + texture_unit + { + texture Metal_Steel_Textured_White.jpg + } + } + } +} +material Metal_Steel_Textured +{ + technique + { + pass + { + diffuse 1 1 1 1.0 + texture_unit + { + texture Metal_Steel_Textured.jpg + } + } + } +} +material Metal_Rusted +{ + technique + { + pass + { + diffuse 1 1 1 1.0 + texture_unit + { + texture Metal_Rusted.jpg + } + } + } +} +material Material1 +{ + technique + { + pass + { + diffuse 0.250980392156863 0.250980392156863 0.250980392156863 1.0 + } + } +} +material [Metal_Rusted]1 +{ + technique + { + pass + { + diffuse 1 1 1 1.0 + texture_unit + { + texture Metal_Rusted.jpg + } + } + } +} +material Carpet_Diamond_Olive +{ + technique + { + pass + { + diffuse 1 1 1 1.0 + texture_unit + { + texture Carpet_Diamond_Olive.jpg + } + } + } +} +material Roofing_Tile_Spanish +{ + technique + { + pass + { + diffuse 1 1 1 1.0 + texture_unit + { + texture Roofing_Tile_Spanish.jpg + } + } + } +} +material TransparentGlassTinted +{ + technique + { + pass + { + scene_blend add + depth_write off + cull_hardware none + + texture_unit + { + texture Translucent_Glass_Tinted.jpg + } + } + } +} diff --git a/res/dist/media/PCZAppMedia/ROOM_NX.mesh b/res/dist/media/PCZAppMedia/ROOM_NX.mesh new file mode 100644 index 00000000000..a41935ce21b Binary files /dev/null and b/res/dist/media/PCZAppMedia/ROOM_NX.mesh differ diff --git a/res/dist/media/PCZAppMedia/ROOM_NY.mesh b/res/dist/media/PCZAppMedia/ROOM_NY.mesh new file mode 100644 index 00000000000..02d5533423e Binary files /dev/null and b/res/dist/media/PCZAppMedia/ROOM_NY.mesh differ diff --git a/res/dist/media/PCZAppMedia/ROOM_NZ.mesh b/res/dist/media/PCZAppMedia/ROOM_NZ.mesh new file mode 100644 index 00000000000..b2f8144a262 Binary files /dev/null and b/res/dist/media/PCZAppMedia/ROOM_NZ.mesh differ diff --git a/res/dist/media/PCZAppMedia/ROOM_PX.mesh b/res/dist/media/PCZAppMedia/ROOM_PX.mesh new file mode 100644 index 00000000000..8d7b92eec27 Binary files /dev/null and b/res/dist/media/PCZAppMedia/ROOM_PX.mesh differ diff --git a/res/dist/media/PCZAppMedia/ROOM_PY.mesh b/res/dist/media/PCZAppMedia/ROOM_PY.mesh new file mode 100644 index 00000000000..ec26eecc9bf Binary files /dev/null and b/res/dist/media/PCZAppMedia/ROOM_PY.mesh differ diff --git a/res/dist/media/PCZAppMedia/ROOM_PZ.mesh b/res/dist/media/PCZAppMedia/ROOM_PZ.mesh new file mode 100644 index 00000000000..a05e2a33ea8 Binary files /dev/null and b/res/dist/media/PCZAppMedia/ROOM_PZ.mesh differ diff --git a/res/dist/media/PCZAppMedia/Roofing_Tile_Spanish.jpg b/res/dist/media/PCZAppMedia/Roofing_Tile_Spanish.jpg new file mode 100644 index 00000000000..78910327489 Binary files /dev/null and b/res/dist/media/PCZAppMedia/Roofing_Tile_Spanish.jpg differ diff --git a/res/dist/media/PCZAppMedia/Translucent_Glass_Tinted.jpg b/res/dist/media/PCZAppMedia/Translucent_Glass_Tinted.jpg new file mode 100644 index 00000000000..7409a5921d3 Binary files /dev/null and b/res/dist/media/PCZAppMedia/Translucent_Glass_Tinted.jpg differ diff --git a/res/dist/media/PCZAppMedia/Translucent_Glass_Tinted1.jpg b/res/dist/media/PCZAppMedia/Translucent_Glass_Tinted1.jpg new file mode 100644 index 00000000000..7409a5921d3 Binary files /dev/null and b/res/dist/media/PCZAppMedia/Translucent_Glass_Tinted1.jpg differ diff --git a/res/dist/media/PCZAppMedia/Wood_Floor.jpg b/res/dist/media/PCZAppMedia/Wood_Floor.jpg new file mode 100644 index 00000000000..97b7a286168 Binary files /dev/null and b/res/dist/media/PCZAppMedia/Wood_Floor.jpg differ diff --git a/res/dist/media/PCZAppMedia/building_exterior.mesh b/res/dist/media/PCZAppMedia/building_exterior.mesh new file mode 100644 index 00000000000..22cfba050b6 Binary files /dev/null and b/res/dist/media/PCZAppMedia/building_exterior.mesh differ diff --git a/res/dist/media/PCZAppMedia/room_nxnynz.mesh b/res/dist/media/PCZAppMedia/room_nxnynz.mesh new file mode 100644 index 00000000000..ae554c85d2a Binary files /dev/null and b/res/dist/media/PCZAppMedia/room_nxnynz.mesh differ diff --git a/res/dist/media/PCZAppMedia/room_nxpx.mesh b/res/dist/media/PCZAppMedia/room_nxpx.mesh new file mode 100644 index 00000000000..4a289820354 Binary files /dev/null and b/res/dist/media/PCZAppMedia/room_nxpx.mesh differ diff --git a/res/dist/media/PCZAppMedia/room_nxpxnypynzpz.mesh b/res/dist/media/PCZAppMedia/room_nxpxnypynzpz.mesh new file mode 100644 index 00000000000..9c46aa478f7 Binary files /dev/null and b/res/dist/media/PCZAppMedia/room_nxpxnypynzpz.mesh differ diff --git a/res/dist/media/PCZAppMedia/room_nxpxnz.mesh b/res/dist/media/PCZAppMedia/room_nxpxnz.mesh new file mode 100644 index 00000000000..4746045ef9b Binary files /dev/null and b/res/dist/media/PCZAppMedia/room_nxpxnz.mesh differ diff --git a/res/dist/media/PCZAppMedia/room_nxpxnzpz.mesh b/res/dist/media/PCZAppMedia/room_nxpxnzpz.mesh new file mode 100644 index 00000000000..d8a8b1de6bd Binary files /dev/null and b/res/dist/media/PCZAppMedia/room_nxpxnzpz.mesh differ diff --git a/res/dist/media/PCZAppMedia/room_nxpxpz.mesh b/res/dist/media/PCZAppMedia/room_nxpxpz.mesh new file mode 100644 index 00000000000..8a37c34ce9b Binary files /dev/null and b/res/dist/media/PCZAppMedia/room_nxpxpz.mesh differ diff --git a/res/dist/media/PCZAppMedia/room_nxpynz.mesh b/res/dist/media/PCZAppMedia/room_nxpynz.mesh new file mode 100644 index 00000000000..8b41888293a Binary files /dev/null and b/res/dist/media/PCZAppMedia/room_nxpynz.mesh differ diff --git a/res/dist/media/PCZAppMedia/room_nxpz.mesh b/res/dist/media/PCZAppMedia/room_nxpz.mesh new file mode 100644 index 00000000000..afac2d77796 Binary files /dev/null and b/res/dist/media/PCZAppMedia/room_nxpz.mesh differ diff --git a/res/dist/media/PCZAppMedia/room_nypy.mesh b/res/dist/media/PCZAppMedia/room_nypy.mesh new file mode 100644 index 00000000000..564b5c589f5 Binary files /dev/null and b/res/dist/media/PCZAppMedia/room_nypy.mesh differ diff --git a/res/dist/media/PCZAppMedia/room_nypy_4y.mesh b/res/dist/media/PCZAppMedia/room_nypy_4y.mesh new file mode 100644 index 00000000000..76c0f0edbea Binary files /dev/null and b/res/dist/media/PCZAppMedia/room_nypy_4y.mesh differ diff --git a/res/dist/media/PCZAppMedia/room_nzpz.mesh b/res/dist/media/PCZAppMedia/room_nzpz.mesh new file mode 100644 index 00000000000..293700835b2 Binary files /dev/null and b/res/dist/media/PCZAppMedia/room_nzpz.mesh differ diff --git a/res/dist/media/PCZAppMedia/room_pxnynz.mesh b/res/dist/media/PCZAppMedia/room_pxnynz.mesh new file mode 100644 index 00000000000..c70792995f1 Binary files /dev/null and b/res/dist/media/PCZAppMedia/room_pxnynz.mesh differ diff --git a/res/dist/media/PCZAppMedia/room_pxpynz.mesh b/res/dist/media/PCZAppMedia/room_pxpynz.mesh new file mode 100644 index 00000000000..43f37c0a85a Binary files /dev/null and b/res/dist/media/PCZAppMedia/room_pxpynz.mesh differ diff --git a/res/dist/media/PCZAppMedia/room_pxpz.mesh b/res/dist/media/PCZAppMedia/room_pxpz.mesh new file mode 100644 index 00000000000..b08c9ddde47 Binary files /dev/null and b/res/dist/media/PCZAppMedia/room_pxpz.mesh differ diff --git a/res/dist/media/PCZAppMedia/terrain2.cfg b/res/dist/media/PCZAppMedia/terrain2.cfg new file mode 100644 index 00000000000..b3b7a939d3c --- /dev/null +++ b/res/dist/media/PCZAppMedia/terrain2.cfg @@ -0,0 +1,71 @@ +# The main world texture (if you wish the terrain manager to create a material for you) +WorldTexture=terrain_texture.jpg + +# The detail texture (if you wish the terrain manager to create a material for you) +DetailTexture=terrain_detail.jpg + +#number of times the detail texture will tile in a terrain tile +DetailTile=3 + +# Heightmap source +PageSource=Heightmap + +# Heightmap-source specific settings +Heightmap.image=terrain2.png + +# If you use RAW, fill in the below too +# RAW-specific setting - size (horizontal/vertical) +#Heightmap.raw.size=513 +# RAW-specific setting - bytes per pixel (1 = 8bit, 2=16bit) +#Heightmap.raw.bpp=2 + +# How large is a page of tiles (in vertices)? Must be (2^n)+1 +PageSize=513 + +# How large is each tile? Must be (2^n)+1 and be smaller than PageSize +TileSize=65 + +# The maximum error allowed when determining which LOD to use +MaxPixelError=3 + +# The size of a terrain page, in world units +PageWorldX=1500 +PageWorldZ=1500 +# Maximum height of the terrain +MaxHeight=250 + +# Upper LOD limit +MaxMipMapLevel=5 + +#VertexNormals=yes +#VertexColors=yes +#UseTriStrips=yes + +# Use vertex program to morph LODs, if available +VertexProgramMorph=yes + +# The proportional distance range at which the LOD morph starts to take effect +# This is as a proportion of the distance between the current LODs effective range, +# and the effective range of the next lower LOD +LODMorphStart=0.2 + +# This following section is for if you want to provide your own terrain shading routine +# Note that since you define your textures within the material this makes the +# WorldTexture and DetailTexture settings redundant + +# The name of the vertex program parameter you wish to bind the morph LOD factor to +# this is 0 when there is no adjustment (highest) to 1 when the morph takes it completely +# to the same position as the next lower LOD +# USE THIS IF YOU USE HIGH-LEVEL VERTEX PROGRAMS WITH LOD MORPHING +#MorphLODFactorParamName=morphFactor + +# The index of the vertex program parameter you wish to bind the morph LOD factor to +# this is 0 when there is no adjustment (highest) to 1 when the morph takes it completely +# to the same position as the next lower LOD +# USE THIS IF YOU USE ASSEMBLER VERTEX PROGRAMS WITH LOD MORPHING +#MorphLODFactorParamIndex=4 + +# The name of the material you will define to shade the terrain +#CustomMaterialName=TestTerrainMaterial + + diff --git a/res/dist/media/PCZAppMedia/terrain2.png b/res/dist/media/PCZAppMedia/terrain2.png new file mode 100644 index 00000000000..18b620b2dfe Binary files /dev/null and b/res/dist/media/PCZAppMedia/terrain2.png differ diff --git a/res/dist/media/RTShaderLib/FFPLib_Common.cg b/res/dist/media/RTShaderLib/FFPLib_Common.cg new file mode 100644 index 00000000000..a9087c35aae --- /dev/null +++ b/res/dist/media/RTShaderLib/FFPLib_Common.cg @@ -0,0 +1,248 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Program Name: FFPLib_Common +// Program Desc: Common functions of the FFP. +// Program Type: Vertex/Pixel shader +// Language: CG +// Notes: Common functions needed by all FFP implementation classes. +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void FFP_Assign(in float vIn, out float vOut) +{ + vOut = vIn; +} +//----------------------------------------------------------------------------- +void FFP_Assign(in float2 vIn, out float2 vOut) +{ + vOut = vIn; +} + +//----------------------------------------------------------------------------- +void FFP_Assign(in float3 vIn, out float3 vOut) +{ + vOut = vIn; +} + +//----------------------------------------------------------------------------- +void FFP_Assign(in float4 vIn, out float4 vOut) +{ + vOut = vIn; +} + +//----------------------------------------------------------------------------- +void FFP_Assign(in float2x4 vIn, out float2x4 vOut) +{ + vOut = vIn; +} + +//----------------------------------------------------------------------------- +void FFP_Assign(in float3x4 vIn, out float3x4 vOut) +{ + vOut = vIn; +} + +//----------------------------------------------------------------------------- +void FFP_Construct(in float r, + in float g, + in float b, + in float a, + out float4 vOut) +{ + vOut = float4(r,g,b,a); +} + +//----------------------------------------------------------------------------- +void FFP_Construct(in float r, + in float g, + out float2 vOut) +{ + vOut = float2(r,g); +} + +//----------------------------------------------------------------------------- +void FFP_Construct(in float r, + in float g, + in float b, + out float3 vOut) +{ + vOut = float3(r,g,b); +} + +//----------------------------------------------------------------------------- +void FFP_Construct(in float r, + out float4 vOut) +{ + vOut = float4(r,r,r,r); +} + +//----------------------------------------------------------------------------- +void FFP_Modulate(in float vIn0, in float vIn1, out float vOut) +{ + vOut = vIn0 * vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Modulate(in float2 vIn0, in float2 vIn1, out float2 vOut) +{ + vOut = vIn0 * vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Modulate(in float3 vIn0, in float3 vIn1, out float3 vOut) +{ + vOut = vIn0 * vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Modulate(in float4 vIn0, in float4 vIn1, out float4 vOut) +{ + vOut = vIn0 * vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Add(in float vIn0, in float vIn1, out float vOut) +{ + vOut = vIn0 + vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Add(in float2 vIn0, in float2 vIn1, out float2 vOut) +{ + vOut = vIn0 + vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Add(in float3 vIn0, in float3 vIn1, out float3 vOut) +{ + vOut = vIn0 + vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Add(in float4 vIn0, in float4 vIn1, out float4 vOut) +{ + vOut = vIn0 + vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Add(in float2x4 vIn0, in float2x4 vIn1, out float2x4 vOut) +{ + vOut = vIn0 + vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Add(in float3x4 vIn0, in float3x4 vIn1, out float3x4 vOut) +{ + vOut = vIn0 + vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Subtract(in float vIn0, in float vIn1, out float vOut) +{ + vOut = vIn0 - vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Subtract(in float2 vIn0, in float2 vIn1, out float2 vOut) +{ + vOut = vIn0 - vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Subtract(in float3 vIn0, in float3 vIn1, out float3 vOut) +{ + vOut = vIn0 - vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Subtract(in float4 vIn0, in float4 vIn1, out float4 vOut) +{ + vOut = vIn0 - vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Lerp(in float vIn0, in float vIn1, float T, out float vOut) +{ + vOut = lerp(vIn0, vIn1, T); +} + +//----------------------------------------------------------------------------- +void FFP_Lerp(in float2 vIn0, in float2 vIn1, float T, out float2 vOut) +{ + vOut = lerp(vIn0, vIn1, T); +} + +//----------------------------------------------------------------------------- +void FFP_Lerp(in float3 vIn0, in float3 vIn1, float T, out float3 vOut) +{ + vOut = lerp(vIn0, vIn1, T); +} + +//----------------------------------------------------------------------------- +void FFP_Lerp(in float4 vIn0, in float4 vIn1, float T, out float4 vOut) +{ + vOut = lerp(vIn0, vIn1, T); +} + +//----------------------------------------------------------------------------- +void FFP_Lerp(in float4 vIn0, in float4 vIn1, float4 T, out float4 vOut) +{ + vOut = lerp(vIn0, vIn1, T); +} + +//----------------------------------------------------------------------------- +void FFP_DotProduct(in float vIn0, in float vIn1, out float vOut) +{ + vOut = dot(vIn0, vIn1); +} + +//----------------------------------------------------------------------------- +void FFP_DotProduct(in float2 vIn0, in float2 vIn1, out float2 vOut) +{ + vOut = dot(vIn0, vIn1); +} + +//----------------------------------------------------------------------------- +void FFP_DotProduct(in float3 vIn0, in float3 vIn1, out float3 vOut) +{ + vOut = dot(vIn0, vIn1); +} + +//----------------------------------------------------------------------------- +void FFP_DotProduct(in float4 vIn0, in float4 vIn1, out float4 vOut) +{ + vOut = dot(vIn0, vIn1); +} + +//----------------------------------------------------------------------------- +void FFP_Normalize(inout float3 vIn) +{ + vIn /= length(vIn); +} + + diff --git a/res/dist/media/RTShaderLib/FFPLib_Common.glsl b/res/dist/media/RTShaderLib/FFPLib_Common.glsl new file mode 100644 index 00000000000..b3c849bab32 --- /dev/null +++ b/res/dist/media/RTShaderLib/FFPLib_Common.glsl @@ -0,0 +1,248 @@ +#version 120 +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Program Name: FFPLib_Common +// Program Desc: Common functions of the FFP. +// Program Type: Vertex/Pixel shader +// Language: GLSL +// Notes: Common functions needed by all FFP implementation classes. +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +void FFP_Assign(in float vIn, out float vOut) +{ + vOut = vIn; +} +//----------------------------------------------------------------------------- +void FFP_Assign(in vec2 vIn, out vec2 vOut) +{ + vOut = vIn; +} + +//----------------------------------------------------------------------------- +void FFP_Assign(in vec3 vIn, out vec3 vOut) +{ + vOut = vIn; +} + +//----------------------------------------------------------------------------- +void FFP_Assign(in vec4 vIn, out vec4 vOut) +{ + vOut = vIn; +} +//----------------------------------------------------------------------------- +void FFP_Assign(in vec4 vIn, out vec2 vOut) +{ + vOut = vIn.xy; +} +//----------------------------------------------------------------------------- +void FFP_Assign(in vec4 vIn, out vec3 vOut) +{ + vOut = vIn.xyz; +} +//----------------------------------------------------------------------------- +void FFP_Assign(in mat2x4 vIn, out mat2x4 vOut) +{ + vOut = vIn; +} +//----------------------------------------------------------------------------- +void FFP_Assign(in mat3x4 vIn, out mat3x4 vOut) +{ + vOut = vIn; +} +//----------------------------------------------------------------------------- +void FFP_Construct(in float r, + in float g, + in float b, + in float a, + out vec4 vOut) +{ + vOut = vec4(r,g,b,a); +} + +//----------------------------------------------------------------------------- +void FFP_Construct(in float r, + in float g, + in float b, + out vec3 vOut) +{ + vOut = vec3(r,g,b); +} + +//----------------------------------------------------------------------------- +void FFP_Construct(in float r, + out vec4 vOut) +{ + vOut = vec4(r,r,r,r); +} + +//----------------------------------------------------------------------------- +void FFP_Construct(in float r, + in float g, + out vec2 vOut) +{ + vOut = vec2(r,g); +} + +//----------------------------------------------------------------------------- +void FFP_Modulate(in float vIn0, in float vIn1, out float vOut) +{ + vOut = vIn0 * vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Modulate(in vec2 vIn0, in vec2 vIn1, out vec2 vOut) +{ + vOut = vIn0 * vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Modulate(in vec3 vIn0, in vec3 vIn1, out vec3 vOut) +{ + vOut = vIn0 * vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Modulate(in vec4 vIn0, in vec4 vIn1, out vec4 vOut) +{ + vOut = vIn0 * vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Add(in float vIn0, in float vIn1, out float vOut) +{ + vOut = vIn0 + vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Add(in vec2 vIn0, in vec2 vIn1, out vec2 vOut) +{ + vOut = vIn0 + vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Add(in vec3 vIn0, in vec3 vIn1, out vec3 vOut) +{ + vOut = vIn0 + vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Add(in vec4 vIn0, in vec4 vIn1, out vec4 vOut) +{ + vOut = vIn0 + vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Add(in mat2x4 vIn0, in mat2x4 vIn1, out mat2x4 vOut) +{ + vOut = vIn0 + vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Add(in mat3x4 vIn0, in mat3x4 vIn1, out mat3x4 vOut) +{ + vOut = vIn0 + vIn1; +} +//----------------------------------------------------------------------------- +void FFP_Subtract(in float vIn0, in float vIn1, out float vOut) +{ + vOut = vIn0 - vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Subtract(in vec2 vIn0, in vec2 vIn1, out vec2 vOut) +{ + vOut = vIn0 - vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Subtract(in vec3 vIn0, in vec3 vIn1, out vec3 vOut) +{ + vOut = vIn0 - vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Subtract(in vec4 vIn0, in vec4 vIn1, out vec4 vOut) +{ + vOut = vIn0 - vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Lerp(in float vIn0, in float vIn1, float T, out float vOut) +{ + vOut = mix(vIn0, vIn1, T); +} + +//----------------------------------------------------------------------------- +void FFP_Lerp(in vec2 vIn0, in vec2 vIn1, float T, out vec2 vOut) +{ + vOut = mix(vIn0, vIn1, T); +} + +//----------------------------------------------------------------------------- +void FFP_Lerp(in vec3 vIn0, in vec3 vIn1, float T, out vec3 vOut) +{ + vOut = mix(vIn0, vIn1, T); +} + +//----------------------------------------------------------------------------- +void FFP_Lerp(in vec4 vIn0, in vec4 vIn1, float T, out vec4 vOut) +{ + vOut = mix(vIn0, vIn1, T); +} + +//----------------------------------------------------------------------------- +void FFP_Lerp(in vec4 vIn0, in vec4 vIn1, vec4 T, out vec4 vOut) +{ + vOut = mix(vIn0, vIn1, T); +} + +//----------------------------------------------------------------------------- +void FFP_DotProduct(in float vIn0, in float vIn1, out float vOut) +{ + vOut = dot(vIn0, vIn1); +} + +//----------------------------------------------------------------------------- +void FFP_DotProduct(in vec2 vIn0, in vec2 vIn1, out vec2 vOut) +{ + vOut = vec2(dot(vIn0, vIn1), 1.0); +} + +//----------------------------------------------------------------------------- +void FFP_DotProduct(in vec3 vIn0, in vec3 vIn1, out vec3 vOut) +{ + vOut = vec3(dot(vIn0, vIn1), 1.0, 1.0); +} + +//----------------------------------------------------------------------------- +void FFP_DotProduct(in vec4 vIn0, in vec4 vIn1, out vec4 vOut) +{ + vOut = vec4(dot(vIn0, vIn1), 1.0, 1.0, 1.0); +} diff --git a/res/dist/media/RTShaderLib/FFPLib_Common.glsles b/res/dist/media/RTShaderLib/FFPLib_Common.glsles new file mode 100644 index 00000000000..696b18631bf --- /dev/null +++ b/res/dist/media/RTShaderLib/FFPLib_Common.glsles @@ -0,0 +1,231 @@ +#version 100 +precision highp float; +precision highp int; +precision lowp sampler2D; +precision lowp samplerCube; +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Program Name: FFPLib_Common +// Program Desc: Common functions of the FFP. +// Program Type: Vertex/Pixel shader +// Language: GLSL ES +// Notes: Common functions needed by all FFP implementation classes. +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +void FFP_Assign(in float vIn, out float vOut) +{ + vOut = vIn; +} +//----------------------------------------------------------------------------- +void FFP_Assign(in vec2 vIn, out vec2 vOut) +{ + vOut = vIn; +} + +//----------------------------------------------------------------------------- +void FFP_Assign(in vec3 vIn, out vec3 vOut) +{ + vOut = vIn; +} + +//----------------------------------------------------------------------------- +void FFP_Assign(in vec4 vIn, out vec4 vOut) +{ + vOut = vIn; +} +//----------------------------------------------------------------------------- +void FFP_Assign(in vec4 vIn, out vec2 vOut) +{ + vOut = vIn.xy; +} +//----------------------------------------------------------------------------- +void FFP_Assign(in vec4 vIn, out vec3 vOut) +{ + vOut = vIn.xyz; +} +//----------------------------------------------------------------------------- +void FFP_Construct(in float r, + in float g, + in float b, + in float a, + out vec4 vOut) +{ + vOut = vec4(r,g,b,a); +} + +//----------------------------------------------------------------------------- +void FFP_Construct(in float r, + in float g, + in float b, + out vec3 vOut) +{ + vOut = vec3(r,g,b); +} + +//----------------------------------------------------------------------------- +void FFP_Construct(in float r, + out vec4 vOut) +{ + vOut = vec4(r,r,r,r); +} + +//----------------------------------------------------------------------------- +void FFP_Construct(in float r, + in float g, + out vec2 vOut) +{ + vOut = vec2(r,g); +} + +//----------------------------------------------------------------------------- +void FFP_Modulate(in float vIn0, in float vIn1, out float vOut) +{ + vOut = vIn0 * vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Modulate(in vec2 vIn0, in vec2 vIn1, out vec2 vOut) +{ + vOut = vIn0 * vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Modulate(in vec3 vIn0, in vec3 vIn1, out vec3 vOut) +{ + vOut = vIn0 * vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Modulate(in vec4 vIn0, in vec4 vIn1, out vec4 vOut) +{ + vOut = vIn0 * vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Add(in float vIn0, in float vIn1, out float vOut) +{ + vOut = vIn0 + vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Add(in vec2 vIn0, in vec2 vIn1, out vec2 vOut) +{ + vOut = vIn0 + vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Add(in vec3 vIn0, in vec3 vIn1, out vec3 vOut) +{ + vOut = vIn0 + vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Add(in vec4 vIn0, in vec4 vIn1, out vec4 vOut) +{ + vOut = vIn0 + vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Subtract(in float vIn0, in float vIn1, out float vOut) +{ + vOut = vIn0 - vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Subtract(in vec2 vIn0, in vec2 vIn1, out vec2 vOut) +{ + vOut = vIn0 - vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Subtract(in vec3 vIn0, in vec3 vIn1, out vec3 vOut) +{ + vOut = vIn0 - vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Subtract(in vec4 vIn0, in vec4 vIn1, out vec4 vOut) +{ + vOut = vIn0 - vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Lerp(in float vIn0, in float vIn1, in float T, out float vOut) +{ + vOut = mix(vIn0, vIn1, T); +} + +//----------------------------------------------------------------------------- +void FFP_Lerp(in vec2 vIn0, in vec2 vIn1, in float T, out vec2 vOut) +{ + vOut = mix(vIn0, vIn1, T); +} + +//----------------------------------------------------------------------------- +void FFP_Lerp(in vec3 vIn0, in vec3 vIn1, in float T, out vec3 vOut) +{ + vOut = mix(vIn0, vIn1, T); +} + +//----------------------------------------------------------------------------- +void FFP_Lerp(in vec4 vIn0, in vec4 vIn1, in float T, out vec4 vOut) +{ + vOut = mix(vIn0, vIn1, T); +} + +//----------------------------------------------------------------------------- +void FFP_Lerp(in vec4 vIn0, in vec4 vIn1, in vec4 T, out vec4 vOut) +{ + vOut = mix(vIn0, vIn1, T); +} + +//----------------------------------------------------------------------------- +void FFP_DotProduct(in float vIn0, in float vIn1, out float vOut) +{ + vOut = dot(vIn0, vIn1); +} + +//----------------------------------------------------------------------------- +void FFP_DotProduct(in vec2 vIn0, in vec2 vIn1, out vec2 vOut) +{ + vOut = vec2(dot(vIn0, vIn1), 1.0); +} + +//----------------------------------------------------------------------------- +void FFP_DotProduct(in vec3 vIn0, in vec3 vIn1, out vec3 vOut) +{ + vOut = vec3(dot(vIn0, vIn1), 1.0, 1.0); +} + +//----------------------------------------------------------------------------- +void FFP_DotProduct(in vec4 vIn0, in vec4 vIn1, out vec4 vOut) +{ + vOut = vec4(dot(vIn0, vIn1), 1.0, 1.0, 1.0); +} diff --git a/res/dist/media/RTShaderLib/FFPLib_Common.hlsl b/res/dist/media/RTShaderLib/FFPLib_Common.hlsl new file mode 100644 index 00000000000..b136f2e02e1 --- /dev/null +++ b/res/dist/media/RTShaderLib/FFPLib_Common.hlsl @@ -0,0 +1,219 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Program Name: FFPLib_Common +// Program Desc: Common functions of the FFP. +// Program Type: Vertex/Pixel shader +// Language: HLSL +// Notes: Common functions needed by all FFP implementation classes. +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void FFP_Assign(in float vIn, out float vOut) +{ + vOut = vIn; +} +//----------------------------------------------------------------------------- +void FFP_Assign(in float2 vIn, out float2 vOut) +{ + vOut = vIn; +} + +//----------------------------------------------------------------------------- +void FFP_Assign(in float3 vIn, out float3 vOut) +{ + vOut = vIn; +} + +//----------------------------------------------------------------------------- +void FFP_Assign(in float4 vIn, out float4 vOut) +{ + vOut = vIn; +} + +//----------------------------------------------------------------------------- +void FFP_Construct(in float r, + in float g, + in float b, + in float a, + out float4 vOut) +{ + vOut = float4(r,g,b,a); +} + +//----------------------------------------------------------------------------- +void FFP_Construct(in float r, + in float g, + out float2 vOut) +{ + vOut = float2(r,g); +} + +//----------------------------------------------------------------------------- +void FFP_Construct(in float r, + in float g, + in float b, + out float3 vOut) +{ + vOut = float3(r,g,b); +} + +//----------------------------------------------------------------------------- +void FFP_Construct(in float r, + out float4 vOut) +{ + vOut = float4(r,r,r,r); +} + +//----------------------------------------------------------------------------- +void FFP_Modulate(in float vIn0, in float vIn1, out float vOut) +{ + vOut = vIn0 * vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Modulate(in float2 vIn0, in float2 vIn1, out float2 vOut) +{ + vOut = vIn0 * vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Modulate(in float3 vIn0, in float3 vIn1, out float3 vOut) +{ + vOut = vIn0 * vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Modulate(in float4 vIn0, in float4 vIn1, out float4 vOut) +{ + vOut = vIn0 * vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Add(in float vIn0, in float vIn1, out float vOut) +{ + vOut = vIn0 + vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Add(in float2 vIn0, in float2 vIn1, out float2 vOut) +{ + vOut = vIn0 + vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Add(in float3 vIn0, in float3 vIn1, out float3 vOut) +{ + vOut = vIn0 + vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Add(in float4 vIn0, in float4 vIn1, out float4 vOut) +{ + vOut = vIn0 + vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Subtract(in float vIn0, in float vIn1, out float vOut) +{ + vOut = vIn0 - vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Subtract(in float2 vIn0, in float2 vIn1, out float2 vOut) +{ + vOut = vIn0 - vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Subtract(in float3 vIn0, in float3 vIn1, out float3 vOut) +{ + vOut = vIn0 - vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Subtract(in float4 vIn0, in float4 vIn1, out float4 vOut) +{ + vOut = vIn0 - vIn1; +} + +//----------------------------------------------------------------------------- +void FFP_Lerp(in float vIn0, in float vIn1, float T, out float vOut) +{ + vOut = lerp(vIn0, vIn1, T); +} + +//----------------------------------------------------------------------------- +void FFP_Lerp(in float2 vIn0, in float2 vIn1, float T, out float2 vOut) +{ + vOut = lerp(vIn0, vIn1, T); +} + +//----------------------------------------------------------------------------- +void FFP_Lerp(in float3 vIn0, in float3 vIn1, float T, out float3 vOut) +{ + vOut = lerp(vIn0, vIn1, T); +} + +//----------------------------------------------------------------------------- +void FFP_Lerp(in float4 vIn0, in float4 vIn1, float T, out float4 vOut) +{ + vOut = lerp(vIn0, vIn1, T); +} + +//----------------------------------------------------------------------------- +void FFP_Lerp(in float4 vIn0, in float4 vIn1, float4 T, out float4 vOut) +{ + vOut = lerp(vIn0, vIn1, T); +} + +//----------------------------------------------------------------------------- +void FFP_DotProduct(in float vIn0, in float vIn1, out float vOut) +{ + vOut = dot(vIn0, vIn1); +} + +//----------------------------------------------------------------------------- +void FFP_DotProduct(in float2 vIn0, in float2 vIn1, out float2 vOut) +{ + vOut = dot(vIn0, vIn1); +} + +//----------------------------------------------------------------------------- +void FFP_DotProduct(in float3 vIn0, in float3 vIn1, out float3 vOut) +{ + vOut = dot(vIn0, vIn1); +} + +//----------------------------------------------------------------------------- +void FFP_DotProduct(in float4 vIn0, in float4 vIn1, out float4 vOut) +{ + vOut = dot(vIn0, vIn1); +} + + + diff --git a/res/dist/media/RTShaderLib/FFPLib_Fog.cg b/res/dist/media/RTShaderLib/FFPLib_Fog.cg new file mode 100644 index 00000000000..f6d0b652020 --- /dev/null +++ b/res/dist/media/RTShaderLib/FFPLib_Fog.cg @@ -0,0 +1,138 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Program Name: FFPLib_Fog +// Program Desc: Fog functions of the FFP. +// Program Type: Vertex/Pixel shader +// Language: CG +// Notes: Implements cor functions needed by FFPFog class. +// Based on fog engine. +// See http://msdn.microsoft.com/en-us/library/bb173398.aspx +// Vertex based fog: the w component of the out position is used +// as the distance parameter to fog formulas. This is basically the z coordinate +// in world space. See pixel fog under D3D docs. The fog factor is computed according +// to each formula, then clamped and output to the pixel shader. +// Pixel based fog: the w component of the out position is passed to pixel shader +// that computes the fog factor based on it. +// Both techniques use the fog factor in the end of the pixel shader to blend +// the output color with the fog color. +//----------------------------------------------------------------------------- + + + +//----------------------------------------------------------------------------- +void FFP_VertexFog_Linear(in float4x4 mWorldViewProj, + in float4 pos, + in float4 fogParams, + out float oFogFactor) +{ + float4 vOutPos = mul(mWorldViewProj, pos); + float distance = abs(vOutPos.w); + float fogFactor = (fogParams.z - distance) * fogParams.w; + + oFogFactor = saturate(fogFactor); +} + +//----------------------------------------------------------------------------- +void FFP_VertexFog_Exp(in float4x4 mWorldViewProj, + in float4 pos, + in float4 fogParams, + out float oFogFactor) +{ + float4 vOutPos = mul(mWorldViewProj, pos); + float distance = abs(vOutPos.w); + float exp = distance*fogParams.x; + float fogFactor = 1 / pow(2.71828, exp); + + oFogFactor = saturate(fogFactor); +} + +//----------------------------------------------------------------------------- +void FFP_VertexFog_Exp2(in float4x4 mWorldViewProj, + in float4 pos, + in float4 fogParams, + out float oFogFactor) +{ + float4 vOutPos = mul(mWorldViewProj, pos); + float distance = abs(vOutPos.w); + float exp = (distance*fogParams.x*distance*fogParams.x); + float fogFactor = 1 / pow(2.71828, exp); + + oFogFactor = saturate(fogFactor); +} + + +//----------------------------------------------------------------------------- +void FFP_PixelFog_Depth(in float4x4 mWorldViewProj, + in float4 pos, + out float oDepth) +{ + float4 vOutPos = mul(mWorldViewProj, pos); + oDepth = vOutPos.w; +} + +//----------------------------------------------------------------------------- +void FFP_PixelFog_Linear(in float depth, + in float4 fogParams, + in float4 fogColor, + in float4 baseColor, + out float4 oColor) +{ + float distance = abs(depth); + float fogFactor = saturate((fogParams.z - distance) * fogParams.w); + + oColor = lerp(fogColor, baseColor, fogFactor); +} + +//----------------------------------------------------------------------------- +void FFP_PixelFog_Exp(in float depth, + in float4 fogParams, + in float4 fogColor, + in float4 baseColor, + out float4 oColor) +{ + float distance = abs(depth); + float exp = (distance*fogParams.x); + float fogFactor = saturate(1 / pow(2.71828, exp)); + + oColor = lerp(fogColor, baseColor, fogFactor); +} + +//----------------------------------------------------------------------------- +void FFP_PixelFog_Exp2(in float depth, + in float4 fogParams, + in float4 fogColor, + in float4 baseColor, + out float4 oColor) +{ + float distance = abs(depth); + float exp = (distance*fogParams.x*distance*fogParams.x); + float fogFactor = saturate(1 / pow(2.71828, exp)); + + oColor = lerp(fogColor, baseColor, fogFactor); +} \ No newline at end of file diff --git a/res/dist/media/RTShaderLib/FFPLib_Fog.glsl b/res/dist/media/RTShaderLib/FFPLib_Fog.glsl new file mode 100644 index 00000000000..b3e5e219228 --- /dev/null +++ b/res/dist/media/RTShaderLib/FFPLib_Fog.glsl @@ -0,0 +1,139 @@ +#version 120 +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Program Name: FFPLib_Fog +// Program Desc: Fog functions of the FFP. +// Program Type: Vertex/Pixel shader +// Language: GLSL +// Notes: Implements core functions needed by FFPFog class. +// Based on fog engine. +// See http://msdn.microsoft.com/en-us/library/bb173398.aspx +// Vertex based fog: the w component of the out position is used +// as the distance parameter to fog formulas. This is basically the z coordinate +// in world space. See pixel fog under D3D docs. The fog factor is computed according +// to each formula, then clamped and output to the pixel shader. +// Pixel based fog: the w component of the out position is passed to pixel shader +// that computes the fog factor based on it. +// Both techniques use the fog factor in the end of the pixel shader to blend +// the output color with the fog color. +//----------------------------------------------------------------------------- + + + +//----------------------------------------------------------------------------- +void FFP_VertexFog_Linear(in mat4 mWorldViewProj, + in vec4 pos, + in vec4 fogParams, + out float oFogFactor) +{ + vec4 vOutPos = mWorldViewProj * pos; + float distance = abs(vOutPos.w); + float fogFactor = (fogParams.z - distance) * fogParams.w; + + oFogFactor = clamp(fogFactor, 0.0, 1.0); +} + +//----------------------------------------------------------------------------- +void FFP_VertexFog_Exp(in mat4 mWorldViewProj, + in vec4 pos, + in vec4 fogParams, + out float oFogFactor) +{ + vec4 vOutPos = mWorldViewProj * pos; + float distance = abs(vOutPos.w); + float exp = distance*fogParams.x; + float fogFactor = 1.0 / pow(2.71828, exp); + + oFogFactor = clamp(fogFactor, 0.0, 1.0); +} + +//----------------------------------------------------------------------------- +void FFP_VertexFog_Exp2(in mat4 mWorldViewProj, + in vec4 pos, + in vec4 fogParams, + out float oFogFactor) +{ + vec4 vOutPos = mWorldViewProj * pos; + float distance = abs(vOutPos.w); + float exp = (distance*fogParams.x*distance*fogParams.x); + float fogFactor = 1.0 / pow(2.71828, exp); + + oFogFactor = clamp(fogFactor, 0.0, 1.0); +} + + +//----------------------------------------------------------------------------- +void FFP_PixelFog_Depth(in mat4 mWorldViewProj, + in vec4 pos, + out float oDepth) +{ + vec4 vOutPos = mWorldViewProj * pos; + oDepth = vOutPos.w; +} + +//----------------------------------------------------------------------------- +void FFP_PixelFog_Linear(in float depth, + in vec4 fogParams, + in vec4 fogColor, + in vec4 baseColor, + out vec4 oColor) +{ + float distance = abs(depth); + float fogFactor = clamp((fogParams.z - distance) * fogParams.w, 0.0, 1.0); + + oColor = mix(fogColor, baseColor, fogFactor); +} + +//----------------------------------------------------------------------------- +void FFP_PixelFog_Exp(in float depth, + in vec4 fogParams, + in vec4 fogColor, + in vec4 baseColor, + out vec4 oColor) +{ + float distance = abs(depth); + float exp = (distance*fogParams.x); + float fogFactor = clamp(1.0 / pow(2.71828, exp), 0.0, 1.0); + + oColor = mix(fogColor, baseColor, fogFactor); +} + +//----------------------------------------------------------------------------- +void FFP_PixelFog_Exp2(in float depth, + in vec4 fogParams, + in vec4 fogColor, + in vec4 baseColor, + out vec4 oColor) +{ + float distance = abs(depth); + float exp = (distance*fogParams.x*distance*fogParams.x); + float fogFactor = clamp(1.0 / pow(2.71828, exp), 0.0, 1.0); + + oColor = mix(fogColor, baseColor, fogFactor); +} diff --git a/res/dist/media/RTShaderLib/FFPLib_Fog.glsles b/res/dist/media/RTShaderLib/FFPLib_Fog.glsles new file mode 100644 index 00000000000..b6f1a6e2a5b --- /dev/null +++ b/res/dist/media/RTShaderLib/FFPLib_Fog.glsles @@ -0,0 +1,141 @@ +#version 100 +precision highp float; +precision highp int; +precision lowp sampler2D; +precision lowp samplerCube; +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Program Name: FFPLib_Fog +// Program Desc: Fog functions of the FFP. +// Program Type: Vertex/Pixel shader +// Language: GLSL ES +// Notes: Implements core functions needed by FFPFog class. +// Based on fog engine. +// See http://msdn.microsoft.com/en-us/library/bb173398.aspx +// Vertex based fog: the w component of the out position is used +// as the distance parameter to fog formulas. This is basically the z coordinate +// in world space. See pixel fog under D3D docs. The fog factor is computed according +// to each formula, then clamped and output to the pixel shader. +// Pixel based fog: the w component of the out position is passed to pixel shader +// that computes the fog factor based on it. +// Both techniques use the fog factor in the end of the pixel shader to blend +// the output color with the fog color. +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +void FFP_VertexFog_Linear(in mat4 mWorldViewProj, + in vec4 pos, + in vec4 fogParams, + out float oFogFactor) +{ + vec4 vOutPos = mWorldViewProj * pos; + float distance = abs(vOutPos.w); + float fogFactor = (fogParams.z - distance) * fogParams.w; + + oFogFactor = clamp(fogFactor, 0.0, 1.0); +} + +//----------------------------------------------------------------------------- +void FFP_VertexFog_Exp(in mat4 mWorldViewProj, + in vec4 pos, + in vec4 fogParams, + out float oFogFactor) +{ + vec4 vOutPos = mWorldViewProj * pos; + float distance = abs(vOutPos.w); + float exp = distance * fogParams.x; + float fogFactor = 1.0 / pow(2.71828, exp); + + oFogFactor = clamp(fogFactor, 0.0, 1.0); +} + +//----------------------------------------------------------------------------- +void FFP_VertexFog_Exp2(in mat4 mWorldViewProj, + in vec4 pos, + in vec4 fogParams, + out float oFogFactor) +{ + vec4 vOutPos = mWorldViewProj * pos; + float distance = abs(vOutPos.w); + float exp = (distance * fogParams.x * distance * fogParams.x); + float fogFactor = 1.0 / pow(2.71828, exp); + + oFogFactor = clamp(fogFactor, 0.0, 1.0); +} + + +//----------------------------------------------------------------------------- +void FFP_PixelFog_Depth(in mat4 mWorldViewProj, + in vec4 pos, + out float oDepth) +{ + vec4 vOutPos = mWorldViewProj * pos; + oDepth = vOutPos.w; +} + +//----------------------------------------------------------------------------- +void FFP_PixelFog_Linear(in float depth, + in vec4 fogParams, + in vec4 fogColor, + in vec4 baseColor, + out vec4 oColor) +{ + float distance = abs(depth); + float fogFactor = clamp((fogParams.z - distance) * fogParams.w, 0.0, 1.0); + + oColor = mix(fogColor, baseColor, fogFactor); +} + +//----------------------------------------------------------------------------- +void FFP_PixelFog_Exp(in float depth, + in vec4 fogParams, + in vec4 fogColor, + in vec4 baseColor, + out vec4 oColor) +{ + float distance = abs(depth); + float exp = (distance * fogParams.x); + float fogFactor = clamp(1.0 / pow(2.71828, exp), 0.0, 1.0); + + oColor = mix(fogColor, baseColor, fogFactor); +} + +//----------------------------------------------------------------------------- +void FFP_PixelFog_Exp2(in float depth, + in vec4 fogParams, + in vec4 fogColor, + in vec4 baseColor, + out vec4 oColor) +{ + float distance = abs(depth); + float exp = (distance * fogParams.x * distance * fogParams.x); + float fogFactor = clamp(1.0 / pow(2.71828, exp), 0.0, 1.0); + + oColor = mix(fogColor, baseColor, fogFactor); +} diff --git a/res/dist/media/RTShaderLib/FFPLib_Fog.hlsl b/res/dist/media/RTShaderLib/FFPLib_Fog.hlsl new file mode 100644 index 00000000000..ff965fc8e29 --- /dev/null +++ b/res/dist/media/RTShaderLib/FFPLib_Fog.hlsl @@ -0,0 +1,138 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Program Name: FFPLib_Fog +// Program Desc: Fog functions of the FFP. +// Program Type: Vertex/Pixel shader +// Language: HLSL +// Notes: Implements cor functions needed by FFPFog class. +// Based on fog engine. +// See http://msdn.microsoft.com/en-us/library/bb173398.aspx +// Vertex based fog: the w component of the out position is used +// as the distance parameter to fog formulas. This is basically the z coordinate +// in world space. See pixel fog under D3D docs. The fog factor is computed according +// to each formula, then clamped and output to the pixel shader. +// Pixel based fog: the w component of the out position is passed to pixel shader +// that computes the fog factor based on it. +// Both techniques use the fog factor in the end of the pixel shader to blend +// the output color with the fog color. +//----------------------------------------------------------------------------- + + + +//----------------------------------------------------------------------------- +void FFP_VertexFog_Linear(in float4x4 mWorldViewProj, + in float4 pos, + in float4 fogParams, + out float oFogFactor) +{ + float4 vOutPos = mul(mWorldViewProj, pos); + float distance = abs(vOutPos.w); + float fogFactor = (fogParams.z - distance) * fogParams.w; + + oFogFactor = saturate(fogFactor); +} + +//----------------------------------------------------------------------------- +void FFP_VertexFog_Exp(in float4x4 mWorldViewProj, + in float4 pos, + in float4 fogParams, + out float oFogFactor) +{ + float4 vOutPos = mul(mWorldViewProj, pos); + float distance = abs(vOutPos.w); + float exp = distance*fogParams.x; + float fogFactor = 1 / pow(2.71828, exp); + + oFogFactor = saturate(fogFactor); +} + +//----------------------------------------------------------------------------- +void FFP_VertexFog_Exp2(in float4x4 mWorldViewProj, + in float4 pos, + in float4 fogParams, + out float oFogFactor) +{ + float4 vOutPos = mul(mWorldViewProj, pos); + float distance = abs(vOutPos.w); + float exp = (distance*fogParams.x*distance*fogParams.x); + float fogFactor = 1 / pow(2.71828, exp); + + oFogFactor = saturate(fogFactor); +} + + +//----------------------------------------------------------------------------- +void FFP_PixelFog_Depth(in float4x4 mWorldViewProj, + in float4 pos, + out float oDepth) +{ + float4 vOutPos = mul(mWorldViewProj, pos); + oDepth = vOutPos.w; +} + +//----------------------------------------------------------------------------- +void FFP_PixelFog_Linear(in float depth, + in float4 fogParams, + in float4 fogColor, + in float4 baseColor, + out float4 oColor) +{ + float distance = abs(depth); + float fogFactor = saturate((fogParams.z - distance) * fogParams.w); + + oColor = lerp(fogColor, baseColor, fogFactor); +} + +//----------------------------------------------------------------------------- +void FFP_PixelFog_Exp(in float depth, + in float4 fogParams, + in float4 fogColor, + in float4 baseColor, + out float4 oColor) +{ + float distance = abs(depth); + float exp = (distance*fogParams.x); + float fogFactor = saturate(1 / pow(2.71828, exp)); + + oColor = lerp(fogColor, baseColor, fogFactor); +} + +//----------------------------------------------------------------------------- +void FFP_PixelFog_Exp2(in float depth, + in float4 fogParams, + in float4 fogColor, + in float4 baseColor, + out float4 oColor) +{ + float distance = abs(depth); + float exp = (distance*fogParams.x*distance*fogParams.x); + float fogFactor = saturate(1 / pow(2.71828, exp)); + + oColor = lerp(fogColor, baseColor, fogFactor); +} diff --git a/res/dist/media/RTShaderLib/FFPLib_Lighting.cg b/res/dist/media/RTShaderLib/FFPLib_Lighting.cg new file mode 100644 index 00000000000..25eb6b3faf5 --- /dev/null +++ b/res/dist/media/RTShaderLib/FFPLib_Lighting.cg @@ -0,0 +1,225 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Program Name: FFPLib_Lighting +// Program Desc: Lighting functions of the FFP. +// Program Type: Vertex shader +// Language: CG +// Notes: Implements core functions for FFPLighting class. +// based on lighting engine. +// See http://msdn.microsoft.com/en-us/library/bb147178.aspx +//----------------------------------------------------------------------------- + + +//----------------------------------------------------------------------------- +void FFP_Light_Directional_Diffuse(in float4x4 mWorldViewIT, + in float3 vNormal, + in float3 vNegLightDirView, + in float3 vDiffuseColour, + in float3 vBaseColour, + out float3 vOut) +{ + float3 vNormalView = normalize(mul((float3x3)mWorldViewIT, vNormal)); + float nDotL = dot(vNormalView, vNegLightDirView); + + vOut = vBaseColour + vDiffuseColour * saturate(nDotL); +} + + +//----------------------------------------------------------------------------- +void FFP_Light_Directional_DiffuseSpecular(in float4x4 mWorldView, + in float4 vPos, + in float4x4 mWorldViewIT, + in float3 vNormal, + in float3 vNegLightDirView, + in float3 vDiffuseColour, + in float3 vSpecularColour, + in float fSpecularPower, + in float3 vBaseDiffuseColour, + in float3 vBaseSpecularColour, + out float3 vOutDiffuse, + out float3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + float3 vNormalView = normalize(mul((float3x3)mWorldViewIT, vNormal)); + float nDotL = dot(vNormalView, vNegLightDirView); + float3 vView = -normalize(mul(mWorldView, vPos).xyz); + float3 vHalfWay = normalize(vView + vNegLightDirView); + float nDotH = dot(vNormalView, vHalfWay); + + if (nDotL > 0) + { + vOutDiffuse += vDiffuseColour * nDotL; + vOutSpecular += vSpecularColour * pow(saturate(nDotH), fSpecularPower); + } +} + + +//----------------------------------------------------------------------------- +void FFP_Light_Point_Diffuse(in float4x4 mWorldView, + in float4 vPos, + in float4x4 mWorldViewIT, + in float3 vNormal, + in float3 vLightPosView, + in float4 vAttParams, + in float3 vDiffuseColour, + in float3 vBaseColour, + out float3 vOut) +{ + vOut = vBaseColour; + + float3 vViewPos = mul(mWorldView, vPos).xyz; + float3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + float3 vNormalView = normalize(mul((float3x3)mWorldViewIT, vNormal)); + float nDotL = dot(vNormalView, normalize(vLightView)); + + if (nDotL > 0 && fLightD <= vAttParams.x) + { + float fAtten = 1 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + + vOut += vDiffuseColour * nDotL * fAtten; + } +} + +//----------------------------------------------------------------------------- +void FFP_Light_Point_DiffuseSpecular(in float4x4 mWorldView, + in float4 vPos, + in float4x4 mWorldViewIT, + in float3 vNormal, + in float3 vLightPosView, + in float4 vAttParams, + in float3 vDiffuseColour, + in float3 vSpecularColour, + in float fSpecularPower, + in float3 vBaseDiffuseColour, + in float3 vBaseSpecularColour, + out float3 vOutDiffuse, + out float3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + float3 vViewPos = mul(mWorldView, vPos).xyz; + float3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + + vLightView = normalize(vLightView); + float3 vNormalView = normalize(mul((float3x3)mWorldViewIT, vNormal)); + float nDotL = dot(vNormalView, vLightView); + + if (nDotL > 0 && fLightD <= vAttParams.x) + { + float3 vView = -normalize(vViewPos); + float3 vHalfWay = normalize(vView + vLightView); + float nDotH = dot(vNormalView, vHalfWay); + float fAtten = 1 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + + vOutDiffuse += vDiffuseColour * nDotL * fAtten; + vOutSpecular += vSpecularColour * pow(saturate(nDotH), fSpecularPower) * fAtten; + } +} + +//----------------------------------------------------------------------------- +void FFP_Light_Spot_Diffuse(in float4x4 mWorldView, + in float4 vPos, + in float4x4 mWorldViewIT, + in float3 vNormal, + in float3 vLightPosView, + in float3 vNegLightDirView, + in float4 vAttParams, + in float3 vSpotParams, + in float3 vDiffuseColour, + in float3 vBaseColour, + out float3 vOut) +{ + vOut = vBaseColour; + + float3 vViewPos = mul(mWorldView, vPos).xyz; + float3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + vLightView = normalize(vLightView); + float3 vNormalView = normalize(mul((float3x3)mWorldViewIT, vNormal)); + float nDotL = dot(vNormalView, vLightView); + + if (nDotL > 0 && fLightD <= vAttParams.x) + { + float fAtten = 1 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + float rho = dot(vNegLightDirView, vLightView); + float fSpotE = saturate((rho - vSpotParams.y) / (vSpotParams.x - vSpotParams.y)); + float fSpotT = pow(fSpotE, vSpotParams.z); + + vOut += vDiffuseColour * nDotL * fAtten * fSpotT; + } +} + +//----------------------------------------------------------------------------- +void FFP_Light_Spot_DiffuseSpecular(in float4x4 mWorldView, + in float4 vPos, + in float4x4 mWorldViewIT, + in float3 vNormal, + in float3 vLightPosView, + in float3 vNegLightDirView, + in float4 vAttParams, + in float3 vSpotParams, + in float3 vDiffuseColour, + in float3 vSpecularColour, + in float fSpecularPower, + in float3 vBaseDiffuseColour, + in float3 vBaseSpecularColour, + out float3 vOutDiffuse, + out float3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + float3 vViewPos = mul(mWorldView, vPos).xyz; + float3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + vLightView = normalize(vLightView); + float3 vNormalView = normalize(mul((float3x3)mWorldViewIT, vNormal)); + float nDotL = dot(vNormalView, vLightView); + + + + if (nDotL > 0 && fLightD <= vAttParams.x) + { + float3 vView = -normalize(vViewPos); + float3 vHalfWay = normalize(vView + vLightView); + float nDotH = dot(vNormalView, vHalfWay); + float fAtten = 1 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + float rho = dot(vNegLightDirView, vLightView); + float fSpotE = saturate((rho - vSpotParams.y) / (vSpotParams.x - vSpotParams.y)); + float fSpotT = pow(fSpotE, vSpotParams.z); + + vOutDiffuse += vDiffuseColour * nDotL * fAtten * fSpotT; + vOutSpecular += vSpecularColour * pow(saturate(nDotH), fSpecularPower) * fAtten * fSpotT; + } +} \ No newline at end of file diff --git a/res/dist/media/RTShaderLib/FFPLib_Lighting.glsl b/res/dist/media/RTShaderLib/FFPLib_Lighting.glsl new file mode 100644 index 00000000000..d088c928283 --- /dev/null +++ b/res/dist/media/RTShaderLib/FFPLib_Lighting.glsl @@ -0,0 +1,226 @@ +#version 120 +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Program Name: FFPLib_Lighting +// Program Desc: Lighting functions of the FFP. +// Program Type: Vertex shader +// Language: GLSL +// Notes: Implements core functions for FFPLighting class. +// based on lighting engine. +// See http://msdn.microsoft.com/en-us/library/bb147178.aspx +//----------------------------------------------------------------------------- + + +//----------------------------------------------------------------------------- +void FFP_Light_Directional_Diffuse(in mat4 mWorldViewIT, + in vec3 vNormal, + in vec3 vNegLightDirView, + in vec3 vDiffuseColour, + in vec3 vBaseColour, + out vec3 vOut) +{ + vec3 vNormalView = normalize((mWorldViewIT * vec4(vNormal.xyz, 1.0)).xyz); + float nDotL = dot(vNormalView, vNegLightDirView); + + vOut = vBaseColour + vDiffuseColour * clamp(nDotL, 0.0, 1.0); +} + + +//----------------------------------------------------------------------------- +void FFP_Light_Directional_DiffuseSpecular(in mat4 mWorldView, + in vec4 vPos, + in mat4 mWorldViewIT, + in vec3 vNormal, + in vec3 vNegLightDirView, + in vec3 vDiffuseColour, + in vec3 vSpecularColour, + in float fSpecularPower, + in vec3 vBaseDiffuseColour, + in vec3 vBaseSpecularColour, + out vec3 vOutDiffuse, + out vec3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + vec3 vNormalView = normalize((mWorldViewIT * vec4(vNormal.xyz, 1.0)).xyz); + float nDotL = dot(vNormalView, vNegLightDirView); + vec3 vView = -normalize((mWorldView* vPos).xyz); + vec3 vHalfWay = normalize(vView + vNegLightDirView); + float nDotH = dot(vNormalView, vHalfWay); + + if (nDotL > 0.0) + { + vOutDiffuse += vDiffuseColour * nDotL; + vOutSpecular += vSpecularColour * pow(clamp(nDotH, 0.0, 1.0), fSpecularPower); + } +} + + +//----------------------------------------------------------------------------- +void FFP_Light_Point_Diffuse(in mat4 mWorldView, + in vec4 vPos, + in mat4 mWorldViewIT, + in vec3 vNormal, + in vec3 vLightPosView, + in vec4 vAttParams, + in vec3 vDiffuseColour, + in vec3 vBaseColour, + out vec3 vOut) +{ + vOut = vBaseColour; + + vec3 vViewPos = (mWorldView * vPos).xyz; + vec3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + vec3 vNormalView = normalize((mWorldViewIT * vec4(vNormal.xyz, 1.0)).xyz); + float nDotL = dot(vNormalView, normalize(vLightView)); + + if (nDotL > 0.0 && fLightD <= vAttParams.x) + { + float fAtten = 1.0 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + + vOut += vDiffuseColour * nDotL * fAtten; + } +} + +//----------------------------------------------------------------------------- +void FFP_Light_Point_DiffuseSpecular(in mat4 mWorldView, + in vec4 vPos, + in mat4 mWorldViewIT, + in vec3 vNormal, + in vec3 vLightPosView, + in vec4 vAttParams, + in vec3 vDiffuseColour, + in vec3 vSpecularColour, + in float fSpecularPower, + in vec3 vBaseDiffuseColour, + in vec3 vBaseSpecularColour, + out vec3 vOutDiffuse, + out vec3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + vec3 vViewPos = (mWorldView * vPos).xyz; + vec3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + + vLightView = normalize(vLightView); + vec3 vNormalView = normalize((mWorldViewIT * vec4(vNormal.xyz, 1.0)).xyz); + float nDotL = dot(vNormalView, vLightView); + + if (nDotL > 0.0 && fLightD <= vAttParams.x) + { + vec3 vView = -normalize(vViewPos); + vec3 vHalfWay = normalize(vView + vLightView); + float nDotH = dot(vNormalView, vHalfWay); + float fAtten = 1.0 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + + vOutDiffuse += vDiffuseColour * nDotL * fAtten; + vOutSpecular += vSpecularColour * pow(clamp(nDotH, 0.0, 1.0), fSpecularPower) * fAtten; + } +} + +//----------------------------------------------------------------------------- +void FFP_Light_Spot_Diffuse(in mat4 mWorldView, + in vec4 vPos, + in mat4 mWorldViewIT, + in vec3 vNormal, + in vec3 vLightPosView, + in vec3 vNegLightDirView, + in vec4 vAttParams, + in vec3 vSpotParams, + in vec3 vDiffuseColour, + in vec3 vBaseColour, + out vec3 vOut) +{ + vOut = vBaseColour; + + vec3 vViewPos = (mWorldView * vPos).xyz; + vec3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + vLightView = normalize(vLightView); + vec3 vNormalView = normalize((mWorldViewIT * vec4(vNormal.xyz, 1.0)).xyz); + float nDotL = dot(vNormalView, vLightView); + + if (nDotL > 0.0 && fLightD <= vAttParams.x) + { + float fAtten = 1.0 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + float rho = dot(vNegLightDirView, vLightView); + float fSpotE = clamp((rho - vSpotParams.y) / (vSpotParams.x - vSpotParams.y), 0.0, 1.0); + float fSpotT = pow(fSpotE, vSpotParams.z); + + vOut += vDiffuseColour * nDotL * fAtten * fSpotT; + } +} + +//----------------------------------------------------------------------------- +void FFP_Light_Spot_DiffuseSpecular(in mat4 mWorldView, + in vec4 vPos, + in mat4 mWorldViewIT, + in vec3 vNormal, + in vec3 vLightPosView, + in vec3 vNegLightDirView, + in vec4 vAttParams, + in vec3 vSpotParams, + in vec3 vDiffuseColour, + in vec3 vSpecularColour, + in float fSpecularPower, + in vec3 vBaseDiffuseColour, + in vec3 vBaseSpecularColour, + out vec3 vOutDiffuse, + out vec3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + vec3 vViewPos = (mWorldView * vPos).xyz; + vec3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + vLightView = normalize(vLightView); + vec3 vNormalView = normalize((mWorldViewIT * vec4(vNormal.xyz, 1.0)).xyz); + float nDotL = dot(vNormalView, vLightView); + + + + if (nDotL > 0.0 && fLightD <= vAttParams.x) + { + vec3 vView = -normalize(vViewPos); + vec3 vHalfWay = normalize(vView + vLightView); + float nDotH = dot(vNormalView, vHalfWay); + float fAtten = 1.0 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + float rho = dot(vNegLightDirView, vLightView); + float fSpotE = clamp((rho - vSpotParams.y) / (vSpotParams.x - vSpotParams.y), 0.0, 1.0); + float fSpotT = pow(fSpotE, vSpotParams.z); + + vOutDiffuse += vDiffuseColour * nDotL * fAtten * fSpotT; + vOutSpecular += vSpecularColour * pow(clamp(nDotH, 0.0, 1.0), fSpecularPower) * fAtten * fSpotT; + } +} diff --git a/res/dist/media/RTShaderLib/FFPLib_Lighting.glsles b/res/dist/media/RTShaderLib/FFPLib_Lighting.glsles new file mode 100644 index 00000000000..0e1b67e2927 --- /dev/null +++ b/res/dist/media/RTShaderLib/FFPLib_Lighting.glsles @@ -0,0 +1,227 @@ +#version 100 +precision highp float; +precision highp int; +precision lowp sampler2D; +precision lowp samplerCube; +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Program Name: FFPLib_Lighting +// Program Desc: Lighting functions of the FFP. +// Program Type: Vertex shader +// Language: GLSL ES +// Notes: Implements core functions for FFPLighting class. +// based on lighting engine. +// See http://msdn.microsoft.com/en-us/library/bb147178.aspx +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +void FFP_Light_Directional_Diffuse(in mat4 mWorldViewIT, + in vec3 vNormal, + in vec3 vNegLightDirView, + in vec3 vDiffuseColour, + in vec3 vBaseColour, + out vec3 vOut) +{ + vec3 vNormalView = normalize((mWorldViewIT * vec4(vNormal.xyz, 1.0)).xyz); + float nDotL = dot(vNormalView, vNegLightDirView); + + vOut = vBaseColour + vDiffuseColour * clamp(nDotL, 0.0, 1.0); +} + + +//----------------------------------------------------------------------------- +void FFP_Light_Directional_DiffuseSpecular(in mat4 mWorldView, + in vec4 vPos, + in mat4 mWorldViewIT, + in vec3 vNormal, + in vec3 vNegLightDirView, + in vec3 vDiffuseColour, + in vec3 vSpecularColour, + in float fSpecularPower, + in vec3 vBaseDiffuseColour, + in vec3 vBaseSpecularColour, + out vec3 vOutDiffuse, + out vec3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + vec3 vNormalView = normalize((mWorldViewIT * vec4(vNormal.xyz, 1.0)).xyz); + float nDotL = dot(vNormalView, vNegLightDirView); + vec3 vView = -normalize((mWorldView * vPos).xyz); + vec3 vHalfWay = normalize(vView + vNegLightDirView); + float nDotH = dot(vNormalView, vHalfWay); + + if (nDotL > 0.0) + { + vOutDiffuse += vDiffuseColour * nDotL; + vOutSpecular += vSpecularColour * pow(clamp(nDotH, 0.0, 1.0), fSpecularPower); + } +} + + +//----------------------------------------------------------------------------- +void FFP_Light_Point_Diffuse(in mat4 mWorldView, + in vec4 vPos, + in mat4 mWorldViewIT, + in vec3 vNormal, + in vec3 vLightPosView, + in vec4 vAttParams, + in vec3 vDiffuseColour, + in vec3 vBaseColour, + out vec3 vOut) +{ + vOut = vBaseColour; + + vec3 vViewPos = (mWorldView * vPos).xyz; + vec3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + vec3 vNormalView = normalize((mWorldViewIT * vec4(vNormal.xyz, 1.0)).xyz); + float nDotL = dot(vNormalView, normalize(vLightView)); + + if (nDotL > 0.0 && fLightD <= vAttParams.x) + { + float fAtten = 1.0 / (vAttParams.y + vAttParams.z * fLightD + vAttParams.w * fLightD * fLightD); + + vOut += vDiffuseColour * nDotL * fAtten; + } +} + +//----------------------------------------------------------------------------- +void FFP_Light_Point_DiffuseSpecular(in mat4 mWorldView, + in vec4 vPos, + in mat4 mWorldViewIT, + in vec3 vNormal, + in vec3 vLightPosView, + in vec4 vAttParams, + in vec3 vDiffuseColour, + in vec3 vSpecularColour, + in float fSpecularPower, + in vec3 vBaseDiffuseColour, + in vec3 vBaseSpecularColour, + out vec3 vOutDiffuse, + out vec3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + vec3 vViewPos = (mWorldView * vPos).xyz; + vec3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + + vLightView = normalize(vLightView); + vec3 vNormalView = normalize((mWorldViewIT * vec4(vNormal.xyz, 1.0)).xyz); + float nDotL = dot(vNormalView, vLightView); + + if (nDotL > 0.0 && fLightD <= vAttParams.x) + { + vec3 vView = -normalize(vViewPos); + vec3 vHalfWay = normalize(vView + vLightView); + float nDotH = dot(vNormalView, vHalfWay); + float fAtten = 1.0 / (vAttParams.y + vAttParams.z * fLightD + vAttParams.w * fLightD * fLightD); + + vOutDiffuse += vDiffuseColour * nDotL * fAtten; + vOutSpecular += vSpecularColour * pow(clamp(nDotH, 0.0, 1.0), fSpecularPower) * fAtten; + } +} + +//----------------------------------------------------------------------------- +void FFP_Light_Spot_Diffuse(in mat4 mWorldView, + in vec4 vPos, + in mat4 mWorldViewIT, + in vec3 vNormal, + in vec3 vLightPosView, + in vec3 vNegLightDirView, + in vec4 vAttParams, + in vec3 vSpotParams, + in vec3 vDiffuseColour, + in vec3 vBaseColour, + out vec3 vOut) +{ + vOut = vBaseColour; + + vec3 vViewPos = (mWorldView * vPos).xyz; + vec3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + vLightView = normalize(vLightView); + vec3 vNormalView = normalize((mWorldViewIT * vec4(vNormal.xyz, 1.0)).xyz); + float nDotL = dot(vNormalView, vLightView); + + if (nDotL > 0.0 && fLightD <= vAttParams.x) + { + float fAtten = 1.0 / (vAttParams.y + vAttParams.z * fLightD + vAttParams.w * fLightD * fLightD); + float rho = dot(vNegLightDirView, vLightView); + float fSpotE = clamp((rho - vSpotParams.y) / (vSpotParams.x - vSpotParams.y), 0.0, 1.0); + float fSpotT = pow(fSpotE, vSpotParams.z); + + vOut += vDiffuseColour * nDotL * fAtten * fSpotT; + } +} + +//----------------------------------------------------------------------------- +void FFP_Light_Spot_DiffuseSpecular(in mat4 mWorldView, + in vec4 vPos, + in mat4 mWorldViewIT, + in vec3 vNormal, + in vec3 vLightPosView, + in vec3 vNegLightDirView, + in vec4 vAttParams, + in vec3 vSpotParams, + in vec3 vDiffuseColour, + in vec3 vSpecularColour, + in float fSpecularPower, + in vec3 vBaseDiffuseColour, + in vec3 vBaseSpecularColour, + out vec3 vOutDiffuse, + out vec3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + vec3 vViewPos = (mWorldView * vPos).xyz; + vec3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + vLightView = normalize(vLightView); + vec3 vNormalView = normalize((mWorldViewIT * vec4(vNormal.xyz, 1.0)).xyz); + float nDotL = dot(vNormalView, vLightView); + + if (nDotL > 0.0 && fLightD <= vAttParams.x) + { + vec3 vView = -normalize(vViewPos); + vec3 vHalfWay = normalize(vView + vLightView); + float nDotH = dot(vNormalView, vHalfWay); + float fAtten = 1.0 / (vAttParams.y + vAttParams.z * fLightD + vAttParams.w * fLightD * fLightD); + float rho = dot(vNegLightDirView, vLightView); + float fSpotE = clamp((rho - vSpotParams.y) / (vSpotParams.x - vSpotParams.y), 0.0, 1.0); + float fSpotT = pow(fSpotE, vSpotParams.z); + + vOutDiffuse += vDiffuseColour * nDotL * fAtten * fSpotT; + vOutSpecular += vSpecularColour * pow(clamp(nDotH, 0.0, 1.0), fSpecularPower) * fAtten * fSpotT; + } +} diff --git a/res/dist/media/RTShaderLib/FFPLib_Lighting.hlsl b/res/dist/media/RTShaderLib/FFPLib_Lighting.hlsl new file mode 100644 index 00000000000..e1a16f149e3 --- /dev/null +++ b/res/dist/media/RTShaderLib/FFPLib_Lighting.hlsl @@ -0,0 +1,225 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Program Name: FFPLib_Lighting +// Program Desc: Lighting functions of the FFP. +// Program Type: Vertex shader +// Language: HLSL +// Notes: Implements core functions for FFPLighting class. +// based on lighting engine. +// See http://msdn.microsoft.com/en-us/library/bb147178.aspx +//----------------------------------------------------------------------------- + + +//----------------------------------------------------------------------------- +void FFP_Light_Directional_Diffuse(in float4x4 mWorldViewIT, + in float3 vNormal, + in float3 vNegLightDirView, + in float3 vDiffuseColour, + in float3 vBaseColour, + out float3 vOut) +{ + float3 vNormalView = normalize(mul((float3x3)mWorldViewIT, vNormal)); + float nDotL = dot(vNormalView, vNegLightDirView); + + vOut = vBaseColour + vDiffuseColour * saturate(nDotL); +} + + +//----------------------------------------------------------------------------- +void FFP_Light_Directional_DiffuseSpecular(in float4x4 mWorldView, + in float4 vPos, + in float4x4 mWorldViewIT, + in float3 vNormal, + in float3 vNegLightDirView, + in float3 vDiffuseColour, + in float3 vSpecularColour, + in float fSpecularPower, + in float3 vBaseDiffuseColour, + in float3 vBaseSpecularColour, + out float3 vOutDiffuse, + out float3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + float3 vNormalView = normalize(mul((float3x3)mWorldViewIT, vNormal)); + float nDotL = dot(vNormalView, vNegLightDirView); + float3 vView = -normalize(mul(mWorldView, vPos).xyz); + float3 vHalfWay = normalize(vView + vNegLightDirView); + float nDotH = dot(vNormalView, vHalfWay); + + if (nDotL > 0) + { + vOutDiffuse += vDiffuseColour * nDotL; + vOutSpecular += vSpecularColour * pow(saturate(nDotH), fSpecularPower); + } +} + + +//----------------------------------------------------------------------------- +void FFP_Light_Point_Diffuse(in float4x4 mWorldView, + in float4 vPos, + in float4x4 mWorldViewIT, + in float3 vNormal, + in float3 vLightPosView, + in float4 vAttParams, + in float3 vDiffuseColour, + in float3 vBaseColour, + out float3 vOut) +{ + vOut = vBaseColour; + + float3 vViewPos = mul(mWorldView, vPos).xyz; + float3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + float3 vNormalView = normalize(mul((float3x3)mWorldViewIT, vNormal)); + float nDotL = dot(vNormalView, normalize(vLightView)); + + if (nDotL > 0 && fLightD <= vAttParams.x) + { + float fAtten = 1 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + + vOut += vDiffuseColour * nDotL * fAtten; + } +} + +//----------------------------------------------------------------------------- +void FFP_Light_Point_DiffuseSpecular(in float4x4 mWorldView, + in float4 vPos, + in float4x4 mWorldViewIT, + in float3 vNormal, + in float3 vLightPosView, + in float4 vAttParams, + in float3 vDiffuseColour, + in float3 vSpecularColour, + in float fSpecularPower, + in float3 vBaseDiffuseColour, + in float3 vBaseSpecularColour, + out float3 vOutDiffuse, + out float3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + float3 vViewPos = mul(mWorldView, vPos).xyz; + float3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + + vLightView = normalize(vLightView); + float3 vNormalView = normalize(mul((float3x3)mWorldViewIT, vNormal)); + float nDotL = dot(vNormalView, vLightView); + + if (nDotL > 0 && fLightD <= vAttParams.x) + { + float3 vView = -normalize(vViewPos); + float3 vHalfWay = normalize(vView + vLightView); + float nDotH = dot(vNormalView, vHalfWay); + float fAtten = 1 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + + vOutDiffuse += vDiffuseColour * nDotL * fAtten; + vOutSpecular += vSpecularColour * pow(saturate(nDotH), fSpecularPower) * fAtten; + } +} + +//----------------------------------------------------------------------------- +void FFP_Light_Spot_Diffuse(in float4x4 mWorldView, + in float4 vPos, + in float4x4 mWorldViewIT, + in float3 vNormal, + in float3 vLightPosView, + in float3 vNegLightDirView, + in float4 vAttParams, + in float3 vSpotParams, + in float3 vDiffuseColour, + in float3 vBaseColour, + out float3 vOut) +{ + vOut = vBaseColour; + + float3 vViewPos = mul(mWorldView, vPos).xyz; + float3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + vLightView = normalize(vLightView); + float3 vNormalView = normalize(mul((float3x3)mWorldViewIT, vNormal)); + float nDotL = dot(vNormalView, vLightView); + + if (nDotL > 0 && fLightD <= vAttParams.x) + { + float fAtten = 1 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + float rho = dot(vNegLightDirView, vLightView); + float fSpotE = saturate((rho - vSpotParams.y) / (vSpotParams.x - vSpotParams.y)); + float fSpotT = pow(fSpotE, vSpotParams.z); + + vOut += vDiffuseColour * nDotL * fAtten * fSpotT; + } +} + +//----------------------------------------------------------------------------- +void FFP_Light_Spot_DiffuseSpecular(in float4x4 mWorldView, + in float4 vPos, + in float4x4 mWorldViewIT, + in float3 vNormal, + in float3 vLightPosView, + in float3 vNegLightDirView, + in float4 vAttParams, + in float3 vSpotParams, + in float3 vDiffuseColour, + in float3 vSpecularColour, + in float fSpecularPower, + in float3 vBaseDiffuseColour, + in float3 vBaseSpecularColour, + out float3 vOutDiffuse, + out float3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + float3 vViewPos = mul(mWorldView, vPos).xyz; + float3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + vLightView = normalize(vLightView); + float3 vNormalView = normalize(mul((float3x3)mWorldViewIT, vNormal)); + float nDotL = dot(vNormalView, vLightView); + + + + if (nDotL > 0 && fLightD <= vAttParams.x) + { + float3 vView = -normalize(vViewPos); + float3 vHalfWay = normalize(vView + vLightView); + float nDotH = dot(vNormalView, vHalfWay); + float fAtten = 1 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + float rho = dot(vNegLightDirView, vLightView); + float fSpotE = saturate((rho - vSpotParams.y) / (vSpotParams.x - vSpotParams.y)); + float fSpotT = pow(fSpotE, vSpotParams.z); + + vOutDiffuse += vDiffuseColour * nDotL * fAtten * fSpotT; + vOutSpecular += vSpecularColour * pow(saturate(nDotH), fSpecularPower) * fAtten * fSpotT; + } +} diff --git a/res/dist/media/RTShaderLib/FFPLib_Texturing.cg b/res/dist/media/RTShaderLib/FFPLib_Texturing.cg new file mode 100644 index 00000000000..202062323f2 --- /dev/null +++ b/res/dist/media/RTShaderLib/FFPLib_Texturing.cg @@ -0,0 +1,319 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Program Name: FFPLib_TextureStage +// Program Desc: Texture functions of the FFP. +// Program Type: Vertex/Pixel shader +// Language: CG +// Notes: Implements core functions for FFPTexturing class. +// based on texturing operations needed by render system. +// Implements texture coordinate processing: +// see http://msdn.microsoft.com/en-us/library/bb206247.aspx +// Implements texture blending operation: +// see http://msdn.microsoft.com/en-us/library/bb206241.aspx +//----------------------------------------------------------------------------- + + +//----------------------------------------------------------------------------- +void FFP_TransformTexCoord(in float4x4 m, in float2 v, out float2 vOut) +{ + vOut = mul(m, float4(v, 0, 1)).xy; +} + +//----------------------------------------------------------------------------- +void FFP_TransformTexCoord(in float4x4 m, in float3 v, out float3 vOut) +{ + vOut = mul(m, float4(v, 1)).xyz; +} + +//----------------------------------------------------------------------------- +void FFP_GenerateTexCoord_EnvMap_Normal(in float4x4 mWorldIT, + in float4x4 mView, + in float3 vNormal, + out float3 vOut) +{ + float3 vWorldNormal = mul((float3x3)mWorldIT, vNormal); + float3 vViewNormal = mul((float3x3)mView, vWorldNormal); + + vOut = vViewNormal; +} + +//----------------------------------------------------------------------------- +void FFP_GenerateTexCoord_EnvMap_Normal(in float4x4 mWorldIT, + in float4x4 mView, + in float4x4 mTexture, + in float3 vNormal, + out float3 vOut) +{ + float3 vWorldNormal = mul((float3x3)mWorldIT, vNormal); + float3 vViewNormal = mul((float3x3)mView, vWorldNormal); + + vOut = mul(mTexture, float4(vViewNormal, 1)).xyz; +} + +//----------------------------------------------------------------------------- +void FFP_GenerateTexCoord_EnvMap_Sphere(in float4x4 mWorld, + in float4x4 mView, + in float3 vNormal, + out float2 vOut) +{ + float3 vWorldNormal = mul((float3x3)mWorld, vNormal); + float3 vViewNormal = mul((float3x3)mView, vWorldNormal); + + vOut.x = vViewNormal.x/2 + 0.5; + vOut.y = -vViewNormal.y/2 + 0.5; +} + +//----------------------------------------------------------------------------- +void FFP_GenerateTexCoord_EnvMap_Sphere(in float4x4 mWorld, + in float4x4 mView, + in float4x4 mTexture, + in float3 vNormal, + out float2 vOut) +{ + float3 vWorldNormal = mul((float3x3)mWorld, vNormal); + float3 vViewNormal = mul((float3x3)mView, vWorldNormal); + float2 vSphereCoords; + + vSphereCoords.x = vViewNormal.x/2 + 0.5; + vSphereCoords.y = -vViewNormal.y/2 + 0.5; + + vOut = mul(mTexture, float4(vSphereCoords, 0, 0)).xy; +} + +//----------------------------------------------------------------------------- +void FFP_GenerateTexCoord_EnvMap_Reflect(in float4x4 mWorld, + in float4x4 mWorldIT, + in float4x4 mView, + in float3 vNormal, + in float4 vPos, + out float3 vOut) +{ + mView[2][0] = -mView[2][0]; + mView[2][1] = -mView[2][1]; + mView[2][2] = -mView[2][2]; + mView[2][3] = -mView[2][3]; + + float4x4 matViewT = transpose(mView); + + float3 vWorldNormal = mul((float3x3)mWorldIT, vNormal); + float3 vViewNormal = mul((float3x3)mView, vWorldNormal); + float4 vWorldPos = mul(mWorld, vPos); + float3 vNormViewPos = normalize(mul(mView, vWorldPos).xyz); + + float3 vReflect = reflect(vNormViewPos, vViewNormal); + + matViewT[2][0] = -matViewT[2][0]; + matViewT[2][1] = -matViewT[2][1]; + matViewT[2][2] = -matViewT[2][2]; + vReflect = mul((float3x3)matViewT, vReflect); + + vOut = vReflect; +} + +//----------------------------------------------------------------------------- +void FFP_GenerateTexCoord_EnvMap_Reflect(in float4x4 mWorld, + in float4x4 mWorldIT, + in float4x4 mView, + in float4x4 mTexture, + in float3 vNormal, + in float4 vPos, + out float3 vOut) +{ + mView[2][0] = -mView[2][0]; + mView[2][1] = -mView[2][1]; + mView[2][2] = -mView[2][2]; + mView[2][3] = -mView[2][3]; + + float4x4 matViewT = transpose(mView); + + float3 vWorldNormal = mul((float3x3)mWorldIT, vNormal); + float3 vViewNormal = mul((float3x3)mView, vWorldNormal); + float4 vWorldPos = mul(mWorld, vPos); + float3 vNormViewPos = normalize(mul(mView, vWorldPos).xyz); + + float3 vReflect = reflect(vNormViewPos, vViewNormal); + + matViewT[2][0] = -matViewT[2][0]; + matViewT[2][1] = -matViewT[2][1]; + matViewT[2][2] = -matViewT[2][2]; + vReflect = mul((float3x3)matViewT, vReflect); + + vReflect = mul(mTexture, float4(vReflect,1)).xyz; + + vOut = vReflect; +} + +//----------------------------------------------------------------------------- +void FFP_GenerateTexCoord_Projection(in float4x4 mWorld, + in float4x4 mTexViewProjImage, + in float4 vPos, + out float3 vOut) +{ + float4 vWorldPos = mul(mWorld, vPos); + float4 vTexturePos = mul(mTexViewProjImage, vWorldPos); + + vOut = float3(vTexturePos.xy, vTexturePos.w); +} + +//----------------------------------------------------------------------------- +void FFP_SampleTexture(in sampler1D s, + in float f, + out float4 t) +{ + t = tex1D(s, f); +} + +//----------------------------------------------------------------------------- +void FFP_SampleTexture(in sampler2D s, + in float2 f, + out float4 t) +{ + t = tex2D(s, f); +} + +//----------------------------------------------------------------------------- +void FFP_SampleTextureProj(in sampler2D s, + in float3 f, + out float4 t) +{ + t = tex2D(s, f.xy/f.z); +} + +//----------------------------------------------------------------------------- +void FFP_SampleTexture(in sampler3D s, + in float3 f, + out float4 t) +{ + t = tex3D(s, f); +} + +//----------------------------------------------------------------------------- +void FFP_SampleTexture(in samplerCUBE s, + in float3 f, + out float4 t) +{ + t = texCUBE(s, f); +} + + +//----------------------------------------------------------------------------- +void FFP_ModulateX2(in float vIn0, in float vIn1, out float vOut) +{ + vOut = vIn0 * vIn1 * 2; +} + +//----------------------------------------------------------------------------- +void FFP_ModulateX2(in float2 vIn0, in float2 vIn1, out float2 vOut) +{ + vOut = vIn0 * vIn1 * 2; +} + +//----------------------------------------------------------------------------- +void FFP_ModulateX2(in float3 vIn0, in float3 vIn1, out float3 vOut) +{ + vOut = vIn0 * vIn1 * 2; +} + +//----------------------------------------------------------------------------- +void FFP_ModulateX2(in float4 vIn0, in float4 vIn1, out float4 vOut) +{ + vOut = vIn0 * vIn1 * 2; +} + +//----------------------------------------------------------------------------- +void FFP_ModulateX4(in float vIn0, in float vIn1, out float vOut) +{ + vOut = vIn0 * vIn1 * 4; +} + +//----------------------------------------------------------------------------- +void FFP_ModulateX4(in float2 vIn0, in float2 vIn1, out float2 vOut) +{ + vOut = vIn0 * vIn1 * 4; +} + +//----------------------------------------------------------------------------- +void FFP_ModulateX4(in float3 vIn0, in float3 vIn1, out float3 vOut) +{ + vOut = vIn0 * vIn1 * 4; +} + +//----------------------------------------------------------------------------- +void FFP_ModulateX4(in float4 vIn0, in float4 vIn1, out float4 vOut) +{ + vOut = vIn0 * vIn1 * 4; +} + +//----------------------------------------------------------------------------- +void FFP_AddSigned(in float vIn0, in float vIn1, out float vOut) +{ + vOut = vIn0 + vIn1 - 0.5; +} + +//----------------------------------------------------------------------------- +void FFP_AddSigned(in float2 vIn0, in float2 vIn1, out float2 vOut) +{ + vOut = vIn0 + vIn1 - 0.5; +} + +//----------------------------------------------------------------------------- +void FFP_AddSigned(in float3 vIn0, in float3 vIn1, out float3 vOut) +{ + vOut = vIn0 + vIn1 - 0.5; +} + +//----------------------------------------------------------------------------- +void FFP_AddSigned(in float4 vIn0, in float4 vIn1, out float4 vOut) +{ + vOut = vIn0 + vIn1 - 0.5; +} + +//----------------------------------------------------------------------------- +void FFP_AddSmooth(in float vIn0, in float vIn1, out float vOut) +{ + vOut = vIn0 + vIn1 - (vIn0 * vIn1); +} + +//----------------------------------------------------------------------------- +void FFP_AddSmooth(in float2 vIn0, in float2 vIn1, out float2 vOut) +{ + vOut = vIn0 + vIn1 - (vIn0 * vIn1); +} + +//----------------------------------------------------------------------------- +void FFP_AddSmooth(in float3 vIn0, in float3 vIn1, out float3 vOut) +{ + vOut = vIn0 + vIn1 - (vIn0 * vIn1); +} + +//----------------------------------------------------------------------------- +void FFP_AddSmooth(in float4 vIn0, in float4 vIn1, out float4 vOut) +{ + vOut = vIn0 + vIn1 - (vIn0 * vIn1); +} diff --git a/res/dist/media/RTShaderLib/FFPLib_Texturing.glsl b/res/dist/media/RTShaderLib/FFPLib_Texturing.glsl new file mode 100644 index 00000000000..de76ec53b37 --- /dev/null +++ b/res/dist/media/RTShaderLib/FFPLib_Texturing.glsl @@ -0,0 +1,334 @@ +#version 120 +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Program Name: FFPLib_TextureStage +// Program Desc: Texture functions of the FFP. +// Program Type: Vertex/Pixel shader +// Language: GLSL +// Notes: Implements core functions for FFPTexturing class. +// based on texturing operations needed by render system. +// Implements texture coordinate processing: +// see http://msdn.microsoft.com/en-us/library/bb206247.aspx +// Implements texture blending operation: +// see http://msdn.microsoft.com/en-us/library/bb206241.aspx +//----------------------------------------------------------------------------- + + +//----------------------------------------------------------------------------- +void FFP_TransformTexCoord(in mat4 m, in vec2 v, out vec2 vOut) +{ + vOut = (m * vec4(v, 1.0, 1.0)).xy; +} +//----------------------------------------------------------------------------- +void FFP_TransformTexCoord(in mat4 m, in vec4 v, out vec2 vOut) +{ + vOut = (m * v).xy; +} + +//----------------------------------------------------------------------------- +void FFP_TransformTexCoord(in mat4 m, in vec3 v, out vec3 vOut) +{ + vOut = (m * vec4(v, 1.0)).xyz; +} + +//----------------------------------------------------------------------------- +void FFP_GenerateTexCoord_EnvMap_Normal(in mat4 mWorldIT, + in mat4 mView, + in vec3 vNormal, + out vec3 vOut) +{ + vec3 vWorldNormal = (mWorldIT * vec4(vNormal, 1.0)).xyz; + vec3 vViewNormal = (mView * vec4(vWorldNormal, 1.0)).xyz; + + vOut = vViewNormal; +} + +//----------------------------------------------------------------------------- +void FFP_GenerateTexCoord_EnvMap_Normal(in mat4 mWorldIT, + in mat4 mView, + in mat4 mTexture, + in vec3 vNormal, + out vec3 vOut) +{ + vec3 vWorldNormal = (mWorldIT * vec4(vNormal, 1.0)).xyz; + vec3 vViewNormal = (mView * vec4(vWorldNormal, 1.0)).xyz; + + vOut = (mTexture * vec4(vViewNormal, 1.0)).xyz; +} + +//----------------------------------------------------------------------------- +void FFP_GenerateTexCoord_EnvMap_Sphere(in mat4 mWorld, + in mat4 mView, + in vec3 vNormal, + out vec2 vOut) +{ + vec3 vWorldNormal = (mWorld * vec4(vNormal, 1.0)).xyz; + vec3 vViewNormal = (mView * vec4(vWorldNormal, 1.0)).xyz; + + vOut.x = vViewNormal.x/2.0 + 0.5; + vOut.y = -vViewNormal.y/2.0 + 0.5; +} + +//----------------------------------------------------------------------------- +void FFP_GenerateTexCoord_EnvMap_Sphere(in mat4 mWorld, + in mat4 mView, + in mat4 mTexture, + in vec3 vNormal, + out vec2 vOut) +{ + vec3 vWorldNormal = (mWorld* vec4(vNormal, 1.0)).xyz; + vec3 vViewNormal = (mView * vec4(vWorldNormal, 1.0)).xyz; + + vec2 vSphereCoords; + + vSphereCoords.x = vViewNormal.x/2.0 + 0.5; + vSphereCoords.y = -vViewNormal.y/2.0 + 0.5; + + vOut = (mTexture * vec4(vSphereCoords, 0.0, 0.0)).xy; +} + +//----------------------------------------------------------------------------- +void FFP_GenerateTexCoord_EnvMap_Reflect(in mat4 mWorld, + in mat4 mWorldIT, + in mat4 mView, + in vec3 vNormal, + in vec4 vPos, + out vec3 vOut) +{ + mView[0][2] = -mView[0][2]; + mView[1][2] = -mView[1][2]; + mView[2][2] = -mView[2][2]; + mView[3][2] = -mView[3][2]; + + mat4 matViewT = transpose(mView); + + vec3 vWorldNormal = (mWorldIT * vec4(vNormal, 0.0)).xyz; + vec3 vViewNormal = (mView * vec4(vWorldNormal, 0.0)).xyz; + vec4 vWorldPos = mWorld * vPos; + vec3 vNormViewPos = normalize((mView * vWorldPos).xyz); + + vec3 vReflect = reflect(vNormViewPos, vViewNormal); + + matViewT[0][2] = -matViewT[0][2]; + matViewT[1][2] = -matViewT[1][2]; + matViewT[2][2] = -matViewT[2][2]; + vReflect = (matViewT * vec4(vReflect, 1.0)).xyz; + + vOut = vReflect; +} + +//----------------------------------------------------------------------------- +void FFP_GenerateTexCoord_EnvMap_Reflect(in mat4 mWorld, + in mat4 mWorldIT, + in mat4 mView, + in mat4 mTexture, + in vec3 vNormal, + in vec4 vPos, + out vec3 vOut) +{ + mView[0][2] = -mView[0][2]; + mView[1][2] = -mView[1][2]; + mView[2][2] = -mView[2][2]; + mView[3][2] = -mView[3][2]; + + mat4 matViewT = transpose(mView); + + vec3 vWorldNormal = (mWorldIT * vec4(vNormal, 0.0)).xyz; + vec3 vViewNormal = (mView * vec4(vWorldNormal, 0.0)).xyz; + vec4 vWorldPos = mWorld * vPos; + vec3 vNormViewPos = normalize((mView * vWorldPos).xyz); + + vec3 vReflect = reflect(vNormViewPos, vViewNormal); + + matViewT[0][2] = -matViewT[0][2]; + matViewT[1][2] = -matViewT[1][2]; + matViewT[2][2] = -matViewT[2][2]; + vReflect = (matViewT * vec4(vReflect, 1.0)).xyz; + + vReflect = (mTexture * vec4(vReflect, 1.0)).xyz; + + vOut = vReflect; +} + +//----------------------------------------------------------------------------- +void FFP_GenerateTexCoord_Projection(in mat4 mWorld, + in mat4 mTexViewProjImage, + in vec4 vPos, + out vec3 vOut) +{ + vec4 vWorldPos = mWorld * vPos; + vec4 vTexturePos = mTexViewProjImage * vWorldPos; + + vOut = vTexturePos.xyw; +} + +//----------------------------------------------------------------------------- +void FFP_SampleTexture(in sampler1D s, + in float f, + out vec4 t) +{ + t = texture1D(s, f); +} + +//----------------------------------------------------------------------------- +void FFP_SampleTexture(in sampler2D s, + in vec2 f, + out vec4 t) +{ + t = texture2D (s, f); +} +//----------------------------------------------------------------------------- +void FFP_SampleTexture(in sampler2D s, + in vec4 f, + out vec4 t) +{ + t = texture2D (s, vec2(f.xy)); +} + +//----------------------------------------------------------------------------- +void FFP_SampleTextureProj(in sampler2D s, + in vec3 f, + out vec4 t) +{ + t = texture2D(s, f.xy/f.z); +} + +//----------------------------------------------------------------------------- +void FFP_SampleTexture(in sampler3D s, + in vec3 f, + out vec4 t) +{ + t = texture3D(s, f); +} + +//----------------------------------------------------------------------------- +void FFP_SampleTexture(in samplerCube s, + in vec3 f, + out vec4 t) +{ + t = textureCube(s, f); +} + + +//----------------------------------------------------------------------------- +void FFP_ModulateX2(in float vIn0, in float vIn1, out float vOut) +{ + vOut = vIn0 * vIn1 * 2.0; +} + +//----------------------------------------------------------------------------- +void FFP_ModulateX2(in vec2 vIn0, in vec2 vIn1, out vec2 vOut) +{ + vOut = vIn0 * vIn1 * 2.0; +} + +//----------------------------------------------------------------------------- +void FFP_ModulateX2(in vec3 vIn0, in vec3 vIn1, out vec3 vOut) +{ + vOut = vIn0 * vIn1 * 2.0; +} + +//----------------------------------------------------------------------------- +void FFP_ModulateX2(in vec4 vIn0, in vec4 vIn1, out vec4 vOut) +{ + vOut = vIn0 * vIn1 * 2.0; +} + +//----------------------------------------------------------------------------- +void FFP_ModulateX4(in float vIn0, in float vIn1, out float vOut) +{ + vOut = vIn0 * vIn1 * 4.0; +} + +//----------------------------------------------------------------------------- +void FFP_ModulateX4(in vec2 vIn0, in vec2 vIn1, out vec2 vOut) +{ + vOut = vIn0 * vIn1 * 4.0; +} + +//----------------------------------------------------------------------------- +void FFP_ModulateX4(in vec3 vIn0, in vec3 vIn1, out vec3 vOut) +{ + vOut = vIn0 * vIn1 * 4.0; +} + +//----------------------------------------------------------------------------- +void FFP_ModulateX4(in vec4 vIn0, in vec4 vIn1, out vec4 vOut) +{ + vOut = vIn0 * vIn1 * 4.0; +} + +//----------------------------------------------------------------------------- +void FFP_AddSigned(in float vIn0, in float vIn1, out float vOut) +{ + vOut = vIn0 + vIn1 - 0.5; +} + +//----------------------------------------------------------------------------- +void FFP_AddSigned(in vec2 vIn0, in vec2 vIn1, out vec2 vOut) +{ + vOut = vIn0 + vIn1 - 0.5; +} + +//----------------------------------------------------------------------------- +void FFP_AddSigned(in vec3 vIn0, in vec3 vIn1, out vec3 vOut) +{ + vOut = vIn0 + vIn1 - 0.5; +} + +//----------------------------------------------------------------------------- +void FFP_AddSigned(in vec4 vIn0, in vec4 vIn1, out vec4 vOut) +{ + vOut = vIn0 + vIn1 - 0.5; +} + +//----------------------------------------------------------------------------- +void FFP_AddSmooth(in float vIn0, in float vIn1, out float vOut) +{ + vOut = vIn0 + vIn1 - (vIn0 * vIn1); +} + +//----------------------------------------------------------------------------- +void FFP_AddSmooth(in vec2 vIn0, in vec2 vIn1, out vec2 vOut) +{ + vOut = vIn0 + vIn1 - (vIn0 * vIn1); +} + +//----------------------------------------------------------------------------- +void FFP_AddSmooth(in vec3 vIn0, in vec3 vIn1, out vec3 vOut) +{ + vOut = vIn0 + vIn1 - (vIn0 * vIn1); +} + +//----------------------------------------------------------------------------- +void FFP_AddSmooth(in vec4 vIn0, in vec4 vIn1, out vec4 vOut) +{ + vOut = vIn0 + vIn1 - (vIn0 * vIn1); +} + diff --git a/res/dist/media/RTShaderLib/FFPLib_Texturing.glsles b/res/dist/media/RTShaderLib/FFPLib_Texturing.glsles new file mode 100644 index 00000000000..5184ab7b8e1 --- /dev/null +++ b/res/dist/media/RTShaderLib/FFPLib_Texturing.glsles @@ -0,0 +1,355 @@ +#version 100 +precision highp float; +precision highp int; +precision lowp sampler2D; +precision lowp samplerCube; +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Program Name: FFPLib_Texturing +// Program Desc: Texture functions of the FFP. +// Program Type: Vertex/Pixel shader +// Language: GLSL ES +// Notes: Implements core functions for FFPTexturing class. +// based on texturing operations needed by render system. +// Implements texture coordinate processing: +// see http://msdn.microsoft.com/en-us/library/bb206247.aspx +// Implements texture blending operation: +// see http://msdn.microsoft.com/en-us/library/bb206241.aspx +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +void FFP_TransformTexCoord(in mat4 m, in vec2 v, out vec2 vOut) +{ + vOut = (m * vec4(v, 1.0, 1.0)).xy; +} +//----------------------------------------------------------------------------- +void FFP_TransformTexCoord(in mat4 m, in vec4 v, out vec2 vOut) +{ + vOut = (m * v).xy; +} + +//----------------------------------------------------------------------------- +void FFP_TransformTexCoord(in mat4 m, in vec3 v, out vec3 vOut) +{ + vOut = (m * vec4(v, 1.0)).xyz; +} + +//----------------------------------------------------------------------------- +void FFP_GenerateTexCoord_EnvMap_Normal(in mat4 mWorldIT, + in mat4 mView, + in vec3 vNormal, + out vec3 vOut) +{ + vec3 vWorldNormal = (mWorldIT * vec4(vNormal, 1.0)).xyz; + vec3 vViewNormal = (mView * vec4(vWorldNormal, 1.0)).xyz; + + vOut = vViewNormal; +} + +//----------------------------------------------------------------------------- +void FFP_GenerateTexCoord_EnvMap_Normal(in mat4 mWorldIT, + in mat4 mView, + in mat4 mTexture, + in vec3 vNormal, + out vec3 vOut) +{ + vec3 vWorldNormal = (mWorldIT * vec4(vNormal, 1.0)).xyz; + vec3 vViewNormal = (mView * vec4(vWorldNormal, 1.0)).xyz; + + vOut = (mTexture * vec4(vViewNormal, 1.0)).xyz; +} + +//----------------------------------------------------------------------------- +void FFP_GenerateTexCoord_EnvMap_Sphere(in mat4 mWorld, + in mat4 mView, + in vec3 vNormal, + out vec2 vOut) +{ + vec3 vWorldNormal = (mWorld * vec4(vNormal, 1.0)).xyz; + vec3 vViewNormal = (mView * vec4(vWorldNormal, 1.0)).xyz; + + vOut.x = vViewNormal.x/2.0 + 0.5; + vOut.y = -vViewNormal.y/2.0 + 0.5; +} + +//----------------------------------------------------------------------------- +void FFP_GenerateTexCoord_EnvMap_Sphere(in mat4 mWorld, + in mat4 mView, + in mat4 mTexture, + in vec3 vNormal, + out vec2 vOut) +{ + vec3 vWorldNormal = (mWorld * vec4(vNormal, 1.0)).xyz; + vec3 vViewNormal = (mView * vec4(vWorldNormal, 1.0)).xyz; + + vec2 vSphereCoords; + + vSphereCoords.x = vViewNormal.x/2.0 + 0.5; + vSphereCoords.y = -vViewNormal.y/2.0 + 0.5; + + vOut = (mTexture * vec4(vSphereCoords, 0.0, 0.0)).xy; +} + +//----------------------------------------------------------------------------- +void FFP_GenerateTexCoord_EnvMap_Reflect(in mat4 mWorld, + in mat4 mWorldIT, + in mat4 mView, + in vec3 vNormal, + in vec4 vPos, + out vec3 vOut) +{ + mat4 matViewT; + + matViewT[0][0] = mView[0][0]; + matViewT[1][0] = mView[0][1]; + matViewT[2][0] = mView[0][2]; + matViewT[3][0] = mView[0][3]; + + matViewT[0][1] = mView[1][0]; + matViewT[1][1] = mView[1][1]; + matViewT[2][1] = mView[1][2]; + matViewT[3][1] = mView[1][3]; + + matViewT[0][2] = mView[2][0]; + matViewT[1][2] = mView[2][1]; + matViewT[2][2] = mView[2][2]; + matViewT[3][2] = mView[2][3]; + + matViewT[0][3] = mView[3][0]; + matViewT[1][3] = mView[3][1]; + matViewT[2][3] = mView[3][2]; + matViewT[3][3] = mView[3][3]; + + vec3 vWorldNormal = (mWorldIT * vec4(vNormal, 0.0)).xyz; + vec3 vViewNormal = (mView * vec4(vWorldNormal, 0.0)).xyz; + vec4 vWorldPos = mWorld * vPos; + vec3 vNormViewPos = normalize((mView * vWorldPos).xyz); + + vec3 vReflect = reflect(vNormViewPos, vViewNormal); + + matViewT[0][2] = -matViewT[0][2]; + matViewT[1][2] = -matViewT[1][2]; + matViewT[2][2] = -matViewT[2][2]; + vReflect = (matViewT * vec4(vReflect, 1.0)).xyz; + + vOut = vReflect; +} + +//----------------------------------------------------------------------------- +void FFP_GenerateTexCoord_EnvMap_Reflect(in mat4 mWorld, + in mat4 mWorldIT, + in mat4 mView, + in mat4 mTexture, + in vec3 vNormal, + in vec4 vPos, + out vec3 vOut) +{ + mat4 matViewT; + matViewT[0][0] = mView[0][0]; + matViewT[1][0] = mView[0][1]; + matViewT[2][0] = mView[0][2]; + matViewT[3][0] = mView[0][3]; + + matViewT[0][1] = mView[1][0]; + matViewT[1][1] = mView[1][1]; + matViewT[2][1] = mView[1][2]; + matViewT[3][1] = mView[1][3]; + + matViewT[0][2] = mView[2][0]; + matViewT[1][2] = mView[2][1]; + matViewT[2][2] = mView[2][2]; + matViewT[3][2] = mView[2][3]; + + matViewT[0][3] = mView[3][0]; + matViewT[1][3] = mView[3][1]; + matViewT[2][3] = mView[3][2]; + matViewT[3][3] = mView[3][3]; + + vec3 vWorldNormal = (mWorldIT * vec4(vNormal, 0.0)).xyz; + vec3 vViewNormal = (mView * vec4(vWorldNormal, 0.0)).xyz; + vec4 vWorldPos = mWorld * vPos; + vec3 vNormViewPos = normalize((mView * vWorldPos).xyz); + + vec3 vReflect = reflect(vNormViewPos, vViewNormal); + + matViewT[0][2] = -matViewT[0][2]; + matViewT[1][2] = -matViewT[1][2]; + matViewT[2][2] = -matViewT[2][2]; + vReflect = (matViewT * vec4(vReflect, 1.0)).xyz; + + vReflect = (mTexture * vec4(vReflect, 1.0)).xyz; + + vOut = vReflect; +} + +//----------------------------------------------------------------------------- +void FFP_GenerateTexCoord_Projection(in mat4 mWorld, + in mat4 mTexViewProjImage, + in vec4 vPos, + out vec3 vOut) +{ + vOut = (mTexViewProjImage * (mWorld * vPos)).xyw; +} + +//----------------------------------------------------------------------------- +void FFP_SampleTexture(in sampler2D s, + in float f, + out vec4 t) +{ + t = texture2D(s, vec2(f)); +} + +//----------------------------------------------------------------------------- +void FFP_SampleTexture(in sampler2D s, + in vec2 f, + out vec4 t) +{ + t = texture2D(s, f); +} + +//----------------------------------------------------------------------------- +void FFP_SampleTexture(in sampler2D s, + in vec4 f, + out vec4 t) +{ + t = texture2D(s, vec2(f.xy)); +} + +//----------------------------------------------------------------------------- +void FFP_SampleTextureProj(in sampler2D s, + in vec3 f, + out vec4 t) +{ + t = texture2D(s, f.xy / f.z); +} + +//----------------------------------------------------------------------------- +void FFP_SampleTexture(in samplerCube s, + in vec3 f, + out vec4 t) +{ + t = textureCube(s, f); +} + + +//----------------------------------------------------------------------------- +void FFP_ModulateX2(in float vIn0, in float vIn1, out float vOut) +{ + vOut = vIn0 * vIn1 * 2.0; +} + +//----------------------------------------------------------------------------- +void FFP_ModulateX2(in vec2 vIn0, in vec2 vIn1, out vec2 vOut) +{ + vOut = vIn0 * vIn1 * 2.0; +} + +//----------------------------------------------------------------------------- +void FFP_ModulateX2(in vec3 vIn0, in vec3 vIn1, out vec3 vOut) +{ + vOut = vIn0 * vIn1 * 2.0; +} + +//----------------------------------------------------------------------------- +void FFP_ModulateX2(in vec4 vIn0, in vec4 vIn1, out vec4 vOut) +{ + vOut = vIn0 * vIn1 * 2.0; +} + +//----------------------------------------------------------------------------- +void FFP_ModulateX4(in float vIn0, in float vIn1, out float vOut) +{ + vOut = vIn0 * vIn1 * 4.0; +} + +//----------------------------------------------------------------------------- +void FFP_ModulateX4(in vec2 vIn0, in vec2 vIn1, out vec2 vOut) +{ + vOut = vIn0 * vIn1 * 4.0; +} + +//----------------------------------------------------------------------------- +void FFP_ModulateX4(in vec3 vIn0, in vec3 vIn1, out vec3 vOut) +{ + vOut = vIn0 * vIn1 * 4.0; +} + +//----------------------------------------------------------------------------- +void FFP_ModulateX4(in vec4 vIn0, in vec4 vIn1, out vec4 vOut) +{ + vOut = vIn0 * vIn1 * 4.0; +} + +//----------------------------------------------------------------------------- +void FFP_AddSigned(in float vIn0, in float vIn1, out float vOut) +{ + vOut = vIn0 + vIn1 - 0.5; +} + +//----------------------------------------------------------------------------- +void FFP_AddSigned(in vec2 vIn0, in vec2 vIn1, out vec2 vOut) +{ + vOut = vIn0 + vIn1 - 0.5; +} + +//----------------------------------------------------------------------------- +void FFP_AddSigned(in vec3 vIn0, in vec3 vIn1, out vec3 vOut) +{ + vOut = vIn0 + vIn1 - 0.5; +} + +//----------------------------------------------------------------------------- +void FFP_AddSigned(in vec4 vIn0, in vec4 vIn1, out vec4 vOut) +{ + vOut = vIn0 + vIn1 - 0.5; +} + +//----------------------------------------------------------------------------- +void FFP_AddSmooth(in float vIn0, in float vIn1, out float vOut) +{ + vOut = vIn0 + vIn1 - (vIn0 * vIn1); +} + +//----------------------------------------------------------------------------- +void FFP_AddSmooth(in vec2 vIn0, in vec2 vIn1, out vec2 vOut) +{ + vOut = vIn0 + vIn1 - (vIn0 * vIn1); +} + +//----------------------------------------------------------------------------- +void FFP_AddSmooth(in vec3 vIn0, in vec3 vIn1, out vec3 vOut) +{ + vOut = vIn0 + vIn1 - (vIn0 * vIn1); +} + +//----------------------------------------------------------------------------- +void FFP_AddSmooth(in vec4 vIn0, in vec4 vIn1, out vec4 vOut) +{ + vOut = vIn0 + vIn1 - (vIn0 * vIn1); +} diff --git a/res/dist/media/RTShaderLib/FFPLib_Texturing.hlsl b/res/dist/media/RTShaderLib/FFPLib_Texturing.hlsl new file mode 100644 index 00000000000..a44b0b9c51a --- /dev/null +++ b/res/dist/media/RTShaderLib/FFPLib_Texturing.hlsl @@ -0,0 +1,319 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Program Name: FFPLib_TextureStage +// Program Desc: Texture functions of the FFP. +// Program Type: Vertex/Pixel shader +// Language: HLSL +// Notes: Implements core functions for FFPTexturing class. +// based on texturing operations needed by render system. +// Implements texture coordinate processing: +// see http://msdn.microsoft.com/en-us/library/bb206247.aspx +// Implements texture blending operation: +// see http://msdn.microsoft.com/en-us/library/bb206241.aspx +//----------------------------------------------------------------------------- + + +//----------------------------------------------------------------------------- +void FFP_TransformTexCoord(in float4x4 m, in float2 v, out float2 vOut) +{ + vOut = mul(m, float4(v, 0, 1)).xy; +} + +//----------------------------------------------------------------------------- +void FFP_TransformTexCoord(in float4x4 m, in float3 v, out float3 vOut) +{ + vOut = mul(m, float4(v, 1)).xyz; +} + +//----------------------------------------------------------------------------- +void FFP_GenerateTexCoord_EnvMap_Normal(in float4x4 mWorldIT, + in float4x4 mView, + in float3 vNormal, + out float3 vOut) +{ + float3 vWorldNormal = mul((float3x3)mWorldIT, vNormal); + float3 vViewNormal = mul((float3x3)mView, vWorldNormal); + + vOut = vViewNormal; +} + +//----------------------------------------------------------------------------- +void FFP_GenerateTexCoord_EnvMap_Normal(in float4x4 mWorldIT, + in float4x4 mView, + in float4x4 mTexture, + in float3 vNormal, + out float3 vOut) +{ + float3 vWorldNormal = mul((float3x3)mWorldIT, vNormal); + float3 vViewNormal = mul((float3x3)mView, vWorldNormal); + + vOut = mul(mTexture, float4(vViewNormal, 1)).xyz; +} + +//----------------------------------------------------------------------------- +void FFP_GenerateTexCoord_EnvMap_Sphere(in float4x4 mWorld, + in float4x4 mView, + in float3 vNormal, + out float2 vOut) +{ + float3 vWorldNormal = mul((float3x3)mWorld, vNormal); + float3 vViewNormal = mul((float3x3)mView, vWorldNormal); + + vOut.x = vViewNormal.x/2 + 0.5; + vOut.y = -vViewNormal.y/2 + 0.5; +} + +//----------------------------------------------------------------------------- +void FFP_GenerateTexCoord_EnvMap_Sphere(in float4x4 mWorld, + in float4x4 mView, + in float4x4 mTexture, + in float3 vNormal, + out float2 vOut) +{ + float3 vWorldNormal = mul((float3x3)mWorld, vNormal); + float3 vViewNormal = mul((float3x3)mView, vWorldNormal); + float2 vSphereCoords; + + vSphereCoords.x = vViewNormal.x/2 + 0.5; + vSphereCoords.y = -vViewNormal.y/2 + 0.5; + + vOut = mul(mTexture, float4(vSphereCoords, 0, 0)).xy; +} + +//----------------------------------------------------------------------------- +void FFP_GenerateTexCoord_EnvMap_Reflect(in float4x4 mWorld, + in float4x4 mWorldIT, + in float4x4 mView, + in float3 vNormal, + in float4 vPos, + out float3 vOut) +{ + mView[2][0] = -mView[2][0]; + mView[2][1] = -mView[2][1]; + mView[2][2] = -mView[2][2]; + mView[2][3] = -mView[2][3]; + + float4x4 matViewT = transpose(mView); + + float3 vWorldNormal = mul((float3x3)mWorldIT, vNormal); + float3 vViewNormal = mul((float3x3)mView, vWorldNormal); + float4 vWorldPos = mul(mWorld, vPos); + float3 vNormViewPos = normalize(mul(mView, vWorldPos).xyz); + + float3 vReflect = reflect(vNormViewPos, vViewNormal); + + matViewT[2][0] = -matViewT[2][0]; + matViewT[2][1] = -matViewT[2][1]; + matViewT[2][2] = -matViewT[2][2]; + vReflect = mul((float3x3)matViewT, vReflect); + + vOut = vReflect; +} + +//----------------------------------------------------------------------------- +void FFP_GenerateTexCoord_EnvMap_Reflect(in float4x4 mWorld, + in float4x4 mWorldIT, + in float4x4 mView, + in float4x4 mTexture, + in float3 vNormal, + in float4 vPos, + out float3 vOut) +{ + mView[2][0] = -mView[2][0]; + mView[2][1] = -mView[2][1]; + mView[2][2] = -mView[2][2]; + mView[2][3] = -mView[2][3]; + + float4x4 matViewT = transpose(mView); + + float3 vWorldNormal = mul((float3x3)mWorldIT, vNormal); + float3 vViewNormal = mul((float3x3)mView, vWorldNormal); + float4 vWorldPos = mul(mWorld, vPos); + float3 vNormViewPos = normalize(mul(mView, vWorldPos).xyz); + + float3 vReflect = reflect(vNormViewPos, vViewNormal); + + matViewT[2][0] = -matViewT[2][0]; + matViewT[2][1] = -matViewT[2][1]; + matViewT[2][2] = -matViewT[2][2]; + vReflect = mul((float3x3)matViewT, vReflect); + + vReflect = mul(mTexture, float4(vReflect,1)).xyz; + + vOut = vReflect; +} + +//----------------------------------------------------------------------------- +void FFP_GenerateTexCoord_Projection(in float4x4 mWorld, + in float4x4 mTexViewProjImage, + in float4 vPos, + out float3 vOut) +{ + float4 vWorldPos = mul(mWorld, vPos); + float4 vTexturePos = mul(mTexViewProjImage, vWorldPos); + + vOut = float3(vTexturePos.xy, vTexturePos.w); +} + +//----------------------------------------------------------------------------- +void FFP_SampleTexture(in sampler1D s, + in float f, + out float4 t) +{ + t = tex1D(s, f); +} + +//----------------------------------------------------------------------------- +void FFP_SampleTexture(in sampler2D s, + in float2 f, + out float4 t) +{ + t = tex2D(s, f); +} + +//----------------------------------------------------------------------------- +void FFP_SampleTextureProj(in sampler2D s, + in float3 f, + out float4 t) +{ + t = tex2D(s, f.xy/f.z); +} + +//----------------------------------------------------------------------------- +void FFP_SampleTexture(in sampler3D s, + in float3 f, + out float4 t) +{ + t = tex3D(s, f); +} + +//----------------------------------------------------------------------------- +void FFP_SampleTexture(in samplerCUBE s, + in float3 f, + out float4 t) +{ + t = texCUBE(s, f); +} + + +//----------------------------------------------------------------------------- +void FFP_ModulateX2(in float vIn0, in float vIn1, out float vOut) +{ + vOut = vIn0 * vIn1 * 2; +} + +//----------------------------------------------------------------------------- +void FFP_ModulateX2(in float2 vIn0, in float2 vIn1, out float2 vOut) +{ + vOut = vIn0 * vIn1 * 2; +} + +//----------------------------------------------------------------------------- +void FFP_ModulateX2(in float3 vIn0, in float3 vIn1, out float3 vOut) +{ + vOut = vIn0 * vIn1 * 2; +} + +//----------------------------------------------------------------------------- +void FFP_ModulateX2(in float4 vIn0, in float4 vIn1, out float4 vOut) +{ + vOut = vIn0 * vIn1 * 2; +} + +//----------------------------------------------------------------------------- +void FFP_ModulateX4(in float vIn0, in float vIn1, out float vOut) +{ + vOut = vIn0 * vIn1 * 4; +} + +//----------------------------------------------------------------------------- +void FFP_ModulateX4(in float2 vIn0, in float2 vIn1, out float2 vOut) +{ + vOut = vIn0 * vIn1 * 4; +} + +//----------------------------------------------------------------------------- +void FFP_ModulateX4(in float3 vIn0, in float3 vIn1, out float3 vOut) +{ + vOut = vIn0 * vIn1 * 4; +} + +//----------------------------------------------------------------------------- +void FFP_ModulateX4(in float4 vIn0, in float4 vIn1, out float4 vOut) +{ + vOut = vIn0 * vIn1 * 4; +} + +//----------------------------------------------------------------------------- +void FFP_AddSigned(in float vIn0, in float vIn1, out float vOut) +{ + vOut = vIn0 + vIn1 - 0.5; +} + +//----------------------------------------------------------------------------- +void FFP_AddSigned(in float2 vIn0, in float2 vIn1, out float2 vOut) +{ + vOut = vIn0 + vIn1 - 0.5; +} + +//----------------------------------------------------------------------------- +void FFP_AddSigned(in float3 vIn0, in float3 vIn1, out float3 vOut) +{ + vOut = vIn0 + vIn1 - 0.5; +} + +//----------------------------------------------------------------------------- +void FFP_AddSigned(in float4 vIn0, in float4 vIn1, out float4 vOut) +{ + vOut = vIn0 + vIn1 - 0.5; +} + +//----------------------------------------------------------------------------- +void FFP_AddSmooth(in float vIn0, in float vIn1, out float vOut) +{ + vOut = vIn0 + vIn1 - (vIn0 * vIn1); +} + +//----------------------------------------------------------------------------- +void FFP_AddSmooth(in float2 vIn0, in float2 vIn1, out float2 vOut) +{ + vOut = vIn0 + vIn1 - (vIn0 * vIn1); +} + +//----------------------------------------------------------------------------- +void FFP_AddSmooth(in float3 vIn0, in float3 vIn1, out float3 vOut) +{ + vOut = vIn0 + vIn1 - (vIn0 * vIn1); +} + +//----------------------------------------------------------------------------- +void FFP_AddSmooth(in float4 vIn0, in float4 vIn1, out float4 vOut) +{ + vOut = vIn0 + vIn1 - (vIn0 * vIn1); +} diff --git a/res/dist/media/RTShaderLib/FFPLib_Transform.cg b/res/dist/media/RTShaderLib/FFPLib_Transform.cg new file mode 100644 index 00000000000..c42466a7b1a --- /dev/null +++ b/res/dist/media/RTShaderLib/FFPLib_Transform.cg @@ -0,0 +1,78 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Program Name: FFPLib_Transform +// Program Desc: Transform functions of the FFP. +// Program Type: Vertex shader +// Language: CG +// Notes: Implements core functions for FFPTransform class. +// based on transform engine. +// See http://msdn.microsoft.com/en-us/library/bb206269.aspx +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +void FFP_Transform(in float3x3 m, + in float3 v, + out float3 vOut) +{ + vOut = mul(m, v); +} +//----------------------------------------------------------------------------- +void FFP_Transform(in float4x4 m, + in float4 v, + out float4 vOut) +{ + vOut = mul(m, v); +} +//----------------------------------------------------------------------------- +#ifndef OPENGL_ES_2 + +//----------------------------------------------------------------------------- +void FFP_Transform(in float3x4 m, + in float4 v, + out float3 vOut) +{ + vOut = mul(m, v); +} + +//----------------------------------------------------------------------------- +void FFP_Transform(in float3x4 m, + in float3 v, + out float3 vOut) +{ + vOut = mul((float3x3)m, v); +} +//----------------------------------------------------------------------------- +#endif +//----------------------------------------------------------------------------- +void FFP_Transform(in float4x4 m, + in float3 v, + out float3 vOut) +{ + vOut = mul((float3x3)m, v); +} diff --git a/res/dist/media/RTShaderLib/FFPLib_Transform.glsl b/res/dist/media/RTShaderLib/FFPLib_Transform.glsl new file mode 100644 index 00000000000..43976dae41b --- /dev/null +++ b/res/dist/media/RTShaderLib/FFPLib_Transform.glsl @@ -0,0 +1,71 @@ +#version 120 +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Program Name: FFPLib_Transform +// Program Desc: Transform functions of the FFP. +// Program Type: Vertex shader +// Language: GLSL +// Notes: Implements core functions for FFPTransform class. +// based on transform engine. +// See http://msdn.microsoft.com/en-us/library/bb206269.aspx +//----------------------------------------------------------------------------- + + +//----------------------------------------------------------------------------- +void FFP_Transform(in mat4 m, + in vec4 v, + out vec4 vOut) +{ + vOut = m * v; +} + +//----------------------------------------------------------------------------- +void FFP_Transform(in mat4 m, + in vec4 v, + out vec3 vOut) +{ + vOut = (m * v).xyz; +} + +//----------------------------------------------------------------------------- +void FFP_Transform(in mat3x4 m, + in vec3 v, + out vec3 vOut) +{ + vOut = mat3(m) * v; +} + + +//----------------------------------------------------------------------------- +void FFP_Transform(in mat4 m, + in vec3 v, + out vec3 vOut) +{ + vOut = mat3(m) * v; +} \ No newline at end of file diff --git a/res/dist/media/RTShaderLib/FFPLib_Transform.glsles b/res/dist/media/RTShaderLib/FFPLib_Transform.glsles new file mode 100644 index 00000000000..3fd849f12cd --- /dev/null +++ b/res/dist/media/RTShaderLib/FFPLib_Transform.glsles @@ -0,0 +1,65 @@ +#version 100 +precision highp float; +precision highp int; +precision lowp sampler2D; +precision lowp samplerCube; +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Program Name: FFPLib_Transform +// Program Desc: Transform functions of the FFP. +// Program Type: Vertex shader +// Language: GLSL ES +// Notes: Implements core functions for FFPTransform class. +// based on transform engine. +// See http://msdn.microsoft.com/en-us/library/bb206269.aspx +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +void FFP_Transform(in mat4 m, + in vec4 v, + out vec4 vOut) +{ + vOut = m * v; +} + +//----------------------------------------------------------------------------- +void FFP_Transform(in mat4 m, + in vec4 v, + out vec3 vOut) +{ + vOut = (m * v).xyz; +} + +//----------------------------------------------------------------------------- +void FFP_Transform(in mat4 m, + in vec3 v, + out vec3 vOut) +{ + vOut = mat3(m) * v; +} \ No newline at end of file diff --git a/res/dist/media/RTShaderLib/FFPLib_Transform.hlsl b/res/dist/media/RTShaderLib/FFPLib_Transform.hlsl new file mode 100644 index 00000000000..36b9bcccb53 --- /dev/null +++ b/res/dist/media/RTShaderLib/FFPLib_Transform.hlsl @@ -0,0 +1,71 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Program Name: FFPLib_Transform +// Program Desc: Transform functions of the FFP. +// Program Type: Vertex shader +// Language: HLSL +// Notes: Implements core functions for FFPTransform class. +// based on transform engine. +// See http://msdn.microsoft.com/en-us/library/bb206269.aspx +//----------------------------------------------------------------------------- + + +//----------------------------------------------------------------------------- +void FFP_Transform(in float4x4 m, + in float4 v, + out float4 vOut) +{ + vOut = mul(m, v); +} + +//----------------------------------------------------------------------------- +void FFP_Transform(in float3x4 m, + in float4 v, + out float3 vOut) +{ + vOut = mul(m, v); +} + +//----------------------------------------------------------------------------- +void FFP_Transform(in float3x4 m, + in float3 v, + out float3 vOut) +{ + vOut = mul((float3x3)m, v); +} + +//----------------------------------------------------------------------------- +void FFP_Transform(in float4x4 m, + in float3 v, + out float3 vOut) +{ + vOut = mul((float3x3)m, v); +} + + diff --git a/res/dist/media/RTShaderLib/SGXLib_DualQuaternion.cg b/res/dist/media/RTShaderLib/SGXLib_DualQuaternion.cg new file mode 100644 index 00000000000..5778cb5ad48 --- /dev/null +++ b/res/dist/media/RTShaderLib/SGXLib_DualQuaternion.cg @@ -0,0 +1,130 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//These functions are based on dqs.cg from http://isg.cs.tcd.ie/kavanl/dq/ +/* dqs.cg + + Dual quaternion skinning vertex shaders (no shading computations) + + Version 1.0.3, November 1st, 2007 + + Copyright (C) 2006-2007 University of Dublin, Trinity College, All Rights + Reserved + + This software is provided 'as-is', without any express or implied + warranty. In no event will the author(s) be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Author: Ladislav Kavan, kavanl@cs.tcd.ie + +*/ + +//----------------------------------------------------------------------------- +// Program Name: SGXLib_DualQuaternion +// Program Desc: Dual quaternion skinning functions. +// Program Type: Vertex shader +// Language: CG +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +void SGX_BlendWeight(in float blendWgt, in float2x4 dualQuaternion, out float2x4 vOut) +{ + vOut = blendWgt*dualQuaternion; +} + +//----------------------------------------------------------------------------- +void SGX_BlendWeight(in float blendWgt, in float3x4 scaleShearMatrix, out float3x4 vOut) +{ + vOut = blendWgt*scaleShearMatrix; +} + +//----------------------------------------------------------------------------- +void SGX_AntipodalityAdjustment(in float2x4 dq0, in float2x4 dq1, out float2x4 dq2) +{ + //Accurate antipodality handling. For speed increase, remove the following line, + //though, the results will only be valid for rotations less than 180 degrees. + dq2 = (dot(dq0[0], dq1[0]) < 0.0) ? dq1 * -1.0 : dq1; +} + +//----------------------------------------------------------------------------- +void SGX_CalculateBlendPosition(in float3 position, in float2x4 blendDQ, out float4 vOut) +{ + float3 blendPosition = position + 2.0*cross(blendDQ[0].yzw, cross(blendDQ[0].yzw, position) + blendDQ[0].x*position); + float3 trans = 2.0*(blendDQ[0].x*blendDQ[1].yzw - blendDQ[1].x*blendDQ[0].yzw + cross(blendDQ[0].yzw, blendDQ[1].yzw)); + blendPosition += trans; + + vOut = float4(blendPosition, 1.0); +} + +//----------------------------------------------------------------------------- +void SGX_CalculateBlendNormal(in float3 vIn, in float2x4 blendDQ, out float3 vOut) +{ + vOut = (vIn + 2.0*cross(blendDQ[0].yzw, cross(blendDQ[0].yzw, vIn) + blendDQ[0].x*vIn)); +} + +//----------------------------------------------------------------------------- +void SGX_NormalizeDualQuaternion(inout float2x4 dq) +{ + dq /= length(dq[0]); +} + +//----------------------------------------------------------------------------- +void SGX_AdjointTransposeMatrix(in float3x4 M, out float3x3 vOut) +{ + float3x3 atM; + atM._m00 = M._m22 * M._m11 - M._m12 * M._m21; + atM._m01 = M._m12 * M._m20 - M._m10 * M._m22; + atM._m02 = M._m10 * M._m21 - M._m20 * M._m11; + + atM._m10 = M._m02 * M._m21 - M._m22 * M._m01; + atM._m11 = M._m22 * M._m00 - M._m02 * M._m20; + atM._m12 = M._m20 * M._m01 - M._m00 * M._m21; + + atM._m20 = M._m12 * M._m01 - M._m02 * M._m11; + atM._m21 = M._m10 * M._m02 - M._m12 * M._m00; + atM._m22 = M._m00 * M._m11 - M._m10 * M._m01; + + vOut = atM; +} + +//----------------------------------------------------------------------------- +void SGX_BuildDualQuaternionMatrix(in float4 r1, in float4 r2, out float2x4 vOut) +{ + vOut = float2x4(r1, r2); +} \ No newline at end of file diff --git a/res/dist/media/RTShaderLib/SGXLib_DualQuaternion.glsl b/res/dist/media/RTShaderLib/SGXLib_DualQuaternion.glsl new file mode 100644 index 00000000000..ee4c6c8b994 --- /dev/null +++ b/res/dist/media/RTShaderLib/SGXLib_DualQuaternion.glsl @@ -0,0 +1,132 @@ +#version 120 + +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//These functions are based on dqs.cg from http://isg.cs.tcd.ie/kavanl/dq/ +/* dqs.cg + + Dual quaternion skinning vertex shaders (no shading computations) + + Version 1.0.3, November 1st, 2007 + + Copyright (C) 2006-2007 University of Dublin, Trinity College, All Rights + Reserved + + This software is provided 'as-is', without any express or implied + warranty. In no event will the author(s) be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Author: Ladislav Kavan, kavanl@cs.tcd.ie + +*/ + +//----------------------------------------------------------------------------- +// Program Name: SGXLib_DualQuaternion +// Program Desc: Dual quaternion skinning functions. +// Program Type: Vertex shader +// Language: GLSL +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +void SGX_BlendWeight(in float blendWgt, in mat2x4 dualQuaternion, out mat2x4 vOut) +{ + vOut = blendWgt*dualQuaternion; +} + +//----------------------------------------------------------------------------- +void SGX_BlendWeight(in float blendWgt, in mat3x4 scaleShearMatrix, out mat3x4 vOut) +{ + vOut = blendWgt*scaleShearMatrix; +} + +//----------------------------------------------------------------------------- +void SGX_AntipodalityAdjustment(in mat2x4 dq0, in mat2x4 dq1,out mat2x4 dq2) +{ + //Accurate antipodality handling. For speed increase, remove the following line, + //though, the results will only be valid for rotations less than 180 degrees. + dq2 = (dot(dq0[0], dq1[0]) < 0.0) ? dq1 * -1.0 : dq1; +} + +//----------------------------------------------------------------------------- +void SGX_CalculateBlendPosition(in vec3 position, in mat2x4 blendDQ, out vec4 vOut) +{ + vec3 blendPosition = position + 2.0*cross(blendDQ[0].yzw, cross(blendDQ[0].yzw, position) + blendDQ[0].x*position); + vec3 trans = 2.0*(blendDQ[0].x*blendDQ[1].yzw - blendDQ[1].x*blendDQ[0].yzw + cross(blendDQ[0].yzw, blendDQ[1].yzw)); + blendPosition += trans; + + vOut = vec4(blendPosition, 1.0); +} + +//----------------------------------------------------------------------------- +void SGX_CalculateBlendNormal(in vec3 normal, in mat2x4 blendDQ, out vec3 vOut) +{ + vOut = normal + 2.0*cross(blendDQ[0].yzw, cross(blendDQ[0].yzw, normal) + blendDQ[0].x*normal); +} + +//----------------------------------------------------------------------------- +void SGX_NormalizeDualQuaternion(inout mat2x4 dq) +{ + dq /= length(dq[0]); +} + +//----------------------------------------------------------------------------- +void SGX_AdjointTransposeMatrix(in mat3x3 M, out mat3x3 vOut) +{ + mat3x3 atM; + atM._m00 = M._m22 * M._m11 - M._m12 * M._m21; + atM._m01 = M._m12 * M._m20 - M._m10 * M._m22; + atM._m02 = M._m10 * M._m21 - M._m20 * M._m11; + + atM._m10 = M._m02 * M._m21 - M._m22 * M._m01; + atM._m11 = M._m22 * M._m00 - M._m02 * M._m20; + atM._m12 = M._m20 * M._m01 - M._m00 * M._m21; + + atM._m20 = M._m12 * M._m01 - M._m02 * M._m11; + atM._m21 = M._m10 * M._m02 - M._m12 * M._m00; + atM._m22 = M._m00 * M._m11 - M._m10 * M._m01; + + vOut = atM; +} + +//----------------------------------------------------------------------------- +void SGX_BuildDualQuaternionMatrix(in vec4 r1, in vec4 r2, out mat2x4 vOut) +{ + vOut = mat2x4(r1, r2); +} diff --git a/res/dist/media/RTShaderLib/SGXLib_IntegratedPSSM.cg b/res/dist/media/RTShaderLib/SGXLib_IntegratedPSSM.cg new file mode 100644 index 00000000000..503359ef6a9 --- /dev/null +++ b/res/dist/media/RTShaderLib/SGXLib_IntegratedPSSM.cg @@ -0,0 +1,81 @@ +//----------------------------------------------------------------------------- +// Program Name: SGXLib_IntegratedPSSM +// Program Desc: Integrated PSSM functions. +// Program Type: Vertex/Pixel shader +// Language: CG +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +void SGX_CopyDepth(in float4 clipSpacePos, + out float oDepth) +{ + oDepth = clipSpacePos.z; +} + +//----------------------------------------------------------------------------- +void SGX_ModulateScalar(in float vIn0, in float4 vIn1, out float4 vOut) +{ + vOut = vIn0 * vIn1; +} + +//----------------------------------------------------------------------------- +void SGX_ApplyShadowFactor_Diffuse(in float4 ambient, + in float4 lightSum, + in float fShadowFactor, + out float4 oLight) +{ + oLight.rgb = ambient.rgb + (lightSum.rgb - ambient.rgb) * fShadowFactor; + oLight.a = lightSum.a; +} + +//----------------------------------------------------------------------------- +float _SGX_ShadowPCF4(sampler2D shadowMap, float4 shadowMapPos, float2 offset) +{ + shadowMapPos = shadowMapPos / shadowMapPos.w; + float2 uv = shadowMapPos.xy; + float3 o = float3(offset, -offset.x) * 0.3f; + + // Note: We using 2x2 PCF. Good enough and is a lot faster. + float c = (shadowMapPos.z <= tex2D(shadowMap, uv.xy - o.xy).r) ? 1 : 0; // top left + c += (shadowMapPos.z <= tex2D(shadowMap, uv.xy + o.xy).r) ? 1 : 0; // bottom right + c += (shadowMapPos.z <= tex2D(shadowMap, uv.xy + o.zy).r) ? 1 : 0; // bottom left + c += (shadowMapPos.z <= tex2D(shadowMap, uv.xy - o.zy).r) ? 1 : 0; // top right + + return c / 4; +} + +//----------------------------------------------------------------------------- +void SGX_ComputeShadowFactor_PSSM3(in float fDepth, + in float4 vSplitPoints, + in float4 lightPosition0, + in float4 lightPosition1, + in float4 lightPosition2, + in sampler2D shadowMap0, + in sampler2D shadowMap1, + in sampler2D shadowMap2, + in float4 invShadowMapSize0, + in float4 invShadowMapSize1, + in float4 invShadowMapSize2, + out float oShadowFactor) +{ + float shadowFactor0; + float shadowFactor1; + float shadowFactor2; + + shadowFactor0 = _SGX_ShadowPCF4(shadowMap0, lightPosition0, invShadowMapSize0.xy); + shadowFactor1 = _SGX_ShadowPCF4(shadowMap1, lightPosition1, invShadowMapSize1.xy); + shadowFactor2 = _SGX_ShadowPCF4(shadowMap2, lightPosition2, invShadowMapSize2.xy); + + if (fDepth <= vSplitPoints.x) + { + oShadowFactor = shadowFactor0; + } + else if (fDepth <= vSplitPoints.y) + { + oShadowFactor = shadowFactor1; + } + else + { + oShadowFactor = shadowFactor2; + } +} diff --git a/res/dist/media/RTShaderLib/SGXLib_IntegratedPSSM.glsl b/res/dist/media/RTShaderLib/SGXLib_IntegratedPSSM.glsl new file mode 100644 index 00000000000..d61c4a94873 --- /dev/null +++ b/res/dist/media/RTShaderLib/SGXLib_IntegratedPSSM.glsl @@ -0,0 +1,107 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ +//----------------------------------------------------------------------------- +// Program Name: SGXLib_IntegratedPSSM +// Program Desc: Integrated PSSM functions. +// Program Type: Vertex/Pixel shader +// Language: GLSL +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +void SGX_CopyDepth(in vec4 clipSpacePos, + out float oDepth) +{ + oDepth = clipSpacePos.z; +} + +//----------------------------------------------------------------------------- +void SGX_ModulateScalar(in float vIn0, in vec4 vIn1, out vec4 vOut) +{ + vOut = vIn0 * vIn1; +} + +//----------------------------------------------------------------------------- +void SGX_ApplyShadowFactor_Diffuse(in vec4 ambient, + in vec4 lightSum, + in float fShadowFactor, + out vec4 oLight) +{ + oLight.rgb = ambient.rgb + (lightSum.rgb - ambient.rgb) * fShadowFactor; + oLight.a = lightSum.a; +} + +//----------------------------------------------------------------------------- +float _SGX_ShadowPCF4(sampler2D shadowMap, vec4 shadowMapPos, vec2 offset) +{ + shadowMapPos = shadowMapPos / shadowMapPos.w; + vec2 uv = shadowMapPos.xy; + vec3 o = vec3(offset, -offset.x) * 0.3; + + // Note: We using 2x2 PCF. Good enough and is a lot faster. + float c = (shadowMapPos.z <= texture2D(shadowMap, uv.xy - o.xy).r) ? 1.0 : 0.0; // top left + c += (shadowMapPos.z <= texture2D(shadowMap, uv.xy + o.xy).r) ? 1.0 : 0.0; // bottom right + c += (shadowMapPos.z <= texture2D(shadowMap, uv.xy + o.zy).r) ? 1.0 : 0.0; // bottom left + c += (shadowMapPos.z <= texture2D(shadowMap, uv.xy - o.zy).r) ? 1.0 : 0.0; // top right + + return c / 4.0; +} + +//----------------------------------------------------------------------------- +void SGX_ComputeShadowFactor_PSSM3(in float fDepth, + in vec4 vSplitPoints, + in vec4 lightPosition0, + in vec4 lightPosition1, + in vec4 lightPosition2, + in sampler2D shadowMap0, + in sampler2D shadowMap1, + in sampler2D shadowMap2, + in vec4 invShadowMapSize0, + in vec4 invShadowMapSize1, + in vec4 invShadowMapSize2, + out float oShadowFactor) +{ + float shadowFactor0; + float shadowFactor1; + float shadowFactor2; + + shadowFactor0 = _SGX_ShadowPCF4(shadowMap0, lightPosition0, invShadowMapSize0.xy); + shadowFactor1 = _SGX_ShadowPCF4(shadowMap1, lightPosition1, invShadowMapSize1.xy); + shadowFactor2 = _SGX_ShadowPCF4(shadowMap2, lightPosition2, invShadowMapSize2.xy); + + if (fDepth <= vSplitPoints.x) + { + oShadowFactor = shadowFactor0; + } + else if (fDepth <= vSplitPoints.y) + { + oShadowFactor = shadowFactor1; + } + else + { + oShadowFactor = shadowFactor2; + } +} diff --git a/res/dist/media/RTShaderLib/SGXLib_IntegratedPSSM.glsles b/res/dist/media/RTShaderLib/SGXLib_IntegratedPSSM.glsles new file mode 100644 index 00000000000..a1b038d2b5a --- /dev/null +++ b/res/dist/media/RTShaderLib/SGXLib_IntegratedPSSM.glsles @@ -0,0 +1,112 @@ +#version 100 +precision highp float; +precision highp int; +precision lowp sampler2D; +precision lowp samplerCube; +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ +//----------------------------------------------------------------------------- +// Program Name: SGXLib_IntegratedPSSM +// Program Desc: Integrated PSSM functions. +// Program Type: Vertex/Pixel shader +// Language: GLSL ES +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +void SGX_CopyDepth(in vec4 clipSpacePos, + out float oDepth) +{ + oDepth = clipSpacePos.z; +} + +//----------------------------------------------------------------------------- +void SGX_ModulateScalar(in float vIn0, in vec4 vIn1, out vec4 vOut) +{ + vOut = vIn0 * vIn1; +} + +//----------------------------------------------------------------------------- +void SGX_ApplyShadowFactor_Diffuse(in vec4 ambient, + in vec4 lightSum, + in float fShadowFactor, + out vec4 oLight) +{ + oLight.rgb = ambient.rgb + (lightSum.rgb - ambient.rgb) * fShadowFactor; + oLight.a = lightSum.a; +} + +//----------------------------------------------------------------------------- +float _SGX_ShadowPCF4(in sampler2D shadowMap, in vec4 shadowMapPos, in vec2 offset) +{ + shadowMapPos = shadowMapPos / shadowMapPos.w; + vec2 uv = shadowMapPos.xy; + vec3 o = vec3(offset, -offset.x) * 0.3; + + // Note: We using 2x2 PCF. Good enough and is a lot faster. + float c = (shadowMapPos.z <= texture2D(shadowMap, uv.xy - o.xy).r) ? 1.0 : 0.0; // top left + c += (shadowMapPos.z <= texture2D(shadowMap, uv.xy + o.xy).r) ? 1.0 : 0.0; // bottom right + c += (shadowMapPos.z <= texture2D(shadowMap, uv.xy + o.zy).r) ? 1.0 : 0.0; // bottom left + c += (shadowMapPos.z <= texture2D(shadowMap, uv.xy - o.zy).r) ? 1.0 : 0.0; // top right + + return c / 4.0; +} + +//----------------------------------------------------------------------------- +void SGX_ComputeShadowFactor_PSSM3(in float fDepth, + in vec4 vSplitPoints, + in vec4 lightPosition0, + in vec4 lightPosition1, + in vec4 lightPosition2, + in sampler2D shadowMap0, + in sampler2D shadowMap1, + in sampler2D shadowMap2, + in vec4 invShadowMapSize0, + in vec4 invShadowMapSize1, + in vec4 invShadowMapSize2, + out float oShadowFactor) +{ + float shadowFactor0; + float shadowFactor1; + float shadowFactor2; + + shadowFactor0 = _SGX_ShadowPCF4(shadowMap0, lightPosition0, invShadowMapSize0.xy); + shadowFactor1 = _SGX_ShadowPCF4(shadowMap1, lightPosition1, invShadowMapSize1.xy); + shadowFactor2 = _SGX_ShadowPCF4(shadowMap2, lightPosition2, invShadowMapSize2.xy); + + if (fDepth <= vSplitPoints.x) + { + oShadowFactor = shadowFactor0; + } + else if (fDepth <= vSplitPoints.y) + { + oShadowFactor = shadowFactor1; + } + else + { + oShadowFactor = shadowFactor2; + } +} diff --git a/res/dist/media/RTShaderLib/SGXLib_IntegratedPSSM.hlsl b/res/dist/media/RTShaderLib/SGXLib_IntegratedPSSM.hlsl new file mode 100644 index 00000000000..d72d33ace2a --- /dev/null +++ b/res/dist/media/RTShaderLib/SGXLib_IntegratedPSSM.hlsl @@ -0,0 +1,81 @@ +//----------------------------------------------------------------------------- +// Program Name: SGXLib_IntegratedPSSM +// Program Desc: Integrated PSSM functions. +// Program Type: Vertex/Pixel shader +// Language: HLSL +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +void SGX_CopyDepth(in float4 clipSpacePos, + out float oDepth) +{ + oDepth = clipSpacePos.z; +} + +//----------------------------------------------------------------------------- +void SGX_ModulateScalar(in float vIn0, in float4 vIn1, out float4 vOut) +{ + vOut = vIn0 * vIn1; +} + +//----------------------------------------------------------------------------- +void SGX_ApplyShadowFactor_Diffuse(in float4 ambient, + in float4 lightSum, + in float fShadowFactor, + out float4 oLight) +{ + oLight.rgb = ambient.rgb + (lightSum.rgb - ambient.rgb) * fShadowFactor; + oLight.a = lightSum.a; +} + +//----------------------------------------------------------------------------- +float _SGX_ShadowPCF4(sampler2D shadowMap, float4 shadowMapPos, float2 offset) +{ + shadowMapPos = shadowMapPos / shadowMapPos.w; + float2 uv = shadowMapPos.xy; + float3 o = float3(offset, -offset.x) * 0.3f; + + // Note: We using 2x2 PCF. Good enough and is a lot faster. + float c = (shadowMapPos.z <= tex2D(shadowMap, uv.xy - o.xy).r) ? 1 : 0; // top left + c += (shadowMapPos.z <= tex2D(shadowMap, uv.xy + o.xy).r) ? 1 : 0; // bottom right + c += (shadowMapPos.z <= tex2D(shadowMap, uv.xy + o.zy).r) ? 1 : 0; // bottom left + c += (shadowMapPos.z <= tex2D(shadowMap, uv.xy - o.zy).r) ? 1 : 0; // top right + + return c / 4; +} + +//----------------------------------------------------------------------------- +void SGX_ComputeShadowFactor_PSSM3(in float fDepth, + in float4 vSplitPoints, + in float4 lightPosition0, + in float4 lightPosition1, + in float4 lightPosition2, + in sampler2D shadowMap0, + in sampler2D shadowMap1, + in sampler2D shadowMap2, + in float4 invShadowMapSize0, + in float4 invShadowMapSize1, + in float4 invShadowMapSize2, + out float oShadowFactor) +{ + float shadowFactor0; + float shadowFactor1; + float shadowFactor2; + + shadowFactor0 = _SGX_ShadowPCF4(shadowMap0, lightPosition0, invShadowMapSize0.xy); + shadowFactor1 = _SGX_ShadowPCF4(shadowMap1, lightPosition1, invShadowMapSize1.xy); + shadowFactor2 = _SGX_ShadowPCF4(shadowMap2, lightPosition2, invShadowMapSize2.xy); + + if (fDepth <= vSplitPoints.x) + { + oShadowFactor = shadowFactor0; + } + else if (fDepth <= vSplitPoints.y) + { + oShadowFactor = shadowFactor1; + } + else + { + oShadowFactor = shadowFactor2; + } +} diff --git a/res/dist/media/RTShaderLib/SGXLib_LayeredBlending.cg b/res/dist/media/RTShaderLib/SGXLib_LayeredBlending.cg new file mode 100644 index 00000000000..0e33d002a6b --- /dev/null +++ b/res/dist/media/RTShaderLib/SGXLib_LayeredBlending.cg @@ -0,0 +1,728 @@ +/* +** layered blending & misc math +** Blending modes, RGB/HSL/Contrast/Desaturate +** +** The shaders below are base on the shaders created by: +** Romain Dura | Romz +** Blog: http://blog.mouaif.org +** Post: http://blog.mouaif.org/?p=94 +*/ + + +/* +** Desaturation +*/ + +float4 Desaturate(float3 color, float Desaturation) +{ + float3 grayXfer = float3(0.3, 0.59, 0.11); + float grayf = dot(grayXfer, color); + float3 gray = float3(grayf, grayf, grayf); + return float4(lerp(color, gray, Desaturation), 1.0); +} + + +/* +** Hue, saturation, luminance +*/ + +float3 RGBToHSL(float3 color) +{ + float3 hsl; // init to 0 to avoid warnings ? (and reverse if + remove first part) + + float fmin = min(min(color.r, color.g), color.b); //Min. value of RGB + float fmax = max(max(color.r, color.g), color.b); //Max. value of RGB + float delta = fmax - fmin; //Delta RGB value + + hsl.z = (fmax + fmin) / 2.0; // Luminance + + if (delta == 0.0) //This is a gray, no chroma... + { + hsl.x = 0.0; // Hue + hsl.y = 0.0; // Saturation + } + else //Chromatic data... + { + if (hsl.z < 0.5) + hsl.y = delta / (fmax + fmin); // Saturation + else + hsl.y = delta / (2.0 - fmax - fmin); // Saturation + + float deltaR = (((fmax - color.r) / 6.0) + (delta / 2.0)) / delta; + float deltaG = (((fmax - color.g) / 6.0) + (delta / 2.0)) / delta; + float deltaB = (((fmax - color.b) / 6.0) + (delta / 2.0)) / delta; + + if (color.r == fmax ) + hsl.x = deltaB - deltaG; // Hue + else if (color.g == fmax) + hsl.x = (1.0 / 3.0) + deltaR - deltaB; // Hue + else if (color.b == fmax) + hsl.x = (2.0 / 3.0) + deltaG - deltaR; // Hue + + if (hsl.x < 0.0) + hsl.x += 1.0; // Hue + else if (hsl.x > 1.0) + hsl.x -= 1.0; // Hue + } + + return hsl; +} + +float HueToRGB(float f1, float f2, float hue) +{ + if (hue < 0.0) + hue += 1.0; + else if (hue > 1.0) + hue -= 1.0; + float res; + if ((6.0 * hue) < 1.0) + res = f1 + (f2 - f1) * 6.0 * hue; + else if ((2.0 * hue) < 1.0) + res = f2; + else if ((3.0 * hue) < 2.0) + res = f1 + (f2 - f1) * ((2.0 / 3.0) - hue) * 6.0; + else + res = f1; + return res; +} + +float3 HSLToRGB(float3 hsl) +{ + float3 rgb; + + if (hsl.y == 0.0) + rgb = float3(hsl.z, hsl.z, hsl.z); // Luminance + else + { + float f2; + + if (hsl.z < 0.5) + f2 = hsl.z * (1.0 + hsl.y); + else + f2 = (hsl.z + hsl.y) - (hsl.y * hsl.z); + + float f1 = 2.0 * hsl.z - f2; + + rgb.r = HueToRGB(f1, f2, hsl.x + (1.0/3.0)); + rgb.g = HueToRGB(f1, f2, hsl.x); + rgb.b= HueToRGB(f1, f2, hsl.x - (1.0/3.0)); + } + + return rgb; +} + +/* +** Contrast, saturation, brightness +** Code of this function is from TGM's shader pack +** http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=21057 +*/ + +// For all settings: 1.0 = 100% 0.5=50% 1.5 = 150% +float3 ContrastSaturationBrightness(float3 color, float brt, float sat, float con) +{ + // Increase or decrease these values to adjust r, g and b color channels separately + const float AvgLumR = 0.5; + const float AvgLumG = 0.5; + const float AvgLumB = 0.5; + + const float3 LumCoeff = float3(0.2125, 0.7154, 0.0721); + + float3 AvgLumin = float3(AvgLumR, AvgLumG, AvgLumB); + float3 brtColor = color * brt; + float intensityf = dot(brtColor, LumCoeff); + float3 intensity = float3(intensityf, intensityf, intensityf); + float3 satColor = lerp(intensity, brtColor, sat); + float3 conColor = lerp(AvgLumin, satColor, con); + return conColor; +} + +/* +** Float blending modes +** Adapted from here: http://www.nathanm.com/photoshop-blending-math/ +** But I modified the HardMix (wrong condition), Overlay, SoftLight, ColorDodge, ColorBurn, VividLight, PinLight (inverted layers) ones to have correct results +*/ + +#define BlendLinearDodgef BlendAddf +#define BlendLinearBurnf BlendSubtractf +#define BlendAddf(base, blend) min(base + blend, 1.0) +#define BlendSubtractf(base, blend) max(base + blend - 1.0, 0.0) +#define BlendLightenf(base, blend) max(blend, base) +#define BlendDarkenf(base, blend) min(blend, base) +#define BlendLinearLightf(base, blend) (blend < 0.5 ? BlendLinearBurnf(base, (2.0 * blend)) : BlendLinearDodgef(base, (2.0 * (blend - 0.5)))) +#define BlendScreenf(base, blend) (1.0 - ((1.0 - base) * (1.0 - blend))) +#define BlendOverlayf(base, blend) (base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend))) +#define BlendSoftLightf(base, blend) ((blend < 0.5) ? (2.0 * base * blend + base * base * (1.0 - 2.0 * blend)) : (sqrt(base) * (2.0 * blend - 1.0) + 2.0 * base * (1.0 - blend))) +#define BlendColorDodgef(base, blend) ((blend == 1.0) ? blend : min(base / (1.0 - blend), 1.0)) +#define BlendColorBurnf(base, blend) ((blend == 0.0) ? blend : max((1.0 - ((1.0 - base) / blend)), 0.0)) +#define BlendVividLightf(base, blend) ((blend < 0.5) ? BlendColorBurnf(base, (2.0 * blend)) : BlendColorDodgef(base, (2.0 * (blend - 0.5)))) +#define BlendPinLightf(base, blend) ((blend < 0.5) ? BlendDarkenf(base, (2.0 * blend)) : BlendLightenf(base, (2.0 *(blend - 0.5)))) +#define BlendHardMixf(base, blend) ((BlendVividLightf(base, blend) < 0.5) ? 0.0 : 1.0) +#define BlendReflectf(base, blend) ((blend == 1.0) ? blend : min(base * base / (1.0 - blend), 1.0)) + + + +/* +** Vector3 blending modes +*/ + +// Component wise blending +#define Blend1(base, blend, funcf) funcf(base, blend) +#define Blend3(base, blend, funcf) float3(funcf(base.r, blend.r), funcf(base.g, blend.g), funcf(base.b, blend.b)) +#define Blend4(base, blend, funcf) float4(funcf(base.r, blend.r), funcf(base.g, blend.g), funcf(base.b, blend.b), funcf(base.a, blend.a)) + +#define BlendNormal(base, blend) (base) +#define BlendLighten BlendLightenf +#define BlendDarken BlendDarkenf +#define BlendMultiply(base, blend) (base * blend) +#define BlendAverage(base, blend) ((base + blend) / 2.0) +#define BlendAdd(base, blend) min(base + blend, 1.0) +#define BlendSubtract(base, blend) max(base + blend - 1.0, 0.0) +#define BlendDifference(base, blend) abs(base - blend) +#define BlendNegation(base, blend) (1.0 - abs(1.0 - base - blend)) +#define BlendExclusion(base, blend) (base + blend - 2.0 * base * blend) + +#define BlendScreen1(base, blend) Blend1(base, blend, BlendScreenf) +#define BlendOverlay1(base, blend) Blend1(base, blend, BlendOverlayf) +#define BlendSoftLight1(base, blend) Blend1(base, blend, BlendSoftLightf) +#define BlendHardLight1(base, blend) BlendOverlay1(blend, base) +#define BlendColorDodge1(base, blend) Blend1(base, blend, BlendColorDodgef) +#define BlendColorBurn1(base, blend) Blend1(base, blend, BlendColorBurnf) +// Linear Light is another contrast-increasing mode +// If the blend color is darker than midgray, Linear Light darkens the image by decreasing the brightness. If the blend color is lighter than midgray, the result is a brighter image due to increased brightness. +#define BlendLinearLight1(base, blend) Blend1(base, blend, BlendLinearLightf) +#define BlendVividLight1(base, blend) Blend1(base, blend, BlendVividLightf) +#define BlendPinLight1(base, blend) Blend1(base, blend, BlendPinLightf) +#define BlendHardMix1(base, blend) Blend1(base, blend, BlendHardMixf) +#define BlendReflect1(base, blend) Blend1(base, blend, BlendReflectf) +#define BlendGlow1(base, blend) BlendReflect1(blend, base) + + +#define BlendScreen3(base, blend) Blend3(base, blend, BlendScreenf) +#define BlendOverlay3(base, blend) Blend3(base, blend, BlendOverlayf) +#define BlendSoftLight3(base, blend) Blend3(base, blend, BlendSoftLightf) +#define BlendHardLight3(base, blend) BlendOverlay3(blend, base) +#define BlendColorDodge3(base, blend) Blend3(base, blend, BlendColorDodgef) +#define BlendColorBurn3(base, blend) Blend3(base, blend, BlendColorBurnf) +// Linear Light is another contrast-increasing mode +// If the blend color is darker than midgray, Linear Light darkens the image by decreasing the brightness. If the blend color is lighter than midgray, the result is a brighter image due to increased brightness. +#define BlendLinearLight3(base, blend) Blend3(base, blend, BlendLinearLightf) +#define BlendVividLight3(base, blend) Blend3(base, blend, BlendVividLightf) +#define BlendPinLight3(base, blend) Blend3(base, blend, BlendPinLightf) +#define BlendHardMix3(base, blend) Blend3(base, blend, BlendHardMixf) +#define BlendReflect3(base, blend) Blend3(base, blend, BlendReflectf) +#define BlendGlow3(base, blend) BlendReflect3(blend, base) + + +#define BlendScreen4(base, blend) Blend4(base, blend, BlendScreenf) +#define BlendOverlay4(base, blend) Blend4(base, blend, BlendOverlayf) +#define BlendSoftLight4(base, blend) Blend4(base, blend, BlendSoftLightf) +#define BlendHardLight4(base, blend) BlendOverlay4(blend, base) +#define BlendColorDodge4(base, blend) Blend4(base, blend, BlendColorDodgef) +#define BlendColorBurn4(base, blend) Blend4(base, blend, BlendColorBurnf) +// Linear Light is another contrast-increasing mode +// If the blend color is darker than midgray, Linear Light darkens the image by decreasing the brightness. If the blend color is lighter than midgray, the result is a brighter image due to increased brightness. +#define BlendLinearLight4(base, blend) Blend4(base, blend, BlendLinearLightf) +#define BlendVividLight4(base, blend) Blend4(base, blend, BlendVividLightf) +#define BlendPinLight4(base, blend) Blend4(base, blend, BlendPinLightf) +#define BlendHardMix4(base, blend) Blend4(base, blend, BlendHardMixf) +#define BlendReflect4(base, blend) Blend4(base, blend, BlendReflectf) +#define BlendGlow4(base, blend) BlendReflect4(blend, base) + + +#define BlendLinearDodge BlendAdd +#define BlendLinearBurn BlendSubtract + +#define BlendPhoenix(base, blend) (min(base, blend) - max(base, blend) + 1.0) + + +#define BlendOpacity(base, blend, F, O) (F(base, blend) * O + blend * (1.0 - O)) + +// Hue Blend mode creates the result color by combining the luminance and saturation of the base color with the hue of the blend color. +float BlendHue1(float base, float blend) +{ + return base; +} +float3 BlendHue3(float3 base, float3 blend) +{ + float3 baseHSL = RGBToHSL(base); + return HSLToRGB(float3(RGBToHSL(blend).r, baseHSL.g, baseHSL.b)); +} +float4 BlendHue4(float4 base, float4 blend) +{ + float3 hue = BlendHue3(base.xyz, blend.xyz); + return float4(hue.x, hue.y, hue.z, BlendHue1(base.w, blend.w)); +} + +// Saturation Blend mode creates the result color by combining the luminance and hue of the base color with the saturation of the blend color. +float BlendSaturation1(float base, float blend) +{ + return base; +} +float3 BlendSaturation3(float3 base, float3 blend) +{ + float3 baseHSL = RGBToHSL(base); + return HSLToRGB(float3(baseHSL.r, RGBToHSL(blend).g, baseHSL.b)); +} +float4 BlendSaturation4(float4 base, float4 blend) +{ + float3 hue = BlendSaturation3(base.xyz, blend.xyz); + return float4(hue.x, hue.y, hue.z, BlendSaturation1(base.w, blend.w)); +} + +// Color Mode keeps the brightness of the base color and applies both the hue and saturation of the blend color. +float BlendColor1(float base, float blend) +{ + return base; +} +float3 BlendColor3(float3 base, float3 blend) +{ + float3 blendHSL = RGBToHSL(blend); + return HSLToRGB(float3(blendHSL.r, blendHSL.g, RGBToHSL(base).b)); +} +float4 BlendColor4(float4 base, float4 blend) +{ + float3 hue = BlendColor3(base.xyz, blend.xyz); + return float4(hue.x, hue.y, hue.z, BlendColor1(base.w, blend.w)); +} + + + +// Luminosity Blend mode creates the result color by combining the hue and saturation of the base color with the luminance of the blend color. +float BlendLuminosity1(float base, float blend) +{ + return base; +} +float3 BlendLuminosity3(float3 base, float3 blend) +{ + float3 baseHSL = RGBToHSL(base); + return HSLToRGB(float3(baseHSL.r, baseHSL.g, RGBToHSL(blend).b)); +} +float4 BlendLuminosity4(float4 base, float4 blend) +{ + float3 hue = BlendLuminosity3(base.xyz, blend.xyz); + return float4(hue.x, hue.y, hue.z, BlendLuminosity1(base.w, blend.w)); +} + +//------------------------------------ +// Interface for RTShader +//------------------------------------ + +void SGX_blend_normal(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendNormal(basePixel, blendPixel); +} +void SGX_blend_normal(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendNormal(basePixel, blendPixel); +} +void SGX_blend_normal(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendNormal(basePixel, blendPixel); +} + + +void SGX_blend_lighten(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendLighten(basePixel, blendPixel); +} +void SGX_blend_lighten(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendLighten(basePixel, blendPixel); +} +void SGX_blend_lighten(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendLighten(basePixel, blendPixel); +} + +void SGX_blend_darken(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendDarken(basePixel, blendPixel); +} +void SGX_blend_darken(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendDarken(basePixel, blendPixel); +} +void SGX_blend_darken(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendDarken(basePixel, blendPixel); +} + + +void SGX_blend_multiply(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendMultiply(basePixel, blendPixel); +} +void SGX_blend_multiply(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendMultiply(basePixel, blendPixel); +} +void SGX_blend_multiply(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendMultiply(basePixel, blendPixel); +} + + +void SGX_blend_average(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendAverage(basePixel, blendPixel); +} +void SGX_blend_average(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendAverage(basePixel, blendPixel); +} +void SGX_blend_average(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendAverage(basePixel, blendPixel); +} + + +void SGX_blend_add(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendAdd(basePixel, blendPixel); +} +void SGX_blend_add(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendAdd(basePixel, blendPixel); +} +void SGX_blend_add(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendAdd(basePixel, blendPixel); +} + + +void SGX_blend_subtract(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendSubtract(basePixel, blendPixel); +} +void SGX_blend_subtract(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendSubtract(basePixel, blendPixel); +} +void SGX_blend_subtract(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendSubtract(basePixel, blendPixel); +} + + +void SGX_blend_difference(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendDifference(basePixel, blendPixel); +} +void SGX_blend_difference(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendDifference(basePixel, blendPixel); +} +void SGX_blend_difference(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendDifference(basePixel, blendPixel); +} + + +void SGX_blend_negation(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendNegation(basePixel, blendPixel); +} +void SGX_blend_negation(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendNegation(basePixel, blendPixel); +} +void SGX_blend_negation(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendNegation(basePixel, blendPixel); +} + + +void SGX_blend_exclusion(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendExclusion(basePixel, blendPixel); +} +void SGX_blend_exclusion(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendExclusion(basePixel, blendPixel); +} +void SGX_blend_exclusion(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendExclusion(basePixel, blendPixel); +} + + +void SGX_blend_screen(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = Blend4(basePixel, blendPixel, BlendScreenf); +} +void SGX_blend_screen(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = Blend3(basePixel, blendPixel, BlendScreenf); +} +void SGX_blend_screen(float basePixel, float blendPixel, out float oColor) +{ + oColor = Blend1(basePixel, blendPixel, BlendScreenf); +} + +void SGX_blend_overlay(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = Blend4(basePixel, blendPixel, BlendOverlayf); +} +void SGX_blend_overlay(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = Blend3(basePixel, blendPixel, BlendOverlayf); +} +void SGX_blend_overlay(float basePixel, float blendPixel, out float oColor) +{ + oColor = Blend1(basePixel, blendPixel, BlendOverlayf); +} + +void SGX_blend_softLight(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = Blend4(basePixel, blendPixel, BlendSoftLightf); +} +void SGX_blend_softLight(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = Blend3(basePixel, blendPixel, BlendSoftLightf); +} +void SGX_blend_softLight(float basePixel, float blendPixel, out float oColor) +{ + oColor = Blend1(basePixel, blendPixel, BlendSoftLightf); +} + + +void SGX_blend_hardLight(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = Blend4(basePixel, blendPixel, BlendOverlayf); +} +void SGX_blend_hardLight(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = Blend3(basePixel, blendPixel, BlendOverlayf); +} +void SGX_blend_hardLight(float basePixel, float blendPixel, out float oColor) +{ + oColor = Blend1(basePixel, blendPixel, BlendOverlayf); +} + + +void SGX_blend_colorDodge(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = Blend4(basePixel, blendPixel, BlendColorDodgef); +} +void SGX_blend_colorDodge(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = Blend3(basePixel, blendPixel, BlendColorDodgef); +} +void SGX_blend_colorDodge(float basePixel, float blendPixel, out float oColor) +{ + oColor = Blend1(basePixel, blendPixel, BlendColorDodgef); +} + + +void SGX_blend_colorBurn(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = Blend4(basePixel, blendPixel, BlendColorBurnf); +} +void SGX_blend_colorBurn(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = Blend3(basePixel, blendPixel, BlendColorBurnf); +} +void SGX_blend_colorBurn(float basePixel, float blendPixel, out float oColor) +{ + oColor = Blend1(basePixel, blendPixel, BlendColorBurnf); +} + + +void SGX_blend_linearDodge(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendLinearDodge(basePixel, blendPixel); +} +void SGX_blend_linearDodge(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendLinearDodge(basePixel, blendPixel); +} +void SGX_blend_linearDodge(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendLinearDodge(basePixel, blendPixel); +} + + +void SGX_blend_linearBurn(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendLinearBurn(basePixel, blendPixel); +} +void SGX_blend_linearBurn(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendLinearBurn(basePixel, blendPixel); +} +void SGX_blend_linearBurn(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendLinearBurn(basePixel, blendPixel); +} + + +void SGX_blend_linearLight(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = Blend4(basePixel, blendPixel, BlendLinearLightf); +} +void SGX_blend_linearLight(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = Blend3(basePixel, blendPixel, BlendLinearLightf); +} +void SGX_blend_linearLight(float basePixel, float blendPixel, out float oColor) +{ + oColor = Blend1(basePixel, blendPixel, BlendLinearLightf); +} + + +void SGX_blend_vividLight(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = Blend4(basePixel, blendPixel, BlendVividLightf); +} +void SGX_blend_vividLight(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = Blend3(basePixel, blendPixel, BlendVividLightf); +} +void SGX_blend_vividLight(float basePixel, float blendPixel, out float oColor) +{ + oColor = Blend1(basePixel, blendPixel, BlendVividLightf); +} + + +void SGX_blend_pinLight(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = Blend4(basePixel, blendPixel, BlendPinLightf); +} +void SGX_blend_pinLight(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = Blend3(basePixel, blendPixel, BlendPinLightf); +} +void SGX_blend_pinLight(float basePixel, float blendPixel, out float oColor) +{ + oColor = Blend1(basePixel, blendPixel, BlendPinLightf); +} + + +void SGX_blend_hardMix(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = Blend4(basePixel, blendPixel, BlendHardMixf); +} +void SGX_blend_hardMix(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = Blend3(basePixel, blendPixel, BlendHardMixf); +} +void SGX_blend_hardMix(float basePixel, float blendPixel, out float oColor) +{ + oColor = Blend1(basePixel, blendPixel, BlendHardMixf); +} + + +void SGX_blend_reflect(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = Blend4(basePixel, blendPixel, BlendReflectf); +} +void SGX_blend_reflect(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = Blend3(basePixel, blendPixel, BlendReflectf); +} +void SGX_blend_reflect(float basePixel, float blendPixel, out float oColor) +{ + oColor = Blend1(basePixel, blendPixel, BlendReflectf); +} + +void SGX_blend_glow(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = Blend4(basePixel, blendPixel, BlendReflectf); +} +void SGX_blend_glow(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = Blend3(basePixel, blendPixel, BlendReflectf); +} +void SGX_blend_glow(float basePixel, float blendPixel, out float oColor) +{ + oColor = Blend1(basePixel, blendPixel, BlendReflectf); +} + + +void SGX_blend_phoenix(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendPhoenix(basePixel, blendPixel); +} +void SGX_blend_phoenix(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendPhoenix(basePixel, blendPixel); +} +void SGX_blend_phoenix(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendPhoenix(basePixel, blendPixel); +} + + +void SGX_blend_saturation(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendSaturation4(basePixel, blendPixel); +} +void SGX_blend_saturation(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendSaturation3(basePixel, blendPixel); +} +void SGX_blend_saturation(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendSaturation1(basePixel, blendPixel); +} + + +void SGX_blend_color(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendColor4(basePixel, blendPixel); +} +void SGX_blend_color(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendColor3(basePixel, blendPixel); +} +void SGX_blend_color(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendColor1(basePixel, blendPixel); +} + + +void SGX_blend_luminosity(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendLuminosity4(basePixel, blendPixel); +} +void SGX_blend_luminosity(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendLuminosity3(basePixel, blendPixel); +} +void SGX_blend_luminosity(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendLuminosity1(basePixel, blendPixel); +} + + + +//////////////////////////////////////////////////////////////////////////////////// +/// Source modification functions +//////////////////////////////////////////////////////////////////////////////////// + + +void SGX_src_mod_modulate(float4 iColor, float4 controlVal, out float4 oColor) +{ + oColor = iColor * controlVal; +} +void SGX_src_mod_modulate(float3 iColor, float3 controlVal, out float3 oColor) +{ + oColor = iColor * controlVal; +} +void SGX_src_mod_modulate(float iColor, float controlVal, out float oColor) +{ + oColor = iColor * controlVal; +} + +void SGX_src_mod_inv_modulate(float4 iColor, float4 controlVal, out float4 oColor) +{ + oColor = lerp(iColor, 1, controlVal); +} +void SGX_src_mod_inv_modulate(float3 iColor, float3 controlVal, out float3 oColor) +{ + oColor = lerp(iColor, 1, controlVal); +} +void SGX_src_mod_inv_modulate(float iColor, float controlVal, out float oColor) +{ + oColor = lerp(iColor, 1, controlVal); +} \ No newline at end of file diff --git a/res/dist/media/RTShaderLib/SGXLib_LayeredBlending.glsl b/res/dist/media/RTShaderLib/SGXLib_LayeredBlending.glsl new file mode 100644 index 00000000000..97edd9d19e9 --- /dev/null +++ b/res/dist/media/RTShaderLib/SGXLib_LayeredBlending.glsl @@ -0,0 +1,825 @@ +#version 120 + +/* +** layered blending & misc math +** Blending modes, RGB/HSL/Contrast/Desaturate, levels control +** +** The shaders below are base on the shaders created by: +** Romain Dura | Romz +** Blog: http://blog.mouaif.org +** Post: http://blog.mouaif.org/?p=94 +*/ + + +/* +** Desaturation +*/ + +vec4 Desaturate(in vec3 color, in float Desaturation) +{ + vec3 grayXfer = vec3(0.3, 0.59, 0.11); + vec3 gray = vec3(dot(grayXfer, color)); + return vec4(mix(color, gray, Desaturation), 1.0); +} + + +/* +** Hue, saturation, luminance +*/ + +vec3 RGBToHSL(in vec3 color) +{ + vec3 hsl; // init to 0 to avoid warnings ? (and reverse if + remove first part) + + float fmin = min(min(color.r, color.g), color.b); //Min. value of RGB + float fmax = max(max(color.r, color.g), color.b); //Max. value of RGB + float delta = fmax - fmin; //Delta RGB value + + hsl.z = (fmax + fmin) / 2.0; // Luminance + + if (delta == 0.0) //This is a gray, no chroma... + { + hsl.x = 0.0; // Hue + hsl.y = 0.0; // Saturation + } + else //Chromatic data... + { + if (hsl.z < 0.5) + hsl.y = delta / (fmax + fmin); // Saturation + else + hsl.y = delta / (2.0 - fmax - fmin); // Saturation + + float deltaR = (((fmax - color.r) / 6.0) + (delta / 2.0)) / delta; + float deltaG = (((fmax - color.g) / 6.0) + (delta / 2.0)) / delta; + float deltaB = (((fmax - color.b) / 6.0) + (delta / 2.0)) / delta; + + if (color.r == fmax ) + hsl.x = deltaB - deltaG; // Hue + else if (color.g == fmax) + hsl.x = (1.0 / 3.0) + deltaR - deltaB; // Hue + else if (color.b == fmax) + hsl.x = (2.0 / 3.0) + deltaG - deltaR; // Hue + + if (hsl.x < 0.0) + hsl.x += 1.0; // Hue + else if (hsl.x > 1.0) + hsl.x -= 1.0; // Hue + } + + return hsl; +} + +float HueToRGB(in float f1, in float f2, in float hue) +{ + if (hue < 0.0) + hue += 1.0; + else if (hue > 1.0) + hue -= 1.0; + float res; + if ((6.0 * hue) < 1.0) + res = f1 + (f2 - f1) * 6.0 * hue; + else if ((2.0 * hue) < 1.0) + res = f2; + else if ((3.0 * hue) < 2.0) + res = f1 + (f2 - f1) * ((2.0 / 3.0) - hue) * 6.0; + else + res = f1; + return res; +} + +vec3 HSLToRGB(in vec3 hsl) +{ + vec3 rgb; + + if (hsl.y == 0.0) + rgb = vec3(hsl.z); // Luminance + else + { + float f2; + + if (hsl.z < 0.5) + f2 = hsl.z * (1.0 + hsl.y); + else + f2 = (hsl.z + hsl.y) - (hsl.y * hsl.z); + + float f1 = 2.0 * hsl.z - f2; + + rgb.r = HueToRGB(f1, f2, hsl.x + (1.0/3.0)); + rgb.g = HueToRGB(f1, f2, hsl.x); + rgb.b = HueToRGB(f1, f2, hsl.x - (1.0/3.0)); + } + + return rgb; +} + + +/* +** Contrast, saturation, brightness +** Code of this function is from TGM's shader pack +** http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=21057 +*/ + +// For all settings: 1.0 = 100% 0.5=50% 1.5 = 150% +vec3 ContrastSaturationBrightness(in vec3 color, in float brt, in float sat, in float con) +{ + // Increase or decrease these values to adjust r, g and b color channels separately + const float AvgLumR = 0.5; + const float AvgLumG = 0.5; + const float AvgLumB = 0.5; + + const vec3 LumCoeff = vec3(0.2125, 0.7154, 0.0721); + + vec3 AvgLumin = vec3(AvgLumR, AvgLumG, AvgLumB); + vec3 brtColor = color * brt; + vec3 intensity = vec3(dot(brtColor, LumCoeff)); + vec3 satColor = mix(intensity, brtColor, sat); + vec3 conColor = mix(AvgLumin, satColor, con); + return conColor; +} + +/* +** Float blending modes +** Adapted from here: http://www.nathanm.com/photoshop-blending-math/ +** But I modified the HardMix (wrong condition), Overlay, SoftLight, ColorDodge, ColorBurn, VividLight, PinLight (inverted layers) ones to have correct results +*/ + +#define BlendLinearDodgef BlendAddf +#define BlendLinearBurnf BlendSubtractf +#define BlendAddf(base, blend) min(base + blend, 1.0) +#define BlendSubtractf(base, blend) max(base + blend - 1.0, 0.0) +#define BlendLightenf(base, blend) max(blend, base) +#define BlendDarkenf(base, blend) min(blend, base) +#define BlendScreenf(base, blend) (1.0 - ((1.0 - base) * (1.0 - blend))) +#define BlendOverlayf(base, blend) (base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend))) +#define BlendSoftLightf(base, blend) ((blend < 0.5) ? (2.0 * base * blend + base * base * (1.0 - 2.0 * blend)) : (sqrt(base) * (2.0 * blend - 1.0) + 2.0 * base * (1.0 - blend))) +#define BlendColorDodgef(base, blend) ((blend == 1.0) ? blend : min(base / (1.0 - blend), 1.0)) +#define BlendColorBurnf(base, blend) ((blend == 0.0) ? blend : max((1.0 - ((1.0 - base) / blend)), 0.0)) +#define BlendHardMixf(base, blend) ((BlendVividLightf(base, blend) < 0.5) ? 0.0 : 1.0) + + + +/* +** Vector3 blending modes +*/ + +// Component wise blending +#define Blend1(base, blend, funcf) funcf(base, blend) +#define Blend3(base, blend, funcf) vec3(funcf(base.r, blend.r), funcf(base.g, blend.g), funcf(base.b, blend.b)) +#define Blend4(base, blend, funcf) vec4(funcf(base.r, blend.r), funcf(base.g, blend.g), funcf(base.b, blend.b), funcf(base.a, blend.a)) + +#define BlendNormal(base, blend) (base) +#define BlendMultiply(base, blend) (base * blend) +#define BlendAverage(base, blend) ((base + blend) / 2.0) +#define BlendAdd(base, blend) min(base + blend, 1.0) +#define BlendSubtract(base, blend) max(base + blend - 1.0, 0.0) +#define BlendDifference(base, blend) abs(base - blend) +#define BlendNegation(base, blend) (1.0 - abs(1.0 - base - blend)) +#define BlendExclusion(base, blend) (base + blend - 2.0 * base * blend) +#define BlendPhoenix(base, blend) (min(base, blend) - max(base, blend) + 1.0) +#define BlendOpacity(base, blend, F, O) (F(base, blend) * O + blend * (1.0 - O)) + +// Hue Blend mode creates the result color by combining the luminance and saturation of the base color with the hue of the blend color. +float BlendHue1(in float base, in float blend) +{ + return base; +} + +vec3 BlendHue3(in vec3 base, in vec3 blend) +{ + vec3 baseHSL = RGBToHSL(base); + return HSLToRGB(vec3(RGBToHSL(blend).r, baseHSL.g, baseHSL.b)); +} + +vec4 BlendHue4(in vec4 base, in vec4 blend) +{ + vec3 hue = BlendHue3(base.xyz, blend.xyz); + return vec4(hue.x, hue.y, hue.z, BlendHue1(base.w, blend.w)); +} + +// Saturation Blend mode creates the result color by combining the luminance and hue of the base color with the saturation of the blend color. +float BlendSaturation1(in float base, in float blend) +{ + return base; +} + +vec3 BlendSaturation3(in vec3 base, in vec3 blend) +{ + vec3 baseHSL = RGBToHSL(base); + return HSLToRGB(vec3(baseHSL.r, RGBToHSL(blend).g, baseHSL.b)); +} + +vec4 BlendSaturation4(in vec4 base, in vec4 blend) +{ + vec3 hue = BlendSaturation3(base.xyz, blend.xyz); + return vec4(hue.x, hue.y, hue.z, BlendSaturation1(base.w, blend.w)); +} + +// Color Mode keeps the brightness of the base color and applies both the hue and saturation of the blend color. +float BlendColor1(in float base, in float blend) +{ + return base; +} + +vec3 BlendColor3(in vec3 base, in vec3 blend) +{ + vec3 blendHSL = RGBToHSL(blend); + return HSLToRGB(vec3(blendHSL.r, blendHSL.g, RGBToHSL(base).b)); +} + +vec4 BlendColor4(in vec4 base, in vec4 blend) +{ + vec3 hue = BlendColor3(base.xyz, blend.xyz); + return vec4(hue.x, hue.y, hue.z, BlendColor1(base.w, blend.w)); +} + + +// Luminosity Blend mode creates the result color by combining the hue and saturation of the base color with the luminance of the blend color. +float BlendLuminosity1(in float base, in float blend) +{ + return base; +} + +vec3 BlendLuminosity3(in vec3 base, in vec3 blend) +{ + vec3 baseHSL = RGBToHSL(base); + return HSLToRGB(vec3(baseHSL.r, baseHSL.g, RGBToHSL(blend).b)); +} + +vec4 BlendLuminosity4(in vec4 base, in vec4 blend) +{ + vec3 hue = BlendLuminosity3(base.xyz, blend.xyz); + return vec4(hue.x, hue.y, hue.z, BlendLuminosity1(base.w, blend.w)); +} + +float BlendLinearLightf(in float s1, in float s2) +{ + float oColor; + + if (s2 < 0.5) + { + float s2x = (2.0 * s2); + oColor = BlendSubtractf(s1, s2x); + } + else + { + float s2x = (2.0 * (s2 - 0.5)); + oColor = BlendAddf(s1, s2x); + } + + return oColor; +} + +float BlendVividLightf(in float s1, in float s2) +{ + float oColor; + + if (s2 < 0.5) + { + float s2x = (2.0 * s2); + oColor = BlendColorBurnf(s1, s2x); + } + else + { + float s2x = (2.0 * (s2 - 0.5)); + oColor = BlendColorDodgef(s1, s2x); + } + + return oColor; +} + +float BlendPinLightf(in float s1, in float s2) +{ + float oColor; + + if (s2 < 0.5) + { + float s2x = (2.0 * s2); + oColor = BlendDarkenf(s1, s2x); + } + else + { + float s2x = (2.0 * (s2 - 0.5)); + oColor = BlendLightenf(s1, s2x); + } + + return oColor; +} + +float BlendReflectf(in float s1, in float s2) +{ + float oColor; + + if (s2 == 1.0) + { + oColor = s2; + } + else + { + float s1x = (s1 * s1) / (1.0 - s2); + + oColor = min(s1x, 1.0); + } + + return oColor; +} + +//------------------------------------ +// Interface for RTShader +//------------------------------------ + + +void SGX_blend_normal(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendNormal(basePixel, blendPixel); +} + +void SGX_blend_normal(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendNormal(basePixel, blendPixel); +} + +void SGX_blend_normal(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendNormal(basePixel, blendPixel); +} + + +void SGX_blend_lighten(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendLightenf(basePixel, blendPixel); +} + +void SGX_blend_lighten(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendLightenf(basePixel, blendPixel); +} + +void SGX_blend_lighten(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendLightenf(basePixel, blendPixel); +} + + +void SGX_blend_darken(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendDarkenf(basePixel, blendPixel); +} + +void SGX_blend_darken(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendDarkenf(basePixel, blendPixel); +} + +void SGX_blend_darken(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendDarkenf(basePixel, blendPixel); +} + + +void SGX_blend_multiply(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendMultiply(basePixel, blendPixel); +} + +void SGX_blend_multiply(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendMultiply(basePixel, blendPixel); +} + +void SGX_blend_multiply(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendMultiply(basePixel, blendPixel); +} + + +void SGX_blend_average(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendAverage(basePixel, blendPixel); +} + +void SGX_blend_average(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendAverage(basePixel, blendPixel); +} + +void SGX_blend_average(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendAverage(basePixel, blendPixel); +} + + +void SGX_blend_add(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendAdd(basePixel, blendPixel); +} + +void SGX_blend_add(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendAdd(basePixel, blendPixel); +} + +void SGX_blend_add(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendAdd(basePixel, blendPixel); +} + + +void SGX_blend_subtract(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendSubtract(basePixel, blendPixel); +} + +void SGX_blend_subtract(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendSubtract(basePixel, blendPixel); +} + +void SGX_blend_subtract(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendSubtract(basePixel, blendPixel); +} + + +void SGX_blend_difference(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendDifference(basePixel, blendPixel); +} +void SGX_blend_difference(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendDifference(basePixel, blendPixel); +} +void SGX_blend_difference(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendDifference(basePixel, blendPixel); +} + + +void SGX_blend_negation(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendNegation(basePixel, blendPixel); +} +void SGX_blend_negation(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendNegation(basePixel, blendPixel); +} +void SGX_blend_negation(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendNegation(basePixel, blendPixel); +} + + +void SGX_blend_exclusion(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendExclusion(basePixel, blendPixel); +} +void SGX_blend_exclusion(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendExclusion(basePixel, blendPixel); +} +void SGX_blend_exclusion(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendExclusion(basePixel, blendPixel); +} + + +void SGX_blend_screen(in vec4 s1, in vec4 s2, out vec4 oColor) +{ + oColor = vec4(BlendScreenf(s1.r, s2.r), + BlendScreenf(s1.g, s2.g), + BlendScreenf(s1.b, s2.b), + BlendScreenf(s1.a, s2.a)); +} +void SGX_blend_screen(in vec3 s1, in vec3 s2, out vec3 oColor) +{ + oColor = vec3(BlendScreenf(s1.r, s2.r), + BlendScreenf(s1.g, s2.g), + BlendScreenf(s1.b, s2.b)); +} +void SGX_blend_screen(in float s1, in float s2, out float oColor) +{ + oColor = BlendScreenf(s1, s2); +} + + +void SGX_blend_overlay(in vec4 s1, in vec4 s2, out vec4 oColor) +{ + oColor = vec4(BlendOverlayf(s1.r, s2.r), + BlendOverlayf(s1.g, s2.g), + BlendOverlayf(s1.b, s2.b), + BlendOverlayf(s1.a, s2.a)); +} +void SGX_blend_overlay(in vec3 s1, in vec3 s2, out vec3 oColor) +{ + oColor = vec3(BlendOverlayf(s1.r, s2.r), + BlendOverlayf(s1.g, s2.g), + BlendOverlayf(s1.b, s2.b)); +} +void SGX_blend_overlay(in float s1, in float s2, out float oColor) +{ + oColor = BlendOverlayf(s1, s2); +} + + +void SGX_blend_softLight(in vec4 s1, in vec4 s2, out vec4 oColor) +{ + oColor = vec4(BlendSoftLightf(s1.r, s2.r), + BlendSoftLightf(s1.g, s2.g), + BlendSoftLightf(s1.b, s2.b), + BlendSoftLightf(s1.a, s2.a)); +} +void SGX_blend_softLight(in vec3 s1, in vec3 s2, out vec3 oColor) +{ + oColor = vec3(BlendSoftLightf(s1.r, s2.r), + BlendSoftLightf(s1.g, s2.g), + BlendSoftLightf(s1.b, s2.b)); +} +void SGX_blend_softLight(in float s1, in float s2, out float oColor) +{ + oColor = BlendSoftLightf(s1, s2); +} + + +void SGX_blend_hardLight(in vec4 s1, in vec4 s2, out vec4 oColor) +{ + oColor = vec4(BlendOverlayf(s1.r, s2.r), + BlendOverlayf(s1.g, s2.g), + BlendOverlayf(s1.b, s2.b), + BlendOverlayf(s1.a, s2.a)); +} +void SGX_blend_hardLight(in vec3 s1, in vec3 s2, out vec3 oColor) +{ + oColor = vec3(BlendOverlayf(s1.r, s2.r), + BlendOverlayf(s1.g, s2.g), + BlendOverlayf(s1.b, s2.b)); +} +void SGX_blend_hardLight(in float s1, in float s2, out float oColor) +{ + oColor = BlendOverlayf(s1, s2); +} + + +void SGX_blend_colorDodge(in vec4 s1, in vec4 s2, out vec4 oColor) +{ + oColor = vec4(BlendColorDodgef(s1.r, s2.r), + BlendColorDodgef(s1.g, s2.g), + BlendColorDodgef(s1.b, s2.b), + BlendColorDodgef(s1.a, s2.a)); +} +void SGX_blend_colorDodge(in vec3 s1, in vec3 s2, out vec3 oColor) +{ + oColor = vec3(BlendColorDodgef(s1.r, s2.r), + BlendColorDodgef(s1.g, s2.g), + BlendColorDodgef(s1.b, s2.b)); +} +void SGX_blend_colorDodge(in float s1, in float s2, out float oColor) +{ + oColor = BlendColorDodgef(s1, s2); +} + + +void SGX_blend_colorBurn(in vec4 s1, in vec4 s2, out vec4 oColor) +{ + oColor = vec4(BlendColorBurnf(s1.r, s2.r), + BlendColorBurnf(s1.g, s2.g), + BlendColorBurnf(s1.b, s2.b), + BlendColorBurnf(s1.a, s2.a)); +} +void SGX_blend_colorBurn(in vec3 s1, in vec3 s2, out vec3 oColor) +{ + oColor = vec3(BlendColorBurnf(s1.r, s2.r), + BlendColorBurnf(s1.g, s2.g), + BlendColorBurnf(s1.b, s2.b)); +} +void SGX_blend_colorBurn(in float s1, in float s2, out float oColor) +{ + oColor = BlendColorBurnf(s1, s2); +} + + +void SGX_blend_linearDodge(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendAddf(basePixel, blendPixel); +} +void SGX_blend_linearDodge(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendAddf(basePixel, blendPixel); +} +void SGX_blend_linearDodge(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendAddf(basePixel, blendPixel); +} + + +void SGX_blend_linearBurn(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendSubtractf(basePixel, blendPixel); +} +void SGX_blend_linearBurn(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendSubtractf(basePixel, blendPixel); +} +void SGX_blend_linearBurn(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendSubtractf(basePixel, blendPixel); +} + + +void SGX_blend_linearLight(in vec4 s1, in vec4 s2, out vec4 oColor) +{ + oColor = vec4(BlendLinearLightf(s1.r, s2.r), + BlendLinearLightf(s1.g, s2.g), + BlendLinearLightf(s1.b, s2.b), + BlendLinearLightf(s1.a, s2.a)); +} +void SGX_blend_linearLight(in vec3 s1, in vec3 s2, out vec3 oColor) +{ + oColor = vec3(BlendLinearLightf(s1.r, s2.r), + BlendLinearLightf(s1.g, s2.g), + BlendLinearLightf(s1.b, s2.b)); +} +void SGX_blend_linearLight(in float s1, in float s2, out float oColor) +{ + oColor = BlendLinearLightf(s1, s2); +} + + +void SGX_blend_vividLight(in vec4 s1, in vec4 s2, out vec4 oColor) +{ + oColor = vec4(BlendVividLightf(s1.r, s2.r), + BlendVividLightf(s1.g, s2.g), + BlendVividLightf(s1.b, s2.b), + BlendVividLightf(s1.a, s2.a)); +} +void SGX_blend_vividLight(in vec3 s1, in vec3 s2, out vec3 oColor) +{ + oColor = vec3(BlendVividLightf(s1.r, s2.r), + BlendVividLightf(s1.g, s2.g), + BlendVividLightf(s1.b, s2.b)); +} +void SGX_blend_vividLight(in float s1, in float s2, out float oColor) +{ + oColor = BlendVividLightf(s1, s2); +} + + +void SGX_blend_pinLight(in vec4 s1, in vec4 s2, out vec4 oColor) +{ + oColor = vec4(BlendPinLightf(s1.r, s2.r), + BlendPinLightf(s1.g, s2.g), + BlendPinLightf(s1.b, s2.b), + BlendPinLightf(s1.a, s2.a)); +} +void SGX_blend_pinLight(in vec3 s1, in vec3 s2, out vec3 oColor) +{ + oColor = vec3(BlendPinLightf(s1.r, s2.r), + BlendPinLightf(s1.g, s2.g), + BlendPinLightf(s1.b, s2.b)); +} +void SGX_blend_pinLight(in float s1, in float s2, out float oColor) +{ + oColor = BlendPinLightf(s1, s2); +} + + +void SGX_blend_hardMix(in vec4 s1, in vec4 s2, out vec4 oColor) +{ + oColor = vec4(BlendHardMixf(s1.r, s2.r), + BlendHardMixf(s1.g, s2.g), + BlendHardMixf(s1.b, s2.b), + BlendHardMixf(s1.a, s2.a)); +} +void SGX_blend_hardMix(in vec3 s1, in vec3 s2, out vec3 oColor) +{ + oColor = vec3(BlendHardMixf(s1.r, s2.r), + BlendHardMixf(s1.g, s2.g), + BlendHardMixf(s1.b, s2.b)); +} +void SGX_blend_hardMix(in float s1, in float s2, out float oColor) +{ + oColor = BlendHardMixf(s1, s2); +} + +void SGX_blend_reflect(in vec4 s1, in vec4 s2, out vec4 oColor) +{ + oColor = vec4(BlendReflectf(s1.r, s2.r), + BlendReflectf(s1.g, s2.g), + BlendReflectf(s1.b, s2.b), + BlendReflectf(s1.a, s2.a)); +} +void SGX_blend_reflect(in vec3 s1, in vec3 s2, out vec3 oColor) +{ + oColor = vec3(BlendReflectf(s1.r, s2.r), + BlendReflectf(s1.g, s2.g), + BlendReflectf(s1.b, s2.b)); +} +void SGX_blend_reflect(in float s1, in float s2, out float oColor) +{ + oColor = BlendReflectf(s1, s2); +} + + +void SGX_blend_glow(in vec4 s1, in vec4 s2, out vec4 oColor) +{ + oColor = vec4(BlendReflectf(s1.r, s2.r), + BlendReflectf(s1.g, s2.g), + BlendReflectf(s1.b, s2.b), + BlendReflectf(s1.a, s2.a)); +} +void SGX_blend_glow(in vec3 s1, in vec3 s2, out vec3 oColor) +{ + oColor = vec3(BlendReflectf(s1.r, s2.r), + BlendReflectf(s1.g, s2.g), + BlendReflectf(s1.b, s2.b)); +} +void SGX_blend_glow(in float s1, in float s2, out float oColor) +{ + oColor = BlendReflectf(s1, s2); +} + + +void SGX_blend_phoenix(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendPhoenix(basePixel, blendPixel); +} +void SGX_blend_phoenix(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendPhoenix(basePixel, blendPixel); +} +void SGX_blend_phoenix(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendPhoenix(basePixel, blendPixel); +} + + +void SGX_blend_saturation(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendSaturation4(basePixel, blendPixel); +} +void SGX_blend_saturation(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendSaturation3(basePixel, blendPixel); +} +void SGX_blend_saturation(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendSaturation1(basePixel, blendPixel); +} + + +void SGX_blend_color(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendColor4(basePixel, blendPixel); +} +void SGX_blend_color(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendColor3(basePixel, blendPixel); +} +void SGX_blend_color(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendColor1(basePixel, blendPixel); +} + + +void SGX_blend_luminosity(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendLuminosity4(basePixel, blendPixel); +} +void SGX_blend_luminosity(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendLuminosity3(basePixel, blendPixel); +} +void SGX_blend_luminosity(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendLuminosity1(basePixel, blendPixel); +} + + +//////////////////////////////////////////////////////////////////////////////////// +/// Source modification functions +//////////////////////////////////////////////////////////////////////////////////// + + +void SGX_src_mod_modulate(in vec4 iColor, in vec4 controlVal, out vec4 oColor) +{ + oColor = iColor * controlVal; +} +void SGX_src_mod_modulate(in vec3 iColor, in vec3 controlVal, out vec3 oColor) +{ + oColor = iColor * controlVal; +} +void SGX_src_mod_modulate(in float iColor, in float controlVal, out float oColor) +{ + oColor = iColor * controlVal; +} + +void SGX_src_mod_inv_modulate(in vec4 iColor, in vec4 controlVal, out vec4 oColor) +{ + oColor = mix(iColor, vec4(1.0,1.0,1.0,1.0), controlVal); +} +void SGX_src_mod_inv_modulate(in vec3 iColor, in vec3 controlVal, out vec3 oColor) +{ + oColor = mix(iColor, vec3(1.0,1.0,1.0), controlVal); +} +void SGX_src_mod_inv_modulate(in float iColor, in float controlVal, out float oColor) +{ + oColor = mix(iColor, 1, controlVal); +} \ No newline at end of file diff --git a/res/dist/media/RTShaderLib/SGXLib_LayeredBlending.glsles b/res/dist/media/RTShaderLib/SGXLib_LayeredBlending.glsles new file mode 100644 index 00000000000..27123984b50 --- /dev/null +++ b/res/dist/media/RTShaderLib/SGXLib_LayeredBlending.glsles @@ -0,0 +1,889 @@ +#version 100 +precision highp float; +precision highp int; +precision lowp sampler2D; +precision lowp samplerCube; + +/* +** layered blending & misc math +** Blending modes, RGB/HSL/Contrast/Desaturate, levels control +** +** The shaders below are base on the shaders created by: +** Romain Dura | Romz +** Blog: http://blog.mouaif.org +** Post: http://blog.mouaif.org/?p=94 +*/ + + +/* +** Desaturation +*/ + +vec4 Desaturate(in vec3 color, in float Desaturation) +{ + vec3 grayXfer = vec3(0.3, 0.59, 0.11); + vec3 gray = vec3(dot(grayXfer, color)); + return vec4(mix(color, gray, Desaturation), 1.0); +} + + +/* +** Hue, saturation, luminance +*/ + +vec3 _RGBToHSL(in vec3 color) +{ + vec3 hsl; // init to 0 to avoid warnings ? (and reverse if + remove first part) + + float fmin = min(min(color.r, color.g), color.b); //Min. value of RGB + float fmax = max(max(color.r, color.g), color.b); //Max. value of RGB + float delta = fmax - fmin; //Delta RGB value + + hsl.z = (fmax + fmin) / 2.0; // Luminance + + if (delta == 0.0) //This is a gray, no chroma... + { + hsl.x = 0.0; // Hue + hsl.y = 0.0; // Saturation + } + else //Chromatic data... + { + if (hsl.z < 0.5) + hsl.y = delta / (fmax + fmin); // Saturation + else + hsl.y = delta / (2.0 - fmax - fmin); // Saturation + + float deltaR = (((fmax - color.r) / 6.0) + (delta / 2.0)) / delta; + float deltaG = (((fmax - color.g) / 6.0) + (delta / 2.0)) / delta; + float deltaB = (((fmax - color.b) / 6.0) + (delta / 2.0)) / delta; + + if (color.r == fmax ) + hsl.x = deltaB - deltaG; // Hue + else if (color.g == fmax) + hsl.x = (1.0 / 3.0) + deltaR - deltaB; // Hue + else if (color.b == fmax) + hsl.x = (2.0 / 3.0) + deltaG - deltaR; // Hue + + if (hsl.x < 0.0) + hsl.x += 1.0; // Hue + else if (hsl.x > 1.0) + hsl.x -= 1.0; // Hue + } + + return hsl; +} + +float _HueToRGB(in float f1, in float f2, in float hue) +{ + if (hue < 0.0) + hue += 1.0; + else if (hue > 1.0) + hue -= 1.0; + float res; + if ((6.0 * hue) < 1.0) + res = f1 + (f2 - f1) * 6.0 * hue; + else if ((2.0 * hue) < 1.0) + res = f2; + else if ((3.0 * hue) < 2.0) + res = f1 + (f2 - f1) * ((2.0 / 3.0) - hue) * 6.0; + else + res = f1; + return res; +} + +/* +** Contrast, saturation, brightness +** Code of this function is from TGM's shader pack +** http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=21057 +*/ + +// For all settings: 1.0 = 100% 0.5=50% 1.5 = 150% +vec3 ContrastSaturationBrightness(in vec3 color, in float brt, in float sat, in float con) +{ + // Increase or decrease these values to adjust r, g and b color channels separately + const float AvgLumR = 0.5; + const float AvgLumG = 0.5; + const float AvgLumB = 0.5; + + const vec3 LumCoeff = vec3(0.2125, 0.7154, 0.0721); + + vec3 AvgLumin = vec3(AvgLumR, AvgLumG, AvgLumB); + vec3 brtColor = color * brt; + vec3 intensity = vec3(dot(brtColor, LumCoeff)); + vec3 satColor = mix(intensity, brtColor, sat); + vec3 conColor = mix(AvgLumin, satColor, con); + return conColor; +} + +/* +** Float blending modes +** Adapted from here: http://www.nathanm.com/photoshop-blending-math/ +** But I modified the HardMix (wrong condition), Overlay, SoftLight, ColorDodge, ColorBurn, VividLight, PinLight (inverted layers) ones to have correct results +*/ + +#define BlendLinearDodgef BlendAddf +#define BlendLinearBurnf BlendSubtractf +#define BlendAddf(base, blend) min(base + blend, 1.0) +#define BlendSubtractf(base, blend) max(base + blend - 1.0, 0.0) +#define BlendLightenf(base, blend) max(blend, base) +#define BlendDarkenf(base, blend) min(blend, base) +#define BlendScreenf(base, blend) (1.0 - ((1.0 - base) * (1.0 - blend))) +#define BlendOverlayf(base, blend) (base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend))) +#define BlendSoftLightf(base, blend) ((blend < 0.5) ? (2.0 * base * blend + base * base * (1.0 - 2.0 * blend)) : (sqrt(base) * (2.0 * blend - 1.0) + 2.0 * base * (1.0 - blend))) +#define BlendColorDodgef(base, blend) ((blend == 1.0) ? blend : min(base / (1.0 - blend), 1.0)) +#define BlendColorBurnf(base, blend) ((blend == 0.0) ? blend : max((1.0 - ((1.0 - base) / blend)), 0.0)) +#define BlendHardMixf(base, blend) ((BlendVividLightf(base, blend) < 0.5) ? 0.0 : 1.0) + +/* +** Vector3 blending modes +*/ + +// Component wise blending +#define Blend1(base, blend, funcf) funcf(base, blend) +#define Blend3(base, blend, funcf) vec3(funcf(base.r, blend.r), funcf(base.g, blend.g), funcf(base.b, blend.b)) +#define Blend4(base, blend, funcf) vec4(funcf(base.r, blend.r), funcf(base.g, blend.g), funcf(base.b, blend.b), funcf(base.a, blend.a)) + +#define BlendNormal(base, blend) (base) +#define BlendMultiply(base, blend) (base * blend) +#define BlendAverage(base, blend) ((base + blend) / 2.0) +#define BlendAdd(base, blend) min(base + blend, 1.0) +#define BlendSubtract(base, blend) max(base + blend - 1.0, 0.0) +#define BlendDifference(base, blend) abs(base - blend) +#define BlendNegation(base, blend) (1.0 - abs(1.0 - base - blend)) +#define BlendExclusion(base, blend) (base + blend - 2.0 * base * blend) +#define BlendPhoenix(base, blend) (min(base, blend) - max(base, blend) + 1.0) +#define BlendOpacity(base, blend, F, O) (F(base, blend) * O + blend * (1.0 - O)) + +// Hue Blend mode creates the result color by combining the luminance and saturation of the base color with the hue of the blend color. +float BlendHue1(in float base, in float blend) +{ + return base; +} + +vec3 BlendHue3(in vec3 base, in vec3 blend) +{ + vec3 baseHSL = _RGBToHSL(base); + vec3 rgb, inHSL = vec3(_RGBToHSL(blend).r, baseHSL.g, baseHSL.b); + + // The HSLToRGB function has been inlined to here + if (inHSL.y == 0.0) + rgb = vec3(inHSL.z); // Luminance + else + { + float f2; + + if (inHSL.z < 0.5) + f2 = inHSL.z * (1.0 + inHSL.y); + else + f2 = (inHSL.z + inHSL.y) - (inHSL.y * inHSL.z); + + float f1 = 2.0 * inHSL.z - f2; + + rgb.r = _HueToRGB(f1, f2, inHSL.x + (1.0/3.0)); + rgb.g = _HueToRGB(f1, f2, inHSL.x); + rgb.b = _HueToRGB(f1, f2, inHSL.x - (1.0/3.0)); + } + + return rgb; +} + +vec4 BlendHue4(in vec4 base, in vec4 blend) +{ + vec3 hue = BlendHue3(base.xyz, blend.xyz); + return vec4(hue.x, hue.y, hue.z, BlendHue1(base.w, blend.w)); +} + +// Saturation Blend mode creates the result color by combining the luminance and hue of the base color with the saturation of the blend color. +float BlendSaturation1(in float base, in float blend) +{ + return base; +} + +vec3 BlendSaturation3(in vec3 base, in vec3 blend) +{ + vec3 baseHSL = _RGBToHSL(base); + + vec3 rgb, inHSL = vec3(baseHSL.r, _RGBToHSL(blend).g, baseHSL.b); + + // The HSLToRGB function has been inlined to here + if (inHSL.y == 0.0) + rgb = vec3(inHSL.z); // Luminance + else + { + float f2; + + if (inHSL.z < 0.5) + f2 = inHSL.z * (1.0 + inHSL.y); + else + f2 = (inHSL.z + inHSL.y) - (inHSL.y * inHSL.z); + + float f1 = 2.0 * inHSL.z - f2; + + rgb.r = _HueToRGB(f1, f2, inHSL.x + (1.0/3.0)); + rgb.g = _HueToRGB(f1, f2, inHSL.x); + rgb.b = _HueToRGB(f1, f2, inHSL.x - (1.0/3.0)); + } + + return rgb; +} + +vec4 BlendSaturation4(in vec4 base, in vec4 blend) +{ + vec3 hue = BlendSaturation3(base.xyz, blend.xyz); + return vec4(hue.x, hue.y, hue.z, BlendSaturation1(base.w, blend.w)); +} + +// Color Mode keeps the brightness of the base color and applies both the hue and saturation of the blend color. +float BlendColor1(in float base, in float blend) +{ + return base; +} + +vec3 BlendColor3(in vec3 base, in vec3 blend) +{ + vec3 blendHSL = _RGBToHSL(blend); + + vec3 rgb, inHSL = vec3(blendHSL.r, blendHSL.g, _RGBToHSL(base).b); + + // The HSLToRGB function has been inlined to here + if (inHSL.y == 0.0) + rgb = vec3(inHSL.z); // Luminance + else + { + float f2; + + if (inHSL.z < 0.5) + f2 = inHSL.z * (1.0 + inHSL.y); + else + f2 = (inHSL.z + inHSL.y) - (inHSL.y * inHSL.z); + + float f1 = 2.0 * inHSL.z - f2; + + rgb.r = _HueToRGB(f1, f2, inHSL.x + (1.0/3.0)); + rgb.g = _HueToRGB(f1, f2, inHSL.x); + rgb.b = _HueToRGB(f1, f2, inHSL.x - (1.0/3.0)); + } + + return rgb; +} + +vec4 BlendColor4(in vec4 base, in vec4 blend) +{ + vec3 hue = BlendColor3(base.xyz, blend.xyz); + return vec4(hue.x, hue.y, hue.z, BlendColor1(base.w, blend.w)); +} + + +// Luminosity Blend mode creates the result color by combining the hue and saturation of the base color with the luminance of the blend color. +float BlendLuminosity1(in float base, in float blend) +{ + return base; +} + +vec3 BlendLuminosity3(in vec3 base, in vec3 blend) +{ + vec3 baseHSL = _RGBToHSL(base); + vec3 rgb, inHSL = vec3(baseHSL.r, baseHSL.g, _RGBToHSL(blend).b); + + // The HSLToRGB function has been inlined to here + if (inHSL.y == 0.0) + rgb = vec3(inHSL.z); // Luminance + else + { + float f2; + + if (inHSL.z < 0.5) + f2 = inHSL.z * (1.0 + inHSL.y); + else + f2 = (inHSL.z + inHSL.y) - (inHSL.y * inHSL.z); + + float f1 = 2.0 * inHSL.z - f2; + + rgb.r = _HueToRGB(f1, f2, inHSL.x + (1.0/3.0)); + rgb.g = _HueToRGB(f1, f2, inHSL.x); + rgb.b = _HueToRGB(f1, f2, inHSL.x - (1.0/3.0)); + } + + return rgb; +} + +vec4 BlendLuminosity4(in vec4 base, in vec4 blend) +{ + vec3 hue = BlendLuminosity3(base.xyz, blend.xyz); + return vec4(hue.x, hue.y, hue.z, BlendLuminosity1(base.w, blend.w)); +} + +float BlendLinearLightf(in float s1, in float s2) +{ + float oColor; + + if (s2 < 0.5) + { + float s2x = (2.0 * s2); + oColor = BlendSubtractf(s1, s2x); + } + else + { + float s2x = (2.0 * (s2 - 0.5)); + oColor = BlendAddf(s1, s2x); + } + + return oColor; +} + +float BlendVividLightf(in float s1, in float s2) +{ + float oColor; + + if (s2 < 0.5) + { + float s2x = (2.0 * s2); + oColor = BlendColorBurnf(s1, s2x); + } + else + { + float s2x = (2.0 * (s2 - 0.5)); + oColor = BlendColorDodgef(s1, s2x); + } + + return oColor; +} + +float BlendPinLightf(in float s1, in float s2) +{ + float oColor; + + if (s2 < 0.5) + { + float s2x = (2.0 * s2); + oColor = BlendDarkenf(s1, s2x); + } + else + { + float s2x = (2.0 * (s2 - 0.5)); + oColor = BlendLightenf(s1, s2x); + } + + return oColor; +} + +float BlendReflectf(in float s1, in float s2) +{ + float oColor; + + if (s2 == 1.0) + { + oColor = s2; + } + else + { + float s1x = (s1 * s1) / (1.0 - s2); + + oColor = min(s1x, 1.0); + } + + return oColor; +} + +//------------------------------------ +// Interface for RTShader +//------------------------------------ + + +void SGX_blend_normal(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendNormal(basePixel, blendPixel); +} + +void SGX_blend_normal(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendNormal(basePixel, blendPixel); +} + +void SGX_blend_normal(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendNormal(basePixel, blendPixel); +} + + +void SGX_blend_lighten(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendLightenf(basePixel, blendPixel); +} + +void SGX_blend_lighten(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendLightenf(basePixel, blendPixel); +} + +void SGX_blend_lighten(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendLightenf(basePixel, blendPixel); +} + + +void SGX_blend_darken(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendDarkenf(basePixel, blendPixel); +} + +void SGX_blend_darken(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendDarkenf(basePixel, blendPixel); +} + +void SGX_blend_darken(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendDarkenf(basePixel, blendPixel); +} + + +void SGX_blend_multiply(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendMultiply(basePixel, blendPixel); +} + +void SGX_blend_multiply(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendMultiply(basePixel, blendPixel); +} + +void SGX_blend_multiply(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendMultiply(basePixel, blendPixel); +} + + +void SGX_blend_average(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendAverage(basePixel, blendPixel); +} + +void SGX_blend_average(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendAverage(basePixel, blendPixel); +} + +void SGX_blend_average(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendAverage(basePixel, blendPixel); +} + + +void SGX_blend_add(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendAdd(basePixel, blendPixel); +} + +void SGX_blend_add(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendAdd(basePixel, blendPixel); +} + +void SGX_blend_add(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendAdd(basePixel, blendPixel); +} + + +void SGX_blend_subtract(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendSubtract(basePixel, blendPixel); +} + +void SGX_blend_subtract(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendSubtract(basePixel, blendPixel); +} + +void SGX_blend_subtract(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendSubtract(basePixel, blendPixel); +} + + +void SGX_blend_difference(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendDifference(basePixel, blendPixel); +} +void SGX_blend_difference(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendDifference(basePixel, blendPixel); +} +void SGX_blend_difference(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendDifference(basePixel, blendPixel); +} + + +void SGX_blend_negation(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendNegation(basePixel, blendPixel); +} +void SGX_blend_negation(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendNegation(basePixel, blendPixel); +} +void SGX_blend_negation(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendNegation(basePixel, blendPixel); +} + + +void SGX_blend_exclusion(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendExclusion(basePixel, blendPixel); +} +void SGX_blend_exclusion(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendExclusion(basePixel, blendPixel); +} +void SGX_blend_exclusion(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendExclusion(basePixel, blendPixel); +} + + +void SGX_blend_screen(in vec4 s1, in vec4 s2, out vec4 oColor) +{ + oColor = vec4(BlendScreenf(s1.r, s2.r), + BlendScreenf(s1.g, s2.g), + BlendScreenf(s1.b, s2.b), + BlendScreenf(s1.a, s2.a)); +} +void SGX_blend_screen(in vec3 s1, in vec3 s2, out vec3 oColor) +{ + oColor = vec3(BlendScreenf(s1.r, s2.r), + BlendScreenf(s1.g, s2.g), + BlendScreenf(s1.b, s2.b)); +} +void SGX_blend_screen(in float s1, in float s2, out float oColor) +{ + oColor = BlendScreenf(s1, s2); +} + + +void SGX_blend_overlay(in vec4 s1, in vec4 s2, out vec4 oColor) +{ + oColor = vec4(BlendOverlayf(s1.r, s2.r), + BlendOverlayf(s1.g, s2.g), + BlendOverlayf(s1.b, s2.b), + BlendOverlayf(s1.a, s2.a)); +} +void SGX_blend_overlay(in vec3 s1, in vec3 s2, out vec3 oColor) +{ + oColor = vec3(BlendOverlayf(s1.r, s2.r), + BlendOverlayf(s1.g, s2.g), + BlendOverlayf(s1.b, s2.b)); +} +void SGX_blend_overlay(in float s1, in float s2, out float oColor) +{ + oColor = BlendOverlayf(s1, s2); +} + + +void SGX_blend_softLight(in vec4 s1, in vec4 s2, out vec4 oColor) +{ + float r = BlendSoftLightf(s1.r, s2.r); + float g = BlendSoftLightf(s1.g, s2.g); + float b = BlendSoftLightf(s1.b, s2.b); + float a = BlendSoftLightf(s1.a, s2.a); + oColor = vec4(r,g,b,a); +} +void SGX_blend_softLight(in vec3 s1, in vec3 s2, out vec3 oColor) +{ + float r = BlendSoftLightf(s1.r, s2.r); + float g = BlendSoftLightf(s1.g, s2.g); + float b = BlendSoftLightf(s1.b, s2.b); + oColor = vec4(r,g,b); +} +void SGX_blend_softLight(in float s1, in float s2, out float oColor) +{ + oColor = BlendSoftLightf(s1, s2); +} + + +void SGX_blend_hardLight(in vec4 s1, in vec4 s2, out vec4 oColor) +{ + oColor = vec4(BlendOverlayf(s1.r, s2.r), + BlendOverlayf(s1.g, s2.g), + BlendOverlayf(s1.b, s2.b), + BlendOverlayf(s1.a, s2.a)); +} +void SGX_blend_hardLight(in vec3 s1, in vec3 s2, out vec3 oColor) +{ + oColor = vec3(BlendOverlayf(s1.r, s2.r), + BlendOverlayf(s1.g, s2.g), + BlendOverlayf(s1.b, s2.b)); +} +void SGX_blend_hardLight(in float s1, in float s2, out float oColor) +{ + oColor = BlendOverlayf(s1, s2); +} + + +void SGX_blend_colorDodge(in vec4 s1, in vec4 s2, out vec4 oColor) +{ + oColor = vec4(BlendColorDodgef(s1.r, s2.r), + BlendColorDodgef(s1.g, s2.g), + BlendColorDodgef(s1.b, s2.b), + BlendColorDodgef(s1.a, s2.a)); +} +void SGX_blend_colorDodge(in vec3 s1, in vec3 s2, out vec3 oColor) +{ + oColor = vec3(BlendColorDodgef(s1.r, s2.r), + BlendColorDodgef(s1.g, s2.g), + BlendColorDodgef(s1.b, s2.b)); +} +void SGX_blend_colorDodge(in float s1, in float s2, out float oColor) +{ + oColor = BlendColorDodgef(s1, s2); +} + + +void SGX_blend_colorBurn(in vec4 s1, in vec4 s2, out vec4 oColor) +{ + oColor = vec4(BlendColorBurnf(s1.r, s2.r), + BlendColorBurnf(s1.g, s2.g), + BlendColorBurnf(s1.b, s2.b), + BlendColorBurnf(s1.a, s2.a)); +} +void SGX_blend_colorBurn(in vec3 s1, in vec3 s2, out vec3 oColor) +{ + oColor = vec3(BlendColorBurnf(s1.r, s2.r), + BlendColorBurnf(s1.g, s2.g), + BlendColorBurnf(s1.b, s2.b)); +} +void SGX_blend_colorBurn(in float s1, in float s2, out float oColor) +{ + oColor = BlendColorBurnf(s1, s2); +} + + +void SGX_blend_linearDodge(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendAddf(basePixel, blendPixel); +} +void SGX_blend_linearDodge(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendAddf(basePixel, blendPixel); +} +void SGX_blend_linearDodge(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendAddf(basePixel, blendPixel); +} + + +void SGX_blend_linearBurn(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendSubtractf(basePixel, blendPixel); +} +void SGX_blend_linearBurn(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendSubtractf(basePixel, blendPixel); +} +void SGX_blend_linearBurn(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendSubtractf(basePixel, blendPixel); +} + + +void SGX_blend_linearLight(in vec4 s1, in vec4 s2, out vec4 oColor) +{ + oColor = vec4(BlendLinearLightf(s1.r, s2.r), + BlendLinearLightf(s1.g, s2.g), + BlendLinearLightf(s1.b, s2.b), + BlendLinearLightf(s1.a, s2.a)); +} +void SGX_blend_linearLight(in vec3 s1, in vec3 s2, out vec3 oColor) +{ + oColor = vec3(BlendLinearLightf(s1.r, s2.r), + BlendLinearLightf(s1.g, s2.g), + BlendLinearLightf(s1.b, s2.b)); +} +void SGX_blend_linearLight(in float s1, in float s2, out float oColor) +{ + oColor = BlendLinearLightf(s1, s2); +} + + +void SGX_blend_vividLight(in vec4 s1, in vec4 s2, out vec4 oColor) +{ + oColor = vec4(BlendVividLightf(s1.r, s2.r), + BlendVividLightf(s1.g, s2.g), + BlendVividLightf(s1.b, s2.b), + BlendVividLightf(s1.a, s2.a)); +} +void SGX_blend_vividLight(in vec3 s1, in vec3 s2, out vec3 oColor) +{ + oColor = vec3(BlendVividLightf(s1.r, s2.r), + BlendVividLightf(s1.g, s2.g), + BlendVividLightf(s1.b, s2.b)); +} +void SGX_blend_vividLight(in float s1, in float s2, out float oColor) +{ + oColor = BlendVividLightf(s1, s2); +} + + +void SGX_blend_pinLight(in vec4 s1, in vec4 s2, out vec4 oColor) +{ + oColor = vec4(BlendPinLightf(s1.r, s2.r), + BlendPinLightf(s1.g, s2.g), + BlendPinLightf(s1.b, s2.b), + BlendPinLightf(s1.a, s2.a)); +} +void SGX_blend_pinLight(in vec3 s1, in vec3 s2, out vec3 oColor) +{ + oColor = vec3(BlendPinLightf(s1.r, s2.r), + BlendPinLightf(s1.g, s2.g), + BlendPinLightf(s1.b, s2.b)); +} +void SGX_blend_pinLight(in float s1, in float s2, out float oColor) +{ + oColor = BlendPinLightf(s1, s2); +} + + +void SGX_blend_hardMix(in vec4 s1, in vec4 s2, out vec4 oColor) +{ + oColor = vec4(BlendHardMixf(s1.r, s2.r), + BlendHardMixf(s1.g, s2.g), + BlendHardMixf(s1.b, s2.b), + BlendHardMixf(s1.a, s2.a)); +} +void SGX_blend_hardMix(in vec3 s1, in vec3 s2, out vec3 oColor) +{ + oColor = vec3(BlendHardMixf(s1.r, s2.r), + BlendHardMixf(s1.g, s2.g), + BlendHardMixf(s1.b, s2.b)); +} +void SGX_blend_hardMix(in float s1, in float s2, out float oColor) +{ + oColor = BlendHardMixf(s1, s2); +} + +void SGX_blend_reflect(in vec4 s1, in vec4 s2, out vec4 oColor) +{ + oColor = vec4(BlendReflectf(s1.r, s2.r), + BlendReflectf(s1.g, s2.g), + BlendReflectf(s1.b, s2.b), + BlendReflectf(s1.a, s2.a)); +} +void SGX_blend_reflect(in vec3 s1, in vec3 s2, out vec3 oColor) +{ + oColor = vec3(BlendReflectf(s1.r, s2.r), + BlendReflectf(s1.g, s2.g), + BlendReflectf(s1.b, s2.b)); +} +void SGX_blend_reflect(in float s1, in float s2, out float oColor) +{ + oColor = BlendReflectf(s1, s2); +} + + +void SGX_blend_glow(in vec4 s1, in vec4 s2, out vec4 oColor) +{ + oColor = vec4(BlendReflectf(s1.r, s2.r), + BlendReflectf(s1.g, s2.g), + BlendReflectf(s1.b, s2.b), + BlendReflectf(s1.a, s2.a)); +} +void SGX_blend_glow(in vec3 s1, in vec3 s2, out vec3 oColor) +{ + oColor = vec3(BlendReflectf(s1.r, s2.r), + BlendReflectf(s1.g, s2.g), + BlendReflectf(s1.b, s2.b)); +} +void SGX_blend_glow(in float s1, in float s2, out float oColor) +{ + oColor = BlendReflectf(s1, s2); +} + + +void SGX_blend_phoenix(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendPhoenix(basePixel, blendPixel); +} +void SGX_blend_phoenix(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendPhoenix(basePixel, blendPixel); +} +void SGX_blend_phoenix(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendPhoenix(basePixel, blendPixel); +} + + +void SGX_blend_saturation(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendSaturation4(basePixel, blendPixel); +} +void SGX_blend_saturation(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendSaturation3(basePixel, blendPixel); +} +void SGX_blend_saturation(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendSaturation1(basePixel, blendPixel); +} + + +void SGX_blend_color(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendColor4(basePixel, blendPixel); +} +void SGX_blend_color(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendColor3(basePixel, blendPixel); +} +void SGX_blend_color(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendColor1(basePixel, blendPixel); +} + + +void SGX_blend_luminosity(in vec4 basePixel, in vec4 blendPixel, out vec4 oColor) +{ + oColor = BlendLuminosity4(basePixel, blendPixel); +} +void SGX_blend_luminosity(in vec3 basePixel, in vec3 blendPixel, out vec3 oColor) +{ + oColor = BlendLuminosity3(basePixel, blendPixel); +} +void SGX_blend_luminosity(in float basePixel, in float blendPixel, out float oColor) +{ + oColor = BlendLuminosity1(basePixel, blendPixel); +} + + +//////////////////////////////////////////////////////////////////////////////////// +/// Source modification functions +//////////////////////////////////////////////////////////////////////////////////// + + +void SGX_src_mod_modulate(in vec4 iColor, in vec4 controlVal, out vec4 oColor) +{ + oColor = iColor * controlVal; +} +void SGX_src_mod_modulate(in vec3 iColor, in vec3 controlVal, out vec3 oColor) +{ + oColor = iColor * controlVal; +} +void SGX_src_mod_modulate(in float iColor, in float controlVal, out float oColor) +{ + oColor = iColor * controlVal; +} + +void SGX_src_mod_inv_modulate(in vec4 iColor, in vec4 controlVal, out vec4 oColor) +{ + oColor = mix(iColor, vec4(1.0), controlVal); +} +void SGX_src_mod_inv_modulate(in vec3 iColor, in vec3 controlVal, out vec3 oColor) +{ + oColor = mix(iColor, vec3(1.0), controlVal); +} +void SGX_src_mod_inv_modulate(in float iColor, in float controlVal, out float oColor) +{ + oColor = mix(iColor, 1.0, controlVal); +} diff --git a/res/dist/media/RTShaderLib/SGXLib_LayeredBlending.hlsl b/res/dist/media/RTShaderLib/SGXLib_LayeredBlending.hlsl new file mode 100644 index 00000000000..4ba809e20bf --- /dev/null +++ b/res/dist/media/RTShaderLib/SGXLib_LayeredBlending.hlsl @@ -0,0 +1,730 @@ +/* +** layered blending & misc math +** Blending modes, RGB/HSL/Contrast/Desaturate +** +** The shaders below are base on the shaders created by: +** Romain Dura | Romz +** Blog: http://blog.mouaif.org +** Post: http://blog.mouaif.org/?p=94 +*/ + + +/* +** Desaturation +*/ + +float4 Desaturate(float3 color, float Desaturation) +{ + float3 grayXfer = float3(0.3, 0.59, 0.11); + float grayf = dot(grayXfer, color); + float3 gray = float3(grayf, grayf, grayf); + return float4(lerp(color, gray, Desaturation), 1.0); +} + + +/* +** Hue, saturation, luminance +*/ + +float3 RGBToHSL(float3 color) +{ + float3 hsl; // init to 0 to avoid warnings ? (and reverse if + remove first part) + + float fmin = min(min(color.r, color.g), color.b); //Min. value of RGB + float fmax = max(max(color.r, color.g), color.b); //Max. value of RGB + float delta = fmax - fmin; //Delta RGB value + + hsl.z = (fmax + fmin) / 2.0; // Luminance + + if (delta == 0.0) //This is a gray, no chroma... + { + hsl.x = 0.0; // Hue + hsl.y = 0.0; // Saturation + } + else //Chromatic data... + { + if (hsl.z < 0.5) + hsl.y = delta / (fmax + fmin); // Saturation + else + hsl.y = delta / (2.0 - fmax - fmin); // Saturation + + float deltaR = (((fmax - color.r) / 6.0) + (delta / 2.0)) / delta; + float deltaG = (((fmax - color.g) / 6.0) + (delta / 2.0)) / delta; + float deltaB = (((fmax - color.b) / 6.0) + (delta / 2.0)) / delta; + + if (color.r == fmax ) + hsl.x = deltaB - deltaG; // Hue + else if (color.g == fmax) + hsl.x = (1.0 / 3.0) + deltaR - deltaB; // Hue + else if (color.b == fmax) + hsl.x = (2.0 / 3.0) + deltaG - deltaR; // Hue + + if (hsl.x < 0.0) + hsl.x += 1.0; // Hue + else if (hsl.x > 1.0) + hsl.x -= 1.0; // Hue + } + + return hsl; +} + +float HueToRGB(float f1, float f2, float hue) +{ + if (hue < 0.0) + hue += 1.0; + else if (hue > 1.0) + hue -= 1.0; + float res; + if ((6.0 * hue) < 1.0) + res = f1 + (f2 - f1) * 6.0 * hue; + else if ((2.0 * hue) < 1.0) + res = f2; + else if ((3.0 * hue) < 2.0) + res = f1 + (f2 - f1) * ((2.0 / 3.0) - hue) * 6.0; + else + res = f1; + return res; +} + +float3 HSLToRGB(float3 hsl) +{ + float3 rgb; + + if (hsl.y == 0.0) + rgb = float3(hsl.z, hsl.z, hsl.z); // Luminance + else + { + float f2; + + if (hsl.z < 0.5) + f2 = hsl.z * (1.0 + hsl.y); + else + f2 = (hsl.z + hsl.y) - (hsl.y * hsl.z); + + float f1 = 2.0 * hsl.z - f2; + + rgb.r = HueToRGB(f1, f2, hsl.x + (1.0/3.0)); + rgb.g = HueToRGB(f1, f2, hsl.x); + rgb.b= HueToRGB(f1, f2, hsl.x - (1.0/3.0)); + } + + return rgb; +} + +/* +** Contrast, saturation, brightness +** Code of this function is from TGM's shader pack +** http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=21057 +*/ + +// For all settings: 1.0 = 100% 0.5=50% 1.5 = 150% +float3 ContrastSaturationBrightness(float3 color, float brt, float sat, float con) +{ + // Increase or decrease these values to adjust r, g and b color channels separately + const float AvgLumR = 0.5; + const float AvgLumG = 0.5; + const float AvgLumB = 0.5; + + const float3 LumCoeff = float3(0.2125, 0.7154, 0.0721); + + float3 AvgLumin = float3(AvgLumR, AvgLumG, AvgLumB); + float3 brtColor = color * brt; + float intensityf = dot(brtColor, LumCoeff); + float3 intensity = float3(intensityf, intensityf, intensityf); + float3 satColor = lerp(intensity, brtColor, sat); + float3 conColor = lerp(AvgLumin, satColor, con); + return conColor; +} + +/* +** Float blending modes +** Adapted from here: http://www.nathanm.com/photoshop-blending-math/ +** But I modified the HardMix (wrong condition), Overlay, SoftLight, ColorDodge, ColorBurn, VividLight, PinLight (inverted layers) ones to have correct results +*/ + +#define BlendLinearDodgef BlendAddf +#define BlendLinearBurnf BlendSubtractf +#define BlendAddf(base, blend) min(base + blend, 1.0) +#define BlendSubtractf(base, blend) max(base + blend - 1.0, 0.0) +#define BlendLightenf(base, blend) max(blend, base) +#define BlendDarkenf(base, blend) min(blend, base) +#define BlendLinearLightf(base, blend) (blend < 0.5 ? BlendLinearBurnf(base, (2.0 * blend)) : BlendLinearDodgef(base, (2.0 * (blend - 0.5)))) +#define BlendScreenf(base, blend) (1.0 - ((1.0 - base) * (1.0 - blend))) +#define BlendOverlayf(base, blend) (base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend))) +#define BlendSoftLightf(base, blend) ((blend < 0.5) ? (2.0 * base * blend + base * base * (1.0 - 2.0 * blend)) : (sqrt(base) * (2.0 * blend - 1.0) + 2.0 * base * (1.0 - blend))) +#define BlendColorDodgef(base, blend) ((blend == 1.0) ? blend : min(base / (1.0 - blend), 1.0)) +#define BlendColorBurnf(base, blend) ((blend == 0.0) ? blend : max((1.0 - ((1.0 - base) / blend)), 0.0)) +#define BlendVividLightf(base, blend) ((blend < 0.5) ? BlendColorBurnf(base, (2.0 * blend)) : BlendColorDodgef(base, (2.0 * (blend - 0.5)))) +#define BlendPinLightf(base, blend) ((blend < 0.5) ? BlendDarkenf(base, (2.0 * blend)) : BlendLightenf(base, (2.0 *(blend - 0.5)))) +#define BlendHardMixf(base, blend) ((BlendVividLightf(base, blend) < 0.5) ? 0.0 : 1.0) +#define BlendReflectf(base, blend) ((blend == 1.0) ? blend : min(base * base / (1.0 - blend), 1.0)) + + + +/* +** Vector3 blending modes +*/ + +// Component wise blending +#define Blend1(base, blend, funcf) funcf(base, blend) +#define Blend3(base, blend, funcf) float3(funcf(base.r, blend.r), funcf(base.g, blend.g), funcf(base.b, blend.b)) +#define Blend4(base, blend, funcf) float4(funcf(base.r, blend.r), funcf(base.g, blend.g), funcf(base.b, blend.b), funcf(base.a, blend.a)) + +#define BlendNormal(base, blend) (base) +#define BlendLighten BlendLightenf +#define BlendDarken BlendDarkenf +#define BlendMultiply(base, blend) (base * blend) +#define BlendAverage(base, blend) ((base + blend) / 2.0) +#define BlendAdd(base, blend) min(base + blend, 1.0) +#define BlendSubtract(base, blend) max(base + blend - 1.0, 0.0) +#define BlendDifference(base, blend) abs(base - blend) +#define BlendNegation(base, blend) (1.0 - abs(1.0 - base - blend)) +#define BlendExclusion(base, blend) (base + blend - 2.0 * base * blend) + +#define BlendScreen1(base, blend) Blend1(base, blend, BlendScreenf) +#define BlendOverlay1(base, blend) Blend1(base, blend, BlendOverlayf) +#define BlendSoftLight1(base, blend) Blend1(base, blend, BlendSoftLightf) +#define BlendHardLight1(base, blend) BlendOverlay1(blend, base) +#define BlendColorDodge1(base, blend) Blend1(base, blend, BlendColorDodgef) +#define BlendColorBurn1(base, blend) Blend1(base, blend, BlendColorBurnf) +// Linear Light is another contrast-increasing mode +// If the blend color is darker than midgray, Linear Light darkens the image by decreasing the brightness. If the blend color is lighter than midgray, the result is a brighter image due to increased brightness. +#define BlendLinearLight1(base, blend) Blend1(base, blend, BlendLinearLightf) +#define BlendVividLight1(base, blend) Blend1(base, blend, BlendVividLightf) +#define BlendPinLight1(base, blend) Blend1(base, blend, BlendPinLightf) +#define BlendHardMix1(base, blend) Blend1(base, blend, BlendHardMixf) +#define BlendReflect1(base, blend) Blend1(base, blend, BlendReflectf) +#define BlendGlow1(base, blend) BlendReflect1(blend, base) + + +#define BlendScreen3(base, blend) Blend3(base, blend, BlendScreenf) +#define BlendOverlay3(base, blend) Blend3(base, blend, BlendOverlayf) +#define BlendSoftLight3(base, blend) Blend3(base, blend, BlendSoftLightf) +#define BlendHardLight3(base, blend) BlendOverlay3(blend, base) +#define BlendColorDodge3(base, blend) Blend3(base, blend, BlendColorDodgef) +#define BlendColorBurn3(base, blend) Blend3(base, blend, BlendColorBurnf) +// Linear Light is another contrast-increasing mode +// If the blend color is darker than midgray, Linear Light darkens the image by decreasing the brightness. If the blend color is lighter than midgray, the result is a brighter image due to increased brightness. +#define BlendLinearLight3(base, blend) Blend3(base, blend, BlendLinearLightf) +#define BlendVividLight3(base, blend) Blend3(base, blend, BlendVividLightf) +#define BlendPinLight3(base, blend) Blend3(base, blend, BlendPinLightf) +#define BlendHardMix3(base, blend) Blend3(base, blend, BlendHardMixf) +#define BlendReflect3(base, blend) Blend3(base, blend, BlendReflectf) +#define BlendGlow3(base, blend) BlendReflect3(blend, base) + + +#define BlendScreen4(base, blend) Blend4(base, blend, BlendScreenf) +#define BlendOverlay4(base, blend) Blend4(base, blend, BlendOverlayf) +#define BlendSoftLight4(base, blend) Blend4(base, blend, BlendSoftLightf) +#define BlendHardLight4(base, blend) BlendOverlay4(blend, base) +#define BlendColorDodge4(base, blend) Blend4(base, blend, BlendColorDodgef) +#define BlendColorBurn4(base, blend) Blend4(base, blend, BlendColorBurnf) +// Linear Light is another contrast-increasing mode +// If the blend color is darker than midgray, Linear Light darkens the image by decreasing the brightness. If the blend color is lighter than midgray, the result is a brighter image due to increased brightness. +#define BlendLinearLight4(base, blend) Blend4(base, blend, BlendLinearLightf) +#define BlendVividLight4(base, blend) Blend4(base, blend, BlendVividLightf) +#define BlendPinLight4(base, blend) Blend4(base, blend, BlendPinLightf) +#define BlendHardMix4(base, blend) Blend4(base, blend, BlendHardMixf) +#define BlendReflect4(base, blend) Blend4(base, blend, BlendReflectf) +#define BlendGlow4(base, blend) BlendReflect4(blend, base) + + +#define BlendLinearDodge BlendAdd +#define BlendLinearBurn BlendSubtract + +#define BlendPhoenix(base, blend) (min(base, blend) - max(base, blend) + 1.0) + + +#define BlendOpacity(base, blend, F, O) (F(base, blend) * O + blend * (1.0 - O)) + +// Hue Blend mode creates the result color by combining the luminance and saturation of the base color with the hue of the blend color. +float BlendHue1(float base, float blend) +{ + return base; +} +float3 BlendHue3(float3 base, float3 blend) +{ + float3 baseHSL = RGBToHSL(base); + return HSLToRGB(float3(RGBToHSL(blend).r, baseHSL.g, baseHSL.b)); +} +float4 BlendHue4(float4 base, float4 blend) +{ + float3 hue = BlendHue3(base.xyz, blend.xyz); + return float4(hue.x, hue.y, hue.z, BlendHue1(base.w, blend.w)); +} + +// Saturation Blend mode creates the result color by combining the luminance and hue of the base color with the saturation of the blend color. +float BlendSaturation1(float base, float blend) +{ + return base; +} +float3 BlendSaturation3(float3 base, float3 blend) +{ + float3 baseHSL = RGBToHSL(base); + return HSLToRGB(float3(baseHSL.r, RGBToHSL(blend).g, baseHSL.b)); +} +float4 BlendSaturation4(float4 base, float4 blend) +{ + float3 hue = BlendSaturation3(base.xyz, blend.xyz); + return float4(hue.x, hue.y, hue.z, BlendSaturation1(base.w, blend.w)); +} + +// Color Mode keeps the brightness of the base color and applies both the hue and saturation of the blend color. +float BlendColor1(float base, float blend) +{ + return base; +} +float3 BlendColor3(float3 base, float3 blend) +{ + float3 blendHSL = RGBToHSL(blend); + return HSLToRGB(float3(blendHSL.r, blendHSL.g, RGBToHSL(base).b)); +} +float4 BlendColor4(float4 base, float4 blend) +{ + float3 hue = BlendColor3(base.xyz, blend.xyz); + return float4(hue.x, hue.y, hue.z, BlendColor1(base.w, blend.w)); +} + + + +// Luminosity Blend mode creates the result color by combining the hue and saturation of the base color with the luminance of the blend color. +float BlendLuminosity1(float base, float blend) +{ + return base; +} +float3 BlendLuminosity3(float3 base, float3 blend) +{ + float3 baseHSL = RGBToHSL(base); + return HSLToRGB(float3(baseHSL.r, baseHSL.g, RGBToHSL(blend).b)); +} +float4 BlendLuminosity4(float4 base, float4 blend) +{ + float3 hue = BlendLuminosity3(base.xyz, blend.xyz); + return float4(hue.x, hue.y, hue.z, BlendLuminosity1(base.w, blend.w)); +} + +//------------------------------------ +// Interface for RTShader +//------------------------------------ + +void SGX_blend_normal(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendNormal(basePixel, blendPixel); +} +void SGX_blend_normal(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendNormal(basePixel, blendPixel); +} +void SGX_blend_normal(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendNormal(basePixel, blendPixel); +} + + +void SGX_blend_lighten(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendLighten(basePixel, blendPixel); +} +void SGX_blend_lighten(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendLighten(basePixel, blendPixel); +} +void SGX_blend_lighten(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendLighten(basePixel, blendPixel); +} + +void SGX_blend_darken(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendDarken(basePixel, blendPixel); +} +void SGX_blend_darken(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendDarken(basePixel, blendPixel); +} +void SGX_blend_darken(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendDarken(basePixel, blendPixel); +} + + +void SGX_blend_multiply(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendMultiply(basePixel, blendPixel); +} +void SGX_blend_multiply(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendMultiply(basePixel, blendPixel); +} +void SGX_blend_multiply(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendMultiply(basePixel, blendPixel); +} + + +void SGX_blend_average(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendAverage(basePixel, blendPixel); +} +void SGX_blend_average(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendAverage(basePixel, blendPixel); +} +void SGX_blend_average(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendAverage(basePixel, blendPixel); +} + + +void SGX_blend_add(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendAdd(basePixel, blendPixel); +} +void SGX_blend_add(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendAdd(basePixel, blendPixel); +} +void SGX_blend_add(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendAdd(basePixel, blendPixel); +} + + +void SGX_blend_subtract(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendSubtract(basePixel, blendPixel); +} +void SGX_blend_subtract(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendSubtract(basePixel, blendPixel); +} +void SGX_blend_subtract(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendSubtract(basePixel, blendPixel); +} + + +void SGX_blend_difference(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendDifference(basePixel, blendPixel); +} +void SGX_blend_difference(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendDifference(basePixel, blendPixel); +} +void SGX_blend_difference(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendDifference(basePixel, blendPixel); +} + + +void SGX_blend_negation(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendNegation(basePixel, blendPixel); +} +void SGX_blend_negation(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendNegation(basePixel, blendPixel); +} +void SGX_blend_negation(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendNegation(basePixel, blendPixel); +} + + +void SGX_blend_exclusion(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendExclusion(basePixel, blendPixel); +} +void SGX_blend_exclusion(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendExclusion(basePixel, blendPixel); +} +void SGX_blend_exclusion(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendExclusion(basePixel, blendPixel); +} + + +void SGX_blend_screen(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = Blend4(basePixel, blendPixel, BlendScreenf); +} +void SGX_blend_screen(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = Blend3(basePixel, blendPixel, BlendScreenf); +} +void SGX_blend_screen(float basePixel, float blendPixel, out float oColor) +{ + oColor = Blend1(basePixel, blendPixel, BlendScreenf); +} + +void SGX_blend_overlay(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = Blend4(basePixel, blendPixel, BlendOverlayf); +} +void SGX_blend_overlay(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = Blend3(basePixel, blendPixel, BlendOverlayf); +} +void SGX_blend_overlay(float basePixel, float blendPixel, out float oColor) +{ + oColor = Blend1(basePixel, blendPixel, BlendOverlayf); +} + +void SGX_blend_softLight(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = Blend4(basePixel, blendPixel, BlendSoftLightf); +} +void SGX_blend_softLight(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = Blend3(basePixel, blendPixel, BlendSoftLightf); +} +void SGX_blend_softLight(float basePixel, float blendPixel, out float oColor) +{ + oColor = Blend1(basePixel, blendPixel, BlendSoftLightf); +} + + +void SGX_blend_hardLight(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = Blend4(basePixel, blendPixel, BlendOverlayf); +} +void SGX_blend_hardLight(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = Blend3(basePixel, blendPixel, BlendOverlayf); +} +void SGX_blend_hardLight(float basePixel, float blendPixel, out float oColor) +{ + oColor = Blend1(basePixel, blendPixel, BlendOverlayf); +} + + +void SGX_blend_colorDodge(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = Blend4(basePixel, blendPixel, BlendColorDodgef); +} +void SGX_blend_colorDodge(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = Blend3(basePixel, blendPixel, BlendColorDodgef); +} +void SGX_blend_colorDodge(float basePixel, float blendPixel, out float oColor) +{ + oColor = Blend1(basePixel, blendPixel, BlendColorDodgef); +} + + +void SGX_blend_colorBurn(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = Blend4(basePixel, blendPixel, BlendColorBurnf); +} +void SGX_blend_colorBurn(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = Blend3(basePixel, blendPixel, BlendColorBurnf); +} +void SGX_blend_colorBurn(float basePixel, float blendPixel, out float oColor) +{ + oColor = Blend1(basePixel, blendPixel, BlendColorBurnf); +} + + +void SGX_blend_linearDodge(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendLinearDodge(basePixel, blendPixel); +} +void SGX_blend_linearDodge(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendLinearDodge(basePixel, blendPixel); +} +void SGX_blend_linearDodge(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendLinearDodge(basePixel, blendPixel); +} + + +void SGX_blend_linearBurn(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendLinearBurn(basePixel, blendPixel); +} +void SGX_blend_linearBurn(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendLinearBurn(basePixel, blendPixel); +} +void SGX_blend_linearBurn(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendLinearBurn(basePixel, blendPixel); +} + + +void SGX_blend_linearLight(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = Blend4(basePixel, blendPixel, BlendLinearLightf); +} +void SGX_blend_linearLight(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = Blend3(basePixel, blendPixel, BlendLinearLightf); +} +void SGX_blend_linearLight(float basePixel, float blendPixel, out float oColor) +{ + oColor = Blend1(basePixel, blendPixel, BlendLinearLightf); +} + + +void SGX_blend_vividLight(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = Blend4(basePixel, blendPixel, BlendVividLightf); +} +void SGX_blend_vividLight(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = Blend3(basePixel, blendPixel, BlendVividLightf); +} +void SGX_blend_vividLight(float basePixel, float blendPixel, out float oColor) +{ + oColor = Blend1(basePixel, blendPixel, BlendVividLightf); +} + + +void SGX_blend_pinLight(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = Blend4(basePixel, blendPixel, BlendPinLightf); +} +void SGX_blend_pinLight(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = Blend3(basePixel, blendPixel, BlendPinLightf); +} +void SGX_blend_pinLight(float basePixel, float blendPixel, out float oColor) +{ + oColor = Blend1(basePixel, blendPixel, BlendPinLightf); +} + + +void SGX_blend_hardMix(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = Blend4(basePixel, blendPixel, BlendHardMixf); +} +void SGX_blend_hardMix(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = Blend3(basePixel, blendPixel, BlendHardMixf); +} +void SGX_blend_hardMix(float basePixel, float blendPixel, out float oColor) +{ + oColor = Blend1(basePixel, blendPixel, BlendHardMixf); +} + + +void SGX_blend_reflect(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = Blend4(basePixel, blendPixel, BlendReflectf); +} +void SGX_blend_reflect(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = Blend3(basePixel, blendPixel, BlendReflectf); +} +void SGX_blend_reflect(float basePixel, float blendPixel, out float oColor) +{ + oColor = Blend1(basePixel, blendPixel, BlendReflectf); +} + +void SGX_blend_glow(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = Blend4(basePixel, blendPixel, BlendReflectf); +} +void SGX_blend_glow(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = Blend3(basePixel, blendPixel, BlendReflectf); +} +void SGX_blend_glow(float basePixel, float blendPixel, out float oColor) +{ + oColor = Blend1(basePixel, blendPixel, BlendReflectf); +} + + +void SGX_blend_phoenix(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendPhoenix(basePixel, blendPixel); +} +void SGX_blend_phoenix(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendPhoenix(basePixel, blendPixel); +} +void SGX_blend_phoenix(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendPhoenix(basePixel, blendPixel); +} + + +void SGX_blend_saturation(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendSaturation4(basePixel, blendPixel); +} +void SGX_blend_saturation(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendSaturation3(basePixel, blendPixel); +} +void SGX_blend_saturation(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendSaturation1(basePixel, blendPixel); +} + + +void SGX_blend_color(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendColor4(basePixel, blendPixel); +} +void SGX_blend_color(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendColor3(basePixel, blendPixel); +} +void SGX_blend_color(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendColor1(basePixel, blendPixel); +} + + +void SGX_blend_luminosity(float4 basePixel, float4 blendPixel, out float4 oColor) +{ + oColor = BlendLuminosity4(basePixel, blendPixel); +} +void SGX_blend_luminosity(float3 basePixel, float3 blendPixel, out float3 oColor) +{ + oColor = BlendLuminosity3(basePixel, blendPixel); +} +void SGX_blend_luminosity(float basePixel, float blendPixel, out float oColor) +{ + oColor = BlendLuminosity1(basePixel, blendPixel); +} + + +//////////////////////////////////////////////////////////////////////////////////// +/// Source modification functions +//////////////////////////////////////////////////////////////////////////////////// + + +void SGX_src_mod_modulate(float4 iColor, float4 controlVal, out float4 oColor) +{ + oColor = iColor * controlVal; +} +void SGX_src_mod_modulate(float3 iColor, float3 controlVal, out float3 oColor) +{ + oColor = iColor * controlVal; +} +void SGX_src_mod_modulate(float iColor, float controlVal, out float oColor) +{ + oColor = iColor * controlVal; +} + +void SGX_src_mod_inv_modulate(float4 iColor, float4 controlVal, out float4 oColor) +{ + oColor = lerp(iColor, 1, controlVal); +} +void SGX_src_mod_inv_modulate(float3 iColor, float3 controlVal, out float3 oColor) +{ + oColor = lerp(iColor, 1, controlVal); +} +void SGX_src_mod_inv_modulate(float iColor, float controlVal, out float oColor) +{ + oColor = lerp(iColor, 1, controlVal); +} + + + diff --git a/res/dist/media/RTShaderLib/SGXLib_NormalMapLighting.cg b/res/dist/media/RTShaderLib/SGXLib_NormalMapLighting.cg new file mode 100644 index 00000000000..53a069f15a8 --- /dev/null +++ b/res/dist/media/RTShaderLib/SGXLib_NormalMapLighting.cg @@ -0,0 +1,257 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Program Name: SGXLib_NormalMapLighting +// Program Desc: Normal map lighting functions. +// Program Type: Vertex/Pixel shader +// Language: CG +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +void SGX_ConstructTBNMatrix(in float3 vNormal, + in float3 vTangent, + out float3x3 vOut) +{ + float3 vBinormal = cross(vTangent, vNormal); + + vOut = float3x3(vTangent, vBinormal, vNormal); +} + +//----------------------------------------------------------------------------- +void SGX_TransformNormal(in float3x3 m, + in float3 v, + out float3 vOut) +{ + vOut = mul(m, v); +} + +//----------------------------------------------------------------------------- +void SGX_TransformNormal(in float4x4 m, + in float3 v, + out float3 vOut) +{ + vOut = mul((float3x3)m, v); +} + +//----------------------------------------------------------------------------- +void SGX_TransformPosition(in float4x4 m, + in float4 v, + out float3 vOut) +{ + vOut = mul(m, v).xyz; +} + +//----------------------------------------------------------------------------- +void SGX_FetchNormal(in sampler2D s, + in float2 uv, + out float3 vOut) +{ + vOut = 2 * tex2D(s, uv).xyz - 1; +} + +//----------------------------------------------------------------------------- +void SGX_Generate_Parallax_Texcoord(in sampler2D normalHeightMap, + in float2 texCoord, + in float3 eyeVec, + in float2 scaleBias, + out float2 newTexCoord) +{ + eyeVec = normalize(eyeVec); + float height = tex2D(normalHeightMap, texCoord).a; + float displacement = (height * scaleBias.x) + scaleBias.y; + float3 scaledEyeDir = eyeVec * displacement; + newTexCoord = (scaledEyeDir + float3(texCoord, 1.0)).xy; +} + +//----------------------------------------------------------------------------- +void SGX_Light_Directional_Diffuse( + in float3 vTSNormal, + in float3 vTSNegLightDir, + in float3 vDiffuseColour, + in float3 vBaseColour, + out float3 vOut) +{ + float3 vTSNegLightDirNorm = normalize(vTSNegLightDir); + float nDotL = dot(vTSNormal, vTSNegLightDirNorm); + + vOut = vBaseColour + vDiffuseColour * saturate(nDotL); +} + +//----------------------------------------------------------------------------- +void SGX_Light_Directional_DiffuseSpecular( + in float3 vTSNormal, + in float3 vTSView, + in float3 vTSNegLightDir, + in float3 vDiffuseColour, + in float3 vSpecularColour, + in float fSpecularPower, + in float3 vBaseDiffuseColour, + in float3 vBaseSpecularColour, + out float3 vOutDiffuse, + out float3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + float3 vTSNegLightDirNorm = normalize(vTSNegLightDir); + float nDotL = dot(vTSNormal, vTSNegLightDirNorm); + float3 vTSViewNorm = normalize(vTSView); + float3 vHalfWay = normalize(vTSView + vTSNegLightDir); + float nDotH = dot(vTSNormal, vHalfWay); + + if (nDotL > 0) + { + vOutDiffuse += vDiffuseColour * nDotL; + vOutSpecular += vSpecularColour * pow(saturate(nDotH), fSpecularPower); + } +} + +//----------------------------------------------------------------------------- +void SGX_Light_Point_Diffuse( + in float3 vTSNormal, + in float3 vTSToLight, + in float4 vAttParams, + in float3 vDiffuseColour, + in float3 vBaseColour, + out float3 vOut) +{ + vOut = vBaseColour; + + float fLightD = length(vTSToLight); + float nDotL = dot(vTSNormal, normalize(vTSToLight)); + + if (nDotL > 0 && fLightD <= vAttParams.x) + { + float fAtten = 1 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + + vOut += vDiffuseColour * nDotL * fAtten; + } +} + + + +//----------------------------------------------------------------------------- +void SGX_Light_Point_DiffuseSpecular( + in float3 vTSNormal, + in float3 vTSView, + in float3 vTSToLight, + in float4 vAttParams, + in float3 vDiffuseColour, + in float3 vSpecularColour, + in float fSpecularPower, + in float3 vBaseDiffuseColour, + in float3 vBaseSpecularColour, + out float3 vOutDiffuse, + out float3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + float fLightD = length(vTSToLight); + float3 vTSNegLightDirNorm = normalize(vTSToLight); + float nDotL = dot(vTSNormal, vTSNegLightDirNorm); + + if (nDotL > 0 && fLightD <= vAttParams.x) + { + float3 vTSViewNorm = normalize(vTSView); + float3 vHalfWay = normalize(vTSViewNorm + vTSNegLightDirNorm); + float nDotH = dot(vTSNormal, vHalfWay); + float fAtten = 1 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + + vOutDiffuse += vDiffuseColour * nDotL * fAtten; + vOutSpecular += vSpecularColour * pow(saturate(nDotH), fSpecularPower) * fAtten; + } +} + +//----------------------------------------------------------------------------- +void SGX_Light_Spot_Diffuse( + in float3 vTSNormal, + in float3 vTSToLight, + in float3 vTSNegLightDir, + in float4 vAttParams, + in float3 vSpotParams, + in float3 vDiffuseColour, + in float3 vBaseColour, + out float3 vOut) +{ + vOut = vBaseColour; + + float fLightD = length(vTSToLight); + float3 vTSToLightNorm = normalize(vTSToLight); + float nDotL = dot(vTSNormal, vTSToLightNorm); + + if (nDotL > 0 && fLightD <= vAttParams.x) + { + float3 vTSNegLightDirNorm = normalize(vTSNegLightDir); + float fAtten = 1 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + float rho = dot(vTSNegLightDirNorm, vTSToLightNorm); + float fSpotE = saturate((rho - vSpotParams.y) / (vSpotParams.x - vSpotParams.y)); + float fSpotT = pow(fSpotE, vSpotParams.z); + + vOut += vDiffuseColour * nDotL * fAtten * fSpotT; + } +} + +//----------------------------------------------------------------------------- +void SGX_Light_Spot_DiffuseSpecular( + in float3 vTSNormal, + in float3 vTSView, + in float3 vTSToLight, + in float3 vTSNegLightDir, + in float4 vAttParams, + in float3 vSpotParams, + in float3 vDiffuseColour, + in float3 vSpecularColour, + in float fSpecularPower, + in float3 vBaseDiffuseColour, + in float3 vBaseSpecularColour, + out float3 vOutDiffuse, + out float3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + float fLightD = length(vTSToLight); + float3 vTSToLightNorm = normalize(vTSToLight); + float nDotL = dot(vTSNormal, vTSToLightNorm); + + if (nDotL > 0 && fLightD <= vAttParams.x) + { + float3 vTSNegLightDirNorm = normalize(vTSNegLightDir); + float3 vTSViewNorm = normalize(vTSView); + float3 vHalfWay = normalize(vTSViewNorm + vTSNegLightDirNorm); + float nDotH = dot(vTSNormal, vHalfWay); + float fAtten = 1 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + float rho = dot(vTSNegLightDirNorm, vTSToLightNorm); + float fSpotE = saturate((rho - vSpotParams.y) / (vSpotParams.x - vSpotParams.y)); + float fSpotT = pow(fSpotE, vSpotParams.z); + + vOutDiffuse += vDiffuseColour * nDotL * fAtten * fSpotT; + vOutSpecular += vSpecularColour * pow(saturate(nDotH), fSpecularPower) * fAtten * fSpotT; + } +} diff --git a/res/dist/media/RTShaderLib/SGXLib_NormalMapLighting.glsl b/res/dist/media/RTShaderLib/SGXLib_NormalMapLighting.glsl new file mode 100644 index 00000000000..847b469ff3c --- /dev/null +++ b/res/dist/media/RTShaderLib/SGXLib_NormalMapLighting.glsl @@ -0,0 +1,269 @@ +#version 120 +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Program Name: SGXLib_NormalMapLighting +// Program Desc: Normal map lighting functions. +// Program Type: Vertex/Pixel shader +// Language: GLSL +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +void SGX_ConstructTBNMatrix(in vec3 vNormal, + in vec3 vTangent, + out mat3 vOut) +{ + vec3 vBinormal = cross(vTangent, vNormal); + + vOut[0][0] = vTangent.x; + vOut[1][0] = vTangent.y; + vOut[2][0] = vTangent.z; + + vOut[0][1] = vBinormal.x; + vOut[1][1] = vBinormal.y; + vOut[2][1] = vBinormal.z; + + vOut[0][2] = vNormal.x; + vOut[1][2] = vNormal.y; + vOut[2][2] = vNormal.z; +} + +//----------------------------------------------------------------------------- +void SGX_TransformNormal(in mat3 m, + in vec3 v, + out vec3 vOut) +{ + vOut = (m * v) ; +} + +//----------------------------------------------------------------------------- +void SGX_TransformNormal(in mat4 m, + in vec3 v, + out vec3 vOut) +{ + vOut = (m * vec4(v, 1.0)).xyz ; +} + +//----------------------------------------------------------------------------- +void SGX_TransformPosition(in mat4 m, + in vec4 v, + out vec3 vOut) +{ + vOut = (m * v).xyz; +} + +//----------------------------------------------------------------------------- +void SGX_FetchNormal(in sampler2D s, + in vec2 uv, + out vec3 vOut) +{ + vOut = 2.0 * texture2D(s, uv).xyz - 1.0; +} + +//----------------------------------------------------------------------------- +void SGX_Light_Directional_Diffuse( + in vec3 vTSNormal, + in vec3 vTSNegLightDir, + in vec3 vDiffuseColour, + in vec3 vBaseColour, + out vec3 vOut) +{ + vec3 vTSNegLightDirNorm = normalize(vTSNegLightDir); + float nDotL = dot(vTSNormal, vTSNegLightDirNorm); + + vOut = vBaseColour + vDiffuseColour * clamp(nDotL, 0.0, 1.0); +} + +//----------------------------------------------------------------------------- +void SGX_Generate_Parallax_Texcoord(in sampler2D normalHeightMap, + in vec2 texCoord, + in vec3 eyeVec, + in vec2 scaleBias, + out vec2 newTexCoord) +{ + eyeVec = normalize(eyeVec); + float height = texture2D(normalHeightMap, texCoord).a; + float displacement = (height * scaleBias.x) + scaleBias.y; + vec3 scaledEyeDir = eyeVec * displacement; + newTexCoord = (scaledEyeDir + vec3(texCoord, 1.0)).xy; +} + +//----------------------------------------------------------------------------- +void SGX_Light_Directional_DiffuseSpecular( + in vec3 vTSNormal, + in vec3 vTSView, + in vec3 vTSNegLightDir, + in vec3 vDiffuseColour, + in vec3 vSpecularColour, + in float fSpecularPower, + in vec3 vBaseDiffuseColour, + in vec3 vBaseSpecularColour, + out vec3 vOutDiffuse, + out vec3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + vec3 vTSNegLightDirNorm = normalize(vTSNegLightDir); + float nDotL = dot(vTSNormal, vTSNegLightDirNorm); + vec3 vTSViewNorm = normalize(vTSView); + vec3 vHalfWay = normalize(vTSView + vTSNegLightDir); + float nDotH = dot(vTSNormal, vHalfWay); + + if (nDotL > 0.0) + { + vOutDiffuse += vDiffuseColour * nDotL; + vOutSpecular += vSpecularColour * pow(clamp(nDotH, 0.0, 1.0), fSpecularPower); + } +} + +//----------------------------------------------------------------------------- +void SGX_Light_Point_Diffuse( + in vec3 vTSNormal, + in vec3 vTSToLight, + in vec4 vAttParams, + in vec3 vDiffuseColour, + in vec3 vBaseColour, + out vec3 vOut) +{ + vOut = vBaseColour; + + float fLightD = length(vTSToLight); + float nDotL = dot(vTSNormal, normalize(vTSToLight)); + + if (nDotL > 0.0 && fLightD <= vAttParams.x) + { + float fAtten = 1.0 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + + vOut += vDiffuseColour * nDotL * fAtten; + } +} + + + +//----------------------------------------------------------------------------- +void SGX_Light_Point_DiffuseSpecular( + in vec3 vTSNormal, + in vec3 vTSView, + in vec3 vTSToLight, + in vec4 vAttParams, + in vec3 vDiffuseColour, + in vec3 vSpecularColour, + in float fSpecularPower, + in vec3 vBaseDiffuseColour, + in vec3 vBaseSpecularColour, + out vec3 vOutDiffuse, + out vec3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + float fLightD = length(vTSToLight); + vec3 vTSNegLightDirNorm = normalize(vTSToLight); + float nDotL = dot(vTSNormal, vTSNegLightDirNorm); + + if (nDotL > 0.0 && fLightD <= vAttParams.x) + { + vec3 vTSViewNorm = normalize(vTSView); + vec3 vHalfWay = normalize(vTSViewNorm + vTSNegLightDirNorm); + float nDotH = dot(vTSNormal, vHalfWay); + float fAtten = 1.0 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + + vOutDiffuse += vDiffuseColour * nDotL * fAtten; + vOutSpecular += vSpecularColour * pow(clamp(nDotH, 0.0, 1.0), fSpecularPower) * fAtten; + } +} + +//----------------------------------------------------------------------------- +void SGX_Light_Spot_Diffuse( + in vec3 vTSNormal, + in vec3 vTSToLight, + in vec3 vTSNegLightDir, + in vec4 vAttParams, + in vec3 vSpotParams, + in vec3 vDiffuseColour, + in vec3 vBaseColour, + out vec3 vOut) +{ + vOut = vBaseColour; + + float fLightD = length(vTSToLight); + vec3 vTSToLightNorm = normalize(vTSToLight); + float nDotL = dot(vTSNormal, vTSToLightNorm); + + if (nDotL > 0.0 && fLightD <= vAttParams.x) + { + vec3 vTSNegLightDirNorm = normalize(vTSNegLightDir); + float fAtten = 1.0 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + float rho = dot(vTSNegLightDirNorm, vTSToLightNorm); + float fSpotE = clamp((rho - vSpotParams.y) / (vSpotParams.x - vSpotParams.y), 0.0, 1.0); + float fSpotT = pow(fSpotE, vSpotParams.z); + + vOut += vDiffuseColour * nDotL * fAtten * fSpotT; + } +} + +//----------------------------------------------------------------------------- +void SGX_Light_Spot_DiffuseSpecular( + in vec3 vTSNormal, + in vec3 vTSView, + in vec3 vTSToLight, + in vec3 vTSNegLightDir, + in vec4 vAttParams, + in vec3 vSpotParams, + in vec3 vDiffuseColour, + in vec3 vSpecularColour, + in float fSpecularPower, + in vec3 vBaseDiffuseColour, + in vec3 vBaseSpecularColour, + out vec3 vOutDiffuse, + out vec3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + float fLightD = length(vTSToLight); + vec3 vTSToLightNorm = normalize(vTSToLight); + float nDotL = dot(vTSNormal, vTSToLightNorm); + + if (nDotL > 0.0 && fLightD <= vAttParams.x) + { + vec3 vTSNegLightDirNorm = normalize(vTSNegLightDir); + vec3 vTSViewNorm = normalize(vTSView); + vec3 vHalfWay = normalize(vTSViewNorm + vTSNegLightDirNorm); + float nDotH = dot(vTSNormal, vHalfWay); + float fAtten = 1.0 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + float rho = dot(vTSNegLightDirNorm, vTSToLightNorm); + float fSpotE = clamp((rho - vSpotParams.y) / (vSpotParams.x - vSpotParams.y), 0.0, 1.0); + float fSpotT = pow(fSpotE, vSpotParams.z); + + vOutDiffuse += vDiffuseColour * nDotL * fAtten * fSpotT; + vOutSpecular += vSpecularColour * pow(clamp(nDotH, 0.0, 1.0), fSpecularPower) * fAtten * fSpotT; + } +} + diff --git a/res/dist/media/RTShaderLib/SGXLib_NormalMapLighting.glsles b/res/dist/media/RTShaderLib/SGXLib_NormalMapLighting.glsles new file mode 100644 index 00000000000..6ea28e3b24d --- /dev/null +++ b/res/dist/media/RTShaderLib/SGXLib_NormalMapLighting.glsles @@ -0,0 +1,264 @@ +#version 100 +precision highp float; +precision highp int; +precision lowp sampler2D; +precision lowp samplerCube; +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Program Name: SGXLib_NormalMapLighting +// Program Desc: Normal map lighting functions. +// Program Type: Vertex/Pixel shader +// Language: GLSL ES +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +void SGX_ConstructTBNMatrix(in vec3 vNormal, + in vec3 vTangent, + out mat3 vOut) +{ + vec3 vBinormal = cross(vTangent, vNormal); + + vOut[0][0] = vTangent.x; + vOut[1][0] = vTangent.y; + vOut[2][0] = vTangent.z; + + vOut[0][1] = vBinormal.x; + vOut[1][1] = vBinormal.y; + vOut[2][1] = vBinormal.z; + + vOut[0][2] = vNormal.x; + vOut[1][2] = vNormal.y; + vOut[2][2] = vNormal.z; +} + +//----------------------------------------------------------------------------- +void SGX_TransformNormal(in mat3 m, + in vec3 v, + out vec3 vOut) +{ + vOut = (m * v) ; +} + +//----------------------------------------------------------------------------- +void SGX_TransformNormal(in mat4 m, + in vec3 v, + out vec3 vOut) +{ + vOut = (m * vec4(v, 1.0)).xyz ; +} + +//----------------------------------------------------------------------------- +void SGX_TransformPosition(in mat4 m, + in vec4 v, + out vec3 vOut) +{ + vOut = (m * v).xyz; +} + +//----------------------------------------------------------------------------- +void SGX_FetchNormal(in sampler2D s, + in vec2 uv, + out vec3 vOut) +{ + vOut = 2.0 * texture2D(s, uv).xyz - 1.0; +} + +//----------------------------------------------------------------------------- +void SGX_Light_Directional_Diffuse(in vec3 vTSNormal, + in vec3 vTSNegLightDir, + in vec3 vDiffuseColour, + in vec3 vBaseColour, + out vec3 vOut) +{ + vec3 vTSNegLightDirNorm = normalize(vTSNegLightDir); + float nDotL = dot(vTSNormal, vTSNegLightDirNorm); + + vOut = vBaseColour + vDiffuseColour * clamp(nDotL, 0.0, 1.0); +} + +//----------------------------------------------------------------------------- +void SGX_Generate_Parallax_Texcoord(in sampler2D normalHeightMap, + in vec2 texCoord, + in vec3 eyeVec, + in vec2 scaleBias, + out vec2 newTexCoord) +{ + eyeVec = normalize(eyeVec); + float height = texture2D(normalHeightMap, texCoord).a; + float displacement = (height * scaleBias.x) + scaleBias.y; + vec3 scaledEyeDir = eyeVec * displacement; + newTexCoord = (scaledEyeDir + vec3(texCoord, 1.0)).xy; +} + +//----------------------------------------------------------------------------- +void SGX_Light_Directional_DiffuseSpecular(in vec3 vTSNormal, + in vec3 vTSView, + in vec3 vTSNegLightDir, + in vec3 vDiffuseColour, + in vec3 vSpecularColour, + in float fSpecularPower, + in vec3 vBaseDiffuseColour, + in vec3 vBaseSpecularColour, + out vec3 vOutDiffuse, + out vec3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + vec3 vTSNegLightDirNorm = normalize(vTSNegLightDir); + float nDotL = dot(vTSNormal, vTSNegLightDirNorm); + vec3 vTSViewNorm = normalize(vTSView); + vec3 vHalfWay = normalize(vTSView + vTSNegLightDir); + float nDotH = dot(vTSNormal, vHalfWay); + + if (nDotL > 0.0) + { + vOutDiffuse += vDiffuseColour * nDotL; + vOutSpecular += vSpecularColour * pow(clamp(nDotH, 0.0, 1.0), fSpecularPower); + } +} + +//----------------------------------------------------------------------------- +void SGX_Light_Point_Diffuse(in vec3 vTSNormal, + in vec3 vTSToLight, + in vec4 vAttParams, + in vec3 vDiffuseColour, + in vec3 vBaseColour, + out vec3 vOut) +{ + vOut = vBaseColour; + + float fLightD = length(vTSToLight); + float nDotL = dot(vTSNormal, normalize(vTSToLight)); + + if (nDotL > 0.0 && fLightD <= vAttParams.x) + { + float fAtten = 1.0 / (vAttParams.y + vAttParams.z * fLightD + vAttParams.w * fLightD * fLightD); + + vOut += vDiffuseColour * nDotL * fAtten; + } +} + +//----------------------------------------------------------------------------- +void SGX_Light_Point_DiffuseSpecular(in vec3 vTSNormal, + in vec3 vTSView, + in vec3 vTSToLight, + in vec4 vAttParams, + in vec3 vDiffuseColour, + in vec3 vSpecularColour, + in float fSpecularPower, + in vec3 vBaseDiffuseColour, + in vec3 vBaseSpecularColour, + out vec3 vOutDiffuse, + out vec3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + float fLightD = length(vTSToLight); + vec3 vTSNegLightDirNorm = normalize(vTSToLight); + float nDotL = dot(vTSNormal, vTSNegLightDirNorm); + + if (nDotL > 0.0 && fLightD <= vAttParams.x) + { + vec3 vTSViewNorm = normalize(vTSView); + vec3 vHalfWay = normalize(vTSViewNorm + vTSNegLightDirNorm); + float nDotH = dot(vTSNormal, vHalfWay); + float fAtten = 1.0 / (vAttParams.y + vAttParams.z * fLightD + vAttParams.w * fLightD * fLightD); + + vOutDiffuse += vDiffuseColour * nDotL * fAtten; + vOutSpecular += vSpecularColour * pow(clamp(nDotH, 0.0, 1.0), fSpecularPower) * fAtten; + } +} + +//----------------------------------------------------------------------------- +void SGX_Light_Spot_Diffuse(in vec3 vTSNormal, + in vec3 vTSToLight, + in vec3 vTSNegLightDir, + in vec4 vAttParams, + in vec3 vSpotParams, + in vec3 vDiffuseColour, + in vec3 vBaseColour, + out vec3 vOut) +{ + vOut = vBaseColour; + + float fLightD = length(vTSToLight); + vec3 vTSToLightNorm = normalize(vTSToLight); + float nDotL = dot(vTSNormal, vTSToLightNorm); + + if (nDotL > 0.0 && fLightD <= vAttParams.x) + { + vec3 vTSNegLightDirNorm = normalize(vTSNegLightDir); + float fAtten = 1.0 / (vAttParams.y + vAttParams.z * fLightD + vAttParams.w * fLightD * fLightD); + float rho = dot(vTSNegLightDirNorm, vTSToLightNorm); + float fSpotE = clamp((rho - vSpotParams.y) / (vSpotParams.x - vSpotParams.y), 0.0, 1.0); + float fSpotT = pow(fSpotE, vSpotParams.z); + + vOut += vDiffuseColour * nDotL * fAtten * fSpotT; + } +} + +//----------------------------------------------------------------------------- +void SGX_Light_Spot_DiffuseSpecular(in vec3 vTSNormal, + in vec3 vTSView, + in vec3 vTSToLight, + in vec3 vTSNegLightDir, + in vec4 vAttParams, + in vec3 vSpotParams, + in vec3 vDiffuseColour, + in vec3 vSpecularColour, + in float fSpecularPower, + in vec3 vBaseDiffuseColour, + in vec3 vBaseSpecularColour, + out vec3 vOutDiffuse, + out vec3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + float fLightD = length(vTSToLight); + vec3 vTSToLightNorm = normalize(vTSToLight); + float nDotL = dot(vTSNormal, vTSToLightNorm); + + if (nDotL > 0.0 && fLightD <= vAttParams.x) + { + vec3 vTSNegLightDirNorm = normalize(vTSNegLightDir); + vec3 vTSViewNorm = normalize(vTSView); + vec3 vHalfWay = normalize(vTSViewNorm + vTSNegLightDirNorm); + float nDotH = dot(vTSNormal, vHalfWay); + float fAtten = 1.0 / (vAttParams.y + vAttParams.z * fLightD + vAttParams.w * fLightD * fLightD); + float rho = dot(vTSNegLightDirNorm, vTSToLightNorm); + float fSpotE = clamp((rho - vSpotParams.y) / (vSpotParams.x - vSpotParams.y), 0.0, 1.0); + float fSpotT = pow(fSpotE, vSpotParams.z); + + vOutDiffuse += vDiffuseColour * nDotL * fAtten * fSpotT; + vOutSpecular += vSpecularColour * pow(clamp(nDotH, 0.0, 1.0), fSpecularPower) * fAtten * fSpotT; + } +} diff --git a/res/dist/media/RTShaderLib/SGXLib_NormalMapLighting.hlsl b/res/dist/media/RTShaderLib/SGXLib_NormalMapLighting.hlsl new file mode 100644 index 00000000000..39390f3f3b8 --- /dev/null +++ b/res/dist/media/RTShaderLib/SGXLib_NormalMapLighting.hlsl @@ -0,0 +1,257 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Program Name: SGXLib_NormalMapLighting +// Program Desc: Normal map lighting functions. +// Program Type: Vertex/Pixel shader +// Language: HLSL +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +void SGX_ConstructTBNMatrix(in float3 vNormal, + in float3 vTangent, + out float3x3 vOut) +{ + float3 vBinormal = cross(vTangent, vNormal); + + vOut = float3x3(vTangent, vBinormal, vNormal); +} + +//----------------------------------------------------------------------------- +void SGX_TransformNormal(in float3x3 m, + in float3 v, + out float3 vOut) +{ + vOut = mul(m, v); +} + +//----------------------------------------------------------------------------- +void SGX_TransformNormal(in float4x4 m, + in float3 v, + out float3 vOut) +{ + vOut = mul((float3x3)m, v); +} + +//----------------------------------------------------------------------------- +void SGX_TransformPosition(in float4x4 m, + in float4 v, + out float3 vOut) +{ + vOut = mul(m, v).xyz; +} + +//----------------------------------------------------------------------------- +void SGX_FetchNormal(in sampler2D s, + in float2 uv, + out float3 vOut) +{ + vOut = 2 * tex2D(s, uv).xyz - 1; +} + +//----------------------------------------------------------------------------- +void SGX_Generate_Parallax_Texcoord(in sampler2D normalHeightMap, + in float2 texCoord, + in float3 eyeVec, + in float2 scaleBias, + out float2 newTexCoord) +{ + eyeVec = normalize(eyeVec); + float height = tex2D(normalHeightMap, texCoord).a; + float displacement = (height * scaleBias.x) + scaleBias.y; + float3 scaledEyeDir = eyeVec * displacement; + newTexCoord = (scaledEyeDir + float3(texCoord, 1.0)).xy; +} + +//----------------------------------------------------------------------------- +void SGX_Light_Directional_Diffuse( + in float3 vTSNormal, + in float3 vTSNegLightDir, + in float3 vDiffuseColour, + in float3 vBaseColour, + out float3 vOut) +{ + float3 vTSNegLightDirNorm = normalize(vTSNegLightDir); + float nDotL = dot(vTSNormal, vTSNegLightDirNorm); + + vOut = vBaseColour + vDiffuseColour * saturate(nDotL); +} + +//----------------------------------------------------------------------------- +void SGX_Light_Directional_DiffuseSpecular( + in float3 vTSNormal, + in float3 vTSView, + in float3 vTSNegLightDir, + in float3 vDiffuseColour, + in float3 vSpecularColour, + in float fSpecularPower, + in float3 vBaseDiffuseColour, + in float3 vBaseSpecularColour, + out float3 vOutDiffuse, + out float3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + float3 vTSNegLightDirNorm = normalize(vTSNegLightDir); + float nDotL = dot(vTSNormal, vTSNegLightDirNorm); + float3 vTSViewNorm = normalize(vTSView); + float3 vHalfWay = normalize(vTSView + vTSNegLightDir); + float nDotH = dot(vTSNormal, vHalfWay); + + if (nDotL > 0) + { + vOutDiffuse += vDiffuseColour * nDotL; + vOutSpecular += vSpecularColour * pow(saturate(nDotH), fSpecularPower); + } +} + +//----------------------------------------------------------------------------- +void SGX_Light_Point_Diffuse( + in float3 vTSNormal, + in float3 vTSToLight, + in float4 vAttParams, + in float3 vDiffuseColour, + in float3 vBaseColour, + out float3 vOut) +{ + vOut = vBaseColour; + + float fLightD = length(vTSToLight); + float nDotL = dot(vTSNormal, normalize(vTSToLight)); + + if (nDotL > 0 && fLightD <= vAttParams.x) + { + float fAtten = 1 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + + vOut += vDiffuseColour * nDotL * fAtten; + } +} + + + +//----------------------------------------------------------------------------- +void SGX_Light_Point_DiffuseSpecular( + in float3 vTSNormal, + in float3 vTSView, + in float3 vTSToLight, + in float4 vAttParams, + in float3 vDiffuseColour, + in float3 vSpecularColour, + in float fSpecularPower, + in float3 vBaseDiffuseColour, + in float3 vBaseSpecularColour, + out float3 vOutDiffuse, + out float3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + float fLightD = length(vTSToLight); + float3 vTSNegLightDirNorm = normalize(vTSToLight); + float nDotL = dot(vTSNormal, vTSNegLightDirNorm); + + if (nDotL > 0 && fLightD <= vAttParams.x) + { + float3 vTSViewNorm = normalize(vTSView); + float3 vHalfWay = normalize(vTSViewNorm + vTSNegLightDirNorm); + float nDotH = dot(vTSNormal, vHalfWay); + float fAtten = 1 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + + vOutDiffuse += vDiffuseColour * nDotL * fAtten; + vOutSpecular += vSpecularColour * pow(saturate(nDotH), fSpecularPower) * fAtten; + } +} + +//----------------------------------------------------------------------------- +void SGX_Light_Spot_Diffuse( + in float3 vTSNormal, + in float3 vTSToLight, + in float3 vTSNegLightDir, + in float4 vAttParams, + in float3 vSpotParams, + in float3 vDiffuseColour, + in float3 vBaseColour, + out float3 vOut) +{ + vOut = vBaseColour; + + float fLightD = length(vTSToLight); + float3 vTSToLightNorm = normalize(vTSToLight); + float nDotL = dot(vTSNormal, vTSToLightNorm); + + if (nDotL > 0 && fLightD <= vAttParams.x) + { + float3 vTSNegLightDirNorm = normalize(vTSNegLightDir); + float fAtten = 1 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + float rho = dot(vTSNegLightDirNorm, vTSToLightNorm); + float fSpotE = saturate((rho - vSpotParams.y) / (vSpotParams.x - vSpotParams.y)); + float fSpotT = pow(fSpotE, vSpotParams.z); + + vOut += vDiffuseColour * nDotL * fAtten * fSpotT; + } +} + +//----------------------------------------------------------------------------- +void SGX_Light_Spot_DiffuseSpecular( + in float3 vTSNormal, + in float3 vTSView, + in float3 vTSToLight, + in float3 vTSNegLightDir, + in float4 vAttParams, + in float3 vSpotParams, + in float3 vDiffuseColour, + in float3 vSpecularColour, + in float fSpecularPower, + in float3 vBaseDiffuseColour, + in float3 vBaseSpecularColour, + out float3 vOutDiffuse, + out float3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + float fLightD = length(vTSToLight); + float3 vTSToLightNorm = normalize(vTSToLight); + float nDotL = dot(vTSNormal, vTSToLightNorm); + + if (nDotL > 0 && fLightD <= vAttParams.x) + { + float3 vTSNegLightDirNorm = normalize(vTSNegLightDir); + float3 vTSViewNorm = normalize(vTSView); + float3 vHalfWay = normalize(vTSViewNorm + vTSNegLightDirNorm); + float nDotH = dot(vTSNormal, vHalfWay); + float fAtten = 1 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + float rho = dot(vTSNegLightDirNorm, vTSToLightNorm); + float fSpotE = saturate((rho - vSpotParams.y) / (vSpotParams.x - vSpotParams.y)); + float fSpotT = pow(fSpotE, vSpotParams.z); + + vOutDiffuse += vDiffuseColour * nDotL * fAtten * fSpotT; + vOutSpecular += vSpecularColour * pow(saturate(nDotH), fSpecularPower) * fAtten * fSpotT; + } +} diff --git a/res/dist/media/RTShaderLib/SGXLib_PerPixelLighting.cg b/res/dist/media/RTShaderLib/SGXLib_PerPixelLighting.cg new file mode 100644 index 00000000000..bd4b955ab14 --- /dev/null +++ b/res/dist/media/RTShaderLib/SGXLib_PerPixelLighting.cg @@ -0,0 +1,226 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Program Name: SGXLib_Lighting +// Program Desc: Per pixel lighting functions. +// Program Type: Vertex/Pixel shader +// Language: CG +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +void SGX_TransformNormal(in float4x4 m, + in float3 v, + out float3 vOut) +{ + vOut = mul((float3x3)m, v); +} + +//----------------------------------------------------------------------------- +void SGX_TransformPosition(in float4x4 mWorldView, + in float4 vPos, + out float3 vOut) +{ + vOut = mul(mWorldView, vPos).xyz; +} + +//----------------------------------------------------------------------------- +void SGX_Light_Directional_Diffuse( + in float3 vNormal, + in float3 vNegLightDirView, + in float3 vDiffuseColour, + in float3 vBaseColour, + out float3 vOut) +{ + float3 vNormalView = normalize(vNormal); + float nDotL = dot(vNormalView, vNegLightDirView); + + vOut = vBaseColour + vDiffuseColour * saturate(nDotL); +} + +//----------------------------------------------------------------------------- +void SGX_Light_Directional_DiffuseSpecular( + in float3 vNormal, + in float3 vViewPos, + in float3 vNegLightDirView, + in float3 vDiffuseColour, + in float3 vSpecularColour, + in float fSpecularPower, + in float3 vBaseDiffuseColour, + in float3 vBaseSpecularColour, + out float3 vOutDiffuse, + out float3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + float3 vNormalView = normalize(vNormal); + float nDotL = dot(vNormalView, vNegLightDirView); + float3 vView = -normalize(vViewPos); + float3 vHalfWay = normalize(vView + vNegLightDirView); + float nDotH = dot(vNormalView, vHalfWay); + + if (nDotL > 0) + { + vOutDiffuse += vDiffuseColour * nDotL; + vOutSpecular += vSpecularColour * pow(saturate(nDotH), fSpecularPower); + } +} + +//----------------------------------------------------------------------------- +void SGX_Light_Point_Diffuse( + in float3 vNormal, + in float3 vViewPos, + in float3 vLightPosView, + in float4 vAttParams, + in float3 vDiffuseColour, + in float3 vBaseColour, + out float3 vOut) +{ + vOut = vBaseColour; + + float3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + float3 vNormalView = normalize(vNormal); + float nDotL = dot(vNormalView, normalize(vLightView)); + + if (nDotL > 0 && fLightD <= vAttParams.x) + { + float fAtten = 1 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + + vOut += vDiffuseColour * nDotL * fAtten; + } +} + + + +//----------------------------------------------------------------------------- +void SGX_Light_Point_DiffuseSpecular( + in float3 vNormal, + in float3 vViewPos, + in float3 vLightPosView, + in float4 vAttParams, + in float3 vDiffuseColour, + in float3 vSpecularColour, + in float fSpecularPower, + in float3 vBaseDiffuseColour, + in float3 vBaseSpecularColour, + out float3 vOutDiffuse, + out float3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + float3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + vLightView = normalize(vLightView); + float3 vNormalView = normalize(vNormal); + float nDotL = dot(vNormalView, vLightView); + + if (nDotL > 0 && fLightD <= vAttParams.x) + { + float3 vView = -normalize(vViewPos); + float3 vHalfWay = normalize(vView + vLightView); + float nDotH = dot(vNormalView, vHalfWay); + float fAtten = 1 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + + vOutDiffuse += vDiffuseColour * nDotL * fAtten; + vOutSpecular += vSpecularColour * pow(saturate(nDotH), fSpecularPower) * fAtten; + } +} + +//----------------------------------------------------------------------------- +void SGX_Light_Spot_Diffuse( + in float3 vNormal, + in float3 vViewPos, + in float3 vLightPosView, + in float3 vNegLightDirView, + in float4 vAttParams, + in float3 vSpotParams, + in float3 vDiffuseColour, + in float3 vBaseColour, + out float3 vOut) +{ + vOut = vBaseColour; + + float3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + vLightView = normalize(vLightView); + float3 vNormalView = normalize(vNormal); + float nDotL = dot(vNormalView, vLightView); + + if (nDotL > 0 && fLightD <= vAttParams.x) + { + float fAtten = 1 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + float rho = dot(vNegLightDirView, vLightView); + float fSpotE = saturate((rho - vSpotParams.y) / (vSpotParams.x - vSpotParams.y)); + float fSpotT = pow(fSpotE, vSpotParams.z); + + vOut += vDiffuseColour * nDotL * fAtten * fSpotT; + } +} + +//----------------------------------------------------------------------------- +void SGX_Light_Spot_DiffuseSpecular( + in float3 vNormal, + in float3 vViewPos, + in float3 vLightPosView, + in float3 vNegLightDirView, + in float4 vAttParams, + in float3 vSpotParams, + in float3 vDiffuseColour, + in float3 vSpecularColour, + in float fSpecularPower, + in float3 vBaseDiffuseColour, + in float3 vBaseSpecularColour, + out float3 vOutDiffuse, + out float3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + float3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + vLightView = normalize(vLightView); + float3 vNormalView = normalize(vNormal); + float nDotL = dot(vNormalView, vLightView); + + + if (nDotL > 0 && fLightD <= vAttParams.x) + { + float3 vView = -normalize(vViewPos); + float3 vHalfWay = normalize(vView + vLightView); + float nDotH = dot(vNormalView, vHalfWay); + float fAtten = 1 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + float rho = dot(vNegLightDirView, vLightView); + float fSpotE = saturate((rho - vSpotParams.y) / (vSpotParams.x - vSpotParams.y)); + float fSpotT = pow(fSpotE, vSpotParams.z); + + vOutDiffuse += vDiffuseColour * nDotL * fAtten * fSpotT; + vOutSpecular += vSpecularColour * pow(saturate(nDotH), fSpecularPower) * fAtten * fSpotT; + } +} diff --git a/res/dist/media/RTShaderLib/SGXLib_PerPixelLighting.glsl b/res/dist/media/RTShaderLib/SGXLib_PerPixelLighting.glsl new file mode 100644 index 00000000000..7e035c2d47c --- /dev/null +++ b/res/dist/media/RTShaderLib/SGXLib_PerPixelLighting.glsl @@ -0,0 +1,228 @@ +#version 120 +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Program Name: SGXLib_Lighting +// Program Desc: Per pixel lighting functions. +// Program Type: Vertex/Pixel shader +// Language: GLSL +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +void SGX_TransformNormal(in mat4 m, + in vec3 v, + out vec3 vOut) +{ + vOut = (m * vec4(v, 1.0)).xyz; +} + +//----------------------------------------------------------------------------- +void SGX_TransformPosition(in mat4 mWorldView, + in vec4 vPos, + out vec3 vOut) +{ + vOut = (mWorldView * vPos).xyz; +} + +//----------------------------------------------------------------------------- +void SGX_Light_Directional_Diffuse( + in vec3 vNormal, + in vec3 vNegLightDirView, + in vec3 vDiffuseColour, + in vec3 vBaseColour, + out vec3 vOut) +{ + vec3 vNormalView = normalize(vNormal); + float nDotL = dot(vNormalView, vNegLightDirView); + + vOut = vBaseColour + vDiffuseColour * clamp(nDotL, 0.0, 1.0); +} + +//----------------------------------------------------------------------------- +void SGX_Light_Directional_DiffuseSpecular( + in vec3 vNormal, + in vec3 vViewPos, + in vec3 vNegLightDirView, + in vec3 vDiffuseColour, + in vec3 vSpecularColour, + in float fSpecularPower, + in vec3 vBaseDiffuseColour, + in vec3 vBaseSpecularColour, + out vec3 vOutDiffuse, + out vec3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + vec3 vNormalView = normalize(vNormal); + float nDotL = dot(vNormalView, vNegLightDirView); + vec3 vView = -normalize(vViewPos); + vec3 vHalfWay = normalize(vView + vNegLightDirView); + float nDotH = dot(vNormalView, vHalfWay); + + if (nDotL > 0.0) + { + vOutDiffuse += vDiffuseColour * nDotL; + vOutSpecular += vSpecularColour * pow(clamp(nDotH, 0.0, 1.0), fSpecularPower); + } +} + +//----------------------------------------------------------------------------- +void SGX_Light_Point_Diffuse( + in vec3 vNormal, + in vec3 vViewPos, + in vec3 vLightPosView, + in vec4 vAttParams, + in vec3 vDiffuseColour, + in vec3 vBaseColour, + out vec3 vOut) +{ + vOut = vBaseColour; + + vec3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + vec3 vNormalView = normalize(vNormal); + float nDotL = dot(vNormalView, normalize(vLightView)); + + if (nDotL > 0.0 && fLightD <= vAttParams.x) + { + float fAtten = 1.0 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + + vOut += vDiffuseColour * nDotL * fAtten; + } +} + + + +//----------------------------------------------------------------------------- +void SGX_Light_Point_DiffuseSpecular( + in vec3 vNormal, + in vec3 vViewPos, + in vec3 vLightPosView, + in vec4 vAttParams, + in vec3 vDiffuseColour, + in vec3 vSpecularColour, + in float fSpecularPower, + in vec3 vBaseDiffuseColour, + in vec3 vBaseSpecularColour, + out vec3 vOutDiffuse, + out vec3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + vec3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + vLightView = normalize(vLightView); + vec3 vNormalView = normalize(vNormal); + float nDotL = dot(vNormalView, vLightView); + + if (nDotL > 0.0 && fLightD <= vAttParams.x) + { + vec3 vView = -normalize(vViewPos); + vec3 vHalfWay = normalize(vView + vLightView); + float nDotH = dot(vNormalView, vHalfWay); + float fAtten = 1.0 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + + vOutDiffuse += vDiffuseColour * nDotL * fAtten; + vOutSpecular += vSpecularColour * pow(clamp(nDotH, 0.0, 1.0), fSpecularPower) * fAtten; + } +} + +//----------------------------------------------------------------------------- +void SGX_Light_Spot_Diffuse( + in vec3 vNormal, + in vec3 vViewPos, + in vec3 vLightPosView, + in vec3 vNegLightDirView, + in vec4 vAttParams, + in vec3 vSpotParams, + in vec3 vDiffuseColour, + in vec3 vBaseColour, + out vec3 vOut) +{ + vOut = vBaseColour; + + vec3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + vLightView = normalize(vLightView); + vec3 vNormalView = normalize(vNormal); + float nDotL = dot(vNormalView, vLightView); + + if (nDotL > 0.0 && fLightD <= vAttParams.x) + { + float fAtten = 1.0 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + float rho = dot(vNegLightDirView, vLightView); + float fSpotE = clamp((rho - vSpotParams.y) / (vSpotParams.x - vSpotParams.y), 0.0, 1.0); + float fSpotT = pow(fSpotE, vSpotParams.z); + + vOut += vDiffuseColour * nDotL * fAtten * fSpotT; + } +} + +//----------------------------------------------------------------------------- +void SGX_Light_Spot_DiffuseSpecular( + in vec3 vNormal, + in vec3 vViewPos, + in vec3 vLightPosView, + in vec3 vNegLightDirView, + in vec4 vAttParams, + in vec3 vSpotParams, + in vec3 vDiffuseColour, + in vec3 vSpecularColour, + in float fSpecularPower, + in vec3 vBaseDiffuseColour, + in vec3 vBaseSpecularColour, + out vec3 vOutDiffuse, + out vec3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + vec3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + vLightView = normalize(vLightView); + vec3 vNormalView = normalize(vNormal); + float nDotL = dot(vNormalView, vLightView); + + + if (nDotL > 0.0 && fLightD <= vAttParams.x) + { + vec3 vView = -normalize(vViewPos); + vec3 vHalfWay = normalize(vView + vLightView); + float nDotH = dot(vNormalView, vHalfWay); + float fAtten = 1.0 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + float rho = dot(vNegLightDirView, vLightView); + float fSpotE = clamp((rho - vSpotParams.y) / (vSpotParams.x - vSpotParams.y), 0.0, 1.0); + float fSpotT = pow(fSpotE, vSpotParams.z); + + vOutDiffuse += vDiffuseColour * nDotL * fAtten * fSpotT; + vOutSpecular += vSpecularColour * pow(clamp(nDotH, 0.0, 1.0), fSpecularPower) * fAtten * fSpotT; + } +} + diff --git a/res/dist/media/RTShaderLib/SGXLib_PerPixelLighting.glsles b/res/dist/media/RTShaderLib/SGXLib_PerPixelLighting.glsles new file mode 100644 index 00000000000..ad3d78e760a --- /dev/null +++ b/res/dist/media/RTShaderLib/SGXLib_PerPixelLighting.glsles @@ -0,0 +1,223 @@ +#version 100 +precision highp float; +precision highp int; +precision lowp sampler2D; +precision lowp samplerCube; +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Program Name: SGXLib_Lighting +// Program Desc: Per pixel lighting functions. +// Program Type: Vertex/Pixel shader +// Language: GLSL ES +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +void SGX_TransformNormal(in mat4 m, + in vec3 v, + out vec3 vOut) +{ + vOut = (m * vec4(v, 1.0)).xyz; +} + +//----------------------------------------------------------------------------- +void SGX_TransformPosition(in mat4 mWorldView, + in vec4 vPos, + out vec3 vOut) +{ + vOut = (mWorldView * vPos).xyz; +} + +//----------------------------------------------------------------------------- +void SGX_Light_Directional_Diffuse(in vec3 vNormal, + in vec3 vNegLightDirView, + in vec3 vDiffuseColour, + in vec3 vBaseColour, + out vec3 vOut) +{ + vec3 vNormalView = normalize(vNormal); + float nDotL = dot(vNormalView, vNegLightDirView); + + vOut = vBaseColour + vDiffuseColour * clamp(nDotL, 0.0, 1.0); +} + +//----------------------------------------------------------------------------- +void SGX_Light_Directional_DiffuseSpecular(in vec3 vNormal, + in vec3 vViewPos, + in vec3 vNegLightDirView, + in vec3 vDiffuseColour, + in vec3 vSpecularColour, + in float fSpecularPower, + in vec3 vBaseDiffuseColour, + in vec3 vBaseSpecularColour, + out vec3 vOutDiffuse, + out vec3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + vec3 vNormalView = normalize(vNormal); + float nDotL = dot(vNormalView, vNegLightDirView); + vec3 vView = -normalize(vViewPos); + vec3 vHalfWay = normalize(vView + vNegLightDirView); + float nDotH = dot(vNormalView, vHalfWay); + + if (nDotL > 0.0) + { + vOutDiffuse += vDiffuseColour * nDotL; + vOutSpecular += vSpecularColour * pow(clamp(nDotH, 0.0, 1.0), fSpecularPower); + } +} + +//----------------------------------------------------------------------------- +void SGX_Light_Point_Diffuse(in vec3 vNormal, + in vec3 vViewPos, + in vec3 vLightPosView, + in vec4 vAttParams, + in vec3 vDiffuseColour, + in vec3 vBaseColour, + out vec3 vOut) +{ + vOut = vBaseColour; + + vec3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + vec3 vNormalView = normalize(vNormal); + float nDotL = dot(vNormalView, normalize(vLightView)); + + if (nDotL > 0.0 && fLightD <= vAttParams.x) + { + float fAtten = 1.0 / (vAttParams.y + vAttParams.z * fLightD + vAttParams.w * fLightD * fLightD); + + vOut += vDiffuseColour * nDotL * fAtten; + } +} + +//----------------------------------------------------------------------------- +void SGX_Light_Point_DiffuseSpecular(in vec3 vNormal, + in vec3 vViewPos, + in vec3 vLightPosView, + in vec4 vAttParams, + in vec3 vDiffuseColour, + in vec3 vSpecularColour, + in float fSpecularPower, + in vec3 vBaseDiffuseColour, + in vec3 vBaseSpecularColour, + out vec3 vOutDiffuse, + out vec3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + vec3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + vLightView = normalize(vLightView); + vec3 vNormalView = normalize(vNormal); + float nDotL = dot(vNormalView, vLightView); + + if (nDotL > 0.0 && fLightD <= vAttParams.x) + { + vec3 vView = -normalize(vViewPos); + vec3 vHalfWay = normalize(vView + vLightView); + float nDotH = dot(vNormalView, vHalfWay); + float fAtten = 1.0 / (vAttParams.y + vAttParams.z * fLightD + vAttParams.w * fLightD * fLightD); + + vOutDiffuse += vDiffuseColour * nDotL * fAtten; + vOutSpecular += vSpecularColour * pow(clamp(nDotH, 0.0, 1.0), fSpecularPower) * fAtten; + } +} + +//----------------------------------------------------------------------------- +void SGX_Light_Spot_Diffuse(in vec3 vNormal, + in vec3 vViewPos, + in vec3 vLightPosView, + in vec3 vNegLightDirView, + in vec4 vAttParams, + in vec3 vSpotParams, + in vec3 vDiffuseColour, + in vec3 vBaseColour, + out vec3 vOut) +{ + vOut = vBaseColour; + + vec3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + vLightView = normalize(vLightView); + vec3 vNormalView = normalize(vNormal); + float nDotL = dot(vNormalView, vLightView); + + if (nDotL > 0.0 && fLightD <= vAttParams.x) + { + float fAtten = 1.0 / (vAttParams.y + vAttParams.z * fLightD + vAttParams.w * fLightD * fLightD); + float rho = dot(vNegLightDirView, vLightView); + float fSpotE = clamp((rho - vSpotParams.y) / (vSpotParams.x - vSpotParams.y), 0.0, 1.0); + float fSpotT = pow(fSpotE, vSpotParams.z); + + vOut += vDiffuseColour * nDotL * fAtten * fSpotT; + } +} + +//----------------------------------------------------------------------------- +void SGX_Light_Spot_DiffuseSpecular(in vec3 vNormal, + in vec3 vViewPos, + in vec3 vLightPosView, + in vec3 vNegLightDirView, + in vec4 vAttParams, + in vec3 vSpotParams, + in vec3 vDiffuseColour, + in vec3 vSpecularColour, + in float fSpecularPower, + in vec3 vBaseDiffuseColour, + in vec3 vBaseSpecularColour, + out vec3 vOutDiffuse, + out vec3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + vec3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + vLightView = normalize(vLightView); + vec3 vNormalView = normalize(vNormal); + float nDotL = dot(vNormalView, vLightView); + + + if (nDotL > 0.0 && fLightD <= vAttParams.x) + { + vec3 vView = -normalize(vViewPos); + vec3 vHalfWay = normalize(vView + vLightView); + float nDotH = dot(vNormalView, vHalfWay); + float fAtten = 1.0 / (vAttParams.y + vAttParams.z * fLightD + vAttParams.w * fLightD * fLightD); + float rho = dot(vNegLightDirView, vLightView); + float fSpotE = clamp((rho - vSpotParams.y) / (vSpotParams.x - vSpotParams.y), 0.0, 1.0); + float fSpotT = pow(fSpotE, vSpotParams.z); + + vOutDiffuse += vDiffuseColour * nDotL * fAtten * fSpotT; + vOutSpecular += vSpecularColour * pow(clamp(nDotH, 0.0, 1.0), fSpecularPower) * fAtten * fSpotT; + } +} diff --git a/res/dist/media/RTShaderLib/SGXLib_PerPixelLighting.hlsl b/res/dist/media/RTShaderLib/SGXLib_PerPixelLighting.hlsl new file mode 100644 index 00000000000..611b2e284e9 --- /dev/null +++ b/res/dist/media/RTShaderLib/SGXLib_PerPixelLighting.hlsl @@ -0,0 +1,226 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Program Name: SGXLib_Lighting +// Program Desc: Per pixel lighting functions. +// Program Type: Vertex/Pixel shader +// Language: HLSL +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +void SGX_TransformNormal(in float4x4 m, + in float3 v, + out float3 vOut) +{ + vOut = mul((float3x3)m, v); +} + +//----------------------------------------------------------------------------- +void SGX_TransformPosition(in float4x4 mWorldView, + in float4 vPos, + out float3 vOut) +{ + vOut = mul(mWorldView, vPos).xyz; +} + +//----------------------------------------------------------------------------- +void SGX_Light_Directional_Diffuse( + in float3 vNormal, + in float3 vNegLightDirView, + in float3 vDiffuseColour, + in float3 vBaseColour, + out float3 vOut) +{ + float3 vNormalView = normalize(vNormal); + float nDotL = dot(vNormalView, vNegLightDirView); + + vOut = vBaseColour + vDiffuseColour * saturate(nDotL); +} + +//----------------------------------------------------------------------------- +void SGX_Light_Directional_DiffuseSpecular( + in float3 vNormal, + in float3 vViewPos, + in float3 vNegLightDirView, + in float3 vDiffuseColour, + in float3 vSpecularColour, + in float fSpecularPower, + in float3 vBaseDiffuseColour, + in float3 vBaseSpecularColour, + out float3 vOutDiffuse, + out float3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + float3 vNormalView = normalize(vNormal); + float nDotL = dot(vNormalView, vNegLightDirView); + float3 vView = -normalize(vViewPos); + float3 vHalfWay = normalize(vView + vNegLightDirView); + float nDotH = dot(vNormalView, vHalfWay); + + if (nDotL > 0) + { + vOutDiffuse += vDiffuseColour * nDotL; + vOutSpecular += vSpecularColour * pow(saturate(nDotH), fSpecularPower); + } +} + +//----------------------------------------------------------------------------- +void SGX_Light_Point_Diffuse( + in float3 vNormal, + in float3 vViewPos, + in float3 vLightPosView, + in float4 vAttParams, + in float3 vDiffuseColour, + in float3 vBaseColour, + out float3 vOut) +{ + vOut = vBaseColour; + + float3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + float3 vNormalView = normalize(vNormal); + float nDotL = dot(vNormalView, normalize(vLightView)); + + if (nDotL > 0 && fLightD <= vAttParams.x) + { + float fAtten = 1 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + + vOut += vDiffuseColour * nDotL * fAtten; + } +} + + + +//----------------------------------------------------------------------------- +void SGX_Light_Point_DiffuseSpecular( + in float3 vNormal, + in float3 vViewPos, + in float3 vLightPosView, + in float4 vAttParams, + in float3 vDiffuseColour, + in float3 vSpecularColour, + in float fSpecularPower, + in float3 vBaseDiffuseColour, + in float3 vBaseSpecularColour, + out float3 vOutDiffuse, + out float3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + float3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + vLightView = normalize(vLightView); + float3 vNormalView = normalize(vNormal); + float nDotL = dot(vNormalView, vLightView); + + if (nDotL > 0 && fLightD <= vAttParams.x) + { + float3 vView = -normalize(vViewPos); + float3 vHalfWay = normalize(vView + vLightView); + float nDotH = dot(vNormalView, vHalfWay); + float fAtten = 1 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + + vOutDiffuse += vDiffuseColour * nDotL * fAtten; + vOutSpecular += vSpecularColour * pow(saturate(nDotH), fSpecularPower) * fAtten; + } +} + +//----------------------------------------------------------------------------- +void SGX_Light_Spot_Diffuse( + in float3 vNormal, + in float3 vViewPos, + in float3 vLightPosView, + in float3 vNegLightDirView, + in float4 vAttParams, + in float3 vSpotParams, + in float3 vDiffuseColour, + in float3 vBaseColour, + out float3 vOut) +{ + vOut = vBaseColour; + + float3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + vLightView = normalize(vLightView); + float3 vNormalView = normalize(vNormal); + float nDotL = dot(vNormalView, vLightView); + + if (nDotL > 0 && fLightD <= vAttParams.x) + { + float fAtten = 1 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + float rho = dot(vNegLightDirView, vLightView); + float fSpotE = saturate((rho - vSpotParams.y) / (vSpotParams.x - vSpotParams.y)); + float fSpotT = pow(fSpotE, vSpotParams.z); + + vOut += vDiffuseColour * nDotL * fAtten * fSpotT; + } +} + +//----------------------------------------------------------------------------- +void SGX_Light_Spot_DiffuseSpecular( + in float3 vNormal, + in float3 vViewPos, + in float3 vLightPosView, + in float3 vNegLightDirView, + in float4 vAttParams, + in float3 vSpotParams, + in float3 vDiffuseColour, + in float3 vSpecularColour, + in float fSpecularPower, + in float3 vBaseDiffuseColour, + in float3 vBaseSpecularColour, + out float3 vOutDiffuse, + out float3 vOutSpecular) +{ + vOutDiffuse = vBaseDiffuseColour; + vOutSpecular = vBaseSpecularColour; + + float3 vLightView = vLightPosView - vViewPos; + float fLightD = length(vLightView); + vLightView = normalize(vLightView); + float3 vNormalView = normalize(vNormal); + float nDotL = dot(vNormalView, vLightView); + + + if (nDotL > 0 && fLightD <= vAttParams.x) + { + float3 vView = -normalize(vViewPos); + float3 vHalfWay = normalize(vView + vLightView); + float nDotH = dot(vNormalView, vHalfWay); + float fAtten = 1 / (vAttParams.y + vAttParams.z*fLightD + vAttParams.w*fLightD*fLightD); + float rho = dot(vNegLightDirView, vLightView); + float fSpotE = saturate((rho - vSpotParams.y) / (vSpotParams.x - vSpotParams.y)); + float fSpotT = pow(fSpotE, vSpotParams.z); + + vOutDiffuse += vDiffuseColour * nDotL * fAtten * fSpotT; + vOutSpecular += vSpecularColour * pow(saturate(nDotH), fSpecularPower) * fAtten * fSpotT; + } +} diff --git a/res/dist/media/RTShaderLib/SGXLib_TextureAtlas.cg b/res/dist/media/RTShaderLib/SGXLib_TextureAtlas.cg new file mode 100644 index 00000000000..87f1db9c204 --- /dev/null +++ b/res/dist/media/RTShaderLib/SGXLib_TextureAtlas.cg @@ -0,0 +1,122 @@ +//----------------------------------------------------------------------------- +// Program Name: SGXLib_IntegratedPSSM +// Program Desc: Texture Atlas functions. +// Program Type: Vertex/Pixel shader +// Language: CG +//----------------------------------------------------------------------------- + +float mipmapLevel(float2 coords, float2 texSize) +{ + coords = coords.xy * texSize; + float2 dx = ddx(coords.xy); + float2 dy = ddy(coords.xy); + float Px = length(dx); + float Py = length(dy); + float Pmax = max(Px, Py); + return log2(max(Pmax,1)); +} + + +//----------------------------------------------------------------------------- +void SGX_Atlas_Sample_Auto_Adjust(in sampler2D sample, + in float2 origTexcoord, + in float2 atlasTexcoord, + in float4 textureData, + in float2 imageSize, + out float4 texel) +{ + // + // Most of the idea for this function has been taken from the code under the webpage: + // http://www.gamedev.net/topic/534149-solved-texture-seams-using-atlas-with-screenshots/ + + + // origTexcoord - original texture coordintates as received from the vertex buffer. + // atlasTexcoord - texture coordinates that have gone through on which different mathematical + // functions to simulate different texture addressing modes (wrap, mirror, clamp) + // textureData.xy - top left corner (in 0-1 units) where the needed texture in the texture atlas begins + // textureData.zw - width and height in power of 2 for the needed texture in the texture atlas + // imageSize - size of the image in pixels + // texel - [Output] The color of the pixel at the requested position + + float2 startPos = textureData.xy; + + + // calculate the tileSize by using the power of 2 value + float2 pwrs = textureData.zw; + + //Calculate the power of 2 size of the maximum avialable Mipmap + //Note: We limit the amount of available LODs to [actual number] - 2 + //as some atlas packaging tools do not include the last 2 LODs + //when packeging DXT format atlas textures. + float availableLODCount = min(pwrs.x,pwrs.y) - 2; + float2 tileSize = pow(float2(2.0,2.0),pwrs); + + // retrieve the mipmap level for this pixel clamped by the power of 2 value + float lod = clamp(mipmapLevel(origTexcoord, tileSize), 0, availableLODCount); + + float2 relativeTileSize = tileSize / imageSize; + // get the width/height of the mip surface we've decided on + float2 mipSize = pow(float2(2.0,2.0), pwrs.xy - ceil(lod)); + + // compute the inverse fraction size for the tile + //float2 lodSize = mipSize * imageSize / tileSize; + float2 lodSizeInv = (relativeTileSize / mipSize); + //compute the new coordinates + //atlasTexcoord = atlasTexcoord * ((lodSize * (tileSize / imageSize) - 1.0) / lodSize) + (0.5 / lodSize) + startPos; + atlasTexcoord = atlasTexcoord * (relativeTileSize - lodSizeInv) + (0.5 * lodSizeInv) + startPos; + + //return the pixel from the correct mip surface of the atlas + texel = tex2Dlod(sample, float4(atlasTexcoord, 0, lod)); +} +//----------------------------------------------------------------------------- +void SGX_Atlas_Sample_Normal(in sampler2D sample, + in float2 origTexcoord, + in float2 atlasTexcoord, + in float4 textureData, + in float2 imageSize, + out float4 texel) +{ + //texcoord contain: + // x = texture atlas u + // y = texture atlas v + // z = derivative of original u + // w = derivative of original v + atlasTexcoord = textureData.xy + (atlasTexcoord * pow(float2(2.0,2.0),textureData.zw) / imageSize); + //texel = tex2Dlod(sample, float4(atlasTexcoord, 0,0)); + texel = tex2D(sample, atlasTexcoord); +} + +//----------------------------------------------------------------------------- +void SGX_Atlas_Wrap(in float inpCoord, out float outCoord) +{ + outCoord = frac(inpCoord); +} + +//----------------------------------------------------------------------------- +void SGX_Atlas_Clamp(in float inpCoord, out float outCoord) +{ + outCoord = saturate(inpCoord); +} +//----------------------------------------------------------------------------- +void SGX_Atlas_Mirror(in float inpCoord, out float outCoord) +{ + outCoord = (inpCoord + 1) * 0.5; + outCoord = abs(frac(outCoord) * 2 - 1); +} + +//----------------------------------------------------------------------------- +void SGX_Atlas_Border(in float inpCoord, out float outCoord) +{ + // + //The shader needs to check whether the original texcoord are beyond the 0,1 range. + //The shader attempts to do so without using if statments which are complicated for shaders + // + + //if texcoord is in the 0,1 range then check will equal 0, + //Otherwise it will equal the number 1 or greater + float check = step(inpCoord, 0) + step(1, inpCoord); + + //using the check value transport the value of the texcoord beyond the 0,1 range so it will + //recive the border color + outCoord = abs(inpCoord) + check * 2; +} \ No newline at end of file diff --git a/res/dist/media/RTShaderLib/SGXLib_TextureAtlas.glsl b/res/dist/media/RTShaderLib/SGXLib_TextureAtlas.glsl new file mode 100644 index 00000000000..69a3221a2fd --- /dev/null +++ b/res/dist/media/RTShaderLib/SGXLib_TextureAtlas.glsl @@ -0,0 +1,124 @@ +//----------------------------------------------------------------------------- +// Program Name: SGXLib_IntegratedPSSM +// Program Desc: Texture Atlas functions. +// Program Type: Vertex/Pixel shader +// Language: GLSL +//----------------------------------------------------------------------------- +#version 120 +#extension GL_ARB_shader_texture_lod : require + +float mipmapLevel(vec2 coords, vec2 texSize) +{ + coords = coords.xy * texSize; + vec2 dx = dFdx(coords.xy); + vec2 dy = dFdy(coords.xy); + float Px = length(dx); + float Py = length(dy); + float Pmax = max(Px, Py); + return log2(max(Pmax,1)); +} + + +//----------------------------------------------------------------------------- +void SGX_Atlas_Sample_Auto_Adjust(in sampler2D sample, + in vec2 origTexcoord, + in vec2 atlasTexcoord, + in vec4 textureData, + in vec2 imageSize, + out vec4 texel) +{ + // + // Most of the idea for this function has been taken from the code under the webpage: + // http://www.gamedev.net/topic/534149-solved-texture-seams-using-atlas-with-screenshots/ + + + // origTexcoord - original texture coordintates as received from the vertex buffer. + // atlasTexcoord - texture coordinates that have gone through on which different mathematical + // functions to simulate different texture addressing modes (wrap, mirror, clamp) + // textureData.xy - top left corner (in 0-1 units) where the needed texture in the texture atlas begins + // textureData.zw - width and height in power of 2 for the needed texture in the texture atlas + // imageSize - size of the image in pixels + // texel - [Output] The color of the pixel at the requested position + + vec2 startPos = textureData.xy; + + + // calculate the tileSize by using the power of 2 value + vec2 pwrs = textureData.zw; + + //Calculate the power of 2 size of the maximum avialable Mipmap + //Note: We limit the amount of available LODs to [actual number] - 2 + //as some atlas packaging tools do not include the last 2 LODs + //when packeging DXT format atlas textures. + float availableLODCount = min(pwrs.x,pwrs.y) - 2; + vec2 tileSize = pow(vec2(2.0,2.0),pwrs); + + // retrieve the mipmap level for this pixel clamped by the power of 2 value + float lod = clamp(mipmapLevel(origTexcoord, tileSize), 0, availableLODCount); + + vec2 relativeTileSize = tileSize / imageSize; + // get the width/height of the mip surface we've decided on + vec2 mipSize = pow(vec2(2.0,2.0), pwrs.xy - ceil(lod)); + + // compute the inverse fraction size for the tile + //vec2 lodSize = mipSize * imageSize / tileSize; + vec2 lodSizeInv = (relativeTileSize / mipSize); + //compute the new coordinates + //atlasTexcoord = atlasTexcoord * ((lodSize * (tileSize / imageSize) - 1.0) / lodSize) + (0.5 / lodSize) + startPos; + atlasTexcoord = atlasTexcoord * (relativeTileSize - lodSizeInv) + (0.5 * lodSizeInv) + startPos; + + //return the pixel from the correct mip surface of the atlas + texel = texture2DLod(sample, atlasTexcoord, lod); +} +//----------------------------------------------------------------------------- +void SGX_Atlas_Sample_Normal(in sampler2D sample, + in vec2 origTexcoord, + in vec2 atlasTexcoord, + in vec4 textureData, + in vec2 imageSize, + out vec4 texel) +{ + //texcoord contain: + // x = texture atlas u + // y = texture atlas v + // z = derivative of original u + // w = derivative of original v + atlasTexcoord = textureData.xy + (atlasTexcoord * pow(vec2(2.0,2.0),textureData.zw) / imageSize); + //texel = texture2DLod(sample, vec4(atlasTexcoord, 0,0)); + texel = texture2D(sample, atlasTexcoord); +} + +//----------------------------------------------------------------------------- +void SGX_Atlas_Wrap(in float inpCoord, out float outCoord) +{ + outCoord = fract(inpCoord); +} + +//----------------------------------------------------------------------------- +void SGX_Atlas_Clamp(in float inpCoord, out float outCoord) +{ + outCoord = clamp(inpCoord, 0.0, 1.0); +} +//----------------------------------------------------------------------------- +void SGX_Atlas_Mirror(in float inpCoord, out float outCoord) +{ + outCoord = (inpCoord + 1) * 0.5; + outCoord = abs(fract(outCoord) * 2 - 1); +} + +//----------------------------------------------------------------------------- +void SGX_Atlas_Border(in float inpCoord, out float outCoord) +{ + // + //The shader needs to check whether the original texcoord are beyond the 0,1 range. + //The shader attempts to do so without using if statments which are complicated for shaders + // + + //if texcoord is in the 0,1 range then check will equal 0, + //Otherwise it will equal the number 1 or greater + float check = step(inpCoord, 0) + step(1, inpCoord); + + //using the check value transport the value of the texcoord beyond the 0,1 range so it will + //recive the border color + outCoord = abs(inpCoord) + check * 2; +} \ No newline at end of file diff --git a/res/dist/media/RTShaderLib/SGXLib_TextureAtlas.glsles b/res/dist/media/RTShaderLib/SGXLib_TextureAtlas.glsles new file mode 100644 index 00000000000..2ae482240af --- /dev/null +++ b/res/dist/media/RTShaderLib/SGXLib_TextureAtlas.glsles @@ -0,0 +1,122 @@ +//----------------------------------------------------------------------------- +// Program Name: SGXLib_IntegratedPSSM +// Program Desc: Texture Atlas functions. +// Program Type: Vertex/Pixel shader +// Language: GLSLES +//----------------------------------------------------------------------------- + +float mipmapLevel(vec2 coords, vec2 texSize) +{ + coords = coords.xy * texSize; + vec2 dx = ddx(coords.xy); + vec2 dy = ddy(coords.xy); + float Px = length(dx); + float Py = length(dy); + float Pmax = max(Px, Py); + return log2(max(Pmax,1)); +} + + +//----------------------------------------------------------------------------- +void SGX_Atlas_Sample_Auto_Adjust(in sampler2D sample, + in vec2 origTexcoord, + in vec2 atlasTexcoord, + in vec4 textureData, + in vec2 imageSize, + out vec4 texel) +{ + // + // Most of the idea for this function has been taken from the code under the webpage: + // http://www.gamedev.net/topic/534149-solved-texture-seams-using-atlas-with-screenshots/ + + + // origTexcoord - original texture coordintates as received from the vertex buffer. + // atlasTexcoord - texture coordinates that have gone through on which different mathematical + // functions to simulate different texture addressing modes (wrap, mirror, clamp) + // textureData.xy - top left corner (in 0-1 units) where the needed texture in the texture atlas begins + // textureData.zw - width and height in power of 2 for the needed texture in the texture atlas + // imageSize - size of the image in pixels + // texel - [Output] The color of the pixel at the requested position + + vec2 startPos = textureData.xy; + + + // calculate the tileSize by using the power of 2 value + vec2 pwrs = textureData.zw; + + //Calculate the power of 2 size of the maximum avialable Mipmap + //Note: We limit the amount of available LODs to [actual number] - 2 + //as some atlas packaging tools do not include the last 2 LODs + //when packeging DXT format atlas textures. + float availableLODCount = min(pwrs.x,pwrs.y) - 2; + vec2 tileSize = pow(vec2(2.0,2.0),pwrs); + + // retrieve the mipmap level for this pixel clamped by the power of 2 value + float lod = clamp(mipmapLevel(origTexcoord, tileSize), 0, availableLODCount); + + vec2 relativeTileSize = tileSize / imageSize; + // get the width/height of the mip surface we've decided on + vec2 mipSize = pow(vec2(2.0,2.0), pwrs.xy - ceil(lod)); + + // compute the inverse fraction size for the tile + //vec2 lodSize = mipSize * imageSize / tileSize; + vec2 lodSizeInv = (relativeTileSize / mipSize); + //compute the new coordinates + //atlasTexcoord = atlasTexcoord * ((lodSize * (tileSize / imageSize) - 1.0) / lodSize) + (0.5 / lodSize) + startPos; + atlasTexcoord = atlasTexcoord * (relativeTileSize - lodSizeInv) + (0.5 * lodSizeInv) + startPos; + + //return the pixel from the correct mip surface of the atlas + texel = texture2DLod(sample, vec4(atlasTexcoord, 0, lod)); +} +//----------------------------------------------------------------------------- +void SGX_Atlas_Sample_Normal(in sampler2D sample, + in vec2 origTexcoord, + in vec2 atlasTexcoord, + in vec4 textureData, + in vec2 imageSize, + out vec4 texel) +{ + //texcoord contain: + // x = texture atlas u + // y = texture atlas v + // z = derivative of original u + // w = derivative of original v + atlasTexcoord = textureData.xy + (atlasTexcoord * pow(vec2(2.0,2.0),textureData.zw) / imageSize); + //texel = texture2DLod(sample, float4(atlasTexcoord, 0,0)); + texel = texture2D(sample, atlasTexcoord); +} + +//----------------------------------------------------------------------------- +void SGX_Atlas_Wrap(in float inpCoord, out float outCoord) +{ + outCoord = frac(inpCoord); +} + +//----------------------------------------------------------------------------- +void SGX_Atlas_Clamp(in float inpCoord, out float outCoord) +{ + outCoord = clamp(inpCoord, 0.0, 1.0); +} +//----------------------------------------------------------------------------- +void SGX_Atlas_Mirror(in float inpCoord, out float outCoord) +{ + outCoord = (inpCoord + 1) * 0.5; + outCoord = abs(frac(outCoord) * 2 - 1); +} + +//----------------------------------------------------------------------------- +void SGX_Atlas_Border(in float inpCoord, out float outCoord) +{ + // + //The shader needs to check whether the original texcoord are beyond the 0,1 range. + //The shader attempts to do so without using if statments which are complicated for shaders + // + + //if texcoord is in the 0,1 range then check will equal 0, + //Otherwise it will equal the number 1 or greater + float check = step(inpCoord, 0) + step(1, inpCoord); + + //using the check value transport the value of the texcoord beyond the 0,1 range so it will + //recive the border color + outCoord = abs(inpCoord) + check * 2; +} \ No newline at end of file diff --git a/res/dist/media/RTShaderLib/SGXLib_TextureAtlas.hlsl b/res/dist/media/RTShaderLib/SGXLib_TextureAtlas.hlsl new file mode 100644 index 00000000000..b8f062039f5 --- /dev/null +++ b/res/dist/media/RTShaderLib/SGXLib_TextureAtlas.hlsl @@ -0,0 +1,122 @@ +//----------------------------------------------------------------------------- +// Program Name: SGXLib_IntegratedPSSM +// Program Desc: Texture Atlas functions. +// Program Type: Vertex/Pixel shader +// Language: HLSL +//----------------------------------------------------------------------------- + +float mipmapLevel(float2 coords, float2 texSize) +{ + coords = coords.xy * texSize; + float2 dx = ddx(coords.xy); + float2 dy = ddy(coords.xy); + float Px = length(dx); + float Py = length(dy); + float Pmax = max(Px, Py); + return log2(max(Pmax,1)); +} + + +//----------------------------------------------------------------------------- +void SGX_Atlas_Sample_Auto_Adjust(in sampler2D sample, + in float2 origTexcoord, + in float2 atlasTexcoord, + in float4 textureData, + in float2 imageSize, + out float4 texel) +{ + // + // Most of the idea for this function has been taken from the code under the webpage: + // http://www.gamedev.net/topic/534149-solved-texture-seams-using-atlas-with-screenshots/ + + + // origTexcoord - original texture coordintates as received from the vertex buffer. + // atlasTexcoord - texture coordinates that have gone through on which different mathematical + // functions to simulate different texture addressing modes (wrap, mirror, clamp) + // textureData.xy - top left corner (in 0-1 units) where the needed texture in the texture atlas begins + // textureData.zw - width and height in power of 2 for the needed texture in the texture atlas + // imageSize - size of the image in pixels + // texel - [Output] The color of the pixel at the requested position + + float2 startPos = textureData.xy; + + + // calculate the tileSize by using the power of 2 value + float2 pwrs = textureData.zw; + + //Calculate the power of 2 size of the maximum avialable Mipmap + //Note: We limit the amount of available LODs to [actual number] - 2 + //as some atlas packaging tools do not include the last 2 LODs + //when packeging DXT format atlas textures. + float availableLODCount = min(pwrs.x,pwrs.y) - 2; + float2 tileSize = pow(float2(2.0,2.0),pwrs); + + // retrieve the mipmap level for this pixel clamped by the power of 2 value + float lod = clamp(mipmapLevel(origTexcoord, tileSize), 0, availableLODCount); + + float2 relativeTileSize = tileSize / imageSize; + // get the width/height of the mip surface we've decided on + float2 mipSize = pow(float2(2.0,2.0), pwrs.xy - ceil(lod)); + + // compute the inverse fraction size for the tile + //float2 lodSize = mipSize * imageSize / tileSize; + float2 lodSizeInv = (relativeTileSize / mipSize); + //compute the new coordinates + //atlasTexcoord = atlasTexcoord * ((lodSize * (tileSize / imageSize) - 1.0) / lodSize) + (0.5 / lodSize) + startPos; + atlasTexcoord = atlasTexcoord * (relativeTileSize - lodSizeInv) + (0.5 * lodSizeInv) + startPos; + + //return the pixel from the correct mip surface of the atlas + texel = tex2Dlod(sample, float4(atlasTexcoord, 0, lod)); +} +//----------------------------------------------------------------------------- +void SGX_Atlas_Sample_Normal(in sampler2D sample, + in float2 origTexcoord, + in float2 atlasTexcoord, + in float4 textureData, + in float2 imageSize, + out float4 texel) +{ + //texcoord contain: + // x = texture atlas u + // y = texture atlas v + // z = derivative of original u + // w = derivative of original v + atlasTexcoord = textureData.xy + (atlasTexcoord * pow(float2(2.0,2.0),textureData.zw) / imageSize); + //texel = tex2Dlod(sample, float4(atlasTexcoord, 0,0)); + texel = tex2D(sample, atlasTexcoord); +} + +//----------------------------------------------------------------------------- +void SGX_Atlas_Wrap(in float inpCoord, out float outCoord) +{ + outCoord = frac(inpCoord); +} + +//----------------------------------------------------------------------------- +void SGX_Atlas_Clamp(in float inpCoord, out float outCoord) +{ + outCoord = saturate(inpCoord); +} +//----------------------------------------------------------------------------- +void SGX_Atlas_Mirror(in float inpCoord, out float outCoord) +{ + outCoord = (inpCoord + 1) * 0.5; + outCoord = abs(frac(outCoord) * 2 - 1); +} + +//----------------------------------------------------------------------------- +void SGX_Atlas_Border(in float inpCoord, out float outCoord) +{ + // + //The shader needs to check whether the original texcoord are beyond the 0,1 range. + //The shader attempts to do so without using if statments which are complicated for shaders + // + + //if texcoord is in the 0,1 range then check will equal 0, + //Otherwise it will equal the number 1 or greater + float check = step(inpCoord, 0) + step(1, inpCoord); + + //using the check value transport the value of the texcoord beyond the 0,1 range so it will + //recive the border color + outCoord = abs(inpCoord) + check * 2; +} \ No newline at end of file diff --git a/res/dist/media/RTShaderLib/SampleLib_InstancedViewports.cg b/res/dist/media/RTShaderLib/SampleLib_InstancedViewports.cg new file mode 100644 index 00000000000..35bde92edab --- /dev/null +++ b/res/dist/media/RTShaderLib/SampleLib_InstancedViewports.cg @@ -0,0 +1,76 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Transform the output position to the current "monitor" +//----------------------------------------------------------------------------- + +void SGX_InstancedViewportsTransform( + in float4 i_position, + in float4x4 i_worldViewMatrix, + in float4x4 i_projectionMatrix, + in float4 i_viewportOffsetMatrixR0, + in float4 i_viewportOffsetMatrixR1, + in float4 i_viewportOffsetMatrixR2, + in float4 i_viewportOffsetMatrixR3, + in float2 i_monitorsCount, + in float4 i_monitorIndex, + out float4 o_position) + { + o_position = mul(i_worldViewMatrix, i_position); + float4x4 viewportOffset = float4x4(i_viewportOffsetMatrixR0, + i_viewportOffsetMatrixR1, + i_viewportOffsetMatrixR2, + i_viewportOffsetMatrixR3 + ); + o_position = mul(viewportOffset, o_position); + o_position = mul(i_projectionMatrix, o_position); + float2 monitorIndexNorm =i_monitorIndex.xy - ((i_monitorsCount - 1.0)/ 2.0) ; + o_position.xy = + (o_position.xy + (o_position.w * monitorIndexNorm)*2.0) / i_monitorsCount ; + }; + +//----------------------------------------------------------------------------- +// Discard any pixel that is outside the bounds of the current "monitor" +//----------------------------------------------------------------------------- + +void SGX_InstancedViewportsDiscardOutOfBounds( + in float2 i_monitorsCount, + in float4 i_monitorIndex, + in float4 i_positionProjectiveSpace) +{ + float2 boxedXY = i_positionProjectiveSpace.xy / (i_positionProjectiveSpace.w * 2); + boxedXY = (boxedXY + 0.5) * i_monitorsCount; + float2 middleMonitor = ((i_monitorIndex.xy + 0.5)); + + boxedXY = abs(boxedXY - middleMonitor); + float maxM = max(boxedXY.x,boxedXY.y); + if (maxM >= 0.5) + { + discard; + } +} \ No newline at end of file diff --git a/res/dist/media/RTShaderLib/SampleLib_InstancedViewports.glsl b/res/dist/media/RTShaderLib/SampleLib_InstancedViewports.glsl new file mode 100644 index 00000000000..80dfff59244 --- /dev/null +++ b/res/dist/media/RTShaderLib/SampleLib_InstancedViewports.glsl @@ -0,0 +1,93 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Transform the output position to the current "monitor" +//----------------------------------------------------------------------------- + +void SGX_InstancedViewportsTransform( + in vec4 i_position, + in mat4 i_worldViewMatrix, + in mat4 i_projectionMatrix, + in vec4 i_viewportOffsetMatrixR0, + in vec4 i_viewportOffsetMatrixR1, + in vec4 i_viewportOffsetMatrixR2, + in vec4 i_viewportOffsetMatrixR3, + in vec2 i_monitorsCount, + in vec4 i_monitorIndex, + out vec4 o_position) + { + o_position = i_worldViewMatrix * i_position; + mat4 viewportOffset; + viewportOffset[0][0] = i_viewportOffsetMatrixR0.x; + viewportOffset[1][0] = i_viewportOffsetMatrixR0.y; + viewportOffset[2][0] = i_viewportOffsetMatrixR0.z; + viewportOffset[3][0] = i_viewportOffsetMatrixR0.w; + + viewportOffset[0][1] = i_viewportOffsetMatrixR1.x; + viewportOffset[1][1] = i_viewportOffsetMatrixR1.y; + viewportOffset[2][1] = i_viewportOffsetMatrixR1.z; + viewportOffset[3][1] = i_viewportOffsetMatrixR1.w; + + viewportOffset[0][2] = i_viewportOffsetMatrixR2.x; + viewportOffset[1][2] = i_viewportOffsetMatrixR2.y; + viewportOffset[2][2] = i_viewportOffsetMatrixR2.z; + viewportOffset[3][2] = i_viewportOffsetMatrixR2.w; + + viewportOffset[0][3] = i_viewportOffsetMatrixR3.x; + viewportOffset[1][3] = i_viewportOffsetMatrixR3.y; + viewportOffset[2][3] = i_viewportOffsetMatrixR3.z; + viewportOffset[3][3] = i_viewportOffsetMatrixR3.w; + + o_position = viewportOffset * o_position; + o_position = i_projectionMatrix * o_position; + + vec2 monitorIndexNorm = i_monitorIndex.xy - ((i_monitorsCount - 1.0)/2.0); + o_position.xy = + (o_position.xy + (o_position.w * monitorIndexNorm)*2.0) / i_monitorsCount; + } + +//----------------------------------------------------------------------------- +// Discard any pixel that is outside the bounds of the current "monitor" +//----------------------------------------------------------------------------- + +void SGX_InstancedViewportsDiscardOutOfBounds( + in vec2 i_monitorsCount, + in vec4 i_monitorIndex, + in vec4 i_positionProjectiveSpace) +{ + vec2 boxedXY = i_positionProjectiveSpace.xy / (i_positionProjectiveSpace.w * 2.0); + boxedXY = (boxedXY + 0.5) * i_monitorsCount; + vec2 middleMonitor = i_monitorIndex.xy + 0.5; + + boxedXY = abs(boxedXY - middleMonitor); + float maxM = max(boxedXY.x,boxedXY.y); + if (maxM >= 0.5) + { + discard; + } +} \ No newline at end of file diff --git a/res/dist/media/RTShaderLib/SampleLib_InstancedViewports.hlsl b/res/dist/media/RTShaderLib/SampleLib_InstancedViewports.hlsl new file mode 100644 index 00000000000..35bde92edab --- /dev/null +++ b/res/dist/media/RTShaderLib/SampleLib_InstancedViewports.hlsl @@ -0,0 +1,76 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Transform the output position to the current "monitor" +//----------------------------------------------------------------------------- + +void SGX_InstancedViewportsTransform( + in float4 i_position, + in float4x4 i_worldViewMatrix, + in float4x4 i_projectionMatrix, + in float4 i_viewportOffsetMatrixR0, + in float4 i_viewportOffsetMatrixR1, + in float4 i_viewportOffsetMatrixR2, + in float4 i_viewportOffsetMatrixR3, + in float2 i_monitorsCount, + in float4 i_monitorIndex, + out float4 o_position) + { + o_position = mul(i_worldViewMatrix, i_position); + float4x4 viewportOffset = float4x4(i_viewportOffsetMatrixR0, + i_viewportOffsetMatrixR1, + i_viewportOffsetMatrixR2, + i_viewportOffsetMatrixR3 + ); + o_position = mul(viewportOffset, o_position); + o_position = mul(i_projectionMatrix, o_position); + float2 monitorIndexNorm =i_monitorIndex.xy - ((i_monitorsCount - 1.0)/ 2.0) ; + o_position.xy = + (o_position.xy + (o_position.w * monitorIndexNorm)*2.0) / i_monitorsCount ; + }; + +//----------------------------------------------------------------------------- +// Discard any pixel that is outside the bounds of the current "monitor" +//----------------------------------------------------------------------------- + +void SGX_InstancedViewportsDiscardOutOfBounds( + in float2 i_monitorsCount, + in float4 i_monitorIndex, + in float4 i_positionProjectiveSpace) +{ + float2 boxedXY = i_positionProjectiveSpace.xy / (i_positionProjectiveSpace.w * 2); + boxedXY = (boxedXY + 0.5) * i_monitorsCount; + float2 middleMonitor = ((i_monitorIndex.xy + 0.5)); + + boxedXY = abs(boxedXY - middleMonitor); + float maxM = max(boxedXY.x,boxedXY.y); + if (maxM >= 0.5) + { + discard; + } +} \ No newline at end of file diff --git a/res/dist/media/RTShaderLib/SampleLib_ReflectionMap.cg b/res/dist/media/RTShaderLib/SampleLib_ReflectionMap.cg new file mode 100644 index 00000000000..b69baf56c03 --- /dev/null +++ b/res/dist/media/RTShaderLib/SampleLib_ReflectionMap.cg @@ -0,0 +1,62 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + + +//----------------------------------------------------------------------------- +// Simple masked reflection map effect. +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +void SGX_ApplyReflectionMap(in sampler2D maskSampler, + in float2 maskSamplerTexCoord, + in sampler2D reflectionSampler, + in float2 reflectionSamplerTexCoord, + in float3 baseColor, + in float reflectionPower, + out float3 vOut) +{ + float3 maskTexel = tex2D(maskSampler, maskSamplerTexCoord).xyz; + float3 reflectionTexel = tex2D(reflectionSampler, reflectionSamplerTexCoord).xyz; + + vOut = baseColor + reflectionTexel.xyz*maskTexel.xyz*reflectionPower; +} + +//----------------------------------------------------------------------------- +void SGX_ApplyReflectionMap(in sampler2D maskSampler, + in float2 maskSamplerTexCoord, + in samplerCUBE reflectionSampler, + in float3 reflectionSamplerTexCoord, + in float3 baseColor, + in float reflectionPower, + out float3 vOut) +{ + float3 maskTexel = tex2D(maskSampler, maskSamplerTexCoord).xyz; + float3 reflectionTexel = texCUBE(reflectionSampler, reflectionSamplerTexCoord).xyz; + + vOut = baseColor + reflectionTexel.xyz*maskTexel.xyz*reflectionPower; +} + \ No newline at end of file diff --git a/res/dist/media/RTShaderLib/SampleLib_ReflectionMap.glsl b/res/dist/media/RTShaderLib/SampleLib_ReflectionMap.glsl new file mode 100644 index 00000000000..028711446ae --- /dev/null +++ b/res/dist/media/RTShaderLib/SampleLib_ReflectionMap.glsl @@ -0,0 +1,65 @@ +#version 120 +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + + +//----------------------------------------------------------------------------- +// Simple masked reflection map effect. +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +void SGX_ApplyReflectionMap(in sampler2D maskSampler, + in vec2 maskSamplerTexCoord, + in sampler2D reflectionSampler, + in vec2 reflectionSamplerTexCoord, + in vec3 baseColor, + in float reflectionPower, + out vec3 vOut) +{ + vec3 maskTexel = texture2D(maskSampler, maskSamplerTexCoord).xyz; + reflectionSamplerTexCoord.y = -reflectionSamplerTexCoord.y; // Hack for gl + vec3 reflectionTexel = texture2D(reflectionSampler, reflectionSamplerTexCoord).xyz; + + vOut = baseColor + reflectionTexel.xyz*maskTexel.xyz*reflectionPower; +} + +//----------------------------------------------------------------------------- +void SGX_ApplyReflectionMap(in sampler2D maskSampler, + in vec2 maskSamplerTexCoord, + in samplerCube reflectionSampler, + in vec3 reflectionSamplerTexCoord, + in vec3 baseColor, + in float reflectionPower, + out vec3 vOut) +{ + vec3 maskTexel = texture2D(maskSampler, maskSamplerTexCoord).xyz; + reflectionSamplerTexCoord.z = -reflectionSamplerTexCoord.z; // Hack for gl + vec3 reflectionTexel = textureCube(reflectionSampler, reflectionSamplerTexCoord).xyz; + + vOut = baseColor + reflectionTexel.xyz*maskTexel.xyz*reflectionPower; +} + diff --git a/res/dist/media/RTShaderLib/SampleLib_ReflectionMap.glsles b/res/dist/media/RTShaderLib/SampleLib_ReflectionMap.glsles new file mode 100644 index 00000000000..ef9e64a5b43 --- /dev/null +++ b/res/dist/media/RTShaderLib/SampleLib_ReflectionMap.glsles @@ -0,0 +1,67 @@ +#version 100 +precision highp float; +precision highp int; +precision lowp sampler2D; +precision lowp samplerCube; +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + +//----------------------------------------------------------------------------- +// Simple masked reflection map effect. +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +void SGX_ApplyReflectionMap(in sampler2D maskSampler, + in vec2 maskSamplerTexCoord, + in sampler2D reflectionSampler, + in vec2 reflectionSamplerTexCoord, + in vec3 baseColor, + in float reflectionPower, + out vec3 vOut) +{ + vec3 maskTexel = texture2D(maskSampler, maskSamplerTexCoord).xyz; + reflectionSamplerTexCoord.y = -reflectionSamplerTexCoord.y; // Hack for gl + vec3 reflectionTexel = texture2D(reflectionSampler, reflectionSamplerTexCoord).xyz; + + vOut = baseColor + reflectionTexel.xyz * maskTexel.xyz * reflectionPower; +} + +//----------------------------------------------------------------------------- +void SGX_ApplyReflectionMap(in sampler2D maskSampler, + in vec2 maskSamplerTexCoord, + in samplerCube reflectionSampler, + in vec3 reflectionSamplerTexCoord, + in vec3 baseColor, + in float reflectionPower, + out vec3 vOut) +{ + vec3 maskTexel = texture2D(maskSampler, maskSamplerTexCoord).xyz; + reflectionSamplerTexCoord.z = -reflectionSamplerTexCoord.z; // Hack for gl + vec3 reflectionTexel = textureCube(reflectionSampler, reflectionSamplerTexCoord).xyz; + + vOut = baseColor + reflectionTexel.xyz * maskTexel.xyz * reflectionPower; +} diff --git a/res/dist/media/RTShaderLib/SampleLib_ReflectionMap.hlsl b/res/dist/media/RTShaderLib/SampleLib_ReflectionMap.hlsl new file mode 100644 index 00000000000..b69baf56c03 --- /dev/null +++ b/res/dist/media/RTShaderLib/SampleLib_ReflectionMap.hlsl @@ -0,0 +1,62 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org + +Copyright (c) 2000-2012 Torus Knot Software Ltd +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ + + +//----------------------------------------------------------------------------- +// Simple masked reflection map effect. +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +void SGX_ApplyReflectionMap(in sampler2D maskSampler, + in float2 maskSamplerTexCoord, + in sampler2D reflectionSampler, + in float2 reflectionSamplerTexCoord, + in float3 baseColor, + in float reflectionPower, + out float3 vOut) +{ + float3 maskTexel = tex2D(maskSampler, maskSamplerTexCoord).xyz; + float3 reflectionTexel = tex2D(reflectionSampler, reflectionSamplerTexCoord).xyz; + + vOut = baseColor + reflectionTexel.xyz*maskTexel.xyz*reflectionPower; +} + +//----------------------------------------------------------------------------- +void SGX_ApplyReflectionMap(in sampler2D maskSampler, + in float2 maskSamplerTexCoord, + in samplerCUBE reflectionSampler, + in float3 reflectionSamplerTexCoord, + in float3 baseColor, + in float reflectionPower, + out float3 vOut) +{ + float3 maskTexel = tex2D(maskSampler, maskSamplerTexCoord).xyz; + float3 reflectionTexel = texCUBE(reflectionSampler, reflectionSamplerTexCoord).xyz; + + vOut = baseColor + reflectionTexel.xyz*maskTexel.xyz*reflectionPower; +} + \ No newline at end of file diff --git a/res/dist/media/RTShaderLib/cache/dummy.txt b/res/dist/media/RTShaderLib/cache/dummy.txt new file mode 100644 index 00000000000..5bad61fd9af --- /dev/null +++ b/res/dist/media/RTShaderLib/cache/dummy.txt @@ -0,0 +1 @@ +This is a dummy file used to create this directory in the mercurial source control. \ No newline at end of file diff --git a/res/dist/media/RTShaderLib/materials/DualQuaternionSkinning_Shadow.cg b/res/dist/media/RTShaderLib/materials/DualQuaternionSkinning_Shadow.cg new file mode 100644 index 00000000000..9acf2e30c48 --- /dev/null +++ b/res/dist/media/RTShaderLib/materials/DualQuaternionSkinning_Shadow.cg @@ -0,0 +1,292 @@ +float2x4 blendTwoWeights(float4 blendWgt, float4 blendIdx, float2x4 dualQuaternions[24]) +{ + float2x4 blendDQ = blendWgt.x*dualQuaternions[blendIdx.x]; + blendDQ += blendWgt.y*dualQuaternions[blendIdx.y]; + + return blendDQ; +} + +float2x4 blendTwoWeightsAntipod(float4 blendWgt, float4 blendIdx, float2x4 dualQuaternions[24]) +{ + float2x4 dq0 = dualQuaternions[blendIdx.x]; + float2x4 dq1 = dualQuaternions[blendIdx.y]; + + //Accurate antipodality handling. For speed increase, remove the following line, + //though, the results will only be valid for rotations less than 180 degrees. + if (dot(dq0[0], dq1[0]) < 0.0) dq1 *= -1.0; + + float2x4 blendDQ = blendWgt.x*dq0; + blendDQ += blendWgt.y*dq1; + + return blendDQ; +} + +float2x4 blendThreeWeightsAntipod(float4 blendWgt, float4 blendIdx, float2x4 dualQuaternions[24]) +{ + float2x4 dq0 = dualQuaternions[blendIdx.x]; + float2x4 dq1 = dualQuaternions[blendIdx.y]; + float2x4 dq2 = dualQuaternions[blendIdx.z]; + + //Accurate antipodality handling. For speed increase, remove the following line, + //though, the results will only be valid for rotations less than 180 degrees. + if (dot(dq0[0], dq1[0]) < 0.0) dq1 *= -1.0; + if (dot(dq0[0], dq2[0]) < 0.0) dq2 *= -1.0; + + float2x4 blendDQ = blendWgt.x*dq0; + blendDQ += blendWgt.y*dq1; + blendDQ += blendWgt.z*dq2; + + return blendDQ; +} + +float2x4 blendFourWeightsAntipod(float4 blendWgt, float4 blendIdx, float2x4 dualQuaternions[24]) +{ + float2x4 dq0 = dualQuaternions[blendIdx.x]; + float2x4 dq1 = dualQuaternions[blendIdx.y]; + float2x4 dq2 = dualQuaternions[blendIdx.z]; + float2x4 dq3 = dualQuaternions[blendIdx.w]; + + //Accurate antipodality handling. For speed increase, remove the following line, + //though, the results will only be valid for rotations less than 180 degrees. + if (dot(dq0[0], dq1[0]) < 0.0) dq1 *= -1.0; + if (dot(dq0[0], dq2[0]) < 0.0) dq2 *= -1.0; + if (dot(dq0[0], dq3[0]) < 0.0) dq3 *= -1.0; + + float2x4 blendDQ = blendWgt.x*dq0; + blendDQ += blendWgt.y*dq1; + blendDQ += blendWgt.z*dq2; + blendDQ += blendWgt.w*dq3; + + return blendDQ; +} + +float3 calculateBlendPosition(float4 position, float2x4 blendDQ) +{ + float3 blendPosition = position.xyz + 2.0*cross(blendDQ[0].yzw, cross(blendDQ[0].yzw, position.xyz) + blendDQ[0].x*position.xyz); + float3 trans = 2.0*(blendDQ[0].x*blendDQ[1].yzw - blendDQ[1].x*blendDQ[0].yzw + cross(blendDQ[0].yzw, blendDQ[1].yzw)); + blendPosition += trans; + + return blendPosition; +} + +float3 calculateBlendNormal(float3 normal, float2x4 blendDQ) +{ + return normal + 2.0*cross(blendDQ[0].yzw, cross(blendDQ[0].yzw, normal) + blendDQ[0].x*normal); +} + +float3x3 adjointTransposeMatrix(float3x3 M) +{ + float3x3 atM; + atM._m00 = M._m22 * M._m11 - M._m12 * M._m21; + atM._m01 = M._m12 * M._m20 - M._m10 * M._m22; + atM._m02 = M._m10 * M._m21 - M._m20 * M._m11; + + atM._m10 = M._m02 * M._m21 - M._m22 * M._m01; + atM._m11 = M._m22 * M._m00 - M._m02 * M._m20; + atM._m12 = M._m20 * M._m01 - M._m00 * M._m21; + + atM._m20 = M._m12 * M._m01 - M._m02 * M._m11; + atM._m21 = M._m10 * M._m02 - M._m12 * M._m00; + atM._m22 = M._m00 * M._m11 - M._m10 * M._m01; + + return atM; +} + +void shadow_caster_dq_vs( + float4 position : POSITION, + out float4 oPosition : POSITION, + out float2 oDepthInfo : TEXCOORD0, + + uniform float4x4 wvpMatrix) +{ + // output position. + oPosition = mul(wvpMatrix, position); + + // depth info for the fragment. + oDepthInfo.x = oPosition.z; + oDepthInfo.y = oPosition.w; +} + +void shadow_caster_dq_ps( + in float4 colour : COLOR, + out float4 oColour : COLOR) +{ + oColour = colour; +} + +//Shadow caster pass +void shadow_caster_dq_skinning_1weight_vs( + float4 position : POSITION, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + out float4 oPosition : POSITION, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float2x4 worldDualQuaternion2x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 ambient) +{ + float2x4 blendDQ = blendWgt.x * worldDualQuaternion2x4Array[blendIdx.x]; + + float len = length(blendDQ[0]); + blendDQ /= len; + + float3 blendPosition = calculateBlendPosition(position, blendDQ); + + // view / projection + oPosition = mul(viewProjectionMatrix, float4(blendPosition, 1.0)); + + colour = ambient; +} + +void shadow_caster_dq_skinning_2weight_vs( + float4 position : POSITION, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + out float4 oPosition : POSITION, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float2x4 worldDualQuaternion2x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 ambient) +{ + float2x4 blendDQ = blendTwoWeightsAntipod(blendWgt, blendIdx, worldDualQuaternion2x4Array); + + float len = length(blendDQ[0]); + blendDQ /= len; + + float3 blendPosition = calculateBlendPosition(position, blendDQ); + + // view / projection + oPosition = mul(viewProjectionMatrix, float4(blendPosition, 1.0)); + + colour = ambient; +} + +void shadow_caster_dq_skinning_3weight_vs( + float4 position : POSITION, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + out float4 oPosition : POSITION, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float2x4 worldDualQuaternion2x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 ambient) +{ + float2x4 blendDQ = blendThreeWeightsAntipod(blendWgt, blendIdx, worldDualQuaternion2x4Array); + + float len = length(blendDQ[0]); + blendDQ /= len; + + float3 blendPosition = calculateBlendPosition(position, blendDQ); + + // view / projection + oPosition = mul(viewProjectionMatrix, float4(blendPosition, 1.0)); + + colour = ambient; +} + +void shadow_caster_dq_skinning_4weight_vs( + float4 position : POSITION, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + out float4 oPosition : POSITION, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float2x4 worldDualQuaternion2x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 ambient) +{ + float2x4 blendDQ = blendFourWeightsAntipod(blendWgt, blendIdx, worldDualQuaternion2x4Array); + + float len = length(blendDQ[0]); + blendDQ /= len; + + float3 blendPosition = calculateBlendPosition(position, blendDQ); + + // view / projection + oPosition = mul(viewProjectionMatrix, float4(blendPosition, 1.0)); + + colour = ambient; +} + + +//Two-phase skinning shadow caster pass +void shadow_caster_dq_skinning_1weight_twophase_vs( + float4 position : POSITION, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + out float4 oPosition : POSITION, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float2x4 worldDualQuaternion2x4Array[24], + uniform float3x4 scaleM[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 ambient) +{ + //First phase - applies scaling and shearing: + float3x4 blendS = blendWgt.x*scaleM[blendIdx.x]; + + float3 pass1_position = mul(blendS, position); + + //Second phase + float2x4 blendDQ = blendWgt.x * worldDualQuaternion2x4Array[blendIdx.x]; + + float len = length(blendDQ[0]); + blendDQ /= len; + + float3 blendPosition = calculateBlendPosition(float4(pass1_position, 1.0), blendDQ); + + // view / projection + oPosition = mul(viewProjectionMatrix, float4(blendPosition, 1.0)); + + colour = ambient; +} + +//Two-phase skinning shadow caster pass +void shadow_caster_dq_skinning_2weight_twophase_vs( + float4 position : POSITION, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + out float4 oPosition : POSITION, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float2x4 worldDualQuaternion2x4Array[24], + uniform float3x4 scaleM[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 ambient) +{ + //First phase - applies scaling and shearing: + float3x4 blendS = blendWgt.x*scaleM[blendIdx.x]; + blendS += blendWgt.y*scaleM[blendIdx.y]; + + float3 pass1_position = mul(blendS, position); + + //Second phase + float2x4 blendDQ = blendTwoWeightsAntipod(blendWgt, blendIdx, worldDualQuaternion2x4Array); + + float len = length(blendDQ[0]); + blendDQ /= len; + + float3 blendPosition = calculateBlendPosition(float4(pass1_position, 1.0), blendDQ); + + // view / projection + oPosition = mul(viewProjectionMatrix, float4(blendPosition, 1.0)); + + colour = ambient; +} + + diff --git a/res/dist/media/RTShaderLib/materials/DualQuaternionSkinning_Shadow.material b/res/dist/media/RTShaderLib/materials/DualQuaternionSkinning_Shadow.material new file mode 100644 index 00000000000..fd94953a14e --- /dev/null +++ b/res/dist/media/RTShaderLib/materials/DualQuaternionSkinning_Shadow.material @@ -0,0 +1,384 @@ +/////////////////////////////////////////////////////////////////////////// +/// Declare shaders for casters +/////////////////////////////////////////////////////////////////////////// + +vertex_program Ogre/RTShader/shadow_caster_dq_skinning_1weight_vs unified +{ + delegate Ogre/RTShader/shadow_caster_dq_skinning_1weight_vs_glsl + delegate Ogre/RTShader/shadow_caster_dq_skinning_1weight_vs_cg +} + +vertex_program Ogre/RTShader/shadow_caster_dq_skinning_2weight_vs unified +{ + delegate Ogre/RTShader/shadow_caster_dq_skinning_2weight_vs_glsl + delegate Ogre/RTShader/shadow_caster_dq_skinning_2weight_vs_cg +} + +vertex_program Ogre/RTShader/shadow_caster_dq_skinning_3weight_vs unified +{ + delegate Ogre/RTShader/shadow_caster_dq_skinning_3weight_vs_glsl + delegate Ogre/RTShader/shadow_caster_dq_skinning_3weight_vs_cg +} + +vertex_program Ogre/RTShader/shadow_caster_dq_skinning_4weight_vs unified +{ + delegate Ogre/RTShader/shadow_caster_dq_skinning_4weight_vs_glsl + delegate Ogre/RTShader/shadow_caster_dq_skinning_4weight_vs_cg +} +vertex_program Ogre/RTShader/shadow_caster_dq_skinning_1weight_twophase_vs unified +{ + delegate Ogre/RTShader/shadow_caster_dq_skinning_1weight_twophase_vs_cg +} + +vertex_program Ogre/RTShader/shadow_caster_dq_skinning_2weight_twophase_vs unified +{ + delegate Ogre/RTShader/shadow_caster_dq_skinning_2weight_twophase_vs_cg +} + +vertex_program Ogre/RTShader/shadow_caster_dq_skinning_3weight_twophase_vs unified +{ + delegate Ogre/RTShader/shadow_caster_dq_skinning_3weight_twophase_vs_cg +} + +vertex_program Ogre/RTShader/shadow_caster_dq_skinning_4weight_twophase_vs unified +{ + delegate Ogre/RTShader/shadow_caster_dq_skinning_4weight_twophase_vs_cg +} + +fragment_program Ogre/RTShader/shadow_caster_dq_ps unified +{ + delegate Ogre/RTShader/shadow_caster_dq_ps_glsl + delegate Ogre/RTShader/shadow_caster_dq_ps_cg +} + +// declare the fragment shader (GLSL for the language) +fragment_program Ogre/RTShader/shadow_caster_dq_ps_glsl glsl +{ + source DualQuaternionSkinning_ShadowPassThrough_ps.glsl +} + +// declare the fragment shader (CG for the language) +fragment_program Ogre/RTShader/shadow_caster_dq_ps_cg cg +{ + // source file + source DualQuaternionSkinning_Shadow.cg + // will run on pixel shader 2.0+ + profiles ps_2_0 arbfp1 + // entry function + entry_point shadow_caster_dq_ps + + default_params + { + + } +} + +vertex_program Ogre/RTShader/DualQuaternionHardwareSkinningTwoWeightsCommon glsl +{ + source DualQuaternion_Common.glsl +} + +vertex_program Ogre/RTShader/shadow_caster_dq_skinning_1weight_vs_glsl glsl +{ + source DualQuaternionSkinning_ShadowOneWeight.glsl + attach Ogre/RTShader/DualQuaternionHardwareSkinningTwoWeightsCommon + includes_skeletal_animation true + + default_params + { + param_named_auto worldDualQuaternion2x4Array world_dualquaternion_array_2x4 + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto ambient ambient_light_colour + } +} + +vertex_program Ogre/RTShader/shadow_caster_dq_skinning_2weight_vs_glsl glsl +{ + source DualQuaternionSkinning_ShadowTwoWeights.glsl + attach Ogre/RTShader/DualQuaternionHardwareSkinningTwoWeightsCommon + includes_skeletal_animation true + + default_params + { + param_named_auto worldDualQuaternion2x4Array world_dualquaternion_array_2x4 + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto ambient ambient_light_colour + } +} + +vertex_program Ogre/RTShader/shadow_caster_dq_skinning_3weight_vs_glsl glsl +{ + source DualQuaternionSkinning_ShadowThreeWeights.glsl + attach Ogre/RTShader/DualQuaternionHardwareSkinningTwoWeightsCommon + includes_skeletal_animation true + + default_params + { + param_named_auto worldDualQuaternion2x4Array world_dualquaternion_array_2x4 + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto ambient ambient_light_colour + } +} + +vertex_program Ogre/RTShader/shadow_caster_dq_skinning_4weight_vs_glsl glsl +{ + source DualQuaternionSkinning_ShadowFourWeights.glsl + attach Ogre/RTShader/DualQuaternionHardwareSkinningTwoWeightsCommon + includes_skeletal_animation true + + default_params + { + param_named_auto worldDualQuaternion2x4Array world_dualquaternion_array_2x4 + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto ambient ambient_light_colour + } +} + +vertex_program Ogre/RTShader/shadow_caster_dq_skinning_1weight_vs_cg cg +{ + source DualQuaternionSkinning_Shadow.cg + //will run on 3 to accommodate the amount of registers + profiles vs_3_0 vp40 arbvp1 + entry_point shadow_caster_dq_skinning_1weight_vs + + default_params + { + param_named_auto worldDualQuaternion2x4Array world_dualquaternion_array_2x4 + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto ambient ambient_light_colour + } +} + +vertex_program Ogre/RTShader/shadow_caster_dq_skinning_2weight_vs_cg cg +{ + source DualQuaternionSkinning_Shadow.cg + //will run on 3 to accommodate the amount of registers + profiles vs_3_0 vp40 arbvp1 + entry_point shadow_caster_dq_skinning_2weight_vs + includes_skeletal_animation true + + default_params + { + param_named_auto worldDualQuaternion2x4Array world_dualquaternion_array_2x4 + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto ambient ambient_light_colour + } +} + +vertex_program Ogre/RTShader/shadow_caster_dq_skinning_3weight_vs_cg cg +{ + source DualQuaternionSkinning_Shadow.cg + //will run on 3 to accommodate the amount of registers + profiles vs_3_0 vp40 arbvp1 + entry_point shadow_caster_dq_skinning_3weight_vs + + default_params + { + param_named_auto worldDualQuaternion2x4Array world_dualquaternion_array_2x4 + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto ambient ambient_light_colour + } +} + + +vertex_program Ogre/RTShader/shadow_caster_dq_skinning_4weight_vs_cg cg +{ + source DualQuaternionSkinning_Shadow.cg + //will run on 3 to accommodate the amount of registers + profiles vs_3_0 vp40 arbvp1 + entry_point shadow_caster_dq_skinning_4weight_vs + + default_params + { + param_named_auto worldDualQuaternion2x4Array world_dualquaternion_array_2x4 + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto ambient ambient_light_colour + } +} + +vertex_program Ogre/RTShader/shadow_caster_dq_skinning_1weight_twophase_vs_cg cg +{ + source DualQuaternionSkinning_Shadow.cg + //will run on 3 to accommodate the amount of registers + profiles vs_3_0 vp40 arbvp1 + entry_point shadow_caster_dq_skinning_1weight_twophase_vs + + default_params + { + param_named_auto worldDualQuaternion2x4Array world_dualquaternion_array_2x4 + param_named_auto scaleM world_scale_shear_matrix_array_3x4 + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto ambient ambient_light_colour + } +} + +vertex_program Ogre/RTShader/shadow_caster_dq_skinning_2weight_twophase_vs_cg cg +{ + source DualQuaternionSkinning_Shadow.cg + //will run on 3 to accommodate the amount of registers + profiles vs_3_0 vp40 arbvp1 + entry_point shadow_caster_dq_skinning_2weight_twophase_vs + includes_skeletal_animation true + + default_params + { + param_named_auto worldDualQuaternion2x4Array world_dualquaternion_array_2x4 + param_named_auto scaleM world_scale_shear_matrix_array_3x4 + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto ambient ambient_light_colour + } +} + +/////////////////////////////////////////////////////////////////////////// +/// Declare materials for casters and casters with hardware skinning +/////////////////////////////////////////////////////////////////////////// + +material Ogre/RTShader/shadow_caster_dq_skinning_1weight +{ + technique + { + // all this will do is write depth and depth² to red and green + pass + { + vertex_program_ref Ogre/RTShader/shadow_caster_dq_skinning_1weight_vs + { + } + + fragment_program_ref Ogre/RTShader/shadow_caster_dq_ps + { + } + } + } +} + + +material Ogre/RTShader/shadow_caster_dq_skinning_2weight +{ + technique + { + // all this will do is write depth and depth² to red and green + pass + { + vertex_program_ref Ogre/RTShader/shadow_caster_dq_skinning_2weight_vs + { + } + + fragment_program_ref Ogre/RTShader/shadow_caster_dq_ps + { + } + } + } +} + + +material Ogre/RTShader/shadow_caster_dq_skinning_3weight +{ + technique + { + // all this will do is write depth and depth² to red and green + pass + { + vertex_program_ref Ogre/RTShader/shadow_caster_dq_skinning_3weight_vs + { + } + + fragment_program_ref Ogre/RTShader/shadow_caster_dq_ps + { + } + } + } +} + + +material Ogre/RTShader/shadow_caster_dq_skinning_4weight +{ + technique + { + // all this will do is write depth and depth² to red and green + pass + { + vertex_program_ref Ogre/RTShader/shadow_caster_dq_skinning_4weight_vs + { + } + + fragment_program_ref Ogre/RTShader/shadow_caster_dq_ps + { + } + } + } +} + +material Ogre/RTShader/shadow_caster_dq_skinning_1weight_twophase +{ + technique + { + // all this will do is write depth and depth² to red and green + pass + { + vertex_program_ref Ogre/RTShader/shadow_caster_dq_skinning_1weight_twophase_vs + { + } + + fragment_program_ref Ogre/RTShader/shadow_caster_dq_ps + { + } + } + } +} + + +material Ogre/RTShader/shadow_caster_dq_skinning_2weight_twophase +{ + technique + { + // all this will do is write depth and depth² to red and green + pass + { + vertex_program_ref Ogre/RTShader/shadow_caster_dq_skinning_2weight_twophase_vs + { + } + + fragment_program_ref Ogre/RTShader/shadow_caster_dq_ps + { + } + } + } +} + + +material Ogre/RTShader/shadow_caster_dq_skinning_3weight_twophase +{ + technique + { + // all this will do is write depth and depth² to red and green + pass + { + vertex_program_ref Ogre/RTShader/shadow_caster_dq_skinning_2weight_twophase_vs + { + } + + fragment_program_ref Ogre/RTShader/shadow_caster_dq_ps + { + } + } + } +} + + +material Ogre/RTShader/shadow_caster_dq_skinning_4weight_twophase +{ + technique + { + // all this will do is write depth and depth² to red and green + pass + { + vertex_program_ref Ogre/RTShader/shadow_caster_dq_skinning_2weight_twophase_vs + { + } + + fragment_program_ref Ogre/RTShader/shadow_caster_dq_ps + { + } + } + } +} diff --git a/res/dist/media/RTShaderLib/materials/DualQuaternionSkinning_ShadowFourWeights.glsl b/res/dist/media/RTShaderLib/materials/DualQuaternionSkinning_ShadowFourWeights.glsl new file mode 100644 index 00000000000..bf2d5a8077d --- /dev/null +++ b/res/dist/media/RTShaderLib/materials/DualQuaternionSkinning_ShadowFourWeights.glsl @@ -0,0 +1,29 @@ +#version 120 + +mat2x4 blendTwoWeightsAntipod(vec4 blendWgt, vec4 blendIdx, mat4x2 dualQuaternions[24]); +vec3 calculateBlendPosition(vec4 position, mat2x4 blendDQ); + +uniform mat4x2 worldDualQuaternion2x4Array[24]; +uniform mat4x4 viewProjectionMatrix; +uniform vec4 ambient; + +attribute vec4 vertex; +attribute vec4 blendIndices; +attribute vec4 blendWeights; + +//Shadow caster pass +void main() +{ + mat2x4 blendDQ = blendTwoWeightsAntipod(blendWeights, blendIndices, worldDualQuaternion2x4Array); + + float len = length(blendDQ[0]); + blendDQ /= len; + + vec3 blendPosition = calculateBlendPosition(vertex, blendDQ); + + // view / projection + gl_Position = viewProjectionMatrix * vec4(blendPosition, 1.0); + + gl_FrontColor = ambient; +} + diff --git a/res/dist/media/RTShaderLib/materials/DualQuaternionSkinning_ShadowOneWeight.glsl b/res/dist/media/RTShaderLib/materials/DualQuaternionSkinning_ShadowOneWeight.glsl new file mode 100644 index 00000000000..efff54c7380 --- /dev/null +++ b/res/dist/media/RTShaderLib/materials/DualQuaternionSkinning_ShadowOneWeight.glsl @@ -0,0 +1,28 @@ +#version 120 + +vec3 calculateBlendPosition(vec4 position, mat2x4 blendDQ); + +uniform mat4x2 worldDualQuaternion2x4Array[24]; +uniform mat4x4 viewProjectionMatrix; +uniform vec4 ambient; + +attribute vec4 vertex; +attribute vec4 blendIndices; +attribute vec4 blendWeights; + +//Shadow caster pass +void main() +{ + mat2x4 blendDQ = blendWeights.x * worldDualQuaternion2x4Array[blendIndices.x]; + + float len = length(blendDQ[0]); + blendDQ /= len; + + vec3 blendPosition = calculateBlendPosition(vertex, blendDQ); + + // view / projection + gl_Position = viewProjectionMatrix * vec4(blendPosition, 1.0); + + gl_FrontColor = ambient; +} + diff --git a/res/dist/media/RTShaderLib/materials/DualQuaternionSkinning_ShadowPassThrough_ps.glsl b/res/dist/media/RTShaderLib/materials/DualQuaternionSkinning_ShadowPassThrough_ps.glsl new file mode 100644 index 00000000000..020d50ec01d --- /dev/null +++ b/res/dist/media/RTShaderLib/materials/DualQuaternionSkinning_ShadowPassThrough_ps.glsl @@ -0,0 +1,9 @@ +#version 120 + +attribute vec4 colour; + +void main() +{ + gl_FragColor = colour; +} + diff --git a/res/dist/media/RTShaderLib/materials/DualQuaternionSkinning_ShadowPassThrough_vs.glsl b/res/dist/media/RTShaderLib/materials/DualQuaternionSkinning_ShadowPassThrough_vs.glsl new file mode 100644 index 00000000000..60f0a2d4982 --- /dev/null +++ b/res/dist/media/RTShaderLib/materials/DualQuaternionSkinning_ShadowPassThrough_vs.glsl @@ -0,0 +1,15 @@ +#version 120 + +uniform mat4x4 viewProjectionMatrix; +attribute vec4 vertex; + +void main() +{ + // view / projection + gl_Position = viewProjectionMatrix * vertex; + + //Depth information + gl_TexCoord[0].x = gl_Position.z; + gl_TexCoord[0].y = gl_Position.w; +} + diff --git a/res/dist/media/RTShaderLib/materials/DualQuaternionSkinning_ShadowThreeWeights.glsl b/res/dist/media/RTShaderLib/materials/DualQuaternionSkinning_ShadowThreeWeights.glsl new file mode 100644 index 00000000000..bf2d5a8077d --- /dev/null +++ b/res/dist/media/RTShaderLib/materials/DualQuaternionSkinning_ShadowThreeWeights.glsl @@ -0,0 +1,29 @@ +#version 120 + +mat2x4 blendTwoWeightsAntipod(vec4 blendWgt, vec4 blendIdx, mat4x2 dualQuaternions[24]); +vec3 calculateBlendPosition(vec4 position, mat2x4 blendDQ); + +uniform mat4x2 worldDualQuaternion2x4Array[24]; +uniform mat4x4 viewProjectionMatrix; +uniform vec4 ambient; + +attribute vec4 vertex; +attribute vec4 blendIndices; +attribute vec4 blendWeights; + +//Shadow caster pass +void main() +{ + mat2x4 blendDQ = blendTwoWeightsAntipod(blendWeights, blendIndices, worldDualQuaternion2x4Array); + + float len = length(blendDQ[0]); + blendDQ /= len; + + vec3 blendPosition = calculateBlendPosition(vertex, blendDQ); + + // view / projection + gl_Position = viewProjectionMatrix * vec4(blendPosition, 1.0); + + gl_FrontColor = ambient; +} + diff --git a/res/dist/media/RTShaderLib/materials/DualQuaternionSkinning_ShadowTwoWeights.glsl b/res/dist/media/RTShaderLib/materials/DualQuaternionSkinning_ShadowTwoWeights.glsl new file mode 100644 index 00000000000..e0ff330fac6 --- /dev/null +++ b/res/dist/media/RTShaderLib/materials/DualQuaternionSkinning_ShadowTwoWeights.glsl @@ -0,0 +1,29 @@ +#version 120 + +mat2x4 blendTwoWeightsAntipod(vec4 blendWgt, vec4 blendIdx, vec4 dualQuaternions[48]); +vec3 calculateBlendPosition(vec3 position, mat2x4 blendDQ); + +uniform vec4 worldDualQuaternion2x4Array[48]; +uniform mat4x4 viewProjectionMatrix; +uniform vec4 ambient; + +attribute vec4 vertex; +attribute vec4 blendIndices; +attribute vec4 blendWeights; + +//Shadow caster pass +void main() +{ + mat2x4 blendDQ = blendTwoWeightsAntipod(blendWeights, blendIndices, worldDualQuaternion2x4Array); + + float len = length(blendDQ[0]); + blendDQ /= len; + + vec3 blendPosition = calculateBlendPosition(vertex.xyz, blendDQ); + + // view / projection + gl_Position = viewProjectionMatrix * vec4(blendPosition, 1.0); + + gl_FrontColor = ambient; +} + diff --git a/res/dist/media/RTShaderLib/materials/HardwareSkinningShadow.cg b/res/dist/media/RTShaderLib/materials/HardwareSkinningShadow.cg new file mode 100644 index 00000000000..a407a8a4b0f --- /dev/null +++ b/res/dist/media/RTShaderLib/materials/HardwareSkinningShadow.cg @@ -0,0 +1,111 @@ +void shadow_caster_vs( + float4 position : POSITION, + out float4 oPosition : POSITION, + out float2 oDepthInfo : TEXCOORD0, + + uniform float4x4 wvpMatrix) +{ + // output position. + oPosition = mul(wvpMatrix, position); + + // depth info for the fragment. + oDepthInfo.x = oPosition.z; + oDepthInfo.y = oPosition.w; +} + +void shadow_caster_skinning_1weight_vs( + float4 position : POSITION, + out float4 oPosition : POSITION, + out float2 oDepthInfo : TEXCOORD0, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + uniform float4x4 viewProjectionMatrix, + uniform float3x4 worldMatrix3x4Array[80]) +{ + // output position. + oPosition.xyz = mul(worldMatrix3x4Array[blendIdx.x], position) * blendWgt.x; + oPosition.w = 1; + oPosition = mul(viewProjectionMatrix, oPosition); + + + // depth info for the fragment. + oDepthInfo.x = oPosition.z; + oDepthInfo.y = oPosition.w; +} + +void shadow_caster_skinning_2weight_vs( + float4 position : POSITION, + out float4 oPosition : POSITION, + out float2 oDepthInfo : TEXCOORD0, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + uniform float4x4 viewProjectionMatrix, + uniform float3x4 worldMatrix3x4Array[80]) +{ + // output position. + oPosition.xyz = mul(worldMatrix3x4Array[blendIdx.x], position) * blendWgt.x + + mul(worldMatrix3x4Array[blendIdx.y], position) * blendWgt.y; + oPosition.w = 1; + oPosition = mul(viewProjectionMatrix, oPosition); + + + // depth info for the fragment. + oDepthInfo.x = oPosition.z; + oDepthInfo.y = oPosition.w; +} + + +void shadow_caster_skinning_3weight_vs( + float4 position : POSITION, + out float4 oPosition : POSITION, + out float2 oDepthInfo : TEXCOORD0, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + uniform float4x4 viewProjectionMatrix, + uniform float3x4 worldMatrix3x4Array[80]) +{ + // output position. + oPosition.xyz = mul(worldMatrix3x4Array[blendIdx.x], position) * blendWgt.x + + mul(worldMatrix3x4Array[blendIdx.y], position) * blendWgt.y + + mul(worldMatrix3x4Array[blendIdx.z], position) * blendWgt.z; + oPosition.w = 1; + oPosition = mul(viewProjectionMatrix, oPosition); + + + // depth info for the fragment. + oDepthInfo.x = oPosition.z; + oDepthInfo.y = oPosition.w; +} + + +void shadow_caster_skinning_4weight_vs( + float4 position : POSITION, + out float4 oPosition : POSITION, + out float2 oDepthInfo : TEXCOORD0, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + uniform float4x4 viewProjectionMatrix, + uniform float3x4 worldMatrix3x4Array[80]) +{ + // output position. + oPosition.xyz = mul(worldMatrix3x4Array[blendIdx.x], position) * blendWgt.x + + mul(worldMatrix3x4Array[blendIdx.y], position) * blendWgt.y + + mul(worldMatrix3x4Array[blendIdx.z], position) * blendWgt.z + + mul(worldMatrix3x4Array[blendIdx.w], position) * blendWgt.w; + oPosition.w = 1; + oPosition = mul(viewProjectionMatrix, oPosition); + + + // depth info for the fragment. + oDepthInfo.x = oPosition.z; + oDepthInfo.y = oPosition.w; +} + +void shadow_caster_ps( + out float4 oColour : COLOR) +{ + oColour = 0.5; +} diff --git a/res/dist/media/RTShaderLib/materials/HardwareSkinningShadow.material b/res/dist/media/RTShaderLib/materials/HardwareSkinningShadow.material new file mode 100644 index 00000000000..1685ee88ce7 --- /dev/null +++ b/res/dist/media/RTShaderLib/materials/HardwareSkinningShadow.material @@ -0,0 +1,265 @@ +/////////////////////////////////////////////////////////////////////////// +/// Declare CG shaders for casters +/////////////////////////////////////////////////////////////////////////// + +// declare the fragment shader (CG for the language) +fragment_program Ogre/RTShader/shadow_caster_ps_cg cg +{ + // source file + source HardwareSkinningShadow.cg + // will run on pixel shader 2.0+ + profiles ps_2_0 arbfp1 + // entry function + entry_point shadow_caster_ps + default_params + { + + } +} + +vertex_program Ogre/RTShader/shadow_caster_skinning_1weight_vs cg +{ + source HardwareSkinningShadow.cg + //will run on 3 to accommodate the amount of registers + profiles vs_3_0 vp40 arbvp1 + entry_point shadow_caster_skinning_1weight_vs + + default_params + { + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto worldMatrix3x4Array world_matrix_array_3x4 + } +} + +vertex_program Ogre/RTShader/shadow_caster_skinning_2weight_vs_cg cg +{ + source HardwareSkinningShadow.cg + //will run on 3 to accommodate the amount of registers + profiles vs_3_0 vp40 arbvp1 + entry_point shadow_caster_skinning_2weight_vs + + default_params + { + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto worldMatrix3x4Array world_matrix_array_3x4 + } +} + +vertex_program Ogre/RTShader/shadow_caster_skinning_3weight_vs cg +{ + source HardwareSkinningShadow.cg + //will run on 3 to accommodate the amount of registers + profiles vs_3_0 vp40 arbvp1 + entry_point shadow_caster_skinning_3weight_vs + + default_params + { + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto worldMatrix3x4Array world_matrix_array_3x4 + } +} + + +vertex_program Ogre/RTShader/shadow_caster_skinning_4weight_vs cg +{ + source HardwareSkinningShadow.cg + //will run on 3 to accommodate the amount of registers + profiles vs_3_0 vp40 arbvp1 + entry_point shadow_caster_skinning_4weight_vs + + default_params + { + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto worldMatrix3x4Array world_matrix_array_3x4 + } +} + +/////////////////////////////////////////////////////////////////////////// +/// Declare GLSL shaders for casters +/////////////////////////////////////////////////////////////////////////// + +fragment_program Ogre/RTShader/shadow_caster_ps_glsl glsl +{ + source HardwareSkinningShadow_Fragment.glsl +} + +vertex_program Ogre/RTShader/shadow_caster_skinning_2weight_vs_glsl glsl +{ + source HardwareSkinningShadow_TwoWeights.glsl + includes_skeletal_animation true + + default_params + { + param_named_auto viewProjectionMatrix viewproj_matrix + param_named_auto worldMatrix3x4Array world_matrix_array_3x4 + param_named_auto ambient ambient_light_colour + } +} + +/////////////////////////////////////////////////////////////////////////// +/// Unified program declarations +/////////////////////////////////////////////////////////////////////////// +fragment_program Ogre/RTShader/shadow_caster_ps unified +{ + delegate Ogre/RTShader/shadow_caster_ps_glsl + delegate Ogre/RTShader/shadow_caster_ps_cg +} + +vertex_program Ogre/RTShader/shadow_caster_skinning_2weight_vs unified +{ + delegate Ogre/RTShader/shadow_caster_skinning_2weight_vs_glsl + delegate Ogre/RTShader/shadow_caster_skinning_2weight_vs_cg +} + +/////////////////////////////////////////////////////////////////////////// +/// Declare materials for casters and casters with hardware skinning +/////////////////////////////////////////////////////////////////////////// + +material Ogre/RTShader/shadow_caster_skinning_1weight +{ + technique + { + // all this will do is write depth and depth² to red and green + pass + { + vertex_program_ref Ogre/RTShader/shadow_caster_skinning_1weight_vs + { + } + + fragment_program_ref Ogre/RTShader/shadow_caster_ps + { + } + } + } +} + + +material Ogre/RTShader/shadow_caster_skinning_2weight +{ + technique + { + // all this will do is write depth and depth² to red and green + pass + { + vertex_program_ref Ogre/RTShader/shadow_caster_skinning_2weight_vs + { + } + + fragment_program_ref Ogre/RTShader/shadow_caster_ps + { + } + } + } +} + + +material Ogre/RTShader/shadow_caster_skinning_3weight +{ + technique + { + // all this will do is write depth and depth² to red and green + pass + { + vertex_program_ref Ogre/RTShader/shadow_caster_skinning_3weight_vs + { + } + + fragment_program_ref Ogre/RTShader/shadow_caster_ps + { + } + } + } +} + + +material Ogre/RTShader/shadow_caster_skinning_4weight +{ + technique + { + // all this will do is write depth and depth² to red and green + pass + { + vertex_program_ref Ogre/RTShader/shadow_caster_skinning_4weight_vs + { + } + + fragment_program_ref Ogre/RTShader/shadow_caster_ps + { + } + } + } +} + +/////////////////////////////////////////////////////////////////////////// +/// Declare programs for recievers +/////////////////////////////////////////////////////////////////////////// + + +vertex_program Ogre/RTShader/shadow_receiver_vs cg +{ + source HardwareSkinningShadow.cg + profiles vs_1_1 arbvp1 + entry_point shadow_receiver_vs + + default_params + { + param_named_auto worldMatrix world_matrix + param_named_auto viewProjMatrix viewproj_matrix + } +} + +fragment_program Ogre/RTShader/shadow_receiver_ps cg +{ + source HardwareSkinningShadow.cg + profiles ps_2_x arbfp1 + entry_point shadow_receiver_ps + + default_params + { + param_named_auto shadowColor shadow_colour + } +} + +material Ogre/RTShader/shadow_receiver +{ + technique + { + pass + { + ambient 1 1 1 1 + diffuse 1 1 1 1 + + depth_bias 1.25 1.15 + lighting off + fog_override true none + depth_write off + + vertex_program_ref Ogre/RTShader/shadow_receiver_vs + { + param_named texViewProjMatrix0 float4x4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + param_named texViewProjMatrix1 float4x4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + param_named texViewProjMatrix2 float4x4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + } + fragment_program_ref Ogre/RTShader/shadow_receiver_ps + { + param_named pssmSplitPoints float3 0 0 0 + } + + texture_unit shadow_tex0 + { + tex_address_mode border + tex_border_colour 1.0 1.0 1.0 1.0 + } + texture_unit shadow_tex1 + { + tex_address_mode border + tex_border_colour 1.0 1.0 1.0 1.0 + } + texture_unit shadow_tex2 + { + tex_address_mode border + tex_border_colour 1.0 1.0 1.0 1.0 + } + } + } +} diff --git a/res/dist/media/RTShaderLib/materials/HardwareSkinningShadow_Fragment.glsl b/res/dist/media/RTShaderLib/materials/HardwareSkinningShadow_Fragment.glsl new file mode 100644 index 00000000000..4d1e91ff7b1 --- /dev/null +++ b/res/dist/media/RTShaderLib/materials/HardwareSkinningShadow_Fragment.glsl @@ -0,0 +1,6 @@ +#version 120 + +void main() +{ + gl_FragColor = gl_Color; +} diff --git a/res/dist/media/RTShaderLib/materials/HardwareSkinningShadow_TwoWeights.glsl b/res/dist/media/RTShaderLib/materials/HardwareSkinningShadow_TwoWeights.glsl new file mode 100644 index 00000000000..2e050103b08 --- /dev/null +++ b/res/dist/media/RTShaderLib/materials/HardwareSkinningShadow_TwoWeights.glsl @@ -0,0 +1,18 @@ +#version 120 + +attribute vec4 vertex; +attribute vec4 blendIndices; +attribute vec4 blendWeights; + +uniform vec4 ambient; +uniform mat4x4 viewProjectionMatrix; +uniform mat4x3 worldMatrix3x4Array[80]; + +void main() +{ + // output position. + gl_Position = vertex.xyz * worldMatrix3x4Array[int(blendIndices.x)] * blendWeights.x + vertex.xyz * worldMatrix3x4Array[int(blendIndices.y)] * blendWeights.y; + gl_Position = viewProjectionMatrix * gl_Position; + + gl_FrontColor = ambient; +} diff --git a/res/dist/media/RTShaderLib/materials/RTShaderSystem.material b/res/dist/media/RTShaderLib/materials/RTShaderSystem.material new file mode 100644 index 00000000000..2afc7c2cc9e --- /dev/null +++ b/res/dist/media/RTShaderLib/materials/RTShaderSystem.material @@ -0,0 +1,221 @@ + +// RTShader System materials. + +// This is a single pass per pixel lighting based material. +// All scene lights will be applied within a single rendering pass. +// It saves geometry overdraw but it consumes more instructions during vertex and pixel shaders. +// Use this method when your scene uses small amount of lights. (1-3). +material RTSS/PerPixel_SinglePass +{ + technique + { + pass + { + // Turn off specular in order to use only diffuse based bump map technique. + specular 1.0 1.0 1.0 32 + + texture_unit + { + texture Panels_Diffuse.png + } + + // RT Shader system section. + rtshader_system + { + // Override lighting stage with per pixel lighting. + lighting_stage per_pixel + } + } + } +} + +// This is a single pass normal map lighting based material. +// All scene lights will be applied within a single rendering pass. +// Supports all kind of lights - directional, point and spot. +// It saves geometry overdraw but it consumes more instructions during vertex and pixel shaders. +// Use this method when your scene uses small amount of lights. (1-3). +material RTSS/NormalMapping_SinglePass +{ + technique + { + pass + { + // Comment the specular in order to use only diffuse based normal map technique. + specular 1.0 1.0 1.0 32 + + texture_unit + { + texture Panels_Diffuse.png + } + + // RT Shader system section. + rtshader_system + { + // Override lighting stage with normal map lighting. + lighting_stage normal_map Panels_Normal_Tangent.png tangent_space 0 bilinear 1 -1.0 + } + } + } +} + +// This is a multi pass normal map lighting based material. +// It acts as any other multi light material. +// This material defined to use only one type of light per lighting pass because the RTSS need to +// know what code to produce for the iterative lighting pass, otherwise it will throw an exception. +// It support any number of lights drawing but it uses more geometry drawing. +// Use this method when your scene uses large amount of lights. (3-8). +material RTSS/NormalMapping_MultiPass +{ + technique + { + // Base ambient pass + pass ambient + { + // base colours, not needed for rendering, but as information + // to lighting pass categorisation routine + ambient 1 1 1 + diffuse 0 0 0 + specular 0 0 0 0 + + // RT Shader system section. + rtshader_system + { + // Override dynamic light count with zero light count. + // Doing this will cause the RTSS to create + // ambient lighting shaders. + // If not doing that the RTSS it will use the current scene light count + // which will result in full lighting calculation in this pass. + light_count 0 0 0 + } + } + + // Lighting pass. + pass lighting + { + // Comment the specular in order to use only diffuse based normal map technique. + specular 1.0 1.0 1.0 32 + + // base colours, not needed for rendering, but as information + // to lighting pass categorisation routine + ambient 0 0 0 + + // do this for each point light + // You MUST specify the light type when working with the RT Shader System in iterative lighting method. + // otherwise an exception will be thrown. + iteration once_per_light point + + scene_blend add + + // RT Shader system section. + rtshader_system + { + // Override lighting stage with normal map lighting. + lighting_stage normal_map Panels_Normal_Tangent.png tangent_space 0 bilinear 1 -1.0 + } + } + + // Decal pass + pass decal + { + + lighting off + + scene_blend dest_colour zero + texture_unit decalmap + { + texture Panels_Diffuse.png + } + } + } +} + +// Athene single multi pass material override. +material RTSS/Athene/NormalMapping_SinglePass : RTSS/NormalMapping_SinglePass +{ + technique + { + pass + { + // Override the diffuse map. + texture_unit + { + texture egyptrockyfull.jpg + } + + // Override the normal map. + rtshader_system + { + lighting_stage normal_map atheneNormalMap.png tangent_space 0 bilinear 1 -1.0 + } + } + } +} + +// Athene model multi pass material override. +material RTSS/Athene/NormalMapping_MultiPass : RTSS/NormalMapping_MultiPass +{ + technique + { + pass lighting + { + // Override the normal map. + rtshader_system + { + lighting_stage normal_map atheneNormalMap.png tangent_space 0 bilinear 1 -1.0 + } + } + + // Decal pass + pass decal + { + // Override the decal map. + texture_unit decalmap + { + texture egyptrockyfull.jpg + } + } + } +} + +// This material derive from the multi pass normal map material. +// The only difference is that it process 2 point lights at each lighting pass. +material RTSS/NormalMapping_MultiPass_2lights : RTSS/NormalMapping_MultiPass +{ + technique + { + pass lighting + { + // Override light iteration definition. + iteration 1 per_n_lights 2 point + } + } +} + +// This material demonstrates the texture blending extension. +material RTSS/LayeredBlending +{ + technique + { + pass + { + lighting off + texture_unit + { + scale 0.1 0.1 + texture rockwall.tga + } + + texture_unit + { + // RT Shader system section - required by the layered blend extension. + rtshader_system + { + layered_blend luminosity + source_modifier src1_inverse_modulate custom 2 + } + texture ogrelogo.png + } + } + } +} + diff --git a/res/dist/media/fonts/bluebold.ttf b/res/dist/media/fonts/bluebold.ttf new file mode 100644 index 00000000000..ce5d904833e Binary files /dev/null and b/res/dist/media/fonts/bluebold.ttf differ diff --git a/res/dist/media/fonts/bluecond.ttf b/res/dist/media/fonts/bluecond.ttf new file mode 100644 index 00000000000..4c5b01f95e2 Binary files /dev/null and b/res/dist/media/fonts/bluecond.ttf differ diff --git a/res/dist/media/fonts/bluehigh.ttf b/res/dist/media/fonts/bluehigh.ttf new file mode 100644 index 00000000000..14d45c5a1eb Binary files /dev/null and b/res/dist/media/fonts/bluehigh.ttf differ diff --git a/res/dist/media/fonts/bluehighway-10.font b/res/dist/media/fonts/bluehighway-10.font new file mode 100644 index 00000000000..23a7bc7e0d0 --- /dev/null +++ b/res/dist/media/fonts/bluehighway-10.font @@ -0,0 +1,2 @@ + + diff --git a/res/dist/media/fonts/bluehighway-12.font b/res/dist/media/fonts/bluehighway-12.font new file mode 100644 index 00000000000..e6aac73e984 --- /dev/null +++ b/res/dist/media/fonts/bluehighway-12.font @@ -0,0 +1,2 @@ + + diff --git a/res/dist/media/fonts/bluehighway-8.font b/res/dist/media/fonts/bluehighway-8.font new file mode 100644 index 00000000000..ba3ac2e6d13 --- /dev/null +++ b/res/dist/media/fonts/bluehighway-8.font @@ -0,0 +1,2 @@ + + diff --git a/res/dist/media/fonts/read_me.html b/res/dist/media/fonts/read_me.html new file mode 100644 index 00000000000..9f53dc86dfb --- /dev/null +++ b/res/dist/media/fonts/read_me.html @@ -0,0 +1,2 @@ +
All Larabie Fonts in this file are free to use for personal and/or commercial purposes. No payment is necessary to use these fonts for personal or commercial use. For Software Products who want to include Larabie Fonts see the License Agreement below. You can add this font to a website but do not combine fonts into a single archive or alter them in any way.
All Larabie Fonts are free for commercial use but a sample of your product would be gratefully appreciated so I can see how the font looks in use. Contact www.larabiefonts.com/donation.html for mailing information.
Some Larabie Fonts have enhanced and expanded families available for sale at www.typodermic.com.
If you'd like to make a voluntary donation to Larabie Fonts for the use of the free fonts in any amount please go to www.larabiefonts.com/donation.html
I accept CDs, magazines, t-shirts, a sample of your merchandise or anything featuring Larabie Fonts. Please remember to list your item as a ‘gift’ on the customs form or I will have to pay import duties and taxes on the item. Mailing information is provided at the link above.
Font installation help is available at www.larabiefonts.com/help.html
The SOFTWARE PRODUCT is protected by copyright laws and International copyright treaties, as well as other intellectual property laws and treaties. The SOFTWARE PRODUCT is licensed, not sold.
- Installation and Use. You may install and use an unlimited number of copies of the SOFTWARE PRODUCT. You may copy and distribute unlimited copies of the SOFTWARE PRODUCT as you receive them, in any medium, provided that you publish on each copy an appropriate copyright notice. Keep intact all the notices that refer to this License and give any other recipients of the fonts a copy of this License along with the fonts.
- You may modify your copy or copies of the SOFTWARE PRODUCT or any portion of it, provided that you also meet all of these rules:
a) Do not alter in any way alphanumeric characters (A-Z, a-z, 1-9) contained in the font. An exception is converting between formats, here is allowed the nominal distortion that occurs during conversion from second order to third order quadratic curves (TrueType to Postscript) and vice versa.
b) Extra characters may be added; here it is allowed to use curves (shapes) from alphanumeric characters in fonts under same license.
c) It is allowed to modify and remove analpahbetics (punctuation, special characters, ligatures and symbols).
d) The original font name must be retained but can be augmented. (ie. a Font named Blue Highway can be renamed Blue Highway Cyrillic or Blue Highway ANSI, etc.)
e) Character mapping may be altered.
f) If the kerning information is altered or discarded it must be stated in the user notes or documentation.
g) All modifications must be released under this license.
LIMITED WARRANTY NO WARRANTIES. Larabie Fonts expressly disclaims any warranty for the SOFTWARE PRODUCT. The SOFTWARE PRODUCT and any related documentation is provided "as is" without warranty of any kind, either express or implied, including, without limitation, the implied warranties or merchantability, fitness for a particular purpose, or non-infringement. The entire risk arising out of use or performance of the SOFTWARE PRODUCT remains with you.NO LIABILITY FOR CONSEQUENTIAL DAMAGES. In no event shall Larabie Fonts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or any other pecuniary loss) arising out of the use of or inability to use this product, even if Larabie Fonts has been advised of the possibility of such damages.
Should you have any questions concerning this document, or if you desire to contact Larabie Fonts for any reason, please email www.larabiefonts.com/email.html.
+ diff --git a/res/dist/media/fonts/sample.fontdef b/res/dist/media/fonts/sample.fontdef new file mode 100644 index 00000000000..462defc5f14 --- /dev/null +++ b/res/dist/media/fonts/sample.fontdef @@ -0,0 +1,11 @@ +StarWars +{ + // Now this one I agree with ;) + // A Star Wars font :) + type truetype + source solo5.ttf + size 16 + resolution 96 +} + + diff --git a/res/dist/media/fonts/solo5.ttf b/res/dist/media/fonts/solo5.ttf new file mode 100644 index 00000000000..c723496ee5f Binary files /dev/null and b/res/dist/media/fonts/solo5.ttf differ diff --git a/res/dist/media/materials/programs/ASCIIFP.cg b/res/dist/media/materials/programs/ASCIIFP.cg new file mode 100644 index 00000000000..9f4357e3874 --- /dev/null +++ b/res/dist/media/materials/programs/ASCIIFP.cg @@ -0,0 +1,32 @@ +sampler2D RT : register(s0); +sampler3D pattern : register(s1); + +float4 ASCII_ps( float4 pos : POSITION, + float2 TexCoord : TEXCOORD0, + uniform float2 numTiles, + uniform float2 iNumTiles, + uniform float2 iNumTiles2, + uniform float4 lum, + uniform float charBias) : COLOR +{ + float3 local; + + //sample RT + local.xy = fmod(TexCoord, iNumTiles); + float2 middle = TexCoord - local.xy; + local.xy = local.xy * numTiles; + + //iNumTiles2 = iNumTiles / 2 + middle = middle + iNumTiles2; + float4 c = tex2D(RT, middle ); + + //multiply luminance by charbias , beacause not all slices of the ascii + //volume texture are used + local.z = dot(c , lum)*charBias; + + //fix to brighten the dark pixels with small characters + //c *= lerp(2.0,1.0, local.z); + + c *= tex3D(pattern,local); + return c; +} \ No newline at end of file diff --git a/res/dist/media/materials/programs/ASCIIFP.glsles b/res/dist/media/materials/programs/ASCIIFP.glsles new file mode 100644 index 00000000000..7af11ab39b3 --- /dev/null +++ b/res/dist/media/materials/programs/ASCIIFP.glsles @@ -0,0 +1,31 @@ +sampler RT : register(s0); +sampler pattern : register(s1); + +float4 ASCII_ps( float2 TexCoord : TEXCOORD0, + uniform float2 numTiles, + uniform float2 iNumTiles, + uniform float2 iNumTiles2, + uniform float4 lum, + uniform float charBias) : COLOR +{ + float3 local; + + //sample RT + local.xy = fmod(TexCoord, iNumTiles); + float2 middle = TexCoord - local.xy; + local.xy = local.xy * numTiles; + + //iNumTiles2 = iNumTiles / 2 + middle = middle + iNumTiles2; + float4 c = tex2D(RT, middle ); + + //multiply luminance by charbias , because not all slices of the ascii + //volume texture are used + local.z = dot(c , lum)*charBias; + + //fix to brighten the dark pixels with small characters + //c *= mix(2.0,1.0, local.z); + + c *= tex3D(pattern,local); + return c; +} \ No newline at end of file diff --git a/res/dist/media/materials/programs/AmbientOneTexture.glsl b/res/dist/media/materials/programs/AmbientOneTexture.glsl new file mode 100644 index 00000000000..66b4bcd3d3a --- /dev/null +++ b/res/dist/media/materials/programs/AmbientOneTexture.glsl @@ -0,0 +1,13 @@ +uniform vec4 ambient; + +/* + Basic ambient lighting vertex program +*/ +void main() +{ + gl_Position = ftransform(); + gl_TexCoord[0] = gl_MultiTexCoord0; + gl_FrontColor = ambient; +} + + diff --git a/res/dist/media/materials/programs/AmbientOneTexture.glsles b/res/dist/media/materials/programs/AmbientOneTexture.glsles new file mode 100644 index 00000000000..1345ab072ee --- /dev/null +++ b/res/dist/media/materials/programs/AmbientOneTexture.glsles @@ -0,0 +1,20 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform vec4 ambient; +uniform mat4 worldViewProj; + +attribute vec4 position; + +varying vec4 colour; + +/* + Basic ambient lighting vertex program for GLSL ES +*/ +void main() +{ + gl_Position = worldViewProj * position; + colour = ambient; +} diff --git a/res/dist/media/materials/programs/AmbientOneTextureWithUV.glsles b/res/dist/media/materials/programs/AmbientOneTextureWithUV.glsles new file mode 100644 index 00000000000..c9994fea07f --- /dev/null +++ b/res/dist/media/materials/programs/AmbientOneTextureWithUV.glsles @@ -0,0 +1,23 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform vec4 ambient; +uniform mat4 worldViewProj; + +attribute vec4 position; +attribute vec4 uv0; + +varying vec4 colour; +varying vec4 ambientUV; + +/* + Basic ambient lighting vertex program for GLSL ES +*/ +void main() +{ + gl_Position = worldViewProj * position; + colour = ambient; + ambientUV = uv0; +} diff --git a/res/dist/media/materials/programs/Bloom2_ps20.glsl b/res/dist/media/materials/programs/Bloom2_ps20.glsl new file mode 100644 index 00000000000..9443e66e136 --- /dev/null +++ b/res/dist/media/materials/programs/Bloom2_ps20.glsl @@ -0,0 +1,27 @@ +//------------------------------- +//Bloom_ps20.glsl +// Blends using weights the blurred image with the sharp one +// Params: +// OriginalImageWeight +// BlurWeight +//------------------------------- + +uniform sampler2D RT; +uniform sampler2D Blur1; + +uniform float OriginalImageWeight; +uniform float BlurWeight; + +void main() +{ + vec4 sharp; + vec4 blur; + + vec2 texCoord = vec2( gl_TexCoord[0] ); + + sharp = texture2D( RT, texCoord); + blur = texture2D( Blur1, texCoord); + + gl_FragColor = ( (blur * BlurWeight) + (sharp * OriginalImageWeight) ); + //gl_FragColor = vec4(0); +} diff --git a/res/dist/media/materials/programs/Bloom2_ps20.glsles b/res/dist/media/materials/programs/Bloom2_ps20.glsles new file mode 100644 index 00000000000..5dfdead7eaf --- /dev/null +++ b/res/dist/media/materials/programs/Bloom2_ps20.glsles @@ -0,0 +1,30 @@ +#version 100 +precision mediump int; +precision mediump float; + +//------------------------------- +// Bloom_ps20.glsles +// Blends using weights the blurred image with the sharp one +// Params: +// OriginalImageWeight +// BlurWeight +//------------------------------- + +uniform sampler2D RT; +uniform sampler2D Blur1; + +uniform float OriginalImageWeight; +uniform float BlurWeight; +varying vec2 texCoord; + +void main() +{ + vec4 sharp; + vec4 blur; + + sharp = texture2D( RT, texCoord); + blur = texture2D( Blur1, texCoord); + + gl_FragColor = ( (blur * BlurWeight) + (sharp * OriginalImageWeight) ); + //gl_FragColor = vec4(0); +} diff --git a/res/dist/media/materials/programs/Bloom2_ps20.hlsl b/res/dist/media/materials/programs/Bloom2_ps20.hlsl new file mode 100644 index 00000000000..a33674df9f6 --- /dev/null +++ b/res/dist/media/materials/programs/Bloom2_ps20.hlsl @@ -0,0 +1,58 @@ +//--------------------------------------------- +// Bloom + + +float4 main(float2 texCoord: TEXCOORD0, + uniform sampler RT: register(s0), + uniform sampler Blur1: register(s1), + uniform float OriginalImageWeight, + uniform float BlurWeight + ) : COLOR { + + + float4 sharp = tex2D(RT, texCoord); + float4 blur = tex2D(Blur1, texCoord); + + //return blur*0.5+sharp*0.5; + return blur*BlurWeight+sharp*OriginalImageWeight; + //return blur; + + //return ( sharp + blur * 1.8 ) / 2; + +// return (sharp*3/6 + (blur*4/6))*float4(1.5, 1.5, 1.5, 1);; + +// float4 color = lerp( sharp, blur, 0.4f ); + +// return color; + + +/* + return ( sharp + blur * 1.8 ) / 2 + + luminance(blur) * + float4( 0.5, 0.5, 0.5, 0) + + luminance(sharp) * + float4( 0.3, 0.3, 0.3, 0); +*/ +/* + return ( sharp + blur * 0.9) / 2 + + luminance(blur) * float4(0.1, 0.15, 0.7, 0); +*/ + +/* + return ( sharp + blur * 0.9) / 2 + + luminance(blur) * float4(0.1, 0.15, 0.7, 0); +*/ + +// float4 retColor = luminance( sharp ) + +// luminance( blur ) + blur / 2; +// return retColor; +} + + + + + + + + + diff --git a/res/dist/media/materials/programs/Bloom_ps20.hlsl b/res/dist/media/materials/programs/Bloom_ps20.hlsl new file mode 100644 index 00000000000..15aa068c34b --- /dev/null +++ b/res/dist/media/materials/programs/Bloom_ps20.hlsl @@ -0,0 +1,52 @@ +sampler Blur1: register(s1); +sampler RT: register(s0); + + +float luminance(float3 c) +{ + return dot( c, float3(0.3, 0.59, 0.11) ); +} + +float4 main(float2 texCoord: TEXCOORD0) : COLOR { + float4 sharp = tex2D(RT, texCoord); + float4 blur = tex2D(Blur1, texCoord); + + + + return ( sharp + blur * 1.8 ) / 2; + +// float4 color = lerp( sharp, blur, 0.4f ); + +// return color; + + +/* + return ( sharp + blur * 1.8 ) / 2 + + luminance(blur) * + float4( 0.5, 0.5, 0.5, 0) + + luminance(sharp) * + float4( 0.3, 0.3, 0.3, 0); +*/ +/* + return ( sharp + blur * 0.9) / 2 + + luminance(blur) * float4(0.1, 0.15, 0.7, 0); +*/ + +/* + return ( sharp + blur * 0.9) / 2 + + luminance(blur) * float4(0.1, 0.15, 0.7, 0); +*/ + +// float4 retColor = luminance( sharp ) + +// luminance( blur ) + blur / 2; +// return retColor; +} + + + + + + + + + diff --git a/res/dist/media/materials/programs/Bloom_vs11.hlsl b/res/dist/media/materials/programs/Bloom_vs11.hlsl new file mode 100644 index 00000000000..b6e49a3e053 --- /dev/null +++ b/res/dist/media/materials/programs/Bloom_vs11.hlsl @@ -0,0 +1,21 @@ + +struct VS_OUTPUT { + float4 Pos: POSITION; + float2 texCoord: TEXCOORD0; +}; + +VS_OUTPUT main(float4 Pos: POSITION){ + VS_OUTPUT Out; + + // Clean up inaccuracies + Pos.xy = sign(Pos.xy); + + Out.Pos = float4(Pos.xy, 0, 1); + // Image-space + Out.texCoord.x = 0.5 * (1 + Pos.x); + Out.texCoord.y = 0.5 * (1 - Pos.y); + + return Out; +} + + diff --git a/res/dist/media/materials/programs/Blur0_ps20.hlsl b/res/dist/media/materials/programs/Blur0_ps20.hlsl new file mode 100644 index 00000000000..5790dce51d8 --- /dev/null +++ b/res/dist/media/materials/programs/Blur0_ps20.hlsl @@ -0,0 +1,31 @@ +sampler RT: register(s0); +// Simple blur filter + +float4 main(float2 texCoord: TEXCOORD0) : COLOR { + + float2 samples[12] = { + -0.326212, -0.405805, + -0.840144, -0.073580, + -0.695914, 0.457137, + -0.203345, 0.620716, + 0.962340, -0.194983, + 0.473434, -0.480026, + 0.519456, 0.767022, + 0.185461, -0.893124, + 0.507431, 0.064425, + 0.896420, 0.412458, + -0.321940, -0.932615, + -0.791559, -0.597705, + }; + + float4 sum = tex2D(RT, texCoord); + for (int i = 0; i < 12; i++){ + sum += tex2D(RT, texCoord + 0.025 * samples[i]); + } + return sum / 13; + +} + + + + diff --git a/res/dist/media/materials/programs/Blur0_vs.glsl b/res/dist/media/materials/programs/Blur0_vs.glsl new file mode 100644 index 00000000000..24212edd037 --- /dev/null +++ b/res/dist/media/materials/programs/Blur0_vs.glsl @@ -0,0 +1,15 @@ +varying vec2 texCoord[5]; + +void main() +{ + vec2 inPos = sign(gl_Vertex.xy); + gl_Position = vec4(inPos.xy, 0.0, 1.0); + + texCoord[0] = (vec2(inPos.x, -inPos.y) + 1.0)/2.0; + + const float size = 0.01; + texCoord[1] = texCoord[0] + vec2(1.0, 0.0)*size; + texCoord[2] = texCoord[0] + vec2(2.0, 0.0)*size; + texCoord[3] = texCoord[0] + vec2(-1.0, 0.0)*size; + texCoord[4] = texCoord[0] + vec2(-2.0, 0.0)*size; +} diff --git a/res/dist/media/materials/programs/Blur0_vs.glsles b/res/dist/media/materials/programs/Blur0_vs.glsles new file mode 100644 index 00000000000..b30795a0141 --- /dev/null +++ b/res/dist/media/materials/programs/Blur0_vs.glsles @@ -0,0 +1,22 @@ +#version 100 + +precision mediump int; +precision mediump float; + +varying vec2 texCoord[5]; + +attribute vec4 vertex; + +void main() +{ + vec2 inPos = sign(vertex.xy); + gl_Position = vec4(inPos.xy, 0.0, 1.0); + + texCoord[0] = (vec2(inPos.x, -inPos.y) + 1.0)/2.0; + + const float size = 0.01; + texCoord[1] = texCoord[0] + vec2(1.0, 0.0)*size; + texCoord[2] = texCoord[0] + vec2(2.0, 0.0)*size; + texCoord[3] = texCoord[0] + vec2(-1.0, 0.0)*size; + texCoord[4] = texCoord[0] + vec2(-2.0, 0.0)*size; +} diff --git a/res/dist/media/materials/programs/Blur0_vs11.hlsl b/res/dist/media/materials/programs/Blur0_vs11.hlsl new file mode 100644 index 00000000000..3979eae9fba --- /dev/null +++ b/res/dist/media/materials/programs/Blur0_vs11.hlsl @@ -0,0 +1,22 @@ +struct VS_OUTPUT { + float4 Pos: POSITION; + float2 texCoord: TEXCOORD0; +}; + +VS_OUTPUT main(float4 Pos: POSITION){ + VS_OUTPUT Out; + + // Clean up inaccuracies + Pos.xy = sign(Pos.xy); + + Out.Pos = float4(Pos.xy, 0, 1); + // Image-space + Out.texCoord.x = 0.5 * (1 + Pos.x); + Out.texCoord.y = 0.5 * (1 - Pos.y); + + return Out; +} + + + + diff --git a/res/dist/media/materials/programs/Blur1_ps20.hlsl b/res/dist/media/materials/programs/Blur1_ps20.hlsl new file mode 100644 index 00000000000..95e754b24fc --- /dev/null +++ b/res/dist/media/materials/programs/Blur1_ps20.hlsl @@ -0,0 +1,28 @@ +sampler Blur0: register(s0); +// Simple blur filter + +float4 main(float2 texCoord: TEXCOORD0) : COLOR { + + float2 samples[12] = { + -0.326212, -0.405805, + -0.840144, -0.073580, + -0.695914, 0.457137, + -0.203345, 0.620716, + 0.962340, -0.194983, + 0.473434, -0.480026, + 0.519456, 0.767022, + 0.185461, -0.893124, + 0.507431, 0.064425, + 0.896420, 0.412458, + -0.321940, -0.932615, + -0.791559, -0.597705, + }; + + float4 sum = tex2D(Blur0, texCoord); + for (int i = 0; i < 12; i++){ + sum += tex2D(Blur0, texCoord + 0.025 * samples[i]); + } + return sum / 13; + +} + diff --git a/res/dist/media/materials/programs/Blur1_vs.glsl b/res/dist/media/materials/programs/Blur1_vs.glsl new file mode 100644 index 00000000000..dd20151971d --- /dev/null +++ b/res/dist/media/materials/programs/Blur1_vs.glsl @@ -0,0 +1,15 @@ +varying vec2 texCoord[5]; + +void main() +{ + vec2 inPos = sign(gl_Vertex.xy); + gl_Position = vec4(inPos.xy, 0.0, 1.0); + + texCoord[0] = (vec2(inPos.x, -inPos.y) + 1.0)/2.0; + + const float size = 0.01; + texCoord[1] = texCoord[0] + vec2(0.0, 1.0)*size; + texCoord[2] = texCoord[0] + vec2(0.0, 2.0)*size; + texCoord[3] = texCoord[0] + vec2(0.0, -1.0)*size; + texCoord[4] = texCoord[0] + vec2(0.0, -2.0)*size; +} diff --git a/res/dist/media/materials/programs/Blur1_vs.glsles b/res/dist/media/materials/programs/Blur1_vs.glsles new file mode 100644 index 00000000000..05d99684d33 --- /dev/null +++ b/res/dist/media/materials/programs/Blur1_vs.glsles @@ -0,0 +1,22 @@ +#version 100 + +precision mediump int; +precision mediump float; + +varying vec2 texCoord; + +attribute vec4 vertex; + +void main() +{ + vec2 inPos = sign(vertex.xy); + gl_Position = vec4(inPos.xy, 0.0, 1.0); + + texCoord = (vec2(inPos.x, -inPos.y) + 1.0)/2.0; + +/* const float size = 0.01; + texCoord[1] = texCoord[0] + vec2(0.0, 1.0)*size; + texCoord[2] = texCoord[0] + vec2(0.0, 2.0)*size; + texCoord[3] = texCoord[0] + vec2(0.0, -1.0)*size; + texCoord[4] = texCoord[0] + vec2(0.0, -2.0)*size; +*/} diff --git a/res/dist/media/materials/programs/Blur1_vs11.hlsl b/res/dist/media/materials/programs/Blur1_vs11.hlsl new file mode 100644 index 00000000000..49b316f169c --- /dev/null +++ b/res/dist/media/materials/programs/Blur1_vs11.hlsl @@ -0,0 +1,19 @@ +struct VS_OUTPUT { + float4 Pos: POSITION; + float2 texCoord: TEXCOORD0; +}; + +VS_OUTPUT main(float4 Pos: POSITION){ + VS_OUTPUT Out; + + // Clean up inaccuracies + Pos.xy = sign(Pos.xy); + + Out.Pos = float4(Pos.xy, 0, 1); + // Image-space + Out.texCoord.x = 0.5 * (1 + Pos.x); + Out.texCoord.y = 0.5 * (1 - Pos.y); + + return Out; +} + diff --git a/res/dist/media/materials/programs/BlurH_ps20.glsl b/res/dist/media/materials/programs/BlurH_ps20.glsl new file mode 100644 index 00000000000..59a8f514d16 --- /dev/null +++ b/res/dist/media/materials/programs/BlurH_ps20.glsl @@ -0,0 +1,56 @@ +//------------------------------- +//BlurH_ps20.glsl +// Horizontal Gaussian-Blur pass +//------------------------------- + +uniform sampler2D Blur0; +vec2 pos[11] = +{ + vec2( -5, 0), + vec2( -4, 0), + vec2( -3, 0), + vec2( -2, 0), + vec2( -1, 0), + vec2( 0, 0), + vec2( 1, 0), + vec2( 2, 0), + vec2( 3, 0), + vec2( 4, 0), + vec2( 5, 0) +}; + +//We use the Normal-gauss distribution formula +//f(x) being the formula, we used f(0.5)-f(-0.5); f(1.5)-f(0.5)... +float samples[11] = +{//stddev=2.0 +0.01222447, +0.02783468, +0.06559061, +0.12097757, +0.17466632, + +0.19741265, + +0.17466632, +0.12097757, +0.06559061, +0.02783468, +0.01222447 +}; + +void main() +{ + vec4 retVal; + + vec4 sum; + vec2 texcoord = vec2( gl_TexCoord[0] ); + int i = 0; + + sum = vec4( 0 ); + for( i=0;i < 11; i++ ) + { + sum += texture2D( Blur0, texcoord + (pos[i] * 0.0100000) ) * samples[i]; + } + + gl_FragColor = sum; +} diff --git a/res/dist/media/materials/programs/BlurH_ps20.glsles b/res/dist/media/materials/programs/BlurH_ps20.glsles new file mode 100644 index 00000000000..534559f8a5b --- /dev/null +++ b/res/dist/media/materials/programs/BlurH_ps20.glsles @@ -0,0 +1,58 @@ +#version 100 +precision mediump int; +precision mediump float; + +//------------------------------- +//BlurH_ps20.glsles +// Horizontal Gaussian-Blur pass +//------------------------------- + +uniform sampler2D Blur0; +varying vec2 texCoord; + +vec2 pos[11]; +//We use the Normal-gauss distribution formula +//f(x) being the formula, we used f(0.5)-f(-0.5); f(1.5)-f(0.5)... +float samples[11]; + +void main() +{ + pos[0] = vec2(-5.0, 0.0); + pos[1] = vec2(-4.0, 0.0); + pos[2] = vec2(-3.0, 0.0); + pos[3] = vec2(-2.0, 0.0); + pos[4] = vec2(-1.0, 0.0); + pos[5] = vec2(0.0, 0.0); + pos[6] = vec2(1.0, 0.0); + pos[7] = vec2(2.0, 0.0); + pos[8] = vec2(3.0, 0.0); + pos[9] = vec2(4.0, 0.0); + pos[10] = vec2(5.0, 0.0); + + //We use the Normal-gauss distribution formula + //f(x) being the formula, we used f(0.5)-f(-0.5); f(1.5)-f(0.5)... + //stddev=2.0 + samples[0] = 0.01222447; + samples[1] = 0.02783468; + samples[2] = 0.06559061; + samples[3] = 0.12097757; + samples[4] = 0.17466632; + samples[5] = 0.19741265; + samples[6] = 0.17466632; + samples[7] = 0.12097757; + samples[8] = 0.06559061; + samples[9] = 0.02783468; + samples[10] = 0.01222447; + + vec4 retVal; + vec4 sum; + int i = 0; + + sum = vec4( 0 ); + for( i = 0;i < 11; i++ ) + { + sum += texture2D( Blur0, texCoord + (pos[i] * 0.0100000) ) * samples[i]; + } + + gl_FragColor = sum; +} diff --git a/res/dist/media/materials/programs/BlurH_ps20.hlsl b/res/dist/media/materials/programs/BlurH_ps20.hlsl new file mode 100644 index 00000000000..ab7388c5185 --- /dev/null +++ b/res/dist/media/materials/programs/BlurH_ps20.hlsl @@ -0,0 +1,51 @@ +//------------------------------- +//BlurH_ps20.hlsl +// Horizontal Gaussian-Blur pass +//------------------------------- + +sampler Blur0: register(s0); +// Simple blur filter + +//We use the Normal-gauss distribution formula +//f(x) being the formula, we used f(0.5)-f(-0.5); f(1.5)-f(0.5)... +static const float samples[11] = +{//stddev=2.0 +0.01222447, +0.02783468, +0.06559061, +0.12097757, +0.17466632, + +0.19741265, + +0.17466632, +0.12097757, +0.06559061, +0.02783468, +0.01222447 +}; + +static const float2 pos[11] = +{ +-5, 0, +-4, 0, +-3, 0, +-2, 0, +-1, 0, + 0, 0, + 1, 0, + 2, 0, + 3, 0, + 4, 0, + 5, 0, +}; + +float4 main(float2 texCoord: TEXCOORD0) : COLOR +{ + float4 sum = 0; + for (int i = 0; i < 11; i++) + { + sum += tex2D(Blur0, texCoord + pos[i]*0.01) * samples[i]; + } + return sum; +} diff --git a/res/dist/media/materials/programs/BlurV_ps20.glsl b/res/dist/media/materials/programs/BlurV_ps20.glsl new file mode 100644 index 00000000000..3448e1de1fc --- /dev/null +++ b/res/dist/media/materials/programs/BlurV_ps20.glsl @@ -0,0 +1,60 @@ +// Note, this won't work on ATI which is why it's not used +// the issue is with the array initializers +// no card supports GL_3DL_array_objects but it does work on nvidia, not on ATI +//#extension GL_3DL_array_objects : enable + +//------------------------------- +//BlurV_ps20.glsl +// Vertical Gaussian-Blur pass +//------------------------------- + +uniform sampler2D Blur0; +vec2 pos[11] = vec2[11]( + vec2(0.0, -5.0), + vec2(0.0, -4.0), + vec2(0.0, -3.0), + vec2(0.0, -2.0), + vec2(0.0, -1.0), + vec2(0.0, 0.0), + vec2(0.0, 1.0), + vec2(0.0, 2.0), + vec2(0.0, 3.0), + vec2(0.0, 4.0), + vec2(0.0, 5.0) +); + +//We use the Normal-gauss distribution formula +//f(x) being the formula, we used f(0.5)-f(-0.5); f(1.5)-f(0.5)... +float samples[11] = float[11] +(//stddev=2.0 +0.01222447, +0.02783468, +0.06559061, +0.12097757, +0.17466632, + +0.19741265, + +0.17466632, +0.12097757, +0.06559061, +0.02783468, +0.01222447 +); + +void main() +{ + vec4 retVal; + + vec4 sum; + vec2 texcoord = vec2(gl_TexCoord[0]); + int i = 0; + + sum = vec4( 0 ); + for( ;i < 11; i++ ) + { + sum += texture2D( Blur0, texcoord + (pos[i] * 0.0100000) ) * samples[i]; + } + + gl_FragColor = sum; +} diff --git a/res/dist/media/materials/programs/BlurV_ps20.glsles b/res/dist/media/materials/programs/BlurV_ps20.glsles new file mode 100644 index 00000000000..bc9f39c8dec --- /dev/null +++ b/res/dist/media/materials/programs/BlurV_ps20.glsles @@ -0,0 +1,63 @@ +#version 100 +precision mediump int; +precision mediump float; + +// Note, this won't work on ATI which is why it's not used +// the issue is with the array initializers +// no card supports GL_3DL_array_objects but it does work on nvidia, not on ATI +//#extension GL_3DL_array_objects : enable + +//------------------------------- +//BlurV_ps20.glsles +// Vertical Gaussian-Blur pass +//------------------------------- + +uniform sampler2D Blur0; +varying vec2 texCoord; + +vec2 pos[11]; +//We use the Normal-gauss distribution formula +//f(x) being the formula, we used f(0.5)-f(-0.5); f(1.5)-f(0.5)... +float samples[11]; + +void main() +{ + pos[0] = vec2(0.0, -5.0); + pos[1] = vec2(0.0, -4.0); + pos[2] = vec2(0.0, -3.0); + pos[3] = vec2(0.0, -2.0); + pos[4] = vec2(0.0, -1.0); + pos[5] = vec2(0.0, 0.0); + pos[6] = vec2(0.0, 1.0); + pos[7] = vec2(0.0, 2.0); + pos[8] = vec2(0.0, 3.0); + pos[9] = vec2(0.0, 4.0); + pos[10] = vec2(0.0, 5.0); + + //We use the Normal-gauss distribution formula + //f(x) being the formula, we used f(0.5)-f(-0.5); f(1.5)-f(0.5)... + //stddev=2.0 + samples[0] = 0.01222447; + samples[1] = 0.02783468; + samples[2] = 0.06559061; + samples[3] = 0.12097757; + samples[4] = 0.17466632; + samples[5] = 0.19741265; + samples[6] = 0.17466632; + samples[7] = 0.12097757; + samples[8] = 0.06559061; + samples[9] = 0.02783468; + samples[10] = 0.01222447; + + vec4 retVal; + vec4 sum; + int i = 0; + + sum = vec4( 0 ); + for( ;i < 11; i++ ) + { + sum += texture2D( Blur0, texCoord + (pos[i] * 0.0100000) ) * samples[i]; + } + + gl_FragColor = sum; +} diff --git a/res/dist/media/materials/programs/BlurV_ps20.hlsl b/res/dist/media/materials/programs/BlurV_ps20.hlsl new file mode 100644 index 00000000000..c5becdc350f --- /dev/null +++ b/res/dist/media/materials/programs/BlurV_ps20.hlsl @@ -0,0 +1,51 @@ +//------------------------------- +//BlurV_ps20.hlsl +// Vertical Gaussian-Blur pass +//------------------------------- + +sampler Blur0: register(s0); +// Simple blur filter + +//We use the Normal-gauss distribution formula +//f(x) being the formula, we used f(0.5)-f(-0.5); f(1.5)-f(0.5)... +static const float samples[11] = +{//stddev=2.0 +0.01222447, +0.02783468, +0.06559061, +0.12097757, +0.17466632, + +0.19741265, + +0.17466632, +0.12097757, +0.06559061, +0.02783468, +0.01222447 +}; + +static const float2 pos[11] = +{ +0, -5, +0, -4, +0, -3, +0, -2, +0, -1, +0, 0, +0, 1, +0, 2, +0, 3, +0, 4, +0, 5 +}; + +float4 main(float2 texCoord: TEXCOORD0) : COLOR +{ + float4 sum = 0; + for (int i = 0; i < 11; i++) + { + sum += tex2D(Blur0, texCoord + pos[i]*0.01) * samples[i]; + } + return sum; +} diff --git a/res/dist/media/materials/programs/Blur_ps.glsl b/res/dist/media/materials/programs/Blur_ps.glsl new file mode 100644 index 00000000000..d6bb1939c8e --- /dev/null +++ b/res/dist/media/materials/programs/Blur_ps.glsl @@ -0,0 +1,14 @@ +uniform sampler2D tex0; + +varying vec2 texCoord[5]; + +void main() +{ + vec4 sum = texture2D(tex0, texCoord[0]) + + texture2D(tex0, texCoord[1]) + + texture2D(tex0, texCoord[2]) + + texture2D(tex0, texCoord[3]) + + texture2D(tex0, texCoord[4]); + gl_FragColor = sum / 5.0; +} + diff --git a/res/dist/media/materials/programs/Blur_ps.glsles b/res/dist/media/materials/programs/Blur_ps.glsles new file mode 100644 index 00000000000..bbde137469d --- /dev/null +++ b/res/dist/media/materials/programs/Blur_ps.glsles @@ -0,0 +1,18 @@ +#version 100 +precision mediump int; +precision mediump float; + +uniform sampler2D tex0; + +varying vec2 texCoord[5]; + +void main() +{ + vec4 sum = texture2D(tex0, texCoord[0]) + + texture2D(tex0, texCoord[1]) + + texture2D(tex0, texCoord[2]) + + texture2D(tex0, texCoord[3]) + + texture2D(tex0, texCoord[4]); + gl_FragColor = sum / 5.0; +} + diff --git a/res/dist/media/materials/programs/Blur_vs.glsl b/res/dist/media/materials/programs/Blur_vs.glsl new file mode 100644 index 00000000000..e64f9d31e99 --- /dev/null +++ b/res/dist/media/materials/programs/Blur_vs.glsl @@ -0,0 +1,14 @@ +void main() +{ + vec2 inPos = sign(gl_Vertex.xy); + gl_Position = vec4(inPos.xy, 0.0, 1.0); + + vec2 uv = (vec2(inPos.x, -inPos.y) + 1.0)*0.5; + gl_TexCoord[0] = vec4( uv, 0, 0 ); + + const float size = 0.01; + gl_TexCoord[1] = vec4( uv + vec2(0.0, 1.0)*size, 0, 0); + gl_TexCoord[2] = vec4( uv + vec2(0.0, 2.0)*size, 0, 0); + gl_TexCoord[3] = vec4( uv + vec2(0.0, -1.0)*size, 0, 0); + gl_TexCoord[4] = vec4( uv + vec2(0.0, -2.0)*size, 0, 0); +} diff --git a/res/dist/media/materials/programs/Blur_vs.glsles b/res/dist/media/materials/programs/Blur_vs.glsles new file mode 100644 index 00000000000..a32d54a8d12 --- /dev/null +++ b/res/dist/media/materials/programs/Blur_vs.glsles @@ -0,0 +1,24 @@ +#version 100 + +precision mediump int; +precision mediump float; + +varying vec2 texCoord; + +attribute vec4 vertex; + +void main() +{ + vec2 inPos = sign(vertex.xy); + gl_Position = vec4(inPos.xy, 0.0, 1.0); + + vec2 uv = (vec2(inPos.x, -inPos.y) + 1.0)*0.5; + texCoord = uv; + /* + const float size = 0.01; + texCoord[1] = uv + vec2(0.0, 1.0)*size; + texCoord[2] = uv + vec2(0.0, 2.0)*size; + texCoord[3] = uv + vec2(0.0, -1.0)*size; + texCoord[4] = uv + vec2(0.0, -2.0)*size; + */ +} diff --git a/res/dist/media/materials/programs/Blur_vs11.hlsl b/res/dist/media/materials/programs/Blur_vs11.hlsl new file mode 100644 index 00000000000..49b316f169c --- /dev/null +++ b/res/dist/media/materials/programs/Blur_vs11.hlsl @@ -0,0 +1,19 @@ +struct VS_OUTPUT { + float4 Pos: POSITION; + float2 texCoord: TEXCOORD0; +}; + +VS_OUTPUT main(float4 Pos: POSITION){ + VS_OUTPUT Out; + + // Clean up inaccuracies + Pos.xy = sign(Pos.xy); + + Out.Pos = float4(Pos.xy, 0, 1); + // Image-space + Out.texCoord.x = 0.5 * (1 + Pos.x); + Out.texCoord.y = 0.5 * (1 - Pos.y); + + return Out; +} + diff --git a/res/dist/media/materials/programs/BrightBloom2_ps20.glsl b/res/dist/media/materials/programs/BrightBloom2_ps20.glsl new file mode 100644 index 00000000000..4a3b9ab021d --- /dev/null +++ b/res/dist/media/materials/programs/BrightBloom2_ps20.glsl @@ -0,0 +1,29 @@ +//------------------------------- +//BrightBloom_ps20.glsl +// High-pass filter for obtaining lumminance +// We use an aproximation formula that is pretty fast: +// f(x) = ( -3 * ( x - 1 )^2 + 1 ) * 2 +// Color += Grayscale( f(Color) ) + 0.6 +// +// Special thanks to ATI for their great HLSL2GLSL utility +// http://sourceforge.net/projects/hlsl2glsl +//------------------------------- + +uniform sampler2D RT; + +void main() +{ + vec4 tex; + vec4 bright4; + float bright; + + vec2 texCoord = vec2( gl_TexCoord[0] ); + + tex = texture2D( RT, texCoord); + tex -= 1.00000; + bright4 = -6.00000 * tex * tex + 2.00000; + bright = dot( bright4, vec4( 0.333333, 0.333333, 0.333333, 0.000000) ); + tex += (bright + 0.600000); + + gl_FragColor = tex; +} diff --git a/res/dist/media/materials/programs/BrightBloom2_ps20.glsles b/res/dist/media/materials/programs/BrightBloom2_ps20.glsles new file mode 100644 index 00000000000..3dc06925a21 --- /dev/null +++ b/res/dist/media/materials/programs/BrightBloom2_ps20.glsles @@ -0,0 +1,32 @@ +#version 100 +precision mediump int; +precision mediump float; + +//------------------------------- +//BrightBloom_ps20.glsles +// High-pass filter for obtaining luminance +// We use an approximation formula that is pretty fast: +// f(x) = ( -3 * ( x - 1 )^2 + 1 ) * 2 +// Color += Grayscale( f(Color) ) + 0.6 +// +// Special thanks to ATI for their great HLSL2GLSL utility +// http://sourceforge.net/projects/hlsl2glsl +//------------------------------- + +uniform sampler2D RT; +varying vec2 uv; + +void main() +{ + vec4 tex; + vec4 bright4; + float bright; + + tex = texture2D(RT, uv); + tex -= 1.00000; + bright4 = -6.00000 * tex * tex + 2.00000; + bright = dot( bright4, vec4( 0.333333, 0.333333, 0.333333, 0.000000) ); + tex += (bright + 0.600000); + + gl_FragColor = tex; +} diff --git a/res/dist/media/materials/programs/BrightBloom2_ps20.hlsl b/res/dist/media/materials/programs/BrightBloom2_ps20.hlsl new file mode 100644 index 00000000000..81c7bf53b53 --- /dev/null +++ b/res/dist/media/materials/programs/BrightBloom2_ps20.hlsl @@ -0,0 +1,20 @@ +//------------------------------- +//BrightBloom_ps20.hlsl +// High-pass filter for obtaining lumminance +// We use an aproximation formula that is pretty fast: +// f(x) = ( -3 * ( x - 1 )^2 + 1 ) * 2 +// Color += f(Color) +//------------------------------- + +float4 main(float2 texCoord: TEXCOORD0, + uniform sampler RT: register(s0) + ) : COLOR { + float4 tex = tex2D(RT, texCoord); + + tex -= 1; + float4 bright4= -6 * tex * tex + 2; //float4 bright4= ( -3 * tex * tex + 1 ) * 2; + float bright = dot( bright4, float4( 0.333333, 0.333333, 0.333333, 0) ); + tex += bright + 0.6; + + return tex; +} diff --git a/res/dist/media/materials/programs/ColdCasterFp.glsles b/res/dist/media/materials/programs/ColdCasterFp.glsles new file mode 100644 index 00000000000..9ba88ef2111 --- /dev/null +++ b/res/dist/media/materials/programs/ColdCasterFp.glsles @@ -0,0 +1,11 @@ +#version 100 + +precision mediump int; +precision mediump float; + +varying vec2 NDotV; + +void main() +{ + gl_FragColor = vec4(NDotV.x / 2.0); +} diff --git a/res/dist/media/materials/programs/ColdCasterVp.glsles b/res/dist/media/materials/programs/ColdCasterVp.glsles new file mode 100644 index 00000000000..571759710db --- /dev/null +++ b/res/dist/media/materials/programs/ColdCasterVp.glsles @@ -0,0 +1,18 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform mat4 worldViewProj; +uniform vec3 eyePosition; +attribute vec4 position; +attribute vec4 normal; +varying vec2 NDotV; + +void main() +{ + vec4 eyeDir = vec4(eyePosition - position.xyz, 0.0); + eyeDir = normalize(eyeDir); + gl_Position = worldViewProj * position; + NDotV = vec2(clamp( dot( normal, eyeDir ), 0.0, 1.0 )); +} diff --git a/res/dist/media/materials/programs/Combine_fp.cg b/res/dist/media/materials/programs/Combine_fp.cg new file mode 100644 index 00000000000..6ad9c7b7d64 --- /dev/null +++ b/res/dist/media/materials/programs/Combine_fp.cg @@ -0,0 +1,15 @@ +float4 Combine_fp +( + in float2 texCoord: TEXCOORD0, + + uniform sampler RT : register(s0), + uniform sampler Sum : register(s1), + + uniform float blur +) : COLOR +{ + float4 render = tex2D(RT, texCoord); + float4 sum = tex2D(Sum, texCoord); + + return lerp(render, sum, blur); +} diff --git a/res/dist/media/materials/programs/Combine_fp.glsles b/res/dist/media/materials/programs/Combine_fp.glsles new file mode 100644 index 00000000000..95c86ea1512 --- /dev/null +++ b/res/dist/media/materials/programs/Combine_fp.glsles @@ -0,0 +1,17 @@ +#version 100 +precision mediump int; +precision mediump float; + +uniform sampler2D RT; +uniform sampler2D Sum; +uniform float blur; + +varying vec2 uv; + +void main() +{ + vec4 render = texture2D(RT, uv); + vec4 sum = texture2D(Sum, uv); + + gl_FragColor = mix(render, sum, blur); +} diff --git a/res/dist/media/materials/programs/Common.cg b/res/dist/media/materials/programs/Common.cg new file mode 100644 index 00000000000..45a903d012c --- /dev/null +++ b/res/dist/media/materials/programs/Common.cg @@ -0,0 +1,81 @@ +struct outPixel +{ + float4 colour : COLOR0; +}; + +// General functions + +// Expand a range-compressed vector +half4 expand(half4 v) +{ + return v * 2 - 1; +} +half3 expand(half3 v) +{ + return v * 2 - 1; +} +half2 expand(half2 v) +{ + return v * 2 - 1; +} +half1 expand(half1 v) +{ + return v * 2 - 1; +} + +// Returns light direction from light position and vertex position +half3 getLightDirection(float4 lightPosition, float4 position) +{ + // calculate tangent space light vector + // Get object space light direction + // Non-normalised since we'll do that in the fragment program anyway + return lightPosition.xyz - (position.xyz * lightPosition.w); +} + +// Returns eye direction from eye position and vertex position +half3 getEyeDirection(float3 eyePosition, float4 position) +{ + return eyePosition - position.xyz; +} + +// Returns a Tangent Binormal Normal matrix +half3x3 getTBNMatrix(float3 tangent, float3 normal) +{ + // Calculate the binormal (NB we assume both normal and tangent are + // already normalised) + // NB looks like nvidia cross params are BACKWARDS to what you'd expect + // this equates to NxT, not TxN + float3 binormal = cross(tangent, normal); + + // Form a rotation matrix out of the vectors + return half3x3(tangent, binormal, normal); +} + +// Returns expanded normal vector from texture map +half3 getNormalMapVector(sampler2D normalMap, float2 uv) +{ + // get bump map vector, again expand from range-compressed + return expand(tex2D(normalMap, uv).xyz); +} + +// Returns displacement vector from normalmaps alpha channel +half getDisplacement(sampler2D normalMap, float2 uv, half scale, half bias) +{ + // get the height using the tex coords + half height = tex2D(normalMap, uv).a; + + // calculate displacement + return (height * scale) + bias; +} + +// Returns a specular component from normal vector, specular colour and specular power +half3 getSpecularComponent(float3 normal, float3 halfAngle, float3 specularcolour, float specularPower) +{ + return pow(saturate(dot(normal, halfAngle)), specularPower) * specularcolour; +} + +// Returns a per-pixel lighted component from normal vector, lightdir and colour +half3 getLightingComponent(float3 normal, float3 lightDir, float3 colour) +{ + return saturate(dot(normal, lightDir)) * colour; +} diff --git a/res/dist/media/materials/programs/DOF_ps.cg b/res/dist/media/materials/programs/DOF_ps.cg new file mode 100644 index 00000000000..ecf8ce06f22 --- /dev/null +++ b/res/dist/media/materials/programs/DOF_ps.cg @@ -0,0 +1,47 @@ +// Simple blur filter + +const float2 samples[8] = { + {-1, 1}, + {-1, 0}, + {-1, -1}, + {0, -1}, + {1, -1}, + {1, 0}, + {1, 1}, + {0, 1} +}; + +float4 blur( + + in float2 texCoord: TEXCOORD0, + uniform float sampleDistance: register(c0), + uniform sampler Blur0: register(s0) + +) : COLOR +{ + float4 sum = tex2D(Blur0, texCoord); + for (int i = 0; i < 8; ++i){ + sum += tex2D(Blur0, texCoord + sampleDistance * samples[i]); + } + return sum / 9; +} + + + +float4 blend +( + in float2 texCoord: TEXCOORD0, + + uniform sampler Blur0 : register(s0), + uniform sampler Blur1 : register(s1), + + uniform float focus: register(c0), + uniform float range: register(c1) +) : COLOR +{ + float4 sharp = tex2D(Blur0, texCoord); + float4 blur = tex2D(Blur1, texCoord); + + // alpha channel of sharp RT has depth info + return lerp(sharp, blur, saturate(range * abs(focus - sharp.a))); +} diff --git a/res/dist/media/materials/programs/DOF_ps.glsles b/res/dist/media/materials/programs/DOF_ps.glsles new file mode 100644 index 00000000000..833d955b151 --- /dev/null +++ b/res/dist/media/materials/programs/DOF_ps.glsles @@ -0,0 +1,94 @@ +// Simple blur filter + +const float2 samples[8] = { + {-1, 1}, + {-1, 0}, + {-1, -1}, + {0, -1}, + {1, -1}, + {1, 0}, + {1, 1}, + {0, 1} +}; + +float4 blur( + + in float2 texCoord: TEXCOORD0, + uniform float sampleDistance: register(c0), + uniform sampler Blur0: register(s0) + +) : COLOR +{ + float4 sum = tex2D(Blur0, texCoord); + for (int i = 0; i < 8; ++i){ + sum += tex2D(Blur0, texCoord + sampleDistance * samples[i]); + } + return sum / 9; +} + + + +float4 blend +( + in float2 texCoord: TEXCOORD0, + + uniform sampler Blur0 : register(s0), + uniform sampler Blur1 : register(s1), + + uniform float focus: register(c0), + uniform float range: register(c1) +) : COLOR +{ + float4 sharp = tex2D(Blur0, texCoord); + float4 blur = tex2D(Blur1, texCoord); + + // alpha channel of sharp RT has depth info + return mix(sharp, blur, saturate(range * abs(focus - sharp.a))); +} +// Simple blur filter + +const float2 samples[8] = { + {-1, 1}, + {-1, 0}, + {-1, -1}, + {0, -1}, + {1, -1}, + {1, 0}, + {1, 1}, + {0, 1} +}; + +float4 blur( + + in float2 texCoord: TEXCOORD0, + uniform float sampleDistance: register(c0), + uniform sampler Blur0: register(s0) + +) : COLOR +{ + float4 sum = tex2D(Blur0, texCoord); + for (int i = 0; i < 8; ++i){ + sum += tex2D(Blur0, texCoord + sampleDistance * samples[i]); + } + return sum / 9; +} + + + +float4 blend +( + in float2 texCoord: TEXCOORD0, + + uniform sampler Blur0 : register(s0), + uniform sampler Blur1 : register(s1), + + uniform float focus: register(c0), + uniform float range: register(c1) +) : COLOR +{ + float4 sharp = tex2D(Blur0, texCoord); + float4 blur = tex2D(Blur1, texCoord); + + // alpha channel of sharp RT has depth info + return mix(sharp, blur, saturate(range * abs(focus - sharp.a))); +} diff --git a/res/dist/media/materials/programs/DepthShadowmap.hlsl b/res/dist/media/materials/programs/DepthShadowmap.hlsl new file mode 100644 index 00000000000..f79134346d0 --- /dev/null +++ b/res/dist/media/materials/programs/DepthShadowmap.hlsl @@ -0,0 +1,309 @@ +/* This file implements standard programs for depth shadow mapping. + These particular ones are suitable for additive lighting models, and + include 3 techniques to reduce depth fighting on self-shadowed surfaces, + constant bias, gradient (slope-scale) bias, and a fuzzy shadow map comparison*/ + + +// Shadow caster vertex program. +void casterVP( + float4 position : POSITION, + out float4 outPos : POSITION, + out float2 outDepth : TEXCOORD0, + + uniform float4x4 worldViewProj, + uniform float4 texelOffsets, + uniform float4 depthRange + ) +{ + outPos = mul(worldViewProj, position); + + // fix pixel / texel alignment + outPos.xy += texelOffsets.zw * outPos.w; + // linear depth storage + // offset / scale range output +#if LINEAR_RANGE + outDepth.x = (outPos.z - depthRange.x) * depthRange.w; +#else + outDepth.x = outPos.z; +#endif + outDepth.y = outPos.w; +} + + +// Shadow caster fragment program for high-precision single-channel textures +void casterFP( + float2 depth : TEXCOORD0, + out float4 result : COLOR) + +{ +#if LINEAR_RANGE + float finalDepth = depth.x; +#else + float finalDepth = depth.x / depth.y; +#endif + // just smear across all components + // therefore this one needs high individual channel precision + result = float4(finalDepth, finalDepth, finalDepth, 1); +} + + + +void receiverVP( + float4 position : POSITION, + float4 normal : NORMAL, + + out float4 outPos : POSITION, + out float4 outColour : COLOR, + out float4 outShadowUV : TEXCOORD0, + + uniform float4x4 world, + uniform float4x4 worldIT, + uniform float4x4 worldViewProj, + uniform float4x4 texViewProj, + uniform float4 lightPosition, + uniform float4 lightColour, + uniform float4 shadowDepthRange + ) +{ + float4 worldPos = mul(world, position); + outPos = mul(worldViewProj, position); + + float3 worldNorm = mul(worldIT, normal).xyz; + + // calculate lighting (simple vertex lighting) + float3 lightDir = normalize( + lightPosition.xyz - (worldPos.xyz * lightPosition.w)); + + outColour = lightColour * max(dot(lightDir, worldNorm), 0.0); + + // calculate shadow map coords + outShadowUV = mul(texViewProj, worldPos); +#if LINEAR_RANGE + // adjust by fixed depth bias, rescale into range + outShadowUV.z = (outShadowUV.z - shadowDepthRange.x) * shadowDepthRange.w; +#endif + + + + +} + +void receiverFP( + float4 position : POSITION, + float4 shadowUV : TEXCOORD0, + float4 vertexColour : COLOR, + + uniform sampler2D shadowMap : register(s0), + uniform float inverseShadowmapSize, + uniform float fixedDepthBias, + uniform float gradientClamp, + uniform float gradientScaleBias, + uniform float shadowFuzzyWidth, + + out float4 result : COLOR) +{ + // point on shadowmap +#if LINEAR_RANGE + shadowUV.xy = shadowUV.xy / shadowUV.w; +#else + shadowUV = shadowUV / shadowUV.w; +#endif + float centerdepth = tex2D(shadowMap, shadowUV.xy).x; + + // gradient calculation + float pixeloffset = inverseShadowmapSize; + float4 depths = float4( + tex2D(shadowMap, shadowUV.xy + float2(-pixeloffset, 0)).x, + tex2D(shadowMap, shadowUV.xy + float2(+pixeloffset, 0)).x, + tex2D(shadowMap, shadowUV.xy + float2(0, -pixeloffset)).x, + tex2D(shadowMap, shadowUV.xy + float2(0, +pixeloffset)).x); + + float2 differences = abs( depths.yw - depths.xz ); + float gradient = min(gradientClamp, max(differences.x, differences.y)); + float gradientFactor = gradient * gradientScaleBias; + + // visibility function + float depthAdjust = gradientFactor + (fixedDepthBias * centerdepth); + float finalCenterDepth = centerdepth + depthAdjust; + + // shadowUV.z contains lightspace position of current object + +#if FUZZY_TEST + // fuzzy test - introduces some ghosting in result and doesn't appear to be needed? + //float visibility = saturate(1 + delta_z / (gradient * shadowFuzzyWidth)); + float visibility = saturate(1 + (finalCenterDepth - shadowUV.z) * shadowFuzzyWidth * shadowUV.w); + + result = vertexColour * visibility; +#else + // hard test +#if PCF + // use depths from prev, calculate diff + depths += depthAdjust.xxxx; + float final = (finalCenterDepth > shadowUV.z) ? 1.0f : 0.0f; + final += (depths.x > shadowUV.z) ? 1.0f : 0.0f; + final += (depths.y > shadowUV.z) ? 1.0f : 0.0f; + final += (depths.z > shadowUV.z) ? 1.0f : 0.0f; + final += (depths.w > shadowUV.z) ? 1.0f : 0.0f; + + final *= 0.2f; + + result = float4(vertexColour.xyz * final, 1); + +#else + result = (finalCenterDepth > shadowUV.z) ? vertexColour : float4(0,0,0,1); +#endif + +#endif + + + +} + + + + +// Expand a range-compressed vector +float3 expand(float3 v) +{ + return (v - 0.5) * 2; +} + + +/* Normal mapping plus depth shadowmapping receiver programs +*/ +void normalMapShadowReceiverVp(float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float3 tangent : TANGENT0, + + // outputs + out float4 outPos : POSITION, + out float4 outShadowUV : TEXCOORD0, + out float2 oUv : TEXCOORD1, + out float3 oTSLightDir : TEXCOORD2, + // parameters + uniform float4 lightPosition, // object space + uniform float4x4 world, + uniform float4x4 worldViewProj, + uniform float4x4 texViewProj) +{ + float4 worldPos = mul(world, position); + outPos = mul(worldViewProj, position); + + // calculate shadow map coords + outShadowUV = mul(texViewProj, worldPos); +#if LINEAR_RANGE + // adjust by fixed depth bias, rescale into range + outShadowUV.z = (outShadowUV.z - shadowDepthRange.x) * shadowDepthRange.w; +#endif + + // pass the main uvs straight through unchanged + oUv = uv; + + // calculate tangent space light vector + // Get object space light direction + // Non-normalised since we'll do that in the fragment program anyway + float3 lightDir = lightPosition.xyz - (position * lightPosition.w); + + // Calculate the binormal (NB we assume both normal and tangent are + // already normalised) + // NB looks like nvidia cross params are BACKWARDS to what you'd expect + // this equates to NxT, not TxN + float3 binormal = cross(tangent, normal); + + // Form a rotation matrix out of the vectors + float3x3 rotation = float3x3(tangent, binormal, normal); + + // Transform the light vector according to this matrix + oTSLightDir = mul(rotation, lightDir); + + +} + + +void normalMapShadowReceiverFp( + float4 shadowUV : TEXCOORD0, + float2 uv : TEXCOORD1, + float3 TSlightDir : TEXCOORD2, + + out float4 result : COLOR, + + uniform float4 lightColour, + uniform float inverseShadowmapSize, + uniform float fixedDepthBias, + uniform float gradientClamp, + uniform float gradientScaleBias, + uniform float shadowFuzzyWidth, + + uniform sampler2D shadowMap : register(s0), + uniform sampler2D normalMap : register(s1), + uniform samplerCUBE normalCubeMap : register(s2)) +{ + + // retrieve normalised light vector, expand from range-compressed + float3 lightVec = expand(texCUBE(normalCubeMap, TSlightDir).xyz); + + // get bump map vector, again expand from range-compressed + float3 bumpVec = expand(tex2D(normalMap, uv).xyz); + + // Calculate dot product + float4 vertexColour = lightColour * dot(bumpVec, lightVec); + + + // point on shadowmap +#if LINEAR_RANGE + shadowUV.xy = shadowUV.xy / shadowUV.w; +#else + shadowUV = shadowUV / shadowUV.w; +#endif + float centerdepth = tex2D(shadowMap, shadowUV.xy).x; + + // gradient calculation + float pixeloffset = inverseShadowmapSize; + float4 depths = float4( + tex2D(shadowMap, shadowUV.xy + float2(-pixeloffset, 0)).x, + tex2D(shadowMap, shadowUV.xy + float2(+pixeloffset, 0)).x, + tex2D(shadowMap, shadowUV.xy + float2(0, -pixeloffset)).x, + tex2D(shadowMap, shadowUV.xy + float2(0, +pixeloffset)).x); + + float2 differences = abs( depths.yw - depths.xz ); + float gradient = min(gradientClamp, max(differences.x, differences.y)); + float gradientFactor = gradient * gradientScaleBias; + + // visibility function + float depthAdjust = gradientFactor + (fixedDepthBias * centerdepth); + float finalCenterDepth = centerdepth + depthAdjust; + + // shadowUV.z contains lightspace position of current object + +#if FUZZY_TEST + // fuzzy test - introduces some ghosting in result and doesn't appear to be needed? + //float visibility = saturate(1 + delta_z / (gradient * shadowFuzzyWidth)); + float visibility = saturate(1 + (finalCenterDepth - shadowUV.z) * shadowFuzzyWidth * shadowUV.w); + + result = vertexColour * visibility; +#else + // hard test +#if PCF + // use depths from prev, calculate diff + depths += depthAdjust.xxxx; + float final = (finalCenterDepth > shadowUV.z) ? 1.0f : 0.0f; + final += (depths.x > shadowUV.z) ? 1.0f : 0.0f; + final += (depths.y > shadowUV.z) ? 1.0f : 0.0f; + final += (depths.z > shadowUV.z) ? 1.0f : 0.0f; + final += (depths.w > shadowUV.z) ? 1.0f : 0.0f; + + final *= 0.2f; + + result = float4(vertexColour.xyz * final, 1); + +#else + result = (finalCenterDepth > shadowUV.z) ? vertexColour : float4(0,0,0,1); +#endif + +#endif + + + +} + diff --git a/res/dist/media/materials/programs/DepthShadowmapCasterFp.glsl b/res/dist/media/materials/programs/DepthShadowmapCasterFp.glsl new file mode 100644 index 00000000000..1e32d262647 --- /dev/null +++ b/res/dist/media/materials/programs/DepthShadowmapCasterFp.glsl @@ -0,0 +1,16 @@ + +varying vec2 depth; + +void main() +{ +#if LINEAR_RANGE + float finalDepth = depth.x; +#else + float finalDepth = depth.x / depth.y; +#endif + // just smear across all components + // therefore this one needs high individual channel precision + gl_FragColor = vec4(finalDepth, finalDepth, finalDepth, 1); + +} + diff --git a/res/dist/media/materials/programs/DepthShadowmapCasterFp.glsles b/res/dist/media/materials/programs/DepthShadowmapCasterFp.glsles new file mode 100644 index 00000000000..827305b5483 --- /dev/null +++ b/res/dist/media/materials/programs/DepthShadowmapCasterFp.glsles @@ -0,0 +1,19 @@ +#version 100 + +precision mediump int; +precision mediump float; + +varying vec2 depth; + +void main() +{ +#if LINEAR_RANGE + float finalDepth = depth.x; +#else + float finalDepth = depth.x / depth.y; +#endif + // just smear across all components + // therefore this one needs high individual channel precision + gl_FragColor = vec4(finalDepth, finalDepth, finalDepth, 1.0); + +} diff --git a/res/dist/media/materials/programs/DepthShadowmapCasterVp.glsl b/res/dist/media/materials/programs/DepthShadowmapCasterVp.glsl new file mode 100644 index 00000000000..2f19c7599c2 --- /dev/null +++ b/res/dist/media/materials/programs/DepthShadowmapCasterVp.glsl @@ -0,0 +1,24 @@ +uniform mat4 worldViewProj; +uniform vec4 texelOffsets; +uniform vec4 depthRange; + +varying vec2 depth; + +void main() +{ + gl_Position = ftransform(); + + // fix pixel / texel alignment + gl_Position.xy += texelOffsets.zw * gl_Position.w; + // linear depth storage + // offset / scale range output +#if LINEAR_RANGE + depth.x = (gl_Position.z - depthRange.x) * depthRange.w; +#else + depth.x = gl_Position.z; +#endif + depth.y = gl_Position.w; + + +} + diff --git a/res/dist/media/materials/programs/DepthShadowmapCasterVp.glsles b/res/dist/media/materials/programs/DepthShadowmapCasterVp.glsles new file mode 100644 index 00000000000..a347c4d1ea7 --- /dev/null +++ b/res/dist/media/materials/programs/DepthShadowmapCasterVp.glsles @@ -0,0 +1,27 @@ +#version 100 +precision mediump int; +precision mediump float; + +uniform mat4 worldViewProj; +uniform vec4 texelOffsets; +uniform vec4 depthRange; + +varying vec2 depth; + +attribute vec4 position; + +void main() +{ + gl_Position = position * worldViewProj; + + // fix pixel / texel alignment + gl_Position.xy += texelOffsets.zw * gl_Position.w; + // linear depth storage + // offset / scale range output +#if LINEAR_RANGE + depth.x = (gl_Position.z - depthRange.x) * depthRange.w; +#else + depth.x = gl_Position.z; +#endif + depth.y = gl_Position.w; +} diff --git a/res/dist/media/materials/programs/DepthShadowmapNormalMapReceiverFp.glsl b/res/dist/media/materials/programs/DepthShadowmapNormalMapReceiverFp.glsl new file mode 100644 index 00000000000..2c45a54534d --- /dev/null +++ b/res/dist/media/materials/programs/DepthShadowmapNormalMapReceiverFp.glsl @@ -0,0 +1,84 @@ +uniform float inverseShadowmapSize; +uniform float fixedDepthBias; +uniform float gradientClamp; +uniform float gradientScaleBias; +uniform float shadowFuzzyWidth; +uniform vec4 lightColour; + +uniform sampler2D shadowMap; +uniform sampler2D normalMap; + +varying vec3 tangentLightDir; + + +// Expand a range-compressed vector +vec3 expand(vec3 v) +{ + return (v - 0.5) * 2.0; +} + +void main() +{ + + // get the new normal and diffuse values + vec3 normal = normalize(expand(texture2D(normalMap, gl_TexCoord[1].xy).xyz)); + + vec4 vertexColour = clamp(dot(normal, tangentLightDir),0.0,1.0) * lightColour; + + + vec4 shadowUV = gl_TexCoord[0]; + // point on shadowmap +#if LINEAR_RANGE + shadowUV.xy = shadowUV.xy / shadowUV.w; +#else + shadowUV = shadowUV / shadowUV.w; +#endif + float centerdepth = texture2D(shadowMap, shadowUV.xy).x; + + // gradient calculation + float pixeloffset = inverseShadowmapSize; + vec4 depths = vec4( + texture2D(shadowMap, shadowUV.xy + vec2(-pixeloffset, 0)).x, + texture2D(shadowMap, shadowUV.xy + vec2(+pixeloffset, 0)).x, + texture2D(shadowMap, shadowUV.xy + vec2(0, -pixeloffset)).x, + texture2D(shadowMap, shadowUV.xy + vec2(0, +pixeloffset)).x); + + vec2 differences = abs( depths.yw - depths.xz ); + float gradient = min(gradientClamp, max(differences.x, differences.y)); + float gradientFactor = gradient * gradientScaleBias; + + // visibility function + float depthAdjust = gradientFactor + (fixedDepthBias * centerdepth); + float finalCenterDepth = centerdepth + depthAdjust; + + // shadowUV.z contains lightspace position of current object + +#if FUZZY_TEST + // fuzzy test - introduces some ghosting in result and doesn't appear to be needed? + //float visibility = saturate(1 + delta_z / (gradient * shadowFuzzyWidth)); + float visibility = saturate(1 + (finalCenterDepth - shadowUV.z) * shadowFuzzyWidth * shadowUV.w); + + gl_FragColor = vertexColour * visibility; +#else + // hard test +#if PCF + // use depths from prev, calculate diff + depths += depthAdjust; + float final = (finalCenterDepth > shadowUV.z) ? 1.0 : 0.0; + final += (depths.x > shadowUV.z) ? 1.0 : 0.0; + final += (depths.y > shadowUV.z) ? 1.0 : 0.0; + final += (depths.z > shadowUV.z) ? 1.0 : 0.0; + final += (depths.w > shadowUV.z) ? 1.0 : 0.0; + + final *= 0.2; + + gl_FragColor = vec4(vertexColour.xyz * final, 1); + +#else + gl_FragColor = (finalCenterDepth > shadowUV.z) ? vertexColour : vec4(0,0,0,1); +#endif + +#endif + +} + diff --git a/res/dist/media/materials/programs/DepthShadowmapNormalMapReceiverFp.glsles b/res/dist/media/materials/programs/DepthShadowmapNormalMapReceiverFp.glsles new file mode 100644 index 00000000000..15eca58ebe0 --- /dev/null +++ b/res/dist/media/materials/programs/DepthShadowmapNormalMapReceiverFp.glsles @@ -0,0 +1,86 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform float inverseShadowmapSize; +uniform float fixedDepthBias; +uniform float gradientClamp; +uniform float gradientScaleBias; +uniform float shadowFuzzyWidth; +uniform vec4 lightColour; + +uniform sampler2D shadowMap; +uniform sampler2D normalMap; + +varying vec3 tangentLightDir; +varying vec4 vUv0; +varying vec4 vUv1; + +// Expand a range-compressed vector +vec3 expand(vec3 v) +{ + return (v - 0.5) * 2.0; +} + +void main() +{ + + // get the new normal and diffuse values + vec3 normal = normalize(expand(texture2D(normalMap, vUv1.xy).xyz)); + vec4 vertexColour = clamp(dot(normal, tangentLightDir), 0.0, 1.0) * lightColour; + vec4 shadowUV = vUv0; + // point on shadowmap +#if LINEAR_RANGE + shadowUV.xy = shadowUV.xy / shadowUV.w; +#else + shadowUV = shadowUV / shadowUV.w; +#endif + float centerdepth = texture2D(shadowMap, shadowUV.xy).x; + + // gradient calculation + float pixeloffset = inverseShadowmapSize; + vec4 depths = vec4( + texture2D(shadowMap, shadowUV.xy + vec2(-pixeloffset, 0.0)).x, + texture2D(shadowMap, shadowUV.xy + vec2(+pixeloffset, 0.0)).x, + texture2D(shadowMap, shadowUV.xy + vec2(0.0, -pixeloffset)).x, + texture2D(shadowMap, shadowUV.xy + vec2(0.0, +pixeloffset)).x); + + vec2 differences = abs( depths.yw - depths.xz ); + float gradient = min(gradientClamp, max(differences.x, differences.y)); + float gradientFactor = gradient * gradientScaleBias; + + // visibility function + float depthAdjust = gradientFactor + (fixedDepthBias * centerdepth); + float finalCenterDepth = centerdepth + depthAdjust; + + // shadowUV.z contains lightspace position of current object + +#if FUZZY_TEST + // fuzzy test - introduces some ghosting in result and doesn't appear to be needed? + //float visibility = saturate(1 + delta_z / (gradient * shadowFuzzyWidth)); + float visibility = saturate(1.0 + (finalCenterDepth - shadowUV.z) * shadowFuzzyWidth * shadowUV.w); + + gl_FragColor = vertexColour * visibility; +#else + // hard test +#if PCF + // use depths from prev, calculate diff + depths += depthAdjust; + float final = (finalCenterDepth > shadowUV.z) ? 1.0 : 0.0; + final += (depths.x > shadowUV.z) ? 1.0 : 0.0; + final += (depths.y > shadowUV.z) ? 1.0 : 0.0; + final += (depths.z > shadowUV.z) ? 1.0 : 0.0; + final += (depths.w > shadowUV.z) ? 1.0 : 0.0; + + final *= 0.2; + + gl_FragColor = vec4(vertexColour.xyz * final, 1.0); + +#else + gl_FragColor = (finalCenterDepth > shadowUV.z) ? vertexColour : vec4(0.0, 0.0, 0.0, 1.0); +#endif + +#endif + +} diff --git a/res/dist/media/materials/programs/DepthShadowmapNormalMapReceiverVp.glsl b/res/dist/media/materials/programs/DepthShadowmapNormalMapReceiverVp.glsl new file mode 100644 index 00000000000..66762f3ea89 --- /dev/null +++ b/res/dist/media/materials/programs/DepthShadowmapNormalMapReceiverVp.glsl @@ -0,0 +1,42 @@ +attribute vec3 tangent; + +uniform mat4 world; +uniform mat4 worldViewProj; +uniform mat4 texViewProj; +uniform vec4 lightPosition; // object space +uniform vec4 shadowDepthRange; + +varying vec3 tangentLightDir; + + +void main() +{ + gl_Position = ftransform(); + + vec4 worldPos = world * gl_Vertex; + + // Get object space light direction + vec3 lightDir = normalize(lightPosition.xyz - (gl_Vertex.xyz * lightPosition.w)); + + // calculate shadow map coords + gl_TexCoord[0] = texViewProj * worldPos; +#if LINEAR_RANGE + // adjust by fixed depth bias, rescale into range + gl_TexCoord[0].z = (gl_TexCoord[0].z - shadowDepthRange.x) * shadowDepthRange.w; +#endif + + // pass the main uvs straight through unchanged + gl_TexCoord[1] = gl_MultiTexCoord0; + + // Calculate the binormal (NB we assume both normal and tangent are + // already normalised) + vec3 binormal = cross(gl_Normal, tangent); + + // Form a rotation matrix out of the vectors + mat3 rotation = mat3(tangent, binormal, gl_Normal); + + // Transform the light vector according to this matrix + tangentLightDir = normalize(rotation * lightDir); + +} + diff --git a/res/dist/media/materials/programs/DepthShadowmapNormalMapReceiverVp.glsles b/res/dist/media/materials/programs/DepthShadowmapNormalMapReceiverVp.glsles new file mode 100644 index 00000000000..6b7274872ee --- /dev/null +++ b/res/dist/media/materials/programs/DepthShadowmapNormalMapReceiverVp.glsles @@ -0,0 +1,51 @@ +#version 100 +precision mediump int; +precision mediump float; + +attribute vec3 tangent; +attribute vec4 position; +attribute vec3 normal; + +uniform mat4 world; +uniform mat4 worldViewProj; +uniform mat4 texViewProj; +uniform vec4 lightPosition; // object space +uniform vec4 shadowDepthRange; + +varying vec3 tangentLightDir; +varying vec4 vUv0; +varying vec4 vUv1; + +attribute vec4 uv0; +attribute vec4 uv1; + +void main() +{ + gl_Position = position * worldViewProj; + + vec4 worldPos = world * position; + + // Get object space light direction + vec3 lightDir = normalize(lightPosition.xyz - (position.xyz * lightPosition.w)); + + // calculate shadow map coords + vUv0 = texViewProj * worldPos; +#if LINEAR_RANGE + // adjust by fixed depth bias, rescale into range + vUv0.z = (uv0.z - shadowDepthRange.x) * shadowDepthRange.w; +#endif + + vUv1 = uv1; + + // Calculate the binormal (NB we assume both normal and tangent are + // already normalised) + vec3 binormal = cross(normal, tangent); + + // Form a rotation matrix out of the vectors, column major for glsl es + mat3 rotation = mat3(vec3(tangent[0], binormal[0], normal[0]), + vec3(tangent[1], binormal[1], normal[1]), + vec3(tangent[2], binormal[2], normal[2])); + + // Transform the light vector according to this matrix + tangentLightDir = normalize(rotation * lightDir); +} diff --git a/res/dist/media/materials/programs/DepthShadowmapReceiverFp.glsl b/res/dist/media/materials/programs/DepthShadowmapReceiverFp.glsl new file mode 100644 index 00000000000..04ebeaadb9b --- /dev/null +++ b/res/dist/media/materials/programs/DepthShadowmapReceiverFp.glsl @@ -0,0 +1,66 @@ +uniform float inverseShadowmapSize; +uniform float fixedDepthBias; +uniform float gradientClamp; +uniform float gradientScaleBias; +uniform float shadowFuzzyWidth; + +uniform sampler2D shadowMap; + +void main() +{ + vec4 shadowUV = gl_TexCoord[0]; + // point on shadowmap +#if LINEAR_RANGE + shadowUV.xy = shadowUV.xy / shadowUV.w; +#else + shadowUV = shadowUV / shadowUV.w; +#endif + float centerdepth = texture2D(shadowMap, shadowUV.xy).x; + + // gradient calculation + float pixeloffset = inverseShadowmapSize; + vec4 depths = vec4( + texture2D(shadowMap, shadowUV.xy + vec2(-pixeloffset, 0)).x, + texture2D(shadowMap, shadowUV.xy + vec2(+pixeloffset, 0)).x, + texture2D(shadowMap, shadowUV.xy + vec2(0, -pixeloffset)).x, + texture2D(shadowMap, shadowUV.xy + vec2(0, +pixeloffset)).x); + + vec2 differences = abs( depths.yw - depths.xz ); + float gradient = min(gradientClamp, max(differences.x, differences.y)); + float gradientFactor = gradient * gradientScaleBias; + + // visibility function + float depthAdjust = gradientFactor + (fixedDepthBias * centerdepth); + float finalCenterDepth = centerdepth + depthAdjust; + + // shadowUV.z contains lightspace position of current object + +#if FUZZY_TEST + // fuzzy test - introduces some ghosting in result and doesn't appear to be needed? + //float visibility = saturate(1 + delta_z / (gradient * shadowFuzzyWidth)); + float visibility = saturate(1 + (finalCenterDepth - shadowUV.z) * shadowFuzzyWidth * shadowUV.w); + + gl_FragColor = vertexColour * visibility; +#else + // hard test +#if PCF + // use depths from prev, calculate diff + depths += depthAdjust; + float final = (finalCenterDepth > shadowUV.z) ? 1.0 : 0.0; + final += (depths.x > shadowUV.z) ? 1.0 : 0.0; + final += (depths.y > shadowUV.z) ? 1.0 : 0.0; + final += (depths.z > shadowUV.z) ? 1.0 : 0.0; + final += (depths.w > shadowUV.z) ? 1.0 : 0.0; + + final *= 0.2; + + gl_FragColor = vec4(gl_Color.xyz * final, 1); + +#else + gl_FragColor = (finalCenterDepth > shadowUV.z) ? gl_Color : vec4(0,0,0,1); +#endif + +#endif + +} + diff --git a/res/dist/media/materials/programs/DepthShadowmapReceiverFp.glsles b/res/dist/media/materials/programs/DepthShadowmapReceiverFp.glsles new file mode 100644 index 00000000000..62d3dfaaf17 --- /dev/null +++ b/res/dist/media/materials/programs/DepthShadowmapReceiverFp.glsles @@ -0,0 +1,67 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform float inverseShadowmapSize; +uniform float fixedDepthBias; +uniform float gradientClamp; +uniform float gradientScaleBias; +uniform float shadowFuzzyWidth; +uniform sampler2D shadowMap; + +varying vec4 shadowUV; +varying vec4 vColor; +varying vec4 oColour; + +void main() +{ + // point on shadowmap + float centerdepth = texture2D(shadowMap, shadowUV.xy).x; + + // gradient calculation + float pixeloffset = inverseShadowmapSize; + vec4 depths = vec4( + texture2D(shadowMap, shadowUV.xy + vec2(-pixeloffset, 0.0)).x, + texture2D(shadowMap, shadowUV.xy + vec2(+pixeloffset, 0.0)).x, + texture2D(shadowMap, shadowUV.xy + vec2(0.0, -pixeloffset)).x, + texture2D(shadowMap, shadowUV.xy + vec2(0.0, +pixeloffset)).x); + + vec2 differences = abs( depths.yw - depths.xz ); + float gradient = min(gradientClamp, max(differences.x, differences.y)); + float gradientFactor = gradient * gradientScaleBias; + + // visibility function + float depthAdjust = gradientFactor + (fixedDepthBias * centerdepth); + float finalCenterDepth = centerdepth + depthAdjust; + + // shadowUV.z contains lightspace position of current object + +#if FUZZY_TEST + // Fuzzy test - introduces some ghosting in result and doesn't appear to be needed? + //float visibility = saturate(1 + delta_z / (gradient * shadowFuzzyWidth)); + float visibility = saturate(1.0 + (finalCenterDepth - shadowUV.z) * shadowFuzzyWidth * shadowUV.w); + + gl_FragColor = vertexColour * visibility; +#else + // Hard test +#if PCF + // Use depths from prev, calculate diff + depths += depthAdjust; + float final = (finalCenterDepth > shadowUV.z) ? 1.0 : 0.0; + final += (depths.x > shadowUV.z) ? 1.0 : 0.0; + final += (depths.y > shadowUV.z) ? 1.0 : 0.0; + final += (depths.z > shadowUV.z) ? 1.0 : 0.0; + final += (depths.w > shadowUV.z) ? 1.0 : 0.0; + + final *= 0.2; + + gl_FragColor = vec4(oColour.xyz * final, 1.0); + +#else + gl_FragColor = (finalCenterDepth > shadowUV.z) ? oColour : vec4(0.0, 0.0, 0.0, 1.0); +#endif + +#endif + +} diff --git a/res/dist/media/materials/programs/DepthShadowmapReceiverVp.glsl b/res/dist/media/materials/programs/DepthShadowmapReceiverVp.glsl new file mode 100644 index 00000000000..85c32e6a1e1 --- /dev/null +++ b/res/dist/media/materials/programs/DepthShadowmapReceiverVp.glsl @@ -0,0 +1,32 @@ +uniform mat4 world; +uniform mat4 worldIT; +uniform mat4 worldViewProj; +uniform mat4 texViewProj; +uniform vec4 lightPosition; +uniform vec4 lightColour; +uniform vec4 shadowDepthRange; + + +void main() +{ + gl_Position = ftransform(); + + vec4 worldPos = world * gl_Vertex; + + vec3 worldNorm = (worldIT * vec4(gl_Normal, 1)).xyz; + + // calculate lighting (simple vertex lighting) + vec3 lightDir = normalize( + lightPosition.xyz - (worldPos.xyz * lightPosition.w)); + + gl_FrontColor = lightColour * max(dot(lightDir, worldNorm), 0.0); + + // calculate shadow map coords + gl_TexCoord[0] = texViewProj * worldPos; +#if LINEAR_RANGE + // adjust by fixed depth bias, rescale into range + gl_TexCoord[0].z = (gl_TexCoord[0].z - shadowDepthRange.x) * shadowDepthRange.w; +#endif + +} + diff --git a/res/dist/media/materials/programs/DepthShadowmapReceiverVp.glsles b/res/dist/media/materials/programs/DepthShadowmapReceiverVp.glsles new file mode 100644 index 00000000000..f07ca6fb958 --- /dev/null +++ b/res/dist/media/materials/programs/DepthShadowmapReceiverVp.glsles @@ -0,0 +1,42 @@ +#version 100 +precision mediump int; +precision mediump float; + +uniform mat4 world; +uniform mat4 worldIT; +uniform mat4 worldViewProj; +uniform mat4 texViewProj; +uniform vec4 lightPosition; +uniform vec4 lightColour; +uniform vec4 shadowDepthRange; + +attribute vec4 position; +attribute vec3 normal; +attribute vec4 ambient; + +varying vec4 shadowUV; +varying vec4 vColor; +varying vec4 oColour; + +void main() +{ + gl_Position = position * worldViewProj; + oColour = ambient; + vec4 worldPos = world * position; + vec3 worldNorm = (worldIT * vec4(normal, 1.0)).xyz; + + // Calculate lighting (simple vertex lighting) + vec3 lightDir = normalize(lightPosition.xyz - (worldPos.xyz * lightPosition.w)); + + vColor = lightColour * max(dot(lightDir, worldNorm), 0.0); + + // Calculate shadow map coords + shadowUV = texViewProj * worldPos; +#if LINEAR_RANGE + // Adjust by fixed depth bias, rescale into range + shadowUV.z = (shadowUV.z - shadowDepthRange.x) * shadowDepthRange.w; + shadowUV.xy = shadowUV.xy / shadowUV.w; +#else + shadowUV = shadowUV / shadowUV.w; +#endif +} diff --git a/res/dist/media/materials/programs/DiffuseOneTexture.glsles b/res/dist/media/materials/programs/DiffuseOneTexture.glsles new file mode 100644 index 00000000000..bc6c155eeda --- /dev/null +++ b/res/dist/media/materials/programs/DiffuseOneTexture.glsles @@ -0,0 +1,17 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform sampler2D texMap; + +varying vec4 colour; +varying vec4 uv; + +/* + Basic fragment program using texture and diffuse colour. +*/ +void main() +{ + gl_FragColor = texture2D(texMap, uv.xy) * colour; +} diff --git a/res/dist/media/materials/programs/DitherFP.cg b/res/dist/media/materials/programs/DitherFP.cg new file mode 100644 index 00000000000..e6500d176ba --- /dev/null +++ b/res/dist/media/materials/programs/DitherFP.cg @@ -0,0 +1,18 @@ +sampler2D RT : register(s0); +sampler2D pattern : register(s1); + +half4 Dither_ps(float4 pos : POSITION, float2 TexCoord : TEXCOORD0) : COLOR +{ + half c = dot(tex2D(RT, TexCoord),half4(0.30,0.11,0.59,0.00)); + half n = tex2D(pattern, TexCoord).a*2 - 1.0; + c += n; + if (c > 0.5) + { + c = 0.0; + } + else + { + c = 1.0; + } + return half4(c,c,c,1.0); +} \ No newline at end of file diff --git a/res/dist/media/materials/programs/DitherFP.glsles b/res/dist/media/materials/programs/DitherFP.glsles new file mode 100644 index 00000000000..bc9788421ec --- /dev/null +++ b/res/dist/media/materials/programs/DitherFP.glsles @@ -0,0 +1,25 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform sampler2D RT; +uniform sampler2D pattern; +varying vec2 uv0; +varying vec2 uv1; + +void main() +{ + float c = dot(texture2D(RT, uv0), vec4(0.30, 0.11, 0.59, 0.00)); + float n = texture2D(pattern, uv0).a*2.0 - 1.0; + c += n; + if (c > 0.5) + { + c = 0.0; + } + else + { + c = 1.0; + } + gl_FragColor = vec4(c,c,c,1.0); +} \ No newline at end of file diff --git a/res/dist/media/materials/programs/DualQuaternion.cg b/res/dist/media/materials/programs/DualQuaternion.cg new file mode 100644 index 00000000000..f468a97d39c --- /dev/null +++ b/res/dist/media/materials/programs/DualQuaternion.cg @@ -0,0 +1,159 @@ +#include "DualQuaternion_Common.cg" + +//Dual quaternion skinning with per-vertex antipodality handling (this is the most robust, but not the most efficient way): +void dualQuaternionHardwareSkinningTwoWeights_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float2x4 worldDualQuaternion2x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 lightPos[2], + uniform float4 lightDiffuseColour[2], + uniform float4 ambient, + uniform float4 diffuse) +{ + float2x4 blendDQ = blendTwoWeightsAntipod(blendWgt, blendIdx, worldDualQuaternion2x4Array); + + float len = length(blendDQ[0]); + blendDQ /= len; + + float3 blendPosition = calculateBlendPosition(position.xyz, blendDQ); + + //No need to normalize, the magnitude of the normal is preserved because only rotation is performed + float3 blendNormal = calculateBlendNormal(normal, blendDQ); + + oPosition = mul(viewProjectionMatrix, float4(blendPosition, 1.0)); + + // Lighting - support point and directional + float3 lightDir0 = normalize(lightPos[0].xyz - (blendPosition.xyz * lightPos[0].w)); + float3 lightDir1 = normalize(lightPos[1].xyz - (blendPosition.xyz * lightPos[1].w)); + + oUv = uv; + + colour = diffuse * (ambient + (saturate(dot(lightDir0, blendNormal)) * lightDiffuseColour[0]) + + (saturate(dot(lightDir1, blendNormal)) * lightDiffuseColour[1])); +} + + +//Shadow caster pass +void dualQuaternionHardwareSkinningTwoWeightsCaster_vp( + float4 position : POSITION, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + out float4 oPosition : POSITION, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float2x4 worldDualQuaternion2x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 ambient) +{ + float2x4 blendDQ = blendTwoWeightsAntipod(blendWgt, blendIdx, worldDualQuaternion2x4Array); + + float len = length(blendDQ[0]); + blendDQ /= len; + + float3 blendPosition = calculateBlendPosition(position.xyz, blendDQ); + + // view / projection + oPosition = mul(viewProjectionMatrix, float4(blendPosition, 1.0)); + + colour = ambient; +} + +//Two-phase skinning: dual quaternion skinning with scale and shear transformations +void dualQuaternionHardwareSkinningTwoWeightsTwoPhase_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float2x4 worldDualQuaternion2x4Array[24], + uniform float3x4 scaleM[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 lightPos[2], + uniform float4 lightDiffuseColour[2], + uniform float4 ambient, + uniform float4 diffuse) +{ + //First phase - applies scaling and shearing: + float3x4 blendS = blendWgt.x*scaleM[blendIdx.x]; + blendS += blendWgt.y*scaleM[blendIdx.y]; + + float3 pass1_position = mul(blendS, position); + float3x3 blendSrotAT = adjointTransposeMatrix(float3x3(blendS)); + float3 pass1_normal = normalize(mul(blendSrotAT, normal.xyz)); + + //Second phase + float2x4 blendDQ = blendTwoWeightsAntipod(blendWgt, blendIdx, worldDualQuaternion2x4Array); + + float len = length(blendDQ[0]); + blendDQ /= len; + + float3 blendPosition = calculateBlendPosition(pass1_position, blendDQ); + + //No need to normalize, the magnitude of the normal is preserved because only rotation is performed + float3 blendNormal = calculateBlendNormal(pass1_normal, blendDQ); + + oPosition = mul(viewProjectionMatrix, float4(blendPosition, 1.0)); + + // Lighting - support point and directional + float3 lightDir0 = normalize(lightPos[0].xyz - (blendPosition.xyz * lightPos[0].w)); + float3 lightDir1 = normalize(lightPos[1].xyz - (blendPosition.xyz * lightPos[1].w)); + + oUv = uv; + colour = diffuse * (ambient + (saturate(dot(lightDir0, blendNormal)) * lightDiffuseColour[0]) + + (saturate(dot(lightDir1, blendNormal)) * lightDiffuseColour[1])); +} + +//Two-phase skinning shadow caster pass +void dualQuaternionHardwareSkinningTwoWeightsTwoPhaseCaster_vp( + float4 position : POSITION, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + out float4 oPosition : POSITION, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float2x4 worldDualQuaternion2x4Array[24], + uniform float3x4 scaleM[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 ambient) +{ + //First phase - applies scaling and shearing: + float3x4 blendS = blendWgt.x*scaleM[blendIdx.x]; + blendS += blendWgt.y*scaleM[blendIdx.y]; + + float3 pass1_position = mul(blendS, position); + + //Second phase + float2x4 blendDQ = blendTwoWeightsAntipod(blendWgt, blendIdx, worldDualQuaternion2x4Array); + + float len = length(blendDQ[0]); + blendDQ /= len; + + float3 blendPosition = calculateBlendPosition(pass1_position, blendDQ); + + // view / projection + oPosition = mul(viewProjectionMatrix, float4(blendPosition, 1.0)); + + colour = ambient; +} + diff --git a/res/dist/media/materials/programs/DualQuaternion.glsl b/res/dist/media/materials/programs/DualQuaternion.glsl new file mode 100644 index 00000000000..9d670a40d03 --- /dev/null +++ b/res/dist/media/materials/programs/DualQuaternion.glsl @@ -0,0 +1,42 @@ +#version 120 + +mat2x4 blendTwoWeightsAntipod(vec4 blendWgt, vec4 blendIdx, vec4 dualQuaternions[24]); +vec3 calculateBlendPosition(vec3 position, mat2x4 blendDQ); +vec3 calculateBlendNormal(vec3 normal, mat2x4 blendDQ); + +uniform vec4 worldDualQuaternion2x4Array[24]; +uniform mat4 viewProjectionMatrix; +uniform vec4 lightPos[2]; +uniform vec4 lightDiffuseColour[2]; +uniform vec4 ambient; + +attribute vec4 vertex; +attribute vec3 normal; +attribute vec4 blendIndices; +attribute vec4 blendWeights; +attribute vec4 uv0; + +void main() +{ + mat2x4 blendDQ = blendTwoWeightsAntipod(blendWeights, blendIndices, worldDualQuaternion2x4Array); + + float len = length(blendDQ[0]); + blendDQ /= len; + + vec3 blendPosition = calculateBlendPosition(vertex.xyz, blendDQ); + + //No need to normalize, the magnitude of the normal is preserved because only rotation is performed + vec3 blendNormal = calculateBlendNormal(normal, blendDQ); + + gl_Position = viewProjectionMatrix * vec4(blendPosition, 1.0); + + // Lighting - support point and directional + vec3 lightDir0 = normalize(lightPos[0].xyz - (blendPosition * lightPos[0].w)); + vec3 lightDir1 = normalize(lightPos[1].xyz - (blendPosition * lightPos[1].w)); + + gl_TexCoord[0] = uv0; + + gl_FrontColor = gl_FrontMaterial.diffuse * (ambient + (clamp(dot(lightDir0, blendNormal), 0.0, 1.0) * lightDiffuseColour[0]) + + (clamp(dot(lightDir1, blendNormal), 0.0, 1.0) * lightDiffuseColour[1])); +} + diff --git a/res/dist/media/materials/programs/DualQuaternion_Common.cg b/res/dist/media/materials/programs/DualQuaternion_Common.cg new file mode 100644 index 00000000000..038e12c57dc --- /dev/null +++ b/res/dist/media/materials/programs/DualQuaternion_Common.cg @@ -0,0 +1,85 @@ +//All of these functions are based on dqs.cg from http://isg.cs.tcd.ie/kavanl/dq/ +/* dqs.cg + + Dual quaternion skinning vertex shaders (no shading computations) + + Version 1.0.3, November 1st, 2007 + + Copyright (C) 2006-2007 University of Dublin, Trinity College, All Rights + Reserved + + This software is provided 'as-is', without any express or implied + warranty. In no event will the author(s) be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Author: Ladislav Kavan, kavanl@cs.tcd.ie + +*/ + +float2x4 blendTwoWeights(float4 blendWgt, float4 blendIdx, float2x4 dualQuaternions[24]) +{ + float2x4 blendDQ = blendWgt.x*dualQuaternions[blendIdx.x]; + blendDQ += blendWgt.y*dualQuaternions[blendIdx.y]; + + return blendDQ; +} + +float2x4 blendTwoWeightsAntipod(float4 blendWgt, float4 blendIdx, float2x4 dualQuaternions[24]) +{ + float2x4 dq0 = dualQuaternions[blendIdx.x]; + float2x4 dq1 = dualQuaternions[blendIdx.y]; + + //Accurate antipodality handling. For speed increase, remove the following line, + //though, the results will only be valid for rotations less than 180 degrees. + if (dot(dq0[0], dq1[0]) < 0.0) dq1 *= -1.0; + + float2x4 blendDQ = blendWgt.x*dq0; + blendDQ += blendWgt.y*dq1; + + return blendDQ; +} + +float3 calculateBlendPosition(float3 position, float2x4 blendDQ) +{ + float3 blendPosition = position + 2.0*cross(blendDQ[0].yzw, cross(blendDQ[0].yzw, position.xyz) + blendDQ[0].x*position); + float3 trans = 2.0*(blendDQ[0].x*blendDQ[1].yzw - blendDQ[1].x*blendDQ[0].yzw + cross(blendDQ[0].yzw, blendDQ[1].yzw)); + blendPosition += trans; + + return blendPosition; +} + +float3 calculateBlendNormal(float3 normal, float2x4 blendDQ) +{ + return normal + 2.0*cross(blendDQ[0].yzw, cross(blendDQ[0].yzw, normal) + blendDQ[0].x*normal); +} + +float3x3 adjointTransposeMatrix(float3x3 M) +{ + float3x3 atM; + atM._m00 = M._m22 * M._m11 - M._m12 * M._m21; + atM._m01 = M._m12 * M._m20 - M._m10 * M._m22; + atM._m02 = M._m10 * M._m21 - M._m20 * M._m11; + + atM._m10 = M._m02 * M._m21 - M._m22 * M._m01; + atM._m11 = M._m22 * M._m00 - M._m02 * M._m20; + atM._m12 = M._m20 * M._m01 - M._m00 * M._m21; + + atM._m20 = M._m12 * M._m01 - M._m02 * M._m11; + atM._m21 = M._m10 * M._m02 - M._m12 * M._m00; + atM._m22 = M._m00 * M._m11 - M._m10 * M._m01; + + return atM; +} + diff --git a/res/dist/media/materials/programs/DualQuaternion_Common.glsl b/res/dist/media/materials/programs/DualQuaternion_Common.glsl new file mode 100644 index 00000000000..7dc9b075410 --- /dev/null +++ b/res/dist/media/materials/programs/DualQuaternion_Common.glsl @@ -0,0 +1,70 @@ +#version 120 + +//All of these functions are based on dqs.cg from http://isg.cs.tcd.ie/kavanl/dq/ +/* dqs.cg + + Dual quaternion skinning vertex shaders (no shading computations) + + Version 1.0.3, November 1st, 2007 + + Copyright (C) 2006-2007 University of Dublin, Trinity College, All Rights + Reserved + + This software is provided 'as-is', without any express or implied + warranty. In no event will the author(s) be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Author: Ladislav Kavan, kavanl@cs.tcd.ie + +*/ + +mat2x4 blendTwoWeights(vec4 blendWgt, vec4 blendIdx, vec4 dualQuaternions[24]) +{ + mat2x4 blendDQ = blendWgt.x*mat2x4(dualQuaternions[int(blendIdx.x) * 2], dualQuaternions[int(blendIdx.x) * 2 + 1]); + blendDQ += blendWgt.y*mat2x4(dualQuaternions[int(blendIdx.y) * 2], dualQuaternions[int(blendIdx.y) * 2 + 1]); + + return blendDQ; +} + +mat2x4 blendTwoWeightsAntipod(vec4 blendWgt, vec4 blendIdx, vec4 dualQuaternions[24]) +{ + mat2x4 dq0 = mat2x4(dualQuaternions[int(blendIdx.x) * 2], dualQuaternions[int(blendIdx.x) * 2 + 1]); + mat2x4 dq1 = mat2x4(dualQuaternions[int(blendIdx.y) * 2], dualQuaternions[int(blendIdx.y) * 2 + 1]); + + //Accurate antipodality handling. For speed increase, remove the following line, + //though, the results will only be valid for rotations less than 180 degrees. + if (dot(dq0[0], dq1[0]) < 0.0) dq1 *= -1.0; + + mat2x4 blendDQ = blendWgt.x*dq0; + blendDQ += blendWgt.y*dq1; + + return blendDQ; +} + +vec3 calculateBlendPosition(vec3 position, mat2x4 blendDQ) +{ + vec3 blendPosition = position + 2.0*cross(blendDQ[0].yzw, cross(blendDQ[0].yzw, position) + blendDQ[0].x*position); + vec3 trans = 2.0*(blendDQ[0].x*blendDQ[1].yzw - blendDQ[1].x*blendDQ[0].yzw + cross(blendDQ[0].yzw, blendDQ[1].yzw)); + blendPosition += trans; + + return blendPosition; +} + +vec3 calculateBlendNormal(vec3 normal, mat2x4 blendDQ) +{ + return normal + 2.0*cross(blendDQ[0].yzw, cross(blendDQ[0].yzw, normal) + blendDQ[0].x*normal); +} + + diff --git a/res/dist/media/materials/programs/DualQuaternion_ShadowCaster.glsl b/res/dist/media/materials/programs/DualQuaternion_ShadowCaster.glsl new file mode 100644 index 00000000000..6f726a1bb15 --- /dev/null +++ b/res/dist/media/materials/programs/DualQuaternion_ShadowCaster.glsl @@ -0,0 +1,29 @@ +#version 120 + +mat2x4 blendTwoWeightsAntipod(vec4 blendWgt, vec4 blendIdx, vec4 dualQuaternions[24]); +vec3 calculateBlendPosition(vec3 position, mat2x4 blendDQ); + +uniform vec4 worldDualQuaternion2x4Array[24]; +uniform mat4x4 viewProjectionMatrix; +uniform vec4 ambient; + +attribute vec4 vertex; +attribute vec4 blendIndices; +attribute vec4 blendWeights; + +//Shadow caster pass +void main() +{ + mat2x4 blendDQ = blendTwoWeightsAntipod(blendWeights, blendIndices, worldDualQuaternion2x4Array); + + float len = length(blendDQ[0]); + blendDQ /= len; + + vec3 blendPosition = calculateBlendPosition(vertex.xyz, blendDQ); + + // view / projection + gl_Position = viewProjectionMatrix * vec4(blendPosition, 1.0); + + gl_FrontColor = ambient; +} + diff --git a/res/dist/media/materials/programs/DualQuaternion_TwoPhase.glsl b/res/dist/media/materials/programs/DualQuaternion_TwoPhase.glsl new file mode 100644 index 00000000000..8fabafcd978 --- /dev/null +++ b/res/dist/media/materials/programs/DualQuaternion_TwoPhase.glsl @@ -0,0 +1,77 @@ +#version 120 + +mat2x4 blendTwoWeightsAntipod(vec4 blendWgt, vec4 blendIdx, vec4 dualQuaternions[24]); +vec3 calculateBlendPosition(vec3 position, mat2x4 blendDQ); +vec3 calculateBlendNormal(vec3 normal, mat2x4 blendDQ); + +mat3 adjointTransposeMatrix(mat3 M) +{ + mat3 atM; + atM[0][0] = M[2][2] * M[1][1] - M[2][1] * M[1][2]; + atM[1][0] = M[2][1] * M[0][2] - M[0][1] * M[2][2]; + atM[2][0] = M[0][1] * M[1][2] - M[0][2] * M[1][1]; + + atM[0][1] = M[2][0] * M[1][2] - M[2][2] * M[1][0]; + atM[1][1] = M[2][2] * M[0][0] - M[2][0] * M[0][2]; + atM[2][1] = M[0][2] * M[1][0] - M[0][0] * M[1][2]; + + atM[0][2] = M[2][1] * M[1][0] - M[2][0] * M[1][1]; + atM[1][2] = M[0][1] * M[2][0] - M[2][1] * M[0][0]; + atM[2][2] = M[0][0] * M[1][1] - M[0][1] * M[1][0]; + + return atM; +} + +uniform vec4 worldDualQuaternion2x4Array[24]; +uniform vec4 scaleM[72]; +uniform mat4 viewProjectionMatrix; +uniform vec4 lightPos[2]; +uniform vec4 lightDiffuseColour[2]; +uniform vec4 ambient; + +attribute vec4 vertex; +attribute vec3 normal; +attribute vec4 blendIndices; +attribute vec4 blendWeights; +attribute vec4 uv0; + +void main() +{ + //First phase - applies scaling and shearing: + int blendIndicesX = int(blendIndices.x) * 3; + int blendIndicesY = int(blendIndices.y) * 3; + + mat3x4 blendS = blendWeights.x*mat3x4(scaleM[blendIndicesX], + scaleM[blendIndicesX + 1], scaleM[blendIndicesX + 2]); + + blendS += blendWeights.y*mat3x4(scaleM[blendIndicesY], scaleM[blendIndicesY + 1], scaleM[blendIndicesY + 2]); + + mat4x3 blendF = transpose(blendS); + + vec3 pass1_position = blendF * vertex; + + mat3x3 blendSrotAT = adjointTransposeMatrix(mat3x3(blendF)); + vec3 pass1_normal = normalize(blendSrotAT * normal); + + //Second phase + mat2x4 blendDQ = blendTwoWeightsAntipod(blendWeights, blendIndices, worldDualQuaternion2x4Array); + + blendDQ /= length(blendDQ[0]); + + vec3 blendPosition = calculateBlendPosition(pass1_position, blendDQ); + + //No need to normalize, the magnitude of the normal is preserved because only rotation is performed + vec3 blendNormal = calculateBlendNormal(pass1_normal, blendDQ); + + gl_Position = viewProjectionMatrix * vec4(blendPosition, 1.0); + + // Lighting - support point and directional + vec3 lightDir0 = normalize(lightPos[0].xyz - (blendPosition * lightPos[0].w)); + vec3 lightDir1 = normalize(lightPos[1].xyz - (blendPosition * lightPos[1].w)); + + gl_TexCoord[0] = uv0; + + gl_FrontColor = gl_FrontMaterial.diffuse * (ambient + (clamp(dot(lightDir0, blendNormal), 0.0, 1.0) * lightDiffuseColour[0]) + + (clamp(dot(lightDir1, blendNormal), 0.0, 1.0) * lightDiffuseColour[1])); +} + diff --git a/res/dist/media/materials/programs/DualQuaternion_TwoPhaseShadowCaster.glsl b/res/dist/media/materials/programs/DualQuaternion_TwoPhaseShadowCaster.glsl new file mode 100644 index 00000000000..efe8f3cbf20 --- /dev/null +++ b/res/dist/media/materials/programs/DualQuaternion_TwoPhaseShadowCaster.glsl @@ -0,0 +1,41 @@ +#version 120 + +mat2x4 blendTwoWeightsAntipod(vec4 blendWgt, vec4 blendIdx, vec4 dualQuaternions[24]); +vec3 calculateBlendPosition(vec3 position, mat2x4 blendDQ); + +uniform vec4 worldDualQuaternion2x4Array[24]; +uniform vec4 scaleM[72]; +uniform mat4 viewProjectionMatrix; +uniform vec4 ambient; + +attribute vec4 vertex; +attribute vec4 blendIndices; +attribute vec4 blendWeights; + +void main() +{ + //First phase - applies scaling and shearing: + int blendIndicesX = int(blendIndices.x) * 3; + int blendIndicesY = int(blendIndices.y) * 3; + + mat3x4 blendS = blendWeights.x*mat3x4(scaleM[blendIndicesX], + scaleM[blendIndicesX + 1], scaleM[blendIndicesX + 2]); + + blendS += blendWeights.y*mat3x4(scaleM[blendIndicesY], scaleM[blendIndicesY + 1], scaleM[blendIndicesY + 2]); + + mat4x3 blendF = transpose(blendS); + + vec3 pass1_position = blendF * vertex; + + //Second phase + mat2x4 blendDQ = blendTwoWeightsAntipod(blendWeights, blendIndices, worldDualQuaternion2x4Array); + + blendDQ /= length(blendDQ[0]); + + vec3 blendPosition = calculateBlendPosition(pass1_position, blendDQ); + + gl_Position = viewProjectionMatrix * vec4(blendPosition, 1.0); + + gl_FrontColor = ambient; +} + diff --git a/res/dist/media/materials/programs/EmbossedFp.glsles b/res/dist/media/materials/programs/EmbossedFp.glsles new file mode 100644 index 00000000000..1c172c15e19 --- /dev/null +++ b/res/dist/media/materials/programs/EmbossedFp.glsles @@ -0,0 +1,18 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform sampler2D RT; +varying vec2 uv; + +void main() +{ + vec4 Color; + Color.a = 1.0; + Color.rgb = vec3(0.5); + Color -= texture2D( RT, uv - 0.001)*2.0; + Color += texture2D( RT, uv + 0.001)*2.0; + Color.rgb = vec3((Color.r+Color.g+Color.b)/3.0); + gl_FragColor = Color; +} diff --git a/res/dist/media/materials/programs/Example_Basic.cg b/res/dist/media/materials/programs/Example_Basic.cg new file mode 100644 index 00000000000..0c826c63e8e --- /dev/null +++ b/res/dist/media/materials/programs/Example_Basic.cg @@ -0,0 +1,400 @@ +/* + Basic ambient lighting vertex program +*/ +void ambientOneTexture_vp(float4 position : POSITION, + float2 uv : TEXCOORD0, + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + + uniform float4x4 worldViewProj, + uniform float4 ambient) +{ + oPosition = mul(worldViewProj, position); + oUv = uv; + colour = ambient; +} + +/* + Basic fragment program using texture and diffuse colour. +*/ +void diffuseOneTexture_fp(float4 position : POSITION, + float2 uv : TEXCOORD0, + float4 diffuse : COLOR, + out float4 colour : COLOR, + uniform sampler2D texMap : register(s0)) +{ + colour = tex2D(texMap,uv) * diffuse; +} + +/* + Single-weight-per-vertex hardware skinning, 2 lights + The trouble with vertex programs is they're not general purpose, but + fixed function hardware skinning is very poorly supported +*/ +void hardwareSkinningOneWeight_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float blendIdx : BLENDINDICES, + + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 lightPos[2], + uniform float4 lightDiffuseColour[2], + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(mul(worldMatrix3x4Array[blendIdx], position).xyz, 1.0); + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + // transform normal + float3 norm = mul((float3x3)worldMatrix3x4Array[blendIdx], normal); + // Lighting - support point and directional + float3 lightDir0 = normalize( + lightPos[0].xyz - (blendPos.xyz * lightPos[0].w)); + float3 lightDir1 = normalize( + lightPos[1].xyz - (blendPos.xyz * lightPos[1].w)); + + oUv = uv; + colour = ambient + + (saturate(dot(lightDir0, norm)) * lightDiffuseColour[0]) + + (saturate(dot(lightDir1, norm)) * lightDiffuseColour[1]); + +} + +/* + Single-weight-per-vertex hardware skinning, shadow-caster pass +*/ +void hardwareSkinningOneWeightCaster_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float blendIdx : BLENDINDICES, + + + out float4 oPosition : POSITION, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(mul(worldMatrix3x4Array[blendIdx], position).xyz, 1.0); + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + + colour = ambient; + +} + +/* + Two-weight-per-vertex hardware skinning, 2 lights + The trouble with vertex programs is they're not general purpose, but + fixed function hardware skinning is very poorly supported +*/ +void hardwareSkinningTwoWeights_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 lightPos[2], + uniform float4 lightDiffuseColour[2], + uniform float4 ambient, + uniform float4 diffuse) +{ + // transform by indexed matrix + float4 blendPos = float4(0,0,0,0); + int i; + for (i = 0; i < 2; ++i) + { + blendPos += float4(mul(worldMatrix3x4Array[blendIdx[i]], position).xyz, 1.0) * blendWgt[i]; + } + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + // transform normal + float3 norm = float3(0,0,0); + for (i = 0; i < 2; ++i) + { + norm += mul((float3x3)worldMatrix3x4Array[blendIdx[i]], normal) * + blendWgt[i]; + } + norm = normalize(norm); + // Lighting - support point and directional + float3 lightDir0 = normalize( + lightPos[0].xyz - (blendPos.xyz * lightPos[0].w)); + float3 lightDir1 = normalize( + lightPos[1].xyz - (blendPos.xyz * lightPos[1].w)); + + + oUv = uv; + colour = diffuse * (ambient + + (saturate(dot(lightDir0, norm)) * lightDiffuseColour[0]) + + (saturate(dot(lightDir1, norm)) * lightDiffuseColour[1])); + +} + +/* + Two-weight-per-vertex hardware skinning, shadow caster pass +*/ +void hardwareSkinningTwoWeightsCaster_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + + out float4 oPosition : POSITION, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(0,0,0,0); + int i; + for (i = 0; i < 2; ++i) + { + blendPos += float4(mul(worldMatrix3x4Array[blendIdx[i]], position).xyz, 1.0) * blendWgt[i]; + } + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + + + colour = ambient; +} + + +/* + Four-weight-per-vertex hardware skinning, 2 lights + The trouble with vertex programs is they're not general purpose, but + fixed function hardware skinning is very poorly supported +*/ +void hardwareSkinningFourWeights_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 lightPos[2], + uniform float4 lightDiffuseColour[2], + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(0,0,0,0); + int i; + for (i = 0; i < 4; ++i) + { + blendPos += float4(mul(worldMatrix3x4Array[blendIdx[i]], position).xyz, 1.0) * blendWgt[i]; + } + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + // transform normal + float3 norm = float3(0,0,0); + for (i = 0; i < 4; ++i) + { + float3x3 d = (float3x3)worldMatrix3x4Array[blendIdx[i]]; + norm += mul(d, normal) * + blendWgt[i]; + } + norm = normalize(norm); + // Lighting - support point and directional + float3 lightDir0 = normalize( + lightPos[0].xyz - (blendPos.xyz * lightPos[0].w)); + float3 lightDir1 = normalize( + lightPos[1].xyz - (blendPos.xyz * lightPos[1].w)); + + + oUv = uv; + colour = ambient + + (saturate(dot(lightDir0, norm)) * lightDiffuseColour[0]) + + (saturate(dot(lightDir1, norm)) * lightDiffuseColour[1]); + +} + +// hardware morph animation (no normals) +void hardwareMorphAnimation(float3 pos1 : POSITION, + float4 normal : NORMAL, + float2 uv : TEXCOORD0, + float3 pos2 : TEXCOORD1, + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + + uniform float4x4 worldViewProj, + uniform float4 anim_t) +{ + // interpolate + float4 interp = float4(pos1 + anim_t.x*(pos2 - pos1), 1.0f); + + oPosition = mul(worldViewProj, interp); + oUv = uv; + colour = float4(1,0,0,1); +} + +// hardware pose animation (no normals) +void hardwarePoseAnimation(float3 pos : POSITION, + float4 normal : NORMAL, + float2 uv : TEXCOORD0, + float3 pose1 : TEXCOORD1, + float3 pose2 : TEXCOORD2, + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + + uniform float4x4 worldViewProj, + uniform float4 anim_t) +{ + // interpolate + float4 interp = float4(pos + anim_t.x*pose1 + anim_t.y*pose2, 1.0f); + + oPosition = mul(worldViewProj, interp); + oUv = uv; + colour = float4(1,0,0,1); +} + +// hardware morph animation (with normals) +void hardwareMorphAnimationWithNormals(float3 pos1 : POSITION, + float3 normal1 : NORMAL, + float2 uv : TEXCOORD0, + float3 pos2 : TEXCOORD1, + float3 normal2 : TEXCOORD2, + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + + uniform float4x4 worldViewProj, + uniform float4 objSpaceLightPos, + uniform float4 ambient, + uniform float4 anim_t) +{ + // interpolate position + float4 posinterp = float4(pos1 + anim_t.x*(pos2 - pos1), 1.0f); + + // nlerp normal + float3 ninterp = normal1 + anim_t.x*(normal2 - normal1); + ninterp = normalize(ninterp); + + oPosition = mul(worldViewProj, posinterp); + oUv = uv; + + float3 lightDir = normalize( + objSpaceLightPos.xyz - (posinterp.xyz * objSpaceLightPos.w)); + + // Colour it red to make it easy to identify + float lit = saturate(dot(lightDir, ninterp)); + colour = float4((ambient.rgb + float3(lit,lit,lit)) * float3(1,0,0), 1); +} + +// hardware pose animation (with normals) +void hardwarePoseAnimationWithNormals(float3 pos : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float3 pose1pos : TEXCOORD1, + float3 pose1norm : TEXCOORD2, + float3 pose2pos : TEXCOORD3, + float3 pose2norm : TEXCOORD4, + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + + uniform float4x4 worldViewProj, + uniform float4 objSpaceLightPos, + uniform float4 ambient, + uniform float4 anim_t) +{ + // interpolate + float4 posinterp = float4(pos + anim_t.x*pose1pos + anim_t.y*pose2pos, 1.0f); + + // nlerp normal + // First apply the pose normals (these are actual normals, not offsets) + float3 ninterp = anim_t.x*pose1norm + anim_t.y*pose2norm; + + // Now add back any influence of the original normal + // This depends on what the cumulative weighting left the normal at, if it's lacking or cancelled out + //float remainder = 1.0 - min(anim_t.x + anim_t.y, 1.0); + float remainder = 1.0 - min(length(ninterp), 1.0); + ninterp = ninterp + (normal * remainder); + ninterp = normalize(ninterp); + + oPosition = mul(worldViewProj, posinterp); + oUv = uv; + + float3 lightDir = normalize( + objSpaceLightPos.xyz - (posinterp.xyz * objSpaceLightPos.w)); + + // Colour it red to make it easy to identify + float lit = saturate(dot(lightDir, ninterp)); + colour = float4((ambient.rgb + float3(lit,lit,lit)) * float3(1,0,0), 1); +} + +void basicPassthroughTangent_v(float4 position : POSITION, + float3 tangent : TANGENT, + + out float4 oPosition : POSITION, + out float3 oTangent : TEXCOORD0, + + uniform float4x4 worldViewProj) +{ + oPosition = mul(worldViewProj, position); + oTangent = tangent; +} +void basicPassthroughNormal_v(float4 position : POSITION, + float3 normal : NORMAL, + + out float4 oPosition : POSITION, + out float3 oNormal : TEXCOORD0, + + uniform float4x4 worldViewProj) +{ + oPosition = mul(worldViewProj, position); + oNormal = normal; +} +// Basic fragment program to display UV +float4 showuv_p (float4 position : POSITION, float2 uv : TEXCOORD0) : COLOR +{ + // wrap values using frac + return float4(frac(uv.x), frac(uv.y), 0, 1); +} +// Basic fragment program to display 3d uv +float4 showuvdir3d_p (float4 position : POSITION, float3 uv : TEXCOORD0) : COLOR +{ + float3 n = normalize(uv); + return float4(n.x, n.y, n.z, 1); +} + + diff --git a/res/dist/media/materials/programs/Example_Basic.hlsl b/res/dist/media/materials/programs/Example_Basic.hlsl new file mode 100644 index 00000000000..b7a2f51a983 --- /dev/null +++ b/res/dist/media/materials/programs/Example_Basic.hlsl @@ -0,0 +1,273 @@ +/* + Basic ambient lighting vertex program +*/ +void ambientOneTexture_vp(float4 position : POSITION, + float2 uv : TEXCOORD0, + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + + uniform float4x4 worldViewProj, + uniform float4 ambient) +{ + oPosition = mul(worldViewProj, position); + oUv = uv; + colour = ambient; +} + +/* + Single-weight-per-vertex hardware skinning, 2 lights + The trouble with vertex programs is they're not general purpose, but + fixed function hardware skinning is very poorly supported +*/ +void hardwareSkinningOneWeight_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float blendIdx : BLENDINDICES, + + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 lightPos[2], + uniform float4 lightDiffuseColour[2], + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(mul(worldMatrix3x4Array[blendIdx], position).xyz, 1.0); + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + // transform normal + float3 norm = mul((float3x3)worldMatrix3x4Array[blendIdx], normal); + // Lighting - support point and directional + float3 lightDir0 = normalize( + lightPos[0].xyz - (blendPos.xyz * lightPos[0].w)); + float3 lightDir1 = normalize( + lightPos[1].xyz - (blendPos.xyz * lightPos[1].w)); + + oUv = uv; + colour = ambient + + (saturate(dot(lightDir0, norm)) * lightDiffuseColour[0]) + + (saturate(dot(lightDir1, norm)) * lightDiffuseColour[1]); + +} + +/* + Single-weight-per-vertex hardware skinning, shadow-caster pass +*/ +void hardwareSkinningOneWeightCaster_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float blendIdx : BLENDINDICES, + + + out float4 oPosition : POSITION, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(mul(worldMatrix3x4Array[blendIdx], position).xyz, 1.0); + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + + colour = ambient; + +} + +/* + Two-weight-per-vertex hardware skinning, 2 lights + The trouble with vertex programs is they're not general purpose, but + fixed function hardware skinning is very poorly supported +*/ +void hardwareSkinningTwoWeights_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 lightPos[2], + uniform float4 lightDiffuseColour[2], + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(0,0,0,0); + int i; + for (i = 0; i < 2; ++i) + { + blendPos += float4(mul(worldMatrix3x4Array[blendIdx[i]], position).xyz, 1.0) * blendWgt[i]; + } + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + // transform normal + float3 norm = float3(0,0,0); + for (i = 0; i < 2; ++i) + { + norm += mul((float3x3)worldMatrix3x4Array[blendIdx[i]], normal) * + blendWgt[i]; + } + norm = normalize(norm); + // Lighting - support point and directional + float3 lightDir0 = normalize( + lightPos[0].xyz - (blendPos.xyz * lightPos[0].w)); + float3 lightDir1 = normalize( + lightPos[1].xyz - (blendPos.xyz * lightPos[1].w)); + + + oUv = uv; + colour = ambient + + (saturate(dot(lightDir0, norm)) * lightDiffuseColour[0]) + + (saturate(dot(lightDir1, norm)) * lightDiffuseColour[1]); + +} + +/* + Two-weight-per-vertex hardware skinning, shadow caster pass +*/ +void hardwareSkinningTwoWeightsCaster_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + + out float4 oPosition : POSITION, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(0,0,0,0); + int i; + for (i = 0; i < 2; ++i) + { + blendPos += float4(mul(worldMatrix3x4Array[blendIdx[i]], position).xyz, 1.0) * blendWgt[i]; + } + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + + + colour = ambient; + + +} + + +/* + Four-weight-per-vertex hardware skinning, 2 lights + The trouble with vertex programs is they're not general purpose, but + fixed function hardware skinning is very poorly supported +*/ +void hardwareSkinningFourWeights_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 lightPos[2], + uniform float4 lightDiffuseColour[2], + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(0,0,0,0); + int i; + for (i = 0; i < 4; ++i) + { + blendPos += float4(mul(worldMatrix3x4Array[blendIdx[i]], position).xyz, 1.0) * blendWgt[i]; + } + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + // transform normal + float3 norm = float3(0,0,0); + for (i = 0; i < 4; ++i) + { + norm += mul((float3x3)worldMatrix3x4Array[blendIdx[i]], normal) * + blendWgt[i]; + } + norm = normalize(norm); + // Lighting - support point and directional + float3 lightDir0 = normalize( + lightPos[0].xyz - (blendPos.xyz * lightPos[0].w)); + float3 lightDir1 = normalize( + lightPos[1].xyz - (blendPos.xyz * lightPos[1].w)); + + + oUv = uv; + colour = ambient + + (saturate(dot(lightDir0, norm)) * lightDiffuseColour[0]) + + (saturate(dot(lightDir1, norm)) * lightDiffuseColour[1]); + +} + +void hardwareMorphAnimation(float3 pos1 : POSITION, + float4 normal : NORMAL, + float2 uv : TEXCOORD0, + float3 pos2 : TEXCOORD1, + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + + uniform float4x4 worldViewProj, + uniform float4 anim_t) +{ + // interpolate + float4 interp = float4(pos1 + anim_t.x*(pos2 - pos1), 1.0f); + + oPosition = mul(worldViewProj, interp); + oUv = uv; + colour = float4(1,0,0,1); +} + +void hardwarePoseAnimation(float3 pos : POSITION, + float4 normal : NORMAL, + float2 uv : TEXCOORD0, + float3 pose1 : TEXCOORD1, + float3 pose2 : TEXCOORD2, + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + + uniform float4x4 worldViewProj, + uniform float4 anim_t) +{ + // interpolate + float4 interp = float4(pos + anim_t.x*pose1 + anim_t.y*pose2, 1.0f); + + oPosition = mul(worldViewProj, interp); + oUv = uv; + colour = float4(1,0,0,1); +} + diff --git a/res/dist/media/materials/programs/Example_BasicFp.glsles b/res/dist/media/materials/programs/Example_BasicFp.glsles new file mode 100644 index 00000000000..1502cb79eca --- /dev/null +++ b/res/dist/media/materials/programs/Example_BasicFp.glsles @@ -0,0 +1,620 @@ +/* + Basic ambient lighting vertex program +*/ +void ambientOneTexture_vp(float4 position : POSITION, + float2 uv : TEXCOORD0, + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + + uniform float4x4 worldViewProj, + uniform float4 ambient) +{ + oPosition = mul(worldViewProj, position); + oUv = uv; + colour = ambient; +} + +/* + Single-weight-per-vertex hardware skinning, 2 lights + The trouble with vertex programs is they're not general purpose, but + fixed function hardware skinning is very poorly supported +*/ +void hardwareSkinningOneWeight_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float blendIdx : BLENDINDICES, + + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 lightPos[2], + uniform float4 lightDiffuseColour[2], + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(mul(worldMatrix3x4Array[blendIdx], position).xyz, 1.0); + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + // transform normal + float3 norm = mul((float3x3)worldMatrix3x4Array[blendIdx], normal); + // Lighting - support point and directional + float3 lightDir0 = normalize( + lightPos[0].xyz - (blendPos.xyz * lightPos[0].w)); + float3 lightDir1 = normalize( + lightPos[1].xyz - (blendPos.xyz * lightPos[1].w)); + + oUv = uv; + colour = ambient + + (saturate(dot(lightDir0, norm)) * lightDiffuseColour[0]) + + (saturate(dot(lightDir1, norm)) * lightDiffuseColour[1]); + +} + +/* + Single-weight-per-vertex hardware skinning, shadow-caster pass +*/ +void hardwareSkinningOneWeightCaster_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float blendIdx : BLENDINDICES, + + + out float4 oPosition : POSITION, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(mul(worldMatrix3x4Array[blendIdx], position).xyz, 1.0); + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + + colour = ambient; + +} + +/* + Two-weight-per-vertex hardware skinning, 2 lights + The trouble with vertex programs is they're not general purpose, but + fixed function hardware skinning is very poorly supported +*/ +void hardwareSkinningTwoWeights_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 lightPos[2], + uniform float4 lightDiffuseColour[2], + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(0,0,0,0); + int i; + for (i = 0; i < 2; ++i) + { + blendPos += float4(mul(worldMatrix3x4Array[blendIdx[i]], position).xyz, 1.0) * blendWgt[i]; + } + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + // transform normal + float3 norm = float3(0,0,0); + for (i = 0; i < 2; ++i) + { + norm += mul((float3x3)worldMatrix3x4Array[blendIdx[i]], normal) * + blendWgt[i]; + } + norm = normalize(norm); + // Lighting - support point and directional + float3 lightDir0 = normalize( + lightPos[0].xyz - (blendPos.xyz * lightPos[0].w)); + float3 lightDir1 = normalize( + lightPos[1].xyz - (blendPos.xyz * lightPos[1].w)); + + + oUv = uv; + colour = float4(0.5, 0.5, 0.5, 1) + + (saturate(dot(lightDir0, norm)) * lightDiffuseColour[0]) + + (saturate(dot(lightDir1, norm)) * lightDiffuseColour[1]); + +} + +/* + Two-weight-per-vertex hardware skinning, shadow caster pass +*/ +void hardwareSkinningTwoWeightsCaster_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + + out float4 oPosition : POSITION, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(0,0,0,0); + int i; + for (i = 0; i < 2; ++i) + { + blendPos += float4(mul(worldMatrix3x4Array[blendIdx[i]], position).xyz, 1.0) * blendWgt[i]; + } + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + + + colour = ambient; + + +} + + +/* + Four-weight-per-vertex hardware skinning, 2 lights + The trouble with vertex programs is they're not general purpose, but + fixed function hardware skinning is very poorly supported +*/ +void hardwareSkinningFourWeights_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 lightPos[2], + uniform float4 lightDiffuseColour[2], + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(0,0,0,0); + int i; + for (i = 0; i < 4; ++i) + { + blendPos += float4(mul(worldMatrix3x4Array[blendIdx[i]], position).xyz, 1.0) * blendWgt[i]; + } + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + // transform normal + float3 norm = float3(0,0,0); + for (i = 0; i < 4; ++i) + { + norm += mul((float3x3)worldMatrix3x4Array[blendIdx[i]], normal) * + blendWgt[i]; + } + norm = normalize(norm); + // Lighting - support point and directional + float3 lightDir0 = normalize( + lightPos[0].xyz - (blendPos.xyz * lightPos[0].w)); + float3 lightDir1 = normalize( + lightPos[1].xyz - (blendPos.xyz * lightPos[1].w)); + + + oUv = uv; + colour = ambient + + (saturate(dot(lightDir0, norm)) * lightDiffuseColour[0]) + + (saturate(dot(lightDir1, norm)) * lightDiffuseColour[1]); + +} + +void hardwareMorphAnimation(float3 pos1 : POSITION, + float4 normal : NORMAL, + float2 uv : TEXCOORD0, + float3 pos2 : TEXCOORD1, + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + + uniform float4x4 worldViewProj, + uniform float4 anim_t) +{ + // interpolate + float4 interp = float4(pos1 + anim_t.x*(pos2 - pos1), 1.0f); + + oPosition = mul(worldViewProj, interp); + oUv = uv; + colour = float4(1,0,0,1); +} + +void hardwarePoseAnimation(float3 pos : POSITION, + float4 normal : NORMAL, + float2 uv : TEXCOORD0, + float3 pose1 : TEXCOORD1, + float3 pose2 : TEXCOORD2, + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + + uniform float4x4 worldViewProj, + uniform float4 anim_t) +{ + // interpolate + float4 interp = float4(pos + anim_t.x*pose1 + anim_t.y*pose2, 1.0f); + + oPosition = mul(worldViewProj, interp); + oUv = uv; + colour = float4(1,0,0,1); +} + + +void basicPassthroughTangent_v(float4 position : POSITION, + float3 tangent : TANGENT, + + out float4 oPosition : POSITION, + out float3 oTangent : TEXCOORD0, + + uniform float4x4 worldViewProj) +{ + oPosition = mul(worldViewProj, position); + oTangent = tangent; +} +void basicPassthroughNormal_v(float4 position : POSITION, + float3 normal : NORMAL, + + out float4 oPosition : POSITION, + out float3 oNormal : TEXCOORD0, + + uniform float4x4 worldViewProj) +{ + oPosition = mul(worldViewProj, position); + oNormal = normal; +} +// Basic fragment program to display UV +float4 showuv_p (float2 uv : TEXCOORD0) : COLOR +{ + // wrap values using frac + return float4(frac(uv.x), frac(uv.y), 0, 1); +} +// Basic fragment program to display 3d uv +float4 showuvdir3d_p (float3 uv : TEXCOORD0) : COLOR +{ + float3 n = normalize(uv); + return float4(n.x, n.y, n.z, 1); +} + + +/* + Basic ambient lighting vertex program +*/ +void ambientOneTexture_vp(float4 position : POSITION, + float2 uv : TEXCOORD0, + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + + uniform float4x4 worldViewProj, + uniform float4 ambient) +{ + oPosition = mul(worldViewProj, position); + oUv = uv; + colour = ambient; +} + +/* + Single-weight-per-vertex hardware skinning, 2 lights + The trouble with vertex programs is they're not general purpose, but + fixed function hardware skinning is very poorly supported +*/ +void hardwareSkinningOneWeight_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float blendIdx : BLENDINDICES, + + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 lightPos[2], + uniform float4 lightDiffuseColour[2], + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(mul(worldMatrix3x4Array[blendIdx], position).xyz, 1.0); + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + // transform normal + float3 norm = mul((float3x3)worldMatrix3x4Array[blendIdx], normal); + // Lighting - support point and directional + float3 lightDir0 = normalize( + lightPos[0].xyz - (blendPos.xyz * lightPos[0].w)); + float3 lightDir1 = normalize( + lightPos[1].xyz - (blendPos.xyz * lightPos[1].w)); + + oUv = uv; + colour = ambient + + (saturate(dot(lightDir0, norm)) * lightDiffuseColour[0]) + + (saturate(dot(lightDir1, norm)) * lightDiffuseColour[1]); + +} + +/* + Single-weight-per-vertex hardware skinning, shadow-caster pass +*/ +void hardwareSkinningOneWeightCaster_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float blendIdx : BLENDINDICES, + + + out float4 oPosition : POSITION, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(mul(worldMatrix3x4Array[blendIdx], position).xyz, 1.0); + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + + colour = ambient; + +} + +/* + Two-weight-per-vertex hardware skinning, 2 lights + The trouble with vertex programs is they're not general purpose, but + fixed function hardware skinning is very poorly supported +*/ +void hardwareSkinningTwoWeights_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 lightPos[2], + uniform float4 lightDiffuseColour[2], + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(0,0,0,0); + int i; + for (i = 0; i < 2; ++i) + { + blendPos += float4(mul(worldMatrix3x4Array[blendIdx[i]], position).xyz, 1.0) * blendWgt[i]; + } + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + // transform normal + float3 norm = float3(0,0,0); + for (i = 0; i < 2; ++i) + { + norm += mul((float3x3)worldMatrix3x4Array[blendIdx[i]], normal) * + blendWgt[i]; + } + norm = normalize(norm); + // Lighting - support point and directional + float3 lightDir0 = normalize( + lightPos[0].xyz - (blendPos.xyz * lightPos[0].w)); + float3 lightDir1 = normalize( + lightPos[1].xyz - (blendPos.xyz * lightPos[1].w)); + + + oUv = uv; + colour = float4(0.5, 0.5, 0.5, 1) + + (saturate(dot(lightDir0, norm)) * lightDiffuseColour[0]) + + (saturate(dot(lightDir1, norm)) * lightDiffuseColour[1]); + +} + +/* + Two-weight-per-vertex hardware skinning, shadow caster pass +*/ +void hardwareSkinningTwoWeightsCaster_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + + out float4 oPosition : POSITION, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(0,0,0,0); + int i; + for (i = 0; i < 2; ++i) + { + blendPos += float4(mul(worldMatrix3x4Array[blendIdx[i]], position).xyz, 1.0) * blendWgt[i]; + } + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + + + colour = ambient; + + +} + + +/* + Four-weight-per-vertex hardware skinning, 2 lights + The trouble with vertex programs is they're not general purpose, but + fixed function hardware skinning is very poorly supported +*/ +void hardwareSkinningFourWeights_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 lightPos[2], + uniform float4 lightDiffuseColour[2], + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(0,0,0,0); + int i; + for (i = 0; i < 4; ++i) + { + blendPos += float4(mul(worldMatrix3x4Array[blendIdx[i]], position).xyz, 1.0) * blendWgt[i]; + } + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + // transform normal + float3 norm = float3(0,0,0); + for (i = 0; i < 4; ++i) + { + norm += mul((float3x3)worldMatrix3x4Array[blendIdx[i]], normal) * + blendWgt[i]; + } + norm = normalize(norm); + // Lighting - support point and directional + float3 lightDir0 = normalize( + lightPos[0].xyz - (blendPos.xyz * lightPos[0].w)); + float3 lightDir1 = normalize( + lightPos[1].xyz - (blendPos.xyz * lightPos[1].w)); + + + oUv = uv; + colour = ambient + + (saturate(dot(lightDir0, norm)) * lightDiffuseColour[0]) + + (saturate(dot(lightDir1, norm)) * lightDiffuseColour[1]); + +} + +void hardwareMorphAnimation(float3 pos1 : POSITION, + float4 normal : NORMAL, + float2 uv : TEXCOORD0, + float3 pos2 : TEXCOORD1, + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + + uniform float4x4 worldViewProj, + uniform float4 anim_t) +{ + // interpolate + float4 interp = float4(pos1 + anim_t.x*(pos2 - pos1), 1.0f); + + oPosition = mul(worldViewProj, interp); + oUv = uv; + colour = float4(1,0,0,1); +} + +void hardwarePoseAnimation(float3 pos : POSITION, + float4 normal : NORMAL, + float2 uv : TEXCOORD0, + float3 pose1 : TEXCOORD1, + float3 pose2 : TEXCOORD2, + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + + uniform float4x4 worldViewProj, + uniform float4 anim_t) +{ + // interpolate + float4 interp = float4(pos + anim_t.x*pose1 + anim_t.y*pose2, 1.0f); + + oPosition = mul(worldViewProj, interp); + oUv = uv; + colour = float4(1,0,0,1); +} + + +void basicPassthroughTangent_v(float4 position : POSITION, + float3 tangent : TANGENT, + + out float4 oPosition : POSITION, + out float3 oTangent : TEXCOORD0, + + uniform float4x4 worldViewProj) +{ + oPosition = mul(worldViewProj, position); + oTangent = tangent; +} +void basicPassthroughNormal_v(float4 position : POSITION, + float3 normal : NORMAL, + + out float4 oPosition : POSITION, + out float3 oNormal : TEXCOORD0, + + uniform float4x4 worldViewProj) +{ + oPosition = mul(worldViewProj, position); + oNormal = normal; +} +// Basic fragment program to display UV +float4 showuv_p (float2 uv : TEXCOORD0) : COLOR +{ + // wrap values using frac + return float4(frac(uv.x), frac(uv.y), 0, 1); +} +// Basic fragment program to display 3d uv +float4 showuvdir3d_p (float3 uv : TEXCOORD0) : COLOR +{ + float3 n = normalize(uv); + return float4(n.x, n.y, n.z, 1); +} + + diff --git a/res/dist/media/materials/programs/Example_BasicVp.glsles b/res/dist/media/materials/programs/Example_BasicVp.glsles new file mode 100644 index 00000000000..1502cb79eca --- /dev/null +++ b/res/dist/media/materials/programs/Example_BasicVp.glsles @@ -0,0 +1,620 @@ +/* + Basic ambient lighting vertex program +*/ +void ambientOneTexture_vp(float4 position : POSITION, + float2 uv : TEXCOORD0, + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + + uniform float4x4 worldViewProj, + uniform float4 ambient) +{ + oPosition = mul(worldViewProj, position); + oUv = uv; + colour = ambient; +} + +/* + Single-weight-per-vertex hardware skinning, 2 lights + The trouble with vertex programs is they're not general purpose, but + fixed function hardware skinning is very poorly supported +*/ +void hardwareSkinningOneWeight_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float blendIdx : BLENDINDICES, + + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 lightPos[2], + uniform float4 lightDiffuseColour[2], + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(mul(worldMatrix3x4Array[blendIdx], position).xyz, 1.0); + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + // transform normal + float3 norm = mul((float3x3)worldMatrix3x4Array[blendIdx], normal); + // Lighting - support point and directional + float3 lightDir0 = normalize( + lightPos[0].xyz - (blendPos.xyz * lightPos[0].w)); + float3 lightDir1 = normalize( + lightPos[1].xyz - (blendPos.xyz * lightPos[1].w)); + + oUv = uv; + colour = ambient + + (saturate(dot(lightDir0, norm)) * lightDiffuseColour[0]) + + (saturate(dot(lightDir1, norm)) * lightDiffuseColour[1]); + +} + +/* + Single-weight-per-vertex hardware skinning, shadow-caster pass +*/ +void hardwareSkinningOneWeightCaster_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float blendIdx : BLENDINDICES, + + + out float4 oPosition : POSITION, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(mul(worldMatrix3x4Array[blendIdx], position).xyz, 1.0); + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + + colour = ambient; + +} + +/* + Two-weight-per-vertex hardware skinning, 2 lights + The trouble with vertex programs is they're not general purpose, but + fixed function hardware skinning is very poorly supported +*/ +void hardwareSkinningTwoWeights_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 lightPos[2], + uniform float4 lightDiffuseColour[2], + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(0,0,0,0); + int i; + for (i = 0; i < 2; ++i) + { + blendPos += float4(mul(worldMatrix3x4Array[blendIdx[i]], position).xyz, 1.0) * blendWgt[i]; + } + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + // transform normal + float3 norm = float3(0,0,0); + for (i = 0; i < 2; ++i) + { + norm += mul((float3x3)worldMatrix3x4Array[blendIdx[i]], normal) * + blendWgt[i]; + } + norm = normalize(norm); + // Lighting - support point and directional + float3 lightDir0 = normalize( + lightPos[0].xyz - (blendPos.xyz * lightPos[0].w)); + float3 lightDir1 = normalize( + lightPos[1].xyz - (blendPos.xyz * lightPos[1].w)); + + + oUv = uv; + colour = float4(0.5, 0.5, 0.5, 1) + + (saturate(dot(lightDir0, norm)) * lightDiffuseColour[0]) + + (saturate(dot(lightDir1, norm)) * lightDiffuseColour[1]); + +} + +/* + Two-weight-per-vertex hardware skinning, shadow caster pass +*/ +void hardwareSkinningTwoWeightsCaster_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + + out float4 oPosition : POSITION, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(0,0,0,0); + int i; + for (i = 0; i < 2; ++i) + { + blendPos += float4(mul(worldMatrix3x4Array[blendIdx[i]], position).xyz, 1.0) * blendWgt[i]; + } + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + + + colour = ambient; + + +} + + +/* + Four-weight-per-vertex hardware skinning, 2 lights + The trouble with vertex programs is they're not general purpose, but + fixed function hardware skinning is very poorly supported +*/ +void hardwareSkinningFourWeights_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 lightPos[2], + uniform float4 lightDiffuseColour[2], + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(0,0,0,0); + int i; + for (i = 0; i < 4; ++i) + { + blendPos += float4(mul(worldMatrix3x4Array[blendIdx[i]], position).xyz, 1.0) * blendWgt[i]; + } + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + // transform normal + float3 norm = float3(0,0,0); + for (i = 0; i < 4; ++i) + { + norm += mul((float3x3)worldMatrix3x4Array[blendIdx[i]], normal) * + blendWgt[i]; + } + norm = normalize(norm); + // Lighting - support point and directional + float3 lightDir0 = normalize( + lightPos[0].xyz - (blendPos.xyz * lightPos[0].w)); + float3 lightDir1 = normalize( + lightPos[1].xyz - (blendPos.xyz * lightPos[1].w)); + + + oUv = uv; + colour = ambient + + (saturate(dot(lightDir0, norm)) * lightDiffuseColour[0]) + + (saturate(dot(lightDir1, norm)) * lightDiffuseColour[1]); + +} + +void hardwareMorphAnimation(float3 pos1 : POSITION, + float4 normal : NORMAL, + float2 uv : TEXCOORD0, + float3 pos2 : TEXCOORD1, + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + + uniform float4x4 worldViewProj, + uniform float4 anim_t) +{ + // interpolate + float4 interp = float4(pos1 + anim_t.x*(pos2 - pos1), 1.0f); + + oPosition = mul(worldViewProj, interp); + oUv = uv; + colour = float4(1,0,0,1); +} + +void hardwarePoseAnimation(float3 pos : POSITION, + float4 normal : NORMAL, + float2 uv : TEXCOORD0, + float3 pose1 : TEXCOORD1, + float3 pose2 : TEXCOORD2, + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + + uniform float4x4 worldViewProj, + uniform float4 anim_t) +{ + // interpolate + float4 interp = float4(pos + anim_t.x*pose1 + anim_t.y*pose2, 1.0f); + + oPosition = mul(worldViewProj, interp); + oUv = uv; + colour = float4(1,0,0,1); +} + + +void basicPassthroughTangent_v(float4 position : POSITION, + float3 tangent : TANGENT, + + out float4 oPosition : POSITION, + out float3 oTangent : TEXCOORD0, + + uniform float4x4 worldViewProj) +{ + oPosition = mul(worldViewProj, position); + oTangent = tangent; +} +void basicPassthroughNormal_v(float4 position : POSITION, + float3 normal : NORMAL, + + out float4 oPosition : POSITION, + out float3 oNormal : TEXCOORD0, + + uniform float4x4 worldViewProj) +{ + oPosition = mul(worldViewProj, position); + oNormal = normal; +} +// Basic fragment program to display UV +float4 showuv_p (float2 uv : TEXCOORD0) : COLOR +{ + // wrap values using frac + return float4(frac(uv.x), frac(uv.y), 0, 1); +} +// Basic fragment program to display 3d uv +float4 showuvdir3d_p (float3 uv : TEXCOORD0) : COLOR +{ + float3 n = normalize(uv); + return float4(n.x, n.y, n.z, 1); +} + + +/* + Basic ambient lighting vertex program +*/ +void ambientOneTexture_vp(float4 position : POSITION, + float2 uv : TEXCOORD0, + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + + uniform float4x4 worldViewProj, + uniform float4 ambient) +{ + oPosition = mul(worldViewProj, position); + oUv = uv; + colour = ambient; +} + +/* + Single-weight-per-vertex hardware skinning, 2 lights + The trouble with vertex programs is they're not general purpose, but + fixed function hardware skinning is very poorly supported +*/ +void hardwareSkinningOneWeight_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float blendIdx : BLENDINDICES, + + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 lightPos[2], + uniform float4 lightDiffuseColour[2], + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(mul(worldMatrix3x4Array[blendIdx], position).xyz, 1.0); + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + // transform normal + float3 norm = mul((float3x3)worldMatrix3x4Array[blendIdx], normal); + // Lighting - support point and directional + float3 lightDir0 = normalize( + lightPos[0].xyz - (blendPos.xyz * lightPos[0].w)); + float3 lightDir1 = normalize( + lightPos[1].xyz - (blendPos.xyz * lightPos[1].w)); + + oUv = uv; + colour = ambient + + (saturate(dot(lightDir0, norm)) * lightDiffuseColour[0]) + + (saturate(dot(lightDir1, norm)) * lightDiffuseColour[1]); + +} + +/* + Single-weight-per-vertex hardware skinning, shadow-caster pass +*/ +void hardwareSkinningOneWeightCaster_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float blendIdx : BLENDINDICES, + + + out float4 oPosition : POSITION, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(mul(worldMatrix3x4Array[blendIdx], position).xyz, 1.0); + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + + colour = ambient; + +} + +/* + Two-weight-per-vertex hardware skinning, 2 lights + The trouble with vertex programs is they're not general purpose, but + fixed function hardware skinning is very poorly supported +*/ +void hardwareSkinningTwoWeights_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 lightPos[2], + uniform float4 lightDiffuseColour[2], + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(0,0,0,0); + int i; + for (i = 0; i < 2; ++i) + { + blendPos += float4(mul(worldMatrix3x4Array[blendIdx[i]], position).xyz, 1.0) * blendWgt[i]; + } + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + // transform normal + float3 norm = float3(0,0,0); + for (i = 0; i < 2; ++i) + { + norm += mul((float3x3)worldMatrix3x4Array[blendIdx[i]], normal) * + blendWgt[i]; + } + norm = normalize(norm); + // Lighting - support point and directional + float3 lightDir0 = normalize( + lightPos[0].xyz - (blendPos.xyz * lightPos[0].w)); + float3 lightDir1 = normalize( + lightPos[1].xyz - (blendPos.xyz * lightPos[1].w)); + + + oUv = uv; + colour = float4(0.5, 0.5, 0.5, 1) + + (saturate(dot(lightDir0, norm)) * lightDiffuseColour[0]) + + (saturate(dot(lightDir1, norm)) * lightDiffuseColour[1]); + +} + +/* + Two-weight-per-vertex hardware skinning, shadow caster pass +*/ +void hardwareSkinningTwoWeightsCaster_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + + out float4 oPosition : POSITION, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(0,0,0,0); + int i; + for (i = 0; i < 2; ++i) + { + blendPos += float4(mul(worldMatrix3x4Array[blendIdx[i]], position).xyz, 1.0) * blendWgt[i]; + } + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + + + colour = ambient; + + +} + + +/* + Four-weight-per-vertex hardware skinning, 2 lights + The trouble with vertex programs is they're not general purpose, but + fixed function hardware skinning is very poorly supported +*/ +void hardwareSkinningFourWeights_vp( + float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float4 blendIdx : BLENDINDICES, + float4 blendWgt : BLENDWEIGHT, + + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + // Support up to 24 bones of float3x4 + // vs_1_1 only supports 96 params so more than this is not feasible + uniform float3x4 worldMatrix3x4Array[24], + uniform float4x4 viewProjectionMatrix, + uniform float4 lightPos[2], + uniform float4 lightDiffuseColour[2], + uniform float4 ambient) +{ + // transform by indexed matrix + float4 blendPos = float4(0,0,0,0); + int i; + for (i = 0; i < 4; ++i) + { + blendPos += float4(mul(worldMatrix3x4Array[blendIdx[i]], position).xyz, 1.0) * blendWgt[i]; + } + // view / projection + oPosition = mul(viewProjectionMatrix, blendPos); + // transform normal + float3 norm = float3(0,0,0); + for (i = 0; i < 4; ++i) + { + norm += mul((float3x3)worldMatrix3x4Array[blendIdx[i]], normal) * + blendWgt[i]; + } + norm = normalize(norm); + // Lighting - support point and directional + float3 lightDir0 = normalize( + lightPos[0].xyz - (blendPos.xyz * lightPos[0].w)); + float3 lightDir1 = normalize( + lightPos[1].xyz - (blendPos.xyz * lightPos[1].w)); + + + oUv = uv; + colour = ambient + + (saturate(dot(lightDir0, norm)) * lightDiffuseColour[0]) + + (saturate(dot(lightDir1, norm)) * lightDiffuseColour[1]); + +} + +void hardwareMorphAnimation(float3 pos1 : POSITION, + float4 normal : NORMAL, + float2 uv : TEXCOORD0, + float3 pos2 : TEXCOORD1, + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + + uniform float4x4 worldViewProj, + uniform float4 anim_t) +{ + // interpolate + float4 interp = float4(pos1 + anim_t.x*(pos2 - pos1), 1.0f); + + oPosition = mul(worldViewProj, interp); + oUv = uv; + colour = float4(1,0,0,1); +} + +void hardwarePoseAnimation(float3 pos : POSITION, + float4 normal : NORMAL, + float2 uv : TEXCOORD0, + float3 pose1 : TEXCOORD1, + float3 pose2 : TEXCOORD2, + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 colour : COLOR, + + uniform float4x4 worldViewProj, + uniform float4 anim_t) +{ + // interpolate + float4 interp = float4(pos + anim_t.x*pose1 + anim_t.y*pose2, 1.0f); + + oPosition = mul(worldViewProj, interp); + oUv = uv; + colour = float4(1,0,0,1); +} + + +void basicPassthroughTangent_v(float4 position : POSITION, + float3 tangent : TANGENT, + + out float4 oPosition : POSITION, + out float3 oTangent : TEXCOORD0, + + uniform float4x4 worldViewProj) +{ + oPosition = mul(worldViewProj, position); + oTangent = tangent; +} +void basicPassthroughNormal_v(float4 position : POSITION, + float3 normal : NORMAL, + + out float4 oPosition : POSITION, + out float3 oNormal : TEXCOORD0, + + uniform float4x4 worldViewProj) +{ + oPosition = mul(worldViewProj, position); + oNormal = normal; +} +// Basic fragment program to display UV +float4 showuv_p (float2 uv : TEXCOORD0) : COLOR +{ + // wrap values using frac + return float4(frac(uv.x), frac(uv.y), 0, 1); +} +// Basic fragment program to display 3d uv +float4 showuvdir3d_p (float3 uv : TEXCOORD0) : COLOR +{ + float3 n = normalize(uv); + return float4(n.x, n.y, n.z, 1); +} + + diff --git a/res/dist/media/materials/programs/Example_BumpMapping.cg b/res/dist/media/materials/programs/Example_BumpMapping.cg new file mode 100644 index 00000000000..d87f58e74e7 --- /dev/null +++ b/res/dist/media/materials/programs/Example_BumpMapping.cg @@ -0,0 +1,235 @@ +// General functions + +// Expand a range-compressed vector +float3 expand(float3 v) +{ + return (v - 0.5) * 2; +} + + +/* Bump mapping vertex program + In this program, we want to calculate the tangent space light vector + on a per-vertex level which will get passed to the fragment program, + or to the fixed function dot3 operation, to produce the per-pixel + lighting effect. +*/ +void main_vp(float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float4 tangent : TANGENT, + // outputs + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float3 oTSLightDir : TEXCOORD1, + // parameters + uniform float4 lightPosition, // object space + uniform float4x4 worldViewProj) +{ + // calculate output position + oPosition = mul(worldViewProj, position); + + // pass the main uvs straight through unchanged + oUv = uv; + + // calculate tangent space light vector + // Get object space light direction + // Non-normalised since we'll do that in the fragment program anyway + float3 lightDir = lightPosition.xyz - (position * lightPosition.w); + + // Calculate the binormal (NB we assume both normal and tangent are + // already normalised) + // NB looks like nvidia cross params are BACKWARDS to what you'd expect + // this equates to NxT, not TxN + +#if TANGENTS_HAVE_PARITY + float3 binormal = cross(tangent.xyz, normal) * tangent.www; +#else + // fixed handedness + float3 binormal = cross(tangent.xyz, normal); +#endif + + // Form a rotation matrix out of the vectors + float3x3 rotation = float3x3(tangent.xyz, binormal, normal); + + // Transform the light vector according to this matrix + oTSLightDir = mul(rotation, lightDir); + + +} + +/* Bump mapping vertex program for shadow receiving + In this program, we want to calculate the tangent space light vector + on a per-vertex level which will get passed to the fragment program, + or to the fixed function dot3 operation, to produce the per-pixel + lighting effect. +*/ +void main_shadowreceiver_vp(float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float3 tangent : TANGENT, + + // outputs + out float4 oPosition : POSITION, + out float4 uvproj : TEXCOORD0, + out float2 oUv : TEXCOORD1, + out float3 oTSLightDir : TEXCOORD2, + + // parameters + uniform float4 lightPosition, // object space + uniform float4x4 worldViewProj, + uniform float4x4 worldMatrix, + uniform float4x4 texViewProj) +{ + // calculate output position + oPosition = mul(worldViewProj, position); + + // pass the main uvs straight through unchanged + oUv = uv; + + // calculate tangent space light vector + // Get object space light direction + // Non-normalised since we'll do that in the fragment program anyway + float3 lightDir = lightPosition.xyz - (position * lightPosition.w); + + // Calculate the binormal (NB we assume both normal and tangent are + // already normalised) + // NB looks like nvidia cross params are BACKWARDS to what you'd expect + // this equates to NxT, not TxN + float3 binormal = cross(tangent, normal); + + // Form a rotation matrix out of the vectors + float3x3 rotation = float3x3(tangent.xyz, binormal, normal); + + // Transform the light vector according to this matrix + oTSLightDir = mul(rotation, lightDir); + + // Projection + uvproj = mul(worldMatrix, position); + uvproj = mul(texViewProj, uvproj); + +} + + +void main_fp( float4 position : POSITION, + float2 uv : TEXCOORD0, + float3 TSlightDir : TEXCOORD1, + + out float4 colour : COLOR, + + uniform float4 lightDiffuse, + uniform sampler2D normalMap : register(s0)) +{ + // retrieve normalised light vector, expand from range-compressed + float3 lightVec = normalize(TSlightDir).xyz; + + // get bump map vector, again expand from range-compressed + float3 bumpVec = expand(tex2D(normalMap, uv).xyz); + + // Calculate dot product + colour = lightDiffuse * dot(bumpVec, lightVec); + +} + +void main_shadowreceiver_fp( float4 position : POSITION, + float4 uvproj : TEXCOORD0, + float2 uv : TEXCOORD1, + float3 TSlightDir : TEXCOORD2, + + out float4 colour : COLOR, + + uniform float4 lightDiffuse, + uniform sampler2D shadowMap : register(s0), + uniform sampler2D normalMap : register(s1)) +{ + + + // retrieve normalised light vector, expand from range-compressed + float3 lightVec = expand(normalize(TSlightDir).xyz); + + // get bump map vector, again expand from range-compressed + float3 bumpVec = expand(tex2D(normalMap, uv).xyz); + + // get shadow value + float3 shadow = tex2Dproj(shadowMap, uvproj).xyz; + + // Calculate dot product + colour = float4(shadow * lightDiffuse * dot(bumpVec, lightVec), 1.0f); + +} + +/* Vertex program which includes specular component */ +void specular_vp(float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + float3 tangent : TANGENT, + // outputs + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float3 oTSLightDir : TEXCOORD1, + out float3 oTSHalfAngle : TEXCOORD2, + // parameters + uniform float4 lightPosition, // object space + uniform float3 eyePosition, // object space + uniform float4x4 worldViewProj) +{ + // calculate output position + oPosition = mul(worldViewProj, position); + + // pass the main uvs straight through unchanged + oUv = uv; + + // calculate tangent space light vector + // Get object space light direction + float3 lightDir = normalize(lightPosition.xyz - (position * lightPosition.w)); + + // Calculate the binormal (NB we assume both normal and tangent are + // already normalised) + // NB looks like nvidia cross params are BACKWARDS to what you'd expect + // this equates to NxT, not TxN + float3 binormal = cross(tangent, normal); + + // Form a rotation matrix out of the vectors + float3x3 rotation = float3x3(tangent, binormal, normal); + + // Transform the light vector according to this matrix + oTSLightDir = mul(rotation, lightDir); + + // Calculate half-angle in tangent space + float3 eyeDir = normalize(eyePosition - position.xyz); + float3 halfAngle = normalize(eyeDir + lightDir); + oTSHalfAngle = mul(rotation, halfAngle); + + +} + +/* Fragment program which supports specular component */ +void specular_fp( float4 position : POSITION, + float2 uv : TEXCOORD0, + float3 TSlightDir : TEXCOORD1, + float3 TShalfAngle: TEXCOORD2, + + out float4 colour : COLOR, + + uniform float4 lightDiffuse, + uniform float4 lightSpecular, + uniform sampler2D normalMap : register(s0)) +{ + // retrieve normalised light vector + float3 lightVec = normalize(TSlightDir); + + // retrieve half angle and normalise + float3 halfAngle = normalize(TShalfAngle); + + // get bump map vector, again expand from range-compressed + float3 bumpVec = expand(tex2D(normalMap, uv).xyz); + + // Pre-raise the specular exponent to the eight power + float specFactor = pow(saturate(dot(bumpVec, halfAngle)), 4); + + + // Calculate dot product for diffuse + colour = (lightDiffuse * saturate(dot(bumpVec, lightVec))) + + (lightSpecular * specFactor); + +} + diff --git a/res/dist/media/materials/programs/Example_BumpMappingFp.glsles b/res/dist/media/materials/programs/Example_BumpMappingFp.glsles new file mode 100644 index 00000000000..e9f297184a6 --- /dev/null +++ b/res/dist/media/materials/programs/Example_BumpMappingFp.glsles @@ -0,0 +1,29 @@ +#version 100 +precision mediump int; +precision mediump float; + +uniform vec4 lightDiffuse; +uniform sampler2D normalMap; + +varying vec2 oUv0; +varying vec3 oTSLightDir; + +// General functions + +// Expand a range-compressed vector +vec3 expand(vec3 v) +{ + return (v - 0.5) * 2.0; +} + +void main() +{ + // Retrieve normalised light vector, expand from range-compressed + vec3 lightVec = normalize(oTSLightDir).xyz; + + // Get bump map vector, again expand from range-compressed + vec3 bumpVec = expand(texture2D(normalMap, oUv0).xyz); + + // Calculate dot product + gl_FragColor = lightDiffuse * dot(bumpVec, lightVec); +} diff --git a/res/dist/media/materials/programs/Example_BumpMappingShadowRcvFp.glsles b/res/dist/media/materials/programs/Example_BumpMappingShadowRcvFp.glsles new file mode 100644 index 00000000000..0b179e8b89f --- /dev/null +++ b/res/dist/media/materials/programs/Example_BumpMappingShadowRcvFp.glsles @@ -0,0 +1,34 @@ +#version 100 +precision mediump int; +precision mediump float; + +// General functions + +// Expand a range-compressed vector +vec3 expand(vec3 v) +{ + return (v - 0.5) * 2.0; +} + +uniform sampler2D shadowMap; +uniform sampler2D normalMap; +uniform vec4 lightDiffuse; + +varying vec4 uvproj; +varying vec4 oUv0; +varying vec3 oTSLightDir; + +void main() +{ + // retrieve normalised light vector, expand from range-compressed + vec3 lightVec = expand(normalize(oTSLightDir).xyz); + + // get bump map vector, again expand from range-compressed + vec3 bumpVec = expand(texture2D(normalMap, oUv0.xy).xyz); + + // get shadow value + vec3 shadow = texture2DProj(shadowMap, uvproj).xyz; + + // Calculate dot product + gl_FragColor = vec4(shadow * lightDiffuse.xyz * dot(bumpVec, lightVec), 1.0); +} diff --git a/res/dist/media/materials/programs/Example_BumpMappingShadowRcvVp.glsles b/res/dist/media/materials/programs/Example_BumpMappingShadowRcvVp.glsles new file mode 100644 index 00000000000..181993f0b7c --- /dev/null +++ b/res/dist/media/materials/programs/Example_BumpMappingShadowRcvVp.glsles @@ -0,0 +1,55 @@ +#version 100 +precision mediump int; +precision mediump float; + +/* Bump mapping vertex program for shadow receiving + In this program, we want to calculate the tangent space light vector + on a per-vertex level which will get passed to the fragment program, + or to the fixed function dot3 operation, to produce the per-pixel + lighting effect. +*/ + +// parameters +uniform vec4 lightPosition; // object space +uniform mat4 worldViewProj; +uniform mat4 worldMatrix; +uniform mat4 texViewProj; + +attribute vec4 vertex; +attribute vec3 normal; +attribute vec3 tangent; +attribute vec4 uv0; + +varying vec4 uvproj; +varying vec4 oUv0; +varying vec3 oTSLightDir; + +void main() +{ + // Calculate output position + gl_Position = worldViewProj * vertex; + + // Pass the main uvs straight through unchanged + oUv0 = uv0; + + // Calculate tangent space light vector + // Get object space light direction + // Non-normalised since we'll do that in the fragment program anyway + vec3 lightDir = lightPosition.xyz - (vertex * lightPosition.w).xyz; + + // Calculate the binormal (NB we assume both normal and tangent are + // already normalised) + vec3 binormal = cross(normal, tangent); + + // Form a rotation matrix out of the vectors, column major for glsl es + mat3 rotation = mat3(tangent,binormal,normal); +// mat3 rotation = mat3(vec3(tangent[0], binormal[0], normal[0]), +// vec3(tangent[1], binormal[1], normal[1]), +// vec3(tangent[2], binormal[2], normal[2])); + + // Transform the light vector according to this matrix + oTSLightDir = rotation * lightDir; + + // Projection + uvproj = texViewProj * (worldMatrix * vertex); +} diff --git a/res/dist/media/materials/programs/Example_BumpMappingSpecularFp.glsles b/res/dist/media/materials/programs/Example_BumpMappingSpecularFp.glsles new file mode 100644 index 00000000000..0ba5b3c4396 --- /dev/null +++ b/res/dist/media/materials/programs/Example_BumpMappingSpecularFp.glsles @@ -0,0 +1,41 @@ +#version 100 +precision mediump int; +precision mediump float; + +// General functions + +// Expand a range-compressed vector +vec3 expand(vec3 v) +{ + return (v - 0.5) * 2.0; +} + +uniform vec4 lightDiffuse; +uniform vec4 lightSpecular; +uniform sampler2D normalMap; + +varying vec4 oUv0; +varying vec3 oTSLightDir; +varying vec3 oTSHalfAngle; + +// NOTE: GLSL does not have the saturate function. But it is equivalent to clamp(val, 0.0, 1.0) + +/* Fragment program which supports specular component */ +void main() +{ + // retrieve normalised light vector + vec3 lightVec = normalize(oTSLightDir); + + // retrieve half angle and normalise + vec3 halfAngle = normalize(oTSHalfAngle); + + // get bump map vector, again expand from range-compressed + vec3 bumpVec = expand(texture2D(normalMap, oUv0.xy).xyz); + + // Pre-raise the specular exponent to the eight power + float specFactor = pow(clamp(dot(bumpVec, halfAngle), 0.0, 1.0), 4.0); + + // Calculate dot product for diffuse + gl_FragColor = (lightDiffuse * clamp(dot(bumpVec, lightVec), 0.0, 1.0)) + + (lightSpecular * specFactor); +} diff --git a/res/dist/media/materials/programs/Example_BumpMappingSpecularVp.glsles b/res/dist/media/materials/programs/Example_BumpMappingSpecularVp.glsles new file mode 100644 index 00000000000..6576660c3a2 --- /dev/null +++ b/res/dist/media/materials/programs/Example_BumpMappingSpecularVp.glsles @@ -0,0 +1,50 @@ +#version 100 +precision mediump int; +precision mediump float; + +// General functions +// parameters +uniform vec4 lightPosition; // object space +uniform vec3 eyePosition; // object space +uniform mat4 worldViewProj; + +attribute vec4 vertex; +attribute vec3 normal; +attribute vec3 tangent; +attribute vec4 uv0; + +varying vec4 oUv0; +varying vec3 oTSLightDir; +varying vec3 oTSHalfAngle; + +/* Vertex program which includes specular component */ +void main() +{ + // calculate output position + gl_Position = worldViewProj * vertex; + + // pass the main uvs straight through unchanged + oUv0 = uv0; + + // calculate tangent space light vector + // Get object space light direction + vec3 lightDir = normalize(lightPosition.xyz - (vertex * lightPosition.w).xyz); + + // Calculate the binormal (NB we assume both normal and tangent are + // already normalised) + vec3 binormal = cross(normal, tangent); + + // Form a rotation matrix out of the vectors + mat3 rotation = mat3(tangent,binormal,normal); +// mat3 rotation = mat3(vec3(tangent[0], binormal[0], normal[0]), +// vec3(tangent[1], binormal[1], normal[1]), +// vec3(tangent[2], binormal[2], normal[2])); + + // Transform the light vector according to this matrix + oTSLightDir = rotation * lightDir; + + // Calculate half-angle in tangent space + vec3 eyeDir = normalize(eyePosition - vertex.xyz); + vec3 halfAngle = normalize(eyeDir + lightDir); + oTSHalfAngle = rotation * halfAngle; +} diff --git a/res/dist/media/materials/programs/Example_BumpMappingVp.glsles b/res/dist/media/materials/programs/Example_BumpMappingVp.glsles new file mode 100644 index 00000000000..19d9e87f106 --- /dev/null +++ b/res/dist/media/materials/programs/Example_BumpMappingVp.glsles @@ -0,0 +1,50 @@ +#version 100 +precision mediump int; +precision mediump float; + +/* Bump mapping vertex program + In this program, we want to calculate the tangent space light vector + on a per-vertex level which will get passed to the fragment program, + or to the fixed function dot3 operation, to produce the per-pixel + lighting effect. +*/ +// parameters +uniform vec4 lightPosition; // object space +uniform mat4 worldViewProj; + +attribute vec4 vertex; +attribute vec3 normal; +attribute vec3 tangent; +attribute vec2 uv0; + +varying vec2 oUv0; +varying vec3 oTSLightDir; + +void main() +{ + // Calculate output position + gl_Position = worldViewProj * vertex; + + // Pass the main uvs straight through unchanged + oUv0 = uv0; + + // Calculate tangent space light vector + // Get object space light direction + // Non-normalised since we'll do that in the fragment program anyway + vec3 lightDir = lightPosition.xyz - (vertex * lightPosition.w).xyz; + + // Calculate the binormal (NB we assume both normal and tangent are + // already normalised) + + // Fixed handedness + vec3 binormal = cross(normal, tangent); + + // Form a rotation matrix out of the vectors, column major for glsl es + mat3 rotation = mat3(tangent,binormal,normal); +// mat3 rotation = mat3(vec3(tangent[0], binormal[0], normal[0]), +// vec3(tangent[1], binormal[1], normal[1]), +// vec3(tangent[2], binormal[2], normal[2])); + + // Transform the light vector according to this matrix + oTSLightDir = rotation * lightDir; +} diff --git a/res/dist/media/materials/programs/Example_CelShading.cg b/res/dist/media/materials/programs/Example_CelShading.cg new file mode 100644 index 00000000000..72ee749f7c7 --- /dev/null +++ b/res/dist/media/materials/programs/Example_CelShading.cg @@ -0,0 +1,64 @@ + +/* Cel shading vertex program for single-pass rendering + In this program, we want to calculate the diffuse and specular + ramp components, and the edge factor (for doing simple outlining) + For the outlining to look good, we need a pretty well curved model. +*/ +void main_vp(float4 position : POSITION, + float3 normal : NORMAL, + // outputs + out float4 oPosition : POSITION, + out float diffuse : TEXCOORD0, + out float specular : TEXCOORD1, + out float edge : TEXCOORD2, + // parameters + uniform float3 lightPosition, // object space + uniform float3 eyePosition, // object space + uniform float4 shininess, + uniform float4x4 worldViewProj) +{ + // calculate output position + oPosition = mul(worldViewProj, position); + + // calculate light vector + float3 N = normalize(normal); + float3 L = normalize(lightPosition - position.xyz); + + // Calculate diffuse component + diffuse = max(dot(N, L) , 0); + + // Calculate specular component + float3 E = normalize(eyePosition - position.xyz); + float3 H = normalize(L + E); + specular = pow(max(dot(N, H), 0), shininess); + // Mask off specular if diffuse is 0 + if (diffuse == 0) specular = 0; + + // Edge detection, dot eye and normal vectors + edge = max(dot(N, E), 0); +} + +void main_fp( float4 position : POSITION, + float diffuseIn : TEXCOORD0, + float specularIn : TEXCOORD1, + float edge : TEXCOORD2, + + out float4 colour : COLOR, + + uniform float4 diffuse, + uniform float4 specular, + + uniform sampler1D diffuseRamp, + uniform sampler1D specularRamp, + uniform sampler1D edgeRamp) +{ + // Step functions from textures + diffuseIn = tex1D(diffuseRamp, diffuseIn).x; + specularIn = tex1D(specularRamp, specularIn).x; + edge = tex1D(edgeRamp, edge).x; + + colour = edge * ((diffuse * diffuseIn) + + (specular * specularIn)); +} + + diff --git a/res/dist/media/materials/programs/Example_CelShadingFp.glsles b/res/dist/media/materials/programs/Example_CelShadingFp.glsles new file mode 100644 index 00000000000..db311e55acc --- /dev/null +++ b/res/dist/media/materials/programs/Example_CelShadingFp.glsles @@ -0,0 +1,25 @@ +#version 100 +precision mediump int; +precision mediump float; + +/* Cel shading fragment program for single-pass rendering */ +uniform vec4 diffuse; +uniform vec4 specular; +uniform sampler2D diffuseRamp; +uniform sampler2D specularRamp; +uniform sampler2D edgeRamp; + +varying float diffuseIn; +varying float specularIn; +varying float edge; + +void main() +{ + // Step functions from textures + vec4 diffuseStep = texture2D(diffuseRamp, vec2(diffuseIn)); + vec4 specularStep = texture2D(specularRamp, vec2(specularIn)); + vec4 edgeStep = texture2D(edgeRamp, vec2(edge)); + + gl_FragColor = edgeStep.x * ((diffuse * diffuseStep.x) + + (specular * specularStep.x)); +} diff --git a/res/dist/media/materials/programs/Example_CelShadingVp.glsles b/res/dist/media/materials/programs/Example_CelShadingVp.glsles new file mode 100644 index 00000000000..c37b738ec46 --- /dev/null +++ b/res/dist/media/materials/programs/Example_CelShadingVp.glsles @@ -0,0 +1,50 @@ +#version 100 +precision mediump int; +precision mediump float; + +/* Cel shading vertex program for single-pass rendering + In this program, we want to calculate the diffuse and specular + ramp components, and the edge factor (for doing simple outlining) + For the outlining to look good, we need a pretty well curved model. +*/ +// Parameters +attribute vec4 vertex; +attribute vec3 normal; + +uniform vec3 lightPosition; // object space +uniform vec3 eyePosition; // object space +uniform vec4 shininess; +uniform mat4 worldViewProj; + +varying float diffuseIn; +varying float specularIn; +varying float edge; + +void main() +{ + // calculate output position + gl_Position = worldViewProj * vertex; + + // calculate light vector + vec3 N = normalize(normal); + vec3 L = normalize(lightPosition - vertex.xyz); + vec3 E = normalize(eyePosition - vertex.xyz); + + // Calculate diffuse component + diffuseIn = max(dot(N, L) , 0.0); + + // Mask off specular if diffuse is 0 + if (diffuseIn == 0.0) + { + specularIn = 0.0; + } + else + { + // Calculate specular component + vec3 H = normalize(L + E); + specularIn = pow(max(dot(N, H), 0.0), shininess.x); + } + + // Edge detection, dot eye and normal vectors + edge = max(dot(N, E), 0.0); +} diff --git a/res/dist/media/materials/programs/Example_Fresnel.cg b/res/dist/media/materials/programs/Example_Fresnel.cg new file mode 100644 index 00000000000..d3eaabc76e7 --- /dev/null +++ b/res/dist/media/materials/programs/Example_Fresnel.cg @@ -0,0 +1,116 @@ +// Vertex program for fresnel reflections / refractions +void main_vp( + float4 pos : POSITION, + float4 normal : NORMAL, + float2 tex : TEXCOORD0, + + out float4 oPos : POSITION, + out float3 noiseCoord : TEXCOORD0, + out float4 projectionCoord : TEXCOORD1, + out float3 oEyeDir : TEXCOORD2, + out float3 oNormal : TEXCOORD3, + + uniform float4x4 worldViewProjMatrix, + uniform float3 eyePosition, // object space + uniform float timeVal, + uniform float scale, // the amount to scale the noise texture by + uniform float scroll, // the amount by which to scroll the noise + uniform float noise // the noise perturb as a factor of the time + ) +{ + oPos = mul(worldViewProjMatrix, pos); + // Projective texture coordinates, adjust for mapping + float4x4 scalemat = float4x4(0.5, 0, 0, 0.5, + 0,-0.5, 0, 0.5, + 0, 0, 0.5, 0.5, + 0, 0, 0, 1); + projectionCoord = mul(scalemat, oPos); + // Noise map coords + noiseCoord.xy = (tex + (timeVal * scroll)) * scale; + noiseCoord.z = noise * timeVal; + + oEyeDir = normalize(pos.xyz - eyePosition); + oNormal = normal.rgb; + +} + +// Fragment program for distorting a texture using a 3D noise texture +void main_fp( + float4 pos : POSITION, + float3 noiseCoord : TEXCOORD0, + float4 projectionCoord : TEXCOORD1, + float3 eyeDir : TEXCOORD2, + float3 normal : TEXCOORD3, + + out float4 col : COLOR, + + uniform float4 tintColour, + uniform float noiseScale, + uniform float fresnelBias, + uniform float fresnelScale, + uniform float fresnelPower, + uniform sampler2D noiseMap : register(s0), + uniform sampler2D reflectMap : register(s1), + uniform sampler2D refractMap : register(s2) + ) +{ + // Do the tex projection manually so we can distort _after_ + float2 final = projectionCoord.xy / projectionCoord.w; + + // Noise + float3 noiseNormal = (tex2D(noiseMap, (noiseCoord.xy / 5)).rgb - 0.5).rbg * noiseScale; + final += noiseNormal.xz; + + // Fresnel + //normal = normalize(normal + noiseNormal.xz); + float fresnel = fresnelBias + fresnelScale * pow(1 + dot(eyeDir, normal), fresnelPower); + + // Reflection / refraction + float4 reflectionColour = tex2D(reflectMap, final); + float4 refractionColour = tex2D(refractMap, final) + tintColour; + + // Final colour + col = lerp(refractionColour, reflectionColour, fresnel); + + +} + + +// Old version to match ATI PS 1.3 implementation +void main_vp_old( + float4 pos : POSITION, + float4 normal : NORMAL, + float2 tex : TEXCOORD0, + + out float4 oPos : POSITION, + out float fresnel : COLOR, + out float3 noiseCoord : TEXCOORD0, + out float4 projectionCoord : TEXCOORD1, + + uniform float4x4 worldViewProjMatrix, + uniform float3 eyePosition, // object space + uniform float fresnelBias, + uniform float fresnelScale, + uniform float fresnelPower, + uniform float timeVal, + uniform float scale, // the amount to scale the noise texture by + uniform float scroll, // the amount by which to scroll the noise + uniform float noise // the noise perturb as a factor of the time + ) +{ + oPos = mul(worldViewProjMatrix, pos); + // Projective texture coordinates, adjust for mapping + float4x4 scalemat = float4x4(0.5, 0, 0, 0.5, + 0,-0.5, 0, 0.5, + 0, 0, 0.5, 0.5, + 0, 0, 0, 1); + projectionCoord = mul(scalemat, oPos); + // Noise map coords + noiseCoord.xy = (tex + (timeVal * scroll)) * scale; + noiseCoord.z = noise * timeVal; + + // calc fresnel factor (reflection coefficient) + float3 eyeDir = normalize(pos.xyz - eyePosition); + fresnel = fresnelBias + fresnelScale * pow(1 + dot(eyeDir, normal), fresnelPower); + +} diff --git a/res/dist/media/materials/programs/Example_FresnelFp.glsles b/res/dist/media/materials/programs/Example_FresnelFp.glsles new file mode 100644 index 00000000000..4f58e7cd643 --- /dev/null +++ b/res/dist/media/materials/programs/Example_FresnelFp.glsles @@ -0,0 +1,40 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform vec4 tintColour; +uniform float noiseScale; +uniform float fresnelBias; +uniform float fresnelScale; +uniform float fresnelPower; +uniform sampler2D noiseMap; +uniform sampler2D reflectMap; +uniform sampler2D refractMap; + +varying vec3 noiseCoord; +varying vec4 projectionCoord; +varying vec3 eyeDir; +varying vec3 oNormal; + +// Fragment program for distorting a texture using a 3D noise texture +void main() +{ + // Do the tex projection manually so we can distort _after_ + vec2 final = projectionCoord.xy / projectionCoord.w; + + // Noise + vec3 noiseNormal = (texture2D(noiseMap, (noiseCoord.xy / 5.0)).rgb - 0.5).rbg * noiseScale; + final += noiseNormal.xz; + + // Fresnel + //normal = normalize(normal + noiseNormal.xz); + float fresnel = fresnelBias + fresnelScale * pow(1.0 + dot(eyeDir, oNormal), fresnelPower); + + // Reflection / refraction + vec4 reflectionColour = texture2D(reflectMap, final); + vec4 refractionColour = texture2D(refractMap, final) + tintColour; + + // Final colour + gl_FragColor = mix(refractionColour, reflectionColour, fresnel); +} diff --git a/res/dist/media/materials/programs/Example_FresnelPS.asm b/res/dist/media/materials/programs/Example_FresnelPS.asm new file mode 100644 index 00000000000..193881a7719 --- /dev/null +++ b/res/dist/media/materials/programs/Example_FresnelPS.asm @@ -0,0 +1,72 @@ +ps.1.4 + // conversion from Cg generated ARB_fragment_program to ps.1.4 by NFZ + // command line args: -profile arbfp1 -entry main_fp + // program main_fp + // c0 : distortionRange + // c1 : tintColour + // testure 0 : noiseMap + // texture 1 : reflectMap + // texture 2 : refractMap + // v0.x : fresnel + // t0.xyz : noiseCoord + // t1.xyw : projectionCoord + +def c2, 2, 1, 0, 0 + + // Cg: distort.x = tex3D(noiseMap, noiseCoord).x; + // arbfp1: TEX R0.x, fragment.texcoord[0], texture[0], 3D; + // sample noise map using noiseCoord in TEX unit 0 + +texld r0, t0.xyz + + // get projected texture coordinates from TEX coord 1 + // will be used in phase 2 + +texcrd r1.xy, t1_dw.xyw +mov r1.z, c2.y + + // Cg: distort.y = tex3D(noiseMap, noiseCoord + yoffset).x; + // arbfp1: ADD R1.xyz, fragment.texcoord[0], c1; + // arbfp1: TEX R1.x, R1, texture[0], 3D; + // arbfp1: MOV R0.y, R1.x; + + // Cg: distort = (distort * 2 - 1) * distortionRange; + // arbfp1: MAD R0.xy, R0, c0.x, -c0.y; + // arbfp1: MUL R0.xy, R0, u0.x; + // (distort * 2 - 1) same as 2*(distort -.5) so use _bx2 + + + // Cg: final = projectionCoord.xy / projectionCoord.w; + // Cg: final += distort; + // arbfp1: RCP R0.w, fragment.texcoord[1].w; + // arbfp1: MAD R0.xy, fragment.texcoord[1], R0.w, R0; + // final = (distort * projectionCoord.w) + projectionCoord.xy + // for ps.1.4 have to re-arrange things a bit to perturb projected texture coordinates + +mad r0.xyz, r0_bx2, c0.x, r1 + +phase + + // do dependent texture reads + // Cg: reflectionColour = tex2D(reflectMap, final); + // arbfp1: TEX R0, R0, texture[1], 2D; + // sampe reflectMap using dependent read : texunit 1 + +texld r1, r0.xyz + + // Cg: refractionColour = tex2D(refractMap, final) + tintColour; + // arbfp1: TEX R1, R0, texture[2], 2D; + // sample refractMap : texunit 2 + +texld r2, r0.xyz + + // adding tintColour that is in global c1 + // arbfp1: ADD R1, R1, u1; + +add r2, r2, c1 + + // Cg: col = lerp(refractionColour, reflectionColour, fresnel); + // arbfp1: ADD R0, R0, -R1; + // arbfp1: MAD result.color, fragment.color.primary.x, R0, R1; + +lrp r0, v0.x, r1, r2 diff --git a/res/dist/media/materials/programs/Example_FresnelVp.glsles b/res/dist/media/materials/programs/Example_FresnelVp.glsles new file mode 100644 index 00000000000..a9fc0c387ea --- /dev/null +++ b/res/dist/media/materials/programs/Example_FresnelVp.glsles @@ -0,0 +1,39 @@ +#version 100 + +precision mediump int; +precision mediump float; + +attribute vec4 uv0; +attribute vec4 position; +attribute vec3 normal; + +uniform mat4 worldViewProjMatrix; +uniform vec3 eyePosition; // object space +uniform float timeVal; +uniform float scale; // the amount to scale the noise texture by +uniform float scroll; // the amount by which to scroll the noise +uniform float noise; // the noise perturb as a factor of the time + +varying vec3 noiseCoord; +varying vec4 projectionCoord; +varying vec3 eyeDir; +varying vec3 oNormal; + +// Vertex program for fresnel reflections / refractions +void main() +{ + gl_Position = worldViewProjMatrix * position; + // Projective texture coordinates, adjust for mapping + mat4 scalemat = mat4(0.5, 0.0, 0.0, 0.0, + 0.0, -0.5, 0.0, 0.0, + 0.0, 0.0, 0.5, 0.0, + 0.5, 0.5, 0.5, 1.0); + projectionCoord = scalemat * gl_Position; + + // Noise map coords + noiseCoord.xy = (uv0.xy + (timeVal * scroll)) * scale; + noiseCoord.z = noise * timeVal; + + eyeDir = normalize(position.xyz - eyePosition); + oNormal = normal.rgb; +} diff --git a/res/dist/media/materials/programs/Example_Projection.cg b/res/dist/media/materials/programs/Example_Projection.cg new file mode 100644 index 00000000000..c43f59041bd --- /dev/null +++ b/res/dist/media/materials/programs/Example_Projection.cg @@ -0,0 +1,28 @@ + +void generalPurposeProjection_vp( + float4 pos : POSITION, + + out float4 oPos : POSITION, + out float4 texCoord : TEXCOORD0, + + uniform float4x4 worldViewProjMatrix, + uniform float4x4 worldMatrix, + uniform float4x4 texViewProjMatrix) +{ + oPos = mul(worldViewProjMatrix, pos); + // multiply position by world matrix, then by projective view/proj + float4 newpos = mul(worldMatrix, pos); + texCoord = mul(texViewProjMatrix, newpos); + +} + +void generalPurposeProjection_fp( + float4 texCoord : TEXCOORD0, + out float4 col : COLOR, + uniform sampler2D texMap) +{ + col = tex2Dproj(texMap, texCoord); + +} + + diff --git a/res/dist/media/materials/programs/Example_ProjectionFp.glsles b/res/dist/media/materials/programs/Example_ProjectionFp.glsles new file mode 100644 index 00000000000..20fd2bd22b7 --- /dev/null +++ b/res/dist/media/materials/programs/Example_ProjectionFp.glsles @@ -0,0 +1,56 @@ + +void generalPurposeProjection_vp( + float4 pos : POSITION, + + out float4 oPos : POSITION, + out float4 texCoord : TEXCOORD0, + + uniform float4x4 worldViewProjMatrix, + uniform float4x4 worldMatrix, + uniform float4x4 texViewProjMatrix) +{ + oPos = mul(worldViewProjMatrix, pos); + // multiply position by world matrix, then by projective view/proj + float4 newpos = mul(worldMatrix, pos); + texCoord = mul(texViewProjMatrix, newpos); + +} + +void generalPurposeProjection_fp( + float4 texCoord : TEXCOORD0, + out float4 col : COLOR, + uniform sampler2D texMap) +{ + col = tex2Dproj(texMap, texCoord); + +} + + + +void generalPurposeProjection_vp( + float4 pos : POSITION, + + out float4 oPos : POSITION, + out float4 texCoord : TEXCOORD0, + + uniform float4x4 worldViewProjMatrix, + uniform float4x4 worldMatrix, + uniform float4x4 texViewProjMatrix) +{ + oPos = mul(worldViewProjMatrix, pos); + // multiply position by world matrix, then by projective view/proj + float4 newpos = mul(worldMatrix, pos); + texCoord = mul(texViewProjMatrix, newpos); + +} + +void generalPurposeProjection_fp( + float4 texCoord : TEXCOORD0, + out float4 col : COLOR, + uniform sampler2D texMap) +{ + col = tex2Dproj(texMap, texCoord); + +} + + diff --git a/res/dist/media/materials/programs/Example_ProjectionVp.glsles b/res/dist/media/materials/programs/Example_ProjectionVp.glsles new file mode 100644 index 00000000000..095109475df --- /dev/null +++ b/res/dist/media/materials/programs/Example_ProjectionVp.glsles @@ -0,0 +1,26 @@ + +void generalPurposeProjection_vp( + float4 pos : POSITION, + + out float4 oPos : POSITION, + out float4 texCoord : TEXCOORD0, + + uniform float4x4 worldViewProjMatrix, + uniform float4x4 worldMatrix, + uniform float4x4 texViewProjMatrix) +{ + oPos = mul(worldViewProjMatrix, pos); + // multiply position by world matrix, then by projective view/proj + float4 newpos = mul(worldMatrix, pos); + texCoord = mul(texViewProjMatrix, newpos); +} + +void generalPurposeProjection_fp( + float4 texCoord : TEXCOORD0, + out float4 col : COLOR, + uniform sampler2D texMap) +{ + col = tex2Dproj(texMap, texCoord); +} + + diff --git a/res/dist/media/materials/programs/Example_TextureArrayPS.asm b/res/dist/media/materials/programs/Example_TextureArrayPS.asm new file mode 100644 index 00000000000..8134784a895 --- /dev/null +++ b/res/dist/media/materials/programs/Example_TextureArrayPS.asm @@ -0,0 +1,10 @@ +!!NVfp4.0 +TEMP texcoord, c0, c1, frac; +MOV texcoord, fragment.texcoord[0]; +FLR texcoord.z, texcoord; +TEX c0, texcoord, texture[0], ARRAY2D; +ADD texcoord.z, texcoord, { 0, 0, 1, 0 }; +TEX c1, texcoord, texture[0], ARRAY2D; +FRC frac.x, fragment.texcoord[0].z; +LRP result.color, frac.x, c1, c0; +END diff --git a/res/dist/media/materials/programs/Example_TextureArrayPS.glsl b/res/dist/media/materials/programs/Example_TextureArrayPS.glsl new file mode 100644 index 00000000000..13c92aea292 --- /dev/null +++ b/res/dist/media/materials/programs/Example_TextureArrayPS.glsl @@ -0,0 +1,17 @@ +#version 120 +#extension GL_EXT_texture_array : enable + +uniform sampler2DArray TextureArrayTex; +varying vec3 oUv; + +void main(void) +{ + vec3 texcoord; + texcoord = oUv; + texcoord.z = floor(texcoord.z); + vec4 c0 = texture2DArray(TextureArrayTex, texcoord); + texcoord.z += 1.0; + vec4 c1 = texture2DArray(TextureArrayTex, texcoord); + + gl_FragColor = mix(c0, c1, fract(oUv.z)); +} diff --git a/res/dist/media/materials/programs/Example_TextureArrayPS.hlsl4 b/res/dist/media/materials/programs/Example_TextureArrayPS.hlsl4 new file mode 100644 index 00000000000..faaff11b32b --- /dev/null +++ b/res/dist/media/materials/programs/Example_TextureArrayPS.hlsl4 @@ -0,0 +1,33 @@ + +Texture2DArray g_txTextures : TextureArray; + +//-------------------------------------------------------------------------------------- + +SamplerState g_samAniso +{ + Filter = ANISOTROPIC; + AddressU = Wrap; + AddressV = Wrap; +}; + +//-------------------------------------------------------------------------------------- + +struct VS_OUTPUT { + float4 Position : SV_Position; + float3 TextureUV : TEXCOORD0; +}; + +//-------------------------------------------------------------------------------------- + +float4 textureArray_p ( VS_OUTPUT In ) : SV_Target +{ + int numberOfTextures = 20; + float3 texcoord; + texcoord = In.TextureUV; + texcoord.z = floor(texcoord.z); + float4 c0 = g_txTextures.Sample(g_samAniso, texcoord); + texcoord.z += 1; + float4 c1 = g_txTextures.Sample(g_samAniso, texcoord); + + return lerp(c0, c1, frac(In.TextureUV.z)); +} diff --git a/res/dist/media/materials/programs/Example_TextureArrayVS.cg b/res/dist/media/materials/programs/Example_TextureArrayVS.cg new file mode 100644 index 00000000000..be020d71db7 --- /dev/null +++ b/res/dist/media/materials/programs/Example_TextureArrayVS.cg @@ -0,0 +1,14 @@ + + +void textureArray_v(float4 position : POSITION, + float3 uv : TEXCOORD0, + + out float4 oPosition : POSITION, + out float3 oUv : TEXCOORD0, + + uniform float4x4 worldViewProj) +{ + oPosition = mul(worldViewProj, position); + oUv = uv; +} + diff --git a/res/dist/media/materials/programs/Example_TextureArrayVS.glsl b/res/dist/media/materials/programs/Example_TextureArrayVS.glsl new file mode 100644 index 00000000000..864b1e57983 --- /dev/null +++ b/res/dist/media/materials/programs/Example_TextureArrayVS.glsl @@ -0,0 +1,11 @@ +#version 120 + +varying vec3 oUv; + +uniform mat4 worldViewProj; + +void main(void) +{ + gl_Position = worldViewProj * gl_Vertex; + oUv = gl_MultiTexCoord0.xyz; +} diff --git a/res/dist/media/materials/programs/GlassFP.cg b/res/dist/media/materials/programs/GlassFP.cg new file mode 100644 index 00000000000..efcf73c8ef7 --- /dev/null +++ b/res/dist/media/materials/programs/GlassFP.cg @@ -0,0 +1,9 @@ +sampler2D RT : register(s0); +sampler2D NormalMap : register(s1); + +float4 main_ps(float4 pos : POSITION, float2 iTexCoord : TEXCOORD0) : COLOR +{ + float4 normal = 2 * (tex2D(NormalMap, iTexCoord * 2.5) - 0.5); + + return tex2D(RT, iTexCoord + normal.xy * 0.05); +} diff --git a/res/dist/media/materials/programs/GlassFP.glsles b/res/dist/media/materials/programs/GlassFP.glsles new file mode 100644 index 00000000000..ac95084e9a3 --- /dev/null +++ b/res/dist/media/materials/programs/GlassFP.glsles @@ -0,0 +1,15 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform sampler2D RT; +uniform sampler2D NormalMap; +varying vec2 uv; + +void main() +{ + vec4 normal = 2.0 * (texture2D(NormalMap, uv * 2.5) - 0.5); + + gl_FragColor = texture2D(RT, uv + normal.xy * 0.05); +} diff --git a/res/dist/media/materials/programs/Grass.cg b/res/dist/media/materials/programs/Grass.cg new file mode 100644 index 00000000000..5072e891af5 --- /dev/null +++ b/res/dist/media/materials/programs/Grass.cg @@ -0,0 +1,283 @@ +////////////////////////////// MOVING GRASS +// Vertex program to wave some grass about +// Assumes UV texture coords of v==0 indicates the top of the grass +void grass_vp(float4 position : POSITION, + float3 normal : NORMAL, + float2 uv : TEXCOORD0, + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 oColour : COLOR, + + uniform float4x4 worldViewProj, + //uniform float4 camObjPos, + uniform float4 ambient, + uniform float4 objSpaceLight, + uniform float4 lightColour, + uniform float4 offset) +{ + float4 mypos = position; + //offset = float4(0.5, 0, 0, 0); + float4 factor = float4(1,1,1,1) - uv.yyyy; + mypos = mypos + offset * factor; + oPosition = mul(worldViewProj, mypos); + + oUv = uv; + // Color + // get vertex light direction (support directional and point) + float3 light = normalize(objSpaceLight.xyz - (mypos.xyz * objSpaceLight.w)); + // grass is just 2D quads, so if light passes underneath we need to invert the normal + // abs() will have the same effect + float diffuseFactor = abs(dot(normal.xyz, light)); + oColour = ambient + diffuseFactor * lightColour; + +} + +void grass_fp( float4 position : POSITION, + float2 uv : TEXCOORD0, + float4 colour : COLOR, + + out float4 oColour : COLOR, + + uniform sampler2D diffuseMap + ) +{ + float4 texColor = tex2D(diffuseMap, uv.xy); + oColour = float4(texColor.rgb * colour.rgb, texColor.a); + if(oColour.a < 0.58) + discard; +} + + +void grassTex_vp( + float4 position : POSITION, + float4 normal : NORMAL, + float2 uv : TEXCOORD0, + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + //out float4 oNormal : NORMAL, + + uniform float4x4 worldViewProj, + + uniform float4 ambient, + uniform float4 objSpaceLight, + uniform float4 lightColour, + + uniform float4 offset) +{ + // Position + float4 mypos = position; + float4 factor = float4(1,1,1,1) - uv.yyyy; + mypos = mypos + offset * factor; + oPosition = mul(worldViewProj, mypos); + // Texture Coord + oUv.xy = uv.xy; +} + +/// grass_vp ambient +void grassAmbient_vp( + float4 position : POSITION, + float4 normal : NORMAL, + float2 uv : TEXCOORD0, + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float4 oColour : COLOR, + //out float4 oNormal : NORMAL, + + //uniform float4 camObjPos, + uniform float4x4 worldViewProj, + uniform float4 ambient, + uniform float4 offset) +{ + // Position + float4 mypos = position; + float4 factor = float4(1,1,1,1) - uv.yyyy; + mypos = mypos + offset * factor; + oPosition = mul(worldViewProj, mypos); + // Texture Coord + oUv.xy = uv.xy; + /* + // Normal + // Make vec from vertex to camera + float4 EyeVec = camObjPos - mypos; + // Dot the v to eye and the normal to see if they point + // in the same direction or opposite + float aligned = dot(normal, EyeVec); // -1..1 + // If aligned is negative, we need to flip the normal + if (aligned < 0) + normal = -normal; + //oNormal = normal; + */ + // Color + oColour = ambient; +} + + +void grassAmbient_fp( + float4 position : POSITION, + float2 uv : TEXCOORD0, + float4 colour : COLOR, + + out float4 oColour : COLOR, + + uniform sampler2D diffuseMap + ) +{ + float4 texColor = tex2D(diffuseMap, uv.xy); + oColour = float4(colour.rgb, texColor.a); +} + +//////////////////////// GRASS SHADOW CASTER +// Shadow caster vertex program. +void grasscaster_vp(float4 position : POSITION, + float2 uv : TEXCOORD0, + + out float4 oPosition : POSITION, + out float2 oUv : TEXCOORD0, + out float2 oDepth : TEXCOORD1, + + uniform float4x4 worldViewProj, + uniform float4 offset, + uniform float4 texelOffsets) +{ + float4 mypos = position; + float4 factor = float4(1,1,1,1) - uv.yyyy; + mypos = mypos + offset * factor; + oPosition = mul(worldViewProj, mypos); + + // fix pixel / texel alignment + oPosition.xy += texelOffsets.zw * oPosition.w; + + oDepth.x = oPosition.z; + oDepth.y = oPosition.w; + + oUv = uv; + +} + + +void grasscaster_fp( + float4 position : POSITION, + float2 uv : TEXCOORD0, + float2 depth : TEXCOORD1, + + out float4 result : COLOR, + + uniform sampler2D diffuseMap + ) +{ + float alpha = tex2D(diffuseMap, uv).a; + if (alpha > 0.001) + { + result = float4(1.0f, 1.0f, 1.0f, 0.0f); + } + else + { + float finalDepth = depth.x / depth.y; + // just smear across all components + // therefore this one needs high individual channel precision + result = float4(finalDepth.xxx, 1.0f); + } +} + + +//////////////////////// GRASS SHADOW RECEIVER +void grassreceiver_vp( + float4 position : POSITION, + float4 normal : NORMAL, + float2 uv : TEXCOORD0, + + out float4 oPosition : POSITION, + out float4 oShadowUV : TEXCOORD0, + out float3 oUv : TEXCOORD1, + out float4 oColour : COLOR, + //out float4 oNormal : NORMAL, + + uniform float4x4 world, + uniform float4x4 worldViewProj, + uniform float4x4 texViewProj, + + uniform float4 camObjPos, + + uniform float4 objSpaceLight, + uniform float4 lightColour, + + uniform float4 offset) +{ + float4 mypos = position; + float4 factor = float4(1,1,1,1) - uv.yyyy; + mypos = mypos + offset * factor; + oPosition = mul(worldViewProj, mypos); + oUv.xy = uv.xy; + // Transform position to world space + float4 worldPos = mul(world, mypos); + // calculate shadow map coords + oShadowUV = mul(texViewProj, worldPos); + + // Make vec from vertex to camera + float4 EyeVec = camObjPos - mypos; + // Dot the v to eye and the normal to see if they point + // in the same direction or opposite + float alignedEye = dot(normal, EyeVec); // -1..1 + // If aligned is negative, we need to flip the normal + if (alignedEye < 0) + normal = -normal; + //oNormal = normal; + + // get vertex light direction (support directional and point) + float3 lightVec = normalize(objSpaceLight.xyz - (mypos.xyz * objSpaceLight.w)); + // Dot the v to light and the normal to see if they point + // in the same direction or opposite + float alignedLight = dot(normal.xyz, lightVec); // -1..1 + // If aligned is negative, shadowing/lighting is not possible. + oUv.z = (alignedLight < 0)? 0 : 1 ; + + float diffuseFactor = max(alignedLight, 0); + //oColour = diffuseFactor * lightColour; + oColour = lightColour; +} + + +void grassreceiver_fp( + float4 position : POSITION + , float4 shadowUV : TEXCOORD0 + , float3 uv : TEXCOORD1 + , float4 vertexLight : COLOR + + , out float4 oColour : COLOR + + , uniform sampler2D shadowMap : register(s0) + , uniform sampler2D diffuseMap : register(s1) + + //, uniform float inverseShadowmapSize + , uniform float fixedDepthBias + , uniform float gradientClamp + , uniform float gradientScaleBias + ) +{ + if (shadowUV.z > 0) + { + float4 diffuse = tex2D(diffuseMap, uv.xy); + if (diffuse.a > 0.001) + { + oColour = float4(0.0f, 0.0f, 0.0f, 0.0f); + } + else + { + // point on shadowmap (no gradient as cg1.4 compiler is unable to handle that complexity) + shadowUV = shadowUV / shadowUV.w; + float4 shadowDepths = tex2D(shadowMap, shadowUV.xy); + + float gradientFactor = gradientClamp * gradientScaleBias; + float depthAdjust = gradientFactor + fixedDepthBias * shadowDepths.x; + float centerdepth = shadowDepths.x + depthAdjust; + + oColour = (centerdepth > shadowUV.z) ? float4(vertexLight.rgb, diffuse.a) : float4(0, 0, 0, diffuse.a); + } + } + else + { + oColour = float4(0.0f, 0.0f, 0.0f, 0.0f); + } +} diff --git a/res/dist/media/materials/programs/GrassAmbientFp.glsles b/res/dist/media/materials/programs/GrassAmbientFp.glsles new file mode 100644 index 00000000000..204ff50850b --- /dev/null +++ b/res/dist/media/materials/programs/GrassAmbientFp.glsles @@ -0,0 +1,22 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform sampler2D diffuseMap; + +varying vec4 oUv0; +varying vec4 oColour; + +/// grass_vp ambient +void main() +{ + vec4 texColor = texture2D(diffuseMap, oUv0.xy); + // Do manual alpha rejection because it is not built into OpenGL ES 2 + if (texColor.a < 0.588) + { + discard; + } + + gl_FragColor = vec4(oColour.rgb, texColor.a); +} diff --git a/res/dist/media/materials/programs/GrassAmbientVp.glsles b/res/dist/media/materials/programs/GrassAmbientVp.glsles new file mode 100644 index 00000000000..7e0c85db3cc --- /dev/null +++ b/res/dist/media/materials/programs/GrassAmbientVp.glsles @@ -0,0 +1,41 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform mat4 worldViewProj; +uniform vec4 ambient; +uniform vec4 offset; + +attribute vec4 position; +attribute vec4 normal; +attribute vec4 uv0; + +varying vec4 oUv0; +varying vec4 oColour; + +/// grass_vp ambient +void main() +{ + // Position + vec4 mypos = position; + vec4 factor = vec4(1.0, 1.0, 1.0, 1.0) - uv0.yyyy; + mypos = mypos + offset * factor; + gl_Position = worldViewProj * mypos; + // Texture Coord + oUv0.xy = uv0.xy; + /* + // Normal + // Make vec from vertex to camera + vec4 EyeVec = camObjPos - mypos; + // Dot the v to eye and the normal to see if they point + // in the same direction or opposite + float aligned = dot(normal, EyeVec); // -1..1 + // If aligned is negative, we need to flip the normal + if (aligned < 0) + normal = -normal; + //oNormal = normal; + */ + // Color + oColour = ambient; +} diff --git a/res/dist/media/materials/programs/GrassCasterFp.glsles b/res/dist/media/materials/programs/GrassCasterFp.glsles new file mode 100644 index 00000000000..afbd62d9ddd --- /dev/null +++ b/res/dist/media/materials/programs/GrassCasterFp.glsles @@ -0,0 +1,33 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform sampler2D diffuseMap; + +varying vec4 oUv0; +varying vec2 oDepth; + +//////////////////////// GRASS SHADOW CASTER +void main() +{ + float alpha = texture2D(diffuseMap, oUv0.xy).a; + + // Do manual alpha rejection because it is not built into OpenGL ES 2 + if (alpha < 0.588) + { + discard; + } + + if (alpha > 0.001) + { + gl_FragColor = vec4(1.0, 1.0, 1.0, 0.0); + } + else + { + float finalDepth = oDepth.x / oDepth.y; + // just smear across all components + // therefore this one needs high individual channel precision + gl_FragColor = vec4(vec3(finalDepth), 1.0); + } +} diff --git a/res/dist/media/materials/programs/GrassCasterVp.glsles b/res/dist/media/materials/programs/GrassCasterVp.glsles new file mode 100644 index 00000000000..a2f3bb73761 --- /dev/null +++ b/res/dist/media/materials/programs/GrassCasterVp.glsles @@ -0,0 +1,32 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform mat4 worldViewProj; +uniform vec4 offset; +uniform vec4 texelOffsets; + +attribute vec4 position; +attribute vec4 uv0; + +varying vec4 oUv0; +varying vec2 oDepth; + +//////////////////////// GRASS SHADOW CASTER +// Shadow caster vertex program. +void main() +{ + vec4 mypos = position; + vec4 factor = vec4(1.0, 1.0, 1.0, 1.0) - uv0.yyyy; + mypos = mypos + offset * factor; + gl_Position = worldViewProj * mypos; + + // fix pixel / texel alignment + gl_Position.xy += texelOffsets.zw * gl_Position.w; + + oDepth.x = gl_Position.z; + oDepth.y = gl_Position.w; + + oUv0 = uv0; +} diff --git a/res/dist/media/materials/programs/GrassFp.glsles b/res/dist/media/materials/programs/GrassFp.glsles new file mode 100644 index 00000000000..064b0e73bca --- /dev/null +++ b/res/dist/media/materials/programs/GrassFp.glsles @@ -0,0 +1,25 @@ +#version 100 + +precision mediump int; +precision mediump float; + +////////////////////////////// MOVING GRASS +// Vertex program to wave some grass about +// Assumes UV texture coords of v==0 indicates the top of the grass +uniform sampler2D diffuseMap; + +varying vec4 oUv0; +varying vec4 oColour; + +void main() +{ + vec4 texColor = texture2D(diffuseMap, oUv0.xy); + + // Do manual alpha rejection because it is not built into OpenGL ES 2 + if (texColor.a < 0.588) + { + discard; + } + + gl_FragColor = vec4(texColor.rgb * oColour.rgb, texColor.a); +} diff --git a/res/dist/media/materials/programs/GrassReceiverFp.glsles b/res/dist/media/materials/programs/GrassReceiverFp.glsles new file mode 100644 index 00000000000..e1c5595e2a4 --- /dev/null +++ b/res/dist/media/materials/programs/GrassReceiverFp.glsles @@ -0,0 +1,47 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform float fixedDepthBias; +uniform float gradientClamp; +uniform float gradientScaleBias; +uniform sampler2D shadowMap; +uniform sampler2D diffuseMap; +uniform vec4 vertexLight; + +varying vec4 oUv0; +varying vec4 oShadowUV; + +//////////////////////// GRASS SHADOW RECEIVER +void main() +{ + if (oShadowUV.z > 0.0) + { + vec4 diffuse = texture2D(diffuseMap, oUv0.xy); + if (diffuse.a > 0.001) + { + // Do manual alpha rejection because it is not built into OpenGL ES 2 + if (diffuse.a < 0.588) + { + discard; + } + gl_FragColor = vec4(0.0); + } + else + { + vec4 normShadowUV = oShadowUV / oShadowUV.w; + vec4 shadowDepths = texture2D(shadowMap, normShadowUV.xy); + + float gradientFactor = gradientClamp * gradientScaleBias; + float depthAdjust = gradientFactor + fixedDepthBias * shadowDepths.x; + float centerdepth = shadowDepths.x + depthAdjust; + + gl_FragColor = (centerdepth > normShadowUV.z) ? vec4(vertexLight.rgb, diffuse.a) : vec4(0.0, 0.0, 0.0, diffuse.a); + } + } + else + { + gl_FragColor = vec4(0.0); + } +} diff --git a/res/dist/media/materials/programs/GrassReceiverVp.glsles b/res/dist/media/materials/programs/GrassReceiverVp.glsles new file mode 100644 index 00000000000..5b5d14d99db --- /dev/null +++ b/res/dist/media/materials/programs/GrassReceiverVp.glsles @@ -0,0 +1,57 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform mat4 world; +uniform mat4 worldViewProj; +uniform mat4 texViewProj; +uniform vec4 camObjPos; +uniform vec4 objSpaceLight; +uniform vec4 lightColour; +uniform vec4 offset; + +attribute vec4 position; +attribute vec4 normal; +attribute vec4 uv0; + +varying vec4 oShadowUV; +varying vec3 oUv0; +varying vec4 oColour; + +//////////////////////// GRASS SHADOW RECEIVER +void main() +{ + vec4 mypos = position; + vec4 factor = vec4(1.0, 1.0, 1.0, 1.0) - uv0.yyyy; + mypos = mypos + offset * factor; + gl_Position = worldViewProj * mypos; + oUv0.xy = uv0.xy; + // Transform position to world space + vec4 worldPos = world * mypos; + // calculate shadow map coords + oShadowUV = texViewProj * worldPos; + + // Make vec from vertex to camera + vec4 EyeVec = camObjPos - mypos; + // Dot the v to eye and the normal to see if they point + // in the same direction or opposite + float alignedEye = dot(normal, EyeVec); // -1..1 + // If aligned is negative, we need to flip the normal + vec4 myNormal = normal; + if (alignedEye < 0.0) + myNormal = -normal; + //oNormal = normal; + + // get vertex light direction (support directional and point) + vec3 lightVec = normalize(objSpaceLight.xyz - (mypos.xyz * objSpaceLight.w).xyz); + // Dot the v to light and the normal to see if they point + // in the same direction or opposite + float alignedLight = dot(myNormal.xyz, lightVec); // -1..1 + // If aligned is negative, shadowing/lighting is not possible. + oUv0.z = (alignedLight < 0.0) ? 0.0 : 1.0 ; + + float diffuseFactor = max(alignedLight, 0.0); + //oColour = diffuseFactor * lightColour; + oColour = lightColour; +} diff --git a/res/dist/media/materials/programs/GrassTexVp.glsles b/res/dist/media/materials/programs/GrassTexVp.glsles new file mode 100644 index 00000000000..63f453d9d5c --- /dev/null +++ b/res/dist/media/materials/programs/GrassTexVp.glsles @@ -0,0 +1,26 @@ +#version 100 + +precision mediump int; +precision mediump float; + +varying vec4 oUv0; + +attribute vec4 position; +attribute vec4 uv0; + +uniform mat4 worldViewProj; +uniform vec4 ambient; +uniform vec4 objSpaceLight; +uniform vec4 lightColour; +uniform vec4 offset; + +void main() +{ + // Position + vec4 mypos = position; + vec4 factor = vec4(1.0, 1.0, 1.0, 1.0) - uv0.yyyy; + mypos = mypos + offset * factor; + gl_Position = worldViewProj * mypos; + // Texture Coord + oUv0.xy = uv0.xy; +} diff --git a/res/dist/media/materials/programs/GrassVp.glsles b/res/dist/media/materials/programs/GrassVp.glsles new file mode 100644 index 00000000000..60b725632b1 --- /dev/null +++ b/res/dist/media/materials/programs/GrassVp.glsles @@ -0,0 +1,38 @@ +#version 100 + +precision mediump int; +precision mediump float; + +////////////////////////////// MOVING GRASS +// Vertex program to wave some grass about +// Assumes UV texture coords of v==0 indicates the top of the grass +uniform mat4 worldViewProj; +uniform vec4 camObjPos; +uniform vec4 ambient; +uniform vec4 objSpaceLight; +uniform vec4 lightColour; +uniform vec4 offset; + +attribute vec4 position; +attribute vec4 normal; +attribute vec4 uv0; + +varying vec4 oUv0; +varying vec4 oColour; + +void main() +{ + vec4 mypos = position; + vec4 factor = vec4(1.0, 1.0, 1.0, 1.0) - uv0.yyyy; + mypos = mypos + offset * factor; + gl_Position = worldViewProj * mypos; + + oUv0 = uv0; + // Color + // get vertex light direction (support directional and point) + vec3 light = normalize(objSpaceLight.xyz - (mypos.xyz * objSpaceLight.w).xyz); + // grass is just 2D quads, so if light passes underneath we need to invert the normal + // abs() will have the same effect + float diffuseFactor = abs(dot(normal.xyz, light)); + oColour = ambient + diffuseFactor * lightColour; +} diff --git a/res/dist/media/materials/programs/GrayScale.cg b/res/dist/media/materials/programs/GrayScale.cg new file mode 100644 index 00000000000..6a18a47fccb --- /dev/null +++ b/res/dist/media/materials/programs/GrayScale.cg @@ -0,0 +1,20 @@ +sampler2D RT : register(s0); + +float4 GrayScale_ps( float4 pos : POSITION, + float2 iTexCoord : TEXCOORD0) : COLOR +{ + float3 greyscale = dot(tex2D(RT, iTexCoord).rgb, float3(0.3, 0.59, 0.11)); + return float4(greyscale, 1.0); +} + +float4 Embossed_ps( float4 pos : POSITION, + float2 iTexCoord : TEXCOORD0) : COLOR +{ + float4 Color; + Color.a = 1.0f; + Color.rgb = 0.5f; + Color -= tex2D( RT, iTexCoord - 0.001)*2.0f; + Color += tex2D( RT, iTexCoord + 0.001)*2.0f; + Color.rgb = (Color.r+Color.g+Color.b)/3.0f; + return Color; +} diff --git a/res/dist/media/materials/programs/GrayScale.glsles b/res/dist/media/materials/programs/GrayScale.glsles new file mode 100644 index 00000000000..b5c3b85d668 --- /dev/null +++ b/res/dist/media/materials/programs/GrayScale.glsles @@ -0,0 +1,13 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform sampler2D RT; +varying vec2 uv; + +void main() +{ + vec3 greyscale = vec3(dot(texture2D(RT, uv).rgb, vec3(0.3, 0.59, 0.11))); + gl_FragColor = vec4(greyscale, 1.0); +} diff --git a/res/dist/media/materials/programs/HWBasicInstancing.cg b/res/dist/media/materials/programs/HWBasicInstancing.cg new file mode 100644 index 00000000000..d5e4fac895e --- /dev/null +++ b/res/dist/media/materials/programs/HWBasicInstancing.cg @@ -0,0 +1,69 @@ +//--------------------------------------------------------------------------- +//These materials/shaders are part of the NEW InstanceManager implementation +//Written by Matias N. Goldberg ("dark_sylinc") +//--------------------------------------------------------------------------- + +//--------------------------------------------- +//Vertex Shader Input +//--------------------------------------------- +struct VS_INPUT +{ + float4 Position : POSITION; + float3 Normal : NORMAL; + float3 Tangent : TANGENT; + float2 uv0 : TEXCOORD0; + + float4 mat14 : TEXCOORD1; + float4 mat24 : TEXCOORD2; + float4 mat34 : TEXCOORD3; +}; + +#include "InstancingVertexInterpolators.cg" + +//--------------------------------------------- +//Main Vertex Shader +//--------------------------------------------- +VS_OUTPUT main_vs( in VS_INPUT input, + uniform float4x4 viewProjMatrix + +#if defined( DEPTH_SHADOWCASTER ) || defined( DEPTH_SHADOWRECEIVER ) + , uniform float4 depthRange +#endif +#ifdef DEPTH_SHADOWRECEIVER + , uniform float4x4 texViewProjMatrix +#endif + ) +{ + VS_OUTPUT output; + + float3x4 worldMatrix; + worldMatrix[0] = input.mat14; + worldMatrix[1] = input.mat24; + worldMatrix[2] = input.mat34; + + float4 worldPos = float4( mul( worldMatrix, input.Position ).xyz, 1.0f ); + float3 worldNorm= mul( (float3x3)(worldMatrix), input.Normal ); + + //Transform the position + output.Position = mul( viewProjMatrix, worldPos ); + +#ifdef DEPTH_SHADOWCASTER + output.ps.unused = float3( 0 ); + output.ps.depth = (output.Position.z - depthRange.x + SHADOW_BIAS) * depthRange.w; +#else + output.ps.uv0 = input.uv0; + + //Pass Normal and position for Blinn Phong lighting + output.ps.Normal = normalize(worldNorm); + output.ps.vPos = worldPos.xyz; + + #ifdef DEPTH_SHADOWRECEIVER + // Calculate the position of vertex in light space to do shadows + output.ps.lightSpacePos = mul( texViewProjMatrix, worldPos ); + // make linear + output.ps.lightSpacePos.z = (output.ps.lightSpacePos.z - depthRange.x) * depthRange.w; + #endif +#endif + + return output; +} diff --git a/res/dist/media/materials/programs/HWBasicInstancing.vert b/res/dist/media/materials/programs/HWBasicInstancing.vert new file mode 100644 index 00000000000..e427e488331 --- /dev/null +++ b/res/dist/media/materials/programs/HWBasicInstancing.vert @@ -0,0 +1,69 @@ +//--------------------------------------------------------------------------- +//These materials/shaders are part of the NEW InstanceManager implementation +//Written by Matias N. Goldberg ("dark_sylinc") +//--------------------------------------------------------------------------- +#version 120 + +//Vertex input +attribute vec4 vertex; +attribute vec3 normal; +attribute vec4 uv0; +attribute vec4 uv1; +attribute vec4 uv2; +attribute vec4 uv3; +attribute vec3 tangent; + +//Parameters +uniform mat4 viewProjMatrix; + +#if (DEPTH_SHADOWCASTER || DEPTH_SHADOWRECEIVER) +uniform vec4 depthRange; +#endif + +#if DEPTH_SHADOWRECEIVER +uniform mat4 texViewProjMatrix; +#endif + +//Output +#if DEPTH_SHADOWCASTER + varying vec2 depth; +#else + varying vec2 _uv0; + varying vec3 oNormal; + varying vec3 oVPos; + #if DEPTH_SHADOWRECEIVER + varying vec4 oLightSpacePos; + #endif +#endif + +//--------------------------------------------- +//Main Vertex Shader +//--------------------------------------------- +void main(void) +{ + mat4 worldMatrix; + worldMatrix[0] = uv1; + worldMatrix[1] = uv2; + worldMatrix[2] = uv3; + worldMatrix[3] = vec4( 0, 0, 0, 1 ); + + vec4 worldPos = vertex * worldMatrix; + vec3 worldNorm = normal * mat3(worldMatrix); + + //Transform the position + gl_Position = viewProjMatrix * worldPos; + +#if DEPTH_SHADOWCASTER + depth.x = (gl_Position.z - depthRange.x) * depthRange.w; + depth.y = depthRange.w; +#else + _uv0 = uv0.xy; + oNormal = worldNorm; + oVPos = worldPos.xyz; + + #if DEPTH_SHADOWRECEIVER + oLightSpacePos = texViewProjMatrix * worldPos; + oLightSpacePos.z = (oLightSpacePos.z - depthRange.x) * depthRange.w; + #endif +#endif +} diff --git a/res/dist/media/materials/programs/HW_VTFInstancing.cg b/res/dist/media/materials/programs/HW_VTFInstancing.cg new file mode 100644 index 00000000000..e10352fe046 --- /dev/null +++ b/res/dist/media/materials/programs/HW_VTFInstancing.cg @@ -0,0 +1,124 @@ +//--------------------------------------------------------------------------- +//These materials/shaders are part of the NEW InstanceManager implementation +//Written by Matias N. Goldberg ("dark_sylinc") +//--------------------------------------------------------------------------- + +//--------------------------------------------- +//Vertex Shader Input +//--------------------------------------------- +struct VS_INPUT +{ + float4 Position : POSITION; + float3 Normal : NORMAL; + float3 Tangent : TANGENT; +#ifdef BONE_TWO_WEIGHTS + float4 weights : BLENDWEIGHT; +#endif + float2 uv0 : TEXCOORD0; + float4 m03 : TEXCOORD1; //m03.w is always 0 + + float2 mOffset : TEXCOORD2; + +#ifdef BONE_MATRIX_LUT + float4 worldMatrix0 : TEXCOORD3; + float4 worldMatrix1 : TEXCOORD4; + float4 worldMatrix2 : TEXCOORD5; +#endif +}; + +#include "InstancingVertexInterpolators.cg" +#ifdef ST_DUAL_QUATERNION +#include "DualQuaternion_Common.cg" +#endif + +//--------------------------------------------- +//Main Vertex Shader +//--------------------------------------------- +VS_OUTPUT main_vs( in VS_INPUT input, + uniform float4x4 viewProjMatrix, + +#ifdef DEPTH_SHADOWCASTER + uniform sampler2D matrixTexture : register(s0) +#else + uniform sampler2D matrixTexture : register(s2) +#endif + +#if defined( DEPTH_SHADOWCASTER ) || defined( DEPTH_SHADOWRECEIVER ) + , uniform float4 depthRange +#endif +#ifdef DEPTH_SHADOWRECEIVER + , uniform float4x4 texViewProjMatrix +#endif + ) +{ + VS_OUTPUT output; + float4 worldPos; + float3 worldNorm; + + +#ifdef ST_DUAL_QUATERNION + float2x4 blendDQ; + blendDQ[0] = tex2D( matrixTexture, float2(input.m03.x, 0.0) + input.mOffset ); + blendDQ[1] = tex2D( matrixTexture, float2(input.m03.y, 0.0) + input.mOffset ); +#ifdef BONE_TWO_WEIGHTS + float2x4 blendDQ2; + //Use the empty parts of m03, z and w, for the second dual quaternion + blendDQ2[0] = tex2D( matrixTexture, float2(input.m03.z, 0.0) + input.mOffset ); + blendDQ2[1] = tex2D( matrixTexture, float2(input.m03.w, 0.0) + input.mOffset ); + + //Accurate antipodality handling. For speed increase, remove the following line + if (dot(blendDQ[0], blendDQ2[0]) < 0.0) blendDQ2 *= -1.0; + + //Blend the dual quaternions based on the weights + blendDQ *= input.weights.x; + blendDQ += input.weights.y*blendDQ2; + //Normalize the resultant dual quaternion + blendDQ /= length(blendDQ[0]); +#endif + worldPos = float4(calculateBlendPosition(input.Position.xyz, blendDQ), 1.0); + worldNorm = calculateBlendNormal(input.Normal, blendDQ); +#else + float3x4 worldMatrix; + worldMatrix[0] = tex2D( matrixTexture, input.m03.xw + input.mOffset ); + worldMatrix[1] = tex2D( matrixTexture, input.m03.yw + input.mOffset ); + worldMatrix[2] = tex2D( matrixTexture, input.m03.zw + input.mOffset ); + + worldPos = float4( mul( worldMatrix, input.Position ).xyz, 1.0f ); + worldNorm= mul( (float3x3)(worldMatrix), input.Normal ); +#endif + +#ifdef BONE_MATRIX_LUT + float3x4 worldCompMatrix; + worldCompMatrix[0] = input.worldMatrix0; + worldCompMatrix[1] = input.worldMatrix1; + worldCompMatrix[2] = input.worldMatrix2; + + worldPos = float4( mul( worldCompMatrix, worldPos ).xyz, 1.0f ); + worldNorm = mul( (float3x3)(worldCompMatrix), worldNorm ); + +#endif + + + //Transform the position + output.Position = mul( viewProjMatrix, worldPos ); + +#ifdef DEPTH_SHADOWCASTER + output.ps.unused = float3( 0 ); + output.ps.depth = (output.Position.z - depthRange.x + SHADOW_BIAS) * depthRange.w; +#else + output.ps.uv0 = input.uv0; + + //Pass Normal and position for Blinn Phong lighting + output.ps.Normal = normalize(worldNorm); + output.ps.vPos = worldPos.xyz; + + #ifdef DEPTH_SHADOWRECEIVER + // Calculate the position of vertex in light space to do shadows + output.ps.lightSpacePos = mul( texViewProjMatrix, worldPos ); + // make linear + output.ps.lightSpacePos.z = (output.ps.lightSpacePos.z - depthRange.x) * depthRange.w; + #endif +#endif + + return output; +} diff --git a/res/dist/media/materials/programs/HW_VTFInstancing.vert b/res/dist/media/materials/programs/HW_VTFInstancing.vert new file mode 100644 index 00000000000..d53bcd05577 --- /dev/null +++ b/res/dist/media/materials/programs/HW_VTFInstancing.vert @@ -0,0 +1,131 @@ +//--------------------------------------------------------------------------- +//These materials/shaders are part of the NEW InstanceManager implementation +//Written by Matias N. Goldberg ("dark_sylinc") +//--------------------------------------------------------------------------- +#version 120 + +//Vertex input +attribute vec4 vertex; +attribute vec3 normal; + +#ifdef BONE_TWO_WEIGHTS + attribute vec4 blendWeights; +#endif + +attribute vec4 uv0; +attribute vec4 uv1; +attribute vec4 uv2; + +#if BONE_MATRIX_LUT + attribute vec4 uv3; + attribute vec4 uv4; + attribute vec4 uv5; +#endif + +attribute vec3 tangent; + +//Parameters +uniform mat4 viewProjMatrix; +uniform sampler2D matrixTexture; + +#if (DEPTH_SHADOWCASTER || DEPTH_SHADOWRECEIVER) +uniform vec4 depthRange; +#endif + +#if DEPTH_SHADOWRECEIVER +uniform mat4 texViewProjMatrix; +#endif + +//Output +#if DEPTH_SHADOWCASTER + varying vec2 depth; +#else + varying vec2 _uv0; + varying vec3 oNormal; + varying vec3 oVPos; + #if DEPTH_SHADOWRECEIVER + varying vec4 oLightSpacePos; + #endif +#endif + +vec3 calculateBlendPosition(vec3 position, mat2x4 blendDQ) +{ + vec3 blendPosition = position + 2.0*cross(blendDQ[0].yzw, cross(blendDQ[0].yzw, position) + blendDQ[0].x*position); + vec3 trans = 2.0*(blendDQ[0].x*blendDQ[1].yzw - blendDQ[1].x*blendDQ[0].yzw + cross(blendDQ[0].yzw, blendDQ[1].yzw)); + blendPosition += trans; + + return blendPosition; +} + +vec3 calculateBlendNormal(vec3 normal, mat2x4 blendDQ) +{ + return normal + 2.0*cross(blendDQ[0].yzw, cross(blendDQ[0].yzw, normal) + blendDQ[0].x*normal); +} + +//--------------------------------------------- +//Main Vertex Shader +//--------------------------------------------- +void main(void) +{ + vec4 worldPos; + vec3 worldNorm; + +#ifdef ST_DUAL_QUATERNION + mat2x4 blendDQ; + blendDQ[0] = texture2D( matrixTexture, vec2(uv1.x, 0.0) + uv2.xy ); + blendDQ[1] = texture2D( matrixTexture, vec2(uv1.y, 0.0) + uv2.xy ); +#ifdef BONE_TWO_WEIGHTS + mat2x4 blendDQ2; + blendDQ2[0] = texture2D( matrixTexture, vec2(uv1.z, 0.0) + uv2.xy ); + blendDQ2[1] = texture2D( matrixTexture, vec2(uv1.w, 0.0) + uv2.xy ); + + //Accurate antipodality handling. For speed increase, remove the following line + if (dot(blendDQ[0], blendDQ2[0]) < 0.0) blendDQ2 *= -1.0; + + //Blend the dual quaternions based on the weights + blendDQ *= blendWeights.x; + blendDQ += blendWeights.y*blendDQ2; + //Normalize the resultant dual quaternion + blendDQ /= length(blendDQ[0]); +#endif + worldPos = vec4(calculateBlendPosition(vertex.xyz, blendDQ), 1.0); + worldNorm = calculateBlendNormal(normal, blendDQ); +#else + mat4 worldMatrix; + worldMatrix[0] = texture2D( matrixTexture, uv1.xw + uv2.xy ); + worldMatrix[1] = texture2D( matrixTexture, uv1.yw + uv2.xy ); + worldMatrix[2] = texture2D( matrixTexture, uv1.zw + uv2.xy ); + worldMatrix[3] = vec4( 0, 0, 0, 1 ); + + worldPos = vertex * worldMatrix; + worldNorm = normal * mat3(worldMatrix); +#endif + +#if BONE_MATRIX_LUT + mat4 worldCompMatrix; + worldCompMatrix[0] = uv3; + worldCompMatrix[1] = uv4; + worldCompMatrix[2] = uv5; + worldCompMatrix[3] = vec4( 0, 0, 0, 1 ); + + worldPos = worldPos * worldCompMatrix; + worldNorm = worldNorm * mat3(worldCompMatrix); +#endif + + //Transform the position + gl_Position = viewProjMatrix * worldPos; + +#if DEPTH_SHADOWCASTER + depth.x = (gl_Position.z - depthRange.x) * depthRange.w; + depth.y = depthRange.w; +#else + _uv0 = uv0.xy; + oNormal = worldNorm; + oVPos = worldPos.xyz; + + #if DEPTH_SHADOWRECEIVER + oLightSpacePos = texViewProjMatrix * worldPos; + oLightSpacePos.z = (oLightSpacePos.z - depthRange.x) * depthRange.w; + #endif +#endif +} diff --git a/res/dist/media/materials/programs/HalftoneFP.cg b/res/dist/media/materials/programs/HalftoneFP.cg new file mode 100644 index 00000000000..19bb81e9e63 --- /dev/null +++ b/res/dist/media/materials/programs/HalftoneFP.cg @@ -0,0 +1,19 @@ +sampler2D RT : register(s0); +sampler3D pattern : register(s1); + +float4 Halftone_ps( float4 pos : POSITION, + float2 TexCoord : TEXCOORD0, + uniform float2 numTiles, + uniform float2 iNumTiles, + uniform float2 iNumTiles2, + uniform float4 lum) : COLOR +{ + float3 local; + local.xy = fmod(TexCoord, iNumTiles); + float2 middle = TexCoord - local.xy; + local.xy = local.xy * numTiles; + middle += iNumTiles2; + local.z = dot(tex2D(RT, middle ) , lum); + float4 c = tex3D(pattern,local).a; + return c; +} \ No newline at end of file diff --git a/res/dist/media/materials/programs/HalftoneFP.glsles b/res/dist/media/materials/programs/HalftoneFP.glsles new file mode 100644 index 00000000000..460f7f4e91e --- /dev/null +++ b/res/dist/media/materials/programs/HalftoneFP.glsles @@ -0,0 +1,24 @@ +#version 100 + +precision mediump int; +precision mediump float; + +sampler2D RT : register(s0); +sampler3D pattern : register(s1); + +float4 Halftone_ps( float4 pos : POSITION, + float2 TexCoord : TEXCOORD0, + uniform float2 numTiles, + uniform float2 iNumTiles, + uniform float2 iNumTiles2, + uniform float4 lum) : COLOR +{ + float3 local; + local.xy = fmod(TexCoord, iNumTiles); + float2 middle = TexCoord - local.xy; + local.xy = local.xy * numTiles; + middle += iNumTiles2; + local.z = dot(tex2D(RT, middle ) , lum); + float4 c = tex3D(pattern,local).a; + return c; +} \ No newline at end of file diff --git a/res/dist/media/materials/programs/HeatBlurFp.glsles b/res/dist/media/materials/programs/HeatBlurFp.glsles new file mode 100644 index 00000000000..831b633fec3 --- /dev/null +++ b/res/dist/media/materials/programs/HeatBlurFp.glsles @@ -0,0 +1,63 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform sampler2D Input; +uniform vec4 blurAmount; + +varying vec2 uv; + +void main() +{ + int i; + vec4 tmpOutColor; + float diffuseGlowFactor; + vec2 offsets[4]; +/* + // hazy blur + -1.8, -1.8, + -1.8, 1.8, + 1.8, -1.8, + 1.8, 1.8 +*/ +/* + // less-hazy blur + -1.0, 2.0, + -1.0, -1.0, + 1.0, -1.0, + 1.0, 1.0 +*/ +/* + -0.326212, -0.405805, + -0.840144, -0.073580, + -0.695914, 0.457137, + -0.203345, 0.620716 +*/ + + offsets[0] = vec2(-0.3, 0.4); + offsets[1] = vec2(-0.3, -0.4); + offsets[2] = vec2(0.3, -0.4); + offsets[3] = vec2(0.3, 0.4); + + tmpOutColor = texture2D( Input, uv ); // UV coords are in image space + + // calculate glow amount + diffuseGlowFactor = 0.0113 * (2.0 - max( tmpOutColor.r, tmpOutColor.g )); + + // basic blur filter + for (i = 0; i < 4; i++) { + tmpOutColor += texture2D( Input, uv + blurAmount.x * diffuseGlowFactor * offsets[i] ); + } + + tmpOutColor *= 0.25; + + // TIPS (old-skool strikes again!) + // Pay attention here! If you use the "out float4 outColor" directly + // in your steps while creating the output color (like you remove + // the "tmpOutColor" var and just use the "outColor" directly) + // your pixel-color output IS CHANGING EACH TIME YOU DO AN ASSIGNMENT TOO! + // A temporary variable, instead, acts like a per-pixel double buffer, and + // best of all, lead to better performance. + gl_FragColor = tmpOutColor; +} \ No newline at end of file diff --git a/res/dist/media/materials/programs/HeatBlurVp.glsles b/res/dist/media/materials/programs/HeatBlurVp.glsles new file mode 100644 index 00000000000..ae194a172ad --- /dev/null +++ b/res/dist/media/materials/programs/HeatBlurVp.glsles @@ -0,0 +1,16 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform vec4 position; +uniform float flipping; +varying vec2 uv; + +void main() +{ + vec4 inPos = position; + gl_Position = vec4(inPos.x, flipping * inPos.y, 0.0, 1.0); + inPos.xy = sign(inPos.xy); + uv = (vec2(inPos.x, -inPos.y) + 1.0)/2.0; +} diff --git a/res/dist/media/materials/programs/HeatCasterFp.glsles b/res/dist/media/materials/programs/HeatCasterFp.glsles new file mode 100644 index 00000000000..c1188974809 --- /dev/null +++ b/res/dist/media/materials/programs/HeatCasterFp.glsles @@ -0,0 +1,11 @@ +#version 100 + +precision mediump int; +precision mediump float; + +varying vec2 NDotV; + +void main() +{ + gl_FragColor = vec4(NDotV.x); +} diff --git a/res/dist/media/materials/programs/HeatCasterVp.glsles b/res/dist/media/materials/programs/HeatCasterVp.glsles new file mode 100644 index 00000000000..571759710db --- /dev/null +++ b/res/dist/media/materials/programs/HeatCasterVp.glsles @@ -0,0 +1,18 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform mat4 worldViewProj; +uniform vec3 eyePosition; +attribute vec4 position; +attribute vec4 normal; +varying vec2 NDotV; + +void main() +{ + vec4 eyeDir = vec4(eyePosition - position.xyz, 0.0); + eyeDir = normalize(eyeDir); + gl_Position = worldViewProj * position; + NDotV = vec2(clamp( dot( normal, eyeDir ), 0.0, 1.0 )); +} diff --git a/res/dist/media/materials/programs/HeatVision.cg b/res/dist/media/materials/programs/HeatVision.cg new file mode 100644 index 00000000000..86d5b8124a9 --- /dev/null +++ b/res/dist/media/materials/programs/HeatVision.cg @@ -0,0 +1,230 @@ +////////////////////////////////////////////// +// CASTER PASS // +// HEAT // +////////////////////////////////////////////// + +// vs_1_1 +void HeatCaster_vp( + // in + float4 vPos: POSITION, + float4 vNormal: NORMAL, + + // out + out float4 oPos: POSITION, + out float2 oNDotV: TEXCOORD0, + + // parameters + uniform float4x4 worldViewProj, + uniform float3 eyePosition // object space + ) +{ + float4 eyeDir = float4(eyePosition - vPos.xyz, 0); + eyeDir = normalize(eyeDir); + oPos = mul( worldViewProj, vPos ); + oNDotV = clamp( dot( vNormal, eyeDir ), 0, 1 ); +} + +// ps_2_0 +float4 HeatCaster_fp( + // input from vp + float2 iNDotV: TEXCOORD0 + ) : COLOR0 +{ + return iNDotV.x; +} + + +////////////////////////////////////////////// +// CASTER PASS // +// COLD // +////////////////////////////////////////////// + +// vs_1_1 +void ColdCaster_vp( + // in + float4 vPos: POSITION, + float4 vNormal: NORMAL, + + // out + out float4 oPos: POSITION, + out float2 oNDotV: TEXCOORD0, + + // parameters + uniform float4x4 worldViewProj, + uniform float3 eyePosition // object space + ) +{ + float4 eyeDir = float4(eyePosition - vPos.xyz, 0); + eyeDir = normalize(eyeDir); + oPos = mul( worldViewProj, vPos ); + oNDotV = clamp( dot( vNormal, eyeDir ), 0, 1 ); +} + +// ps_2_0 +float4 ColdCaster_fp( + // input from vp + float2 iNDotV: TEXCOORD0 + ) : COLOR0 +{ + return iNDotV.x / 2; +} + + +////////////////////////////////////////////// +// PASS 1 - Light to heat conversion // +////////////////////////////////////////////// + +// vs_1_1 +void LightToHeat_vp( + // in + float4 inPos: POSITION, + + uniform float flipping, + + // out + out float4 Pos: POSITION, + out float2 uv0: TEXCOORD0 + ) +{ + Pos = float4(inPos.x, flipping * inPos.y, 0.0f, 1.0f); + inPos.xy = sign(inPos.xy); + uv0 = (float2(inPos.x, -inPos.y) + 1.0f)/2.0f; +} + + +// ps_2_0 +void LightToHeat_fp( + // input from vp + float4 inDiffuse: COLOR0, + float2 inUV0: TEXCOORD0, + + // out + out float4 outColor: COLOR0, + + // params + uniform float4 random_fractions, + uniform float4 heatBiasScale, + uniform float4 depth_modulator, + + uniform sampler2D Input, // output of HeatVisionCaster_fp (NdotV) + uniform sampler2D NoiseMap, + uniform sampler2D HeatLookup + ) +{ + float depth, heat, interference; + + // Output constant color: + depth = tex2D( Input, inUV0 ); + depth *= (depth * depth_modulator); + + heat = (depth * heatBiasScale.y); + +// if (depth > 0) + { + interference = -0.5 + tex2D( NoiseMap, inUV0 + float2( random_fractions.x, random_fractions.y ) ); + interference *= interference; + interference *= 1 - heat; + heat += interference;//+ heatBiasScale.x; + } + +/* + heatBias isn't used for now + if (heat > 0) + heat += heatBiasScale.x; +*/ + + // Clamp UVs + heat = max( 0.005, min( 0.995, heat ) ); + outColor = tex2D( HeatLookup, float2( heat, 0.f ) ); +} + + +////////////////////////////////////////////// +// PASS 2 - add simple blur (final pass) // +////////////////////////////////////////////// + +// vs_1_1 +void Blur_vp( + // in + float4 inPos: POSITION, + + uniform float flipping, + + // out + out float4 Pos: POSITION, + out float2 uv0: TEXCOORD0 + ) +{ + Pos = float4(inPos.x, flipping * inPos.y, 0.0f, 1.0f); + inPos.xy = sign(inPos.xy); + uv0 = (float2(inPos.x, -inPos.y) + 1.0f)/2.0f; +} + +// ps_2_0 +void Blur_fp( + // input from vp + float4 inDiffuse: COLOR0, + float2 inUV0: TEXCOORD0, + + // out + out float4 outColor: COLOR0, + + // parameters + uniform sampler2D Input, // output of HeatVision_fp1 (HeatRenderTexture) + uniform float4 blurAmount + ) +{ + int i; + float4 tmpOutColor; + float diffuseGlowFactor; + const float2 offsets[4] = + { +/* + // hazy blur + -1.8, -1.8, + -1.8, 1.8, + 1.8, -1.8, + 1.8, 1.8 +*/ +/* + // less-hazy blur + -1.0, 2.0, + -1.0, -1.0, + 1.0, -1.0, + 1.0, 1.0 +*/ +/* + -0.326212, -0.405805, + -0.840144, -0.073580, + -0.695914, 0.457137, + -0.203345, 0.620716 +*/ + + -0.3, 0.4, + -0.3, -0.4, + 0.3, -0.4, + 0.3, 0.4 + + }; + + tmpOutColor = tex2D( Input, inUV0 ); // UV coords are in image space + + // calculate glow amount + diffuseGlowFactor = 0.0113f * (2.0 - max( tmpOutColor.r, tmpOutColor.g )); + + // basic blur filter + for (i = 0; i < 4; i++) { + tmpOutColor += tex2D( Input, inUV0 + blurAmount.x * diffuseGlowFactor * offsets[i] ); + } + + tmpOutColor *= 0.25; + + // TIPS (old-skool strikes again!) + // Pay attention here! If you use the "out float4 outColor" directly + // in your steps while creating the output color (like you remove + // the "tmpOutColor" var and just use the "outColor" directly) + // your pixel-color output IS CHANGING EACH TIME YOU DO AN ASSIGNMENT TOO! + // A temporary variable, instead, acts like a per-pixel double buffer, and + // best of all, lead to better performance. + outColor = tmpOutColor; +} \ No newline at end of file diff --git a/res/dist/media/materials/programs/Instancing.frag b/res/dist/media/materials/programs/Instancing.frag new file mode 100644 index 00000000000..cf064dacffa --- /dev/null +++ b/res/dist/media/materials/programs/Instancing.frag @@ -0,0 +1,66 @@ +//--------------------------------------------------------------------------- +//These materials/shaders are part of the NEW InstanceManager implementation +//Written by Matias N. Goldberg ("dark_sylinc") +//--------------------------------------------------------------------------- + +uniform sampler2D diffuseMap; + +uniform vec4 lightPosition; +uniform vec3 cameraPosition; +uniform vec3 lightAmbient; +uniform vec3 lightDiffuse; +uniform vec3 lightSpecular; +uniform vec4 lightAttenuation; +uniform float lightGloss; + +#if DEPTH_SHADOWRECEIVER +uniform float invShadowMapSize; +uniform sampler2DShadow shadowMap; + +//declare external function +//vec4 calcDepthShadow(in vec4 inColour, in float lum); +float calcDepthShadow(sampler2DShadow shadowMap, vec4 uv, float invShadowMapSize); +#endif + +varying vec2 _uv0; +varying vec3 oNormal; +varying vec3 oVPos; +#if DEPTH_SHADOWRECEIVER + varying vec4 oLightSpacePos; +#endif + +//--------------------------------------------- +//Main Pixel Shader +//--------------------------------------------- +void main(void) +{ + vec4 color = texture2D( diffuseMap, _uv0 ); + + float fShadow = 1.0; +#if DEPTH_SHADOWRECEIVER + fShadow = calcDepthShadow( shadowMap, oLightSpacePos, invShadowMapSize ); +#endif + + vec4 baseColour = texture2D( diffuseMap, _uv0 ); + + //Blinn-Phong lighting + vec3 normal = normalize( oNormal ); + vec3 lightDir = lightPosition.xyz - oVPos * lightPosition.w; + vec3 eyeDir = normalize( cameraPosition - oVPos ); + + float fLength = length( lightDir ); + lightDir = normalize( lightDir ); + + float NdotL = max( 0.0, dot( normal, lightDir ) ); + vec3 halfVector = normalize(lightDir + eyeDir); + float HdotN = max( 0.0, dot( halfVector, normal ) ); + + vec3 ambient = lightAmbient * baseColour.xyz; + vec3 diffuse = lightDiffuse * NdotL * baseColour.xyz; + vec3 specular = lightSpecular * pow( HdotN, lightGloss ); + + vec3 directLighting = (diffuse + specular) * fShadow; + + gl_FragColor = vec4( directLighting + ambient, baseColour.a ); + //gl_FragColor = baseColour; +} diff --git a/res/dist/media/materials/programs/Instancing.program b/res/dist/media/materials/programs/Instancing.program new file mode 100644 index 00000000000..5adbbb61246 --- /dev/null +++ b/res/dist/media/materials/programs/Instancing.program @@ -0,0 +1,84 @@ +//--------------------------------------------------------------------------- +//These materials/shaders are part of the NEW InstanceManager implementation +//Written by Matias N. Goldberg ("dark_sylinc") +//--------------------------------------------------------------------------- + +//-------------------------------------------------------------- +// GLSL Programs +//-------------------------------------------------------------- +fragment_program Ogre/Shadow/Utils glsl +{ + source shadows.glsl +} + +fragment_program Ogre/Instancing_glsl_ps glsl +{ + source Instancing.frag + attach Ogre/Shadow/Utils + + preprocessor_defines DEPTH_SHADOWRECEIVER=1 + + default_params + { + param_named diffuseMap int 0 + param_named shadowMap int 1 + } +} + +fragment_program Ogre/Instancing/shadow_caster_glsl_ps glsl +{ + source DepthShadowmapCasterFp.glsl + + preprocessor_defines LINEAR_RANGE=1 +} + +//-------------------------------------------------------------- +// CG Programs +//-------------------------------------------------------------- +fragment_program Ogre/Instancing_cg_ps cg +{ + source Instancing_ps.cg + entry_point main_ps + profiles ps_3_0 ps_2_x fp40 + + compile_arguments -DDEPTH_SHADOWRECEIVER +} + +fragment_program Ogre/Instancing/shadow_caster_cg_ps cg +{ + source depthshadowobject.cg + profiles ps_3_0 ps_2_x fp40 + entry_point main_fp + compile_arguments -DSHADOWCASTER=1 -DDEPTH_SHADOWCASTER=1 -DDEPTH_SHADOWRECEIVER=0 + + default_params + { + } +} + +//-------------------------------------------------------------- +// Unified CG/GLSL Programs +//-------------------------------------------------------------- +fragment_program Ogre/Instancing_ps unified +{ + delegate Ogre/Instancing_glsl_ps + delegate Ogre/Instancing_cg_ps + + default_params + { + param_named_auto lightPosition light_position 0 + param_named_auto cameraPosition camera_position 0 + param_named_auto lightAmbient ambient_light_colour + param_named_auto lightDiffuse light_diffuse_colour 0 + param_named_auto lightSpecular light_specular_colour 0 + param_named_auto lightGloss surface_shininess + + param_named_auto invShadowMapSize inverse_texture_size 1 + } +} + +fragment_program Ogre/Instancing/shadow_caster_ps unified +{ + delegate Ogre/Instancing/shadow_caster_glsl_ps + delegate Ogre/Instancing/shadow_caster_cg_ps +} diff --git a/res/dist/media/materials/programs/InstancingMisc.cg b/res/dist/media/materials/programs/InstancingMisc.cg new file mode 100644 index 00000000000..f586aa72940 --- /dev/null +++ b/res/dist/media/materials/programs/InstancingMisc.cg @@ -0,0 +1,63 @@ +//--------------------------------------------------------------------------- +//These materials/shaders are part of the NEW InstanceManager implementation +//Written by Matias N. Goldberg ("dark_sylinc") +//--------------------------------------------------------------------------- + +//This shader is not instancing related, but is used in the Instancing tests for lighting +//consistency (i.e. the ground) + +//--------------------------------------------- +//Vertex Shader Input +//--------------------------------------------- +struct VS_INPUT +{ + float4 Position : POSITION; + float3 Normal : NORMAL; + float2 uv0 : TEXCOORD0; +}; + +#include "InstancingVertexInterpolators.cg" + +//--------------------------------------------- +//Main Vertex Shader +//--------------------------------------------- +VS_OUTPUT main_vs( in VS_INPUT input, + uniform float4x4 viewProjMatrix, + uniform float4x4 worldMatrix + +#if defined( DEPTH_SHADOWCASTER ) || defined( DEPTH_SHADOWRECEIVER ) + , uniform float4 depthRange +#endif +#ifdef DEPTH_SHADOWRECEIVER + , uniform float4x4 texViewProjMatrix +#endif + ) +{ + VS_OUTPUT output; + + float4 worldPos = mul( worldMatrix, input.Position ); + float3 worldNorm = mul( (float3x3)(worldMatrix), input.Normal ); + + //Transform the position + output.Position = mul( viewProjMatrix, worldPos ); + +#ifdef DEPTH_SHADOWCASTER + output.ps.unused = float3( 0 ); + output.ps.depth = (output.Position.z - depthRange.x + SHADOW_BIAS) * depthRange.w; +#else + output.ps.uv0 = input.uv0; + + //Pass Normal and position for Blinn Phong lighting + output.ps.Normal = worldNorm; + output.ps.vPos = worldPos.xyz; + + #ifdef DEPTH_SHADOWRECEIVER + // Calculate the position of vertex in light space to do shadows + output.ps.lightSpacePos = mul( texViewProjMatrix, worldPos ); + // make linear + output.ps.lightSpacePos.z = (output.ps.lightSpacePos.z - depthRange.x) * depthRange.w; + #endif +#endif + + return output; +} diff --git a/res/dist/media/materials/programs/InstancingMisc.vert b/res/dist/media/materials/programs/InstancingMisc.vert new file mode 100644 index 00000000000..f79ee37f3cc --- /dev/null +++ b/res/dist/media/materials/programs/InstancingMisc.vert @@ -0,0 +1,62 @@ +//--------------------------------------------------------------------------- +//These materials/shaders are part of the NEW InstanceManager implementation +//Written by Matias N. Goldberg ("dark_sylinc") +//--------------------------------------------------------------------------- +#version 120 + +//Vertex input +attribute vec4 vertex; +attribute vec3 normal; +attribute vec3 tangent; +attribute vec4 uv0; +attribute vec4 blendIndices; +attribute vec4 blendWeights; + +//Parameters +uniform mat4 viewProjMatrix; +uniform mat4 worldMatrix; + +#if (DEPTH_SHADOWCASTER || DEPTH_SHADOWRECEIVER) +uniform vec4 depthRange; +#endif + +#if DEPTH_SHADOWRECEIVER +uniform mat4 texViewProjMatrix; +#endif + +//Output +#if DEPTH_SHADOWCASTER + varying vec2 depth; +#else + varying vec2 _uv0; + varying vec3 oNormal; + varying vec3 oVPos; + #if DEPTH_SHADOWRECEIVER + varying vec4 oLightSpacePos; + #endif +#endif +//--------------------------------------------- +//Main Vertex Shader +//--------------------------------------------- +void main(void) +{ + vec4 worldPos = vertex * worldMatrix; + vec3 worldNorm = normal * mat3(worldMatrix); + + //Transform the position + gl_Position = viewProjMatrix * worldPos; + +#if DEPTH_SHADOWCASTER + depth.x = (gl_Position.z - depthRange.x) * depthRange.w; + depth.y = depthRange.w; +#else + _uv0 = uv0.xy; + oNormal = worldNorm; + oVPos = worldPos.xyz; + + #if DEPTH_SHADOWRECEIVER + oLightSpacePos = texViewProjMatrix * worldPos; + oLightSpacePos.z = (oLightSpacePos.z - depthRange.x) * depthRange.w; + #endif +#endif +} diff --git a/res/dist/media/materials/programs/InstancingVertexInterpolators.cg b/res/dist/media/materials/programs/InstancingVertexInterpolators.cg new file mode 100644 index 00000000000..45cfd6c9091 --- /dev/null +++ b/res/dist/media/materials/programs/InstancingVertexInterpolators.cg @@ -0,0 +1,34 @@ +//--------------------------------------------------------------------------- +//These materials/shaders are part of the NEW InstanceManager implementation +//Written by Matias N. Goldberg ("dark_sylinc") +//--------------------------------------------------------------------------- + +//--------------------------------------------- +//Pixel Shader Input +//--------------------------------------------- +struct PS_INPUT +{ +#ifdef DEPTH_SHADOWCASTER + float3 unused : TEXCOORD0; + float depth : TEXCOORD1; +#else + float2 uv0 : TEXCOORD0; + float3 Normal : TEXCOORD1; + float3 vPos : TEXCOORD2; + + #ifdef DEPTH_SHADOWRECEIVER + float4 lightSpacePos : TEXCOORD3; + #endif +#endif +}; + +#define SHADOW_BIAS 0 + +//--------------------------------------------- +//Vertex Shader Output +//--------------------------------------------- +struct VS_OUTPUT +{ + float4 Position : POSITION; + PS_INPUT ps; +}; diff --git a/res/dist/media/materials/programs/Instancing_ps.cg b/res/dist/media/materials/programs/Instancing_ps.cg new file mode 100644 index 00000000000..00d80ff9642 --- /dev/null +++ b/res/dist/media/materials/programs/Instancing_ps.cg @@ -0,0 +1,57 @@ +//--------------------------------------------------------------------------- +//These materials/shaders are part of the NEW InstanceManager implementation +//Written by Matias N. Goldberg ("dark_sylinc") +//--------------------------------------------------------------------------- + +#include "InstancingVertexInterpolators.cg" + +#include "shadows.cg" + +//--------------------------------------------- +//Main Pixel Shader +//--------------------------------------------- +half4 main_ps( PS_INPUT input , + uniform float4 lightPosition, + uniform float3 cameraPosition, + uniform half3 lightAmbient, + uniform half3 lightDiffuse, + uniform half3 lightSpecular, + uniform half4 lightAttenuation, + uniform half lightGloss, + + //Textures + uniform sampler2D diffuseMap : register(s0) + +#ifdef DEPTH_SHADOWRECEIVER + , uniform float invShadowMapSize, + uniform sampler2D shadowMap : register(s1) +#endif + ) : COLOR0 +{ + float fShadow = 1.0f; +#ifdef DEPTH_SHADOWRECEIVER + fShadow = calcDepthShadow( shadowMap, input.lightSpacePos, invShadowMapSize ); +#endif + + const half4 baseColour = tex2D( diffuseMap, input.uv0 ); + + //Blinn-Phong lighting + const half3 normal = normalize( input.Normal ); + half3 lightDir = lightPosition.xyz - input.vPos * lightPosition.w; + half3 eyeDir = normalize( cameraPosition - input.vPos ); + + const half fLength = length( lightDir ); + lightDir = normalize( lightDir ); + + const half NdotL = max( 0.0f, dot( normal, lightDir ) ); + half3 halfVector = normalize(lightDir + eyeDir); + const half HdotN = max( 0.0f, dot( halfVector, normal ) ); + + const half3 ambient = lightAmbient * baseColour.xyz; + const half3 diffuse = lightDiffuse * NdotL * baseColour.xyz; + const half3 specular = lightSpecular * pow( HdotN, lightGloss ); + + const half3 directLighting = (diffuse + specular) * fShadow; + + return half4( directLighting + ambient, baseColour.a ); +} diff --git a/res/dist/media/materials/programs/InvertFP.cg b/res/dist/media/materials/programs/InvertFP.cg new file mode 100644 index 00000000000..4e34426871d --- /dev/null +++ b/res/dist/media/materials/programs/InvertFP.cg @@ -0,0 +1,6 @@ +sampler2D RT : register(s0); + +float4 Invert_ps (float4 pos : POSITION, float2 iTexCoord : TEXCOORD0) : COLOR +{ + return 1 - tex2D(RT, iTexCoord); +} diff --git a/res/dist/media/materials/programs/InvertFP.glsles b/res/dist/media/materials/programs/InvertFP.glsles new file mode 100644 index 00000000000..86c5d72cf78 --- /dev/null +++ b/res/dist/media/materials/programs/InvertFP.glsles @@ -0,0 +1,13 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform sampler2D RT; +varying vec2 uv0; +varying vec2 uv1; + +void main() +{ + gl_FragColor = 1.0 - texture2D(RT, uv0); +} diff --git a/res/dist/media/materials/programs/LaplaceFP.cg b/res/dist/media/materials/programs/LaplaceFP.cg new file mode 100644 index 00000000000..f96b5008ddf --- /dev/null +++ b/res/dist/media/materials/programs/LaplaceFP.cg @@ -0,0 +1,37 @@ +sampler2D Image : register(s0); + +// The Laplace filter approximates the second order derivate, +// that is, the rate of change of slope in the image. It can be +// used for edge detection. The Laplace filter gives negative +// response on the higher side of the edge and positive response +// on the lower side. + +// This is the filter kernel: +// 0 1 0 +// 1 -4 1 +// 0 1 0 + + + +float4 Laplace_ps ( float4 pos : POSITION, + float2 texCoord: TEXCOORD0, + uniform float scale, + uniform float pixelSize) : COLOR +{ + + float2 samples[4] = { + 0, -1, + -1, 0, + 1, 0, + 0, 1 + }; + float4 laplace = -4 * tex2D(Image, texCoord); + + // Sample the neighbor pixels + for (int i = 0; i < 4; i++){ + laplace += tex2D(Image, texCoord + pixelSize * samples[i]); + } + + return (0.5 + scale * laplace); +} + diff --git a/res/dist/media/materials/programs/LaplaceFP.glsles b/res/dist/media/materials/programs/LaplaceFP.glsles new file mode 100644 index 00000000000..0c4104c59e6 --- /dev/null +++ b/res/dist/media/materials/programs/LaplaceFP.glsles @@ -0,0 +1,40 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform sampler2D Image; +uniform float scale; +uniform float pixelSize; +varying vec2 uv0; + +// The Laplace filter approximates the second order derivate, +// that is, the rate of change of slope in the image. It can be +// used for edge detection. The Laplace filter gives negative +// response on the higher side of the edge and positive response +// on the lower side. + +// This is the filter kernel: +// 0 1 0 +// 1 -4 1 +// 0 1 0 + +void main() +{ + vec2 samples[4]; + samples[0] = vec2(0, -1); + samples[1] = vec2(-1, 0); + samples[2] = vec2(1, 0); + samples[3] = vec2(0, 1); + + mediump vec4 tc = texture2D(Image, uv0); + vec4 laplace = -4.0 * tc; + + // Sample the neighbor pixels + for (int i = 0; i < 4; i++){ + laplace += texture2D(Image, uv0 + pixelSize * samples[i]); + } + + gl_FragColor = (0.5 + scale * laplace); +} + diff --git a/res/dist/media/materials/programs/LightToHeatFp.glsles b/res/dist/media/materials/programs/LightToHeatFp.glsles new file mode 100644 index 00000000000..4fe7e5554c7 --- /dev/null +++ b/res/dist/media/materials/programs/LightToHeatFp.glsles @@ -0,0 +1,39 @@ +#version 100 + +precision mediump int; +precision mediump float; + +uniform vec4 random_fractions; +uniform vec4 heatBiasScale; +uniform vec4 depth_modulator; + +uniform sampler2D Input; // output of HeatVisionCaster_fp (NdotV) +uniform sampler2D NoiseMap; +uniform sampler2D HeatLookup; + +varying vec4 diffuse; +varying vec2 uv; + +void main() +{ + float depth, heat, interference; + + // Output constant color: + depth = texture2D( Input, uv ).x; + depth *= (depth * depth_modulator).x; + + heat = (depth * heatBiasScale.y); + +// if (depth > 0) + { + interference = -0.5 + texture2D( NoiseMap, uv + vec2( random_fractions.x, random_fractions.y ) ).x; + interference *= interference; + interference *= 1.0 - heat; + heat += interference;//+ heatBiasScale.x; + } + + // Clamp UVs + heat = max( 0.005, min( 0.995, heat ) ); + gl_FragColor = texture2D( HeatLookup, vec2( heat, 0.0 ) ); +} + diff --git a/res/dist/media/materials/programs/LightToHeatVp.glsles b/res/dist/media/materials/programs/LightToHeatVp.glsles new file mode 100644 index 00000000000..a32020ef78f --- /dev/null +++ b/res/dist/media/materials/programs/LightToHeatVp.glsles @@ -0,0 +1,17 @@ +#version 100 + +precision mediump int; +precision mediump float; + + +attribute vec4 position; +uniform float flipping; +varying vec2 uv; + +void main() +{ + vec4 inPos = position; + gl_Position = vec4(inPos.x, flipping * inPos.y, 0.0, 1.0); + inPos.xy = sign(inPos.xy); + uv = (vec2(inPos.x, -inPos.y) + 1.0)/2.0; +} diff --git a/res/dist/media/materials/programs/NightVisionFP.cg b/res/dist/media/materials/programs/NightVisionFP.cg new file mode 100644 index 00000000000..5bbd831835b --- /dev/null +++ b/res/dist/media/materials/programs/NightVisionFP.cg @@ -0,0 +1,27 @@ +sampler2D RT : register(s0); +sampler3D noiseVol : register(s1); + +float4 NightVision_ps( float4 pos : POSITION, + float2 TexCoord : TEXCOORD0, + uniform float4 lum, + uniform float time) : COLOR +{ + float4 oC; + oC = tex2D(RT, TexCoord); + + //obtain luminence value + oC = dot(oC,lum); + + //add some random noise + oC += 0.2 *(tex3D(noiseVol, float3(TexCoord*5,time)))- 0.05; + + //add lens circle effect + //(could be optimised by using texture) + float dist = distance(TexCoord, float2(0.5,0.5)); + oC *= smoothstep(0.5,0.45,dist); + + //add rb to the brightest pixels + oC.rb = max (oC.r - 0.75, 0)*4; + + return oC ; +} \ No newline at end of file diff --git a/res/dist/media/materials/programs/NightVisionFP.glsles b/res/dist/media/materials/programs/NightVisionFP.glsles new file mode 100644 index 00000000000..33252974e1b --- /dev/null +++ b/res/dist/media/materials/programs/NightVisionFP.glsles @@ -0,0 +1,26 @@ +sampler RT : register(s0); +sampler noiseVol : register(s1); + +float4 NightVision_ps( float2 TexCoord : TEXCOORD0, + uniform float4 lum, + uniform float time) : COLOR +{ + float4 oC; + oC = tex2D(RT, TexCoord); + + //obtain luminence value + oC = dot(oC,lum); + + //add some random noise + oC += 0.2 *(tex3D(noiseVol, float3(TexCoord*5,time)))- 0.05; + + //add lens circle effect + //(could be optimised by using texture) + float dist = distance(TexCoord, float2(0.5,0.5)); + oC *= smoothstep(0.5,0.45,dist); + + //add rb to the brightest pixels + oC.rb = max (oC.r - 0.75, 0)*4; + + return oC ; +} \ No newline at end of file diff --git a/res/dist/media/materials/programs/Ocean2GLSL.frag b/res/dist/media/materials/programs/Ocean2GLSL.frag new file mode 100644 index 00000000000..024b68eb37e --- /dev/null +++ b/res/dist/media/materials/programs/Ocean2GLSL.frag @@ -0,0 +1,71 @@ +/*********************************************************************NVMH3**** +Copyright NVIDIA Corporation 2003 +TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED +*AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS +BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES +WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, +BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) +ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS +BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + + +Comments: + Simple ocean shader with animated bump map and geometric waves + Based partly on "Effective Water Simulation From Physical Models", GPU Gems + +11 Aug 05: converted from HLSL to GLSL by Jeff Doyle (nfz) to work in Ogre + +******************************************************************************/ + + +uniform sampler2D NormalMap; +uniform samplerCube EnvironmentMap; +uniform vec4 deepColor; +uniform vec4 shallowColor; +uniform vec4 reflectionColor; +uniform float reflectionAmount; +uniform float reflectionBlur; +uniform float waterAmount; +uniform float fresnelPower; +uniform float fresnelBias; +uniform float hdrMultiplier; + +varying mat3 rotMatrix; // first row of the 3x3 transform from tangent to cube space +varying vec2 bumpCoord0; +varying vec2 bumpCoord1; +varying vec2 bumpCoord2; +varying vec3 eyeVector; + + +void main(void) +{ + // sum normal maps + // sample from 3 different points so no texture repetition is noticeable + vec4 t0 = texture2D(NormalMap, bumpCoord0) * 2.0 - 1.0; + vec4 t1 = texture2D(NormalMap, bumpCoord1) * 2.0 - 1.0; + vec4 t2 = texture2D(NormalMap, bumpCoord2) * 2.0 - 1.0; + vec3 N = t0.xyz + t1.xyz + t2.xyz; + + N = normalize(rotMatrix * N); + + // reflection + vec3 E = normalize(eyeVector); + vec3 R = reflect(E, N); + // Ogre conversion for cube map lookup + R.z = -R.z; + + vec4 reflection = textureCube(EnvironmentMap, R, reflectionBlur); + // cheap hdr effect + reflection.rgb *= (reflection.r + reflection.g + reflection.b) * hdrMultiplier; + + // fresnel + float facing = 1.0 - dot(-E, N); + float fresnel = clamp(fresnelBias + pow(facing, fresnelPower), 0.0, 1.0); + + vec4 waterColor = mix(shallowColor, deepColor, facing) * waterAmount; + + reflection = mix(waterColor, reflection * reflectionColor, fresnel) * reflectionAmount; + gl_FragColor = waterColor + reflection; +} diff --git a/res/dist/media/materials/programs/Ocean2GLSL.vert b/res/dist/media/materials/programs/Ocean2GLSL.vert new file mode 100644 index 00000000000..89a4cc76a04 --- /dev/null +++ b/res/dist/media/materials/programs/Ocean2GLSL.vert @@ -0,0 +1,91 @@ +/*********************************************************************NVMH3**** +Copyright NVIDIA Corporation 2003 +TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED +*AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS +BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES +WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, +BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) +ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS +BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + + +Comments: + Simple ocean shader with animated bump map and geometric waves + Based partly on "Effective Water Simulation From Physical Models", GPU Gems + +11 Aug 05: converted from HLSL to GLSL by Jeff Doyle (nfz) to work in Ogre + +******************************************************************************/ + +uniform vec3 eyePosition; +uniform float BumpScale; +uniform vec2 textureScale; +uniform vec2 bumpSpeed; +uniform float time; +uniform float waveFreq; +uniform float waveAmp; + +varying mat3 rotMatrix; // transform from tangent to obj space +varying vec2 bumpCoord0; +varying vec2 bumpCoord1; +varying vec2 bumpCoord2; +varying vec3 eyeVector; + +// wave functions +struct Wave { + float freq; // 2*PI / wavelength + float amp; // amplitude + float phase; // speed * 2*PI / wavelength + vec2 dir; +}; + + +void main(void) +{ + + #define NWAVES 2 + + Wave wave[NWAVES]; + + wave[0] = Wave( waveFreq, waveAmp, 0.5, vec2(-1, 0) ); + wave[1] = Wave( 3.0 * waveFreq, 0.33 * waveAmp, 1.7, vec2(-0.7, 0.7) ); + + + vec4 P = gl_Vertex; + + // sum waves + float ddx = 0.0, ddy = 0.0; + float deriv; + float angle; + + // wave synthesis using two sine waves at different frequencies and phase shift + for(int i = 0; i